Re: [FFmpeg-devel] [PATCH v7 09/10] qsv: use a new method to create mfx session when using oneVPL
On Fri, 2022-03-11 at 15:00 +0100, Hendrik Leppkes wrote: > On Fri, Mar 11, 2022 at 2:43 PM Xiang, Haihao > wrote: > > > > On Fri, 2022-03-11 at 09:35 +0100, Hendrik Leppkes wrote: > > > On Fri, Mar 11, 2022 at 9:18 AM Xiang, Haihao > > > wrote: > > > > diff --git a/libavutil/hwcontext_d3d11va.c > > > > b/libavutil/hwcontext_d3d11va.c > > > > index 8ab96bad25..e0e820f164 100644 > > > > --- a/libavutil/hwcontext_d3d11va.c > > > > +++ b/libavutil/hwcontext_d3d11va.c > > > > @@ -525,6 +525,13 @@ static void d3d11va_device_uninit(AVHWDeviceContext > > > > *hwdev) > > > > } > > > > } > > > > > > > > +static void d3d11va_device_free(AVHWDeviceContext *ctx) > > > > +{ > > > > +AVD3D11VADeviceContext *hwctx = ctx->hwctx; > > > > + > > > > +av_free(hwctx->device_name); > > > > +} > > > > + > > > > static int d3d11va_device_create(AVHWDeviceContext *ctx, const char > > > > *device, > > > > AVDictionary *opts, int flags) > > > > { > > > > @@ -537,6 +544,8 @@ static int d3d11va_device_create(AVHWDeviceContext > > > > *ctx, > > > > const char *device, > > > > int is_debug = !!av_dict_get(opts, "debug", NULL, 0); > > > > int ret; > > > > > > > > +ctx->free = d3d11va_device_free; > > > > + > > > > // (On UWP we can't check this.) > > > > #if !HAVE_UWP > > > > if (!LoadLibrary("d3d11_1sdklayers.dll")) > > > > @@ -561,6 +570,10 @@ static int d3d11va_device_create(AVHWDeviceContext > > > > *ctx, const char *device, > > > > if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, > > > > adapter, > > > > &pAdapter))) > > > > pAdapter = NULL; > > > > IDXGIFactory2_Release(pDXGIFactory); > > > > + > > > > +device_hwctx->device_name = av_strdup(device); > > > > +if (!device_hwctx->device_name) > > > > +return AVERROR(ENOMEM); > > > > } > > > > } > > > > > > > > diff --git a/libavutil/hwcontext_d3d11va.h > > > > b/libavutil/hwcontext_d3d11va.h > > > > index 77d2d72f1b..41a315b9e6 100644 > > > > --- a/libavutil/hwcontext_d3d11va.h > > > > +++ b/libavutil/hwcontext_d3d11va.h > > > > @@ -94,6 +94,11 @@ typedef struct AVD3D11VADeviceContext { > > > > void (*lock)(void *lock_ctx); > > > > void (*unlock)(void *lock_ctx); > > > > void *lock_ctx; > > > > + > > > > +/** > > > > + * The string for the used adapter > > > > + */ > > > > +char *device_name; > > > > } AVD3D11VADeviceContext; > > > > > > > > /** > > > > diff --git a/libavutil/hwcontext_dxva2.c b/libavutil/hwcontext_dxva2.c > > > > index 53d00fa815..6967357093 100644 > > > > --- a/libavutil/hwcontext_dxva2.c > > > > +++ b/libavutil/hwcontext_dxva2.c > > > > @@ -431,6 +431,7 @@ static void dxva2_device_free(AVHWDeviceContext > > > > *ctx) > > > > dlclose(priv->dxva2lib); > > > > > > > > av_freep(&ctx->user_opaque); > > > > +av_free(hwctx->device_name); > > > > } > > > > > > > > static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter) > > > > @@ -571,6 +572,13 @@ static int dxva2_device_create(AVHWDeviceContext > > > > *ctx, > > > > const char *device, > > > > return AVERROR_UNKNOWN; > > > > } > > > > > > > > +if (device) { > > > > +hwctx->device_name = av_strdup(device); > > > > + > > > > +if (!hwctx->device_name) > > > > +return AVERROR(ENOMEM); > > > > +} > > > > + > > > > return 0; > > > > } > > > > > > > > diff --git a/libavutil/hwcontext_dxva2.h b/libavutil/hwcontext_dxva2.h > > > > index e1b79bc0de..253ddbed51 100644 > > > > --- a/libavutil/hwcontext_dxva2.h > > > > +++ b/libavutil/hwcontext_dxva2.h > > > > @@ -38,6 +38,10 @@ > > > > */ > > > > typedef struct AVDXVA2DeviceContext { > > > > IDirect3DDeviceManager9 *devmgr; > > > > +/** > > > > + * The string for the used adapter > > > > + */ > > > > +char *device_name; > > > > } AVDXVA2DeviceContext; > > > > > > > > /** > > > > > > Why are these device names required? I would think deriving a child > > > device would use the actual device, eg. ID3D11Device or > > > IDirect3DDeviceManager9 (and whatever for VAAPI), and not some string > > > (that may or may not even be set). > > > It feels quite a bit icky to store these in the context just for qsv > > > to do... what with? > > > > Yes, it is a little ugly here. MediaSDK or oneVPL application creates mfx > > session and the device (dxva2, d3d11va or vaapi), then pass this device to > > the > > SDK through MFXVideoCORE_SetHandle(). implementation is introduced in oneVPL > > ( > > https://spec.oneapi.io/versions/latest/elements/oneVPL/source/API_ref/VPL_disp_api_struct.html#structmfx_impl_description > > ) and user must select an available implementation before the creation of > > mfx > > session, however the device handle is unknown in the SDK when selecting an > > available implementation, the SDK provides a method to select implementation > > v
Re: [FFmpeg-devel] [PATCH 1/2] avcodec: add null encoders
Quoting Paul B Mahol (2022-03-14 12:56:01) > +static int null_encoder(AVCodecContext *avctx, AVPacket *pkt, > +const AVFrame *frame, int *got_packet) > +{ > +int ret; > + > +pkt->pts = frame->pts; > +if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) > +pkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); > +pkt->flags |= AV_PKT_FLAG_KEY; > +if ((ret = ff_alloc_packet(avctx, pkt, 1)) < 0) > +return ret; > +*got_packet = 1; Why return packets at all? Wouldn't it be simpler to just never return any data? -- 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 v6 1/2] libavcodec: Added DFPWM1a codec
Could we please have tests for all new decoders/demuxers? -- 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 1/2] avcodec: add null encoders
On Tue, Mar 15, 2022 at 9:47 AM Anton Khirnov wrote: > Quoting Paul B Mahol (2022-03-14 12:56:01) > > +static int null_encoder(AVCodecContext *avctx, AVPacket *pkt, > > +const AVFrame *frame, int *got_packet) > > +{ > > +int ret; > > + > > +pkt->pts = frame->pts; > > +if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) > > +pkt->duration = ff_samples_to_time_base(avctx, > frame->nb_samples); > > +pkt->flags |= AV_PKT_FLAG_KEY; > > +if ((ret = ff_alloc_packet(avctx, pkt, 1)) < 0) > > +return ret; > > +*got_packet = 1; > > Why return packets at all? Wouldn't it be simpler to just never return > any data? > But than there is no progress report at all. > > -- > 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". > ___ 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] avcodec/hevc_refs: don't use the frame's AVBufferRef sizes when initializing planes
Quoting James Almer (2022-03-08 14:55:00) > Use the actual plane sizes instead. > > Signed-off-by: James Almer > --- > libavcodec/hevc_refs.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c > index 35b8e5e696..fe18ca2b1d 100644 > --- a/libavcodec/hevc_refs.c > +++ b/libavcodec/hevc_refs.c > @@ -401,9 +401,9 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, > int poc) > > if (!s->avctx->hwaccel) { > if (!s->ps.sps->pixel_shift) { > -for (i = 0; frame->frame->buf[i]; i++) > -memset(frame->frame->buf[i]->data, 1 << > (s->ps.sps->bit_depth - 1), > - frame->frame->buf[i]->size); > +for (i = 0; frame->frame->data[i]; i++) > +memset(frame->frame->data[i], 1 << (s->ps.sps->bit_depth - > 1), > + frame->frame->linesize[i] * > AV_CEIL_RSHIFT(s->ps.sps->height, s->ps.sps->vshift[i])); Looks good. -- 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 v2] avcodec: Add dv marker bsf
Could you please add a test? -- 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".
[FFmpeg-devel] [PATCH 1/2] avfilter: simplify processing child context options
THe call to av_opt_set() is redundant, since the option is written in the options dict, which is later passed to avfilter_init_dict(). --- libavfilter/avfilter.c | 13 + 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 1f37a70179..030f1823ee 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -861,14 +861,11 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, } } else { av_dict_set(options, key, value, 0); -if ((ret = av_opt_set(ctx->priv, key, value, AV_OPT_SEARCH_CHILDREN)) < 0) { -if (!av_opt_find(ctx->priv, key, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) { -if (ret == AVERROR_OPTION_NOT_FOUND) -av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key); -av_free(value); -av_free(parsed_key); -return ret; -} +if (!av_opt_find(ctx->priv, key, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) { +av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key); +av_free(value); +av_free(parsed_key); +return AVERROR_OPTION_NOT_FOUND; } } -- 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 2/2] avfilter: handle duplicates in the options string
Use the same logic as fftools/cmdutils - when a flag-type option starts with [+-], append it to the existing value. --- libavfilter/avfilter.c | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 030f1823ee..a6f2181efb 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -860,13 +860,17 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, return ret; } } else { -av_dict_set(options, key, value, 0); -if (!av_opt_find(ctx->priv, key, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) { +o = av_opt_find(ctx->priv, key, NULL, 0, +AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ); +if (!o) { av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key); av_free(value); av_free(parsed_key); return AVERROR_OPTION_NOT_FOUND; } +av_dict_set(options, key, value, +(o->type == AV_OPT_TYPE_FLAGS && + (value[0] == '-' || value[0] == '+')) ? AV_DICT_APPEND : 0); } av_free(value); -- 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 02/10] fftools/cmdutils: drop extern declarations for nonexistent variables
--- fftools/cmdutils.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index d8e5aa342b..f460cb028e 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -44,8 +44,6 @@ extern const char program_name[]; */ extern const int program_birth_year; -extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB]; -extern AVFormatContext *avformat_opts; extern AVDictionary *sws_dict; extern AVDictionary *swr_opts; extern AVDictionary *format_opts, *codec_opts; -- 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 05/10] fftools: move opt_timelimit from cmdutils to ffmpeg
This option is only supported by ffmpeg. --- fftools/cmdutils.c | 17 - fftools/ffmpeg_opt.c | 20 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 12ef07b62f..e5684fa840 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -47,10 +47,6 @@ #include "libavutil/opt.h" #include "cmdutils.h" #include "opt_common.h" -#if HAVE_SYS_RESOURCE_H -#include -#include -#endif #ifdef _WIN32 #include #endif @@ -797,19 +793,6 @@ do { \ return 0; } -int opt_timelimit(void *optctx, const char *opt, const char *arg) -{ -#if HAVE_SETRLIMIT -int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); -struct rlimit rl = { lim, lim + 1 }; -if (setrlimit(RLIMIT_CPU, &rl)) -perror("setrlimit"); -#else -av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt); -#endif -return 0; -} - void print_error(const char *filename, int err) { char errbuf[128]; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index b2746259d7..778e02c39e 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -19,8 +19,15 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" + #include +#if HAVE_SYS_RESOURCE_H +#include +#include +#endif + #include "ffmpeg.h" #include "cmdutils.h" #include "opt_common.h" @@ -3501,6 +3508,19 @@ static int opt_progress(void *optctx, const char *opt, const char *arg) return 0; } +int opt_timelimit(void *optctx, const char *opt, const char *arg) +{ +#if HAVE_SETRLIMIT +int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); +struct rlimit rl = { lim, lim + 1 }; +if (setrlimit(RLIMIT_CPU, &rl)) +perror("setrlimit"); +#else +av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt); +#endif +return 0; +} + #define OFFSET(x) offsetof(OptionsContext, x) const OptionDef options[] = { /* main options */ -- 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 01/10] fftools/cmdutils: drop prototypes for nonexistent functions
--- fftools/cmdutils.h | 7 --- 1 file changed, 7 deletions(-) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 50eed9b13a..d8e5aa342b 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -66,11 +66,6 @@ void exit_program(int ret) av_noreturn; */ void init_dynload(void); -/** - * Initialize the cmdutils option system, in particular - * allocate the *_opts contexts. - */ -void init_opts(void); /** * Uninitialize the cmdutils option system, in particular * free the *_opts contexts and their contents. @@ -108,8 +103,6 @@ int opt_report(void *optctx, const char *opt, const char *arg); int opt_max_alloc(void *optctx, const char *opt, const char *arg); -int opt_codec_debug(void *optctx, const char *opt, const char *arg); - /** * Limit the execution time. */ -- 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 06/10] fftools/ffmpeg: drop mistakenly added empty line
--- fftools/ffmpeg_opt.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 778e02c39e..5f08cab908 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1,4 +1,3 @@ - /* * ffmpeg option parsing * -- 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 03/10] fftools: drop useless indirection
--- fftools/cmdutils.c | 4 ++-- fftools/cmdutils.h | 2 -- fftools/ffmpeg.c | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 4b50e15eef..0ac98852fe 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -1961,7 +1961,7 @@ static void show_help_filter(const char *name) count = avfilter_filter_pad_count(f, 0); for (i = 0; i < count; i++) { printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i), - media_type_string(avfilter_pad_get_type(f->inputs, i))); + av_get_media_type_string(avfilter_pad_get_type(f->inputs, i))); } if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS) printf("dynamic (depending on the options)\n"); @@ -1972,7 +1972,7 @@ static void show_help_filter(const char *name) count = avfilter_filter_pad_count(f, 1); for (i = 0; i < count; i++) { printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i), - media_type_string(avfilter_pad_get_type(f->outputs, i))); + av_get_media_type_string(avfilter_pad_get_type(f->outputs, i))); } if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS) printf("dynamic (depending on the options)\n"); diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index f460cb028e..57db531f5c 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -633,8 +633,6 @@ void *grow_array(void *array, int elem_size, int *size, int new_size); */ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); -#define media_type_string av_get_media_type_string - #define GROW_ARRAY(array, nb_elems)\ array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 9a3fdc636d..eaca897aec 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1606,7 +1606,7 @@ static void print_final_stats(int64_t total_size) total_packets += ist->nb_packets; av_log(NULL, AV_LOG_VERBOSE, " Input stream #%d:%d (%s): ", - i, j, media_type_string(type)); + i, j, av_get_media_type_string(type)); av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ", ist->nb_packets, ist->data_size); @@ -1640,7 +1640,7 @@ static void print_final_stats(int64_t total_size) total_packets += ost->packets_written; av_log(NULL, AV_LOG_VERBOSE, " Output stream #%d:%d (%s): ", - i, j, media_type_string(type)); + i, j, av_get_media_type_string(type)); if (ost->encoding_needed) { av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded", ost->frames_encoded); -- 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 08/10] fftools/ffprobe; drop -show_format_entry
Deprecated since 2012. --- fftools/ffprobe.c | 18 -- 1 file changed, 18 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 42032ee9d6..c4e962389f 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3618,22 +3618,6 @@ static int opt_show_entries(void *optctx, const char *opt, const char *arg) return ret; } -static int opt_show_format_entry(void *optctx, const char *opt, const char *arg) -{ -char *buf = av_asprintf("format=%s", arg); -int ret; - -if (!buf) -return AVERROR(ENOMEM); - -av_log(NULL, AV_LOG_WARNING, - "Option '%s' is deprecated, use '-show_entries format=%s' instead\n", - opt, arg); -ret = opt_show_entries(optctx, opt, buf); -av_free(buf); -return ret; -} - static void opt_input_file(void *optctx, const char *arg) { if (input_filename) { @@ -3894,8 +3878,6 @@ static const OptionDef real_options[] = { { "show_error", 0, { .func_arg = &opt_show_error }, "show probing error" }, { "show_format", 0, { .func_arg = &opt_show_format }, "show format/container info" }, { "show_frames", 0, { .func_arg = &opt_show_frames }, "show frames info" }, -{ "show_format_entry", HAS_ARG, {.func_arg = opt_show_format_entry}, - "show a particular entry from the format/container info", "entry" }, { "show_entries", HAS_ARG, {.func_arg = opt_show_entries}, "show a set of specified entries", "entry_list" }, #if HAVE_THREADS -- 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 07/10] fftools/ffplay: drop options deprecated since 2011
--- doc/ffplay.texi | 8 fftools/ffplay.c | 14 -- 2 files changed, 22 deletions(-) diff --git a/doc/ffplay.texi b/doc/ffplay.texi index e187b5852e..0f090128f2 100644 --- a/doc/ffplay.texi +++ b/doc/ffplay.texi @@ -34,10 +34,6 @@ various FFmpeg APIs. Force displayed width. @item -y @var{height} Force displayed height. -@item -s @var{size} -Set frame size (WxH or abbreviation), needed for videos which do -not contain a header with the frame size like raw YUV. This option -has been deprecated in favor of private options, try -video_size. @item -fs Start in fullscreen mode. @item -an @@ -126,10 +122,6 @@ Read @var{input_url}. @section Advanced options @table @option -@item -pix_fmt @var{format} -Set pixel format. -This option has been deprecated in favor of private options, try -pixel_format. - @item -stats Print several playback statistics, in particular show the stream duration, the codec parameters, the current position in the stream and diff --git a/fftools/ffplay.c b/fftools/ffplay.c index c929ce32ed..38df91f72e 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3471,12 +3471,6 @@ static void event_loop(VideoState *cur_stream) } } -static int opt_frame_size(void *optctx, const char *opt, const char *arg) -{ -av_log(NULL, AV_LOG_WARNING, "Option -s is deprecated, use -video_size.\n"); -return opt_default(NULL, "video_size", arg); -} - static int opt_width(void *optctx, const char *opt, const char *arg) { screen_width = parse_number_or_die(opt, arg, OPT_INT64, 1, INT_MAX); @@ -3499,12 +3493,6 @@ static int opt_format(void *optctx, const char *opt, const char *arg) return 0; } -static int opt_frame_pix_fmt(void *optctx, const char *opt, const char *arg) -{ -av_log(NULL, AV_LOG_WARNING, "Option -pix_fmt is deprecated, use -pixel_format.\n"); -return opt_default(NULL, "pixel_format", arg); -} - static int opt_sync(void *optctx, const char *opt, const char *arg) { if (!strcmp(arg, "audio")) @@ -3582,7 +3570,6 @@ static const OptionDef options[] = { CMDUTILS_COMMON_OPTIONS { "x", HAS_ARG, { .func_arg = opt_width }, "force displayed width", "width" }, { "y", HAS_ARG, { .func_arg = opt_height }, "force displayed height", "height" }, -{ "s", HAS_ARG | OPT_VIDEO, { .func_arg = opt_frame_size }, "set frame size (WxH or abbreviation)", "size" }, { "fs", OPT_BOOL, { &is_full_screen }, "force full screen" }, { "an", OPT_BOOL, { &audio_disable }, "disable audio" }, { "vn", OPT_BOOL, { &video_disable }, "disable video" }, @@ -3599,7 +3586,6 @@ static const OptionDef options[] = { { "alwaysontop", OPT_BOOL, { &alwaysontop }, "window always on top" }, { "volume", OPT_INT | HAS_ARG, { &startup_volume}, "set startup volume 0=min 100=max", "volume" }, { "f", HAS_ARG, { .func_arg = opt_format }, "force format", "fmt" }, -{ "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { .func_arg = opt_frame_pix_fmt }, "set pixel format", "format" }, { "stats", OPT_BOOL | OPT_EXPERT, { &show_status }, "show status", "" }, { "fast", OPT_BOOL | OPT_EXPERT, { &fast }, "non spec compliant optimizations", "" }, { "genpts", OPT_BOOL | OPT_EXPERT, { &genpts }, "generate pts", "" }, -- 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 09/10] fftools: drop the fake "default" option from ffplay/ffprobe
It tries to process any unhandled options as AVOptions. Handle this directly in cmdutils.c, without resorting to a confusing fake option definition (which is currently visible to the users in -help output). --- fftools/cmdutils.c | 8 +++- fftools/ffplay.c | 1 - fftools/ffprobe.c | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index e5684fa840..a52c87dfaf 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -302,6 +302,12 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options) { +static const OptionDef opt_avoptions = { +.name = "AVOption passthrough", +.flags = HAS_ARG, +.u.func_arg = opt_default, +}; + const OptionDef *po; int ret; @@ -315,7 +321,7 @@ int parse_option(void *optctx, const char *opt, const char *arg, arg = "1"; if (!po->name) -po = find_option(options, "default"); +po = &opt_avoptions; if (!po->name) { av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt); return AVERROR(EINVAL); diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 38df91f72e..59fba0e169 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3607,7 +3607,6 @@ static const OptionDef options[] = { #endif { "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, { &rdftspeed }, "rdft speed", "msecs" }, { "showmode", HAS_ARG, { .func_arg = opt_show_mode}, "select show mode (0 = video, 1 = waves, 2 = RDFT)", "mode" }, -{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, { .func_arg = opt_default }, "generic catch all option", "" }, { "i", OPT_BOOL, { &dummy}, "read specified file", "input_file"}, { "codec", HAS_ARG, { .func_arg = opt_codec}, "force decoder", "decoder_name" }, { "acodec", HAS_ARG | OPT_STRING | OPT_EXPERT, {&audio_codec_name }, "force audio decoder","decoder_name" }, diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index c4e962389f..db8930f226 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3898,7 +3898,6 @@ static const OptionDef real_options[] = { { "private", OPT_BOOL, { &show_private_data }, "same as show_private_data" }, { "bitexact", OPT_BOOL, {&do_bitexact}, "force bitexact output" }, { "read_intervals", HAS_ARG, {.func_arg = opt_read_intervals}, "set read intervals", "read_intervals" }, -{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {.func_arg = opt_default}, "generic catch all option", "" }, { "i", HAS_ARG, {.func_arg = opt_input_file_i}, "read specified file", "input_file"}, { "print_filename", HAS_ARG, {.func_arg = opt_print_filename}, "override the printed input filename", "print_file"}, { "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT, { &find_stream_info }, -- 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 10/10] fftools/cmdutils: drop redundant code
It allocates a dummy sws/swr context and tries setting options on it, apparently to check if they are valid. This is redundant, since the options will be checked if/when they are later applied on a context that is actually used for conversion. --- fftools/cmdutils.c | 15 --- 1 file changed, 15 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index a52c87dfaf..6e5ef1beb4 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -539,20 +539,12 @@ int opt_default(void *optctx, const char *opt, const char *arg) #if CONFIG_SWSCALE if (!consumed && (o = opt_find(&sc, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { -struct SwsContext *sws = sws_alloc_context(); -int ret = av_opt_set(sws, opt, arg, 0); -sws_freeContext(sws); if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") || !strcmp(opt, "dstw") || !strcmp(opt, "dsth") || !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) { av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n"); return AVERROR(EINVAL); } -if (ret < 0) { -av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt); -return ret; -} - av_dict_set(&sws_dict, opt, arg, FLAGS); consumed = 1; @@ -566,13 +558,6 @@ int opt_default(void *optctx, const char *opt, const char *arg) #if CONFIG_SWRESAMPLE if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { -struct SwrContext *swr = swr_alloc(); -int ret = av_opt_set(swr, opt, arg, 0); -swr_free(&swr); -if (ret < 0) { -av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt); -return ret; -} av_dict_set(&swr_opts, opt, arg, FLAGS); consumed = 1; } -- 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 2/2] lavc/vp9: fix the race in exporting video enc params
The parameters are currently attached directly to the decoded frame after it is decoded. This is racy, since the frame is shared with other threads, as reported e.g. by the fate-vp9-encparams test in TSAN build. Instead, write the params to a refcounted AVBuffer. Each output frame then gets its own reference to this buffer, which should be thread-safe. --- libavcodec/vp9.c | 93 ++-- 1 file changed, 83 insertions(+), 10 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 7ef10f7a80..f9df898733 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -41,6 +41,10 @@ #define VP9_SYNCCODE 0x498342 +typedef struct VP9TFPriv { +AVBufferRef *enc_par; +} VP9TFPriv; + #if HAVE_THREADS DEFINE_OFFSET_ARRAY(VP9Context, vp9_context, pthread_init_cnt, (offsetof(VP9Context, progress_mutex)), @@ -100,6 +104,13 @@ static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f) f->hwaccel_picture_private = NULL; } +static void vp9_tf_priv_free(void *opaque, uint8_t *data) +{ +VP9TFPriv *p = (VP9TFPriv*)data; +av_buffer_unref(&p->enc_par); +av_freep(&data); +} + static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) { VP9Context *s = avctx->priv_data; @@ -139,6 +150,19 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) } } +if (avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS) { +VP9TFPriv *p = av_mallocz(sizeof(*p)); +if (!p) +goto fail; + +f->tf.priv_buf = av_buffer_create((uint8_t*)p, sizeof(*p), vp9_tf_priv_free, + NULL, AV_BUFFER_FLAG_READONLY); +if (!f->tf.priv_buf) { +av_freep(&p); +goto fail; +} +} + return 0; fail: @@ -1497,7 +1521,9 @@ int loopfilter_proc(AVCodecContext *avctx) static int vp9_export_enc_params(VP9Context *s, VP9Frame *frame) { +VP9TFPriv *p = (VP9TFPriv*)frame->tf.priv_buf->data; AVVideoEncParams *par; +size_t par_size; unsigned int tile, nb_blocks = 0; if (s->s.h.segmentation.enabled) { @@ -1505,11 +1531,16 @@ static int vp9_export_enc_params(VP9Context *s, VP9Frame *frame) nb_blocks += s->td[tile].nb_block_structure; } -par = av_video_enc_params_create_side_data(frame->tf.f, -AV_VIDEO_ENC_PARAMS_VP9, nb_blocks); +par = av_video_enc_params_alloc(AV_VIDEO_ENC_PARAMS_VP9, nb_blocks, &par_size); if (!par) return AVERROR(ENOMEM); +p->enc_par = av_buffer_create((uint8_t *)par, par_size, NULL, NULL, 0); +if (!p->enc_par) { +av_freep(&par); +return AVERROR(ENOMEM); +} + par->qp = s->s.h.yac_qi; par->delta_qp[0][0] = s->s.h.ydc_qdelta; par->delta_qp[1][0] = s->s.h.uvdc_qdelta; @@ -1547,6 +1578,38 @@ static int vp9_export_enc_params(VP9Context *s, VP9Frame *frame) return 0; } +static int vp9_output_frame(AVFrame *dst, const ThreadFrame *src) +{ +int ret = 0; + +ret = av_frame_ref(dst, src->f); +if (ret < 0) +return ret; + +if (src->priv_buf) { +VP9TFPriv *p = (VP9TFPriv*)src->priv_buf->data; + +if (p->enc_par) { +AVBufferRef *buf = av_buffer_ref(p->enc_par); +if (!buf) { +ret = AVERROR(ENOMEM); +goto finish; +} + +if (!av_frame_new_side_data_from_buf(dst, AV_FRAME_DATA_VIDEO_ENC_PARAMS, buf)) { +av_buffer_unref(&buf); +ret = AVERROR(ENOMEM); +goto finish; +} +} +} + +finish: +if (ret < 0) +av_frame_unref(dst); +return ret; +} + static int vp9_decode_frame(AVCodecContext *avctx, void *frame, int *got_frame, AVPacket *pkt) { @@ -1561,11 +1624,14 @@ static int vp9_decode_frame(AVCodecContext *avctx, void *frame, if ((ret = decode_frame_header(avctx, data, size, &ref)) < 0) { return ret; } else if (ret == 0) { -if (!s->s.refs[ref].f->buf[0]) { +ThreadFrame *tf = &s->s.refs[ref]; +if (!tf->f->buf[0]) { av_log(avctx, AV_LOG_ERROR, "Requested reference %d not available\n", ref); return AVERROR_INVALIDDATA; } -if ((ret = av_frame_ref(frame, s->s.refs[ref].f)) < 0) +ff_thread_await_progress(tf, INT_MAX, 0); +ret = vp9_output_frame(frame, tf); +if (ret < 0) return ret; ((AVFrame *)frame)->pts = pkt->pts; ((AVFrame *)frame)->pkt_dts = pkt->dts; @@ -1743,6 +1809,17 @@ static int vp9_decode_frame(AVCodecContext *avctx, void *frame, ff_thread_finish_setup(avctx); } } while (s->pass++ == 1); + +/* this must be done before report_progress(INT_MAX), since the exported + * data may be read in other threads */ +if (avctx->export_side_data & AV_CODEC_EXPORT_DAT
[FFmpeg-devel] [PATCH 1/2] lavc/threadframe: allow decoders to attach buffers to ThreadFrame
This may be useful for synchronizing side data that only becomes available after ff_thread_finish_setup() is called. --- libavcodec/pthread_frame.c | 1 + libavcodec/threadframe.h | 3 +++ libavcodec/utils.c | 7 +++ 3 files changed, 11 insertions(+) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 33b5a2e628..4da3832942 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -1138,6 +1138,7 @@ fail: void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f) { av_buffer_unref(&f->progress); +av_buffer_unref(&f->priv_buf); f->owner[0] = f->owner[1] = NULL; ff_thread_release_buffer(avctx, f->f); } diff --git a/libavcodec/threadframe.h b/libavcodec/threadframe.h index dea4dadc6d..c2ddc2969f 100644 --- a/libavcodec/threadframe.h +++ b/libavcodec/threadframe.h @@ -30,6 +30,9 @@ typedef struct ThreadFrame { // progress->data is an array of 2 ints holding progress for top/bottom // fields AVBufferRef *progress; + +/* arbitrary user data propagated along with the frame */ +AVBufferRef *priv_buf; } ThreadFrame; /** diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 066da76e16..cc2c2715b3 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -881,6 +881,12 @@ int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src) return AVERROR(ENOMEM); } +if (src->priv_buf) { +dst->priv_buf = av_buffer_ref(src->priv_buf); +if (!dst->priv_buf) +return AVERROR(ENOMEM); +} + return 0; } @@ -913,6 +919,7 @@ void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f) f->owner[0] = f->owner[1] = NULL; if (f->f) av_frame_unref(f->f); +av_buffer_unref(&f->priv_buf); } void ff_thread_finish_setup(AVCodecContext *avctx) -- 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 v4] avcodec/pngenc: support writing iCCP chunks
From: Niklas Haas encode_zbuf is mostly a mirror image of decode_zbuf. Other than that, the code is pretty straightforward. Special care needs to be taken to avoid writing more than 79 characters of the profile description (the maximum supported). To write the (dynamically sized) deflate-encoded data, we allocate extra space in the packet and use that directly as a scratch buffer. Modify png_write_chunk slightly to allow pre-writing the chunk contents like this. Also add a FATE transcode test to ensure that the ICC profile gets encoded correctly. --- Changes in v4: - Remove stray commas on line endings - Re-use s->zstream instead of creating new deflate instances - Add size checking and explicit header padding - Delete the now redundant and overly specialized single-use helpers - Don't redundantly print error code, just print cause - Correctly account for max_packet_size in encode_apng as well - Fix FATE_PNG_PROBE -> FATE_PNG and add -show_frames to test --- libavcodec/pngenc.c| 86 +- tests/fate/image.mak | 3 ++ tests/ref/fate/png-icc | 43 + 3 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 tests/ref/fate/png-icc diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 3ebcc1e571..b0091f2b40 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -235,7 +235,8 @@ static void png_write_chunk(uint8_t **f, uint32_t tag, bytestream_put_be32(f, av_bswap32(tag)); if (length > 0) { crc = av_crc(crc_table, crc, buf, length); -memcpy(*f, buf, length); +if (*f != buf) +memcpy(*f, buf, length); *f += length; } bytestream_put_be32(f, ~crc); @@ -343,10 +344,53 @@ static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf) return 1; } +static int png_write_iccp(AVCodecContext *avctx, const AVFrameSideData *sd) +{ +PNGEncContext *s = avctx->priv_data; +const AVDictionaryEntry *entry; +const char *name; +uint8_t *start, *buf; +int ret; + +if (!sd || !sd->size) +return 0; +s->zstream.next_in = sd->data; +s->zstream.avail_in = sd->size; + +/* write the chunk contents first */ +start = s->bytestream + 8; /* make room for iCCP tag + length */ +buf = start; + +/* profile description */ +entry = av_dict_get(sd->metadata, "name", NULL, 0); +name = (entry && entry->value[0]) ? entry->value : "icc"; +for (int i = 0;; i++) { +char c = (i == 79) ? 0 : name[i]; +bytestream_put_byte(&buf, c); +if (!c) +break; +} + +/* compression method and profile data */ +bytestream_put_byte(&buf, 0); +s->zstream.next_out = buf; +s->zstream.avail_out = s->bytestream_end - buf; +ret = deflate(&s->zstream, Z_FINISH); +deflateReset(&s->zstream); +if (ret != Z_STREAM_END) +return AVERROR_EXTERNAL; + +/* rewind to the start and write the chunk header/crc */ +png_write_chunk(&s->bytestream, MKTAG('i', 'C', 'C', 'P'), start, +s->zstream.next_out - start); +return 0; +} + static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) { AVFrameSideData *side_data; PNGEncContext *s = avctx->priv_data; +int ret; /* write png header */ AV_WB32(s->buf, avctx->width); @@ -399,7 +443,13 @@ static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) if (png_get_gama(pict->color_trc, s->buf)) png_write_chunk(&s->bytestream, MKTAG('g', 'A', 'M', 'A'), s->buf, 4); -/* put the palette if needed */ +side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE); +if ((ret = png_write_iccp(avctx, side_data))) { +av_log(avctx, AV_LOG_WARNING, "Failed writing iCCP chunk\n"); +return ret; +} + +/* put the palette if needed, must be after colorspace information */ if (s->color_type == PNG_COLOR_TYPE_PALETTE) { int has_alpha, alpha, i; unsigned int v; @@ -522,6 +572,34 @@ the_end: return ret; } +static int add_icc_profile_size(AVCodecContext *avctx, const AVFrame *pict, +size_t *max_packet_size) +{ +PNGEncContext *s = avctx->priv_data; +const AVFrameSideData *sd; +uLong bound; + +sd = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE); +if (!sd || !sd->size) +return 0; +if (sd->size > UINT_MAX) +goto too_large; + +s->zstream.next_in = sd->data; +s->zstream.avail_in = sd->size; +bound = deflateBound(&s->zstream, sd->size) + 128; /* header */ +deflateReset(&s->zstream); +if (bound > INT_MAX) +goto too_large; + +*max_packet_size += bound; +return 0; + +too_large: +av_log(avctx, AV_LOG_WARNING, "ICC profile too large for iCCP chunk\n"); +return AVERROR_INVALIDDATA; +} + static int encode_png(AVCodecContext *avctx, AVPacket *pkt, const
[FFmpeg-devel] [PATCH v5] avcodec/pngenc: support writing iCCP chunks
From: Niklas Haas We re-use the PNGEncContext.zstream for deflate-related operations. Other than that, the code is pretty straightforward. Special care needs to be taken to avoid writing more than 79 characters of the profile description (the maximum supported). To write the (dynamically sized) deflate-encoded data, we allocate extra space in the packet and use that directly as a scratch buffer. Modify png_write_chunk slightly to allow pre-writing the chunk contents like this. Also add a FATE transcode test to ensure that the ICC profile gets encoded correctly. Signed-off-by: Niklas Haas --- Changes in v5: - Fix FATE failure (possible segfault in encode_apng) - Fix commit message (still talked about deleted encode_zbuf) - Add Signed-off-by line --- libavcodec/pngenc.c| 88 +- tests/fate/image.mak | 3 ++ tests/ref/fate/png-icc | 43 + 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 tests/ref/fate/png-icc diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 3ebcc1e571..947138e3b5 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -235,7 +235,8 @@ static void png_write_chunk(uint8_t **f, uint32_t tag, bytestream_put_be32(f, av_bswap32(tag)); if (length > 0) { crc = av_crc(crc_table, crc, buf, length); -memcpy(*f, buf, length); +if (*f != buf) +memcpy(*f, buf, length); *f += length; } bytestream_put_be32(f, ~crc); @@ -343,10 +344,53 @@ static int png_get_gama(enum AVColorTransferCharacteristic trc, uint8_t *buf) return 1; } +static int png_write_iccp(AVCodecContext *avctx, const AVFrameSideData *sd) +{ +PNGEncContext *s = avctx->priv_data; +const AVDictionaryEntry *entry; +const char *name; +uint8_t *start, *buf; +int ret; + +if (!sd || !sd->size) +return 0; +s->zstream.next_in = sd->data; +s->zstream.avail_in = sd->size; + +/* write the chunk contents first */ +start = s->bytestream + 8; /* make room for iCCP tag + length */ +buf = start; + +/* profile description */ +entry = av_dict_get(sd->metadata, "name", NULL, 0); +name = (entry && entry->value[0]) ? entry->value : "icc"; +for (int i = 0;; i++) { +char c = (i == 79) ? 0 : name[i]; +bytestream_put_byte(&buf, c); +if (!c) +break; +} + +/* compression method and profile data */ +bytestream_put_byte(&buf, 0); +s->zstream.next_out = buf; +s->zstream.avail_out = s->bytestream_end - buf; +ret = deflate(&s->zstream, Z_FINISH); +deflateReset(&s->zstream); +if (ret != Z_STREAM_END) +return AVERROR_EXTERNAL; + +/* rewind to the start and write the chunk header/crc */ +png_write_chunk(&s->bytestream, MKTAG('i', 'C', 'C', 'P'), start, +s->zstream.next_out - start); +return 0; +} + static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) { AVFrameSideData *side_data; PNGEncContext *s = avctx->priv_data; +int ret; /* write png header */ AV_WB32(s->buf, avctx->width); @@ -399,7 +443,13 @@ static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) if (png_get_gama(pict->color_trc, s->buf)) png_write_chunk(&s->bytestream, MKTAG('g', 'A', 'M', 'A'), s->buf, 4); -/* put the palette if needed */ +side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE); +if ((ret = png_write_iccp(avctx, side_data))) { +av_log(avctx, AV_LOG_WARNING, "Failed writing iCCP chunk\n"); +return ret; +} + +/* put the palette if needed, must be after colorspace information */ if (s->color_type == PNG_COLOR_TYPE_PALETTE) { int has_alpha, alpha, i; unsigned int v; @@ -522,6 +572,36 @@ the_end: return ret; } +static int add_icc_profile_size(AVCodecContext *avctx, const AVFrame *pict, +size_t *max_packet_size) +{ +PNGEncContext *s = avctx->priv_data; +const AVFrameSideData *sd; +uLong bound; + +if (!pict) +return 0; +sd = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE); +if (!sd || !sd->size) +return 0; +if (sd->size > UINT_MAX) +goto too_large; + +s->zstream.next_in = sd->data; +s->zstream.avail_in = sd->size; +bound = deflateBound(&s->zstream, sd->size) + 128; /* header */ +deflateReset(&s->zstream); +if (bound > INT_MAX) +goto too_large; + +*max_packet_size += bound; +return 0; + +too_large: +av_log(avctx, AV_LOG_WARNING, "ICC profile too large for iCCP chunk\n"); +return AVERROR_INVALIDDATA; +} + static int encode_png(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { @@ -537,6 +617,8 @@ static int encode_png(AVCodecContext *avctx, AVPacket *pkt, enc_row_size + 12 * (((int64_t)enc_r
[FFmpeg-devel] [PATCH v2] avcodec/mjpegenc: support writing ICC profiles
From: Niklas Haas This is mostly straightforward. The major complication is that, as a result of the 16-bit chunk size limitation, ICC profiles may need to be split up into multiple chunks. We also need to make sure to allocate enough extra space in the packet to fit the ICC profile, so modify both mpegvideo_enc.c and ljpegenc.c to take into account this extra overhead. Also add a FATE transcode test to ensure that the ICC profile gets written (and read) correctly. Note that this ICC profile is smaller than 64 kB, so this doesn't test the APP2 chunk re-arranging code at all. Signed-off-by: Niklas Haas --- Changes in v2: - Merge FATE test into this commit - Fix possible segfault (when no AVFrame is available) --- libavcodec/ljpegenc.c| 6 - libavcodec/mjpegenc.c| 3 ++- libavcodec/mjpegenc_common.c | 43 +--- libavcodec/mjpegenc_common.h | 2 +- libavcodec/mpegvideo_enc.c | 3 +++ tests/fate/image.mak | 3 +++ tests/ref/fate/jpg-icc | 42 +++ 7 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 tests/ref/fate/jpg-icc diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c index e15f448f90..c54450c338 100644 --- a/libavcodec/ljpegenc.c +++ b/libavcodec/ljpegenc.c @@ -216,6 +216,7 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, { LJpegEncContext *s = avctx->priv_data; PutBitContext pb; +const AVFrameSideData *sd; const int width = avctx->width; const int height = avctx->height; const int mb_width = (width + s->hsample[0] - 1) / s->hsample[0]; @@ -233,12 +234,15 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, * s->hsample[0] * s->vsample[0]; } +if ((sd = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE))) +max_pkt_size += sd->size; + if ((ret = ff_alloc_packet(avctx, pkt, max_pkt_size)) < 0) return ret; init_put_bits(&pb, pkt->data, pkt->size); -ff_mjpeg_encode_picture_header(avctx, &pb, NULL, &s->scantable, +ff_mjpeg_encode_picture_header(avctx, &pb, pict, NULL, &s->scantable, s->pred, s->matrix, s->matrix); header_bits = put_bits_count(&pb); diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index 08671b0df7..d7c0c763a1 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -77,7 +77,8 @@ static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256], static void mjpeg_encode_picture_header(MpegEncContext *s) { -ff_mjpeg_encode_picture_header(s->avctx, &s->pb, s->mjpeg_ctx, +const AVFrame *frame = s->picture->f; +ff_mjpeg_encode_picture_header(s->avctx, &s->pb, frame, s->mjpeg_ctx, &s->intra_scantable, 0, s->intra_matrix, s->chroma_intra_matrix); diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c index 995e2b7670..5594a8d239 100644 --- a/libavcodec/mjpegenc_common.c +++ b/libavcodec/mjpegenc_common.c @@ -130,8 +130,10 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, AV_WB16(ptr, size); } -static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p) +static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p, + const AVFrame *frame) { +const AVFrameSideData *sd = NULL; int size; uint8_t *ptr; @@ -161,6 +163,41 @@ static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p) put_bits(p, 8, 0); /* thumbnail height */ } +/* ICC profile */ +if (frame) +sd = av_frame_get_side_data(frame, AV_FRAME_DATA_ICC_PROFILE); +if (sd && sd->size) { +static const uint8_t hdr_size = strlen("ICC_PROFILE")+5; +static const uint16_t max_chunk_size = UINT16_MAX - hdr_size; +const uint8_t *data = sd->data; +size_t remaining = sd->size; +size_t nb_chunks = (remaining + max_chunk_size - 1) / max_chunk_size; +if (nb_chunks > 255) { +av_log(avctx, AV_LOG_WARNING, +"Cannot store %zu byte ICC profile: too large for JPEG\n", +sd->size); +nb_chunks = remaining = 0; +} + +for (int i = 0; i < nb_chunks; i++) { +size = FFMIN(remaining, max_chunk_size); +av_assert1(size > 0); +put_marker(p, APP2); +put_bits(p, 16, size + hdr_size); +ff_put_string(p, "ICC_PROFILE", 1); +put_bits(p, 8, i+1); +put_bits(p, 8, nb_chunks); +flush_put_bits(p); +ptr = put_bits_ptr(p); +skip_put_bytes(p, size); +memcpy(ptr, data, size); +remaining -= size; +data += size; +} + +av_assert1(!remaining); +} + /* comment */ if (!(avctx->flags & AV_CODEC_FLAG_BITEX
Re: [FFmpeg-devel] [PATCH 3/4] avformat/mxfdec: Check for avio_read() failure in mxf_read_strong_ref_array()
On Mon, Mar 14, 2022 at 06:08:32PM +0100, Marton Balint wrote: > > > On Mon, 14 Mar 2022, Michael Niedermayer wrote: > > > On Sun, Mar 13, 2022 at 04:52:25PM +0100, Marton Balint wrote: > > > > > > > > > On Sun, 13 Mar 2022, Michael Niedermayer wrote: > > > > > > > Signed-off-by: Michael Niedermayer > > > > --- > > > > libavformat/mxfdec.c | 8 +++- > > > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c > > > > index d7cdd22c8a..828fc0f9f1 100644 > > > > --- a/libavformat/mxfdec.c > > > > +++ b/libavformat/mxfdec.c > > > > @@ -932,6 +932,7 @@ static int mxf_read_cryptographic_context(void > > > > *arg, AVIOContext *pb, int tag, i > > > > > > > > static int mxf_read_strong_ref_array(AVIOContext *pb, UID **refs, int > > > > *count) > > > > { > > > > +int64_t ret; > > > > unsigned c = avio_rb32(pb); > > > > > > > > //avio_read() used int > > > > @@ -946,7 +947,12 @@ static int mxf_read_strong_ref_array(AVIOContext > > > > *pb, UID **refs, int *count) > > > > return AVERROR(ENOMEM); > > > > } > > > > avio_skip(pb, 4); /* useless size of objects, always 16 according > > > > to specs */ > > > > -avio_read(pb, (uint8_t *)*refs, *count * sizeof(UID)); > > > > +ret = avio_read(pb, (uint8_t *)*refs, *count * sizeof(UID)); > > > > +if (ret != *count * sizeof(UID)) { > > > > +*count = ret < 0 ? 0 : ret / sizeof(UID); > > > > > > > > I suggest you hard fail if the read count is not the expected, do not > > > silently ignore corrupt file. > > > > > > Regards, > > > Marton > > > > > > > +return ret < 0 ? ret : AVERROR_INVALIDDATA; > > > > Does it not hard fail here ? > > Yeah, it does, sorry. This extra count calculation confused me... I'd just > probably set it to 0 in case of a partial read, same as in case of an error, > but fine either way I guess. i wanted to set the count to be most correct value. So if someone was debuging this and tried to just not fail it would already have a useable value in count. thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB it is not once nor twice but times without number that the same ideas make their appearance in the world. -- Aristotle 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 1/2] lavc/threadframe: allow decoders to attach buffers to ThreadFrame
Anton Khirnov: > This may be useful for synchronizing side data that only becomes > available after ff_thread_finish_setup() is called. > --- > libavcodec/pthread_frame.c | 1 + > libavcodec/threadframe.h | 3 +++ > libavcodec/utils.c | 7 +++ > 3 files changed, 11 insertions(+) > > diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c > index 33b5a2e628..4da3832942 100644 > --- a/libavcodec/pthread_frame.c > +++ b/libavcodec/pthread_frame.c > @@ -1138,6 +1138,7 @@ fail: > void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f) > { > av_buffer_unref(&f->progress); > +av_buffer_unref(&f->priv_buf); > f->owner[0] = f->owner[1] = NULL; > ff_thread_release_buffer(avctx, f->f); > } > diff --git a/libavcodec/threadframe.h b/libavcodec/threadframe.h > index dea4dadc6d..c2ddc2969f 100644 > --- a/libavcodec/threadframe.h > +++ b/libavcodec/threadframe.h > @@ -30,6 +30,9 @@ typedef struct ThreadFrame { > // progress->data is an array of 2 ints holding progress for top/bottom > // fields > AVBufferRef *progress; > + > +/* arbitrary user data propagated along with the frame */ > +AVBufferRef *priv_buf; > } ThreadFrame; > > /** > diff --git a/libavcodec/utils.c b/libavcodec/utils.c > index 066da76e16..cc2c2715b3 100644 > --- a/libavcodec/utils.c > +++ b/libavcodec/utils.c > @@ -881,6 +881,12 @@ int ff_thread_ref_frame(ThreadFrame *dst, const > ThreadFrame *src) > return AVERROR(ENOMEM); > } > > +if (src->priv_buf) { > +dst->priv_buf = av_buffer_ref(src->priv_buf); > +if (!dst->priv_buf) > +return AVERROR(ENOMEM); > +} > + > return 0; > } > > @@ -913,6 +919,7 @@ void ff_thread_release_ext_buffer(AVCodecContext *avctx, > ThreadFrame *f) > f->owner[0] = f->owner[1] = NULL; > if (f->f) > av_frame_unref(f->f); > +av_buffer_unref(&f->priv_buf); > } > > void ff_thread_finish_setup(AVCodecContext *avctx) This approach has the downside that you have to add the priv_buf before ff_thread_finish_setup(). So in case it is not apparent initially whether one needs this one is forced to add it (even if it turns out not to be needed); it will also necessitate two av_buffer_ref() in. A better approach would be to replace the progress array (of two atomic ints) with a struct containing these two atomic ints and whatever data needs to be shared. The owner should logically also be part of this struct, yet I could not figure out if this is compatible with current h264dec last time I looked at this (when I wrote the patchset containing 02220b88fc38ef9dd4f2d519f5d3e4151258b60c); the current way of doing things allows different threads to have different opinions about the ownership of the frames. (My actual aim with this patchset was to move the AVFrame into the aforementioned structure like so: struct { atomic_int progress[2]; AVFrame *f; }; This would avoid the need for the av_frame_ref() in ff_thread_ref_frame(); therefore all the frame's properties could be set directly on the AVFrame by its owner as long as the frame is not finished. The non-owners could read the data subject to the current limitations (i.e. they have to wait for progress) and could read anything after the frame is finished (progress == INT_MAX; codecs could of course use their own semantics here if they wished). There were two reasons why I didn't finish this approach: 1. How to synchronize in case of two owners? (Happens only for h264dec.) 2. This would add an av_frame_alloc() for every frame, even when not using frame threading. The latter can be easily avoided, but avoiding this with frame-threading would require a smarter pool-implementation. And I hate to use/extend the AVBuffer-API for something for which it is simply the wrong tool and use something that does not require an allocation for every ref. (It would nevertheless have been advantageous allocation-wise, because one saves the allocations implicit in av_frame_ref().)) - Andreas ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2] avcodec: Add dv marker bsf
On Tue, Mar 15, 2022 at 09:54:26AM +0100, Anton Khirnov wrote: > Could you please add a test? that was my plan somehow i forgot after the sample files from fate didnt work with it and i fixed that (in fact adding a test was why i tried it with files from fate :) thx for reminding me [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I do not agree with what you have to say, but I'll defend to the death your right to say it. -- Voltaire 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".
[FFmpeg-devel] [PATCH] avcodec/codec_par: do not copy AVChannelLayout struct directly
Later we use av_channel_layout_copy, but that uninits the struct unintentionally freeing the possibly allocated u.map pointer. Signed-off-by: Marton Balint --- libavcodec/codec_par.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c index e4b329c838..abda649aa8 100644 --- a/libavcodec/codec_par.c +++ b/libavcodec/codec_par.c @@ -78,6 +78,7 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src codec_parameters_reset(dst); memcpy(dst, src, sizeof(*dst)); +dst->ch_layout = (AVChannelLayout){0}; dst->extradata = NULL; dst->extradata_size = 0; if (src->extradata) { -- 2.31.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] doc/APIchanges: update for the new channel layout API
--- doc/APIchanges | 30 ++ 1 file changed, 30 insertions(+) diff --git a/doc/APIchanges b/doc/APIchanges index ccc4f24b28..88a2e82b76 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,36 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-03-15 - cdba98bb80 - lavfi 8.28.100 - avfilter.h buffersink.h buffersrc.h + Update AVFilterLink for the new channel layout API: add ch_layout, + deprecate channel_layout. + + Update the buffersink filter sink for the new channel layout API: + add av_buffersink_get_ch_layout() and the ch_layouts option, + deprecate av_buffersink_get_channel_layout() and the channel_layouts option. + + Update AVBufferSrcParameters for the new channel layout API: + add ch_layout, deprecate channel_layout. + +2022-03-15 - cdba98bb80 - lavc 59.24.100 - avcodec.h codec_par.h + Update AVCodecParameters for the new channel layout API: add ch_layout, + deprecate channels/channel_layout. + + Update AVCodecContext for the new channel layout API: add ch_layout, + deprecate channels/channel_layout. + + Update AVCodec for the new channel layout API: add ch_layouts, + deprecate channel_layouts. + +2022-03-15 - cdba98bb80 - lavu 57.24.100 - channel_layout.h frame.h opt.h + Add new channel layout API based on the AVChannelLayout struct. + Add support for Ambisonic audio. + Deprecate previous channel layout API based on uint64 bitmasks. + + Add AV_OPT_TYPE_CHLAYOUT option type, deprecate AV_OPT_TYPE_CHANNEL_LAYOUT. + Update AVFrame for the new channel layout API: add ch_layout, deprecate + channels/channel_layout. + 2022-03-10 - xx - lavu 57.23.100 - cpu.h Add AV_CPU_FLAG_AVX512ICL. -- 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] avutil/channel_layout: Fix leak of string
Fixes memleaks in the channel_layout FATE-test. Signed-off-by: Andreas Rheinhardt --- libavutil/channel_layout.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 05ed35c078..8cc4efe4cf 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -587,6 +587,7 @@ int av_channel_layout_from_string(AVChannelLayout *channel_layout, av_free(channel); av_free(chname); } +av_free(chlist); return 0; } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avfilter/af_join: Don't use memcpy for overlapping regions
Reported by ASAN as memcpy-param-overlap when running the filter-join FATE-test. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_join.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/af_join.c b/libavfilter/af_join.c index 3e272d9161..6f01c6f70a 100644 --- a/libavfilter/af_join.c +++ b/libavfilter/af_join.c @@ -252,8 +252,8 @@ typedef struct ChannelList { static enum AVChannel channel_list_pop(ChannelList *chl, int idx) { enum AVChannel ret = chl->ch[idx]; -memcpy(chl->ch + idx, chl->ch + idx + 1, - (chl->nb_ch - idx - 1) * sizeof(*chl->ch)); +memmove(chl->ch + idx, chl->ch + idx + 1, +(chl->nb_ch - idx - 1) * sizeof(*chl->ch)); chl->nb_ch--; return ret; } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avfilter/af_join: Don't use memcpy for overlapping regions
lgtm ___ 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/codec_par: do not copy AVChannelLayout struct directly
On 3/15/2022 11:28 AM, Marton Balint wrote: Later we use av_channel_layout_copy, but that uninits the struct unintentionally freeing the possibly allocated u.map pointer. Signed-off-by: Marton Balint --- libavcodec/codec_par.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c index e4b329c838..abda649aa8 100644 --- a/libavcodec/codec_par.c +++ b/libavcodec/codec_par.c @@ -78,6 +78,7 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src codec_parameters_reset(dst); memcpy(dst, src, sizeof(*dst)); +dst->ch_layout = (AVChannelLayout){0}; dst->extradata = NULL; dst->extradata_size = 0; if (src->extradata) { LGTM. ___ 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] avutil/channel_layout: Fix leak of string
On 3/15/2022 11:55 AM, Andreas Rheinhardt wrote: Fixes memleaks in the channel_layout FATE-test. Signed-off-by: Andreas Rheinhardt --- libavutil/channel_layout.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 05ed35c078..8cc4efe4cf 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -587,6 +587,7 @@ int av_channel_layout_from_string(AVChannelLayout *channel_layout, av_free(channel); av_free(chname); } +av_free(chlist); return 0; } LGTM. ___ 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] doc/APIchanges: update for the new channel layout API
On 3/15/2022 11:54 AM, Anton Khirnov wrote: --- doc/APIchanges | 30 ++ 1 file changed, 30 insertions(+) diff --git a/doc/APIchanges b/doc/APIchanges index ccc4f24b28..88a2e82b76 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,36 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-03-15 - cdba98bb80 - lavfi 8.28.100 - avfilter.h buffersink.h buffersrc.h + Update AVFilterLink for the new channel layout API: add ch_layout, + deprecate channel_layout. + + Update the buffersink filter sink for the new channel layout API: + add av_buffersink_get_ch_layout() and the ch_layouts option, + deprecate av_buffersink_get_channel_layout() and the channel_layouts option. + + Update AVBufferSrcParameters for the new channel layout API: + add ch_layout, deprecate channel_layout. + +2022-03-15 - cdba98bb80 - lavc 59.24.100 - avcodec.h codec_par.h + Update AVCodecParameters for the new channel layout API: add ch_layout, + deprecate channels/channel_layout. + + Update AVCodecContext for the new channel layout API: add ch_layout, + deprecate channels/channel_layout. + + Update AVCodec for the new channel layout API: add ch_layouts, + deprecate channel_layouts. + +2022-03-15 - cdba98bb80 - lavu 57.24.100 - channel_layout.h frame.h opt.h + Add new channel layout API based on the AVChannelLayout struct. + Add support for Ambisonic audio. + Deprecate previous channel layout API based on uint64 bitmasks. + + Add AV_OPT_TYPE_CHLAYOUT option type, deprecate AV_OPT_TYPE_CHANNEL_LAYOUT. + Update AVFrame for the new channel layout API: add ch_layout, deprecate + channels/channel_layout. + 2022-03-10 - xx - lavu 57.23.100 - cpu.h Add AV_CPU_FLAG_AVX512ICL. Missing the non diegetic disposition from b2d6e7a289 in lavf, and swr_alloc_set_opts2() from libswr (and some AVOption values, but not sure if those need to be mentioned). LGTM otherwise. Thanks. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing
On Thu, Mar 10, 2022 at 10:14 AM Vignesh Venkatasubramanian wrote: > > On Thu, Mar 10, 2022 at 8:01 AM Andreas Rheinhardt > wrote: > > > > Vignesh Venkatasubramanian: > > > Add an AVIF muxer by re-using the existing the mov/mp4 muxer. > > > > > > AVIF Specifiation: https://aomediacodec.github.io/av1-avif > > > > > > Sample usage for still image: > > > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif > > > > > > Sample usage for animated AVIF image: > > > ffmpeg -i video.mp4 animated.avif > > > > > > We can re-use any of the AV1 encoding options that will make > > > sense for image encoding (like bitrate, tiles, encoding speed, > > > etc). > > > > > > The files generated by this muxer has been verified to be valid > > > AVIF files by the following: > > > 1) Displays on Chrome (both still and animated images). > > > 2) Displays on Firefox (only still images, firefox does not support > > >animated AVIF yet). > > > 3) Verfied to be valid by Compliance Warden: > > >https://github.com/gpac/ComplianceWarden > > > > > > Fixes the encoder/muxer part of Trac Ticket #7621 > > > > > > Signed-off-by: Vignesh Venkatasubramanian > > > --- > > > configure| 1 + > > > libavformat/allformats.c | 1 + > > > libavformat/movenc.c | 323 --- > > > libavformat/movenc.h | 5 + > > > 4 files changed, 305 insertions(+), 25 deletions(-) > > > > > > diff --git a/configure b/configure > > > index 8c69ab0c86..6d7020e96b 100755 > > > --- a/configure > > > +++ b/configure > > > @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer" > > > av1_demuxer_select="av1_frame_merge_bsf av1_parser" > > > avi_demuxer_select="riffdec exif" > > > avi_muxer_select="riffenc" > > > +avif_muxer_select="mov_muxer" > > > caf_demuxer_select="iso_media" > > > caf_muxer_select="iso_media" > > > dash_muxer_select="mp4_muxer" > > > diff --git a/libavformat/allformats.c b/libavformat/allformats.c > > > index d066a7745b..400c17afbd 100644 > > > --- a/libavformat/allformats.c > > > +++ b/libavformat/allformats.c > > > @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer; > > > extern const AVInputFormat ff_av1_demuxer; > > > extern const AVInputFormat ff_avi_demuxer; > > > extern const AVOutputFormat ff_avi_muxer; > > > +extern const AVOutputFormat ff_avif_muxer; > > > extern const AVInputFormat ff_avisynth_demuxer; > > > extern const AVOutputFormat ff_avm2_muxer; > > > extern const AVInputFormat ff_avr_demuxer; > > > diff --git a/libavformat/movenc.c b/libavformat/movenc.c > > > index 1a746a67fd..504403ab0b 100644 > > > --- a/libavformat/movenc.c > > > +++ b/libavformat/movenc.c > > > @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, > > > MOVTrack *track) > > > > > > avio_wb32(pb, 0); > > > ffio_wfourcc(pb, "av1C"); > > > -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1); > > > +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode > > > != MODE_AVIF); > > > return update_size(pb, pos); > > > } > > > > > > @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, > > > MOVTrack *track, int prefer_icc) > > > } > > > } > > > > > > -/* We should only ever be called by MOV or MP4. */ > > > -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4); > > > +/* We should only ever be called for MOV, MP4 and AVIF. */ > > > +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 || > > > + track->mode == MODE_AVIF); > > > > > > avio_wb32(pb, 0); /* size */ > > > ffio_wfourcc(pb, "colr"); > > > -if (track->mode == MODE_MP4) > > > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) > > > ffio_wfourcc(pb, "nclx"); > > > else > > > ffio_wfourcc(pb, "nclc"); > > > @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, > > > MOVTrack *track, int prefer_icc) > > > avio_wb16(pb, track->par->color_primaries); > > > avio_wb16(pb, track->par->color_trc); > > > avio_wb16(pb, track->par->color_space); > > > -if (track->mode == MODE_MP4) { > > > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) { > > > int full_range = track->par->color_range == AVCOL_RANGE_JPEG; > > > avio_w8(pb, full_range << 7); > > > } > > > @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, > > > int len, MOVTrack *track) > > >|| (track->par->width == 1440 && track->par->height == > > > 1080) > > >|| (track->par->width == 1920 && track->par->height == > > > 1080); > > > > > > -if (track->mode == MODE_MOV && > > > +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) && > > > (encoder = av_dict_get(track->st->metadata, "encoder", NULL, > > > 0))) { > > > av_strlcpy(compressor_name, encoder->value, 32); > > > } else if (track->par->codec_id == AV_CODEC
[FFmpeg-devel] [PATCH 1/2] avformat/hls: add AVFMT_NO_BYTE_SEEK flag
After d6ac6650b91, ffplay failed to seek HLS stream with AVSEEK_FLAG_BYTE enabled by default. --- libavformat/hls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 06bc46c23f..a01529 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -2497,7 +2497,7 @@ const AVInputFormat ff_hls_demuxer = { .long_name = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"), .priv_class = &hls_class, .priv_data_size = sizeof(HLSContext), -.flags = AVFMT_NOGENSEARCH | AVFMT_TS_DISCONT, +.flags = AVFMT_NOGENSEARCH | AVFMT_TS_DISCONT | AVFMT_NO_BYTE_SEEK, .flags_internal = FF_FMT_INIT_CLEANUP, .read_probe = hls_probe, .read_header= hls_read_header, -- 2.31.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] ffplay: check AVFMT_NO_BYTE_SEEK flag for seek_by_bytes
--- fftools/ffplay.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 92ad7ce1a6..80678cfbb5 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -2819,7 +2819,9 @@ static int read_thread(void *arg) ic->pb->eof_reached = 0; // FIXME hack, ffplay maybe should not use avio_feof() to test for the end if (seek_by_bytes < 0) -seek_by_bytes = !!(ic->iformat->flags & AVFMT_TS_DISCONT) && strcmp("ogg", ic->iformat->name); +seek_by_bytes = !(ic->iformat->flags & AVFMT_NO_BYTE_SEEK) && +!!(ic->iformat->flags & AVFMT_TS_DISCONT) && +strcmp("ogg", ic->iformat->name); is->max_frame_duration = (ic->iformat->flags & AVFMT_TS_DISCONT) ? 10.0 : 3600.0; -- 2.31.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] tests: Add fate-bsf-dv-error-marker
Signed-off-by: Michael Niedermayer --- tests/Makefile | 1 + tests/fate/dvvideo.mak | 6 ++ tests/ref/fate/bsf-dv-error-marker | 1 + 3 files changed, 8 insertions(+) create mode 100644 tests/fate/dvvideo.mak create mode 100644 tests/ref/fate/bsf-dv-error-marker diff --git a/tests/Makefile b/tests/Makefile index c4c31ae871..9f33394856 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -133,6 +133,7 @@ include $(SRC_PATH)/tests/fate/dfa.mak include $(SRC_PATH)/tests/fate/dnn.mak include $(SRC_PATH)/tests/fate/dnxhd.mak include $(SRC_PATH)/tests/fate/dpcm.mak +include $(SRC_PATH)/tests/fate/dvvideo.mak include $(SRC_PATH)/tests/fate/ea.mak include $(SRC_PATH)/tests/fate/exif.mak include $(SRC_PATH)/tests/fate/ffmpeg.mak diff --git a/tests/fate/dvvideo.mak b/tests/fate/dvvideo.mak new file mode 100644 index 00..3122a24f76 --- /dev/null +++ b/tests/fate/dvvideo.mak @@ -0,0 +1,6 @@ + +fate-bsf-dv-error-marker: CMD = md5 -i $(TARGET_SAMPLES)/dv/dvcprohd_720p50.mov -flags +bitexact -fflags +bitexact -c:v copy -bsf noise=100,dv_error_marker=color=blue -f avi +FATE_DVVIDEO-$(call ALLYES, MOV_DEMUXER DV_ERROR_MARKER_BSF NOISE_BSF AVI_MUXER) += fate-bsf-dv-error-marker + +FATE_SAMPLES_FFMPEG += $(FATE_DVVIDEO-yes) +fate-dvvideo: $(FATE_DVVIDEO-yes) diff --git a/tests/ref/fate/bsf-dv-error-marker b/tests/ref/fate/bsf-dv-error-marker new file mode 100644 index 00..513c9d72a3 --- /dev/null +++ b/tests/ref/fate/bsf-dv-error-marker @@ -0,0 +1 @@ +4e884d3e8045299d0d45ec920fa58a44 -- 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] [PATCH] tests: Add fate-bsf-dv-error-marker
On 3/15/2022 3:30 PM, Michael Niedermayer wrote: Signed-off-by: Michael Niedermayer --- tests/Makefile | 1 + tests/fate/dvvideo.mak | 6 ++ tests/ref/fate/bsf-dv-error-marker | 1 + 3 files changed, 8 insertions(+) create mode 100644 tests/fate/dvvideo.mak create mode 100644 tests/ref/fate/bsf-dv-error-marker diff --git a/tests/Makefile b/tests/Makefile index c4c31ae871..9f33394856 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -133,6 +133,7 @@ include $(SRC_PATH)/tests/fate/dfa.mak include $(SRC_PATH)/tests/fate/dnn.mak include $(SRC_PATH)/tests/fate/dnxhd.mak include $(SRC_PATH)/tests/fate/dpcm.mak +include $(SRC_PATH)/tests/fate/dvvideo.mak include $(SRC_PATH)/tests/fate/ea.mak include $(SRC_PATH)/tests/fate/exif.mak include $(SRC_PATH)/tests/fate/ffmpeg.mak diff --git a/tests/fate/dvvideo.mak b/tests/fate/dvvideo.mak new file mode 100644 index 00..3122a24f76 --- /dev/null +++ b/tests/fate/dvvideo.mak @@ -0,0 +1,6 @@ + +fate-bsf-dv-error-marker: CMD = md5 -i $(TARGET_SAMPLES)/dv/dvcprohd_720p50.mov -flags +bitexact -fflags +bitexact -c:v copy -bsf noise=100,dv_error_marker=color=blue -f avi Add fate-bsf-dv-error-marker: CMP = oneline fate-bsf-dv-error-marker: REF = 4e884d3e8045299d0d45ec920fa58a44 So there's no need for the ref file below. +FATE_DVVIDEO-$(call ALLYES, MOV_DEMUXER DV_ERROR_MARKER_BSF NOISE_BSF AVI_MUXER) += fate-bsf-dv-error-marker + +FATE_SAMPLES_FFMPEG += $(FATE_DVVIDEO-yes) +fate-dvvideo: $(FATE_DVVIDEO-yes) diff --git a/tests/ref/fate/bsf-dv-error-marker b/tests/ref/fate/bsf-dv-error-marker new file mode 100644 index 00..513c9d72a3 --- /dev/null +++ b/tests/ref/fate/bsf-dv-error-marker @@ -0,0 +1 @@ +4e884d3e8045299d0d45ec920fa58a44 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 01/21] avcodec/pngenc: Avoid potentially truncating integers
So use 64bits for max_packet_size instead of size_t which might be 32 bits; this is consistent with ff_alloc_packet(). Also remove a redundant size check (ff_alloc_packet() already checks for that). Signed-off-by: Andreas Rheinhardt --- libavcodec/pngenc.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 3ebcc1e571..64a9f5cc95 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -528,7 +528,7 @@ static int encode_png(AVCodecContext *avctx, AVPacket *pkt, PNGEncContext *s = avctx->priv_data; int ret; int enc_row_size; -size_t max_packet_size; +int64_t max_packet_size; enc_row_size= deflateBound(&s->zstream, (avctx->width * s->bits_per_pixel + 7) >> 3); max_packet_size = @@ -537,8 +537,6 @@ static int encode_png(AVCodecContext *avctx, AVPacket *pkt, enc_row_size + 12 * (((int64_t)enc_row_size + IOBUF_SIZE - 1) / IOBUF_SIZE) // IDAT * ceil(enc_row_size / IOBUF_SIZE) ); -if (max_packet_size > INT_MAX) -return AVERROR(ENOMEM); ret = ff_alloc_packet(avctx, pkt, max_packet_size); if (ret < 0) return ret; @@ -845,7 +843,7 @@ static int encode_apng(AVCodecContext *avctx, AVPacket *pkt, PNGEncContext *s = avctx->priv_data; int ret; int enc_row_size; -size_t max_packet_size; +int64_t max_packet_size; APNGFctlChunk fctl_chunk = {0}; if (pict && s->color_type == PNG_COLOR_TYPE_PALETTE) { -- 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 02/21] avcodec/zlib_wrapper: Add wrappers for zlib inflateInit, inflateEnd
It is not documented to be safe to call inflateEnd() on a z_stream that has never been successfully been initialized by inflateInit(), but just zeroed. It just happens to work and several codecs rely on this (they have FF_CODEC_CAP_INIT_CLEANUP set and even call inflateEnd() when inflateInit() failed or has never been called). To avoid this, other codecs recorded whether their zstream has been initialized successfully or not. This commit adds wrappers for inflateInit() and inflateEnd() that do what these other codecs do; furthermore, they also take care of properly setting up the zstream before inflateInit() and emit an error message in case of error. Signed-off-by: Andreas Rheinhardt --- configure | 2 ++ libavcodec/Makefile | 1 + libavcodec/zlib_wrapper.c | 57 +++ libavcodec/zlib_wrapper.h | 51 +++ 4 files changed, 111 insertions(+) create mode 100644 libavcodec/zlib_wrapper.c create mode 100644 libavcodec/zlib_wrapper.h diff --git a/configure b/configure index 82642deabe..6254dc9dc1 100755 --- a/configure +++ b/configure @@ -2461,6 +2461,7 @@ CONFIG_EXTRA=" idctdsp iirfilter mdct15 +inflate_wrapper intrax8 iso_media ividsp @@ -2722,6 +2723,7 @@ faanidct_select="idctdsp" h264dsp_select="startcode" hevcparse_select="atsc_a53 golomb" frame_thread_encoder_deps="encoders threads" +inflate_wrapper_deps="zlib" intrax8_select="blockdsp idctdsp" iso_media_select="mpeg4audio" mdct_select="fft" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index f36b2e992d..62c8e34963 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -104,6 +104,7 @@ OBJS-$(CONFIG_HUFFYUVENCDSP) += huffyuvencdsp.o OBJS-$(CONFIG_IDCTDSP) += idctdsp.o simple_idct.o jrevdct.o OBJS-$(CONFIG_IIRFILTER) += iirfilter.o OBJS-$(CONFIG_MDCT15) += mdct15.o +OBJS-$(CONFIG_INFLATE_WRAPPER) += zlib_wrapper.o OBJS-$(CONFIG_INTRAX8) += intrax8.o intrax8dsp.o msmpeg4data.o OBJS-$(CONFIG_IVIDSP) += ivi_dsp.o OBJS-$(CONFIG_JNI) += ffjni.o jni.o diff --git a/libavcodec/zlib_wrapper.c b/libavcodec/zlib_wrapper.c new file mode 100644 index 00..b15d5be2b8 --- /dev/null +++ b/libavcodec/zlib_wrapper.c @@ -0,0 +1,57 @@ +/* + * Wrappers for zlib + * Copyright (C) 2022 Andreas Rheinhardt + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/error.h" +#include "libavutil/log.h" +#include "zlib_wrapper.h" + +int ff_inflate_init(FFZStream *z, void *logctx) +{ +z_stream *const zstream = &z->zstream; +int zret; + +z->inited = 0; +zstream->next_in = Z_NULL; +zstream->avail_in = 0; +zstream->zalloc = Z_NULL; +zstream->zfree= Z_NULL; +zstream->opaque = Z_NULL; + +zret = inflateInit(zstream); +if (zret == Z_OK) { +z->inited = 1; +} else { +av_log(logctx, AV_LOG_ERROR, "inflateInit error %d, message: %s\n", + zret, zstream->msg ? zstream->msg : ""); +return AVERROR_EXTERNAL; +} +return 0; +} + +void ff_inflate_end(FFZStream *z) +{ +if (z->inited) { +z->inited = 0; +inflateEnd(&z->zstream); +} +} diff --git a/libavcodec/zlib_wrapper.h b/libavcodec/zlib_wrapper.h new file mode 100644 index 00..0e91713b25 --- /dev/null +++ b/libavcodec/zlib_wrapper.h @@ -0,0 +1,51 @@ +/* + * Wrappers for zlib + * Copyright (C) 2022 Andreas Rheinhardt + * + * 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 + * Fou
[FFmpeg-devel] [PATCH 03/21] avcodec/zmbv: Use ff_inflate_init/end()
Returns better error messages in case of error and deduplicates the inflateInit() code. Signed-off-by: Andreas Rheinhardt --- configure | 2 +- libavcodec/zmbv.c | 38 ++ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/configure b/configure index 6254dc9dc1..c86e70e985 100755 --- a/configure +++ b/configure @@ -2993,7 +2993,7 @@ ylc_decoder_select="bswapdsp" zerocodec_decoder_deps="zlib" zlib_decoder_deps="zlib" zlib_encoder_deps="zlib" -zmbv_decoder_deps="zlib" +zmbv_decoder_select="inflate_wrapper" zmbv_encoder_deps="zlib" # hardware accelerators diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c index 0a5bb40ad5..0bc34c81dd 100644 --- a/libavcodec/zmbv.c +++ b/libavcodec/zmbv.c @@ -32,6 +32,7 @@ #include "libavutil/intreadwrite.h" #include "avcodec.h" #include "internal.h" +#include "zlib_wrapper.h" #include @@ -56,7 +57,6 @@ enum ZmbvFormat { typedef struct ZmbvContext { AVCodecContext *avctx; -int zlib_init_ok; int bpp; int alloc_bpp; unsigned int decomp_size; @@ -71,7 +71,7 @@ typedef struct ZmbvContext { int bw, bh, bx, by; int decomp_len; int got_keyframe; -z_stream zstream; +FFZStream zstream; int (*decode_xor)(struct ZmbvContext *c); } ZmbvContext; @@ -493,7 +493,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac return AVERROR_PATCHWELCOME; } -zret = inflateReset(&c->zstream); +zret = inflateReset(&c->zstream.zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return AVERROR_UNKNOWN; @@ -536,17 +536,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac memcpy(c->decomp_buf, buf, len); c->decomp_len = len; } else { // ZLIB-compressed data -c->zstream.total_in = c->zstream.total_out = 0; -c->zstream.next_in = buf; -c->zstream.avail_in = len; -c->zstream.next_out = c->decomp_buf; -c->zstream.avail_out = c->decomp_size; -zret = inflate(&c->zstream, Z_SYNC_FLUSH); +z_stream *const zstream = &c->zstream.zstream; + +zstream->total_in = zstream->total_out = 0; +zstream->next_in = buf; +zstream->avail_in = len; +zstream->next_out = c->decomp_buf; +zstream->avail_out = c->decomp_size; +zret = inflate(zstream, Z_SYNC_FLUSH); if (zret != Z_OK && zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "inflate error %d\n", zret); return AVERROR_INVALIDDATA; } -c->decomp_len = c->zstream.total_out; +c->decomp_len = zstream->total_out; } if (expected_size > c->decomp_len || (c->flags & ZMBV_KEYFRAME) && expected_size < c->decomp_len) { @@ -603,7 +605,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac static av_cold int decode_init(AVCodecContext *avctx) { ZmbvContext * const c = avctx->priv_data; -int zret; // Zlib return code c->avctx = avctx; @@ -627,17 +628,7 @@ static av_cold int decode_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } -c->zstream.zalloc = Z_NULL; -c->zstream.zfree = Z_NULL; -c->zstream.opaque = Z_NULL; -zret = inflateInit(&c->zstream); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); -return AVERROR_UNKNOWN; -} -c->zlib_init_ok = 1; - -return 0; +return ff_inflate_init(&c->zstream, avctx); } static av_cold int decode_end(AVCodecContext *avctx) @@ -648,8 +639,7 @@ static av_cold int decode_end(AVCodecContext *avctx) av_freep(&c->cur); av_freep(&c->prev); -if (c->zlib_init_ok) -inflateEnd(&c->zstream); +ff_inflate_end(&c->zstream); return 0; } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 04/21] avcodec/zerocodec: Use ff_inflate_init/end()
This fixes the problem of potentially closing a z_stream that has never been successfully initialized. Signed-off-by: Andreas Rheinhardt --- configure | 2 +- libavcodec/zerocodec.c | 21 + 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/configure b/configure index c86e70e985..7c87548359 100755 --- a/configure +++ b/configure @@ -2990,7 +2990,7 @@ wmv3image_decoder_select="wmv3_decoder" xma1_decoder_select="wmapro_decoder" xma2_decoder_select="wmapro_decoder" ylc_decoder_select="bswapdsp" -zerocodec_decoder_deps="zlib" +zerocodec_decoder_select="inflate_wrapper" zlib_decoder_deps="zlib" zlib_encoder_deps="zlib" zmbv_decoder_select="inflate_wrapper" diff --git a/libavcodec/zerocodec.c b/libavcodec/zerocodec.c index 3bd04567a1..86cdf96f5a 100644 --- a/libavcodec/zerocodec.c +++ b/libavcodec/zerocodec.c @@ -20,11 +20,12 @@ #include "avcodec.h" #include "internal.h" +#include "zlib_wrapper.h" #include "libavutil/common.h" typedef struct ZeroCodecContext { AVFrame *previous_frame; -z_stream zstream; +FFZStream zstream; } ZeroCodecContext; static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, @@ -33,7 +34,7 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data, ZeroCodecContext *zc = avctx->priv_data; AVFrame *pic = data; AVFrame *prev_pic= zc->previous_frame; -z_stream *zstream= &zc->zstream; +z_stream *const zstream = &zc->zstream.zstream; uint8_t *prev= prev_pic->data[0]; uint8_t *dst; int i, j, zret, ret; @@ -106,7 +107,7 @@ static av_cold int zerocodec_decode_close(AVCodecContext *avctx) av_frame_free(&zc->previous_frame); -inflateEnd(&zc->zstream); +ff_inflate_end(&zc->zstream); return 0; } @@ -114,27 +115,15 @@ static av_cold int zerocodec_decode_close(AVCodecContext *avctx) static av_cold int zerocodec_decode_init(AVCodecContext *avctx) { ZeroCodecContext *zc = avctx->priv_data; -z_stream *zstream= &zc->zstream; -int zret; avctx->pix_fmt = AV_PIX_FMT_UYVY422; avctx->bits_per_raw_sample = 8; -zstream->zalloc = Z_NULL; -zstream->zfree = Z_NULL; -zstream->opaque = Z_NULL; - -zret = inflateInit(zstream); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Could not initialize inflate: %d.\n", zret); -return AVERROR(ENOMEM); -} - zc->previous_frame = av_frame_alloc(); if (!zc->previous_frame) return AVERROR(ENOMEM); -return 0; +return ff_inflate_init(&zc->zstream, avctx); } static void zerocodec_decode_flush(AVCodecContext *avctx) -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 06/21] avcodec/tscc: Use ff_inflate_init/end()
Returns better error messages in case of error and deduplicates the inflateInit() code. Signed-off-by: Andreas Rheinhardt --- configure | 2 +- libavcodec/tscc.c | 36 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/configure b/configure index fdc3f3d28c..ad5b5f1727 100755 --- a/configure +++ b/configure @@ -2953,7 +2953,7 @@ truehd_decoder_select="mlp_parser" truehd_encoder_select="lpc audio_frame_queue" truemotion2_decoder_select="bswapdsp" truespeech_decoder_select="bswapdsp" -tscc_decoder_deps="zlib" +tscc_decoder_select="inflate_wrapper" twinvq_decoder_select="mdct lsp sinewin" txd_decoder_select="texturedsp" utvideo_decoder_select="bswapdsp llviddsp" diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c index 841f0c0d14..cba4d5bdc9 100644 --- a/libavcodec/tscc.c +++ b/libavcodec/tscc.c @@ -41,6 +41,7 @@ #include "decode.h" #include "internal.h" #include "msrledec.h" +#include "zlib_wrapper.h" #include @@ -57,8 +58,7 @@ typedef struct TsccContext { unsigned char* decomp_buf; GetByteContext gb; int height; -int zlib_init_ok; -z_stream zstream; +FFZStream zstream; uint32_t pal[256]; } CamtasiaContext; @@ -69,6 +69,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; CamtasiaContext * const c = avctx->priv_data; +z_stream *const zstream = &c->zstream.zstream; AVFrame *frame = c->frame; int ret; int palette_has_changed = 0; @@ -77,16 +78,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, palette_has_changed = ff_copy_palette(c->pal, avpkt, avctx); } -ret = inflateReset(&c->zstream); +ret = inflateReset(zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); return AVERROR_UNKNOWN; } -c->zstream.next_in = buf; -c->zstream.avail_in = buf_size; -c->zstream.next_out = c->decomp_buf; -c->zstream.avail_out = c->decomp_size; -ret = inflate(&c->zstream, Z_FINISH); +zstream->next_in = buf; +zstream->avail_in = buf_size; +zstream->next_out = c->decomp_buf; +zstream->avail_out = c->decomp_size; +ret = inflate(zstream, Z_FINISH); // Z_DATA_ERROR means empty picture if (ret == Z_DATA_ERROR && !palette_has_changed) { return buf_size; @@ -102,7 +103,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (ret != Z_DATA_ERROR) { bytestream2_init(&c->gb, c->decomp_buf, - c->decomp_size - c->zstream.avail_out); + c->decomp_size - zstream->avail_out); ff_msrle_decode(avctx, frame, c->bpp, &c->gb); } @@ -123,7 +124,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, static av_cold int decode_init(AVCodecContext *avctx) { CamtasiaContext * const c = avctx->priv_data; -int zret; // Zlib return code c->avctx = avctx; @@ -151,21 +151,11 @@ static av_cold int decode_init(AVCodecContext *avctx) } } -c->zstream.zalloc = Z_NULL; -c->zstream.zfree = Z_NULL; -c->zstream.opaque = Z_NULL; -zret = inflateInit(&c->zstream); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); -return AVERROR_UNKNOWN; -} -c->zlib_init_ok = 1; - c->frame = av_frame_alloc(); if (!c->frame) return AVERROR(ENOMEM); -return 0; +return ff_inflate_init(&c->zstream, avctx); } static av_cold int decode_end(AVCodecContext *avctx) @@ -174,9 +164,7 @@ static av_cold int decode_end(AVCodecContext *avctx) av_freep(&c->decomp_buf); av_frame_free(&c->frame); - -if (c->zlib_init_ok) -inflateEnd(&c->zstream); +ff_inflate_end(&c->zstream); return 0; } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 07/21] avcodec/rasc: Use ff_inflate_init/end()
This fixes the problem of potentially closing a z_stream that has never been successfully initialized. Signed-off-by: Andreas Rheinhardt --- configure | 2 +- libavcodec/rasc.c | 49 --- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/configure b/configure index ad5b5f1727..464ddb019c 100755 --- a/configure +++ b/configure @@ -2914,7 +2914,7 @@ qdm2_decoder_select="mdct rdft mpegaudiodsp" ra_144_decoder_select="audiodsp" ra_144_encoder_select="audio_frame_queue lpc audiodsp" ralf_decoder_select="golomb" -rasc_decoder_deps="zlib" +rasc_decoder_select="inflate_wrapper" rawvideo_decoder_select="bswapdsp" rscc_decoder_deps="zlib" rtjpeg_decoder_select="me_cmp" diff --git a/libavcodec/rasc.c b/libavcodec/rasc.c index b328e219bb..9b748be9ae 100644 --- a/libavcodec/rasc.c +++ b/libavcodec/rasc.c @@ -30,6 +30,7 @@ #include "avcodec.h" #include "bytestream.h" #include "internal.h" +#include "zlib_wrapper.h" #include @@ -58,10 +59,10 @@ typedef struct RASCContext { unsignedcursor_y; int stride; int bpp; -z_streamzstream; AVFrame*frame; AVFrame*frame1; AVFrame*frame2; +FFZStream zstream; } RASCContext; static void clear_plane(AVCodecContext *avctx, AVFrame *frame) @@ -174,10 +175,11 @@ static int decode_zlib(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size, unsigned uncompressed_size) { RASCContext *s = avctx->priv_data; +z_stream *const zstream = &s->zstream.zstream; GetByteContext *gb = &s->gb; int zret; -zret = inflateReset(&s->zstream); +zret = inflateReset(zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return AVERROR_EXTERNAL; @@ -187,13 +189,13 @@ static int decode_zlib(AVCodecContext *avctx, const AVPacket *avpkt, if (!s->delta) return AVERROR(ENOMEM); -s->zstream.next_in = avpkt->data + bytestream2_tell(gb); -s->zstream.avail_in = FFMIN(size, bytestream2_get_bytes_left(gb)); +zstream->next_in = avpkt->data + bytestream2_tell(gb); +zstream->avail_in = FFMIN(size, bytestream2_get_bytes_left(gb)); -s->zstream.next_out = s->delta; -s->zstream.avail_out = s->delta_size; +zstream->next_out = s->delta; +zstream->avail_out = s->delta_size; -zret = inflate(&s->zstream, Z_FINISH); +zret = inflate(zstream, Z_FINISH); if (zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate failed with return code: %d.\n", zret); @@ -473,6 +475,7 @@ static int decode_kfrm(AVCodecContext *avctx, const AVPacket *avpkt, unsigned size) { RASCContext *s = avctx->priv_data; +z_stream *const zstream = &s->zstream.zstream; GetByteContext *gb = &s->gb; uint8_t *dst; unsigned pos; @@ -488,21 +491,21 @@ static int decode_kfrm(AVCodecContext *avctx, if (!s->frame2->data[0]) return AVERROR_INVALIDDATA; -zret = inflateReset(&s->zstream); +zret = inflateReset(zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return AVERROR_EXTERNAL; } -s->zstream.next_in = avpkt->data + bytestream2_tell(gb); -s->zstream.avail_in = bytestream2_get_bytes_left(gb); +zstream->next_in = avpkt->data + bytestream2_tell(gb); +zstream->avail_in = bytestream2_get_bytes_left(gb); dst = s->frame2->data[0] + (avctx->height - 1) * s->frame2->linesize[0]; for (int i = 0; i < avctx->height; i++) { -s->zstream.next_out = dst; -s->zstream.avail_out = s->stride; +zstream->next_out = dst; +zstream->avail_out = s->stride; -zret = inflate(&s->zstream, Z_SYNC_FLUSH); +zret = inflate(zstream, Z_SYNC_FLUSH); if (zret != Z_OK && zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate failed with return code: %d.\n", zret); @@ -514,10 +517,10 @@ static int decode_kfrm(AVCodecContext *avctx, dst = s->frame1->data[0] + (avctx->height - 1) * s->frame1->linesize[0]; for (int i = 0; i < avctx->height; i++) { -s->zstream.next_out = dst; -s->zstream.avail_out = s->stride; +zstream->next_out = dst; +zstream->avail_out = s->stride; -zret = inflate(&s->zstream, Z_SYNC_FLUSH); +zret = inflate(zstream, Z_SYNC_FLUSH); if (zret != Z_OK && zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate failed with return code: %d.\n", zret); @@ -751,23 +754,13 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_init(AVCodecContext *avctx) { RASCContext *s = avctx->priv_data; -int zret; - -s->zstream.zalloc = Z_NULL; -s->zstream.zfree = Z_NULL; -s->zstream.opaque
[FFmpeg-devel] [PATCH 08/21] avcodec/mwsc: Use ff_inflate_init/end()
This fixes the problem of potentially closing a z_stream that has never been successfully initialized. Signed-off-by: Andreas Rheinhardt --- configure | 2 +- libavcodec/mwsc.c | 32 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/configure b/configure index 464ddb019c..dd7adbfac4 100755 --- a/configure +++ b/configure @@ -2894,7 +2894,7 @@ mts2_decoder_select="jpegtables mss34dsp" mv30_decoder_select="aandcttables blockdsp" mvha_decoder_deps="zlib" mvha_decoder_select="llviddsp" -mwsc_decoder_deps="zlib" +mwsc_decoder_select="inflate_wrapper" mxpeg_decoder_select="mjpeg_decoder" nellymoser_decoder_select="mdct sinewin" nellymoser_encoder_select="audio_frame_queue mdct sinewin" diff --git a/libavcodec/mwsc.c b/libavcodec/mwsc.c index b62db67ff5..0ae99f6655 100644 --- a/libavcodec/mwsc.c +++ b/libavcodec/mwsc.c @@ -27,14 +27,15 @@ #include "avcodec.h" #include "bytestream.h" #include "internal.h" +#include "zlib_wrapper.h" #include typedef struct MWSCContext { unsigned int decomp_size; uint8_t *decomp_buf; -z_stream zstream; AVFrame *prev_frame; +FFZStream zstream; } MWSCContext; static int rle_uncompress(GetByteContext *gb, PutByteContext *pb, GetByteContext *gbp, @@ -90,6 +91,7 @@ static int decode_frame(AVCodecContext *avctx, AVPacket *avpkt) { MWSCContext *s = avctx->priv_data; +z_stream *const zstream = &s->zstream.zstream; AVFrame *frame = data; uint8_t *buf = avpkt->data; int buf_size = avpkt->size; @@ -98,16 +100,16 @@ static int decode_frame(AVCodecContext *avctx, PutByteContext pb; int ret; -ret = inflateReset(&s->zstream); +ret = inflateReset(zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); return AVERROR_EXTERNAL; } -s->zstream.next_in = buf; -s->zstream.avail_in = buf_size; -s->zstream.next_out = s->decomp_buf; -s->zstream.avail_out = s->decomp_size; -ret = inflate(&s->zstream, Z_FINISH); +zstream->next_in = buf; +zstream->avail_in = buf_size; +zstream->next_out = s->decomp_buf; +zstream->avail_out = s->decomp_size; +ret = inflate(zstream, Z_FINISH); if (ret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", ret); return AVERROR_EXTERNAL; @@ -116,7 +118,7 @@ static int decode_frame(AVCodecContext *avctx, if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) return ret; -bytestream2_init(&gb, s->decomp_buf, s->zstream.total_out); +bytestream2_init(&gb, s->decomp_buf, zstream->total_out); bytestream2_init(&gbp, s->prev_frame->data[0], avctx->height * s->prev_frame->linesize[0]); bytestream2_init_writer(&pb, frame->data[0], avctx->height * frame->linesize[0]); @@ -138,7 +140,6 @@ static av_cold int decode_init(AVCodecContext *avctx) { MWSCContext *s = avctx->priv_data; int64_t size; -int zret; avctx->pix_fmt = AV_PIX_FMT_BGR24; @@ -149,20 +150,11 @@ static av_cold int decode_init(AVCodecContext *avctx) if (!(s->decomp_buf = av_malloc(s->decomp_size))) return AVERROR(ENOMEM); -s->zstream.zalloc = Z_NULL; -s->zstream.zfree = Z_NULL; -s->zstream.opaque = Z_NULL; -zret = inflateInit(&s->zstream); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); -return AVERROR_EXTERNAL; -} - s->prev_frame = av_frame_alloc(); if (!s->prev_frame) return AVERROR(ENOMEM); -return 0; +return ff_inflate_init(&s->zstream, avctx); } static av_cold int decode_close(AVCodecContext *avctx) @@ -172,7 +164,7 @@ static av_cold int decode_close(AVCodecContext *avctx) av_frame_free(&s->prev_frame); av_freep(&s->decomp_buf); s->decomp_size = 0; -inflateEnd(&s->zstream); +ff_inflate_end(&s->zstream); return 0; } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 09/21] avcodec/mvha: Use ff_inflate_init/end()
This fixes the problem of potentially closing a z_stream that has never been successfully initialized. Signed-off-by: Andreas Rheinhardt --- configure | 3 +-- libavcodec/mvha.c | 30 +++--- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/configure b/configure index dd7adbfac4..46b02275ad 100755 --- a/configure +++ b/configure @@ -2892,8 +2892,7 @@ msmpeg4v3_encoder_select="h263_encoder" mss2_decoder_select="mpegvideodec qpeldsp vc1_decoder" mts2_decoder_select="jpegtables mss34dsp" mv30_decoder_select="aandcttables blockdsp" -mvha_decoder_deps="zlib" -mvha_decoder_select="llviddsp" +mvha_decoder_select="inflate_wrapper llviddsp" mwsc_decoder_select="inflate_wrapper" mxpeg_decoder_select="mjpeg_decoder" nellymoser_decoder_select="mdct sinewin" diff --git a/libavcodec/mvha.c b/libavcodec/mvha.c index 4048e4625c..05ddcfeb8f 100644 --- a/libavcodec/mvha.c +++ b/libavcodec/mvha.c @@ -32,6 +32,7 @@ #include "get_bits.h" #include "internal.h" #include "lossless_videodsp.h" +#include "zlib_wrapper.h" #include @@ -43,7 +44,7 @@ typedef struct MVHAContext { uint32_t prob[256]; VLC vlc; -z_stream zstream; +FFZStream zstream; LLVidDSPContext llviddsp; } MVHAContext; @@ -168,21 +169,22 @@ static int decode_frame(AVCodecContext *avctx, return ret; if (type == MKTAG('L','Z','Y','V')) { -ret = inflateReset(&s->zstream); +z_stream *const zstream = &s->zstream.zstream; +ret = inflateReset(zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); return AVERROR_EXTERNAL; } -s->zstream.next_in = avpkt->data + 8; -s->zstream.avail_in = avpkt->size - 8; +zstream->next_in = avpkt->data + 8; +zstream->avail_in = avpkt->size - 8; for (int p = 0; p < 3; p++) { for (int y = 0; y < avctx->height; y++) { -s->zstream.next_out = frame->data[p] + (avctx->height - y - 1) * frame->linesize[p]; -s->zstream.avail_out = avctx->width >> (p > 0); +zstream->next_out = frame->data[p] + (avctx->height - y - 1) * frame->linesize[p]; +zstream->avail_out = avctx->width >> (p > 0); -ret = inflate(&s->zstream, Z_SYNC_FLUSH); +ret = inflate(zstream, Z_SYNC_FLUSH); if (ret != Z_OK && ret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", ret); return AVERROR_EXTERNAL; @@ -279,29 +281,19 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_init(AVCodecContext *avctx) { MVHAContext *s = avctx->priv_data; -int zret; avctx->pix_fmt = AV_PIX_FMT_YUV422P; -s->zstream.zalloc = Z_NULL; -s->zstream.zfree = Z_NULL; -s->zstream.opaque = Z_NULL; -zret = inflateInit(&s->zstream); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); -return AVERROR_EXTERNAL; -} - ff_llviddsp_init(&s->llviddsp); -return 0; +return ff_inflate_init(&s->zstream, avctx); } static av_cold int decode_close(AVCodecContext *avctx) { MVHAContext *s = avctx->priv_data; -inflateEnd(&s->zstream); +ff_inflate_end(&s->zstream); ff_free_vlc(&s->vlc); return 0; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 10/21] avcodec/mscc: Use ff_inflate_init/end()
This fixes the problem of potentially closing a z_stream that has never been successfully initialized. Signed-off-by: Andreas Rheinhardt --- configure | 4 ++-- libavcodec/mscc.c | 33 + 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/configure b/configure index 46b02275ad..c79908c1bd 100755 --- a/configure +++ b/configure @@ -2883,7 +2883,7 @@ mpeg2video_encoder_select="mpegvideoenc h263dsp" mpeg4_decoder_select="h263_decoder mpeg4video_parser" mpeg4_encoder_select="h263_encoder" msa1_decoder_select="mss34dsp" -mscc_decoder_deps="zlib" +mscc_decoder_select="inflate_wrapper" msmpeg4v1_decoder_select="h263_decoder" msmpeg4v2_decoder_select="h263_decoder" msmpeg4v2_encoder_select="h263_encoder" @@ -2935,7 +2935,7 @@ sonic_ls_encoder_select="golomb rangecoder" sp5x_decoder_select="mjpeg_decoder" speedhq_decoder_select="mpegvideo" speedhq_encoder_select="mpegvideoenc" -srgc_decoder_deps="zlib" +srgc_decoder_select="inflate_wrapper" svq1_decoder_select="hpeldsp" svq1_encoder_select="hpeldsp me_cmp mpegvideoenc" svq3_decoder_select="golomb h264dsp h264parse h264pred hpeldsp tpeldsp videodsp" diff --git a/libavcodec/mscc.c b/libavcodec/mscc.c index d9a6de094a..19cfce796e 100644 --- a/libavcodec/mscc.c +++ b/libavcodec/mscc.c @@ -27,6 +27,7 @@ #include "avcodec.h" #include "bytestream.h" #include "internal.h" +#include "zlib_wrapper.h" #include @@ -36,7 +37,7 @@ typedef struct MSCCContext { uint8_t *decomp_buf; unsigned int uncomp_size; uint8_t *uncomp_buf; -z_stream zstream; +FFZStream zstream; uint32_t pal[256]; } MSCCContext; @@ -132,6 +133,7 @@ static int decode_frame(AVCodecContext *avctx, AVPacket *avpkt) { MSCCContext *s = avctx->priv_data; +z_stream *const zstream = &s->zstream.zstream; AVFrame *frame = data; uint8_t *buf = avpkt->data; int buf_size = avpkt->size; @@ -166,22 +168,22 @@ static int decode_frame(AVCodecContext *avctx, memcpy(frame->data[1], s->pal, AVPALETTE_SIZE); } -ret = inflateReset(&s->zstream); +ret = inflateReset(zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); return AVERROR_UNKNOWN; } -s->zstream.next_in = buf; -s->zstream.avail_in = buf_size; -s->zstream.next_out = s->decomp_buf; -s->zstream.avail_out = s->decomp_size; -ret = inflate(&s->zstream, Z_FINISH); +zstream->next_in = buf; +zstream->avail_in = buf_size; +zstream->next_out = s->decomp_buf; +zstream->avail_out = s->decomp_size; +ret = inflate(zstream, Z_FINISH); if (ret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", ret); return AVERROR_UNKNOWN; } -bytestream2_init(&gb, s->decomp_buf, s->zstream.total_out); +bytestream2_init(&gb, s->decomp_buf, zstream->total_out); bytestream2_init_writer(&pb, s->uncomp_buf, s->uncomp_size); ret = rle_uncompress(avctx, &gb, &pb); @@ -204,7 +206,7 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_init(AVCodecContext *avctx) { MSCCContext *s = avctx->priv_data; -int stride, zret; +int stride; switch (avctx->bits_per_coded_sample) { case 8: avctx->pix_fmt = AV_PIX_FMT_PAL8; break; @@ -227,16 +229,7 @@ static av_cold int decode_init(AVCodecContext *avctx) if (!(s->uncomp_buf = av_malloc(s->uncomp_size))) return AVERROR(ENOMEM); -s->zstream.zalloc = Z_NULL; -s->zstream.zfree = Z_NULL; -s->zstream.opaque = Z_NULL; -zret = inflateInit(&s->zstream); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); -return AVERROR_UNKNOWN; -} - -return 0; +return ff_inflate_init(&s->zstream, avctx); } static av_cold int decode_close(AVCodecContext *avctx) @@ -247,7 +240,7 @@ static av_cold int decode_close(AVCodecContext *avctx) s->decomp_size = 0; av_freep(&s->uncomp_buf); s->uncomp_size = 0; -inflateEnd(&s->zstream); +ff_inflate_end(&s->zstream); return 0; } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 11/21] avcodec/lcldec: Use ff_inflate_init/end(), cleanup generically
Returns better error messages in case of error and deduplicates the inflateInit() code and also allows to cleanup generically in case of errors as it is save to call ff_inflate_end() if ff_inflate_init() has not been called successfully. Signed-off-by: Andreas Rheinhardt --- configure | 2 +- libavcodec/lcldec.c | 43 +-- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/configure b/configure index c79908c1bd..c56b7ba85b 100755 --- a/configure +++ b/configure @@ -2990,7 +2990,7 @@ xma1_decoder_select="wmapro_decoder" xma2_decoder_select="wmapro_decoder" ylc_decoder_select="bswapdsp" zerocodec_decoder_select="inflate_wrapper" -zlib_decoder_deps="zlib" +zlib_decoder_select="inflate_wrapper" zlib_encoder_deps="zlib" zmbv_decoder_select="inflate_wrapper" zmbv_encoder_deps="zlib" diff --git a/libavcodec/lcldec.c b/libavcodec/lcldec.c index f3b7a8ac1b..8a66065800 100644 --- a/libavcodec/lcldec.c +++ b/libavcodec/lcldec.c @@ -49,6 +49,7 @@ #include "thread.h" #if CONFIG_ZLIB_DECODER +#include "zlib_wrapper.h" #include #endif @@ -64,7 +65,7 @@ typedef struct LclDecContext { // Decompression buffer unsigned char* decomp_buf; #if CONFIG_ZLIB_DECODER -z_stream zstream; +FFZStream zstream; #endif } LclDecContext; @@ -131,26 +132,27 @@ static unsigned int mszh_decomp(const unsigned char * srcptr, int srclen, unsign static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, int offset, int expected) { LclDecContext *c = avctx->priv_data; -int zret = inflateReset(&c->zstream); +z_stream *const zstream = &c->zstream.zstream; +int zret = inflateReset(zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return AVERROR_UNKNOWN; } -c->zstream.next_in = src; -c->zstream.avail_in = src_len; -c->zstream.next_out = c->decomp_buf + offset; -c->zstream.avail_out = c->decomp_size - offset; -zret = inflate(&c->zstream, Z_FINISH); +zstream->next_in = src; +zstream->avail_in = src_len; +zstream->next_out = c->decomp_buf + offset; +zstream->avail_out = c->decomp_size - offset; +zret = inflate(zstream, Z_FINISH); if (zret != Z_OK && zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); return AVERROR_UNKNOWN; } -if (expected != (unsigned int)c->zstream.total_out) { +if (expected != (unsigned int)zstream->total_out) { av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", - expected, c->zstream.total_out); + expected, zstream->total_out); return AVERROR_UNKNOWN; } -return c->zstream.total_out; +return zstream->total_out; } #endif @@ -606,18 +608,8 @@ static av_cold int decode_init(AVCodecContext *avctx) /* If needed init zlib */ #if CONFIG_ZLIB_DECODER -if (avctx->codec_id == AV_CODEC_ID_ZLIB) { -int zret; -c->zstream.zalloc = Z_NULL; -c->zstream.zfree = Z_NULL; -c->zstream.opaque = Z_NULL; -zret = inflateInit(&c->zstream); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); -av_freep(&c->decomp_buf); -return AVERROR_UNKNOWN; -} -} +if (avctx->codec_id == AV_CODEC_ID_ZLIB) +return ff_inflate_init(&c->zstream, avctx); #endif return 0; @@ -629,8 +621,7 @@ static av_cold int decode_end(AVCodecContext *avctx) av_freep(&c->decomp_buf); #if CONFIG_ZLIB_DECODER -if (avctx->codec_id == AV_CODEC_ID_ZLIB) -inflateEnd(&c->zstream); +ff_inflate_end(&c->zstream); #endif return 0; @@ -647,7 +638,7 @@ const AVCodec ff_mszh_decoder = { .close = decode_end, .decode = decode_frame, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; #endif @@ -662,6 +653,6 @@ const AVCodec ff_zlib_decoder = { .close = decode_end, .decode = decode_frame, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, -.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; #endif -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 05/21] avcodec/wcmv: Use ff_inflate_init/end()
This fixes the problem of potentially closing a z_stream that has never been successfully initialized. Signed-off-by: Andreas Rheinhardt --- configure | 2 +- libavcodec/wcmv.c | 46 +++--- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/configure b/configure index 7c87548359..fdc3f3d28c 100755 --- a/configure +++ b/configure @@ -2972,7 +2972,7 @@ vp6f_decoder_select="vp6_decoder" vp7_decoder_select="h264pred videodsp vp8dsp" vp8_decoder_select="h264pred videodsp vp8dsp" vp9_decoder_select="videodsp vp9_parser vp9_superframe_split_bsf" -wcmv_decoder_deps="zlib" +wcmv_decoder_select="inflate_wrapper" webp_decoder_select="vp8_decoder exif" wmalossless_decoder_select="llauddsp" wmapro_decoder_select="mdct sinewin wma_freqs" diff --git a/libavcodec/wcmv.c b/libavcodec/wcmv.c index 04c597e767..d98d2d52cf 100644 --- a/libavcodec/wcmv.c +++ b/libavcodec/wcmv.c @@ -29,12 +29,13 @@ #include "avcodec.h" #include "bytestream.h" #include "internal.h" +#include "zlib_wrapper.h" #include typedef struct WCMVContext { int bpp; -z_streamzstream; +FFZStream zstream; AVFrame*prev_frame; uint8_t block_data[65536*8]; } WCMVContext; @@ -44,12 +45,13 @@ static int decode_frame(AVCodecContext *avctx, AVPacket *avpkt) { WCMVContext *s = avctx->priv_data; +z_stream *const zstream = &s->zstream.zstream; AVFrame *frame = data; int skip, blocks, zret, ret, intra = 0, flags = 0, bpp = s->bpp; GetByteContext gb; uint8_t *dst; -ret = inflateReset(&s->zstream); +ret = inflateReset(zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); return AVERROR_EXTERNAL; @@ -78,19 +80,19 @@ static int decode_frame(AVCodecContext *avctx, if (size > avpkt->size - skip) return AVERROR_INVALIDDATA; -s->zstream.next_in = avpkt->data + skip; -s->zstream.avail_in = size; -s->zstream.next_out = s->block_data; -s->zstream.avail_out = sizeof(s->block_data); +zstream->next_in = avpkt->data + skip; +zstream->avail_in = size; +zstream->next_out = s->block_data; +zstream->avail_out = sizeof(s->block_data); -zret = inflate(&s->zstream, Z_FINISH); +zret = inflate(zstream, Z_FINISH); if (zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate failed with return code: %d.\n", zret); return AVERROR_INVALIDDATA; } -ret = inflateReset(&s->zstream); +ret = inflateReset(zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); return AVERROR_EXTERNAL; @@ -119,8 +121,8 @@ static int decode_frame(AVCodecContext *avctx, skip = bytestream2_tell(&gb); -s->zstream.next_in = avpkt->data + skip; -s->zstream.avail_in = avpkt->size - skip; +zstream->next_in = avpkt->data + skip; +zstream->avail_in = avpkt->size - skip; bytestream2_init(&gb, s->block_data, blocks * 8); } else if (blocks) { @@ -148,8 +150,8 @@ static int decode_frame(AVCodecContext *avctx, skip = bytestream2_tell(&gb); -s->zstream.next_in = avpkt->data + skip; -s->zstream.avail_in = avpkt->size - skip; +zstream->next_in = avpkt->data + skip; +zstream->avail_in = avpkt->size - skip; bytestream2_seek(&gb, 2, SEEK_SET); } @@ -182,10 +184,10 @@ static int decode_frame(AVCodecContext *avctx, dst = s->prev_frame->data[0] + (avctx->height - y - 1) * s->prev_frame->linesize[0] + x * bpp; for (int i = 0; i < h; i++) { -s->zstream.next_out = dst; -s->zstream.avail_out = w * bpp; +zstream->next_out = dst; +zstream->avail_out = w * bpp; -zret = inflate(&s->zstream, Z_SYNC_FLUSH); +zret = inflate(zstream, Z_SYNC_FLUSH); if (zret != Z_OK && zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate failed with return code: %d.\n", zret); @@ -210,7 +212,6 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_init(AVCodecContext *avctx) { WCMVContext *s = avctx->priv_data; -int zret; switch (avctx->bits_per_coded_sample) { case 16: avctx->pix_fmt = AV_PIX_FMT_RGB565LE; break; @@ -223,20 +224,11 @@ static av_cold int decode_init(AVCodecContext *avctx) s->bpp = avctx->bits_per_coded_sample >> 3; -s->zstream.zalloc = Z_NULL; -s->zstream.zfree = Z_NULL; -s->zstream.opaque = Z_NULL; -zret = inflateInit(&s->zstream); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); -return AVERROR_EXTERNAL; -} - s->prev_frame = av_frame_a
[FFmpeg-devel] [PATCH 12/21] avcodec/flashsv: Use ff_inflate_init/end()
This fixes the problem of potentially closing a z_stream that has never been successfully initialized. Signed-off-by: Andreas Rheinhardt --- configure| 4 +-- libavcodec/flashsv.c | 73 +--- 2 files changed, 36 insertions(+), 41 deletions(-) diff --git a/configure b/configure index c56b7ba85b..e3d2f590cd 100755 --- a/configure +++ b/configure @@ -2810,9 +2810,9 @@ ffvhuff_encoder_select="huffyuv_encoder" fic_decoder_select="golomb" flac_decoder_select="flacdsp" flac_encoder_select="bswapdsp flacdsp lpc" -flashsv2_decoder_deps="zlib" +flashsv2_decoder_select="inflate_wrapper" flashsv2_encoder_deps="zlib" -flashsv_decoder_deps="zlib" +flashsv_decoder_select="inflate_wrapper" flashsv_encoder_deps="zlib" flv_decoder_select="h263_decoder" flv_encoder_select="h263_encoder" diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c index e284439972..eccf568f85 100644 --- a/libavcodec/flashsv.c +++ b/libavcodec/flashsv.c @@ -42,6 +42,7 @@ #include "bytestream.h" #include "get_bits.h" #include "internal.h" +#include "zlib_wrapper.h" typedef struct BlockInfo { const uint8_t *pos; @@ -55,7 +56,6 @@ typedef struct FlashSVContext { int block_width, block_height; uint8_t*tmpblock; int block_size; -z_streamzstream; int ver; const uint32_t *pal; int is_keyframe; @@ -66,6 +66,7 @@ typedef struct FlashSVContext { int color_depth; int zlibprime_curr, zlibprime_prev; int diff_start, diff_height; +FFZStream zstream; uint8_t tmp[UINT16_MAX]; } FlashSVContext; @@ -104,7 +105,8 @@ static int decode_hybrid(const uint8_t *sptr, const uint8_t *sptr_end, uint8_t * static av_cold int flashsv_decode_end(AVCodecContext *avctx) { FlashSVContext *s = avctx->priv_data; -inflateEnd(&s->zstream); + +ff_inflate_end(&s->zstream); /* release the frame if needed */ av_frame_free(&s->frame); @@ -117,17 +119,8 @@ static av_cold int flashsv_decode_end(AVCodecContext *avctx) static av_cold int flashsv_decode_init(AVCodecContext *avctx) { FlashSVContext *s = avctx->priv_data; -int zret; // Zlib return code s->avctx = avctx; -s->zstream.zalloc = Z_NULL; -s->zstream.zfree = Z_NULL; -s->zstream.opaque = Z_NULL; -zret = inflateInit(&s->zstream); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); -return AVERROR_EXTERNAL; -} avctx->pix_fmt = AV_PIX_FMT_BGR24; s->frame = av_frame_alloc(); @@ -135,27 +128,28 @@ static av_cold int flashsv_decode_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } -return 0; +return ff_inflate_init(&s->zstream, avctx); } static int flashsv2_prime(FlashSVContext *s, const uint8_t *src, int size) { int zret; // Zlib return code static const uint8_t zlib_header[] = { 0x78, 0x01 }; +z_stream *const zstream = &s->zstream.zstream; uint8_t *data = s->tmpblock; unsigned remaining; if (!src) return AVERROR_INVALIDDATA; -s->zstream.next_in = src; -s->zstream.avail_in = size; -s->zstream.next_out = data; -s->zstream.avail_out = s->block_size * 3; -inflate(&s->zstream, Z_SYNC_FLUSH); -remaining = s->block_size * 3 - s->zstream.avail_out; +zstream->next_in = src; +zstream->avail_in = size; +zstream->next_out = data; +zstream->avail_out = s->block_size * 3; +inflate(zstream, Z_SYNC_FLUSH); +remaining = s->block_size * 3 - zstream->avail_out; -if ((zret = inflateReset(&s->zstream)) != Z_OK) { +if ((zret = inflateReset(zstream)) != Z_OK) { av_log(s->avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return AVERROR_UNKNOWN; } @@ -166,9 +160,9 @@ static int flashsv2_prime(FlashSVContext *s, const uint8_t *src, int size) * the adler32 checksum is correctly initialized). * This is accomplished by synthetizing blocks of uncompressed data * out of the output from above. See section 3.2.4 of RFC 1951. */ -s->zstream.next_in = zlib_header; -s->zstream.avail_in = sizeof(zlib_header); -inflate(&s->zstream, Z_SYNC_FLUSH); +zstream->next_in = zlib_header; +zstream->avail_in = sizeof(zlib_header); +inflate(zstream, Z_SYNC_FLUSH); while (remaining > 0) { unsigned block_size = FFMIN(UINT16_MAX, remaining); uint8_t header[5]; @@ -178,16 +172,16 @@ static int flashsv2_prime(FlashSVContext *s, const uint8_t *src, int size) AV_WL16(header + 1, block_size); /* Block size (one's complement) */ AV_WL16(header + 3, block_size ^ 0x); -s->zstream.next_in = header; -s->zstream.avail_in = sizeof(header); -s->zstream.next_out = s->tmp; -s->zstream.avail_out = sizeof(s->tmp); -zr
[FFmpeg-devel] [PATCH 13/21] avcodec/zlib_wrapper: Use our allocation, freeing functions
Signed-off-by: Andreas Rheinhardt --- libavcodec/zlib_wrapper.c | 15 +-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libavcodec/zlib_wrapper.c b/libavcodec/zlib_wrapper.c index b15d5be2b8..5b93c2c74f 100644 --- a/libavcodec/zlib_wrapper.c +++ b/libavcodec/zlib_wrapper.c @@ -23,8 +23,19 @@ #include "libavutil/error.h" #include "libavutil/log.h" +#include "libavutil/mem.h" #include "zlib_wrapper.h" +static void *alloc_wrapper(void *opaque, uInt items, uInt size) +{ +return av_malloc_array(items, size); +} + +static void free_wrapper(void *opaque, void *ptr) +{ +av_free(ptr); +} + int ff_inflate_init(FFZStream *z, void *logctx) { z_stream *const zstream = &z->zstream; @@ -33,8 +44,8 @@ int ff_inflate_init(FFZStream *z, void *logctx) z->inited = 0; zstream->next_in = Z_NULL; zstream->avail_in = 0; -zstream->zalloc = Z_NULL; -zstream->zfree= Z_NULL; +zstream->zalloc = alloc_wrapper; +zstream->zfree= free_wrapper; zstream->opaque = Z_NULL; zret = inflateInit(zstream); -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 14/21] avcodec/lscrdec: Don't open and close z_streams unnecessarily
Instead reuse and reset a single z_stream. Signed-off-by: Andreas Rheinhardt --- configure| 2 +- libavcodec/lscrdec.c | 84 +--- 2 files changed, 33 insertions(+), 53 deletions(-) diff --git a/configure b/configure index e3d2f590cd..0e5923fced 100755 --- a/configure +++ b/configure @@ -2850,7 +2850,7 @@ jpegls_decoder_select="mjpeg_decoder" jv_decoder_select="blockdsp" lagarith_decoder_select="llviddsp" ljpeg_encoder_select="idctdsp jpegtables" -lscr_decoder_deps="zlib" +lscr_decoder_select="inflate_wrapper" magicyuv_decoder_select="llviddsp" magicyuv_encoder_select="llvidencdsp" mdec_decoder_select="blockdsp bswapdsp idctdsp mpegvideo" diff --git a/libavcodec/lscrdec.c b/libavcodec/lscrdec.c index 18f46bd27c..58dac6e587 100644 --- a/libavcodec/lscrdec.c +++ b/libavcodec/lscrdec.c @@ -32,6 +32,7 @@ #include "packet.h" #include "png.h" #include "pngdsp.h" +#include "zlib_wrapper.h" typedef struct LSCRContext { PNGDSPContext dsp; @@ -52,7 +53,7 @@ typedef struct LSCRContext { int cur_h; int y; -z_streamzstream; +FFZStream zstream; } LSCRContext; static void handle_row(LSCRContext *s) @@ -71,11 +72,11 @@ static void handle_row(LSCRContext *s) s->y++; } -static int decode_idat(LSCRContext *s, int length) +static int decode_idat(LSCRContext *s, z_stream *zstream, int length) { int ret; -s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb)); -s->zstream.next_in = s->gb.buffer; +zstream->avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb)); +zstream->next_in = s->gb.buffer; if (length <= 0) return AVERROR_INVALIDDATA; @@ -83,22 +84,22 @@ static int decode_idat(LSCRContext *s, int length) bytestream2_skip(&s->gb, length); /* decode one line if possible */ -while (s->zstream.avail_in > 0) { -ret = inflate(&s->zstream, Z_PARTIAL_FLUSH); +while (zstream->avail_in > 0) { +ret = inflate(zstream, Z_PARTIAL_FLUSH); if (ret != Z_OK && ret != Z_STREAM_END) { av_log(s->avctx, AV_LOG_ERROR, "inflate returned error %d\n", ret); return AVERROR_EXTERNAL; } -if (s->zstream.avail_out == 0) { +if (zstream->avail_out == 0) { if (s->y < s->cur_h) { handle_row(s); } -s->zstream.avail_out = s->crow_size; -s->zstream.next_out = s->crow_buf; +zstream->avail_out = s->crow_size; +zstream->next_out = s->crow_buf; } -if (ret == Z_STREAM_END && s->zstream.avail_in > 0) { +if (ret == Z_STREAM_END && zstream->avail_in > 0) { av_log(s->avctx, AV_LOG_WARNING, - "%d undecompressed bytes left in buffer\n", s->zstream.avail_in); + "%d undecompressed bytes left in buffer\n", zstream->avail_in); return 0; } } @@ -131,18 +132,12 @@ static int decode_frame_lscr(AVCodecContext *avctx, return ret; for (int b = 0; b < nb_blocks; b++) { +z_stream *const zstream = &s->zstream.zstream; int x, y, x2, y2, w, h, left; uint32_t csize, size; -s->zstream.zalloc = ff_png_zalloc; -s->zstream.zfree = ff_png_zfree; -s->zstream.opaque = NULL; - -if ((ret = inflateInit(&s->zstream)) != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "inflateInit returned error %d\n", ret); -ret = AVERROR_EXTERNAL; -goto end; -} +if (inflateReset(zstream) != Z_OK) +return AVERROR_EXTERNAL; bytestream2_seek(gb, 2 + b * 12, SEEK_SET); @@ -154,10 +149,8 @@ static int decode_frame_lscr(AVCodecContext *avctx, s->cur_h = h = y2-y; if (w <= 0 || x < 0 || x >= avctx->width || w + x > avctx->width || -h <= 0 || y < 0 || y >= avctx->height || h + y > avctx->height) { -ret = AVERROR_INVALIDDATA; -goto end; -} +h <= 0 || y < 0 || y >= avctx->height || h + y > avctx->height) +return AVERROR_INVALIDDATA; size = bytestream2_get_le32(gb); @@ -168,10 +161,8 @@ static int decode_frame_lscr(AVCodecContext *avctx, bytestream2_seek(gb, 2 + nb_blocks * 12 + offset, SEEK_SET); csize = bytestream2_get_be32(gb); -if (bytestream2_get_le32(gb) != MKTAG('I', 'D', 'A', 'T')) { -ret = AVERROR_INVALIDDATA; -goto end; -} +if (bytestream2_get_le32(gb) != MKTAG('I', 'D', 'A', 'T')) +return AVERROR_INVALIDDATA; offset += size; left = size; @@ -180,40 +171,32 @@ static int decode_frame_lscr(AVCodecContext *avctx, s->row_size = w * 3; av_fast_padded_malloc(&s->buffer, &s->buffer_size, s->row_size + 16); -if (!s->buffer) { -ret = AVERROR(ENOME
[FFmpeg-devel] [PATCH 15/21] avcodec/pngdec: Don't open and close z_streams unnecessarily
Instead reuse and reset a single z_stream. Also use FFZStream in decode_zbuf(), because it has nicer error messages. Signed-off-by: Andreas Rheinhardt --- configure | 4 +- libavcodec/pngdec.c | 108 +++- 2 files changed, 48 insertions(+), 64 deletions(-) diff --git a/configure b/configure index 0e5923fced..74485fb713 100755 --- a/configure +++ b/configure @@ -2758,7 +2758,7 @@ amrwb_decoder_select="lsp" amv_decoder_select="sp5x_decoder exif" amv_encoder_select="jpegtables mpegvideoenc" ape_decoder_select="bswapdsp llauddsp" -apng_decoder_deps="zlib" +apng_decoder_select="inflate_wrapper" apng_encoder_deps="zlib" apng_encoder_select="llvidencdsp" aptx_decoder_select="audio_frame_queue" @@ -2903,7 +2903,7 @@ on2avc_decoder_select="mdct" opus_decoder_deps="swresample" opus_decoder_select="mdct15" opus_encoder_select="audio_frame_queue mdct15" -png_decoder_deps="zlib" +png_decoder_select="inflate_wrapper" png_encoder_deps="zlib" png_encoder_select="llvidencdsp" prores_decoder_select="blockdsp idctdsp" diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index a335a29b08..67931aad81 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -37,6 +37,7 @@ #include "pngdsp.h" #include "thread.h" #include "threadframe.h" +#include "zlib_wrapper.h" #include @@ -105,7 +106,7 @@ typedef struct PNGDecContext { int row_size; /* decompressed row size */ int pass_row_size; /* decompress row size of the current pass */ int y; -z_stream zstream; +FFZStream zstream; } PNGDecContext; /* Mask to determine which pixels are valid in a pass */ @@ -427,27 +428,28 @@ the_end:; static int png_decode_idat(PNGDecContext *s, GetByteContext *gb, uint8_t *dst, ptrdiff_t dst_stride) { +z_stream *const zstream = &s->zstream.zstream; int ret; -s->zstream.avail_in = bytestream2_get_bytes_left(gb); -s->zstream.next_in = gb->buffer; +zstream->avail_in = bytestream2_get_bytes_left(gb); +zstream->next_in = gb->buffer; /* decode one line if possible */ -while (s->zstream.avail_in > 0) { -ret = inflate(&s->zstream, Z_PARTIAL_FLUSH); +while (zstream->avail_in > 0) { +ret = inflate(zstream, Z_PARTIAL_FLUSH); if (ret != Z_OK && ret != Z_STREAM_END) { av_log(s->avctx, AV_LOG_ERROR, "inflate returned error %d\n", ret); return AVERROR_EXTERNAL; } -if (s->zstream.avail_out == 0) { +if (zstream->avail_out == 0) { if (!(s->pic_state & PNG_ALLIMAGE)) { png_handle_row(s, dst, dst_stride); } -s->zstream.avail_out = s->crow_size; -s->zstream.next_out = s->crow_buf; +zstream->avail_out = s->crow_size; +zstream->next_out = s->crow_buf; } -if (ret == Z_STREAM_END && s->zstream.avail_in > 0) { +if (ret == Z_STREAM_END && zstream->avail_in > 0) { av_log(s->avctx, AV_LOG_WARNING, - "%d undecompressed bytes left in buffer\n", s->zstream.avail_in); + "%d undecompressed bytes left in buffer\n", zstream->avail_in); return 0; } } @@ -455,45 +457,43 @@ static int png_decode_idat(PNGDecContext *s, GetByteContext *gb, } static int decode_zbuf(AVBPrint *bp, const uint8_t *data, - const uint8_t *data_end) + const uint8_t *data_end, void *logctx) { -z_stream zstream; +FFZStream z; +z_stream *const zstream = &z.zstream; unsigned char *buf; unsigned buf_size; -int ret; +int ret = ff_inflate_init(&z, logctx); +if (ret < 0) +return ret; -zstream.zalloc = ff_png_zalloc; -zstream.zfree = ff_png_zfree; -zstream.opaque = NULL; -if (inflateInit(&zstream) != Z_OK) -return AVERROR_EXTERNAL; -zstream.next_in = data; -zstream.avail_in = data_end - data; +zstream->next_in = data; +zstream->avail_in = data_end - data; av_bprint_init(bp, 0, AV_BPRINT_SIZE_UNLIMITED); -while (zstream.avail_in > 0) { +while (zstream->avail_in > 0) { av_bprint_get_buffer(bp, 2, &buf, &buf_size); if (buf_size < 2) { ret = AVERROR(ENOMEM); goto fail; } -zstream.next_out = buf; -zstream.avail_out = buf_size - 1; -ret = inflate(&zstream, Z_PARTIAL_FLUSH); +zstream->next_out = buf; +zstream->avail_out = buf_size - 1; +ret = inflate(zstream, Z_PARTIAL_FLUSH); if (ret != Z_OK && ret != Z_STREAM_END) { ret = AVERROR_EXTERNAL; goto fail; } -bp->len += zstream.next_out - buf; +bp->len += zstream->next_out - buf; if (ret == Z_STREAM_END) break; } -inflateEnd(&zstream); +ff_inflate_end(&z); bp->str[bp->len] = 0; return 0;
[FFmpeg-devel] [PATCH 16/21] avcodec/pngenc: Don't use deflateInit2() with default parameters
Use deflateInit() instead. Signed-off-by: Andreas Rheinhardt --- libavcodec/pngenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 64a9f5cc95..0b75f948d5 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -1071,7 +1071,7 @@ static av_cold int png_enc_init(AVCodecContext *avctx) compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT ? Z_DEFAULT_COMPRESSION : av_clip(avctx->compression_level, 0, 9); -if (deflateInit2(&s->zstream, compression_level, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY) != Z_OK) +if (deflateInit(&s->zstream, compression_level) != Z_OK) return -1; return 0; -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 17/21] avcodec/zlib_wrapper: Add wrapper for deflateInit()
The rationale is the same as for the wrappers for inflateInit(), although the case for it is admittedly not so strong because there are less users of deflateInit(). Signed-off-by: Andreas Rheinhardt --- configure | 2 ++ libavcodec/Makefile | 1 + libavcodec/zlib_wrapper.c | 34 ++ libavcodec/zlib_wrapper.h | 10 ++ 4 files changed, 47 insertions(+) diff --git a/configure b/configure index 74485fb713..26417f541f 100755 --- a/configure +++ b/configure @@ -2433,6 +2433,7 @@ CONFIG_EXTRA=" cbs_jpeg cbs_mpeg2 cbs_vp9 +deflate_wrapper dirac_parse dnn dovi_rpu @@ -2711,6 +2712,7 @@ cbs_jpeg_select="cbs" cbs_mpeg2_select="cbs" cbs_vp9_select="cbs" dct_select="rdft" +deflate_wrapper_deps="zlib" dirac_parse_select="golomb" dovi_rpu_select="golomb" dnn_suggest="libtensorflow libopenvino" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 62c8e34963..c45503b81b 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -77,6 +77,7 @@ OBJS-$(CONFIG_CBS_MPEG2) += cbs_mpeg2.o OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o OBJS-$(CONFIG_CRYSTALHD) += crystalhd.o OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o +OBJS-$(CONFIG_DEFLATE_WRAPPER) += zlib_wrapper.o OBJS-$(CONFIG_DOVI_RPU)+= dovi_rpu.o OBJS-$(CONFIG_ERROR_RESILIENCE)+= error_resilience.o OBJS-$(CONFIG_EXIF)+= exif.o tiff_common.o diff --git a/libavcodec/zlib_wrapper.c b/libavcodec/zlib_wrapper.c index 5b93c2c74f..bf104e5bf6 100644 --- a/libavcodec/zlib_wrapper.c +++ b/libavcodec/zlib_wrapper.c @@ -21,6 +21,7 @@ #include +#include "config.h" #include "libavutil/error.h" #include "libavutil/log.h" #include "libavutil/mem.h" @@ -36,6 +37,7 @@ static void free_wrapper(void *opaque, void *ptr) av_free(ptr); } +#if CONFIG_INFLATE_WRAPPER int ff_inflate_init(FFZStream *z, void *logctx) { z_stream *const zstream = &z->zstream; @@ -58,7 +60,9 @@ int ff_inflate_init(FFZStream *z, void *logctx) } return 0; } +#endif +#if CONFIG_DEFLATE_WRAPPER void ff_inflate_end(FFZStream *z) { if (z->inited) { @@ -66,3 +70,33 @@ void ff_inflate_end(FFZStream *z) inflateEnd(&z->zstream); } } + +int ff_deflate_init(FFZStream *z, int level, void *logctx) +{ +z_stream *const zstream = &z->zstream; +int zret; + +z->inited = 0; +zstream->zalloc = alloc_wrapper; +zstream->zfree = free_wrapper; +zstream->opaque = Z_NULL; + +zret = deflateInit(zstream, level); +if (zret == Z_OK) { +z->inited = 1; +} else { +av_log(logctx, AV_LOG_ERROR, "deflateInit error %d, message: %s\n", + zret, zstream->msg ? zstream->msg : ""); +return AVERROR_EXTERNAL; +} +return 0; +} + +void ff_deflate_end(FFZStream *z) +{ +if (z->inited) { +z->inited = 0; +deflateEnd(&z->zstream); +} +} +#endif diff --git a/libavcodec/zlib_wrapper.h b/libavcodec/zlib_wrapper.h index 0e91713b25..fa8ee654fd 100644 --- a/libavcodec/zlib_wrapper.h +++ b/libavcodec/zlib_wrapper.h @@ -48,4 +48,14 @@ int ff_inflate_init(FFZStream *zstream, void *logctx); */ void ff_inflate_end(FFZStream *zstream); +/** + * Wrapper around deflateInit(). It works analogously to ff_inflate_init(). + */ +int ff_deflate_init(FFZStream *zstream, int level, void *logctx); + +/** + * Wrapper around deflateEnd(). It works analogously to ff_inflate_end(). + */ +void ff_deflate_end(FFZStream *zstream); + #endif /* AVCODEC_ZLIB_WRAPPER_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 18/21] avcodec/zmbvenc: Use ff_deflate_init/end() wrappers
They emit better error messages (it does not claim that inflateInit failed upon an error from deflateInit!) and uses our allocation functions. Signed-off-by: Andreas Rheinhardt --- configure| 2 +- libavcodec/zmbvenc.c | 41 +++-- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/configure b/configure index 26417f541f..8f36699d0c 100755 --- a/configure +++ b/configure @@ -2995,7 +2995,7 @@ zerocodec_decoder_select="inflate_wrapper" zlib_decoder_select="inflate_wrapper" zlib_encoder_deps="zlib" zmbv_decoder_select="inflate_wrapper" -zmbv_encoder_deps="zlib" +zmbv_encoder_select="deflate_wrapper" # hardware accelerators crystalhd_deps="libcrystalhd_libcrystalhd_if_h" diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c index 8efdbc963e..065d390a92 100644 --- a/libavcodec/zmbvenc.c +++ b/libavcodec/zmbvenc.c @@ -32,6 +32,7 @@ #include "avcodec.h" #include "encode.h" #include "internal.h" +#include "zlib_wrapper.h" #include @@ -74,8 +75,7 @@ typedef struct ZmbvEncContext { int keyint, curfrm; int bypp; enum ZmbvFormat fmt; -int zlib_init_ok; -z_stream zstream; +FFZStream zstream; int score_tab[ZMBV_BLOCK * ZMBV_BLOCK * 4 + 1]; } ZmbvEncContext; @@ -169,6 +169,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { ZmbvEncContext * const c = avctx->priv_data; +z_stream *const zstream = &c->zstream.zstream; const AVFrame * const p = pict; uint8_t *src, *prev, *buf; uint32_t *palptr; @@ -262,21 +263,21 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, } if (keyframe) -deflateReset(&c->zstream); +deflateReset(zstream); -c->zstream.next_in = c->work_buf; -c->zstream.avail_in = work_size; -c->zstream.total_in = 0; +zstream->next_in = c->work_buf; +zstream->avail_in = work_size; +zstream->total_in = 0; -c->zstream.next_out = c->comp_buf; -c->zstream.avail_out = c->comp_size; -c->zstream.total_out = 0; -if(deflate(&c->zstream, Z_SYNC_FLUSH) != Z_OK){ +zstream->next_out = c->comp_buf; +zstream->avail_out = c->comp_size; +zstream->total_out = 0; +if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Error compressing data\n"); return -1; } -pkt_size = c->zstream.total_out + 1 + 6*keyframe; +pkt_size = zstream->total_out + 1 + 6 * keyframe; if ((ret = ff_get_encode_buffer(avctx, pkt, pkt_size, 0)) < 0) return ret; buf = pkt->data; @@ -292,7 +293,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, *buf++ = ZMBV_BLOCK; // block height pkt->flags |= AV_PKT_FLAG_KEY; } -memcpy(buf, c->comp_buf, c->zstream.total_out); +memcpy(buf, c->comp_buf, zstream->total_out); *got_packet = 1; @@ -307,8 +308,7 @@ static av_cold int encode_end(AVCodecContext *avctx) av_freep(&c->work_buf); av_freep(&c->prev_buf); -if (c->zlib_init_ok) -deflateEnd(&c->zstream); +ff_deflate_end(&c->zstream); return 0; } @@ -319,7 +319,6 @@ static av_cold int encode_end(AVCodecContext *avctx) static av_cold int encode_init(AVCodecContext *avctx) { ZmbvEncContext * const c = avctx->priv_data; -int zret; // Zlib return code int i; int lvl = 9; int prev_size, prev_offset; @@ -408,17 +407,7 @@ static av_cold int encode_init(AVCodecContext *avctx) } c->prev = c->prev_buf + prev_offset; -c->zstream.zalloc = Z_NULL; -c->zstream.zfree = Z_NULL; -c->zstream.opaque = Z_NULL; -zret = deflateInit(&c->zstream, lvl); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); -return -1; -} -c->zlib_init_ok = 1; - -return 0; +return ff_deflate_init(&c->zstream, lvl, avctx); } const AVCodec ff_zmbv_encoder = { -- 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 19/21] avcodec/pngenc: Use ff_deflate_init/end() wrappers
They return nicer error messages. Signed-off-by: Andreas Rheinhardt --- configure | 6 ++ libavcodec/png.c| 10 - libavcodec/png.h| 4 libavcodec/pngenc.c | 49 ++--- 4 files changed, 26 insertions(+), 43 deletions(-) diff --git a/configure b/configure index 8f36699d0c..a3d4b224f4 100755 --- a/configure +++ b/configure @@ -2761,8 +2761,7 @@ amv_decoder_select="sp5x_decoder exif" amv_encoder_select="jpegtables mpegvideoenc" ape_decoder_select="bswapdsp llauddsp" apng_decoder_select="inflate_wrapper" -apng_encoder_deps="zlib" -apng_encoder_select="llvidencdsp" +apng_encoder_select="deflate_wrapper llvidencdsp" aptx_decoder_select="audio_frame_queue" aptx_encoder_select="audio_frame_queue" aptx_hd_decoder_select="audio_frame_queue" @@ -2906,8 +2905,7 @@ opus_decoder_deps="swresample" opus_decoder_select="mdct15" opus_encoder_select="audio_frame_queue mdct15" png_decoder_select="inflate_wrapper" -png_encoder_deps="zlib" -png_encoder_select="llvidencdsp" +png_encoder_select="deflate_wrapper llvidencdsp" prores_decoder_select="blockdsp idctdsp" prores_encoder_select="fdctdsp" qcelp_decoder_select="lsp" diff --git a/libavcodec/png.c b/libavcodec/png.c index e772eaad26..34f649815a 100644 --- a/libavcodec/png.c +++ b/libavcodec/png.c @@ -38,16 +38,6 @@ static const uint8_t ff_png_pass_xshift[NB_PASSES] = { 3, 3, 2, 2, 1, 1, 0 }; -void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size) -{ -return av_calloc(items, size); -} - -void ff_png_zfree(void *opaque, void *ptr) -{ -av_free(ptr); -} - int ff_png_get_nb_channels(int color_type) { int channels; diff --git a/libavcodec/png.h b/libavcodec/png.h index a15560131f..01171e682e 100644 --- a/libavcodec/png.h +++ b/libavcodec/png.h @@ -52,10 +52,6 @@ /* Mask to determine which y pixels are valid in a pass */ extern const uint8_t ff_png_pass_ymask[NB_PASSES]; -void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size); - -void ff_png_zfree(void *opaque, void *ptr); - int ff_png_get_nb_channels(int color_type); /* compute the row size of an interleaved pass */ diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 0b75f948d5..b34a94db21 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -26,6 +26,7 @@ #include "lossless_videoencdsp.h" #include "png.h" #include "apng.h" +#include "zlib_wrapper.h" #include "libavutil/avassert.h" #include "libavutil/crc.h" @@ -56,7 +57,7 @@ typedef struct PNGEncContext { int filter_type; -z_stream zstream; +FFZStream zstream; uint8_t buf[IOBUF_SIZE]; int dpi; ///< Physical pixel density, in dots per inch, if set int dpm; ///< Physical pixel density, in dots per meter, if set @@ -272,19 +273,20 @@ static void png_write_image_data(AVCodecContext *avctx, static int png_write_row(AVCodecContext *avctx, const uint8_t *data, int size) { PNGEncContext *s = avctx->priv_data; +z_stream *const zstream = &s->zstream.zstream; int ret; -s->zstream.avail_in = size; -s->zstream.next_in = data; -while (s->zstream.avail_in > 0) { -ret = deflate(&s->zstream, Z_NO_FLUSH); +zstream->avail_in = size; +zstream->next_in = data; +while (zstream->avail_in > 0) { +ret = deflate(zstream, Z_NO_FLUSH); if (ret != Z_OK) return -1; -if (s->zstream.avail_out == 0) { +if (zstream->avail_out == 0) { if (s->bytestream_end - s->bytestream > IOBUF_SIZE + 100) png_write_image_data(avctx, s->buf, IOBUF_SIZE); -s->zstream.avail_out = IOBUF_SIZE; -s->zstream.next_out = s->buf; +zstream->avail_out = IOBUF_SIZE; +zstream->next_out = s->buf; } } return 0; @@ -432,6 +434,7 @@ static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) static int encode_frame(AVCodecContext *avctx, const AVFrame *pict) { PNGEncContext *s = avctx->priv_data; +z_stream *const zstream = &s->zstream.zstream; const AVFrame *const p = pict; int y, len, ret; int row_size, pass_row_size; @@ -459,8 +462,8 @@ static int encode_frame(AVCodecContext *avctx, const AVFrame *pict) } /* put each row */ -s->zstream.avail_out = IOBUF_SIZE; -s->zstream.next_out = s->buf; +zstream->avail_out = IOBUF_SIZE; +zstream->next_out = s->buf; if (s->is_progressive) { int pass; @@ -496,14 +499,14 @@ static int encode_frame(AVCodecContext *avctx, const AVFrame *pict) } /* compress last bytes */ for (;;) { -ret = deflate(&s->zstream, Z_FINISH); +ret = deflate(zstream, Z_FINISH); if (ret == Z_OK || ret == Z_STREAM_END) { -len = IOBUF_SIZE - s->zstream.avail_out; +len = IOBUF_SIZE - zstream->avail_out; if (len > 0 && s->bytestream_
[FFmpeg-devel] [PATCH 20/21] avcodec/lclenc: Use ff_deflate_init/end() wrappers
They return nicer error messages on error; furthermore, they also use our allocation functions. It also stops calling deflateEnd() on a z_stream that might not have been successfully initialized. Signed-off-by: Andreas Rheinhardt --- configure | 2 +- libavcodec/lclenc.c | 36 ++-- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/configure b/configure index a3d4b224f4..ee3c6783f3 100755 --- a/configure +++ b/configure @@ -2991,7 +2991,7 @@ xma2_decoder_select="wmapro_decoder" ylc_decoder_select="bswapdsp" zerocodec_decoder_select="inflate_wrapper" zlib_decoder_select="inflate_wrapper" -zlib_encoder_deps="zlib" +zlib_encoder_select="deflate_wrapper" zmbv_decoder_select="inflate_wrapper" zmbv_encoder_select="deflate_wrapper" diff --git a/libavcodec/lclenc.c b/libavcodec/lclenc.c index 7deea4f20a..afa99d1f92 100644 --- a/libavcodec/lclenc.c +++ b/libavcodec/lclenc.c @@ -45,6 +45,7 @@ #include "encode.h" #include "internal.h" #include "lcl.h" +#include "zlib_wrapper.h" #include "libavutil/internal.h" #include "libavutil/mem.h" @@ -60,16 +61,17 @@ typedef struct LclEncContext { int compression; // Flags int flags; -z_stream zstream; +FFZStream zstream; } LclEncContext; static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *p, int *got_packet) { LclEncContext *c = avctx->priv_data; +z_stream *const zstream = &c->zstream.zstream; int i, ret; int zret; // Zlib return code -int max_size = deflateBound(&c->zstream, avctx->width * avctx->height * 3); +int max_size = deflateBound(zstream, avctx->width * avctx->height * 3); if ((ret = ff_alloc_packet(avctx, pkt, max_size)) < 0) return ret; @@ -79,30 +81,30 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, return -1; } -zret = deflateReset(&c->zstream); +zret = deflateReset(zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Deflate reset error: %d\n", zret); return -1; } -c->zstream.next_out = pkt->data; -c->zstream.avail_out = pkt->size; +zstream->next_out = pkt->data; +zstream->avail_out = pkt->size; for(i = avctx->height - 1; i >= 0; i--) { -c->zstream.next_in = p->data[0]+p->linesize[0]*i; -c->zstream.avail_in = avctx->width*3; -zret = deflate(&c->zstream, Z_NO_FLUSH); +zstream->next_in = p->data[0] + p->linesize[0] * i; +zstream->avail_in = avctx->width * 3; +zret = deflate(zstream, Z_NO_FLUSH); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); return -1; } } -zret = deflate(&c->zstream, Z_FINISH); +zret = deflate(zstream, Z_FINISH); if (zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); return -1; } -pkt->size = c->zstream.total_out; +pkt->size = zstream->total_out; *got_packet = 1; return 0; @@ -111,7 +113,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, static av_cold int encode_init(AVCodecContext *avctx) { LclEncContext *c = avctx->priv_data; -int zret; // Zlib return code c->avctx= avctx; @@ -138,23 +139,14 @@ static av_cold int encode_init(AVCodecContext *avctx) avctx->extradata[7]= CODEC_ZLIB; c->avctx->extradata_size= 8; -c->zstream.zalloc = Z_NULL; -c->zstream.zfree = Z_NULL; -c->zstream.opaque = Z_NULL; -zret = deflateInit(&c->zstream, c->compression); -if (zret != Z_OK) { -av_log(avctx, AV_LOG_ERROR, "Deflate init error: %d\n", zret); -return AVERROR_UNKNOWN; -} - -return 0; +return ff_deflate_init(&c->zstream, c->compression, avctx); } static av_cold int encode_end(AVCodecContext *avctx) { LclEncContext *c = avctx->priv_data; -deflateEnd(&c->zstream); +ff_deflate_end(&c->zstream); return 0; } -- 2.32.0 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 21/21] avcodec/flashsv2enc: Avoid opening and closing z_stream
Instead initialize a z_stream during init and reset it when needed. Signed-off-by: Andreas Rheinhardt --- configure| 2 +- libavcodec/flashsv2enc.c | 70 +++- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/configure b/configure index ee3c6783f3..b175019a61 100755 --- a/configure +++ b/configure @@ -2812,7 +2812,7 @@ fic_decoder_select="golomb" flac_decoder_select="flacdsp" flac_encoder_select="bswapdsp flacdsp lpc" flashsv2_decoder_select="inflate_wrapper" -flashsv2_encoder_deps="zlib" +flashsv2_encoder_select="deflate_wrapper" flashsv_decoder_select="inflate_wrapper" flashsv_encoder_deps="zlib" flv_decoder_select="h263_decoder" diff --git a/libavcodec/flashsv2enc.c b/libavcodec/flashsv2enc.c index 56ea0ed0a4..9b8a891ae4 100644 --- a/libavcodec/flashsv2enc.c +++ b/libavcodec/flashsv2enc.c @@ -52,6 +52,7 @@ #include "internal.h" #include "put_bits.h" #include "bytestream.h" +#include "zlib_wrapper.h" #define HAS_IFRAME_IMAGE 0x02 #define HAS_PALLET_INFO 0x01 @@ -112,6 +113,7 @@ typedef struct FlashSV2Context { uint8_t use_custom_palette; uint8_t palette_type; ///< 0=>default, 1=>custom - changed when palette regenerated. Palette palette; +FFZStream zstream; #ifndef FLASHSV2_DUMB double tot_blocks; ///< blocks encoded since last keyframe double diff_blocks; ///< blocks that were different since last keyframe @@ -136,6 +138,7 @@ static av_cold void cleanup(FlashSV2Context * s) av_freep(&s->frame_blocks); av_freep(&s->key_blocks); +ff_deflate_end(&s->zstream); } static void init_blocks(FlashSV2Context * s, Block * blocks, @@ -234,7 +237,9 @@ static av_cold int flashsv2_encode_init(AVCodecContext * avctx) if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) return ret; - +ret = ff_deflate_init(&s->zstream, s->comp, avctx); +if (ret < 0) +return ret; s->last_key_frame = 0; s->image_width = avctx->width; @@ -357,41 +362,47 @@ static int write_block(Block * b, uint8_t * buf, int buf_size) return buf_pos; } -static int encode_zlib(Block * b, uint8_t * buf, unsigned long *buf_size, int comp) +static int encode_zlib(Block *b, uint8_t *buf, unsigned long *buf_size, + z_stream *zstream) { -int res = compress2(buf, buf_size, b->sl_begin, b->sl_end - b->sl_begin, comp); -return res == Z_OK ? 0 : -1; +int res; + +if (deflateReset(zstream) != Z_OK) +return AVERROR_EXTERNAL; +zstream->next_out = buf; +zstream->avail_out = *buf_size; +zstream->next_in = b->sl_begin; +zstream->avail_in = b->sl_end - b->sl_begin; +res = deflate(zstream, Z_FINISH); +if (res != Z_STREAM_END) +return AVERROR_EXTERNAL; +*buf_size -= zstream->avail_out; +return 0; } static int encode_zlibprime(Block * b, Block * prime, uint8_t * buf, -int *buf_size, int comp) +int *buf_size, z_stream *zstream) { -z_stream s; int res; -s.zalloc = NULL; -s.zfree = NULL; -s.opaque = NULL; -res = deflateInit(&s, comp); -if (res < 0) -return -1; -s.next_in = prime->enc; -s.avail_in = prime->enc_size; -while (s.avail_in > 0) { -s.next_out = buf; -s.avail_out = *buf_size; -res = deflate(&s, Z_SYNC_FLUSH); +if (deflateReset(zstream) != Z_OK) +return AVERROR_EXTERNAL; +zstream->next_in = prime->enc; +zstream->avail_in = prime->enc_size; +while (zstream->avail_in > 0) { +zstream->next_out = buf; +zstream->avail_out = *buf_size; +res = deflate(zstream, Z_SYNC_FLUSH); if (res < 0) return -1; } -s.next_in = b->sl_begin; -s.avail_in = b->sl_end - b->sl_begin; -s.next_out = buf; -s.avail_out = *buf_size; -res = deflate(&s, Z_FINISH); -deflateEnd(&s); -*buf_size -= s.avail_out; +zstream->next_in = b->sl_begin; +zstream->avail_in = b->sl_end - b->sl_begin; +zstream->next_out = buf; +zstream->avail_out = *buf_size; +res = deflate(zstream, Z_FINISH); +*buf_size -= zstream->avail_out; if (res != Z_STREAM_END) return -1; return 0; @@ -559,7 +570,7 @@ static int encode_15_7(Palette * palette, Block * b, const uint8_t * src, } static int encode_block(FlashSV2Context *s, Palette * palette, Block * b, -Block * prev, const uint8_t * src, int stride, int comp, +Block *prev, const uint8_t *src, int stride, int dist, int keyframe) { unsigned buf_size = b->width * b->height * 6; @@ -574,12 +585,12 @@ static int encode_block(FlashSV2Context *s, Palette * palette, Block * b, if (b->len > 0) { b->data_size = buf_size; -res = encode_zlib(b, b->data, &b->data_size, comp); +
[FFmpeg-devel] [PATCH 1/4] avutil/channel_layout: print channels using av_channel_name_bprint in av_channel_layout_describe_bprint
This reduces code duplication an allows printing AMBI%d channel names for custom layouts for non-standard or partial ambisonic layouts. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 6 +- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 8cc4efe4cf..c60ccf368f 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -737,14 +737,10 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, av_bprintf(bp, "%d channels (", channel_layout->nb_channels); for (i = 0; i < channel_layout->nb_channels; i++) { enum AVChannel ch = av_channel_layout_channel_from_index(channel_layout, i); -const char *channel = get_channel_name(ch); if (i) av_bprintf(bp, "+"); -if (channel) -av_bprintf(bp, "%s", channel); -else -av_bprintf(bp, "USR%d", ch); +av_channel_name_bprint(bp, ch); if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM && channel_layout->u.map[i].name[0]) av_bprintf(bp, "@%s", channel_layout->u.map[i].name); -- 2.31.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/4] avutil/channel_layout: factorize ambisonic order detection
Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 40 ++ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index c60ccf368f..fb2335a334 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -644,29 +644,29 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src) } /** - * If the custom layout is n-th order standard-order ambisonic, with optional - * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * If the layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, return the order. + * Return a negative error code otherwise. */ -static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +static int ambisonic_order(const AVChannelLayout *channel_layout) { int i, highest_ambi, order; highest_ambi = -1; -if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) +if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1; -else { +} else if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { const AVChannelCustom *map = channel_layout->u.map; for (i = 0; i < channel_layout->nb_channels; i++) { int is_ambi = CHAN_IS_AMBI(map[i].id); /* ambisonic following non-ambisonic */ if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id)) -return 0; +return AVERROR(EINVAL); /* non-default ordering */ if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i) -return 0; +return AVERROR(EINVAL); if (CHAN_IS_AMBI(map[i].id)) highest_ambi = i; @@ -674,17 +674,33 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l } /* no ambisonic channels*/ if (highest_ambi < 0) -return 0; +return AVERROR(EINVAL); order = floor(sqrt(highest_ambi)); /* incomplete order - some harmonics are missing */ if ((order + 1) * (order + 1) != highest_ambi + 1) +return AVERROR(EINVAL); + +return order; +} + +/** + * If the custom layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, write its string description in bp. + * Return a negative error code on error. + */ +static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +{ +int nb_ambi_channels; +int order = ambisonic_order(channel_layout); +if (order < 0) return 0; av_bprintf(bp, "ambisonic %d", order); /* extra channels present */ -if (highest_ambi < channel_layout->nb_channels - 1) { +nb_ambi_channels = (order + 1) * (order + 1); +if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; char buf[128]; @@ -696,12 +712,12 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l const AVChannelCustom *map = channel_layout->u.map; extra.order = AV_CHANNEL_ORDER_CUSTOM; -extra.nb_channels = channel_layout->nb_channels - highest_ambi - 1; +extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); if (!extra.u.map) return AVERROR(ENOMEM); -memcpy(extra.u.map, &map[highest_ambi + 1], +memcpy(extra.u.map, &map[nb_ambi_channels], sizeof(*extra.u.map) * extra.nb_channels); } -- 2.31.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] avutil/channel_layout: do not copy alloc new map for extra channel layout
Also use av_channel_layout_bprint directly for describing channel layout for extra channels. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 16 +++- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index fb2335a334..8406089fe0 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -702,29 +702,19 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l nb_ambi_channels = (order + 1) * (order + 1); if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; -char buf[128]; if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { extra.order = AV_CHANNEL_ORDER_NATIVE; extra.nb_channels = av_popcount64(channel_layout->u.mask); extra.u.mask = channel_layout->u.mask; } else { -const AVChannelCustom *map = channel_layout->u.map; - extra.order = AV_CHANNEL_ORDER_CUSTOM; extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; -extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); -if (!extra.u.map) -return AVERROR(ENOMEM); - -memcpy(extra.u.map, &map[nb_ambi_channels], - sizeof(*extra.u.map) * extra.nb_channels); +extra.u.map = channel_layout->u.map + nb_ambi_channels; } -av_channel_layout_describe(&extra, buf, sizeof(buf)); -av_channel_layout_uninit(&extra); - -av_bprintf(bp, "+%s", buf); +av_bprint_chars(bp, '+', 1); +av_channel_layout_describe_bprint(&extra, bp); } return 0; -- 2.31.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] avutil/channel_layout: fix av_channel_layout_describe_bprint with custom and ambisonic channels
bp->len cannot be used to detect if try_describe_ambisonic was successful because the bprint buffer might contain other data as well. Also describing an invalid ambisonic layout should not return 0 but AVERROR(EINVAL) instead, so change try_describe_ambisonic to actually return error on invalid ambisonics. This also allows us to fix the first issue. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 8406089fe0..be511dcf68 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -687,14 +687,14 @@ static int ambisonic_order(const AVChannelLayout *channel_layout) /** * If the custom layout is n-th order standard-order ambisonic, with optional * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * Return a negative error code otherwise. */ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) { int nb_ambi_channels; int order = ambisonic_order(channel_layout); if (order < 0) -return 0; +return order; av_bprintf(bp, "ambisonic %d", order); @@ -736,7 +736,7 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, case AV_CHANNEL_ORDER_CUSTOM: if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { int res = try_describe_ambisonic(bp, channel_layout); -if (res < 0 || bp->len) +if (res >= 0) return res; } if (channel_layout->nb_channels) -- 2.31.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 3/4] avutil/channel_layout: do not copy alloc new map for extra channel layout
On 3/15/2022 5:30 PM, Marton Balint wrote: Also use av_channel_layout_bprint directly for describing channel layout for extra channels. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 16 +++- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index fb2335a334..8406089fe0 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -702,29 +702,19 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l nb_ambi_channels = (order + 1) * (order + 1); if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; -char buf[128]; if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { extra.order = AV_CHANNEL_ORDER_NATIVE; extra.nb_channels = av_popcount64(channel_layout->u.mask); extra.u.mask = channel_layout->u.mask; } else { -const AVChannelCustom *map = channel_layout->u.map; - extra.order = AV_CHANNEL_ORDER_CUSTOM; extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; -extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); -if (!extra.u.map) -return AVERROR(ENOMEM); - -memcpy(extra.u.map, &map[nb_ambi_channels], - sizeof(*extra.u.map) * extra.nb_channels); +extra.u.map = channel_layout->u.map + nb_ambi_channels; } -av_channel_layout_describe(&extra, buf, sizeof(buf)); -av_channel_layout_uninit(&extra); Maybe add a comment that you're not calling uninit on extra because it doesn't own its AVChannelMap pointer. - -av_bprintf(bp, "+%s", buf); +av_bprint_chars(bp, '+', 1); +av_channel_layout_describe_bprint(&extra, bp); } return 0; ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 4/4] avutil/channel_layout: fix av_channel_layout_describe_bprint with custom and ambisonic channels
On 3/15/2022 5:30 PM, Marton Balint wrote: bp->len cannot be used to detect if try_describe_ambisonic was successful because the bprint buffer might contain other data as well. Also describing an invalid ambisonic layout should not return 0 but AVERROR(EINVAL) instead, so change try_describe_ambisonic to actually return error on invalid ambisonics. This also allows us to fix the first issue. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 8406089fe0..be511dcf68 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -687,14 +687,14 @@ static int ambisonic_order(const AVChannelLayout *channel_layout) /** * If the custom layout is n-th order standard-order ambisonic, with optional * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * Return a negative error code otherwise. */ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) { int nb_ambi_channels; int order = ambisonic_order(channel_layout); if (order < 0) -return 0; +return order; av_bprintf(bp, "ambisonic %d", order); @@ -736,7 +736,7 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, case AV_CHANNEL_ORDER_CUSTOM: if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { int res = try_describe_ambisonic(bp, channel_layout); -if (res < 0 || bp->len) +if (res >= 0) return res; return 0. The doxy for av_channel_layout_describe_bprint() does not define values > 0. } if (channel_layout->nb_channels) ___ 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/4] avutil/channel_layout: print channels using av_channel_name_bprint in av_channel_layout_describe_bprint
On 3/15/2022 5:30 PM, Marton Balint wrote: This reduces code duplication an allows printing AMBI%d channel names for custom layouts for non-standard or partial ambisonic layouts. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 6 +- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 8cc4efe4cf..c60ccf368f 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -737,14 +737,10 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, av_bprintf(bp, "%d channels (", channel_layout->nb_channels); for (i = 0; i < channel_layout->nb_channels; i++) { enum AVChannel ch = av_channel_layout_channel_from_index(channel_layout, i); -const char *channel = get_channel_name(ch); if (i) av_bprintf(bp, "+"); -if (channel) -av_bprintf(bp, "%s", channel); -else -av_bprintf(bp, "USR%d", ch); +av_channel_name_bprint(bp, ch); if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM && channel_layout->u.map[i].name[0]) av_bprintf(bp, "@%s", channel_layout->u.map[i].name); Should be ok. ___ 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 2/4] avutil/channel_layout: factorize ambisonic order detection
On 3/15/2022 5:30 PM, Marton Balint wrote: Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 40 ++ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index c60ccf368f..fb2335a334 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -644,29 +644,29 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src) } /** - * If the custom layout is n-th order standard-order ambisonic, with optional - * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * If the layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, return the order. + * Return a negative error code otherwise. */ -static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +static int ambisonic_order(const AVChannelLayout *channel_layout) { int i, highest_ambi, order; highest_ambi = -1; -if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) +if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1; -else { +} else if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { It's not called for any other order, so this is not needed. Maybe add an av_assert0() instead. const AVChannelCustom *map = channel_layout->u.map; for (i = 0; i < channel_layout->nb_channels; i++) { int is_ambi = CHAN_IS_AMBI(map[i].id); /* ambisonic following non-ambisonic */ if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id)) -return 0; +return AVERROR(EINVAL); /* non-default ordering */ if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i) -return 0; +return AVERROR(EINVAL); if (CHAN_IS_AMBI(map[i].id)) highest_ambi = i; @@ -674,17 +674,33 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l } /* no ambisonic channels*/ if (highest_ambi < 0) -return 0; +return AVERROR(EINVAL); order = floor(sqrt(highest_ambi)); /* incomplete order - some harmonics are missing */ if ((order + 1) * (order + 1) != highest_ambi + 1) +return AVERROR(EINVAL); + +return order; +} + +/** + * If the custom layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, write its string description in bp. + * Return a negative error code on error. + */ +static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +{ +int nb_ambi_channels; +int order = ambisonic_order(channel_layout); +if (order < 0) return 0; av_bprintf(bp, "ambisonic %d", order); /* extra channels present */ -if (highest_ambi < channel_layout->nb_channels - 1) { +nb_ambi_channels = (order + 1) * (order + 1); +if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; char buf[128]; @@ -696,12 +712,12 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l const AVChannelCustom *map = channel_layout->u.map; extra.order = AV_CHANNEL_ORDER_CUSTOM; -extra.nb_channels = channel_layout->nb_channels - highest_ambi - 1; +extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); if (!extra.u.map) return AVERROR(ENOMEM); -memcpy(extra.u.map, &map[highest_ambi + 1], +memcpy(extra.u.map, &map[nb_ambi_channels], sizeof(*extra.u.map) * extra.nb_channels); } Should be ok. ___ 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] ffmpeg: remove usage of internal deprecation macro
Signed-off-by: James Almer --- fftools/ffmpeg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index a98e49b775..3b625a9918 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2880,9 +2880,9 @@ static int init_input_stream(int ist_index, char *error, int error_len) ist->dec_ctx->opaque= ist; ist->dec_ctx->get_format= get_format; #if LIBAVCODEC_VERSION_MAJOR < 60 -FF_DISABLE_DEPRECATION_WARNINGS +AV_NOWARN_DEPRECATED({ ist->dec_ctx->thread_safe_callbacks = 1; -FF_ENABLE_DEPRECATION_WARNINGS +}) #endif if (ist->dec_ctx->codec_id == AV_CODEC_ID_DVB_SUBTITLE && -- 2.35.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 v2] avcodec/hevc_refs: don't use the frame's AVBufferRef sizes when initializing planes
On 3/15/2022 5:53 AM, Anton Khirnov wrote: Quoting James Almer (2022-03-08 14:55:00) Use the actual plane sizes instead. Signed-off-by: James Almer --- libavcodec/hevc_refs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index 35b8e5e696..fe18ca2b1d 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -401,9 +401,9 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc) if (!s->avctx->hwaccel) { if (!s->ps.sps->pixel_shift) { -for (i = 0; frame->frame->buf[i]; i++) -memset(frame->frame->buf[i]->data, 1 << (s->ps.sps->bit_depth - 1), - frame->frame->buf[i]->size); +for (i = 0; frame->frame->data[i]; i++) +memset(frame->frame->data[i], 1 << (s->ps.sps->bit_depth - 1), + frame->frame->linesize[i] * AV_CEIL_RSHIFT(s->ps.sps->height, s->ps.sps->vshift[i])); Looks good. Applied, thanks. ___ 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 1/4] avutil/channel_layout: print channels using av_channel_name_bprint in av_channel_layout_describe_bprint
This reduces code duplication an allows printing AMBI%d channel names for custom layouts for non-standard or partial ambisonic layouts. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 6 +- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 8cc4efe4cf..c60ccf368f 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -737,14 +737,10 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, av_bprintf(bp, "%d channels (", channel_layout->nb_channels); for (i = 0; i < channel_layout->nb_channels; i++) { enum AVChannel ch = av_channel_layout_channel_from_index(channel_layout, i); -const char *channel = get_channel_name(ch); if (i) av_bprintf(bp, "+"); -if (channel) -av_bprintf(bp, "%s", channel); -else -av_bprintf(bp, "USR%d", ch); +av_channel_name_bprint(bp, ch); if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM && channel_layout->u.map[i].name[0]) av_bprintf(bp, "@%s", channel_layout->u.map[i].name); -- 2.31.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 2/4] avutil/channel_layout: factorize ambisonic order detection
Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 42 +++--- libavutil/channel_layout.h | 1 + 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index c60ccf368f..0069c6257b 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -644,29 +644,31 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src) } /** - * If the custom layout is n-th order standard-order ambisonic, with optional - * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * If the layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, return the order. + * Return a negative error code otherwise. */ -static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +static int ambisonic_order(const AVChannelLayout *channel_layout) { int i, highest_ambi, order; highest_ambi = -1; -if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) +if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1; -else { +} else { const AVChannelCustom *map = channel_layout->u.map; +av_assert0(channel_layout->order == AV_CHANNEL_ORDER_CUSTOM); + for (i = 0; i < channel_layout->nb_channels; i++) { int is_ambi = CHAN_IS_AMBI(map[i].id); /* ambisonic following non-ambisonic */ if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id)) -return 0; +return AVERROR(EINVAL); /* non-default ordering */ if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i) -return 0; +return AVERROR(EINVAL); if (CHAN_IS_AMBI(map[i].id)) highest_ambi = i; @@ -674,17 +676,33 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l } /* no ambisonic channels*/ if (highest_ambi < 0) -return 0; +return AVERROR(EINVAL); order = floor(sqrt(highest_ambi)); /* incomplete order - some harmonics are missing */ if ((order + 1) * (order + 1) != highest_ambi + 1) +return AVERROR(EINVAL); + +return order; +} + +/** + * If the custom layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, write its string description in bp. + * Return a negative error code on error. + */ +static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +{ +int nb_ambi_channels; +int order = ambisonic_order(channel_layout); +if (order < 0) return 0; av_bprintf(bp, "ambisonic %d", order); /* extra channels present */ -if (highest_ambi < channel_layout->nb_channels - 1) { +nb_ambi_channels = (order + 1) * (order + 1); +if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; char buf[128]; @@ -696,12 +714,12 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l const AVChannelCustom *map = channel_layout->u.map; extra.order = AV_CHANNEL_ORDER_CUSTOM; -extra.nb_channels = channel_layout->nb_channels - highest_ambi - 1; +extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); if (!extra.u.map) return AVERROR(ENOMEM); -memcpy(extra.u.map, &map[highest_ambi + 1], +memcpy(extra.u.map, &map[nb_ambi_channels], sizeof(*extra.u.map) * extra.nb_channels); } diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index 4dd6614de9..294e8b0773 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -27,6 +27,7 @@ #include "version.h" #include "attributes.h" +#include "avassert.h" /** * @file -- 2.31.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 3/4] avutil/channel_layout: do not copy alloc new map for extra channel layout
Also use av_channel_layout_bprint directly for describing channel layout for extra channels. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 17 - 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 0069c6257b..fb1f72737f 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -704,29 +704,20 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l nb_ambi_channels = (order + 1) * (order + 1); if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; -char buf[128]; if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { extra.order = AV_CHANNEL_ORDER_NATIVE; extra.nb_channels = av_popcount64(channel_layout->u.mask); extra.u.mask = channel_layout->u.mask; } else { -const AVChannelCustom *map = channel_layout->u.map; - extra.order = AV_CHANNEL_ORDER_CUSTOM; extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; -extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); -if (!extra.u.map) -return AVERROR(ENOMEM); - -memcpy(extra.u.map, &map[nb_ambi_channels], - sizeof(*extra.u.map) * extra.nb_channels); +extra.u.map = channel_layout->u.map + nb_ambi_channels; } -av_channel_layout_describe(&extra, buf, sizeof(buf)); -av_channel_layout_uninit(&extra); - -av_bprintf(bp, "+%s", buf); +av_bprint_chars(bp, '+', 1); +av_channel_layout_describe_bprint(&extra, bp); +/* Not calling uninit here on extra because we don't own the u.map pointer */ } return 0; -- 2.31.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 4/4] avutil/channel_layout: fix av_channel_layout_describe_bprint with custom and ambisonic channels
bp->len cannot be used to detect if try_describe_ambisonic was successful because the bprint buffer might contain other data as well. Also describing an invalid ambisonic layout should not return 0 but AVERROR(EINVAL) instead, so change try_describe_ambisonic to actually return error on invalid ambisonics. This also allows us to fix the first issue. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index fb1f72737f..1a141d4a6a 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -689,14 +689,14 @@ static int ambisonic_order(const AVChannelLayout *channel_layout) /** * If the custom layout is n-th order standard-order ambisonic, with optional * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * Return a negative error code otherwise. */ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) { int nb_ambi_channels; int order = ambisonic_order(channel_layout); if (order < 0) -return 0; +return order; av_bprintf(bp, "ambisonic %d", order); @@ -739,8 +739,8 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, case AV_CHANNEL_ORDER_CUSTOM: if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { int res = try_describe_ambisonic(bp, channel_layout); -if (res < 0 || bp->len) -return res; +if (res >= 0) +return 0; } if (channel_layout->nb_channels) av_bprintf(bp, "%d channels (", channel_layout->nb_channels); -- 2.31.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 v2 2/4] avutil/channel_layout: factorize ambisonic order detection
On 3/15/2022 6:18 PM, Marton Balint wrote: Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 42 +++--- libavutil/channel_layout.h | 1 + 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index c60ccf368f..0069c6257b 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -644,29 +644,31 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src) } /** - * If the custom layout is n-th order standard-order ambisonic, with optional - * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * If the layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, return the order. + * Return a negative error code otherwise. */ -static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +static int ambisonic_order(const AVChannelLayout *channel_layout) { int i, highest_ambi, order; highest_ambi = -1; -if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) +if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1; -else { +} else { nit: Remove these brackets since it's still a single line after the if statement. They bloat the diff for no gain. const AVChannelCustom *map = channel_layout->u.map; +av_assert0(channel_layout->order == AV_CHANNEL_ORDER_CUSTOM); + for (i = 0; i < channel_layout->nb_channels; i++) { int is_ambi = CHAN_IS_AMBI(map[i].id); /* ambisonic following non-ambisonic */ if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id)) -return 0; +return AVERROR(EINVAL); /* non-default ordering */ if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i) -return 0; +return AVERROR(EINVAL); if (CHAN_IS_AMBI(map[i].id)) highest_ambi = i; @@ -674,17 +676,33 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l } /* no ambisonic channels*/ if (highest_ambi < 0) -return 0; +return AVERROR(EINVAL); order = floor(sqrt(highest_ambi)); /* incomplete order - some harmonics are missing */ if ((order + 1) * (order + 1) != highest_ambi + 1) +return AVERROR(EINVAL); + +return order; +} + +/** + * If the custom layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, write its string description in bp. + * Return a negative error code on error. + */ +static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +{ +int nb_ambi_channels; +int order = ambisonic_order(channel_layout); +if (order < 0) return 0; av_bprintf(bp, "ambisonic %d", order); /* extra channels present */ -if (highest_ambi < channel_layout->nb_channels - 1) { +nb_ambi_channels = (order + 1) * (order + 1); +if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; char buf[128]; @@ -696,12 +714,12 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l const AVChannelCustom *map = channel_layout->u.map; extra.order = AV_CHANNEL_ORDER_CUSTOM; -extra.nb_channels = channel_layout->nb_channels - highest_ambi - 1; +extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); if (!extra.u.map) return AVERROR(ENOMEM); -memcpy(extra.u.map, &map[highest_ambi + 1], +memcpy(extra.u.map, &map[nb_ambi_channels], sizeof(*extra.u.map) * extra.nb_channels); } diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index 4dd6614de9..294e8b0773 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -27,6 +27,7 @@ #include "version.h" #include "attributes.h" +#include "avassert.h" Nothing in the header uses it. It'll become an unnecessary dependency every user of this header will have to deal with, so add it to channel_layout.c instead. /** * @file LGTM with the above two changes. ___ 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 3/4] avutil/channel_layout: do not copy alloc new map for extra channel layout
On 3/15/2022 6:18 PM, Marton Balint wrote: Also use av_channel_layout_bprint directly for describing channel layout for extra channels. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 17 - 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 0069c6257b..fb1f72737f 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -704,29 +704,20 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l nb_ambi_channels = (order + 1) * (order + 1); if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; -char buf[128]; if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { extra.order = AV_CHANNEL_ORDER_NATIVE; extra.nb_channels = av_popcount64(channel_layout->u.mask); extra.u.mask = channel_layout->u.mask; } else { -const AVChannelCustom *map = channel_layout->u.map; - extra.order = AV_CHANNEL_ORDER_CUSTOM; extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; -extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); -if (!extra.u.map) -return AVERROR(ENOMEM); - -memcpy(extra.u.map, &map[nb_ambi_channels], - sizeof(*extra.u.map) * extra.nb_channels); +extra.u.map = channel_layout->u.map + nb_ambi_channels; } -av_channel_layout_describe(&extra, buf, sizeof(buf)); -av_channel_layout_uninit(&extra); - -av_bprintf(bp, "+%s", buf); +av_bprint_chars(bp, '+', 1); +av_channel_layout_describe_bprint(&extra, bp); +/* Not calling uninit here on extra because we don't own the u.map pointer */ } return 0; LGTM. ___ 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 4/4] avutil/channel_layout: fix av_channel_layout_describe_bprint with custom and ambisonic channels
On 3/15/2022 6:18 PM, Marton Balint wrote: bp->len cannot be used to detect if try_describe_ambisonic was successful because the bprint buffer might contain other data as well. Also describing an invalid ambisonic layout should not return 0 but AVERROR(EINVAL) instead, so change try_describe_ambisonic to actually return error on invalid ambisonics. This also allows us to fix the first issue. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index fb1f72737f..1a141d4a6a 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -689,14 +689,14 @@ static int ambisonic_order(const AVChannelLayout *channel_layout) /** * If the custom layout is n-th order standard-order ambisonic, with optional * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * Return a negative error code otherwise. */ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) { int nb_ambi_channels; int order = ambisonic_order(channel_layout); if (order < 0) -return 0; +return order; av_bprintf(bp, "ambisonic %d", order); @@ -739,8 +739,8 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, case AV_CHANNEL_ORDER_CUSTOM: if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { int res = try_describe_ambisonic(bp, channel_layout); -if (res < 0 || bp->len) -return res; +if (res >= 0) +return 0; } if (channel_layout->nb_channels) av_bprintf(bp, "%d channels (", channel_layout->nb_channels); LGTM. ___ 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 2/4] avutil/channel_layout: factorize ambisonic order detection
On Tue, 15 Mar 2022, James Almer wrote: On 3/15/2022 6:18 PM, Marton Balint wrote: Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 42 +++--- libavutil/channel_layout.h | 1 + 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index c60ccf368f..0069c6257b 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -644,29 +644,31 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src) } /** - * If the custom layout is n-th order standard-order ambisonic, with optional - * extra non-diegetic channels at the end, write its string description in bp. - * Return a negative error code on error. + * If the layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, return the order. + * Return a negative error code otherwise. */ -static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +static int ambisonic_order(const AVChannelLayout *channel_layout) { int i, highest_ambi, order; highest_ambi = -1; -if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) +if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1; -else { +} else { nit: Remove these brackets since it's still a single line after the if statement. They bloat the diff for no gain. Ok. const AVChannelCustom *map = channel_layout->u.map; +av_assert0(channel_layout->order == AV_CHANNEL_ORDER_CUSTOM); + for (i = 0; i < channel_layout->nb_channels; i++) { int is_ambi = CHAN_IS_AMBI(map[i].id); /* ambisonic following non-ambisonic */ if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id)) -return 0; +return AVERROR(EINVAL); /* non-default ordering */ if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i) -return 0; +return AVERROR(EINVAL); if (CHAN_IS_AMBI(map[i].id)) highest_ambi = i; @@ -674,17 +676,33 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l } /* no ambisonic channels*/ if (highest_ambi < 0) -return 0; +return AVERROR(EINVAL); order = floor(sqrt(highest_ambi)); /* incomplete order - some harmonics are missing */ if ((order + 1) * (order + 1) != highest_ambi + 1) +return AVERROR(EINVAL); + +return order; +} + +/** + * If the custom layout is n-th order standard-order ambisonic, with optional + * extra non-diegetic channels at the end, write its string description in bp. + * Return a negative error code on error. + */ +static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) +{ +int nb_ambi_channels; +int order = ambisonic_order(channel_layout); +if (order < 0) return 0; av_bprintf(bp, "ambisonic %d", order); /* extra channels present */ -if (highest_ambi < channel_layout->nb_channels - 1) { +nb_ambi_channels = (order + 1) * (order + 1); +if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; char buf[128]; @@ -696,12 +714,12 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l const AVChannelCustom *map = channel_layout->u.map; extra.order = AV_CHANNEL_ORDER_CUSTOM; -extra.nb_channels = channel_layout->nb_channels - highest_ambi - 1; +extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); if (!extra.u.map) return AVERROR(ENOMEM); -memcpy(extra.u.map, &map[highest_ambi + 1], +memcpy(extra.u.map, &map[nb_ambi_channels], sizeof(*extra.u.map) * extra.nb_channels); } diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index 4dd6614de9..294e8b0773 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -27,6 +27,7 @@ #include "version.h" #include "attributes.h" +#include "avassert.h" Nothing in the header uses it. It'll become an unnecessary dependency every user of this header will have to deal with, so add it to channel_layout.c instead. Ok, I have no idea why I added it to the header... :) Thanks, Marton ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-dev
Re: [FFmpeg-devel] [PATCH] avformat/mov: Add support for still image AVIF parsing
On Thu, Mar 3, 2022 at 3:58 PM Vignesh Venkatasubramanian wrote: > > Add support for parsing AVIF still images. This patches supports > AVIF still images that have exactly 1 item (i.e.) no alpha channel. > Essentially, we will have to parse the "iloc" box and populate > the mov index. > > With this patch, we can decode still AVIF images like so: > ffmpeg -i image.avif image.png > > Partially fixes trac ticket #7621 > > Signed-off-by: Vignesh Venkatasubramanian > --- > libavformat/isom.h | 1 + > libavformat/mov.c | 142 + > 2 files changed, 143 insertions(+) > > diff --git a/libavformat/isom.h b/libavformat/isom.h > index 625dea8421..cc0a8e1ca9 100644 > --- a/libavformat/isom.h > +++ b/libavformat/isom.h > @@ -306,6 +306,7 @@ typedef struct MOVContext { > int have_read_mfra_size; > uint32_t mfra_size; > uint32_t max_stts_delta; > +int is_still_picture_avif; > } MOVContext; > > int ff_mp4_read_descr_len(AVIOContext *pb); > diff --git a/libavformat/mov.c b/libavformat/mov.c > index 68b6d7f075..d260024e47 100644 > --- a/libavformat/mov.c > +++ b/libavformat/mov.c > @@ -1126,6 +1126,7 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext > *pb, MOVAtom atom) > c->isom = 1; > av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char > *)&type); > av_dict_set(&c->fc->metadata, "major_brand", type, 0); > +c->is_still_picture_avif = !strncmp(type, "avif", 4); > minor_ver = avio_rb32(pb); /* minor version */ > av_dict_set_int(&c->fc->metadata, "minor_version", minor_ver, 0); > > @@ -7173,6 +7174,146 @@ cleanup: > return ret; > } > > +static int rb_size(AVIOContext *pb, uint64_t* value, int size) > +{ > +if (size == 0) { > +*value = 0; > +} else if (size == 1) { > +*value = avio_r8(pb); > +} else if (size == 2) { > +*value = avio_rb16(pb); > +} else if (size == 4) { > +*value = avio_rb32(pb); > +} else if (size == 8) { > +*value = avio_rb64(pb); > +} else { > +return -1; > +} > +return size; > +} > + > +static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom) > +{ > +int version, offset_size, length_size, base_offset_size, index_size; > +int item_count, extent_count; > +uint64_t base_offset, extent_offset, extent_length; > +int i, j; > +uint8_t value; > +AVStream *st; > +MOVStreamContext *sc; > + > +if (!c->is_still_picture_avif) { > +// * For non-avif, we simply ignore the iloc box. > +// * For animated avif, we don't care about the iloc box as all the > +// necessary information can be found in the moov box. > +return 0; > +} > + > +if (c->fc->nb_streams != 0) { > +av_log(c->fc, AV_LOG_INFO, "Duplicate iloc box found\n"); > +return 0; > +} > + > +st = avformat_new_stream(c->fc, NULL); > +if (!st) return AVERROR(ENOMEM); > +st->id = c->fc->nb_streams; > +sc = av_mallocz(sizeof(MOVStreamContext)); > +if (!sc) return AVERROR(ENOMEM); > + > +st->priv_data = sc; > +st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; > +st->codecpar->codec_id = AV_CODEC_ID_AV1; > +sc->ffindex = st->index; > +c->trak_index = st->index; > +st->avg_frame_rate.num = st->avg_frame_rate.den = 1; > +st->time_base.num = st->time_base.den = 1; > +st->nb_frames = 1; > +sc->time_scale = 1; > +sc = st->priv_data; > +sc->pb = c->fc->pb; > +sc->pb_is_copied = 1; > + > +version = avio_r8(pb); > +avio_rb24(pb); // flags. > + > +value = avio_r8(pb); > +offset_size = (value >> 4) & 0xF; > +length_size = value & 0xF; > +value = avio_r8(pb); > +base_offset_size = (value >> 4) & 0xF; > +index_size = (version == 0) ? 0 : (value & 0xF); > +if (index_size != 0) { > +return AVERROR_PATCHWELCOME; > +} > +item_count = (version < 2) ? avio_rb16(pb) : avio_rb32(pb); > +if (item_count > 1) { > +// For still AVIF images, we only support one item. Second item will > +// generally be found for AVIF images with alpha channel. We don't > +// support them as of now. > +return AVERROR_PATCHWELCOME; > +} > + > +// Populate the necessary fields used by mov_build_index. > +sc->stsc_count = item_count; > +sc->stsc_data = av_malloc_array(item_count, sizeof(*sc->stsc_data)); > +if (!sc->stsc_data) { > +return AVERROR(ENOMEM); > +} > +sc->stsc_data[0].first = 1; > +sc->stsc_data[0].count = 1; > +sc->stsc_data[0].id = 1; > +sc->chunk_count = item_count; > +sc->chunk_offsets = av_malloc_array(item_count, > sizeof(*sc->chunk_offsets)); > +if (!sc->chunk_offsets) { > +return AVERROR(ENOMEM); > +} > +sc->sample_count = item_count; > +sc->sample_sizes = av_malloc_array(item_count, > sizeof(*sc->sample_sizes)); > +if (!sc->sample_sizes) { > +
Re: [FFmpeg-devel] [PATCH] tests: Add fate-bsf-dv-error-marker
On Tue, Mar 15, 2022 at 03:35:08PM -0300, James Almer wrote: > > > On 3/15/2022 3:30 PM, Michael Niedermayer wrote: > > Signed-off-by: Michael Niedermayer > > --- > > tests/Makefile | 1 + > > tests/fate/dvvideo.mak | 6 ++ > > tests/ref/fate/bsf-dv-error-marker | 1 + > > 3 files changed, 8 insertions(+) > > create mode 100644 tests/fate/dvvideo.mak > > create mode 100644 tests/ref/fate/bsf-dv-error-marker > > > > diff --git a/tests/Makefile b/tests/Makefile > > index c4c31ae871..9f33394856 100644 > > --- a/tests/Makefile > > +++ b/tests/Makefile > > @@ -133,6 +133,7 @@ include $(SRC_PATH)/tests/fate/dfa.mak > > include $(SRC_PATH)/tests/fate/dnn.mak > > include $(SRC_PATH)/tests/fate/dnxhd.mak > > include $(SRC_PATH)/tests/fate/dpcm.mak > > +include $(SRC_PATH)/tests/fate/dvvideo.mak > > include $(SRC_PATH)/tests/fate/ea.mak > > include $(SRC_PATH)/tests/fate/exif.mak > > include $(SRC_PATH)/tests/fate/ffmpeg.mak > > diff --git a/tests/fate/dvvideo.mak b/tests/fate/dvvideo.mak > > new file mode 100644 > > index 00..3122a24f76 > > --- /dev/null > > +++ b/tests/fate/dvvideo.mak > > @@ -0,0 +1,6 @@ > > + > > +fate-bsf-dv-error-marker: CMD = md5 -i > > $(TARGET_SAMPLES)/dv/dvcprohd_720p50.mov -flags +bitexact -fflags +bitexact > > -c:v copy -bsf noise=100,dv_error_marker=color=blue -f avi > > Add > > fate-bsf-dv-error-marker: CMP = oneline > fate-bsf-dv-error-marker: REF = 4e884d3e8045299d0d45ec920fa58a44 > > So there's no need for the ref file below. ok will apply with that change thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If a bugfix only changes things apparently unrelated to the bug with no further explanation, that is a good sign that the bugfix is wrong. 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 3/4] avutil/channel_layout: do not copy alloc new map for extra channel layout
On Tue, 15 Mar 2022, James Almer wrote: On 3/15/2022 6:18 PM, Marton Balint wrote: Also use av_channel_layout_bprint directly for describing channel layout for extra channels. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 17 - 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 0069c6257b..fb1f72737f 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -704,29 +704,20 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l nb_ambi_channels = (order + 1) * (order + 1); if (nb_ambi_channels < channel_layout->nb_channels) { AVChannelLayout extra = { 0 }; -char buf[128]; if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) { extra.order = AV_CHANNEL_ORDER_NATIVE; extra.nb_channels = av_popcount64(channel_layout->u.mask); extra.u.mask = channel_layout->u.mask; } else { -const AVChannelCustom *map = channel_layout->u.map; - extra.order = AV_CHANNEL_ORDER_CUSTOM; extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; -extra.u.map = av_calloc(extra.nb_channels, sizeof(*extra.u.map)); -if (!extra.u.map) -return AVERROR(ENOMEM); - -memcpy(extra.u.map, &map[nb_ambi_channels], - sizeof(*extra.u.map) * extra.nb_channels); +extra.u.map = channel_layout->u.map + nb_ambi_channels; } -av_channel_layout_describe(&extra, buf, sizeof(buf)); -av_channel_layout_uninit(&extra); - -av_bprintf(bp, "+%s", buf); +av_bprint_chars(bp, '+', 1); +av_channel_layout_describe_bprint(&extra, bp); +/* Not calling uninit here on extra because we don't own the u.map pointer */ } return 0; LGTM. Thanks, applied the series (although in different order, because it turned out that this patch depends on the next). Thanks, Marton ___ 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] tools/target_dec_fuzzer: Fix build failure from channels API
Regression since 2f8ccca2fa94ce256ff77baa18f462c1abd8d2cc and surrounding commits Signed-off-by: Michael Niedermayer --- tools/target_dec_fuzzer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c index eaa26b0e62..3bd1eff3ce 100644 --- a/tools/target_dec_fuzzer.c +++ b/tools/target_dec_fuzzer.c @@ -47,6 +47,7 @@ #include "config.h" #include "libavutil/avassert.h" +#include "libavutil/avstring.h" #include "libavutil/cpu.h" #include "libavutil/imgutils.h" #include "libavutil/intreadwrite.h" @@ -273,7 +274,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { extradata_size = bytestream2_get_le32(&gbc); ctx->sample_rate= bytestream2_get_le32(&gbc) & 0x7FFF; -ctx->ch_layout.channels = (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS; +ctx->ch_layout.nb_channels = (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS; ctx->block_align= bytestream2_get_le32(&gbc) & 0x7FFF; ctx->codec_tag = bytestream2_get_le32(&gbc); if (c->codec_tags) { -- 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] [PATCH] tools/target_dec_fuzzer: Fix build failure from channels API
On 3/15/2022 7:34 PM, Michael Niedermayer wrote: Regression since 2f8ccca2fa94ce256ff77baa18f462c1abd8d2cc and surrounding commits Signed-off-by: Michael Niedermayer --- tools/target_dec_fuzzer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c index eaa26b0e62..3bd1eff3ce 100644 --- a/tools/target_dec_fuzzer.c +++ b/tools/target_dec_fuzzer.c @@ -47,6 +47,7 @@ #include "config.h" #include "libavutil/avassert.h" +#include "libavutil/avstring.h" Why? #include "libavutil/cpu.h" #include "libavutil/imgutils.h" #include "libavutil/intreadwrite.h" @@ -273,7 +274,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { extradata_size = bytestream2_get_le32(&gbc); ctx->sample_rate= bytestream2_get_le32(&gbc) & 0x7FFF; -ctx->ch_layout.channels = (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS; +ctx->ch_layout.nb_channels = (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS; LGTM, sorry about the breakage. ctx->block_align= bytestream2_get_le32(&gbc) & 0x7FFF; ctx->codec_tag = bytestream2_get_le32(&gbc); if (c->codec_tags) { ___ 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] tools/target_dec_fuzzer: Fix build failure from channels API
On Tue, Mar 15, 2022 at 07:45:36PM -0300, James Almer wrote: > On 3/15/2022 7:34 PM, Michael Niedermayer wrote: > > Regression since 2f8ccca2fa94ce256ff77baa18f462c1abd8d2cc and surrounding > > commits > > > > Signed-off-by: Michael Niedermayer > > --- > > tools/target_dec_fuzzer.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c > > index eaa26b0e62..3bd1eff3ce 100644 > > --- a/tools/target_dec_fuzzer.c > > +++ b/tools/target_dec_fuzzer.c > > @@ -47,6 +47,7 @@ > > #include "config.h" > > #include "libavutil/avassert.h" > > +#include "libavutil/avstring.h" > > Why? av_strlcatf() IIRC > > > #include "libavutil/cpu.h" > > #include "libavutil/imgutils.h" > > #include "libavutil/intreadwrite.h" > > @@ -273,7 +274,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t > > size) { > > extradata_size = bytestream2_get_le32(&gbc); > > ctx->sample_rate= > > bytestream2_get_le32(&gbc) & 0x7FFF; > > -ctx->ch_layout.channels = > > (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS; > > +ctx->ch_layout.nb_channels = > > (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS; > > LGTM, sorry about the breakage. will apply tomorrow, feel free to apply before thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope 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] tools/target_dec_fuzzer: Fix build failure from channels API
On 3/15/2022 9:33 PM, Michael Niedermayer wrote: On Tue, Mar 15, 2022 at 07:45:36PM -0300, James Almer wrote: On 3/15/2022 7:34 PM, Michael Niedermayer wrote: Regression since 2f8ccca2fa94ce256ff77baa18f462c1abd8d2cc and surrounding commits Signed-off-by: Michael Niedermayer --- tools/target_dec_fuzzer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c index eaa26b0e62..3bd1eff3ce 100644 --- a/tools/target_dec_fuzzer.c +++ b/tools/target_dec_fuzzer.c @@ -47,6 +47,7 @@ #include "config.h" #include "libavutil/avassert.h" +#include "libavutil/avstring.h" Why? av_strlcatf() IIRC Seems unrelated, but ok. #include "libavutil/cpu.h" #include "libavutil/imgutils.h" #include "libavutil/intreadwrite.h" @@ -273,7 +274,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { extradata_size = bytestream2_get_le32(&gbc); ctx->sample_rate= bytestream2_get_le32(&gbc) & 0x7FFF; -ctx->ch_layout.channels = (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS; +ctx->ch_layout.nb_channels = (unsigned)bytestream2_get_le32(&gbc) % FF_SANE_NB_CHANNELS; LGTM, sorry about the breakage. will apply tomorrow, feel free to apply before thx Applied. ___ 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 001/293 v8] avutil/channel_layout: Add a new channel layout API
On Mon, Jan 24, 2022 at 05:46:56PM -0300, James Almer wrote: > From: Anton Khirnov > > The new API is more extensible and allows for custom layouts. > More accurate information is exported, eg for decoders that do not > set a channel layout, lavc will not make one up for them. > > Deprecate the old API working with just uint64_t bitmasks. > > Expanded and completed by Vittorio Giovara > and James Almer . > Signed-off-by: Vittorio Giovara > Signed-off-by: James Almer > --- > Changes since last version: > > *Both av_channel_layout_describe() and av_channel_layout_from_string() now > support a "2 channels (FL+LFE)" syntax, to signal native (usually > non-standard) or custom order layouts. > *a single decimal value is now interpreted as a mask by > av_channel_layout_from_string(), same as a single hexadecimal value. > *De-duplicated code by simplifying av_channel_layout_channel_from_string(). > > The entire set can still be found in > https://github.com/jamrial/FFmpeg/commits/channel_layout4 > > libavutil/channel_layout.c | 661 + > libavutil/channel_layout.h | 551 +-- > libavutil/version.h| 1 + > 3 files changed, 1110 insertions(+), 103 deletions(-) didnt bisect but this ./ffmpeg -i ~/tickets/3542/out.mov -channel_layout stereo -acodec pcm_s16be file.mov fails after the patchset but not before [graph_0_in_0_0 @ 0x5642d659ec40] filter context - fmt: s16 r: 44100 layout: 3 ch: 2, incoming frame - fmt: s16 r: 44100 layout: 6000 ch: 2 pts_time: 0 [graph_0_in_0_0 @ 0x5642d659ec40] Changing audio frame properties on the fly is not supported. Error while filtering: Invalid argument Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0 Conversion failed! [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The bravest are surely those who have the clearest vision of what is before them, glory and danger alike, and yet notwithstanding go out to meet it. -- Thucydides 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 001/293 v8] avutil/channel_layout: Add a new channel layout API
On 3/15/2022 9:41 PM, Michael Niedermayer wrote: On Mon, Jan 24, 2022 at 05:46:56PM -0300, James Almer wrote: From: Anton Khirnov The new API is more extensible and allows for custom layouts. More accurate information is exported, eg for decoders that do not set a channel layout, lavc will not make one up for them. Deprecate the old API working with just uint64_t bitmasks. Expanded and completed by Vittorio Giovara and James Almer . Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- Changes since last version: *Both av_channel_layout_describe() and av_channel_layout_from_string() now support a "2 channels (FL+LFE)" syntax, to signal native (usually non-standard) or custom order layouts. *a single decimal value is now interpreted as a mask by av_channel_layout_from_string(), same as a single hexadecimal value. *De-duplicated code by simplifying av_channel_layout_channel_from_string(). The entire set can still be found in https://github.com/jamrial/FFmpeg/commits/channel_layout4 libavutil/channel_layout.c | 661 + libavutil/channel_layout.h | 551 +-- libavutil/version.h| 1 + 3 files changed, 1110 insertions(+), 103 deletions(-) didnt bisect but this ./ffmpeg -i ~/tickets/3542/out.mov -channel_layout stereo -acodec pcm_s16be file.mov fails after the patchset but not before [graph_0_in_0_0 @ 0x5642d659ec40] filter context - fmt: s16 r: 44100 layout: 3 ch: 2, incoming frame - fmt: s16 r: 44100 layout: 6000 ch: 2 pts_time: 0 [graph_0_in_0_0 @ 0x5642d659ec40] Changing audio frame properties on the fly is not supported. Error while filtering: Invalid argument Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0 Conversion failed! Should be fixed. ___ 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] ffplay: don't shadow global variable
--- fftools/ffplay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 92ad7ce1a6..b583225d53 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -1454,13 +1454,13 @@ static void check_external_clock_speed(VideoState *is) { } /* seek in the stream */ -static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_bytes) +static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int by_bytes) { if (!is->seek_req) { is->seek_pos = pos; is->seek_rel = rel; is->seek_flags &= ~AVSEEK_FLAG_BYTE; -if (seek_by_bytes) +if (by_bytes) is->seek_flags |= AVSEEK_FLAG_BYTE; is->seek_req = 1; SDL_CondSignal(is->continue_read_thread); -- 2.31.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".