[FFmpeg-cvslog] avcodec/mlpenc: export max_interval option

Paul B Mahol git at videolan.org
Tue Oct 10 00:49:42 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Oct  9 23:40:23 2023 +0200| [78fa1cff70bda889361dda81e69fc88d521ee8ce] | committer: Paul B Mahol

avcodec/mlpenc: export max_interval option

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=78fa1cff70bda889361dda81e69fc88d521ee8ce
---

 libavcodec/mlpenc.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index f1c2b52fbd..60a8abe929 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -38,7 +38,8 @@
 #include "mlp.h"
 #include "lpc.h"
 
-#define MAJOR_HEADER_INTERVAL 16
+#define MIN_HEADER_INTERVAL    8
+#define MAX_HEADER_INTERVAL  128
 
 #define MLP_MIN_LPC_ORDER      1
 #define MLP_MAX_LPC_ORDER      8
@@ -124,6 +125,8 @@ typedef struct MLPEncodeContext {
     AVClass        *class;
     AVCodecContext *avctx;
 
+    int             max_restart_interval;   ///< Max interval of access units in between two major frames.
+    int             min_restart_interval;   ///< Min interval of access units in between two major frames.
     int             lpc_type;
     int             lpc_passes;
     int             prediction_order;
@@ -165,8 +168,6 @@ typedef struct MLPEncodeContext {
 
     unsigned int    one_sample_buffer_size; ///< Number of samples*channel for one access unit.
 
-    unsigned int    max_restart_interval;   ///< Max interval of access units in between two major frames.
-    unsigned int    min_restart_interval;   ///< Min interval of access units in between two major frames.
     unsigned int    restart_intervals;      ///< Number of possible major frame sizes.
 
     uint16_t        output_timing;          ///< Timestamp of current access unit.
@@ -182,9 +183,9 @@ typedef struct MLPEncodeContext {
     uint8_t         ch8_presentation_mod;   ///< channel modifier for TrueHD stream 2
     RestartHeader   restart_header;
 
-    MLPBlock        b[MAJOR_HEADER_INTERVAL + 1];
-    int32_t         lpc_sample_buffer[MAJOR_HEADER_INTERVAL * MAX_BLOCKSIZE];
-    int32_t         filter_state_buffer[NUM_FILTERS][MAX_BLOCKSIZE * MAJOR_HEADER_INTERVAL];
+    MLPBlock        b[MAX_HEADER_INTERVAL + 1];
+    int32_t         lpc_sample_buffer[MAX_HEADER_INTERVAL * MAX_BLOCKSIZE];
+    int32_t         filter_state_buffer[NUM_FILTERS][MAX_BLOCKSIZE * MAX_HEADER_INTERVAL];
 
     unsigned int    major_cur_subblock_index;
     unsigned int    major_filter_state_subblock;
@@ -555,10 +556,8 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
     ctx->num_channels = avctx->ch_layout.nb_channels + 2; /* +2 noise channels */
     ctx->one_sample_buffer_size = avctx->frame_size
                                 * ctx->num_channels;
-    /* TODO Let user pass major header interval as parameter. */
-    ctx->max_restart_interval = MAJOR_HEADER_INTERVAL;
 
-    ctx->min_restart_interval = MAJOR_HEADER_INTERVAL;
+    ctx->min_restart_interval = ctx->max_restart_interval;
     ctx->restart_intervals = ctx->max_restart_interval / ctx->min_restart_interval;
 
     size = ctx->one_sample_buffer_size * ctx->max_restart_interval;
@@ -643,7 +642,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
     /* FIXME: this works for 1 and 2 channels, but check for more */
     rh->max_matrix_channel = rh->max_channel;
 
-    ctx->number_of_samples = avctx->frame_size * MAJOR_HEADER_INTERVAL;
+    ctx->number_of_samples = avctx->frame_size * ctx->max_restart_interval;
 
     if ((ret = ff_lpc_init(&ctx->lpc_ctx, ctx->number_of_samples,
                            MLP_MAX_LPC_ORDER, ctx->lpc_type)) < 0)
@@ -1800,7 +1799,7 @@ static void rematrix_channels(MLPEncodeContext *ctx)
  ****************************************************************************/
 
 typedef struct PathCounter {
-    char    path[MAJOR_HEADER_INTERVAL + 2];
+    char    path[MAX_HEADER_INTERVAL + 2];
     int     cur_idx;
     uint32_t bitcount;
 } PathCounter;
@@ -1948,7 +1947,7 @@ static void set_major_params(MLPEncodeContext *ctx)
     ctx->prev_decoding_params = restart_decoding_params;
     ctx->prev_channel_params = restart_channel_params;
 
-    for (unsigned int index = 0; index < MAJOR_HEADER_INTERVAL + 1; index++) {
+    for (unsigned int index = 0; index < MAX_HEADER_INTERVAL + 1; index++) {
         ctx->cur_decoding_params = &ctx->b[index].major_decoding_params;
         ctx->cur_channel_params = ctx->b[index].major_channel_params;
 
@@ -2160,6 +2159,7 @@ static av_cold int mlp_encode_close(AVCodecContext *avctx)
 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
 #define OFFSET(x) offsetof(MLPEncodeContext, x)
 static const AVOption mlp_options[] = {
+{ "max_interval", "Max number of frames between each new header", OFFSET(max_restart_interval),  AV_OPT_TYPE_INT, {.i64 = 16 }, MIN_HEADER_INTERVAL, MAX_HEADER_INTERVAL, FLAGS },
 { "lpc_type", "LPC algorithm", OFFSET(lpc_type), AV_OPT_TYPE_INT, {.i64 = FF_LPC_TYPE_LEVINSON }, FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_CHOLESKY, FLAGS, "lpc_type" },
 { "levinson", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_LPC_TYPE_LEVINSON }, 0, 0, FLAGS, "lpc_type" },
 { "cholesky", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_LPC_TYPE_CHOLESKY }, 0, 0, FLAGS, "lpc_type" },



More information about the ffmpeg-cvslog mailing list