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

« back to all changes in this revision

Viewing changes to libavcodec/mpegvideo.h

  • 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:
36
36
#include "parser.h"
37
37
#include "mpeg12data.h"
38
38
#include "rl.h"
 
39
#include "videodsp.h"
 
40
 
 
41
#include "libavutil/opt.h"
39
42
 
40
43
#define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
41
44
 
77
80
#define EXT_START_CODE          0x000001b5
78
81
#define USER_START_CODE         0x000001b2
79
82
 
 
83
/**
 
84
 * Value of Picture.reference when Picture is not a reference picture, but
 
85
 * is held for delayed output.
 
86
 */
 
87
#define DELAYED_PIC_REF 4
 
88
 
80
89
struct MpegEncContext;
81
90
 
82
91
/**
137
146
    int32_t *mb_cmp_score;      ///< Table for MB cmp scores, for mb decision FIXME remove
138
147
    int b_frame_score;          /* */
139
148
    struct MpegEncContext *owner2; ///< pointer to the MpegEncContext that allocated this picture
 
149
    int needs_realloc;          ///< Picture needs to be reallocated (eg due to a frame size change)
140
150
} Picture;
141
151
 
142
152
/**
214
224
    int h263_plus;    ///< h263 plus headers
215
225
    int h263_flv;     ///< use flv h263 header
216
226
 
217
 
    enum CodecID codec_id;     /* see CODEC_ID_xxx */
 
227
    enum AVCodecID codec_id;     /* see AV_CODEC_ID_xxx */
218
228
    int fixed_qscale; ///< fixed qscale if non zero
219
229
    int encoding;     ///< true if we are encoding (vs decoding)
220
230
    int flags;        ///< AVCodecContext.flags (HQ, MV4, ...)
261
271
     *          offsets used in asm. */
262
272
 
263
273
    int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video()
 
274
    /**
 
275
     * pts difference between the first and second input frame, used for
 
276
     * calculating dts of the first frame when there's a delay */
 
277
    int64_t dts_delta;
 
278
    /**
 
279
     * reordered pts to be used as dts for the next output frame when there's
 
280
     * a delay */
 
281
    int64_t reordered_pts;
264
282
 
265
283
    /** bit output */
266
284
    PutBitContext pb;
331
349
    int pict_type;              ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
332
350
    int last_pict_type; //FIXME removes
333
351
    int last_non_b_pict_type;   ///< used for mpeg4 gmc b-frames & ratecontrol
334
 
    int dropable;
 
352
    int droppable;
335
353
    int frame_rate_index;
336
354
    int last_lambda_for[5];     ///< last lambda for a specific pict type
337
355
    int skipdct;                ///< skip dct and code zero residual
341
359
    int h263_long_vectors;      ///< use horrible h263v1 long vector mode
342
360
 
343
361
    DSPContext dsp;             ///< pointers for accelerated dsp functions
 
362
    VideoDSPContext vdsp;
344
363
    int f_code;                 ///< forward MV resolution
345
364
    int b_code;                 ///< backward MV resolution for B Frames (mpeg4)
346
365
    int16_t (*p_mv_table_base)[2];
496
515
    int gob_index;
497
516
    int obmc;                       ///< overlapped block motion compensation
498
517
    int showed_packed_warning;      ///< flag for having shown the warning about divxs invalid b frames
 
518
    int mb_info;                    ///< interval for outputting info about mb offsets as side data
 
519
    int prev_mb_info, last_mb_info;
 
520
    uint8_t *mb_info_ptr;
 
521
    int mb_info_size;
499
522
 
500
523
    /* H.263+ specific */
501
524
    int umvplus;                    ///< == H263+ && unrestricted_mv
679
702
    int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
680
703
    int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
681
704
    void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
 
705
 
 
706
    int mpv_flags;      ///< flags set by private options
 
707
    int quantizer_noise_shaping;
 
708
 
 
709
    /* error resilience stuff */
 
710
    uint8_t *er_temp_buffer;
 
711
 
 
712
    /* temp buffers for rate control */
 
713
    float *cplx_tab, *bits_tab;
 
714
 
 
715
    /* flag to indicate a reinitialization is required, e.g. after
 
716
     * a frame size change */
 
717
    int context_reinit;
682
718
} MpegEncContext;
683
719
 
684
720
#define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \
685
721
    (pic >= old_ctx->picture && pic < old_ctx->picture+old_ctx->picture_count ?\
686
 
        &new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\
 
722
        &new_ctx->picture[pic - old_ctx->picture] : (Picture*) ((uint8_t*)pic - (uint8_t*)old_ctx + (uint8_t*)new_ctx))\
687
723
    : NULL)
688
724
 
689
 
void MPV_decode_defaults(MpegEncContext *s);
690
 
int MPV_common_init(MpegEncContext *s);
691
 
void MPV_common_end(MpegEncContext *s);
692
 
void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]);
693
 
int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);
694
 
void MPV_frame_end(MpegEncContext *s);
695
 
int MPV_encode_init(AVCodecContext *avctx);
696
 
int MPV_encode_end(AVCodecContext *avctx);
697
 
int MPV_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data);
698
 
void MPV_common_init_mmx(MpegEncContext *s);
699
 
void MPV_common_init_axp(MpegEncContext *s);
700
 
void MPV_common_init_mlib(MpegEncContext *s);
701
 
void MPV_common_init_mmi(MpegEncContext *s);
702
 
void MPV_common_init_arm(MpegEncContext *s);
703
 
void MPV_common_init_altivec(MpegEncContext *s);
704
 
void MPV_common_init_bfin(MpegEncContext *s);
 
725
/* mpegvideo_enc common options */
 
726
#define FF_MPV_FLAG_SKIP_RD      0x0001
 
727
#define FF_MPV_FLAG_STRICT_GOP   0x0002
 
728
#define FF_MPV_FLAG_QP_RD        0x0004
 
729
#define FF_MPV_FLAG_CBP_RD       0x0008
 
730
 
 
731
#define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x)
 
732
#define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
 
733
#define FF_MPV_COMMON_OPTS \
 
734
{ "mpv_flags",      "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "mpv_flags" },\
 
735
{ "skip_rd",        "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_SKIP_RD },    0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
 
736
{ "strict_gop",     "Strictly enforce gop size",             0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
 
737
{ "qp_rd",          "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_QP_RD },  0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
 
738
{ "cbp_rd",         "use rate distortion optimization for CBP",          0, AV_OPT_TYPE_CONST, { .i64 = FF_MPV_FLAG_CBP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
 
739
{ "luma_elim_threshold",   "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\
 
740
                                                                      FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
 
741
{ "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\
 
742
                                                                      FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
 
743
{ "quantizer_noise_shaping", NULL,                                  FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { .i64 = 0 },       0, INT_MAX, FF_MPV_OPT_FLAGS },
 
744
 
 
745
extern const AVOption ff_mpv_generic_options[];
 
746
 
 
747
#define FF_MPV_GENERIC_CLASS(name) \
 
748
static const AVClass name ## _class = {\
 
749
    .class_name = #name " encoder",\
 
750
    .item_name  = av_default_item_name,\
 
751
    .option     = ff_mpv_generic_options,\
 
752
    .version    = LIBAVUTIL_VERSION_INT,\
 
753
};
 
754
 
 
755
/**
 
756
 * Set the given MpegEncContext to common defaults (same for encoding
 
757
 * and decoding).  The changed fields will not depend upon the prior
 
758
 * state of the MpegEncContext.
 
759
 */
 
760
void ff_MPV_common_defaults(MpegEncContext *s);
 
761
 
 
762
void ff_MPV_decode_defaults(MpegEncContext *s);
 
763
int ff_MPV_common_init(MpegEncContext *s);
 
764
int ff_mpv_frame_size_alloc(MpegEncContext *s, int linesize);
 
765
int ff_MPV_common_frame_size_change(MpegEncContext *s);
 
766
void ff_MPV_common_end(MpegEncContext *s);
 
767
void ff_MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]);
 
768
int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);
 
769
void ff_MPV_frame_end(MpegEncContext *s);
 
770
int ff_MPV_encode_init(AVCodecContext *avctx);
 
771
int ff_MPV_encode_end(AVCodecContext *avctx);
 
772
int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
 
773
                          const AVFrame *frame, int *got_packet);
 
774
void ff_MPV_encode_init_x86(MpegEncContext *s);
 
775
void ff_MPV_common_init_x86(MpegEncContext *s);
 
776
void ff_MPV_common_init_axp(MpegEncContext *s);
 
777
void ff_MPV_common_init_arm(MpegEncContext *s);
 
778
void ff_MPV_common_init_altivec(MpegEncContext *s);
 
779
void ff_MPV_common_init_bfin(MpegEncContext *s);
705
780
void ff_clean_intra_table_entries(MpegEncContext *s);
706
781
void ff_draw_horiz_band(MpegEncContext *s, int y, int h);
707
782
void ff_mpeg_flush(AVCodecContext *avctx);
710
785
void ff_release_unused_pictures(MpegEncContext *s, int remove_current);
711
786
int ff_find_unused_picture(MpegEncContext *s, int shared);
712
787
void ff_denoise_dct(MpegEncContext *s, DCTELEM *block);
713
 
void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
714
 
int MPV_lowest_referenced_row(MpegEncContext *s, int dir);
715
 
void MPV_report_decode_progress(MpegEncContext *s);
 
788
int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
 
789
int ff_MPV_lowest_referenced_row(MpegEncContext *s, int dir);
 
790
void ff_MPV_report_decode_progress(MpegEncContext *s);
716
791
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
717
792
const uint8_t *avpriv_mpv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state);
718
793
void ff_set_qscale(MpegEncContext * s, int qscale);
724
799
int ff_dct_common_init(MpegEncContext *s);
725
800
void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64],
726
801
                       const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra);
 
802
int ff_dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
727
803
 
728
804
void ff_init_block_index(MpegEncContext *s);
729
805
void ff_copy_picture(Picture *dst, Picture *src);
730
806
 
 
807
void ff_MPV_motion(MpegEncContext *s,
 
808
                   uint8_t *dest_y, uint8_t *dest_cb,
 
809
                   uint8_t *dest_cr, int dir,
 
810
                   uint8_t **ref_picture,
 
811
                   op_pixels_func (*pix_op)[4],
 
812
                   qpel_mc_func (*qpix_op)[16]);
 
813
 
731
814
/**
732
815
 * Allocate a Picture.
733
816
 * The pixels are allocated/set by calling get_buffer() if shared = 0.
734
817
 */
735
818
int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared);
736
819
 
737
 
extern const enum PixelFormat ff_pixfmt_list_420[];
738
 
extern const enum PixelFormat ff_hwaccel_pixfmt_list_420[];
 
820
extern const enum AVPixelFormat ff_pixfmt_list_420[];
 
821
extern const enum AVPixelFormat ff_hwaccel_pixfmt_list_420[];
739
822
 
740
823
static inline void ff_update_block_index(MpegEncContext *s){
741
 
    const int block_size= 8>>s->avctx->lowres;
 
824
    const int block_size = 8;
742
825
 
743
826
    s->block_index[0]+=2;
744
827
    s->block_index[1]+=2;
789
872
extern const uint8_t ff_mpeg1_dc_scale_table[128];
790
873
extern const uint8_t * const ff_mpeg2_dc_scale_table[4];
791
874
 
792
 
void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number);
793
 
void mpeg1_encode_mb(MpegEncContext *s,
794
 
                     DCTELEM block[6][64],
795
 
                     int motion_x, int motion_y);
 
875
void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number);
 
876
void ff_mpeg1_encode_mb(MpegEncContext *s,
 
877
                        DCTELEM block[6][64],
 
878
                        int motion_x, int motion_y);
796
879
void ff_mpeg1_encode_init(MpegEncContext *s);
797
880
void ff_mpeg1_encode_slice_header(MpegEncContext *s);
798
881
void ff_mpeg1_clean_buffers(MpegEncContext *s);
814
897
 
815
898
 
816
899
/* rv10.c */
817
 
void rv10_encode_picture_header(MpegEncContext *s, int picture_number);
818
 
int rv_decode_dc(MpegEncContext *s, int n);
819
 
void rv20_encode_picture_header(MpegEncContext *s, int picture_number);
 
900
void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number);
 
901
int ff_rv_decode_dc(MpegEncContext *s, int n);
 
902
void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number);
820
903
 
821
904
 
822
905
/* msmpeg4.c */
823
 
void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number);
824
 
void msmpeg4_encode_ext_header(MpegEncContext * s);
825
 
void msmpeg4_encode_mb(MpegEncContext * s,
826
 
                       DCTELEM block[6][64],
827
 
                       int motion_x, int motion_y);
828
 
int msmpeg4_decode_picture_header(MpegEncContext * s);
829
 
int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size);
 
906
void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number);
 
907
void ff_msmpeg4_encode_ext_header(MpegEncContext * s);
 
908
void ff_msmpeg4_encode_mb(MpegEncContext * s,
 
909
                          DCTELEM block[6][64],
 
910
                          int motion_x, int motion_y);
 
911
int ff_msmpeg4_decode_picture_header(MpegEncContext * s);
 
912
int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size);
830
913
int ff_msmpeg4_decode_init(AVCodecContext *avctx);
831
914
void ff_msmpeg4_encode_init(MpegEncContext *s);
832
915
int ff_wmv2_decode_picture_header(MpegEncContext * s);