summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/aacdec.c154
-rw-r--r--libavcodec/ac3enc.c28
-rw-r--r--libavcodec/ac3enc_fixed.c1
-rw-r--r--libavcodec/ac3enc_float.c1
-rw-r--r--libavcodec/ac3enc_opts_template.c6
-rw-r--r--libavcodec/amrnbdec.c8
-rw-r--r--libavcodec/avcodec.h34
-rw-r--r--libavcodec/cscd.c4
-rw-r--r--libavcodec/dpxenc.c3
-rw-r--r--libavcodec/eac3enc.c1
-rw-r--r--libavcodec/flvenc.c3
-rw-r--r--libavcodec/h261enc.c3
-rw-r--r--libavcodec/h263.h2
-rw-r--r--libavcodec/h264_cabac.c2
-rw-r--r--libavcodec/libvorbis.c308
-rw-r--r--libavcodec/mpeg12enc.c2
-rw-r--r--libavcodec/mpeg4videoenc.c3
-rw-r--r--libavcodec/mpegaudiodec.c7
-rw-r--r--libavcodec/mpegvideo.h35
-rw-r--r--libavcodec/mpegvideo_enc.c73
-rw-r--r--libavcodec/options.c28
-rw-r--r--libavcodec/proresdec_lgpl.c45
-rw-r--r--libavcodec/proresenc_kostya.c57
-rw-r--r--libavcodec/qtrle.c2
-rw-r--r--libavcodec/rpza.c4
-rw-r--r--libavcodec/rv10enc.c3
-rw-r--r--libavcodec/rv20enc.c3
-rw-r--r--libavcodec/version.h9
-rw-r--r--libavcodec/vmnc.c2
-rw-r--r--libavcodec/vp5.c5
-rw-r--r--libavcodec/vp6.c6
31 files changed, 546 insertions, 296 deletions
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 3d38645599..74ad09902e 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -114,55 +114,6 @@ static VLC vlc_spectral[11];
static const char overread_err[] = "Input buffer exhausted before END element found\n";
-static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
-{
- // For PCE based channel configurations map the channels solely based on tags.
- if (!ac->m4ac.chan_config) {
- return ac->tag_che_map[type][elem_id];
- }
- // For indexed channel configurations map the channels solely based on position.
- switch (ac->m4ac.chan_config) {
- case 7:
- if (ac->tags_mapped == 3 && type == TYPE_CPE) {
- ac->tags_mapped++;
- return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
- }
- case 6:
- /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
- instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have
- encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */
- if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
- ac->tags_mapped++;
- return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
- }
- case 5:
- if (ac->tags_mapped == 2 && type == TYPE_CPE) {
- ac->tags_mapped++;
- return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
- }
- case 4:
- if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
- ac->tags_mapped++;
- return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
- }
- case 3:
- case 2:
- if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
- ac->tags_mapped++;
- return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
- } else if (ac->m4ac.chan_config == 2) {
- return NULL;
- }
- case 1:
- if (!ac->tags_mapped && type == TYPE_SCE) {
- ac->tags_mapped++;
- return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
- }
- default:
- return NULL;
- }
-}
-
static int count_channels(uint8_t (*layout)[3], int tags)
{
int i, sum = 0;
@@ -455,6 +406,90 @@ static void flush(AVCodecContext *avctx)
}
/**
+ * Set up channel positions based on a default channel configuration
+ * as specified in table 1.17.
+ *
+ * @return Returns error status. 0 - OK, !0 - error
+ */
+static av_cold int set_default_channel_config(AVCodecContext *avctx,
+ uint8_t (*layout_map)[3],
+ int *tags,
+ int channel_config)
+{
+ if (channel_config < 1 || channel_config > 7) {
+ av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
+ channel_config);
+ return -1;
+ }
+ *tags = tags_per_config[channel_config];
+ memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map));
+ return 0;
+}
+
+static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
+{
+ // For PCE based channel configurations map the channels solely based on tags.
+ if (!ac->m4ac.chan_config) {
+ return ac->tag_che_map[type][elem_id];
+ }
+ // Allow single CPE stereo files to be signalled with mono configuration.
+ if (!ac->tags_mapped && type == TYPE_CPE && ac->m4ac.chan_config == 1) {
+ uint8_t layout_map[MAX_ELEM_ID*4][3];
+ int layout_map_tags;
+
+ if (set_default_channel_config(ac->avctx, layout_map, &layout_map_tags,
+ 2) < 0)
+ return NULL;
+ if (output_configure(ac, layout_map, layout_map_tags,
+ 2, OC_TRIAL_FRAME) < 0)
+ return NULL;
+
+ ac->m4ac.chan_config = 2;
+ }
+ // For indexed channel configurations map the channels solely based on position.
+ switch (ac->m4ac.chan_config) {
+ case 7:
+ if (ac->tags_mapped == 3 && type == TYPE_CPE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
+ }
+ case 6:
+ /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
+ instead of SCE[0] CPE[0] CPE[1] LFE[0]. If we seem to have
+ encountered such a stream, transfer the LFE[0] element to the SCE[1]'s mapping */
+ if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
+ }
+ case 5:
+ if (ac->tags_mapped == 2 && type == TYPE_CPE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
+ }
+ case 4:
+ if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
+ }
+ case 3:
+ case 2:
+ if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
+ } else if (ac->m4ac.chan_config == 2) {
+ return NULL;
+ }
+ case 1:
+ if (!ac->tags_mapped && type == TYPE_SCE) {
+ ac->tags_mapped++;
+ return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
+ }
+ default:
+ return NULL;
+ }
+}
+
+/**
* Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit.
*
* @param type speaker type/position for these channels
@@ -551,27 +586,6 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
}
/**
- * Set up channel positions based on a default channel configuration
- * as specified in table 1.17.
- *
- * @return Returns error status. 0 - OK, !0 - error
- */
-static av_cold int set_default_channel_config(AVCodecContext *avctx,
- uint8_t (*layout_map)[3],
- int *tags,
- int channel_config)
-{
- if (channel_config < 1 || channel_config > 7) {
- av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
- channel_config);
- return -1;
- }
- *tags = tags_per_config[channel_config];
- memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map));
- return 0;
-}
-
-/**
* Decode GA "General Audio" specific configuration; reference: table 4.1.
*
* @param ac pointer to AACContext, may be null
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index d49873a6f6..9d72a3bd88 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -2138,6 +2138,17 @@ static av_cold int validate_options(AC3EncodeContext *s)
s->bit_alloc.sr_code = i % 3;
s->bitstream_id = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift;
+ /* select a default bit rate if not set by the user */
+ if (!avctx->bit_rate) {
+ switch (s->fbw_channels) {
+ case 1: avctx->bit_rate = 96000; break;
+ case 2: avctx->bit_rate = 192000; break;
+ case 3: avctx->bit_rate = 320000; break;
+ case 4: avctx->bit_rate = 384000; break;
+ case 5: avctx->bit_rate = 448000; break;
+ }
+ }
+
/* validate bit rate */
if (s->eac3) {
int max_br, min_br, wpf, min_br_dist, min_br_code;
@@ -2186,15 +2197,20 @@ static av_cold int validate_options(AC3EncodeContext *s)
wpf--;
s->frame_size_min = 2 * wpf;
} else {
+ int best_br = 0, best_code = 0, best_diff = INT_MAX;
for (i = 0; i < 19; i++) {
- if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate)
+ int br = (ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift) * 1000;
+ int diff = abs(br - avctx->bit_rate);
+ if (diff < best_diff) {
+ best_br = br;
+ best_code = i;
+ best_diff = diff;
+ }
+ if (!best_diff)
break;
}
- if (i == 19) {
- av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n");
- return AVERROR(EINVAL);
- }
- s->frame_size_code = i << 1;
+ avctx->bit_rate = best_br;
+ s->frame_size_code = best_code << 1;
s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];
s->num_blks_code = 0x3;
s->num_blocks = 6;
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index 4b844783a9..24612c0949 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -157,4 +157,5 @@ AVCodec ff_ac3_fixed_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
.priv_class = &ac3enc_class,
.channel_layouts = ff_ac3_channel_layouts,
+ .defaults = ac3_defaults,
};
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index 0d4000c05a..073045c9e0 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -155,5 +155,6 @@ AVCodec ff_ac3_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
.priv_class = &ac3enc_class,
.channel_layouts = ff_ac3_channel_layouts,
+ .defaults = ac3_defaults,
};
#endif
diff --git a/libavcodec/ac3enc_opts_template.c b/libavcodec/ac3enc_opts_template.c
index a5f848e200..fa8984476e 100644
--- a/libavcodec/ac3enc_opts_template.c
+++ b/libavcodec/ac3enc_opts_template.c
@@ -20,6 +20,7 @@
*/
#include "libavutil/opt.h"
+#include "internal.h"
#include "ac3.h"
#if AC3ENC_TYPE == AC3ENC_TYPE_AC3_FIXED
@@ -78,3 +79,8 @@ static const AVOption eac3_options[] = {
{"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"},
{NULL}
};
+
+static const AVCodecDefault ac3_defaults[] = {
+ { "b", "0" },
+ { NULL }
+};
diff --git a/libavcodec/amrnbdec.c b/libavcodec/amrnbdec.c
index c560d69e88..dc7f95ccbc 100644
--- a/libavcodec/amrnbdec.c
+++ b/libavcodec/amrnbdec.c
@@ -200,6 +200,10 @@ static enum Mode unpack_bitstream(AMRContext *p, const uint8_t *buf,
p->bad_frame_indicator = !get_bits1(&gb); // quality bit
skip_bits(&gb, 2); // two padding bits
+ if (mode >= N_MODES || buf_size < frame_sizes_nb[mode] + 1) {
+ return NO_DATA;
+ }
+
if (mode < MODE_DTX)
ff_amr_bit_reorder((uint16_t *) &p->frame, sizeof(AMRNBFrame), buf + 1,
amr_unpacking_bitmaps_per_mode[mode]);
@@ -947,6 +951,10 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data,
buf_out = (float *)p->avframe.data[0];
p->cur_frame_mode = unpack_bitstream(p, buf, buf_size);
+ if (p->cur_frame_mode == NO_DATA) {
+ av_log(avctx, AV_LOG_ERROR, "Corrupt bitstream\n");
+ return AVERROR_INVALIDDATA;
+ }
if (p->cur_frame_mode == MODE_DTX) {
av_log_missing_feature(avctx, "dtx mode", 0);
av_log(avctx, AV_LOG_INFO, "Note: libopencore_amrnb supports dtx\n");
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3ece8fe86c..39f69eee44 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -582,17 +582,19 @@ typedef struct RcOverride{
#define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT).
/* Fx : Flag for h263+ extra options */
#define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction
-#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
-#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
#define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
#define CODEC_FLAG_CLOSED_GOP 0x80000000
#define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks.
-#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding.
#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata.
#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. DEPRECATED!!!!
+#if FF_API_MPV_GLOBAL_OPTS
+#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp.
+#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon.
+#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size.
#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping
+#endif
#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries.
#define CODEC_FLAG2_SHOW_ALL 0x00400000 ///< Show all frames before the first keyframe
@@ -1492,19 +1494,21 @@ typedef struct AVCodecContext {
int b_frame_strategy;
+#if FF_API_MPV_GLOBAL_OPTS
/**
* luma single coefficient elimination threshold
* - encoding: Set by user.
* - decoding: unused
*/
- int luma_elim_threshold;
+ attribute_deprecated int luma_elim_threshold;
/**
* chroma single coeff elimination threshold
* - encoding: Set by user.
* - decoding: unused
*/
- int chroma_elim_threshold;
+ attribute_deprecated int chroma_elim_threshold;
+#endif
/**
* qscale offset between IP and B-frames
@@ -1735,13 +1739,15 @@ typedef struct AVCodecContext {
*/
int inter_quant_bias;
+#if FF_API_COLOR_TABLE_ID
/**
* color table ID
* - encoding: unused
* - decoding: Which clrtable should be used for 8bit RGB images.
* Tables have to be stored somewhere. FIXME
*/
- int color_table_id;
+ attribute_deprecated int color_table_id;
+#endif
/**
* slice flags
@@ -1799,19 +1805,19 @@ typedef struct AVCodecContext {
*/
int noise_reduction;
+#if FF_API_INTER_THRESHOLD
/**
- *
- * - encoding: Set by user.
- * - decoding: unused
+ * @deprecated this field is unused
*/
- int inter_threshold;
+ attribute_deprecated int inter_threshold;
+#endif
+#if FF_API_MPV_GLOBAL_OPTS
/**
- * quantizer noise shaping
- * - encoding: Set by user.
- * - decoding: unused
+ * @deprecated use mpegvideo private options instead
*/
- int quantizer_noise_shaping;
+ attribute_deprecated int quantizer_noise_shaping;
+#endif
/**
* Motion estimation threshold below which no motion estimation is
diff --git a/libavcodec/cscd.c b/libavcodec/cscd.c
index 4f9b70c88b..dafb0c9161 100644
--- a/libavcodec/cscd.c
+++ b/libavcodec/cscd.c
@@ -228,7 +228,7 @@ static av_cold int decode_init(AVCodecContext *avctx) {
av_log(avctx, AV_LOG_ERROR,
"CamStudio codec error: invalid depth %i bpp\n",
avctx->bits_per_coded_sample);
- return 1;
+ return AVERROR_INVALIDDATA;
}
c->bpp = avctx->bits_per_coded_sample;
avcodec_get_frame_defaults(&c->pic);
@@ -242,7 +242,7 @@ static av_cold int decode_init(AVCodecContext *avctx) {
c->decomp_buf = av_malloc(c->decomp_size + AV_LZO_OUTPUT_PADDING);
if (!c->decomp_buf) {
av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
- return 1;
+ return AVERROR(ENOMEM);
}
return 0;
}
diff --git a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c
index bde02bce1c..05a7134378 100644
--- a/libavcodec/dpxenc.c
+++ b/libavcodec/dpxenc.c
@@ -131,9 +131,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
memcpy (buf + 8, "V1.0", 4);
write32(buf + 20, 1); /* new image */
write32(buf + 24, HEADER_SIZE);
- if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
+ if (!(avctx->flags & CODEC_FLAG_BITEXACT))
memcpy (buf + 160, LIBAVCODEC_IDENT, FFMIN(sizeof(LIBAVCODEC_IDENT), 100));
- }
write32(buf + 660, 0xFFFFFFFF); /* unencrypted */
/* Image information header */
diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c
index f3b4418896..459fb90ce6 100644
--- a/libavcodec/eac3enc.c
+++ b/libavcodec/eac3enc.c
@@ -258,5 +258,6 @@ AVCodec ff_eac3_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),
.priv_class = &eac3enc_class,
.channel_layouts = ff_ac3_channel_layouts,
+ .defaults = ac3_defaults,
};
#endif
diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index d1484b44e3..be9778c5ab 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -84,6 +84,8 @@ void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, in
}
}
+FF_MPV_GENERIC_CLASS(flv)
+
AVCodec ff_flv_encoder = {
.name = "flv",
.type = AVMEDIA_TYPE_VIDEO,
@@ -94,4 +96,5 @@ AVCodec ff_flv_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"),
+ .priv_class = &flv_class,
};
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 35b4abd251..a2566988ea 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -321,6 +321,8 @@ static void h261_encode_block(H261Context * h, DCTELEM * block, int n){
}
}
+FF_MPV_GENERIC_CLASS(h261)
+
AVCodec ff_h261_encoder = {
.name = "h261",
.type = AVMEDIA_TYPE_VIDEO,
@@ -331,4 +333,5 @@ AVCodec ff_h261_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("H.261"),
+ .priv_class = &h261_class,
};
diff --git a/libavcodec/h263.h b/libavcodec/h263.h
index ed9da5352b..91dd548108 100644
--- a/libavcodec/h263.h
+++ b/libavcodec/h263.h
@@ -148,7 +148,7 @@ static inline int get_p_cbp(MpegEncContext * s,
int motion_x, int motion_y){
int cbp, i;
- if(s->flags & CODEC_FLAG_CBP_RD){
+ if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
int best_cbpy_score= INT_MAX;
int best_cbpc_score= INT_MAX;
int cbpc = (-1), cbpy= (-1);
diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c
index ea120ed74a..2c83348a5f 100644
--- a/libavcodec/h264_cabac.c
+++ b/libavcodec/h264_cabac.c
@@ -1998,6 +1998,8 @@ decode_intra_mb:
}
// The pixels are stored in the same order as levels in h->mb array.
+ if ((int) (h->cabac.bytestream_end - ptr) < mb_size)
+ return -1;
memcpy(h->mb, ptr, mb_size); ptr+=mb_size;
ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
diff --git a/libavcodec/libvorbis.c b/libavcodec/libvorbis.c
index 19dfa34fcc..f5ad49e68f 100644
--- a/libavcodec/libvorbis.c
+++ b/libavcodec/libvorbis.c
@@ -20,12 +20,13 @@
/**
* @file
- * Ogg Vorbis codec support via libvorbisenc.
+ * Vorbis encoding support via libvorbisenc.
* @author Mark Hills <mark@pogo.org.uk>
*/
#include <vorbis/vorbisenc.h>
+#include "libavutil/fifo.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "bytestream.h"
@@ -35,32 +36,41 @@
#undef NDEBUG
#include <assert.h>
+/* Number of samples the user should send in each call.
+ * This value is used because it is the LCD of all possible frame sizes, so
+ * an output packet will always start at the same point as one of the input
+ * packets.
+ */
#define OGGVORBIS_FRAME_SIZE 64
#define BUFFER_SIZE (1024 * 64)
typedef struct OggVorbisContext {
- AVClass *av_class;
- vorbis_info vi;
- vorbis_dsp_state vd;
- vorbis_block vb;
- uint8_t buffer[BUFFER_SIZE];
- int buffer_index;
- int eof;
-
- /* decoder */
- vorbis_comment vc;
- ogg_packet op;
-
- double iblock;
+ AVClass *av_class; /**< class for AVOptions */
+ vorbis_info vi; /**< vorbis_info used during init */
+ vorbis_dsp_state vd; /**< DSP state used for analysis */
+ vorbis_block vb; /**< vorbis_block used for analysis */
+ AVFifoBuffer *pkt_fifo; /**< output packet buffer */
+ int eof; /**< end-of-file flag */
+ int dsp_initialized; /**< vd has been initialized */
+ vorbis_comment vc; /**< VorbisComment info */
+ ogg_packet op; /**< ogg packet */
+ double iblock; /**< impulse block bias option */
} OggVorbisContext;
static const AVOption options[] = {
{ "iblock", "Sets the impulse block bias", offsetof(OggVorbisContext, iblock), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, -15, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
{ NULL }
};
+
+static const AVCodecDefault defaults[] = {
+ { "b", "0" },
+ { NULL },
+};
+
static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT };
+
static int vorbis_error_to_averror(int ov_err)
{
switch (ov_err) {
@@ -71,27 +81,34 @@ static int vorbis_error_to_averror(int ov_err)
}
}
-static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext)
+static av_cold int oggvorbis_init_encoder(vorbis_info *vi,
+ AVCodecContext *avctx)
{
- OggVorbisContext *context = avccontext->priv_data;
+ OggVorbisContext *s = avctx->priv_data;
double cfreq;
int ret;
- if (avccontext->flags & CODEC_FLAG_QSCALE) {
- /* variable bitrate */
- float q = avccontext->global_quality / (float)FF_QP2LAMBDA;
- if ((ret = vorbis_encode_setup_vbr(vi, avccontext->channels,
- avccontext->sample_rate,
+ if (avctx->flags & CODEC_FLAG_QSCALE || !avctx->bit_rate) {
+ /* variable bitrate
+ * NOTE: we use the oggenc range of -1 to 10 for global_quality for
+ * user convenience, but libvorbis uses -0.1 to 1.0.
+ */
+ float q = avctx->global_quality / (float)FF_QP2LAMBDA;
+ /* default to 3 if the user did not set quality or bitrate */
+ if (!(avctx->flags & CODEC_FLAG_QSCALE))
+ q = 3.0;
+ if ((ret = vorbis_encode_setup_vbr(vi, avctx->channels,
+ avctx->sample_rate,
q / 10.0)))
goto error;
} else {
- int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1;
- int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1;
+ int minrate = avctx->rc_min_rate > 0 ? avctx->rc_min_rate : -1;
+ int maxrate = avctx->rc_max_rate > 0 ? avctx->rc_max_rate : -1;
- /* constant bitrate */
- if ((ret = vorbis_encode_setup_managed(vi, avccontext->channels,
- avccontext->sample_rate, minrate,
- avccontext->bit_rate, maxrate)))
+ /* average bitrate */
+ if ((ret = vorbis_encode_setup_managed(vi, avctx->channels,
+ avctx->sample_rate, maxrate,
+ avctx->bit_rate, minrate)))
goto error;
/* variable bitrate by estimate, disable slow rate management */
@@ -101,43 +118,44 @@ static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avcco
}
/* cutoff frequency */
- if (avccontext->cutoff > 0) {
- cfreq = avccontext->cutoff / 1000.0;
+ if (avctx->cutoff > 0) {
+ cfreq = avctx->cutoff / 1000.0;
if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)))
goto error; /* should not happen */
}
- if (context->iblock) {
- if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock)))
+ /* impulse block bias */
+ if (s->iblock) {
+ if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &s->iblock)))
goto error;
}
- if (avccontext->channels == 3 &&
- avccontext->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
- avccontext->channels == 4 &&
- avccontext->channel_layout != AV_CH_LAYOUT_2_2 &&
- avccontext->channel_layout != AV_CH_LAYOUT_QUAD ||
- avccontext->channels == 5 &&
- avccontext->channel_layout != AV_CH_LAYOUT_5POINT0 &&
- avccontext->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
- avccontext->channels == 6 &&
- avccontext->channel_layout != AV_CH_LAYOUT_5POINT1 &&
- avccontext->channel_layout != AV_CH_LAYOUT_5POINT1_BACK ||
- avccontext->channels == 7 &&
- avccontext->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) ||
- avccontext->channels == 8 &&
- avccontext->channel_layout != AV_CH_LAYOUT_7POINT1) {
- if (avccontext->channel_layout) {
+ if (avctx->channels == 3 &&
+ avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
+ avctx->channels == 4 &&
+ avctx->channel_layout != AV_CH_LAYOUT_2_2 &&
+ avctx->channel_layout != AV_CH_LAYOUT_QUAD ||
+ avctx->channels == 5 &&
+ avctx->channel_layout != AV_CH_LAYOUT_5POINT0 &&
+ avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
+ avctx->channels == 6 &&
+ avctx->channel_layout != AV_CH_LAYOUT_5POINT1 &&
+ avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK ||
+ avctx->channels == 7 &&
+ avctx->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) ||
+ avctx->channels == 8 &&
+ avctx->channel_layout != AV_CH_LAYOUT_7POINT1) {
+ if (avctx->channel_layout) {
char name[32];
- av_get_channel_layout_string(name, sizeof(name), avccontext->channels,
- avccontext->channel_layout);
- av_log(avccontext, AV_LOG_ERROR, "%s not supported by Vorbis: "
+ av_get_channel_layout_string(name, sizeof(name), avctx->channels,
+ avctx->channel_layout);
+ av_log(avctx, AV_LOG_ERROR, "%s not supported by Vorbis: "
"output stream will have incorrect "
"channel layout.\n", name);
} else {
- av_log(avccontext, AV_LOG_WARNING, "No channel layout specified. The encoder "
+ av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder "
"will use Vorbis channel layout for "
- "%d channels.\n", avccontext->channels);
+ "%d channels.\n", avctx->channels);
}
}
@@ -155,59 +173,64 @@ static int xiph_len(int l)
return 1 + l / 255 + l;
}
-static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext)
+static av_cold int oggvorbis_encode_close(AVCodecContext *avctx)
{
- OggVorbisContext *context = avccontext->priv_data;
-/* ogg_packet op ; */
+ OggVorbisContext *s = avctx->priv_data;
- vorbis_analysis_wrote(&context->vd, 0); /* notify vorbisenc this is EOF */
+ /* notify vorbisenc this is EOF */
+ if (s->dsp_initialized)
+ vorbis_analysis_wrote(&s->vd, 0);
- vorbis_block_clear(&context->vb);
- vorbis_dsp_clear(&context->vd);
- vorbis_info_clear(&context->vi);
+ vorbis_block_clear(&s->vb);
+ vorbis_dsp_clear(&s->vd);
+ vorbis_info_clear(&s->vi);
- av_freep(&avccontext->coded_frame);
- av_freep(&avccontext->extradata);
+ av_fifo_free(s->pkt_fifo);
+ av_freep(&avctx->coded_frame);
+ av_freep(&avctx->extradata);
return 0;
}
-static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext)
+static av_cold int oggvorbis_encode_init(AVCodecContext *avctx)
{
- OggVorbisContext *context = avccontext->priv_data;
+ OggVorbisContext *s = avctx->priv_data;
ogg_packet header, header_comm, header_code;
uint8_t *p;
unsigned int offset;
int ret;
- vorbis_info_init(&context->vi);
- if ((ret = oggvorbis_init_encoder(&context->vi, avccontext))) {
- av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed\n");
+ vorbis_info_init(&s->vi);
+ if ((ret = oggvorbis_init_encoder(&s->vi, avctx))) {
+ av_log(avctx, AV_LOG_ERROR, "encoder setup failed\n");
goto error;
}
- if ((ret = vorbis_analysis_init(&context->vd, &context->vi))) {
+ if ((ret = vorbis_analysis_init(&s->vd, &s->vi))) {
+ av_log(avctx, AV_LOG_ERROR, "analysis init failed\n");
ret = vorbis_error_to_averror(ret);
goto error;
}
- if ((ret = vorbis_block_init(&context->vd, &context->vb))) {
+ s->dsp_initialized = 1;
+ if ((ret = vorbis_block_init(&s->vd, &s->vb))) {
+ av_log(avctx, AV_LOG_ERROR, "dsp init failed\n");
ret = vorbis_error_to_averror(ret);
goto error;
}
- vorbis_comment_init(&context->vc);
- vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT);
+ vorbis_comment_init(&s->vc);
+ vorbis_comment_add_tag(&s->vc, "encoder", LIBAVCODEC_IDENT);
- if ((ret = vorbis_analysis_headerout(&context->vd, &context->vc, &header,
- &header_comm, &header_code))) {
+ if ((ret = vorbis_analysis_headerout(&s->vd, &s->vc, &header, &header_comm,
+ &header_code))) {
ret = vorbis_error_to_averror(ret);
goto error;
}
- avccontext->extradata_size =
- 1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) +
- header_code.bytes;
- p = avccontext->extradata =
- av_malloc(avccontext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ avctx->extradata_size = 1 + xiph_len(header.bytes) +
+ xiph_len(header_comm.bytes) +
+ header_code.bytes;
+ p = avctx->extradata = av_malloc(avctx->extradata_size +
+ FF_INPUT_BUFFER_PADDING_SIZE);
if (!p) {
ret = AVERROR(ENOMEM);
goto error;
@@ -222,100 +245,107 @@ static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext)
offset += header_comm.bytes;
memcpy(&p[offset], header_code.packet, header_code.bytes);
offset += header_code.bytes;
- assert(offset == avccontext->extradata_size);
+ assert(offset == avctx->extradata_size);
-#if 0
- vorbis_block_clear(&context->vb);
- vorbis_dsp_clear(&context->vd);
- vorbis_info_clear(&context->vi);
-#endif
- vorbis_comment_clear(&context->vc);
+ vorbis_comment_clear(&s->vc);
- avccontext->frame_size = OGGVORBIS_FRAME_SIZE;
+ avctx->frame_size = OGGVORBIS_FRAME_SIZE;
+
+ s->pkt_fifo = av_fifo_alloc(BUFFER_SIZE);
+ if (!s->pkt_fifo) {
+ ret = AVERROR(ENOMEM);
+ goto error;
+ }
- avccontext->coded_frame = avcodec_alloc_frame();
- if (!avccontext->coded_frame) {
+ avctx->coded_frame = avcodec_alloc_frame();
+ if (!avctx->coded_frame) {
ret = AVERROR(ENOMEM);
goto error;
}
return 0;
error:
- oggvorbis_encode_close(avccontext);
+ oggvorbis_encode_close(avctx);
return ret;
}
-static int oggvorbis_encode_frame(AVCodecContext *avccontext,
- unsigned char *packets,
+static int oggvorbis_encode_frame(AVCodecContext *avctx, unsigned char *packets,
int buf_size, void *data)
{
- OggVorbisContext *context = avccontext->priv_data;
+ OggVorbisContext *s = avctx->priv_data;
ogg_packet op;
- signed short *audio = data;
- int l;
+ float *audio = data;
+ int pkt_size, ret;
+ /* send samples to libvorbis */
if (data) {
- const int samples = avccontext->frame_size;
+ const int samples = avctx->frame_size;
float **buffer;
- int c, channels = context->vi.channels;
+ int c, channels = s->vi.channels;
- buffer = vorbis_analysis_buffer(&context->vd, samples);
+ buffer = vorbis_analysis_buffer(&s->vd, samples);
for (c = 0; c < channels; c++) {
+ int i;
int co = (channels > 8) ? c :
ff_vorbis_encoding_channel_layout_offsets[channels - 1][c];
- for (l = 0; l < samples; l++)
- buffer[c][l] = audio[l * channels + co] / 32768.f;
+ for (i = 0; i < samples; i++)
+ buffer[c][i] = audio[i * channels + co];
+ }
+ if ((ret = vorbis_analysis_wrote(&s->vd, samples)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n");
+ return vorbis_error_to_averror(ret);
}
- vorbis_analysis_wrote(&context->vd, samples);
} else {
- if (!context->eof)
- vorbis_analysis_wrote(&context->vd, 0);
- context->eof = 1;
+ if (!s->eof)
+ if ((ret = vorbis_analysis_wrote(&s->vd, 0)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n");
+ return vorbis_error_to_averror(ret);
+ }
+ s->eof = 1;
}
- while (vorbis_analysis_blockout(&context->vd, &context->vb) == 1) {
- vorbis_analysis(&context->vb, NULL);
- vorbis_bitrate_addblock(&context->vb);
-
- while (vorbis_bitrate_flushpacket(&context->vd, &op)) {
- /* i'd love to say the following line is a hack, but sadly it's
- * not, apparently the end of stream decision is in libogg. */
- if (op.bytes == 1 && op.e_o_s)
- continue;
- if (context->buffer_index + sizeof(ogg_packet) + op.bytes > BUFFER_SIZE) {
- av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n");
- return AVERROR(EINVAL);
+ /* retrieve available packets from libvorbis */
+ while ((ret = vorbis_analysis_blockout(&s->vd, &s->vb)) == 1) {
+ if ((ret = vorbis_analysis(&s->vb, NULL)) < 0)
+ break;
+ if ((ret = vorbis_bitrate_addblock(&s->vb)) < 0)
+ break;
+
+ /* add any available packets to the output packet buffer */
+ while ((ret = vorbis_bitrate_flushpacket(&s->vd, &op)) == 1) {
+ if (av_fifo_space(s->pkt_fifo) < sizeof(ogg_packet) + op.bytes) {
+ av_log(avctx, AV_LOG_ERROR, "packet buffer is too small\n");
+ return AVERROR_BUG;
}
- memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet));
- context->buffer_index += sizeof(ogg_packet);
- memcpy(context->buffer + context->buffer_index, op.packet, op.bytes);
- context->buffer_index += op.bytes;
-// av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes);
+ av_fifo_generic_write(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
+ av_fifo_generic_write(s->pkt_fifo, op.packet, op.bytes, NULL);
+ }
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "error getting available packets\n");
+ break;
}
}
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "error getting available packets\n");
+ return vorbis_error_to_averror(ret);
+ }
- l = 0;
- if (context->buffer_index) {
- ogg_packet *op2 = (ogg_packet *)context->buffer;
- op2->packet = context->buffer + sizeof(ogg_packet);
-
- l = op2->bytes;
- avccontext->coded_frame->pts = ff_samples_to_time_base(avccontext,
- op2->granulepos);
- //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate
-
- if (l > buf_size) {
- av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n");
+ /* output then next packet from the output buffer, if available */
+ pkt_size = 0;
+ if (av_fifo_size(s->pkt_fifo) >= sizeof(ogg_packet)) {
+ av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL);
+ pkt_size = op.bytes;
+ // FIXME: we should use the user-supplied pts and duration
+ avctx->coded_frame->pts = ff_samples_to_time_base(avctx,
+ op.granulepos);
+ if (pkt_size > buf_size) {
+ av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
return AVERROR(EINVAL);
}
-
- memcpy(packets, op2->packet, l);
- context->buffer_index -= l + sizeof(ogg_packet);
- memmove(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index);
-// av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l);
+ av_fifo_generic_read(s->pkt_fifo, packets, pkt_size, NULL);
}
- return l;
+ return pkt_size;
}
AVCodec ff_libvorbis_encoder = {
@@ -327,7 +357,9 @@ AVCodec ff_libvorbis_encoder = {
.encode = oggvorbis_encode_frame,
.close = oggvorbis_encode_close,
.capabilities = CODEC_CAP_DELAY,
- .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
+ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT,
+ AV_SAMPLE_FMT_NONE },
.long_name = NULL_IF_CONFIG_SMALL("libvorbis Vorbis"),
.priv_class = &class,
+ .defaults = defaults,
};
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index cc77fd1548..ddb9a34b37 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -939,6 +939,7 @@ static void mpeg1_encode_block(MpegEncContext *s,
static const AVOption mpeg1_options[] = {
COMMON_OPTS
+ FF_MPV_COMMON_OPTS
{ NULL },
};
@@ -946,6 +947,7 @@ static const AVOption mpeg2_options[] = {
COMMON_OPTS
{ "non_linear_quant", "Use nonlinear quantizer.", OFFSET(q_scale_type), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
{ "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ FF_MPV_COMMON_OPTS
{ NULL },
};
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 343c31644c..e31d2ce363 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -430,7 +430,7 @@ static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64],
{
int cbp = 0, i;
- if (s->flags & CODEC_FLAG_CBP_RD) {
+ if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
int score = 0;
const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
@@ -1330,6 +1330,7 @@ void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
static const AVOption options[] = {
{ "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
{ "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
+ FF_MPV_COMMON_OPTS
{ NULL },
};
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index 75a3c5d372..00565875fc 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -31,6 +31,7 @@
#include "get_bits.h"
#include "mathops.h"
#include "mpegaudiodsp.h"
+#include "dsputil.h"
/*
* TODO:
@@ -82,6 +83,7 @@ typedef struct MPADecodeContext {
int err_recognition;
AVCodecContext* avctx;
MPADSPContext mpadsp;
+ DSPContext dsp;
AVFrame frame;
} MPADecodeContext;
@@ -434,6 +436,7 @@ static av_cold int decode_init(AVCodecContext * avctx)
s->avctx = avctx;
ff_mpadsp_init(&s->mpadsp);
+ ff_dsputil_init(&s->dsp, avctx);
avctx->sample_fmt= OUT_FMT;
s->err_recognition = avctx->err_recognition;
@@ -1155,6 +1158,9 @@ found2:
/* ms stereo ONLY */
/* NOTE: the 1/sqrt(2) normalization factor is included in the
global gain */
+#if CONFIG_FLOAT
+ s-> dsp.butterflies_float(g0->sb_hybrid, g1->sb_hybrid, 576);
+#else
tab0 = g0->sb_hybrid;
tab1 = g1->sb_hybrid;
for (i = 0; i < 576; i++) {
@@ -1163,6 +1169,7 @@ found2:
tab0[i] = tmp0 + tmp1;
tab1[i] = tmp0 - tmp1;
}
+#endif
}
}
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 06c56c9c5a..02f15da433 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -38,6 +38,8 @@
#include "rl.h"
#include "libavutil/timecode.h"
+#include "libavutil/opt.h"
+
#define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
enum OutputFormat {
@@ -695,6 +697,9 @@ typedef struct MpegEncContext {
int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
+
+ int mpv_flags; ///< flags set by private options
+ int quantizer_noise_shaping;
} MpegEncContext;
#define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \
@@ -702,6 +707,36 @@ typedef struct MpegEncContext {
&new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\
: NULL)
+/* mpegvideo_enc common options */
+#define FF_MPV_FLAG_SKIP_RD 0x0001
+#define FF_MPV_FLAG_STRICT_GOP 0x0002
+#define FF_MPV_FLAG_QP_RD 0x0004
+#define FF_MPV_FLAG_CBP_RD 0x0008
+
+#define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x)
+#define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
+#define FF_MPV_COMMON_OPTS \
+{ "mpv_flags", "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "mpv_flags" },\
+{ "skip_rd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_SKIP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
+{ "strict_gop", "Strictly enforce gop size", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
+{ "qp_rd", "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_QP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
+{ "cbp_rd", "use rate distortion optimization for CBP", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_CBP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\
+{ "luma_elim_threshold", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)",\
+ FF_MPV_OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
+{ "chroma_elim_threshold", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)",\
+ FF_MPV_OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS },\
+{ "quantizer_noise_shaping", NULL, FF_MPV_OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS },
+
+extern const AVOption ff_mpv_generic_options[];
+
+#define FF_MPV_GENERIC_CLASS(name) \
+static const AVClass name ## _class = {\
+ .class_name = #name " encoder",\
+ .item_name = av_default_item_name,\
+ .option = ff_mpv_generic_options,\
+ .version = LIBAVUTIL_VERSION_INT,\
+};
+
void ff_MPV_decode_defaults(MpegEncContext *s);
int ff_MPV_common_init(MpegEncContext *s);
void ff_MPV_common_end(MpegEncContext *s);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 0441d8fa35..c780ffb598 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -63,6 +63,11 @@ static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int
static uint8_t default_mv_penalty[MAX_FCODE + 1][MAX_MV * 2 + 1];
static uint8_t default_fcode_tab[MAX_MV * 2 + 1];
+const AVOption ff_mpv_generic_options[] = {
+ FF_MPV_COMMON_OPTS
+ { NULL },
+};
+
void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64],
uint16_t (*qmat16)[2][64],
const uint16_t *quant_matrix,
@@ -352,8 +357,12 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
s->flags2 = avctx->flags2;
s->max_b_frames = avctx->max_b_frames;
s->codec_id = avctx->codec->id;
- s->luma_elim_threshold = avctx->luma_elim_threshold;
- s->chroma_elim_threshold = avctx->chroma_elim_threshold;
+#if FF_API_MPV_GLOBAL_OPTS
+ if (avctx->luma_elim_threshold)
+ s->luma_elim_threshold = avctx->luma_elim_threshold;
+ if (avctx->chroma_elim_threshold)
+ s->chroma_elim_threshold = avctx->chroma_elim_threshold;
+#endif
s->strict_std_compliance = avctx->strict_std_compliance;
s->quarter_sample = (avctx->flags & CODEC_FLAG_QPEL) != 0;
s->mpeg_quant = avctx->mpeg_quant;
@@ -373,13 +382,18 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
/* Fixed QSCALE */
s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);
+#if FF_API_MPV_GLOBAL_OPTS
+ if (s->flags & CODEC_FLAG_QP_RD)
+ s->mpv_flags |= FF_MPV_FLAG_QP_RD;
+#endif
+
s->adaptive_quant = (s->avctx->lumi_masking ||
s->avctx->dark_masking ||
s->avctx->temporal_cplx_masking ||
s->avctx->spatial_cplx_masking ||
s->avctx->p_masking ||
s->avctx->border_masking ||
- (s->flags & CODEC_FLAG_QP_RD)) &&
+ (s->mpv_flags & FF_MPV_FLAG_QP_RD)) &&
!s->fixed_qscale;
s->loop_filter = !!(s->flags & CODEC_FLAG_LOOP_FILTER);
@@ -488,12 +502,17 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
return -1;
}
- if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) {
+#if FF_API_MPV_GLOBAL_OPTS
+ if (s->flags & CODEC_FLAG_CBP_RD)
+ s->mpv_flags |= FF_MPV_FLAG_CBP_RD;
+#endif
+
+ if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) {
av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
return -1;
}
- if ((s->flags & CODEC_FLAG_QP_RD) &&
+ if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) &&
s->avctx->mb_decision != FF_MB_DECISION_RD) {
av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
return -1;
@@ -610,6 +629,15 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
}
s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
+#if FF_API_MPV_GLOBAL_OPTS
+ if (avctx->flags2 & CODEC_FLAG2_SKIP_RD)
+ s->mpv_flags |= FF_MPV_FLAG_SKIP_RD;
+ if (avctx->flags2 & CODEC_FLAG2_STRICT_GOP)
+ s->mpv_flags |= FF_MPV_FLAG_STRICT_GOP;
+ if (avctx->quantizer_noise_shaping)
+ s->quantizer_noise_shaping = avctx->quantizer_noise_shaping;
+#endif
+
switch (avctx->codec->id) {
case CODEC_ID_MPEG1VIDEO:
s->out_format = FMT_MPEG1;
@@ -1301,7 +1329,7 @@ static int select_input_picture(MpegEncContext *s)
}
if (s->picture_in_gop_number + b_frames >= s->gop_size) {
- if ((s->flags2 & CODEC_FLAG2_STRICT_GOP) &&
+ if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&
s->gop_size > s->picture_in_gop_number) {
b_frames = s->gop_size - s->picture_in_gop_number - 1;
} else {
@@ -1726,7 +1754,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
s->lambda = s->lambda_table[mb_xy];
update_qscale(s);
- if (!(s->flags & CODEC_FLAG_QP_RD)) {
+ if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) {
s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy];
s->dquant = s->qscale - last_qp;
@@ -1746,7 +1774,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
}
}
ff_set_qscale(s, last_qp + s->dquant);
- } else if (s->flags & CODEC_FLAG_QP_RD)
+ } else if (s->mpv_flags & FF_MPV_FLAG_QP_RD)
ff_set_qscale(s, s->qscale + s->dquant);
wrap_y = s->linesize;
@@ -1934,7 +1962,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
}
}
- if (s->avctx->quantizer_noise_shaping) {
+ if (s->quantizer_noise_shaping) {
if (!skip_dct[0])
get_visual_weight(weight[0], ptr_y , wrap_y);
if (!skip_dct[1])
@@ -1975,7 +2003,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
} else
s->block_last_index[i] = -1;
}
- if (s->avctx->quantizer_noise_shaping) {
+ if (s->quantizer_noise_shaping) {
for (i = 0; i < mb_block_count; i++) {
if (!skip_dct[i]) {
s->block_last_index[i] =
@@ -1992,7 +2020,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
for (i = 4; i < mb_block_count; i++)
dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);
- if (s->flags & CODEC_FLAG_CBP_RD) {
+ if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
for (i = 0; i < mb_block_count; i++) {
if (s->block_last_index[i] == -1)
s->coded_score[i] = INT_MAX / 256;
@@ -2513,7 +2541,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
s->mb_skipped=0;
s->dquant=0; //only for QP_RD
- if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD
+ if (mb_type & (mb_type-1) || (s->mpv_flags & FF_MPV_FLAG_QP_RD)) { // more than 1 MB type possible or FF_MPV_FLAG_QP_RD
int next_block=0;
int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
@@ -2650,7 +2678,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
}
}
- if((s->flags & CODEC_FLAG_QP_RD) && dmin < INT_MAX){
+ if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && dmin < INT_MAX) {
if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD
const int last_qp= backup_s.qscale;
int qpi, qp, dc[6];
@@ -2715,7 +2743,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
&dmin, &next_block, 0, 0);
}
- if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){
+ if (!best_s.mb_intra && s->mpv_flags & FF_MPV_FLAG_SKIP_RD) {
int coded=0;
for(i=0; i<6; i++)
coded |= s->block_last_index[i];
@@ -3755,7 +3783,7 @@ STOP_TIMER("init rem[]")
#ifdef REFINE_STATS
{START_TIMER
#endif
- analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3;
+ analyze_gradient = last_non_zero > 2 || s->quantizer_noise_shaping >= 3;
if(analyze_gradient){
#ifdef REFINE_STATS
@@ -3813,7 +3841,7 @@ STOP_TIMER("dct")}
const int level= block[j];
int change, old_coeff;
- if(s->avctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1)
+ if(s->quantizer_noise_shaping < 3 && i > last_non_zero + 1)
break;
if(level){
@@ -3831,7 +3859,7 @@ STOP_TIMER("dct")}
int score, new_coeff, unquant_change;
score=0;
- if(s->avctx->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))
+ if(s->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))
continue;
if(new_level){
@@ -4089,6 +4117,7 @@ int ff_dct_quantize_c(MpegEncContext *s,
static const AVOption h263_options[] = {
{ "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
{ "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
+ FF_MPV_COMMON_OPTS
{ NULL },
};
@@ -4117,6 +4146,7 @@ static const AVOption h263p_options[] = {
{ "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
{ "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
{ "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
+ FF_MPV_COMMON_OPTS
{ NULL },
};
static const AVClass h263p_class = {
@@ -4140,6 +4170,8 @@ AVCodec ff_h263p_encoder = {
.priv_class = &h263p_class,
};
+FF_MPV_GENERIC_CLASS(msmpeg4v2)
+
AVCodec ff_msmpeg4v2_encoder = {
.name = "msmpeg4v2",
.type = AVMEDIA_TYPE_VIDEO,
@@ -4150,8 +4182,11 @@ AVCodec ff_msmpeg4v2_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
+ .priv_class = &msmpeg4v2_class,
};
+FF_MPV_GENERIC_CLASS(msmpeg4v3)
+
AVCodec ff_msmpeg4v3_encoder = {
.name = "msmpeg4",
.type = AVMEDIA_TYPE_VIDEO,
@@ -4162,8 +4197,11 @@ AVCodec ff_msmpeg4v3_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
+ .priv_class = &msmpeg4v3_class,
};
+FF_MPV_GENERIC_CLASS(wmv1)
+
AVCodec ff_wmv1_encoder = {
.name = "wmv1",
.type = AVMEDIA_TYPE_VIDEO,
@@ -4174,4 +4212,5 @@ AVCodec ff_wmv1_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
+ .priv_class = &wmv1_class,
};
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 3be5861dde..04277dba4d 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -98,12 +98,16 @@ static const AVOption options[]={
{"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"},
{"bitexact", "use only bitexact stuff (except (i)dct)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_BITEXACT }, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_AC_PRED }, INT_MIN, INT_MAX, V|E, "flags"},
-{"cbp", "use rate distortion optimization for cbp", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
-{"qprd", "use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
+#if FF_API_MPV_GLOBAL_OPTS
+{"cbp", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
+{"qprd", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"},
+#endif
{"ilme", "interlaced motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_ME }, INT_MIN, INT_MAX, V|E, "flags"},
{"cgop", "closed gop", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CLOSED_GOP }, INT_MIN, INT_MAX, V|E, "flags"},
{"fast", "allow non spec compliant speedup tricks", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FAST }, INT_MIN, INT_MAX, V|E, "flags2"},
-{"sgop", "strictly enforce gop size", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"},
+#if FF_API_MPV_GLOBAL_OPTS
+{"sgop", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"},
+#endif
{"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"},
{"local_header", "place global headers at every keyframe instead of in extradata", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"},
{"showall", "Show all frames before the first keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SHOW_ALL }, INT_MIN, INT_MAX, V|D, "flags2"},
@@ -167,8 +171,10 @@ static const AVOption options[]={
{"dc_clip", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"},
{"ms", "workaround various bugs in microsofts broken decoders", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_MS }, INT_MIN, INT_MAX, V|D, "bug"},
{"trunc", "trancated frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"},
+#if FF_API_MPV_GLOBAL_OPTS
{"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
{"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+#endif
{"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
{"very", "strictly conform to a older more strict version of the spec or reference software", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_VERY_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"},
@@ -194,8 +200,8 @@ static const AVOption options[]={
{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
{"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
{"rc_eq", "set rate control equation", OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},
-{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+{"maxrate", "set max bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
+{"minrate", "set min bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|E},
{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E},
{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), AV_OPT_TYPE_FLOAT, {.dbl = -0.8 }, -FLT_MAX, FLT_MAX, V|E},
@@ -296,7 +302,9 @@ static const AVOption options[]={
{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
{"ibias", "intra quant bias", OFFSET(intra_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
{"pbias", "inter quant bias", OFFSET(inter_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E},
+#if FF_API_COLOR_TABLE_ID
{"color_table_id", NULL, OFFSET(color_table_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX},
+#endif
{"global_quality", NULL, OFFSET(global_quality), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
{"coder", NULL, OFFSET(coder_type), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "coder"},
{"vlc", "variable length coder / huffman coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_VLC }, INT_MIN, INT_MAX, V|E, "coder"},
@@ -317,10 +325,14 @@ static const AVOption options[]={
{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), AV_OPT_TYPE_INT, {.dbl = 31*FF_QP2LAMBDA }, 0, INT_MAX, V|E},
{"nr", "noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+#if FF_API_INTER_THRESHOLD
{"inter_threshold", NULL, OFFSET(inter_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+#endif
{"flags2", NULL, OFFSET(flags2), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT}, 0, UINT_MAX, V|A|E|D, "flags2"},
{"error", NULL, OFFSET(error_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
-{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+#if FF_API_MPV_GLOBAL_OPTS
+{"qns", "deprecated, use mpegvideo private options instead", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+#endif
{"threads", NULL, OFFSET(thread_count), AV_OPT_TYPE_INT, {.dbl = 1 }, 0, INT_MAX, V|E|D, "threads"},
{"auto", "detect a good number of threads", 0, AV_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, V|E|D, "threads"},
{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
@@ -366,7 +378,9 @@ static const AVOption options[]={
{"refs", "reference frames to consider for motion compensation", OFFSET(refs), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},
{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
-{"skiprd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},
+#if FF_API_MPV_GLOBAL_OPTS
+{"skiprd", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"},
+#endif
{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), AV_OPT_TYPE_INT, {.dbl = 6 }, 0, INT_MAX, V|E},
{"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.dbl = 256 }, 0, INT_MAX, V|E},
{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.dbl = 40 }, 1, INT_MAX, V|E},
diff --git a/libavcodec/proresdec_lgpl.c b/libavcodec/proresdec_lgpl.c
index 882503a129..e358d7f9cb 100644
--- a/libavcodec/proresdec_lgpl.c
+++ b/libavcodec/proresdec_lgpl.c
@@ -165,6 +165,10 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
ctx->picture.top_field_first = ctx->frame_type & 1;
}
+ avctx->color_primaries = buf[14];
+ avctx->color_trc = buf[15];
+ avctx->colorspace = buf[16];
+
ctx->alpha_info = buf[17] & 0xf;
if (ctx->alpha_info)
av_log_missing_feature(avctx, "alpha channel", 0);
@@ -411,7 +415,7 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td,
int data_size, uint16_t *out_ptr,
int linesize, int mbs_per_slice,
int blocks_per_mb, int plane_size_factor,
- const int16_t *qmat)
+ const int16_t *qmat, int is_chroma)
{
GetBitContext gb;
DCTELEM *block_ptr;
@@ -431,18 +435,33 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td,
/* inverse quantization, inverse transform and output */
block_ptr = td->blocks;
- for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
- ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);
- block_ptr += 64;
- if (blocks_per_mb > 2) {
- ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);
+ if (!is_chroma) {
+ for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
+ ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ if (blocks_per_mb > 2) {
+ ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ }
+ ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
block_ptr += 64;
+ if (blocks_per_mb > 2) {
+ ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ }
}
- ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
- block_ptr += 64;
- if (blocks_per_mb > 2) {
- ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
+ } else {
+ for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {
+ ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);
block_ptr += 64;
+ if (blocks_per_mb > 2) {
+ ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);
+ block_ptr += 64;
+ }
}
}
}
@@ -523,7 +542,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata)
(uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize +
(mb_x_pos << 5)), y_linesize,
mbs_per_slice, 4, slice_width_factor + 2,
- td->qmat_luma_scaled);
+ td->qmat_luma_scaled, 0);
/* decode U chroma plane */
decode_slice_plane(ctx, td, buf + hdr_size + y_data_size, u_data_size,
@@ -531,7 +550,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata)
(mb_x_pos << ctx->mb_chroma_factor)),
u_linesize, mbs_per_slice, ctx->num_chroma_blocks,
slice_width_factor + ctx->chroma_factor - 1,
- td->qmat_chroma_scaled);
+ td->qmat_chroma_scaled, 1);
/* decode V chroma plane */
decode_slice_plane(ctx, td, buf + hdr_size + y_data_size + u_data_size,
@@ -540,7 +559,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata)
(mb_x_pos << ctx->mb_chroma_factor)),
v_linesize, mbs_per_slice, ctx->num_chroma_blocks,
slice_width_factor + ctx->chroma_factor - 1,
- td->qmat_chroma_scaled);
+ td->qmat_chroma_scaled, 1);
return 0;
}
diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
index 375dc5261c..7920d65ed1 100644
--- a/libavcodec/proresenc_kostya.c
+++ b/libavcodec/proresenc_kostya.c
@@ -171,7 +171,7 @@ typedef struct ProresContext {
static void get_slice_data(ProresContext *ctx, const uint16_t *src,
int linesize, int x, int y, int w, int h,
DCTELEM *blocks,
- int mbs_per_slice, int blocks_per_mb)
+ int mbs_per_slice, int blocks_per_mb, int is_chroma)
{
const uint16_t *esrc;
const int mb_width = 4 * blocks_per_mb;
@@ -189,37 +189,50 @@ static void get_slice_data(ProresContext *ctx, const uint16_t *src,
elinesize = linesize;
} else {
int bw, bh, pix;
- const int estride = 16 / sizeof(*ctx->emu_buf);
esrc = ctx->emu_buf;
- elinesize = 16;
+ elinesize = 16 * sizeof(*ctx->emu_buf);
bw = FFMIN(w - x, mb_width);
bh = FFMIN(h - y, 16);
for (j = 0; j < bh; j++) {
- memcpy(ctx->emu_buf + j * estride, src + j * linesize,
+ memcpy(ctx->emu_buf + j * 16,
+ (const uint8_t*)src + j * linesize,
bw * sizeof(*src));
- pix = ctx->emu_buf[j * estride + bw - 1];
+ pix = ctx->emu_buf[j * 16 + bw - 1];
for (k = bw; k < mb_width; k++)
- ctx->emu_buf[j * estride + k] = pix;
+ ctx->emu_buf[j * 16 + k] = pix;
}
for (; j < 16; j++)
- memcpy(ctx->emu_buf + j * estride,
- ctx->emu_buf + (bh - 1) * estride,
+ memcpy(ctx->emu_buf + j * 16,
+ ctx->emu_buf + (bh - 1) * 16,
mb_width * sizeof(*ctx->emu_buf));
}
- ctx->dsp.fdct(esrc, elinesize, blocks);
- blocks += 64;
- if (blocks_per_mb > 2) {
- ctx->dsp.fdct(src + 8, linesize, blocks);
+ if (!is_chroma) {
+ ctx->dsp.fdct(esrc, elinesize, blocks);
blocks += 64;
- }
- ctx->dsp.fdct(src + linesize * 4, linesize, blocks);
- blocks += 64;
- if (blocks_per_mb > 2) {
- ctx->dsp.fdct(src + linesize * 4 + 8, linesize, blocks);
+ if (blocks_per_mb > 2) {
+ ctx->dsp.fdct(src + 8, linesize, blocks);
+ blocks += 64;
+ }
+ ctx->dsp.fdct(src + linesize * 4, linesize, blocks);
blocks += 64;
+ if (blocks_per_mb > 2) {
+ ctx->dsp.fdct(src + linesize * 4 + 8, linesize, blocks);
+ blocks += 64;
+ }
+ } else {
+ ctx->dsp.fdct(esrc, elinesize, blocks);
+ blocks += 64;
+ ctx->dsp.fdct(src + linesize * 4, linesize, blocks);
+ blocks += 64;
+ if (blocks_per_mb > 2) {
+ ctx->dsp.fdct(src + 8, linesize, blocks);
+ blocks += 64;
+ ctx->dsp.fdct(src + linesize * 4 + 8, linesize, blocks);
+ blocks += 64;
+ }
}
x += mb_width;
@@ -383,7 +396,7 @@ static int encode_slice(AVCodecContext *avctx, const AVFrame *pic,
get_slice_data(ctx, src, pic->linesize[i], xp, yp,
pwidth, avctx->height, ctx->blocks[0],
- mbs_per_slice, num_cblocks);
+ mbs_per_slice, num_cblocks, is_chroma);
sizes[i] = encode_slice_plane(ctx, pb, src, pic->linesize[i],
mbs_per_slice, ctx->blocks[0],
num_cblocks, plane_factor,
@@ -539,7 +552,7 @@ static int find_slice_quant(AVCodecContext *avctx, const AVFrame *pic,
get_slice_data(ctx, src, pic->linesize[i], xp, yp,
pwidth, avctx->height, ctx->blocks[i],
- mbs_per_slice, num_cblocks[i]);
+ mbs_per_slice, num_cblocks[i], is_chroma[i]);
}
for (q = min_quant; q < max_quant + 2; q++) {
@@ -676,9 +689,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
bytestream_put_be16 (&buf, avctx->height);
bytestream_put_byte (&buf, ctx->chroma_factor << 6); // frame flags
bytestream_put_byte (&buf, 0); // reserved
- bytestream_put_byte (&buf, 0); // primaries
- bytestream_put_byte (&buf, 0); // transfer function
- bytestream_put_byte (&buf, 6); // colour matrix - ITU-R BT.601-4
+ bytestream_put_byte (&buf, avctx->color_primaries);
+ bytestream_put_byte (&buf, avctx->color_trc);
+ bytestream_put_byte (&buf, avctx->colorspace);
bytestream_put_byte (&buf, 0x40); // source format and alpha information
bytestream_put_byte (&buf, 0); // reserved
bytestream_put_byte (&buf, 0x03); // matrix flags - both matrices are present
diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index 606a2ea95d..e3a595c5ac 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -424,7 +424,7 @@ static av_cold int qtrle_decode_init(AVCodecContext *avctx)
default:
av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n",
avctx->bits_per_coded_sample);
- break;
+ return AVERROR_INVALIDDATA;
}
avcodec_get_frame_defaults(&s->frame);
diff --git a/libavcodec/rpza.c b/libavcodec/rpza.c
index 4c87b3c1b2..635b4069ef 100644
--- a/libavcodec/rpza.c
+++ b/libavcodec/rpza.c
@@ -183,6 +183,8 @@ static void rpza_decode_stream(RpzaContext *s)
color4[1] |= ((11 * ta + 21 * tb) >> 5);
color4[2] |= ((21 * ta + 11 * tb) >> 5);
+ if (s->size - stream_ptr < n_blocks * 4)
+ return;
while (n_blocks--) {
block_ptr = row_ptr + pixel_ptr;
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
@@ -200,6 +202,8 @@ static void rpza_decode_stream(RpzaContext *s)
/* Fill block with 16 colors */
case 0x00:
+ if (s->size - stream_ptr < 16)
+ return;
block_ptr = row_ptr + pixel_ptr;
for (pixel_y = 0; pixel_y < 4; pixel_y++) {
for (pixel_x = 0; pixel_x < 4; pixel_x++){
diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c
index add7855b7f..3a4ee387ba 100644
--- a/libavcodec/rv10enc.c
+++ b/libavcodec/rv10enc.c
@@ -56,6 +56,8 @@ void ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number)
put_bits(&s->pb, 3, 0); /* ignored */
}
+FF_MPV_GENERIC_CLASS(rv10)
+
AVCodec ff_rv10_encoder = {
.name = "rv10",
.type = AVMEDIA_TYPE_VIDEO,
@@ -66,4 +68,5 @@ AVCodec ff_rv10_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"),
+ .priv_class = &rv10_class,
};
diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c
index 1eb21803ba..db5c86b8b2 100644
--- a/libavcodec/rv20enc.c
+++ b/libavcodec/rv20enc.c
@@ -57,6 +57,8 @@ void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number){
}
}
+FF_MPV_GENERIC_CLASS(rv20)
+
AVCodec ff_rv20_encoder = {
.name = "rv20",
.type = AVMEDIA_TYPE_VIDEO,
@@ -67,4 +69,5 @@ AVCodec ff_rv20_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
+ .priv_class = &rv20_class,
};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index ca0efb4fed..238866be6b 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -60,5 +60,14 @@
#ifndef FF_API_OLD_ENCODE_VIDEO
#define FF_API_OLD_ENCODE_VIDEO (LIBAVCODEC_VERSION_MAJOR < 55)
#endif
+#ifndef FF_API_MPV_GLOBAL_OPTS
+#define FF_API_MPV_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
+#ifndef FF_API_COLOR_TABLE_ID
+#define FF_API_COLOR_TABLE_ID (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
+#ifndef FF_API_INTER_THRESHOLD
+#define FF_API_INTER_THRESHOLD (LIBAVCODEC_VERSION_MAJOR < 55)
+#endif
#endif /* AVCODEC_VERSION_H */
diff --git a/libavcodec/vmnc.c b/libavcodec/vmnc.c
index ac0b8252e4..a716b29b3c 100644
--- a/libavcodec/vmnc.c
+++ b/libavcodec/vmnc.c
@@ -484,7 +484,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp);
- return AVERROR_PATCHWELCOME;
+ return AVERROR_INVALIDDATA;
}
return 0;
diff --git a/libavcodec/vp5.c b/libavcodec/vp5.c
index dc3c833f44..4c985525a2 100644
--- a/libavcodec/vp5.c
+++ b/libavcodec/vp5.c
@@ -57,6 +57,11 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
}
rows = vp56_rac_gets(c, 8); /* number of stored macroblock rows */
cols = vp56_rac_gets(c, 8); /* number of stored macroblock cols */
+ if (!rows || !cols) {
+ av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n",
+ cols << 4, rows << 4);
+ return 0;
+ }
vp56_rac_gets(c, 8); /* number of displayed macroblock rows */
vp56_rac_gets(c, 8); /* number of displayed macroblock cols */
vp56_rac_gets(c, 2);
diff --git a/libavcodec/vp6.c b/libavcodec/vp6.c
index b9a9b237b6..8b975029d8 100644
--- a/libavcodec/vp6.c
+++ b/libavcodec/vp6.c
@@ -77,6 +77,10 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
cols = buf[3]; /* number of stored macroblock cols */
/* buf[4] is number of displayed macroblock rows */
/* buf[5] is number of displayed macroblock cols */
+ if (!rows || !cols) {
+ av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n", cols << 4, rows << 4);
+ return 0;
+ }
if (!s->macroblocks || /* first frame */
16*cols != s->avctx->coded_width ||
@@ -97,7 +101,7 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
vrt_shift = 5;
s->sub_version = sub_version;
} else {
- if (!s->sub_version)
+ if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height)
return 0;
if (separated_coeff || !s->filter_header) {