MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / decode_chunks

Function decode_chunks

libavcodec/mpeg12dec.c:2238–2554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2236}
2237
2238static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
2239 int *got_output, const uint8_t *buf, int buf_size)
2240{
2241 Mpeg1Context *s = avctx->priv_data;
2242 MPVContext *const s2 = &s->slice.c;
2243 const uint8_t *buf_ptr = buf;
2244 const uint8_t *buf_end = buf + buf_size;
2245 int ret, input_size;
2246 int last_code = 0, skip_frame = 0;
2247 int picture_start_code_seen = 0;
2248
2249 for (;;) {
2250 /* find next start code */
2251 uint32_t start_code = -1;
2252 buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &start_code);
2253 if (start_code > 0x1ff) {
2254 if (!skip_frame) {
2255 mpeg12_execute_slice_threads(avctx, s);
2256
2257 ret = slice_end(avctx, picture, got_output);
2258 if (ret < 0)
2259 return ret;
2260 }
2261 s2->pict_type = 0;
2262
2263 if (avctx->err_recognition & AV_EF_EXPLODE && s2->er.error_count)
2264 return AVERROR_INVALIDDATA;
2265
2266 return FFMAX(0, buf_ptr - buf);
2267 }
2268
2269 input_size = buf_end - buf_ptr;
2270
2271 if (avctx->debug & FF_DEBUG_STARTCODE)
2272 av_log(avctx, AV_LOG_DEBUG, "%3"PRIX32" at %td left %d\n",
2273 start_code, buf_ptr - buf, input_size);
2274
2275 /* prepare data for next start code */
2276 switch (start_code) {
2277 case SEQ_START_CODE:
2278 if (last_code == 0) {
2279 mpeg1_decode_sequence(avctx, buf_ptr, input_size);
2280 if (buf != avctx->extradata)
2281 s->sync = 1;
2282 } else {
2283 av_log(avctx, AV_LOG_ERROR,
2284 "ignoring SEQ_START_CODE after %X\n", last_code);
2285 if (avctx->err_recognition & AV_EF_EXPLODE)
2286 return AVERROR_INVALIDDATA;
2287 }
2288 break;
2289
2290 case PICTURE_START_CODE:
2291 if (picture_start_code_seen && s2->picture_structure == PICT_FRAME) {
2292 /* If it's a frame picture, there can't be more than one picture header.
2293 Yet, it does happen and we need to handle it. */
2294 av_log(avctx, AV_LOG_WARNING, "ignoring extra picture following a frame-picture\n");
2295 break;

Callers 1

mpeg_decode_frameFunction · 0.85

Calls 15

avpriv_find_start_codeFunction · 0.85
slice_endFunction · 0.85
av_logFunction · 0.85
mpeg1_decode_sequenceFunction · 0.85
mpeg_decode_postinitFunction · 0.85
mpeg1_decode_pictureFunction · 0.85
init_get_bits8Function · 0.85

Tested by

no test coverage detected