lavc: Move {min,max}_prediction_order to codec private options

These options are only used by alac and flac.
They are very codec-specific options, so deprecate the global variants.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
pull/172/merge
Vittorio Giovara 9 years ago
parent 936f0d98f8
commit 243df1351d
  1. 27
      libavcodec/alacenc.c
  2. 14
      libavcodec/avcodec.h
  3. 33
      libavcodec/flacenc.c
  4. 2
      libavcodec/options_table.h

@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/opt.h"
#include "avcodec.h" #include "avcodec.h"
#include "put_bits.h" #include "put_bits.h"
#include "internal.h" #include "internal.h"
@ -57,6 +59,7 @@ typedef struct AlacLPCContext {
} AlacLPCContext; } AlacLPCContext;
typedef struct AlacEncodeContext { typedef struct AlacEncodeContext {
AVCodecContext *avctx;
int frame_size; /**< current frame size */ int frame_size; /**< current frame size */
int verbatim; /**< current frame verbatim mode flag */ int verbatim; /**< current frame verbatim mode flag */
int compression_level; int compression_level;
@ -73,7 +76,6 @@ typedef struct AlacEncodeContext {
RiceContext rc; RiceContext rc;
AlacLPCContext lpc[2]; AlacLPCContext lpc[2];
LPCContext lpc_ctx; LPCContext lpc_ctx;
AVCodecContext *avctx;
} AlacEncodeContext; } AlacEncodeContext;
@ -544,7 +546,8 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
AV_WB8(alac_extradata+20, s->rc.k_modifier); AV_WB8(alac_extradata+20, s->rc.k_modifier);
} }
s->min_prediction_order = DEFAULT_MIN_PRED_ORDER; #if FF_API_PRIVATE_OPT
FF_DISABLE_DEPRECATION_WARNINGS
if (avctx->min_prediction_order >= 0) { if (avctx->min_prediction_order >= 0) {
if (avctx->min_prediction_order < MIN_LPC_ORDER || if (avctx->min_prediction_order < MIN_LPC_ORDER ||
avctx->min_prediction_order > ALAC_MAX_LPC_ORDER) { avctx->min_prediction_order > ALAC_MAX_LPC_ORDER) {
@ -557,7 +560,6 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
s->min_prediction_order = avctx->min_prediction_order; s->min_prediction_order = avctx->min_prediction_order;
} }
s->max_prediction_order = DEFAULT_MAX_PRED_ORDER;
if (avctx->max_prediction_order >= 0) { if (avctx->max_prediction_order >= 0) {
if (avctx->max_prediction_order < MIN_LPC_ORDER || if (avctx->max_prediction_order < MIN_LPC_ORDER ||
avctx->max_prediction_order > ALAC_MAX_LPC_ORDER) { avctx->max_prediction_order > ALAC_MAX_LPC_ORDER) {
@ -569,6 +571,8 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
s->max_prediction_order = avctx->max_prediction_order; s->max_prediction_order = avctx->max_prediction_order;
} }
FF_ENABLE_DEPRECATION_WARNINGS
#endif
if (s->max_prediction_order < s->min_prediction_order) { if (s->max_prediction_order < s->min_prediction_order) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
@ -634,12 +638,29 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
return 0; return 0;
} }
#define OFFSET(x) offsetof(AlacEncodeContext, x)
#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
{ "min_prediction_order", NULL, OFFSET(min_prediction_order), AV_OPT_TYPE_INT, { .i64 = DEFAULT_MIN_PRED_ORDER }, MIN_LPC_ORDER, ALAC_MAX_LPC_ORDER, AE },
{ "max_prediction_order", NULL, OFFSET(max_prediction_order), AV_OPT_TYPE_INT, { .i64 = DEFAULT_MAX_PRED_ORDER }, MIN_LPC_ORDER, ALAC_MAX_LPC_ORDER, AE },
{ NULL },
};
static const AVClass alacenc_class = {
.class_name = "alacenc",
.item_name = av_default_item_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
};
AVCodec ff_alac_encoder = { AVCodec ff_alac_encoder = {
.name = "alac", .name = "alac",
.long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
.type = AVMEDIA_TYPE_AUDIO, .type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_ALAC, .id = AV_CODEC_ID_ALAC,
.priv_data_size = sizeof(AlacEncodeContext), .priv_data_size = sizeof(AlacEncodeContext),
.priv_class = &alacenc_class,
.init = alac_encode_init, .init = alac_encode_init,
.encode2 = alac_encode_frame, .encode2 = alac_encode_frame,
.close = alac_encode_close, .close = alac_encode_close,

@ -2386,19 +2386,15 @@ typedef struct AVCodecContext {
*/ */
int trellis; int trellis;
/** #if FF_API_PRIVATE_OPT
* - encoding: Set by user. /** @deprecated use encoder private options instead */
* - decoding: unused attribute_deprecated
*/
int min_prediction_order; int min_prediction_order;
/** /** @deprecated use encoder private options instead */
* - encoding: Set by user. attribute_deprecated
* - decoding: unused
*/
int max_prediction_order; int max_prediction_order;
#if FF_API_PRIVATE_OPT
/** @deprecated use encoder private options instead */ /** @deprecated use encoder private options instead */
attribute_deprecated attribute_deprecated
int64_t timecode_frame_start; int64_t timecode_frame_start;

@ -325,9 +325,9 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
if (s->options.max_partition_order < 0) if (s->options.max_partition_order < 0)
s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level]; s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level];
if (s->options.lpc_type == FF_LPC_TYPE_NONE) { #if FF_API_PRIVATE_OPT
s->options.min_prediction_order = 0; FF_DISABLE_DEPRECATION_WARNINGS
} else if (avctx->min_prediction_order >= 0) { if (avctx->min_prediction_order >= 0) {
if (s->options.lpc_type == FF_LPC_TYPE_FIXED) { if (s->options.lpc_type == FF_LPC_TYPE_FIXED) {
if (avctx->min_prediction_order > MAX_FIXED_ORDER) { if (avctx->min_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_WARNING, av_log(avctx, AV_LOG_WARNING,
@ -343,9 +343,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
} }
s->options.min_prediction_order = avctx->min_prediction_order; s->options.min_prediction_order = avctx->min_prediction_order;
} }
if (s->options.lpc_type == FF_LPC_TYPE_NONE) { if (avctx->max_prediction_order >= 0) {
s->options.max_prediction_order = 0;
} else if (avctx->max_prediction_order >= 0) {
if (s->options.lpc_type == FF_LPC_TYPE_FIXED) { if (s->options.lpc_type == FF_LPC_TYPE_FIXED) {
if (avctx->max_prediction_order > MAX_FIXED_ORDER) { if (avctx->max_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_WARNING, av_log(avctx, AV_LOG_WARNING,
@ -361,6 +359,26 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
} }
s->options.max_prediction_order = avctx->max_prediction_order; s->options.max_prediction_order = avctx->max_prediction_order;
} }
FF_ENABLE_DEPRECATION_WARNINGS
#endif
if (s->options.lpc_type == FF_LPC_TYPE_NONE) {
s->options.min_prediction_order = 0;
s->options.max_prediction_order = 0;
} else if (s->options.lpc_type == FF_LPC_TYPE_FIXED) {
if (s->options.min_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_WARNING,
"invalid min prediction order %d, clamped to %d\n",
s->options.min_prediction_order, MAX_FIXED_ORDER);
s->options.min_prediction_order = MAX_FIXED_ORDER;
}
if (s->options.max_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_WARNING,
"invalid max prediction order %d, clamped to %d\n",
s->options.max_prediction_order, MAX_FIXED_ORDER);
s->options.max_prediction_order = MAX_FIXED_ORDER;
}
}
if (s->options.max_prediction_order < s->options.min_prediction_order) { if (s->options.max_prediction_order < s->options.min_prediction_order) {
av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n", av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n",
s->options.min_prediction_order, s->options.max_prediction_order); s->options.min_prediction_order, s->options.max_prediction_order);
@ -1332,6 +1350,9 @@ static const AVOption options[] = {
{ "left_side", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FLAC_CHMODE_LEFT_SIDE }, INT_MIN, INT_MAX, FLAGS, "ch_mode" }, { "left_side", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FLAC_CHMODE_LEFT_SIDE }, INT_MIN, INT_MAX, FLAGS, "ch_mode" },
{ "right_side", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FLAC_CHMODE_RIGHT_SIDE }, INT_MIN, INT_MAX, FLAGS, "ch_mode" }, { "right_side", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FLAC_CHMODE_RIGHT_SIDE }, INT_MIN, INT_MAX, FLAGS, "ch_mode" },
{ "mid_side", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FLAC_CHMODE_MID_SIDE }, INT_MIN, INT_MAX, FLAGS, "ch_mode" }, { "mid_side", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FLAC_CHMODE_MID_SIDE }, INT_MIN, INT_MAX, FLAGS, "ch_mode" },
{ "min_prediction_order", NULL, offsetof(FlacEncodeContext, options.min_prediction_order), AV_OPT_TYPE_INT, { .i64 = 0 }, MIN_LPC_ORDER, MAX_LPC_ORDER, FLAGS },
{ "max_prediction_order", NULL, offsetof(FlacEncodeContext, options.max_prediction_order), AV_OPT_TYPE_INT, { .i64 = 0 }, MIN_LPC_ORDER, MAX_LPC_ORDER, FLAGS },
{ NULL }, { NULL },
}; };

@ -410,9 +410,9 @@ static const AVOption avcodec_options[] = {
{"b_sensitivity", "adjust sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.i64 = 40 }, 1, INT_MAX, V|E}, {"b_sensitivity", "adjust sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.i64 = 40 }, 1, INT_MAX, V|E},
#endif #endif
{"compression_level", NULL, OFFSET(compression_level), AV_OPT_TYPE_INT, {.i64 = FF_COMPRESSION_DEFAULT }, INT_MIN, INT_MAX, V|A|E}, {"compression_level", NULL, OFFSET(compression_level), AV_OPT_TYPE_INT, {.i64 = FF_COMPRESSION_DEFAULT }, INT_MIN, INT_MAX, V|A|E},
#if FF_API_PRIVATE_OPT
{"min_prediction_order", NULL, OFFSET(min_prediction_order), AV_OPT_TYPE_INT, {.i64 = -1 }, INT_MIN, INT_MAX, A|E}, {"min_prediction_order", NULL, OFFSET(min_prediction_order), AV_OPT_TYPE_INT, {.i64 = -1 }, INT_MIN, INT_MAX, A|E},
{"max_prediction_order", NULL, OFFSET(max_prediction_order), AV_OPT_TYPE_INT, {.i64 = -1 }, INT_MIN, INT_MAX, A|E}, {"max_prediction_order", NULL, OFFSET(max_prediction_order), AV_OPT_TYPE_INT, {.i64 = -1 }, INT_MIN, INT_MAX, A|E},
#if FF_API_PRIVATE_OPT
{"timecode_frame_start", "GOP timecode frame start number, in non-drop-frame format", OFFSET(timecode_frame_start), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, V|E}, {"timecode_frame_start", "GOP timecode frame start number, in non-drop-frame format", OFFSET(timecode_frame_start), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, V|E},
#endif #endif
{"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, {"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},

Loading…
Cancel
Save