~ubuntu-branches/ubuntu/trusty/libav/trusty-proposed

« back to all changes in this revision

Viewing changes to libavcodec/mpeg12.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2013-10-22 23:24:08 UTC
  • mfrom: (1.3.36 sid)
  • Revision ID: package-import@ubuntu.com-20131022232408-b8tvvn4pyzri9mi3
Tags: 6:9.10-1ubuntu1
* Build all -extra flavors from this source package, as libav got demoted
  from main to universe, cf LP: #1243235
* Simplify debian/rules to follow exactly the code that debian executes
* New upstream (LP: #1180288) fixes lots of security issues (LP: #1242802)
* Merge from unstable, remaining changes:
  - build-depend on libtiff5-dev rather than libtiff4-dev,
    avoids FTBFS caused by imlib
  - follow the regular debian codepaths

Show diffs side-by-side

added added

removed removed

Lines of Context:
837
837
            }
838
838
        }
839
839
 
840
 
        if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
 
840
        if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
841
841
            if (s->flags2 & CODEC_FLAG2_FAST) {
842
842
                for (i = 0; i < 6; i++) {
843
843
                    mpeg2_fast_decode_block_intra(s, *s->pblocks[i], i);
1050
1050
                }
1051
1051
            }
1052
1052
 
1053
 
            if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
 
1053
            if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
1054
1054
                if (s->flags2 & CODEC_FLAG2_FAST) {
1055
1055
                    for (i = 0; i < 6; i++) {
1056
1056
                        if (cbp & 32) {
1117
1117
    for (i = 0; i < 64; i++)
1118
1118
       s2->dsp.idct_permutation[i]=i;
1119
1119
 
1120
 
    MPV_decode_defaults(s2);
 
1120
    ff_MPV_decode_defaults(s2);
1121
1121
 
1122
1122
    s->mpeg_enc_ctx.avctx  = avctx;
1123
1123
    s->mpeg_enc_ctx.flags  = avctx->flags;
1130
1130
    s->repeat_field                = 0;
1131
1131
    s->mpeg_enc_ctx.codec_id       = avctx->codec->id;
1132
1132
    avctx->color_range = AVCOL_RANGE_MPEG;
1133
 
    if (avctx->codec->id == CODEC_ID_MPEG1VIDEO)
 
1133
    if (avctx->codec->id == AV_CODEC_ID_MPEG1VIDEO)
1134
1134
        avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
1135
1135
    else
1136
1136
        avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
1171
1171
    }
1172
1172
}
1173
1173
 
1174
 
static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = {
1175
 
    PIX_FMT_XVMC_MPEG2_IDCT,
1176
 
    PIX_FMT_XVMC_MPEG2_MC,
1177
 
    PIX_FMT_NONE };
 
1174
static const enum AVPixelFormat pixfmt_xvmc_mpg2_420[] = {
 
1175
    AV_PIX_FMT_XVMC_MPEG2_IDCT,
 
1176
    AV_PIX_FMT_XVMC_MPEG2_MC,
 
1177
    AV_PIX_FMT_NONE };
1178
1178
 
1179
 
static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
 
1179
static enum AVPixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
1180
1180
{
1181
1181
    Mpeg1Context *s1 = avctx->priv_data;
1182
1182
    MpegEncContext *s = &s1->mpeg_enc_ctx;
1184
1184
    if (avctx->xvmc_acceleration)
1185
1185
        return avctx->get_format(avctx, pixfmt_xvmc_mpg2_420);
1186
1186
    else if (avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {
1187
 
        if (avctx->codec_id == CODEC_ID_MPEG1VIDEO)
1188
 
            return PIX_FMT_VDPAU_MPEG1;
 
1187
        if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO)
 
1188
            return AV_PIX_FMT_VDPAU_MPEG1;
1189
1189
        else
1190
 
            return PIX_FMT_VDPAU_MPEG2;
 
1190
            return AV_PIX_FMT_VDPAU_MPEG2;
1191
1191
    } else {
1192
1192
        if (s->chroma_format <  2)
1193
1193
            return avctx->get_format(avctx, ff_hwaccel_pixfmt_list_420);
1194
1194
        else if (s->chroma_format == 2)
1195
 
            return PIX_FMT_YUV422P;
 
1195
            return AV_PIX_FMT_YUV422P;
1196
1196
        else
1197
 
            return PIX_FMT_YUV444P;
 
1197
            return AV_PIX_FMT_YUV444P;
1198
1198
    }
1199
1199
}
1200
1200
 
1219
1219
        if (s1->mpeg_enc_ctx_allocated) {
1220
1220
            ParseContext pc = s->parse_context;
1221
1221
            s->parse_context.buffer = 0;
1222
 
            MPV_common_end(s);
 
1222
            ff_MPV_common_end(s);
1223
1223
            s->parse_context = pc;
1224
1224
        }
1225
1225
 
1237
1237
         * that behave like P-frames. */
1238
1238
        avctx->has_b_frames = !s->low_delay;
1239
1239
 
1240
 
        assert((avctx->sub_id == 1) == (avctx->codec_id == CODEC_ID_MPEG1VIDEO));
1241
 
        if (avctx->codec_id == CODEC_ID_MPEG1VIDEO) {
 
1240
        if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
1242
1241
            //MPEG-1 fps
1243
 
            avctx->time_base.den = avpriv_frame_rate_tab[s->frame_rate_index].num;
1244
 
            avctx->time_base.num = avpriv_frame_rate_tab[s->frame_rate_index].den;
 
1242
            avctx->time_base.den = ff_mpeg12_frame_rate_tab[s->frame_rate_index].num;
 
1243
            avctx->time_base.num = ff_mpeg12_frame_rate_tab[s->frame_rate_index].den;
1245
1244
            //MPEG-1 aspect
1246
1245
            avctx->sample_aspect_ratio = av_d2q(1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255);
1247
1246
            avctx->ticks_per_frame=1;
1249
1248
        //MPEG-2 fps
1250
1249
            av_reduce(&s->avctx->time_base.den,
1251
1250
                      &s->avctx->time_base.num,
1252
 
                      avpriv_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2,
1253
 
                      avpriv_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
 
1251
                      ff_mpeg12_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2,
 
1252
                      ff_mpeg12_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
1254
1253
                      1 << 30);
1255
1254
            avctx->ticks_per_frame = 2;
1256
1255
            //MPEG-2 aspect
1276
1275
//res_change_ffmpeg_aspect.ts 4/3 225/44 ->4/3
1277
1276
//widescreen-issue562.mpg 4/3 16/9 -> 16/9
1278
1277
//                    s->avctx->sample_aspect_ratio = av_mul_q(s->avctx->sample_aspect_ratio, (AVRational) {s->width, s->height});
1279
 
//av_log(NULL, AV_LOG_ERROR, "A %d/%d\n", ff_mpeg2_aspect[s->aspect_ratio_info].num, ff_mpeg2_aspect[s->aspect_ratio_info].den);
1280
 
//av_log(NULL, AV_LOG_ERROR, "B %d/%d\n", s->avctx->sample_aspect_ratio.num, s->avctx->sample_aspect_ratio.den);
 
1278
                    av_dlog(avctx, "A %d/%d\n",
 
1279
                            ff_mpeg2_aspect[s->aspect_ratio_info].num, ff_mpeg2_aspect[s->aspect_ratio_info].den);
 
1280
                    av_dlog(avctx, "B %d/%d\n", s->avctx->sample_aspect_ratio.num,
 
1281
                            s->avctx->sample_aspect_ratio.den);
1281
1282
                }
1282
1283
            } else {
1283
1284
                s->avctx->sample_aspect_ratio =
1288
1289
        avctx->pix_fmt = mpeg_get_pixelformat(avctx);
1289
1290
        avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
1290
1291
        // until then pix_fmt may be changed right after codec init
1291
 
        if (avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
 
1292
        if (avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT ||
1292
1293
            avctx->hwaccel                            ||
1293
1294
            s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
1294
1295
            if (avctx->idct_algo == FF_IDCT_AUTO)
1298
1299
         * if DCT permutation is changed. */
1299
1300
        memcpy(old_permutation, s->dsp.idct_permutation, 64 * sizeof(uint8_t));
1300
1301
 
1301
 
        if (MPV_common_init(s) < 0)
 
1302
        if (ff_MPV_common_init(s) < 0)
1302
1303
            return -2;
1303
1304
 
1304
1305
        quant_matrix_rebuild(s->intra_matrix,        old_permutation, s->dsp.idct_permutation);
1381
1382
    s1->frame_rate_ext.den = get_bits(&s->gb, 5) + 1;
1382
1383
 
1383
1384
    av_dlog(s->avctx, "sequence extension\n");
1384
 
    s->codec_id      = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO;
1385
 
    s->avctx->sub_id = 2; /* indicates MPEG-2 found */
 
1385
    s->codec_id      = s->avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
1386
1386
 
1387
1387
    if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1388
1388
        av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n",
1523
1523
    }
1524
1524
 
1525
1525
    if (s->progressive_sequence && !s->frame_pred_frame_dct) {
1526
 
        av_log(s->avctx, AV_LOG_ERROR, "invalid frame_pred_frame_dct\n");
1527
 
        s->frame_pred_frame_dct = 1;
 
1526
        av_log(s->avctx, AV_LOG_WARNING, "invalid frame_pred_frame_dct\n");
1528
1527
    }
1529
1528
 
1530
1529
    if (s->picture_structure == PICT_FRAME) {
1563
1562
 
1564
1563
    /* start frame decoding */
1565
1564
    if (s->first_field || s->picture_structure == PICT_FRAME) {
1566
 
        if (MPV_frame_start(s, avctx) < 0)
 
1565
        if (ff_MPV_frame_start(s, avctx) < 0)
1567
1566
            return -1;
1568
1567
 
1569
1568
        ff_er_frame_start(s);
1593
1592
            return -1;
1594
1593
        }
1595
1594
 
 
1595
        if (s->avctx->hwaccel &&
 
1596
            (s->avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD)) {
 
1597
            if (s->avctx->hwaccel->end_frame(s->avctx) < 0)
 
1598
                av_log(avctx, AV_LOG_ERROR, "hardware accelerator failed to decode first field\n");
 
1599
        }
 
1600
 
1596
1601
        for (i = 0; i < 4; i++) {
1597
1602
            s->current_picture.f.data[i] = s->current_picture_ptr->f.data[i];
1598
1603
            if (s->picture_structure == PICT_BOTTOM_FIELD) {
1628
1633
                             const uint8_t **buf, int buf_size)
1629
1634
{
1630
1635
    AVCodecContext *avctx = s->avctx;
1631
 
    const int lowres      = s->avctx->lowres;
1632
1636
    const int field_pic   = s->picture_structure != PICT_FRAME;
1633
1637
 
1634
1638
    s->resync_mb_x =
1749
1753
            }
1750
1754
        }
1751
1755
 
1752
 
        s->dest[0] += 16 >> lowres;
1753
 
        s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift;
1754
 
        s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
 
1756
        s->dest[0] += 16;
 
1757
        s->dest[1] += 16 >> s->chroma_x_shift;
 
1758
        s->dest[2] += 16 >> s->chroma_x_shift;
1755
1759
 
1756
 
        MPV_decode_mb(s, s->block);
 
1760
        ff_MPV_decode_mb(s, s->block);
1757
1761
 
1758
1762
        if (++s->mb_x >= s->mb_width) {
1759
 
            const int mb_size = 16 >> s->avctx->lowres;
 
1763
            const int mb_size = 16;
1760
1764
 
1761
1765
            ff_draw_horiz_band(s, mb_size*(s->mb_y >> field_pic), mb_size);
1762
 
            MPV_report_decode_progress(s);
 
1766
            ff_MPV_report_decode_progress(s);
1763
1767
 
1764
1768
            s->mb_x = 0;
1765
1769
            s->mb_y += 1 << field_pic;
1841
1845
    }
1842
1846
eos: // end of slice
1843
1847
    *buf += (get_bits_count(&s->gb)-1)/8;
1844
 
//printf("y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y);
 
1848
    av_dlog(s, "y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y);
1845
1849
    return 0;
1846
1850
}
1847
1851
 
1860
1864
 
1861
1865
        ret = mpeg_decode_slice(s, mb_y, &buf, s->gb.buffer_end - buf);
1862
1866
        emms_c();
1863
 
//av_log(c, AV_LOG_DEBUG, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
1864
 
//ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, s->start_mb_y, s->end_mb_y, s->error_count);
 
1867
        av_dlog(c, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
 
1868
                ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y,
 
1869
                s->start_mb_y, s->end_mb_y, s->error_count);
1865
1870
        if (ret < 0) {
1866
1871
            if (c->err_recognition & AV_EF_EXPLODE)
1867
1872
                return ret;
1912
1917
 
1913
1918
        ff_er_frame_end(s);
1914
1919
 
1915
 
        MPV_frame_end(s);
 
1920
        ff_MPV_frame_end(s);
1916
1921
 
1917
1922
        if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
1918
 
            *pict = *(AVFrame*)s->current_picture_ptr;
 
1923
            *pict = s->current_picture_ptr->f;
1919
1924
            ff_print_debug_info(s, pict);
1920
1925
        } else {
1921
1926
            if (avctx->active_thread_type & FF_THREAD_FRAME)
1923
1928
            /* latency of 1 frame for I- and P-frames */
1924
1929
            /* XXX: use another variable than picture_number */
1925
1930
            if (s->last_picture_ptr != NULL) {
1926
 
                *pict = *(AVFrame*)s->last_picture_ptr;
 
1931
                *pict = s->last_picture_ptr->f;
1927
1932
                 ff_print_debug_info(s, pict);
1928
1933
            }
1929
1934
        }
1999
2004
    s->picture_structure    = PICT_FRAME;
2000
2005
    s->frame_pred_frame_dct = 1;
2001
2006
    s->chroma_format        = 1;
2002
 
    s->codec_id             = s->avctx->codec_id = CODEC_ID_MPEG1VIDEO;
2003
 
    avctx->sub_id           = 1; /* indicates MPEG-1 */
 
2007
    s->codec_id             = s->avctx->codec_id = AV_CODEC_ID_MPEG1VIDEO;
2004
2008
    s->out_format           = FMT_MPEG1;
2005
2009
    s->swap_uv              = 0; // AFAIK VCR2 does not have SEQ_HEADER
2006
2010
    if (s->flags & CODEC_FLAG_LOW_DELAY)
2022
2026
    /* start new MPEG-1 context decoding */
2023
2027
    s->out_format = FMT_MPEG1;
2024
2028
    if (s1->mpeg_enc_ctx_allocated) {
2025
 
        MPV_common_end(s);
 
2029
        ff_MPV_common_end(s);
2026
2030
    }
2027
2031
    s->width  = avctx->coded_width;
2028
2032
    s->height = avctx->coded_height;
2032
2036
    avctx->pix_fmt = mpeg_get_pixelformat(avctx);
2033
2037
    avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
2034
2038
 
2035
 
    if (avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ||
 
2039
    if (avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ||
2036
2040
        s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
2037
2041
        if (avctx->idct_algo == FF_IDCT_AUTO)
2038
2042
            avctx->idct_algo = FF_IDCT_SIMPLE;
2039
2043
 
2040
 
    if (MPV_common_init(s) < 0)
 
2044
    if (ff_MPV_common_init(s) < 0)
2041
2045
        return -1;
2042
2046
    exchange_uv(s); // common init reset pblocks, so we swap them here
2043
2047
    s->swap_uv = 1; // in case of xvmc we need to swap uv for each MB
2059
2063
    s->picture_structure     = PICT_FRAME;
2060
2064
    s->frame_pred_frame_dct  = 1;
2061
2065
    s->chroma_format         = 1;
2062
 
    s->codec_id              = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO;
2063
 
    avctx->sub_id            = 2; /* indicates MPEG-2 */
 
2066
    s->codec_id              = s->avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
2064
2067
    s1->save_width           = s->width;
2065
2068
    s1->save_height          = s->height;
2066
2069
    s1->save_progressive_seq = s->progressive_sequence;
2161
2164
                pc->frame_start_found = 4;
2162
2165
            }
2163
2166
            if (state == SEQ_END_CODE) {
 
2167
                pc->frame_start_found = 0;
2164
2168
                pc->state=-1;
2165
2169
                return i+1;
2166
2170
            }
2185
2189
}
2186
2190
 
2187
2191
static int decode_chunks(AVCodecContext *avctx,
2188
 
                         AVFrame *picture, int *data_size,
2189
 
                         const uint8_t *buf, int buf_size);
2190
 
 
2191
 
/* handle buffering and image synchronisation */
2192
 
static int mpeg_decode_frame(AVCodecContext *avctx,
2193
 
                             void *data, int *data_size,
2194
 
                             AVPacket *avpkt)
2195
 
{
2196
 
    const uint8_t *buf = avpkt->data;
2197
 
    int buf_size = avpkt->size;
2198
 
    Mpeg1Context *s = avctx->priv_data;
2199
 
    AVFrame *picture = data;
2200
 
    MpegEncContext *s2 = &s->mpeg_enc_ctx;
2201
 
    av_dlog(avctx, "fill_buffer\n");
2202
 
 
2203
 
    if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
2204
 
        /* special case for last picture */
2205
 
        if (s2->low_delay == 0 && s2->next_picture_ptr) {
2206
 
            *picture = *(AVFrame*)s2->next_picture_ptr;
2207
 
            s2->next_picture_ptr = NULL;
2208
 
 
2209
 
            *data_size = sizeof(AVFrame);
2210
 
        }
2211
 
        return buf_size;
2212
 
    }
2213
 
 
2214
 
    if (s2->flags & CODEC_FLAG_TRUNCATED) {
2215
 
        int next = ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL);
2216
 
 
2217
 
        if (ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0)
2218
 
            return buf_size;
2219
 
    }
2220
 
 
2221
 
    if (s->mpeg_enc_ctx_allocated == 0 && avctx->codec_tag == AV_RL32("VCR2"))
2222
 
        vcr2_init_sequence(avctx);
2223
 
 
2224
 
    s->slice_count = 0;
2225
 
 
2226
 
    if (avctx->extradata && !s->extradata_decoded) {
2227
 
        int ret = decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size);
2228
 
        s->extradata_decoded = 1;
2229
 
        if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
2230
 
            return ret;
2231
 
    }
2232
 
 
2233
 
    return decode_chunks(avctx, picture, data_size, buf, buf_size);
2234
 
}
2235
 
 
2236
 
static int decode_chunks(AVCodecContext *avctx,
2237
 
                         AVFrame *picture, int *data_size,
 
2192
                         AVFrame *picture, int *got_output,
2238
2193
                         const uint8_t *buf, int buf_size)
2239
2194
{
2240
2195
    Mpeg1Context *s = avctx->priv_data;
2263
2218
 
2264
2219
                if (slice_end(avctx, picture)) {
2265
2220
                    if (s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice
2266
 
                        *data_size = sizeof(AVPicture);
 
2221
                        *got_output = 1;
2267
2222
                }
2268
2223
            }
2269
2224
            s2->pict_type = 0;
2401
2356
                if (!s->mpeg_enc_ctx_allocated)
2402
2357
                    break;
2403
2358
 
2404
 
                if (s2->codec_id == CODEC_ID_MPEG2VIDEO) {
 
2359
                if (s2->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
2405
2360
                    if (mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom)
2406
2361
                        break;
2407
2362
                }
2439
2394
                        thread_context->end_mb_y   = s2->mb_height;
2440
2395
                        if (s->slice_count) {
2441
2396
                            s2->thread_context[s->slice_count-1]->end_mb_y = mb_y;
2442
 
                            ff_update_duplicate_context(thread_context, s2);
 
2397
                            ret = ff_update_duplicate_context(thread_context,
 
2398
                                                              s2);
 
2399
                            if (ret < 0)
 
2400
                                return ret;
2443
2401
                        }
2444
2402
                        init_get_bits(&thread_context->gb, buf_ptr, input_size*8);
2445
2403
                        s->slice_count++;
2464
2422
    }
2465
2423
}
2466
2424
 
 
2425
static int mpeg_decode_frame(AVCodecContext *avctx,
 
2426
                             void *data, int *got_output,
 
2427
                             AVPacket *avpkt)
 
2428
{
 
2429
    const uint8_t *buf = avpkt->data;
 
2430
    int buf_size = avpkt->size;
 
2431
    Mpeg1Context *s = avctx->priv_data;
 
2432
    AVFrame *picture = data;
 
2433
    MpegEncContext *s2 = &s->mpeg_enc_ctx;
 
2434
    av_dlog(avctx, "fill_buffer\n");
 
2435
 
 
2436
    if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
 
2437
        /* special case for last picture */
 
2438
        if (s2->low_delay == 0 && s2->next_picture_ptr) {
 
2439
            *picture = s2->next_picture_ptr->f;
 
2440
            s2->next_picture_ptr = NULL;
 
2441
 
 
2442
            *got_output = 1;
 
2443
        }
 
2444
        return buf_size;
 
2445
    }
 
2446
 
 
2447
    if (s2->flags & CODEC_FLAG_TRUNCATED) {
 
2448
        int next = ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL);
 
2449
 
 
2450
        if (ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0)
 
2451
            return buf_size;
 
2452
    }
 
2453
 
 
2454
    if (s->mpeg_enc_ctx_allocated == 0 && avctx->codec_tag == AV_RL32("VCR2"))
 
2455
        vcr2_init_sequence(avctx);
 
2456
 
 
2457
    s->slice_count = 0;
 
2458
 
 
2459
    if (avctx->extradata && !s->extradata_decoded) {
 
2460
        int ret = decode_chunks(avctx, picture, got_output, avctx->extradata, avctx->extradata_size);
 
2461
        s->extradata_decoded = 1;
 
2462
        if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
 
2463
            return ret;
 
2464
    }
 
2465
 
 
2466
    return decode_chunks(avctx, picture, got_output, buf, buf_size);
 
2467
}
 
2468
 
 
2469
 
2467
2470
static void flush(AVCodecContext *avctx)
2468
2471
{
2469
2472
    Mpeg1Context *s = avctx->priv_data;
2479
2482
    Mpeg1Context *s = avctx->priv_data;
2480
2483
 
2481
2484
    if (s->mpeg_enc_ctx_allocated)
2482
 
        MPV_common_end(&s->mpeg_enc_ctx);
 
2485
        ff_MPV_common_end(&s->mpeg_enc_ctx);
2483
2486
    return 0;
2484
2487
}
2485
2488
 
2497
2500
 
2498
2501
 
2499
2502
AVCodec ff_mpeg1video_decoder = {
2500
 
    .name           = "mpeg1video",
2501
 
    .type           = AVMEDIA_TYPE_VIDEO,
2502
 
    .id             = CODEC_ID_MPEG1VIDEO,
2503
 
    .priv_data_size = sizeof(Mpeg1Context),
2504
 
    .init           = mpeg_decode_init,
2505
 
    .close          = mpeg_decode_end,
2506
 
    .decode         = mpeg_decode_frame,
2507
 
    .capabilities   = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
2508
 
    .flush          = flush,
2509
 
    .max_lowres     = 3,
2510
 
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
 
2503
    .name                  = "mpeg1video",
 
2504
    .type                  = AVMEDIA_TYPE_VIDEO,
 
2505
    .id                    = AV_CODEC_ID_MPEG1VIDEO,
 
2506
    .priv_data_size        = sizeof(Mpeg1Context),
 
2507
    .init                  = mpeg_decode_init,
 
2508
    .close                 = mpeg_decode_end,
 
2509
    .decode                = mpeg_decode_frame,
 
2510
    .capabilities          = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 |
 
2511
                             CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY |
 
2512
                             CODEC_CAP_SLICE_THREADS,
 
2513
    .flush                 = flush,
 
2514
    .long_name             = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
2511
2515
    .update_thread_context = ONLY_IF_THREADS_ENABLED(mpeg_decode_update_thread_context)
2512
2516
};
2513
2517
 
2514
2518
AVCodec ff_mpeg2video_decoder = {
2515
2519
    .name           = "mpeg2video",
2516
2520
    .type           = AVMEDIA_TYPE_VIDEO,
2517
 
    .id             = CODEC_ID_MPEG2VIDEO,
 
2521
    .id             = AV_CODEC_ID_MPEG2VIDEO,
2518
2522
    .priv_data_size = sizeof(Mpeg1Context),
2519
2523
    .init           = mpeg_decode_init,
2520
2524
    .close          = mpeg_decode_end,
2521
2525
    .decode         = mpeg_decode_frame,
2522
 
    .capabilities   = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
 
2526
    .capabilities   = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 |
 
2527
                      CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY |
 
2528
                      CODEC_CAP_SLICE_THREADS,
2523
2529
    .flush          = flush,
2524
 
    .max_lowres     = 3,
2525
2530
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 video"),
2526
2531
    .profiles       = NULL_IF_CONFIG_SMALL(mpeg2_video_profiles),
2527
2532
};
2538
2543
    }
2539
2544
    mpeg_decode_init(avctx);
2540
2545
 
2541
 
    avctx->pix_fmt           = PIX_FMT_XVMC_MPEG2_IDCT;
 
2546
    avctx->pix_fmt           = AV_PIX_FMT_XVMC_MPEG2_IDCT;
2542
2547
    avctx->xvmc_acceleration = 2; // 2 - the blocks are packed!
2543
2548
 
2544
2549
    return 0;
2547
2552
AVCodec ff_mpeg_xvmc_decoder = {
2548
2553
    .name           = "mpegvideo_xvmc",
2549
2554
    .type           = AVMEDIA_TYPE_VIDEO,
2550
 
    .id             = CODEC_ID_MPEG2VIDEO_XVMC,
 
2555
    .id             = AV_CODEC_ID_MPEG2VIDEO_XVMC,
2551
2556
    .priv_data_size = sizeof(Mpeg1Context),
2552
2557
    .init           = mpeg_mc_decode_init,
2553
2558
    .close          = mpeg_decode_end,
2554
2559
    .decode         = mpeg_decode_frame,
2555
 
    .capabilities   = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
 
2560
    .capabilities   = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 |
 
2561
                      CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
2556
2562
    .flush          = flush,
2557
2563
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"),
2558
2564
};
2563
2569
AVCodec ff_mpeg_vdpau_decoder = {
2564
2570
    .name           = "mpegvideo_vdpau",
2565
2571
    .type           = AVMEDIA_TYPE_VIDEO,
2566
 
    .id             = CODEC_ID_MPEG2VIDEO,
 
2572
    .id             = AV_CODEC_ID_MPEG2VIDEO,
2567
2573
    .priv_data_size = sizeof(Mpeg1Context),
2568
2574
    .init           = mpeg_decode_init,
2569
2575
    .close          = mpeg_decode_end,
2570
2576
    .decode         = mpeg_decode_frame,
2571
 
    .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
 
2577
    .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED |
 
2578
                      CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
2572
2579
    .flush          = flush,
2573
2580
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"),
2574
2581
};
2578
2585
AVCodec ff_mpeg1_vdpau_decoder = {
2579
2586
    .name           = "mpeg1video_vdpau",
2580
2587
    .type           = AVMEDIA_TYPE_VIDEO,
2581
 
    .id             = CODEC_ID_MPEG1VIDEO,
 
2588
    .id             = AV_CODEC_ID_MPEG1VIDEO,
2582
2589
    .priv_data_size = sizeof(Mpeg1Context),
2583
2590
    .init           = mpeg_decode_init,
2584
2591
    .close          = mpeg_decode_end,
2585
2592
    .decode         = mpeg_decode_frame,
2586
 
    .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
 
2593
    .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED |
 
2594
                      CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
2587
2595
    .flush          = flush,
2588
2596
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"),
2589
2597
};
2590
2598
#endif
2591