changeset 9858:9af61fc7955c

changed input and output buffer handling to be mplayer-compatible... based on patch by Fabian Franz <FabianFranz@gmx.de>
author arpi
date Sun, 06 Apr 2003 16:42:15 +0000
parents 89b48bc6c441
children 16a7d1f4da38
files libmpeg2/decode.c libmpeg2/header.c
diffstat 2 files changed, 42 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libmpeg2/decode.c	Sun Apr 06 16:41:49 2003 +0000
+++ b/libmpeg2/decode.c	Sun Apr 06 16:42:15 2003 +0000
@@ -154,6 +154,21 @@
 {
     int size_buffer, size_chunk, copied;
 
+    if(mpeg2dec->code==0xff){
+	// FIXME: we need to resync stream (esp. mpeg2dec-->code) as we
+	// left parser at 0x1FF last time at the end of prev. chunk.
+	// Why? mpeg2dec->action is set to mpeg2_header_picture_start, but
+	// it will call mpeg2_parse_header() too...
+	//
+	// following code copied from mpeg2_seek_header():
+	while (mpeg2dec->code != 0xb3 &&
+	   ((mpeg2dec->code != 0xb7 && mpeg2dec->code != 0xb8 &&
+	     mpeg2dec->code) || mpeg2dec->sequence.width == -1))
+	    if (seek_chunk (mpeg2dec))
+		return -1;
+	mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
+    }
+
     if (mpeg2dec->action) {
 	int state;
 
@@ -161,8 +176,9 @@
 	if (state)
 	    return state;
     }
-
+    
     while (1) {
+	//printf("code=0x%X       \n",mpeg2dec->code);
 	while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) <
 	       mpeg2dec->nb_decode_slices) {
 	    size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
@@ -196,6 +212,13 @@
 	if (seek_chunk (mpeg2dec))
 	    return -1;
     }
+    
+    //printf("next_code=0x%X  state=%d     \n",mpeg2dec->code,mpeg2dec->state);
+    
+    if(mpeg2dec->code==0xff){
+	mpeg2dec->action = mpeg2_header_picture_start; //mpeg2_seek_header;
+	return mpeg2dec->state;
+    }
 
     switch (RECEIVED (mpeg2dec->code, mpeg2dec->state)) {
     case RECEIVED (0x00, STATE_SLICE_1ST):
@@ -248,6 +271,11 @@
 	}
 	mpeg2dec->bytes_since_pts += copied;
 
+    //printf("header_code=0x%X    state=%d   \n",mpeg2dec->code,mpeg2dec->state);
+    
+//    if(!mpeg2dec->code && mpeg2dec->state==7)
+	
+
 	if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec)) {
 	    mpeg2dec->code = mpeg2dec->buf_start[-1];
 	    mpeg2dec->action = mpeg2_seek_header;
@@ -255,6 +283,9 @@
 	}
 
 	mpeg2dec->code = mpeg2dec->buf_start[-1];
+
+    //printf("next_header_code=0x%X    state=%d   \n",mpeg2dec->code,mpeg2dec->state);
+
 	switch (RECEIVED (mpeg2dec->code, mpeg2dec->state)) {
 
 	/* state transition after a sequence header */
@@ -348,6 +379,15 @@
     fbuf->buf[1] = buf[1];
     fbuf->buf[2] = buf[2];
     fbuf->id = id;
+    // HACK! FIXME! At first I frame, copy pointers to prediction frame too!
+    if (mpeg2dec->custom_fbuf && !mpeg2dec->fbuf[1]->buf[0]){
+	mpeg2dec->fbuf[1]->buf[0]=buf[0];
+	mpeg2dec->fbuf[1]->buf[1]=buf[1];
+	mpeg2dec->fbuf[1]->buf[2]=buf[2];
+	mpeg2dec->fbuf[1]->id=NULL;
+    }
+//        printf("libmpeg2: FBUF 0:%p 1:%p 2:%p\n",
+//	    mpeg2dec->fbuf[0]->buf[0],mpeg2dec->fbuf[1]->buf[0],mpeg2dec->fbuf[2]->buf[0]);
 }
 
 void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf)
--- a/libmpeg2/header.c	Sun Apr 06 16:41:49 2003 +0000
+++ b/libmpeg2/header.c	Sun Apr 06 16:42:15 2003 +0000
@@ -655,7 +655,7 @@
     } else {
 	int b_type;
 
-	mpeg2dec->decoder.convert = NULL;
+	//mpeg2dec->decoder.convert = NULL;
 	b_type = (mpeg2dec->decoder.coding_type == B_TYPE);
 	mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->fbuf[0]->buf,
 			 mpeg2dec->fbuf[b_type + 1]->buf,