handle buffering and image synchronisation */
| 2221 | |
| 2222 | /* handle buffering and image synchronisation */ |
| 2223 | static int mpeg_decode_frame(AVCodecContext *avctx, |
| 2224 | void *data, int *data_size, |
| 2225 | AVPacket *avpkt) |
| 2226 | { |
| 2227 | const uint8_t *buf = avpkt->data; |
| 2228 | int buf_size = avpkt->size; |
| 2229 | Mpeg1Context *s = avctx->priv_data; |
| 2230 | AVFrame *picture = data; |
| 2231 | MpegEncContext *s2 = &s->mpeg_enc_ctx; |
| 2232 | dprintf(avctx, "fill_buffer\n"); |
| 2233 | |
| 2234 | if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) { |
| 2235 | /* special case for last picture */ |
| 2236 | if (s2->low_delay==0 && s2->next_picture_ptr) { |
| 2237 | *picture= *(AVFrame*)s2->next_picture_ptr; |
| 2238 | s2->next_picture_ptr= NULL; |
| 2239 | |
| 2240 | *data_size = sizeof(AVFrame); |
| 2241 | } |
| 2242 | return buf_size; |
| 2243 | } |
| 2244 | |
| 2245 | if(s2->flags&CODEC_FLAG_TRUNCATED){ |
| 2246 | int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL); |
| 2247 | |
| 2248 | if( ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) |
| 2249 | return buf_size; |
| 2250 | } |
| 2251 | |
| 2252 | #if 0 |
| 2253 | if (s->repeat_field % 2 == 1) { |
| 2254 | s->repeat_field++; |
| 2255 | //fprintf(stderr,"\nRepeating last frame: %d -> %d! pict: %d %d", avctx->frame_number-1, avctx->frame_number, |
| 2256 | // s2->picture_number, s->repeat_field); |
| 2257 | if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) { |
| 2258 | *data_size = sizeof(AVPicture); |
| 2259 | goto the_end; |
| 2260 | } |
| 2261 | } |
| 2262 | #endif |
| 2263 | |
| 2264 | if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == AV_RL32("VCR2")) |
| 2265 | vcr2_init_sequence(avctx); |
| 2266 | |
| 2267 | s->slice_count= 0; |
| 2268 | |
| 2269 | if(avctx->extradata && !avctx->frame_number) |
| 2270 | decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size); |
| 2271 | |
| 2272 | return decode_chunks(avctx, picture, data_size, buf, buf_size); |
| 2273 | } |
| 2274 | |
| 2275 | static int decode_chunks(AVCodecContext *avctx, |
| 2276 | AVFrame *picture, int *data_size, |
nothing calls this directly
no test coverage detected