comparison libmpcodecs/vd_libmpeg2.c @ 13112:3e4bea88c1c1

libmpeg2 B-frame fix
author henry
date Tue, 24 Aug 2004 16:15:56 +0000
parents cda4ad0d3e70
children 9bba611637fb
comparison
equal deleted inserted replaced
13111:fad3639920d5 13112:3e4bea88c1c1
61 61
62 mpeg2_custom_fbuf(mpeg2dec,1); // enable DR1 62 mpeg2_custom_fbuf(mpeg2dec,1); // enable DR1
63 63
64 sh->context=mpeg2dec; 64 sh->context=mpeg2dec;
65 65
66 mpeg2dec->pending_buffer = 0;
67 mpeg2dec->pending_length = 0;
68
66 return 1; 69 return 1;
67 //return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); 70 //return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12);
68 } 71 }
69 72
70 // uninit driver 73 // uninit driver
71 static void uninit(sh_video_t *sh){ 74 static void uninit(sh_video_t *sh){
72 mpeg2dec_t * mpeg2dec = sh->context; 75 mpeg2dec_t * mpeg2dec = sh->context;
76 if (mpeg2dec->pending_buffer) free(mpeg2dec->pending_buffer);
73 mpeg2_close (mpeg2dec); 77 mpeg2_close (mpeg2dec);
74 } 78 }
75 79
76 static void draw_slice (void * _sh, uint8_t ** src, unsigned int y){ 80 static void draw_slice (void * _sh, uint8_t * const * src, unsigned int y){
77 sh_video_t* sh = (sh_video_t*) _sh; 81 sh_video_t* sh = (sh_video_t*) _sh;
78 mpeg2dec_t* mpeg2dec = sh->context; 82 mpeg2dec_t* mpeg2dec = sh->context;
79 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); 83 const mpeg2_info_t * info = mpeg2_info (mpeg2dec);
80 int stride[3]; 84 int stride[3];
81 85
82 // printf("draw_slice() y=%d \n",y); 86 // printf("draw_slice() y=%d \n",y);
83 87
84 stride[0]=mpeg2dec->decoder.stride; 88 stride[0]=mpeg2dec->decoder.stride;
85 stride[1]=stride[2]=mpeg2dec->decoder.uv_stride; 89 stride[1]=stride[2]=mpeg2dec->decoder.uv_stride;
86 90
87 mpcodecs_draw_slice(sh, (uint8_t **)src, 91 mpcodecs_draw_slice(sh, (uint8_t **)src,
105 ((char*)data+len)[1]=0; 109 ((char*)data+len)[1]=0;
106 ((char*)data+len)[2]=1; 110 ((char*)data+len)[2]=1;
107 ((char*)data+len)[3]=0xff; 111 ((char*)data+len)[3]=0xff;
108 len+=4; 112 len+=4;
109 113
110 mpeg2_buffer (mpeg2dec, data, data+len); 114 if (mpeg2dec->pending_length) {
115 mpeg2_buffer (mpeg2dec, mpeg2dec->pending_buffer, mpeg2dec->pending_buffer + mpeg2dec->pending_length);
116 } else {
117 mpeg2_buffer (mpeg2dec, data, data+len);
118 }
111 119
112 while(1){ 120 while(1){
113 int state=mpeg2_parse (mpeg2dec); 121 int state=mpeg2_parse (mpeg2dec);
114 switch(state){ 122 switch(state){
115 case STATE_BUFFER: 123 case STATE_BUFFER:
116 // parsing of the passed buffer finished, return. 124 if (mpeg2dec->pending_length) {
117 // if(!mpi) printf("\nNO PICTURE!\n"); 125 mpeg2dec->pending_length = 0;
118 return mpi; 126 mpeg2_buffer (mpeg2dec, data, data+len);
127 } else {
128 // parsing of the passed buffer finished, return.
129 // if(!mpi) fprintf(stderr, "\nNO PICTURE!\n");
130 return 0;
131 }
132 break;
119 case STATE_SEQUENCE: 133 case STATE_SEQUENCE:
120 // video parameters inited/changed, (re)init libvo: 134 // video parameters inited/changed, (re)init libvo:
121 if(!mpcodecs_config_vo(sh, 135 if(!mpcodecs_config_vo(sh,
122 info->sequence->width, 136 info->sequence->width,
123 info->sequence->height, IMGFMT_YV12)) return 0; 137 info->sequence->height, IMGFMT_YV12)) return 0;
124 break; 138 break;
125 case STATE_PICTURE: { 139 case STATE_PICTURE: {
126 int type=info->current_picture->flags&PIC_MASK_CODING_TYPE; 140 int type=info->current_picture->flags&PIC_MASK_CODING_TYPE;
127 mp_image_t* mpi; 141 mp_image_t* mpi_new;
128 142
129 drop_frame = framedrop && (mpeg2dec->decoder.coding_type == B_TYPE); 143 drop_frame = framedrop && (mpeg2dec->decoder.coding_type == B_TYPE);
130 drop_frame |= framedrop>=2; // hard drop 144 drop_frame |= framedrop>=2; // hard drop
131 if (drop_frame) { 145 if (drop_frame) {
132 mpeg2_skip(mpeg2dec, 1); 146 mpeg2_skip(mpeg2dec, 1);
134 break; 148 break;
135 } 149 }
136 mpeg2_skip(mpeg2dec, 0); //mpeg2skip skips frames until set again to 0 150 mpeg2_skip(mpeg2dec, 0); //mpeg2skip skips frames until set again to 0
137 151
138 // get_buffer "callback": 152 // get_buffer "callback":
139 mpi=mpcodecs_get_image(sh,MP_IMGTYPE_IPB, 153 mpi_new=mpcodecs_get_image(sh,MP_IMGTYPE_IPB,
140 (type==PIC_FLAG_CODING_TYPE_B) 154 (type==PIC_FLAG_CODING_TYPE_B)
141 ? ((!framedrop && vd_use_slices && 155 ? ((!framedrop && vd_use_slices &&
142 (info->current_picture->flags&PIC_FLAG_PROGRESSIVE_FRAME)) ? 156 (info->current_picture->flags&PIC_FLAG_PROGRESSIVE_FRAME)) ?
143 MP_IMGFLAG_DRAW_CALLBACK:0) 157 MP_IMGFLAG_DRAW_CALLBACK:0)
144 : (MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE), 158 : (MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE),
145 (info->sequence->picture_width+15)&(~15), 159 (info->sequence->picture_width+15)&(~15),
146 (info->sequence->picture_height+15)&(~15) ); 160 (info->sequence->picture_height+15)&(~15) );
147 if(!mpi) return 0; // VO ERROR!!!!!!!! 161 if(!mpi_new) return 0; // VO ERROR!!!!!!!!
148 mpeg2_set_buf(mpeg2dec, mpi->planes, mpi); 162 // if (mpi_new == mpi)
163 // fprintf(stderr, "AIEEEEEEEEEE\n");;
164 mpeg2_set_buf(mpeg2dec, mpi_new->planes, mpi_new);
149 if (info->current_picture->flags&PIC_FLAG_TOP_FIELD_FIRST) 165 if (info->current_picture->flags&PIC_FLAG_TOP_FIELD_FIRST)
150 mpi->fields |= MP_IMGFIELD_TOP_FIRST; 166 mpi_new->fields |= MP_IMGFIELD_TOP_FIRST;
151 else mpi->fields &= ~MP_IMGFIELD_TOP_FIRST; 167 else mpi_new->fields &= ~MP_IMGFIELD_TOP_FIRST;
152 if (info->current_picture->flags&PIC_FLAG_REPEAT_FIRST_FIELD) 168 if (info->current_picture->flags&PIC_FLAG_REPEAT_FIRST_FIELD)
153 mpi->fields |= MP_IMGFIELD_REPEAT_FIRST; 169 mpi_new->fields |= MP_IMGFIELD_REPEAT_FIRST;
154 else mpi->fields &= ~MP_IMGFIELD_REPEAT_FIRST; 170 else mpi_new->fields &= ~MP_IMGFIELD_REPEAT_FIRST;
155 mpi->fields |= MP_IMGFIELD_ORDERED; 171 mpi_new->fields |= MP_IMGFIELD_ORDERED;
156 172
157 #ifdef MPEG12_POSTPROC 173 #ifdef MPEG12_POSTPROC
158 if(!mpi->qscale){ 174 if(!mpi_new->qscale){
159 mpi->qstride=(info->sequence->picture_width+15)>>4; 175 mpi_new->qstride=(info->sequence->picture_width+15)>>4;
160 mpi->qscale=malloc(mpi->qstride*((info->sequence->picture_height+15)>>4)); 176 mpi_new->qscale=malloc(mpi_new->qstride*((info->sequence->picture_height+15)>>4));
161 } 177 }
162 mpeg2dec->decoder.quant_store=mpi->qscale; 178 mpeg2dec->decoder.quant_store=mpi_new->qscale;
163 mpeg2dec->decoder.quant_stride=mpi->qstride; 179 mpeg2dec->decoder.quant_stride=mpi_new->qstride;
164 mpi->pict_type=type; // 1->I, 2->P, 3->B 180 mpi_new->pict_type=type; // 1->I, 2->P, 3->B
165 mpi->qscale_type= 1; 181 mpi_new->qscale_type= 1;
166 #endif 182 #endif
167 183
168 if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && 184 if(mpi_new->flags&MP_IMGFLAG_DRAW_CALLBACK &&
169 !(mpi->flags&MP_IMGFLAG_DIRECT)){ 185 !(mpi_new->flags&MP_IMGFLAG_DIRECT)){
170 // nice, filter/vo likes draw_callback :) 186 // nice, filter/vo likes draw_callback :)
171 mpeg2dec->decoder.convert=draw_slice; 187 mpeg2dec->decoder.convert=draw_slice;
172 mpeg2dec->decoder.convert_id=sh; 188 mpeg2dec->decoder.convert_id=sh;
173 } else 189 } else
174 mpeg2dec->decoder.convert=NULL; 190 mpeg2dec->decoder.convert=NULL;
177 case STATE_SLICE: 193 case STATE_SLICE:
178 case STATE_END: 194 case STATE_END:
179 case STATE_INVALID_END: 195 case STATE_INVALID_END:
180 // decoding done: 196 // decoding done:
181 if(mpi) printf("AJAJJJJJJJJ2!\n"); 197 if(mpi) printf("AJAJJJJJJJJ2!\n");
182 if(info->display_fbuf) mpi=info->display_fbuf->id; 198 if(info->display_fbuf) {
183 // return mpi; 199 mpi=info->display_fbuf->id;
200 mpeg2dec->pending_length = mpeg2dec->buf_end - mpeg2dec->buf_start;
201 // fprintf(stderr, "pending = %d\n", pending);
202 mpeg2dec->pending_buffer = realloc(mpeg2dec->pending_buffer, mpeg2dec->pending_length);
203 memcpy(mpeg2dec->pending_buffer, mpeg2dec->buf_start, mpeg2dec->pending_length);
204 return mpi;
205 }
184 } 206 }
185 } 207 }
186 } 208 }
187 #endif 209 #endif