[matroska] r1124 - trunk/DvdMenuXtractor/mpegparser
[email protected] Sun, 10 Apr 2005 18:31:28 +0400 (MSD)
Newsgroups
gmane.comp.multimedia.matroska.cvs
Message-ID
<[email protected] >
Author: robux4
Date: 2005-04-10 18:31:26 +0400 (Sun, 10 Apr 2005)
New Revision: 1124
Modified:
trunk/DvdMenuXtractor/mpegparser/M2VParser.cpp
trunk/DvdMenuXtractor/mpegparser/M2VParser.h
trunk/DvdMenuXtractor/mpegparser/MPEGVideoBuffer.cpp
trunk/DvdMenuXtractor/mpegparser/MPEGVideoBuffer.h
Log:
DMX: cleaning and optimisation of mpegparser
Modified: trunk/DvdMenuXtractor/mpegparser/M2VParser.cpp
===================================================================
--- trunk/DvdMenuXtractor/mpegparser/M2VParser.cpp 2005-04-10 13:36:44 UTC (rev 1123)
+++ trunk/DvdMenuXtractor/mpegparser/M2VParser.cpp 2005-04-10 14:31:26 UTC (rev 1124)
@@ -130,20 +130,19 @@
//Gotta find a sequence header now
MPEGChunk* chunk;
//MPEGChunk* seqHdrChunk;
- for(int i = 0; i < chunks.size(); i++){
+ for(size_t i = 0; i < chunks.size(); i++){
chunk = chunks[i];
if(chunk->GetType() == MPEG_VIDEO_SEQUENCE_START_CODE){
//Copy the header for later, we must copy because the actual chunk will be deleted in a bit
binary * hdrData = new binary[chunk->GetSize()];
memcpy(hdrData, chunk->GetPointer(), chunk->GetSize());
seqHdrChunk = new MPEGChunk(hdrData, chunk->GetSize()); //Save this for adding as private data...
- MPEG2SequenceHeader seqHdr = ParseSequenceHeader(chunk);
- m_seqHdr = seqHdr;
+ ParseSequenceHeader(chunk, m_seqHdr);
//Look for sequence extension to identify mpeg2
binary* pData = chunk->GetPointer();
- for(int i = 3; i < chunk->GetSize() - 4; i++){
- if(pData[i] == 0x00 && pData[i+1] == 0x00 && pData[i+2] == 0x01 && pData[i+3] == 0xb5 && ((pData[i+4] & 0xF0) == 0x10)){
+ for(size_t j = 3; i < chunk->GetSize() - 4; i++){
+ if(pData[j] == 0x00 && pData[j+1] == 0x00 && pData[j+2] == 0x01 && pData[j+3] == 0xb5 && ((pData[j+4] & 0xF0) == 0x10)){
mpegVersion = 2;
break;
}
@@ -195,15 +194,16 @@
return parserState;
}
-int32_t M2VParser::CountBFrames(){
+MediaTime M2VParser::CountBFrames(){
//We count after the first chunk.
- int32_t count = 0;
+ MediaTime count = 0;
if(m_eos) return 0;
if(notReachedFirstGOP) return 0;
- for(int i = 1; i < chunks.size(); i++){
+ for(size_t i = 1; i < chunks.size(); i++){
MPEGChunk* c = chunks[i];
if(c->GetType() == MPEG_VIDEO_PICTURE_START_CODE){
- MPEG2PictureHeader h = ParsePictureHeader(c);
+ MPEG2PictureHeader h;
+ ParsePictureHeader(c, h);
if(h.frameType == MPEG2_B_FRAME){
count += GetFrameDuration(h);
}else{
@@ -287,7 +287,7 @@
if(chunk->GetType() == MPEG_VIDEO_SEQUENCE_START_CODE){
if (chunks.size() == 1) return -1;
if(seqHdr) delete seqHdr;
- m_seqHdr = ParseSequenceHeader(chunk);
+ ParseSequenceHeader(chunk, m_seqHdr);
seqHdr = chunk;
}else{
delete chunk; //Skip all non picture, non seq headers
@@ -300,8 +300,9 @@
}
chunk = chunks.front();
}
- MPEG2PictureHeader picHdr = ParsePictureHeader(chunk);
- int bcount;
+ MPEG2PictureHeader picHdr;
+ ParsePictureHeader(chunk, picHdr);
+ MediaTime bcount;
if(myTime == nextSkip){
myTime+=nextSkipDuration;
currentStampingTime=myTime;
@@ -320,7 +321,7 @@
}
ShoveRef(myTime);
QueueFrame(seqHdr,chunk,myTime,picHdr);
- if(notReachedFirstGOP) notReachedFirstGOP = false;
+ notReachedFirstGOP = false;
break;
case MPEG2_P_FRAME:
bcount = CountBFrames();
Modified: trunk/DvdMenuXtractor/mpegparser/M2VParser.h
===================================================================
--- trunk/DvdMenuXtractor/mpegparser/M2VParser.h 2005-04-10 13:36:44 UTC (rev 1123)
+++ trunk/DvdMenuXtractor/mpegparser/M2VParser.h 2005-04-10 14:31:26 UTC (rev 1124)
@@ -76,7 +76,7 @@
int32_t InitParser();
void DumpQueues();
int32_t FillQueues();
- int32_t CountBFrames();
+ MediaTime CountBFrames();
void ShoveRef(MediaTime ref);
MediaTime GetFrameDuration(MPEG2PictureHeader picHdr);
int32_t QueueFrame(MPEGChunk* seqHdr, MPEGChunk* chunk, MediaTime timecode, MPEG2PictureHeader picHdr);
@@ -96,7 +96,7 @@
return seqHdrChunk;
}
- uint8_t GetMPEGVersion(){
+ uint8_t GetMPEGVersion() const{
return mpegVersion;
}
Modified: trunk/DvdMenuXtractor/mpegparser/MPEGVideoBuffer.cpp
===================================================================
--- trunk/DvdMenuXtractor/mpegparser/MPEGVideoBuffer.cpp 2005-04-10 13:36:44 UTC (rev 1123)
+++ trunk/DvdMenuXtractor/mpegparser/MPEGVideoBuffer.cpp 2005-04-10 14:31:26 UTC (rev 1124)
@@ -61,32 +61,19 @@
return;
}
if(chunkStart == -1){
- test = FindStartCode(0);
- if(test != -1) //We found a new startcode
- chunkStart = test;
+ chunkStart = FindStartCode(0);
}
if(chunkEnd == -1){
- test = FindStartCode(chunkStart+4);
- if(test != -1) //We found a new startcode
- chunkEnd = test;
+ chunkEnd = FindStartCode(chunkStart+4);
}
- if(chunkStart == -1){
+ if(chunkStart == -1 || chunkEnd == -1){
state = MPEG2_BUFFER_STATE_NEED_MORE_DATA;
- return;
- }else if(chunkEnd == -1){
- state = MPEG2_BUFFER_STATE_NEED_MORE_DATA;
- return;
}else{
assert(chunkStart >= 0 && chunkStart < chunkEnd && chunkEnd > 0);
state = MPEG2_BUFFER_STATE_CHUNK_READY;
- return;
}
}
-MPEG2BufferState MPEGVideoBuffer::GetState(){
- return state;
-}
-
MPEGChunk * MPEGVideoBuffer::ReadChunk(){
MPEGChunk* myChunk = NULL;
if(state == MPEG2_BUFFER_STATE_CHUNK_READY){
@@ -121,14 +108,9 @@
return res;
}
-MPEG2SequenceHeader ParseSequenceHeader(MPEGChunk* chunk){
- MPEG2SequenceHeader hdr;
+void ParseSequenceHeader(MPEGChunk* chunk, MPEG2SequenceHeader & hdr){
binary* pos = chunk->GetPointer();
uint8_t haveSeqExt = 0;
- if(chunk->GetType() != MPEG_VIDEO_SEQUENCE_START_CODE){
- //printf("Don't feed parse_sequence_header a chunk that isn't a sequence header!!!\n");
- return hdr;
- }
//Parse out the resolution info, horizontal first
pos+=4; //Skip the start code
hdr.width = (((unsigned int)pos[0]) << 4) | (((unsigned int) pos[1])>>4); //xx x0 00
@@ -206,18 +188,15 @@
}else{
hdr.progressiveSequence = 0;
}
-
- return hdr;
}
-MPEG2GOPHeader ParseGOPHeader(MPEGChunk* chunk){
- MPEG2GOPHeader hdr;
- binary* pos = chunk->GetPointer();
- uint32_t timecode;
+bool ParseGOPHeader(MPEGChunk* chunk, MPEG2GOPHeader & hdr){
if(chunk->GetType() != MPEG_VIDEO_GOP_START_CODE){
//printf("Don't feed parse_gop_header a chunk that isn't a gop header!!!\n");
- return hdr;
+ return false;
}
+ binary* pos = chunk->GetPointer();
+ uint32_t timecode;
pos+=4; //skip the startcode
//Parse GOP timecode structure
timecode = ((uint32_t)pos[0] << 24) |
@@ -234,19 +213,17 @@
}else{
hdr.closedGOP = 0;
}
- return hdr;
+ return true;
}
-MPEG2PictureHeader ParsePictureHeader(MPEGChunk* chunk){
- MPEG2PictureHeader hdr;
- binary* pos = chunk->GetPointer();
-// int i = 0;
- int havePicExt = 0;
- uint32_t temp = 0;
+bool ParsePictureHeader(MPEGChunk* chunk, MPEG2PictureHeader & hdr){
if(chunk->GetType() != MPEG_VIDEO_PICTURE_START_CODE){
//printf("Don't feed parse_picture_header a chunk that isn't a picture!!!\n");
- return hdr;
+ return false;
}
+ binary* pos = chunk->GetPointer();
+ int havePicExt = 0;
+ uint32_t temp = 0;
pos+=4;
temp = (((uint32_t)pos[0]) << 8) | (pos[1] & 0xC0);
hdr.temporalReference = temp >> 6;
@@ -284,5 +261,5 @@
hdr.progressive = (pos[0] & 0x80);
}
- return hdr;
+ return true;
}
Modified: trunk/DvdMenuXtractor/mpegparser/MPEGVideoBuffer.h
===================================================================
--- trunk/DvdMenuXtractor/mpegparser/MPEGVideoBuffer.h 2005-04-10 13:36:44 UTC (rev 1123)
+++ trunk/DvdMenuXtractor/mpegparser/MPEGVideoBuffer.h 2005-04-10 14:31:26 UTC (rev 1124)
@@ -92,11 +92,11 @@
delete [] data;
}
- uint8_t GetType(){
+ inline uint8_t GetType() const {
return type;
}
- uint32_t GetSize(){
+ inline uint32_t GetSize() const{
return size;
}
@@ -108,14 +108,14 @@
return data[i];
}
- binary * GetPointer(){
+ inline binary * GetPointer(){
return data;
}
};
-MPEG2SequenceHeader ParseSequenceHeader(MPEGChunk* chunk);
-MPEG2PictureHeader ParsePictureHeader(MPEGChunk* chunk);
-MPEG2GOPHeader ParseGOPHeader(MPEGChunk* chunk);
+void ParseSequenceHeader(MPEGChunk* chunk, MPEG2SequenceHeader & hdr);
+bool ParsePictureHeader(MPEGChunk* chunk, MPEG2PictureHeader & hdr);
+bool ParseGOPHeader(MPEGChunk* chunk, MPEG2GOPHeader & hdr);
class MPEGVideoBuffer{
private:
@@ -137,7 +137,7 @@
delete myBuffer;
}
- MPEG2BufferState GetState();
+ inline MPEG2BufferState GetState() const { return state; }
int32_t GetFreeBufferSpace(){
return (myBuffer->buf_capacity - myBuffer->bytes_in_buf);