comparison libschroedingerdec.c @ 7234:dea986389c57 libavcodec

Parse frames to feed the decoder with individual parse units. Patch by Anuradha Suraparaju anuradha rd bbc co uk Original thread: [PATCH] Patches to fix issue453 individuallibdiracschroedinger Date: 05/22/2008 04:26 AM
author benoit
date Thu, 10 Jul 2008 11:44:01 +0000
parents e943e1409077
children e623323d409f
comparison
equal deleted inserted replaced
7233:238a3511f183 7234:dea986389c57
62 62
63 /** decoded picture */ 63 /** decoded picture */
64 AVPicture dec_pic; 64 AVPicture dec_pic;
65 } FfmpegSchroDecoderParams; 65 } FfmpegSchroDecoderParams;
66 66
67 typedef struct FfmpegSchroParseUnitContext
68 {
69 const uint8_t *buf;
70 int buf_size;
71 } FfmpegSchroParseUnitContext;
72
73
74 static void libschroedinger_decode_buffer_free (SchroBuffer *schro_buf,
75 void *priv);
76
77 static void FfmpegSchroParseContextInit (FfmpegSchroParseUnitContext *parse_ctx,
78 const uint8_t *buf, int buf_size)
79 {
80 parse_ctx->buf = buf;
81 parse_ctx->buf_size = buf_size;
82 }
83
84 static SchroBuffer* FfmpegFindNextSchroParseUnit (FfmpegSchroParseUnitContext *parse_ctx)
85 {
86 SchroBuffer *enc_buf = NULL;
87 int next_pu_offset = 0;
88 unsigned char *in_buf;
89
90 if (parse_ctx->buf_size < 13 ||
91 parse_ctx->buf[0] != 'B' ||
92 parse_ctx->buf[1] != 'B' ||
93 parse_ctx->buf[2] != 'C' ||
94 parse_ctx->buf[3] != 'D')
95 return NULL;
96
97 next_pu_offset = (parse_ctx->buf[5] << 24) +
98 (parse_ctx->buf[6] << 16) +
99 (parse_ctx->buf[7] << 8) +
100 parse_ctx->buf[8];
101
102 if (next_pu_offset == 0 &&
103 SCHRO_PARSE_CODE_IS_END_OF_SEQUENCE(parse_ctx->buf[4]))
104 next_pu_offset = 13;
105
106 if (next_pu_offset <= 0 || parse_ctx->buf_size < next_pu_offset)
107 return NULL;
108
109 in_buf = av_malloc(next_pu_offset);
110 memcpy (in_buf, parse_ctx->buf, next_pu_offset);
111 enc_buf = schro_buffer_new_with_data (in_buf, next_pu_offset);
112 enc_buf->free = libschroedinger_decode_buffer_free;
113 enc_buf->priv = in_buf;
114
115 parse_ctx->buf += next_pu_offset;
116 parse_ctx->buf_size -= next_pu_offset;
117
118 return enc_buf;
119 }
120
67 /** 121 /**
68 * Returns FFmpeg chroma format. 122 * Returns FFmpeg chroma format.
69 */ 123 */
70 static enum PixelFormat GetFfmpegChromaFormat(SchroChromaFormat schro_pix_fmt) 124 static enum PixelFormat GetFfmpegChromaFormat(SchroChromaFormat schro_pix_fmt)
71 { 125 {
162 AVPicture *picture = data; 216 AVPicture *picture = data;
163 SchroBuffer *enc_buf; 217 SchroBuffer *enc_buf;
164 SchroFrame* frame; 218 SchroFrame* frame;
165 int state; 219 int state;
166 int go = 1; 220 int go = 1;
221 int outer = 1;
222 FfmpegSchroParseUnitContext parse_ctx;
167 223
168 *data_size = 0; 224 *data_size = 0;
169 225
170 if (buf_size>0) { 226 FfmpegSchroParseContextInit (&parse_ctx, buf, buf_size);
171 unsigned char *in_buf = av_malloc(buf_size); 227 if (buf_size == 0) {
172 memcpy (in_buf, buf, buf_size);
173 enc_buf = schro_buffer_new_with_data (in_buf, buf_size);
174 enc_buf->free = libschroedinger_decode_buffer_free;
175 enc_buf->priv = in_buf;
176 /* Push buffer into decoder. */
177 state = schro_decoder_push (decoder, enc_buf);
178 if (state == SCHRO_DECODER_FIRST_ACCESS_UNIT)
179 libschroedinger_handle_first_access_unit(avccontext);
180 } else {
181 if (!p_schro_params->eos_signalled) { 228 if (!p_schro_params->eos_signalled) {
182 state = schro_decoder_push_end_of_stream(decoder); 229 state = schro_decoder_push_end_of_stream(decoder);
183 p_schro_params->eos_signalled = 1; 230 p_schro_params->eos_signalled = 1;
184 } 231 }
185 } 232 }
186 233
234 /* Loop through all the individual parse units in the input buffer */
235 do {
236 if ((enc_buf = FfmpegFindNextSchroParseUnit(&parse_ctx))) {
237 /* Push buffer into decoder. */
238 state = schro_decoder_push (decoder, enc_buf);
239 if (state == SCHRO_DECODER_FIRST_ACCESS_UNIT)
240 libschroedinger_handle_first_access_unit(avccontext);
241 go = 1;
242 }
243 else
244 outer = 0;
187 format = p_schro_params->format; 245 format = p_schro_params->format;
188 246
189 while (go) { 247 while (go) {
190 /* Parse data and process result. */ 248 /* Parse data and process result. */
191 state = schro_decoder_wait (decoder); 249 state = schro_decoder_wait (decoder);
222 break; 280 break;
223 case SCHRO_DECODER_EOS: 281 case SCHRO_DECODER_EOS:
224 go = 0; 282 go = 0;
225 p_schro_params->eos_pulled = 1; 283 p_schro_params->eos_pulled = 1;
226 schro_decoder_reset (decoder); 284 schro_decoder_reset (decoder);
285 outer = 0;
227 break; 286 break;
228 287
229 case SCHRO_DECODER_ERROR: 288 case SCHRO_DECODER_ERROR:
230 return -1; 289 return -1;
231 break; 290 break;
232 } 291 }
233 } 292 }
293 } while(outer);
234 294
235 /* Grab next frame to be returned from the top of the queue. */ 295 /* Grab next frame to be returned from the top of the queue. */
236 frame = ff_dirac_schro_queue_pop(&p_schro_params->dec_frame_queue); 296 frame = ff_dirac_schro_queue_pop(&p_schro_params->dec_frame_queue);
237 297
238 if (frame != NULL) { 298 if (frame != NULL) {