* [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly
@ 2021-12-22 3:19 Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 02/14] avcodec/mjpegenc: Avoid allocation of MJpegContext Andreas Rheinhardt
` (38 more replies)
0 siblings, 39 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:19 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Currently, ff_mpv_encode_end() is the close function of
the two MJPEG-based encoders; it calls ff_mjpeg_encode_close()
for them which adds a check to the generic code.
This commit reverses the order of this relationship:
The MJPEG encoders directly use a custom close function
which in turn calls ff_mpv_encode_end(). This avoids the branch
in ff_mpv_encode_end() and makes the generic code more generic.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc.c | 9 ++++++---
libavcodec/mjpegenc.h | 1 -
libavcodec/mpegvideo_enc.c | 3 ---
3 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 0ade66bc5f..5bd25b4f3b 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -320,12 +320,15 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
return 0;
}
-av_cold void ff_mjpeg_encode_close(MpegEncContext *s)
+static av_cold int mjpeg_encode_close(AVCodecContext *avctx)
{
+ MpegEncContext *const s = avctx->priv_data;
if (s->mjpeg_ctx) {
av_freep(&s->mjpeg_ctx->huff_buffer);
av_freep(&s->mjpeg_ctx);
}
+ ff_mpv_encode_end(avctx);
+ return 0;
}
/**
@@ -618,7 +621,7 @@ const AVCodec ff_mjpeg_encoder = {
.priv_data_size = sizeof(MpegEncContext),
.init = ff_mpv_encode_init,
.encode2 = ff_mpv_encode_picture,
- .close = ff_mpv_encode_end,
+ .close = mjpeg_encode_close,
.capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
.pix_fmts = (const enum AVPixelFormat[]) {
@@ -647,7 +650,7 @@ const AVCodec ff_amv_encoder = {
.priv_data_size = sizeof(MpegEncContext),
.init = ff_mpv_encode_init,
.encode2 = amv_encode_picture,
- .close = ff_mpv_encode_end,
+ .close = mjpeg_encode_close,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
.pix_fmts = (const enum AVPixelFormat[]) {
AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_NONE
diff --git a/libavcodec/mjpegenc.h b/libavcodec/mjpegenc.h
index 2e92511276..bc9b017e7a 100644
--- a/libavcodec/mjpegenc.h
+++ b/libavcodec/mjpegenc.h
@@ -105,7 +105,6 @@ static inline void put_marker(PutBitContext *p, enum JpegMarker code)
}
int ff_mjpeg_encode_init(MpegEncContext *s);
-void ff_mjpeg_encode_close(MpegEncContext *s);
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]);
int ff_mjpeg_encode_stuffing(MpegEncContext *s);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 128d1a327c..d2520368e1 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -970,9 +970,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
ff_rate_control_uninit(s);
ff_mpv_common_end(s);
- if ((CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER) &&
- s->out_format == FMT_MJPEG)
- ff_mjpeg_encode_close(s);
for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++)
av_frame_free(&s->tmp_frames[i]);
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 02/14] avcodec/mjpegenc: Avoid allocation of MJpegContext
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 03/14] avcodec/mpegvideo_enc: Move MJPEG init checks to mjpegenc.c Andreas Rheinhardt
` (37 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible by allocating it together with the MpegEncContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc.c | 31 +++++++++++++++++--------------
libavcodec/mjpegenc_common.c | 2 +-
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 5bd25b4f3b..1652087948 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -41,6 +41,15 @@
#include "mjpegenc.h"
#include "profiles.h"
+/* The following is the private context of MJPEG/AMV decoder.
+ * Note that when using slice threading only the main thread's
+ * MpegEncContext is followed by a MjpegContext; the other threads
+ * can access this shared context via MpegEncContext.mjpeg. */
+typedef struct MJPEGEncContext {
+ MpegEncContext mpeg;
+ MJpegContext mjpeg;
+} MJPEGEncContext;
+
static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256],
uint8_t *uni_ac_vlc_len)
{
@@ -260,9 +269,11 @@ static int alloc_huffman(MpegEncContext *s)
av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
{
- MJpegContext *m;
+ MJpegContext *const m = &((MJPEGEncContext*)s)->mjpeg;
int ret;
+ s->mjpeg_ctx = m;
+
av_assert0(s->slice_context_count == 1);
/* The following check is automatically true for AMV,
@@ -276,10 +287,6 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
return AVERROR(EINVAL);
}
- m = av_mallocz(sizeof(MJpegContext));
- if (!m)
- return AVERROR(ENOMEM);
-
s->min_qcoeff=-1023;
s->max_qcoeff= 1023;
@@ -312,7 +319,6 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
// Buffers start out empty.
m->huff_ncode = 0;
- s->mjpeg_ctx = m;
if(s->huffman == HUFFMAN_TABLE_OPTIMAL)
return alloc_huffman(s);
@@ -322,11 +328,8 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
static av_cold int mjpeg_encode_close(AVCodecContext *avctx)
{
- MpegEncContext *const s = avctx->priv_data;
- if (s->mjpeg_ctx) {
- av_freep(&s->mjpeg_ctx->huff_buffer);
- av_freep(&s->mjpeg_ctx);
- }
+ MJPEGEncContext *const mjpeg = avctx->priv_data;
+ av_freep(&mjpeg->mjpeg.huff_buffer);
ff_mpv_encode_end(avctx);
return 0;
}
@@ -377,7 +380,7 @@ static void ff_mjpeg_encode_coef(MJpegContext *s, uint8_t table_id, int val, int
/**
* Add the block's data into the JPEG buffer.
*
- * @param s The MJpegEncContext that contains the JPEG buffer.
+ * @param s The MpegEncContext that contains the JPEG buffer.
* @param block The block.
* @param n The block's index or number.
*/
@@ -618,7 +621,7 @@ const AVCodec ff_mjpeg_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MJPEG,
- .priv_data_size = sizeof(MpegEncContext),
+ .priv_data_size = sizeof(MJPEGEncContext),
.init = ff_mpv_encode_init,
.encode2 = ff_mpv_encode_picture,
.close = mjpeg_encode_close,
@@ -647,7 +650,7 @@ const AVCodec ff_amv_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("AMV Video"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_AMV,
- .priv_data_size = sizeof(MpegEncContext),
+ .priv_data_size = sizeof(MJPEGEncContext),
.init = ff_mpv_encode_init,
.encode2 = amv_encode_picture,
.close = mjpeg_encode_close,
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index c1b842d547..0c6a98c394 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -323,7 +323,7 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
end:
if (!lossless) {
MpegEncContext *s = avctx->priv_data;
- av_assert0(avctx->codec->priv_data_size == sizeof(MpegEncContext));
+ av_assert0(avctx->codec->priv_data_size > sizeof(MpegEncContext));
s->esc_pos = put_bytes_count(pb, 0);
for(i=1; i<s->slice_context_count; i++)
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 03/14] avcodec/mpegvideo_enc: Move MJPEG init checks to mjpegenc.c
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 02/14] avcodec/mjpegenc: Avoid allocation of MJpegContext Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 04/14] avcodec/mpegvideo_enc: Remove redundant checks for multithreading Andreas Rheinhardt
` (36 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc.c | 10 ++++++++++
libavcodec/mpegvideo_enc.c | 12 ------------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 1652087948..8b51058f5d 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -276,6 +276,16 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
av_assert0(s->slice_context_count == 1);
+ if (s->codec_id == AV_CODEC_ID_AMV || (s->avctx->active_thread_type & FF_THREAD_SLICE))
+ s->huffman = 0;
+
+ if (s->mpv_flags & FF_MPV_FLAG_QP_RD) {
+ // Used to produce garbage with MJPEG.
+ av_log(s->avctx, AV_LOG_ERROR,
+ "QP RD is no longer compatible with MJPEG or AMV\n");
+ return AVERROR(EINVAL);
+ }
+
/* The following check is automatically true for AMV,
* but it doesn't hurt either. */
ret = ff_mjpeg_encode_check_pix_fmt(s->avctx);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index d2520368e1..7e45fd0ff3 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -370,9 +370,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- if (avctx->codec_id == AV_CODEC_ID_AMV || (avctx->active_thread_type & FF_THREAD_SLICE))
- s->huffman = 0;
-
if (s->intra_dc_precision > (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 3 : 0)) {
av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n");
return AVERROR(EINVAL);
@@ -573,15 +570,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) &&
- (s->codec_id == AV_CODEC_ID_AMV ||
- s->codec_id == AV_CODEC_ID_MJPEG)) {
- // Used to produce garbage with MJPEG.
- av_log(avctx, AV_LOG_ERROR,
- "QP RD is no longer compatible with MJPEG or AMV\n");
- return AVERROR(EINVAL);
- }
-
if (s->scenechange_threshold < 1000000000 &&
(avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)) {
av_log(avctx, AV_LOG_ERROR,
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 04/14] avcodec/mpegvideo_enc: Remove redundant checks for multithreading
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 02/14] avcodec/mjpegenc: Avoid allocation of MJpegContext Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 03/14] avcodec/mpegvideo_enc: Move MJPEG init checks to mjpegenc.c Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 05/14] avcodec/mjpegenc: Add wrapper for ff_mjpeg_encode_picture_header() Andreas Rheinhardt
` (35 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The generic code ensures that only codecs with
the FF_CODEC_CAP_AUTO_THREADS internal cap ever have to
handle the case avctx->thread_count == 0 themselves;
moreover, it is also ensured generically that only codecs
that support some form of threading have thread_count set
to something else than one. So these checks are unnecessary.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 18 ------------------
1 file changed, 18 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 7e45fd0ff3..23e8a41a86 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -607,24 +607,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- if (avctx->thread_count > 1 &&
- s->codec_id != AV_CODEC_ID_MPEG4 &&
- s->codec_id != AV_CODEC_ID_MPEG1VIDEO &&
- s->codec_id != AV_CODEC_ID_MPEG2VIDEO &&
- s->codec_id != AV_CODEC_ID_MJPEG &&
- (s->codec_id != AV_CODEC_ID_H263P)) {
- av_log(avctx, AV_LOG_ERROR,
- "multi threaded encoding not supported by codec\n");
- return AVERROR_PATCHWELCOME;
- }
-
- if (avctx->thread_count < 1) {
- av_log(avctx, AV_LOG_ERROR,
- "automatic thread number detection not supported by codec, "
- "patch welcome\n");
- return AVERROR_PATCHWELCOME;
- }
-
if (s->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");
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 05/14] avcodec/mjpegenc: Add wrapper for ff_mjpeg_encode_picture_header()
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (2 preceding siblings ...)
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 04/14] avcodec/mpegvideo_enc: Remove redundant checks for multithreading Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 06/14] avcodec/mjpegenc_common: Move code for MJPEG/AMV to mjpegenc Andreas Rheinhardt
` (34 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This factors the translation from MpegEncContext out
and will enable further optimizations in the next commits.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc.c | 16 ++++++++++++++--
libavcodec/mjpegenc.h | 1 +
libavcodec/mpegvideo_enc.c | 5 +----
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 8b51058f5d..b682036f87 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -74,6 +74,19 @@ static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256],
}
}
+static void mjpeg_encode_picture_header(MpegEncContext *s)
+{
+ ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,
+ s->pred, s->intra_matrix, s->chroma_intra_matrix);
+}
+
+void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s)
+{
+ /* s->huffman == HUFFMAN_TABLE_OPTIMAL can only be true for MJPEG. */
+ if (!CONFIG_MJPEG_ENCODER || s->huffman != HUFFMAN_TABLE_OPTIMAL)
+ mjpeg_encode_picture_header(s);
+}
+
#if CONFIG_MJPEG_ENCODER
/**
* Encodes and outputs the entire frame in the JPEG format.
@@ -213,8 +226,7 @@ int ff_mjpeg_encode_stuffing(MpegEncContext *s)
s->intra_chroma_ac_vlc_length =
s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len;
- ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,
- s->pred, s->intra_matrix, s->chroma_intra_matrix);
+ mjpeg_encode_picture_header(s);
mjpeg_encode_picture_frame(s);
}
#endif
diff --git a/libavcodec/mjpegenc.h b/libavcodec/mjpegenc.h
index bc9b017e7a..555677e69a 100644
--- a/libavcodec/mjpegenc.h
+++ b/libavcodec/mjpegenc.h
@@ -105,6 +105,7 @@ static inline void put_marker(PutBitContext *p, enum JpegMarker code)
}
int ff_mjpeg_encode_init(MpegEncContext *s);
+void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s);
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]);
int ff_mjpeg_encode_stuffing(MpegEncContext *s);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 23e8a41a86..9807e491e5 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3702,10 +3702,7 @@ static int encode_picture(MpegEncContext *s, int picture_number)
switch(s->out_format) {
#if CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER
case FMT_MJPEG:
- /* s->huffman == HUFFMAN_TABLE_OPTIMAL can only be true for MJPEG. */
- if (!CONFIG_MJPEG_ENCODER || s->huffman != HUFFMAN_TABLE_OPTIMAL)
- ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,
- s->pred, s->intra_matrix, s->chroma_intra_matrix);
+ ff_mjpeg_amv_encode_picture_header(s);
break;
#endif
case FMT_SPEEDHQ:
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 06/14] avcodec/mjpegenc_common: Move code for MJPEG/AMV to mjpegenc
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (3 preceding siblings ...)
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 05/14] avcodec/mjpegenc: Add wrapper for ff_mjpeg_encode_picture_header() Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 07/14] avcodec/mjpegenc_common: Fix intendation Andreas Rheinhardt
` (33 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc.c | 4 ++++
libavcodec/mjpegenc_common.c | 14 ++------------
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index b682036f87..c1b759f7a8 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -78,6 +78,10 @@ static void mjpeg_encode_picture_header(MpegEncContext *s)
{
ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,
s->pred, s->intra_matrix, s->chroma_intra_matrix);
+
+ s->esc_pos = put_bytes_count(&s->pb, 0);
+ for (int i = 1; i < s->slice_context_count; i++)
+ s->thread_context[i]->esc_pos = 0;
}
void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s)
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index 0c6a98c394..8046e4b8f7 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -224,7 +224,6 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
{
const int lossless = avctx->codec_id != AV_CODEC_ID_MJPEG && avctx->codec_id != AV_CODEC_ID_AMV;
int hsample[4], vsample[4];
- int i;
int components = 3 + (avctx->pix_fmt == AV_PIX_FMT_BGRA);
int chroma_matrix = !!memcmp(luma_intra_matrix,
chroma_intra_matrix,
@@ -235,7 +234,8 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
put_marker(pb, SOI);
// hack for AMV mjpeg format
- if(avctx->codec_id == AV_CODEC_ID_AMV) goto end;
+ if (avctx->codec_id == AV_CODEC_ID_AMV)
+ return;
jpeg_put_comments(avctx, pb);
@@ -319,16 +319,6 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
}
put_bits(pb, 8, 0); /* Ah/Al (not used) */
-
-end:
- if (!lossless) {
- MpegEncContext *s = avctx->priv_data;
- av_assert0(avctx->codec->priv_data_size > sizeof(MpegEncContext));
-
- s->esc_pos = put_bytes_count(pb, 0);
- for(i=1; i<s->slice_context_count; i++)
- s->thread_context[i]->esc_pos = 0;
- }
}
void ff_mjpeg_escape_FF(PutBitContext *pb, int start)
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 07/14] avcodec/mjpegenc_common: Fix intendation
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (4 preceding siblings ...)
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 06/14] avcodec/mjpegenc_common: Move code for MJPEG/AMV to mjpegenc Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 08/14] avcodec/mpegvideo: Move MJPEG/AMV-only fields to MJpegContext Andreas Rheinhardt
` (32 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc_common.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index 8046e4b8f7..b9df32ad15 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -73,17 +73,17 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
int matrix_count = 1 + !!memcmp(luma_intra_matrix,
chroma_intra_matrix,
sizeof(luma_intra_matrix[0]) * 64);
- if (s && s->force_duplicated_matrix)
- matrix_count = 2;
- /* quant matrixes */
- put_marker(p, DQT);
- put_bits(p, 16, 2 + matrix_count * (1 + 64));
- put_bits(p, 4, 0); /* 8 bit precision */
- put_bits(p, 4, 0); /* table 0 */
- for(i=0;i<64;i++) {
- j = intra_scantable->permutated[i];
- put_bits(p, 8, luma_intra_matrix[j]);
- }
+ if (s && s->force_duplicated_matrix)
+ matrix_count = 2;
+ /* quant matrixes */
+ put_marker(p, DQT);
+ put_bits(p, 16, 2 + matrix_count * (1 + 64));
+ put_bits(p, 4, 0); /* 8 bit precision */
+ put_bits(p, 4, 0); /* table 0 */
+ for (int i = 0; i < 64; i++) {
+ uint8_t j = intra_scantable->permutated[i];
+ put_bits(p, 8, luma_intra_matrix[j]);
+ }
if (matrix_count > 1) {
put_bits(p, 4, 0); /* 8 bit precision */
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 08/14] avcodec/mpegvideo: Move MJPEG/AMV-only fields to MJpegContext
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (5 preceding siblings ...)
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 07/14] avcodec/mjpegenc_common: Fix intendation Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 09/14] avcodec/mjpegenc: Deprecate unused prediction type Andreas Rheinhardt
` (31 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible now that MJpegContext is allocated jointly
with MpegEncContext as part of the AVCodecContext's private data.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc.c | 18 ++++++++++--------
libavcodec/mjpegenc.h | 3 +++
libavcodec/mjpegenc_common.c | 4 ++--
libavcodec/mpegvideo.h | 8 +++++---
4 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index c1b759f7a8..9b5acde58d 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -86,8 +86,10 @@ static void mjpeg_encode_picture_header(MpegEncContext *s)
void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s)
{
+ MJPEGEncContext *const m = (MJPEGEncContext*)s;
+ av_assert2(s->mjpeg_ctx == &m->mjpeg);
/* s->huffman == HUFFMAN_TABLE_OPTIMAL can only be true for MJPEG. */
- if (!CONFIG_MJPEG_ENCODER || s->huffman != HUFFMAN_TABLE_OPTIMAL)
+ if (!CONFIG_MJPEG_ENCODER || m->mjpeg.huffman != HUFFMAN_TABLE_OPTIMAL)
mjpeg_encode_picture_header(s);
}
@@ -211,13 +213,13 @@ static void mjpeg_build_optimal_huffman(MJpegContext *m)
*/
int ff_mjpeg_encode_stuffing(MpegEncContext *s)
{
+ MJpegContext *const m = s->mjpeg_ctx;
PutBitContext *pbc = &s->pb;
int mb_y = s->mb_y - !s->mb_x;
int ret;
#if CONFIG_MJPEG_ENCODER
- if (s->huffman == HUFFMAN_TABLE_OPTIMAL) {
- MJpegContext *m = s->mjpeg_ctx;
+ if (m->huffman == HUFFMAN_TABLE_OPTIMAL) {
mjpeg_build_optimal_huffman(m);
@@ -293,7 +295,7 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
av_assert0(s->slice_context_count == 1);
if (s->codec_id == AV_CODEC_ID_AMV || (s->avctx->active_thread_type & FF_THREAD_SLICE))
- s->huffman = 0;
+ m->huffman = HUFFMAN_TABLE_DEFAULT;
if (s->mpv_flags & FF_MPV_FLAG_QP_RD) {
// Used to produce garbage with MJPEG.
@@ -346,7 +348,7 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
// Buffers start out empty.
m->huff_ncode = 0;
- if(s->huffman == HUFFMAN_TABLE_OPTIMAL)
+ if (m->huffman == HUFFMAN_TABLE_OPTIMAL)
return alloc_huffman(s);
return 0;
@@ -514,7 +516,7 @@ static void encode_block(MpegEncContext *s, int16_t *block, int n)
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64])
{
int i;
- if (s->huffman == HUFFMAN_TABLE_OPTIMAL) {
+ if (s->mjpeg_ctx->huffman == HUFFMAN_TABLE_OPTIMAL) {
if (s->chroma_format == CHROMA_444) {
record_block(s, block[0], 0);
record_block(s, block[2], 2);
@@ -614,11 +616,11 @@ static int amv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
}
#endif
-#define OFFSET(x) offsetof(MpegEncContext, x)
+#define OFFSET(x) offsetof(MJPEGEncContext, mjpeg.x)
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
FF_MPV_COMMON_OPTS
-{ "pred", "Prediction method", OFFSET(pred), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 3, VE, "pred" },
+{ "pred", "Prediction method", FF_MPV_OFFSET(pred), 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/mjpegenc.h b/libavcodec/mjpegenc.h
index 555677e69a..a593b67e96 100644
--- a/libavcodec/mjpegenc.h
+++ b/libavcodec/mjpegenc.h
@@ -57,6 +57,9 @@ typedef struct MJpegHuffmanCode {
* Holds JPEG frame data and Huffman table data.
*/
typedef struct MJpegContext {
+ int huffman;
+ /* Force duplication of mjpeg matrices, useful for rtp streaming */
+ int force_duplicated_matrix;
//FIXME use array [3] instead of lumi / chroma, for easier addressing
uint8_t huff_size_dc_luminance[12]; ///< DC luminance Huffman table size.
uint16_t huff_code_dc_luminance[12]; ///< DC luminance Huffman table codes.
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index b9df32ad15..0303e65790 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -73,7 +73,7 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
int matrix_count = 1 + !!memcmp(luma_intra_matrix,
chroma_intra_matrix,
sizeof(luma_intra_matrix[0]) * 64);
- if (s && s->force_duplicated_matrix)
+ if (s && s->mjpeg_ctx->force_duplicated_matrix)
matrix_count = 2;
/* quant matrixes */
put_marker(p, DQT);
@@ -110,7 +110,7 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
// Only MJPEG can have a variable Huffman variable. All other
// formats use the default Huffman table.
- if (s && s->huffman == HUFFMAN_TABLE_OPTIMAL) {
+ if (s && s->mjpeg_ctx->huffman == HUFFMAN_TABLE_OPTIMAL) {
size += put_huffman_table(p, 0, 0, s->mjpeg_ctx->bits_dc_luminance,
s->mjpeg_ctx->val_dc_luminance);
size += put_huffman_table(p, 0, 1, s->mjpeg_ctx->bits_dc_chrominance,
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 879b019ffc..5a3486d74c 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -290,7 +290,6 @@ typedef struct MpegEncContext {
uint16_t chroma_intra_matrix[64];
uint16_t inter_matrix[64];
uint16_t chroma_inter_matrix[64];
- int force_duplicated_matrix; ///< Force duplication of mjpeg matrices, useful for rtp streaming
int intra_quant_bias; ///< bias for the quantizer
int inter_quant_bias; ///< bias for the quantizer
@@ -414,7 +413,6 @@ typedef struct MpegEncContext {
struct MJpegContext *mjpeg_ctx;
int esc_pos;
int pred;
- int huffman;
/* MSMPEG4 specific */
int mv_table_index;
@@ -575,6 +573,10 @@ typedef struct MpegEncContext {
int noise_reduction;
int intra_penalty;
+
+#if FF_API_MPEGVIDEO_OPTS
+ int dummy; ///< used as target for deprecated options
+#endif
} MpegEncContext;
/* mpegvideo_enc common options */
@@ -664,7 +666,7 @@ FF_MPV_OPT_CMP_FUNC, \
#define FF_MPV_DEPRECATED_A53_CC_OPT \
{ "a53cc", "Deprecated, does nothing", FF_MPV_OFFSET(a53_cc), 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(force_duplicated_matrix), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED },
+ { "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 },
#define FF_MPV_DEPRECATED_BFRAME_OPTS \
{ "b_strategy", "Deprecated, does nothing", FF_MPV_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_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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 09/14] avcodec/mjpegenc: Deprecate unused prediction type
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (6 preceding siblings ...)
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 08/14] avcodec/mpegvideo: Move MJPEG/AMV-only fields to MJpegContext Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 10/14] avcodec/mjpegenc_common: Pass MJpegContext for writing picture header Andreas Rheinhardt
` (30 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc.c | 6 ++++--
libavcodec/mjpegenc_common.c | 2 +-
libavcodec/mpegvideo.h | 3 +--
libavcodec/version.h | 3 ++-
4 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 9b5acde58d..cafa0487c5 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -77,7 +77,7 @@ static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256],
static void mjpeg_encode_picture_header(MpegEncContext *s)
{
ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,
- s->pred, s->intra_matrix, s->chroma_intra_matrix);
+ 0, s->intra_matrix, s->chroma_intra_matrix);
s->esc_pos = put_bytes_count(&s->pb, 0);
for (int i = 1; i < s->slice_context_count; i++)
@@ -620,10 +620,12 @@ static int amv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
FF_MPV_COMMON_OPTS
-{ "pred", "Prediction method", FF_MPV_OFFSET(pred), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 3, VE, "pred" },
+#if FF_API_MJPEG_PRED
+{ "pred", "Deprecated, does nothing", FF_MPV_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" },
+#endif
{ "huffman", "Huffman table strategy", OFFSET(huffman), AV_OPT_TYPE_INT, { .i64 = HUFFMAN_TABLE_OPTIMAL }, 0, NB_HUFFMAN_TABLE_OPTION - 1, VE, "huffman" },
{ "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = HUFFMAN_TABLE_DEFAULT }, INT_MIN, INT_MAX, VE, "huffman" },
{ "optimal", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = HUFFMAN_TABLE_OPTIMAL }, INT_MIN, INT_MAX, VE, "huffman" },
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index 0303e65790..ed0e8c234d 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -310,7 +310,7 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
put_bits(pb, 4, 0); /* AC huffman table index */
}
- put_bits(pb, 8, lossless ? pred : 0); /* Ss (not used) */
+ put_bits(pb, 8, pred); /* Ss (not used); pred only nonzero for LJPEG */
switch (avctx->codec_id) {
case AV_CODEC_ID_MJPEG: put_bits(pb, 8, 63); break; /* Se (not used) */
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 5a3486d74c..942b05ba37 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -412,7 +412,6 @@ typedef struct MpegEncContext {
/* MJPEG specific */
struct MJpegContext *mjpeg_ctx;
int esc_pos;
- int pred;
/* MSMPEG4 specific */
int mv_table_index;
@@ -574,7 +573,7 @@ typedef struct MpegEncContext {
int intra_penalty;
-#if FF_API_MPEGVIDEO_OPTS
+#if FF_API_MPEGVIDEO_OPTS || FF_API_MJPEG_PRED
int dummy; ///< used as target for deprecated options
#endif
} MpegEncContext;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 8a0b94f5aa..8581d891e1 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 59
-#define LIBAVCODEC_VERSION_MINOR 14
+#define LIBAVCODEC_VERSION_MINOR 15
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@@ -63,5 +63,6 @@
#define FF_API_MPEGVIDEO_OPTS (LIBAVCODEC_VERSION_MAJOR < 60)
#define FF_API_FLAG_TRUNCATED (LIBAVCODEC_VERSION_MAJOR < 60)
#define FF_API_SUB_TEXT_FORMAT (LIBAVCODEC_VERSION_MAJOR < 60)
+#define FF_API_MJPEG_PRED (LIBAVCODEC_VERSION_MAJOR < 60)
#endif /* AVCODEC_VERSION_H */
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 10/14] avcodec/mjpegenc_common: Pass MJpegContext for writing picture header
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (7 preceding siblings ...)
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 09/14] avcodec/mjpegenc: Deprecate unused prediction type Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 11/14] avcodec/mjpegenc_common: Don't call function unnecessarily Andreas Rheinhardt
` (29 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is the structure that is actually used.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ljpegenc.c | 2 +-
libavcodec/mjpegenc.c | 5 +++--
libavcodec/mjpegenc_common.c | 36 +++++++++++++++++-------------------
libavcodec/mjpegenc_common.h | 3 +++
4 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c
index 968ba1fb60..ea00d5cf3c 100644
--- a/libavcodec/ljpegenc.c
+++ b/libavcodec/ljpegenc.c
@@ -238,7 +238,7 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
init_put_bits(&pb, pkt->data, pkt->size);
- ff_mjpeg_encode_picture_header(avctx, &pb, &s->scantable,
+ ff_mjpeg_encode_picture_header(avctx, &pb, NULL, &s->scantable,
s->pred, s->matrix, s->matrix);
header_bits = put_bits_count(&pb);
diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index cafa0487c5..e74720dbab 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -76,8 +76,9 @@ static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256],
static void mjpeg_encode_picture_header(MpegEncContext *s)
{
- ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,
- 0, s->intra_matrix, s->chroma_intra_matrix);
+ ff_mjpeg_encode_picture_header(s->avctx, &s->pb, s->mjpeg_ctx,
+ &s->intra_scantable, 0,
+ s->intra_matrix, s->chroma_intra_matrix);
s->esc_pos = put_bytes_count(&s->pb, 0);
for (int i = 1; i < s->slice_context_count; i++)
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index ed0e8c234d..70d5fddfd5 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -56,6 +56,7 @@ static int put_huffman_table(PutBitContext *p, int table_class, int table_id,
}
static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
+ MJpegContext *m,
ScanTable *intra_scantable,
uint16_t luma_intra_matrix[64],
uint16_t chroma_intra_matrix[64],
@@ -63,17 +64,12 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
{
int i, j, size;
uint8_t *ptr;
- MpegEncContext *s = NULL;
- /* Since avctx->priv_data will point to LJpegEncContext in this case */
- if (avctx->codec_id != AV_CODEC_ID_LJPEG)
- s = avctx->priv_data;
-
- if (avctx->codec_id != AV_CODEC_ID_LJPEG) {
+ if (m) {
int matrix_count = 1 + !!memcmp(luma_intra_matrix,
chroma_intra_matrix,
sizeof(luma_intra_matrix[0]) * 64);
- if (s && s->mjpeg_ctx->force_duplicated_matrix)
+ if (m->force_duplicated_matrix)
matrix_count = 2;
/* quant matrixes */
put_marker(p, DQT);
@@ -110,16 +106,16 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
// Only MJPEG can have a variable Huffman variable. All other
// formats use the default Huffman table.
- if (s && s->mjpeg_ctx->huffman == HUFFMAN_TABLE_OPTIMAL) {
- size += put_huffman_table(p, 0, 0, s->mjpeg_ctx->bits_dc_luminance,
- s->mjpeg_ctx->val_dc_luminance);
- size += put_huffman_table(p, 0, 1, s->mjpeg_ctx->bits_dc_chrominance,
- s->mjpeg_ctx->val_dc_chrominance);
-
- size += put_huffman_table(p, 1, 0, s->mjpeg_ctx->bits_ac_luminance,
- s->mjpeg_ctx->val_ac_luminance);
- size += put_huffman_table(p, 1, 1, s->mjpeg_ctx->bits_ac_chrominance,
- s->mjpeg_ctx->val_ac_chrominance);
+ if (m && m->huffman == HUFFMAN_TABLE_OPTIMAL) {
+ size += put_huffman_table(p, 0, 0, m->bits_dc_luminance,
+ m->val_dc_luminance);
+ size += put_huffman_table(p, 0, 1, m->bits_dc_chrominance,
+ m->val_dc_chrominance);
+
+ size += put_huffman_table(p, 1, 0, m->bits_ac_luminance,
+ m->val_ac_luminance);
+ size += put_huffman_table(p, 1, 1, m->bits_ac_chrominance,
+ m->val_ac_chrominance);
} else {
size += put_huffman_table(p, 0, 0, avpriv_mjpeg_bits_dc_luminance,
avpriv_mjpeg_val_dc);
@@ -218,11 +214,12 @@ void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4
}
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])
{
- const int lossless = avctx->codec_id != AV_CODEC_ID_MJPEG && avctx->codec_id != AV_CODEC_ID_AMV;
+ const int lossless = !m;
int hsample[4], vsample[4];
int components = 3 + (avctx->pix_fmt == AV_PIX_FMT_BGRA);
int chroma_matrix = !!memcmp(luma_intra_matrix,
@@ -239,7 +236,8 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
jpeg_put_comments(avctx, pb);
- jpeg_table_header(avctx, pb, intra_scantable, luma_intra_matrix, chroma_intra_matrix, hsample);
+ jpeg_table_header(avctx, pb, m, intra_scantable,
+ luma_intra_matrix, chroma_intra_matrix, hsample);
switch (avctx->codec_id) {
case AV_CODEC_ID_MJPEG: put_marker(pb, SOF0 ); break;
diff --git a/libavcodec/mjpegenc_common.h b/libavcodec/mjpegenc_common.h
index 76c236d835..ac753bf153 100644
--- a/libavcodec/mjpegenc_common.h
+++ b/libavcodec/mjpegenc_common.h
@@ -27,7 +27,10 @@
#include "idctdsp.h"
#include "put_bits.h"
+struct MJpegContext;
+
void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb,
+ struct MJpegContext *m,
ScanTable *intra_scantable, int pred,
uint16_t luma_intra_matrix[64],
uint16_t chroma_intra_matrix[64]);
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 11/14] avcodec/mjpegenc_common: Don't call function unnecessarily
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (8 preceding siblings ...)
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 10/14] avcodec/mjpegenc_common: Pass MJpegContext for writing picture header Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 12/14] avcodec/mjpegenc_common: Use AVCodecContext.codec_id directly Andreas Rheinhardt
` (28 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc_common.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index 70d5fddfd5..ecc21da1b8 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -188,10 +188,6 @@ static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p)
void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4])
{
- int chroma_h_shift, chroma_v_shift;
-
- av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
- &chroma_v_shift);
if (avctx->codec->id == AV_CODEC_ID_LJPEG &&
( avctx->pix_fmt == AV_PIX_FMT_BGR0
|| avctx->pix_fmt == AV_PIX_FMT_BGRA
@@ -204,6 +200,9 @@ void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4
vsample[0] = vsample[1] = vsample[2] = 2;
hsample[0] = hsample[1] = hsample[2] = 1;
} else {
+ int chroma_h_shift, chroma_v_shift;
+ av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift,
+ &chroma_v_shift);
vsample[0] = 2;
vsample[1] = 2 >> chroma_v_shift;
vsample[2] = 2 >> chroma_v_shift;
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 12/14] avcodec/mjpegenc_common: Use AVCodecContext.codec_id directly
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (9 preceding siblings ...)
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 11/14] avcodec/mjpegenc_common: Don't call function unnecessarily Andreas Rheinhardt
@ 2021-12-22 3:25 ` Andreas Rheinhardt
2021-12-22 3:30 ` [FFmpeg-devel] [PATCH 13/14] avcodec/mpegvideo: Remove unnecessary headers Andreas Rheinhardt
` (27 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:25 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegenc_common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index ecc21da1b8..e385ea20ed 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -188,7 +188,7 @@ static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p)
void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4])
{
- if (avctx->codec->id == AV_CODEC_ID_LJPEG &&
+ if (avctx->codec_id == AV_CODEC_ID_LJPEG &&
( avctx->pix_fmt == AV_PIX_FMT_BGR0
|| avctx->pix_fmt == AV_PIX_FMT_BGRA
|| avctx->pix_fmt == AV_PIX_FMT_BGR24)) {
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 13/14] avcodec/mpegvideo: Remove unnecessary headers
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (10 preceding siblings ...)
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 12/14] avcodec/mjpegenc_common: Use AVCodecContext.codec_id directly Andreas Rheinhardt
@ 2021-12-22 3:30 ` Andreas Rheinhardt
2021-12-22 3:30 ` [FFmpeg-devel] [PATCH 14/14] avcodec/mpegvideo_enc: Remove impossible branch Andreas Rheinhardt
` (26 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:30 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/eatqi.c | 1 +
libavcodec/mdec.c | 1 +
libavcodec/mpegvideo.c | 3 ---
libavcodec/mpegvideo.h | 3 +--
libavcodec/mpegvideo_enc.c | 1 +
libavcodec/mpegvideo_parser.c | 1 +
libavcodec/speedhqenc.c | 1 +
7 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/libavcodec/eatqi.c b/libavcodec/eatqi.c
index 9beab58a83..8f502b3c56 100644
--- a/libavcodec/eatqi.c
+++ b/libavcodec/eatqi.c
@@ -37,6 +37,7 @@
#include "idctdsp.h"
#include "internal.h"
#include "mpeg12.h"
+#include "mpeg12data.h"
typedef struct TqiContext {
AVCodecContext *avctx;
diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 39efed69b1..007e7fada8 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -34,6 +34,7 @@
#include "bswapdsp.h"
#include "idctdsp.h"
#include "mpeg12.h"
+#include "mpeg12data.h"
#include "thread.h"
typedef struct MDECContext {
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 46e56ca08e..43f27514b0 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -31,7 +31,6 @@
#include "libavutil/avassert.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
-#include "libavutil/motion_vector.h"
#include "libavutil/video_enc_params.h"
#include "avcodec.h"
@@ -44,8 +43,6 @@
#include "mpegutils.h"
#include "mpegvideo.h"
#include "mpegvideodata.h"
-#include "mjpegenc.h"
-#include "msmpeg4.h"
#include "qpeldsp.h"
#include "thread.h"
#include "wmv2.h"
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 942b05ba37..d810f900f2 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -53,9 +53,8 @@
#include "parser.h"
#endif
#include "mpegutils.h"
-#include "mpeg12data.h"
#include "qpeldsp.h"
-#include "thread.h"
+#include "rl.h"
#include "videodsp.h"
#include "libavutil/opt.h"
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 9807e491e5..4ee7666c78 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -45,6 +45,7 @@
#include "encode.h"
#include "idctdsp.h"
#include "mpeg12.h"
+#include "mpeg12data.h"
#include "mpegvideo.h"
#include "mpegvideodata.h"
#include "h261.h"
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index 39b9f2e43a..c5dc867d24 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -22,6 +22,7 @@
#include "parser.h"
#include "mpeg12.h"
+#include "mpeg12data.h"
#include "internal.h"
struct MpvParseContext {
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index 4a2b422f13..8f8b791164 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -32,6 +32,7 @@
#include "avcodec.h"
#include "mpeg12.h"
+#include "mpeg12data.h"
#include "mpegvideo.h"
#include "speedhqenc.h"
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 14/14] avcodec/mpegvideo_enc: Remove impossible branch
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (11 preceding siblings ...)
2021-12-22 3:30 ` [FFmpeg-devel] [PATCH 13/14] avcodec/mpegvideo: Remove unnecessary headers Andreas Rheinhardt
@ 2021-12-22 3:30 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 15/30] avcodec/speedhqenc: Inline constants Andreas Rheinhardt
` (25 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-22 3:30 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 4ee7666c78..79f67ca01b 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3596,9 +3596,7 @@ static int encode_picture(MpegEncContext *s, int picture_number)
s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, !!s->intra_penalty);
}
}
- }
-
- if(s->pict_type==AV_PICTURE_TYPE_B){
+ } else if (s->pict_type == AV_PICTURE_TYPE_B) {
int a, b;
a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD);
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 15/30] avcodec/speedhqenc: Inline constants
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (12 preceding siblings ...)
2021-12-22 3:30 ` [FFmpeg-devel] [PATCH 14/14] avcodec/mpegvideo_enc: Remove impossible branch Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 16/30] avcodec/mpegvideo_enc: Move updating mb_info to its only user Andreas Rheinhardt
` (24 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/speedhqenc.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index 8f8b791164..967774931c 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -213,8 +213,9 @@ static void encode_block(MpegEncContext *s, int16_t *block, int n)
put_bits_le(&s->pb, ff_rl_speedhq.table_vlc[code][1] + 1,
ff_rl_speedhq.table_vlc[code][0] + (sign << ff_rl_speedhq.table_vlc[code][1]));
} else {
- /* escape seems to be pretty rare <5% so I do not optimize it */
- put_bits_le(&s->pb, ff_rl_speedhq.table_vlc[121][1], ff_rl_speedhq.table_vlc[121][0]);
+ /* escape seems to be pretty rare <5% so I do not optimize it;
+ * the values correspond to ff_rl_speedhq.table_vlc[121] */
+ put_bits_le(&s->pb, 6, 32);
/* escape: only clip in this case */
put_bits_le(&s->pb, 6, run);
put_bits_le(&s->pb, 12, level + 2048);
@@ -222,8 +223,8 @@ static void encode_block(MpegEncContext *s, int16_t *block, int n)
last_non_zero = i;
}
}
- /* end of block */
- put_bits_le(&s->pb, ff_rl_speedhq.table_vlc[122][1], ff_rl_speedhq.table_vlc[122][0]);
+ /* end of block; the values correspond to ff_rl_speedhq.table_vlc[122] */
+ put_bits_le(&s->pb, 4, 6);
}
void ff_speedhq_encode_mb(MpegEncContext *s, int16_t block[12][64])
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 16/30] avcodec/mpegvideo_enc: Move updating mb_info to its only user
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (13 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 15/30] avcodec/speedhqenc: Inline constants Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 17/30] avcodec/mpeg12enc: Simplify check for A53 closed captions Andreas Rheinhardt
` (23 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is a H.263 option.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
There is unfortunately another call to update_mb_info()
that is not immediately followed (or preceded) by some ff_h263_*
function; otherwise one could have easily moved this to
a h263-specific place.
libavcodec/mpegvideo_enc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 79f67ca01b..0c98629603 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2906,8 +2906,6 @@ static int encode_thread(AVCodecContext *c, void *arg){
}
}
- update_mb_info(s, 1);
-
switch(s->codec_id){
case AV_CODEC_ID_MPEG4:
if (CONFIG_MPEG4_ENCODER) {
@@ -2924,8 +2922,10 @@ static int encode_thread(AVCodecContext *c, void *arg){
break;
case AV_CODEC_ID_H263:
case AV_CODEC_ID_H263P:
- if (CONFIG_H263_ENCODER)
+ if (CONFIG_H263_ENCODER) {
+ update_mb_info(s, 1);
ff_h263_encode_gob_header(s, mb_y);
+ }
break;
}
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 17/30] avcodec/mpeg12enc: Simplify check for A53 closed captions
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (14 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 16/30] avcodec/mpegvideo_enc: Move updating mb_info to its only user Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 18/30] avcodec/mpeg12enc: Add custom context, move mpeg2_frame_rate_ext to it Andreas Rheinhardt
` (22 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The a53_cc option is only useful and meaningful for MPEG-2,
yet it was accidentally added for all mpegvideo-based encoders.
This means that it is possible for a53_cc to be set for other
encoders as well.
This commit changes this and reroutes a53_cc to the dummy field
in MpegEncContext for all codecs for which it is not supported.
This allows to avoid a check for the current codec in mpeg12enc.c.
Also add a compile-time check for whether the MPEG-2 encoder is
available while at it.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12enc.c | 2 +-
libavcodec/mpegvideo.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 2fb2232f3c..abb0a4b29f 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -551,7 +551,7 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
}
}
- if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->a53_cc) {
+ if (CONFIG_MPEG2VIDEO_ENCODER && s->a53_cc) {
side_data = av_frame_get_side_data(s->current_picture_ptr->f,
AV_FRAME_DATA_A53_CC);
if (side_data) {
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index d810f900f2..900b8b1403 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -662,7 +662,7 @@ 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(a53_cc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED },
+ { "a53cc", "Deprecated, does nothing", FF_MPV_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 },
#define FF_MPV_DEPRECATED_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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 18/30] avcodec/mpeg12enc: Add custom context, move mpeg2_frame_rate_ext to it
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (15 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 17/30] avcodec/mpeg12enc: Simplify check for A53 closed captions Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 19/30] avcodec/mpeg12enc: Move options-related fields to MPEG12EncContext Andreas Rheinhardt
` (21 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is only used here.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12enc.c | 26 +++++++++++++++++---------
libavcodec/mpegvideo.h | 1 -
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index abb0a4b29f..97df5523cc 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -62,6 +62,11 @@ static uint8_t uni_mpeg2_ac_vlc_len[64 * 64 * 2];
static uint32_t mpeg1_lum_dc_uni[512];
static uint32_t mpeg1_chr_dc_uni[512];
+typedef struct MPEG12EncContext {
+ MpegEncContext mpeg;
+ AVRational frame_rate_ext;
+} MPEG12EncContext;
+
#define A53_MAX_CC_COUNT 0x1f
#endif /* CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER */
@@ -101,8 +106,9 @@ av_cold void ff_mpeg1_init_uni_ac_vlc(const RLTable *rl, uint8_t *uni_ac_vlc_len
}
#if CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER
-static int find_frame_rate_index(MpegEncContext *s)
+static int find_frame_rate_index(MPEG12EncContext *mpeg12)
{
+ MpegEncContext *const s = &mpeg12->mpeg;
int i;
AVRational bestq = (AVRational) {0, 0};
AVRational ext;
@@ -127,8 +133,8 @@ static int find_frame_rate_index(MpegEncContext *s)
|| ext.num==1 && ext.den==1 && av_nearer_q(target, bestq, q) == 0) {
bestq = q;
s->frame_rate_index = i;
- s->mpeg2_frame_rate_ext.num = ext.num;
- s->mpeg2_frame_rate_ext.den = ext.den;
+ mpeg12->frame_rate_ext.num = ext.num;
+ mpeg12->frame_rate_ext.den = ext.den;
}
}
}
@@ -142,8 +148,9 @@ static int find_frame_rate_index(MpegEncContext *s)
static av_cold int encode_init(AVCodecContext *avctx)
{
+ MPEG12EncContext *const mpeg12 = avctx->priv_data;
+ MpegEncContext *const s = &mpeg12->mpeg;
int ret;
- MpegEncContext *s = avctx->priv_data;
int max_size = avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 16383 : 4095;
if (avctx->width > max_size || avctx->height > max_size) {
@@ -199,7 +206,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
if ((ret = ff_mpv_encode_init(avctx)) < 0)
return ret;
- if (find_frame_rate_index(s) < 0) {
+ if (find_frame_rate_index(mpeg12) < 0) {
if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
av_log(avctx, AV_LOG_ERROR, "MPEG-1/2 does not support %d/%d fps\n",
avctx->time_base.den, avctx->time_base.num);
@@ -244,6 +251,7 @@ static void put_header(MpegEncContext *s, int header)
/* put sequence header if needed */
static void mpeg1_encode_sequence_header(MpegEncContext *s)
{
+ MPEG12EncContext *const mpeg12 = (MPEG12EncContext*)s;
unsigned int vbv_buffer_size, fps, v;
int i, constraint_parameter_flag;
uint64_t time_code;
@@ -339,8 +347,8 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
put_bits(&s->pb, 1, 1); // marker
put_bits(&s->pb, 8, vbv_buffer_size >> 10); // vbv buffer ext
put_bits(&s->pb, 1, s->low_delay);
- put_bits(&s->pb, 2, s->mpeg2_frame_rate_ext.num-1); // frame_rate_ext_n
- put_bits(&s->pb, 5, s->mpeg2_frame_rate_ext.den-1); // frame_rate_ext_d
+ put_bits(&s->pb, 2, mpeg12->frame_rate_ext.num-1); // frame_rate_ext_n
+ put_bits(&s->pb, 5, mpeg12->frame_rate_ext.den-1); // frame_rate_ext_d
side_data = av_frame_get_side_data(s->current_picture_ptr->f, AV_FRAME_DATA_PANSCAN);
if (side_data) {
@@ -1204,7 +1212,7 @@ const AVCodec ff_mpeg1video_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MPEG1VIDEO,
- .priv_data_size = sizeof(MpegEncContext),
+ .priv_data_size = sizeof(MPEG12EncContext),
.init = encode_init,
.encode2 = ff_mpv_encode_picture,
.close = ff_mpv_encode_end,
@@ -1221,7 +1229,7 @@ const AVCodec ff_mpeg2video_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MPEG2VIDEO,
- .priv_data_size = sizeof(MpegEncContext),
+ .priv_data_size = sizeof(MPEG12EncContext),
.init = encode_init,
.encode2 = ff_mpv_encode_picture,
.close = ff_mpv_encode_end,
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 900b8b1403..2611e7c667 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -203,7 +203,6 @@ typedef struct MpegEncContext {
int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
int droppable;
int frame_rate_index;
- AVRational mpeg2_frame_rate_ext;
int last_lambda_for[5]; ///< last lambda for a specific pict type
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 19/30] avcodec/mpeg12enc: Move options-related fields to MPEG12EncContext
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (16 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 18/30] avcodec/mpeg12enc: Add custom context, move mpeg2_frame_rate_ext to it Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 20/30] avcodec/mpegvideo_enc: Don't merge decoder-only fields Andreas Rheinhardt
` (20 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 1 +
libavcodec/mpeg12enc.c | 58 +++++++++++++++++++++++++-----------------
libavcodec/mpegvideo.h | 9 -------
3 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 672031b6db..b75b2c9ea2 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -33,6 +33,7 @@
#include "libavutil/internal.h"
#include "libavutil/mem_internal.h"
#include "libavutil/stereo3d.h"
+#include "libavutil/timecode.h"
#include "libavutil/video_enc_params.h"
#include "avcodec.h"
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 97df5523cc..3692494713 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -65,6 +65,16 @@ static uint32_t mpeg1_chr_dc_uni[512];
typedef struct MPEG12EncContext {
MpegEncContext mpeg;
AVRational frame_rate_ext;
+
+ int64_t timecode_frame_start; ///< GOP timecode frame start number, in non drop frame format
+ AVTimecode tc; ///< timecode context
+ char *tc_opt_str; ///< timecode option string
+ int drop_frame_timecode; ///< timecode is in drop frame format.
+ int scan_offset; ///< reserve space for SVCD scan offset user data.
+
+ int a53_cc;
+ int seq_disp_ext;
+ int video_format;
} MPEG12EncContext;
#define A53_MAX_CC_COUNT 0x1f
@@ -218,24 +228,24 @@ static av_cold int encode_init(AVCodecContext *avctx)
}
}
- s->drop_frame_timecode = s->drop_frame_timecode || !!(avctx->flags2 & AV_CODEC_FLAG2_DROP_FRAME_TIMECODE);
- if (s->drop_frame_timecode)
- s->tc.flags |= AV_TIMECODE_FLAG_DROPFRAME;
- if (s->drop_frame_timecode && s->frame_rate_index != 4) {
+ mpeg12->drop_frame_timecode = mpeg12->drop_frame_timecode || !!(avctx->flags2 & AV_CODEC_FLAG2_DROP_FRAME_TIMECODE);
+ if (mpeg12->drop_frame_timecode)
+ mpeg12->tc.flags |= AV_TIMECODE_FLAG_DROPFRAME;
+ if (mpeg12->drop_frame_timecode && s->frame_rate_index != 4) {
av_log(avctx, AV_LOG_ERROR,
"Drop frame time code only allowed with 1001/30000 fps\n");
return AVERROR(EINVAL);
}
- if (s->tc_opt_str) {
+ if (mpeg12->tc_opt_str) {
AVRational rate = ff_mpeg12_frame_rate_tab[s->frame_rate_index];
- int ret = av_timecode_init_from_string(&s->tc, rate, s->tc_opt_str, s);
+ int ret = av_timecode_init_from_string(&mpeg12->tc, rate, mpeg12->tc_opt_str, s);
if (ret < 0)
return ret;
- s->drop_frame_timecode = !!(s->tc.flags & AV_TIMECODE_FLAG_DROPFRAME);
- s->timecode_frame_start = s->tc.start;
+ mpeg12->drop_frame_timecode = !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME);
+ mpeg12->timecode_frame_start = mpeg12->tc.start;
} else {
- s->timecode_frame_start = 0; // default is -1
+ mpeg12->timecode_frame_start = 0; // default is -1
}
return 0;
@@ -364,12 +374,13 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
s->avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
s->avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
s->avctx->colorspace != AVCOL_SPC_UNSPECIFIED ||
- s->video_format != VIDEO_FORMAT_UNSPECIFIED);
+ mpeg12->video_format != VIDEO_FORMAT_UNSPECIFIED);
- if (s->seq_disp_ext == 1 || (s->seq_disp_ext == -1 && use_seq_disp_ext)) {
+ if (mpeg12->seq_disp_ext == 1 ||
+ (mpeg12->seq_disp_ext == -1 && use_seq_disp_ext)) {
put_header(s, EXT_START_CODE);
put_bits(&s->pb, 4, 2); // sequence display extension
- put_bits(&s->pb, 3, s->video_format); // video_format
+ put_bits(&s->pb, 3, mpeg12->video_format); // video_format
put_bits(&s->pb, 1, 1); // colour_description
put_bits(&s->pb, 8, s->avctx->color_primaries); // colour_primaries
put_bits(&s->pb, 8, s->avctx->color_trc); // transfer_characteristics
@@ -382,17 +393,17 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
}
put_header(s, GOP_START_CODE);
- put_bits(&s->pb, 1, s->drop_frame_timecode); // drop frame flag
+ put_bits(&s->pb, 1, mpeg12->drop_frame_timecode); // drop frame flag
/* time code: we must convert from the real frame rate to a
* fake MPEG frame rate in case of low frame rate */
fps = (framerate.num + framerate.den / 2) / framerate.den;
time_code = s->current_picture_ptr->f->coded_picture_number +
- s->timecode_frame_start;
+ mpeg12->timecode_frame_start;
s->gop_picture_number = s->current_picture_ptr->f->coded_picture_number;
- av_assert0(s->drop_frame_timecode == !!(s->tc.flags & AV_TIMECODE_FLAG_DROPFRAME));
- if (s->drop_frame_timecode)
+ av_assert0(mpeg12->drop_frame_timecode == !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME));
+ if (mpeg12->drop_frame_timecode)
time_code = av_timecode_adjust_ntsc_framenum2(time_code, fps);
put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
@@ -436,6 +447,7 @@ void ff_mpeg1_encode_slice_header(MpegEncContext *s)
void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
{
+ MPEG12EncContext *const mpeg12 = (MPEG12EncContext*)s;
AVFrameSideData *side_data;
mpeg1_encode_sequence_header(s);
@@ -513,7 +525,7 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
put_bits(&s->pb, 1, s->progressive_frame);
put_bits(&s->pb, 1, 0); /* composite_display_flag */
}
- if (s->scan_offset) {
+ if (mpeg12->scan_offset) {
int i;
put_header(s, USER_START_CODE);
@@ -559,7 +571,7 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
}
}
- if (CONFIG_MPEG2VIDEO_ENCODER && s->a53_cc) {
+ if (CONFIG_MPEG2VIDEO_ENCODER && mpeg12->a53_cc) {
side_data = av_frame_get_side_data(s->current_picture_ptr->f,
AV_FRAME_DATA_A53_CC);
if (side_data) {
@@ -1138,7 +1150,7 @@ av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
ff_thread_once(&init_static_once, mpeg12_encode_init_static);
}
-#define OFFSET(x) offsetof(MpegEncContext, x)
+#define OFFSET(x) offsetof(MPEG12EncContext, x)
#define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
#define COMMON_OPTS \
{ "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format. Overrides timecode_frame_start.", \
@@ -1165,9 +1177,9 @@ static const AVOption mpeg1_options[] = {
static const AVOption mpeg2_options[] = {
COMMON_OPTS
{ "intra_vlc", "Use MPEG-2 intra VLC table.",
- OFFSET(intra_vlc_format), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
- { "non_linear_quant", "Use nonlinear quantizer.", OFFSET(q_scale_type), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
- { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ FF_MPV_OFFSET(intra_vlc_format), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ { "non_linear_quant", "Use nonlinear quantizer.", FF_MPV_OFFSET(q_scale_type), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ { "alternate_scan", "Enable alternate scantable.", FF_MPV_OFFSET(alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },
{ "seq_disp_ext", "Write sequence_display_extension blocks.", OFFSET(seq_disp_ext), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE, "seq_disp_ext" },
{ "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, VE, "seq_disp_ext" },
@@ -1188,7 +1200,7 @@ static const AVOption mpeg2_options[] = {
#undef LEVEL
FF_MPV_COMMON_OPTS
#if FF_API_MPEGVIDEO_OPTS
- { "mpeg_quant", "Deprecated, does nothing", OFFSET(mpeg_quant),
+ { "mpeg_quant", "Deprecated, does nothing", FF_MPV_OFFSET(mpeg_quant),
AV_OPT_TYPE_INT, {.i64 = 1 }, 0, 1, VE | AV_OPT_FLAG_DEPRECATED },
FF_MPV_DEPRECATED_MATRIX_OPT
#endif
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 2611e7c667..fabcce2436 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -58,7 +58,6 @@
#include "videodsp.h"
#include "libavutil/opt.h"
-#include "libavutil/timecode.h"
#define MAX_THREADS 32
@@ -443,7 +442,6 @@ typedef struct MpegEncContext {
/* MPEG-2-specific - I wished not to have to support this mess. */
int progressive_sequence;
int mpeg_f_code[2][2];
- int a53_cc;
// picture structure defines are loaded from mpegutils.h
int picture_structure;
@@ -457,8 +455,6 @@ typedef struct MpegEncContext {
int brd_scale;
int intra_vlc_format;
int alternate_scan;
- int seq_disp_ext;
- int video_format;
#define VIDEO_FORMAT_COMPONENT 0
#define VIDEO_FORMAT_PAL 1
#define VIDEO_FORMAT_NTSC 2
@@ -478,16 +474,11 @@ typedef struct MpegEncContext {
int full_pel[2];
int interlaced_dct;
int first_field; ///< is 1 for the first field of a field picture 0 otherwise
- int drop_frame_timecode; ///< timecode is in drop frame format.
- int scan_offset; ///< reserve space for SVCD scan offset user data.
/* RTP specific */
int rtp_mode;
int rtp_payload_size;
- char *tc_opt_str; ///< timecode option string
- AVTimecode tc; ///< timecode context
-
uint8_t *ptr_lastgob;
int swap_uv; //vcr2 codec is an MPEG-2 variant with U and V swapped
int pack_pblocks; //xvmc needs to keep blocks without gaps.
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 20/30] avcodec/mpegvideo_enc: Don't merge decoder-only fields
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (17 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 19/30] avcodec/mpeg12enc: Move options-related fields to MPEG12EncContext Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 21/30] avcodec/mpeg12dec: Use %c to write single char Andreas Rheinhardt
` (19 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
How could this ever happen? And why did it go unnoticed for so long?
(Btw: skip_count is nearly unused: It is only used to write its value
to the file in case this is the first pass of a two-pass encoding;
said value is read in the second pass, but not used.)
libavcodec/mpegvideo_enc.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 0c98629603..0279816d3c 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3404,8 +3404,6 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src)
MERGE(b_count);
MERGE(skip_count);
MERGE(misc_bits);
- MERGE(er.error_count);
- MERGE(padding_bug_score);
MERGE(current_picture.encoding_error[0]);
MERGE(current_picture.encoding_error[1]);
MERGE(current_picture.encoding_error[2]);
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 21/30] avcodec/mpeg12dec: Use %c to write single char
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (18 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 20/30] avcodec/mpegvideo_enc: Don't merge decoder-only fields Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 22/30] avcodec/mpegvideo: Don't duplicate identical code Andreas Rheinhardt
` (18 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index b75b2c9ea2..e7961c1498 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1790,13 +1790,13 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
if (s->mb_y == 0 && s->mb_x == 0 && (s->first_field || s->picture_structure == PICT_FRAME)) {
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(s->avctx, AV_LOG_DEBUG,
- "qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
+ "qp:%d fc:%2d%2d%2d%2d %c %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
s->qscale,
s->mpeg_f_code[0][0], s->mpeg_f_code[0][1],
s->mpeg_f_code[1][0], s->mpeg_f_code[1][1],
- s->pict_type == AV_PICTURE_TYPE_I ? "I" :
- (s->pict_type == AV_PICTURE_TYPE_P ? "P" :
- (s->pict_type == AV_PICTURE_TYPE_B ? "B" : "S")),
+ s->pict_type == AV_PICTURE_TYPE_I ? 'I' :
+ (s->pict_type == AV_PICTURE_TYPE_P ? 'P' :
+ (s->pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')),
s->progressive_sequence ? "ps" : "",
s->progressive_frame ? "pf" : "",
s->alternate_scan ? "alt" : "",
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 22/30] avcodec/mpegvideo: Don't duplicate identical code
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (19 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 21/30] avcodec/mpeg12dec: Use %c to write single char Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 23/30] avcodec/mpegvideo: Avoid needlessly calling function Andreas Rheinhardt
` (17 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 37 ++++++++++++++++++-------------------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 43f27514b0..4c3e0fa8bf 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1963,25 +1963,6 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
{
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
- if (CONFIG_XVMC &&
- s->avctx->hwaccel && s->avctx->hwaccel->decode_mb) {
- s->avctx->hwaccel->decode_mb(s);//xvmc uses pblocks
- return;
- }
-
- if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
- /* print DCT coefficients */
- int i,j;
- av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
- for(i=0; i<6; i++){
- for(j=0; j<64; j++){
- av_log(s->avctx, AV_LOG_DEBUG, "%5d",
- block[i][s->idsp.idct_permutation[j]]);
- }
- av_log(s->avctx, AV_LOG_DEBUG, "\n");
- }
- }
-
s->current_picture.qscale_table[mb_xy] = s->qscale;
/* update DC predictors for P macroblocks */
@@ -2263,6 +2244,24 @@ skip_idct:
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
{
+ if (CONFIG_XVMC &&
+ s->avctx->hwaccel && s->avctx->hwaccel->decode_mb) {
+ s->avctx->hwaccel->decode_mb(s); //xvmc uses pblocks
+ return;
+ }
+
+ if (s->avctx->debug & FF_DEBUG_DCT_COEFF) {
+ /* print DCT coefficients */
+ av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
+ for (int i = 0; i < 6; i++) {
+ for (int j = 0; j < 64; j++) {
+ av_log(s->avctx, AV_LOG_DEBUG, "%5d",
+ block[i][s->idsp.idct_permutation[j]]);
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ }
+
#if !CONFIG_SMALL
if(s->out_format == FMT_MPEG1) {
if(s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, 1);
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 23/30] avcodec/mpegvideo: Avoid needlessly calling function
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (20 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 22/30] avcodec/mpegvideo: Don't duplicate identical code Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 24/30] avcodec/wmv2: Move ff_wmv2_add_mb() to the wmv2dec Andreas Rheinhardt
` (16 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The very first check in this if-else if-else if construct is
"if (s->encoding ||", i.e. in case of the WMV2 encoder the else
branches are never executed.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 4c3e0fa8bf..3a42e08a04 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -2122,8 +2122,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
}
}//fi gray
- }
- else if (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) {
+ } else if (CONFIG_WMV2_DECODER) {
ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
}
} else {
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 24/30] avcodec/wmv2: Move ff_wmv2_add_mb() to the wmv2dec
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (21 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 23/30] avcodec/mpegvideo: Avoid needlessly calling function Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 25/30] avcodec/mpegvideo_motion: Don't duplicate identical code Andreas Rheinhardt
` (15 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Only the decoder ever used it.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/wmv2.c | 44 --------------------------------------------
libavcodec/wmv2dec.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 44 deletions(-)
diff --git a/libavcodec/wmv2.c b/libavcodec/wmv2.c
index 327c5bdae1..fd64a0938f 100644
--- a/libavcodec/wmv2.c
+++ b/libavcodec/wmv2.c
@@ -23,7 +23,6 @@
#include "mpegutils.h"
#include "mpegvideo.h"
#include "msmpeg4data.h"
-#include "simple_idct.h"
#include "wmv2.h"
#include "wmv2data.h"
@@ -54,49 +53,6 @@ av_cold void ff_wmv2_common_init(Wmv2Context *w)
s->idsp.idct = NULL;
}
-static void wmv2_add_block(Wmv2Context *w, int16_t *block1,
- uint8_t *dst, int stride, int n)
-{
- MpegEncContext *const s = &w->s;
-
- if (s->block_last_index[n] >= 0) {
- switch (w->abt_type_table[n]) {
- case 0:
- w->wdsp.idct_add(dst, stride, block1);
- break;
- case 1:
- ff_simple_idct84_add(dst, stride, block1);
- ff_simple_idct84_add(dst + 4 * stride, stride, w->abt_block2[n]);
- s->bdsp.clear_block(w->abt_block2[n]);
- break;
- case 2:
- ff_simple_idct48_add(dst, stride, block1);
- ff_simple_idct48_add(dst + 4, stride, w->abt_block2[n]);
- s->bdsp.clear_block(w->abt_block2[n]);
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
- }
- }
-}
-
-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;
-
- wmv2_add_block(w, block1[0], dest_y, s->linesize, 0);
- wmv2_add_block(w, block1[1], dest_y + 8, s->linesize, 1);
- wmv2_add_block(w, block1[2], dest_y + 8 * s->linesize, s->linesize, 2);
- wmv2_add_block(w, block1[3], dest_y + 8 + 8 * s->linesize, s->linesize, 3);
-
- if (s->avctx->flags & AV_CODEC_FLAG_GRAY)
- return;
-
- wmv2_add_block(w, block1[4], dest_cb, s->uvlinesize, 4);
- wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5);
-}
-
void ff_mspel_motion(MpegEncContext *s, uint8_t *dest_y,
uint8_t *dest_cb, uint8_t *dest_cr,
uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index c500e3e779..f7745c5a83 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -27,9 +27,53 @@
#include "mpegvideo.h"
#include "msmpeg4.h"
#include "msmpeg4data.h"
+#include "simple_idct.h"
#include "wmv2.h"
+static void wmv2_add_block(Wmv2Context *w, int16_t *block1,
+ uint8_t *dst, int stride, int n)
+{
+ MpegEncContext *const s = &w->s;
+
+ if (s->block_last_index[n] >= 0) {
+ switch (w->abt_type_table[n]) {
+ case 0:
+ w->wdsp.idct_add(dst, stride, block1);
+ break;
+ case 1:
+ ff_simple_idct84_add(dst, stride, block1);
+ ff_simple_idct84_add(dst + 4 * stride, stride, w->abt_block2[n]);
+ s->bdsp.clear_block(w->abt_block2[n]);
+ break;
+ case 2:
+ ff_simple_idct48_add(dst, stride, block1);
+ ff_simple_idct48_add(dst + 4, stride, w->abt_block2[n]);
+ s->bdsp.clear_block(w->abt_block2[n]);
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
+ }
+ }
+}
+
+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;
+
+ wmv2_add_block(w, block1[0], dest_y, s->linesize, 0);
+ wmv2_add_block(w, block1[1], dest_y + 8, s->linesize, 1);
+ wmv2_add_block(w, block1[2], dest_y + 8 * s->linesize, s->linesize, 2);
+ wmv2_add_block(w, block1[3], dest_y + 8 + 8 * s->linesize, s->linesize, 3);
+
+ if (s->avctx->flags & AV_CODEC_FLAG_GRAY)
+ return;
+
+ wmv2_add_block(w, block1[4], dest_cb, s->uvlinesize, 4);
+ wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5);
+}
+
static int parse_mb_skip(Wmv2Context *w)
{
int mb_x, mb_y;
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 25/30] avcodec/mpegvideo_motion: Don't duplicate identical code
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (22 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 24/30] avcodec/wmv2: Move ff_wmv2_add_mb() to the wmv2dec Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 26/30] avcodec/mpegvideo: Don't check for > 8 bit MPEG-1/2 Andreas Rheinhardt
` (14 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_motion.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index 427bc96887..876a7375f8 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -839,8 +839,6 @@ static av_always_inline void mpv_motion_internal(MpegEncContext *s,
int i;
int mb_y = s->mb_y;
- prefetch_motion(s, ref_picture, dir);
-
if (!is_mpeg12 && s->obmc && s->pict_type != AV_PICTURE_TYPE_B) {
apply_obmc(s, dest_y, dest_cb, dest_cr, ref_picture, pix_op);
return;
@@ -978,6 +976,8 @@ void ff_mpv_motion(MpegEncContext *s,
op_pixels_func (*pix_op)[4],
qpel_mc_func (*qpix_op)[16])
{
+ prefetch_motion(s, ref_picture, dir);
+
#if !CONFIG_SMALL
if (s->out_format == FMT_MPEG1)
mpv_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 26/30] avcodec/mpegvideo: Don't check for > 8 bit MPEG-1/2
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (23 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 25/30] avcodec/mpegvideo_motion: Don't duplicate identical code Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 27/30] avcodec/mpegvideo: Partially check for being encoder at compile-time Andreas Rheinhardt
` (13 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It doesn't exist.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
Apart from the mpeg4 decoder no mpegvideo decoder sets
bits_per_raw_sample. Should it be set (in ff_mpv_decode_init())?
libavcodec/mpegvideo.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 3a42e08a04..4e6ad92473 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -2128,7 +2128,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
} else {
/* Only MPEG-4 Simple Studio Profile is supported in > 8-bit mode.
TODO: Integrate 10-bit properly into mpegvideo.c so that ER works properly */
- if (s->avctx->bits_per_raw_sample > 8){
+ if (!is_mpeg12 && s->avctx->bits_per_raw_sample > 8) {
const int act_block_size = block_size * 2;
if(s->dpcm_direction == 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 27/30] avcodec/mpegvideo: Partially check for being encoder at compile-time
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (24 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 26/30] avcodec/mpegvideo: Don't check for > 8 bit MPEG-1/2 Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 28/30] avcodec/mpegvideo: Try to perform check for MPEG-1/2 " Andreas Rheinhardt
` (12 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Whether lowres is in use or not is inlined in
mpv_reconstruct_mb_internal(), so one can use the fact
that lowres is always zero during encoding to evaluate
the checks for whether one is encoding or not at compile-time
when one is in lowres mode.
Also reorder the main check to check for whether it is an encoder
first to shortcircuit it in the common case of a decoder.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
lowres is currently only checked for decoders; should it also be
checked for encoders?
(The relevant AVOption is not marked as decoding, but not encoding
parameter.)
libavcodec/mpegvideo.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 4e6ad92473..5e1a1522a2 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1961,6 +1961,7 @@ static av_always_inline
void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
int lowres_flag, int is_mpeg12)
{
+#define IS_ENCODER(s) (CONFIG_MPEGVIDEOENC && !lowres_flag && (s)->encoding)
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
s->current_picture.qscale_table[mb_xy] = s->qscale;
@@ -1979,8 +1980,8 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
else if (!is_mpeg12 && (s->h263_pred || s->h263_aic))
s->mbintra_table[mb_xy]=1;
- if ((s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
- !(s->encoding && (s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) &&
+ if (!IS_ENCODER(s) || (s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
+ !((s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) &&
s->avctx->mb_decision != FF_MB_DECISION_RD)) { // FIXME precalc
uint8_t *dest_y, *dest_cb, *dest_cr;
int dct_linesize, dct_offset;
@@ -1988,12 +1989,12 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
qpel_mc_func (*op_qpix)[16];
const int linesize = s->current_picture.f->linesize[0]; //not s->linesize as this would be wrong for field pics
const int uvlinesize = s->current_picture.f->linesize[1];
- const int readable= s->pict_type != AV_PICTURE_TYPE_B || s->encoding || s->avctx->draw_horiz_band || lowres_flag;
+ const int readable = s->pict_type != AV_PICTURE_TYPE_B || IS_ENCODER(s) || s->avctx->draw_horiz_band || lowres_flag;
const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8;
/* avoid copy if macroblock skipped in last frame too */
/* skip only during decoding as we might trash the buffers during encoding a bit */
- if(!s->encoding){
+ if (!IS_ENCODER(s)) {
uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
if (s->mb_skipped) {
@@ -2023,7 +2024,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
if (!s->mb_intra) {
/* motion handling */
/* decoding or more than one mb_type (MC was already done otherwise) */
- if(!s->encoding){
+ if (!IS_ENCODER(s)) {
if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
if (s->mv_dir & MV_DIR_FORWARD) {
@@ -2075,7 +2076,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
/* add dct residue */
- if(s->encoding || !( s->msmpeg4_version || s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==AV_CODEC_ID_MPEG2VIDEO
+ if (IS_ENCODER(s) || !(s->msmpeg4_version || s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO
|| (s->codec_id==AV_CODEC_ID_MPEG4 && !s->mpeg_quant))){
add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
@@ -2182,7 +2183,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
}
/* dct only in intra block */
- else if(s->encoding || !(s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==AV_CODEC_ID_MPEG2VIDEO)){
+ else if (IS_ENCODER(s) || !(s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO)) {
put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 28/30] avcodec/mpegvideo: Try to perform check for MPEG-1/2 at compile-time
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (25 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 27/30] avcodec/mpegvideo: Partially check for being encoder at compile-time Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 29/30] avcodec/mpegvideo: Remove always-true branch Andreas Rheinhardt
` (11 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible if CONFIG_SMALL is not true.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 5e1a1522a2..73b91b459c 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1962,6 +1962,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
int lowres_flag, int is_mpeg12)
{
#define IS_ENCODER(s) (CONFIG_MPEGVIDEOENC && !lowres_flag && (s)->encoding)
+#define IS_MPEG12(s) (CONFIG_SMALL ? ((s)->out_format == FMT_MPEG1) : is_mpeg12)
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
s->current_picture.qscale_table[mb_xy] = s->qscale;
@@ -2076,7 +2077,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
/* add dct residue */
- if (IS_ENCODER(s) || !(s->msmpeg4_version || s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO
+ if (IS_ENCODER(s) || !(IS_MPEG12(s) || s->msmpeg4_version
|| (s->codec_id==AV_CODEC_ID_MPEG4 && !s->mpeg_quant))){
add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
@@ -2183,7 +2184,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
}
/* dct only in intra block */
- else if (IS_ENCODER(s) || !(s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO)) {
+ else if (IS_ENCODER(s) || !IS_MPEG12(s)) {
put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 29/30] avcodec/mpegvideo: Remove always-true branch
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (26 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 28/30] avcodec/mpegvideo: Try to perform check for MPEG-1/2 " Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 30/30] avcodec/mpegvideo: Check for no_rounding at compile-time if possible Andreas Rheinhardt
` (10 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 73b91b459c..7626f97be5 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -2166,10 +2166,11 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
dest_pcm[i] += linesize[i] / 2;
}
}
- } else if(s->dpcm_direction == -1) {
+ } else {
int i, w, h;
uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
+ av_assert2(s->dpcm_direction == -1);
for(i = 0; i < 3; i++) {
int idx = 0;
int vsub = i ? s->chroma_y_shift : 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 30/30] avcodec/mpegvideo: Check for no_rounding at compile-time if possible
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (27 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 29/30] avcodec/mpegvideo: Remove always-true branch Andreas Rheinhardt
@ 2021-12-23 9:13 ` Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 31/36] avcodec/mpegvideo: Don't initialize error resilience context for encoder Andreas Rheinhardt
` (9 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-23 9:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is partially possible if it is inlined whether
we deal with MPEG-1/2, because no_rounding is never set
for MPEG-1/2.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 7626f97be5..8b16b4ec0b 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -2052,7 +2052,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
}else{
op_qpix = s->me.qpel_put;
- if ((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){
+ if ((is_mpeg12 || !s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
op_pix = s->hdsp.put_pixels_tab;
}else{
op_pix = s->hdsp.put_no_rnd_pixels_tab;
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 31/36] avcodec/mpegvideo: Don't initialize error resilience context for encoder
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (28 preceding siblings ...)
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 30/30] avcodec/mpegvideo: Check for no_rounding at compile-time if possible Andreas Rheinhardt
@ 2021-12-24 3:23 ` Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 32/36] avcodec/mpegvideo: Remove always-false check Andreas Rheinhardt
` (8 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-24 3:23 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is only used for decoders.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 8b16b4ec0b..c0ba91e864 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -835,7 +835,7 @@ static int init_context_frame(MpegEncContext *s)
return AVERROR(ENOMEM);
memset(s->mbintra_table, 1, mb_array_size);
- return ff_mpeg_er_init(s);
+ return s->encoding ? 0 : ff_mpeg_er_init(s);
}
static void clear_context(MpegEncContext *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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 32/36] avcodec/mpegvideo: Remove always-false check
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (29 preceding siblings ...)
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 31/36] avcodec/mpegvideo: Don't initialize error resilience context for encoder Andreas Rheinhardt
@ 2021-12-24 3:23 ` Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 33/36] avcodec/mpegvideo: Move decoding-only code into a new file Andreas Rheinhardt
` (7 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-24 3:23 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
An AVCodecContext's private data is always allocated
in avcodec_open2() and calling avcodec_flush_buffers()
on an unopened AVCodecContext (or an already closed one)
is not allowed (and will crash before the decoder's flush
function is even called).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index c0ba91e864..942952e46b 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -2318,7 +2318,7 @@ void ff_mpeg_flush(AVCodecContext *avctx){
int i;
MpegEncContext *s = avctx->priv_data;
- if (!s || !s->picture)
+ if (!s->picture)
return;
for (i = 0; i < MAX_PICTURE_COUNT; i++)
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 33/36] avcodec/mpegvideo: Move decoding-only code into a new file
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (30 preceding siblings ...)
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 32/36] avcodec/mpegvideo: Remove always-false check Andreas Rheinhardt
@ 2021-12-24 3:23 ` Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 34/36] configure: Add new mpegvideodec CONFIG_EXTRA Andreas Rheinhardt
` (6 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-24 3:23 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This will allow to disable this code altogether when
all decoders are disabled.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/Makefile | 2 +-
libavcodec/mpegvideo.c | 582 +-----------------------------------
libavcodec/mpegvideo.h | 22 ++
libavcodec/mpegvideo_dec.c | 583 +++++++++++++++++++++++++++++++++++++
4 files changed, 612 insertions(+), 577 deletions(-)
create mode 100644 libavcodec/mpegvideo_dec.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9577062eec..e7f1f110e7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -123,7 +123,7 @@ OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \
mpegaudiodsp_fixed.o \
mpegaudiodsp_float.o
OBJS-$(CONFIG_MPEGAUDIOHEADER) += mpegaudiodecheader.o mpegaudiodata.o
-OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideodsp.o rl.o \
+OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideo_dec.o mpegvideodsp.o rl.o \
mpegvideo_motion.o mpegutils.o \
mpegvideodata.o mpegpicture.o
OBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideo_enc.o mpeg12data.o \
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 942952e46b..a2c4e14b6e 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -31,13 +31,11 @@
#include "libavutil/avassert.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
-#include "libavutil/video_enc_params.h"
#include "avcodec.h"
#include "blockdsp.h"
#include "h264chroma.h"
#include "idctdsp.h"
-#include "internal.h"
#include "mathops.h"
#include "mpeg_er.h"
#include "mpegutils.h"
@@ -345,14 +343,6 @@ av_cold void ff_mpv_idct_init(MpegEncContext *s)
ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
}
-static int alloc_picture(MpegEncContext *s, Picture *pic)
-{
- return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 0, 0,
- s->chroma_x_shift, s->chroma_y_shift, s->out_format,
- s->mb_stride, s->mb_width, s->mb_height, s->b8_stride,
- &s->linesize, &s->uvlinesize);
-}
-
static int init_duplicate_context(MpegEncContext *s)
{
int y_size = s->b8_stride * (2 * s->mb_height + 1);
@@ -403,12 +393,7 @@ static int init_duplicate_context(MpegEncContext *s)
return 0;
}
-/**
- * Initialize an MpegEncContext's thread contexts. Presumes that
- * slice_context_count is already set and that all the fields
- * that are freed/reset in free_duplicate_context() are NULL.
- */
-static int init_duplicate_contexts(MpegEncContext *s)
+int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
{
int nb_slices = s->slice_context_count, ret;
@@ -518,146 +503,6 @@ int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src)
return 0;
}
-int ff_mpeg_update_thread_context(AVCodecContext *dst,
- const AVCodecContext *src)
-{
- int i, ret;
- MpegEncContext *s = dst->priv_data, *s1 = src->priv_data;
-
- if (dst == src)
- return 0;
-
- av_assert0(s != s1);
-
- // FIXME can parameters change on I-frames?
- // in that case dst may need a reinit
- if (!s->context_initialized) {
- int err;
- memcpy(s, s1, sizeof(MpegEncContext));
-
- s->avctx = dst;
- s->bitstream_buffer = NULL;
- s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0;
-
- if (s1->context_initialized){
-// s->picture_range_start += MAX_PICTURE_COUNT;
-// s->picture_range_end += MAX_PICTURE_COUNT;
- ff_mpv_idct_init(s);
- if((err = ff_mpv_common_init(s)) < 0){
- memset(s, 0, sizeof(MpegEncContext));
- s->avctx = dst;
- return err;
- }
- }
- }
-
- if (s->height != s1->height || s->width != s1->width || s->context_reinit) {
- s->height = s1->height;
- s->width = s1->width;
- if ((ret = ff_mpv_common_frame_size_change(s)) < 0)
- return ret;
- }
-
- s->avctx->coded_height = s1->avctx->coded_height;
- s->avctx->coded_width = s1->avctx->coded_width;
- s->avctx->width = s1->avctx->width;
- s->avctx->height = s1->avctx->height;
-
- s->quarter_sample = s1->quarter_sample;
-
- s->coded_picture_number = s1->coded_picture_number;
- s->picture_number = s1->picture_number;
-
- av_assert0(!s->picture || s->picture != s1->picture);
- if(s->picture)
- for (i = 0; i < MAX_PICTURE_COUNT; i++) {
- ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
- if (s1->picture && s1->picture[i].f->buf[0] &&
- (ret = ff_mpeg_ref_picture(s->avctx, &s->picture[i], &s1->picture[i])) < 0)
- return ret;
- }
-
-#define UPDATE_PICTURE(pic)\
-do {\
- ff_mpeg_unref_picture(s->avctx, &s->pic);\
- if (s1->pic.f && s1->pic.f->buf[0])\
- ret = ff_mpeg_ref_picture(s->avctx, &s->pic, &s1->pic);\
- else\
- ret = ff_update_picture_tables(&s->pic, &s1->pic);\
- if (ret < 0)\
- return ret;\
-} while (0)
-
- UPDATE_PICTURE(current_picture);
- UPDATE_PICTURE(last_picture);
- UPDATE_PICTURE(next_picture);
-
-#define REBASE_PICTURE(pic, new_ctx, old_ctx) \
- ((pic && pic >= old_ctx->picture && \
- pic < old_ctx->picture + MAX_PICTURE_COUNT) ? \
- &new_ctx->picture[pic - old_ctx->picture] : NULL)
-
- s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1);
- s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1);
- s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, s, s1);
-
- // Error/bug resilience
- s->next_p_frame_damaged = s1->next_p_frame_damaged;
- s->workaround_bugs = s1->workaround_bugs;
- s->padding_bug_score = s1->padding_bug_score;
-
- // MPEG-4 timing info
- memcpy(&s->last_time_base, &s1->last_time_base,
- (char *) &s1->pb_field_time + sizeof(s1->pb_field_time) -
- (char *) &s1->last_time_base);
-
- // B-frame info
- s->max_b_frames = s1->max_b_frames;
- s->low_delay = s1->low_delay;
- s->droppable = s1->droppable;
-
- // DivX handling (doesn't work)
- s->divx_packed = s1->divx_packed;
-
- if (s1->bitstream_buffer) {
- if (s1->bitstream_buffer_size +
- AV_INPUT_BUFFER_PADDING_SIZE > s->allocated_bitstream_buffer_size) {
- av_fast_malloc(&s->bitstream_buffer,
- &s->allocated_bitstream_buffer_size,
- s1->allocated_bitstream_buffer_size);
- if (!s->bitstream_buffer) {
- s->bitstream_buffer_size = 0;
- return AVERROR(ENOMEM);
- }
- }
- s->bitstream_buffer_size = s1->bitstream_buffer_size;
- memcpy(s->bitstream_buffer, s1->bitstream_buffer,
- s1->bitstream_buffer_size);
- memset(s->bitstream_buffer + s->bitstream_buffer_size, 0,
- AV_INPUT_BUFFER_PADDING_SIZE);
- }
-
- // linesize-dependent scratch buffer allocation
- if (!s->sc.edge_emu_buffer)
- if (s1->linesize) {
- if (ff_mpeg_framesize_alloc(s->avctx, &s->me,
- &s->sc, s1->linesize) < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate context "
- "scratch buffers.\n");
- return AVERROR(ENOMEM);
- }
- } else {
- av_log(s->avctx, AV_LOG_ERROR, "Context scratch buffers could not "
- "be allocated due to unknown size.\n");
- }
-
- // MPEG-2/interlacing info
- memcpy(&s->progressive_sequence, &s1->progressive_sequence,
- (char *) &s1->rtp_mode - (char *) &s1->progressive_sequence);
-
- return 0;
-}
-
/**
* Set the given MpegEncContext to common defaults
* (same for encoding and decoding).
@@ -682,29 +527,7 @@ void ff_mpv_common_defaults(MpegEncContext *s)
s->slice_context_count = 1;
}
-/**
- * Initialize the given MpegEncContext for decoding.
- * the changed fields will not depend upon
- * the prior state of the MpegEncContext.
- */
-void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
-{
- ff_mpv_common_defaults(s);
-
- s->avctx = avctx;
- s->width = avctx->coded_width;
- s->height = avctx->coded_height;
- s->codec_id = avctx->codec->id;
- s->workaround_bugs = avctx->workaround_bugs;
-
- /* convert fourcc to upper case */
- s->codec_tag = avpriv_toupper4(avctx->codec_tag);
-}
-
-/**
- * Initialize and allocates MpegEncContext fields dependent on the resolution.
- */
-static int init_context_frame(MpegEncContext *s)
+int ff_mpv_init_context_frame(MpegEncContext *s)
{
int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
@@ -981,7 +804,7 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
!(s->new_picture.f = av_frame_alloc()))
goto fail_nomem;
- if ((ret = init_context_frame(s)))
+ if ((ret = ff_mpv_init_context_frame(s)))
goto fail;
#if FF_API_FLAG_TRUNCATED
@@ -994,7 +817,7 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
s->slice_context_count = nb_slices;
// if (s->width && s->height) {
- ret = init_duplicate_contexts(s);
+ ret = ff_mpv_init_duplicate_contexts(s);
if (ret < 0)
goto fail;
// }
@@ -1007,13 +830,7 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
return ret;
}
-/**
- * Frees and resets MpegEncContext fields depending on the resolution
- * as well as the slice thread contexts.
- * Is used during resolution changes to avoid a full reinitialization of the
- * codec.
- */
-static void free_context_frame(MpegEncContext *s)
+void ff_mpv_free_context_frame(MpegEncContext *s)
{
int i, j, k;
@@ -1066,61 +883,6 @@ static void free_context_frame(MpegEncContext *s)
s->linesize = s->uvlinesize = 0;
}
-int ff_mpv_common_frame_size_change(MpegEncContext *s)
-{
- int i, err = 0;
-
- if (!s->context_initialized)
- return AVERROR(EINVAL);
-
- free_context_frame(s);
-
- if (s->picture)
- for (i = 0; i < MAX_PICTURE_COUNT; i++) {
- s->picture[i].needs_realloc = 1;
- }
-
- s->last_picture_ptr =
- s->next_picture_ptr =
- s->current_picture_ptr = NULL;
-
- // init
- if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
- s->mb_height = (s->height + 31) / 32 * 2;
- else
- s->mb_height = (s->height + 15) / 16;
-
- if ((s->width || s->height) &&
- (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
- goto fail;
-
- /* set chroma shifts */
- err = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
- &s->chroma_x_shift,
- &s->chroma_y_shift);
- if (err < 0)
- goto fail;
-
- if ((err = init_context_frame(s)))
- goto fail;
-
- memset(s->thread_context, 0, sizeof(s->thread_context));
- s->thread_context[0] = s;
-
- if (s->width && s->height) {
- err = init_duplicate_contexts(s);
- if (err < 0)
- goto fail;
- }
- s->context_reinit = 0;
-
- return 0;
- fail:
- free_context_frame(s);
- s->context_reinit = 1;
- return err;
-}
-
/* init common structure for both encoder and decoder */
void ff_mpv_common_end(MpegEncContext *s)
{
@@ -1129,7 +891,7 @@ void ff_mpv_common_end(MpegEncContext *s)
if (!s)
return;
- free_context_frame(s);
+ ff_mpv_free_context_frame(s);
if (s->slice_context_count > 1)
s->slice_context_count = 1;
@@ -1174,296 +936,6 @@ void ff_mpv_common_end(MpegEncContext *s)
}
-static void gray_frame(AVFrame *frame)
-{
- int i, h_chroma_shift, v_chroma_shift;
-
- av_pix_fmt_get_chroma_sub_sample(frame->format, &h_chroma_shift, &v_chroma_shift);
-
- for(i=0; i<frame->height; i++)
- memset(frame->data[0] + frame->linesize[0]*i, 0x80, frame->width);
- for(i=0; i<AV_CEIL_RSHIFT(frame->height, v_chroma_shift); i++) {
- memset(frame->data[1] + frame->linesize[1]*i,
- 0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift));
- memset(frame->data[2] + frame->linesize[2]*i,
- 0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift));
- }
-}
-
-/**
- * generic function called after decoding
- * the header and before a frame is decoded.
- */
-int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
-{
- int i, ret;
- Picture *pic;
- s->mb_skipped = 0;
-
- if (!ff_thread_can_start_frame(avctx)) {
- av_log(avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n");
- return -1;
- }
-
- /* mark & release old frames */
- if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr &&
- s->last_picture_ptr != s->next_picture_ptr &&
- s->last_picture_ptr->f->buf[0]) {
- ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr);
- }
-
- /* release forgotten pictures */
- /* if (MPEG-124 / H.263) */
- for (i = 0; i < MAX_PICTURE_COUNT; i++) {
- if (&s->picture[i] != s->last_picture_ptr &&
- &s->picture[i] != s->next_picture_ptr &&
- s->picture[i].reference && !s->picture[i].needs_realloc) {
- ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
- }
- }
-
- ff_mpeg_unref_picture(s->avctx, &s->current_picture);
- ff_mpeg_unref_picture(s->avctx, &s->last_picture);
- ff_mpeg_unref_picture(s->avctx, &s->next_picture);
-
- /* release non reference frames */
- for (i = 0; i < MAX_PICTURE_COUNT; i++) {
- if (!s->picture[i].reference)
- ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
- }
-
- if (s->current_picture_ptr && !s->current_picture_ptr->f->buf[0]) {
- // we already have an unused image
- // (maybe it was set before reading the header)
- pic = s->current_picture_ptr;
- } else {
- i = ff_find_unused_picture(s->avctx, s->picture, 0);
- if (i < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
- return i;
- }
- pic = &s->picture[i];
- }
-
- pic->reference = 0;
- if (!s->droppable) {
- if (s->pict_type != AV_PICTURE_TYPE_B)
- pic->reference = 3;
- }
-
- pic->f->coded_picture_number = s->coded_picture_number++;
-
- if (alloc_picture(s, pic) < 0)
- return -1;
-
- s->current_picture_ptr = pic;
- // FIXME use only the vars from current_pic
- s->current_picture_ptr->f->top_field_first = s->top_field_first;
- if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO ||
- s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
- if (s->picture_structure != PICT_FRAME)
- s->current_picture_ptr->f->top_field_first =
- (s->picture_structure == PICT_TOP_FIELD) == s->first_field;
- }
- s->current_picture_ptr->f->interlaced_frame = !s->progressive_frame &&
- !s->progressive_sequence;
- s->current_picture_ptr->field_picture = s->picture_structure != PICT_FRAME;
-
- s->current_picture_ptr->f->pict_type = s->pict_type;
- // if (s->avctx->flags && AV_CODEC_FLAG_QSCALE)
- // s->current_picture_ptr->quality = s->new_picture_ptr->quality;
- s->current_picture_ptr->f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
-
- if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture,
- s->current_picture_ptr)) < 0)
- return ret;
-
- if (s->pict_type != AV_PICTURE_TYPE_B) {
- s->last_picture_ptr = s->next_picture_ptr;
- if (!s->droppable)
- s->next_picture_ptr = s->current_picture_ptr;
- }
- ff_dlog(s->avctx, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n",
- s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr,
- s->last_picture_ptr ? s->last_picture_ptr->f->data[0] : NULL,
- s->next_picture_ptr ? s->next_picture_ptr->f->data[0] : NULL,
- s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL,
- s->pict_type, s->droppable);
-
- if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
- (s->pict_type != AV_PICTURE_TYPE_I)) {
- int h_chroma_shift, v_chroma_shift;
- av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
- &h_chroma_shift, &v_chroma_shift);
- if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0])
- av_log(avctx, AV_LOG_DEBUG,
- "allocating dummy last picture for B frame\n");
- else if (s->pict_type != AV_PICTURE_TYPE_I)
- av_log(avctx, AV_LOG_ERROR,
- "warning: first frame is no keyframe\n");
-
- /* Allocate a dummy frame */
- i = ff_find_unused_picture(s->avctx, s->picture, 0);
- if (i < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
- return i;
- }
- s->last_picture_ptr = &s->picture[i];
-
- s->last_picture_ptr->reference = 3;
- s->last_picture_ptr->f->key_frame = 0;
- s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
-
- if (alloc_picture(s, s->last_picture_ptr) < 0) {
- s->last_picture_ptr = NULL;
- return -1;
- }
-
- if (!avctx->hwaccel) {
- for(i=0; i<avctx->height; i++)
- memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0]*i,
- 0x80, avctx->width);
- if (s->last_picture_ptr->f->data[2]) {
- for(i=0; i<AV_CEIL_RSHIFT(avctx->height, v_chroma_shift); i++) {
- memset(s->last_picture_ptr->f->data[1] + s->last_picture_ptr->f->linesize[1]*i,
- 0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
- memset(s->last_picture_ptr->f->data[2] + s->last_picture_ptr->f->linesize[2]*i,
- 0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
- }
- }
-
- if(s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263){
- for(i=0; i<avctx->height; i++)
- memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0]*i, 16, avctx->width);
- }
- }
-
- ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
- ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1);
- }
- if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
- s->pict_type == AV_PICTURE_TYPE_B) {
- /* Allocate a dummy frame */
- i = ff_find_unused_picture(s->avctx, s->picture, 0);
- if (i < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
- return i;
- }
- s->next_picture_ptr = &s->picture[i];
-
- s->next_picture_ptr->reference = 3;
- s->next_picture_ptr->f->key_frame = 0;
- s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
-
- if (alloc_picture(s, s->next_picture_ptr) < 0) {
- s->next_picture_ptr = NULL;
- return -1;
- }
- ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 0);
- ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 1);
- }
-
-#if 0 // BUFREF-FIXME
- memset(s->last_picture.f->data, 0, sizeof(s->last_picture.f->data));
- memset(s->next_picture.f->data, 0, sizeof(s->next_picture.f->data));
-#endif
- if (s->last_picture_ptr) {
- if (s->last_picture_ptr->f->buf[0] &&
- (ret = ff_mpeg_ref_picture(s->avctx, &s->last_picture,
- s->last_picture_ptr)) < 0)
- return ret;
- }
- if (s->next_picture_ptr) {
- if (s->next_picture_ptr->f->buf[0] &&
- (ret = ff_mpeg_ref_picture(s->avctx, &s->next_picture,
- s->next_picture_ptr)) < 0)
- return ret;
- }
-
- av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
- s->last_picture_ptr->f->buf[0]));
-
- if (s->picture_structure!= PICT_FRAME) {
- int i;
- for (i = 0; i < 4; i++) {
- if (s->picture_structure == PICT_BOTTOM_FIELD) {
- s->current_picture.f->data[i] +=
- s->current_picture.f->linesize[i];
- }
- s->current_picture.f->linesize[i] *= 2;
- s->last_picture.f->linesize[i] *= 2;
- s->next_picture.f->linesize[i] *= 2;
- }
- }
-
- /* set dequantizer, we can't do it during init as
- * it might change for MPEG-4 and we can't do it in the header
- * decode as init is not called for MPEG-4 there yet */
- if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
- s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
- s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
- } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
- s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
- s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
- } else {
- s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
- s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
- }
-
- if (s->avctx->debug & FF_DEBUG_NOMC) {
- gray_frame(s->current_picture_ptr->f);
- }
-
- return 0;
-}
-
-/* called after a frame has been decoded. */
-void ff_mpv_frame_end(MpegEncContext *s)
-{
- emms_c();
-
- if (s->current_picture.reference)
- ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0);
-}
-
-void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
-{
- ff_print_debug_info2(s->avctx, pict, s->mbskip_table, p->mb_type,
- p->qscale_table, p->motion_val,
- s->mb_width, s->mb_height, s->mb_stride, s->quarter_sample);
-}
-
-int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
-{
- AVVideoEncParams *par;
- int mult = (qp_type == FF_QSCALE_TYPE_MPEG1) ? 2 : 1;
- unsigned int nb_mb = p->alloc_mb_height * p->alloc_mb_width;
- unsigned int x, y;
-
- if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS))
- return 0;
-
- par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_MPEG2, nb_mb);
- if (!par)
- return AVERROR(ENOMEM);
-
- for (y = 0; y < p->alloc_mb_height; y++)
- for (x = 0; x < p->alloc_mb_width; x++) {
- const unsigned int block_idx = y * p->alloc_mb_width + x;
- const unsigned int mb_xy = y * p->alloc_mb_stride + x;
- AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
-
- b->src_x = x * 16;
- b->src_y = y * 16;
- b->w = 16;
- b->h = 16;
-
- b->delta_qp = p->qscale_table[mb_xy] * mult;
- }
-
- return 0;
-}
-
static inline int hpel_motion_lowres(MpegEncContext *s,
uint8_t *dest, uint8_t *src,
int field_based, int field_select,
@@ -2274,13 +1746,6 @@ void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
else mpv_reconstruct_mb_internal(s, block, 0, 0);
}
-void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
-{
- ff_draw_horiz_band(s->avctx, s->current_picture_ptr->f,
- s->last_picture_ptr ? s->last_picture_ptr->f : NULL, y, h, s->picture_structure,
- s->first_field, s->low_delay);
-}
-
void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
const int linesize = s->current_picture.f->linesize[0]; //not s->linesize as this would be wrong for field pics
const int uvlinesize = s->current_picture.f->linesize[1];
@@ -2314,35 +1779,6 @@ void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
}
}
-void ff_mpeg_flush(AVCodecContext *avctx){
- int i;
- MpegEncContext *s = avctx->priv_data;
-
- if (!s->picture)
- return;
-
- for (i = 0; i < MAX_PICTURE_COUNT; i++)
- ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
- s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL;
-
- ff_mpeg_unref_picture(s->avctx, &s->current_picture);
- ff_mpeg_unref_picture(s->avctx, &s->last_picture);
- ff_mpeg_unref_picture(s->avctx, &s->next_picture);
-
- s->mb_x= s->mb_y= 0;
-
-#if FF_API_FLAG_TRUNCATED
- s->parse_context.state= -1;
- s->parse_context.frame_start_found= 0;
- s->parse_context.overread= 0;
- s->parse_context.overread_index= 0;
- s->parse_context.index= 0;
- s->parse_context.last_index= 0;
-#endif
- s->bitstream_buffer_size=0;
- s->pp_time=0;
-}
-
/**
* set qscale and update qscale dependent variables.
*/
@@ -2359,9 +1795,3 @@ void ff_set_qscale(MpegEncContext * s, int qscale)
s->y_dc_scale= s->y_dc_scale_table[ qscale ];
s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ];
}
-
-void ff_mpv_report_decode_progress(MpegEncContext *s)
-{
- if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred)
- ff_thread_report_progress(&s->current_picture_ptr->tf, s->mb_y, 0);
-}
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index fabcce2436..1c14f5b0f0 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -679,10 +679,32 @@ void ff_mpv_common_init_neon(MpegEncContext *s);
void ff_mpv_common_init_ppc(MpegEncContext *s);
void ff_mpv_common_init_x86(MpegEncContext *s);
void ff_mpv_common_init_mips(MpegEncContext *s);
+/**
+ * Initialize an MpegEncContext's thread contexts. Presumes that
+ * slice_context_count is already set and that all the fields
+ * that are freed/reset in free_duplicate_context() are NULL.
+ */
+int ff_mpv_init_duplicate_contexts(MpegEncContext *s);
+/**
+ * Initialize and allocates MpegEncContext fields dependent on the resolution.
+ */
+int ff_mpv_init_context_frame(MpegEncContext *s);
+/**
+ * Frees and resets MpegEncContext fields depending on the resolution
+ * as well as the slice thread contexts.
+ * Is used during resolution changes to avoid a full reinitialization of the
+ * codec.
+ */
+void ff_mpv_free_context_frame(MpegEncContext *s);
int ff_mpv_common_frame_size_change(MpegEncContext *s);
void ff_mpv_common_end(MpegEncContext *s);
+/**
+ * Initialize the given MpegEncContext for decoding.
+ * the changed fields will not depend upon
+ * the prior state of the MpegEncContext.
+ */
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx);
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]);
void ff_mpv_report_decode_progress(MpegEncContext *s);
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
new file mode 100644
index 0000000000..56bd6b0570
--- /dev/null
+++ b/libavcodec/mpegvideo_dec.c
@@ -0,0 +1,583 @@
+/*
+ * Common mpeg video decoding code
+ * Copyright (c) 2000,2001 Fabrice Bellard
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * 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
+ */
+
+#include <limits.h>
+
+#include "libavutil/avassert.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/internal.h"
+#include "libavutil/video_enc_params.h"
+
+#include "avcodec.h"
+#include "internal.h"
+#include "mpegutils.h"
+#include "mpegvideo.h"
+#include "thread.h"
+
+void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
+{
+ ff_mpv_common_defaults(s);
+
+ s->avctx = avctx;
+ s->width = avctx->coded_width;
+ s->height = avctx->coded_height;
+ s->codec_id = avctx->codec->id;
+ s->workaround_bugs = avctx->workaround_bugs;
+
+ /* convert fourcc to upper case */
+ s->codec_tag = avpriv_toupper4(avctx->codec_tag);
+}
+
+int ff_mpeg_update_thread_context(AVCodecContext *dst,
+ const AVCodecContext *src)
+{
+ MpegEncContext *const s1 = src->priv_data;
+ MpegEncContext *const s = dst->priv_data;
+ int ret;
+
+ if (dst == src)
+ return 0;
+
+ av_assert0(s != s1);
+
+ // FIXME can parameters change on I-frames?
+ // in that case dst may need a reinit
+ if (!s->context_initialized) {
+ int err;
+ memcpy(s, s1, sizeof(*s));
+
+ s->avctx = dst;
+ s->bitstream_buffer = NULL;
+ s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0;
+
+ if (s1->context_initialized) {
+// s->picture_range_start += MAX_PICTURE_COUNT;
+// s->picture_range_end += MAX_PICTURE_COUNT;
+ ff_mpv_idct_init(s);
+ if ((err = ff_mpv_common_init(s)) < 0) {
+ memset(s, 0, sizeof(*s));
+ s->avctx = dst;
+ return err;
+ }
+ }
+ }
+
+ if (s->height != s1->height || s->width != s1->width || s->context_reinit) {
+ s->height = s1->height;
+ s->width = s1->width;
+ if ((ret = ff_mpv_common_frame_size_change(s)) < 0)
+ return ret;
+ }
+
+ s->avctx->coded_height = s1->avctx->coded_height;
+ s->avctx->coded_width = s1->avctx->coded_width;
+ s->avctx->width = s1->avctx->width;
+ s->avctx->height = s1->avctx->height;
+
+ s->quarter_sample = s1->quarter_sample;
+
+ s->coded_picture_number = s1->coded_picture_number;
+ s->picture_number = s1->picture_number;
+
+ av_assert0(!s->picture || s->picture != s1->picture);
+ if (s->picture)
+ for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
+ if (s1->picture && s1->picture[i].f->buf[0] &&
+ (ret = ff_mpeg_ref_picture(s->avctx, &s->picture[i], &s1->picture[i])) < 0)
+ return ret;
+ }
+
+#define UPDATE_PICTURE(pic)\
+do {\
+ ff_mpeg_unref_picture(s->avctx, &s->pic);\
+ if (s1->pic.f && s1->pic.f->buf[0])\
+ ret = ff_mpeg_ref_picture(s->avctx, &s->pic, &s1->pic);\
+ else\
+ ret = ff_update_picture_tables(&s->pic, &s1->pic);\
+ if (ret < 0)\
+ return ret;\
+} while (0)
+
+ UPDATE_PICTURE(current_picture);
+ UPDATE_PICTURE(last_picture);
+ UPDATE_PICTURE(next_picture);
+
+#define REBASE_PICTURE(pic, new_ctx, old_ctx) \
+ ((pic && pic >= old_ctx->picture && \
+ pic < old_ctx->picture + MAX_PICTURE_COUNT) ? \
+ &new_ctx->picture[pic - old_ctx->picture] : NULL)
+
+ s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1);
+ s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1);
+ s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, s, s1);
+
+ // Error/bug resilience
+ s->next_p_frame_damaged = s1->next_p_frame_damaged;
+ s->workaround_bugs = s1->workaround_bugs;
+ s->padding_bug_score = s1->padding_bug_score;
+
+ // MPEG-4 timing info
+ memcpy(&s->last_time_base, &s1->last_time_base,
+ (char *) &s1->pb_field_time + sizeof(s1->pb_field_time) -
+ (char *) &s1->last_time_base);
+
+ // B-frame info
+ s->max_b_frames = s1->max_b_frames;
+ s->low_delay = s1->low_delay;
+ s->droppable = s1->droppable;
+
+ // DivX handling (doesn't work)
+ s->divx_packed = s1->divx_packed;
+
+ if (s1->bitstream_buffer) {
+ if (s1->bitstream_buffer_size +
+ AV_INPUT_BUFFER_PADDING_SIZE > s->allocated_bitstream_buffer_size) {
+ av_fast_malloc(&s->bitstream_buffer,
+ &s->allocated_bitstream_buffer_size,
+ s1->allocated_bitstream_buffer_size);
+ if (!s->bitstream_buffer) {
+ s->bitstream_buffer_size = 0;
+ return AVERROR(ENOMEM);
+ }
+ }
+ s->bitstream_buffer_size = s1->bitstream_buffer_size;
+ memcpy(s->bitstream_buffer, s1->bitstream_buffer,
+ s1->bitstream_buffer_size);
+ memset(s->bitstream_buffer + s->bitstream_buffer_size, 0,
+ AV_INPUT_BUFFER_PADDING_SIZE);
+ }
+
+ // linesize-dependent scratch buffer allocation
+ if (!s->sc.edge_emu_buffer)
+ if (s1->linesize) {
+ if (ff_mpeg_framesize_alloc(s->avctx, &s->me,
+ &s->sc, s1->linesize) < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate context "
+ "scratch buffers.\n");
+ return AVERROR(ENOMEM);
+ }
+ } else {
+ av_log(s->avctx, AV_LOG_ERROR, "Context scratch buffers could not "
+ "be allocated due to unknown size.\n");
+ }
+
+ // MPEG-2/interlacing info
+ memcpy(&s->progressive_sequence, &s1->progressive_sequence,
+ (char *) &s1->rtp_mode - (char *) &s1->progressive_sequence);
+
+ return 0;
+}
+
+int ff_mpv_common_frame_size_change(MpegEncContext *s)
+{
+ int err = 0;
+
+ if (!s->context_initialized)
+ return AVERROR(EINVAL);
+
+ ff_mpv_free_context_frame(s);
+
+ if (s->picture)
+ for (int i = 0; i < MAX_PICTURE_COUNT; i++)
+ s->picture[i].needs_realloc = 1;
+
+ s->last_picture_ptr =
+ s->next_picture_ptr =
+ s->current_picture_ptr = NULL;
+
+ // init
+ if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
+ s->mb_height = (s->height + 31) / 32 * 2;
+ else
+ s->mb_height = (s->height + 15) / 16;
+
+ if ((s->width || s->height) &&
+ (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
+ goto fail;
+
+ /* set chroma shifts */
+ err = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
+ &s->chroma_x_shift,
+ &s->chroma_y_shift);
+ if (err < 0)
+ goto fail;
+
+ if ((err = ff_mpv_init_context_frame(s)))
+ goto fail;
+
+ memset(s->thread_context, 0, sizeof(s->thread_context));
+ s->thread_context[0] = s;
+
+ if (s->width && s->height) {
+ err = ff_mpv_init_duplicate_contexts(s);
+ if (err < 0)
+ goto fail;
+ }
+ s->context_reinit = 0;
+
+ return 0;
+ fail:
+ ff_mpv_free_context_frame(s);
+ s->context_reinit = 1;
+ return err;
+}
+
+static int alloc_picture(MpegEncContext *s, Picture *pic)
+{
+ return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 0, 0,
+ s->chroma_x_shift, s->chroma_y_shift, s->out_format,
+ s->mb_stride, s->mb_width, s->mb_height, s->b8_stride,
+ &s->linesize, &s->uvlinesize);
+}
+
+static void gray_frame(AVFrame *frame)
+{
+ int h_chroma_shift, v_chroma_shift;
+
+ av_pix_fmt_get_chroma_sub_sample(frame->format, &h_chroma_shift, &v_chroma_shift);
+
+ for (int i = 0; i < frame->height; i++)
+ memset(frame->data[0] + frame->linesize[0] * i, 0x80, frame->width);
+ for (int i = 0; i < AV_CEIL_RSHIFT(frame->height, v_chroma_shift); i++) {
+ memset(frame->data[1] + frame->linesize[1] * i,
+ 0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift));
+ memset(frame->data[2] + frame->linesize[2] * i,
+ 0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift));
+ }
+}
+
+/**
+ * generic function called after decoding
+ * the header and before a frame is decoded.
+ */
+int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
+{
+ Picture *pic;
+ int idx, ret;
+
+ s->mb_skipped = 0;
+
+ if (!ff_thread_can_start_frame(avctx)) {
+ av_log(avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n");
+ return -1;
+ }
+
+ /* mark & release old frames */
+ if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr &&
+ s->last_picture_ptr != s->next_picture_ptr &&
+ s->last_picture_ptr->f->buf[0]) {
+ ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr);
+ }
+
+ /* release forgotten pictures */
+ /* if (MPEG-124 / H.263) */
+ for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
+ if (&s->picture[i] != s->last_picture_ptr &&
+ &s->picture[i] != s->next_picture_ptr &&
+ s->picture[i].reference && !s->picture[i].needs_realloc) {
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
+ }
+ }
+
+ ff_mpeg_unref_picture(s->avctx, &s->current_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->last_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->next_picture);
+
+ /* release non reference frames */
+ for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
+ if (!s->picture[i].reference)
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
+ }
+
+ if (s->current_picture_ptr && !s->current_picture_ptr->f->buf[0]) {
+ // we already have an unused image
+ // (maybe it was set before reading the header)
+ pic = s->current_picture_ptr;
+ } else {
+ idx = ff_find_unused_picture(s->avctx, s->picture, 0);
+ if (idx < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
+ return idx;
+ }
+ pic = &s->picture[idx];
+ }
+
+ pic->reference = 0;
+ if (!s->droppable) {
+ if (s->pict_type != AV_PICTURE_TYPE_B)
+ pic->reference = 3;
+ }
+
+ pic->f->coded_picture_number = s->coded_picture_number++;
+
+ if (alloc_picture(s, pic) < 0)
+ return -1;
+
+ s->current_picture_ptr = pic;
+ // FIXME use only the vars from current_pic
+ s->current_picture_ptr->f->top_field_first = s->top_field_first;
+ if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO ||
+ s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+ if (s->picture_structure != PICT_FRAME)
+ s->current_picture_ptr->f->top_field_first =
+ (s->picture_structure == PICT_TOP_FIELD) == s->first_field;
+ }
+ s->current_picture_ptr->f->interlaced_frame = !s->progressive_frame &&
+ !s->progressive_sequence;
+ s->current_picture_ptr->field_picture = s->picture_structure != PICT_FRAME;
+
+ s->current_picture_ptr->f->pict_type = s->pict_type;
+ // if (s->avctx->flags && AV_CODEC_FLAG_QSCALE)
+ // s->current_picture_ptr->quality = s->new_picture_ptr->quality;
+ s->current_picture_ptr->f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
+
+ if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture,
+ s->current_picture_ptr)) < 0)
+ return ret;
+
+ if (s->pict_type != AV_PICTURE_TYPE_B) {
+ s->last_picture_ptr = s->next_picture_ptr;
+ if (!s->droppable)
+ s->next_picture_ptr = s->current_picture_ptr;
+ }
+ ff_dlog(s->avctx, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n",
+ s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr,
+ s->last_picture_ptr ? s->last_picture_ptr->f->data[0] : NULL,
+ s->next_picture_ptr ? s->next_picture_ptr->f->data[0] : NULL,
+ s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL,
+ s->pict_type, s->droppable);
+
+ if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
+ (s->pict_type != AV_PICTURE_TYPE_I)) {
+ int h_chroma_shift, v_chroma_shift;
+ av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
+ &h_chroma_shift, &v_chroma_shift);
+ if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0])
+ av_log(avctx, AV_LOG_DEBUG,
+ "allocating dummy last picture for B frame\n");
+ else if (s->pict_type != AV_PICTURE_TYPE_I)
+ av_log(avctx, AV_LOG_ERROR,
+ "warning: first frame is no keyframe\n");
+
+ /* Allocate a dummy frame */
+ idx = ff_find_unused_picture(s->avctx, s->picture, 0);
+ if (idx < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
+ return idx;
+ }
+ s->last_picture_ptr = &s->picture[idx];
+
+ s->last_picture_ptr->reference = 3;
+ s->last_picture_ptr->f->key_frame = 0;
+ s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
+
+ if (alloc_picture(s, s->last_picture_ptr) < 0) {
+ s->last_picture_ptr = NULL;
+ return -1;
+ }
+
+ if (!avctx->hwaccel) {
+ for (int i = 0; i < avctx->height; i++)
+ memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0]*i,
+ 0x80, avctx->width);
+ if (s->last_picture_ptr->f->data[2]) {
+ for (int i = 0; i < AV_CEIL_RSHIFT(avctx->height, v_chroma_shift); i++) {
+ memset(s->last_picture_ptr->f->data[1] + s->last_picture_ptr->f->linesize[1]*i,
+ 0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
+ memset(s->last_picture_ptr->f->data[2] + s->last_picture_ptr->f->linesize[2]*i,
+ 0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
+ }
+ }
+
+ if (s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263) {
+ for (int i = 0; i < avctx->height; i++)
+ memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0] * i,
+ 16, avctx->width);
+ }
+ }
+
+ ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
+ ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1);
+ }
+ if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
+ s->pict_type == AV_PICTURE_TYPE_B) {
+ /* Allocate a dummy frame */
+ idx = ff_find_unused_picture(s->avctx, s->picture, 0);
+ if (idx < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
+ return idx;
+ }
+ s->next_picture_ptr = &s->picture[idx];
+
+ s->next_picture_ptr->reference = 3;
+ s->next_picture_ptr->f->key_frame = 0;
+ s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
+
+ if (alloc_picture(s, s->next_picture_ptr) < 0) {
+ s->next_picture_ptr = NULL;
+ return -1;
+ }
+ ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 0);
+ ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 1);
+ }
+
+#if 0 // BUFREF-FIXME
+ memset(s->last_picture.f->data, 0, sizeof(s->last_picture.f->data));
+ memset(s->next_picture.f->data, 0, sizeof(s->next_picture.f->data));
+#endif
+ if (s->last_picture_ptr) {
+ if (s->last_picture_ptr->f->buf[0] &&
+ (ret = ff_mpeg_ref_picture(s->avctx, &s->last_picture,
+ s->last_picture_ptr)) < 0)
+ return ret;
+ }
+ if (s->next_picture_ptr) {
+ if (s->next_picture_ptr->f->buf[0] &&
+ (ret = ff_mpeg_ref_picture(s->avctx, &s->next_picture,
+ s->next_picture_ptr)) < 0)
+ return ret;
+ }
+
+ av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
+ s->last_picture_ptr->f->buf[0]));
+
+ if (s->picture_structure != PICT_FRAME) {
+ for (int i = 0; i < 4; i++) {
+ if (s->picture_structure == PICT_BOTTOM_FIELD) {
+ s->current_picture.f->data[i] +=
+ s->current_picture.f->linesize[i];
+ }
+ s->current_picture.f->linesize[i] *= 2;
+ s->last_picture.f->linesize[i] *= 2;
+ s->next_picture.f->linesize[i] *= 2;
+ }
+ }
+
+ /* set dequantizer, we can't do it during init as
+ * it might change for MPEG-4 and we can't do it in the header
+ * decode as init is not called for MPEG-4 there yet */
+ if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+ s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
+ s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
+ } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
+ s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
+ s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
+ } else {
+ s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
+ s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
+ }
+
+ if (s->avctx->debug & FF_DEBUG_NOMC)
+ gray_frame(s->current_picture_ptr->f);
+
+ return 0;
+}
+
+/* called after a frame has been decoded. */
+void ff_mpv_frame_end(MpegEncContext *s)
+{
+ emms_c();
+
+ if (s->current_picture.reference)
+ ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0);
+}
+
+void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
+{
+ ff_print_debug_info2(s->avctx, pict, s->mbskip_table, p->mb_type,
+ p->qscale_table, p->motion_val,
+ s->mb_width, s->mb_height, s->mb_stride, s->quarter_sample);
+}
+
+int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
+{
+ AVVideoEncParams *par;
+ int mult = (qp_type == FF_QSCALE_TYPE_MPEG1) ? 2 : 1;
+ unsigned int nb_mb = p->alloc_mb_height * p->alloc_mb_width;
+
+ if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS))
+ return 0;
+
+ par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_MPEG2, nb_mb);
+ if (!par)
+ return AVERROR(ENOMEM);
+
+ for (unsigned y = 0; y < p->alloc_mb_height; y++)
+ for (unsigned x = 0; x < p->alloc_mb_width; x++) {
+ const unsigned int block_idx = y * p->alloc_mb_width + x;
+ const unsigned int mb_xy = y * p->alloc_mb_stride + x;
+ AVVideoBlockParams *const b = av_video_enc_params_block(par, block_idx);
+
+ b->src_x = x * 16;
+ b->src_y = y * 16;
+ b->w = 16;
+ b->h = 16;
+
+ b->delta_qp = p->qscale_table[mb_xy] * mult;
+ }
+
+ return 0;
+}
+
+void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
+{
+ ff_draw_horiz_band(s->avctx, s->current_picture_ptr->f,
+ s->last_picture_ptr ? s->last_picture_ptr->f : NULL,
+ y, h, s->picture_structure,
+ s->first_field, s->low_delay);
+}
+
+void ff_mpeg_flush(AVCodecContext *avctx)
+{
+ MpegEncContext *const s = avctx->priv_data;
+
+ if (!s->picture)
+ return;
+
+ for (int i = 0; i < MAX_PICTURE_COUNT; i++)
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
+ s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL;
+
+ ff_mpeg_unref_picture(s->avctx, &s->current_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->last_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->next_picture);
+
+ s->mb_x = s->mb_y = 0;
+
+#if FF_API_FLAG_TRUNCATED
+ s->parse_context.state = -1;
+ s->parse_context.frame_start_found = 0;
+ s->parse_context.overread = 0;
+ s->parse_context.overread_index = 0;
+ s->parse_context.index = 0;
+ s->parse_context.last_index = 0;
+#endif
+ s->bitstream_buffer_size = 0;
+ s->pp_time = 0;
+}
+
+void ff_mpv_report_decode_progress(MpegEncContext *s)
+{
+ if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred)
+ ff_thread_report_progress(&s->current_picture_ptr->tf, s->mb_y, 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 34/36] configure: Add new mpegvideodec CONFIG_EXTRA
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (31 preceding siblings ...)
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 33/36] avcodec/mpegvideo: Move decoding-only code into a new file Andreas Rheinhardt
@ 2021-12-24 3:23 ` Andreas Rheinhardt
2021-12-25 6:09 ` [FFmpeg-devel] [PATCH v2 34/35] " Andreas Rheinhardt
2021-12-25 6:09 ` [FFmpeg-devel] [PATCH v2 35/35] configure: Remove mpegvideo dependency on me_cmp Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 35/36] avcodec/mpegvideo_enc: Improve inlining of chroma_format Andreas Rheinhardt
` (5 subsequent siblings)
38 siblings, 2 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-24 3:23 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This allows to remove the spurious dependencies of mpegvideo encoders
on error_resilience; some other components that do not use mpegvideo
to its fullest turned out to not need it either.
Adding a new CONFIG_EXTRA needs a reconfigure to take effect.
In order to force this a few unnecessary headers from lavfi/allfilters.c
have been removed.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
configure | 26 ++++++++++++++------------
libavcodec/Makefile | 3 ++-
libavcodec/mpegvideo.c | 2 +-
libavfilter/allfilters.c | 2 --
4 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/configure b/configure
index 23ef2abc9b..f3bdfd2920 100755
--- a/configure
+++ b/configure
@@ -2476,6 +2476,7 @@ CONFIG_EXTRA="
mpegaudiodsp
mpegaudioheader
mpegvideo
+ mpegvideodec
mpegvideoenc
mss34dsp
pixblockdsp
@@ -2723,7 +2724,8 @@ me_cmp_select="fdctdsp idctdsp pixblockdsp"
mpeg_er_select="error_resilience"
mpegaudio_select="mpegaudiodsp mpegaudioheader"
mpegaudiodsp_select="dct"
-mpegvideo_select="blockdsp h264chroma hpeldsp idctdsp me_cmp mpeg_er videodsp"
+mpegvideo_select="blockdsp h264chroma hpeldsp idctdsp me_cmp videodsp"
+mpegvideodec_select="mpegvideo mpeg_er"
mpegvideoenc_select="aandcttables me_cmp mpegvideo pixblockdsp qpeldsp"
vc1dsp_select="h264chroma qpeldsp startcode"
rdft_select="fft"
@@ -2812,9 +2814,9 @@ fraps_decoder_select="bswapdsp huffman"
g2m_decoder_deps="zlib"
g2m_decoder_select="blockdsp idctdsp jpegtables"
g729_decoder_select="audiodsp"
-h261_decoder_select="mpegvideo"
+h261_decoder_select="mpegvideodec"
h261_encoder_select="mpegvideoenc"
-h263_decoder_select="h263_parser h263dsp mpegvideo qpeldsp"
+h263_decoder_select="h263_parser h263dsp mpegvideodec qpeldsp"
h263_encoder_select="h263dsp mpegvideoenc"
h263i_decoder_select="h263_decoder"
h263p_decoder_select="h263_decoder"
@@ -2836,7 +2838,7 @@ indeo3_decoder_select="hpeldsp"
indeo4_decoder_select="ividsp"
indeo5_decoder_select="ividsp"
interplay_video_decoder_select="hpeldsp"
-ipu_decoder_select="mpegvideo"
+ipu_decoder_select="mpegvideodec"
jpegls_decoder_select="mjpeg_decoder"
jv_decoder_select="blockdsp"
lagarith_decoder_select="llviddsp"
@@ -2866,10 +2868,10 @@ mp3on4_decoder_select="mpegaudio"
mp3on4float_decoder_select="mpegaudio"
mpc7_decoder_select="bswapdsp mpegaudiodsp"
mpc8_decoder_select="mpegaudiodsp"
-mpegvideo_decoder_select="mpegvideo"
-mpeg1video_decoder_select="mpegvideo"
+mpegvideo_decoder_select="mpegvideodec"
+mpeg1video_decoder_select="mpegvideodec"
mpeg1video_encoder_select="mpegvideoenc h263dsp"
-mpeg2video_decoder_select="mpegvideo"
+mpeg2video_decoder_select="mpegvideodec"
mpeg2video_encoder_select="mpegvideoenc h263dsp"
mpeg4_decoder_select="h263_decoder mpeg4video_parser"
mpeg4_encoder_select="h263_encoder"
@@ -2880,7 +2882,7 @@ msmpeg4v2_decoder_select="h263_decoder"
msmpeg4v2_encoder_select="h263_encoder"
msmpeg4v3_decoder_select="h263_decoder"
msmpeg4v3_encoder_select="h263_encoder"
-mss2_decoder_select="mpegvideo qpeldsp vc1_decoder"
+mss2_decoder_select="mpegvideodec qpeldsp vc1_decoder"
mts2_decoder_select="jpegtables mss34dsp"
mv30_decoder_select="aandcttables blockdsp"
mvha_decoder_deps="zlib"
@@ -2913,8 +2915,8 @@ rv10_decoder_select="h263_decoder"
rv10_encoder_select="h263_encoder"
rv20_decoder_select="h263_decoder"
rv20_encoder_select="h263_encoder"
-rv30_decoder_select="golomb h264pred h264qpel mpegvideo rv34dsp"
-rv40_decoder_select="golomb h264pred h264qpel mpegvideo rv34dsp"
+rv30_decoder_select="golomb h264pred h264qpel mpegvideodec rv34dsp"
+rv40_decoder_select="golomb h264pred h264qpel mpegvideodec rv34dsp"
screenpresso_decoder_deps="zlib"
shorten_decoder_select="bswapdsp"
sipr_decoder_select="lsp"
@@ -2950,7 +2952,7 @@ txd_decoder_select="texturedsp"
utvideo_decoder_select="bswapdsp llviddsp"
utvideo_encoder_select="bswapdsp huffman llvidencdsp"
vble_decoder_select="llviddsp"
-vc1_decoder_select="blockdsp h263_decoder h264qpel intrax8 mpegvideo vc1dsp"
+vc1_decoder_select="blockdsp h263_decoder h264qpel intrax8 mpegvideodec vc1dsp"
vc1image_decoder_select="vc1_decoder"
vorbis_decoder_select="mdct"
vorbis_encoder_select="audio_frame_queue mdct"
@@ -3246,7 +3248,7 @@ h264_parser_select="atsc_a53 golomb h264dsp h264parse"
hevc_parser_select="hevcparse"
mpegaudio_parser_select="mpegaudioheader"
mpegvideo_parser_select="mpegvideo"
-mpeg4video_parser_select="h263dsp mpegvideo qpeldsp"
+mpeg4video_parser_select="h263dsp mpegvideodec qpeldsp"
vc1_parser_select="vc1dsp"
# bitstream_filters
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index e7f1f110e7..df118fd3e7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -123,9 +123,10 @@ OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \
mpegaudiodsp_fixed.o \
mpegaudiodsp_float.o
OBJS-$(CONFIG_MPEGAUDIOHEADER) += mpegaudiodecheader.o mpegaudiodata.o
-OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideo_dec.o mpegvideodsp.o rl.o \
+OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideodsp.o rl.o \
mpegvideo_motion.o mpegutils.o \
mpegvideodata.o mpegpicture.o
+OBJS-$(CONFIG_MPEGVIDEODEC) += mpegvideo_dec.o
OBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideo_enc.o mpeg12data.o \
motion_est.o ratecontrol.o \
mpegvideoencdsp.o
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index a2c4e14b6e..1c2b28f450 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -658,7 +658,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
return AVERROR(ENOMEM);
memset(s->mbintra_table, 1, mb_array_size);
- return s->encoding ? 0 : ff_mpeg_er_init(s);
+ return !CONFIG_MPEGVIDEODEC || s->encoding ? 0 : ff_mpeg_er_init(s);
}
static void clear_context(MpegEncContext *s)
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 26f1c73505..f506ef64cc 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -19,9 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libavutil/thread.h"
#include "avfilter.h"
-#include "config.h"
extern const AVFilter ff_af_abench;
extern const AVFilter ff_af_acompressor;
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 35/36] avcodec/mpegvideo_enc: Improve inlining of chroma_format
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (32 preceding siblings ...)
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 34/36] configure: Add new mpegvideodec CONFIG_EXTRA Andreas Rheinhardt
@ 2021-12-24 3:23 ` Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time Andreas Rheinhardt
` (4 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-24 3:23 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
encode_mb() calls encode_mb_internal() three times, once
for each supported chroma format. The reason for this is
that some chroma format dependent parameters can then be
inlined as encode_mb_internal() is marked as av_always_inline.
Yet the most basic parameters based upon chroma format have
not been inlined: The chroma format itself and the chroma
subsampling parameters. This commit does so.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 0279816d3c..0ac8886246 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2030,7 +2030,10 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
int motion_x, int motion_y,
int mb_block_height,
int mb_block_width,
- int mb_block_count)
+ int mb_block_count,
+ int chroma_x_shift,
+ int chroma_y_shift,
+ int chroma_format)
{
int16_t weight[12][64];
int16_t orig[12][64];
@@ -2087,8 +2090,8 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
if((mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) && s->codec_id != AV_CODEC_ID_AMV){
uint8_t *ebuf = s->sc.edge_emu_buffer + 38 * wrap_y;
- int cw = (s->width + s->chroma_x_shift) >> s->chroma_x_shift;
- int ch = (s->height + s->chroma_y_shift) >> s->chroma_y_shift;
+ int cw = (s->width + chroma_x_shift) >> chroma_x_shift;
+ int ch = (s->height + chroma_y_shift) >> chroma_y_shift;
s->vdsp.emulated_edge_mc(ebuf, ptr_y,
wrap_y, wrap_y,
16, 16, mb_x * 16, mb_y * 16,
@@ -2128,8 +2131,8 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
dct_offset = wrap_y;
uv_dct_offset = wrap_c;
wrap_y <<= 1;
- if (s->chroma_format == CHROMA_422 ||
- s->chroma_format == CHROMA_444)
+ if (chroma_format == CHROMA_422 ||
+ chroma_format == CHROMA_444)
wrap_c <<= 1;
}
}
@@ -2146,10 +2149,10 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
} else {
s->pdsp.get_pixels(s->block[4], ptr_cb, wrap_c);
s->pdsp.get_pixels(s->block[5], ptr_cr, wrap_c);
- if (!s->chroma_y_shift && s->chroma_x_shift) { /* 422 */
+ if (chroma_format == CHROMA_422) {
s->pdsp.get_pixels(s->block[6], ptr_cb + uv_dct_offset, wrap_c);
s->pdsp.get_pixels(s->block[7], ptr_cr + uv_dct_offset, wrap_c);
- } else if (!s->chroma_y_shift && !s->chroma_x_shift) { /* 444 */
+ } else if (chroma_format == CHROMA_444) {
s->pdsp.get_pixels(s->block[ 6], ptr_cb + 8, wrap_c);
s->pdsp.get_pixels(s->block[ 7], ptr_cr + 8, wrap_c);
s->pdsp.get_pixels(s->block[ 8], ptr_cb + uv_dct_offset, wrap_c);
@@ -2213,7 +2216,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
dct_offset = wrap_y;
uv_dct_offset = wrap_c;
wrap_y <<= 1;
- if (s->chroma_format == CHROMA_422)
+ if (chroma_format == CHROMA_422)
wrap_c <<= 1;
}
}
@@ -2232,7 +2235,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
} else {
s->pdsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);
s->pdsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);
- if (!s->chroma_y_shift) { /* 422 */
+ if (!chroma_y_shift) { /* 422 */
s->pdsp.diff_pixels(s->block[6], ptr_cb + uv_dct_offset,
dest_cb + uv_dct_offset, wrap_c);
s->pdsp.diff_pixels(s->block[7], ptr_cr + uv_dct_offset,
@@ -2257,7 +2260,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
skip_dct[4] = 1;
if (s->mecc.sad[1](NULL, ptr_cr, dest_cr, wrap_c, 8) < 20 * s->qscale)
skip_dct[5] = 1;
- if (!s->chroma_y_shift) { /* 422 */
+ if (!chroma_y_shift) { /* 422 */
if (s->mecc.sad[1](NULL, ptr_cb + uv_dct_offset,
dest_cb + uv_dct_offset,
wrap_c, 8) < 20 * s->qscale)
@@ -2283,7 +2286,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
get_visual_weight(weight[4], ptr_cb , wrap_c);
if (!skip_dct[5])
get_visual_weight(weight[5], ptr_cr , wrap_c);
- if (!s->chroma_y_shift) { /* 422 */
+ if (!chroma_y_shift) { /* 422 */
if (!skip_dct[6])
get_visual_weight(weight[6], ptr_cb + uv_dct_offset,
wrap_c);
@@ -2341,7 +2344,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
s->block_last_index[5] = 0;
s->block[4][0] =
s->block[5][0] = (1024 + s->c_dc_scale / 2) / s->c_dc_scale;
- if (!s->chroma_y_shift) { /* 422 / 444 */
+ if (!chroma_y_shift) { /* 422 / 444 */
for (i=6; i<12; i++) {
s->block_last_index[i] = 0;
s->block[i][0] = s->block[4][0];
@@ -2413,9 +2416,12 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
{
- if (s->chroma_format == CHROMA_420) encode_mb_internal(s, motion_x, motion_y, 8, 8, 6);
- else if (s->chroma_format == CHROMA_422) encode_mb_internal(s, motion_x, motion_y, 16, 8, 8);
- else encode_mb_internal(s, motion_x, motion_y, 16, 16, 12);
+ if (s->chroma_format == CHROMA_420)
+ encode_mb_internal(s, motion_x, motion_y, 8, 8, 6, 1, 1, CHROMA_420);
+ else if (s->chroma_format == CHROMA_422)
+ encode_mb_internal(s, motion_x, motion_y, 16, 8, 8, 1, 0, CHROMA_422);
+ else
+ encode_mb_internal(s, motion_x, motion_y, 16, 16, 12, 0, 0, CHROMA_444);
}
static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (33 preceding siblings ...)
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 35/36] avcodec/mpegvideo_enc: Improve inlining of chroma_format Andreas Rheinhardt
@ 2021-12-24 3:23 ` Andreas Rheinhardt
2021-12-24 17:17 ` Michael Niedermayer
2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 37/39] avcodec/mpeg12enc: Also inline chroma subsampling Andreas Rheinhardt
` (3 subsequent siblings)
38 siblings, 1 reply; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-24 3:23 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
There are no encoders for interlaced dct that support 4:4:4.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_enc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 0ac8886246..15b6669e46 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2035,6 +2035,10 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
int chroma_y_shift,
int chroma_format)
{
+/* Interlaced DCT is only possible with MPEG-2 and MPEG-4
+ * and neither of these encoders currently supports 444. */
+#define INTERLACED_DCT(s) ((chroma_format == CHROMA_420 || chroma_format == CHROMA_422) && \
+ (s)->avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT)
int16_t weight[12][64];
int16_t orig[12][64];
const int mb_x = s->mb_x;
@@ -2112,7 +2116,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
}
if (s->mb_intra) {
- if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
+ if (INTERLACED_DCT(s)) {
int progressive_score, interlaced_score;
s->interlaced_dct = 0;
@@ -2191,7 +2195,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
op_pix, op_qpix);
}
- if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
+ if (INTERLACED_DCT(s)) {
int progressive_score, interlaced_score;
s->interlaced_dct = 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time Andreas Rheinhardt
@ 2021-12-24 17:17 ` Michael Niedermayer
2021-12-24 18:30 ` Andreas Rheinhardt
0 siblings, 1 reply; 45+ messages in thread
From: Michael Niedermayer @ 2021-12-24 17:17 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 867 bytes --]
On Fri, Dec 24, 2021 at 04:23:32AM +0100, Andreas Rheinhardt wrote:
> There are no encoders for interlaced dct that support 4:4:4.
i dont remember why its not supported but
why not add 4:4:4 interlaced dct support ?
just thinking as you already work on the code, that would seem to me
the "more interresting" route than to optimize that out
nothing againt this patch of course, thats fine too
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Modern terrorism, a quick summary: Need oil, start war with country that
has oil, kill hundread thousand in war. Let country fall into chaos,
be surprised about raise of fundamantalists. Drop more bombs, kill more
people, be surprised about them taking revenge and drop even more bombs
and strip your own citizens of their rights and freedoms. to be continued
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time
2021-12-24 17:17 ` Michael Niedermayer
@ 2021-12-24 18:30 ` Andreas Rheinhardt
2021-12-24 18:36 ` Michael Niedermayer
0 siblings, 1 reply; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-24 18:30 UTC (permalink / raw)
To: ffmpeg-devel
Michael Niedermayer:
> On Fri, Dec 24, 2021 at 04:23:32AM +0100, Andreas Rheinhardt wrote:
>> There are no encoders for interlaced dct that support 4:4:4.
>
> i dont remember why its not supported but
> why not add 4:4:4 interlaced dct support ?
>
> just thinking as you already work on the code, that would seem to me
> the "more interresting" route than to optimize that out
>
> nothing againt this patch of course, thats fine too
>
> thx
> [...]
>
There are two encoders that support interlaced DCT: mpeg2video and
mpeg4. Our encoder for the former supports 420 and 422; the format also
allows 444. I don't really know how much is missing for supporting this
(it's probably more than just hardcoding a third chroma format in
ff_mpeg1_encode_mb()). And honestly, I don't really want to reread the
mpeg-2 spec to find out, because it is nearly 2022 and MPEG-2 is
obsolete and legacy.
- 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time
2021-12-24 18:30 ` Andreas Rheinhardt
@ 2021-12-24 18:36 ` Michael Niedermayer
0 siblings, 0 replies; 45+ messages in thread
From: Michael Niedermayer @ 2021-12-24 18:36 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1391 bytes --]
On Fri, Dec 24, 2021 at 07:30:11PM +0100, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Fri, Dec 24, 2021 at 04:23:32AM +0100, Andreas Rheinhardt wrote:
> >> There are no encoders for interlaced dct that support 4:4:4.
> >
> > i dont remember why its not supported but
> > why not add 4:4:4 interlaced dct support ?
> >
> > just thinking as you already work on the code, that would seem to me
> > the "more interresting" route than to optimize that out
> >
> > nothing againt this patch of course, thats fine too
> >
> > thx
> > [...]
> >
>
> There are two encoders that support interlaced DCT: mpeg2video and
> mpeg4. Our encoder for the former supports 420 and 422; the format also
> allows 444. I don't really know how much is missing for supporting this
> (it's probably more than just hardcoding a third chroma format in
> ff_mpeg1_encode_mb()). And honestly, I don't really want to reread the
> mpeg-2 spec to find out, because it is nearly 2022 and MPEG-2 is
> obsolete and legacy.
our decoder should support 444 i dont remember anything special
but i agree, it makes little sense for a old format unless one
enjoys doing it
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 37/39] avcodec/mpeg12enc: Also inline chroma subsampling
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (34 preceding siblings ...)
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time Andreas Rheinhardt
@ 2021-12-25 6:06 ` Andreas Rheinhardt
2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 38/39] avcodec/mpeg12enc: Partially inline whether codec is MPEG-1 Andreas Rheinhardt
` (2 subsequent siblings)
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-25 6:06 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
ff_mpeg1_encode_mb() contains two inlined calls to
mpeg1_encode_mb_internal(); these calls are supposed
to inline the properties depending upon the color space
used. Yet inlining vertical chroma subsampling (which
allows to remove complete branches and blocks depending
upon them) has been forgotten.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
Looking at this code makes me wonder whether inlining was ever
worth it here.
libavcodec/mpeg12enc.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 3692494713..1437ac421c 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -773,7 +773,8 @@ next_coef:
static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
int16_t block[8][64],
int motion_x, int motion_y,
- int mb_block_count)
+ int mb_block_count,
+ int chroma_y_shift)
{
int i, cbp;
const int mb_x = s->mb_x;
@@ -918,7 +919,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
s->mv_bits += get_bits_diff(s);
}
if (cbp) {
- if (s->chroma_y_shift) {
+ if (chroma_y_shift) {
put_bits(&s->pb,
ff_mpeg12_mbPatTable[cbp][1],
ff_mpeg12_mbPatTable[cbp][0]);
@@ -1025,7 +1026,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
}
s->mv_bits += get_bits_diff(s);
if (cbp) {
- if (s->chroma_y_shift) {
+ if (chroma_y_shift) {
put_bits(&s->pb,
ff_mpeg12_mbPatTable[cbp][1],
ff_mpeg12_mbPatTable[cbp][0]);
@@ -1052,9 +1053,9 @@ void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64],
int motion_x, int motion_y)
{
if (s->chroma_format == CHROMA_420)
- mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6);
+ mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6, 1);
else
- mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8);
+ mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8, 0);
}
static av_cold void mpeg12_encode_init_static(void)
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 38/39] avcodec/mpeg12enc: Partially inline whether codec is MPEG-1
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (35 preceding siblings ...)
2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 37/39] avcodec/mpeg12enc: Also inline chroma subsampling Andreas Rheinhardt
@ 2021-12-25 6:06 ` Andreas Rheinhardt
2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 39/39] avcodec/mpeg12enc: Inline constants Andreas Rheinhardt
2021-12-31 10:03 ` [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-25 6:06 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
MPEG-1 only supports 4:2:0, so one can optimize away the checks
for whether one encodes MPEG-1 in codepaths that encode 4:2:2.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12enc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 1437ac421c..97d497d619 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -776,6 +776,8 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
int mb_block_count,
int chroma_y_shift)
{
+/* MPEG-1 is always 420. */
+#define IS_MPEG1(s) (chroma_y_shift == 1 && (s)->codec_id == AV_CODEC_ID_MPEG1VIDEO)
int i, cbp;
const int mb_x = s->mb_x;
const int mb_y = s->mb_y;
@@ -789,7 +791,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 &&
(mb_x != s->mb_width - 1 ||
- (mb_y != s->end_mb_y - 1 && s->codec_id == AV_CODEC_ID_MPEG1VIDEO)) &&
+ (mb_y != s->end_mb_y - 1 && IS_MPEG1(s))) &&
((s->pict_type == AV_PICTURE_TYPE_P && (motion_x | motion_y) == 0) ||
(s->pict_type == AV_PICTURE_TYPE_B && s->mv_dir == s->last_mv_dir &&
(((s->mv_dir & MV_DIR_FORWARD)
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 39/39] avcodec/mpeg12enc: Inline constants
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (36 preceding siblings ...)
2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 38/39] avcodec/mpeg12enc: Partially inline whether codec is MPEG-1 Andreas Rheinhardt
@ 2021-12-25 6:06 ` Andreas Rheinhardt
2021-12-31 10:03 ` [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-25 6:06 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
For a long time, ff_mpeg1_init_uni_ac_vlc() has only been used
to create MPEG-1/2 tables and therefore some values (namely
the number of elements) have been inlined; yet nowadays this function
is also used for speedhq whose number of elements differs.
So it seems to me that one should uninline this value
in ff_mpeg1_init_uni_ac_vlc.
libavcodec/mpeg12enc.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 97d497d619..e28aa809d2 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -621,10 +621,8 @@ static inline void put_mb_modes(MpegEncContext *s, int n, int bits,
static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
{
if (val == 0) {
- /* zero vector */
- put_bits(&s->pb,
- ff_mpeg12_mbMotionVectorTable[0][1],
- ff_mpeg12_mbMotionVectorTable[0][0]);
+ /* zero vector, corresponds to ff_mpeg12_mbMotionVectorTable[0] */
+ put_bits(&s->pb, 1, 0x01);
} else {
int code, sign, bits;
int bit_size = f_or_b_code - 1;
@@ -746,8 +744,10 @@ next_coef:
put_bits(&s->pb, table_vlc[code][1] + 1,
(table_vlc[code][0] << 1) + sign);
} else {
- /* escape seems to be pretty rare <5% so I do not optimize it */
- put_bits(&s->pb, table_vlc[111][1], table_vlc[111][0]);
+ /* Escape seems to be pretty rare <5% so I do not optimize it;
+ * the following value is the common escape value for both
+ * possible tables (i.e. table_vlc[111]). */
+ put_bits(&s->pb, 6, 0x01);
/* escape: only clip in this case */
put_bits(&s->pb, 6, run);
if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
@@ -1097,7 +1097,7 @@ static av_cold void mpeg12_encode_init_static(void)
int len;
if (mv == 0) {
- len = ff_mpeg12_mbMotionVectorTable[0][1];
+ len = 1; /* ff_mpeg12_mbMotionVectorTable[0][1] */
} else {
int val, bit_size, code;
@@ -1112,7 +1112,7 @@ static av_cold void mpeg12_encode_init_static(void)
len = ff_mpeg12_mbMotionVectorTable[code][1] +
1 + bit_size;
else
- len = ff_mpeg12_mbMotionVectorTable[16][1] +
+ len = 10 /* ff_mpeg12_mbMotionVectorTable[16][1] */ +
2 + bit_size;
}
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH v2 34/35] configure: Add new mpegvideodec CONFIG_EXTRA
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 34/36] configure: Add new mpegvideodec CONFIG_EXTRA Andreas Rheinhardt
@ 2021-12-25 6:09 ` Andreas Rheinhardt
2021-12-25 6:09 ` [FFmpeg-devel] [PATCH v2 35/35] configure: Remove mpegvideo dependency on me_cmp Andreas Rheinhardt
1 sibling, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-25 6:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This allows to remove the spurious dependencies of mpegvideo encoders
on error_resilience; some other components that do not use mpegvideo
to its fullest turned out to not need it either.
Adding a new CONFIG_EXTRA needs a reconfigure to take effect.
In order to force this a few unnecessary headers from lavfi/allfilters.c
have been removed.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
Moved mpegutils.c to mpegvideodec.
configure | 26 ++++++++++++++------------
libavcodec/Makefile | 5 +++--
libavcodec/h264dec.c | 2 +-
libavcodec/mpegvideo.c | 2 +-
libavfilter/allfilters.c | 2 --
5 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/configure b/configure
index 23ef2abc9b..f3bdfd2920 100755
--- a/configure
+++ b/configure
@@ -2476,6 +2476,7 @@ CONFIG_EXTRA="
mpegaudiodsp
mpegaudioheader
mpegvideo
+ mpegvideodec
mpegvideoenc
mss34dsp
pixblockdsp
@@ -2723,7 +2724,8 @@ me_cmp_select="fdctdsp idctdsp pixblockdsp"
mpeg_er_select="error_resilience"
mpegaudio_select="mpegaudiodsp mpegaudioheader"
mpegaudiodsp_select="dct"
-mpegvideo_select="blockdsp h264chroma hpeldsp idctdsp me_cmp mpeg_er videodsp"
+mpegvideo_select="blockdsp h264chroma hpeldsp idctdsp me_cmp videodsp"
+mpegvideodec_select="mpegvideo mpeg_er"
mpegvideoenc_select="aandcttables me_cmp mpegvideo pixblockdsp qpeldsp"
vc1dsp_select="h264chroma qpeldsp startcode"
rdft_select="fft"
@@ -2812,9 +2814,9 @@ fraps_decoder_select="bswapdsp huffman"
g2m_decoder_deps="zlib"
g2m_decoder_select="blockdsp idctdsp jpegtables"
g729_decoder_select="audiodsp"
-h261_decoder_select="mpegvideo"
+h261_decoder_select="mpegvideodec"
h261_encoder_select="mpegvideoenc"
-h263_decoder_select="h263_parser h263dsp mpegvideo qpeldsp"
+h263_decoder_select="h263_parser h263dsp mpegvideodec qpeldsp"
h263_encoder_select="h263dsp mpegvideoenc"
h263i_decoder_select="h263_decoder"
h263p_decoder_select="h263_decoder"
@@ -2836,7 +2838,7 @@ indeo3_decoder_select="hpeldsp"
indeo4_decoder_select="ividsp"
indeo5_decoder_select="ividsp"
interplay_video_decoder_select="hpeldsp"
-ipu_decoder_select="mpegvideo"
+ipu_decoder_select="mpegvideodec"
jpegls_decoder_select="mjpeg_decoder"
jv_decoder_select="blockdsp"
lagarith_decoder_select="llviddsp"
@@ -2866,10 +2868,10 @@ mp3on4_decoder_select="mpegaudio"
mp3on4float_decoder_select="mpegaudio"
mpc7_decoder_select="bswapdsp mpegaudiodsp"
mpc8_decoder_select="mpegaudiodsp"
-mpegvideo_decoder_select="mpegvideo"
-mpeg1video_decoder_select="mpegvideo"
+mpegvideo_decoder_select="mpegvideodec"
+mpeg1video_decoder_select="mpegvideodec"
mpeg1video_encoder_select="mpegvideoenc h263dsp"
-mpeg2video_decoder_select="mpegvideo"
+mpeg2video_decoder_select="mpegvideodec"
mpeg2video_encoder_select="mpegvideoenc h263dsp"
mpeg4_decoder_select="h263_decoder mpeg4video_parser"
mpeg4_encoder_select="h263_encoder"
@@ -2880,7 +2882,7 @@ msmpeg4v2_decoder_select="h263_decoder"
msmpeg4v2_encoder_select="h263_encoder"
msmpeg4v3_decoder_select="h263_decoder"
msmpeg4v3_encoder_select="h263_encoder"
-mss2_decoder_select="mpegvideo qpeldsp vc1_decoder"
+mss2_decoder_select="mpegvideodec qpeldsp vc1_decoder"
mts2_decoder_select="jpegtables mss34dsp"
mv30_decoder_select="aandcttables blockdsp"
mvha_decoder_deps="zlib"
@@ -2913,8 +2915,8 @@ rv10_decoder_select="h263_decoder"
rv10_encoder_select="h263_encoder"
rv20_decoder_select="h263_decoder"
rv20_encoder_select="h263_encoder"
-rv30_decoder_select="golomb h264pred h264qpel mpegvideo rv34dsp"
-rv40_decoder_select="golomb h264pred h264qpel mpegvideo rv34dsp"
+rv30_decoder_select="golomb h264pred h264qpel mpegvideodec rv34dsp"
+rv40_decoder_select="golomb h264pred h264qpel mpegvideodec rv34dsp"
screenpresso_decoder_deps="zlib"
shorten_decoder_select="bswapdsp"
sipr_decoder_select="lsp"
@@ -2950,7 +2952,7 @@ txd_decoder_select="texturedsp"
utvideo_decoder_select="bswapdsp llviddsp"
utvideo_encoder_select="bswapdsp huffman llvidencdsp"
vble_decoder_select="llviddsp"
-vc1_decoder_select="blockdsp h263_decoder h264qpel intrax8 mpegvideo vc1dsp"
+vc1_decoder_select="blockdsp h263_decoder h264qpel intrax8 mpegvideodec vc1dsp"
vc1image_decoder_select="vc1_decoder"
vorbis_decoder_select="mdct"
vorbis_encoder_select="audio_frame_queue mdct"
@@ -3246,7 +3248,7 @@ h264_parser_select="atsc_a53 golomb h264dsp h264parse"
hevc_parser_select="hevcparse"
mpegaudio_parser_select="mpegaudioheader"
mpegvideo_parser_select="mpegvideo"
-mpeg4video_parser_select="h263dsp mpegvideo qpeldsp"
+mpeg4video_parser_select="h263dsp mpegvideodec qpeldsp"
vc1_parser_select="vc1dsp"
# bitstream_filters
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index e7f1f110e7..4b0911e9c8 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -123,9 +123,10 @@ OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \
mpegaudiodsp_fixed.o \
mpegaudiodsp_float.o
OBJS-$(CONFIG_MPEGAUDIOHEADER) += mpegaudiodecheader.o mpegaudiodata.o
-OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideo_dec.o mpegvideodsp.o rl.o \
- mpegvideo_motion.o mpegutils.o \
+OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideodsp.o rl.o \
+ mpegvideo_motion.o \
mpegvideodata.o mpegpicture.o
+OBJS-$(CONFIG_MPEGVIDEODEC) += mpegvideo_dec.o mpegutils.o
OBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideo_enc.o mpeg12data.o \
motion_est.o ratecontrol.o \
mpegvideoencdsp.o
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 6a5bf51f5d..7f10026340 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -939,7 +939,7 @@ static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *g
*got_frame = 1;
- if (CONFIG_MPEGVIDEO) {
+ if (CONFIG_MPEGVIDEODEC) {
ff_print_debug_info2(h->avctx, dst, NULL,
out->mb_type,
out->qscale_table,
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index a2c4e14b6e..1c2b28f450 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -658,7 +658,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s)
return AVERROR(ENOMEM);
memset(s->mbintra_table, 1, mb_array_size);
- return s->encoding ? 0 : ff_mpeg_er_init(s);
+ return !CONFIG_MPEGVIDEODEC || s->encoding ? 0 : ff_mpeg_er_init(s);
}
static void clear_context(MpegEncContext *s)
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 26f1c73505..f506ef64cc 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -19,9 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libavutil/thread.h"
#include "avfilter.h"
-#include "config.h"
extern const AVFilter ff_af_abench;
extern const AVFilter ff_af_acompressor;
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH v2 35/35] configure: Remove mpegvideo dependency on me_cmp
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 34/36] configure: Add new mpegvideodec CONFIG_EXTRA Andreas Rheinhardt
2021-12-25 6:09 ` [FFmpeg-devel] [PATCH v2 34/35] " Andreas Rheinhardt
@ 2021-12-25 6:09 ` Andreas Rheinhardt
1 sibling, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-25 6:09 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Forgotten in cf1e0786ed64e69614760bfb4ecd7adbde8e6094.
(Both mpegvideodec as well as mpegvideoenc use me_cmp,
so this doesn't affect them.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
configure | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure b/configure
index f3bdfd2920..c89f0ae5fb 100755
--- a/configure
+++ b/configure
@@ -2724,7 +2724,7 @@ me_cmp_select="fdctdsp idctdsp pixblockdsp"
mpeg_er_select="error_resilience"
mpegaudio_select="mpegaudiodsp mpegaudioheader"
mpegaudiodsp_select="dct"
-mpegvideo_select="blockdsp h264chroma hpeldsp idctdsp me_cmp videodsp"
+mpegvideo_select="blockdsp h264chroma hpeldsp idctdsp videodsp"
mpegvideodec_select="mpegvideo mpeg_er"
mpegvideoenc_select="aandcttables me_cmp mpegvideo pixblockdsp qpeldsp"
vc1dsp_select="h264chroma qpeldsp startcode"
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
` (37 preceding siblings ...)
2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 39/39] avcodec/mpeg12enc: Inline constants Andreas Rheinhardt
@ 2021-12-31 10:03 ` Andreas Rheinhardt
38 siblings, 0 replies; 45+ messages in thread
From: Andreas Rheinhardt @ 2021-12-31 10:03 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> Currently, ff_mpv_encode_end() is the close function of
> the two MJPEG-based encoders; it calls ff_mjpeg_encode_close()
> for them which adds a check to the generic code.
> This commit reverses the order of this relationship:
> The MJPEG encoders directly use a custom close function
> which in turn calls ff_mpv_encode_end(). This avoids the branch
> in ff_mpv_encode_end() and makes the generic code more generic.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/mjpegenc.c | 9 ++++++---
> libavcodec/mjpegenc.h | 1 -
> libavcodec/mpegvideo_enc.c | 3 ---
> 3 files changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
> index 0ade66bc5f..5bd25b4f3b 100644
> --- a/libavcodec/mjpegenc.c
> +++ b/libavcodec/mjpegenc.c
> @@ -320,12 +320,15 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
> return 0;
> }
>
> -av_cold void ff_mjpeg_encode_close(MpegEncContext *s)
> +static av_cold int mjpeg_encode_close(AVCodecContext *avctx)
> {
> + MpegEncContext *const s = avctx->priv_data;
> if (s->mjpeg_ctx) {
> av_freep(&s->mjpeg_ctx->huff_buffer);
> av_freep(&s->mjpeg_ctx);
> }
> + ff_mpv_encode_end(avctx);
> + return 0;
> }
>
> /**
> @@ -618,7 +621,7 @@ const AVCodec ff_mjpeg_encoder = {
> .priv_data_size = sizeof(MpegEncContext),
> .init = ff_mpv_encode_init,
> .encode2 = ff_mpv_encode_picture,
> - .close = ff_mpv_encode_end,
> + .close = mjpeg_encode_close,
> .capabilities = AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
> .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
> .pix_fmts = (const enum AVPixelFormat[]) {
> @@ -647,7 +650,7 @@ const AVCodec ff_amv_encoder = {
> .priv_data_size = sizeof(MpegEncContext),
> .init = ff_mpv_encode_init,
> .encode2 = amv_encode_picture,
> - .close = ff_mpv_encode_end,
> + .close = mjpeg_encode_close,
> .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
> .pix_fmts = (const enum AVPixelFormat[]) {
> AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_NONE
> diff --git a/libavcodec/mjpegenc.h b/libavcodec/mjpegenc.h
> index 2e92511276..bc9b017e7a 100644
> --- a/libavcodec/mjpegenc.h
> +++ b/libavcodec/mjpegenc.h
> @@ -105,7 +105,6 @@ static inline void put_marker(PutBitContext *p, enum JpegMarker code)
> }
>
> int ff_mjpeg_encode_init(MpegEncContext *s);
> -void ff_mjpeg_encode_close(MpegEncContext *s);
> void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]);
> int ff_mjpeg_encode_stuffing(MpegEncContext *s);
>
> diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
> index 128d1a327c..d2520368e1 100644
> --- a/libavcodec/mpegvideo_enc.c
> +++ b/libavcodec/mpegvideo_enc.c
> @@ -970,9 +970,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
> ff_rate_control_uninit(s);
>
> ff_mpv_common_end(s);
> - if ((CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER) &&
> - s->out_format == FMT_MJPEG)
> - ff_mjpeg_encode_close(s);
>
> for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++)
> av_frame_free(&s->tmp_frames[i]);
>
Will apply this patchset tonight unless there are objections.
- 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
end of thread, other threads:[~2021-12-31 10:03 UTC | newest]
Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-22 3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 02/14] avcodec/mjpegenc: Avoid allocation of MJpegContext Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 03/14] avcodec/mpegvideo_enc: Move MJPEG init checks to mjpegenc.c Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 04/14] avcodec/mpegvideo_enc: Remove redundant checks for multithreading Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 05/14] avcodec/mjpegenc: Add wrapper for ff_mjpeg_encode_picture_header() Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 06/14] avcodec/mjpegenc_common: Move code for MJPEG/AMV to mjpegenc Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 07/14] avcodec/mjpegenc_common: Fix intendation Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 08/14] avcodec/mpegvideo: Move MJPEG/AMV-only fields to MJpegContext Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 09/14] avcodec/mjpegenc: Deprecate unused prediction type Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 10/14] avcodec/mjpegenc_common: Pass MJpegContext for writing picture header Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 11/14] avcodec/mjpegenc_common: Don't call function unnecessarily Andreas Rheinhardt
2021-12-22 3:25 ` [FFmpeg-devel] [PATCH 12/14] avcodec/mjpegenc_common: Use AVCodecContext.codec_id directly Andreas Rheinhardt
2021-12-22 3:30 ` [FFmpeg-devel] [PATCH 13/14] avcodec/mpegvideo: Remove unnecessary headers Andreas Rheinhardt
2021-12-22 3:30 ` [FFmpeg-devel] [PATCH 14/14] avcodec/mpegvideo_enc: Remove impossible branch Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 15/30] avcodec/speedhqenc: Inline constants Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 16/30] avcodec/mpegvideo_enc: Move updating mb_info to its only user Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 17/30] avcodec/mpeg12enc: Simplify check for A53 closed captions Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 18/30] avcodec/mpeg12enc: Add custom context, move mpeg2_frame_rate_ext to it Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 19/30] avcodec/mpeg12enc: Move options-related fields to MPEG12EncContext Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 20/30] avcodec/mpegvideo_enc: Don't merge decoder-only fields Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 21/30] avcodec/mpeg12dec: Use %c to write single char Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 22/30] avcodec/mpegvideo: Don't duplicate identical code Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 23/30] avcodec/mpegvideo: Avoid needlessly calling function Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 24/30] avcodec/wmv2: Move ff_wmv2_add_mb() to the wmv2dec Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 25/30] avcodec/mpegvideo_motion: Don't duplicate identical code Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 26/30] avcodec/mpegvideo: Don't check for > 8 bit MPEG-1/2 Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 27/30] avcodec/mpegvideo: Partially check for being encoder at compile-time Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 28/30] avcodec/mpegvideo: Try to perform check for MPEG-1/2 " Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 29/30] avcodec/mpegvideo: Remove always-true branch Andreas Rheinhardt
2021-12-23 9:13 ` [FFmpeg-devel] [PATCH 30/30] avcodec/mpegvideo: Check for no_rounding at compile-time if possible Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 31/36] avcodec/mpegvideo: Don't initialize error resilience context for encoder Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 32/36] avcodec/mpegvideo: Remove always-false check Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 33/36] avcodec/mpegvideo: Move decoding-only code into a new file Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 34/36] configure: Add new mpegvideodec CONFIG_EXTRA Andreas Rheinhardt
2021-12-25 6:09 ` [FFmpeg-devel] [PATCH v2 34/35] " Andreas Rheinhardt
2021-12-25 6:09 ` [FFmpeg-devel] [PATCH v2 35/35] configure: Remove mpegvideo dependency on me_cmp Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 35/36] avcodec/mpegvideo_enc: Improve inlining of chroma_format Andreas Rheinhardt
2021-12-24 3:23 ` [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time Andreas Rheinhardt
2021-12-24 17:17 ` Michael Niedermayer
2021-12-24 18:30 ` Andreas Rheinhardt
2021-12-24 18:36 ` Michael Niedermayer
2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 37/39] avcodec/mpeg12enc: Also inline chroma subsampling Andreas Rheinhardt
2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 38/39] avcodec/mpeg12enc: Partially inline whether codec is MPEG-1 Andreas Rheinhardt
2021-12-25 6:06 ` [FFmpeg-devel] [PATCH 39/39] avcodec/mpeg12enc: Inline constants Andreas Rheinhardt
2021-12-31 10:03 ` [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git