Basic Theora support working, added a function to the dtsc lib.
This commit is contained in:
parent
a2f088ad80
commit
f88bee5baf
6 changed files with 90 additions and 13 deletions
54
lib/dtsc.cpp
54
lib/dtsc.cpp
|
@ -708,6 +708,60 @@ void DTSC::File::seekNext(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DTSC::File::parseNext(){
|
||||||
|
if (fread(buffer, 4, 1, F) != 1){
|
||||||
|
if (feof(F)){
|
||||||
|
#if DEBUG >= 4
|
||||||
|
fprintf(stderr, "End of file reached.\n");
|
||||||
|
#endif
|
||||||
|
}else{
|
||||||
|
fprintf(stderr, "Could not read header\n");
|
||||||
|
}
|
||||||
|
strbuffer = "";
|
||||||
|
jsonbuffer.null();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (memcmp(buffer, DTSC::Magic_Header, 4) == 0){
|
||||||
|
readHeader(lastreadpos);
|
||||||
|
jsonbuffer = metadata;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long long unsigned int version = 0;
|
||||||
|
if (memcmp(buffer, DTSC::Magic_Packet, 4) == 0){
|
||||||
|
version = 1;
|
||||||
|
}
|
||||||
|
if (memcmp(buffer, DTSC::Magic_Packet2, 4) == 0){
|
||||||
|
version = 2;
|
||||||
|
}
|
||||||
|
if (version == 0){
|
||||||
|
fprintf(stderr, "Invalid packet header @ %#x - %.4s != %.4s\n", lastreadpos, buffer, DTSC::Magic_Packet2);
|
||||||
|
strbuffer = "";
|
||||||
|
jsonbuffer.null();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fread(buffer, 4, 1, F) != 1){
|
||||||
|
fprintf(stderr, "Could not read size\n");
|
||||||
|
strbuffer = "";
|
||||||
|
jsonbuffer.null();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t * ubuffer = (uint32_t *)buffer;
|
||||||
|
long packSize = ntohl(ubuffer[0]);
|
||||||
|
strbuffer.resize(packSize);
|
||||||
|
if (fread((void*)strbuffer.c_str(), packSize, 1, F) != 1){
|
||||||
|
fprintf(stderr, "Could not read packet\n");
|
||||||
|
strbuffer = "";
|
||||||
|
jsonbuffer.null();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (version == 2){
|
||||||
|
jsonbuffer = JSON::fromDTMI2(strbuffer);
|
||||||
|
}else{
|
||||||
|
jsonbuffer = JSON::fromDTMI(strbuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the byte positon of the start of the last packet that was read.
|
/// Returns the byte positon of the start of the last packet that was read.
|
||||||
long long int DTSC::File::getLastReadPos(){
|
long long int DTSC::File::getLastReadPos(){
|
||||||
return lastreadpos;
|
return lastreadpos;
|
||||||
|
|
|
@ -104,6 +104,7 @@ namespace DTSC {
|
||||||
long int getBytePos();
|
long int getBytePos();
|
||||||
bool reachedEOF();
|
bool reachedEOF();
|
||||||
void seekNext();
|
void seekNext();
|
||||||
|
void parseNext();
|
||||||
std::string & getPacket();
|
std::string & getPacket();
|
||||||
JSON::Value & getJSON();
|
JSON::Value & getJSON();
|
||||||
JSON::Value & getTrackById(int trackNo);
|
JSON::Value & getTrackById(int trackNo);
|
||||||
|
|
25
lib/ogg.cpp
25
lib/ogg.cpp
|
@ -46,6 +46,7 @@ namespace OGG{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Page::read(std::string & newData){
|
bool Page::read(std::string & newData){
|
||||||
|
segmentTableDeque.clear();
|
||||||
//datasize = 0;
|
//datasize = 0;
|
||||||
if (newData.size()<27){
|
if (newData.size()<27){
|
||||||
return false;
|
return false;
|
||||||
|
@ -178,18 +179,18 @@ namespace OGG{
|
||||||
return data+27;
|
return data+27;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::deque<unsigned int> Page::getSegmentTableDeque(){
|
std::deque<unsigned int> & Page::getSegmentTableDeque(){
|
||||||
std::deque<unsigned int> retVal;
|
if ( !segmentTableDeque.size()){
|
||||||
unsigned int temp = 0;
|
unsigned int temp = 0;
|
||||||
char* segmentTable = getSegmentTable();
|
for (unsigned int i = 0; i < getPageSegments(); i++){
|
||||||
for (unsigned int i = 0; i < getPageSegments(); i++){
|
temp += getSegmentTable()[i];
|
||||||
temp += segmentTable[i];
|
if (getSegmentTable()[i] < 255){
|
||||||
if (segmentTable[i] < 255){
|
segmentTableDeque.push_back(temp);
|
||||||
retVal.push_back(temp);
|
temp = 0;
|
||||||
temp = 0;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retVal;
|
return segmentTableDeque;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Page::setSegmentTable(std::vector<unsigned int> layout){
|
bool Page::setSegmentTable(std::vector<unsigned int> layout){
|
||||||
|
@ -272,10 +273,10 @@ namespace OGG{
|
||||||
r << " eos";
|
r << " eos";
|
||||||
}
|
}
|
||||||
r << std::endl;
|
r << std::endl;
|
||||||
r << std::string(indent + 2,' ') << "Granule Position: " <<std::hex<< getGranulePosition() <<std::dec<< std::endl;
|
r << std::string(indent + 2,' ') << "Granule Position: " << std::hex << getGranulePosition() << std::dec << std::endl;
|
||||||
r << std::string(indent + 2,' ') << "Bitstream Number: " << getBitstreamSerialNumber() << std::endl;
|
r << std::string(indent + 2,' ') << "Bitstream Number: " << getBitstreamSerialNumber() << std::endl;
|
||||||
r << std::string(indent + 2,' ') << "Sequence Number: " << getPageSequenceNumber() << std::endl;
|
r << std::string(indent + 2,' ') << "Sequence Number: " << getPageSequenceNumber() << std::endl;
|
||||||
r << std::string(indent + 2,' ') << "Checksum: " << std::hex << getCRCChecksum()<< std::dec << std::endl;
|
r << std::string(indent + 2,' ') << "Checksum: " << std::hex << getCRCChecksum() << std::dec << std::endl;
|
||||||
//r << " Calced Checksum: " << std::hex << calcChecksum() << std::dec << std::endl;
|
//r << " Calced Checksum: " << std::hex << calcChecksum() << std::dec << std::endl;
|
||||||
//r << "CRC_checksum write: " << std::hex << getCRCChecksum()<< std::dec << std::endl;
|
//r << "CRC_checksum write: " << std::hex << getCRCChecksum()<< std::dec << std::endl;
|
||||||
r << std::string(indent + 2,' ') << "Segments: " << (int)getPageSegments() << std::endl;
|
r << std::string(indent + 2,' ') << "Segments: " << (int)getPageSegments() << std::endl;
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace OGG{
|
||||||
char getPageSegments();
|
char getPageSegments();
|
||||||
inline void setPageSegments(char newVal);
|
inline void setPageSegments(char newVal);
|
||||||
char* getSegmentTable();
|
char* getSegmentTable();
|
||||||
std::deque<unsigned int> getSegmentTableDeque();
|
std::deque<unsigned int> & getSegmentTableDeque();
|
||||||
bool setSegmentTable(std::vector<unsigned int> layout);
|
bool setSegmentTable(std::vector<unsigned int> layout);
|
||||||
void setSegmentTable(char* newVal, unsigned int length);
|
void setSegmentTable(char* newVal, unsigned int length);
|
||||||
unsigned long int getPageSize();
|
unsigned long int getPageSize();
|
||||||
|
@ -40,6 +40,7 @@ namespace OGG{
|
||||||
std::string toPrettyString(size_t indent = 0);
|
std::string toPrettyString(size_t indent = 0);
|
||||||
void setInternalCodec(std::string myCodec);
|
void setInternalCodec(std::string myCodec);
|
||||||
private:
|
private:
|
||||||
|
std::deque<unsigned int> segmentTableDeque;
|
||||||
long unsigned int calcChecksum();
|
long unsigned int calcChecksum();
|
||||||
char* data;
|
char* data;
|
||||||
unsigned int datasize;
|
unsigned int datasize;
|
||||||
|
|
|
@ -203,6 +203,13 @@ namespace theora{
|
||||||
return commentLen(offset);
|
return commentLen(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char header::getLFLIMS(size_t index){
|
||||||
|
if (getHeaderType() != 2){return 0;}
|
||||||
|
if (index >= 64){return 0;}
|
||||||
|
char NBITS = (data[0] >> 5) & 0x07;
|
||||||
|
return NBITS;
|
||||||
|
}
|
||||||
|
|
||||||
std::string header::getUserComment(size_t index){
|
std::string header::getUserComment(size_t index){
|
||||||
if (index >= getNComments()){return "";}
|
if (index >= getNComments()){return "";}
|
||||||
int len;
|
int len;
|
||||||
|
@ -244,6 +251,8 @@ namespace theora{
|
||||||
result << std::string(indent+4,' ') << "[" << i << "] " << getUserComment(i) << std::endl;
|
result << std::string(indent+4,' ') << "[" << i << "] " << getUserComment(i) << std::endl;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 2:
|
||||||
|
result << std::string(indent+2,' ') << "NBITS: " << (int)getLFLIMS(0) << std::endl;
|
||||||
}
|
}
|
||||||
return result.str();
|
return result.str();
|
||||||
}
|
}
|
||||||
|
@ -296,6 +305,14 @@ namespace theora{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long long unsigned int header::parseGranuleUpper(long long unsigned int granPos){
|
||||||
|
return granPos >> getKFGShift();
|
||||||
|
}
|
||||||
|
|
||||||
|
long long unsigned int header::parseGranuleLower(long long unsigned int granPos){
|
||||||
|
return (granPos & ((1 << getKFGShift()) - 1));
|
||||||
|
}
|
||||||
|
|
||||||
std::string frame::toPrettyString(size_t indent){
|
std::string frame::toPrettyString(size_t indent){
|
||||||
std::stringstream result;
|
std::stringstream result;
|
||||||
result << std::string(indent,' ') << "Theora Frame" << std::endl;
|
result << std::string(indent,' ') << "Theora Frame" << std::endl;
|
||||||
|
|
|
@ -30,7 +30,10 @@ namespace theora{
|
||||||
std::string getVendor();
|
std::string getVendor();
|
||||||
long unsigned int getNComments();
|
long unsigned int getNComments();
|
||||||
std::string getUserComment(size_t index);
|
std::string getUserComment(size_t index);
|
||||||
|
char getLFLIMS(size_t index);
|
||||||
std::string toPrettyString(size_t indent = 0);
|
std::string toPrettyString(size_t indent = 0);
|
||||||
|
long long unsigned int parseGranuleUpper(long long unsigned int granPos);
|
||||||
|
long long unsigned int parseGranuleLower(long long unsigned int granPos);
|
||||||
protected:
|
protected:
|
||||||
uint32_t getInt32(size_t index);
|
uint32_t getInt32(size_t index);
|
||||||
uint32_t getInt24(size_t index);
|
uint32_t getInt24(size_t index);
|
||||||
|
|
Loading…
Add table
Reference in a new issue