~ubuntu-branches/ubuntu/oneiric/libav/oneiric

« back to all changes in this revision

Viewing changes to libavcodec/mpeg12.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-04-30 14:27:42 UTC
  • mfrom: (1.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110430142742-quvblxk1tj6adlh5
Tags: 4:0.7~b1-1ubuntu1
* Merge from debian. Remaining changes:
  - don't build against libfaad, libdirac, librtmp and libopenjpeg
    (all in universe)
  - explicitly --enable-pic on powerpc, cf. LP #654666
  - different arm configure bits that should probably better be
    merged into debian
* Cherry-picked from git: 
  - install doc/APIChanges and refer to them in NEWS.Debian (Closes: #623682)
  - don't try to install non-existing documentation, fixes FTBFS on powerpc

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * Copyright (c) 2000,2001 Fabrice Bellard
4
4
 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5
5
 *
6
 
 * This file is part of FFmpeg.
 
6
 * This file is part of Libav.
7
7
 *
8
 
 * FFmpeg is free software; you can redistribute it and/or
 
8
 * Libav is free software; you can redistribute it and/or
9
9
 * modify it under the terms of the GNU Lesser General Public
10
10
 * License as published by the Free Software Foundation; either
11
11
 * version 2.1 of the License, or (at your option) any later version.
12
12
 *
13
 
 * FFmpeg is distributed in the hope that it will be useful,
 
13
 * Libav is distributed in the hope that it will be useful,
14
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
16
 * Lesser General Public License for more details.
17
17
 *
18
18
 * You should have received a copy of the GNU Lesser General Public
19
 
 * License along with FFmpeg; if not, write to the Free Software
 
19
 * License along with Libav; if not, write to the Free Software
20
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
21
 */
22
22
 
137
137
/******************************************/
138
138
/* decoding */
139
139
 
 
140
VLC ff_dc_lum_vlc;
 
141
VLC ff_dc_chroma_vlc;
 
142
 
140
143
static VLC mv_vlc;
141
144
static VLC mbincr_vlc;
142
145
static VLC mb_ptype_vlc;
150
153
    if (!done) {
151
154
        done = 1;
152
155
 
153
 
        INIT_VLC_STATIC(&dc_lum_vlc, DC_VLC_BITS, 12,
 
156
        INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12,
154
157
                 ff_mpeg12_vlc_dc_lum_bits, 1, 1,
155
158
                 ff_mpeg12_vlc_dc_lum_code, 2, 2, 512);
156
 
        INIT_VLC_STATIC(&dc_chroma_vlc,  DC_VLC_BITS, 12,
 
159
        INIT_VLC_STATIC(&ff_dc_chroma_vlc,  DC_VLC_BITS, 12,
157
160
                 ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
158
161
                 ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514);
159
162
        INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 17,
210
213
    int i, j, k, cbp, val, mb_type, motion_type;
211
214
    const int mb_block_count = 4 + (1<< s->chroma_format);
212
215
 
213
 
    dprintf(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
 
216
    av_dlog(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
214
217
 
215
218
    assert(s->mb_skipped==0);
216
219
 
269
272
        mb_type = btype2mb_type[ mb_type ];
270
273
        break;
271
274
    }
272
 
    dprintf(s->avctx, "mb_type=%x\n", mb_type);
 
275
    av_dlog(s->avctx, "mb_type=%x\n", mb_type);
273
276
//    motion_type = 0; /* avoid warning */
274
277
    if (IS_INTRA(mb_type)) {
275
278
        s->dsp.clear_blocks(s->block[0]);
367
370
 
368
371
            /* motion vectors */
369
372
            s->mv_dir= (mb_type>>13)&3;
370
 
            dprintf(s->avctx, "motion_type=%d\n", motion_type);
 
373
            av_dlog(s->avctx, "motion_type=%d\n", motion_type);
371
374
            switch(motion_type) {
372
375
            case MT_FRAME: /* or MT_16X8 */
373
376
                if (s->picture_structure == PICT_FRAME) {
418
421
                                                         s->last_mv[i][j][0]);
419
422
                                s->last_mv[i][j][0] = val;
420
423
                                s->mv[i][j][0] = val;
421
 
                                dprintf(s->avctx, "fmx=%d\n", val);
 
424
                                av_dlog(s->avctx, "fmx=%d\n", val);
422
425
                                val = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
423
426
                                                         s->last_mv[i][j][1] >> 1);
424
427
                                s->last_mv[i][j][1] = val << 1;
425
428
                                s->mv[i][j][1] = val;
426
 
                                dprintf(s->avctx, "fmy=%d\n", val);
 
429
                                av_dlog(s->avctx, "fmy=%d\n", val);
427
430
                            }
428
431
                        }
429
432
                    }
629
632
    dc += diff;
630
633
    s->last_dc[component] = dc;
631
634
    block[0] = dc*quant_matrix[0];
632
 
    dprintf(s->avctx, "dc=%d diff=%d\n", dc, diff);
 
635
    av_dlog(s->avctx, "dc=%d diff=%d\n", dc, diff);
633
636
    i = 0;
634
637
    {
635
638
        OPEN_READER(re, &s->gb);
715
718
            if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
716
719
                goto end;
717
720
        }
718
 
#if MIN_CACHE_BITS < 19
719
 
        UPDATE_CACHE(re, &s->gb);
720
 
#endif
721
721
        /* now quantify & encode AC coefficients */
722
722
        for(;;) {
723
723
            GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
757
757
            }
758
758
 
759
759
            block[j] = level;
760
 
#if MIN_CACHE_BITS < 19
761
 
            UPDATE_CACHE(re, &s->gb);
762
 
#endif
763
760
            if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
764
761
                break;
765
 
#if MIN_CACHE_BITS >= 19
766
762
            UPDATE_CACHE(re, &s->gb);
767
 
#endif
768
763
        }
769
764
end:
770
765
        LAST_SKIP_BITS(re, &s->gb, 2);
797
792
            if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
798
793
                goto end;
799
794
        }
800
 
#if MIN_CACHE_BITS < 19
801
 
        UPDATE_CACHE(re, &s->gb);
802
 
#endif
803
795
 
804
796
        /* now quantify & encode AC coefficients */
805
797
        for(;;) {
836
828
            }
837
829
 
838
830
            block[j] = level;
839
 
#if MIN_CACHE_BITS < 19
840
 
            UPDATE_CACHE(re, &s->gb);
841
 
#endif
842
831
            if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
843
832
                break;
844
 
#if MIN_CACHE_BITS >= 19
845
833
            UPDATE_CACHE(re, &s->gb);
846
 
#endif
847
834
        }
848
835
end:
849
836
        LAST_SKIP_BITS(re, &s->gb, 2);
888
875
            if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
889
876
                goto end;
890
877
        }
891
 
#if MIN_CACHE_BITS < 19
892
 
        UPDATE_CACHE(re, &s->gb);
893
 
#endif
894
878
 
895
879
        /* now quantify & encode AC coefficients */
896
880
        for(;;) {
924
908
 
925
909
            mismatch ^= level;
926
910
            block[j] = level;
927
 
#if MIN_CACHE_BITS < 19
928
 
            UPDATE_CACHE(re, &s->gb);
929
 
#endif
930
911
            if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
931
912
                break;
932
 
#if MIN_CACHE_BITS >= 19
933
913
            UPDATE_CACHE(re, &s->gb);
934
 
#endif
935
914
        }
936
915
end:
937
916
        LAST_SKIP_BITS(re, &s->gb, 2);
966
945
        if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
967
946
            goto end;
968
947
    }
969
 
#if MIN_CACHE_BITS < 19
970
 
    UPDATE_CACHE(re, &s->gb);
971
 
#endif
972
948
 
973
949
    /* now quantify & encode AC coefficients */
974
950
    for(;;) {
997
973
        }
998
974
 
999
975
        block[j] = level;
1000
 
#if MIN_CACHE_BITS < 19
1001
 
        UPDATE_CACHE(re, &s->gb);
1002
 
#endif
1003
976
        if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
1004
977
            break;
1005
 
#if MIN_CACHE_BITS >=19
1006
978
        UPDATE_CACHE(re, &s->gb);
1007
 
#endif
1008
979
    }
1009
980
end:
1010
981
    LAST_SKIP_BITS(re, &s->gb, 2);
1041
1012
    dc += diff;
1042
1013
    s->last_dc[component] = dc;
1043
1014
    block[0] = dc << (3 - s->intra_dc_precision);
1044
 
    dprintf(s->avctx, "dc=%d\n", block[0]);
 
1015
    av_dlog(s->avctx, "dc=%d\n", block[0]);
1045
1016
    mismatch = block[0] ^ 1;
1046
1017
    i = 0;
1047
1018
    if (s->intra_vlc_format)
1168
1139
    MpegEncContext mpeg_enc_ctx;
1169
1140
    int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
1170
1141
    int repeat_field; /* true if we must repeat the field */
1171
 
    AVPanScan pan_scan; /** some temporary storage for the panscan */
 
1142
    AVPanScan pan_scan;              /**< some temporary storage for the panscan */
1172
1143
    int slice_count;
1173
1144
    int swap_uv;//indicate VCR2
1174
1145
    int save_aspect_info;
1415
1386
    s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1;
1416
1387
    s1->frame_rate_ext.den = get_bits(&s->gb, 5)+1;
1417
1388
 
1418
 
    dprintf(s->avctx, "sequence extension\n");
 
1389
    av_dlog(s->avctx, "sequence extension\n");
1419
1390
    s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
1420
1391
    s->avctx->sub_id = 2; /* indicates MPEG-2 found */
1421
1392
 
1440
1411
    w= get_bits(&s->gb, 14);
1441
1412
    skip_bits(&s->gb, 1); //marker
1442
1413
    h= get_bits(&s->gb, 14);
1443
 
    skip_bits(&s->gb, 1); //marker
 
1414
    // remaining 3 bits are zero padding
1444
1415
 
1445
1416
    s1->pan_scan.width= 16*w;
1446
1417
    s1->pan_scan.height=16*h;
1506
1477
 
1507
1478
static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
1508
1479
{
1509
 
    dprintf(s->avctx, "matrix extension\n");
 
1480
    av_dlog(s->avctx, "matrix extension\n");
1510
1481
 
1511
1482
    if(get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
1512
1483
    if(get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
1580
1551
    }
1581
1552
 
1582
1553
    /* composite display not parsed */
1583
 
    dprintf(s->avctx, "intra_dc_precision=%d\n", s->intra_dc_precision);
1584
 
    dprintf(s->avctx, "picture_structure=%d\n", s->picture_structure);
1585
 
    dprintf(s->avctx, "top field first=%d\n", s->top_field_first);
1586
 
    dprintf(s->avctx, "repeat first field=%d\n", s->repeat_first_field);
1587
 
    dprintf(s->avctx, "conceal=%d\n", s->concealment_motion_vectors);
1588
 
    dprintf(s->avctx, "intra_vlc_format=%d\n", s->intra_vlc_format);
1589
 
    dprintf(s->avctx, "alternate_scan=%d\n", s->alternate_scan);
1590
 
    dprintf(s->avctx, "frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct);
1591
 
    dprintf(s->avctx, "progressive_frame=%d\n", s->progressive_frame);
 
1554
    av_dlog(s->avctx, "intra_dc_precision=%d\n", s->intra_dc_precision);
 
1555
    av_dlog(s->avctx, "picture_structure=%d\n", s->picture_structure);
 
1556
    av_dlog(s->avctx, "top field first=%d\n", s->top_field_first);
 
1557
    av_dlog(s->avctx, "repeat first field=%d\n", s->repeat_first_field);
 
1558
    av_dlog(s->avctx, "conceal=%d\n", s->concealment_motion_vectors);
 
1559
    av_dlog(s->avctx, "intra_vlc_format=%d\n", s->intra_vlc_format);
 
1560
    av_dlog(s->avctx, "alternate_scan=%d\n", s->alternate_scan);
 
1561
    av_dlog(s->avctx, "frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct);
 
1562
    av_dlog(s->avctx, "progressive_frame=%d\n", s->progressive_frame);
1592
1563
}
1593
1564
 
1594
1565
static void exchange_uv(MpegEncContext *s){
1911
1882
 
1912
1883
        start_code= -1;
1913
1884
        buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code);
1914
 
        mb_y= start_code - SLICE_MIN_START_CODE;
 
1885
        mb_y= (start_code - SLICE_MIN_START_CODE) << field_pic;
 
1886
        if (s->picture_structure == PICT_BOTTOM_FIELD)
 
1887
            mb_y++;
1915
1888
        if(mb_y < 0 || mb_y >= s->end_mb_y)
1916
1889
            return -1;
1917
1890
    }
1920
1893
}
1921
1894
 
1922
1895
/**
1923
 
 * Handles slice ends.
 
1896
 * Handle slice ends.
1924
1897
 * @return 1 if it seems to be the last slice
1925
1898
 */
1926
1899
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
2155
2128
            time_code_pictures, s->closed_gop, broken_link);
2156
2129
}
2157
2130
/**
2158
 
 * Finds the end of the current frame in the bitstream.
 
2131
 * Find the end of the current frame in the bitstream.
2159
2132
 * @return the position of the first byte of the next frame, or -1
2160
2133
 */
2161
2134
int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s)
2229
2202
    Mpeg1Context *s = avctx->priv_data;
2230
2203
    AVFrame *picture = data;
2231
2204
    MpegEncContext *s2 = &s->mpeg_enc_ctx;
2232
 
    dprintf(avctx, "fill_buffer\n");
 
2205
    av_dlog(avctx, "fill_buffer\n");
2233
2206
 
2234
2207
    if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
2235
2208
        /* special case for last picture */
2328
2301
            break;
2329
2302
 
2330
2303
        case PICTURE_START_CODE:
 
2304
            if (HAVE_THREADS && (avctx->active_thread_type&FF_THREAD_SLICE) && s->slice_count) {
 
2305
                int i;
 
2306
 
 
2307
                avctx->execute(avctx, slice_decode_thread,
 
2308
                               s2->thread_context, NULL,
 
2309
                               s->slice_count, sizeof(void*));
 
2310
                for (i = 0; i < s->slice_count; i++)
 
2311
                    s2->error_count += s2->thread_context[i]->error_count;
 
2312
                s->slice_count = 0;
 
2313
            }
2331
2314
            if(last_code == 0 || last_code == SLICE_MIN_START_CODE){
2332
2315
            if(mpeg_decode_postinit(avctx) < 0){
2333
2316
                av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n");
2415
2398
                /* Skip P-frames if we do not have a reference frame or we have an invalid header. */
2416
2399
                    if(s2->pict_type==FF_P_TYPE && !s->sync) break;
2417
2400
                }
 
2401
#if FF_API_HURRY_UP
2418
2402
                /* Skip B-frames if we are in a hurry. */
2419
2403
                if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break;
 
2404
#endif
2420
2405
                if(  (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==FF_B_TYPE)
2421
2406
                    ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=FF_I_TYPE)
2422
2407
                    || avctx->skip_frame >= AVDISCARD_ALL)
2423
2408
                    break;
 
2409
#if FF_API_HURRY_UP
2424
2410
                /* Skip everything if we are in a hurry>=5. */
2425
2411
                if(avctx->hurry_up>=5) break;
 
2412
#endif
2426
2413
 
2427
2414
                if (!s->mpeg_enc_ctx_allocated) break;
2428
2415
 
2500
2487
    return 0;
2501
2488
}
2502
2489
 
2503
 
AVCodec mpeg1video_decoder = {
 
2490
static const AVProfile mpeg2_video_profiles[] = {
 
2491
    { FF_PROFILE_MPEG2_422,          "4:2:2"              },
 
2492
    { FF_PROFILE_MPEG2_HIGH,         "High"               },
 
2493
    { FF_PROFILE_MPEG2_SS,           "Spatially Scalable" },
 
2494
    { FF_PROFILE_MPEG2_SNR_SCALABLE, "SNR Scalable"       },
 
2495
    { FF_PROFILE_MPEG2_MAIN,         "Main"               },
 
2496
    { FF_PROFILE_MPEG2_SIMPLE,       "Simple"             },
 
2497
    { FF_PROFILE_RESERVED,           "Reserved"           },
 
2498
    { FF_PROFILE_RESERVED,           "Reserved"           },
 
2499
};
 
2500
 
 
2501
 
 
2502
AVCodec ff_mpeg1video_decoder = {
2504
2503
    "mpeg1video",
2505
2504
    AVMEDIA_TYPE_VIDEO,
2506
2505
    CODEC_ID_MPEG1VIDEO,
2511
2510
    mpeg_decode_frame,
2512
2511
    CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
2513
2512
    .flush= flush,
 
2513
    .max_lowres= 3,
2514
2514
    .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"),
2515
2515
};
2516
2516
 
2517
 
AVCodec mpeg2video_decoder = {
 
2517
AVCodec ff_mpeg2video_decoder = {
2518
2518
    "mpeg2video",
2519
2519
    AVMEDIA_TYPE_VIDEO,
2520
2520
    CODEC_ID_MPEG2VIDEO,
2525
2525
    mpeg_decode_frame,
2526
2526
    CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
2527
2527
    .flush= flush,
 
2528
    .max_lowres= 3,
2528
2529
    .long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"),
 
2530
    .profiles = NULL_IF_CONFIG_SMALL(mpeg2_video_profiles),
2529
2531
};
2530
2532
 
2531
2533
//legacy decoder
2532
 
AVCodec mpegvideo_decoder = {
 
2534
AVCodec ff_mpegvideo_decoder = {
2533
2535
    "mpegvideo",
2534
2536
    AVMEDIA_TYPE_VIDEO,
2535
2537
    CODEC_ID_MPEG2VIDEO,
2540
2542
    mpeg_decode_frame,
2541
2543
    CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
2542
2544
    .flush= flush,
 
2545
    .max_lowres= 3,
2543
2546
    .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"),
2544
2547
};
2545
2548
 
2550
2553
    if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
2551
2554
        return -1;
2552
2555
    if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){
2553
 
        dprintf(avctx, "mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
 
2556
        av_dlog(avctx, "mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
2554
2557
    }
2555
2558
    mpeg_decode_init(avctx);
2556
2559
 
2560
2563
    return 0;
2561
2564
}
2562
2565
 
2563
 
AVCodec mpeg_xvmc_decoder = {
 
2566
AVCodec ff_mpeg_xvmc_decoder = {
2564
2567
    "mpegvideo_xvmc",
2565
2568
    AVMEDIA_TYPE_VIDEO,
2566
2569
    CODEC_ID_MPEG2VIDEO_XVMC,
2577
2580
#endif
2578
2581
 
2579
2582
#if CONFIG_MPEG_VDPAU_DECODER
2580
 
AVCodec mpeg_vdpau_decoder = {
 
2583
AVCodec ff_mpeg_vdpau_decoder = {
2581
2584
    "mpegvideo_vdpau",
2582
2585
    AVMEDIA_TYPE_VIDEO,
2583
2586
    CODEC_ID_MPEG2VIDEO,
2593
2596
#endif
2594
2597
 
2595
2598
#if CONFIG_MPEG1_VDPAU_DECODER
2596
 
AVCodec mpeg1_vdpau_decoder = {
 
2599
AVCodec ff_mpeg1_vdpau_decoder = {
2597
2600
    "mpeg1video_vdpau",
2598
2601
    AVMEDIA_TYPE_VIDEO,
2599
2602
    CODEC_ID_MPEG1VIDEO,