[FFmpeg-devel] [PATCH 2/4] lavc/xvmc.h: mark the header as deprecated
--- libavcodec/xvmc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/xvmc.h b/libavcodec/xvmc.h index 465ee78d6e..78ec4530c2 100644 --- a/libavcodec/xvmc.h +++ b/libavcodec/xvmc.h @@ -27,6 +27,8 @@ * Public libavcodec XvMC header. */ +#pragma message("XvMC is no longer supported; this header is deprecated and will be removed") + #include #include "libavutil/attributes.h" -- 2.34.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 4/4] lavc: deprecate FF_IDCT_NONE
It was only used by XvMC. --- libavcodec/avcodec.h | 5 - libavcodec/idctdsp.c | 1 - libavcodec/version.h | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index acb7ae0e14..5362446092 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1407,7 +1407,10 @@ typedef struct AVCodecContext { #define FF_IDCT_SIMPLEARMV6 17 #define FF_IDCT_FAAN 20 #define FF_IDCT_SIMPLENEON22 -#define FF_IDCT_NONE 24 /* Used by XvMC to extract IDCT coefficients with FF_IDCT_PERM_NONE */ +#if FF_API_IDCT_NONE +// formerly used by xvmc +#define FF_IDCT_NONE 24 +#endif #define FF_IDCT_SIMPLEAUTO128 /** diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c index 71bd03c606..79e7f87443 100644 --- a/libavcodec/idctdsp.c +++ b/libavcodec/idctdsp.c @@ -287,7 +287,6 @@ av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx) c->perm_type = FF_IDCT_PERM_NONE; #endif /* CONFIG_FAANIDCT */ } else { // accurate/default -/* Be sure FF_IDCT_NONE will select this one, since it uses FF_IDCT_PERM_NONE */ c->idct_put = ff_simple_idct_put_int16_8bit; c->idct_add = ff_simple_idct_add_int16_8bit; c->idct = ff_simple_idct_int16_8bit; diff --git a/libavcodec/version.h b/libavcodec/version.h index a46fb05f1a..b2c57360cf 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -64,5 +64,6 @@ #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) +#define FF_API_IDCT_NONE (LIBAVCODEC_VERSION_MAJOR < 60) #endif /* AVCODEC_VERSION_H */ -- 2.34.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 3/4] lavu/pixfmt: deprecate AV_PIX_FMT_XVMC
It is no longer used for anything. --- libavutil/pixdesc.c | 2 ++ libavutil/pixfmt.h | 2 ++ libavutil/version.h | 1 + 3 files changed, 5 insertions(+) diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index 727d7540b3..6e57a82cb6 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -432,10 +432,12 @@ static const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = { }, .flags = AV_PIX_FMT_FLAG_PLANAR, }, +#if FF_API_XVMC [AV_PIX_FMT_XVMC] = { .name = "xvmc", .flags = AV_PIX_FMT_FLAG_HWACCEL, }, +#endif [AV_PIX_FMT_UYVY422] = { .name = "uyvy422", .nb_components = 3, diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h index 66913f606b..2d3927cc3f 100644 --- a/libavutil/pixfmt.h +++ b/libavutil/pixfmt.h @@ -260,7 +260,9 @@ enum AVPixelFormat { AV_PIX_FMT_BAYER_GRBG16LE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian AV_PIX_FMT_BAYER_GRBG16BE, ///< bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, big-endian +#if FF_API_XVMC AV_PIX_FMT_XVMC,///< XVideo Motion Acceleration via common packet passing +#endif AV_PIX_FMT_YUV440P10LE, ///< planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), little-endian AV_PIX_FMT_YUV440P10BE, ///< planar YUV 4:4:0,20bpp, (1 Cr & Cb sample per 1x2 Y samples), big-endian diff --git a/libavutil/version.h b/libavutil/version.h index 331b8f6ea9..6f6e873a92 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -110,6 +110,7 @@ #define FF_API_COLORSPACE_NAME (LIBAVUTIL_VERSION_MAJOR < 58) #define FF_API_AV_MALLOCZ_ARRAY (LIBAVUTIL_VERSION_MAJOR < 58) #define FF_API_FIFO_PEEK2 (LIBAVUTIL_VERSION_MAJOR < 58) +#define FF_API_XVMC (LIBAVUTIL_VERSION_MAJOR < 58) /** * @} -- 2.34.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/4] lavc/mpeg*: drop the XvMC hwaccel code
XvMC was last relevant over 10 years ago, if ever. There is no reason to use it today. --- MAINTAINERS| 1 - configure | 9 - libavcodec/Makefile| 2 - libavcodec/avcodec.h | 12 -- libavcodec/error_resilience.c | 9 - libavcodec/hwaccels.h | 2 - libavcodec/hwconfig.h | 2 - libavcodec/mpeg12dec.c | 43 libavcodec/mpegvideo.c | 6 - libavcodec/mpegvideo.h | 2 - libavcodec/mpegvideo_xvmc.c| 376 - libavcodec/x86/blockdsp_init.c | 4 - libavcodec/xvmc_internal.h | 31 --- 13 files changed, 499 deletions(-) delete mode 100644 libavcodec/mpegvideo_xvmc.c delete mode 100644 libavcodec/xvmc_internal.h diff --git a/MAINTAINERS b/MAINTAINERS index c065e94498..f33ccbd1d9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -266,7 +266,6 @@ Codecs: xan.c Mike Melanson xbm* Paul B Mahol xface Stefano Sabatini - xvmc.cIvan Kalvachev xwd* Paul B Mahol Hardware acceleration: diff --git a/configure b/configure index 5b19a35f59..6dbe108284 100755 --- a/configure +++ b/configure @@ -1900,7 +1900,6 @@ HWACCEL_AUTODETECT_LIBRARY_LIST=" videotoolbox vulkan v4l2_m2m -xvmc " # catchall list of things that require external libs to link @@ -3006,7 +3005,6 @@ vaapi_x11_deps="xlib_x11" videotoolbox_hwaccel_deps="videotoolbox pthreads" videotoolbox_hwaccel_extralibs="-framework QuartzCore" vulkan_deps_any="libdl LoadLibrary" -xvmc_deps="X11_extensions_XvMClib_h" av1_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_AV1" av1_d3d11va_hwaccel_select="av1_decoder" @@ -3054,16 +3052,12 @@ mjpeg_nvdec_hwaccel_deps="nvdec" mjpeg_nvdec_hwaccel_select="mjpeg_decoder" mjpeg_vaapi_hwaccel_deps="vaapi" mjpeg_vaapi_hwaccel_select="mjpeg_decoder" -mpeg_xvmc_hwaccel_deps="xvmc" -mpeg_xvmc_hwaccel_select="mpeg2video_decoder" mpeg1_nvdec_hwaccel_deps="nvdec" mpeg1_nvdec_hwaccel_select="mpeg1video_decoder" mpeg1_vdpau_hwaccel_deps="vdpau" mpeg1_vdpau_hwaccel_select="mpeg1video_decoder" mpeg1_videotoolbox_hwaccel_deps="videotoolbox" mpeg1_videotoolbox_hwaccel_select="mpeg1video_decoder" -mpeg1_xvmc_hwaccel_deps="xvmc" -mpeg1_xvmc_hwaccel_select="mpeg1video_decoder" mpeg2_d3d11va_hwaccel_deps="d3d11va" mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder" mpeg2_d3d11va2_hwaccel_deps="d3d11va" @@ -3078,8 +3072,6 @@ mpeg2_vdpau_hwaccel_deps="vdpau" mpeg2_vdpau_hwaccel_select="mpeg2video_decoder" mpeg2_videotoolbox_hwaccel_deps="videotoolbox" mpeg2_videotoolbox_hwaccel_select="mpeg2video_decoder" -mpeg2_xvmc_hwaccel_deps="xvmc" -mpeg2_xvmc_hwaccel_select="mpeg2video_decoder" mpeg4_nvdec_hwaccel_deps="nvdec" mpeg4_nvdec_hwaccel_select="mpeg4_decoder" mpeg4_vaapi_hwaccel_deps="vaapi" @@ -6320,7 +6312,6 @@ check_headers unistd.h check_headers valgrind/valgrind.h check_func_headers VideoToolbox/VTCompressionSession.h VTCompressionSessionPrepareToEncodeFrames -framework VideoToolbox check_headers windows.h -check_headers X11/extensions/XvMClib.h check_headers asm/types.h # it seems there are versions of clang in some distros that try to use the diff --git a/libavcodec/Makefile b/libavcodec/Makefile index cfc70a3eaf..6076b4ad80 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -963,7 +963,6 @@ OBJS-$(CONFIG_MJPEG_VAAPI_HWACCEL)+= vaapi_mjpeg.o OBJS-$(CONFIG_MPEG1_NVDEC_HWACCEL)+= nvdec_mpeg12.o OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL)+= vdpau_mpeg12.o OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o -OBJS-$(CONFIG_MPEG1_XVMC_HWACCEL) += mpegvideo_xvmc.o OBJS-$(CONFIG_MPEG2_D3D11VA_HWACCEL) += dxva2_mpeg2.o OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL)+= dxva2_mpeg2.o OBJS-$(CONFIG_MPEG2_NVDEC_HWACCEL)+= nvdec_mpeg12.o @@ -971,7 +970,6 @@ OBJS-$(CONFIG_MPEG2_QSV_HWACCEL) += qsvdec.o OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL)+= vaapi_mpeg2.o OBJS-$(CONFIG_MPEG2_VDPAU_HWACCEL)+= vdpau_mpeg12.o OBJS-$(CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o -OBJS-$(CONFIG_MPEG2_XVMC_HWACCEL) += mpegvideo_xvmc.o OBJS-$(CONFIG_MPEG4_NVDEC_HWACCEL)+= nvdec_mpeg4.o OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL)+= vaapi_mpeg4.o OBJS-$(CONFIG_MPEG4_VDPAU_HWACCEL)+= vdpau_mpeg4.o diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index ec1a0566a4..acb7ae0e14 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2119,7 +2119,6 @@ typedef struct AVHWAccel { * * Meaningful slice information (codec specific) is guaranteed to * be parsed at this point. This function is mandatory. - * The only exception is XvMC, that works on MB level. * * @param avctx the codec context * @param buf the slice data buffer base @@ -2148,17 +2147,6 @@
Re: [FFmpeg-devel] [PATCH 0/5] Add IPFS and IPNS protocol support
On Mon, Jan 31, 2022 at 09:22:52PM +0100, Tomas Härdin wrote: [...] > It strikes me that this borders on incorporating business logic within > lavf. A user could achieve the same thing with a small shell script. > For example adding an alias that inspects calls to ffmpeg and sed:s > ipfs:// URLs accordingly That sounds like a security nightmare the ffmpeg command line is complex, there are filters, strings for thinsg like drawtext, there is metadata possibly and links can occur at different places some of this may be controlled by a user (= attacker) seperating the actual links out to modify them and just them is no easy feat thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB There will always be a question for which you do not know the correct answer. signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2 31/31] avutil/fifo: Deprecate old FIFO API
Quoting Andreas Rheinhardt (2022-01-24 15:46:16) > @@ -323,7 +350,11 @@ int av_fifo_generic_read(AVFifoBuffer *f, void *dest, > int buf_size, void (*func) > * indicate no more data available to write. > * If func is NULL, src is interpreted as a simple byte array for source > data. > * @return the number of bytes written to the FIFO or a negative error code > on failure > + * > + * @deprecated use the new AVFifo-API with av_fifo_write() when func == NULL, > + * av_fifo_write_to_cb() otherwise _from_cb -- Anton Khirnov ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 4/4] lavc: deprecate FF_IDCT_NONE
1 Feb 2022, 11:02 by an...@khirnov.net: > It was only used by XvMC. > --- > libavcodec/avcodec.h | 5 - > libavcodec/idctdsp.c | 1 - > libavcodec/version.h | 1 + > 3 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h > index acb7ae0e14..5362446092 100644 > --- a/libavcodec/avcodec.h > +++ b/libavcodec/avcodec.h > @@ -1407,7 +1407,10 @@ typedef struct AVCodecContext { > #define FF_IDCT_SIMPLEARMV6 17 > #define FF_IDCT_FAAN 20 > #define FF_IDCT_SIMPLENEON22 > -#define FF_IDCT_NONE 24 /* Used by XvMC to extract IDCT > coefficients with FF_IDCT_PERM_NONE */ > +#if FF_API_IDCT_NONE > +// formerly used by xvmc > +#define FF_IDCT_NONE 24 > +#endif > #define FF_IDCT_SIMPLEAUTO128 > Isn't this a private define that clients weren't meant to use? If so, may as well drop it with patch #1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 4/4] lavc: deprecate FF_IDCT_NONE
On 2/1/2022 8:16 AM, Lynne wrote: 1 Feb 2022, 11:02 by an...@khirnov.net: It was only used by XvMC. --- libavcodec/avcodec.h | 5 - libavcodec/idctdsp.c | 1 - libavcodec/version.h | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index acb7ae0e14..5362446092 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1407,7 +1407,10 @@ typedef struct AVCodecContext { #define FF_IDCT_SIMPLEARMV6 17 #define FF_IDCT_FAAN 20 #define FF_IDCT_SIMPLENEON22 -#define FF_IDCT_NONE 24 /* Used by XvMC to extract IDCT coefficients with FF_IDCT_PERM_NONE */ +#if FF_API_IDCT_NONE +// formerly used by xvmc +#define FF_IDCT_NONE 24 +#endif #define FF_IDCT_SIMPLEAUTO128 Isn't this a private define that clients weren't meant to use? Nowhere it says that. All FF_IDCT_ defines are documented as being able to be used in AVCodecContext.idct_algo If so, may as well drop it with patch #1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] fftools/cmdutils: add an option to append to the report file
There are times when we want ffmpeg to log, but we don't want it to overwrite the log file. In addition to the use case described in the ticket, a third party tool that invokes ffmpeg may write additional information to the log file, such as why the encoding options were chosen. This implements: https://trac.ffmpeg.org/ticket/3059 Note: unknown keys are ignored, so adding a new "append" key does not break backward compatibility. Signed-off-by: Dan Zwell --- doc/fftools-common-opts.texi | 3 +++ fftools/cmdutils.c | 8 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index d9145704d6..4c6c297315 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -270,6 +270,9 @@ of the program, @code{%t} is expanded to a timestamp, @code{%%} is expanded to a plain @code{%} @item level set the log verbosity level using a numerical value (see @code{-loglevel}). +@item append +@code{append=1} tells ffmpeg to append to a report file if it exists instead +of overwriting it. @end table For example, to output a report to a file named @file{ffreport.log} diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 4b50e15eef..350329ee8b 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -983,6 +983,7 @@ static int init_report(const char *env) time_t now; struct tm *tm; AVBPrint filename; +int append = 0; if (report_file) /* already opened */ return 0; @@ -1012,6 +1013,8 @@ static int init_report(const char *env) exit_program(1); } envlevel = 1; +} else if (!strcmp(key, "append")) { +append = strtol(val, NULL, 10); } else { av_log(NULL, AV_LOG_ERROR, "Unknown key '%s' in FFREPORT\n", key); } @@ -1032,7 +1035,10 @@ static int init_report(const char *env) if (!envlevel) report_file_level = FFMAX(report_file_level, prog_loglevel); -report_file = fopen(filename.str, "w"); +if (append) +report_file = fopen(filename.str, "a"); +else +report_file = fopen(filename.str, "w"); if (!report_file) { int ret = AVERROR(errno); av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n", -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] fftools/cmdutils: add an option to append to the report file
On 2/1/2022 8:58 AM, Dan Zwell wrote: There are times when we want ffmpeg to log, but we don't want it to overwrite the log file. In addition to the use case described in the ticket, a third party tool that invokes ffmpeg may write additional information to the log file, such as why the encoding options were chosen. This implements: https://trac.ffmpeg.org/ticket/3059 Note: unknown keys are ignored, so adding a new "append" key does not break backward compatibility. Signed-off-by: Dan Zwell --- doc/fftools-common-opts.texi | 3 +++ fftools/cmdutils.c | 8 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index d9145704d6..4c6c297315 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -270,6 +270,9 @@ of the program, @code{%t} is expanded to a timestamp, @code{%%} is expanded to a plain @code{%} @item level set the log verbosity level using a numerical value (see @code{-loglevel}). +@item append +@code{append=1} tells ffmpeg to append to a report file if it exists instead +of overwriting it. Maybe "A non zero value", since it will work with more than just 1. Alternatively, you can check for the argument and error out on anything but 0 or 1. @end table For example, to output a report to a file named @file{ffreport.log} diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 4b50e15eef..350329ee8b 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -983,6 +983,7 @@ static int init_report(const char *env) time_t now; struct tm *tm; AVBPrint filename; + int append = 0; if (report_file) /* already opened */ return 0; @@ -1012,6 +1013,8 @@ static int init_report(const char *env) exit_program(1); } envlevel = 1; + } else if (!strcmp(key, "append")) { + append = strtol(val, NULL, 10); Don't silently ignore invalid arguments. See how level is handled above. } else { av_log(NULL, AV_LOG_ERROR, "Unknown key '%s' in FFREPORT\n", key); } @@ -1032,7 +1035,10 @@ static int init_report(const char *env) if (!envlevel) report_file_level = FFMAX(report_file_level, prog_loglevel); - report_file = fopen(filename.str, "w"); + if (append) + report_file = fopen(filename.str, "a"); + else + report_file = fopen(filename.str, "w"); if (!report_file) { int ret = AVERROR(errno); av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n", ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 01/69] avcodec/avcodec: Avoid MpegEncContext in AVHWAccel.decode_mb
Use an opaque pointer to void instead. Signed-off-by: Andreas Rheinhardt --- libavcodec/avcodec.h| 6 +- libavcodec/mpegvideo_xvmc.c | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index ec1a0566a4..918753fd0e 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2026,8 +2026,6 @@ typedef struct AVCodecContext { int (*get_encode_buffer)(struct AVCodecContext *s, AVPacket *pkt, int flags); } AVCodecContext; -struct MpegEncContext; - /** * @defgroup lavc_hwaccel AVHWAccel * @@ -2154,10 +2152,8 @@ typedef struct AVHWAccel { * XvMC uses it to replace the ff_mpv_reconstruct_mb(). * Instead of decoding to raw picture, MB parameters are * stored in an array provided by the video driver. - * - * @param s the mpeg context */ -void (*decode_mb)(struct MpegEncContext *s); +void (*decode_mb)(void *opaque); /** * Initialize the hwaccel private data. diff --git a/libavcodec/mpegvideo_xvmc.c b/libavcodec/mpegvideo_xvmc.c index f06583768c..bfeb453834 100644 --- a/libavcodec/mpegvideo_xvmc.c +++ b/libavcodec/mpegvideo_xvmc.c @@ -168,8 +168,9 @@ static int ff_xvmc_field_end(AVCodecContext *avctx) * Synthesize the data needed by XvMC to render one macroblock of data. * Fill all relevant fields, if necessary do IDCT. */ -static void ff_xvmc_decode_mb(struct MpegEncContext *s) +static void ff_xvmc_decode_mb(void *opaque) { +MpegEncContext *const s = opaque; XvMCMacroBlock *mv_block; struct xvmc_pix_fmt *render; int i, cbp, blocks_per_mb; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] fftools/cmdutils: add an option to append to the report file
There are times when we want ffmpeg to log, but we don't want it to overwrite the log file. In addition to the use case described in the ticket, a third party tool that invokes ffmpeg may write additional information to the log file, such as why the encoding options were chosen. I made the error checking nonfatal for future compatibility, because this feature is aimed at scripts and ffmpeg frontends. This implements: https://trac.ffmpeg.org/ticket/3059 Note: unknown keys are ignored, so adding a new "append" key does not break backward compatibility. Signed-off-by: Dan Zwell --- doc/fftools-common-opts.texi | 3 +++ fftools/cmdutils.c | 13 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index d9145704d6..a9a8eda417 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -270,6 +270,9 @@ of the program, @code{%t} is expanded to a timestamp, @code{%%} is expanded to a plain @code{%} @item level set the log verbosity level using a numerical value (see @code{-loglevel}). +@item append +@code{append=1} tells ffmpeg to append to a report file if it exists instead of +overwriting it. @code{append=0} is the default @end table For example, to output a report to a file named @file{ffreport.log} diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 4b50e15eef..08aec489cb 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -983,6 +983,7 @@ static int init_report(const char *env) time_t now; struct tm *tm; AVBPrint filename; +int append = 0; if (report_file) /* already opened */ return 0; @@ -1012,6 +1013,13 @@ static int init_report(const char *env) exit_program(1); } envlevel = 1; +} else if (!strcmp(key, "append")) { +char *tail; +append = strtol(val, &tail, 10); +if (*val == '\0' || *tail || (append != 0 && append != 1)) { +av_log(NULL, AV_LOG_ERROR, "Invalid append value '%s' (should be 0 or 1)\n", val); +append = 0; +} } else { av_log(NULL, AV_LOG_ERROR, "Unknown key '%s' in FFREPORT\n", key); } @@ -1032,7 +1040,10 @@ static int init_report(const char *env) if (!envlevel) report_file_level = FFMAX(report_file_level, prog_loglevel); -report_file = fopen(filename.str, "w"); +if (append) +report_file = fopen(filename.str, "a"); +else +report_file = fopen(filename.str, "w"); if (!report_file) { int ret = AVERROR(errno); av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n", -- 2.25.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 02/69] avcodec/mpegvideo_enc: Allow slices only for slice-thread-able codecs
One can use slices without slice-threading. The results for mpegvideo-encoders are abysmal: AMV, SpeedHQ, H.263, RV10, RV20, MSMPEG4v2, MSMPEG4v3 and WMV1 produce broken files. WMV2 meanwhile expects the MpegEncContext given to ff_wmv2_encode_mb() to be at the beginning of a Wmv2Context (a structure that this encoder shares with the WMV2 decoder), yet this is only true for the main context and not for the slice contexts, leading to segfaults. SpeedHQ additionally triggers an av_assert2, because it is not byte-aligned at a position where it ought to be byte-aligned. Given that no codec not supporting slice threading works this commit disallows using slices unless the encoder supports slice threading. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 33f2937217..6df2a46eaa 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -599,7 +599,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) } if (avctx->slices > 1 && -(avctx->codec_id == AV_CODEC_ID_FLV1 || avctx->codec_id == AV_CODEC_ID_H261)) { +!(avctx->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)) { av_log(avctx, AV_LOG_ERROR, "Multiple slices are not supported by this codec\n"); return AVERROR(EINVAL); } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 03/69] avcodec/mjpegenc, speedhqenc: Remove nonsense assert
Our code for writing optimal huffman tables is incompatible with using multiple slices and hence commit 884506dfe2e29a5b2bd2905ca4f17e277e32acb1 that implemented this also added an assert that slice_context_count is always 1. Yet this was always wrong: a) The MJPEG-encoder has (and had) the AV_CODEC_CAP_SLICE_THREADS capability, so asserting that it always uses one slice context is incorrect. b) This commit did not add any proper checks that ensured that optimal huffman tables are never used together with multiple slices. This only happened with 03eb0515c12637dbd20c2e3ca8503d7b47cf583a. c) This assert is at the wrong place: ff_mjpeg_encode_init() is called before the actual slice_context_count is set. This is the reason why this assert was never triggered. Therefore this commit removes this assert. Also remove an assert from the SpeedHQ encoder sharing b) and c). Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpegenc.c | 2 -- libavcodec/speedhqenc.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index d15b9ece50..022f171c9e 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -293,8 +293,6 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s) s->mjpeg_ctx = m; -av_assert0(s->slice_context_count == 1); - if (s->codec_id == AV_CODEC_ID_AMV || (s->avctx->active_thread_type & FF_THREAD_SLICE)) m->huffman = HUFFMAN_TABLE_DEFAULT; diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c index 967774931c..6df0316611 100644 --- a/libavcodec/speedhqenc.c +++ b/libavcodec/speedhqenc.c @@ -87,8 +87,6 @@ av_cold int ff_speedhq_encode_init(MpegEncContext *s) { static AVOnce init_static_once = AV_ONCE_INIT; -av_assert0(s->slice_context_count == 1); - if (s->width > 65500 || s->height > 65500) { av_log(s, AV_LOG_ERROR, "SpeedHQ does not support resolutions above 65500x65500\n"); return AVERROR(EINVAL); -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 04/69] avcodec/mjpegenc: Fix files with slices > 1, but threads == 1
In the aforementioned case mpegvideo_enc.c calls ff_mjpeg_encode_stuffing() at the end of every line which pads the output to byte-alignment and escapes it; yet it does not write the restart-markers (and also not the DRI marker when writing the header) and so the output files are broken. Fix this by writing these markers depending upon the number of slices and not the number of threads in use; this also makes the output of the encoder reproducible given a slice count and is therefore important if encoder tests that actually use -threads auto are added in the future. Signed-off-by: Andreas Rheinhardt --- libavcodec/ljpegenc.c| 2 +- libavcodec/mjpegenc.c| 12 libavcodec/mjpegenc_common.c | 10 ++ libavcodec/mjpegenc_common.h | 3 ++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c index e15f448f90..7c53da7bc3 100644 --- a/libavcodec/ljpegenc.c +++ b/libavcodec/ljpegenc.c @@ -239,7 +239,7 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, init_put_bits(&pb, pkt->data, pkt->size); ff_mjpeg_encode_picture_header(avctx, &pb, NULL, &s->scantable, - s->pred, s->matrix, s->matrix); + s->pred, s->matrix, s->matrix, 0); header_bits = put_bits_count(&pb); diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index 022f171c9e..6a47503ab4 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -78,7 +78,8 @@ static void mjpeg_encode_picture_header(MpegEncContext *s) { ff_mjpeg_encode_picture_header(s->avctx, &s->pb, s->mjpeg_ctx, &s->intra_scantable, 0, - s->intra_matrix, s->chroma_intra_matrix); + s->intra_matrix, s->chroma_intra_matrix, + s->slice_context_count > 1); s->esc_pos = put_bytes_count(&s->pb, 0); for (int i = 1; i < s->slice_context_count; i++) @@ -247,7 +248,7 @@ int ff_mjpeg_encode_stuffing(MpegEncContext *s) ff_mjpeg_escape_FF(pbc, s->esc_pos); -if ((s->avctx->active_thread_type & FF_THREAD_SLICE) && mb_y < s->mb_height - 1) +if (s->slice_context_count > 1 && mb_y < s->mb_height - 1) put_marker(pbc, RST0 + (mb_y&7)); s->esc_pos = put_bytes_count(pbc, 0); @@ -289,11 +290,14 @@ static int alloc_huffman(MpegEncContext *s) av_cold int ff_mjpeg_encode_init(MpegEncContext *s) { MJpegContext *const m = &((MJPEGEncContext*)s)->mjpeg; -int ret; +int ret, use_slices; s->mjpeg_ctx = m; +use_slices = s->avctx->slices > 0 ? s->avctx->slices > 1 : + (s->avctx->active_thread_type & FF_THREAD_SLICE) && + s->avctx->thread_count > 1; -if (s->codec_id == AV_CODEC_ID_AMV || (s->avctx->active_thread_type & FF_THREAD_SLICE)) +if (s->codec_id == AV_CODEC_ID_AMV || use_slices) m->huffman = HUFFMAN_TABLE_DEFAULT; if (s->mpv_flags & FF_MPV_FLAG_QP_RD) { diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c index 995e2b7670..86b6568902 100644 --- a/libavcodec/mjpegenc_common.c +++ b/libavcodec/mjpegenc_common.c @@ -60,7 +60,7 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, ScanTable *intra_scantable, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64], - int hsample[3]) + int hsample[3], int use_slices) { int i, j, size; uint8_t *ptr; @@ -91,7 +91,7 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, } } -if(avctx->active_thread_type & FF_THREAD_SLICE){ +if (use_slices) { put_marker(p, DRI); put_bits(p, 16, 4); put_bits(p, 16, (avctx->width-1)/(8*hsample[0]) + 1); @@ -216,7 +216,8 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, MJpegContext *m, ScanTable *intra_scantable, int pred, uint16_t luma_intra_matrix[64], -uint16_t chroma_intra_matrix[64]) +uint16_t chroma_intra_matrix[64], +int use_slices) { const int lossless = !m; int hsample[4], vsample[4]; @@ -236,7 +237,8 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, jpeg_put_comments(avctx, pb); jpeg_table_header(avctx, pb, m, intra_scantable, - luma_intra_matrix, chroma_intra_matrix, hsample); + luma_intra_matrix, chroma_intra_matrix, hsample, + use_slices); switch (avctx->codec_id) { case AV_CODEC_ID_MJPEG: put_ma
[FFmpeg-devel] [PATCH v2 09/69] avcodec/idctdsp: Constify the permutation parameter of ff_init_scantable
Signed-off-by: Andreas Rheinhardt --- libavcodec/idctdsp.c | 2 +- libavcodec/idctdsp.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/idctdsp.c b/libavcodec/idctdsp.c index 71bd03c606..d07dc29207 100644 --- a/libavcodec/idctdsp.c +++ b/libavcodec/idctdsp.c @@ -26,7 +26,7 @@ #include "simple_idct.h" #include "xvididct.h" -av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, +av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable) { int i, end; diff --git a/libavcodec/idctdsp.h b/libavcodec/idctdsp.h index 014488aec3..e8f20acaf2 100644 --- a/libavcodec/idctdsp.h +++ b/libavcodec/idctdsp.h @@ -43,7 +43,7 @@ enum idct_permutation_type { FF_IDCT_PERM_SSE2, }; -void ff_init_scantable(uint8_t *permutation, ScanTable *st, +void ff_init_scantable(const uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable); void ff_init_scantable_permutation(uint8_t *idct_permutation, enum idct_permutation_type perm_type); -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 05/69] avcodec/mpegvideo: Enable private contexts
MpegEncContext is used by many different codecs and every one of these uses just a subset of its fields. If one tries to separate this and e.g. add a real MpegContext and extension structures (say MpegDecContext and MpegEncContext), one runs into two difficulties: a) Some code is shared between decoder and encoder of the same format and they therefore use the same contexts, either MpegEncContext itself or identical extensions thereof. The latter is the case for H.261 as well as WMV2. b) In case of slice threading, the generic code can only allocate and initialize the structure it knows about; right now this is an MpegEncContext. If the codec has an even more extensive structure, it is only available for the main thread's MpegEncContext. Fixing this would involve making ff_mpv_common_init() aware of the size the size of slice context to allocate and would be part of separating the main thread's context from the slice contexts in general. This commit only intends to tackle the first issue by adding a pointer to MpegEncContext that codecs can set to a common context so that the aforementioned codecs can use this context (together with the MpegEncContext) in their common code. This will allow to move fields only used by the main thread to more specialized contexts. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 3 +++ libavcodec/mpegvideo_dec.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 84d79d2e59..5e406b9a9c 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -84,6 +84,9 @@ typedef struct MpegEncContext { * offsets used in ASM. */ struct AVCodecContext *avctx; +/* The following pointer is intended for codecs sharing code + * between decoder and encoder and in need of a common context to do so. */ +void *private_ctx; /* the following parameters must be initialized before encoding */ int width, height;///< picture size. must be a multiple of 16 int gop_size; diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 1e238bd1e1..cc23e070ea 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -62,10 +62,12 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, // FIXME can parameters change on I-frames? // in that case dst may need a reinit if (!s->context_initialized) { +void *private_ctx = s->private_ctx; int err; memcpy(s, s1, sizeof(*s)); s->avctx = dst; +s->private_ctx = private_ctx; s->bitstream_buffer = NULL; s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0; @@ -76,6 +78,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, if ((err = ff_mpv_common_init(s)) < 0) { memset(s, 0, sizeof(*s)); s->avctx = dst; +s->private_ctx = private_ctx; return err; } } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 06/69] avcodec/h261: Separate decode and encode contexts
Signed-off-by: Andreas Rheinhardt --- libavcodec/h261.c| 2 +- libavcodec/h261.h| 8 -- libavcodec/h261dec.c | 59 +++- libavcodec/h261enc.c | 54 +--- 4 files changed, 72 insertions(+), 51 deletions(-) diff --git a/libavcodec/h261.c b/libavcodec/h261.c index 1290c040cd..7dfaee7dc4 100644 --- a/libavcodec/h261.c +++ b/libavcodec/h261.c @@ -60,7 +60,7 @@ static void h261_loop_filter(uint8_t *src, int stride) void ff_h261_loop_filter(MpegEncContext *s) { -H261Context *h = (H261Context *)s; +H261Context *const h = s->private_ctx; const int linesize = s->linesize; const int uvlinesize = s->uvlinesize; uint8_t *dest_y = s->dest[0]; diff --git a/libavcodec/h261.h b/libavcodec/h261.h index 25728a295d..ff1903e508 100644 --- a/libavcodec/h261.h +++ b/libavcodec/h261.h @@ -35,15 +35,7 @@ * H261Context */ typedef struct H261Context { -MpegEncContext s; - -int current_mba; -int mba_diff; int mtype; -int current_mv_x; -int current_mv_y; -int gob_number; -int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read } H261Context; #define MB_TYPE_H261_FIL 0x80 diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index 2fd8d94df1..17f1067b15 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -47,6 +47,19 @@ static VLC h261_mtype_vlc; static VLC h261_mv_vlc; static VLC h261_cbp_vlc; +typedef struct H261DecContext { +MpegEncContext s; + +H261Context common; + +int current_mba; +int mba_diff; +int current_mv_x; +int current_mv_y; +int gob_number; +int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read +} H261DecContext; + static av_cold void h261_decode_init_static(void) { INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35, @@ -67,9 +80,10 @@ static av_cold void h261_decode_init_static(void) static av_cold int h261_decode_init(AVCodecContext *avctx) { static AVOnce init_static_once = AV_ONCE_INIT; -H261Context *h = avctx->priv_data; +H261DecContext *const h = avctx->priv_data; MpegEncContext *const s = &h->s; +s->private_ctx = &h->common; // set defaults ff_mpv_decode_init(s, avctx); @@ -89,7 +103,7 @@ static av_cold int h261_decode_init(AVCodecContext *avctx) * Decode the group of blocks header or slice header. * @return <0 if an error occurred */ -static int h261_decode_gob_header(H261Context *h) +static int h261_decode_gob_header(H261DecContext *h) { unsigned int val; MpegEncContext *const s = &h->s; @@ -143,7 +157,7 @@ static int h261_decode_gob_header(H261Context *h) * Decode the group of blocks / video packet header. * @return <0 if no resync found */ -static int h261_resync(H261Context *h) +static int h261_resync(H261DecContext *h) { MpegEncContext *const s = &h->s; int left, ret; @@ -184,7 +198,7 @@ static int h261_resync(H261Context *h) * Decode skipped macroblocks. * @return 0 */ -static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2) +static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2) { MpegEncContext *const s = &h->s; int i; @@ -209,7 +223,7 @@ static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2) s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; s->mb_skipped = 1; -h->mtype &= ~MB_TYPE_H261_FIL; +h->common.mtype &= ~MB_TYPE_H261_FIL; if (s->current_picture.motion_val[0]) { int b_stride = 2*s->mb_width + 1; @@ -254,7 +268,7 @@ static int decode_mv_component(GetBitContext *gb, int v) * Decode a macroblock. * @return <0 if an error occurred */ -static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded) +static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded) { MpegEncContext *const s = &h->s; int level, i, j, run; @@ -346,9 +360,10 @@ static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded) return 0; } -static int h261_decode_mb(H261Context *h) +static int h261_decode_mb(H261DecContext *h) { MpegEncContext *const s = &h->s; +H261Context *const com = &h->common; int i, cbp, xy; cbp = 63; @@ -386,23 +401,23 @@ static int h261_decode_mb(H261Context *h) ff_update_block_index(s); // Read mtype -h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2); -if (h->mtype < 0) { +com->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2); +if (com->mtype < 0) { av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n", - h->mtype); + com->mtype); return SLICE_ERROR; } -av_assert0(h->mtype < FF_ARRAY_EL
[FFmpeg-devel] [PATCH v2 07/69] avcodec/h261: Move encoder-only stuff to a new header
Signed-off-by: Andreas Rheinhardt --- libavcodec/h261.h | 7 --- libavcodec/h261enc.c | 1 + libavcodec/h261enc.h | 40 ++ libavcodec/mpegvideo_enc.c | 2 +- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 libavcodec/h261enc.h diff --git a/libavcodec/h261.h b/libavcodec/h261.h index ff1903e508..67c362be93 100644 --- a/libavcodec/h261.h +++ b/libavcodec/h261.h @@ -51,11 +51,4 @@ extern RLTable ff_h261_rl_tcoeff; void ff_h261_loop_filter(MpegEncContext *s); -int ff_h261_get_picture_format(int width, int height); -void ff_h261_reorder_mb_index(MpegEncContext *s); -void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], - int motion_x, int motion_y); -void ff_h261_encode_picture_header(MpegEncContext *s, int picture_number); -void ff_h261_encode_init(MpegEncContext *s); - #endif /* AVCODEC_H261_H */ diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c index 13fe5bbfb2..f1cd51ec2f 100644 --- a/libavcodec/h261enc.c +++ b/libavcodec/h261enc.c @@ -32,6 +32,7 @@ #include "mpegutils.h" #include "mpegvideo.h" #include "h261.h" +#include "h261enc.h" #include "mpegvideodata.h" static uint8_t uni_h261_rl_len [64*64*2*2]; diff --git a/libavcodec/h261enc.h b/libavcodec/h261enc.h new file mode 100644 index 00..0a01858be5 --- /dev/null +++ b/libavcodec/h261enc.h @@ -0,0 +1,40 @@ +/* + * H.261 encoder + * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2004 Maarten Daniels + * + * 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 + */ + +/** + * @file + * H.261 encoder header. + */ + +#ifndef AVCODEC_H261ENC_H +#define AVCODEC_H261ENC_H + +#include "mpegvideo.h" + +int ff_h261_get_picture_format(int width, int height); +void ff_h261_reorder_mb_index(MpegEncContext *s); +void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], + int motion_x, int motion_y); +void ff_h261_encode_picture_header(MpegEncContext *s, int picture_number); +void ff_h261_encode_init(MpegEncContext *s); + +#endif diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 6df2a46eaa..bb8d3bc908 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -48,7 +48,7 @@ #include "mpeg12data.h" #include "mpegvideo.h" #include "mpegvideodata.h" -#include "h261.h" +#include "h261enc.h" #include "h263.h" #include "h263data.h" #include "mjpegenc_common.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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 08/69] avcodec/h261enc: Pass PutBitContext directly in h261_encode_motion()
Signed-off-by: Andreas Rheinhardt --- libavcodec/h261enc.c | 13 ++--- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c index f1cd51ec2f..66b7cc18fd 100644 --- a/libavcodec/h261enc.c +++ b/libavcodec/h261enc.c @@ -141,13 +141,12 @@ void ff_h261_reorder_mb_index(MpegEncContext *s) } } -static void h261_encode_motion(H261EncContext *h, int val) +static void h261_encode_motion(PutBitContext *pb, int val) { -MpegEncContext *const s = &h->s; int sign, code; if (val == 0) { code = 0; -put_bits(&s->pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]); +put_bits(pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]); } else { if (val > 15) val -= 32; @@ -155,8 +154,8 @@ static void h261_encode_motion(H261EncContext *h, int val) val += 32; sign = val < 0; code = sign ? -val : val; -put_bits(&s->pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]); -put_bits(&s->pb, 1, sign); +put_bits(pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]); +put_bits(pb, 1, sign); } } @@ -314,8 +313,8 @@ void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], mv_diff_y = (motion_y >> 1) - s->last_mv[0][0][1]; s->last_mv[0][0][0] = (motion_x >> 1); s->last_mv[0][0][1] = (motion_y >> 1); -h261_encode_motion(h, mv_diff_x); -h261_encode_motion(h, mv_diff_y); +h261_encode_motion(&s->pb, mv_diff_x); +h261_encode_motion(&s->pb, mv_diff_y); } if (HAS_CBP(com->mtype)) { -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 10/69] avcodec/wmv2: Move initializing abt_scantables to the decoder
They are not used by the encoder at all. Signed-off-by: Andreas Rheinhardt --- libavcodec/wmv2.c| 6 -- libavcodec/wmv2dec.c | 6 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/wmv2.c b/libavcodec/wmv2.c index fd64a0938f..57e1267782 100644 --- a/libavcodec/wmv2.c +++ b/libavcodec/wmv2.c @@ -20,11 +20,9 @@ #include "avcodec.h" #include "idctdsp.h" -#include "mpegutils.h" #include "mpegvideo.h" #include "msmpeg4data.h" #include "wmv2.h" -#include "wmv2data.h" av_cold void ff_wmv2_common_init(Wmv2Context *w) @@ -36,10 +34,6 @@ av_cold void ff_wmv2_common_init(Wmv2Context *w) s->idsp.perm_type = w->wdsp.idct_perm; ff_init_scantable_permutation(s->idsp.idct_permutation, w->wdsp.idct_perm); -ff_init_scantable(s->idsp.idct_permutation, &w->abt_scantable[0], - ff_wmv2_scantableA); -ff_init_scantable(s->idsp.idct_permutation, &w->abt_scantable[1], - ff_wmv2_scantableB); ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_wmv1_scantable[1]); ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c index 7518088b6a..dd0e2683f5 100644 --- a/libavcodec/wmv2dec.c +++ b/libavcodec/wmv2dec.c @@ -29,6 +29,7 @@ #include "msmpeg4data.h" #include "simple_idct.h" #include "wmv2.h" +#include "wmv2data.h" static void wmv2_add_block(Wmv2Context *w, int16_t *block1, @@ -537,12 +538,17 @@ int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) static av_cold int wmv2_decode_init(AVCodecContext *avctx) { Wmv2Context *const w = avctx->priv_data; +MpegEncContext *const s = &w->s; int ret; if ((ret = ff_msmpeg4_decode_init(avctx)) < 0) return ret; ff_wmv2_common_init(w); +ff_init_scantable(s->idsp.idct_permutation, &w->abt_scantable[0], + ff_wmv2_scantableA); +ff_init_scantable(s->idsp.idct_permutation, &w->abt_scantable[1], + ff_wmv2_scantableB); return ff_intrax8_common_init(avctx, &w->x8, &w->s.idsp, w->s.block, w->s.block_last_index, -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 11/69] avcodec/wmv2: Split Wmv2Context into decoder and encoder context
Signed-off-by: Andreas Rheinhardt --- libavcodec/wmv2.c| 6 ++--- libavcodec/wmv2.h| 26 +++--- libavcodec/wmv2dec.c | 64 +++- libavcodec/wmv2enc.c | 29 +++- 4 files changed, 73 insertions(+), 52 deletions(-) diff --git a/libavcodec/wmv2.c b/libavcodec/wmv2.c index 57e1267782..8d1d117dea 100644 --- a/libavcodec/wmv2.c +++ b/libavcodec/wmv2.c @@ -25,9 +25,9 @@ #include "wmv2.h" -av_cold void ff_wmv2_common_init(Wmv2Context *w) +av_cold void ff_wmv2_common_init(MpegEncContext *s) { -MpegEncContext *const s = &w->s; +WMV2Context *const w = s->private_ctx; ff_blockdsp_init(&s->bdsp, s->avctx); ff_wmv2dsp_init(&w->wdsp); @@ -52,7 +52,7 @@ void ff_mspel_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t **ref_picture, op_pixels_func (*pix_op)[4], int motion_x, int motion_y, int h) { -Wmv2Context *const w = (Wmv2Context *) s; +WMV2Context *const w = s->private_ctx; uint8_t *ptr; int dxy, mx, my, src_x, src_y, v_edge_pos; ptrdiff_t offset, linesize, uvlinesize; diff --git a/libavcodec/wmv2.h b/libavcodec/wmv2.h index 1798dbabcd..4001093881 100644 --- a/libavcodec/wmv2.h +++ b/libavcodec/wmv2.h @@ -21,9 +21,6 @@ #ifndef AVCODEC_WMV2_H #define AVCODEC_WMV2_H -#include "libavutil/mem_internal.h" - -#include "intrax8.h" #include "mpegvideo.h" #include "wmv2dsp.h" @@ -33,29 +30,12 @@ #define SKIP_TYPE_COL 3 -typedef struct Wmv2Context { -MpegEncContext s; -IntraX8Context x8; +typedef struct WMV2Context { WMV2DSPContext wdsp; -int j_type_bit; -int j_type; -int abt_flag; -int abt_type; -int abt_type_table[6]; -int per_mb_abt; -int per_block_abt; -int mspel_bit; -int cbp_table_index; -int top_left_mv_flag; -int per_mb_rl_bit; -int skip_type; int hshift; +} WMV2Context; -ScanTable abt_scantable[2]; -DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64]; -} Wmv2Context; - -void ff_wmv2_common_init(Wmv2Context *w); +void ff_wmv2_common_init(MpegEncContext *s); int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]); int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number); diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c index dd0e2683f5..f9d91f9571 100644 --- a/libavcodec/wmv2dec.c +++ b/libavcodec/wmv2dec.c @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mem_internal.h" + #include "avcodec.h" #include "h263dec.h" #include "internal.h" @@ -31,8 +33,28 @@ #include "wmv2.h" #include "wmv2data.h" - -static void wmv2_add_block(Wmv2Context *w, int16_t *block1, +typedef struct WMV2DecContext { +MpegEncContext s; +WMV2Context common; +IntraX8Context x8; +int j_type_bit; +int j_type; +int abt_flag; +int abt_type; +int abt_type_table[6]; +int per_mb_abt; +int per_block_abt; +int mspel_bit; +int cbp_table_index; +int top_left_mv_flag; +int per_mb_rl_bit; +int skip_type; + +ScanTable abt_scantable[2]; +DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64]; +} WMV2DecContext; + +static void wmv2_add_block(WMV2DecContext *w, int16_t *block1, uint8_t *dst, int stride, int n) { MpegEncContext *const s = &w->s; @@ -40,7 +62,7 @@ static void wmv2_add_block(Wmv2Context *w, int16_t *block1, if (s->block_last_index[n] >= 0) { switch (w->abt_type_table[n]) { case 0: -w->wdsp.idct_add(dst, stride, block1); +w->common.wdsp.idct_add(dst, stride, block1); break; case 1: ff_simple_idct84_add(dst, stride, block1); @@ -61,7 +83,7 @@ static void wmv2_add_block(Wmv2Context *w, int16_t *block1, void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr) { -Wmv2Context *const w = (Wmv2Context *) s; +WMV2DecContext *const w = (WMV2DecContext *) s; wmv2_add_block(w, block1[0], dest_y, s->linesize, 0); wmv2_add_block(w, block1[1], dest_y + 8, s->linesize, 1); @@ -75,7 +97,7 @@ void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64], wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5); } -static int parse_mb_skip(Wmv2Context *w) +static int parse_mb_skip(WMV2DecContext *w) { int mb_x, mb_y; int coded_mb_count = 0; @@ -140,7 +162,7 @@ static int parse_mb_skip(Wmv2Context *w) return 0; } -static int decode_ext_header(Wmv2Context *w) +static int decode_ext_header(WMV2DecContext *w) { MpegEncContext *const s = &w->s; GetBitContext gb; @@ -180,7 +202,7 @@ static int decode_ext_header(Wmv2Context *w) int ff_wmv2_decode_picture_header(MpegEncContext *s) { -Wmv2Context *const w = (Wmv2Context *) s; +WMV2DecContext *const w =
[FFmpeg-devel] [PATCH v2 12/69] avcodec/wmv2.h: Move encoder- and decoder-only parts to new headers
Signed-off-by: Andreas Rheinhardt --- libavcodec/h263dec.c | 2 +- libavcodec/mpegvideo.c | 2 +- libavcodec/mpegvideo_enc.c | 2 +- libavcodec/msmpeg4dec.c| 2 +- libavcodec/wmv2.h | 9 - libavcodec/wmv2dec.c | 1 + libavcodec/wmv2dec.h | 32 libavcodec/wmv2enc.c | 1 + libavcodec/wmv2enc.h | 31 +++ 9 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 libavcodec/wmv2dec.h create mode 100644 libavcodec/wmv2enc.h diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 3466027286..0812912f17 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -49,7 +49,7 @@ #include "msmpeg4.h" #include "qpeldsp.h" #include "thread.h" -#include "wmv2.h" +#include "wmv2dec.h" static enum AVPixelFormat h263_get_format(AVCodecContext *avctx) { diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index bbcf00b014..0e0f035526 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -44,7 +44,7 @@ #include "mpegvideodata.h" #include "qpeldsp.h" #include "thread.h" -#include "wmv2.h" +#include "wmv2dec.h" #include static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index bb8d3bc908..d2365a54af 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -67,7 +67,7 @@ #include "mpeg4videodata.h" #include "internal.h" #include "bytestream.h" -#include "wmv2.h" +#include "wmv2enc.h" #include "rv10.h" #include "packet_internal.h" #include diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c index 3d2dcb9429..e1d2c342bc 100644 --- a/libavcodec/msmpeg4dec.c +++ b/libavcodec/msmpeg4dec.c @@ -33,7 +33,7 @@ #include "mpeg4video.h" #include "msmpeg4data.h" #include "vc1data.h" -#include "wmv2.h" +#include "wmv2dec.h" #define DC_VLC_BITS 9 #define V2_INTRA_CBPC_VLC_BITS 3 diff --git a/libavcodec/wmv2.h b/libavcodec/wmv2.h index 4001093881..cdd58cf011 100644 --- a/libavcodec/wmv2.h +++ b/libavcodec/wmv2.h @@ -37,15 +37,6 @@ typedef struct WMV2Context { void ff_wmv2_common_init(MpegEncContext *s); -int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]); -int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number); -void ff_wmv2_encode_mb(MpegEncContext * s, int16_t block[6][64], - int motion_x, int motion_y); -int ff_wmv2_decode_picture_header(MpegEncContext * s); -int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s); -void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64], -uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr); - 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 f9d91f9571..ddf68545fc 100644 --- a/libavcodec/wmv2dec.c +++ b/libavcodec/wmv2dec.c @@ -32,6 +32,7 @@ #include "simple_idct.h" #include "wmv2.h" #include "wmv2data.h" +#include "wmv2dec.h" typedef struct WMV2DecContext { MpegEncContext s; diff --git a/libavcodec/wmv2dec.h b/libavcodec/wmv2dec.h new file mode 100644 index 00..cc410afe17 --- /dev/null +++ b/libavcodec/wmv2dec.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2002 The FFmpeg Project + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_WMV2DEC_H +#define AVCODEC_WMV2DEC_H + +#include "mpegvideo.h" + +int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]); +int ff_wmv2_decode_picture_header(MpegEncContext * s); +int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s); +void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64], +uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr); + +#endif diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c index a7827f3194..5cb4c4073c 100644 --- a/libavcodec/wmv2enc.c +++ b/libavcodec/wmv2enc.c @@ -24,6 +24,7 @@ #include "msmpeg4.h" #include "msmpeg4data.h" #include "wmv2.h" +#include "wmv2enc.h" typedef struct WMV2EncContext { MpegEncContext s; diff --git a/libavcodec/wmv2enc.h b/libav
[FFmpeg-devel] [PATCH v2 13/69] avcodec/msmpeg4.h: Move encoder-only stuff to a new header
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 2 +- libavcodec/msmpeg4.h | 15 - libavcodec/msmpeg4enc.c| 1 + libavcodec/msmpeg4enc.h| 45 ++ libavcodec/wmv2enc.c | 1 + 5 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 libavcodec/msmpeg4enc.h diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index d2365a54af..07dc575a5b 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -56,7 +56,7 @@ #include "mpegutils.h" #include "mjpegenc.h" #include "speedhqenc.h" -#include "msmpeg4.h" +#include "msmpeg4enc.h" #include "pixblockdsp.h" #include "qpeldsp.h" #include "faandct.h" diff --git a/libavcodec/msmpeg4.h b/libavcodec/msmpeg4.h index 483c965b9d..dbe650cbbc 100644 --- a/libavcodec/msmpeg4.h +++ b/libavcodec/msmpeg4.h @@ -28,7 +28,6 @@ #include "avcodec.h" #include "mpegvideo.h" #include "msmpeg4data.h" -#include "put_bits.h" #define INTER_INTRA_VLC_BITS 3 #define MB_NON_INTRA_VLC_BITS 9 @@ -42,20 +41,10 @@ extern VLC ff_mb_non_intra_vlc[4]; extern VLC ff_inter_intra_vlc; -void ff_msmpeg4_code012(PutBitContext *pb, int n); void ff_msmpeg4_common_init(MpegEncContext *s); -void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n); -void ff_msmpeg4_handle_slices(MpegEncContext *s); -void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my); int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr); -void ff_msmpeg4_encode_init(MpegEncContext *s); -void ff_msmpeg4_encode_picture_header(MpegEncContext *s, int picture_number); -void ff_msmpeg4_encode_ext_header(MpegEncContext *s); -void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], - int motion_x, int motion_y); - int ff_msmpeg4_decode_init(AVCodecContext *avctx); int ff_msmpeg4_decode_picture_header(MpegEncContext *s); int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size); @@ -72,9 +61,5 @@ int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, CONFIG_WMV1_DECODER || \ CONFIG_WMV2_DECODER || \ CONFIG_VC1_DECODER) -#define CONFIG_MSMPEG4_ENCODER (CONFIG_MSMPEG4V2_ENCODER || \ -CONFIG_MSMPEG4V3_ENCODER || \ -CONFIG_WMV1_ENCODER || \ -CONFIG_WMV2_ENCODER) #endif /* AVCODEC_MSMPEG4_H */ diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c index 2c619e1210..31920b7f0d 100644 --- a/libavcodec/msmpeg4enc.c +++ b/libavcodec/msmpeg4enc.c @@ -39,6 +39,7 @@ #include "mpeg4video.h" #include "msmpeg4.h" #include "msmpeg4data.h" +#include "msmpeg4enc.h" #include "put_bits.h" #include "rl.h" #include "vc1data.h" diff --git a/libavcodec/msmpeg4enc.h b/libavcodec/msmpeg4enc.h new file mode 100644 index 00..12f8f44232 --- /dev/null +++ b/libavcodec/msmpeg4enc.h @@ -0,0 +1,45 @@ +/* + * MSMPEG4 encoder header + * copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_MSMPEG4ENC_H +#define AVCODEC_MSMPEG4ENC_H + +#include "config.h" +#include "mpegvideo.h" +#include "put_bits.h" + +void ff_msmpeg4_encode_init(MpegEncContext *s); +void ff_msmpeg4_encode_picture_header(MpegEncContext *s, int picture_number); +void ff_msmpeg4_encode_ext_header(MpegEncContext *s); +void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], + int motion_x, int motion_y); +void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n); +void ff_msmpeg4_handle_slices(MpegEncContext *s); +void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my); + +void ff_msmpeg4_code012(PutBitContext *pb, int n); + +#define CONFIG_MSMPEG4_ENCODER (CONFIG_MSMPEG4V2_ENCODER || \ +CONFIG_MSMPEG4V3_ENCODER || \ +CONFIG_WMV1_ENCODER || \ +CONFIG_WMV2_ENCODER) + +#endif diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c index 5cb4c4073c..2622f833b0 100644 --- a/libavcodec
[FFmpeg-devel] [PATCH v2 14/69] avcodec/msmpeg4.h: Move decoder-only parts to a new header
Signed-off-by: Andreas Rheinhardt --- libavcodec/h263dec.c| 2 +- libavcodec/msmpeg4.h| 23 --- libavcodec/msmpeg4dec.c | 1 + libavcodec/msmpeg4dec.h | 50 + libavcodec/mss2.c | 2 +- libavcodec/vc1dec.c | 2 +- libavcodec/wmv2dec.c| 1 + 7 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 libavcodec/msmpeg4dec.h diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 0812912f17..5a54d57bbc 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -46,7 +46,7 @@ #endif #include "mpegutils.h" #include "mpegvideo.h" -#include "msmpeg4.h" +#include "msmpeg4dec.h" #include "qpeldsp.h" #include "thread.h" #include "wmv2dec.h" diff --git a/libavcodec/msmpeg4.h b/libavcodec/msmpeg4.h index dbe650cbbc..6dd16d3957 100644 --- a/libavcodec/msmpeg4.h +++ b/libavcodec/msmpeg4.h @@ -24,42 +24,19 @@ #include -#include "config.h" #include "avcodec.h" #include "mpegvideo.h" -#include "msmpeg4data.h" - -#define INTER_INTRA_VLC_BITS 3 -#define MB_NON_INTRA_VLC_BITS 9 -#define MB_INTRA_VLC_BITS 9 #define II_BITRATE 128*1024 #define MBAC_BITRATE 50*1024 #define DC_MAX 119 -extern VLC ff_mb_non_intra_vlc[4]; -extern VLC ff_inter_intra_vlc; - void ff_msmpeg4_common_init(MpegEncContext *s); int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr); -int ff_msmpeg4_decode_init(AVCodecContext *avctx); -int ff_msmpeg4_decode_picture_header(MpegEncContext *s); -int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size); -void ff_msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr); -int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block, -int n, int coded, const uint8_t *scan_table); int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr, int *dir_ptr); - -#define CONFIG_MSMPEG4_DECODER (CONFIG_MSMPEG4V1_DECODER || \ -CONFIG_MSMPEG4V2_DECODER || \ -CONFIG_MSMPEG4V3_DECODER || \ -CONFIG_WMV1_DECODER || \ -CONFIG_WMV2_DECODER || \ -CONFIG_VC1_DECODER) - #endif /* AVCODEC_MSMPEG4_H */ diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c index e1d2c342bc..a7870f252f 100644 --- a/libavcodec/msmpeg4dec.c +++ b/libavcodec/msmpeg4dec.c @@ -27,6 +27,7 @@ #include "mpegutils.h" #include "mpegvideo.h" #include "msmpeg4.h" +#include "msmpeg4dec.h" #include "libavutil/imgutils.h" #include "h263.h" #include "h263dec.h" diff --git a/libavcodec/msmpeg4dec.h b/libavcodec/msmpeg4dec.h new file mode 100644 index 00..af2591caf5 --- /dev/null +++ b/libavcodec/msmpeg4dec.h @@ -0,0 +1,50 @@ +/* + * MSMPEG4 decoder header + * copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_MSMPEG4DEC_H +#define AVCODEC_MSMPEG4DEC_H + +#include "config.h" +#include "avcodec.h" +#include "mpegvideo.h" + +#define INTER_INTRA_VLC_BITS 3 +#define MB_NON_INTRA_VLC_BITS 9 +#define MB_INTRA_VLC_BITS 9 + +extern VLC ff_mb_non_intra_vlc[4]; +extern VLC ff_inter_intra_vlc; + +int ff_msmpeg4_decode_init(AVCodecContext *avctx); +int ff_msmpeg4_decode_picture_header(MpegEncContext *s); +int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size); +void ff_msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr); +int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block, +int n, int coded, const uint8_t *scan_table); + +#define CONFIG_MSMPEG4_DECODER (CONFIG_MSMPEG4V1_DECODER || \ +CONFIG_MSMPEG4V2_DECODER || \ +CONFIG_MSMPEG4V3_DECODER || \ +CONFIG_WMV1_DECODER || \ +CONFIG_WMV2_DECODER || \ +CONFIG_VC1_DECODER) + +#endif diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c index d7a19f6ad2..dcf91f9828 100644 --- a/libavcodec/mss2.c +++ b/libavcodec/mss2.c @@ -27,7 +27,7 @@ #include "error_resilience.h" #
[FFmpeg-devel] [PATCH v2 15/69] avcodec/msmpegenc: Add MSMPEG4EncContext and move ac_stats to it
Also avoid the allocation by making it part of the context. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 2 -- libavcodec/mpegvideo_enc.c | 7 --- libavcodec/msmpeg4enc.c| 26 +++--- libavcodec/msmpeg4enc.h| 8 libavcodec/wmv2enc.c | 8 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 5e406b9a9c..f5c9789fea 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -422,8 +422,6 @@ typedef struct MpegEncContext { int per_mb_rl_table; int esc3_level_length; int esc3_run_length; -/** [mb_intra][isChroma][level][run][last] */ -int (*ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2]; int inter_intra_pred; int mspel; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 07dc575a5b..0dde4edc73 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -813,12 +813,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) ff_pixblockdsp_init(&s->pdsp, avctx); ff_qpeldsp_init(&s->qdsp); -if (s->msmpeg4_version) { -int ac_stats_size = 2 * 2 * (MAX_LEVEL + 1) * (MAX_RUN + 1) * 2 * sizeof(int); -if (!(s->ac_stats = av_mallocz(ac_stats_size))) -return AVERROR(ENOMEM); -} - if (!(avctx->stats_out = av_mallocz(256)) || !FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix, 32) || !FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix, 32) || @@ -944,7 +938,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) ff_mpv_picture_free(avctx, &s->new_picture); av_freep(&avctx->stats_out); -av_freep(&s->ac_stats); if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c index 31920b7f0d..c436f78f9d 100644 --- a/libavcodec/msmpeg4enc.c +++ b/libavcodec/msmpeg4enc.c @@ -148,8 +148,9 @@ av_cold void ff_msmpeg4_encode_init(MpegEncContext *s) ff_thread_once(&init_static_once, msmpeg4_encode_init_static); } -static void find_best_tables(MpegEncContext * s) +static void find_best_tables(MSMPEG4EncContext *ms) { +MpegEncContext *const s = &ms->s; int i; int best= 0, best_size= INT_MAX; int chroma_best = 0, best_chroma_size = INT_MAX; @@ -169,9 +170,9 @@ static void find_best_tables(MpegEncContext * s) int last; const int last_size= size + chroma_size; for(last=0; last<2; last++){ -int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last]; -int intra_luma_count = s->ac_stats[1][0][level][run][last]; -int intra_chroma_count= s->ac_stats[1][1][level][run][last]; +int inter_count = ms->ac_stats[0][0][level][run][last] + ms->ac_stats[0][1][level][run][last]; +int intra_luma_count = ms->ac_stats[1][0][level][run][last]; +int intra_chroma_count= ms->ac_stats[1][1][level][run][last]; if(s->pict_type==AV_PICTURE_TYPE_I){ size += intra_luma_count *rl_length[i ][level][run][last]; @@ -197,7 +198,7 @@ static void find_best_tables(MpegEncContext * s) if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best; -memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2); +memset(ms->ac_stats, 0, sizeof(ms->ac_stats)); s->rl_table_index =best; s->rl_chroma_table_index= chroma_best; @@ -215,7 +216,9 @@ static void find_best_tables(MpegEncContext * s) /* write MSMPEG4 compatible frame header */ void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number) { -find_best_tables(s); +MSMPEG4EncContext *const ms = (MSMPEG4EncContext*)s; + +find_best_tables(ms); align_put_bits(&s->pb); put_bits(&s->pb, 2, s->pict_type - 1); @@ -553,6 +556,7 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr * escape coding (same as H.263) and more VLC tables. */ void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n) { +MSMPEG4EncContext *const ms = (MSMPEG4EncContext*)s; int level, run, last, i, j, last_index; int last_non_zero, sign, slevel; int code, run_diff, dc_pred_dir; @@ -603,10 +607,10 @@ void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n) } if(level<=MAX_LEVEL && run<=MAX_RUN){ -s->ac_stats[s->mb_intra][n>3][level][run][last]++; +ms->ac_stats[s->mb_intra][n>3][level][run][last]++; } -s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like +ms->a
[FFmpeg-devel] [PATCH v2 16/69] avcodec/h263.h: Move encoder-only stuff to a new header h263enc.h
Signed-off-by: Andreas Rheinhardt --- libavcodec/h263.h | 101 libavcodec/h263enc.h | 130 + libavcodec/ituh263enc.c| 1 + libavcodec/mpeg4videodec.c | 1 + libavcodec/mpeg4videoenc.c | 1 + libavcodec/mpegvideo_enc.c | 1 + libavcodec/msmpeg4dec.c| 1 + libavcodec/msmpeg4enc.c| 1 + libavcodec/rv20enc.c | 2 +- libavcodec/snowenc.c | 2 +- libavcodec/svq1enc.c | 1 + 11 files changed, 139 insertions(+), 103 deletions(-) create mode 100644 libavcodec/h263enc.h diff --git a/libavcodec/h263.h b/libavcodec/h263.h index 6dd5d2295a..27a5f31c59 100644 --- a/libavcodec/h263.h +++ b/libavcodec/h263.h @@ -20,119 +20,18 @@ #ifndef AVCODEC_H263_H #define AVCODEC_H263_H -#include #include "libavutil/rational.h" #include "mpegvideo.h" -#include "h263data.h" #define FF_ASPECT_EXTENDED 15 #define H263_GOB_HEIGHT(h) ((h) <= 400 ? 1 : (h) <= 800 ? 2 : 4) av_const int ff_h263_aspect_to_info(AVRational aspect); -void ff_h263_encode_mb(MpegEncContext *s, - int16_t block[6][64], - int motion_x, int motion_y); -void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number); -void ff_h263_encode_gob_header(MpegEncContext * s, int mb_line); int16_t *ff_h263_pred_motion(MpegEncContext * s, int block, int dir, int *px, int *py); -void ff_h263_encode_init(MpegEncContext *s); void ff_h263_init_rl_inter(void); void ff_h263_update_motion_val(MpegEncContext * s); void ff_h263_loop_filter(MpegEncContext * s); -void ff_h263_encode_mba(MpegEncContext *s); -void ff_init_qscale_tab(MpegEncContext *s); - - -void ff_clean_h263_qscales(MpegEncContext *s); -void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code); - - -static inline int h263_get_motion_length(int val, int f_code){ -int bit_size, code, sign; - -if (val == 0) { -return 1; /* ff_mvtab[0][1] */ -} else { -bit_size = f_code - 1; -/* modulo encoding */ -val = sign_extend(val, 6 + bit_size); -sign = val >> 31; -val = (val ^ sign) - sign; /* val = FFABS(val) */ -val--; -code = (val >> bit_size) + 1; - -return ff_mvtab[code][1] + 1 + bit_size; -} -} - -static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){ -if (s->avctx->flags2 & AV_CODEC_FLAG2_NO_OUTPUT) { -skip_put_bits(&s->pb, -h263_get_motion_length(x, f_code) - +h263_get_motion_length(y, f_code)); -}else{ -ff_h263_encode_motion(&s->pb, x, f_code); -ff_h263_encode_motion(&s->pb, y, f_code); -} -} - -static inline int get_p_cbp(MpegEncContext * s, - int16_t block[6][64], - int motion_x, int motion_y){ -int cbp, i; - -if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) { -int best_cbpy_score= INT_MAX; -int best_cbpc_score= INT_MAX; -int cbpc = (-1), cbpy= (-1); -const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0); -const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); - -for(i=0; i<4; i++){ -int score= ff_h263_inter_MCBPC_bits[i + offset] * lambda; -if(i&1) score += s->coded_score[5]; -if(i&2) score += s->coded_score[4]; - -if(score < best_cbpc_score){ -best_cbpc_score= score; -cbpc= i; -} -} - -for(i=0; i<16; i++){ -int score= ff_h263_cbpy_tab[i ^ 0xF][1] * lambda; -if(i&1) score += s->coded_score[3]; -if(i&2) score += s->coded_score[2]; -if(i&4) score += s->coded_score[1]; -if(i&8) score += s->coded_score[0]; - -if(score < best_cbpy_score){ -best_cbpy_score= score; -cbpy= i; -} -} -cbp= cbpc + 4*cbpy; -if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){ -if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0) -cbp= 0; -} - -for (i = 0; i < 6; i++) { -if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ -s->block_last_index[i]= -1; -s->bdsp.clear_block(s->block[i]); -} -} -}else{ -cbp= 0; -for (i = 0; i < 6; i++) { -if (s->block_last_index[i] >= 0) -cbp |= 1 << (5 - i); -} -} -return cbp; -} #endif /* AVCODEC_H263_H */ diff --git a/libavcodec/h263enc.h b/libavcodec/h263enc.h new file mode 100644 index 00..31f00665ce --- /dev/null +++ b/libavcodec/h263enc.h @@ -0,0 +1,130 @@ +/* + * H.263 encoder header + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Les
[FFmpeg-devel] [PATCH v2 17/69] avcodec/mpeg4video.h: Move decoder-only parts to a new header
Signed-off-by: Andreas Rheinhardt --- libavcodec/h263dec.c | 1 + libavcodec/ituh263dec.c| 1 + libavcodec/mpeg4video.h| 66 --- libavcodec/mpeg4video_parser.c | 1 + libavcodec/mpeg4videodec.c | 1 + libavcodec/mpeg4videodec.h | 99 ++ libavcodec/mpegvideo.c | 2 +- libavcodec/msmpeg4dec.c| 2 +- libavcodec/nvdec_mpeg4.c | 1 + libavcodec/vaapi_mpeg4.c | 2 +- libavcodec/vdpau_mpeg4.c | 2 +- 11 files changed, 108 insertions(+), 70 deletions(-) create mode 100644 libavcodec/mpeg4videodec.h diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 5a54d57bbc..99dc7a74d2 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -41,6 +41,7 @@ #include "internal.h" #include "mpeg_er.h" #include "mpeg4video.h" +#include "mpeg4videodec.h" #if FF_API_FLAG_TRUNCATED #include "mpeg4video_parser.h" #endif diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c index 7d7a1f01a2..b09cc9a2db 100644 --- a/libavcodec/ituh263dec.c +++ b/libavcodec/ituh263dec.c @@ -48,6 +48,7 @@ #include "rv10.h" #include "mpeg4video.h" #include "mpegvideodata.h" +#include "mpeg4videodec.h" // The defines below define the number of bits that are read at once for // reading vlc values. Changing these may improve speed and data cache needs diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h index 14fc5e1396..bee52b2c29 100644 --- a/libavcodec/mpeg4video.h +++ b/libavcodec/mpeg4video.h @@ -70,86 +70,20 @@ /* smaller packets likely don't contain a real frame */ #define MAX_NVOP_SIZE 19 -typedef struct Mpeg4DecContext { -MpegEncContext m; - -/// number of bits to represent the fractional part of time -int time_increment_bits; -int shape; -int vol_sprite_usage; -int sprite_brightness_change; -int num_sprite_warping_points; -/// sprite trajectory points -uint16_t sprite_traj[4][2]; -/// sprite shift [isChroma] -int sprite_shift[2]; - -// reversible vlc -int rvlc; -/// could this stream contain resync markers -int resync_marker; -/// time distance of first I -> B, used for interlaced B-frames -int t_frame; - -int new_pred; -int enhancement_type; -int scalability; - -/// QP above which the ac VLC should be used for intra dc -int intra_dc_threshold; - -/* bug workarounds */ -int divx_version; -int divx_build; -int xvid_build; -int lavc_build; - -int vo_type; - -/// flag for having shown the warning about invalid Divx B-frames -int showed_packed_warning; -/** does the stream contain the low_delay flag, - * used to work around buggy encoders. */ -int vol_control_parameters; -int cplx_estimation_trash_i; -int cplx_estimation_trash_p; -int cplx_estimation_trash_b; - -int rgb; - -int32_t block32[12][64]; -// 0 = DCT, 1 = DPCM top to bottom scan, -1 = DPCM bottom to top scan -int dpcm_direction; -int16_t dpcm_macroblock[3][256]; -} Mpeg4DecContext; - - -void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, -uint8_t *dest_cr, int block_size, int uvlinesize, -int dct_linesize, int dct_offset); void ff_mpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y); -void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, - int dir); void ff_set_mpeg4_time(MpegEncContext *s); int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); -int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, - int header, int parse_only); void ff_mpeg4_encode_video_packet_header(MpegEncContext *s); void ff_mpeg4_clean_buffers(MpegEncContext *s); void ff_mpeg4_stuffing(PutBitContext *pbc); void ff_mpeg4_init_partitions(MpegEncContext *s); void ff_mpeg4_merge_partitions(MpegEncContext *s); void ff_clean_mpeg4_qscales(MpegEncContext *s); -int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx); int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s); -int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx); -int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx); void ff_mpeg4_init_direct_mv(MpegEncContext *s); -int ff_mpeg4_workaround_bugs(AVCodecContext *avctx); -int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size); /** * @return the mb_type diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c index 1f89bae490..3d0d0e4714 100644 --- a/libavcodec/mpeg4video_parser.c +++ b/libavcodec/mpeg4video_parser.c @@ -26,6 +26,7 @@ #include "parser.h" #include "mpegvideo.h" #include "mpeg4video.h" +#include "mpeg4videodec.h" #if FF_API_FLAG_TRUNCATED /* Nuke this header when removing FF_API_FLAG_TRUNCATED */ #
[FFmpeg-devel] [PATCH v2 18/69] avcodec/mpeg4video.h: Move encoder-only parts in a new file
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg4video.h| 12 --- libavcodec/mpeg4videoenc.c | 1 + libavcodec/mpeg4videoenc.h | 43 ++ libavcodec/mpegvideo_enc.c | 1 + 4 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 libavcodec/mpeg4videoenc.h diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h index bee52b2c29..ab65280756 100644 --- a/libavcodec/mpeg4video.h +++ b/libavcodec/mpeg4video.h @@ -25,7 +25,6 @@ #include -#include "get_bits.h" #include "mpegvideo.h" // shapes @@ -70,18 +69,7 @@ /* smaller packets likely don't contain a real frame */ #define MAX_NVOP_SIZE 19 -void ff_mpeg4_encode_mb(MpegEncContext *s, -int16_t block[6][64], -int motion_x, int motion_y); -void ff_set_mpeg4_time(MpegEncContext *s); -int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); - -void ff_mpeg4_encode_video_packet_header(MpegEncContext *s); void ff_mpeg4_clean_buffers(MpegEncContext *s); -void ff_mpeg4_stuffing(PutBitContext *pbc); -void ff_mpeg4_init_partitions(MpegEncContext *s); -void ff_mpeg4_merge_partitions(MpegEncContext *s); -void ff_clean_mpeg4_qscales(MpegEncContext *s); int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s); void ff_mpeg4_init_direct_mv(MpegEncContext *s); diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index 8a1a6cbcc8..d55667c1a6 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -30,6 +30,7 @@ #include "h263enc.h" #include "mpeg4video.h" #include "mpeg4videodata.h" +#include "mpeg4videoenc.h" #include "profiles.h" /* The uni_DCtab_* tables below contain unified bits+length tables to encode DC diff --git a/libavcodec/mpeg4videoenc.h b/libavcodec/mpeg4videoenc.h new file mode 100644 index 00..243cd297a2 --- /dev/null +++ b/libavcodec/mpeg4videoenc.h @@ -0,0 +1,43 @@ +/* + * MPEG-4 encoder internal header. + * Copyright (c) 2000,2001 Fabrice Bellard + * Copyright (c) 2002-2010 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_MPEG4VIDEOENC_H +#define AVCODEC_MPEG4VIDEOENC_H + +#include + +#include "mpegvideo.h" +#include "put_bits.h" + +void ff_mpeg4_encode_mb(MpegEncContext *s, +int16_t block[6][64], +int motion_x, int motion_y); +void ff_set_mpeg4_time(MpegEncContext *s); +int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); + +void ff_mpeg4_encode_video_packet_header(MpegEncContext *s); +void ff_mpeg4_stuffing(PutBitContext *pbc); +void ff_mpeg4_init_partitions(MpegEncContext *s); +void ff_mpeg4_merge_partitions(MpegEncContext *s); +void ff_clean_mpeg4_qscales(MpegEncContext *s); + +#endif diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index a57de01944..460462d997 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -66,6 +66,7 @@ #include "flv.h" #include "mpeg4video.h" #include "mpeg4videodata.h" +#include "mpeg4videoenc.h" #include "internal.h" #include "bytestream.h" #include "wmv2enc.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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 19/69] avcodec/flv.h: Split header into encoder-only and decoder-only headers
Signed-off-by: Andreas Rheinhardt --- libavcodec/flvdec.c| 2 +- libavcodec/flvdec.h| 29 + libavcodec/flvenc.c| 2 +- libavcodec/{flv.h => flvenc.h} | 9 +++-- libavcodec/h263dec.c | 2 +- libavcodec/ituh263dec.c| 3 --- libavcodec/ituh263enc.c| 2 +- libavcodec/mpegvideo_enc.c | 2 +- 8 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 libavcodec/flvdec.h rename libavcodec/{flv.h => flvenc.h} (87%) diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c index 2bd86b5b47..62bb32bc62 100644 --- a/libavcodec/flvdec.c +++ b/libavcodec/flvdec.c @@ -20,7 +20,7 @@ #include "libavutil/imgutils.h" -#include "flv.h" +#include "flvdec.h" #include "h263dec.h" #include "mpegvideo.h" #include "mpegvideodata.h" diff --git a/libavcodec/flvdec.h b/libavcodec/flvdec.h new file mode 100644 index 00..3527d82beb --- /dev/null +++ b/libavcodec/flvdec.h @@ -0,0 +1,29 @@ +/* + * FLV decoder header. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_FLVDEC_H +#define AVCODEC_FLVDEC_H + +#include "get_bits.h" +#include "mpegvideo.h" + +int ff_flv_decode_picture_header(MpegEncContext *s); + +#endif /* AVCODEC_FLVDEC_H */ diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c index 158b399c40..7271d64af3 100644 --- a/libavcodec/flvenc.c +++ b/libavcodec/flvenc.c @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "flv.h" +#include "flvenc.h" #include "h263data.h" #include "mpegvideo.h" #include "mpegvideodata.h" diff --git a/libavcodec/flv.h b/libavcodec/flvenc.h similarity index 87% rename from libavcodec/flv.h rename to libavcodec/flvenc.h index 561cfe0baa..aaa0fcffab 100644 --- a/libavcodec/flv.h +++ b/libavcodec/flvenc.h @@ -1,5 +1,5 @@ /* - * FLV specific private header. + * FLV encoder header. * * This file is part of FFmpeg. * @@ -18,10 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_FLV_H -#define AVCODEC_FLV_H +#ifndef AVCODEC_FLVENC_H +#define AVCODEC_FLVENC_H -#include "get_bits.h" #include "mpegvideo.h" #include "put_bits.h" @@ -29,6 +28,4 @@ void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number); void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last); -int ff_flv_decode_picture_header(MpegEncContext *s); - #endif /* AVCODEC_FLV_H */ diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 99dc7a74d2..bf2e9b1583 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -31,7 +31,7 @@ #include "avcodec.h" #include "error_resilience.h" -#include "flv.h" +#include "flvdec.h" #include "h263.h" #include "h263dec.h" #if FF_API_FLAG_TRUNCATED diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c index b09cc9a2db..5588840c3d 100644 --- a/libavcodec/ituh263dec.c +++ b/libavcodec/ituh263dec.c @@ -28,7 +28,6 @@ */ #define UNCHECKED_BITSTREAM_READER 1 -#include #include "libavutil/attributes.h" #include "libavutil/imgutils.h" @@ -40,11 +39,9 @@ #include "h263.h" #include "h263data.h" #include "h263dec.h" -#include "internal.h" #include "mathops.h" #include "mpegutils.h" #include "unary.h" -#include "flv.h" #include "rv10.h" #include "mpeg4video.h" #include "mpegvideodata.h" diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c index 70ac1f643b..c8a95574d2 100644 --- a/libavcodec/ituh263enc.c +++ b/libavcodec/ituh263enc.c @@ -34,12 +34,12 @@ #include "avcodec.h" #include "mpegvideo.h" #include "mpegvideodata.h" +#include "flvenc.h" #include "h263.h" #include "h263enc.h" #include "h263data.h" #include "mathops.h" #include "mpegutils.h" -#include "flv.h" #include "internal.h" /** diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 460462d997..7c5d013200 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -63,7 +63,7 @@ #include "faandct.h" #include "thread.h" #include "aandcttab.h" -#include "flv.h" +#include "flvenc.h" #include "mpeg4video.h" #include "mpeg4videodata.h" #include "mpeg4videoenc.h" -- 2.32.0 ___
[FFmpeg-devel] [PATCH v2 20/69] avcodec/mpeg12.h: Move decoder-only stuff to a new header
Signed-off-by: Andreas Rheinhardt --- libavcodec/eatqi.c | 2 +- libavcodec/mdec.c | 3 ++- libavcodec/mpeg12.c| 7 ++--- libavcodec/mpeg12.h| 31 -- libavcodec/mpeg12dec.c | 3 +-- libavcodec/mpeg12dec.h | 60 ++ libavcodec/speedhq.c | 4 ++- 7 files changed, 69 insertions(+), 41 deletions(-) create mode 100644 libavcodec/mpeg12dec.h diff --git a/libavcodec/eatqi.c b/libavcodec/eatqi.c index 8f502b3c56..51eff20b65 100644 --- a/libavcodec/eatqi.c +++ b/libavcodec/eatqi.c @@ -36,8 +36,8 @@ #include "eaidct.h" #include "idctdsp.h" #include "internal.h" -#include "mpeg12.h" #include "mpeg12data.h" +#include "mpeg12dec.h" typedef struct TqiContext { AVCodecContext *avctx; diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c index 007e7fada8..759967e28f 100644 --- a/libavcodec/mdec.c +++ b/libavcodec/mdec.c @@ -33,8 +33,9 @@ #include "blockdsp.h" #include "bswapdsp.h" #include "idctdsp.h" -#include "mpeg12.h" +#include "internal.h" #include "mpeg12data.h" +#include "mpeg12dec.h" #include "thread.h" typedef struct MDECContext { diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 58e03c05d4..ecb0706cf5 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -29,18 +29,15 @@ #include "libavutil/attributes.h" #include "libavutil/avassert.h" -#include "libavutil/timecode.h" #include "libavutil/thread.h" #include "internal.h" #include "avcodec.h" #include "mpegvideo.h" -#include "error_resilience.h" #include "mpeg12.h" #include "mpeg12data.h" +#include "mpeg12dec.h" #include "mpegvideodata.h" -#include "bytestream.h" -#include "thread.h" static const uint8_t table_mb_ptype[7][2] = { { 3, 5 }, // 0x01 MB_INTRA @@ -238,7 +235,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, int ff_mpeg1_decode_block_intra(GetBitContext *gb, const uint16_t *quant_matrix, -uint8_t *const scantable, int last_dc[3], +const uint8_t *scantable, int last_dc[3], int16_t *block, int index, int qscale) { int dc, diff, i = 0, component; diff --git a/libavcodec/mpeg12.h b/libavcodec/mpeg12.h index fb2b37e7c8..a405db6c2d 100644 --- a/libavcodec/mpeg12.h +++ b/libavcodec/mpeg12.h @@ -22,7 +22,6 @@ #ifndef AVCODEC_MPEG12_H #define AVCODEC_MPEG12_H -#include "mpeg12vlc.h" #include "mpegvideo.h" /* Start codes. */ @@ -37,38 +36,8 @@ void ff_mpeg12_common_init(MpegEncContext *s); -#define INIT_2D_VLC_RL(rl, static_size, flags)\ -{\ -static RL_VLC_ELEM rl_vlc_table[static_size];\ -rl.rl_vlc[0] = rl_vlc_table;\ -ff_init_2d_vlc_rl(&rl, static_size, flags);\ -} - -void ff_init_2d_vlc_rl(RLTable *rl, unsigned static_size, int flags); void ff_mpeg1_init_uni_ac_vlc(const RLTable *rl, uint8_t *uni_ac_vlc_len); -static inline int decode_dc(GetBitContext *gb, int component) -{ -int code, diff; - -if (component == 0) { -code = get_vlc2(gb, ff_dc_lum_vlc.table, DC_VLC_BITS, 2); -} else { -code = get_vlc2(gb, ff_dc_chroma_vlc.table, DC_VLC_BITS, 2); -} -if (code == 0) { -diff = 0; -} else { -diff = get_xbits(gb, code); -} -return diff; -} - -int ff_mpeg1_decode_block_intra(GetBitContext *gb, -const uint16_t *quant_matrix, -uint8_t *const scantable, int last_dc[3], -int16_t *block, int index, int qscale); - void ff_mpeg1_clean_buffers(MpegEncContext *s); #if FF_API_FLAG_TRUNCATED int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s); diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 4a7bd6d466..d55a4d2feb 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -34,10 +34,8 @@ #include "libavutil/mem_internal.h" #include "libavutil/stereo3d.h" #include "libavutil/timecode.h" -#include "libavutil/video_enc_params.h" #include "avcodec.h" -#include "bytestream.h" #include "error_resilience.h" #include "hwconfig.h" #include "idctdsp.h" @@ -45,6 +43,7 @@ #include "mpeg_er.h" #include "mpeg12.h" #include "mpeg12data.h" +#include "mpeg12dec.h" #include "mpegutils.h" #include "mpegvideo.h" #include "mpegvideodata.h" diff --git a/libavcodec/mpeg12dec.h b/libavcodec/mpeg12dec.h new file mode 100644 index 00..b4e94a92ce --- /dev/null +++ b/libavcodec/mpeg12dec.h @@ -0,0 +1,60 @@ +/* + * MPEG-1/2 decoder header + * Copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in t
[FFmpeg-devel] [PATCH v2 21/69] avcodec/mpeg12.h: Move encoder-only stuff into a new header
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg12.h| 8 libavcodec/mpeg12enc.c | 2 +- libavcodec/mpeg12enc.h | 38 ++ libavcodec/mpegvideo_enc.c | 1 + libavcodec/speedhqenc.c| 3 +-- 5 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 libavcodec/mpeg12enc.h diff --git a/libavcodec/mpeg12.h b/libavcodec/mpeg12.h index a405db6c2d..e0406b32d9 100644 --- a/libavcodec/mpeg12.h +++ b/libavcodec/mpeg12.h @@ -36,19 +36,11 @@ void ff_mpeg12_common_init(MpegEncContext *s); -void ff_mpeg1_init_uni_ac_vlc(const RLTable *rl, uint8_t *uni_ac_vlc_len); - void ff_mpeg1_clean_buffers(MpegEncContext *s); #if FF_API_FLAG_TRUNCATED int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s); #endif -void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); -void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64], -int motion_x, int motion_y); -void ff_mpeg1_encode_init(MpegEncContext *s); -void ff_mpeg1_encode_slice_header(MpegEncContext *s); - void ff_mpeg12_find_best_frame_rate(AVRational frame_rate, int *code, int *ext_n, int *ext_d, int nonstandard); diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index 9c0be69ded..3acb82ac9d 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -37,10 +37,10 @@ #include "libavutil/stereo3d.h" #include "avcodec.h" -#include "bytestream.h" #include "mathops.h" #include "mpeg12.h" #include "mpeg12data.h" +#include "mpeg12enc.h" #include "mpegutils.h" #include "mpegvideo.h" #include "profiles.h" diff --git a/libavcodec/mpeg12enc.h b/libavcodec/mpeg12enc.h new file mode 100644 index 00..fbbc43f891 --- /dev/null +++ b/libavcodec/mpeg12enc.h @@ -0,0 +1,38 @@ +/* + * MPEG-1/2 encoder header + * Copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_MPEG12ENC_H +#define AVCODEC_MPEG12ENC_H + +#include + +#include "mpegvideo.h" +#include "rl.h" + +void ff_mpeg1_init_uni_ac_vlc(const RLTable *rl, uint8_t *uni_ac_vlc_len); + +void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); +void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64], +int motion_x, int motion_y); +void ff_mpeg1_encode_init(MpegEncContext *s); +void ff_mpeg1_encode_slice_header(MpegEncContext *s); + +#endif /* AVCODEC_MPEG12ENC_H */ diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 7c5d013200..aaa1488977 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -46,6 +46,7 @@ #include "idctdsp.h" #include "mpeg12.h" #include "mpeg12data.h" +#include "mpeg12enc.h" #include "mpegvideo.h" #include "mpegvideodata.h" #include "h261enc.h" diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c index 6df0316611..2a310a6c4f 100644 --- a/libavcodec/speedhqenc.c +++ b/libavcodec/speedhqenc.c @@ -27,12 +27,11 @@ * SpeedHQ encoder. */ -#include "libavutil/pixdesc.h" #include "libavutil/thread.h" #include "avcodec.h" -#include "mpeg12.h" #include "mpeg12data.h" +#include "mpeg12enc.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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 22/69] avcodec/rv10.h: Split header into decoder- and encoder-only parts
Signed-off-by: Andreas Rheinhardt --- libavcodec/ituh263dec.c | 2 +- libavcodec/mpegvideo_enc.c | 2 +- libavcodec/rv10.c| 2 +- libavcodec/rv10dec.h | 28 libavcodec/rv10enc.c | 2 +- libavcodec/{rv10.h => rv10enc.h} | 12 libavcodec/rv20enc.c | 2 +- 7 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 libavcodec/rv10dec.h rename libavcodec/{rv10.h => rv10enc.h} (85%) diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c index 5588840c3d..77ca0d7e40 100644 --- a/libavcodec/ituh263dec.c +++ b/libavcodec/ituh263dec.c @@ -42,7 +42,7 @@ #include "mathops.h" #include "mpegutils.h" #include "unary.h" -#include "rv10.h" +#include "rv10dec.h" #include "mpeg4video.h" #include "mpegvideodata.h" #include "mpeg4videodec.h" diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index aaa1488977..a8146c6473 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -71,7 +71,7 @@ #include "internal.h" #include "bytestream.h" #include "wmv2enc.h" -#include "rv10.h" +#include "rv10enc.h" #include "packet_internal.h" #include #include "sp5x.h" diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 4dfaa3460d..241ee53442 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -41,7 +41,7 @@ #include "mpegvideo.h" #include "mpeg4video.h" #include "mpegvideodata.h" -#include "rv10.h" +#include "rv10dec.h" #define RV_GET_MAJOR_VER(x) ((x) >> 28) #define RV_GET_MINOR_VER(x) (((x) >> 20) & 0xFF) diff --git a/libavcodec/rv10dec.h b/libavcodec/rv10dec.h new file mode 100644 index 00..daa6b8d653 --- /dev/null +++ b/libavcodec/rv10dec.h @@ -0,0 +1,28 @@ +/* + * RV10/RV20 decoder + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_RV10DEC_H +#define AVCODEC_RV10DEC_H + +#include "mpegvideo.h" + +int ff_rv_decode_dc(MpegEncContext *s, int n); + +#endif /* AVCODEC_RV10DEC_H */ diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c index 72b25e0c55..dbc7a370f4 100644 --- a/libavcodec/rv10enc.c +++ b/libavcodec/rv10enc.c @@ -27,7 +27,7 @@ #include "mpegvideo.h" #include "put_bits.h" -#include "rv10.h" +#include "rv10enc.h" int ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number) { diff --git a/libavcodec/rv10.h b/libavcodec/rv10enc.h similarity index 85% rename from libavcodec/rv10.h rename to libavcodec/rv10enc.h index 364270e76a..66672f8087 100644 --- a/libavcodec/rv10.h +++ b/libavcodec/rv10enc.h @@ -1,5 +1,5 @@ /* - * RV10/RV20 decoder + * RV10/RV20 encoder * * This file is part of FFmpeg. * @@ -18,16 +18,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_RV10_H -#define AVCODEC_RV10_H - -#include +#ifndef AVCODEC_RV10ENC_H +#define AVCODEC_RV10ENC_H #include "mpegvideo.h" -int ff_rv_decode_dc(MpegEncContext *s, int n); - int ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number); void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number); -#endif /* AVCODEC_RV10_H */ +#endif /* AVCODEC_RV10ENC_H */ diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c index 204cd03a24..892107f1f8 100644 --- a/libavcodec/rv20enc.c +++ b/libavcodec/rv20enc.c @@ -30,7 +30,7 @@ #include "h263data.h" #include "h263enc.h" #include "put_bits.h" -#include "rv10.h" +#include "rv10enc.h" void ff_rv20_encode_picture_header(MpegEncContext *s, int picture_number){ put_bits(&s->pb, 2, s->pict_type); //I 0 vs. 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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 23/69] avcodec/mpegvideo: Move encoder-only stuff to a new header
Signed-off-by: Andreas Rheinhardt --- libavcodec/dnxhdenc.c | 1 + libavcodec/flvdec.c | 1 + libavcodec/flvenc.c | 1 + libavcodec/h261enc.c| 1 + libavcodec/h263enc.h| 2 +- libavcodec/intelh263dec.c | 1 + libavcodec/ituh263enc.c | 1 + libavcodec/libxavs2.c | 2 + libavcodec/me_cmp.c | 2 +- libavcodec/mjpegenc.c | 1 + libavcodec/motion_est.c | 2 +- libavcodec/mpeg12enc.c | 1 + libavcodec/mpeg4videoenc.c | 1 + libavcodec/mpegvideo.h | 127 - libavcodec/mpegvideo_enc.c | 1 + libavcodec/mpegvideoenc.h | 161 libavcodec/msmpeg4enc.c | 1 + libavcodec/nvdec_mpeg12.c | 1 + libavcodec/nvdec_mpeg4.c| 1 + libavcodec/ratecontrol.c| 2 +- libavcodec/rv10enc.c| 1 + libavcodec/rv20enc.c| 1 + libavcodec/rv30.c | 1 + libavcodec/rv40.c | 1 + libavcodec/speedhqenc.c | 1 + libavcodec/vaapi_encode_mpeg2.c | 2 + libavcodec/wmv2enc.c| 1 + libavcodec/x86/mpegvideoenc.c | 2 +- 28 files changed, 189 insertions(+), 132 deletions(-) create mode 100644 libavcodec/mpegvideoenc.h diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index ca67964330..ac92474e56 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -34,6 +34,7 @@ #include "fdctdsp.h" #include "internal.h" #include "mpegvideo.h" +#include "mpegvideoenc.h" #include "pixblockdsp.h" #include "packet_internal.h" #include "profiles.h" diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c index 62bb32bc62..dacc64c81c 100644 --- a/libavcodec/flvdec.c +++ b/libavcodec/flvdec.c @@ -22,6 +22,7 @@ #include "flvdec.h" #include "h263dec.h" +#include "internal.h" #include "mpegvideo.h" #include "mpegvideodata.h" diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c index 7271d64af3..663a33c959 100644 --- a/libavcodec/flvenc.c +++ b/libavcodec/flvenc.c @@ -22,6 +22,7 @@ #include "h263data.h" #include "mpegvideo.h" #include "mpegvideodata.h" +#include "mpegvideoenc.h" void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number) { diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c index 66b7cc18fd..7d6a559f46 100644 --- a/libavcodec/h261enc.c +++ b/libavcodec/h261enc.c @@ -34,6 +34,7 @@ #include "h261.h" #include "h261enc.h" #include "mpegvideodata.h" +#include "mpegvideoenc.h" static uint8_t uni_h261_rl_len [64*64*2*2]; #define UNI_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level)) diff --git a/libavcodec/h263enc.h b/libavcodec/h263enc.h index 31f00665ce..fff85a18f2 100644 --- a/libavcodec/h263enc.h +++ b/libavcodec/h263enc.h @@ -22,7 +22,7 @@ #include #include "h263data.h" -#include "mpegvideo.h" +#include "mpegvideoenc.h" void ff_h263_encode_init(MpegEncContext *s); void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number); diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c index 9dde247298..b61effa4df 100644 --- a/libavcodec/intelh263dec.c +++ b/libavcodec/intelh263dec.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "internal.h" #include "mpegutils.h" #include "mpegvideo.h" #include "h263data.h" diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c index c8a95574d2..11d8873253 100644 --- a/libavcodec/ituh263enc.c +++ b/libavcodec/ituh263enc.c @@ -35,6 +35,7 @@ #include "mpegvideo.h" #include "mpegvideodata.h" #include "flvenc.h" +#include "mpegvideoenc.h" #include "h263.h" #include "h263enc.h" #include "h263data.h" diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c index 9c5a576e90..4742b18f9f 100644 --- a/libavcodec/libxavs2.c +++ b/libavcodec/libxavs2.c @@ -24,8 +24,10 @@ #include "xavs2.h" #include "encode.h" +#include "internal.h" #include "mpeg12.h" #include "libavutil/avstring.h" +#include "libavutil/opt.h" #define xavs2_opt_set2(name, format, ...) do{ \ char opt_str[16] = {0}; \ diff --git a/libavcodec/me_cmp.c b/libavcodec/me_cmp.c index 60545248b3..b2f87d2e1b 100644 --- a/libavcodec/me_cmp.c +++ b/libavcodec/me_cmp.c @@ -27,7 +27,7 @@ #include "copy_block.h" #include "simple_idct.h" #include "me_cmp.h" -#include "mpegvideo.h" +#include "mpegvideoenc.h" #include "config.h" /* (i - 256) * (i - 256) */ diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index 6a47503ab4..b9b17a50df 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -39,6 +39,7 @@ #include "mpegvideo.h" #include "mjpeg.h" #include "mjpegenc.h" +#include "mpegvideoenc.h" #include "profiles.h" /* The following is the private context of MJPEG/AMV decoder. diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index 5b0958733c..35ca40b90a 100644 --- a/libavcodec/motion_es
[FFmpeg-devel] [PATCH v2 24/69] avcodec/mpegvideo: Move decoder-only stuff to a new header
Signed-off-by: Andreas Rheinhardt --- libavcodec/dxva2_vc1.c | 1 + libavcodec/h261dec.c | 1 + libavcodec/h263dec.c | 1 + libavcodec/mpeg12dec.c | 1 + libavcodec/mpeg4videodec.c | 1 + libavcodec/mpegvideo.h | 28 libavcodec/mpegvideo_dec.c | 1 + libavcodec/mpegvideodec.h | 67 ++ libavcodec/mss2.c | 1 + libavcodec/rv10.c | 1 + libavcodec/rv30.c | 1 + libavcodec/rv34.c | 1 + libavcodec/rv40.c | 1 + libavcodec/vaapi_mpeg2.c | 1 + libavcodec/vaapi_mpeg4.c | 1 + libavcodec/vaapi_vc1.c | 1 + libavcodec/vc1_block.c | 1 + libavcodec/vc1dec.c| 1 + libavcodec/vdpau.c | 1 + 19 files changed, 84 insertions(+), 28 deletions(-) create mode 100644 libavcodec/mpegvideodec.h diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c index f08ac8b5a0..5fd6957d0c 100644 --- a/libavcodec/dxva2_vc1.c +++ b/libavcodec/dxva2_vc1.c @@ -22,6 +22,7 @@ #include "dxva2_internal.h" #include "mpegutils.h" +#include "mpegvideodec.h" #include "vc1.h" #include "vc1data.h" diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index 17f1067b15..5e732b05bf 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -31,6 +31,7 @@ #include "mpeg_er.h" #include "mpegutils.h" #include "mpegvideo.h" +#include "mpegvideodec.h" #include "h261.h" #include "internal.h" diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index bf2e9b1583..df9ac2f831 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -47,6 +47,7 @@ #endif #include "mpegutils.h" #include "mpegvideo.h" +#include "mpegvideodec.h" #include "msmpeg4dec.h" #include "qpeldsp.h" #include "thread.h" diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index d55a4d2feb..a3a7e86ccf 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -47,6 +47,7 @@ #include "mpegutils.h" #include "mpegvideo.h" #include "mpegvideodata.h" +#include "mpegvideodec.h" #include "profiles.h" #include "thread.h" #include "xvmc_internal.h" diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index a437f233ec..6d7f7f66f9 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -33,6 +33,7 @@ #include "mpegutils.h" #include "mpegvideo.h" #include "mpegvideodata.h" +#include "mpegvideodec.h" #include "mpeg4video.h" #include "mpeg4videodata.h" #include "mpeg4videodec.h" diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index e16f850f30..c4ac7bc966 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -44,7 +44,6 @@ #include "mpegpicture.h" #include "mpegvideodsp.h" #include "mpegvideoencdsp.h" -#include "mpegvideodata.h" #include "pixblockdsp.h" #include "put_bits.h" #include "ratecontrol.h" @@ -586,31 +585,13 @@ int ff_mpv_init_context_frame(MpegEncContext *s); */ 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); - -int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx); -void ff_mpv_frame_end(MpegEncContext *s); void ff_clean_intra_table_entries(MpegEncContext *s); -void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h); -void ff_mpeg_flush(AVCodecContext *avctx); - -void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict); - -int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type); int ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src); -int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src); void ff_set_qscale(MpegEncContext * s, int qscale); void ff_mpv_idct_init(MpegEncContext *s); @@ -638,13 +619,4 @@ static inline void ff_update_block_index(MpegEncContext *s){ s->dest[2]+= (2 >> s->chroma_x_shift) * block_size; } -static inline int mpeg_get_qscale(MpegEncContext *s) -{ -int qscale = get_bits(&s->gb, 5); -if (s->q_scale_type) -return ff_mpeg2_non_linear_qscale[qscale]; -else -return qscale << 1; -} - #endif /* AVCODEC_MPEGVIDEO_H */ diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index cc23e070ea..b1b15c7fcf 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -31,6 +31,7 @@ #include "internal.h" #include "mpegutils.h" #include "mpegvideo.h" +#include "mpegvideodec.h" #include "thread.h" void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx) diff --git a/libavcodec/mpegvideodec.h b/libavcodec/mpegvideodec.h new file mode 100644
[FFmpeg-devel] [PATCH v2 25/69] avcodec/speedhqenc: Add SpeedHQEncContext and move slice_start to it
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 3 --- libavcodec/speedhqenc.c | 19 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index c4ac7bc966..e31ad2ccff 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -419,9 +419,6 @@ typedef struct MpegEncContext { int inter_intra_pred; int mspel; -/* SpeedHQ specific */ -int slice_start; - /* decompression specific */ GetBitContext gb; diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c index 5b40011e40..2a8ddebb0a 100644 --- a/libavcodec/speedhqenc.c +++ b/libavcodec/speedhqenc.c @@ -54,6 +54,12 @@ static uint32_t speedhq_chr_dc_uni[512]; static uint8_t uni_speedhq_ac_vlc_len[64 * 64 * 2]; +typedef struct SpeedHQEncContext { +MpegEncContext m; + +int slice_start; +} SpeedHQEncContext; + static av_cold void speedhq_init_static_data(void) { ff_rl_init(&ff_rl_speedhq, speedhq_static_rl_table_store); @@ -121,24 +127,27 @@ av_cold int ff_speedhq_encode_init(MpegEncContext *s) void ff_speedhq_encode_picture_header(MpegEncContext *s) { +SpeedHQEncContext *ctx = (SpeedHQEncContext*)s; + put_bits_le(&s->pb, 8, 100 - s->qscale * 2); /* FIXME why doubled */ put_bits_le(&s->pb, 24, 4); /* no second field */ +ctx->slice_start = 4; /* length of first slice, will be filled out later */ -s->slice_start = 4; put_bits_le(&s->pb, 24, 0); } void ff_speedhq_end_slice(MpegEncContext *s) { +SpeedHQEncContext *ctx = (SpeedHQEncContext*)s; int slice_len; flush_put_bits_le(&s->pb); -slice_len = s->pb.buf_ptr - (s->pb.buf + s->slice_start); -AV_WL24(s->pb.buf + s->slice_start, slice_len); +slice_len = put_bytes_output(&s->pb) - ctx->slice_start; +AV_WL24(s->pb.buf + ctx->slice_start, slice_len); /* length of next slice, will be filled out later */ -s->slice_start = s->pb.buf_ptr - s->pb.buf; +ctx->slice_start = put_bytes_output(&s->pb); put_bits_le(&s->pb, 24, 0); } @@ -271,7 +280,7 @@ const AVCodec ff_speedhq_encoder = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_SPEEDHQ, .priv_class = &ff_mpv_enc_class, -.priv_data_size = sizeof(MpegEncContext), +.priv_data_size = sizeof(SpeedHQEncContext), .init = ff_mpv_encode_init, .encode2= ff_mpv_encode_picture, .close = ff_mpv_encode_end, -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 27/69] avcodec/mpegvideo_enc: Don't find encoder by ID
mpegvideo-based encoders supporting bframes implement this by opening encoders of their own to test how long the chains of bframes are supposed to be. The needed AVCodec was obtained via avcodec_find_encoder(). This is complicated, as the current encoder can be directly obtained. And it also is not guaranteed that one actually gets the current encoder or not another encoder for the same codec ID (the latter does not seem to be the case now). Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 20c61dc0a6..5bf135bccf 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1218,7 +1218,6 @@ static int encode_frame(AVCodecContext *c, AVFrame *frame, AVPacket *pkt) static int estimate_best_b_count(MPVMainEncContext *s) { -const AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id); AVPacket *pkt; const int scale = s->brd_scale; int width = s->width >> scale; @@ -1302,7 +1301,7 @@ static int estimate_best_b_count(MPVMainEncContext *s) c->time_base= s->avctx->time_base; c->max_b_frames = s->max_b_frames; -ret = avcodec_open2(c, codec, NULL); +ret = avcodec_open2(c, s->avctx->codec, NULL); if (ret < 0) goto fail; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 29/69] avcodec/mpegvideoenc: Move tmp bframes to MPVMainEncContext
Also move b_frame_strategy and b_sensitivity; they are all only used by an encoder's main thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 7 - libavcodec/mpegvideo_enc.c | 61 +++--- libavcodec/mpegvideoenc.h | 15 +++--- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index a32bd277eb..017aadb3e7 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -56,8 +56,6 @@ #define MAX_THREADS 32 -#define MAX_B_FRAMES 16 - /** * MPVContext. */ @@ -528,11 +526,6 @@ typedef struct MPVContext { int error_rate; -/* temporary frames used by b_frame_strategy = 2 */ -AVFrame *tmp_frames[MAX_B_FRAMES + 2]; -int b_frame_strategy; -int b_sensitivity; - /* frame skip options for encoding */ int frame_skip_threshold; int frame_skip_factor; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 5f607d9e11..e365f2fd81 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -354,10 +354,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) } s->gop_size = avctx->gop_size; s->avctx= avctx; -if (avctx->max_b_frames > MAX_B_FRAMES) { +if (avctx->max_b_frames > MPVENC_MAX_B_FRAMES) { av_log(avctx, AV_LOG_ERROR, "Too many B-frames requested, maximum " - "is %d.\n", MAX_B_FRAMES); -avctx->max_b_frames = MAX_B_FRAMES; + "is " AV_STRINGIFY(MPVENC_MAX_B_FRAMES) ".\n"); +avctx->max_b_frames = MPVENC_MAX_B_FRAMES; } else if (avctx->max_b_frames < 0) { av_log(avctx, AV_LOG_ERROR, "max b frames must be 0 or positive for mpegvideo based encoders\n"); @@ -612,10 +612,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } -if (s->b_frame_strategy && (avctx->flags & AV_CODEC_FLAG_PASS2)) { +if (m->b_frame_strategy && (avctx->flags & AV_CODEC_FLAG_PASS2)) { av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n"); -s->b_frame_strategy = 0; +m->b_frame_strategy = 0; } i = av_gcd(avctx->time_base.den, avctx->time_base.num); @@ -904,17 +904,17 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) if ((ret = ff_rate_control_init(m)) < 0) return ret; -if (s->b_frame_strategy == 2) { +if (m->b_frame_strategy == 2) { for (i = 0; i < s->max_b_frames + 2; i++) { -s->tmp_frames[i] = av_frame_alloc(); -if (!s->tmp_frames[i]) +m->tmp_frames[i] = av_frame_alloc(); +if (!m->tmp_frames[i]) return AVERROR(ENOMEM); -s->tmp_frames[i]->format = AV_PIX_FMT_YUV420P; -s->tmp_frames[i]->width = s->width >> s->brd_scale; -s->tmp_frames[i]->height = s->height >> s->brd_scale; +m->tmp_frames[i]->format = AV_PIX_FMT_YUV420P; +m->tmp_frames[i]->width = s->width >> s->brd_scale; +m->tmp_frames[i]->height = s->height >> s->brd_scale; -ret = av_frame_get_buffer(s->tmp_frames[i], 0); +ret = av_frame_get_buffer(m->tmp_frames[i], 0); if (ret < 0) return ret; } @@ -935,14 +935,13 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) { MPVMainEncContext *const m = avctx->priv_data; MPVMainContext *const s = &m->common; -int i; ff_rate_control_uninit(m); ff_mpv_common_end(&m->common); -for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++) -av_frame_free(&s->tmp_frames[i]); +for (int i = 0; i < FF_ARRAY_ELEMS(m->tmp_frames); i++) +av_frame_free(&m->tmp_frames[i]); ff_mpv_picture_free(avctx, &s->new_picture); @@ -1267,18 +1266,18 @@ static int estimate_best_b_count(MPVMainEncContext *m) data[2] += INPLACE_OFFSET; } -s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[0], - s->tmp_frames[i]->linesize[0], +s->mpvencdsp.shrink[scale](m->tmp_frames[i]->data[0], + m->tmp_frames[i]->linesize[0], data[0], pre_input.f->linesize[0], width, height); -s->mpvencdsp.shrink[scale](s->tmp_frames[i]->data[1], - s->tmp_frames[i]->linesize[1], +s->mpvencdsp.shrink[scale](m->tmp_frames[i]->data[1], + m->tmp_frames[i]->linesize[1], data[1], pre_input.f->linesize[1], width >> 1, height >> 1); -s->mpvencdsp.shrink[scale](s->tmp_frames[i]->
[FFmpeg-devel] [PATCH v2 28/69] avcodec/mpegvideoenc: Add proper MPVMainEncContext
This is in preparation for moving fields only used by the main encoder thread from MPVContext to MPVMainEncContext. Signed-off-by: Andreas Rheinhardt --- libavcodec/dnxhdenc.c | 302 +++-- libavcodec/flvenc.c| 3 +- libavcodec/h261enc.c | 15 +- libavcodec/ituh263enc.c| 13 +- libavcodec/mjpegenc.c | 24 +-- libavcodec/mpeg12enc.c | 23 +-- libavcodec/mpeg4videoenc.c | 41 ++--- libavcodec/mpegvideo_enc.c | 135 + libavcodec/mpegvideoenc.h | 7 +- libavcodec/msmpeg4enc.c| 12 +- libavcodec/ratecontrol.c | 59 +--- libavcodec/ratecontrol.h | 2 - libavcodec/rv10enc.c | 3 +- libavcodec/rv20enc.c | 3 +- libavcodec/snow.c | 11 +- libavcodec/snowenc.c | 170 +++-- libavcodec/speedhqenc.c| 8 +- libavcodec/svq1enc.c | 159 +-- libavcodec/wmv2enc.c | 12 +- 19 files changed, 542 insertions(+), 460 deletions(-) diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index 74989276b9..9ad95ac20a 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -267,30 +267,31 @@ static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias) int qscale, i; const uint8_t *luma_weight_table = ctx->cid_table->luma_weight; const uint8_t *chroma_weight_table = ctx->cid_table->chroma_weight; +MPVEncContext *const s = &ctx->m.common; -if (!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_l, ctx->m.avctx->qmax + 1) || -!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_c, ctx->m.avctx->qmax + 1) || -!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_l16, ctx->m.avctx->qmax + 1) || -!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_c16, ctx->m.avctx->qmax + 1)) +if (!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_l, s->avctx->qmax + 1) || +!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_c, s->avctx->qmax + 1) || +!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_l16, s->avctx->qmax + 1) || +!FF_ALLOCZ_TYPED_ARRAY(ctx->qmatrix_c16, s->avctx->qmax + 1)) return AVERROR(ENOMEM); if (ctx->bit_depth == 8) { for (i = 1; i < 64; i++) { -int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]]; +int j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; weight_matrix[j] = ctx->cid_table->luma_weight[i]; } -ff_convert_matrix(&ctx->m, ctx->qmatrix_l, ctx->qmatrix_l16, +ff_convert_matrix(s, ctx->qmatrix_l, ctx->qmatrix_l16, weight_matrix, ctx->intra_quant_bias, 1, - ctx->m.avctx->qmax, 1); + s->avctx->qmax, 1); for (i = 1; i < 64; i++) { -int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]]; +int j = s->idsp.idct_permutation[ff_zigzag_direct[i]]; weight_matrix[j] = ctx->cid_table->chroma_weight[i]; } -ff_convert_matrix(&ctx->m, ctx->qmatrix_c, ctx->qmatrix_c16, +ff_convert_matrix(s, ctx->qmatrix_c, ctx->qmatrix_c16, weight_matrix, ctx->intra_quant_bias, 1, - ctx->m.avctx->qmax, 1); + s->avctx->qmax, 1); -for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) { +for (qscale = 1; qscale <= s->avctx->qmax; qscale++) { for (i = 0; i < 64; i++) { ctx->qmatrix_l[qscale][i] <<= 2; ctx->qmatrix_c[qscale][i] <<= 2; @@ -302,7 +303,7 @@ static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias) } } else { // 10-bit -for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) { +for (qscale = 1; qscale <= s->avctx->qmax; qscale++) { for (i = 1; i < 64; i++) { int j = ff_zigzag_direct[i]; @@ -325,22 +326,23 @@ static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias) } } -ctx->m.q_chroma_intra_matrix16 = ctx->qmatrix_c16; -ctx->m.q_chroma_intra_matrix = ctx->qmatrix_c; -ctx->m.q_intra_matrix16= ctx->qmatrix_l16; -ctx->m.q_intra_matrix = ctx->qmatrix_l; +s->q_chroma_intra_matrix16 = ctx->qmatrix_c16; +s->q_chroma_intra_matrix = ctx->qmatrix_c; +s->q_intra_matrix16= ctx->qmatrix_l16; +s->q_intra_matrix = ctx->qmatrix_l; return 0; } static av_cold int dnxhd_init_rc(DNXHDEncContext *ctx) { -if (!FF_ALLOCZ_TYPED_ARRAY(ctx->mb_rc, (ctx->m.avctx->qmax + 1) * ctx->m.mb_num)) +MPVEncContext *const s = &ctx->m.common; +if (!FF_ALLOCZ_TYPED_ARRAY(ctx->mb_rc, (s->avctx->qmax + 1) * s->mb_num)) return AVERROR(ENOMEM); -if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) { -if (!FF_ALLOCZ_TYPED_ARRAY(ctx->mb_cmp, ctx->m.mb_num) || -!FF_ALLOCZ_TYPED_ARRAY(ctx->mb_cmp_tmp, ctx->m.mb_num)) +if (s->avctx->mb_decision !=
[FFmpeg-devel] [PATCH v2 30/69] avcodec/mpegvideoenc: Move ratecontrol to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 8 libavcodec/mpegvideo_enc.c | 38 +++--- libavcodec/mpegvideoenc.h | 8 libavcodec/ratecontrol.c | 31 +++ libavcodec/snowenc.c | 8 5 files changed, 46 insertions(+), 47 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 017aadb3e7..4811fc0ad6 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -46,7 +46,6 @@ #include "mpegvideoencdsp.h" #include "pixblockdsp.h" #include "put_bits.h" -#include "ratecontrol.h" #if FF_API_FLAG_TRUNCATED #include "parser.h" #endif @@ -312,13 +311,6 @@ typedef struct MPVContext { int dct_count[2]; uint16_t (*dct_offset)[64]; -/* bit rate control */ -int64_t total_bits; -int frame_bits;///< bits used for the current frame -int stuffing_bits; ///< bits used for stuffing -int next_lambda; ///< next lambda used for retrying to encode a frame -RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c - /* statistics, used for 2-pass encoding */ int mv_bits; int header_bits; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index e365f2fd81..37eeb68f15 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1407,15 +1407,15 @@ static int select_input_picture(MPVMainEncContext *m) for (i = 0; i < s->max_b_frames + 1; i++) { int pict_num = s->input_picture[0]->f->display_picture_number + i; -if (pict_num >= s->rc_context.num_entries) +if (pict_num >= m->rc_context.num_entries) break; if (!s->input_picture[i]) { -s->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P; +m->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P; break; } s->input_picture[i]->f->pict_type = -s->rc_context.entry[pict_num].new_pict_type; +m->rc_context.entry[pict_num].new_pict_type; } } @@ -1745,14 +1745,14 @@ vbv_retry: ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits); if (avctx->rc_buffer_size) { -RateControlContext *rcc = &s->rc_context; +RateControlContext *rcc = &m->rc_context; int max_size = FFMAX(rcc->buffer_index * avctx->rc_max_available_vbv_use, rcc->buffer_index - 500); int hq = (avctx->mb_decision == FF_MB_DECISION_RD || avctx->trellis); int min_step = hq ? 1 : (1<<(FF_LAMBDA_SHIFT + 7))/139; if (put_bits_count(&s->pb) > max_size && s->lambda < s->lmax) { -s->next_lambda = FFMAX(s->lambda + min_step, s->lambda * +m->next_lambda = FFMAX(s->lambda + min_step, s->lambda * (s->qscale + 1) / s->qscale); if (s->adaptive_quant) { int i; @@ -1803,10 +1803,10 @@ vbv_retry: s->misc_bits + s->i_tex_bits + s->p_tex_bits); flush_put_bits(&s->pb); -s->frame_bits = put_bits_count(&s->pb); +m->frame_bits = put_bits_count(&s->pb); -stuffing_count = ff_vbv_update(m, s->frame_bits); -s->stuffing_bits = 8*stuffing_count; +stuffing_count = ff_vbv_update(m, m->frame_bits); +m->stuffing_bits = 8 * stuffing_count; if (stuffing_count) { if (put_bytes_left(&s->pb, 0) < stuffing_count + 50) { av_log(avctx, AV_LOG_ERROR, "stuffing too large\n"); @@ -1830,10 +1830,10 @@ vbv_retry: break; default: av_log(avctx, AV_LOG_ERROR, "vbv buffer overflow\n"); -s->stuffing_bits = 0; +m->stuffing_bits = 0; } flush_put_bits(&s->pb); -s->frame_bits = put_bits_count(&s->pb); +m->frame_bits = put_bits_count(&s->pb); } /* update MPEG-1/2 vbv_delay for CBR */ @@ -1848,9 +1848,9 @@ vbv_retry: int vbv_delay, min_delay; double inbits = avctx->rc_max_rate * av_q2d(avctx->time_base); -intminbits = s->frame_bits - 8 * +intminbits = m->frame_bits - 8 * (s->vbv_delay_pos - 1); -double bits= s->rc_context.buffer_index + minbits - inbits; +double bits= m->rc_context.buffer_index + minbits - inbits; uint8_t *const vbv_delay_ptr = s->pb.buf + s->vbv_delay_pos; if (bits < 0) @@ -1885,7 +1885,7 @@
[FFmpeg-devel] [PATCH v2 31/69] avcodec/mpegvideo: Move me_pre and me_penalty_compensation to enc-ctx
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 2 -- libavcodec/mpegvideo_enc.c | 8 libavcodec/mpegvideoenc.h | 7 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 4811fc0ad6..c59d4848a8 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -236,8 +236,6 @@ typedef struct MPVContext { uint8_t (*p_field_select_table[2]); ///< Only the first element is allocated uint8_t (*b_field_select_table[2][2]); ///< Only the first element is allocated int motion_est; ///< ME algorithm -int me_penalty_compensation; -int me_pre; ///< prepass for motion estimation int mv_dir; #define MV_DIR_FORWARD 1 #define MV_DIR_BACKWARD 2 diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 37eeb68f15..b67f706504 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -3563,11 +3563,11 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) /* Estimate motion for every MB */ if(s->pict_type != AV_PICTURE_TYPE_I){ -s->lambda = (s->lambda * s->me_penalty_compensation + 128) >> 8; -s->lambda2 = (s->lambda2 * (int64_t) s->me_penalty_compensation + 128) >> 8; +s->lambda = (s->lambda * m->me_penalty_compensation + 128) >> 8; +s->lambda2 = (s->lambda2 * (int64_t) m->me_penalty_compensation + 128) >> 8; if (s->pict_type != AV_PICTURE_TYPE_B) { -if ((s->me_pre && s->last_non_b_pict_type == AV_PICTURE_TYPE_I) || -s->me_pre == 2) { +if ((m->me_pre && s->last_non_b_pict_type == AV_PICTURE_TYPE_I) || +m->me_pre == 2) { s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); } } diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index b03b785769..06e14ad11f 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -39,6 +39,9 @@ typedef MPVContext MPVEncContext; typedef struct MPVMainEncContext { MPVMainContext common; +int me_penalty_compensation; +int me_pre; ///< prepass for motion estimation + /* bit rate control */ int64_t total_bits; int frame_bits;///< bits used for the current frame @@ -125,8 +128,8 @@ FF_MPV_OPT_CMP_FUNC, \ {"sc_threshold", "Scene change threshold", FF_MPV_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"noise_reduction", "Noise reduction", FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"ps", "RTP payload size in bytes", FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ -{"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", FF_MPV_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ -{"mepre", "pre motion estimation", FF_MPV_OFFSET(me_pre), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ +{"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", FF_MPV_MAIN_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ +{"mepre", "pre motion estimation", FF_MPV_MAIN_OFFSET(me_pre), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"intra_penalty", "Penalty for intra blocks in block decision", FF_MPV_OFFSET(intra_penalty), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX/2, FF_MPV_OPT_FLAGS }, \ #define FF_MPV_COMMON_BFRAME_OPTS \ -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 32/69] avcodec/mpegvideo: Move gop_size to MPVMainEncContext
Only used by the main encoding thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 14 +++--- libavcodec/mpegvideoenc.h | 2 ++ libavcodec/ratecontrol.c | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index c59d4848a8..50c0fa42c4 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -81,7 +81,6 @@ typedef struct MPVContext { void *private_ctx; /* the following parameters must be initialized before encoding */ int width, height;///< picture size. must be a multiple of 16 -int gop_size; int intra_only; ///< if true, only intra pictures are generated int64_t bit_rate; ///< wanted bit rate enum OutputFormat out_format; ///< output format diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index b67f706504..77825e5b82 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -352,7 +352,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) avctx->gop_size, 600); avctx->gop_size = 600; } -s->gop_size = avctx->gop_size; +m->gop_size = avctx->gop_size; s->avctx= avctx; if (avctx->max_b_frames > MPVENC_MAX_B_FRAMES) { av_log(avctx, AV_LOG_ERROR, "Too many B-frames requested, maximum " @@ -394,9 +394,9 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) } s->user_specified_pts = AV_NOPTS_VALUE; -if (s->gop_size <= 1) { +if (m->gop_size <= 1) { s->intra_only = 1; -s->gop_size = 12; +m->gop_size = 12; } else { s->intra_only = 0; } @@ -1382,7 +1382,7 @@ static int select_input_picture(MPVMainEncContext *m) /* set next picture type & ordering */ if (!s->reordered_input_picture[0] && s->input_picture[0]) { if (s->frame_skip_threshold || s->frame_skip_factor) { -if (s->picture_in_gop_number < s->gop_size && +if (s->picture_in_gop_number < m->gop_size && s->next_picture_ptr && skip_check(m, s->input_picture[0], s->next_picture_ptr)) { // FIXME check that the gop check above is +-1 correct @@ -1466,10 +1466,10 @@ static int select_input_picture(MPVMainEncContext *m) "warning, too many B-frames in a row\n"); } -if (s->picture_in_gop_number + b_frames >= s->gop_size) { +if (s->picture_in_gop_number + b_frames >= m->gop_size) { if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) && -s->gop_size > s->picture_in_gop_number) { -b_frames = s->gop_size - s->picture_in_gop_number - 1; +m->gop_size > s->picture_in_gop_number) { +b_frames = m->gop_size - s->picture_in_gop_number - 1; } else { if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) b_frames = 0; diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 06e14ad11f..09dabee223 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -42,6 +42,8 @@ typedef struct MPVMainEncContext { int me_penalty_compensation; int me_pre; ///< prepass for motion estimation +int gop_size; + /* bit rate control */ int64_t total_bits; int frame_bits;///< bits used for the current frame diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index b0f319680b..4e7bbe49a7 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -632,7 +632,7 @@ av_cold int ff_rate_control_init(MPVMainEncContext *m) double bits = s->rc_initial_cplx * (i / 1.0 + 1.0) * s->mb_num; RateControlEntry rce; -if (i % ((s->gop_size + 3) / 4) == 0) +if (i % ((m->gop_size + 3) / 4) == 0) rce.pict_type = AV_PICTURE_TYPE_I; else if (i % (s->max_b_frames + 1)) rce.pict_type = AV_PICTURE_TYPE_B; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 33/69] avcodec/mpegvideo_enc: Don't set picture_in_gop_number for slice threads
They don't ever read this value. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 77825e5b82..fd3f458fb7 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -262,7 +262,6 @@ static void update_duplicate_context_after_me(MPVEncContext *dst, COPY(qscale); COPY(lambda); COPY(lambda2); -COPY(picture_in_gop_number); COPY(frame_pred_frame_dct); // FIXME don't set in encode_header COPY(progressive_frame);// FIXME don't set in encode_header COPY(partitioned_frame);// FIXME don't set in encode_header -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 34/69] avcodec/mpegvideo: Move picture_in_gop_number to MPVMainEncContext
Only ever used by the main encoding thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 14 +++--- libavcodec/mpegvideoenc.h | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 50c0fa42c4..08c795ba17 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -107,7 +107,6 @@ typedef struct MPVContext { int input_picture_number; ///< used to set pic->display_picture_number, should not be used for/by anything else int coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else int picture_number; //FIXME remove, unclear definition -int picture_in_gop_number; ///< 0-> first pic in gop, ... int mb_width, mb_height; ///< number of MBs horizontally & vertically int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index fd3f458fb7..86f2b5fcb1 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -292,7 +292,7 @@ static void mpv_encode_defaults(MPVMainEncContext *m) s->fcode_tab = default_fcode_tab; s->input_picture_number = 0; -s->picture_in_gop_number = 0; +m->picture_in_gop_number = 0; } av_cold int ff_dct_encode_init(MPVEncContext *s) @@ -1381,7 +1381,7 @@ static int select_input_picture(MPVMainEncContext *m) /* set next picture type & ordering */ if (!s->reordered_input_picture[0] && s->input_picture[0]) { if (s->frame_skip_threshold || s->frame_skip_factor) { -if (s->picture_in_gop_number < m->gop_size && +if (m->picture_in_gop_number < m->gop_size && s->next_picture_ptr && skip_check(m, s->input_picture[0], s->next_picture_ptr)) { // FIXME check that the gop check above is +-1 correct @@ -1465,10 +1465,10 @@ static int select_input_picture(MPVMainEncContext *m) "warning, too many B-frames in a row\n"); } -if (s->picture_in_gop_number + b_frames >= m->gop_size) { +if (m->picture_in_gop_number + b_frames >= m->gop_size) { if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) && -m->gop_size > s->picture_in_gop_number) { -b_frames = m->gop_size - s->picture_in_gop_number - 1; +m->gop_size > m->picture_in_gop_number) { +b_frames = m->gop_size - m->picture_in_gop_number - 1; } else { if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) b_frames = 0; @@ -1689,7 +1689,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, s->vbv_ignore_qmax = 0; -s->picture_in_gop_number++; +m->picture_in_gop_number++; if (load_input_picture(m, pic_arg) < 0) return -1; @@ -3719,7 +3719,7 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) s->current_picture.f->pict_type = s->pict_type; if (s->current_picture.f->key_frame) -s->picture_in_gop_number=0; +m->picture_in_gop_number=0; s->mb_x = s->mb_y = 0; s->last_bits= put_bits_count(&s->pb); diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 09dabee223..a177b2d6c6 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -43,6 +43,7 @@ typedef struct MPVMainEncContext { int me_pre; ///< prepass for motion estimation int gop_size; +int picture_in_gop_number; ///< 0-> first pic in gop, ... /* bit rate control */ int64_t total_bits; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 36/69] avcodec/mpegvideo: Move input_picture list to MPVMainEncContext
Also avoid an allocation while doing so. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 60 ++ libavcodec/mpegvideoenc.h | 2 ++ 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 3dd04d6e82..06bb704dc2 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -115,7 +115,6 @@ typedef struct MPVContext { ptrdiff_t linesize;///< line size, in bytes, may be different from width ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width Picture *picture; ///< main picture buffer -Picture **input_picture; ///< next pictures on display order for encoding Picture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding /** bit output */ diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 4f64fd28a7..7bce5c54ca 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -827,7 +827,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) !FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix16,32) || !FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32) || !FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16,32) || -!FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MAX_PICTURE_COUNT) || !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT)) return AVERROR(ENOMEM); @@ -954,7 +953,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) av_freep(&s->q_inter_matrix); av_freep(&s->q_intra_matrix16); av_freep(&s->q_inter_matrix16); -av_freep(&s->input_picture); av_freep(&s->reordered_input_picture); av_freep(&s->dct_offset); @@ -1139,9 +1137,9 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg) pic->f->pts = pts; // we set this here to avoid modifying pic_arg } else { /* Flushing: When we have not received enough input frames, - * ensure s->input_picture[0] contains the first picture */ + * ensure m->input_picture[0] contains the first picture */ for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++) -if (s->input_picture[flush_offset]) +if (m->input_picture[flush_offset]) break; if (flush_offset <= 1) @@ -1152,9 +1150,9 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg) /* shift buffer entries */ for (i = flush_offset; i < MAX_PICTURE_COUNT /*s->encoding_delay + 1*/; i++) -s->input_picture[i - flush_offset] = s->input_picture[i]; +m->input_picture[i - flush_offset] = m->input_picture[i]; -s->input_picture[encoding_delay] = (Picture*) pic; +m->input_picture[encoding_delay] = (Picture*) pic; return 0; } @@ -1251,11 +1249,11 @@ static int estimate_best_b_count(MPVMainEncContext *m) FF_LAMBDA_SHIFT; for (i = 0; i < s->max_b_frames + 2; i++) { -Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] : +Picture pre_input, *pre_input_ptr = i ? m->input_picture[i - 1] : s->next_picture_ptr; uint8_t *data[4]; -if (pre_input_ptr && (!i || s->input_picture[i - 1])) { +if (pre_input_ptr && (!i || m->input_picture[i - 1])) { pre_input = *pre_input_ptr; memcpy(data, pre_input_ptr->f->data, sizeof(data)); @@ -1287,7 +1285,7 @@ static int estimate_best_b_count(MPVMainEncContext *m) AVCodecContext *c; int64_t rd = 0; -if (!s->input_picture[j]) +if (!m->input_picture[j]) break; c = avcodec_alloc_context3(NULL); @@ -1379,13 +1377,13 @@ static int select_input_picture(MPVMainEncContext *m) s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL; /* set next picture type & ordering */ -if (!s->reordered_input_picture[0] && s->input_picture[0]) { +if (!s->reordered_input_picture[0] && m->input_picture[0]) { if (s->frame_skip_threshold || s->frame_skip_factor) { if (m->picture_in_gop_number < m->gop_size && s->next_picture_ptr && -skip_check(m, s->input_picture[0], s->next_picture_ptr)) { +skip_check(m, m->input_picture[0], s->next_picture_ptr)) { // FIXME check that the gop check above is +-1 correct -av_frame_unref(s->input_picture[0]->f); +av_frame_unref(m->input_picture[0]->f); ff_vbv_update(m, 0); @@ -1395,7 +1393,7 @@ static int select_input_picture(MPVMainEncContext *m) if (/*s->picture_in_gop_number >= s->gop_size ||*/ !s->next_picture_ptr || s->intra_only) { -s->reordered_input_picture[0
[FFmpeg-devel] [PATCH v2 37/69] avcodec/mpegvideo: Remove write-only [fb]_code
Signed-off-by: Andreas Rheinhardt --- libavcodec/ituh263enc.c| 1 - libavcodec/mpeg12enc.c | 5 - libavcodec/mpeg4videoenc.c | 8 libavcodec/mpegvideo.h | 2 -- libavcodec/mpegvideo_enc.c | 8 5 files changed, 24 deletions(-) diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c index 97173bfdc6..56f9f91d19 100644 --- a/libavcodec/ituh263enc.c +++ b/libavcodec/ituh263enc.c @@ -682,7 +682,6 @@ void ff_h263_encode_mb(MPVEncContext *s, if(interleaved_stats){ if (!s->mb_intra) { s->p_tex_bits+= get_bits_diff(s); -s->f_count++; }else{ s->i_tex_bits+= get_bits_diff(s); s->i_count++; diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index 4b878b2f90..a0cbd5d8de 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -942,7 +942,6 @@ static av_always_inline void mpeg1_encode_mb_internal(MPVEncContext *s, put_sbits(&s->pb, 2, cbp); } } -s->f_count++; } else { if (s->mv_type == MV_TYPE_16X16) { if (cbp) { // With coded bloc pattern @@ -973,7 +972,6 @@ static av_always_inline void mpeg1_encode_mb_internal(MPVEncContext *s, s->last_mv[0][1][0] = s->mv[0][0][0]; s->last_mv[0][0][1] = s->last_mv[0][1][1] = s->mv[0][0][1]; -s->f_count++; } if (s->mv_dir & MV_DIR_BACKWARD) { mpeg1_encode_motion(s, @@ -986,7 +984,6 @@ static av_always_inline void mpeg1_encode_mb_internal(MPVEncContext *s, s->last_mv[1][1][0] = s->mv[1][0][0]; s->last_mv[1][0][1] = s->last_mv[1][1][1] = s->mv[1][0][1]; -s->b_count++; } } else { av_assert2(s->mv_type == MV_TYPE_FIELD); @@ -1019,7 +1016,6 @@ static av_always_inline void mpeg1_encode_mb_internal(MPVEncContext *s, s->last_mv[0][i][0] = s->mv[0][i][0]; s->last_mv[0][i][1] = s->mv[0][i][1] * 2; } -s->f_count++; } if (s->mv_dir & MV_DIR_BACKWARD) { for (i = 0; i < 2; i++) { @@ -1033,7 +1029,6 @@ static av_always_inline void mpeg1_encode_mb_internal(MPVEncContext *s, s->last_mv[1][i][0] = s->mv[1][i][0]; s->last_mv[1][i][1] = s->mv[1][i][1] * 2; } -s->b_count++; } } s->mv_bits += get_bits_diff(s); diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index c7b0b3ec02..a8c94c9d28 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -565,8 +565,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], if (!mb_type) { av_assert2(s->mv_dir & MV_DIRECT); ff_h263_encode_motion_vector(s, motion_x, motion_y, 1); -s->b_count++; -s->f_count++; } else { av_assert2(mb_type > 0 && mb_type < 4); if (s->mv_type != MV_TYPE_FIELD) { @@ -579,7 +577,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], s->last_mv[0][1][0] = s->mv[0][0][0]; s->last_mv[0][0][1] = s->last_mv[0][1][1] = s->mv[0][0][1]; -s->f_count++; } if (s->mv_dir & MV_DIR_BACKWARD) { ff_h263_encode_motion_vector(s, @@ -590,7 +587,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], s->last_mv[1][1][0] = s->mv[1][0][0]; s->last_mv[1][0][1] = s->last_mv[1][1][1] = s->mv[1][0][1]; -s->b_count++; } } else { if (s->mv_dir & MV_DIR_FORWARD) { @@ -610,7 +606,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], s->last_mv[0][i][0] = s->mv[0][i][0]; s->last_mv[0][i][1] = s->mv[0][i][1] * 2; } -s->f_count++; } if (s->mv_dir & MV_DIR_BACKWARD) { for (i = 0; i < 2; i++) { @@ -621,7 +616,6 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], s->last_mv[1][i][0] = s->mv[1][i][0]; s->last_mv[1][i][1] = s->mv[1][i][1] * 2; } -s->b_count++; } } } @@ -797,8 +791,6 @@ void ff_mpeg4_encod
[FFmpeg-devel] [PATCH v2 38/69] avcodec/mpegvideo: Move last-pic information to MPVMainEncContext
last_pict_type, last_non_b_pict_type and last_lambda_for are only used by the encoder's main thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 3 --- libavcodec/mpegvideo_enc.c | 16 libavcodec/mpegvideoenc.h | 4 libavcodec/msmpeg4enc.c| 5 +++-- libavcodec/ratecontrol.c | 4 ++-- libavcodec/snowenc.c | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 757c514a6d..14e5e241cc 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -180,10 +180,7 @@ typedef struct MPVContext { int dquant; ///< qscale difference to prev qscale int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ... int vbv_delay; -int last_pict_type; //FIXME removes -int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol int droppable; -int last_lambda_for[5]; ///< last lambda for a specific pict type int skipdct;///< skip dct and code zero residual /* motion compensation */ diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index c537ce8c19..6d45885185 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1240,9 +1240,9 @@ static int estimate_best_b_count(MPVMainEncContext *m) //emms_c(); //s->next_picture_ptr->quality; -p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P]; +p_lambda = m->last_lambda_for[AV_PICTURE_TYPE_P]; //p_lambda * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset; -b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B]; +b_lambda = m->last_lambda_for[AV_PICTURE_TYPE_B]; if (!b_lambda) // FIXME we should do this somewhere else b_lambda = p_lambda; lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >> @@ -1577,10 +1577,10 @@ static void frame_end(MPVMainEncContext *m) emms_c(); -s->last_pict_type = s->pict_type; -s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality; +m->last_pict_type = s->pict_type; +m->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality; if (s->pict_type!= AV_PICTURE_TYPE_B) -s->last_non_b_pict_type = s->pict_type; +m->last_non_b_pict_type = s->pict_type; } static void update_noise_reduction(MPVMainEncContext *m) @@ -3527,9 +3527,9 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) ff_get_2pass_fcode(m); } else if (!(s->avctx->flags & AV_CODEC_FLAG_QSCALE)) { if(s->pict_type==AV_PICTURE_TYPE_B) -s->lambda= s->last_lambda_for[s->pict_type]; +s->lambda = m->last_lambda_for[s->pict_type]; else -s->lambda= s->last_lambda_for[s->last_non_b_pict_type]; +s->lambda = m->last_lambda_for[m->last_non_b_pict_type]; update_qscale(s); } @@ -3555,7 +3555,7 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) s->lambda = (s->lambda * m->me_penalty_compensation + 128) >> 8; s->lambda2 = (s->lambda2 * (int64_t) m->me_penalty_compensation + 128) >> 8; if (s->pict_type != AV_PICTURE_TYPE_B) { -if ((m->me_pre && s->last_non_b_pict_type == AV_PICTURE_TYPE_I) || +if ((m->me_pre && m->last_non_b_pict_type == AV_PICTURE_TYPE_I) || m->me_pre == 2) { s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); } diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index d66462b19a..8eab164d7a 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -58,6 +58,10 @@ typedef struct MPVMainEncContext { * a delay */ int64_t reordered_pts; +int last_pict_type; //FIXME remove +int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol +int last_lambda_for[5]; ///< last lambda for a specific pict type + /* bit rate control */ int64_t total_bits; int frame_bits;///< bits used for the current frame diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c index 7c1fa0a1e3..f8080a194c 100644 --- a/libavcodec/msmpeg4enc.c +++ b/libavcodec/msmpeg4enc.c @@ -151,7 +151,8 @@ av_cold void ff_msmpeg4_encode_init(MPVMainEncContext *m) static void find_best_tables(MSMPEG4EncContext *ms) { -MPVEncContext *const s = &ms->s.common; +MPVMainEncContext *const m = &ms->s; +MPVEncContext *const s = &m->common; int i; int best= 0, best_size= INT_MAX; int chroma_best = 0, best_chroma_size = INT_MAX; @@ -204,7 +205,7 @@ static void find_best_tables(MSMPEG4EncContext *ms) s->rl_table_index =best; s->rl_chroma_table_index= chroma_best; -if(s->pict_type != s->last_non_b_pict_type){
[FFmpeg-devel] [PATCH v2 39/69] avcodec/mpegvideo: Move header_bits to MPVMainEncContext
The header is always written by the main thread, so it is not surprising that header_bits can be moved to MPVMainEncContext as well. Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpegenc.c | 14 -- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 6 +++--- libavcodec/mpegvideoenc.h | 2 ++ libavcodec/ratecontrol.c | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index fd87186fbc..a8ea63a76d 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -103,8 +103,9 @@ void ff_mjpeg_amv_encode_picture_header(MPVMainEncContext *main) * * @param s The MPVEncContext. */ -static void mjpeg_encode_picture_frame(MPVEncContext *s) +static void mjpeg_encode_picture_frame(MPVMainEncContext *main) { +MPVEncContext *const s = &main->common; int nbits, code, table_id; MJpegContext *m = s->mjpeg_ctx; uint8_t *huff_size[4] = { m->huff_size_dc_luminance, @@ -118,7 +119,7 @@ static void mjpeg_encode_picture_frame(MPVEncContext *s) size_t total_bits = 0; size_t bytes_needed; -s->header_bits = get_bits_diff(s); +main->header_bits = get_bits_diff(s); // Estimate the total size first for (int i = 0; i < m->huff_ncode; i++) { table_id = m->huff_buffer[i].table_id; @@ -224,6 +225,9 @@ int ff_mjpeg_encode_stuffing(MPVEncContext *s) #if CONFIG_MJPEG_ENCODER if (m->huffman == HUFFMAN_TABLE_OPTIMAL) { +/* HUFFMAN_TABLE_OPTIMAL is incompatible with slice threading, + * therefore the following cast is allowed. */ +MPVMainEncContext *const main = (MPVMainEncContext*)s; mjpeg_build_optimal_huffman(m); @@ -236,10 +240,8 @@ int ff_mjpeg_encode_stuffing(MPVEncContext *s) s->intra_chroma_ac_vlc_length = s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len; -/* HUFFMAN_TABLE_OPTIMAL is incompatible with slice threading, - * therefore the following cast is allowed. */ -mjpeg_encode_picture_header((MPVMainEncContext*)s); -mjpeg_encode_picture_frame(s); +mjpeg_encode_picture_header(main); +mjpeg_encode_picture_frame(main); } #endif diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 14e5e241cc..20be21a834 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -295,7 +295,6 @@ typedef struct MPVContext { /* statistics, used for 2-pass encoding */ int mv_bits; -int header_bits; int i_tex_bits; int p_tex_bits; int i_count; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 6d45885185..03758a387d 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1739,7 +1739,7 @@ vbv_retry: frame_end(m); if ((CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER) && s->out_format == FMT_MJPEG) -ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits); +ff_mjpeg_encode_picture_trailer(&s->pb, m->header_bits); if (avctx->rc_buffer_size) { RateControlContext *rcc = &m->rc_context; @@ -1796,7 +1796,7 @@ vbv_retry: s->pict_type); if (avctx->flags & AV_CODEC_FLAG_PASS1) -assert(put_bits_count(&s->pb) == s->header_bits + s->mv_bits + +assert(put_bits_count(&s->pb) == m->header_bits + s->mv_bits + s->misc_bits + s->i_tex_bits + s->p_tex_bits); flush_put_bits(&s->pb); @@ -3756,7 +3756,7 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) av_assert0(0); } bits= put_bits_count(&s->pb); -s->header_bits= bits - s->last_bits; +m->header_bits = bits - s->last_bits; for(i=1; ithread_context[i], s); diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 8eab164d7a..ab0f7d13c7 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -62,6 +62,8 @@ typedef struct MPVMainEncContext { int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol int last_lambda_for[5]; ///< last lambda for a specific pict type +int header_bits; + /* bit rate control */ int64_t total_bits; int frame_bits;///< bits used for the current frame diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 03466a1a43..c41682b29c 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -54,7 +54,7 @@ void ff_write_pass1_stats(MPVMainEncContext *m) s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, - s->header_bits); + m->header_bits); } static double get_fps(AVCodecContext *avctx) -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-dev
[FFmpeg-devel] [PATCH v2 40/69] avcodec/mpegvideo_enc: Remove unused function parameters
Seems to have been always unused since these functions were introduced in 1f0cd30fd9b656122436ecd625656a04f6235fb3. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 03758a387d..5b6f5211cc 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -2431,7 +2431,7 @@ static av_always_inline void encode_mb(MPVEncContext *s, int motion_x, int motio } static inline void copy_context_before_encode(MPVEncContext *d, - const MPVEncContext *s, int type) + const MPVEncContext *s) { int i; @@ -2459,7 +2459,7 @@ static inline void copy_context_before_encode(MPVEncContext *d, } static inline void copy_context_after_encode(MPVEncContext *d, - const MPVEncContext *s, int type) + const MPVEncContext *s) { int i; @@ -2504,7 +2504,7 @@ static inline void encode_mb_hq(MPVEncContext *s, MPVEncContext *backup, MPVEncC int score; uint8_t *dest_backup[3]; -copy_context_before_encode(s, backup, type); +copy_context_before_encode(s, backup); s->block= s->blocks[*next_block]; s->pb= pb[*next_block]; @@ -2544,7 +2544,7 @@ static inline void encode_mb_hq(MPVEncContext *s, MPVEncContext *backup, MPVEncC *dmin= score; *next_block^=1; -copy_context_after_encode(best, s, type); +copy_context_after_encode(best, s); } } @@ -2968,7 +2968,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ int next_block=0; int pb_bits_count, pb2_bits_count, tex_pb_bits_count; -copy_context_before_encode(&backup_s, s, -1); +copy_context_before_encode(&backup_s, s); backup_s.pb= s->pb; best_s.data_partitioning= s->data_partitioning; best_s.partitioned_frame= s->partitioned_frame; @@ -3202,7 +3202,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->current_picture.qscale_table[xy] = best_s.qscale; -copy_context_after_encode(s, &best_s, -1); +copy_context_after_encode(s, &best_s); pb_bits_count= put_bits_count(&s->pb); flush_put_bits(&s->pb); -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 41/69] avcodec/mpegvideo_enc: Remove unused parameter from encode_mb_hq()
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 32 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 5b6f5211cc..ab49705823 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -2497,7 +2497,7 @@ static inline void copy_context_after_encode(MPVEncContext *d, d->esc3_level_length= s->esc3_level_length; } -static inline void encode_mb_hq(MPVEncContext *s, MPVEncContext *backup, MPVEncContext *best, int type, +static inline void encode_mb_hq(MPVEncContext *s, MPVEncContext *backup, MPVEncContext *best, PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], int *dmin, int *next_block, int motion_x, int motion_y) { @@ -2983,7 +2983,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->mb_intra= 0; s->mv[0][0][0] = s->p_mv_table[xy][0]; s->mv[0][0][1] = s->p_mv_table[xy][1]; -encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb, +encode_mb_hq(s, &backup_s, &best_s, pb, pb2, tex_pb, &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); } if(mb_type&CANDIDATE_MB_TYPE_INTER_I){ @@ -2995,7 +2995,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; } -encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb, +encode_mb_hq(s, &backup_s, &best_s, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&CANDIDATE_MB_TYPE_SKIPPED){ @@ -3004,7 +3004,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->mb_intra= 0; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; -encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb, +encode_mb_hq(s, &backup_s, &best_s, pb, pb2, tex_pb, &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); } if(mb_type&CANDIDATE_MB_TYPE_INTER4V){ @@ -3015,7 +3015,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; } -encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb, +encode_mb_hq(s, &backup_s, &best_s, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&CANDIDATE_MB_TYPE_FORWARD){ @@ -3024,7 +3024,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->mb_intra= 0; s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; -encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb, +encode_mb_hq(s, &backup_s, &best_s, pb, pb2, tex_pb, &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); } if(mb_type&CANDIDATE_MB_TYPE_BACKWARD){ @@ -3033,7 +3033,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->mb_intra= 0; s->mv[1][0][0] = s->b_back_mv_table[xy][0]; s->mv[1][0][1] = s->b_back_mv_table[xy][1]; -encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb, +encode_mb_hq(s, &backup_s, &best_s, pb, pb2, tex_pb, &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); } if(mb_type&CANDIDATE_MB_TYPE_BIDIR){ @@ -3044,7 +3044,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; -encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb, +encode_mb_hq(s, &backup_s, &best_s, pb, pb2, tex_pb, &dmin, &next_block, 0, 0); } if(mb_type&CANDIDATE_MB_TYPE_FORWARD_I){ @@ -3056,7 +3056,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
[FFmpeg-devel] [PATCH v2 46/69] avcodec/mpegvideo: Move encoder-only base-arrays to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 10 libavcodec/mpegvideo_enc.c | 48 +++--- libavcodec/mpegvideoenc.h | 11 + libavcodec/ratecontrol.c | 4 ++-- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 307964b10e..0d6b79fe5d 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -200,14 +200,7 @@ typedef struct MPVContext { H263DSPContext h263dsp; int f_code; ///< forward MV resolution int b_code; ///< backward MV resolution for B-frames (MPEG-4) -int16_t (*p_mv_table_base)[2]; -int16_t (*b_forw_mv_table_base)[2]; -int16_t (*b_back_mv_table_base)[2]; -int16_t (*b_bidir_forw_mv_table_base)[2]; -int16_t (*b_bidir_back_mv_table_base)[2]; -int16_t (*b_direct_mv_table_base)[2]; int16_t (*p_field_mv_table_base)[2]; -int16_t (*b_field_mv_table_base)[2]; int16_t (*p_mv_table)[2];///< MV table (1MV per MB) P-frame encoding int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode B-frame encoding int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode B-frame encoding @@ -471,9 +464,6 @@ typedef struct MPVContext { int vbv_ignore_qmax; -/* temp buffers for rate control */ -float *cplx_tab, *bits_tab; - /* flag to indicate a reinitialization is required, e.g. after * a frame size change */ int context_reinit; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 1739472352..8b2de4770b 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -823,26 +823,26 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) /* Allocate MV tables; the MV and MB tables will be copied * to slice contexts by ff_update_duplicate_context(). */ mv_table_size = (s->mb_height + 2) * s->mb_stride + 1; -if (!FF_ALLOCZ_TYPED_ARRAY(s->p_mv_table_base,mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_forw_mv_table_base, mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_back_mv_table_base, mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_forw_mv_table_base, mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_back_mv_table_base, mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_direct_mv_table_base, mv_table_size)) +if (!FF_ALLOCZ_TYPED_ARRAY(m->p_mv_table_base,mv_table_size) || +!FF_ALLOCZ_TYPED_ARRAY(m->b_forw_mv_table_base, mv_table_size) || +!FF_ALLOCZ_TYPED_ARRAY(m->b_back_mv_table_base, mv_table_size) || +!FF_ALLOCZ_TYPED_ARRAY(m->b_bidir_forw_mv_table_base, mv_table_size) || +!FF_ALLOCZ_TYPED_ARRAY(m->b_bidir_back_mv_table_base, mv_table_size) || +!FF_ALLOCZ_TYPED_ARRAY(m->b_direct_mv_table_base, mv_table_size)) return AVERROR(ENOMEM); -s->p_mv_table= s->p_mv_table_base + s->mb_stride + 1; -s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; -s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; -s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base + s->mb_stride + 1; -s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base + s->mb_stride + 1; -s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; +s->p_mv_table= m->p_mv_table_base + s->mb_stride + 1; +s->b_forw_mv_table = m->b_forw_mv_table_base + s->mb_stride + 1; +s->b_back_mv_table = m->b_back_mv_table_base + s->mb_stride + 1; +s->b_bidir_forw_mv_table = m->b_bidir_forw_mv_table_base + s->mb_stride + 1; +s->b_bidir_back_mv_table = m->b_bidir_back_mv_table_base + s->mb_stride + 1; +s->b_direct_mv_table = m->b_direct_mv_table_base + s->mb_stride + 1; /* Allocate MB type table */ mb_array_size = s->mb_height * s->mb_stride; if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_type, mb_array_size) || !FF_ALLOCZ_TYPED_ARRAY(s->lambda_table, mb_array_size) || -!FF_ALLOC_TYPED_ARRAY (s->cplx_tab, mb_array_size) || -!FF_ALLOC_TYPED_ARRAY (s->bits_tab, mb_array_size)) +!FF_ALLOC_TYPED_ARRAY (m->cplx_tab, mb_array_size) || +!FF_ALLOC_TYPED_ARRAY (m->bits_tab, mb_array_size)) return AVERROR(ENOMEM); #define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * sizeof(*(p @@ -850,7 +850,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) { int16_t (*tmp1)[2]; uint8_t *tmp2; -if (!(tmp1 = ALLOCZ_ARRAYS(s->b_field_mv_table_base, 8, mv_table_size)) || +if (!(tmp1 = ALLOCZ_ARRAYS(m->b_field_mv_table_base, 8, mv_table_size)) || !(tmp2 = ALLOCZ_ARRAYS(s->b_field_select_table[0][0], 2 * 4, mv_table_size)) ||
[FFmpeg-devel] [PATCH v2 42/69] avcodec/mpegvideo: Move vbv_delay to Mpeg1Context
Only used there and only by the main thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg12dec.c | 5 +++-- libavcodec/mpegvideo.h | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 22e0ba5ed3..d3c32818cf 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -69,6 +69,7 @@ typedef struct Mpeg1Context { AVRational save_aspect; int save_width, save_height, save_progressive_seq; int rc_buffer_size; +int vbv_delay; AVRational frame_rate_ext; /* MPEG-2 specific framerate modificator */ unsigned frame_rate_index; int sync; /* Did we reach a sync point like a GOP/SEQ/KEYFrame? */ @@ -1285,7 +1286,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->bit_rate) { avctx->rc_max_rate = s->bit_rate; } else if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO && s->bit_rate && - (s->bit_rate != 0x3*400 || s->vbv_delay != 0x)) { + (s->bit_rate != 0x3*400 || s1->vbv_delay != 0x)) { avctx->bit_rate = s->bit_rate; } s1->save_aspect = s->avctx->sample_aspect_ratio; @@ -1358,7 +1359,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf, return AVERROR_INVALIDDATA; vbv_delay = get_bits(&s->gb, 16); -s->vbv_delay = vbv_delay; +s1->vbv_delay = vbv_delay; if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type == AV_PICTURE_TYPE_B) { s->full_pel[0] = get_bits1(&s->gb); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 20be21a834..0153abde3b 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -179,7 +179,6 @@ typedef struct MPVContext { int adaptive_quant; ///< use adaptive quantization int dquant; ///< qscale difference to prev qscale int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ... -int vbv_delay; int droppable; int skipdct;///< skip dct and code zero residual -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 47/69] avcodec/mpegvideo_enc: Initialize non-JPEG q-matrices only once
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 11 --- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 8b2de4770b..75f1db2a76 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -947,6 +947,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) ff_convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0); +av_freep(&s->q_chroma_intra_matrix); +av_freep(&s->q_chroma_intra_matrix16); +s->q_chroma_intra_matrix = s->q_intra_matrix; +s->q_chroma_intra_matrix16 = s->q_intra_matrix16; } if ((ret = ff_rate_control_init(m)) < 0) @@ -3599,13 +3603,6 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) update_qscale(s); } -if (s->out_format != FMT_MJPEG) { -if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); -if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); -s->q_chroma_intra_matrix = s->q_intra_matrix; -s->q_chroma_intra_matrix16 = s->q_intra_matrix16; -} - s->mb_intra=0; //for the rate distortion & bit compare functions for(i=1; ithread_context[i], s); -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 43/69] avcodec/mpegvideo: Move brd_scale to MPVMainEncContext
Only used by the main encoding thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 6 +++--- libavcodec/mpegvideoenc.h | 5 +++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 0153abde3b..62347eff81 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -406,7 +406,6 @@ typedef struct MPVContext { int top_field_first; int concealment_motion_vectors; int q_scale_type; -int brd_scale; int intra_vlc_format; int alternate_scan; #define VIDEO_FORMAT_COMPONENT 0 diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index ab49705823..a1ea875546 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -909,8 +909,8 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) return AVERROR(ENOMEM); m->tmp_frames[i]->format = AV_PIX_FMT_YUV420P; -m->tmp_frames[i]->width = s->width >> s->brd_scale; -m->tmp_frames[i]->height = s->height >> s->brd_scale; +m->tmp_frames[i]->width = s->width >> m->brd_scale; +m->tmp_frames[i]->height = s->height >> m->brd_scale; ret = av_frame_get_buffer(m->tmp_frames[i], 0); if (ret < 0) @@ -1224,7 +1224,7 @@ static int estimate_best_b_count(MPVMainEncContext *m) { MPVEncContext *const s = &m->common; AVPacket *pkt; -const int scale = s->brd_scale; +const int scale = m->brd_scale; int width = s->width >> scale; int height = s->height >> scale; int i, j, out_size, p_lambda, b_lambda, lambda2; diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index ab0f7d13c7..350a1f70a6 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -75,6 +75,7 @@ typedef struct MPVMainEncContext { AVFrame *tmp_frames[MPVENC_MAX_B_FRAMES + 2]; int b_frame_strategy; int b_sensitivity; +int brd_scale; } MPVMainEncContext; #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level)) @@ -157,7 +158,7 @@ FF_MPV_OPT_CMP_FUNC, \ #define FF_MPV_COMMON_BFRAME_OPTS \ {"b_strategy", "Strategy to choose between I/P/B-frames", FF_MPV_MAIN_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, FF_MPV_OPT_FLAGS }, \ {"b_sensitivity", "Adjust sensitivity of b_frame_strategy 1", FF_MPV_MAIN_OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS }, \ -{"brd_scale", "Downscale frames for dynamic B-frame decision", FF_MPV_OFFSET(brd_scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 3, FF_MPV_OPT_FLAGS }, +{"brd_scale", "Downscale frames for dynamic B-frame decision", FF_MPV_MAIN_OFFSET(brd_scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 3, FF_MPV_OPT_FLAGS }, #if FF_API_MPEGVIDEO_OPTS #define FF_MPV_DEPRECATED_MPEG_QUANT_OPT \ @@ -169,7 +170,7 @@ FF_MPV_OPT_CMP_FUNC, \ #define FF_MPV_DEPRECATED_BFRAME_OPTS \ { "b_strategy","Deprecated, does nothing", FF_MPV_MAIN_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \ { "b_sensitivity", "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(b_sensitivity),AV_OPT_TYPE_INT, { .i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \ - { "brd_scale", "Deprecated, does nothing", FF_MPV_OFFSET(brd_scale), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 3, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, + { "brd_scale", "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(brd_scale),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 3, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, #endif extern const AVClass ff_mpv_enc_class; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 48/69] avcodec/mpegvideo_enc: Avoid allocations for q_int(er|ra)_matrix tables
Do this by making them part of an MPVMainEncContext; the MPVEncContexts still retain their pointers to access them. (These tables are quite big, so that putting them in the MpegEncContext would have been very wasteful for all the decoders using said structure. But this is no longer a problem: MPVMainEncContext is only used by encoders and allows to directly share the tables when slice-threading is in use.) Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 24 libavcodec/mpegvideoenc.h | 7 +++ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 75f1db2a76..0e14cebb3f 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -871,12 +871,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) } if (!(avctx->stats_out = av_mallocz(256)) || -!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix, 32) || -!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix, 32) || -!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix, 32) || -!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix16,32) || -!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32) || -!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16,32) || !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT)) return AVERROR(ENOMEM); @@ -938,6 +932,11 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->inter_matrix[j] = avctx->inter_matrix[i]; } +s->q_inter_matrix = m->q_inter_matrix; +s->q_intra_matrix = m->q_intra_matrix; +s->q_inter_matrix16 = m->q_inter_matrix16; +s->q_intra_matrix16 = m->q_intra_matrix16; + /* precompute matrix */ /* for mjpeg, we do include qscale in the matrix */ if (s->out_format != FMT_MJPEG) { @@ -947,10 +946,11 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) ff_convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0); -av_freep(&s->q_chroma_intra_matrix); -av_freep(&s->q_chroma_intra_matrix16); s->q_chroma_intra_matrix = s->q_intra_matrix; s->q_chroma_intra_matrix16 = s->q_intra_matrix16; +} else { +s->q_chroma_intra_matrix = m->q_chroma_intra_matrix; +s->q_chroma_intra_matrix16 = m->q_chroma_intra_matrix16; } if ((ret = ff_rate_control_init(m)) < 0) @@ -1015,14 +1015,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) av_freep(&m->cplx_tab); av_freep(&m->bits_tab); -if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); -if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); -s->q_chroma_intra_matrix= NULL; -s->q_chroma_intra_matrix16= NULL; -av_freep(&s->q_intra_matrix); -av_freep(&s->q_inter_matrix); -av_freep(&s->q_intra_matrix16); -av_freep(&s->q_inter_matrix16); av_freep(&s->reordered_input_picture); av_freep(&s->dct_offset); diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index e124555b0a..b83c24debb 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -100,6 +100,13 @@ typedef struct MPVMainEncContext { int16_t (*b_bidir_back_mv_table_base)[2]; int16_t (*b_direct_mv_table_base)[2]; int16_t (*b_field_mv_table_base)[2]; + +int q_inter_matrix[32][64]; +int q_intra_matrix[32][64]; +int q_chroma_intra_matrix[32][64]; +uint16_t q_inter_matrix16[32][2][64]; +uint16_t q_intra_matrix16[32][2][64]; +uint16_t q_chroma_intra_matrix16[32][2][64]; } MPVMainEncContext; #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level)) -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 44/69] avcodec/mpegvideo: Move ratecontrol parameters to MPVMainEncContext
All except vbv_ignore_qmax are only ever used by the main encoding thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 13 - libavcodec/mpegvideo_enc.c | 4 ++-- libavcodec/mpegvideoenc.h | 31 ++- libavcodec/ratecontrol.c | 38 -- libavcodec/snowenc.c | 6 +++--- 5 files changed, 47 insertions(+), 45 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 62347eff81..307964b10e 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -469,21 +469,8 @@ typedef struct MPVContext { int mpv_flags; ///< flags set by private options int quantizer_noise_shaping; -/** - * ratecontrol qmin qmax limiting method - * 0-> clipping, 1-> use a nice continuous function to limit qscale within qmin/qmax. - */ -float rc_qsquish; -float rc_qmod_amp; -int rc_qmod_freq; -float rc_initial_cplx; -float rc_buffer_aggressivity; -float border_masking; -int lmin, lmax; int vbv_ignore_qmax; -char *rc_eq; - /* temp buffers for rate control */ float *cplx_tab, *bits_tab; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index a1ea875546..da417acfae 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -408,7 +408,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) avctx->temporal_cplx_masking || avctx->spatial_cplx_masking || avctx->p_masking || - s->border_masking || + m->border_masking || (s->mpv_flags & FF_MPV_FLAG_QP_RD)) && !s->fixed_qscale; @@ -1748,7 +1748,7 @@ vbv_retry: int min_step = hq ? 1 : (1<<(FF_LAMBDA_SHIFT + 7))/139; if (put_bits_count(&s->pb) > max_size && -s->lambda < s->lmax) { +s->lambda < m->lmax) { m->next_lambda = FFMAX(s->lambda + min_step, s->lambda * (s->qscale + 1) / s->qscale); if (s->adaptive_quant) { diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 350a1f70a6..86c86e0ddf 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -70,6 +70,19 @@ typedef struct MPVMainEncContext { int stuffing_bits; ///< bits used for stuffing int next_lambda; ///< next lambda used for retrying to encode a frame RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c +/** + * ratecontrol qmin qmax limiting method + * 0-> clipping, 1-> use a nice continuous function to limit qscale within qmin/qmax. + */ +float rc_qsquish; +float rc_qmod_amp; +int rc_qmod_freq; +float rc_initial_cplx; +float rc_buffer_aggressivity; +float border_masking; +int lmin, lmax; + +char *rc_eq; /* temporary frames used by b_frame_strategy == 2 */ AVFrame *tmp_frames[MPVENC_MAX_B_FRAMES + 2]; @@ -125,19 +138,19 @@ FF_MPV_OPT_CMP_FUNC, \ { "error_rate", "Simulate errors in the bitstream to test error concealment.", \ FF_MPV_OFFSET(error_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FF_MPV_OPT_FLAGS },\ {"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", \ - FF_MPV_OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, FF_MPV_OPT_FLAGS},\ -{"rc_qmod_amp", "experimental quantizer modulation", FF_MPV_OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \ -{"rc_qmod_freq", "experimental quantizer modulation", FF_MPV_OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS}, \ + FF_MPV_MAIN_OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, FF_MPV_OPT_FLAGS},\ +{"rc_qmod_amp", "experimental quantizer modulation", FF_MPV_MAIN_OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \ +{"rc_qmod_freq", "experimental quantizer modulation", FF_MPV_MAIN_OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS}, \ {"rc_eq", "Set rate control equation. When computing the expression, besides the standard functions "
[FFmpeg-devel] [PATCH v2 49/69] avcodec/mpegvideo: Move scenechange_threshold to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 4 ++-- libavcodec/mpegvideoenc.h | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 0d6b79fe5d..4601c4be64 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -478,7 +478,6 @@ typedef struct MPVContext { int frame_skip_exp; int frame_skip_cmp; -int scenechange_threshold; int noise_reduction; int intra_penalty; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 0e14cebb3f..093f3b948f 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -574,7 +574,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } -if (s->scenechange_threshold < 10 && +if (m->scenechange_threshold < 10 && (avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)) { av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection are not supported yet, " @@ -3634,7 +3634,7 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; emms_c(); -if (s->me.scene_change_score > s->scenechange_threshold && +if (s->me.scene_change_score > m->scenechange_threshold && s->pict_type == AV_PICTURE_TYPE_P) { s->pict_type= AV_PICTURE_TYPE_I; for(i=0; imb_stride*s->mb_height; i++) diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index b83c24debb..0abd315846 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -44,6 +44,8 @@ typedef struct MPVMainEncContext { int me_penalty_compensation; int me_pre; ///< prepass for motion estimation +int scenechange_threshold; + int gop_size; int picture_in_gop_number; ///< 0-> first pic in gop, ... @@ -179,7 +181,7 @@ FF_MPV_OPT_CMP_FUNC, \ {"skip_factor", "Frame skip factor", FF_MPV_OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"skip_exp", "Frame skip exponent", FF_MPV_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"skip_cmp", "Frame skip compare function", FF_MPV_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \ -{"sc_threshold", "Scene change threshold", FF_MPV_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ +{"sc_threshold", "Scene change threshold", FF_MPV_MAIN_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"noise_reduction", "Noise reduction", FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"ps", "RTP payload size in bytes", FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"mepc", "Motion estimation bitrate penalty compensation (1.0 = 256)", FF_MPV_MAIN_OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.i64 = 256 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 50/69] avcodec/mpegvideo: Move dummy dst for depr. opts to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpegenc.c | 2 +- libavcodec/mpegvideo.h| 4 libavcodec/mpegvideoenc.h | 8 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index a8ea63a76d..360653c5a1 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -631,7 +631,7 @@ static int amv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, static const AVOption options[] = { FF_MPV_COMMON_OPTS #if FF_API_MJPEG_PRED -{ "pred", "Deprecated, does nothing", FF_MPV_OFFSET(dummy), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 3, VE, "pred" }, +{ "pred", "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(dummy), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 3, VE, "pred" }, { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "pred" }, { "plane", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "pred" }, { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, INT_MIN, INT_MAX, VE, "pred" }, diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 4601c4be64..9002c0549e 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -481,10 +481,6 @@ typedef struct MPVContext { int noise_reduction; int intra_penalty; - -#if FF_API_MPEGVIDEO_OPTS || FF_API_MJPEG_PRED -int dummy; ///< used as target for deprecated options -#endif } MPVContext; /** diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 0abd315846..51610c051b 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -109,6 +109,10 @@ typedef struct MPVMainEncContext { uint16_t q_inter_matrix16[32][2][64]; uint16_t q_intra_matrix16[32][2][64]; uint16_t q_chroma_intra_matrix16[32][2][64]; + +#if FF_API_MPEGVIDEO_OPTS || FF_API_MJPEG_PRED +int dummy; ///< used as target for deprecated options +#endif } MPVMainEncContext; #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level)) @@ -197,9 +201,9 @@ FF_MPV_OPT_CMP_FUNC, \ #define FF_MPV_DEPRECATED_MPEG_QUANT_OPT \ { "mpeg_quant", "Deprecated, does nothing", FF_MPV_OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 0, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, #define FF_MPV_DEPRECATED_A53_CC_OPT \ -{ "a53cc", "Deprecated, does nothing", FF_MPV_OFFSET(dummy), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, +{ "a53cc", "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(dummy), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, #define FF_MPV_DEPRECATED_MATRIX_OPT \ - { "force_duplicated_matrix", "Deprecated, does nothing", FF_MPV_OFFSET(dummy), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, + { "force_duplicated_matrix", "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(dummy), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, #define FF_MPV_DEPRECATED_BFRAME_OPTS \ { "b_strategy","Deprecated, does nothing", FF_MPV_MAIN_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \ { "b_sensitivity", "Deprecated, does nothing", FF_MPV_MAIN_OFFSET(b_sensitivity),AV_OPT_TYPE_INT, { .i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \ -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 45/69] avcodec/mpegvideo: Allocate encoder-only tables in mpegvideo_enc.c
This commit moves the encoder-only allocations of the tables owned solely by the main encoder context to mpegvideo_enc.c. This avoids checks in mpegvideo.c for whether we are dealing with an encoder; it also improves modularity (if encoders are disabled, this code will no longer be included in the binary). And it also avoids having to reset these pointers at the beginning of ff_mpv_common_init() (in case the dst context is uninitialized, ff_mpeg_update_thread_context() simply copies the src context into dst which therefore may contain pointers not owned by it, but this does not happen for encoders at all). Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 118 +++-- libavcodec/mpegvideo_enc.c | 68 - 2 files changed, 74 insertions(+), 112 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 88cd9bc6ed..5a68a7cf07 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -557,61 +557,13 @@ int ff_mpv_init_context_frame(MPVMainContext *s) s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * s->mb_stride + s->mb_width; // FIXME really needed? -if (s->encoding) { -/* Allocate MV tables */ -if (!FF_ALLOCZ_TYPED_ARRAY(s->p_mv_table_base, mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_forw_mv_table_base, mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_back_mv_table_base, mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_forw_mv_table_base, mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_back_mv_table_base, mv_table_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->b_direct_mv_table_base, mv_table_size)) -return AVERROR(ENOMEM); -s->p_mv_table= s->p_mv_table_base + s->mb_stride + 1; -s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; -s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; -s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base + s->mb_stride + 1; -s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base + s->mb_stride + 1; -s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; - -/* Allocate MB type table */ -if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_type, mb_array_size) || -!FF_ALLOCZ_TYPED_ARRAY(s->lambda_table, mb_array_size) || -!FF_ALLOC_TYPED_ARRAY (s->cplx_tab, mb_array_size) || -!FF_ALLOC_TYPED_ARRAY (s->bits_tab, mb_array_size)) -return AVERROR(ENOMEM); - -#define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * sizeof(*(p -if (s->codec_id == AV_CODEC_ID_MPEG4 || -(s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) { -int16_t (*tmp1)[2]; -uint8_t *tmp2; -if (!(tmp1 = ALLOCZ_ARRAYS(s->b_field_mv_table_base, 8, mv_table_size)) || -!(tmp2 = ALLOCZ_ARRAYS(s->b_field_select_table[0][0], 2 * 4, mv_table_size)) || -!ALLOCZ_ARRAYS(s->p_field_select_table[0], 2 * 2, mv_table_size)) -return AVERROR(ENOMEM); - -s->p_field_select_table[1] = s->p_field_select_table[0] + 2 * mv_table_size; -tmp1 += s->mb_stride + 1; - -for (int i = 0; i < 2; i++) { -for (int j = 0; j < 2; j++) { -for (int k = 0; k < 2; k++) { -s->b_field_mv_table[i][j][k] = tmp1; -tmp1 += mv_table_size; -} -s->b_field_select_table[i][j] = tmp2; -tmp2 += 2 * mv_table_size; -} -} -} -} - if (s->codec_id == AV_CODEC_ID_MPEG4 || (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) { -int16_t (*tmp)[2]; /* interlaced direct mode decoding tables */ -if (!(tmp = ALLOCZ_ARRAYS(s->p_field_mv_table_base, 4, mv_table_size))) +int16_t (*tmp)[2] = av_calloc(mv_table_size, 4 * sizeof(*tmp)); +if (!tmp) return AVERROR(ENOMEM); +s->p_field_mv_table_base = tmp; tmp += s->mb_stride + 1; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { @@ -654,8 +606,6 @@ int ff_mpv_init_context_frame(MPVMainContext *s) static void clear_context(MPVMainContext *s) { -int i, j, k; - memset(&s->next_picture, 0, sizeof(s->next_picture)); memset(&s->last_picture, 0, sizeof(s->last_picture)); memset(&s->current_picture, 0, sizeof(s->current_picture)); @@ -684,31 +634,10 @@ static void clear_context(MPVMainContext *s) s->bitstream_buffer = NULL; s->allocated_bitstream_buffer_size = 0; s->picture = NULL; -s->mb_type = NULL; -s->p_mv_table_base = NULL; -s->b_forw_mv_table_base = NULL; -s->b_back_mv_table_base = NULL; -s->b_bid
[FFmpeg-devel] [PATCH v2 51/69] avcodec/mpegvideo: Move frame_skip_(exp|cmp) to MPVMainEncContext
Only used by the main encoding thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 2 -- libavcodec/mpegvideo_enc.c | 8 libavcodec/mpegvideoenc.h | 7 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 9002c0549e..ce2d36ab15 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -475,8 +475,6 @@ typedef struct MPVContext { /* frame skip options for encoding */ int frame_skip_threshold; int frame_skip_factor; -int frame_skip_exp; -int frame_skip_cmp; int noise_reduction; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 093f3b948f..06c6e5cca1 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -894,7 +894,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->quant_precision = 5; ff_set_cmp(&s->mecc, s->mecc.ildct_cmp, avctx->ildct_cmp); -ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, s->frame_skip_cmp); +ff_set_cmp(&s->mecc, s->mecc.frame_skip_cmp, m->frame_skip_cmp); if (CONFIG_H261_ENCODER && s->out_format == FMT_H261) { ff_h261_encode_init(m); @@ -1236,7 +1236,7 @@ static int skip_check(MPVMainEncContext *m, Picture *p, Picture *ref) uint8_t *rptr = ref->f->data[plane] + 8 * (x + y * stride); int v = s->mecc.frame_skip_cmp[1](s, dptr, rptr, stride, 8); -switch (FFABS(s->frame_skip_exp)) { +switch (FFABS(m->frame_skip_exp)) { case 0: score= FFMAX(score, v); break; case 1: score += FFABS(v); break; case 2: score64 += v * (int64_t)v; break; @@ -1250,9 +1250,9 @@ static int skip_check(MPVMainEncContext *m, Picture *p, Picture *ref) if (score) score64 = score; -if (s->frame_skip_exp < 0) +if (m->frame_skip_exp < 0) score64 = pow(score64 / (double)(s->mb_width * s->mb_height), - -1.0/s->frame_skip_exp); + -1.0/m->frame_skip_exp); if (score64 < s->frame_skip_threshold) return 1; diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 51610c051b..8f6d069369 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -89,6 +89,9 @@ typedef struct MPVMainEncContext { /* temp buffers for rate control */ float *cplx_tab, *bits_tab; +int frame_skip_exp; +int frame_skip_cmp; + /* temporary frames used by b_frame_strategy == 2 */ AVFrame *tmp_frames[MPVENC_MAX_B_FRAMES + 2]; int b_frame_strategy; @@ -183,8 +186,8 @@ FF_MPV_OPT_CMP_FUNC, \ { "xone", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FF_ME_XONE }, 0, 0, FF_MPV_OPT_FLAGS, "motion_est" }, \ {"skip_threshold", "Frame skip threshold", FF_MPV_OFFSET(frame_skip_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"skip_factor", "Frame skip factor", FF_MPV_OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ -{"skip_exp", "Frame skip exponent", FF_MPV_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ -{"skip_cmp", "Frame skip compare function", FF_MPV_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \ +{"skip_exp", "Frame skip exponent", FF_MPV_MAIN_OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ +{"skip_cmp", "Frame skip compare function", FF_MPV_MAIN_OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.i64 = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "cmp_func" }, \ {"sc_threshold", "Scene change threshold", FF_MPV_MAIN_OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"noise_reduction", "Noise reduction", FF_MPV_OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ {"ps", "RTP payload size in bytes", FF_MPV_OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS }, \ -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 52/69] avcodec/mpegvideo: Move input_picture_number to MPVMainEncContext
Only used by the main encoder thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 4 ++-- libavcodec/mpegvideoenc.h | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index ce2d36ab15..99361f0733 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -104,7 +104,6 @@ typedef struct MPVContext { /* sequence parameters */ int context_initialized; -int input_picture_number; ///< used to set pic->display_picture_number, should not be used for/by anything else int coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else int picture_number; //FIXME remove, unclear definition int mb_width, mb_height; ///< number of MBs horizontally & vertically diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 06c6e5cca1..ecc25ba8a2 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -291,7 +291,7 @@ static void mpv_encode_defaults(MPVMainEncContext *m) s->me.mv_penalty = default_mv_penalty; s->fcode_tab = default_fcode_tab; -s->input_picture_number = 0; +m->input_picture_number = 0; m->picture_in_gop_number = 0; } @@ -1080,7 +1080,7 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg) if (pic_arg) { pts = pic_arg->pts; -display_picture_number = s->input_picture_number++; +display_picture_number = m->input_picture_number++; if (pts != AV_NOPTS_VALUE) { if (m->user_specified_pts != AV_NOPTS_VALUE) { diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 8f6d069369..42731a5edc 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -48,6 +48,7 @@ typedef struct MPVMainEncContext { int gop_size; int picture_in_gop_number; ///< 0-> first pic in gop, ... +int input_picture_number; ///< used to set pic->display_picture_number, should not be used for/by anything else /** last non-zero pts from AVFrame which was passed into avcodec_send_frame() */ int64_t user_specified_pts; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 53/69] avcodec/mpegvideo: Move fixed_qscale to MPVMainEncContext
Only used by the main encoding thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 10 +- libavcodec/mpegvideoenc.h | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 99361f0733..a379f65143 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -92,7 +92,6 @@ typedef struct MPVContext { int h263_flv; ///< use flv H.263 header enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */ -int fixed_qscale; ///< fixed qscale if non zero int encoding; ///< true if we are encoding (vs decoding) int max_b_frames; ///< max number of B-frames for encoding int luma_elim_threshold; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index ecc25ba8a2..4dafc68cdd 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -401,7 +401,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) } /* Fixed QSCALE */ -s->fixed_qscale = !!(avctx->flags & AV_CODEC_FLAG_QSCALE); +m->fixed_qscale = !!(avctx->flags & AV_CODEC_FLAG_QSCALE); s->adaptive_quant = (avctx->lumi_masking || avctx->dark_masking || @@ -410,7 +410,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) avctx->p_masking || m->border_masking || (s->mpv_flags & FF_MPV_FLAG_QP_RD)) && -!s->fixed_qscale; +!m->fixed_qscale; s->loop_filter = !!(avctx->flags & AV_CODEC_FLAG_LOOP_FILTER); @@ -474,7 +474,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } -if (!s->fixed_qscale && +if (!m->fixed_qscale && avctx->bit_rate * av_q2d(avctx->time_base) > avctx->bit_rate_tolerance) { double nbt = avctx->bit_rate * av_q2d(avctx->time_base) * 5; @@ -3502,7 +3502,7 @@ static int estimate_qp(MPVMainEncContext *m, int dry_run) s->current_picture_ptr->f->quality = s->current_picture.f->quality = m->next_lambda; if (!dry_run) m->next_lambda= 0; -} else if (!s->fixed_qscale) { +} else if (!m->fixed_qscale) { int quality = ff_rate_estimate_qscale(m, dry_run); s->current_picture_ptr->f->quality = s->current_picture.f->quality = quality; @@ -3622,7 +3622,7 @@ static int encode_picture(MPVMainEncContext *m, int picture_number) for(i=0; imb_stride*s->mb_height; i++) s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; -if(!s->fixed_qscale){ +if (!m->fixed_qscale) { /* finding spatial complexity for I-frame rate control */ s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); } diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index 42731a5edc..5c579cc155 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -46,6 +46,8 @@ typedef struct MPVMainEncContext { int scenechange_threshold; +int fixed_qscale; ///< fixed qscale if non zero + int gop_size; int picture_in_gop_number; ///< 0-> first pic in gop, ... int input_picture_number; ///< used to set pic->display_picture_number, should not be used for/by anything 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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 54/69] avcodec/motion_est: Constify mv-table parameters where possible
Signed-off-by: Andreas Rheinhardt --- libavcodec/motion_est.c | 2 +- libavcodec/motion_est.h | 6 +++--- libavcodec/motion_est_template.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index cc305d06ff..3df1e4f40a 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -1595,7 +1595,7 @@ void ff_estimate_b_frame_motion(MPVEncContext *s, } /* find best f_code for ME which do unlimited searches */ -int ff_get_best_fcode(MPVEncContext *s, int16_t (*mv_table)[2], int type) +int ff_get_best_fcode(MPVEncContext *s, const int16_t (*mv_table)[2], int type) { if (s->motion_est != FF_ME_ZERO) { int score[8]; diff --git a/libavcodec/motion_est.h b/libavcodec/motion_est.h index b52b91ab3f..01ca14f9a9 100644 --- a/libavcodec/motion_est.h +++ b/libavcodec/motion_est.h @@ -119,14 +119,14 @@ int ff_pre_estimate_p_frame_motion(struct MPVEncContext *s, int ff_epzs_motion_search(struct MPVEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, - int16_t (*last_mv)[2], int ref_mv_scale, int size, - int h); + const int16_t (*last_mv)[2], int ref_mv_scale, + int size, int h); int ff_get_mb_score(struct MPVEncContext *s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate); int ff_get_best_fcode(struct MPVEncContext *s, - int16_t (*mv_table)[2], int type); + const int16_t (*mv_table)[2], int type); void ff_fix_long_p_mvs(struct MPVEncContext *s, int type); void ff_fix_long_mvs(struct MPVEncContext *s, uint8_t *field_select_table, diff --git a/libavcodec/motion_est_template.c b/libavcodec/motion_est_template.c index fc887b05b7..a8525afc6f 100644 --- a/libavcodec/motion_est_template.c +++ b/libavcodec/motion_est_template.c @@ -858,7 +858,7 @@ static av_always_inline int diamond_search(MPVEncContext *s, int *best, int dmin optimal mv. */ static av_always_inline int epzs_motion_search_internal(MPVEncContext *s, int *mx_ptr, int *my_ptr, - int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2], + int P[10][2], int src_index, int ref_index, const int16_t (*last_mv)[2], int ref_mv_scale, int flags, int size, int h) { MotionEstContext * const c= &s->me; @@ -976,7 +976,7 @@ static av_always_inline int epzs_motion_search_internal(MPVEncContext *s, int *m //this function is dedicated to the brain damaged gcc int ff_epzs_motion_search(MPVEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, - int16_t (*last_mv)[2], int ref_mv_scale, + const int16_t (*last_mv)[2], int ref_mv_scale, int size, int h) { MotionEstContext * const c= &s->me; @@ -992,7 +992,7 @@ int ff_epzs_motion_search(MPVEncContext *s, int *mx_ptr, int *my_ptr, static int epzs_motion_search2(MPVEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], - int src_index, int ref_index, int16_t (*last_mv)[2], + int src_index, int ref_index, const int16_t (*last_mv)[2], int ref_mv_scale, const int size) { MotionEstContext * const c= &s->me; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 55/69] avcodec/mpegvideo: Constify src of ff_update_duplicate_context()
Also do the same for update_duplicate_context_after_me() in mpegvideo_enc.c. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 2 +- libavcodec/mpegvideo.h | 2 +- libavcodec/mpegvideo_enc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 5a68a7cf07..b71e12c3d9 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -469,7 +469,7 @@ static void backup_duplicate_context(MPVContext *bak, MPVContext *src) #undef COPY } -int ff_update_duplicate_context(MPVContext *dst, MPVContext *src) +int ff_update_duplicate_context(MPVContext *dst, const MPVContext *src) { MPVContext bak; int i, ret; diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index a379f65143..cb947ff56b 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -545,7 +545,7 @@ void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[12][64]); void ff_clean_intra_table_entries(MPVContext *s); -int ff_update_duplicate_context(MPVContext *dst, MPVContext *src); +int ff_update_duplicate_context(MPVContext *dst, const MPVContext *src); void ff_set_qscale(MPVContext *s, int qscale); void ff_mpv_idct_init(MPVContext *s); diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 4dafc68cdd..6c40bdb39e 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -252,7 +252,7 @@ void ff_init_qscale_tab(MPVMainEncContext *m) } static void update_duplicate_context_after_me(MPVEncContext *dst, - MPVEncContext *src) + const MPVEncContext *src) { #define COPY(a) dst->a= src->a COPY(pict_type); -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 35/69] avcodec/mpegvideo: Move pts and dts fields to MPVMainEncContext
user_specified_pts, dts_delta and reordered_pts are only used by the main thread. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 10 -- libavcodec/mpegvideo_enc.c | 22 +++--- libavcodec/mpegvideoenc.h | 11 +++ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 08c795ba17..3dd04d6e82 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -118,16 +118,6 @@ typedef struct MPVContext { Picture **input_picture; ///< next pictures on display order for encoding Picture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding -int64_t user_specified_pts; ///< last non-zero pts from AVFrame which was passed into avcodec_send_frame() -/** - * pts difference between the first and second input frame, used for - * calculating dts of the first frame when there's a delay */ -int64_t dts_delta; -/** - * reordered pts to be used as dts for the next output frame when there's - * a delay */ -int64_t reordered_pts; - /** bit output */ PutBitContext pb; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 86f2b5fcb1..4f64fd28a7 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -391,7 +391,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n"); return AVERROR(EINVAL); } -s->user_specified_pts = AV_NOPTS_VALUE; +m->user_specified_pts = AV_NOPTS_VALUE; if (m->gop_size <= 1) { s->intra_only = 1; @@ -1023,8 +1023,8 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg) display_picture_number = s->input_picture_number++; if (pts != AV_NOPTS_VALUE) { -if (s->user_specified_pts != AV_NOPTS_VALUE) { -int64_t last = s->user_specified_pts; +if (m->user_specified_pts != AV_NOPTS_VALUE) { +int64_t last = m->user_specified_pts; if (pts <= last) { av_log(s->avctx, AV_LOG_ERROR, @@ -1034,13 +1034,13 @@ static int load_input_picture(MPVMainEncContext *m, const AVFrame *pic_arg) } if (!s->low_delay && display_picture_number == 1) -s->dts_delta = pts - last; +m->dts_delta = pts - last; } -s->user_specified_pts = pts; +m->user_specified_pts = pts; } else { -if (s->user_specified_pts != AV_NOPTS_VALUE) { -s->user_specified_pts = -pts = s->user_specified_pts + 1; +if (m->user_specified_pts != AV_NOPTS_VALUE) { +m->user_specified_pts = +pts = m->user_specified_pts + 1; av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts); @@ -1889,10 +1889,10 @@ vbv_retry: pkt->pts = s->current_picture.f->pts; if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) { if (!s->current_picture.f->coded_picture_number) -pkt->dts = pkt->pts - s->dts_delta; +pkt->dts = pkt->pts - m->dts_delta; else -pkt->dts = s->reordered_pts; -s->reordered_pts = pkt->pts; +pkt->dts = m->reordered_pts; +m->reordered_pts = pkt->pts; } else pkt->dts = pkt->pts; if (s->current_picture.f->key_frame) diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h index a177b2d6c6..836fa2eaa3 100644 --- a/libavcodec/mpegvideoenc.h +++ b/libavcodec/mpegvideoenc.h @@ -45,6 +45,17 @@ typedef struct MPVMainEncContext { int gop_size; int picture_in_gop_number; ///< 0-> first pic in gop, ... +/** last non-zero pts from AVFrame which was passed into avcodec_send_frame() */ +int64_t user_specified_pts; +/** + * pts difference between the first and second input frame, used for + * calculating dts of the first frame when there's a delay */ +int64_t dts_delta; +/** + * reordered pts to be used as dts for the next output frame when there's + * a delay */ +int64_t reordered_pts; + /* bit rate control */ int64_t total_bits; int frame_bits;///< bits used for the current frame -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 56/69] avcodec/mpegpicture: Constify src parameter of ff_update_picture_tables
Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegpicture.c | 2 +- libavcodec/mpegpicture.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index 27e497c404..07fc79685c 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -333,7 +333,7 @@ void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic) memset((uint8_t*)pic + off, 0, sizeof(*pic) - off); } -int ff_update_picture_tables(Picture *dst, Picture *src) +int ff_update_picture_tables(Picture *dst, const Picture *src) { int i, ret; diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index e1e9f8d7e0..67f83404fa 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -109,7 +109,7 @@ int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src); void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *picture); void ff_mpv_picture_free(AVCodecContext *avctx, Picture *pic); -int ff_update_picture_tables(Picture *dst, Picture *src); +int ff_update_picture_tables(Picture *dst, const Picture *src); int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared); -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 58/69] avcodec/mpegvideo: Move slice-context ptr array to MPVMainContext
The slice contexts don't have sub-slice contexts, so it makes no sense for them to have an array of pointers to slice contexts. Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpegenc.c | 2 +- libavcodec/mpeg12dec.c | 12 ++-- libavcodec/mpegvideo.c | 21 ++--- libavcodec/mpegvideo.h | 3 ++- libavcodec/mpegvideo_dec.c | 11 ++- libavcodec/mpegvideo_enc.c | 29 +++-- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index faf59566b1..70636ffc91 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -86,7 +86,7 @@ static void mjpeg_encode_picture_header(MPVMainEncContext *m) 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; +m2->thread_context[i]->esc_pos = 0; } void ff_mjpeg_amv_encode_picture_header(MPVMainEncContext *main) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index ef2fa80aba..925c72e8ff 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2503,10 +2503,10 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, av_assert0(avctx->thread_count > 1); avctx->execute(avctx, slice_decode_thread, - &s2->thread_context[0], NULL, + &m2->thread_context[0], NULL, s->slice_count, sizeof(void *)); for (i = 0; i < s->slice_count; i++) -s2->er.error_count += s2->thread_context[i]->er.error_count; +s2->er.error_count += m2->thread_context[i]->er.error_count; } ret = slice_end(avctx, picture); @@ -2575,10 +2575,10 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, int i; avctx->execute(avctx, slice_decode_thread, - s2->thread_context, NULL, + m2->thread_context, NULL, s->slice_count, sizeof(void *)); for (i = 0; i < s->slice_count; i++) -s2->er.error_count += s2->thread_context[i]->er.error_count; +s2->er.error_count += m2->thread_context[i]->er.error_count; s->slice_count = 0; } if (last_code == 0 || last_code == SLICE_MIN_START_CODE) { @@ -2774,12 +2774,12 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, s2->slice_context_count; av_assert0(avctx->thread_count > 1); if (threshold <= mb_y) { -MPVDecContext *const thread_context = s2->thread_context[s->slice_count]; +MPVDecContext *const thread_context = m2->thread_context[s->slice_count]; thread_context->start_mb_y = mb_y; thread_context->end_mb_y = s2->mb_height; if (s->slice_count) { -s2->thread_context[s->slice_count - 1]->end_mb_y = mb_y; +m2->thread_context[s->slice_count - 1]->end_mb_y = mb_y; ret = ff_update_duplicate_context(thread_context, s2); if (ret < 0) return ret; diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 072a82e6b3..220f1c39f0 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -400,14 +400,15 @@ int ff_mpv_init_duplicate_contexts(MPVMainContext *m) * fields allocated in init_duplicate_context are NULL after * copying. This prevents double-frees upon allocation error. */ for (int i = 1; i < nb_slices; i++) { -s->thread_context[i] = av_memdup(s, sizeof(MPVContext)); -if (!s->thread_context[i]) +MPVContext *const s2 = av_memdup(s, sizeof(MPVContext)); +if (!s2) return AVERROR(ENOMEM); -if ((ret = init_duplicate_context(s->thread_context[i])) < 0) +m->thread_context[i] = s2; +if ((ret = init_duplicate_context(s2)) < 0) return ret; -s->thread_context[i]->start_mb_y = +s2->start_mb_y = (s->mb_height * (i) + nb_slices / 2) / nb_slices; -s->thread_context[i]->end_mb_y = +s2->end_mb_y = (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; } s->start_mb_y = 0; @@ -441,8 +442,8 @@ static void free_duplicate_contexts(MPVMainContext *m) MPVContext *const s = &m->s; for (int i = 1; i < s->slice_context_count; i++) { -free_duplicate_context(s->thread_context[i]); -av_freep(&s->thread_context[i]); +free_duplicate_context(m->thread_context[i]); +
[FFmpeg-devel] [PATCH v2 59/69] avcodec/mpegvideo: Add ptr to main MPVMainContext to slice contexts
It is a pointer to const to allow the slice threads to inspect values without modifying them. Signed-off-by: Andreas Rheinhardt --- I am unsure whether this should be a pointer to const void or a pointer to const MPVMainContext. libavcodec/mpegvideo.c | 3 +++ libavcodec/mpegvideo.h | 2 ++ libavcodec/mpegvideo_dec.c | 2 ++ 3 files changed, 7 insertions(+) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 220f1c39f0..4b22eb746a 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -396,6 +396,8 @@ int ff_mpv_init_duplicate_contexts(MPVMainContext *m) MPVContext *const s = &m->s; int nb_slices = s->slice_context_count, ret; +s->parent_ctx = m; + /* We initialize the copies before the original so that * fields allocated in init_duplicate_context are NULL after * copying. This prevents double-frees upon allocation error. */ @@ -524,6 +526,7 @@ void ff_mpv_common_defaults(MPVMainContext *m) s->b_code= 1; s->slice_context_count = 1; +s->parent_ctx= m; } int ff_mpv_init_context_frame(MPVMainContext *m) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 9005dcb58a..1c44e9be2f 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -76,6 +76,8 @@ typedef struct MPVContext { * offsets used in ASM. */ struct AVCodecContext *avctx; +/* A pointer to this context's parent MPVMainContext. */ +const struct MPVMainContext *parent_ctx; /* The following pointer is intended for codecs sharing code * between decoder and encoder and in need of a common context to do so. */ void *private_ctx; diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index f202db33e9..fd97e6ac1a 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -72,6 +72,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, memcpy(s, s1, sizeof(*s)); s->avctx = dst; +s->parent_ctx= m; s->private_ctx = private_ctx; s->bitstream_buffer = NULL; s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0; @@ -83,6 +84,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, if ((err = ff_mpv_common_init(m)) < 0) { memset(s, 0, sizeof(*s)); s->avctx = dst; +s->parent_ctx = m; s->private_ctx = private_ctx; return err; } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 60/69] avcodec/mpegvideo: Move slice_context_count to MPVMainContext
Signed-off-by: Andreas Rheinhardt --- libavcodec/mjpegenc.c | 6 +++--- libavcodec/mpeg12dec.c | 4 ++-- libavcodec/mpeg4video_parser.c | 2 +- libavcodec/mpegvideo.c | 13 ++--- libavcodec/mpegvideo.h | 3 ++- libavcodec/mpegvideo_enc.c | 8 libavcodec/vc1_parser.c| 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index 70636ffc91..bf6371768a 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -82,10 +82,10 @@ static void mjpeg_encode_picture_header(MPVMainEncContext *m) ff_mjpeg_encode_picture_header(s->avctx, &s->pb, s->mjpeg_ctx, &s->intra_scantable, 0, s->intra_matrix, s->chroma_intra_matrix, - s->slice_context_count > 1); + m2->slice_context_count > 1); s->esc_pos = put_bytes_count(&s->pb, 0); -for (int i = 1; i < s->slice_context_count; i++) +for (int i = 1; i < m2->slice_context_count; i++) m2->thread_context[i]->esc_pos = 0; } @@ -255,7 +255,7 @@ int ff_mjpeg_encode_stuffing(MPVEncContext *s) ff_mjpeg_escape_FF(pbc, s->esc_pos); -if (s->slice_context_count > 1 && mb_y < s->mb_height - 1) +if (s->parent_ctx->slice_context_count > 1 && mb_y < s->mb_height - 1) put_marker(pbc, RST0 + (mb_y&7)); s->esc_pos = put_bytes_count(pbc, 0); diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 925c72e8ff..69d0bb809b 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2770,8 +2770,8 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, (avctx->active_thread_type & FF_THREAD_SLICE) && !avctx->hwaccel) { int threshold = (s2->mb_height * s->slice_count + - s2->slice_context_count / 2) / -s2->slice_context_count; + m2->slice_context_count / 2) / +m2->slice_context_count; av_assert0(avctx->thread_count > 1); if (threshold <= mb_y) { MPVDecContext *const thread_context = m2->thread_context[s->slice_count]; diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c index adc2409953..a7909d92ec 100644 --- a/libavcodec/mpeg4video_parser.c +++ b/libavcodec/mpeg4video_parser.c @@ -132,7 +132,7 @@ static av_cold int mpeg4video_parse_init(AVCodecParserContext *s) pc->first_picture = 1; pc->dec_ctx.m.s.quant_precision = 5; -pc->dec_ctx.m.s.slice_context_count = 1; +pc->dec_ctx.m.slice_context_count = 1; pc->dec_ctx.showed_packed_warning = 1; return 0; } diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 4b22eb746a..0e98680056 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -394,7 +394,7 @@ static int init_duplicate_context(MPVContext *s) int ff_mpv_init_duplicate_contexts(MPVMainContext *m) { MPVContext *const s = &m->s; -int nb_slices = s->slice_context_count, ret; +int nb_slices = m->slice_context_count, ret; s->parent_ctx = m; @@ -443,7 +443,7 @@ static void free_duplicate_contexts(MPVMainContext *m) { MPVContext *const s = &m->s; -for (int i = 1; i < s->slice_context_count; i++) { +for (int i = 1; i < m->slice_context_count; i++) { free_duplicate_context(m->thread_context[i]); av_freep(&m->thread_context[i]); } @@ -525,7 +525,7 @@ void ff_mpv_common_defaults(MPVMainContext *m) s->f_code= 1; s->b_code= 1; -s->slice_context_count = 1; +m->slice_context_count = 1; s->parent_ctx= m; } @@ -625,7 +625,6 @@ static void clear_context(MPVMainContext *m) memset(&s->current_picture, 0, sizeof(s->current_picture)); memset(&s->new_picture, 0, sizeof(s->new_picture)); -s->slice_context_count = 1; s->me.map = NULL; s->me.score_map = NULL; s->dct_error_sum = NULL; @@ -740,7 +739,7 @@ av_cold int ff_mpv_common_init(MPVMainContext *m) s->context_initialized = 1; m->thread_context[0] = s; -s->slice_context_count = nb_slices; +m->slice_context_count = nb_slices; // if (s->width && s->height) { ret = ff_mpv_init_duplicate_contexts(m); @@ -791,8 +790,8 @@ void ff_mpv_common_end(MPVMainContext *m) s = &m->s; ff_mpv_free_context_frame(m); -if (s->slice_context_count > 1) -s->slice_context_count = 1; +if (m->slice_context_count > 1) +m->slice_context_count = 1; #if FF_API_FLAG_TRUNCATED av_freep(&s->parse_context.buffer); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 1c44e9be2f..4a03cde7fe 100644 --- a/libavcodec/mpe
[FFmpeg-devel] [PATCH v2 61/69] avcodec/mpegvideo: Move reordered_input_picture to MPVMainEncContext
Also avoid an allocation while at it. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg4videoenc.c | 8 +++--- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 51 +++--- libavcodec/mpegvideoenc.h | 2 ++ 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index 7ad93f9e4c..07c82cc54d 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -632,6 +632,8 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type == MV_TYPE_16X16) { +const MPVMainEncContext *const m = + (MPVMainEncContext *)s->parent_ctx; /* Check if the B-frames can skip it too, as we must skip it * if we skip here why didn't they just compress * the skip-mb bits instead of reusing them ?! */ @@ -648,9 +650,9 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], s->mb_skipped = 1; for (i = 0; i < s->max_b_frames; i++) { +const Picture *const pic = m->reordered_input_picture[i + 1]; uint8_t *b_pic; int diff; -Picture *pic = s->reordered_input_picture[i + 1]; if (!pic || pic->f->pict_type != AV_PICTURE_TYPE_B) break; @@ -890,8 +892,8 @@ static void mpeg4_encode_gop_header(MPVMainEncContext *m) put_bits(&s->pb, 16, GOP_STARTCODE); time = s->current_picture_ptr->f->pts; -if (s->reordered_input_picture[1]) -time = FFMIN(time, s->reordered_input_picture[1]->f->pts); +if (m->reordered_input_picture[1]) +time = FFMIN(time, m->reordered_input_picture[1]->f->pts); time = time * s->avctx->time_base.num; s->last_time_base = FFUDIV(time, s->avctx->time_base.den); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 4a03cde7fe..fefcb90188 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -115,7 +115,6 @@ typedef struct MPVContext { ptrdiff_t linesize;///< line size, in bytes, may be different from width ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width Picture *picture; ///< main picture buffer -Picture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding /** bit output */ PutBitContext pb; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index aef4de0fe6..4a90799d17 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -871,8 +871,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) } } -if (!(avctx->stats_out = av_mallocz(256)) || -!FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT)) +if (!(avctx->stats_out = av_mallocz(256))) return AVERROR(ENOMEM); if (s->noise_reduction) { @@ -1017,7 +1016,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) av_freep(&m->cplx_tab); av_freep(&m->bits_tab); -av_freep(&s->reordered_input_picture); av_freep(&s->dct_offset); return 0; @@ -1438,11 +1436,11 @@ static int select_input_picture(MPVMainEncContext *m) int i, ret; for (i = 1; i < MAX_PICTURE_COUNT; i++) -s->reordered_input_picture[i - 1] = s->reordered_input_picture[i]; -s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL; +m->reordered_input_picture[i - 1] = m->reordered_input_picture[i]; +m->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL; /* set next picture type & ordering */ -if (!s->reordered_input_picture[0] && m->input_picture[0]) { +if (!m->reordered_input_picture[0] && m->input_picture[0]) { if (s->frame_skip_threshold || s->frame_skip_factor) { if (m->picture_in_gop_number < m->gop_size && s->next_picture_ptr && @@ -1458,9 +1456,9 @@ static int select_input_picture(MPVMainEncContext *m) if (/*s->picture_in_gop_number >= s->gop_size ||*/ !s->next_picture_ptr || s->intra_only) { -s->reordered_input_picture[0] = m->input_picture[0]; -s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; -s->reordered_input_picture[0]->f->coded_picture_number = +m->reordered_input_picture[0] = m->input_picture[0]; +m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; +m->reordered_input_picture[0]->f->coded_picture_number = s->coded_picture_number++; } else { int b_frames = 0; @@ -1543,16 +1541,16 @@ static int select_input_picture(MPVMainEncContext *m) m->input_picture[b_frames]->f->pict_type ==
[FFmpeg-devel] [PATCH v2 62/69] avcodec/mpegvideo: Move max_b_frames to MPVMainEncContext
With the exception of VC-1-based decoders no decoder sets this, so move it to MPVMainEncContext and add a replacement field to VC1Context. Signed-off-by: Andreas Rheinhardt --- libavcodec/dxva2_vc1.c | 2 +- libavcodec/mpeg4videoenc.c | 8 libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_dec.c | 1 - libavcodec/mpegvideo_enc.c | 38 +++--- libavcodec/mpegvideoenc.h | 1 + libavcodec/mss2.c | 2 +- libavcodec/nvdec_vc1.c | 2 +- libavcodec/ratecontrol.c | 6 +++--- libavcodec/vc1.c | 4 ++-- libavcodec/vc1.h | 1 + libavcodec/vdpau_vc1.c | 2 +- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c index 836367ffe8..d901f023df 100644 --- a/libavcodec/dxva2_vc1.c +++ b/libavcodec/dxva2_vc1.c @@ -113,7 +113,7 @@ static void fill_picture_parameters(AVCodecContext *avctx, (v->multires << 5) | (v->resync_marker << 4) | (v->rangered << 3) | - (s->max_b_frames ); + (v->max_b_frames ); pp->bPicExtrapolation = (!v->interlace || v->fcm == PROGRESSIVE) ? 1 : 2; pp->bPicDeblocked = ((!pp->bPicBackwardPrediction && v->overlap) << 6) | ((v->profile != PROFILE_ADVANCED && v->rangeredfrm) << 5) | diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index 07c82cc54d..9bc6fb9388 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -637,7 +637,7 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], /* Check if the B-frames can skip it too, as we must skip it * if we skip here why didn't they just compress * the skip-mb bits instead of reusing them ?! */ -if (s->max_b_frames > 0) { +if (m->max_b_frames > 0) { int i; int x, y, offset; uint8_t *p_pic; @@ -649,7 +649,7 @@ void ff_mpeg4_encode_mb(MPVEncContext *s, int16_t block[6][64], p_pic = s->new_picture.f->data[0] + offset; s->mb_skipped = 1; -for (i = 0; i < s->max_b_frames; i++) { +for (i = 0; i < m->max_b_frames; i++) { const Picture *const pic = m->reordered_input_picture[i + 1]; uint8_t *b_pic; int diff; @@ -921,7 +921,7 @@ static void mpeg4_encode_visual_object_header(MPVMainEncContext *m) if (s->avctx->profile != FF_PROFILE_UNKNOWN) { profile_and_level_indication = s->avctx->profile << 4; -} else if (s->max_b_frames || s->quarter_sample) { +} else if (m->max_b_frames || s->quarter_sample) { profile_and_level_indication = 0xF0; // adv simple } else { profile_and_level_indication = 0x00; // simple @@ -965,7 +965,7 @@ static void mpeg4_encode_vol_header(MPVMainEncContext *m, MPVEncContext *const s = &m->common.s; int vo_ver_id, vo_type, aspect_ratio_info; -if (s->max_b_frames || s->quarter_sample) { +if (m->max_b_frames || s->quarter_sample) { vo_ver_id = 5; vo_type = ADV_SIMPLE_VO_TYPE; } else { diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index fefcb90188..8632fadae5 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -95,7 +95,6 @@ typedef struct MPVContext { enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */ int encoding; ///< true if we are encoding (vs decoding) -int max_b_frames; ///< max number of B-frames for encoding int luma_elim_threshold; int chroma_elim_threshold; int strict_std_compliance; ///< strictly follow the std (MPEG-4, ...) diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index fd97e6ac1a..57c93de621 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -151,7 +151,6 @@ do {\ (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; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 4a90799d17..2fbcfd56e1 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -363,9 +363,9 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) "max b frames must be 0 or positive for mpegvideo based encoders\n"); return AVERROR(EINVAL); } -s->max_b_frames = avctx->max_b_frames; +m->max_b_frames = avctx->max_b_frames; s->codec_id = avctx->codec->id; -if (s->max_b_frames && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) { +if (m->max_b_frames && !(avctx->
[FFmpeg-devel] [PATCH v2 64/69] avcodec/mpegvideo: Move coded_picture_number to MPVMainContext
It is not used by slice threads at all. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 2 +- libavcodec/mpegvideo.h | 3 ++- libavcodec/mpegvideo_dec.c | 4 ++-- libavcodec/mpegvideo_enc.c | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index be18b428f5..8debf4d6ab 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -519,7 +519,7 @@ void ff_mpv_common_defaults(MPVMainContext *m) s->progressive_sequence = 1; s->picture_structure = PICT_FRAME; -s->coded_picture_number = 0; +m->coded_picture_number = 0; s->picture_number= 0; s->f_code= 1; diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index df5a51577a..99d474991a 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -103,7 +103,6 @@ typedef struct MPVContext { /* the following fields are managed internally by the encoder */ /* sequence parameters */ -int coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else int picture_number; //FIXME remove, unclear definition int mb_width, mb_height; ///< number of MBs horizontally & vertically int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 @@ -505,6 +504,8 @@ typedef struct MPVMainContext { * a frame size change */ int context_reinit; +int coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else + int slice_context_count; ///< number of used thread_contexts /* The first entry of this array points to the above MPVContext. */ MPVContext *thread_context[MAX_THREADS]; diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index a4f751af71..48371aa886 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -105,7 +105,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, s->quarter_sample = s1->quarter_sample; -s->coded_picture_number = s1->coded_picture_number; +m->coded_picture_number = m1->coded_picture_number; s->picture_number = s1->picture_number; av_assert0(!s->picture || s->picture != s1->picture); @@ -339,7 +339,7 @@ int ff_mpv_frame_start(MPVMainDecContext *m, AVCodecContext *avctx) pic->reference = 3; } -pic->f->coded_picture_number = s->coded_picture_number++; +pic->f->coded_picture_number = m->coded_picture_number++; if (alloc_picture(s, pic) < 0) return -1; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 2fbcfd56e1..3e9f8b4e42 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1459,7 +1459,7 @@ static int select_input_picture(MPVMainEncContext *m) m->reordered_input_picture[0] = m->input_picture[0]; m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; m->reordered_input_picture[0]->f->coded_picture_number = -s->coded_picture_number++; +m2->coded_picture_number++; } else { int b_frames = 0; @@ -1545,13 +1545,13 @@ static int select_input_picture(MPVMainEncContext *m) if (m->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; m->reordered_input_picture[0]->f->coded_picture_number = -s->coded_picture_number++; +m2->coded_picture_number++; for (i = 0; i < b_frames; i++) { m->reordered_input_picture[i + 1] = m->input_picture[i]; m->reordered_input_picture[i + 1]->f->pict_type = AV_PICTURE_TYPE_B; m->reordered_input_picture[i + 1]->f->coded_picture_number = -s->coded_picture_number++; +m2->coded_picture_number++; } } } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 65/69] avcodec/mpegvideo: Move arrays owned by main thread to MPVMainContext
This commit moves the base pointers of arrays only allocated by the main thread to MPVMainContext (in case there is a base pointer). Signed-off-by: Andreas Rheinhardt --- These arrays are no longer reset in clear_context() because it is my understanding that there is only one place in the code where these array pointers could become invalid: in ff_mpeg_update_thread_context() where one context is copied over another. Yet only the MPVContext, not the MPVMainContext is copied, so that these base array pointers are always valid. Hopefully this can be checked with the testcase from commit b160fc290cf49b516c5b6ee0730fd9da7fc623b1. libavcodec/mpegvideo.c | 23 ++- libavcodec/mpegvideo.h | 7 --- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 8debf4d6ab..c8eaafcc1c 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -575,7 +575,7 @@ int ff_mpv_init_context_frame(MPVMainContext *m) int16_t (*tmp)[2] = av_calloc(mv_table_size, 4 * sizeof(*tmp)); if (!tmp) return AVERROR(ENOMEM); -s->p_field_mv_table_base = tmp; +m->p_field_mv_table_base = tmp; tmp += s->mb_stride + 1; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { @@ -587,23 +587,23 @@ int ff_mpv_init_context_frame(MPVMainContext *m) if (s->out_format == FMT_H263) { /* cbp values, cbp, ac_pred, pred_dir */ -if (!(s->coded_block_base = av_mallocz(y_size + (s->mb_height&1)*2*s->b8_stride)) || +if (!(m->coded_block_base = av_mallocz(y_size + (s->mb_height&1)*2*s->b8_stride)) || !(s->cbp_table= av_mallocz(mb_array_size)) || !(s->pred_dir_table = av_mallocz(mb_array_size))) return AVERROR(ENOMEM); -s->coded_block = s->coded_block_base + s->b8_stride + 1; +s->coded_block = m->coded_block_base + s->b8_stride + 1; } if (s->h263_pred || s->h263_plus || !s->encoding) { /* dc values */ // MN: we need these for error resilience of intra-frames -if (!FF_ALLOCZ_TYPED_ARRAY(s->dc_val_base, yc_size)) +if (!FF_ALLOCZ_TYPED_ARRAY(m->dc_val_base, yc_size)) return AVERROR(ENOMEM); -s->dc_val[0] = s->dc_val_base + s->b8_stride + 1; -s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; +s->dc_val[0] = m->dc_val_base + s->b8_stride + 1; +s->dc_val[1] = m->dc_val_base + y_size + s->mb_stride + 1; s->dc_val[2] = s->dc_val[1] + c_size; for (i = 0; i < yc_size; i++) -s->dc_val_base[i] = 1024; +m->dc_val_base[i] = 1024; } /* which mb is an intra block, init macroblock skip table */ @@ -646,13 +646,10 @@ static void clear_context(MPVMainContext *m) s->bitstream_buffer = NULL; s->allocated_bitstream_buffer_size = 0; s->picture = NULL; -s->p_field_mv_table_base = NULL; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) s->p_field_mv_table[i][j] = NULL; -s->dc_val_base = NULL; -s->coded_block_base = NULL; s->mbintra_table = NULL; s->cbp_table = NULL; s->pred_dir_table = NULL; @@ -761,13 +758,13 @@ void ff_mpv_free_context_frame(MPVMainContext *m) free_duplicate_contexts(m); -av_freep(&s->p_field_mv_table_base); +av_freep(&m->p_field_mv_table_base); for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) s->p_field_mv_table[i][j] = NULL; -av_freep(&s->dc_val_base); -av_freep(&s->coded_block_base); +av_freep(&m->dc_val_base); +av_freep(&m->coded_block_base); av_freep(&s->mbintra_table); av_freep(&s->cbp_table); av_freep(&s->pred_dir_table); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 99d474991a..56c1d8118c 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -147,12 +147,10 @@ typedef struct MPVContext { Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred) Picture *current_picture_ptr; ///< pointer to the current picture int last_dc[3];///< last DC values for MPEG-1 -int16_t *dc_val_base; int16_t *dc_val[3];///< used for MPEG-4 DC prediction, all 3 arrays must be continuous const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (H.263) -uint8_t *coded_block_base; uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1) int16_t (*ac_val_base)[16]; int16_t (*ac_val[3])[16]; ///< used for MPEG-4 AC prediction, all 3 arrays must be continuous @@ -194,7 +192,6 @@ typedef struct MPVContext { H263DSPContext h263dsp; int f_code;
[FFmpeg-devel] [PATCH v2 66/69] avcodec/mpegvideo: Remove strict_std_compliance from MPVContext
It just duplicates AVCodecContext.strict_std_compliance. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg12enc.c | 2 +- libavcodec/mpeg4videoenc.c | 4 ++-- libavcodec/mpegvideo.h | 1 - libavcodec/mpegvideo_enc.c | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index 4b885669bc..a9d87f6854 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -223,7 +223,7 @@ static av_cold int encode_init(AVCodecContext *avctx) return ret; if (find_frame_rate_index(mpeg12) < 0) { -if (s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { +if (avctx->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); return AVERROR(EINVAL); diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index 9bc6fb9388..2f78763344 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -1068,9 +1068,9 @@ int ff_mpeg4_encode_picture_header(MPVMainEncContext *m, int picture_number) if (s->pict_type == AV_PICTURE_TYPE_I) { if (!(s->avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)) { -if (s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy +if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy mpeg4_encode_visual_object_header(m); -if (s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number == 0) // HACK, the reference sw is buggy +if (s->avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number == 0) // HACK, the reference sw is buggy mpeg4_encode_vol_header(m, 0, 0); } if (!(s->workaround_bugs & FF_BUG_MS)) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 56c1d8118c..a65c23f1d1 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -97,7 +97,6 @@ typedef struct MPVContext { int encoding; ///< true if we are encoding (vs decoding) int luma_elim_threshold; int chroma_elim_threshold; -int strict_std_compliance; ///< strictly follow the std (MPEG-4, ...) int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically int codec_tag; ///< internal codec_tag upper case converted from avctx codec_tag /* the following fields are managed internally by the encoder */ diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 3e9f8b4e42..d3e52126d7 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -370,7 +370,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } -s->strict_std_compliance = avctx->strict_std_compliance; s->quarter_sample = (avctx->flags & AV_CODEC_FLAG_QPEL) != 0; s->rtp_mode = !!s->rtp_payload_size; s->intra_dc_precision = avctx->intra_dc_precision; @@ -585,7 +584,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) if (avctx->flags & AV_CODEC_FLAG_LOW_DELAY) { if (s->codec_id != AV_CODEC_ID_MPEG2VIDEO && -s->strict_std_compliance >= FF_COMPLIANCE_NORMAL) { +avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) { av_log(avctx, AV_LOG_ERROR, "low delay forcing is only available for mpeg2, " "set strict_std_compliance to 'unofficial' or lower in order to allow it\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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 67/69] avcodec/mpegvideo_dec: Remove commented-out cruft
This piece of code has been added in an already commented-out state in commit 158c7f059c3906b0116ae73a7669a3bb7bc570bb. It certainly doesn't make sense now (if ever) because new_picture_ptr it used has been removed in 6571e41dcdee4655237bca0a3277df8976167aee (and new_picture is only used for encoding). Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_dec.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 48371aa886..8927a0a21b 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -358,8 +358,6 @@ int ff_mpv_frame_start(MPVMainDecContext *m, AVCodecContext *avctx) 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, -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 68/69] avcodec/mpegvideo_dec: Remove potentially UB always-true checks
ff_mpeg_update_thread_context() currently checks for whether the source (current|last|next)_picture_ptr points into the src context's picture array by performing a pointer comparison. Yet pointer comparisons are only legal when the pointers point into the same array object (or one past the last element); otherwise they are undefined behaviour that happen to work (at least with a flat address space). In this case this code is moreover a remnant of the time when the H.264 decoder used H.264 (see the commit message of d9df93efbf59b1dc8b013d174ca4ad9c634c28f7); the current decoders never set these pointers to anything outside of the picture array (except NULL). So remove these checks. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 3 +++ libavcodec/mpegvideo_dec.c | 7 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index a65c23f1d1..af1d9af2bd 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -142,6 +142,9 @@ typedef struct MPVContext { */ Picture current_picture;///< buffer to store the decompressed current picture +/* The following three pointers must be either NULL or point + * to a picture in the main picture buffer (i.e. picture) + * for users of mpegvideodec. */ Picture *last_picture_ptr; ///< pointer to the previous picture. Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred) Picture *current_picture_ptr; ///< pointer to the current picture diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 8927a0a21b..137b47efa7 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -74,6 +74,9 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, s->avctx = dst; s->parent_ctx= m; s->private_ctx = private_ctx; +s->current_picture_ptr = NULL; +s->next_picture_ptr = NULL; +s->last_picture_ptr = NULL; s->bitstream_buffer = NULL; s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0; @@ -133,9 +136,7 @@ do {\ 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) +((pic) ? &(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); -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH v2 69/69] avcodec/mpegvideo: Move picture array to MPVMainContext
Also avoid an allocation while at it. Signed-off-by: Andreas Rheinhardt --- libavcodec/h263dec.c | 7 ++--- libavcodec/mpegvideo.c | 14 +++--- libavcodec/mpegvideo.h | 5 +++- libavcodec/mpegvideo_dec.c | 54 +++--- libavcodec/mpegvideo_enc.c | 12 - 5 files changed, 45 insertions(+), 47 deletions(-) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index b502878a4a..dc09d2e15c 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -431,7 +431,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { MPVMainDecContext *const m = avctx->priv_data; -MPVDecContext *const s = &m->s; +MPVMainContext *const m2 = m; +MPVDecContext *const s = &m2->s; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; int ret; @@ -547,10 +548,10 @@ retry: } if (!s->current_picture_ptr || s->current_picture_ptr->f->data[0]) { -int i = ff_find_unused_picture(s->avctx, s->picture, 0); +int i = ff_find_unused_picture(s->avctx, m2->picture, 0); if (i < 0) return i; -s->current_picture_ptr = &s->picture[i]; +s->current_picture_ptr = &m2->picture[i]; } avctx->has_b_frames = !s->low_delay; diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index c8eaafcc1c..7314f1b39e 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -645,7 +645,6 @@ static void clear_context(MPVMainContext *m) s->bitstream_buffer = NULL; s->allocated_bitstream_buffer_size = 0; -s->picture = NULL; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) s->p_field_mv_table[i][j] = NULL; @@ -713,11 +712,9 @@ av_cold int ff_mpv_common_init(MPVMainContext *m) if (ret) return ret; -if (!FF_ALLOCZ_TYPED_ARRAY(s->picture, MAX_PICTURE_COUNT)) -return AVERROR(ENOMEM); for (i = 0; i < MAX_PICTURE_COUNT; i++) { -s->picture[i].f = av_frame_alloc(); -if (!s->picture[i].f) +m->picture[i].f = av_frame_alloc(); +if (!m->picture[i].f) goto fail_nomem; } @@ -801,11 +798,8 @@ void ff_mpv_common_end(MPVMainContext *m) if (!s->avctx) return; -if (s->picture) { -for (int i = 0; i < MAX_PICTURE_COUNT; i++) -ff_mpv_picture_free(s->avctx, &s->picture[i]); -} -av_freep(&s->picture); +for (int i = 0; i < MAX_PICTURE_COUNT; i++) +ff_mpv_picture_free(s->avctx, &m->picture[i]); ff_mpv_picture_free(s->avctx, &s->last_picture); ff_mpv_picture_free(s->avctx, &s->current_picture); ff_mpv_picture_free(s->avctx, &s->next_picture); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index af1d9af2bd..ba081a9087 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -110,7 +110,6 @@ typedef struct MPVContext { int mb_num;///< number of MBs of a picture ptrdiff_t linesize;///< line size, in bytes, may be different from width ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width -Picture *picture; ///< main picture buffer /** bit output */ PutBitContext pb; @@ -498,6 +497,10 @@ typedef struct MPVContext { typedef struct MPVMainContext { MPVContext s; +/* The main picture buffer. The pictures therein are usable iff + * the context is initialized. */ +Picture picture[MAX_PICTURE_COUNT]; + int context_initialized; /* flag to indicate a reinitialization is required, e.g. after * a frame size change */ diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 137b47efa7..8f3c401aff 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -111,12 +111,11 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, m->coded_picture_number = m1->coded_picture_number; s->picture_number = s1->picture_number; -av_assert0(!s->picture || s->picture != s1->picture); -if (s->picture) +if (m->context_initialized) 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) +ff_mpeg_unref_picture(s->avctx, &m->picture[i]); +if (m1->context_initialized && m1->picture[i].f->buf[0] && +(ret = ff_mpeg_ref_picture(s->avctx, &m->picture[i], &m1->picture[i])) < 0) return ret; } @@ -138,9 +137,9 @@ do {\ #define REBASE_PICTURE(pic, new_ctx, old_ctx) \ ((pic) ? &(new_ctx)->picture[(pic) - (old_ctx)->picture] : NULL) -s->last_picture_ptr= REBASE_PICTURE(s1->last_picture_ptr,s, s1); -
[FFmpeg-devel] [PATCH v2 63/69] avcodec/mpegvideo: Move context_initialized flag to MPVMainContext
This is not a per-slice property. Also move context_reinit. Signed-off-by: Andreas Rheinhardt --- libavcodec/h261dec.c | 2 +- libavcodec/h263dec.c | 8 libavcodec/mpeg12dec.c | 2 +- libavcodec/mpeg4videodec.c | 8 libavcodec/mpegvideo.c | 6 +++--- libavcodec/mpegvideo.h | 10 +- libavcodec/mpegvideo_dec.c | 12 ++-- libavcodec/rv10.c | 2 +- libavcodec/rv34.c | 14 +++--- libavcodec/vc1dec.c| 4 ++-- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index 8113d2ff7d..8774f4e7ad 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -625,7 +625,7 @@ retry: ff_mpv_common_end(m); } -if (!s->context_initialized) { +if (!m->context_initialized) { if ((ret = ff_mpv_common_init(m)) < 0) return ret; diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 20a1348d88..b502878a4a 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -498,7 +498,7 @@ retry: if (ret < 0) return ret; -if (!s->context_initialized) +if (!m->context_initialized) // we need the idct permutation for reading a custom matrix ff_mpv_idct_init(s); @@ -540,7 +540,7 @@ retry: return ret; } -if (!s->context_initialized) { +if (!m->context_initialized) { avctx->pix_fmt = h263_get_format(avctx); if ((ret = ff_mpv_common_init(m)) < 0) return ret; @@ -568,9 +568,9 @@ retry: * an H263EncContext */ if (s->width != avctx->coded_width || s->height != avctx->coded_height || -s->context_reinit) { +m->context_reinit) { /* H.263 could change picture size any time */ -s->context_reinit = 0; +m->context_reinit = 0; ret = ff_set_dimensions(avctx, s->width, s->height); if (ret < 0) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 69d0bb809b..3b21b88337 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1087,7 +1087,7 @@ static int mpeg_decode_update_thread_context(AVCodecContext *avctx, if (avctx == avctx_from || !ctx_from->mpeg_ctx_allocated || -!s1->s.context_initialized) +!s1->context_initialized) return 0; err = ff_mpeg_update_thread_context(avctx, avctx_from); diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index 6e3981b523..ca6988fc48 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -2324,7 +2324,7 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) return AVERROR_PATCHWELCOME; } if (rgb != ctx->rgb || s->chroma_format != chroma_format) -s->context_reinit = 1; +m->context_reinit = 1; s->avctx->bits_per_raw_sample = bits_per_raw_sample; ctx->rgb = rgb; s->chroma_format = chroma_format; @@ -2340,7 +2340,7 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) if (width && height) { if (s->width && s->height && (s->width != width || s->height != height)) -s->context_reinit = 1; +m->context_reinit = 1; s->width = width; s->height = height; } @@ -2489,7 +2489,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) !(s->width && s->codec_tag == AV_RL32("MP4S"))) { if (s->width && s->height && (s->width != width || s->height != height)) -s->context_reinit = 1; +m->context_reinit = 1; s->width = width; s->height = height; } @@ -3527,7 +3527,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, { Mpeg4DecContext *s = dst->priv_data; const Mpeg4DecContext *s1 = src->priv_data; -int init = s->m.s.context_initialized; +int init = s->m.context_initialized; int ret = ff_mpeg_update_thread_context(dst, src); diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 0e98680056..be18b428f5 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -737,7 +737,7 @@ av_cold int ff_mpv_common_init(MPVMainContext *m) s->parse_context.state = -1; #endif -s->context_initialized = 1; +m->context_initialized = 1; m->thread_context[0] = s; m->slice_context_count = nb_slices; @@ -814,8 +814,8 @@ void ff_mpv_common_end(MPVMainContext *m) ff_mpv_picture_free(s->avctx, &s->next_picture); ff_mpv_picture_free(s->avctx, &s->new_picture); -s->context_initialized = 0; -s->context_reinit = 0; +m->context_initialized = 0; +m->context_reinit = 0; s->last_picture_ptr = s->next_pi
[FFmpeg-devel] [PATCH] avcodec/libdav1d: free the Dav1dData packet on dav1d_send_data() failure
We still own it on failure, and there's no point trying to feed it again. Signed-off-by: James Almer --- libavcodec/libdav1d.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 29fa4f9c3d..872e60e000 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -347,8 +347,10 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) if (res < 0) { if (res == AVERROR(EINVAL)) res = AVERROR_INVALIDDATA; -if (res != AVERROR(EAGAIN)) +if (res != AVERROR(EAGAIN)) { +dav1d_data_unref(data); return res; +} } res = dav1d_get_picture(dav1d->c, p); -- 2.34.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/2] avcodec/cfhd: Avoid signed integer overflow in coeff
On Mon, Jan 17, 2022 at 11:32:44PM +0100, Michael Niedermayer wrote: > Fixes: signed integer overflow: 15244032 * 256 cannot be represented in type > 'int' > Fixes: > 43504/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4865014842916864 > > Found-by: continuous fuzzing process > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > Signed-off-by: Michael Niedermayer > --- > libavcodec/cfhd.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) will apply patchset thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Its not that you shouldnt use gotos but rather that you should write readable code and code with gotos often but not always is less readable signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avcodec/libdav1d: free the Dav1dData packet on dav1d_send_data() failure
Hi, On Tue, Feb 1, 2022 at 10:07 AM James Almer wrote: > We still own it on failure, and there's no point trying to feed it again. > > Signed-off-by: James Almer > --- > libavcodec/libdav1d.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c > index 29fa4f9c3d..872e60e000 100644 > --- a/libavcodec/libdav1d.c > +++ b/libavcodec/libdav1d.c > @@ -347,8 +347,10 @@ static int libdav1d_receive_frame(AVCodecContext *c, > AVFrame *frame) > if (res < 0) { > if (res == AVERROR(EINVAL)) > res = AVERROR_INVALIDDATA; > -if (res != AVERROR(EAGAIN)) > +if (res != AVERROR(EAGAIN)) { > +dav1d_data_unref(data); > return res; > +} > } > > res = dav1d_get_picture(dav1d->c, p); > -- > 2.34.1 > LGTM. You could at your choice maybe mention that this fixes dav1d #383 and (the FFmpeg portion of) VLC #26259. Ronald ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avcodec/libdav1d: free the Dav1dData packet on dav1d_send_data() failure
On 2/1/2022 12:57 PM, Ronald S. Bultje wrote: Hi, On Tue, Feb 1, 2022 at 10:07 AM James Almer wrote: We still own it on failure, and there's no point trying to feed it again. Signed-off-by: James Almer --- libavcodec/libdav1d.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 29fa4f9c3d..872e60e000 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -347,8 +347,10 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) if (res < 0) { if (res == AVERROR(EINVAL)) res = AVERROR_INVALIDDATA; -if (res != AVERROR(EAGAIN)) +if (res != AVERROR(EAGAIN)) { +dav1d_data_unref(data); return res; +} } res = dav1d_get_picture(dav1d->c, p); -- 2.34.1 LGTM. You could at your choice maybe mention that this fixes dav1d #383 and (the FFmpeg portion of) VLC #26259. Added that, applied and backported. Thanks. Ronald ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavformat/mov: Expose Quicktime poster_time value as metadata TAG.
I need the ability to derive the poster time found in the mvhd, so I can use that value to create a thumbnail from ffmpeg. More details can be found here https://www.mail-archive.com/ffmpeg-user@ffmpeg.org/msg30003.html Signed-off-by: Bryce Chester Newman --- libavformat/mov.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index a80fcc1606..4d4854c09e 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1525,12 +1525,21 @@ static int mov_read_mvhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_rb32(pb); /* preview time */ avio_rb32(pb); /* preview duration */ -avio_rb32(pb); /* poster time */ +int32_t poster_time = avio_rb32(pb); /* poster time */ avio_rb32(pb); /* selection time */ avio_rb32(pb); /* selection duration */ avio_rb32(pb); /* current time */ avio_rb32(pb); /* next track ID */ +av_log(c->fc, AV_LOG_TRACE, "poster_time = %i, time_scale = %i\n", poster_time, c->time_scale); +if(poster_time && c->time_scale && c->time_scale > 0) { +char buffer[32]; +float poster_time_location = (float)poster_time / c->time_scale; +snprintf(buffer, sizeof(buffer), "%.2f", poster_time_location); +/* This will appear as a TAG in the format section of FFProbe output using -show_format */ +av_dict_set(&c->fc->metadata, "poster_time", buffer, 0); +} + return 0; } -- 2.35.1 Bryce Chester Newman | Principal Developer p: +12069255045 | ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 0/5] Add IPFS and IPNS protocol support
mån 2022-01-31 klockan 23:00 +0100 skrev Mark Gaiser: > On Mon, Jan 31, 2022 at 9:23 PM Tomas Härdin > wrote: > > > mån 2022-01-31 klockan 17:31 +0100 skrev Mark Gaiser: > > > On Mon, Jan 31, 2022 at 4:52 PM Tomas Härdin > > > wrote: > > > > > > > mån 2022-01-31 klockan 14:51 +0100 skrev Mark Gaiser: > > > > > > > > > > There are multiple ways to access files on the IPFS network. > > > > > This > > > > > patch series > > > > > uses the gateway driven way. An IPFS node - by default - > > > > > exposes > > > > > a > > > > > local > > > > > gateway (say http://localhost:8080) which is then used to get > > > > > content > > > > > from IPFS. > > > > > > > > > > > > Perhaps the protocol should be called something other than just > > > > ipfs if > > > > it doesn't actually implement IPFS. Like ipfsgateway. It could > > > > still be > > > > registered to ipfs:// of course, until someone writes a wrapper > > > > for > > > > libipfs. > > > > > > > > > > Do you mean to have it named like "ipfsgateway" as files (and > > > library) but > > > keep the protocol registration of ipfs and ipns? > > > I'm fine with that. The name is only artificial in code anyhow, > > > all > > > that > > > matters are the protocol names. > > > > What I'm really after is if other devs think there might be an > > issue > > once someone goes an implements proper IPFS support > > > > A "proper" implementation is unfeasible for ffmpeg purposes because a > proper implementation would act as an IPFS node. > That means it would: > - spin up > - do it's bootstrapping > - connect to nodes and find new nodes to connect to > - find the CID on the network > - etc... This sounds similar to Tor, except Tor has a much more elegant way of dealing with this stuff by just wrapping ffmpeg with torify. It takes care of all the IPC stuff with tor.service > > > > It strikes me that this borders on incorporating business logic > > within > > lavf. A user could achieve the same thing with a small shell > > script. > > For example adding an alias that inspects calls to ffmpeg and sed:s > > ipfs:// URLs accordingly > > > > That might work but isn't really user friendly. It also doesn't help > for > tools/applications that incorporate ffmpeg to potentially use IPFS > resources. > KODI (when IPFS is merged into ffmpeg) is one such application where > I'll > be adding support for IPFS. > But there are more that could potentially benefit. Think for example > of OBS > studio and blender (i haven't been in contact with them, all i know > is that > they use ffmpeg). This sounds like business logic that should live in Kodi, OBS and Blender respectively. Or better yet, in the operating system itself (read: systemd). How does Kodi handle browsing media stored in IPFS in this case? Does it not already have to be IPFS aware for this to work reasonably well? Come to think of it, why aren't URLs openable as files on Linux? /Tomas ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 0/5] Add IPFS and IPNS protocol support
tis 2022-02-01 klockan 11:06 +0100 skrev Michael Niedermayer: > On Mon, Jan 31, 2022 at 09:22:52PM +0100, Tomas Härdin wrote: > [...] > > It strikes me that this borders on incorporating business logic > > within > > lavf. A user could achieve the same thing with a small shell > > script. > > For example adding an alias that inspects calls to ffmpeg and sed:s > > ipfs:// URLs accordingly > > That sounds like a security nightmare Parsing shit in C is a far bigger nightmare I can assure you. The command line can leverage sed and the regex in the URL RFC. /Tomas ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/2] avcodec/{ass, webvttdec}: fix handling of backslashes
On Sun, Jan 16, 2022 at 19:16:54 +0100, Oneric wrote: > [PATCH 1/2] avcodec/{ass, webvttdec}: fix handling of backslashes > libavcodec/ass.c | 5 - > libavcodec/webvttdec.c | 2 +- > 2 files changed, 5 insertions(+), 2 deletions(-) > [PATCH 2/2] avcodec/webvttdec: honour bidi marks > libavcodec/webvttdec.c | 2 +- > tests/ref/fate/sub-webvtt2 | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) ping. In case anyone is wondering why patchwork fails to apply the second patch, this is probably once again because the patch updates one of FATE's ASS reference files which use CRLF line-endings. Locally git am applies both without a hitch for me on top of current master (and FATE passes after applying each patch). ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [FFmpeg-cvslog] avformat/mpegts: add option max_packet_size
On Sun, Jan 16, 2022 at 05:19:15AM +, Gyan Doshi wrote: > ffmpeg | branch: master | Gyan Doshi | Wed Jan 12 20:57:59 > 2022 +0530| [bca30570d28bbaa07badadabf55ec3589201a82f] | committer: Gyan Doshi > > avformat/mpegts: add option max_packet_size > > Makes maximum size of emitted packet user-tunable. > > Default is existing 204800 bytes. > > > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bca30570d28bbaa07badadabf55ec3589201a82f > --- > > doc/demuxers.texi| 4 > libavformat/mpegts.c | 11 ++- > 2 files changed, 10 insertions(+), 5 deletions(-) Since this commit there is occasional memory corruption occuring libavutil 57. 18.100 / 57. 18.100 libavcodec 59. 20.100 / 59. 20.100 libavformat59. 17.101 / 59. 17.101 libavdevice59. 5.100 / 59. 5.100 libavfilter 8. 25.100 / 8. 25.100 libswscale 6. 5.100 / 6. 5.100 libswresample 4. 4.100 / 4. 4.100 libpostproc56. 4.100 / 56. 4.100 invalid fastbin entry (free) doom/rtp-video: line 14: 15621 Aborted (core dumped) ./ffmpeg_g -bitexact -protocol_whitelist http,tcp,rtp,udp -i http://127.0.0.1:8080/test.sdp -bitexact -acodec mp2 -ab 64k -y -t 1 -threads 1 $TMP/out.avi Command exited with non-zero status 134 this was tricky to reproduce under a memory debugger as it dependat on timing but heres a run that crashed under valgrind the input was generated with this: (and some tuned delays) ./ffmpeg -bitexact -i ~/videos/mm-short.mpg -y -s 320x240 -bitexact -t 10 -threads 1 $TMP/in.mpg cvlc --play-and-exit -vvv $TMP/in.mpg --sout '#rtp{dst=127.0.0.1,port=5104,mux=ts,sdp=http://127.0.0.1:8076/test.sdp}' ==17945== Invalid write of size 2 ==17945==at 0x4C38753: memmove (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==17945==by 0x6A6650: mpegts_push_data (mpegts.c:1397) ==17945==by 0x6AB60E: handle_packet (mpegts.c:2879) ==17945==by 0x6AD048: avpriv_mpegts_parse_packet (mpegts.c:3407) ==17945==by 0x7AFA06: mpegts_handle_packet (rtpdec_mpegts.c:77) ==17945==by 0x7A7BFA: rtp_parse_packet_internal (rtpdec.c:762) ==17945==by 0x7A8211: rtp_parse_one_packet (rtpdec.c:900) ==17945==by 0x7A83A7: ff_rtp_parse_packet (rtpdec.c:945) ==17945==by 0x71D4B5: ff_rtsp_fetch_packet (rtsp.c:2273) ==17945==by 0x5DB6E8: ff_read_packet (demux.c:557) ==17945==by 0x5DE6D8: read_frame_internal (demux.c:1231) ==17945==by 0x5E3CB4: avformat_find_stream_info (demux.c:2584) ==17945== Address 0x16a730c0 is 0 bytes after a block of size 64 alloc'd ==17945==at 0x4C33E76: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==17945==by 0x4C33F91: posix_memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==17945==by 0x129949B: av_malloc (mem.c:104) ==17945==by 0x127F3AE: av_buffer_alloc (buffer.c:82) ==17945==by 0x127FDF6: pool_alloc_buffer (buffer.c:365) ==17945==by 0x127FF77: av_buffer_pool_get (buffer.c:404) ==17945==by 0x6A5955: buffer_pool_get (mpegts.c:1130) ==17945==by 0x6A65F5: mpegts_push_data (mpegts.c:1392) ==17945==by 0x6AB60E: handle_packet (mpegts.c:2879) ==17945==by 0x6AD048: avpriv_mpegts_parse_packet (mpegts.c:3407) ==17945==by 0x7AFA06: mpegts_handle_packet (rtpdec_mpegts.c:77) ==17945==by 0x7A7BFA: rtp_parse_packet_internal (rtpdec.c:762) ==17945== --17945-- VALGRIND INTERNAL ERROR: Valgrind received a signal 11 (SIGSEGV) - exiting --17945-- si_code=128; Faulting address: 0x0; sp: 0x10032c1e20 valgrind: the 'impossible' happened: Killed by fatal signal host stacktrace: ==17945==at 0x58051665: ??? (in /usr/lib/valgrind/memcheck-amd64-linux) ==17945==by 0x58053E58: ??? (in /usr/lib/valgrind/memcheck-amd64-linux) ==17945==by 0x5800BA44: ??? (in /usr/lib/valgrind/memcheck-amd64-linux) ==17945==by 0x5800BD64: ??? (in /usr/lib/valgrind/memcheck-amd64-linux) ==17945==by 0x5809F55C: ??? (in /usr/lib/valgrind/memcheck-amd64-linux) ==17945==by 0x580AECD0: ??? (in /usr/lib/valgrind/memcheck-amd64-linux) sched status: running_tid=1 Thread 1: status = VgTs_Runnable (lwpid 17945) ==17945==at 0x4C33E76: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==17945==by 0x4C33F91: posix_memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==17945==by 0x129949B: av_malloc (mem.c:104) ==17945==by 0x12998EE: av_mallocz (mem.c:265) ==17945==by 0x6A671C: add_pes_stream (mpegts.c:1428) ==17945==by 0x6AB01D: handle_packet (mpegts.c:2761) ==17945==by 0x6AD048: avpriv_mpegts_parse_packet (mpegts.c:3407) ==17945==by 0x7AFA06: mpegts_handle_packet (rtpdec_mpegts.c:77) ==17945==by 0x7A7BFA: rtp_parse_packet_internal (rtpdec.c:762) ==17945==by 0x7A8292: rtp_parse_one_packet (rtpdec.c:911) ==17945==by 0x7A83A7: ff_rtp_parse_packet (rtpdec.c:945) ==17945==by 0x71D4B5: ff_rtsp_fetch_packet (rtsp.c:2273) ==17945==by 0x5DB6E8: ff_read_packet (demux.c:557)
[FFmpeg-devel] [PATCH 1/2] avformat/utils: keep chapter monotonicity on chapter updates
Updating a chapter with the same id does not break monotonicity Fixes: Timeout Fixes: 43727/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-4960623367159808 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index e643821fc9..940703e87d 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -895,10 +895,11 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_ba if (!s->nb_chapters) { si->chapter_ids_monotonic = 1; } else if (!si->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) { -si->chapter_ids_monotonic = 0; for (unsigned i = 0; i < s->nb_chapters; i++) if (s->chapters[i]->id == id) chapter = s->chapters[i]; +if (!chapter) +si->chapter_ids_monotonic = 0; } if (!chapter) { -- 2.17.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/2] avcodec/av1dec: Check tile_cols
Fixes: division by zero Fixes: 43769/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AV1_fuzzer-5392562205097984 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/av1dec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 62d459cded..581f22a849 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -394,6 +394,9 @@ static int get_tiles_info(AVCodecContext *avctx, const AV1RawTileGroup *tile_gro s->tg_start = tile_group->tg_start; s->tg_end = tile_group->tg_end; +if (s->raw_frame_header->tile_cols == 0) +return AVERROR_INVALIDDATA; + for (tile_num = tile_group->tg_start; tile_num <= tile_group->tg_end; tile_num++) { tile_row = tile_num / s->raw_frame_header->tile_cols; tile_col = tile_num % s->raw_frame_header->tile_cols; -- 2.17.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [FFmpeg-cvslog] avformat/mpegts: add option max_packet_size
On 2/1/2022 3:47 PM, Michael Niedermayer wrote: On Sun, Jan 16, 2022 at 05:19:15AM +, Gyan Doshi wrote: ffmpeg | branch: master | Gyan Doshi | Wed Jan 12 20:57:59 2022 +0530| [bca30570d28bbaa07badadabf55ec3589201a82f] | committer: Gyan Doshi avformat/mpegts: add option max_packet_size Makes maximum size of emitted packet user-tunable. Default is existing 204800 bytes. http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bca30570d28bbaa07badadabf55ec3589201a82f --- doc/demuxers.texi| 4 libavformat/mpegts.c | 11 ++- 2 files changed, 10 insertions(+), 5 deletions(-) Since this commit there is occasional memory corruption occuring libavutil 57. 18.100 / 57. 18.100 libavcodec 59. 20.100 / 59. 20.100 libavformat59. 17.101 / 59. 17.101 libavdevice59. 5.100 / 59. 5.100 libavfilter 8. 25.100 / 8. 25.100 libswscale 6. 5.100 / 6. 5.100 libswresample 4. 4.100 / 4. 4.100 libpostproc56. 4.100 / 56. 4.100 invalid fastbin entry (free) doom/rtp-video: line 14: 15621 Aborted (core dumped) ./ffmpeg_g -bitexact -protocol_whitelist http,tcp,rtp,udp -i http://127.0.0.1:8080/test.sdp -bitexact -acodec mp2 -ab 64k -y -t 1 -threads 1 $TMP/out.avi Command exited with non-zero status 134 Is the demuxer used in this scenario mpegts or mpegtsraw? The new option was added to the former but not the latter, yet if both read MpegTSContext.max_packet_size, for mpegtsraw it will always be 0. The option might need to be added to that demuxer too. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/2] avcodec/{ass, webvttdec}: fix handling of backslashes
> -Original Message- > From: ffmpeg-devel On Behalf Of Oneric > Sent: Tuesday, February 1, 2022 6:39 PM > To: FFmpeg development discussions and patches > Subject: Re: [FFmpeg-devel] [PATCH 1/2] avcodec/{ass, webvttdec}: fix > handling of backslashes > > On Sun, Jan 16, 2022 at 19:16:54 +0100, Oneric wrote: > > [PATCH 1/2] avcodec/{ass, webvttdec}: fix handling of backslashes > > libavcodec/ass.c | 5 - > > libavcodec/webvttdec.c | 2 +- > > 2 files changed, 5 insertions(+), 2 deletions(-) > > > [PATCH 2/2] avcodec/webvttdec: honour bidi marks > > libavcodec/webvttdec.c | 2 +- > > tests/ref/fate/sub-webvtt2 | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > ping. > > In case anyone is wondering why patchwork fails to apply the second patch, > this is probably once again because the patch updates one of FATE's ASS > reference files which use CRLF line-endings. > Locally git am applies both without a hitch for me on top of current master > (and FATE passes after applying each patch). You can add a .gitattributes file to tests/ref/fate/ which includes the line sub-webvtt2 -diff Then your local git format-patch will create a binary diff for the file. softworkz ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/2] avcodec/{ass, webvttdec}: fix handling of backslashes
On Tue, Feb 01, 2022 at 19:44:24 +, Soft Works wrote: > > On Sun, Jan 16, 2022 at 19:16:54 +0100, Oneric wrote: > > > > In case anyone is wondering why patchwork fails to apply the second patch, > > this is probably once again because the patch updates one of FATE's ASS > > reference files which use CRLF line-endings. > > Locally git am applies both without a hitch for me on top of current master > > (and FATE passes after applying each patch). > > > You can add a .gitattributes file to tests/ref/fate/ which includes the line > > sub-webvtt2 -diff > > Then your local git format-patch will create a binary diff for the file. Thanks for your suggestion. However, a binary diff would look like this which isn't great for seeing what's going on during review: diff --git a/tests/ref/fate/sub-webvtt2 b/tests/ref/fate/sub-webvtt2 index 357b8178ea1cf224ad47dcf78b24f1948ece6665..4cd1d86a9a58ccf65812131bf84a17531c2c6cfa 100644 GIT binary patch delta 24 gcmeys^NnXiIV;bjhJHgMV-r)eM-6?GYgs=70DwpeRR910 delta 18 Zcmeyy^MPkWIV+o?k+F%X+2m%{&j3Hw26O-b Also as noted, locally plain `git am` has no issues applying the regular (non-binary) patch; iirc patchwork uses some additional flags to make it more restrictive because regular codefiles shouldn't use CRLF line-endings. I recall using some .gitattribute settings to force crlf (without making the file binary?) were discussed last time this happened, but deemed to be not worth it because of some other issues with it. > > softworkz ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 1/2] avcodec/{ass, webvttdec}: fix handling of backslashes
> -Original Message- > From: ffmpeg-devel On Behalf Of Oneric > Sent: Tuesday, February 1, 2022 9:07 PM > To: FFmpeg development discussions and patches > Subject: Re: [FFmpeg-devel] [PATCH 1/2] avcodec/{ass, webvttdec}: fix > handling of backslashes > > On Tue, Feb 01, 2022 at 19:44:24 +, Soft Works wrote: > > > On Sun, Jan 16, 2022 at 19:16:54 +0100, Oneric wrote: > > > > > > In case anyone is wondering why patchwork fails to apply the second > patch, > > > this is probably once again because the patch updates one of FATE's ASS > > > reference files which use CRLF line-endings. > > > Locally git am applies both without a hitch for me on top of current > master > > > (and FATE passes after applying each patch). > > > > > > You can add a .gitattributes file to tests/ref/fate/ which includes the > line > > > > sub-webvtt2 -diff > > > > Then your local git format-patch will create a binary diff for the file. > > Thanks for your suggestion. However, a binary diff would look like this which > isn't great for seeing what's going on during review: > > diff --git a/tests/ref/fate/sub-webvtt2 b/tests/ref/fate/sub-webvtt2 > index > 357b8178ea1cf224ad47dcf78b24f1948ece6665..4cd1d86a9a58ccf65812131bf84a17531c2 > c6cfa 100644 > GIT binary patch > delta 24 > gcmeys^NnXiIV;bjhJHgMV-r)eM-6?GYgs=70DwpeRR910 > > delta 18 > Zcmeyy^MPkWIV+o?k+F%X+2m%{&j3Hw26O-b Yes, I know, but the question is probably what's more important.. ..that it can be applied or that the text is viewable? I assume that a reviewer would often apply the patch locally anyway, then the text changes become visible again as this doesn't affect git log. Given that it's just a handful files from a few thousands, this should be acceptable. > Also as noted, locally plain `git am` has no issues applying the regular > (non-binary) patch; Yes, because it hasn't been sent around via e-mail yet. SMTP requires CRLF line endings, so essentially it depends on the receiving e-mail client whether it outputs LF or CRLF. It's then up to git whether it ignores or adjust the line ending when applying a patch. Maybe that's what is configured @patchwork, I can't tell. The most extreme example is sub-textenc (and there was another one iirc). It has mixed line endings - some LF and some CRLF. At least at that point there's no way out, because those endings will get unrecoverably lost as soon as it is sent around via e-mail as text-diff. That's how I came to the binary diff as only working option. (or you just don't send patches around via e-mail at all ;-) > I recall using some .gitattribute settings to force crlf (without making > the file binary?) were discussed last time this happened, but deemed to be > not worth it because of some other issues with it. Doesn't work with mixed endings. BTW, I don't find it wrong to make such files binary because logically these are not text files, but test reference results, which are expected to precisely match (rather than "have the same text"). If you don't want to mark the files as binary, you could probably use .gitattributes without commiting, so it would only affect format-patch generation. Best, softworkz ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 0/5] Add IPFS and IPNS protocol support
On Tue, Feb 1, 2022 at 5:40 PM Tomas Härdin wrote: > mån 2022-01-31 klockan 23:00 +0100 skrev Mark Gaiser: > > On Mon, Jan 31, 2022 at 9:23 PM Tomas Härdin > > wrote: > > > > > mån 2022-01-31 klockan 17:31 +0100 skrev Mark Gaiser: > > > > On Mon, Jan 31, 2022 at 4:52 PM Tomas Härdin > > > > wrote: > > > > > > > > > mån 2022-01-31 klockan 14:51 +0100 skrev Mark Gaiser: > > > > > > > > > > > > There are multiple ways to access files on the IPFS network. > > > > > > This > > > > > > patch series > > > > > > uses the gateway driven way. An IPFS node - by default - > > > > > > exposes > > > > > > a > > > > > > local > > > > > > gateway (say http://localhost:8080) which is then used to get > > > > > > content > > > > > > from IPFS. > > > > > > > > > > > > > > > Perhaps the protocol should be called something other than just > > > > > ipfs if > > > > > it doesn't actually implement IPFS. Like ipfsgateway. It could > > > > > still be > > > > > registered to ipfs:// of course, until someone writes a wrapper > > > > > for > > > > > libipfs. > > > > > > > > > > > > > Do you mean to have it named like "ipfsgateway" as files (and > > > > library) but > > > > keep the protocol registration of ipfs and ipns? > > > > I'm fine with that. The name is only artificial in code anyhow, > > > > all > > > > that > > > > matters are the protocol names. > > > > > > What I'm really after is if other devs think there might be an > > > issue > > > once someone goes an implements proper IPFS support > > > > > > > A "proper" implementation is unfeasible for ffmpeg purposes because a > > proper implementation would act as an IPFS node. > > That means it would: > > - spin up > > - do it's bootstrapping > > - connect to nodes and find new nodes to connect to > > - find the CID on the network > > - etc... > > This sounds similar to Tor, except Tor has a much more elegant way of > dealing with this stuff by just wrapping ffmpeg with torify. It takes > care of all the IPC stuff with tor.service > > > > > > > It strikes me that this borders on incorporating business logic > > > within > > > lavf. A user could achieve the same thing with a small shell > > > script. > > > For example adding an alias that inspects calls to ffmpeg and sed:s > > > ipfs:// URLs accordingly > > > > > > > That might work but isn't really user friendly. It also doesn't help > > for > > tools/applications that incorporate ffmpeg to potentially use IPFS > > resources. > > KODI (when IPFS is merged into ffmpeg) is one such application where > > I'll > > be adding support for IPFS. > > But there are more that could potentially benefit. Think for example > > of OBS > > studio and blender (i haven't been in contact with them, all i know > > is that > > they use ffmpeg). > > This sounds like business logic that should live in Kodi, OBS and > Blender respectively. Or better yet, in the operating system itself > (read: systemd). How does Kodi handle browsing media stored in IPFS in > this case? Does it not already have to be IPFS aware for this to work > reasonably well? > I don't entirely agree that this logic should live in kodi. I think ffmpeg should provide the base essentials (which this patch is doing). Kodi and other applications should then provide an input field or whatever to potentially say "i know the gateway you need to use, pick this one". They would then either pass "-gateway " with the setting they deem correct or by filling in the $IPFS_GATEWAY environment variable. Kodi currently has no way to play IPFS data. Unless one goes through the hassle of translating it manually to a gateway url. To give you an idea of how it looks. Kodi has so called strm (stream) files. They can contain an url that can be played. Without this patch an ipfs file would look like this: http://localhost:8080/ipfs/QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T With this patch it becomes possible to patch kodi to accept: ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T In the former case it's gateway specific. In the latter case it's gateway agnostic. The gateway specific way has a problem. If i translate it to a gateway then that url i picked becomes the point to access the file. If that url goes down, the file isn't playable. Even if the file might still be online just fine on the IPFS network. Imagine you get a file from me and have ipfs running locally. I'm guessing you don't like to edit the file you received to fix the gateway part of the url, do you? I certainly don't. The idea here is that a user sets the gateway that needs to be used to play. The ideal place to do that is ffmpeg because the gateway logic can then be in one application. Others (kodi, vlc, ...) can either rely on ffmpeg doing the right thing or overrule the gateway with their own setting. In either case, ffmpeg needs the option to set the gateway. This all changes if the logic can't go in ffmpeg. Then each application gets its own configuration to set the ipfs gateway. That's a situation I actively
[FFmpeg-devel] [PATCH 0/8] rewrite avpriv_find_start_code() for clarity
I am endeavoring to reduce MythTV’s downstream changes to FFmpeg. avpriv_find_start_code() is one of the internal FFmpeg functions that MythTV uses. I was planning on copying it into MythTV to eventually eliminate all uses of internal FFmpeg headers; however, what avpriv_find_start_code() actually does was not very clear. Therefore, I rewrote it and added comments to make its purpose and effects clearer. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/8] avpriv_find_start_code(): readability enhancement part 1
No functional change. --- libavcodec/utils.c | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index b19befef21..cb4437edc2 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -967,10 +967,14 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, } } -p = FFMIN(p, end) - 4; -*state = AV_RB32(p); +if (p > end) +p = end; +// this will cause the last 4 bytes before end to be read, +// i.e. no out of bounds memory access occurs -return p + 4; +*state = AV_RB32(p - 4); // read the previous 4 bytes + +return p; } AVCPBProperties *av_cpb_properties_alloc(size_t *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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/8] avpriv_find_start_code(): rewrite while loop and add comments for clarity
The expected number of iterations may increase by one for an input of alternating 0 and 1 bytes. Instead of incrementing by 2 everytime, it now alternates between incrementing by 1 and by 3. No functional change, but now much clearer. --- libavcodec/utils.c | 25 - 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index cb4437edc2..882f90be79 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -957,12 +957,26 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, return p; } +/* with memory address increasing left to right, we are looking for (in hexadecimal): + * 00 00 01 XX + * p points at the address which should have the value of XX + */ while (p < end) { -if (p[-1] > 1 ) p += 3; -else if (p[-2] ) p += 2; -else if (p[-3]|(p[-1]-1)) p++; +// UU UU UU +if (p[-1] > 1) p += 3;// start check over with 3 new bytes +else if (p[-1] == 0) p++; // could be in a start code, so check next byte +// this should be one comparison against 1 since p is unsigned, +// i.e. p[-1] == 0 is equivalent to p[-1] < 1 + +// UU UU 01 +else if (p[-2] != 0) p += 2;// we have UU YY 01, so increment by 2 +// to start check over with 3 new bytes +// UU 00 01 +else if (p[-3] != 0) p += 3;// we have YY 00 01, so increment by 3 +// to start check over with 3 new bytes +// 00 00 01 else { -p++; +p++; // p now points at the address following the start code value XX break; } } @@ -972,7 +986,8 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, // this will cause the last 4 bytes before end to be read, // i.e. no out of bounds memory access occurs -*state = AV_RB32(p - 4); // read the previous 4 bytes +*state = AV_RB32(p - 4); +// read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} return p; } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 3/8] avpriv_find_start_code(): make the state parameter output only
--- libavcodec/cbs_mpeg2.c| 8 libavcodec/mpeg12dec.c| 5 ++--- libavcodec/mpeg4_unpack_bframes_bsf.c | 1 - libavcodec/mpegvideo_parser.c | 3 +-- libavcodec/utils.c| 1 + libavformat/rtpenc_mpv.c | 3 +-- 6 files changed, 5 insertions(+), 16 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 26400f279f..03ea49cbca 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -160,14 +160,6 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, for (i = 0;; i++) { unit_type = start_code & 0xff; -if (start == frag->data + frag->data_size) { -// The last four bytes form a start code which constitutes -// a unit of its own. In this situation avpriv_find_start_code -// won't modify start_code at all so modify start_code so that -// the next unit will be treated as the last unit. -start_code = 0; -} - end = avpriv_find_start_code(start--, frag->data + frag->data_size, &start_code); diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 4a7bd6d466..1110fcb319 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1770,7 +1770,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y, if (avctx->hwaccel && avctx->hwaccel->decode_slice) { const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */ -int start_code = -1; +uint32_t start_code; buf_end = avpriv_find_start_code(buf_start + 2, *buf + buf_size, &start_code); if (buf_end < *buf + buf_size) buf_end -= 4; @@ -2020,7 +2020,6 @@ static int slice_decode_thread(AVCodecContext *c, void *arg) if (s->mb_y == s->end_mb_y) return 0; -start_code = -1; buf= avpriv_find_start_code(buf, s->gb.buffer_end, &start_code); if (start_code < SLICE_MIN_START_CODE || start_code > SLICE_MAX_START_CODE) return AVERROR_INVALIDDATA; @@ -2475,7 +2474,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, for (;;) { /* find next start code */ -uint32_t start_code = -1; +uint32_t start_code; buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &start_code); if (start_code > 0x1ff) { if (!skip_frame) { diff --git a/libavcodec/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c index 6f8595713d..8b3fda0b03 100644 --- a/libavcodec/mpeg4_unpack_bframes_bsf.c +++ b/libavcodec/mpeg4_unpack_bframes_bsf.c @@ -36,7 +36,6 @@ static void scan_buffer(const uint8_t *buf, int buf_size, const uint8_t *end = buf + buf_size, *pos = buf; while (pos < end) { -startcode = -1; pos = avpriv_find_start_code(pos, end, &startcode); if (startcode == USER_DATA_STARTCODE && pos_p) { diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index c5dc867d24..c991a82405 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -105,7 +105,6 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, { struct MpvParseContext *pc = s->priv_data; const uint8_t *buf_end = buf + buf_size; -uint32_t start_code; int frame_rate_index, ext_type, bytes_left; int frame_rate_ext_n, frame_rate_ext_d; int top_field_first, repeat_first_field, progressive_frame; @@ -120,7 +119,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, s->repeat_pict = 0; while (buf < buf_end) { -start_code= -1; +uint32_t start_code; buf= avpriv_find_start_code(buf, buf_end, &start_code); bytes_left = buf_end - buf; switch(start_code) { diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 882f90be79..cf88e0a759 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -950,6 +950,7 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, if (p >= end) return end; +*state = ~0; for (i = 0; i < 3; i++) { uint32_t tmp = *state << 8; *state = tmp + *(p++); diff --git a/libavformat/rtpenc_mpv.c b/libavformat/rtpenc_mpv.c index 4b45f51772..bb63c9bdc6 100644 --- a/libavformat/rtpenc_mpv.c +++ b/libavformat/rtpenc_mpv.c @@ -51,11 +51,10 @@ void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) end_of_slice = 1; } else { const uint8_t *r, *r1; -int start_code; r1 = buf1; while (1) { -start_code = -1; +uint32_t start_code; r = avpriv_find_start_code(r1, end, &start_code); if((start_code & 0xFF00) == 0x100) { /* New start code found */ -- 2.32.0 __
[FFmpeg-devel] [PATCH 4/8] avpriv_find_start_code(): add doxygen comment and rename a parameter
--- libavcodec/internal.h | 15 ++- libavcodec/utils.c| 10 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 72ca1553f6..07098e1522 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -285,9 +285,22 @@ int ff_thread_can_start_frame(AVCodecContext *avctx); int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx); +/** + * Find the first start code in the buffer p. A start code is a sequence of 4 + * bytes, with memory address increasing left to right and in hexadecimal, with + * the value 00 00 01 XX, where XX represents any value. + * + * @param[in] p A pointer to the start of the memory buffer to scan. + * @param[in] end A pointer to the past the end memory address for the buffer + * given by p. p must be <= end. + * + * @param[out] start_code The found start code if it exists, otherwise an invalid start code. + * @return A pointer to the memory address following the found start code, or end + * if no start code was found. + */ const uint8_t *avpriv_find_start_code(const uint8_t *p, const uint8_t *end, - uint32_t *state); + uint32_t *start_code); int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index cf88e0a759..54c9dd056d 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -942,7 +942,7 @@ void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, in const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, - uint32_t *av_restrict state) + uint32_t *av_restrict start_code) { int i; @@ -950,10 +950,10 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, if (p >= end) return end; -*state = ~0; +*start_code = ~0; for (i = 0; i < 3; i++) { -uint32_t tmp = *state << 8; -*state = tmp + *(p++); +uint32_t tmp = *start_code << 8; +*start_code = tmp + *(p++); if (tmp == 0x100 || p == end) return p; } @@ -987,7 +987,7 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, // this will cause the last 4 bytes before end to be read, // i.e. no out of bounds memory access occurs -*state = AV_RB32(p - 4); +*start_code = AV_RB32(p - 4); // read the previous 4 bytes, i.e. bytes {p - 4, p - 3, p - 2, p - 1} return p; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 5/8] avpriv_find_start_code(): replace unnecessary for loop
start_code will still be invalid, i.e. all ones, but will no longer have up to the first three bytes in p shifted in. --- libavcodec/utils.c | 13 - 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 54c9dd056d..b4c5fa5009 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -944,19 +944,14 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p, const uint8_t *end, uint32_t *av_restrict start_code) { -int i; +*start_code = ~0; av_assert0(p <= end); -if (p >= end) +// minimum length for a start code +if (p + 4 > end) return end; -*start_code = ~0; -for (i = 0; i < 3; i++) { -uint32_t tmp = *start_code << 8; -*start_code = tmp + *(p++); -if (tmp == 0x100 || p == end) -return p; -} +p += 3; // offset for negative indices in while loop /* with memory address increasing left to right, we are looking for (in hexadecimal): * 00 00 01 XX -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".