[FFmpeg-devel] [PATCH 41/41] avcodec/mpegvideo: Move frame_skip_(exp|cmp) to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Only used by the main encoding thread.

Signed-off-by: Andreas Rheinhardt 
---
frame_skip_factor/threshold are used by slice threads;
they (and several other fields) could be moved by adding
a pointer to the const MPVMainContext. I intend to do this
in the future.

 libavcodec/mpegvideo.h | 2 --
 libavcodec/mpegvideo_enc.c | 8 
 libavcodec/mpegvideoenc.h  | 7 +--
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index bf71d6242b..fc271991fd 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -479,8 +479,6 @@ typedef struct MPVContext {
 /* frame skip options for encoding */
 int frame_skip_threshold;
 int frame_skip_factor;
-int frame_skip_exp;
-int frame_skip_cmp;
 
 int noise_reduction;
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 1a88e4fb93..8c369a94ec 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -892,7 +892,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 s->quant_precision = 5;
 
 ff_set_cmp(>mecc, s->mecc.ildct_cmp,  avctx->ildct_cmp);
-ff_set_cmp(>mecc, s->mecc.frame_skip_cmp, s->frame_skip_cmp);
+ff_set_cmp(>mecc, s->mecc.frame_skip_cmp, m->frame_skip_cmp);
 
 if (CONFIG_H261_ENCODER && s->out_format == FMT_H261) {
 ff_h261_encode_init(m);
@@ -1234,7 +1234,7 @@ static int skip_check(MPVMainEncContext *m, Picture *p, 
Picture *ref)
 uint8_t *rptr = ref->f->data[plane] + 8 * (x + y * stride);
 int v = s->mecc.frame_skip_cmp[1](s, dptr, rptr, stride, 8);
 
-switch (FFABS(s->frame_skip_exp)) {
+switch (FFABS(m->frame_skip_exp)) {
 case 0: score=  FFMAX(score, v);  break;
 case 1: score   += FFABS(v);  break;
 case 2: score64 += v * (int64_t)v;   break;
@@ -1248,9 +1248,9 @@ static int skip_check(MPVMainEncContext *m, Picture *p, 
Picture *ref)
 
 if (score)
 score64 = score;
-if (s->frame_skip_exp < 0)
+if (m->frame_skip_exp < 0)
 score64 = pow(score64 / (double)(s->mb_width * s->mb_height),
-  -1.0/s->frame_skip_exp);
+  -1.0/m->frame_skip_exp);
 
 if (score64 < s->frame_skip_threshold)
 return 1;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index ad55448363..f18463c2bb 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -87,6 +87,9 @@ typedef struct MPVMainEncContext {
 /* temp buffers for rate control */
 float *cplx_tab, *bits_tab;
 
+int frame_skip_exp;
+int frame_skip_cmp;
+
 /* temporary frames used by b_frame_strategy == 2 */
 AVFrame *tmp_frames[MAX_B_FRAMES + 2];
 int b_frame_strategy;
@@ -181,8 +184,8 @@ FF_MPV_OPT_CMP_FUNC, \
 { "xone", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_XONE }, 0, 0, 
FF_MPV_OPT_FLAGS, "motion_est" }, \
 {"skip_threshold", "Frame skip threshold",  
FF_MPV_OFFSET(frame_skip_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"skip_factor", "Frame skip factor",
FF_MPV_OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS }, \
-{"skip_exp", "Frame skip exponent", 
FF_MPV_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, 
FF_MPV_OPT_FLAGS }, \
-{"skip_cmp", "Frame skip compare function", 
FF_MPV_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, 
INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
+{"skip_exp", "Frame skip exponent", 
FF_MPV_MAIN_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS }, \
+{"skip_cmp", "Frame skip compare function", 
FF_MPV_MAIN_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, 
INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
 {"sc_threshold", "Scene change threshold",  
FF_MPV_MAIN_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, 
INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"noise_reduction", "Noise reduction",  
FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, 
FF_MPV_OPT_FLAGS }, \
 {"ps", "RTP payload size in bytes", 
FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS }, \
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 40/41] avcodec/mpegvideo: Move dummy dst for depr. opts to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpegenc.c | 2 +-
 libavcodec/mpegvideo.h| 4 
 libavcodec/mpegvideoenc.h | 8 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index a8efe72231..064562e6c5 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -631,7 +631,7 @@ static int amv_encode_picture(AVCodecContext *avctx, 
AVPacket *pkt,
 static const AVOption options[] = {
 FF_MPV_COMMON_OPTS
 #if FF_API_MJPEG_PRED
-{ "pred", "Deprecated, does nothing", FF_MPV_OFFSET(dummy), AV_OPT_TYPE_INT, { 
.i64 = 1 }, 1, 3, VE, "pred" },
+{ "pred", "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(dummy), 
AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 3, VE, "pred" },
 { "left",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, 
VE, "pred" },
 { "plane",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, 
VE, "pred" },
 { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, INT_MIN, INT_MAX, 
VE, "pred" },
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 5c7654230a..bf71d6242b 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -485,10 +485,6 @@ typedef struct MPVContext {
 int noise_reduction;
 
 int intra_penalty;
-
-#if FF_API_MPEGVIDEO_OPTS || FF_API_MJPEG_PRED
-int dummy;   ///< used as target for deprecated options
-#endif
 } MPVContext;
 
 typedef MPVContext MPVDecContext;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 662236c102..ad55448363 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -107,6 +107,10 @@ typedef struct MPVMainEncContext {
 uint16_t q_inter_matrix16[32][2][64];
 uint16_t q_intra_matrix16[32][2][64];
 uint16_t q_chroma_intra_matrix16[32][2][64];
+
+#if FF_API_MPEGVIDEO_OPTS || FF_API_MJPEG_PRED
+int dummy;   ///< used as target for deprecated options
+#endif
 } MPVMainEncContext;
 
 /* mpegvideo_enc common options */
@@ -195,9 +199,9 @@ FF_MPV_OPT_CMP_FUNC, \
 #define FF_MPV_DEPRECATED_MPEG_QUANT_OPT \
 { "mpeg_quant", "Deprecated, does nothing", FF_MPV_OFFSET(mpeg_quant), 
AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 0, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED },
 #define FF_MPV_DEPRECATED_A53_CC_OPT \
-{ "a53cc",  "Deprecated, does nothing", FF_MPV_OFFSET(dummy),  
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED 
},
+{ "a53cc",  "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(dummy), 
 AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FF_MPV_OPT_FLAGS | 
AV_OPT_FLAG_DEPRECATED },
 #define FF_MPV_DEPRECATED_MATRIX_OPT \
-   { "force_duplicated_matrix", "Deprecated, does nothing", 
FF_MPV_OFFSET(dummy), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS | 
AV_OPT_FLAG_DEPRECATED },
+   { "force_duplicated_matrix", "Deprecated, does nothing", 
FF_MPV_MAIN_OFFSET(dummy), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, 
FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED },
 #define FF_MPV_DEPRECATED_BFRAME_OPTS \
{ "b_strategy","Deprecated, does nothing", 
FF_MPV_MAIN_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 =  0 }, 0, 2, 
FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \
{ "b_sensitivity", "Deprecated, does nothing", 
FF_MPV_MAIN_OFFSET(b_sensitivity),AV_OPT_TYPE_INT, { .i64 = 40 }, 1, 
INT_MAX, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 39/41] avcodec/mpegvideo: Move scenechange_threshold to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h | 1 -
 libavcodec/mpegvideo_enc.c | 4 ++--
 libavcodec/mpegvideoenc.h  | 4 +++-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 201ca81621..5c7654230a 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -482,7 +482,6 @@ typedef struct MPVContext {
 int frame_skip_exp;
 int frame_skip_cmp;
 
-int scenechange_threshold;
 int noise_reduction;
 
 int intra_penalty;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 01ed41a2e7..1a88e4fb93 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -572,7 +572,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-if (s->scenechange_threshold < 10 &&
+if (m->scenechange_threshold < 10 &&
 (avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)) {
 av_log(avctx, AV_LOG_ERROR,
"closed gop with scene change detection are not supported yet, "
@@ -3632,7 +3632,7 @@ static int encode_picture(MPVMainEncContext *m, int 
picture_number)
 s->current_picture.   mb_var_sum= s->current_picture_ptr->   mb_var_sum= 
s->me.   mb_var_sum_temp;
 emms_c();
 
-if (s->me.scene_change_score > s->scenechange_threshold &&
+if (s->me.scene_change_score > m->scenechange_threshold &&
 s->pict_type == AV_PICTURE_TYPE_P) {
 s->pict_type= AV_PICTURE_TYPE_I;
 for(i=0; imb_stride*s->mb_height; i++)
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index bc69c6ea53..662236c102 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -42,6 +42,8 @@ typedef struct MPVMainEncContext {
 int me_penalty_compensation;
 int me_pre;  ///< prepass for motion estimation
 
+int scenechange_threshold;
+
 int gop_size;
 int picture_in_gop_number; ///< 0-> first pic in gop, ...
 
@@ -177,7 +179,7 @@ FF_MPV_OPT_CMP_FUNC, \
 {"skip_factor", "Frame skip factor",
FF_MPV_OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"skip_exp", "Frame skip exponent", 
FF_MPV_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, 
FF_MPV_OPT_FLAGS }, \
 {"skip_cmp", "Frame skip compare function", 
FF_MPV_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, 
INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \
-{"sc_threshold", "Scene change threshold",  
FF_MPV_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS }, \
+{"sc_threshold", "Scene change threshold",  
FF_MPV_MAIN_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, 
INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"noise_reduction", "Noise reduction",  
FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, 
FF_MPV_OPT_FLAGS }, \
 {"ps", "RTP payload size in bytes", 
FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", 
FF_MPV_MAIN_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, 
INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 38/41] avcodec/mpegvideo_enc: Avoid allocations for q_int(er|ra)_matrix tables

2022-01-29 Thread Andreas Rheinhardt
Do this by making them part of an MPVMainEncContext; the MPVEncContexts
still retain their pointers to access them.
(These tables are quite big, so that putting them in the MpegEncContext
would have been very wasteful for all the decoders using said structure.
But this is no longer a problem: MPVMainEncContext is only used by
encoders and allows to directly share the tables when slice-threading
is in use.)

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_enc.c | 24 
 libavcodec/mpegvideoenc.h  |  7 +++
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 7b55e9c17d..01ed41a2e7 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -869,12 +869,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 }
 
 if (!(avctx->stats_out = av_mallocz(256))   ||
-!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix,  32) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix,   32) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix,  32) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix16,32) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16,32) ||
 !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT))
 return AVERROR(ENOMEM);
 
@@ -936,6 +930,11 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 s->inter_matrix[j] = avctx->inter_matrix[i];
 }
 
+s->q_inter_matrix   = m->q_inter_matrix;
+s->q_intra_matrix   = m->q_intra_matrix;
+s->q_inter_matrix16 = m->q_inter_matrix16;
+s->q_intra_matrix16 = m->q_intra_matrix16;
+
 /* precompute matrix */
 /* for mjpeg, we do include qscale in the matrix */
 if (s->out_format != FMT_MJPEG) {
@@ -945,10 +944,11 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 ff_convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16,
   s->inter_matrix, s->inter_quant_bias, avctx->qmin,
   31, 0);
-av_freep(>q_chroma_intra_matrix);
-av_freep(>q_chroma_intra_matrix16);
 s->q_chroma_intra_matrix   = s->q_intra_matrix;
 s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
+} else {
+s->q_chroma_intra_matrix   = m->q_chroma_intra_matrix;
+s->q_chroma_intra_matrix16 = m->q_chroma_intra_matrix16;
 }
 
 if ((ret = ff_rate_control_init(m)) < 0)
@@ -1013,14 +1013,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
 av_freep(>cplx_tab);
 av_freep(>bits_tab);
 
-if(s->q_chroma_intra_matrix   != s->q_intra_matrix  ) 
av_freep(>q_chroma_intra_matrix);
-if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) 
av_freep(>q_chroma_intra_matrix16);
-s->q_chroma_intra_matrix=   NULL;
-s->q_chroma_intra_matrix16= NULL;
-av_freep(>q_intra_matrix);
-av_freep(>q_inter_matrix);
-av_freep(>q_intra_matrix16);
-av_freep(>q_inter_matrix16);
 av_freep(>reordered_input_picture);
 av_freep(>dct_offset);
 
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 23381a31ca..bc69c6ea53 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -98,6 +98,13 @@ typedef struct MPVMainEncContext {
 int16_t (*b_bidir_back_mv_table_base)[2];
 int16_t (*b_direct_mv_table_base)[2];
 int16_t (*b_field_mv_table_base)[2];
+
+int q_inter_matrix[32][64];
+int q_intra_matrix[32][64];
+int q_chroma_intra_matrix[32][64];
+uint16_t q_inter_matrix16[32][2][64];
+uint16_t q_intra_matrix16[32][2][64];
+uint16_t q_chroma_intra_matrix16[32][2][64];
 } MPVMainEncContext;
 
 /* mpegvideo_enc common options */
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 37/41] avcodec/mpegvideo_enc: Initialize non-JPEG q-matrices only once

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_enc.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 892115b68f..7b55e9c17d 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -945,6 +945,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 ff_convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16,
   s->inter_matrix, s->inter_quant_bias, avctx->qmin,
   31, 0);
+av_freep(>q_chroma_intra_matrix);
+av_freep(>q_chroma_intra_matrix16);
+s->q_chroma_intra_matrix   = s->q_intra_matrix;
+s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
 }
 
 if ((ret = ff_rate_control_init(m)) < 0)
@@ -3597,13 +3601,6 @@ static int encode_picture(MPVMainEncContext *m, int 
picture_number)
 update_qscale(s);
 }
 
-if (s->out_format != FMT_MJPEG) {
-if(s->q_chroma_intra_matrix   != s->q_intra_matrix  ) 
av_freep(>q_chroma_intra_matrix);
-if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) 
av_freep(>q_chroma_intra_matrix16);
-s->q_chroma_intra_matrix   = s->q_intra_matrix;
-s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
-}
-
 s->mb_intra=0; //for the rate distortion & bit compare functions
 for(i=1; ithread_context[i], s);
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 36/41] avcodec/mpegvideo: Move encoder-only base-arrays to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h | 10 
 libavcodec/mpegvideo_enc.c | 48 +++---
 libavcodec/mpegvideoenc.h  | 11 +
 libavcodec/ratecontrol.c   |  4 ++--
 4 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index ed62175db5..201ca81621 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -203,14 +203,7 @@ typedef struct MPVContext {
 H263DSPContext h263dsp;
 int f_code; ///< forward MV resolution
 int b_code; ///< backward MV resolution for B-frames 
(MPEG-4)
-int16_t (*p_mv_table_base)[2];
-int16_t (*b_forw_mv_table_base)[2];
-int16_t (*b_back_mv_table_base)[2];
-int16_t (*b_bidir_forw_mv_table_base)[2];
-int16_t (*b_bidir_back_mv_table_base)[2];
-int16_t (*b_direct_mv_table_base)[2];
 int16_t (*p_field_mv_table_base)[2];
-int16_t (*b_field_mv_table_base)[2];
 int16_t (*p_mv_table)[2];///< MV table (1MV per MB) P-frame 
encoding
 int16_t (*b_forw_mv_table)[2];   ///< MV table (1MV per MB) forward 
mode B-frame encoding
 int16_t (*b_back_mv_table)[2];   ///< MV table (1MV per MB) backward 
mode B-frame encoding
@@ -475,9 +468,6 @@ typedef struct MPVContext {
 
 int vbv_ignore_qmax;
 
-/* temp buffers for rate control */
-float *cplx_tab, *bits_tab;
-
 /* flag to indicate a reinitialization is required, e.g. after
  * a frame size change */
 int context_reinit;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 0204b4dacd..892115b68f 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -821,26 +821,26 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 /* Allocate MV tables; the MV and MB tables will be copied
  * to slice contexts by ff_update_duplicate_context().  */
 mv_table_size = (s->mb_height + 2) * s->mb_stride + 1;
-if (!FF_ALLOCZ_TYPED_ARRAY(s->p_mv_table_base,mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_forw_mv_table_base,   mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_back_mv_table_base,   mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_forw_mv_table_base, mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_back_mv_table_base, mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_direct_mv_table_base, mv_table_size))
+if (!FF_ALLOCZ_TYPED_ARRAY(m->p_mv_table_base,mv_table_size) ||
+!FF_ALLOCZ_TYPED_ARRAY(m->b_forw_mv_table_base,   mv_table_size) ||
+!FF_ALLOCZ_TYPED_ARRAY(m->b_back_mv_table_base,   mv_table_size) ||
+!FF_ALLOCZ_TYPED_ARRAY(m->b_bidir_forw_mv_table_base, mv_table_size) ||
+!FF_ALLOCZ_TYPED_ARRAY(m->b_bidir_back_mv_table_base, mv_table_size) ||
+!FF_ALLOCZ_TYPED_ARRAY(m->b_direct_mv_table_base, mv_table_size))
 return AVERROR(ENOMEM);
-s->p_mv_table= s->p_mv_table_base + s->mb_stride + 1;
-s->b_forw_mv_table   = s->b_forw_mv_table_base + s->mb_stride + 1;
-s->b_back_mv_table   = s->b_back_mv_table_base + s->mb_stride + 1;
-s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base + s->mb_stride + 
1;
-s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base + s->mb_stride + 
1;
-s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;
+s->p_mv_table= m->p_mv_table_base + s->mb_stride + 1;
+s->b_forw_mv_table   = m->b_forw_mv_table_base + s->mb_stride + 1;
+s->b_back_mv_table   = m->b_back_mv_table_base + s->mb_stride + 1;
+s->b_bidir_forw_mv_table = m->b_bidir_forw_mv_table_base + s->mb_stride + 
1;
+s->b_bidir_back_mv_table = m->b_bidir_back_mv_table_base + s->mb_stride + 
1;
+s->b_direct_mv_table = m->b_direct_mv_table_base + s->mb_stride + 1;
 
 /* Allocate MB type table */
 mb_array_size = s->mb_height * s->mb_stride;
 if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_type,  mb_array_size) ||
 !FF_ALLOCZ_TYPED_ARRAY(s->lambda_table, mb_array_size) ||
-!FF_ALLOC_TYPED_ARRAY (s->cplx_tab, mb_array_size) ||
-!FF_ALLOC_TYPED_ARRAY (s->bits_tab, mb_array_size))
+!FF_ALLOC_TYPED_ARRAY (m->cplx_tab, mb_array_size) ||
+!FF_ALLOC_TYPED_ARRAY (m->bits_tab, mb_array_size))
 return AVERROR(ENOMEM);
 
 #define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * 
sizeof(*(p
@@ -848,7 +848,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) {
 int16_t (*tmp1)[2];
 uint8_t *tmp2;
-if (!(tmp1 = ALLOCZ_ARRAYS(s->b_field_mv_table_base, 8, 
mv_table_size)) ||
+if (!(tmp1 = ALLOCZ_ARRAYS(m->b_field_mv_table_base, 8, 
mv_table_size)) ||
 !(tmp2 = ALLOCZ_ARRAYS(s->b_field_select_table[0][0], 2 * 4, 
mv_table_size)) ||
  

[FFmpeg-devel] [PATCH 35/41] avcodec/mpegvideo: Allocate encoder-only tables in mpegvideo_enc.c

2022-01-29 Thread Andreas Rheinhardt
This commit moves the encoder-only allocations of the tables
owned solely by the main encoder context to mpegvideo_enc.c.
This avoids checks in mpegvideo.c for whether we are dealing
with an encoder; it also improves modularity (if encoders are
disabled, this code will no longer be included in the binary).
And it also avoids having to reset these pointers at the beginning
of ff_mpv_common_init() (in case the dst context is uninitialized,
ff_mpeg_update_thread_context() simply copies the src context
into dst which therefore may contain pointers not owned by it,
but this does not happen for encoders at all).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.c | 118 +++--
 libavcodec/mpegvideo_enc.c |  68 -
 2 files changed, 74 insertions(+), 112 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 500f8af19d..9836000ad9 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -557,61 +557,13 @@ int ff_mpv_init_context_frame(MPVContext *s)
 
 s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * 
s->mb_stride + s->mb_width; // FIXME really needed?
 
-if (s->encoding) {
-/* Allocate MV tables */
-if (!FF_ALLOCZ_TYPED_ARRAY(s->p_mv_table_base,
mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_forw_mv_table_base,   
mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_back_mv_table_base,   
mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_forw_mv_table_base, 
mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_back_mv_table_base, 
mv_table_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->b_direct_mv_table_base, 
mv_table_size))
-return AVERROR(ENOMEM);
-s->p_mv_table= s->p_mv_table_base + s->mb_stride + 1;
-s->b_forw_mv_table   = s->b_forw_mv_table_base + s->mb_stride + 1;
-s->b_back_mv_table   = s->b_back_mv_table_base + s->mb_stride + 1;
-s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base + 
s->mb_stride + 1;
-s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base + 
s->mb_stride + 1;
-s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 
1;
-
-/* Allocate MB type table */
-if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_type,  mb_array_size) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->lambda_table, mb_array_size) ||
-!FF_ALLOC_TYPED_ARRAY (s->cplx_tab, mb_array_size) ||
-!FF_ALLOC_TYPED_ARRAY (s->bits_tab, mb_array_size))
-return AVERROR(ENOMEM);
-
-#define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * 
sizeof(*(p
-if (s->codec_id == AV_CODEC_ID_MPEG4 ||
-(s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) {
-int16_t (*tmp1)[2];
-uint8_t *tmp2;
-if (!(tmp1 = ALLOCZ_ARRAYS(s->b_field_mv_table_base, 8, 
mv_table_size)) ||
-!(tmp2 = ALLOCZ_ARRAYS(s->b_field_select_table[0][0], 2 * 4, 
mv_table_size)) ||
-!ALLOCZ_ARRAYS(s->p_field_select_table[0], 2 * 2, 
mv_table_size))
-return AVERROR(ENOMEM);
-
-s->p_field_select_table[1] = s->p_field_select_table[0] + 2 * 
mv_table_size;
-tmp1 += s->mb_stride + 1;
-
-for (int i = 0; i < 2; i++) {
-for (int j = 0; j < 2; j++) {
-for (int k = 0; k < 2; k++) {
-s->b_field_mv_table[i][j][k] = tmp1;
-tmp1 += mv_table_size;
-}
-s->b_field_select_table[i][j] = tmp2;
-tmp2 += 2 * mv_table_size;
-}
-}
-}
-}
-
 if (s->codec_id == AV_CODEC_ID_MPEG4 ||
 (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) {
-int16_t (*tmp)[2];
 /* interlaced direct mode decoding tables */
-if (!(tmp = ALLOCZ_ARRAYS(s->p_field_mv_table_base, 4, mv_table_size)))
+int16_t (*tmp)[2] = av_calloc(mv_table_size, 4 * sizeof(*tmp));
+if (!tmp)
 return AVERROR(ENOMEM);
+s->p_field_mv_table_base = tmp;
 tmp += s->mb_stride + 1;
 for (int i = 0; i < 2; i++) {
 for (int j = 0; j < 2; j++) {
@@ -654,8 +606,6 @@ int ff_mpv_init_context_frame(MPVContext *s)
 
 static void clear_context(MPVMainContext *s)
 {
-int i, j, k;
-
 memset(>next_picture, 0, sizeof(s->next_picture));
 memset(>last_picture, 0, sizeof(s->last_picture));
 memset(>current_picture, 0, sizeof(s->current_picture));
@@ -684,31 +634,10 @@ static void clear_context(MPVMainContext *s)
 s->bitstream_buffer = NULL;
 s->allocated_bitstream_buffer_size = 0;
 s->picture  = NULL;
-s->mb_type  = NULL;
-s->p_mv_table_base  = NULL;
-s->b_forw_mv_table_base = NULL;
-s->b_back_mv_table_base = NULL;
-

[FFmpeg-devel] [PATCH 34/41] avcodec/mpegvideo: Move ratecontrol parameters to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
All except vbv_ignore_qmax are only ever used by the main encoding
thread.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h | 13 -
 libavcodec/mpegvideo_enc.c |  4 ++--
 libavcodec/mpegvideoenc.h  | 31 ++-
 libavcodec/ratecontrol.c   | 38 --
 libavcodec/snowenc.c   |  6 +++---
 5 files changed, 47 insertions(+), 45 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index c11aba340e..ed62175db5 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -473,21 +473,8 @@ typedef struct MPVContext {
 int mpv_flags;  ///< flags set by private options
 int quantizer_noise_shaping;
 
-/**
- * ratecontrol qmin qmax limiting method
- * 0-> clipping, 1-> use a nice continuous function to limit qscale within 
qmin/qmax.
- */
-float rc_qsquish;
-float rc_qmod_amp;
-int   rc_qmod_freq;
-float rc_initial_cplx;
-float rc_buffer_aggressivity;
-float border_masking;
-int lmin, lmax;
 int vbv_ignore_qmax;
 
-char *rc_eq;
-
 /* temp buffers for rate control */
 float *cplx_tab, *bits_tab;
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 1039a50db8..fd82681869 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -406,7 +406,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
  avctx->temporal_cplx_masking ||
  avctx->spatial_cplx_masking  ||
  avctx->p_masking  ||
- s->border_masking ||
+ m->border_masking ||
  (s->mpv_flags & FF_MPV_FLAG_QP_RD)) &&
 !s->fixed_qscale;
 
@@ -1746,7 +1746,7 @@ vbv_retry:
 int min_step = hq ? 1 : (1<<(FF_LAMBDA_SHIFT + 7))/139;
 
 if (put_bits_count(>pb) > max_size &&
-s->lambda < s->lmax) {
+s->lambda < m->lmax) {
 m->next_lambda = FFMAX(s->lambda + min_step, s->lambda *
(s->qscale + 1) / s->qscale);
 if (s->adaptive_quant) {
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 539bdf3065..ada5935410 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -68,6 +68,19 @@ typedef struct MPVMainEncContext {
 int stuffing_bits; ///< bits used for stuffing
 int next_lambda;   ///< next lambda used for retrying to 
encode a frame
 RateControlContext rc_context; ///< contains stuff only accessed in 
ratecontrol.c
+/**
+ * ratecontrol qmin qmax limiting method
+ * 0-> clipping, 1-> use a nice continuous function to limit qscale within 
qmin/qmax.
+ */
+float rc_qsquish;
+float rc_qmod_amp;
+int   rc_qmod_freq;
+float rc_initial_cplx;
+float rc_buffer_aggressivity;
+float border_masking;
+int lmin, lmax;
+
+char *rc_eq;
 
 /* temporary frames used by b_frame_strategy == 2 */
 AVFrame *tmp_frames[MAX_B_FRAMES + 2];
@@ -123,19 +136,19 @@ FF_MPV_OPT_CMP_FUNC, \
 { "error_rate", "Simulate errors in the bitstream to test error concealment.", 

 \
 
FF_MPV_OFFSET(error_rate),  AV_OPT_TYPE_INT, { .i64 = 0 },   0, 
INT_MAX, FF_MPV_OPT_FLAGS },\
 {"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use 
differentiable function)",  
\
-
FF_MPV_OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, 
FF_MPV_OPT_FLAGS},\
-{"rc_qmod_amp", "experimental quantizer modulation",
FF_MPV_OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, 
FF_MPV_OPT_FLAGS},   \
-{"rc_qmod_freq", "experimental quantizer modulation",   
FF_MPV_OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, 
FF_MPV_OPT_FLAGS}, \
+
FF_MPV_MAIN_OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, 
FF_MPV_OPT_FLAGS},\
+{"rc_qmod_amp", "experimental quantizer modulation",
FF_MPV_MAIN_OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, 
FLT_MAX, FF_MPV_OPT_FLAGS},   \
+{"rc_qmod_freq", "experimental quantizer modulation",   
FF_MPV_MAIN_OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS}, \
 {"rc_eq", "Set rate control equation. When computing the expression, besides 
the standard functions "

[FFmpeg-devel] [PATCH 33/41] avcodec/mpegvideo: Move brd_scale to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Only used by the main encoding thread.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h | 1 -
 libavcodec/mpegvideo_enc.c | 6 +++---
 libavcodec/mpegvideoenc.h  | 5 +++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 0e8e11743e..c11aba340e 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -410,7 +410,6 @@ typedef struct MPVContext {
 int top_field_first;
 int concealment_motion_vectors;
 int q_scale_type;
-int brd_scale;
 int intra_vlc_format;
 int alternate_scan;
 #define VIDEO_FORMAT_COMPONENT   0
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index b90eb43399..1039a50db8 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -907,8 +907,8 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 return AVERROR(ENOMEM);
 
 m->tmp_frames[i]->format = AV_PIX_FMT_YUV420P;
-m->tmp_frames[i]->width  = s->width  >> s->brd_scale;
-m->tmp_frames[i]->height = s->height >> s->brd_scale;
+m->tmp_frames[i]->width  = s->width  >> m->brd_scale;
+m->tmp_frames[i]->height = s->height >> m->brd_scale;
 
 ret = av_frame_get_buffer(m->tmp_frames[i], 0);
 if (ret < 0)
@@ -1222,7 +1222,7 @@ static int estimate_best_b_count(MPVMainEncContext *m)
 {
 MPVEncContext *const s = >common;
 AVPacket *pkt;
-const int scale = s->brd_scale;
+const int scale = m->brd_scale;
 int width  = s->width  >> scale;
 int height = s->height >> scale;
 int i, j, out_size, p_lambda, b_lambda, lambda2;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 55c265edbe..539bdf3065 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -73,6 +73,7 @@ typedef struct MPVMainEncContext {
 AVFrame *tmp_frames[MAX_B_FRAMES + 2];
 int b_frame_strategy;
 int b_sensitivity;
+int brd_scale;
 } MPVMainEncContext;
 
 /* mpegvideo_enc common options */
@@ -155,7 +156,7 @@ FF_MPV_OPT_CMP_FUNC, \
 #define FF_MPV_COMMON_BFRAME_OPTS \
 {"b_strategy", "Strategy to choose between I/P/B-frames",  
FF_MPV_MAIN_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, 
FF_MPV_OPT_FLAGS }, \
 {"b_sensitivity", "Adjust sensitivity of b_frame_strategy 1",  
FF_MPV_MAIN_OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.i64 = 40 }, 1, INT_MAX, 
FF_MPV_OPT_FLAGS }, \
-{"brd_scale", "Downscale frames for dynamic B-frame decision", 
FF_MPV_OFFSET(brd_scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 3, FF_MPV_OPT_FLAGS 
},
+{"brd_scale", "Downscale frames for dynamic B-frame decision", 
FF_MPV_MAIN_OFFSET(brd_scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 3, 
FF_MPV_OPT_FLAGS },
 
 #if FF_API_MPEGVIDEO_OPTS
 #define FF_MPV_DEPRECATED_MPEG_QUANT_OPT \
@@ -167,7 +168,7 @@ FF_MPV_OPT_CMP_FUNC, \
 #define FF_MPV_DEPRECATED_BFRAME_OPTS \
{ "b_strategy","Deprecated, does nothing", 
FF_MPV_MAIN_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 =  0 }, 0, 2, 
FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \
{ "b_sensitivity", "Deprecated, does nothing", 
FF_MPV_MAIN_OFFSET(b_sensitivity),AV_OPT_TYPE_INT, { .i64 = 40 }, 1, 
INT_MAX, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \
-   { "brd_scale", "Deprecated, does nothing", FF_MPV_OFFSET(brd_scale),
AV_OPT_TYPE_INT, { .i64 =  0 }, 0, 3, FF_MPV_OPT_FLAGS | 
AV_OPT_FLAG_DEPRECATED },
+   { "brd_scale", "Deprecated, does nothing", 
FF_MPV_MAIN_OFFSET(brd_scale),AV_OPT_TYPE_INT, { .i64 =  0 }, 0, 3, 
FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED },
 #endif
 
 extern const AVClass ff_mpv_enc_class;
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 32/41] avcodec/mpegvideo: Move vbv_delay to Mpeg1Context

2022-01-29 Thread Andreas Rheinhardt
Only used there and only by the main thread.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpeg12dec.c | 5 +++--
 libavcodec/mpegvideo.h | 1 -
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 4c53451d8c..631582fd61 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -69,6 +69,7 @@ typedef struct Mpeg1Context {
 AVRational save_aspect;
 int save_width, save_height, save_progressive_seq;
 int rc_buffer_size;
+int vbv_delay;
 AVRational frame_rate_ext;  /* MPEG-2 specific framerate modificator */
 unsigned frame_rate_index;
 int sync;   /* Did we reach a sync point like a 
GOP/SEQ/KEYFrame? */
@@ -1284,7 +1285,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
 if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->bit_rate) {
 avctx->rc_max_rate = s->bit_rate;
 } else if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO && s->bit_rate &&
-   (s->bit_rate != 0x3*400 || s->vbv_delay != 0x)) {
+   (s->bit_rate != 0x3*400 || s1->vbv_delay != 0x)) {
 avctx->bit_rate = s->bit_rate;
 }
 s1->save_aspect  = s->avctx->sample_aspect_ratio;
@@ -1357,7 +1358,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, 
const uint8_t *buf,
 return AVERROR_INVALIDDATA;
 
 vbv_delay = get_bits(>gb, 16);
-s->vbv_delay = vbv_delay;
+s1->vbv_delay = vbv_delay;
 if (s->pict_type == AV_PICTURE_TYPE_P ||
 s->pict_type == AV_PICTURE_TYPE_B) {
 s->full_pel[0] = get_bits1(>gb);
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index ed1416fca6..0e8e11743e 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -182,7 +182,6 @@ typedef struct MPVContext {
 int adaptive_quant; ///< use adaptive quantization
 int dquant; ///< qscale difference to prev qscale
 int pict_type;  ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, 
AV_PICTURE_TYPE_B, ...
-int vbv_delay;
 int droppable;
 int skipdct;///< skip dct and code zero residual
 
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 31/41] avcodec/mpegvideo_enc: Remove unused parameter from encode_mb_hq()

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_enc.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 61f8e20006..b90eb43399 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2495,7 +2495,7 @@ static inline void 
copy_context_after_encode(MPVEncContext *d,
 d->esc3_level_length= s->esc3_level_length;
 }
 
-static inline void encode_mb_hq(MPVEncContext *s, MPVEncContext *backup, 
MPVEncContext *best, int type,
+static inline void encode_mb_hq(MPVEncContext *s, MPVEncContext *backup, 
MPVEncContext *best,
PutBitContext pb[2], PutBitContext pb2[2], 
PutBitContext tex_pb[2],
int *dmin, int *next_block, int motion_x, int 
motion_y)
 {
@@ -2981,7 +2981,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 s->mb_intra= 0;
 s->mv[0][0][0] = s->p_mv_table[xy][0];
 s->mv[0][0][1] = s->p_mv_table[xy][1];
-encode_mb_hq(s, _s, _s, 
CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb,
+encode_mb_hq(s, _s, _s, pb, pb2, tex_pb,
  , _block, s->mv[0][0][0], 
s->mv[0][0][1]);
 }
 if(mb_type_MB_TYPE_INTER_I){
@@ -2993,7 +2993,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0];
 s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1];
 }
-encode_mb_hq(s, _s, _s, 
CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb,
+encode_mb_hq(s, _s, _s, pb, pb2, tex_pb,
  , _block, 0, 0);
 }
 if(mb_type_MB_TYPE_SKIPPED){
@@ -3002,7 +3002,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 s->mb_intra= 0;
 s->mv[0][0][0] = 0;
 s->mv[0][0][1] = 0;
-encode_mb_hq(s, _s, _s, 
CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb,
+encode_mb_hq(s, _s, _s, pb, pb2, tex_pb,
  , _block, s->mv[0][0][0], 
s->mv[0][0][1]);
 }
 if(mb_type_MB_TYPE_INTER4V){
@@ -3013,7 +3013,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 s->mv[0][i][0] = 
s->current_picture.motion_val[0][s->block_index[i]][0];
 s->mv[0][i][1] = 
s->current_picture.motion_val[0][s->block_index[i]][1];
 }
-encode_mb_hq(s, _s, _s, 
CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb,
+encode_mb_hq(s, _s, _s, pb, pb2, tex_pb,
  , _block, 0, 0);
 }
 if(mb_type_MB_TYPE_FORWARD){
@@ -3022,7 +3022,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 s->mb_intra= 0;
 s->mv[0][0][0] = s->b_forw_mv_table[xy][0];
 s->mv[0][0][1] = s->b_forw_mv_table[xy][1];
-encode_mb_hq(s, _s, _s, 
CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb,
+encode_mb_hq(s, _s, _s, pb, pb2, tex_pb,
  , _block, s->mv[0][0][0], 
s->mv[0][0][1]);
 }
 if(mb_type_MB_TYPE_BACKWARD){
@@ -3031,7 +3031,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 s->mb_intra= 0;
 s->mv[1][0][0] = s->b_back_mv_table[xy][0];
 s->mv[1][0][1] = s->b_back_mv_table[xy][1];
-encode_mb_hq(s, _s, _s, 
CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb,
+encode_mb_hq(s, _s, _s, pb, pb2, tex_pb,
  , _block, s->mv[1][0][0], 
s->mv[1][0][1]);
 }
 if(mb_type_MB_TYPE_BIDIR){
@@ -3042,7 +3042,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1];
 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0];
 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1];
-encode_mb_hq(s, _s, _s, 
CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb,
+encode_mb_hq(s, _s, _s, pb, pb2, tex_pb,
  , _block, 0, 0);
 }
 if(mb_type_MB_TYPE_FORWARD_I){
@@ -3054,7 +3054,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0];
 s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1];
 }
-encode_mb_hq(s, _s, _s, 
CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb,
+encode_mb_hq(s, _s, _s, 

[FFmpeg-devel] [PATCH 30/41] avcodec/mpegvideo_enc: Remove unused function parameters

2022-01-29 Thread Andreas Rheinhardt
Seems to have been always unused since these functions were introduced
in 1f0cd30fd9b656122436ecd625656a04f6235fb3.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_enc.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 22f4cd2d0e..61f8e20006 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2429,7 +2429,7 @@ static av_always_inline void encode_mb(MPVEncContext *s, 
int motion_x, int motio
 }
 
 static inline void copy_context_before_encode(MPVEncContext *d,
-  const MPVEncContext *s, int type)
+  const MPVEncContext *s)
 {
 int i;
 
@@ -2457,7 +2457,7 @@ static inline void 
copy_context_before_encode(MPVEncContext *d,
 }
 
 static inline void copy_context_after_encode(MPVEncContext *d,
- const MPVEncContext *s, int type)
+ const MPVEncContext *s)
 {
 int i;
 
@@ -2502,7 +2502,7 @@ static inline void encode_mb_hq(MPVEncContext *s, 
MPVEncContext *backup, MPVEncC
 int score;
 uint8_t *dest_backup[3];
 
-copy_context_before_encode(s, backup, type);
+copy_context_before_encode(s, backup);
 
 s->block= s->blocks[*next_block];
 s->pb= pb[*next_block];
@@ -2542,7 +2542,7 @@ static inline void encode_mb_hq(MPVEncContext *s, 
MPVEncContext *backup, MPVEncC
 *dmin= score;
 *next_block^=1;
 
-copy_context_after_encode(best, s, type);
+copy_context_after_encode(best, s);
 }
 }
 
@@ -2966,7 +2966,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 int next_block=0;
 int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
 
-copy_context_before_encode(_s, s, -1);
+copy_context_before_encode(_s, s);
 backup_s.pb= s->pb;
 best_s.data_partitioning= s->data_partitioning;
 best_s.partitioned_frame= s->partitioned_frame;
@@ -3200,7 +3200,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
 
 s->current_picture.qscale_table[xy] = best_s.qscale;
 
-copy_context_after_encode(s, _s, -1);
+copy_context_after_encode(s, _s);
 
 pb_bits_count= put_bits_count(>pb);
 flush_put_bits(>pb);
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 29/41] avcodec/mpegvideo: Move header_bits to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
The header is always written by the main thread, so it is
not surprising that header_bits can be moved to MPVMainEncContext
as well.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpegenc.c  | 14 --
 libavcodec/mpegvideo.h |  1 -
 libavcodec/mpegvideo_enc.c |  6 +++---
 libavcodec/mpegvideoenc.h  |  2 ++
 libavcodec/ratecontrol.c   |  2 +-
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 23772c4c1f..a8efe72231 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -103,8 +103,9 @@ void ff_mjpeg_amv_encode_picture_header(MPVMainEncContext 
*main)
  *
  * @param s The MPVEncContext.
  */
-static void mjpeg_encode_picture_frame(MPVEncContext *s)
+static void mjpeg_encode_picture_frame(MPVMainEncContext *main)
 {
+MPVEncContext *const s = >common;
 int nbits, code, table_id;
 MJpegContext *m = s->mjpeg_ctx;
 uint8_t  *huff_size[4] = { m->huff_size_dc_luminance,
@@ -118,7 +119,7 @@ static void mjpeg_encode_picture_frame(MPVEncContext *s)
 size_t total_bits = 0;
 size_t bytes_needed;
 
-s->header_bits = get_bits_diff(s);
+main->header_bits = get_bits_diff(s);
 // Estimate the total size first
 for (int i = 0; i < m->huff_ncode; i++) {
 table_id = m->huff_buffer[i].table_id;
@@ -224,6 +225,9 @@ int ff_mjpeg_encode_stuffing(MPVEncContext *s)
 
 #if CONFIG_MJPEG_ENCODER
 if (m->huffman == HUFFMAN_TABLE_OPTIMAL) {
+/* HUFFMAN_TABLE_OPTIMAL is incompatible with slice threading,
+ * therefore the following cast is allowed. */
+MPVMainEncContext *const main = (MPVMainEncContext*)s;
 
 mjpeg_build_optimal_huffman(m);
 
@@ -236,10 +240,8 @@ int ff_mjpeg_encode_stuffing(MPVEncContext *s)
 s->intra_chroma_ac_vlc_length  =
 s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len;
 
-/* HUFFMAN_TABLE_OPTIMAL is incompatible with slice threading,
- * therefore the following cast is allowed. */
-mjpeg_encode_picture_header((MPVMainEncContext*)s);
-mjpeg_encode_picture_frame(s);
+mjpeg_encode_picture_header(main);
+mjpeg_encode_picture_frame(main);
 }
 #endif
 
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 8b5916f68d..ed1416fca6 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -299,7 +299,6 @@ typedef struct MPVContext {
 
 /* statistics, used for 2-pass encoding */
 int mv_bits;
-int header_bits;
 int i_tex_bits;
 int p_tex_bits;
 int i_count;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 36e14efea2..22f4cd2d0e 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1737,7 +1737,7 @@ vbv_retry:
 frame_end(m);
 
if ((CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER) && s->out_format == 
FMT_MJPEG)
-ff_mjpeg_encode_picture_trailer(>pb, s->header_bits);
+ff_mjpeg_encode_picture_trailer(>pb, m->header_bits);
 
 if (avctx->rc_buffer_size) {
 RateControlContext *rcc = >rc_context;
@@ -1794,7 +1794,7 @@ vbv_retry:
s->pict_type);
 
 if (avctx->flags & AV_CODEC_FLAG_PASS1)
-assert(put_bits_count(>pb) == s->header_bits + s->mv_bits +
+assert(put_bits_count(>pb) == m->header_bits + s->mv_bits +
  s->misc_bits + s->i_tex_bits +
  s->p_tex_bits);
 flush_put_bits(>pb);
@@ -3754,7 +3754,7 @@ static int encode_picture(MPVMainEncContext *m, int 
picture_number)
 av_assert0(0);
 }
 bits= put_bits_count(>pb);
-s->header_bits= bits - s->last_bits;
+m->header_bits = bits - s->last_bits;
 
 for(i=1; ithread_context[i], s);
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 8e6c45c0b6..55c265edbe 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -60,6 +60,8 @@ typedef struct MPVMainEncContext {
 int last_non_b_pict_type;   ///< used for MPEG-4 gmc B-frames & ratecontrol
 int last_lambda_for[5]; ///< last lambda for a specific pict type
 
+int header_bits;
+
 /* bit rate control */
 int64_t total_bits;
 int frame_bits;///< bits used for the current frame
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 03466a1a43..c41682b29c 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -54,7 +54,7 @@ void ff_write_pass1_stats(MPVMainEncContext *m)
  s->current_picture.mc_mb_var_sum,
  s->current_picture.mb_var_sum,
  s->i_count, s->skip_count,
- s->header_bits);
+ m->header_bits);
 }
 
 static double get_fps(AVCodecContext *avctx)
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org

[FFmpeg-devel] [PATCH 28/41] avcodec/mpegvideo: Move last-pic information to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
last_pict_type, last_non_b_pict_type and last_lambda_for
are only used by the encoder's main thread.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h |  3 ---
 libavcodec/mpegvideo_enc.c | 16 
 libavcodec/mpegvideoenc.h  |  4 
 libavcodec/msmpeg4enc.c|  5 +++--
 libavcodec/ratecontrol.c   |  4 ++--
 libavcodec/snowenc.c   |  2 +-
 6 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index bb14304495..8b5916f68d 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -183,10 +183,7 @@ typedef struct MPVContext {
 int dquant; ///< qscale difference to prev qscale
 int pict_type;  ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, 
AV_PICTURE_TYPE_B, ...
 int vbv_delay;
-int last_pict_type; //FIXME removes
-int last_non_b_pict_type;   ///< used for MPEG-4 gmc B-frames & ratecontrol
 int droppable;
-int last_lambda_for[5]; ///< last lambda for a specific pict type
 int skipdct;///< skip dct and code zero residual
 
 /* motion compensation */
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 71e751d88b..36e14efea2 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1238,9 +1238,9 @@ static int estimate_best_b_count(MPVMainEncContext *m)
 
 //emms_c();
 //s->next_picture_ptr->quality;
-p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P];
+p_lambda = m->last_lambda_for[AV_PICTURE_TYPE_P];
 //p_lambda * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
-b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B];
+b_lambda = m->last_lambda_for[AV_PICTURE_TYPE_B];
 if (!b_lambda) // FIXME we should do this somewhere else
 b_lambda = p_lambda;
 lambda2  = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >>
@@ -1575,10 +1575,10 @@ static void frame_end(MPVMainEncContext *m)
 
 emms_c();
 
-s->last_pict_type = s->pict_type;
-s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality;
+m->last_pict_type = s->pict_type;
+m->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality;
 if (s->pict_type!= AV_PICTURE_TYPE_B)
-s->last_non_b_pict_type = s->pict_type;
+m->last_non_b_pict_type = s->pict_type;
 }
 
 static void update_noise_reduction(MPVMainEncContext *m)
@@ -3525,9 +3525,9 @@ static int encode_picture(MPVMainEncContext *m, int 
picture_number)
 ff_get_2pass_fcode(m);
 } else if (!(s->avctx->flags & AV_CODEC_FLAG_QSCALE)) {
 if(s->pict_type==AV_PICTURE_TYPE_B)
-s->lambda= s->last_lambda_for[s->pict_type];
+s->lambda = m->last_lambda_for[s->pict_type];
 else
-s->lambda= s->last_lambda_for[s->last_non_b_pict_type];
+s->lambda = m->last_lambda_for[m->last_non_b_pict_type];
 update_qscale(s);
 }
 
@@ -3553,7 +3553,7 @@ static int encode_picture(MPVMainEncContext *m, int 
picture_number)
 s->lambda  = (s->lambda  * m->me_penalty_compensation + 128) >> 8;
 s->lambda2 = (s->lambda2 * (int64_t) m->me_penalty_compensation + 128) 
>> 8;
 if (s->pict_type != AV_PICTURE_TYPE_B) {
-if ((m->me_pre && s->last_non_b_pict_type == AV_PICTURE_TYPE_I) ||
+if ((m->me_pre && m->last_non_b_pict_type == AV_PICTURE_TYPE_I) ||
 m->me_pre == 2) {
 s->avctx->execute(s->avctx, pre_estimate_motion_thread, 
>thread_context[0], NULL, context_count, sizeof(void*));
 }
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index a06e208be8..8e6c45c0b6 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -56,6 +56,10 @@ typedef struct MPVMainEncContext {
  * a delay */
 int64_t reordered_pts;
 
+int last_pict_type; //FIXME remove
+int last_non_b_pict_type;   ///< used for MPEG-4 gmc B-frames & ratecontrol
+int last_lambda_for[5]; ///< last lambda for a specific pict type
+
 /* bit rate control */
 int64_t total_bits;
 int frame_bits;///< bits used for the current frame
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 9ab7f9e146..d34de80192 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -153,7 +153,8 @@ av_cold void ff_msmpeg4_encode_init(MPVMainEncContext *m)
 
 static void find_best_tables(MSMPEG4EncContext *ms)
 {
-MPVEncContext *const s = >s.common;
+MPVMainEncContext *const m = >s;
+MPVEncContext *const s = >common;
 int i;
 int best= 0, best_size= INT_MAX;
 int chroma_best = 0, best_chroma_size = INT_MAX;
@@ -206,7 +207,7 @@ static void find_best_tables(MSMPEG4EncContext *ms)
 s->rl_table_index   =best;
 s->rl_chroma_table_index= chroma_best;
 
-if(s->pict_type != s->last_non_b_pict_type){
+if 

[FFmpeg-devel] [PATCH 27/41] avcodec/mpegvideo: Remove write-only [fb]_code

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ituh263enc.c| 1 -
 libavcodec/mpeg12enc.c | 5 -
 libavcodec/mpeg4videoenc.c | 8 
 libavcodec/mpegvideo.h | 2 --
 libavcodec/mpegvideo_enc.c | 8 
 5 files changed, 24 deletions(-)

diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 4af7ccb527..571abdffd7 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -682,7 +682,6 @@ void ff_h263_encode_mb(MPVEncContext *s,
 if(interleaved_stats){
 if (!s->mb_intra) {
 s->p_tex_bits+= get_bits_diff(s);
-s->f_count++;
 }else{
 s->i_tex_bits+= get_bits_diff(s);
 s->i_count++;
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 78c802d897..2c937ecf61 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -942,7 +942,6 @@ static av_always_inline void 
mpeg1_encode_mb_internal(MPVEncContext *s,
 put_sbits(>pb, 2, cbp);
 }
 }
-s->f_count++;
 } else {
 if (s->mv_type == MV_TYPE_16X16) {
 if (cbp) {  // With coded bloc pattern
@@ -973,7 +972,6 @@ static av_always_inline void 
mpeg1_encode_mb_internal(MPVEncContext *s,
 s->last_mv[0][1][0] = s->mv[0][0][0];
 s->last_mv[0][0][1] =
 s->last_mv[0][1][1] = s->mv[0][0][1];
-s->f_count++;
 }
 if (s->mv_dir & MV_DIR_BACKWARD) {
 mpeg1_encode_motion(s,
@@ -986,7 +984,6 @@ static av_always_inline void 
mpeg1_encode_mb_internal(MPVEncContext *s,
 s->last_mv[1][1][0] = s->mv[1][0][0];
 s->last_mv[1][0][1] =
 s->last_mv[1][1][1] = s->mv[1][0][1];
-s->b_count++;
 }
 } else {
 av_assert2(s->mv_type == MV_TYPE_FIELD);
@@ -1019,7 +1016,6 @@ static av_always_inline void 
mpeg1_encode_mb_internal(MPVEncContext *s,
 s->last_mv[0][i][0] = s->mv[0][i][0];
 s->last_mv[0][i][1] = s->mv[0][i][1] * 2;
 }
-s->f_count++;
 }
 if (s->mv_dir & MV_DIR_BACKWARD) {
 for (i = 0; i < 2; i++) {
@@ -1033,7 +1029,6 @@ static av_always_inline void 
mpeg1_encode_mb_internal(MPVEncContext *s,
 s->last_mv[1][i][0] = s->mv[1][i][0];
 s->last_mv[1][i][1] = s->mv[1][i][1] * 2;
 }
-s->b_count++;
 }
 }
 s->mv_bits += get_bits_diff(s);
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index fcd436082f..4304562669 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -564,8 +564,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t 
block[6][64],
 if (!mb_type) {
 av_assert2(s->mv_dir & MV_DIRECT);
 ff_h263_encode_motion_vector(s, motion_x, motion_y, 1);
-s->b_count++;
-s->f_count++;
 } else {
 av_assert2(mb_type > 0 && mb_type < 4);
 if (s->mv_type != MV_TYPE_FIELD) {
@@ -578,7 +576,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t 
block[6][64],
 s->last_mv[0][1][0] = s->mv[0][0][0];
 s->last_mv[0][0][1] =
 s->last_mv[0][1][1] = s->mv[0][0][1];
-s->f_count++;
 }
 if (s->mv_dir & MV_DIR_BACKWARD) {
 ff_h263_encode_motion_vector(s,
@@ -589,7 +586,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t 
block[6][64],
 s->last_mv[1][1][0] = s->mv[1][0][0];
 s->last_mv[1][0][1] =
 s->last_mv[1][1][1] = s->mv[1][0][1];
-s->b_count++;
 }
 } else {
 if (s->mv_dir & MV_DIR_FORWARD) {
@@ -609,7 +605,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t 
block[6][64],
 s->last_mv[0][i][0] = s->mv[0][i][0];
 s->last_mv[0][i][1] = s->mv[0][i][1] * 2;
 }
-s->f_count++;
 }
 if (s->mv_dir & MV_DIR_BACKWARD) {
 for (i = 0; i < 2; i++) {
@@ -620,7 +615,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t 
block[6][64],
 s->last_mv[1][i][0] = s->mv[1][i][0];
 s->last_mv[1][i][1] = s->mv[1][i][1] * 2;
 }
-s->b_count++;
 }
 }
 }
@@ -796,8 +790,6 @@ void 

[FFmpeg-devel] [PATCH 26/41] avcodec/mpegvideo: Move input_picture list to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Also avoid an allocation while doing so.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h |  1 -
 libavcodec/mpegvideo_enc.c | 60 ++
 libavcodec/mpegvideoenc.h  |  2 ++
 3 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index a334acb3aa..98810ea231 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -118,7 +118,6 @@ typedef struct MPVContext {
 ptrdiff_t linesize;///< line size, in bytes, may be different from 
width
 ptrdiff_t uvlinesize;  ///< line size, for chroma in bytes, may be 
different from width
 Picture *picture;  ///< main picture buffer
-Picture **input_picture;   ///< next pictures on display order for encoding
 Picture **reordered_input_picture; ///< pointer to the next pictures in 
coded order for encoding
 
 /** bit output */
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 9b05b44d36..1cf194dcaf 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -825,7 +825,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 !FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix16,32) ||
 !FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32) ||
 !FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16,32) ||
-!FF_ALLOCZ_TYPED_ARRAY(s->input_picture,   MAX_PICTURE_COUNT) 
||
 !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT))
 return AVERROR(ENOMEM);
 
@@ -952,7 +951,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
 av_freep(>q_inter_matrix);
 av_freep(>q_intra_matrix16);
 av_freep(>q_inter_matrix16);
-av_freep(>input_picture);
 av_freep(>reordered_input_picture);
 av_freep(>dct_offset);
 
@@ -1137,9 +1135,9 @@ static int load_input_picture(MPVMainEncContext *m, const 
AVFrame *pic_arg)
 pic->f->pts = pts; // we set this here to avoid modifying pic_arg
 } else {
 /* Flushing: When we have not received enough input frames,
- * ensure s->input_picture[0] contains the first picture */
+ * ensure m->input_picture[0] contains the first picture */
 for (flush_offset = 0; flush_offset < encoding_delay + 1; 
flush_offset++)
-if (s->input_picture[flush_offset])
+if (m->input_picture[flush_offset])
 break;
 
 if (flush_offset <= 1)
@@ -1150,9 +1148,9 @@ static int load_input_picture(MPVMainEncContext *m, const 
AVFrame *pic_arg)
 
 /* shift buffer entries */
 for (i = flush_offset; i < MAX_PICTURE_COUNT /*s->encoding_delay + 1*/; 
i++)
-s->input_picture[i - flush_offset] = s->input_picture[i];
+m->input_picture[i - flush_offset] = m->input_picture[i];
 
-s->input_picture[encoding_delay] = (Picture*) pic;
+m->input_picture[encoding_delay] = (Picture*) pic;
 
 return 0;
 }
@@ -1249,11 +1247,11 @@ static int estimate_best_b_count(MPVMainEncContext *m)
FF_LAMBDA_SHIFT;
 
 for (i = 0; i < s->max_b_frames + 2; i++) {
-Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] :
+Picture pre_input, *pre_input_ptr = i ? m->input_picture[i - 1] :
 s->next_picture_ptr;
 uint8_t *data[4];
 
-if (pre_input_ptr && (!i || s->input_picture[i - 1])) {
+if (pre_input_ptr && (!i || m->input_picture[i - 1])) {
 pre_input = *pre_input_ptr;
 memcpy(data, pre_input_ptr->f->data, sizeof(data));
 
@@ -1285,7 +1283,7 @@ static int estimate_best_b_count(MPVMainEncContext *m)
 AVCodecContext *c;
 int64_t rd = 0;
 
-if (!s->input_picture[j])
+if (!m->input_picture[j])
 break;
 
 c = avcodec_alloc_context3(NULL);
@@ -1377,13 +1375,13 @@ static int select_input_picture(MPVMainEncContext *m)
 s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL;
 
 /* set next picture type & ordering */
-if (!s->reordered_input_picture[0] && s->input_picture[0]) {
+if (!s->reordered_input_picture[0] && m->input_picture[0]) {
 if (s->frame_skip_threshold || s->frame_skip_factor) {
 if (m->picture_in_gop_number < m->gop_size &&
 s->next_picture_ptr &&
-skip_check(m, s->input_picture[0], s->next_picture_ptr)) {
+skip_check(m, m->input_picture[0], s->next_picture_ptr)) {
 // FIXME check that the gop check above is +-1 correct
-av_frame_unref(s->input_picture[0]->f);
+av_frame_unref(m->input_picture[0]->f);
 
 ff_vbv_update(m, 0);
 
@@ -1393,7 +1391,7 @@ static int select_input_picture(MPVMainEncContext *m)
 
 if (/*s->picture_in_gop_number >= s->gop_size ||*/
 !s->next_picture_ptr || s->intra_only) {
-s->reordered_input_picture[0] = 

[FFmpeg-devel] [PATCH 25/41] avcodec/mpegvideo: Move pts and dts fields to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
user_specified_pts, dts_delta and reordered_pts are only used
by the main thread.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h | 10 --
 libavcodec/mpegvideo_enc.c | 22 +++---
 libavcodec/mpegvideoenc.h  | 11 +++
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index cab3abcc77..a334acb3aa 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -121,16 +121,6 @@ typedef struct MPVContext {
 Picture **input_picture;   ///< next pictures on display order for encoding
 Picture **reordered_input_picture; ///< pointer to the next pictures in 
coded order for encoding
 
-int64_t user_specified_pts; ///< last non-zero pts from AVFrame which was 
passed into avcodec_send_frame()
-/**
- * pts difference between the first and second input frame, used for
- * calculating dts of the first frame when there's a delay */
-int64_t dts_delta;
-/**
- * reordered pts to be used as dts for the next output frame when there's
- * a delay */
-int64_t reordered_pts;
-
 /** bit output */
 PutBitContext pb;
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 9477a02ae1..9b05b44d36 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -389,7 +389,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n");
 return AVERROR(EINVAL);
 }
-s->user_specified_pts = AV_NOPTS_VALUE;
+m->user_specified_pts = AV_NOPTS_VALUE;
 
 if (m->gop_size <= 1) {
 s->intra_only = 1;
@@ -1021,8 +1021,8 @@ static int load_input_picture(MPVMainEncContext *m, const 
AVFrame *pic_arg)
 display_picture_number = s->input_picture_number++;
 
 if (pts != AV_NOPTS_VALUE) {
-if (s->user_specified_pts != AV_NOPTS_VALUE) {
-int64_t last = s->user_specified_pts;
+if (m->user_specified_pts != AV_NOPTS_VALUE) {
+int64_t last = m->user_specified_pts;
 
 if (pts <= last) {
 av_log(s->avctx, AV_LOG_ERROR,
@@ -1032,13 +1032,13 @@ static int load_input_picture(MPVMainEncContext *m, 
const AVFrame *pic_arg)
 }
 
 if (!s->low_delay && display_picture_number == 1)
-s->dts_delta = pts - last;
+m->dts_delta = pts - last;
 }
-s->user_specified_pts = pts;
+m->user_specified_pts = pts;
 } else {
-if (s->user_specified_pts != AV_NOPTS_VALUE) {
-s->user_specified_pts =
-pts = s->user_specified_pts + 1;
+if (m->user_specified_pts != AV_NOPTS_VALUE) {
+m->user_specified_pts =
+pts = m->user_specified_pts + 1;
 av_log(s->avctx, AV_LOG_INFO,
"Warning: AVFrame.pts=? trying to guess (%"PRId64")\n",
pts);
@@ -1887,10 +1887,10 @@ vbv_retry:
 pkt->pts = s->current_picture.f->pts;
 if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) {
 if (!s->current_picture.f->coded_picture_number)
-pkt->dts = pkt->pts - s->dts_delta;
+pkt->dts = pkt->pts - m->dts_delta;
 else
-pkt->dts = s->reordered_pts;
-s->reordered_pts = pkt->pts;
+pkt->dts = m->reordered_pts;
+m->reordered_pts = pkt->pts;
 } else
 pkt->dts = pkt->pts;
 if (s->current_picture.f->key_frame)
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 3deee6d5fb..227701b3e3 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -43,6 +43,17 @@ typedef struct MPVMainEncContext {
 int gop_size;
 int picture_in_gop_number; ///< 0-> first pic in gop, ...
 
+/** last non-zero pts from AVFrame which was passed into 
avcodec_send_frame() */
+int64_t user_specified_pts;
+/**
+ * pts difference between the first and second input frame, used for
+ * calculating dts of the first frame when there's a delay */
+int64_t dts_delta;
+/**
+ * reordered pts to be used as dts for the next output frame when there's
+ * a delay */
+int64_t reordered_pts;
+
 /* bit rate control */
 int64_t total_bits;
 int frame_bits;///< bits used for the current frame
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 24/41] avcodec/mpegvideo: Move picture_in_gop_number to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Only ever used by the main encoding thread.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h |  1 -
 libavcodec/mpegvideo_enc.c | 14 +++---
 libavcodec/mpegvideoenc.h  |  1 +
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index c679b7e531..cab3abcc77 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -110,7 +110,6 @@ typedef struct MPVContext {
 int input_picture_number;  ///< used to set pic->display_picture_number, 
should not be used for/by anything else
 int coded_picture_number;  ///< used to set pic->coded_picture_number, 
should not be used for/by anything else
 int picture_number;   //FIXME remove, unclear definition
-int picture_in_gop_number; ///< 0-> first pic in gop, ...
 int mb_width, mb_height;   ///< number of MBs horizontally & vertically
 int mb_stride; ///< mb_width+1 used for some arrays to allow 
simple addressing of left & top MBs without sig11
 int b8_stride; ///< 2*mb_width+1 used for some 8x8 block 
arrays to allow simple addressing
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 5f3bc93da7..9477a02ae1 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -290,7 +290,7 @@ static void mpv_encode_defaults(MPVMainEncContext *m)
 s->fcode_tab = default_fcode_tab;
 
 s->input_picture_number  = 0;
-s->picture_in_gop_number = 0;
+m->picture_in_gop_number = 0;
 }
 
 av_cold int ff_dct_encode_init(MPVEncContext *s)
@@ -1379,7 +1379,7 @@ static int select_input_picture(MPVMainEncContext *m)
 /* set next picture type & ordering */
 if (!s->reordered_input_picture[0] && s->input_picture[0]) {
 if (s->frame_skip_threshold || s->frame_skip_factor) {
-if (s->picture_in_gop_number < m->gop_size &&
+if (m->picture_in_gop_number < m->gop_size &&
 s->next_picture_ptr &&
 skip_check(m, s->input_picture[0], s->next_picture_ptr)) {
 // FIXME check that the gop check above is +-1 correct
@@ -1463,10 +1463,10 @@ static int select_input_picture(MPVMainEncContext *m)
"warning, too many B-frames in a row\n");
 }
 
-if (s->picture_in_gop_number + b_frames >= m->gop_size) {
+if (m->picture_in_gop_number + b_frames >= m->gop_size) {
 if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&
-m->gop_size > s->picture_in_gop_number) {
-b_frames = m->gop_size - s->picture_in_gop_number - 1;
+m->gop_size > m->picture_in_gop_number) {
+b_frames = m->gop_size - m->picture_in_gop_number - 1;
 } else {
 if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)
 b_frames = 0;
@@ -1687,7 +1687,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket 
*pkt,
 
 s->vbv_ignore_qmax = 0;
 
-s->picture_in_gop_number++;
+m->picture_in_gop_number++;
 
 if (load_input_picture(m, pic_arg) < 0)
 return -1;
@@ -3717,7 +3717,7 @@ static int encode_picture(MPVMainEncContext *m, int 
picture_number)
 s->current_picture.f->pict_type = s->pict_type;
 
 if (s->current_picture.f->key_frame)
-s->picture_in_gop_number=0;
+m->picture_in_gop_number=0;
 
 s->mb_x = s->mb_y = 0;
 s->last_bits= put_bits_count(>pb);
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 1c101d01ac..3deee6d5fb 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -41,6 +41,7 @@ typedef struct MPVMainEncContext {
 int me_pre;  ///< prepass for motion estimation
 
 int gop_size;
+int picture_in_gop_number; ///< 0-> first pic in gop, ...
 
 /* bit rate control */
 int64_t total_bits;
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 23/41] avcodec/mpegvideo_enc: Don't set picture_in_gop_number for slice threads

2022-01-29 Thread Andreas Rheinhardt
They don't ever read this value.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_enc.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 785aeb2aee..5f3bc93da7 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -260,7 +260,6 @@ static void update_duplicate_context_after_me(MPVEncContext 
*dst,
 COPY(qscale);
 COPY(lambda);
 COPY(lambda2);
-COPY(picture_in_gop_number);
 COPY(frame_pred_frame_dct); // FIXME don't set in encode_header
 COPY(progressive_frame);// FIXME don't set in encode_header
 COPY(partitioned_frame);// FIXME don't set in encode_header
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 22/41] avcodec/mpegvideo: Move gop_size to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Only used by the main encoding thread.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h |  1 -
 libavcodec/mpegvideo_enc.c | 14 +++---
 libavcodec/mpegvideoenc.h  |  2 ++
 libavcodec/ratecontrol.c   |  2 +-
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 7089160765..c679b7e531 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -84,7 +84,6 @@ typedef struct MPVContext {
 void *private_ctx;
 /* the following parameters must be initialized before encoding */
 int width, height;///< picture size. must be a multiple of 16
-int gop_size;
 int intra_only;   ///< if true, only intra pictures are generated
 int64_t bit_rate; ///< wanted bit rate
 enum OutputFormat out_format; ///< output format
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 4da765a617..785aeb2aee 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -350,7 +350,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
avctx->gop_size, 600);
 avctx->gop_size = 600;
 }
-s->gop_size = avctx->gop_size;
+m->gop_size = avctx->gop_size;
 s->avctx= avctx;
 if (avctx->max_b_frames > MAX_B_FRAMES) {
 av_log(avctx, AV_LOG_ERROR, "Too many B-frames requested, maximum "
@@ -392,9 +392,9 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 }
 s->user_specified_pts = AV_NOPTS_VALUE;
 
-if (s->gop_size <= 1) {
+if (m->gop_size <= 1) {
 s->intra_only = 1;
-s->gop_size   = 12;
+m->gop_size   = 12;
 } else {
 s->intra_only = 0;
 }
@@ -1380,7 +1380,7 @@ static int select_input_picture(MPVMainEncContext *m)
 /* set next picture type & ordering */
 if (!s->reordered_input_picture[0] && s->input_picture[0]) {
 if (s->frame_skip_threshold || s->frame_skip_factor) {
-if (s->picture_in_gop_number < s->gop_size &&
+if (s->picture_in_gop_number < m->gop_size &&
 s->next_picture_ptr &&
 skip_check(m, s->input_picture[0], s->next_picture_ptr)) {
 // FIXME check that the gop check above is +-1 correct
@@ -1464,10 +1464,10 @@ static int select_input_picture(MPVMainEncContext *m)
"warning, too many B-frames in a row\n");
 }
 
-if (s->picture_in_gop_number + b_frames >= s->gop_size) {
+if (s->picture_in_gop_number + b_frames >= m->gop_size) {
 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;
+m->gop_size > s->picture_in_gop_number) {
+b_frames = m->gop_size - s->picture_in_gop_number - 1;
 } else {
 if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)
 b_frames = 0;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index d32e4372a7..1c101d01ac 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -40,6 +40,8 @@ typedef struct MPVMainEncContext {
 int me_penalty_compensation;
 int me_pre;  ///< prepass for motion estimation
 
+int gop_size;
+
 /* bit rate control */
 int64_t total_bits;
 int frame_bits;///< bits used for the current frame
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index b0f319680b..4e7bbe49a7 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -632,7 +632,7 @@ av_cold int ff_rate_control_init(MPVMainEncContext *m)
 double bits = s->rc_initial_cplx * (i / 1.0 + 1.0) * 
s->mb_num;
 RateControlEntry rce;
 
-if (i % ((s->gop_size + 3) / 4) == 0)
+if (i % ((m->gop_size + 3) / 4) == 0)
 rce.pict_type = AV_PICTURE_TYPE_I;
 else if (i % (s->max_b_frames + 1))
 rce.pict_type = AV_PICTURE_TYPE_B;
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 21/41] avcodec/mpegvideo: Move me_pre and me_penalty_compensation to enc-ctx

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h | 2 --
 libavcodec/mpegvideo_enc.c | 8 
 libavcodec/mpegvideoenc.h  | 7 +--
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index c9467f0752..7089160765 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -239,8 +239,6 @@ typedef struct MPVContext {
 uint8_t (*p_field_select_table[2]);  ///< Only the first element is 
allocated
 uint8_t (*b_field_select_table[2][2]); ///< Only the first element is 
allocated
 int motion_est;  ///< ME algorithm
-int me_penalty_compensation;
-int me_pre;  ///< prepass for motion estimation
 int mv_dir;
 #define MV_DIR_FORWARD   1
 #define MV_DIR_BACKWARD  2
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 3eb8260b06..4da765a617 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3561,11 +3561,11 @@ static int encode_picture(MPVMainEncContext *m, int 
picture_number)
 
 /* Estimate motion for every MB */
 if(s->pict_type != AV_PICTURE_TYPE_I){
-s->lambda  = (s->lambda  * s->me_penalty_compensation + 128) >> 8;
-s->lambda2 = (s->lambda2 * (int64_t) s->me_penalty_compensation + 128) 
>> 8;
+s->lambda  = (s->lambda  * m->me_penalty_compensation + 128) >> 8;
+s->lambda2 = (s->lambda2 * (int64_t) m->me_penalty_compensation + 128) 
>> 8;
 if (s->pict_type != AV_PICTURE_TYPE_B) {
-if ((s->me_pre && s->last_non_b_pict_type == AV_PICTURE_TYPE_I) ||
-s->me_pre == 2) {
+if ((m->me_pre && s->last_non_b_pict_type == AV_PICTURE_TYPE_I) ||
+m->me_pre == 2) {
 s->avctx->execute(s->avctx, pre_estimate_motion_thread, 
>thread_context[0], NULL, context_count, sizeof(void*));
 }
 }
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 6a96909e17..d32e4372a7 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -37,6 +37,9 @@ typedef MPVContext MPVEncContext;
 typedef struct MPVMainEncContext {
 MPVMainContext common;
 
+int me_penalty_compensation;
+int me_pre;  ///< prepass for motion estimation
+
 /* bit rate control */
 int64_t total_bits;
 int frame_bits;///< bits used for the current frame
@@ -123,8 +126,8 @@ FF_MPV_OPT_CMP_FUNC, \
 {"sc_threshold", "Scene change threshold",  
FF_MPV_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"noise_reduction", "Noise reduction",  
FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, 
FF_MPV_OPT_FLAGS }, \
 {"ps", "RTP payload size in bytes", 
FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, 
INT_MAX, FF_MPV_OPT_FLAGS }, \
-{"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", 
FF_MPV_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, 
INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
-{"mepre", "pre motion estimation", FF_MPV_OFFSET(me_pre), AV_OPT_TYPE_INT, 
{.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
+{"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", 
FF_MPV_MAIN_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, 
INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
+{"mepre", "pre motion estimation", FF_MPV_MAIN_OFFSET(me_pre), 
AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \
 {"intra_penalty", "Penalty for intra blocks in block decision", 
FF_MPV_OFFSET(intra_penalty), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX/2, 
FF_MPV_OPT_FLAGS }, \
 
 #define FF_MPV_COMMON_BFRAME_OPTS \
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 20/41] avcodec/mpegvideoenc: Move ratecontrol to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h |  8 
 libavcodec/mpegvideo_enc.c | 38 +++---
 libavcodec/mpegvideoenc.h  |  8 
 libavcodec/ratecontrol.c   | 31 +++
 libavcodec/snowenc.c   |  8 
 5 files changed, 46 insertions(+), 47 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index e83061fa92..c9467f0752 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -47,7 +47,6 @@
 #include "mpegvideodata.h"
 #include "pixblockdsp.h"
 #include "put_bits.h"
-#include "ratecontrol.h"
 #if FF_API_FLAG_TRUNCATED
 #include "parser.h"
 #endif
@@ -316,13 +315,6 @@ typedef struct MPVContext {
 int dct_count[2];
 uint16_t (*dct_offset)[64];
 
-/* bit rate control */
-int64_t total_bits;
-int frame_bits;///< bits used for the current frame
-int stuffing_bits; ///< bits used for stuffing
-int next_lambda;   ///< next lambda used for retrying to 
encode a frame
-RateControlContext rc_context; ///< contains stuff only accessed in 
ratecontrol.c
-
 /* statistics, used for 2-pass encoding */
 int mv_bits;
 int header_bits;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index bbff65ef41..3eb8260b06 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1405,15 +1405,15 @@ static int select_input_picture(MPVMainEncContext *m)
 for (i = 0; i < s->max_b_frames + 1; i++) {
 int pict_num = 
s->input_picture[0]->f->display_picture_number + i;
 
-if (pict_num >= s->rc_context.num_entries)
+if (pict_num >= m->rc_context.num_entries)
 break;
 if (!s->input_picture[i]) {
-s->rc_context.entry[pict_num - 1].new_pict_type = 
AV_PICTURE_TYPE_P;
+m->rc_context.entry[pict_num - 1].new_pict_type = 
AV_PICTURE_TYPE_P;
 break;
 }
 
 s->input_picture[i]->f->pict_type =
-s->rc_context.entry[pict_num].new_pict_type;
+m->rc_context.entry[pict_num].new_pict_type;
 }
 }
 
@@ -1743,14 +1743,14 @@ vbv_retry:
 ff_mjpeg_encode_picture_trailer(>pb, s->header_bits);
 
 if (avctx->rc_buffer_size) {
-RateControlContext *rcc = >rc_context;
+RateControlContext *rcc = >rc_context;
 int max_size = FFMAX(rcc->buffer_index * 
avctx->rc_max_available_vbv_use, rcc->buffer_index - 500);
 int hq = (avctx->mb_decision == FF_MB_DECISION_RD || 
avctx->trellis);
 int min_step = hq ? 1 : (1<<(FF_LAMBDA_SHIFT + 7))/139;
 
 if (put_bits_count(>pb) > max_size &&
 s->lambda < s->lmax) {
-s->next_lambda = FFMAX(s->lambda + min_step, s->lambda *
+m->next_lambda = FFMAX(s->lambda + min_step, s->lambda *
(s->qscale + 1) / s->qscale);
 if (s->adaptive_quant) {
 int i;
@@ -1801,10 +1801,10 @@ vbv_retry:
  s->misc_bits + s->i_tex_bits +
  s->p_tex_bits);
 flush_put_bits(>pb);
-s->frame_bits  = put_bits_count(>pb);
+m->frame_bits  = put_bits_count(>pb);
 
-stuffing_count = ff_vbv_update(m, s->frame_bits);
-s->stuffing_bits = 8*stuffing_count;
+stuffing_count = ff_vbv_update(m, m->frame_bits);
+m->stuffing_bits = 8 * stuffing_count;
 if (stuffing_count) {
 if (put_bytes_left(>pb, 0) < stuffing_count + 50) {
 av_log(avctx, AV_LOG_ERROR, "stuffing too large\n");
@@ -1828,10 +1828,10 @@ vbv_retry:
 break;
 default:
 av_log(avctx, AV_LOG_ERROR, "vbv buffer overflow\n");
-s->stuffing_bits = 0;
+m->stuffing_bits = 0;
 }
 flush_put_bits(>pb);
-s->frame_bits  = put_bits_count(>pb);
+m->frame_bits  = put_bits_count(>pb);
 }
 
 /* update MPEG-1/2 vbv_delay for CBR */
@@ -1846,9 +1846,9 @@ vbv_retry:
 int vbv_delay, min_delay;
 double inbits  = avctx->rc_max_rate *
  av_q2d(avctx->time_base);
-intminbits = s->frame_bits - 8 *
+intminbits = m->frame_bits - 8 *
  (s->vbv_delay_pos - 1);
-double bits= s->rc_context.buffer_index + minbits - inbits;
+double bits= m->rc_context.buffer_index + minbits - inbits;
 uint8_t *const vbv_delay_ptr = s->pb.buf + s->vbv_delay_pos;
 
 if (bits < 0)
@@ -1883,7 +1883,7 @@ vbv_retry:
 

[FFmpeg-devel] [PATCH 18/41] avcodec/mpegvideoenc: Add proper MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
This is in preparation for moving fields only used by
the main encoder thread from MPVContext to MPVMainEncContext.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dnxhdenc.c  | 302 +++--
 libavcodec/flvenc.c|   3 +-
 libavcodec/h261enc.c   |  15 +-
 libavcodec/ituh263enc.c|  13 +-
 libavcodec/mjpegenc.c  |  24 +--
 libavcodec/mpeg12enc.c |  23 +--
 libavcodec/mpeg4videoenc.c |  35 +++--
 libavcodec/mpegvideo_enc.c | 135 +
 libavcodec/mpegvideoenc.h  |   7 +-
 libavcodec/msmpeg4enc.c|  12 +-
 libavcodec/ratecontrol.c   |  59 +---
 libavcodec/ratecontrol.h   |   2 -
 libavcodec/rv10enc.c   |   3 +-
 libavcodec/rv20enc.c   |   3 +-
 libavcodec/snow.c  |  11 +-
 libavcodec/snowenc.c   | 170 +++--
 libavcodec/speedhqenc.c|   8 +-
 libavcodec/svq1enc.c   | 159 +--
 libavcodec/wmv2enc.c   |  12 +-
 19 files changed, 539 insertions(+), 457 deletions(-)

diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 74989276b9..9ad95ac20a 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -267,30 +267,31 @@ static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, 
int lbias, int cbias)
 int qscale, i;
 const uint8_t *luma_weight_table   = ctx->cid_table->luma_weight;
 const uint8_t *chroma_weight_table = ctx->cid_table->chroma_weight;
+MPVEncContext *const s = >m.common;
 
-if (!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_l,   ctx->m.avctx->qmax + 1) ||
-!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_c,   ctx->m.avctx->qmax + 1) ||
-!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_l16, ctx->m.avctx->qmax + 1) ||
-!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_c16, ctx->m.avctx->qmax + 1))
+if (!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_l,   s->avctx->qmax + 1) ||
+!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_c,   s->avctx->qmax + 1) ||
+!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_l16, s->avctx->qmax + 1) ||
+!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_c16, s->avctx->qmax + 1))
 return AVERROR(ENOMEM);
 
 if (ctx->bit_depth == 8) {
 for (i = 1; i < 64; i++) {
-int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]];
+int j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
 weight_matrix[j] = ctx->cid_table->luma_weight[i];
 }
-ff_convert_matrix(>m, ctx->qmatrix_l, ctx->qmatrix_l16,
+ff_convert_matrix(s, ctx->qmatrix_l, ctx->qmatrix_l16,
   weight_matrix, ctx->intra_quant_bias, 1,
-  ctx->m.avctx->qmax, 1);
+  s->avctx->qmax, 1);
 for (i = 1; i < 64; i++) {
-int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]];
+int j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
 weight_matrix[j] = ctx->cid_table->chroma_weight[i];
 }
-ff_convert_matrix(>m, ctx->qmatrix_c, ctx->qmatrix_c16,
+ff_convert_matrix(s, ctx->qmatrix_c, ctx->qmatrix_c16,
   weight_matrix, ctx->intra_quant_bias, 1,
-  ctx->m.avctx->qmax, 1);
+  s->avctx->qmax, 1);
 
-for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
+for (qscale = 1; qscale <= s->avctx->qmax; qscale++) {
 for (i = 0; i < 64; i++) {
 ctx->qmatrix_l[qscale][i]  <<= 2;
 ctx->qmatrix_c[qscale][i]  <<= 2;
@@ -302,7 +303,7 @@ static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, 
int lbias, int cbias)
 }
 } else {
 // 10-bit
-for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
+for (qscale = 1; qscale <= s->avctx->qmax; qscale++) {
 for (i = 1; i < 64; i++) {
 int j = ff_zigzag_direct[i];
 
@@ -325,22 +326,23 @@ static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, 
int lbias, int cbias)
 }
 }
 
-ctx->m.q_chroma_intra_matrix16 = ctx->qmatrix_c16;
-ctx->m.q_chroma_intra_matrix   = ctx->qmatrix_c;
-ctx->m.q_intra_matrix16= ctx->qmatrix_l16;
-ctx->m.q_intra_matrix  = ctx->qmatrix_l;
+s->q_chroma_intra_matrix16 = ctx->qmatrix_c16;
+s->q_chroma_intra_matrix   = ctx->qmatrix_c;
+s->q_intra_matrix16= ctx->qmatrix_l16;
+s->q_intra_matrix  = ctx->qmatrix_l;
 
 return 0;
 }
 
 static av_cold int dnxhd_init_rc(DNXHDEncContext *ctx)
 {
-if (!FF_ALLOCZ_TYPED_ARRAY(ctx->mb_rc, (ctx->m.avctx->qmax + 1) * 
ctx->m.mb_num))
+MPVEncContext *const s = >m.common;
+if (!FF_ALLOCZ_TYPED_ARRAY(ctx->mb_rc, (s->avctx->qmax + 1) * s->mb_num))
 return AVERROR(ENOMEM);
 
-if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) {
-if (!FF_ALLOCZ_TYPED_ARRAY(ctx->mb_cmp, ctx->m.mb_num) ||
-!FF_ALLOCZ_TYPED_ARRAY(ctx->mb_cmp_tmp, ctx->m.mb_num))
+if (s->avctx->mb_decision != FF_MB_DECISION_RD) 

[FFmpeg-devel] [PATCH 19/41] avcodec/mpegvideoenc: Move tmp bframes to MPVMainEncContext

2022-01-29 Thread Andreas Rheinhardt
Also move b_frame_strategy and b_sensitivity; they are all
only used by an encoder's main thread.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h |  5 
 libavcodec/mpegvideo_enc.c | 55 +++---
 libavcodec/mpegvideoenc.h  | 13 ++---
 3 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 1bad288ea5..e83061fa92 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -530,11 +530,6 @@ typedef struct MPVContext {
 
 int error_rate;
 
-/* temporary frames used by b_frame_strategy = 2 */
-AVFrame *tmp_frames[MAX_B_FRAMES + 2];
-int b_frame_strategy;
-int b_sensitivity;
-
 /* frame skip options for encoding */
 int frame_skip_threshold;
 int frame_skip_factor;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index a42cc0fa51..bbff65ef41 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -610,10 +610,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 return AVERROR(EINVAL);
 }
 
-if (s->b_frame_strategy && (avctx->flags & AV_CODEC_FLAG_PASS2)) {
+if (m->b_frame_strategy && (avctx->flags & AV_CODEC_FLAG_PASS2)) {
 av_log(avctx, AV_LOG_INFO,
"notice: b_frame_strategy only affects the first pass\n");
-s->b_frame_strategy = 0;
+m->b_frame_strategy = 0;
 }
 
 i = av_gcd(avctx->time_base.den, avctx->time_base.num);
@@ -902,17 +902,17 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 if ((ret = ff_rate_control_init(m)) < 0)
 return ret;
 
-if (s->b_frame_strategy == 2) {
+if (m->b_frame_strategy == 2) {
 for (i = 0; i < s->max_b_frames + 2; i++) {
-s->tmp_frames[i] = av_frame_alloc();
-if (!s->tmp_frames[i])
+m->tmp_frames[i] = av_frame_alloc();
+if (!m->tmp_frames[i])
 return AVERROR(ENOMEM);
 
-s->tmp_frames[i]->format = AV_PIX_FMT_YUV420P;
-s->tmp_frames[i]->width  = s->width  >> s->brd_scale;
-s->tmp_frames[i]->height = s->height >> s->brd_scale;
+m->tmp_frames[i]->format = AV_PIX_FMT_YUV420P;
+m->tmp_frames[i]->width  = s->width  >> s->brd_scale;
+m->tmp_frames[i]->height = s->height >> s->brd_scale;
 
-ret = av_frame_get_buffer(s->tmp_frames[i], 0);
+ret = av_frame_get_buffer(m->tmp_frames[i], 0);
 if (ret < 0)
 return ret;
 }
@@ -933,14 +933,13 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
 {
 MPVMainEncContext *const m = avctx->priv_data;
 MPVMainContext  *const s = >common;
-int i;
 
 ff_rate_control_uninit(m);
 
 ff_mpv_common_end(>common);
 
-for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++)
-av_frame_free(>tmp_frames[i]);
+for (int i = 0; i < FF_ARRAY_ELEMS(m->tmp_frames); i++)
+av_frame_free(>tmp_frames[i]);
 
 ff_mpv_picture_free(avctx, >new_picture);
 
@@ -1265,18 +1264,18 @@ static int estimate_best_b_count(MPVMainEncContext *m)
 data[2] += INPLACE_OFFSET;
 }
 
-s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[0],
-   s->tmp_frames[i]->linesize[0],
+s->mpvencdsp.shrink[scale](m->tmp_frames[i]->data[0],
+   m->tmp_frames[i]->linesize[0],
data[0],
pre_input.f->linesize[0],
width, height);
-s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[1],
-   s->tmp_frames[i]->linesize[1],
+s->mpvencdsp.shrink[scale](m->tmp_frames[i]->data[1],
+   m->tmp_frames[i]->linesize[1],
data[1],
pre_input.f->linesize[1],
width >> 1, height >> 1);
-s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[2],
-   s->tmp_frames[i]->linesize[2],
+s->mpvencdsp.shrink[scale](m->tmp_frames[i]->data[2],
+   m->tmp_frames[i]->linesize[2],
data[2],
pre_input.f->linesize[2],
width >> 1, height >> 1);
@@ -1313,10 +1312,10 @@ static int estimate_best_b_count(MPVMainEncContext *m)
 goto fail;
 
 
-s->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I;
-s->tmp_frames[0]->quality   = 1 * FF_QP2LAMBDA;
+m->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I;
+m->tmp_frames[0]->quality   = 1 * FF_QP2LAMBDA;
 
-out_size = encode_frame(c, s->tmp_frames[0], pkt);
+out_size = 

[FFmpeg-devel] [PATCH 17/41] avcodec/mpegvideo_enc: Don't find encoder by ID

2022-01-29 Thread Andreas Rheinhardt
mpegvideo-based encoders supporting bframes implement this
by opening encoders of their own to test how long the chains
of bframes are supposed to be. The needed AVCodec was obtained
via avcodec_find_encoder(). This is complicated, as the current
encoder can be directly obtained. And it also is not guaranteed
that one actually gets the current encoder or not another encoder
for the same codec ID (the latter does not seem to be the case now).

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_enc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 02efc9c2e9..f21febd4db 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1216,7 +1216,6 @@ static int encode_frame(AVCodecContext *c, AVFrame 
*frame, AVPacket *pkt)
 
 static int estimate_best_b_count(MPVMainEncContext *s)
 {
-const AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id);
 AVPacket *pkt;
 const int scale = s->brd_scale;
 int width  = s->width  >> scale;
@@ -1300,7 +1299,7 @@ static int estimate_best_b_count(MPVMainEncContext *s)
 c->time_base= s->avctx->time_base;
 c->max_b_frames = s->max_b_frames;
 
-ret = avcodec_open2(c, codec, NULL);
+ret = avcodec_open2(c, s->avctx->codec, NULL);
 if (ret < 0)
 goto fail;
 
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 15/41] avcodec/speedhqenc: Add SpeedHQEncContext and move slice_start to it

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h  |  3 ---
 libavcodec/speedhqenc.c | 19 ++-
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 18d2d0902f..8f65f53c2a 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -421,9 +421,6 @@ typedef struct MpegEncContext {
 int inter_intra_pred;
 int mspel;
 
-/* SpeedHQ specific */
-int slice_start;
-
 /* decompression specific */
 GetBitContext gb;
 
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index 806eae7cf1..ba3b1d9393 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -55,6 +55,12 @@ static uint32_t speedhq_chr_dc_uni[512];
 
 static uint8_t uni_speedhq_ac_vlc_len[64 * 64 * 2];
 
+typedef struct SpeedHQEncContext {
+MpegEncContext m;
+
+int slice_start;
+} SpeedHQEncContext;
+
 static av_cold void speedhq_init_static_data(void)
 {
 ff_rl_init(_rl_speedhq, speedhq_static_rl_table_store);
@@ -124,24 +130,27 @@ av_cold int ff_speedhq_encode_init(MpegEncContext *s)
 
 void ff_speedhq_encode_picture_header(MpegEncContext *s)
 {
+SpeedHQEncContext *ctx = (SpeedHQEncContext*)s;
+
 put_bits_le(>pb, 8, 100 - s->qscale * 2);  /* FIXME why doubled */
 put_bits_le(>pb, 24, 4);  /* no second field */
 
+ctx->slice_start = 4;
 /* length of first slice, will be filled out later */
-s->slice_start = 4;
 put_bits_le(>pb, 24, 0);
 }
 
 void ff_speedhq_end_slice(MpegEncContext *s)
 {
+SpeedHQEncContext *ctx = (SpeedHQEncContext*)s;
 int slice_len;
 
 flush_put_bits_le(>pb);
-slice_len = s->pb.buf_ptr - (s->pb.buf + s->slice_start);
-AV_WL24(s->pb.buf + s->slice_start, slice_len);
+slice_len = put_bytes_output(>pb) - ctx->slice_start;
+AV_WL24(s->pb.buf + ctx->slice_start, slice_len);
 
 /* length of next slice, will be filled out later */
-s->slice_start = s->pb.buf_ptr - s->pb.buf;
+ctx->slice_start = put_bytes_output(>pb);
 put_bits_le(>pb, 24, 0);
 }
 
@@ -274,7 +283,7 @@ const AVCodec ff_speedhq_encoder = {
 .type   = AVMEDIA_TYPE_VIDEO,
 .id = AV_CODEC_ID_SPEEDHQ,
 .priv_class = _mpv_enc_class,
-.priv_data_size = sizeof(MpegEncContext),
+.priv_data_size = sizeof(SpeedHQEncContext),
 .init   = ff_mpv_encode_init,
 .encode2= ff_mpv_encode_picture,
 .close  = ff_mpv_encode_end,
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 14/41] avcodec/avcodec: Avoid MpegEncContext in AVHWAccel.decode_mb

2022-01-29 Thread Andreas Rheinhardt
Use an opaque pointer to void instead.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/avcodec.h| 6 +-
 libavcodec/mpegvideo_xvmc.c | 3 ++-
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ec1a0566a4..918753fd0e 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2026,8 +2026,6 @@ typedef struct AVCodecContext {
 int (*get_encode_buffer)(struct AVCodecContext *s, AVPacket *pkt, int 
flags);
 } AVCodecContext;
 
-struct MpegEncContext;
-
 /**
  * @defgroup lavc_hwaccel AVHWAccel
  *
@@ -2154,10 +2152,8 @@ typedef struct AVHWAccel {
  * XvMC uses it to replace the ff_mpv_reconstruct_mb().
  * Instead of decoding to raw picture, MB parameters are
  * stored in an array provided by the video driver.
- *
- * @param s the mpeg context
  */
-void (*decode_mb)(struct MpegEncContext *s);
+void (*decode_mb)(void *opaque);
 
 /**
  * Initialize the hwaccel private data.
diff --git a/libavcodec/mpegvideo_xvmc.c b/libavcodec/mpegvideo_xvmc.c
index f06583768c..bfeb453834 100644
--- a/libavcodec/mpegvideo_xvmc.c
+++ b/libavcodec/mpegvideo_xvmc.c
@@ -168,8 +168,9 @@ static int ff_xvmc_field_end(AVCodecContext *avctx)
  * Synthesize the data needed by XvMC to render one macroblock of data.
  * Fill all relevant fields, if necessary do IDCT.
  */
-static void ff_xvmc_decode_mb(struct MpegEncContext *s)
+static void ff_xvmc_decode_mb(void *opaque)
 {
+MpegEncContext *const s = opaque;
 XvMCMacroBlock *mv_block;
 struct xvmc_pix_fmt *render;
 int i, cbp, blocks_per_mb;
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 13/41] avcodec/mpegvideo: Move encoder-only stuff to a new header

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/dnxhdenc.c   |   1 +
 libavcodec/flvdec.c |   1 +
 libavcodec/flvenc.c |   1 +
 libavcodec/h261enc.c|   1 +
 libavcodec/h263enc.h|   2 +-
 libavcodec/intelh263dec.c   |   1 +
 libavcodec/ituh263enc.c |   1 +
 libavcodec/libxavs2.c   |   2 +
 libavcodec/mdec.c   |   1 +
 libavcodec/mjpegenc.c   |   1 +
 libavcodec/motion_est.c |   2 +-
 libavcodec/mpeg12.h |   1 +
 libavcodec/mpeg12enc.c  |   1 +
 libavcodec/mpeg4videoenc.c  |   1 +
 libavcodec/mpegvideo.h  | 126 -
 libavcodec/mpegvideo_enc.c  |   1 +
 libavcodec/mpegvideoenc.h   | 161 
 libavcodec/msmpeg4enc.c |   1 +
 libavcodec/nvdec_mpeg12.c   |   1 +
 libavcodec/nvdec_mpeg4.c|   1 +
 libavcodec/ratecontrol.c|   2 +-
 libavcodec/rv10enc.c|   1 +
 libavcodec/rv20enc.c|   1 +
 libavcodec/rv30.c   |   1 +
 libavcodec/rv40.c   |   1 +
 libavcodec/speedhqenc.c |   1 +
 libavcodec/vaapi_encode_mpeg2.c |   2 +
 libavcodec/wmv2enc.c|   1 +
 libavcodec/x86/mpegvideoenc.c   |   2 +-
 29 files changed, 190 insertions(+), 130 deletions(-)
 create mode 100644 libavcodec/mpegvideoenc.h

diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index ca67964330..ac92474e56 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -34,6 +34,7 @@
 #include "fdctdsp.h"
 #include "internal.h"
 #include "mpegvideo.h"
+#include "mpegvideoenc.h"
 #include "pixblockdsp.h"
 #include "packet_internal.h"
 #include "profiles.h"
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c
index 2bd86b5b47..108cf88e34 100644
--- a/libavcodec/flvdec.c
+++ b/libavcodec/flvdec.c
@@ -22,6 +22,7 @@
 
 #include "flv.h"
 #include "h263dec.h"
+#include "internal.h"
 #include "mpegvideo.h"
 #include "mpegvideodata.h"
 
diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index 158b399c40..6824327734 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -22,6 +22,7 @@
 #include "h263data.h"
 #include "mpegvideo.h"
 #include "mpegvideodata.h"
+#include "mpegvideoenc.h"
 
 void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number)
 {
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 7e3af1ff9e..710d292df6 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -33,6 +33,7 @@
 #include "mpegvideo.h"
 #include "h261.h"
 #include "mpegvideodata.h"
+#include "mpegvideoenc.h"
 
 static uint8_t uni_h261_rl_len [64*64*2*2];
 #define UNI_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
diff --git a/libavcodec/h263enc.h b/libavcodec/h263enc.h
index 31f00665ce..fff85a18f2 100644
--- a/libavcodec/h263enc.h
+++ b/libavcodec/h263enc.h
@@ -22,7 +22,7 @@
 
 #include 
 #include "h263data.h"
-#include "mpegvideo.h"
+#include "mpegvideoenc.h"
 
 void ff_h263_encode_init(MpegEncContext *s);
 void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number);
diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c
index 9dde247298..b61effa4df 100644
--- a/libavcodec/intelh263dec.c
+++ b/libavcodec/intelh263dec.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "internal.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
 #include "h263data.h"
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 70ac1f643b..ef7caf8009 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -34,6 +34,7 @@
 #include "avcodec.h"
 #include "mpegvideo.h"
 #include "mpegvideodata.h"
+#include "mpegvideoenc.h"
 #include "h263.h"
 #include "h263enc.h"
 #include "h263data.h"
diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
index 9c5a576e90..4742b18f9f 100644
--- a/libavcodec/libxavs2.c
+++ b/libavcodec/libxavs2.c
@@ -24,8 +24,10 @@
 
 #include "xavs2.h"
 #include "encode.h"
+#include "internal.h"
 #include "mpeg12.h"
 #include "libavutil/avstring.h"
+#include "libavutil/opt.h"
 
 #define xavs2_opt_set2(name, format, ...) do{ \
 char opt_str[16] = {0}; \
diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 007e7fada8..f340bdf385 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -33,6 +33,7 @@
 #include "blockdsp.h"
 #include "bswapdsp.h"
 #include "idctdsp.h"
+#include "internal.h"
 #include "mpeg12.h"
 #include "mpeg12data.h"
 #include "thread.h"
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 6a47503ab4..b9b17a50df 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -39,6 +39,7 @@
 #include "mpegvideo.h"
 #include "mjpeg.h"
 #include "mjpegenc.h"
+#include "mpegvideoenc.h"
 #include "profiles.h"
 
 /* The following is the private context of MJPEG/AMV decoder.
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index 5b0958733c..35ca40b90a 100644
--- 

[FFmpeg-devel] [PATCH 10/41] avcodec/msmpeg4.h: Move encoder-only stuff to a new header

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_enc.c |  2 +-
 libavcodec/msmpeg4.h   | 15 -
 libavcodec/msmpeg4enc.c|  1 +
 libavcodec/msmpeg4enc.h| 45 ++
 libavcodec/wmv2enc.c   |  1 +
 5 files changed, 48 insertions(+), 16 deletions(-)
 create mode 100644 libavcodec/msmpeg4enc.h

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6df2a46eaa..4bc78841ac 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -56,7 +56,7 @@
 #include "mpegutils.h"
 #include "mjpegenc.h"
 #include "speedhqenc.h"
-#include "msmpeg4.h"
+#include "msmpeg4enc.h"
 #include "pixblockdsp.h"
 #include "qpeldsp.h"
 #include "faandct.h"
diff --git a/libavcodec/msmpeg4.h b/libavcodec/msmpeg4.h
index 483c965b9d..dbe650cbbc 100644
--- a/libavcodec/msmpeg4.h
+++ b/libavcodec/msmpeg4.h
@@ -28,7 +28,6 @@
 #include "avcodec.h"
 #include "mpegvideo.h"
 #include "msmpeg4data.h"
-#include "put_bits.h"
 
 #define INTER_INTRA_VLC_BITS 3
 #define MB_NON_INTRA_VLC_BITS 9
@@ -42,20 +41,10 @@
 extern VLC ff_mb_non_intra_vlc[4];
 extern VLC ff_inter_intra_vlc;
 
-void ff_msmpeg4_code012(PutBitContext *pb, int n);
 void ff_msmpeg4_common_init(MpegEncContext *s);
-void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n);
-void ff_msmpeg4_handle_slices(MpegEncContext *s);
-void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my);
 int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n,
 uint8_t **coded_block_ptr);
 
-void ff_msmpeg4_encode_init(MpegEncContext *s);
-void ff_msmpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
-void ff_msmpeg4_encode_ext_header(MpegEncContext *s);
-void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64],
-  int motion_x, int motion_y);
-
 int ff_msmpeg4_decode_init(AVCodecContext *avctx);
 int ff_msmpeg4_decode_picture_header(MpegEncContext *s);
 int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size);
@@ -72,9 +61,5 @@ int ff_msmpeg4_pred_dc(MpegEncContext *s, int n,
 CONFIG_WMV1_DECODER  || \
 CONFIG_WMV2_DECODER  || \
 CONFIG_VC1_DECODER)
-#define CONFIG_MSMPEG4_ENCODER (CONFIG_MSMPEG4V2_ENCODER || \
-CONFIG_MSMPEG4V3_ENCODER || \
-CONFIG_WMV1_ENCODER  || \
-CONFIG_WMV2_ENCODER)
 
 #endif /* AVCODEC_MSMPEG4_H */
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 2c619e1210..31920b7f0d 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -39,6 +39,7 @@
 #include "mpeg4video.h"
 #include "msmpeg4.h"
 #include "msmpeg4data.h"
+#include "msmpeg4enc.h"
 #include "put_bits.h"
 #include "rl.h"
 #include "vc1data.h"
diff --git a/libavcodec/msmpeg4enc.h b/libavcodec/msmpeg4enc.h
new file mode 100644
index 00..12f8f44232
--- /dev/null
+++ b/libavcodec/msmpeg4enc.h
@@ -0,0 +1,45 @@
+/*
+ * MSMPEG4 encoder header
+ * copyright (c) 2007 Aurelien Jacobs 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_MSMPEG4ENC_H
+#define AVCODEC_MSMPEG4ENC_H
+
+#include "config.h"
+#include "mpegvideo.h"
+#include "put_bits.h"
+
+void ff_msmpeg4_encode_init(MpegEncContext *s);
+void ff_msmpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
+void ff_msmpeg4_encode_ext_header(MpegEncContext *s);
+void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64],
+  int motion_x, int motion_y);
+void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n);
+void ff_msmpeg4_handle_slices(MpegEncContext *s);
+void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my);
+
+void ff_msmpeg4_code012(PutBitContext *pb, int n);
+
+#define CONFIG_MSMPEG4_ENCODER (CONFIG_MSMPEG4V2_ENCODER || \
+CONFIG_MSMPEG4V3_ENCODER || \
+CONFIG_WMV1_ENCODER  || \
+CONFIG_WMV2_ENCODER)
+
+#endif
diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c
index a7827f3194..6036a0dec9 100644
--- 

[FFmpeg-devel] [PATCH 12/41] avcodec/h263.h: Move encoder-only stuff to a new header h263enc.h

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h263.h  |  99 
 libavcodec/h263enc.h   | 130 +
 libavcodec/ituh263enc.c|   1 +
 libavcodec/mpeg4videodec.c |   1 +
 libavcodec/mpeg4videoenc.c |   1 +
 libavcodec/mpegvideo_enc.c |   1 +
 libavcodec/msmpeg4dec.c|   1 +
 libavcodec/msmpeg4enc.c|   1 +
 libavcodec/rv20enc.c   |   2 +-
 libavcodec/snowenc.c   |   2 +-
 libavcodec/svq1enc.c   |   1 +
 11 files changed, 139 insertions(+), 101 deletions(-)
 create mode 100644 libavcodec/h263enc.h

diff --git a/libavcodec/h263.h b/libavcodec/h263.h
index 6dd5d2295a..5e4a5bc6e5 100644
--- a/libavcodec/h263.h
+++ b/libavcodec/h263.h
@@ -20,119 +20,20 @@
 #ifndef AVCODEC_H263_H
 #define AVCODEC_H263_H
 
-#include 
 #include "libavutil/rational.h"
 #include "mpegvideo.h"
-#include "h263data.h"
 
 #define FF_ASPECT_EXTENDED 15
 
 #define H263_GOB_HEIGHT(h) ((h) <= 400 ? 1 : (h) <= 800 ? 2 : 4)
 
 av_const int ff_h263_aspect_to_info(AVRational aspect);
-void ff_h263_encode_mb(MpegEncContext *s,
-   int16_t block[6][64],
-   int motion_x, int motion_y);
-void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number);
-void ff_h263_encode_gob_header(MpegEncContext * s, int mb_line);
 int16_t *ff_h263_pred_motion(MpegEncContext * s, int block, int dir,
  int *px, int *py);
-void ff_h263_encode_init(MpegEncContext *s);
 void ff_h263_init_rl_inter(void);
 void ff_h263_update_motion_val(MpegEncContext * s);
 void ff_h263_loop_filter(MpegEncContext * s);
-void ff_h263_encode_mba(MpegEncContext *s);
-void ff_init_qscale_tab(MpegEncContext *s);
 
 
-void ff_clean_h263_qscales(MpegEncContext *s);
-void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code);
-
-
-static inline int h263_get_motion_length(int val, int f_code){
-int bit_size, code, sign;
-
-if (val == 0) {
-return 1; /* ff_mvtab[0][1] */
-} else {
-bit_size = f_code - 1;
-/* modulo encoding */
-val  = sign_extend(val, 6 + bit_size);
-sign = val >> 31;
-val  = (val ^ sign) - sign; /* val = FFABS(val) */
-val--;
-code = (val >> bit_size) + 1;
-
-return ff_mvtab[code][1] + 1 + bit_size;
-}
-}
-
-static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int 
y, int f_code){
-if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) {
-skip_put_bits(>pb,
-h263_get_motion_length(x, f_code)
-   +h263_get_motion_length(y, f_code));
-}else{
-ff_h263_encode_motion(>pb, x, f_code);
-ff_h263_encode_motion(>pb, y, f_code);
-}
-}
-
-static inline int get_p_cbp(MpegEncContext * s,
-  int16_t block[6][64],
-  int motion_x, int motion_y){
-int cbp, i;
-
-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);
-const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 
8 : 0);
-const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
-
-for(i=0; i<4; i++){
-int score= ff_h263_inter_MCBPC_bits[i + offset] * lambda;
-if(i&1) score += s->coded_score[5];
-if(i&2) score += s->coded_score[4];
-
-if(score < best_cbpc_score){
-best_cbpc_score= score;
-cbpc= i;
-}
-}
-
-for(i=0; i<16; i++){
-int score= ff_h263_cbpy_tab[i ^ 0xF][1] * lambda;
-if(i&1) score += s->coded_score[3];
-if(i&2) score += s->coded_score[2];
-if(i&4) score += s->coded_score[1];
-if(i&8) score += s->coded_score[0];
-
-if(score < best_cbpy_score){
-best_cbpy_score= score;
-cbpy= i;
-}
-}
-cbp= cbpc + 4*cbpy;
-if ((motion_x | motion_y | s->dquant) == 0 && 
s->mv_type==MV_TYPE_16X16){
-if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0)
-cbp= 0;
-}
-
-for (i = 0; i < 6; i++) {
-if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){
-s->block_last_index[i]= -1;
-s->bdsp.clear_block(s->block[i]);
-}
-}
-}else{
-cbp= 0;
-for (i = 0; i < 6; i++) {
-if (s->block_last_index[i] >= 0)
-cbp |= 1 << (5 - i);
-}
-}
-return cbp;
-}
 
 #endif /* AVCODEC_H263_H */
diff --git a/libavcodec/h263enc.h b/libavcodec/h263enc.h
new file mode 100644
index 00..31f00665ce
--- /dev/null
+++ b/libavcodec/h263enc.h
@@ -0,0 +1,130 @@
+/*
+ * H.263 encoder header
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 

[FFmpeg-devel] [PATCH 11/41] avcodec/msmpegenc: Add MSMPEG4EncContext and move ac_stats to it

2022-01-29 Thread Andreas Rheinhardt
Also avoid the allocation by making it part of the context.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h |  2 --
 libavcodec/mpegvideo_enc.c |  7 ---
 libavcodec/msmpeg4enc.c| 26 +++---
 libavcodec/msmpeg4enc.h|  8 
 libavcodec/wmv2enc.c   |  8 
 5 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 5e406b9a9c..f5c9789fea 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -422,8 +422,6 @@ typedef struct MpegEncContext {
 int per_mb_rl_table;
 int esc3_level_length;
 int esc3_run_length;
-/** [mb_intra][isChroma][level][run][last] */
-int (*ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2];
 int inter_intra_pred;
 int mspel;
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 4bc78841ac..0e38824cca 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -813,12 +813,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 ff_pixblockdsp_init(>pdsp, avctx);
 ff_qpeldsp_init(>qdsp);
 
-if (s->msmpeg4_version) {
-int ac_stats_size = 2 * 2 * (MAX_LEVEL + 1) *  (MAX_RUN + 1) * 2 * 
sizeof(int);
-if (!(s->ac_stats = av_mallocz(ac_stats_size)))
-return AVERROR(ENOMEM);
-}
-
 if (!(avctx->stats_out = av_mallocz(256))   ||
 !FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix,  32) ||
 !FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix,   32) ||
@@ -944,7 +938,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
 ff_mpv_picture_free(avctx, >new_picture);
 
 av_freep(>stats_out);
-av_freep(>ac_stats);
 
 if(s->q_chroma_intra_matrix   != s->q_intra_matrix  ) 
av_freep(>q_chroma_intra_matrix);
 if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) 
av_freep(>q_chroma_intra_matrix16);
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 31920b7f0d..c436f78f9d 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -148,8 +148,9 @@ av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
 ff_thread_once(_static_once, msmpeg4_encode_init_static);
 }
 
-static void find_best_tables(MpegEncContext * s)
+static void find_best_tables(MSMPEG4EncContext *ms)
 {
+MpegEncContext *const s = >s;
 int i;
 int best= 0, best_size= INT_MAX;
 int chroma_best = 0, best_chroma_size = INT_MAX;
@@ -169,9 +170,9 @@ static void find_best_tables(MpegEncContext * s)
 int last;
 const int last_size= size + chroma_size;
 for(last=0; last<2; last++){
-int inter_count   = 
s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
-int intra_luma_count  = 
s->ac_stats[1][0][level][run][last];
-int intra_chroma_count= 
s->ac_stats[1][1][level][run][last];
+int inter_count   = 
ms->ac_stats[0][0][level][run][last] + ms->ac_stats[0][1][level][run][last];
+int intra_luma_count  = 
ms->ac_stats[1][0][level][run][last];
+int intra_chroma_count= 
ms->ac_stats[1][1][level][run][last];
 
 if(s->pict_type==AV_PICTURE_TYPE_I){
 size   += intra_luma_count  *rl_length[i  
][level][run][last];
@@ -197,7 +198,7 @@ static void find_best_tables(MpegEncContext * s)
 
 if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;
 
-memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
+memset(ms->ac_stats, 0, sizeof(ms->ac_stats));
 
 s->rl_table_index   =best;
 s->rl_chroma_table_index= chroma_best;
@@ -215,7 +216,9 @@ static void find_best_tables(MpegEncContext * s)
 /* write MSMPEG4 compatible frame header */
 void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
 {
-find_best_tables(s);
+MSMPEG4EncContext *const ms = (MSMPEG4EncContext*)s;
+
+find_best_tables(ms);
 
 align_put_bits(>pb);
 put_bits(>pb, 2, s->pict_type - 1);
@@ -553,6 +556,7 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int 
level, int n, int *dir_ptr
  * escape coding (same as H.263) and more VLC tables. */
 void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n)
 {
+MSMPEG4EncContext *const ms = (MSMPEG4EncContext*)s;
 int level, run, last, i, j, last_index;
 int last_non_zero, sign, slevel;
 int code, run_diff, dc_pred_dir;
@@ -603,10 +607,10 @@ void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t 
* block, int n)
 }
 
 if(level<=MAX_LEVEL && run<=MAX_RUN){
-s->ac_stats[s->mb_intra][n>3][level][run][last]++;
+ms->ac_stats[s->mb_intra][n>3][level][run][last]++;
 }
 
-s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
+ms->ac_stats[s->mb_intra][n > 

[FFmpeg-devel] [PATCH 09/41] avcodec/wmv2: Split Wmv2Context into decoder and encoder context

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/wmv2.c|  6 ++---
 libavcodec/wmv2.h| 26 +++---
 libavcodec/wmv2dec.c | 64 +++-
 libavcodec/wmv2enc.c | 29 +++-
 4 files changed, 73 insertions(+), 52 deletions(-)

diff --git a/libavcodec/wmv2.c b/libavcodec/wmv2.c
index 57e1267782..8d1d117dea 100644
--- a/libavcodec/wmv2.c
+++ b/libavcodec/wmv2.c
@@ -25,9 +25,9 @@
 #include "wmv2.h"
 
 
-av_cold void ff_wmv2_common_init(Wmv2Context *w)
+av_cold void ff_wmv2_common_init(MpegEncContext *s)
 {
-MpegEncContext *const s = >s;
+WMV2Context *const w = s->private_ctx;
 
 ff_blockdsp_init(>bdsp, s->avctx);
 ff_wmv2dsp_init(>wdsp);
@@ -52,7 +52,7 @@ void ff_mspel_motion(MpegEncContext *s, uint8_t *dest_y,
  uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
  int motion_x, int motion_y, int h)
 {
-Wmv2Context *const w = (Wmv2Context *) s;
+WMV2Context *const w = s->private_ctx;
 uint8_t *ptr;
 int dxy, mx, my, src_x, src_y, v_edge_pos;
 ptrdiff_t offset, linesize, uvlinesize;
diff --git a/libavcodec/wmv2.h b/libavcodec/wmv2.h
index 1798dbabcd..4001093881 100644
--- a/libavcodec/wmv2.h
+++ b/libavcodec/wmv2.h
@@ -21,9 +21,6 @@
 #ifndef AVCODEC_WMV2_H
 #define AVCODEC_WMV2_H
 
-#include "libavutil/mem_internal.h"
-
-#include "intrax8.h"
 #include "mpegvideo.h"
 #include "wmv2dsp.h"
 
@@ -33,29 +30,12 @@
 #define SKIP_TYPE_COL  3
 
 
-typedef struct Wmv2Context {
-MpegEncContext s;
-IntraX8Context x8;
+typedef struct WMV2Context {
 WMV2DSPContext wdsp;
-int j_type_bit;
-int j_type;
-int abt_flag;
-int abt_type;
-int abt_type_table[6];
-int per_mb_abt;
-int per_block_abt;
-int mspel_bit;
-int cbp_table_index;
-int top_left_mv_flag;
-int per_mb_rl_bit;
-int skip_type;
 int hshift;
+} WMV2Context;
 
-ScanTable abt_scantable[2];
-DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64];
-} Wmv2Context;
-
-void ff_wmv2_common_init(Wmv2Context *w);
+void ff_wmv2_common_init(MpegEncContext *s);
 
 int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]);
 int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number);
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index dd0e2683f5..f9d91f9571 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mem_internal.h"
+
 #include "avcodec.h"
 #include "h263dec.h"
 #include "internal.h"
@@ -31,8 +33,28 @@
 #include "wmv2.h"
 #include "wmv2data.h"
 
-
-static void wmv2_add_block(Wmv2Context *w, int16_t *block1,
+typedef struct WMV2DecContext {
+MpegEncContext s;
+WMV2Context common;
+IntraX8Context x8;
+int j_type_bit;
+int j_type;
+int abt_flag;
+int abt_type;
+int abt_type_table[6];
+int per_mb_abt;
+int per_block_abt;
+int mspel_bit;
+int cbp_table_index;
+int top_left_mv_flag;
+int per_mb_rl_bit;
+int skip_type;
+
+ScanTable abt_scantable[2];
+DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64];
+} WMV2DecContext;
+
+static void wmv2_add_block(WMV2DecContext *w, int16_t *block1,
uint8_t *dst, int stride, int n)
 {
 MpegEncContext *const s = >s;
@@ -40,7 +62,7 @@ static void wmv2_add_block(Wmv2Context *w, int16_t *block1,
 if (s->block_last_index[n] >= 0) {
 switch (w->abt_type_table[n]) {
 case 0:
-w->wdsp.idct_add(dst, stride, block1);
+w->common.wdsp.idct_add(dst, stride, block1);
 break;
 case 1:
 ff_simple_idct84_add(dst, stride, block1);
@@ -61,7 +83,7 @@ static void wmv2_add_block(Wmv2Context *w, int16_t *block1,
 void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64],
 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr)
 {
-Wmv2Context *const w = (Wmv2Context *) s;
+WMV2DecContext *const w = (WMV2DecContext *) s;
 
 wmv2_add_block(w, block1[0], dest_y,   s->linesize, 0);
 wmv2_add_block(w, block1[1], dest_y + 8,   s->linesize, 1);
@@ -75,7 +97,7 @@ void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64],
 wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5);
 }
 
-static int parse_mb_skip(Wmv2Context *w)
+static int parse_mb_skip(WMV2DecContext *w)
 {
 int mb_x, mb_y;
 int coded_mb_count = 0;
@@ -140,7 +162,7 @@ static int parse_mb_skip(Wmv2Context *w)
 return 0;
 }
 
-static int decode_ext_header(Wmv2Context *w)
+static int decode_ext_header(WMV2DecContext *w)
 {
 MpegEncContext *const s = >s;
 GetBitContext gb;
@@ -180,7 +202,7 @@ static int decode_ext_header(Wmv2Context *w)
 
 int ff_wmv2_decode_picture_header(MpegEncContext *s)
 {
-Wmv2Context *const w = (Wmv2Context *) s;
+WMV2DecContext *const w = 

[FFmpeg-devel] [PATCH 08/41] avcodec/wmv2: Move initializing abt_scantables to the decoder

2022-01-29 Thread Andreas Rheinhardt
They are not used by the encoder at all.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/wmv2.c| 6 --
 libavcodec/wmv2dec.c | 6 ++
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/wmv2.c b/libavcodec/wmv2.c
index fd64a0938f..57e1267782 100644
--- a/libavcodec/wmv2.c
+++ b/libavcodec/wmv2.c
@@ -20,11 +20,9 @@
 
 #include "avcodec.h"
 #include "idctdsp.h"
-#include "mpegutils.h"
 #include "mpegvideo.h"
 #include "msmpeg4data.h"
 #include "wmv2.h"
-#include "wmv2data.h"
 
 
 av_cold void ff_wmv2_common_init(Wmv2Context *w)
@@ -36,10 +34,6 @@ av_cold void ff_wmv2_common_init(Wmv2Context *w)
 s->idsp.perm_type = w->wdsp.idct_perm;
 ff_init_scantable_permutation(s->idsp.idct_permutation,
   w->wdsp.idct_perm);
-ff_init_scantable(s->idsp.idct_permutation, >abt_scantable[0],
-  ff_wmv2_scantableA);
-ff_init_scantable(s->idsp.idct_permutation, >abt_scantable[1],
-  ff_wmv2_scantableB);
 ff_init_scantable(s->idsp.idct_permutation, >intra_scantable,
   ff_wmv1_scantable[1]);
 ff_init_scantable(s->idsp.idct_permutation, >intra_h_scantable,
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 7518088b6a..dd0e2683f5 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -29,6 +29,7 @@
 #include "msmpeg4data.h"
 #include "simple_idct.h"
 #include "wmv2.h"
+#include "wmv2data.h"
 
 
 static void wmv2_add_block(Wmv2Context *w, int16_t *block1,
@@ -537,12 +538,17 @@ int ff_wmv2_decode_mb(MpegEncContext *s, int16_t 
block[6][64])
 static av_cold int wmv2_decode_init(AVCodecContext *avctx)
 {
 Wmv2Context *const w = avctx->priv_data;
+MpegEncContext *const s = >s;
 int ret;
 
 if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
 return ret;
 
 ff_wmv2_common_init(w);
+ff_init_scantable(s->idsp.idct_permutation, >abt_scantable[0],
+  ff_wmv2_scantableA);
+ff_init_scantable(s->idsp.idct_permutation, >abt_scantable[1],
+  ff_wmv2_scantableB);
 
 return ff_intrax8_common_init(avctx, >x8, >s.idsp,
   w->s.block, w->s.block_last_index,
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 07/41] avcodec/idctdsp: Constify the permutation parameter of ff_init_scantable

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/idctdsp.c | 2 +-
 libavcodec/idctdsp.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c
index 71bd03c606..d07dc29207 100644
--- a/libavcodec/idctdsp.c
+++ b/libavcodec/idctdsp.c
@@ -26,7 +26,7 @@
 #include "simple_idct.h"
 #include "xvididct.h"
 
-av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st,
+av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
const uint8_t *src_scantable)
 {
 int i, end;
diff --git a/libavcodec/idctdsp.h b/libavcodec/idctdsp.h
index 014488aec3..e8f20acaf2 100644
--- a/libavcodec/idctdsp.h
+++ b/libavcodec/idctdsp.h
@@ -43,7 +43,7 @@ enum idct_permutation_type {
 FF_IDCT_PERM_SSE2,
 };
 
-void ff_init_scantable(uint8_t *permutation, ScanTable *st,
+void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
const uint8_t *src_scantable);
 void ff_init_scantable_permutation(uint8_t *idct_permutation,
enum idct_permutation_type perm_type);
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 06/41] avcodec/h261enc: Pass PutBitContext directly in h261_encode_motion()

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h261enc.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 13fe5bbfb2..7e3af1ff9e 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -140,13 +140,12 @@ void ff_h261_reorder_mb_index(MpegEncContext *s)
 }
 }
 
-static void h261_encode_motion(H261EncContext *h, int val)
+static void h261_encode_motion(PutBitContext *pb, int val)
 {
-MpegEncContext *const s = >s;
 int sign, code;
 if (val == 0) {
 code = 0;
-put_bits(>pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]);
+put_bits(pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]);
 } else {
 if (val > 15)
 val -= 32;
@@ -154,8 +153,8 @@ static void h261_encode_motion(H261EncContext *h, int val)
 val += 32;
 sign = val < 0;
 code = sign ? -val : val;
-put_bits(>pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]);
-put_bits(>pb, 1, sign);
+put_bits(pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]);
+put_bits(pb, 1, sign);
 }
 }
 
@@ -313,8 +312,8 @@ void ff_h261_encode_mb(MpegEncContext *s, int16_t 
block[6][64],
 mv_diff_y   = (motion_y >> 1) - s->last_mv[0][0][1];
 s->last_mv[0][0][0] = (motion_x >> 1);
 s->last_mv[0][0][1] = (motion_y >> 1);
-h261_encode_motion(h, mv_diff_x);
-h261_encode_motion(h, mv_diff_y);
+h261_encode_motion(>pb, mv_diff_x);
+h261_encode_motion(>pb, mv_diff_y);
 }
 
 if (HAS_CBP(com->mtype)) {
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 05/41] avcodec/h261: Separate decode and encode contexts

2022-01-29 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/h261.c|  2 +-
 libavcodec/h261.h|  8 --
 libavcodec/h261dec.c | 59 +++-
 libavcodec/h261enc.c | 54 +---
 4 files changed, 72 insertions(+), 51 deletions(-)

diff --git a/libavcodec/h261.c b/libavcodec/h261.c
index 1290c040cd..7dfaee7dc4 100644
--- a/libavcodec/h261.c
+++ b/libavcodec/h261.c
@@ -60,7 +60,7 @@ static void h261_loop_filter(uint8_t *src, int stride)
 
 void ff_h261_loop_filter(MpegEncContext *s)
 {
-H261Context *h   = (H261Context *)s;
+H261Context *const h = s->private_ctx;
 const int linesize   = s->linesize;
 const int uvlinesize = s->uvlinesize;
 uint8_t *dest_y  = s->dest[0];
diff --git a/libavcodec/h261.h b/libavcodec/h261.h
index 25728a295d..ff1903e508 100644
--- a/libavcodec/h261.h
+++ b/libavcodec/h261.h
@@ -35,15 +35,7 @@
  * H261Context
  */
 typedef struct H261Context {
-MpegEncContext s;
-
-int current_mba;
-int mba_diff;
 int mtype;
-int current_mv_x;
-int current_mv_y;
-int gob_number;
-int gob_start_code_skipped; // 1 if gob start code is already read before 
gob header is read
 } H261Context;
 
 #define MB_TYPE_H261_FIL 0x80
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 2fd8d94df1..17f1067b15 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -47,6 +47,19 @@ static VLC h261_mtype_vlc;
 static VLC h261_mv_vlc;
 static VLC h261_cbp_vlc;
 
+typedef struct H261DecContext {
+MpegEncContext s;
+
+H261Context common;
+
+int current_mba;
+int mba_diff;
+int current_mv_x;
+int current_mv_y;
+int gob_number;
+int gob_start_code_skipped; // 1 if gob start code is already read before 
gob header is read
+} H261DecContext;
+
 static av_cold void h261_decode_init_static(void)
 {
 INIT_VLC_STATIC(_mba_vlc, H261_MBA_VLC_BITS, 35,
@@ -67,9 +80,10 @@ static av_cold void h261_decode_init_static(void)
 static av_cold int h261_decode_init(AVCodecContext *avctx)
 {
 static AVOnce init_static_once = AV_ONCE_INIT;
-H261Context *h  = avctx->priv_data;
+H261DecContext *const h = avctx->priv_data;
 MpegEncContext *const s = >s;
 
+s->private_ctx = >common;
 // set defaults
 ff_mpv_decode_init(s, avctx);
 
@@ -89,7 +103,7 @@ static av_cold int h261_decode_init(AVCodecContext *avctx)
  * Decode the group of blocks header or slice header.
  * @return <0 if an error occurred
  */
-static int h261_decode_gob_header(H261Context *h)
+static int h261_decode_gob_header(H261DecContext *h)
 {
 unsigned int val;
 MpegEncContext *const s = >s;
@@ -143,7 +157,7 @@ static int h261_decode_gob_header(H261Context *h)
  * Decode the group of blocks / video packet header.
  * @return <0 if no resync found
  */
-static int h261_resync(H261Context *h)
+static int h261_resync(H261DecContext *h)
 {
 MpegEncContext *const s = >s;
 int left, ret;
@@ -184,7 +198,7 @@ static int h261_resync(H261Context *h)
  * Decode skipped macroblocks.
  * @return 0
  */
-static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
+static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2)
 {
 MpegEncContext *const s = >s;
 int i;
@@ -209,7 +223,7 @@ static int h261_decode_mb_skipped(H261Context *h, int mba1, 
int mba2)
 s->mv[0][0][0] = 0;
 s->mv[0][0][1] = 0;
 s->mb_skipped  = 1;
-h->mtype  &= ~MB_TYPE_H261_FIL;
+h->common.mtype   &= ~MB_TYPE_H261_FIL;
 
 if (s->current_picture.motion_val[0]) {
 int b_stride = 2*s->mb_width + 1;
@@ -254,7 +268,7 @@ static int decode_mv_component(GetBitContext *gb, int v)
  * Decode a macroblock.
  * @return <0 if an error occurred
  */
-static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
+static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int 
coded)
 {
 MpegEncContext *const s = >s;
 int level, i, j, run;
@@ -346,9 +360,10 @@ static int h261_decode_block(H261Context *h, int16_t 
*block, int n, int coded)
 return 0;
 }
 
-static int h261_decode_mb(H261Context *h)
+static int h261_decode_mb(H261DecContext *h)
 {
 MpegEncContext *const s = >s;
+H261Context *const com = >common;
 int i, cbp, xy;
 
 cbp = 63;
@@ -386,23 +401,23 @@ static int h261_decode_mb(H261Context *h)
 ff_update_block_index(s);
 
 // Read mtype
-h->mtype = get_vlc2(>gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
-if (h->mtype < 0) {
+com->mtype = get_vlc2(>gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 
2);
+if (com->mtype < 0) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
-   h->mtype);
+   com->mtype);
 return SLICE_ERROR;
 }
-av_assert0(h->mtype < FF_ARRAY_ELEMS(ff_h261_mtype_map));
-

[FFmpeg-devel] [PATCH 04/41] avcodec/mpegvideo: Enable private contexts

2022-01-29 Thread Andreas Rheinhardt
MpegEncContext is used by many different codecs and
every one of these uses just a subset of its fields.
If one tries to separate this and e.g. add a real MpegContext
and extension structures (say MpegDecContext and MpegEncContext),
one runs into two difficulties:

a) Some code is shared between decoder and encoder of
the same format and they therefore use the same contexts,
either MpegEncContext itself or identical extensions thereof.
The latter is the case for H.261 as well as WMV2.
b) In case of slice threading, the generic code can only allocate
and initialize the structure it knows about; right now this is
an MpegEncContext. If the codec has an even more extensive structure,
it is only available for the main thread's MpegEncContext.
Fixing this would involve making ff_mpv_common_init() aware
of the size the size of slice context to allocate and would be
part of separating the main thread's context from the slice contexts
in general.

This commit only intends to tackle the first issue by adding
a pointer to MpegEncContext that codecs can set to a common
context so that the aforementioned codecs can use this context
(together with the MpegEncContext) in their common code.
This will allow to move fields only used by the main thread
to more specialized contexts.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo.h | 3 +++
 libavcodec/mpegvideo_dec.c | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 84d79d2e59..5e406b9a9c 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -84,6 +84,9 @@ typedef struct MpegEncContext {
  *  offsets used in ASM. */
 
 struct AVCodecContext *avctx;
+/* The following pointer is intended for codecs sharing code
+ * between decoder and encoder and in need of a common context to do so. */
+void *private_ctx;
 /* the following parameters must be initialized before encoding */
 int width, height;///< picture size. must be a multiple of 16
 int gop_size;
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 1e238bd1e1..dc38f6b267 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -62,10 +62,12 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
 // FIXME can parameters change on I-frames?
 // in that case dst may need a reinit
 if (!s->context_initialized) {
+void *private_ctx = s->private_ctx;
 int err;
 memcpy(s, s1, sizeof(*s));
 
 s->avctx = dst;
+s->private_ctx   = private_ctx;
 s->bitstream_buffer  = NULL;
 s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0;
 
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 03/41] avcodec/mjpegenc: Fix files with slices > 1, but threads == 1

2022-01-29 Thread Andreas Rheinhardt
In the aforementioned case mpegvideo_enc.c calls
ff_mjpeg_encode_stuffing() at the end of every line which
pads the output to byte-alignment and escapes it;
yet it does not write the restart-markers (and also not
the DRI marker when writing the header) and so the output files
are broken.

Fix this by writing these markers depending upon the number of
slices and not the number of threads in use; this also makes
the output of the encoder reproducible given a slice count
and is therefore important if encoder tests that actually use
-threads auto are added in the future.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/ljpegenc.c|  2 +-
 libavcodec/mjpegenc.c| 12 
 libavcodec/mjpegenc_common.c | 10 ++
 libavcodec/mjpegenc_common.h |  3 ++-
 4 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c
index e15f448f90..7c53da7bc3 100644
--- a/libavcodec/ljpegenc.c
+++ b/libavcodec/ljpegenc.c
@@ -239,7 +239,7 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 init_put_bits(, pkt->data, pkt->size);
 
 ff_mjpeg_encode_picture_header(avctx, , NULL, >scantable,
-   s->pred, s->matrix, s->matrix);
+   s->pred, s->matrix, s->matrix, 0);
 
 header_bits = put_bits_count();
 
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 022f171c9e..6a47503ab4 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -78,7 +78,8 @@ static void mjpeg_encode_picture_header(MpegEncContext *s)
 {
 ff_mjpeg_encode_picture_header(s->avctx, >pb, s->mjpeg_ctx,
>intra_scantable, 0,
-   s->intra_matrix, s->chroma_intra_matrix);
+   s->intra_matrix, s->chroma_intra_matrix,
+   s->slice_context_count > 1);
 
 s->esc_pos = put_bytes_count(>pb, 0);
 for (int i = 1; i < s->slice_context_count; i++)
@@ -247,7 +248,7 @@ int ff_mjpeg_encode_stuffing(MpegEncContext *s)
 
 ff_mjpeg_escape_FF(pbc, s->esc_pos);
 
-if ((s->avctx->active_thread_type & FF_THREAD_SLICE) && mb_y < 
s->mb_height - 1)
+if (s->slice_context_count > 1 && mb_y < s->mb_height - 1)
 put_marker(pbc, RST0 + (mb_y&7));
 s->esc_pos = put_bytes_count(pbc, 0);
 
@@ -289,11 +290,14 @@ static int alloc_huffman(MpegEncContext *s)
 av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
 {
 MJpegContext *const m = &((MJPEGEncContext*)s)->mjpeg;
-int ret;
+int ret, use_slices;
 
 s->mjpeg_ctx = m;
+use_slices = s->avctx->slices > 0 ? s->avctx->slices > 1 :
+ (s->avctx->active_thread_type & FF_THREAD_SLICE) &&
+ s->avctx->thread_count > 1;
 
-if (s->codec_id == AV_CODEC_ID_AMV || (s->avctx->active_thread_type & 
FF_THREAD_SLICE))
+if (s->codec_id == AV_CODEC_ID_AMV || use_slices)
 m->huffman = HUFFMAN_TABLE_DEFAULT;
 
 if (s->mpv_flags & FF_MPV_FLAG_QP_RD) {
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index 995e2b7670..86b6568902 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -60,7 +60,7 @@ static void jpeg_table_header(AVCodecContext *avctx, 
PutBitContext *p,
   ScanTable *intra_scantable,
   uint16_t luma_intra_matrix[64],
   uint16_t chroma_intra_matrix[64],
-  int hsample[3])
+  int hsample[3], int use_slices)
 {
 int i, j, size;
 uint8_t *ptr;
@@ -91,7 +91,7 @@ static void jpeg_table_header(AVCodecContext *avctx, 
PutBitContext *p,
 }
 }
 
-if(avctx->active_thread_type & FF_THREAD_SLICE){
+if (use_slices) {
 put_marker(p, DRI);
 put_bits(p, 16, 4);
 put_bits(p, 16, (avctx->width-1)/(8*hsample[0]) + 1);
@@ -216,7 +216,8 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, 
PutBitContext *pb,
 MJpegContext *m,
 ScanTable *intra_scantable, int pred,
 uint16_t luma_intra_matrix[64],
-uint16_t chroma_intra_matrix[64])
+uint16_t chroma_intra_matrix[64],
+int use_slices)
 {
 const int lossless = !m;
 int hsample[4], vsample[4];
@@ -236,7 +237,8 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, 
PutBitContext *pb,
 jpeg_put_comments(avctx, pb);
 
 jpeg_table_header(avctx, pb, m, intra_scantable,
-  luma_intra_matrix, chroma_intra_matrix, hsample);
+  luma_intra_matrix, chroma_intra_matrix, hsample,
+  use_slices);
 
 switch (avctx->codec_id) {
 case AV_CODEC_ID_MJPEG:  put_marker(pb, SOF0 ); 

[FFmpeg-devel] [PATCH 02/41] avcodec/mjpegenc: Remove nonsense assert

2022-01-29 Thread Andreas Rheinhardt
Writing optimal huffman tables is incompatible with using slices
and hence commit 884506dfe2e29a5b2bd2905ca4f17e277e32acb1
that added writing optimal huffman tables also added an assert
that the slice context count is always 1.
Yet this was always wrong: a) The MJPEG-encoder has (and had)
the AV_CODEC_CAP_SLICE_THREADS capability, so asserting that
it always uses one slice context is incorrect.
b) This commit did not add any proper checks that ensured that
optimal huffman tables are never used together with multiple slices.
This only happened with 03eb0515c12637dbd20c2e3ca8503d7b47cf583a.
c) This assert is at the wrong place: ff_mjpeg_encode_init() is
called before the actual slice_context_count is set. This is
the reason why this assert was never triggered.

Therefore this commit removes this assert.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mjpegenc.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index d15b9ece50..022f171c9e 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -293,8 +293,6 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
 
 s->mjpeg_ctx = m;
 
-av_assert0(s->slice_context_count == 1);
-
 if (s->codec_id == AV_CODEC_ID_AMV || (s->avctx->active_thread_type & 
FF_THREAD_SLICE))
 m->huffman = HUFFMAN_TABLE_DEFAULT;
 
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 01/41] avcodec/mpegvideo_enc: Allow slices only for slice-thread-able codecs

2022-01-29 Thread Andreas Rheinhardt
One can use slices without slice-threading. The results for
mpegvideo-encoders are abysmal: AMV, SpeedHQ, H.263, RV10, RV20,
MSMPEG4v2, MSMPEG4v3 and WMV1 produce broken files.
WMV2 meanwhile expects the MpegEncContext given to ff_wmv2_encode_mb()
to be at the beginning of a Wmv2Context (a structure that this encoder
shares with the WMV2 decoder), yet this is only true for the
main context and not for the slice contexts, leading to segfaults.
SpeedHQ additionally triggers an av_assert2, because it is not
byte-aligned at a position where it ought to be byte-aligned.

Given that no codec not supporting slice threading works this commit
disallows using slices unless the encoder supports slice threading.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/mpegvideo_enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 33f2937217..6df2a46eaa 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -599,7 +599,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
 }
 
 if (avctx->slices > 1 &&
-(avctx->codec_id == AV_CODEC_ID_FLV1 || avctx->codec_id == 
AV_CODEC_ID_H261)) {
+!(avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)) {
 av_log(avctx, AV_LOG_ERROR, "Multiple slices are not supported by this 
codec\n");
 return AVERROR(EINVAL);
 }
-- 
2.32.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/dashdec: avoid calling strlen multiple times

2022-01-29 Thread lance . lmwang
On Mon, Jan 24, 2022 at 11:48:22AM +0800, Steven Liu wrote:
>  于2022年1月23日周日 11:52写道:
> >
> > From: Limin Wang 
> >
> > Signed-off-by: Limin Wang 
> > ---
> >  libavformat/dashdec.c | 6 --
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> > index 0d21989..211d77f 100644
> > --- a/libavformat/dashdec.c
> > +++ b/libavformat/dashdec.c
> > @@ -403,6 +403,7 @@ static int open_url(AVFormatContext *s, AVIOContext 
> > **pb, const char *url,
> >  DASHContext *c = s->priv_data;
> >  AVDictionary *tmp = NULL;
> >  const char *proto_name = NULL;
> > +int proto_name_len;
> >  int ret;
> >
> >  if (av_strstart(url, "crypto", NULL)) {
> > @@ -416,6 +417,7 @@ static int open_url(AVFormatContext *s, AVIOContext 
> > **pb, const char *url,
> >  if (!proto_name)
> >  return AVERROR_INVALIDDATA;
> >
> > +proto_name_len = strlen(proto_name);
> >  // only http(s) & file are allowed
> >  if (av_strstart(proto_name, "file", NULL)) {
> >  if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, 
> > c->allowed_extensions)) {
> > @@ -430,9 +432,9 @@ static int open_url(AVFormatContext *s, AVIOContext 
> > **pb, const char *url,
> >  } else
> >  return AVERROR_INVALIDDATA;
> >
> > -if (!strncmp(proto_name, url, strlen(proto_name)) && 
> > url[strlen(proto_name)] == ':')
> > +if (!strncmp(proto_name, url, proto_name_len) && url[proto_name_len] 
> > == ':')
> >  ;
> > -else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url 
> > + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')
> > +else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url 
> > + 7, proto_name_len) && url[7 + proto_name_len] == ':')
> >  ;
> >  else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
> >  return AVERROR_INVALIDDATA;
> > --
> > 1.8.3.1
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 
> lgtm

thanks, will push the patch set tomorrow if no other comments.

> 
> 
> Thanks

-- 
Thanks,
Limin Wang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 1/3] lavc/qsv: allow to add more parameter buffers to QSV frame

2022-01-29 Thread Xiang, Haihao
On Sat, 2022-01-29 at 15:41 +0100, Timo Rothenpieler wrote:
> On 29.01.2022 15:30, Timo Rothenpieler wrote:
> > On 27.01.2022 06:37, Xiang, Haihao wrote:
> > > Will apply
> > > 
> > > -Haihao
> > > 
> > 
> > Something in this patchset broke build on Windows:
> > https://github.com/BtbN/FFmpeg-Builds/runs/4991054208#step:4:9491
> 
> Seems like it really was the typo gcc suggests. Pushed a fix for it.

Sorry for this stupid error, and thanks for the patch, we'll check the 
ourinternal CI and review process. 

BRs
Haihao




___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 5/5] Add AudioToolbox audio input device.

2022-01-29 Thread Romain Beauxis
Le sam. 29 janv. 2022 à 14:42, Andreas Rheinhardt
 a écrit :
>
> Romain Beauxis:
> > Le mer. 19 janv. 2022 à 10:59, Marvin Scholz  a écrit :
> >>
> >>
> >>
> >> On 19 Jan 2022, at 15:42, Romain Beauxis wrote:
> >>
> >> Hi, thanks for the patch. I've not done a full code review yet, just a
> >> few
> >> initial remarks below:
> >>
> >>> This patch adds support for a new, audio-specific input device using
> >>> the documented and battle-tested AUHAL input. This provides a pendant
> >>> to the AudioToolbox audio-only output.
> >>>
> >>> A couple of advantages for this:
> >>> * It avoids a lot of the complexity of supporting audio and video in a
> >>> single input
> >>> * The AUHAL API seems tested, documented and robust
> >>> * This implementation hopefully gives good control over audio latency
> >>> and also minimizes data copy
> >>> From: Romain Beauxis 
> >>> To: ffmpeg-devel@ffmpeg.org
> >>> Subject: [PATCH] Add AudioToolbox audio input device.
> >>> Date: 18. January 2022 at 23:29
> >>> Signed-off-by: Romain Beauxis 
> >>> ---
> >>>  configure  |   5 +
> >>>  doc/indevs.texi|  44 
> >>>  libavdevice/Makefile   |   1 +
> >>>  libavdevice/alldevices.c   |   1 +
> >>>  libavdevice/audiotoolbox_dec.m | 466
> >>> +
> >>>  5 files changed, 517 insertions(+)
> >>>  create mode 100644 libavdevice/audiotoolbox_dec.m
> >>>
> >>> diff --git a/configure b/configure
> >>> index 1413122d87..80e39aae44 100755
> >>> --- a/configure
> >>> +++ b/configure
> >>> @@ -204,6 +204,7 @@ External library support:
> >>>--disable-avfoundation   disable Apple AVFoundation framework
> >>> [autodetect]
> >>>--enable-avisynthenable reading of AviSynth script files
> >>> [no]
> >>>--disable-bzlib  disable bzlib [autodetect]
> >>> +  --disable-coremedia  disable Apple CoreMedia framework
> >>> [autodetect]
> >>>--disable-coreimage  disable Apple CoreImage framework
> >>> [autodetect]
> >>>--enable-chromaprint enable audio fingerprinting with
> >>> chromaprint [no]
> >>>--enable-frei0r  enable frei0r video filtering [no]
> >>> @@ -1750,6 +1751,7 @@ EXTERNAL_AUTODETECT_LIBRARY_LIST="
> >>>  appkit
> >>>  avfoundation
> >>>  bzlib
> >>> +coremedia
> >>>  coreimage
> >>>  iconv
> >>>  libxcb
> >>> @@ -3493,6 +3495,8 @@ alsa_outdev_deps="alsa"
> >>>  avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
> >>>  avfoundation_indev_suggest="coregraphics applicationservices"
> >>>  avfoundation_indev_extralibs="-framework Foundation"
> >>> +audiotoolbox_indev_deps="coremedia audiotoolbox"
> >>> +audiotoolbox_indev_extralibs="-framework CoreMedia -framework
> >>> AudioToolbox"
> >>>  audiotoolbox_outdev_deps="audiotoolbox pthreads"
> >>>  audiotoolbox_outdev_extralibs="-framework AudioToolbox -framework
> >>> CoreAudio"
> >>>  bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h
> >>> dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
> >>> @@ -6340,6 +6344,7 @@ check_lib camera2ndk "stdbool.h stdint.h
> >>> camera/NdkCameraManager.h" ACameraManag
> >>>  enabled appkit   && check_apple_framework AppKit
> >>>  enabled audiotoolbox && check_apple_framework AudioToolbox
> >>>  enabled avfoundation && check_apple_framework AVFoundation
> >>> +enabled coremedia&& check_apple_framework CoreMedia
> >>>  enabled coreimage&& check_apple_framework CoreImage
> >>>  enabled metal&& check_apple_framework Metal
> >>>  enabled videotoolbox && check_apple_framework VideoToolbox
> >>> diff --git a/doc/indevs.texi b/doc/indevs.texi
> >>> index 858c0fa4e4..30a91d304f 100644
> >>> --- a/doc/indevs.texi
> >>> +++ b/doc/indevs.texi
> >>> @@ -103,6 +103,50 @@ Set the maximum number of frames to buffer.
> >>> Default is 5.
> >>>
> >>>  @end table
> >>>
> >>> +@section AudioToolbox
> >>> +
> >>> +AudioToolbox input device.
> >>> +
> >>> +Allows native input from CoreAudio devices on OSX.
> >> Nit: Nowadays it's macOS instead of OSX
> >>
> >>> +
> >>> +All available devices can be enumerated by using
> >>> @option{-list_devices true}, listing
> >>> +all device names, and corresponding unique ID.
> >>
> >> Instead of adding another device that uses a custom list-devices option,
> >> could you
> >> instead implement the .get_device_list callback? (See alsa or pulse
> >> modules for an
> >> example) Then listing would work properly with the `ffmpeg -sources`
> >> command and
> >> devices could be iterated over using the avdevice APIs as well.
> >>
> >> (Ideally we would have that for AVFoundation too but its really hard now
> >> to do that
> >> in a backwards compatible manner)
> >
> > Is there a way to access the result of the get_devices_callback from
> > the ffmpeg CLI? I have searched but haven't found any so far..
> >
>
> -sources or -sinks; you can also add a specific device like "-sources alsa".

Yeah. I re-read Marvin's initial message and the answer was 

Re: [FFmpeg-devel] [PATCH 5/5] Add AudioToolbox audio input device.

2022-01-29 Thread Andreas Rheinhardt
Romain Beauxis:
> Le mer. 19 janv. 2022 à 10:59, Marvin Scholz  a écrit :
>>
>>
>>
>> On 19 Jan 2022, at 15:42, Romain Beauxis wrote:
>>
>> Hi, thanks for the patch. I've not done a full code review yet, just a
>> few
>> initial remarks below:
>>
>>> This patch adds support for a new, audio-specific input device using
>>> the documented and battle-tested AUHAL input. This provides a pendant
>>> to the AudioToolbox audio-only output.
>>>
>>> A couple of advantages for this:
>>> * It avoids a lot of the complexity of supporting audio and video in a
>>> single input
>>> * The AUHAL API seems tested, documented and robust
>>> * This implementation hopefully gives good control over audio latency
>>> and also minimizes data copy
>>> From: Romain Beauxis 
>>> To: ffmpeg-devel@ffmpeg.org
>>> Subject: [PATCH] Add AudioToolbox audio input device.
>>> Date: 18. January 2022 at 23:29
>>> Signed-off-by: Romain Beauxis 
>>> ---
>>>  configure  |   5 +
>>>  doc/indevs.texi|  44 
>>>  libavdevice/Makefile   |   1 +
>>>  libavdevice/alldevices.c   |   1 +
>>>  libavdevice/audiotoolbox_dec.m | 466
>>> +
>>>  5 files changed, 517 insertions(+)
>>>  create mode 100644 libavdevice/audiotoolbox_dec.m
>>>
>>> diff --git a/configure b/configure
>>> index 1413122d87..80e39aae44 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -204,6 +204,7 @@ External library support:
>>>--disable-avfoundation   disable Apple AVFoundation framework
>>> [autodetect]
>>>--enable-avisynthenable reading of AviSynth script files
>>> [no]
>>>--disable-bzlib  disable bzlib [autodetect]
>>> +  --disable-coremedia  disable Apple CoreMedia framework
>>> [autodetect]
>>>--disable-coreimage  disable Apple CoreImage framework
>>> [autodetect]
>>>--enable-chromaprint enable audio fingerprinting with
>>> chromaprint [no]
>>>--enable-frei0r  enable frei0r video filtering [no]
>>> @@ -1750,6 +1751,7 @@ EXTERNAL_AUTODETECT_LIBRARY_LIST="
>>>  appkit
>>>  avfoundation
>>>  bzlib
>>> +coremedia
>>>  coreimage
>>>  iconv
>>>  libxcb
>>> @@ -3493,6 +3495,8 @@ alsa_outdev_deps="alsa"
>>>  avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
>>>  avfoundation_indev_suggest="coregraphics applicationservices"
>>>  avfoundation_indev_extralibs="-framework Foundation"
>>> +audiotoolbox_indev_deps="coremedia audiotoolbox"
>>> +audiotoolbox_indev_extralibs="-framework CoreMedia -framework
>>> AudioToolbox"
>>>  audiotoolbox_outdev_deps="audiotoolbox pthreads"
>>>  audiotoolbox_outdev_extralibs="-framework AudioToolbox -framework
>>> CoreAudio"
>>>  bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h
>>> dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
>>> @@ -6340,6 +6344,7 @@ check_lib camera2ndk "stdbool.h stdint.h
>>> camera/NdkCameraManager.h" ACameraManag
>>>  enabled appkit   && check_apple_framework AppKit
>>>  enabled audiotoolbox && check_apple_framework AudioToolbox
>>>  enabled avfoundation && check_apple_framework AVFoundation
>>> +enabled coremedia&& check_apple_framework CoreMedia
>>>  enabled coreimage&& check_apple_framework CoreImage
>>>  enabled metal&& check_apple_framework Metal
>>>  enabled videotoolbox && check_apple_framework VideoToolbox
>>> diff --git a/doc/indevs.texi b/doc/indevs.texi
>>> index 858c0fa4e4..30a91d304f 100644
>>> --- a/doc/indevs.texi
>>> +++ b/doc/indevs.texi
>>> @@ -103,6 +103,50 @@ Set the maximum number of frames to buffer.
>>> Default is 5.
>>>
>>>  @end table
>>>
>>> +@section AudioToolbox
>>> +
>>> +AudioToolbox input device.
>>> +
>>> +Allows native input from CoreAudio devices on OSX.
>> Nit: Nowadays it's macOS instead of OSX
>>
>>> +
>>> +All available devices can be enumerated by using
>>> @option{-list_devices true}, listing
>>> +all device names, and corresponding unique ID.
>>
>> Instead of adding another device that uses a custom list-devices option,
>> could you
>> instead implement the .get_device_list callback? (See alsa or pulse
>> modules for an
>> example) Then listing would work properly with the `ffmpeg -sources`
>> command and
>> devices could be iterated over using the avdevice APIs as well.
>>
>> (Ideally we would have that for AVFoundation too but its really hard now
>> to do that
>> in a backwards compatible manner)
> 
> Is there a way to access the result of the get_devices_callback from
> the ffmpeg CLI? I have searched but haven't found any so far..
> 

-sources or -sinks; you can also add a specific device like "-sources alsa".

- Andreas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] configure: link to libatomic when it's present

2022-01-29 Thread Anton Khirnov
Quoting Brad Smith (2022-01-29 19:15:46)
> On 1/29/2022 4:54 AM, Hendrik Leppkes wrote:
> 
> > On Sat, Jan 29, 2022 at 5:45 AM Brad Smith
> >  wrote:
> >> libatomic is dropped by --as-needed since it is not necessary.
> >>
> > Thats what this solution relies on, and thus there is no harm in adding it.
> 
> But it doesn't work, and the generated pkg-config files are contaminated 
> too. I'll just
> have to patch out this broken crap locally.

You have now twice disregarded someone explaining why the test first
check with -latomic and then without, then you call this code "broken
crap" without properly explaining what breaks and why.

Consider communicating better if you want people here to take you
seriously.

-- 
Anton Khirnov
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 5/5] Add AudioToolbox audio input device.

2022-01-29 Thread Romain Beauxis
Le mer. 19 janv. 2022 à 10:59, Marvin Scholz  a écrit :
>
>
>
> On 19 Jan 2022, at 15:42, Romain Beauxis wrote:
>
> Hi, thanks for the patch. I've not done a full code review yet, just a
> few
> initial remarks below:
>
> > This patch adds support for a new, audio-specific input device using
> > the documented and battle-tested AUHAL input. This provides a pendant
> > to the AudioToolbox audio-only output.
> >
> > A couple of advantages for this:
> > * It avoids a lot of the complexity of supporting audio and video in a
> > single input
> > * The AUHAL API seems tested, documented and robust
> > * This implementation hopefully gives good control over audio latency
> > and also minimizes data copy
> > From: Romain Beauxis 
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: [PATCH] Add AudioToolbox audio input device.
> > Date: 18. January 2022 at 23:29
> > Signed-off-by: Romain Beauxis 
> > ---
> >  configure  |   5 +
> >  doc/indevs.texi|  44 
> >  libavdevice/Makefile   |   1 +
> >  libavdevice/alldevices.c   |   1 +
> >  libavdevice/audiotoolbox_dec.m | 466
> > +
> >  5 files changed, 517 insertions(+)
> >  create mode 100644 libavdevice/audiotoolbox_dec.m
> >
> > diff --git a/configure b/configure
> > index 1413122d87..80e39aae44 100755
> > --- a/configure
> > +++ b/configure
> > @@ -204,6 +204,7 @@ External library support:
> >--disable-avfoundation   disable Apple AVFoundation framework
> > [autodetect]
> >--enable-avisynthenable reading of AviSynth script files
> > [no]
> >--disable-bzlib  disable bzlib [autodetect]
> > +  --disable-coremedia  disable Apple CoreMedia framework
> > [autodetect]
> >--disable-coreimage  disable Apple CoreImage framework
> > [autodetect]
> >--enable-chromaprint enable audio fingerprinting with
> > chromaprint [no]
> >--enable-frei0r  enable frei0r video filtering [no]
> > @@ -1750,6 +1751,7 @@ EXTERNAL_AUTODETECT_LIBRARY_LIST="
> >  appkit
> >  avfoundation
> >  bzlib
> > +coremedia
> >  coreimage
> >  iconv
> >  libxcb
> > @@ -3493,6 +3495,8 @@ alsa_outdev_deps="alsa"
> >  avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
> >  avfoundation_indev_suggest="coregraphics applicationservices"
> >  avfoundation_indev_extralibs="-framework Foundation"
> > +audiotoolbox_indev_deps="coremedia audiotoolbox"
> > +audiotoolbox_indev_extralibs="-framework CoreMedia -framework
> > AudioToolbox"
> >  audiotoolbox_outdev_deps="audiotoolbox pthreads"
> >  audiotoolbox_outdev_extralibs="-framework AudioToolbox -framework
> > CoreAudio"
> >  bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h
> > dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
> > @@ -6340,6 +6344,7 @@ check_lib camera2ndk "stdbool.h stdint.h
> > camera/NdkCameraManager.h" ACameraManag
> >  enabled appkit   && check_apple_framework AppKit
> >  enabled audiotoolbox && check_apple_framework AudioToolbox
> >  enabled avfoundation && check_apple_framework AVFoundation
> > +enabled coremedia&& check_apple_framework CoreMedia
> >  enabled coreimage&& check_apple_framework CoreImage
> >  enabled metal&& check_apple_framework Metal
> >  enabled videotoolbox && check_apple_framework VideoToolbox
> > diff --git a/doc/indevs.texi b/doc/indevs.texi
> > index 858c0fa4e4..30a91d304f 100644
> > --- a/doc/indevs.texi
> > +++ b/doc/indevs.texi
> > @@ -103,6 +103,50 @@ Set the maximum number of frames to buffer.
> > Default is 5.
> >
> >  @end table
> >
> > +@section AudioToolbox
> > +
> > +AudioToolbox input device.
> > +
> > +Allows native input from CoreAudio devices on OSX.
> Nit: Nowadays it's macOS instead of OSX
>
> > +
> > +All available devices can be enumerated by using
> > @option{-list_devices true}, listing
> > +all device names, and corresponding unique ID.
>
> Instead of adding another device that uses a custom list-devices option,
> could you
> instead implement the .get_device_list callback? (See alsa or pulse
> modules for an
> example) Then listing would work properly with the `ffmpeg -sources`
> command and
> devices could be iterated over using the avdevice APIs as well.
>
> (Ideally we would have that for AVFoundation too but its really hard now
> to do that
> in a backwards compatible manner)

Is there a way to access the result of the get_devices_callback from
the ffmpeg CLI? I have searched but haven't found any so far..

> > +
> > +@subsection Options
> > +
> > +AudioToolbox supports the following options:
> > +
> > +@table @option
> > +
> > +@item channels
> > +Set the number of channels. Default is device's default.
> > +
> > +@item frames_queue_length
> > +Maximum of buffers in the input queue
> > +
> > +@item buffer_frame_size
> > +Buffer frame size, gouverning internal latency
> > +
> > +@item big_endian
> > +Return big endian samples
> > +
> > +@item sample_format
> > +Sample format
> > +
> > 

Re: [FFmpeg-devel] [PATCH] configure: link to libatomic when it's present

2022-01-29 Thread Brad Smith

On 1/29/2022 4:54 AM, Hendrik Leppkes wrote:


On Sat, Jan 29, 2022 at 5:45 AM Brad Smith
 wrote:

libatomic is dropped by --as-needed since it is not necessary.


Thats what this solution relies on, and thus there is no harm in adding it.


But it doesn't work, and the generated pkg-config files are contaminated 
too. I'll just

have to patch out this broken crap locally.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v1] avfilter/vf_gblur_vulkan: add sizeV option

2022-01-29 Thread Lynne
29 Jan 2022, 13:34 by toq...@outlook.com:

> Ping.
>
>> From: Wu, Jianhua
>> Sent: 2022年1月21日 19:42
>> To: ffmpeg-devel@ffmpeg.org
>> Cc: Wu, Jianhua
>> Subject: [FFmpeg-devel] [PATCH v1] avfilter/vf_gblur_vulkan: add sizeV option
>>
>> [PATCH 1/5] avfilter/vf_gblur_vulkan: add sizeV option [PATCH 2/5] 
>> avfilter:add shader_vulkan filter [PATCH 3/5] avfilter/vf_blend_vulkan: add 
>> multiply blend mode [PATCH 4/5] avutil/vulkan: don't use strlen as loop 
>> >condition [PATCH 5/5] avfilter/scale_vulkan: use RET for checking return 
>> value
>>
>> Patches attached.
>>
>
> Hi there,
>
> Any update?
>

Sorry, haven't forgotten, but been busy with FFTs lately.
Will try to review and test the patches soon.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 1/3] lavc/qsv: allow to add more parameter buffers to QSV frame

2022-01-29 Thread Timo Rothenpieler

On 29.01.2022 15:30, Timo Rothenpieler wrote:

On 27.01.2022 06:37, Xiang, Haihao wrote:

Will apply

-Haihao



Something in this patchset broke build on Windows:
https://github.com/BtbN/FFmpeg-Builds/runs/4991054208#step:4:9491


Seems like it really was the typo gcc suggests. Pushed a fix for it.


smime.p7s
Description: S/MIME Cryptographic Signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 1/3] lavc/qsv: allow to add more parameter buffers to QSV frame

2022-01-29 Thread Timo Rothenpieler

On 27.01.2022 06:37, Xiang, Haihao wrote:

Will apply

-Haihao



Something in this patchset broke build on Windows:
https://github.com/BtbN/FFmpeg-Builds/runs/4991054208#step:4:9491


smime.p7s
Description: S/MIME Cryptographic Signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v1] avfilter/vf_gblur_vulkan: add sizeV option

2022-01-29 Thread Wu Jianhua
Ping.

> From: Wu, Jianhua
> Sent: 2022年1月21日 19:42
> To: ffmpeg-devel@ffmpeg.org
> Cc: Wu, Jianhua
> Subject: [FFmpeg-devel] [PATCH v1] avfilter/vf_gblur_vulkan: add sizeV option
>
> [PATCH 1/5] avfilter/vf_gblur_vulkan: add sizeV option [PATCH 2/5] 
> avfilter:add shader_vulkan filter [PATCH 3/5] avfilter/vf_blend_vulkan: add 
> multiply blend mode [PATCH 4/5] avutil/vulkan: don't use strlen as loop 
> >condition [PATCH 5/5] avfilter/scale_vulkan: use RET for checking return 
> value
>
> Patches attached.

Hi there,

Any update?

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] configure: link to libatomic when it's present

2022-01-29 Thread Hendrik Leppkes
On Sat, Jan 29, 2022 at 5:45 AM Brad Smith
 wrote:
>
> libatomic is dropped by --as-needed since it is not necessary.
>

Thats what this solution relies on, and thus there is no harm in adding it.

- Hendrik
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".