comparison libmpcodecs/vd_libmpeg2.c @ 31290:f60cd3b9d453

libmpeg2: Move pending_buffer stuff to local decoder context. It is only used in our wrapper code, so there is no point to patch it into our libmpeg2 copy. This also helps when trying to use external libmpeg2. patch by Luca Barbato
author diego
date Wed, 09 Jun 2010 16:56:21 +0000
parents 2dead2f28eac
children a51baa308479
comparison
equal deleted inserted replaced
31289:2dead2f28eac 31290:f60cd3b9d453
50 char *quant_store[3]; 50 char *quant_store[3];
51 int imgfmt; 51 int imgfmt;
52 int width; 52 int width;
53 int height; 53 int height;
54 double aspect; 54 double aspect;
55 unsigned char *pending_buffer;
56 int pending_length;
55 } vd_libmpeg2_ctx_t; 57 } vd_libmpeg2_ctx_t;
56 58
57 // to set/get/query special features/parameters 59 // to set/get/query special features/parameters
58 static int control(sh_video_t *sh,int cmd,void* arg,...){ 60 static int control(sh_video_t *sh,int cmd,void* arg,...){
59 vd_libmpeg2_ctx_t *context = sh->context; 61 vd_libmpeg2_ctx_t *context = sh->context;
113 115
114 context = calloc(1, sizeof(vd_libmpeg2_ctx_t)); 116 context = calloc(1, sizeof(vd_libmpeg2_ctx_t));
115 context->mpeg2dec = mpeg2dec; 117 context->mpeg2dec = mpeg2dec;
116 sh->context = context; 118 sh->context = context;
117 119
118 mpeg2dec->pending_buffer = 0;
119 mpeg2dec->pending_length = 0;
120
121 return 1; 120 return 1;
122 } 121 }
123 122
124 // uninit driver 123 // uninit driver
125 static void uninit(sh_video_t *sh){ 124 static void uninit(sh_video_t *sh){
126 int i; 125 int i;
127 vd_libmpeg2_ctx_t *context = sh->context; 126 vd_libmpeg2_ctx_t *context = sh->context;
128 mpeg2dec_t * mpeg2dec = context->mpeg2dec; 127 mpeg2dec_t * mpeg2dec = context->mpeg2dec;
129 if (mpeg2dec->pending_buffer) free(mpeg2dec->pending_buffer); 128 if (context->pending_buffer) free(context->pending_buffer);
130 mpeg2dec->decoder.convert=NULL; 129 mpeg2dec->decoder.convert=NULL;
131 mpeg2dec->decoder.convert_id=NULL; 130 mpeg2dec->decoder.convert_id=NULL;
132 mpeg2_close (mpeg2dec); 131 mpeg2_close (mpeg2dec);
133 for (i=0; i < 3; i++) 132 for (i=0; i < 3; i++)
134 free(context->quant_store[i]); 133 free(context->quant_store[i]);
168 ((char*)data+len)[1]=0; 167 ((char*)data+len)[1]=0;
169 ((char*)data+len)[2]=1; 168 ((char*)data+len)[2]=1;
170 ((char*)data+len)[3]=0xff; 169 ((char*)data+len)[3]=0xff;
171 len+=4; 170 len+=4;
172 171
173 if (mpeg2dec->pending_length) { 172 if (context->pending_length) {
174 mpeg2_buffer (mpeg2dec, mpeg2dec->pending_buffer, mpeg2dec->pending_buffer + mpeg2dec->pending_length); 173 mpeg2_buffer (mpeg2dec, context->pending_buffer, context->pending_buffer + context->pending_length);
175 } else { 174 } else {
176 mpeg2_buffer (mpeg2dec, data, (uint8_t *)data+len); 175 mpeg2_buffer (mpeg2dec, data, (uint8_t *)data+len);
177 } 176 }
178 177
179 while(1){ 178 while(1){
183 unsigned long pw, ph; 182 unsigned long pw, ph;
184 int imgfmt; 183 int imgfmt;
185 184
186 switch(state){ 185 switch(state){
187 case STATE_BUFFER: 186 case STATE_BUFFER:
188 if (mpeg2dec->pending_length) { 187 if (context->pending_length) {
189 // just finished the pending data, continue with processing of the passed buffer 188 // just finished the pending data, continue with processing of the passed buffer
190 mpeg2dec->pending_length = 0; 189 context->pending_length = 0;
191 mpeg2_buffer (mpeg2dec, data, (uint8_t *)data+len); 190 mpeg2_buffer (mpeg2dec, data, (uint8_t *)data+len);
192 } else { 191 } else {
193 // parsing of the passed buffer finished, return. 192 // parsing of the passed buffer finished, return.
194 return 0; 193 return 0;
195 } 194 }
286 case STATE_END: 285 case STATE_END:
287 case STATE_INVALID_END: 286 case STATE_INVALID_END:
288 // decoding done: 287 // decoding done:
289 if(info->display_fbuf) { 288 if(info->display_fbuf) {
290 mp_image_t* mpi = info->display_fbuf->id; 289 mp_image_t* mpi = info->display_fbuf->id;
291 if (mpeg2dec->pending_length == 0) { 290 if (context->pending_length == 0) {
292 mpeg2dec->pending_length = mpeg2dec->buf_end - mpeg2dec->buf_start; 291 context->pending_length = mpeg2dec->buf_end - mpeg2dec->buf_start;
293 mpeg2dec->pending_buffer = realloc(mpeg2dec->pending_buffer, mpeg2dec->pending_length); 292 context->pending_buffer = realloc(context->pending_buffer, context->pending_length);
294 memcpy(mpeg2dec->pending_buffer, mpeg2dec->buf_start, mpeg2dec->pending_length); 293 memcpy(context->pending_buffer, mpeg2dec->buf_start, context->pending_length);
295 } else { 294 } else {
296 // still some data in the pending buffer, shouldn't happen 295 // still some data in the pending buffer, shouldn't happen
297 mpeg2dec->pending_length = mpeg2dec->buf_end - mpeg2dec->buf_start; 296 context->pending_length = mpeg2dec->buf_end - mpeg2dec->buf_start;
298 memmove(mpeg2dec->pending_buffer, mpeg2dec->buf_start, mpeg2dec->pending_length); 297 memmove(context->pending_buffer, mpeg2dec->buf_start, context->pending_length);
299 mpeg2dec->pending_buffer = realloc(mpeg2dec->pending_buffer, mpeg2dec->pending_length + len); 298 context->pending_buffer = realloc(context->pending_buffer, context->pending_length + len);
300 memcpy(mpeg2dec->pending_buffer+mpeg2dec->pending_length, data, len); 299 memcpy(context->pending_buffer+context->pending_length, data, len);
301 mpeg2dec->pending_length += len; 300 context->pending_length += len;
302 } 301 }
303 return mpi; 302 return mpi;
304 } 303 }
305 } 304 }
306 } 305 }