* [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
@ 2024-04-05 18:57 Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 02/11] avcodec/encode: switch to avcodec_get_supported_config() Niklas Haas
` (12 more replies)
0 siblings, 13 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
This replaces the myriad of existing lists in AVCodec by a unified API
call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
substantially, while also making this more trivially extensible.
In addition to the already covered lists, add two new entries for color
space and color range, mirroring the newly added negotiable fields in
libavfilter.
I decided to drop the explicit length field from the API proposed by
Andreas Rheinhardt, because having it in place ended up complicating
both the codec side and the client side implementations, while also
being strictly less flexible (it's trivial to recover a length given
a terminator, but requires allocation to add a terminator given
a length). Using a terminator also presents less of a porting challenge
for existing users of the current API.
Once the deprecation period passes for the existing public fields, the
rough plan is to move the commonly used fields (such as
pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
configuration types, and then implement the rarely used fields with
custom callbacks.
---
doc/APIchanges | 5 ++++
libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++
libavcodec/avcodec.h | 27 ++++++++++++++++++++
libavcodec/codec.h | 19 +++++++++++---
libavcodec/codec_internal.h | 21 +++++++++++++++
libavcodec/version.h | 4 +--
6 files changed, 121 insertions(+), 6 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 0a39b6d7ab8..fdeae67159d 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,11 @@ The last version increases of all libraries were on 2024-03-07
API changes, most recent first:
+2024-04-xx - xxxxxxxxxx - lavc 59.6.100 - avcodec.h
+ Add avcodec_get_supported_config() and enum AVCodecConfig; deprecate
+ AVCodec.pix_fmts, AVCodec.sample_fmts, AVCodec.supported_framerates,
+ AVCodec.supported_samplerates and AVCodec.ch_layouts.
+
2024-04-03 - xxxxxxxxxx - lavu 59.13.100 - pixfmt.h
Add AVCOL_SPC_IPT_C2, AVCOL_SPC_YCGCO_RE and AVCOL_SPC_YCGCO_RO
to map new matrix coefficients defined by H.273 v3.
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 525fe516bd2..3615dc7c1f3 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -700,3 +700,54 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
return ff_decode_receive_frame(avctx, frame);
return ff_encode_receive_frame(avctx, frame);
}
+
+#define WRAP_CONFIG(allowed_type, field) \
+ do { \
+ if (codec->type != (allowed_type)) \
+ return AVERROR(EINVAL); \
+ *out_configs = (field); \
+ return 0; \
+ } while (0)
+
+int ff_default_get_supported_config(const AVCodecContext *avctx,
+ const AVCodec *codec,
+ enum AVCodecConfig config,
+ unsigned flags,
+ const void **out_configs)
+{
+ switch (config) {
+FF_DISABLE_DEPRECATION_WARNINGS
+ case AV_CODEC_CONFIG_PIX_FORMAT:
+ WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->pix_fmts);
+ case AV_CODEC_CONFIG_FRAME_RATE:
+ WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec->supported_framerates);
+ case AV_CODEC_CONFIG_SAMPLE_RATE:
+ WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->supported_samplerates);
+ case AV_CODEC_CONFIG_SAMPLE_FORMAT:
+ WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->sample_fmts);
+ case AV_CODEC_CONFIG_CHANNEL_LAYOUT:
+ WRAP_CONFIG(AVMEDIA_TYPE_AUDIO, codec->ch_layouts);
+FF_ENABLE_DEPRECATION_WARNINGS
+ case AV_CODEC_CONFIG_COLOR_RANGE:
+ case AV_CODEC_CONFIG_COLOR_SPACE:
+ *out_configs = NULL;
+ return 0;
+ default:
+ return AVERROR(EINVAL);
+ }
+}
+
+int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec,
+ enum AVCodecConfig config, unsigned flags,
+ const void **out)
+{
+ const FFCodec *codec2;
+ if (!codec)
+ codec = avctx->codec;
+ codec2 = ffcodec(codec);
+ if (codec2->get_supported_config) {
+ return codec2->get_supported_config(avctx, codec, config, flags, out);
+ } else {
+ return ff_default_get_supported_config(avctx, codec, config, flags, out);
+ }
+}
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 83dc487251c..64f31375fc6 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2690,6 +2690,33 @@ int avcodec_get_hw_frames_parameters(AVCodecContext *avctx,
enum AVPixelFormat hw_pix_fmt,
AVBufferRef **out_frames_ref);
+enum AVCodecConfig {
+ AV_CODEC_CONFIG_PIX_FORMAT, ///< AVPixelFormat, terminated by AV_PIX_FMT_NONE
+ AV_CODEC_CONFIG_FRAME_RATE, ///< AVRational, terminated by {0, 0}
+ AV_CODEC_CONFIG_SAMPLE_RATE, ///< int, terminated by 0
+ AV_CODEC_CONFIG_SAMPLE_FORMAT, ///< AVSampleFormat, terminated by AV_SAMPLE_FMT_NONE
+ AV_CODEC_CONFIG_CHANNEL_LAYOUT, ///< AVChannelLayout, terminated by {0}
+ AV_CODEC_CONFIG_COLOR_RANGE, ///< AVColorRange, terminated by AVCOL_RANGE_UNSPECIFIED
+ AV_CODEC_CONFIG_COLOR_SPACE, ///< AVColorSpace, terminated by AVCOL_SPC_UNSPECIFIED
+};
+
+/**
+ * Retrieve a list of all supported values for a given configuration type.
+ *
+ * @param avctx An optional context to use. Values such as
+ * `strict_std_compliance` may affect the result. If NULL,
+ * default values are used.
+ * @param codec The codec to query, or NULL to use avctx->codec.
+ * @param config The configuration to query.
+ * @param flags Currently unused; should be set to zero.
+ * @param out_configs On success, set to a list of configurations, terminated
+ * by a config-specific terminator, or NULL if all
+ * possible values are supported.
+ */
+int avcodec_get_supported_config(const AVCodecContext *avctx,
+ const AVCodec *codec, enum AVCodecConfig config,
+ unsigned flags, const void **out_configs);
+
/**
diff --git a/libavcodec/codec.h b/libavcodec/codec.h
index 6f9b42760d7..f7541ffc42b 100644
--- a/libavcodec/codec.h
+++ b/libavcodec/codec.h
@@ -205,10 +205,19 @@ typedef struct AVCodec {
*/
int capabilities;
uint8_t max_lowres; ///< maximum value for lowres supported by the decoder
- const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
- const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
- const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
- const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
+
+ /**
+ * Deprecated codec capabilities.
+ */
+ attribute_deprecated
+ const AVRational *supported_framerates; ///< @deprecated use avcodec_get_supported_config()
+ attribute_deprecated
+ const enum AVPixelFormat *pix_fmts; ///< @deprecated use avcodec_get_supported_config()
+ attribute_deprecated
+ const int *supported_samplerates; ///< @deprecated use avcodec_get_supported_config()
+ attribute_deprecated
+ const enum AVSampleFormat *sample_fmts; ///< @deprecated use avcodec_get_supported_config()
+
const AVClass *priv_class; ///< AVClass for the private context
const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {AV_PROFILE_UNKNOWN}
@@ -226,7 +235,9 @@ typedef struct AVCodec {
/**
* Array of supported channel layouts, terminated with a zeroed layout.
+ * @deprecated use avcodec_get_supported_config()
*/
+ attribute_deprecated
const AVChannelLayout *ch_layouts;
} AVCodec;
diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h
index d6757e2deff..3c6328364cb 100644
--- a/libavcodec/codec_internal.h
+++ b/libavcodec/codec_internal.h
@@ -22,6 +22,7 @@
#include <stdint.h>
#include "libavutil/attributes.h"
+#include "avcodec.h"
#include "codec.h"
#include "config.h"
@@ -264,8 +265,28 @@ typedef struct FFCodec {
* List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
*/
const uint32_t *codec_tags;
+
+ /**
+ * Custom callback for avcodec_get_supported_config(). If absent,
+ * ff_default_get_supported_config() will be used.
+ */
+ int (*get_supported_config)(const AVCodecContext *avctx,
+ const AVCodec *codec,
+ enum AVCodecConfig config,
+ unsigned flags,
+ const void **out_configs);
} FFCodec;
+/**
+ * Default implementation for avcodec_get_supported_config(). Will return the
+ * relevant fields from AVCodec if present, or NULL otherwise.
+ */
+int ff_default_get_supported_config(const AVCodecContext *avctx,
+ const AVCodec *codec,
+ enum AVCodecConfig config,
+ unsigned flags,
+ const void **out_configs);
+
#if CONFIG_SMALL
#define CODEC_LONG_NAME(str) .p.long_name = NULL
#else
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 84a1c02ce4a..da54f878874 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,8 +29,8 @@
#include "version_major.h"
-#define LIBAVCODEC_VERSION_MINOR 5
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MINOR 6
+#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 02/11] avcodec/encode: switch to avcodec_get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 03/11] avcodec/allcodecs: add backcompat for new config API Niklas Haas
` (11 subsequent siblings)
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
---
libavcodec/encode.c | 88 ++++++++++++++++++++++++++++-----------------
1 file changed, 55 insertions(+), 33 deletions(-)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 34658d13d0c..d0e79379048 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -563,7 +563,8 @@ static int encode_preinit_video(AVCodecContext *avctx)
{
const AVCodec *c = avctx->codec;
const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
- int i;
+ const enum AVPixelFormat *pix_fmts;
+ int ret, i;
if (!av_get_pix_fmt_name(avctx->pix_fmt)) {
av_log(avctx, AV_LOG_ERROR, "Invalid video pixel format: %d\n",
@@ -571,28 +572,33 @@ static int encode_preinit_video(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- if (c->pix_fmts) {
- for (i = 0; c->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
- if (avctx->pix_fmt == c->pix_fmts[i])
+ ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT,
+ 0, (const void **) &pix_fmts);
+ if (ret < 0)
+ return ret;
+
+ if (pix_fmts) {
+ for (i = 0; pix_fmts[i] != AV_PIX_FMT_NONE; i++)
+ if (avctx->pix_fmt == pix_fmts[i])
break;
- if (c->pix_fmts[i] == AV_PIX_FMT_NONE) {
+ if (pix_fmts[i] == AV_PIX_FMT_NONE) {
av_log(avctx, AV_LOG_ERROR,
"Specified pixel format %s is not supported by the %s encoder.\n",
av_get_pix_fmt_name(avctx->pix_fmt), c->name);
av_log(avctx, AV_LOG_ERROR, "Supported pixel formats:\n");
- for (int p = 0; c->pix_fmts[p] != AV_PIX_FMT_NONE; p++) {
+ for (int p = 0; pix_fmts[p] != AV_PIX_FMT_NONE; p++) {
av_log(avctx, AV_LOG_ERROR, " %s\n",
- av_get_pix_fmt_name(c->pix_fmts[p]));
+ av_get_pix_fmt_name(pix_fmts[p]));
}
return AVERROR(EINVAL);
}
- if (c->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
- c->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
- c->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
- c->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
- c->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
+ if (pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
+ pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
+ pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
+ pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
+ pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
avctx->color_range = AVCOL_RANGE_JPEG;
}
@@ -646,7 +652,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
static int encode_preinit_audio(AVCodecContext *avctx)
{
const AVCodec *c = avctx->codec;
- int i;
+ const enum AVSampleFormat *sample_fmts;
+ const int *supported_samplerates;
+ const AVChannelLayout *ch_layouts;
+ int ret, i;
if (!av_get_sample_fmt_name(avctx->sample_fmt)) {
av_log(avctx, AV_LOG_ERROR, "Invalid audio sample format: %d\n",
@@ -659,53 +668,66 @@ static int encode_preinit_audio(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- if (c->sample_fmts) {
- for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
- if (avctx->sample_fmt == c->sample_fmts[i])
+ ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_FORMAT,
+ 0, (const void **) &sample_fmts);
+ if (ret < 0)
+ return ret;
+ if (sample_fmts) {
+ for (i = 0; sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
+ if (avctx->sample_fmt == sample_fmts[i])
break;
if (avctx->ch_layout.nb_channels == 1 &&
av_get_planar_sample_fmt(avctx->sample_fmt) ==
- av_get_planar_sample_fmt(c->sample_fmts[i])) {
- avctx->sample_fmt = c->sample_fmts[i];
+ av_get_planar_sample_fmt(sample_fmts[i])) {
+ avctx->sample_fmt = sample_fmts[i];
break;
}
}
- if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
+ if (sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
av_log(avctx, AV_LOG_ERROR,
"Specified sample format %s is not supported by the %s encoder\n",
av_get_sample_fmt_name(avctx->sample_fmt), c->name);
av_log(avctx, AV_LOG_ERROR, "Supported sample formats:\n");
- for (int p = 0; c->sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) {
+ for (int p = 0; sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) {
av_log(avctx, AV_LOG_ERROR, " %s\n",
- av_get_sample_fmt_name(c->sample_fmts[p]));
+ av_get_sample_fmt_name(sample_fmts[p]));
}
return AVERROR(EINVAL);
}
}
- if (c->supported_samplerates) {
- for (i = 0; c->supported_samplerates[i] != 0; i++)
- if (avctx->sample_rate == c->supported_samplerates[i])
+
+ ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_RATE,
+ 0, (const void **) &supported_samplerates);
+ if (ret < 0)
+ return ret;
+ if (supported_samplerates) {
+ for (i = 0; supported_samplerates[i] != 0; i++)
+ if (avctx->sample_rate == supported_samplerates[i])
break;
- if (c->supported_samplerates[i] == 0) {
+ if (supported_samplerates[i] == 0) {
av_log(avctx, AV_LOG_ERROR,
"Specified sample rate %d is not supported by the %s encoder\n",
avctx->sample_rate, c->name);
av_log(avctx, AV_LOG_ERROR, "Supported sample rates:\n");
- for (int p = 0; c->supported_samplerates[p]; p++)
- av_log(avctx, AV_LOG_ERROR, " %d\n", c->supported_samplerates[p]);
+ for (int p = 0; supported_samplerates[p]; p++)
+ av_log(avctx, AV_LOG_ERROR, " %d\n", supported_samplerates[p]);
return AVERROR(EINVAL);
}
}
- if (c->ch_layouts) {
- for (i = 0; c->ch_layouts[i].nb_channels; i++) {
- if (!av_channel_layout_compare(&avctx->ch_layout, &c->ch_layouts[i]))
+ ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_CHANNEL_LAYOUT,
+ 0, (const void **) &ch_layouts);
+ if (ret < 0)
+ return ret;
+ if (ch_layouts) {
+ for (i = 0; ch_layouts[i].nb_channels; i++) {
+ if (!av_channel_layout_compare(&avctx->ch_layout, &ch_layouts[i]))
break;
}
- if (!c->ch_layouts[i].nb_channels) {
+ if (!ch_layouts[i].nb_channels) {
char buf[512];
int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
av_log(avctx, AV_LOG_ERROR,
@@ -713,8 +735,8 @@ static int encode_preinit_audio(AVCodecContext *avctx)
ret > 0 ? buf : "?", c->name);
av_log(avctx, AV_LOG_ERROR, "Supported channel layouts:\n");
- for (int p = 0; c->ch_layouts[p].nb_channels; p++) {
- ret = av_channel_layout_describe(&c->ch_layouts[p], buf, sizeof(buf));
+ for (int p = 0; ch_layouts[p].nb_channels; p++) {
+ ret = av_channel_layout_describe(&ch_layouts[p], buf, sizeof(buf));
av_log(avctx, AV_LOG_ERROR, " %s\n", ret > 0 ? buf : "?");
}
return AVERROR(EINVAL);
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 03/11] avcodec/allcodecs: add backcompat for new config API
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 02/11] avcodec/encode: switch to avcodec_get_supported_config() Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 04/11] avcodec/libx265: switch to get_supported_config() Niklas Haas
` (10 subsequent siblings)
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
In order to avoid breaking older clients not yet using the new API, we
need to add backwards compatibility for codecs which have switched from
init_static() to get_supported_config().
This function can be removed entirely once the deprecated static fields
are removed.
---
libavcodec/allcodecs.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index f4705651fb8..a9f1797930a 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -916,8 +916,41 @@ static AVOnce av_codec_static_init = AV_ONCE_INIT;
static void av_codec_init_static(void)
{
for (int i = 0; codec_list[i]; i++) {
- if (codec_list[i]->init_static_data)
- codec_list[i]->init_static_data((FFCodec*)codec_list[i]);
+ const FFCodec *codec = codec_list[i];
+ if (codec->init_static_data) {
+ codec->init_static_data((FFCodec*) codec);
+ continue;
+ }
+
+ /* Backward compatibility with deprecated public fields */
+ if (!codec->get_supported_config)
+ continue;
+
+FF_DISABLE_DEPRECATION_WARNINGS
+ switch (codec->p.type) {
+ case AVMEDIA_TYPE_VIDEO:
+ codec->get_supported_config(NULL, &codec->p,
+ AV_CODEC_CONFIG_PIX_FORMAT, 0,
+ (const void **) &codec->p.pix_fmts);
+ codec->get_supported_config(NULL, &codec->p,
+ AV_CODEC_CONFIG_FRAME_RATE, 0,
+ (const void **) &codec->p.supported_framerates);
+ break;
+ case AVMEDIA_TYPE_AUDIO:
+ codec->get_supported_config(NULL, &codec->p,
+ AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
+ (const void **) &codec->p.sample_fmts);
+ codec->get_supported_config(NULL, &codec->p,
+ AV_CODEC_CONFIG_SAMPLE_RATE, 0,
+ (const void **) &codec->p.supported_samplerates);
+ codec->get_supported_config(NULL, &codec->p,
+ AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
+ (const void **) &codec->p.ch_layouts);
+ break;
+ default:
+ break;
+ }
+FF_ENABLE_DEPRECATION_WARNINGS
}
}
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 04/11] avcodec/libx265: switch to get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 02/11] avcodec/encode: switch to avcodec_get_supported_config() Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 03/11] avcodec/allcodecs: add backcompat for new config API Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 05/11] avcodec/libvpxenc: " Niklas Haas
` (9 subsequent siblings)
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
---
libavcodec/libx265.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 0645cd20457..ff1e8463aa1 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -892,14 +892,24 @@ static const enum AVPixelFormat x265_csp_twelve[] = {
AV_PIX_FMT_NONE
};
-static av_cold void libx265_encode_init_csp(FFCodec *codec)
+static int libx265_get_supported_config(const AVCodecContext *avctx,
+ const AVCodec *codec,
+ enum AVCodecConfig config,
+ unsigned flags, const void **out)
{
- if (x265_api_get(12))
- codec->p.pix_fmts = x265_csp_twelve;
- else if (x265_api_get(10))
- codec->p.pix_fmts = x265_csp_ten;
- else if (x265_api_get(8))
- codec->p.pix_fmts = x265_csp_eight;
+ if (config == AV_CODEC_CONFIG_PIX_FORMAT) {
+ if (x265_api_get(12))
+ *out = x265_csp_twelve;
+ else if (x265_api_get(10))
+ *out = x265_csp_ten;
+ else if (x265_api_get(8))
+ *out = x265_csp_eight;
+ else
+ return AVERROR_EXTERNAL;
+ return 0;
+ }
+
+ return ff_default_get_supported_config(avctx, codec, config, flags, out);
}
#define OFFSET(x) offsetof(libx265Context, x)
@@ -951,7 +961,7 @@ FFCodec ff_libx265_encoder = {
.p.priv_class = &class,
.p.wrapper_name = "libx265",
.init = libx265_encode_init,
- .init_static_data = libx265_encode_init_csp,
+ .get_supported_config = libx265_get_supported_config,
FF_CODEC_ENCODE_CB(libx265_encode_frame),
.close = libx265_encode_close,
.priv_data_size = sizeof(libx265Context),
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 05/11] avcodec/libvpxenc: switch to get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (2 preceding siblings ...)
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 04/11] avcodec/libx265: switch to get_supported_config() Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 06/11] avcodec/libaomenc: " Niklas Haas
` (8 subsequent siblings)
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
---
libavcodec/libvpxenc.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index bcbdc4981e5..ac7f01e2aa9 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -2086,13 +2086,21 @@ static const enum AVPixelFormat vp9_pix_fmts_highbd[] = {
AV_PIX_FMT_NONE
};
-static av_cold void vp9_init_static(FFCodec *codec)
+static int vp9_get_supported_config(const AVCodecContext *avctx,
+ const AVCodec *codec,
+ enum AVCodecConfig config,
+ unsigned flags, const void **out)
{
- vpx_codec_caps_t codec_caps = vpx_codec_get_caps(vpx_codec_vp9_cx());
- if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH)
- codec->p.pix_fmts = vp9_pix_fmts_highbd;
- else
- codec->p.pix_fmts = vp9_pix_fmts_highcol;
+ if (config == AV_CODEC_CONFIG_PIX_FORMAT) {
+ vpx_codec_caps_t codec_caps = vpx_codec_get_caps(vpx_codec_vp9_cx());
+ if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH)
+ *out = vp9_pix_fmts_highbd;
+ else
+ *out = vp9_pix_fmts_highcol;
+ return 0;
+ }
+
+ return ff_default_get_supported_config(avctx, codec, config, flags, out);
}
static const AVClass class_vp9 = {
@@ -2120,6 +2128,6 @@ FFCodec ff_libvpx_vp9_encoder = {
.caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
FF_CODEC_CAP_AUTO_THREADS,
.defaults = defaults,
- .init_static_data = vp9_init_static,
+ .get_supported_config = vp9_get_supported_config,
};
#endif /* CONFIG_LIBVPX_VP9_ENCODER */
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 06/11] avcodec/libaomenc: switch to get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (3 preceding siblings ...)
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 05/11] avcodec/libvpxenc: " Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 07/11] avcodec/codec_internal: nuke init_static_data() Niklas Haas
` (7 subsequent siblings)
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
---
libavcodec/libaomenc.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 4a71bba9c9c..899aa2b261f 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -1398,16 +1398,24 @@ static const enum AVPixelFormat av1_pix_fmts_highbd_with_gray[] = {
AV_PIX_FMT_NONE
};
-static av_cold void av1_init_static(FFCodec *codec)
+static int av1_get_supported_config(const AVCodecContext *avctx,
+ const AVCodec *codec,
+ enum AVCodecConfig config,
+ unsigned flags, const void **out)
{
- int supports_monochrome = aom_codec_version() >= 20001;
- aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
- if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
- codec->p.pix_fmts = supports_monochrome ? av1_pix_fmts_highbd_with_gray :
- av1_pix_fmts_highbd;
- else
- codec->p.pix_fmts = supports_monochrome ? av1_pix_fmts_with_gray :
- av1_pix_fmts;
+ if (config == AV_CODEC_CONFIG_PIX_FORMAT) {
+ int supports_monochrome = aom_codec_version() >= 20001;
+ aom_codec_caps_t codec_caps = aom_codec_get_caps(aom_codec_av1_cx());
+ if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH)
+ *out = supports_monochrome ? av1_pix_fmts_highbd_with_gray :
+ av1_pix_fmts_highbd;
+ else
+ *out = supports_monochrome ? av1_pix_fmts_with_gray :
+ av1_pix_fmts;
+ return 0;
+ }
+
+ return ff_default_get_supported_config(avctx, codec, config, flags, out);
}
static av_cold int av1_init(AVCodecContext *avctx)
@@ -1528,5 +1536,5 @@ FFCodec ff_libaom_av1_encoder = {
FF_CODEC_CAP_INIT_CLEANUP |
FF_CODEC_CAP_AUTO_THREADS,
.defaults = defaults,
- .init_static_data = av1_init_static,
+ .get_supported_config = av1_get_supported_config,
};
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 07/11] avcodec/codec_internal: nuke init_static_data()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (4 preceding siblings ...)
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 06/11] avcodec/libaomenc: " Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 08/11] fftools/opt_common: switch to avcodec_get_supported_config() Niklas Haas
` (6 subsequent siblings)
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
All hail get_supported_config()
---
libavcodec/allcodecs.c | 7 +------
libavcodec/codec_internal.h | 8 --------
2 files changed, 1 insertion(+), 14 deletions(-)
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a9f1797930a..1f22e06e710 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -916,13 +916,8 @@ static AVOnce av_codec_static_init = AV_ONCE_INIT;
static void av_codec_init_static(void)
{
for (int i = 0; codec_list[i]; i++) {
- const FFCodec *codec = codec_list[i];
- if (codec->init_static_data) {
- codec->init_static_data((FFCodec*) codec);
- continue;
- }
-
/* Backward compatibility with deprecated public fields */
+ const FFCodec *codec = codec_list[i];
if (!codec->get_supported_config)
continue;
diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h
index 3c6328364cb..f4e97d0fbcd 100644
--- a/libavcodec/codec_internal.h
+++ b/libavcodec/codec_internal.h
@@ -168,14 +168,6 @@ typedef struct FFCodec {
*/
const FFCodecDefault *defaults;
- /**
- * Initialize codec static data, called from av_codec_iterate().
- *
- * This is not intended for time consuming operations as it is
- * run for every codec regardless of that codec being used.
- */
- void (*init_static_data)(struct FFCodec *codec);
-
int (*init)(struct AVCodecContext *);
union {
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 08/11] fftools/opt_common: switch to avcodec_get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (5 preceding siblings ...)
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 07/11] avcodec/codec_internal: nuke init_static_data() Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 19:36 ` James Almer
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 09/11] fftools: drop unused/hacky macros Niklas Haas
` (5 subsequent siblings)
12 siblings, 1 reply; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
While rewriting this macro, I decided to make it a bit more flexible so
it can work for all of the fields (including future fields) in a more
generic way.
---
fftools/opt_common.c | 86 ++++++++++++++++++++++----------------------
1 file changed, 43 insertions(+), 43 deletions(-)
diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 947a226d8d1..1bf66580192 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -262,22 +262,32 @@ int show_buildconf(void *optctx, const char *opt, const char *arg)
return 0;
}
-#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
- if (codec->field) { \
- const type *p = codec->field; \
- \
- printf(" Supported " list_name ":"); \
- while (*p != term) { \
- get_name(*p); \
- printf(" %s", name); \
- p++; \
- } \
- printf("\n"); \
- } \
+#define PRINT_CODEC_SUPPORTED(codec, config, type, name, elem, cond, fmt, ...) \
+ do { \
+ const type *elem = NULL; \
+ avcodec_get_supported_config(NULL, codec, config, 0, \
+ (const void **) &elem); \
+ if (elem) { \
+ printf(" Supported " name ":"); \
+ while (cond) { \
+ printf(" " fmt, __VA_ARGS__); \
+ elem++; \
+ } \
+ printf("\n"); \
+ } \
+ } while (0)
+
+static char *get_channel_layout_desc(const AVChannelLayout *layout,
+ char desc[], int desc_size)
+{
+ av_channel_layout_describe(layout, desc, desc_size);
+ return desc;
+}
static void print_codec(const AVCodec *c)
{
int encoder = av_codec_is_encoder(c);
+ char desc[128];
printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
c->long_name ? c->long_name : "");
@@ -343,35 +353,19 @@ static void print_codec(const AVCodec *c)
printf("\n");
}
- if (c->supported_framerates) {
- const AVRational *fps = c->supported_framerates;
-
- printf(" Supported framerates:");
- while (fps->num) {
- printf(" %d/%d", fps->num, fps->den);
- fps++;
- }
- printf("\n");
- }
- PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
- AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
- PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
- GET_SAMPLE_RATE_NAME);
- PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
- AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
-
- if (c->ch_layouts) {
- const AVChannelLayout *p = c->ch_layouts;
-
- printf(" Supported channel layouts:");
- while (p->nb_channels) {
- char name[128];
- av_channel_layout_describe(p, name, sizeof(name));
- printf(" %s", name);
- p++;
- }
- printf("\n");
- }
+ PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_FRAME_RATE, AVRational, "framerates",
+ fps, fps->num, "%d/%d", fps->num, fps->den);
+ PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_PIX_FORMAT, enum AVPixelFormat,
+ "pixel formats", fmt, *fmt != AV_PIX_FMT_NONE,
+ "%s", av_get_pix_fmt_name(*fmt));
+ PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_RATE, int, "sample rates",
+ rate, *rate != 0, "%d", *rate);
+ PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_FORMAT, enum AVSampleFormat,
+ "sample formats", fmt, *fmt != AV_SAMPLE_FMT_NONE,
+ "%s", av_get_sample_fmt_name(*fmt));
+ PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_CHANNEL_LAYOUT, AVChannelLayout,
+ "channel layouts", layout, layout->nb_channels,
+ "%s", get_channel_layout_desc(layout, desc, sizeof(desc)));
if (c->priv_class) {
show_help_children(c->priv_class,
@@ -566,8 +560,14 @@ static void show_help_bsf(const char *name)
}
printf("Bit stream filter %s\n", bsf->name);
- PRINT_CODEC_SUPPORTED(bsf, codec_ids, enum AVCodecID, "codecs",
- AV_CODEC_ID_NONE, GET_CODEC_NAME);
+ if (bsf->codec_ids) {
+ const enum AVCodecID *id = bsf->codec_ids;
+ printf(" Supported codecs:");
+ while (*id != AV_CODEC_ID_NONE) {
+ printf(" %s", avcodec_descriptor_get(*id)->name);
+ id++;
+ }
+ }
if (bsf->priv_class)
show_help_children(bsf->priv_class, AV_OPT_FLAG_BSF_PARAM);
}
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 09/11] fftools: drop unused/hacky macros
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (6 preceding siblings ...)
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 08/11] fftools/opt_common: switch to avcodec_get_supported_config() Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 10/11] fftools/ffmpeg_mux_init: switch to avcodec_get_supported_config() Niklas Haas
` (4 subsequent siblings)
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
Having macros initialize local variables seems strange to me, and there
are no more current users of these macros. (The one that was commented
out was incorrect anyway, since the macro has changed in the meantime)
---
fftools/cmdutils.h | 13 -------------
fftools/ffmpeg_filter.c | 2 +-
2 files changed, 1 insertion(+), 14 deletions(-)
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index d0c773663ba..940541b9eaf 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -465,19 +465,6 @@ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
#define GROW_ARRAY(array, nb_elems)\
grow_array((void**)&array, sizeof(*array), &nb_elems, nb_elems + 1)
-#define GET_PIX_FMT_NAME(pix_fmt)\
- const char *name = av_get_pix_fmt_name(pix_fmt);
-
-#define GET_CODEC_NAME(id)\
- const char *name = avcodec_descriptor_get(id)->name;
-
-#define GET_SAMPLE_FMT_NAME(sample_fmt)\
- const char *name = av_get_sample_fmt_name(sample_fmt)
-
-#define GET_SAMPLE_RATE_NAME(rate)\
- char name[16];\
- snprintf(name, sizeof(name), "%d", rate);
-
double get_rotation(const int32_t *displaymatrix);
/* read file contents into a string */
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 2308abf82af..ac04841a16c 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -401,7 +401,7 @@ static void choose_ ## name (OutputFilterPriv *ofp, AVBPrint *bprint) \
}
//DEF_CHOOSE_FORMAT(pix_fmts, enum AVPixelFormat, format, formats, AV_PIX_FMT_NONE,
-// GET_PIX_FMT_NAME)
+// av_get_pix_fmt_name)
DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats,
AV_SAMPLE_FMT_NONE, "%s", av_get_sample_fmt_name)
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 10/11] fftools/ffmpeg_mux_init: switch to avcodec_get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (7 preceding siblings ...)
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 09/11] fftools: drop unused/hacky macros Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 11/11] fftools/ffmpeg_filter: " Niklas Haas
` (3 subsequent siblings)
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
---
fftools/ffmpeg_mux_init.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index d3d7d022ff6..508c4f7a697 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -511,13 +511,19 @@ static int fmt_in_list(const int *formats, int format)
}
static enum AVPixelFormat
-choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
+choose_pixel_fmt(const AVCodecContext *avctx, enum AVPixelFormat target)
{
- const enum AVPixelFormat *p = codec->pix_fmts;
+ const enum AVPixelFormat *p;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
//FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
enum AVPixelFormat best= AV_PIX_FMT_NONE;
+ int ret;
+
+ ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT,
+ 0, (const void **) &p);
+ if (ret < 0)
+ return AV_PIX_FMT_NONE;
for (; *p != AV_PIX_FMT_NONE; p++) {
best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
@@ -529,7 +535,7 @@ choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
av_log(NULL, AV_LOG_WARNING,
"Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
av_get_pix_fmt_name(target),
- codec->name,
+ avctx->codec->name,
av_get_pix_fmt_name(best));
return best;
}
@@ -538,8 +544,9 @@ choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
{
- const enum AVPixelFormat *fmts = ost->enc_ctx->codec->pix_fmts;
+ const enum AVPixelFormat *fmts;// = ost->enc_ctx->codec->pix_fmts;
enum AVPixelFormat fmt;
+ int ret;
fmt = av_get_pix_fmt(name);
if (fmt == AV_PIX_FMT_NONE) {
@@ -547,6 +554,11 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
return AV_PIX_FMT_NONE;
}
+ ret = avcodec_get_supported_config(ost->enc_ctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT,
+ 0, (const void **) fmts);
+ if (ret < 0)
+ return AV_PIX_FMT_NONE;
+
/* when the user specified-format is an alias for an endianness-specific
* one (e.g. rgb48 -> rgb48be/le), it gets translated into the native
* endianness by av_get_pix_fmt();
@@ -574,7 +586,7 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
}
if (fmts && !fmt_in_list(fmts, fmt))
- fmt = choose_pixel_fmt(ost->enc_ctx->codec, fmt);
+ fmt = choose_pixel_fmt(ost->enc_ctx, fmt);
return fmt;
}
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* [FFmpeg-devel] [PATCH 11/11] fftools/ffmpeg_filter: switch to avcodec_get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (8 preceding siblings ...)
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 10/11] fftools/ffmpeg_mux_init: switch to avcodec_get_supported_config() Niklas Haas
@ 2024-04-05 18:57 ` Niklas Haas
2024-04-05 19:01 ` [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (2 subsequent siblings)
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 18:57 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
From: Niklas Haas <git@haasn.dev>
I preserved the no-op condition on `!ch_layouts`, even though I suspect
it's not actually needed.
---
fftools/ffmpeg_filter.c | 59 ++++++++++++++++++++++++++++++++---------
1 file changed, 46 insertions(+), 13 deletions(-)
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index ac04841a16c..e617b9da289 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -724,7 +724,7 @@ static int ifilter_bind_dec(InputFilterPriv *ifp, Decoder *dec)
static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
{
- const AVCodec *c = ost->enc_ctx->codec;
+ const AVChannelLayout *ch_layouts;
int i, err;
if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
@@ -735,8 +735,14 @@ static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
return 0;
}
+ err = avcodec_get_supported_config(ost->enc_ctx, NULL,
+ AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
+ (const void **) &ch_layouts);
+ if (err < 0)
+ return err;
+
/* Requested layout is of order UNSPEC */
- if (!c->ch_layouts) {
+ if (!ch_layouts) {
/* Use the default native layout for the requested amount of channels when the
encoder doesn't have a list of supported layouts */
av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
@@ -744,13 +750,13 @@ static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost)
}
/* Encoder has a list of supported layouts. Pick the first layout in it with the
same amount of channels as the requested layout */
- for (i = 0; c->ch_layouts[i].nb_channels; i++) {
- if (c->ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels)
+ for (i = 0; ch_layouts[i].nb_channels; i++) {
+ if (ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels)
break;
}
- if (c->ch_layouts[i].nb_channels) {
+ if (ch_layouts[i].nb_channels) {
/* Use it if one is found */
- err = av_channel_layout_copy(&f->ch_layout, &c->ch_layouts[i]);
+ err = av_channel_layout_copy(&f->ch_layout, &ch_layouts[i]);
if (err < 0)
return err;
return 0;
@@ -787,7 +793,11 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
ofp->format = ost->enc_ctx->pix_fmt;
} else {
- ofp->formats = c->pix_fmts;
+ ret = avcodec_get_supported_config(ost->enc_ctx, NULL,
+ AV_CODEC_CONFIG_PIX_FORMAT, 0,
+ (const void **) &ofp->formats);
+ if (ret < 0)
+ return ret;
// MJPEG encoder exports a full list of supported pixel formats,
// but the full-range ones are experimental-only.
@@ -822,8 +832,16 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
ofp->fps.framerate = ost->frame_rate;
ofp->fps.framerate_max = ost->max_frame_rate;
- ofp->fps.framerate_supported = ost->force_fps ?
- NULL : c->supported_framerates;
+
+ if (ost->force_fps) {
+ ofp->fps.framerate_supported = NULL;
+ } else {
+ ret = avcodec_get_supported_config(ost->enc_ctx, NULL,
+ AV_CODEC_CONFIG_FRAME_RATE, 0,
+ (const void **) &ofp->fps.framerate_supported);
+ if (ret < 0)
+ return ret;
+ }
// reduce frame rate for mpeg4 to be within the spec limits
if (c->id == AV_CODEC_ID_MPEG4)
@@ -836,19 +854,34 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost,
if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
ofp->format = ost->enc_ctx->sample_fmt;
} else {
- ofp->formats = c->sample_fmts;
+ ret = avcodec_get_supported_config(ost->enc_ctx, NULL,
+ AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
+ (const void **) &ofp->formats);
+ if (ret < 0)
+ return ret;
}
if (ost->enc_ctx->sample_rate) {
ofp->sample_rate = ost->enc_ctx->sample_rate;
} else {
- ofp->sample_rates = c->supported_samplerates;
+ ret = avcodec_get_supported_config(ost->enc_ctx, NULL,
+ AV_CODEC_CONFIG_SAMPLE_RATE, 0,
+ (const void **) &ofp->sample_rates);
+ if (ret < 0)
+ return ret;
}
if (ost->enc_ctx->ch_layout.nb_channels) {
int ret = set_channel_layout(ofp, ost);
if (ret < 0)
return ret;
- } else if (c->ch_layouts) {
- ofp->ch_layouts = c->ch_layouts;
+ } else {
+ const AVChannelLayout *ch_layouts;
+ ret = avcodec_get_supported_config(ost->enc_ctx, NULL,
+ AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0,
+ (const void **) &ch_layouts);
+ if (ret < 0)
+ return ret;
+ if (ch_layouts)
+ ofp->ch_layouts = ch_layouts;
}
break;
}
--
2.44.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (9 preceding siblings ...)
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 11/11] fftools/ffmpeg_filter: " Niklas Haas
@ 2024-04-05 19:01 ` Niklas Haas
2024-04-06 23:16 ` Michael Niedermayer
2024-04-08 20:18 ` Michael Niedermayer
12 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-05 19:01 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Niklas Haas
On Fri, 05 Apr 2024 20:57:11 +0200 Niklas Haas <ffmpeg@haasn.xyz> wrote:
> From: Niklas Haas <git@haasn.dev>
> In addition to the already covered lists, add two new entries for color
> space and color range, mirroring the newly added negotiable fields in
> libavfilter.
If this passes review, I will submit a second series implementing these
new fields for relevant codecs.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 08/11] fftools/opt_common: switch to avcodec_get_supported_config()
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 08/11] fftools/opt_common: switch to avcodec_get_supported_config() Niklas Haas
@ 2024-04-05 19:36 ` James Almer
2024-04-06 11:38 ` Niklas Haas
0 siblings, 1 reply; 24+ messages in thread
From: James Almer @ 2024-04-05 19:36 UTC (permalink / raw)
To: ffmpeg-devel
On 4/5/2024 3:57 PM, Niklas Haas wrote:
> From: Niklas Haas <git@haasn.dev>
>
> While rewriting this macro, I decided to make it a bit more flexible so
> it can work for all of the fields (including future fields) in a more
> generic way.
> ---
> fftools/opt_common.c | 86 ++++++++++++++++++++++----------------------
> 1 file changed, 43 insertions(+), 43 deletions(-)
>
> diff --git a/fftools/opt_common.c b/fftools/opt_common.c
> index 947a226d8d1..1bf66580192 100644
> --- a/fftools/opt_common.c
> +++ b/fftools/opt_common.c
> @@ -262,22 +262,32 @@ int show_buildconf(void *optctx, const char *opt, const char *arg)
> return 0;
> }
>
> -#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
> - if (codec->field) { \
> - const type *p = codec->field; \
> - \
> - printf(" Supported " list_name ":"); \
> - while (*p != term) { \
> - get_name(*p); \
> - printf(" %s", name); \
> - p++; \
> - } \
> - printf("\n"); \
> - } \
> +#define PRINT_CODEC_SUPPORTED(codec, config, type, name, elem, cond, fmt, ...) \
> + do { \
> + const type *elem = NULL; \
> + avcodec_get_supported_config(NULL, codec, config, 0, \
> + (const void **) &elem); \
> + if (elem) { \
> + printf(" Supported " name ":"); \
> + while (cond) { \
> + printf(" " fmt, __VA_ARGS__); \
> + elem++; \
> + } \
> + printf("\n"); \
> + } \
> + } while (0)
> +
> +static char *get_channel_layout_desc(const AVChannelLayout *layout,
> + char desc[], int desc_size)
> +{
> + av_channel_layout_describe(layout, desc, desc_size);
> + return desc;
> +}
>
> static void print_codec(const AVCodec *c)
> {
> int encoder = av_codec_is_encoder(c);
> + char desc[128];
>
> printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
> c->long_name ? c->long_name : "");
> @@ -343,35 +353,19 @@ static void print_codec(const AVCodec *c)
> printf("\n");
> }
>
> - if (c->supported_framerates) {
> - const AVRational *fps = c->supported_framerates;
> -
> - printf(" Supported framerates:");
> - while (fps->num) {
> - printf(" %d/%d", fps->num, fps->den);
> - fps++;
> - }
> - printf("\n");
> - }
> - PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
> - AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
> - PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
> - GET_SAMPLE_RATE_NAME);
> - PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
> - AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
> -
> - if (c->ch_layouts) {
> - const AVChannelLayout *p = c->ch_layouts;
> -
> - printf(" Supported channel layouts:");
> - while (p->nb_channels) {
> - char name[128];
> - av_channel_layout_describe(p, name, sizeof(name));
> - printf(" %s", name);
> - p++;
> - }
> - printf("\n");
> - }
> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_FRAME_RATE, AVRational, "framerates",
> + fps, fps->num, "%d/%d", fps->num, fps->den);
> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_PIX_FORMAT, enum AVPixelFormat,
> + "pixel formats", fmt, *fmt != AV_PIX_FMT_NONE,
> + "%s", av_get_pix_fmt_name(*fmt));
> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_RATE, int, "sample rates",
> + rate, *rate != 0, "%d", *rate);
> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_FORMAT, enum AVSampleFormat,
> + "sample formats", fmt, *fmt != AV_SAMPLE_FMT_NONE,
> + "%s", av_get_sample_fmt_name(*fmt));
> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_CHANNEL_LAYOUT, AVChannelLayout,
> + "channel layouts", layout, layout->nb_channels,
> + "%s", get_channel_layout_desc(layout, desc, sizeof(desc)));
Since you're rewriting everything, might as well go and port this to
AVBprint, so we're not limited to 128 bytes for the channel layout.
You can use av_bprintf() to write to the buffer using the different
specifiers, then printf() the final bprint buffer to stdout.
>
> if (c->priv_class) {
> show_help_children(c->priv_class,
> @@ -566,8 +560,14 @@ static void show_help_bsf(const char *name)
> }
>
> printf("Bit stream filter %s\n", bsf->name);
> - PRINT_CODEC_SUPPORTED(bsf, codec_ids, enum AVCodecID, "codecs",
> - AV_CODEC_ID_NONE, GET_CODEC_NAME);
> + if (bsf->codec_ids) {
> + const enum AVCodecID *id = bsf->codec_ids;
> + printf(" Supported codecs:");
> + while (*id != AV_CODEC_ID_NONE) {
> + printf(" %s", avcodec_descriptor_get(*id)->name);
> + id++;
> + }
> + }
> if (bsf->priv_class)
> show_help_children(bsf->priv_class, AV_OPT_FLAG_BSF_PARAM);
> }
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 08/11] fftools/opt_common: switch to avcodec_get_supported_config()
2024-04-05 19:36 ` James Almer
@ 2024-04-06 11:38 ` Niklas Haas
2024-04-07 0:10 ` James Almer
0 siblings, 1 reply; 24+ messages in thread
From: Niklas Haas @ 2024-04-06 11:38 UTC (permalink / raw)
To: ffmpeg-devel
On Fri, 05 Apr 2024 16:36:50 -0300 James Almer <jamrial@gmail.com> wrote:
> On 4/5/2024 3:57 PM, Niklas Haas wrote:
> > From: Niklas Haas <git@haasn.dev>
> >
> > While rewriting this macro, I decided to make it a bit more flexible so
> > it can work for all of the fields (including future fields) in a more
> > generic way.
> > ---
> > fftools/opt_common.c | 86 ++++++++++++++++++++++----------------------
> > 1 file changed, 43 insertions(+), 43 deletions(-)
> >
> > diff --git a/fftools/opt_common.c b/fftools/opt_common.c
> > index 947a226d8d1..1bf66580192 100644
> > --- a/fftools/opt_common.c
> > +++ b/fftools/opt_common.c
> > @@ -262,22 +262,32 @@ int show_buildconf(void *optctx, const char *opt, const char *arg)
> > return 0;
> > }
> >
> > -#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
> > - if (codec->field) { \
> > - const type *p = codec->field; \
> > - \
> > - printf(" Supported " list_name ":"); \
> > - while (*p != term) { \
> > - get_name(*p); \
> > - printf(" %s", name); \
> > - p++; \
> > - } \
> > - printf("\n"); \
> > - } \
> > +#define PRINT_CODEC_SUPPORTED(codec, config, type, name, elem, cond, fmt, ...) \
> > + do { \
> > + const type *elem = NULL; \
> > + avcodec_get_supported_config(NULL, codec, config, 0, \
> > + (const void **) &elem); \
> > + if (elem) { \
> > + printf(" Supported " name ":"); \
> > + while (cond) { \
> > + printf(" " fmt, __VA_ARGS__); \
> > + elem++; \
> > + } \
> > + printf("\n"); \
> > + } \
> > + } while (0)
> > +
> > +static char *get_channel_layout_desc(const AVChannelLayout *layout,
> > + char desc[], int desc_size)
> > +{
> > + av_channel_layout_describe(layout, desc, desc_size);
> > + return desc;
> > +}
> >
> > static void print_codec(const AVCodec *c)
> > {
> > int encoder = av_codec_is_encoder(c);
> > + char desc[128];
> >
> > printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
> > c->long_name ? c->long_name : "");
> > @@ -343,35 +353,19 @@ static void print_codec(const AVCodec *c)
> > printf("\n");
> > }
> >
> > - if (c->supported_framerates) {
> > - const AVRational *fps = c->supported_framerates;
> > -
> > - printf(" Supported framerates:");
> > - while (fps->num) {
> > - printf(" %d/%d", fps->num, fps->den);
> > - fps++;
> > - }
> > - printf("\n");
> > - }
> > - PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
> > - AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
> > - PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
> > - GET_SAMPLE_RATE_NAME);
> > - PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
> > - AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
> > -
> > - if (c->ch_layouts) {
> > - const AVChannelLayout *p = c->ch_layouts;
> > -
> > - printf(" Supported channel layouts:");
> > - while (p->nb_channels) {
> > - char name[128];
> > - av_channel_layout_describe(p, name, sizeof(name));
> > - printf(" %s", name);
> > - p++;
> > - }
> > - printf("\n");
> > - }
> > + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_FRAME_RATE, AVRational, "framerates",
> > + fps, fps->num, "%d/%d", fps->num, fps->den);
> > + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_PIX_FORMAT, enum AVPixelFormat,
> > + "pixel formats", fmt, *fmt != AV_PIX_FMT_NONE,
> > + "%s", av_get_pix_fmt_name(*fmt));
> > + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_RATE, int, "sample rates",
> > + rate, *rate != 0, "%d", *rate);
> > + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_FORMAT, enum AVSampleFormat,
> > + "sample formats", fmt, *fmt != AV_SAMPLE_FMT_NONE,
> > + "%s", av_get_sample_fmt_name(*fmt));
> > + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_CHANNEL_LAYOUT, AVChannelLayout,
> > + "channel layouts", layout, layout->nb_channels,
> > + "%s", get_channel_layout_desc(layout, desc, sizeof(desc)));
>
> Since you're rewriting everything, might as well go and port this to
> AVBprint, so we're not limited to 128 bytes for the channel layout.
> You can use av_bprintf() to write to the buffer using the different
> specifiers, then printf() the final bprint buffer to stdout.
I implemented something like this initially, but it is IMO premature
optimization as there is no multi-threading going on in this code, so no
risk of colliding printf() calls. printf() already internally buffers
data, so we are not gaining anything by buffering it inside an AVBPrint
a second time.
That said, using an AVBPrint instead of a fixed size buffer is a good
idea for the channel layout specifically, something like this:
diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 1bf66580192..fae68949f89 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -277,17 +277,17 @@ int show_buildconf(void *optctx, const char *opt, const char *arg)
} \
} while (0)
-static char *get_channel_layout_desc(const AVChannelLayout *layout,
- char desc[], int desc_size)
+static char *get_channel_layout_desc(const AVChannelLayout *layout, AVBPrint *bp)
{
- av_channel_layout_describe(layout, desc, desc_size);
- return desc;
+ av_bprint_clear(bp);
+ av_channel_layout_describe_bprintf(layout, bp);
+ return bp->str;
}
static void print_codec(const AVCodec *c)
{
int encoder = av_codec_is_encoder(c);
- char desc[128];
+ AVBPrint desc;
printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
c->long_name ? c->long_name : "");
@@ -363,9 +363,12 @@ static void print_codec(const AVCodec *c)
PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_FORMAT, enum AVSampleFormat,
"sample formats", fmt, *fmt != AV_SAMPLE_FMT_NONE,
"%s", av_get_sample_fmt_name(*fmt));
+
+ av_bprint_init(&desc, AV_BPRINT_SIZE_AUTOMATIC);
PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_CHANNEL_LAYOUT, AVChannelLayout,
"channel layouts", layout, layout->nb_channels,
- "%s", get_channel_layout_desc(layout, desc, sizeof(desc)));
+ "%s", get_channel_layout_desc(layout, &desc));
+ av_bprint_finalize(&desc, NULL);
if (c->priv_class) {
show_help_children(c->priv_class,
>
> >
> > if (c->priv_class) {
> > show_help_children(c->priv_class,
> > @@ -566,8 +560,14 @@ static void show_help_bsf(const char *name)
> > }
> >
> > printf("Bit stream filter %s\n", bsf->name);
> > - PRINT_CODEC_SUPPORTED(bsf, codec_ids, enum AVCodecID, "codecs",
> > - AV_CODEC_ID_NONE, GET_CODEC_NAME);
> > + if (bsf->codec_ids) {
> > + const enum AVCodecID *id = bsf->codec_ids;
> > + printf(" Supported codecs:");
> > + while (*id != AV_CODEC_ID_NONE) {
> > + printf(" %s", avcodec_descriptor_get(*id)->name);
> > + id++;
> > + }
> > + }
> > if (bsf->priv_class)
> > show_help_children(bsf->priv_class, AV_OPT_FLAG_BSF_PARAM);
> > }
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (10 preceding siblings ...)
2024-04-05 19:01 ` [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
@ 2024-04-06 23:16 ` Michael Niedermayer
2024-04-07 11:47 ` Anton Khirnov
2024-04-08 11:15 ` Niklas Haas
2024-04-08 20:18 ` Michael Niedermayer
12 siblings, 2 replies; 24+ messages in thread
From: Michael Niedermayer @ 2024-04-06 23:16 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2014 bytes --]
On Fri, Apr 05, 2024 at 08:57:11PM +0200, Niklas Haas wrote:
> From: Niklas Haas <git@haasn.dev>
>
> This replaces the myriad of existing lists in AVCodec by a unified API
> call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
> substantially, while also making this more trivially extensible.
>
> In addition to the already covered lists, add two new entries for color
> space and color range, mirroring the newly added negotiable fields in
> libavfilter.
>
> I decided to drop the explicit length field from the API proposed by
> Andreas Rheinhardt, because having it in place ended up complicating
> both the codec side and the client side implementations, while also
> being strictly less flexible (it's trivial to recover a length given
> a terminator, but requires allocation to add a terminator given
> a length). Using a terminator also presents less of a porting challenge
> for existing users of the current API.
>
> Once the deprecation period passes for the existing public fields, the
> rough plan is to move the commonly used fields (such as
> pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
> configuration types, and then implement the rarely used fields with
> custom callbacks.
> ---
> doc/APIchanges | 5 ++++
> libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++
> libavcodec/avcodec.h | 27 ++++++++++++++++++++
> libavcodec/codec.h | 19 +++++++++++---
> libavcodec/codec_internal.h | 21 +++++++++++++++
> libavcodec/version.h | 4 +--
> 6 files changed, 121 insertions(+), 6 deletions(-)
If the API is changed, it should be to an API that allows externally
maintained codecs.
(it would result in more developers working on codecs)
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
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 08/11] fftools/opt_common: switch to avcodec_get_supported_config()
2024-04-06 11:38 ` Niklas Haas
@ 2024-04-07 0:10 ` James Almer
2024-04-08 11:15 ` Niklas Haas
0 siblings, 1 reply; 24+ messages in thread
From: James Almer @ 2024-04-07 0:10 UTC (permalink / raw)
To: ffmpeg-devel
On 4/6/2024 8:38 AM, Niklas Haas wrote:
> On Fri, 05 Apr 2024 16:36:50 -0300 James Almer <jamrial@gmail.com> wrote:
>> On 4/5/2024 3:57 PM, Niklas Haas wrote:
>>> From: Niklas Haas <git@haasn.dev>
>>>
>>> While rewriting this macro, I decided to make it a bit more flexible so
>>> it can work for all of the fields (including future fields) in a more
>>> generic way.
>>> ---
>>> fftools/opt_common.c | 86 ++++++++++++++++++++++----------------------
>>> 1 file changed, 43 insertions(+), 43 deletions(-)
>>>
>>> diff --git a/fftools/opt_common.c b/fftools/opt_common.c
>>> index 947a226d8d1..1bf66580192 100644
>>> --- a/fftools/opt_common.c
>>> +++ b/fftools/opt_common.c
>>> @@ -262,22 +262,32 @@ int show_buildconf(void *optctx, const char *opt, const char *arg)
>>> return 0;
>>> }
>>>
>>> -#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
>>> - if (codec->field) { \
>>> - const type *p = codec->field; \
>>> - \
>>> - printf(" Supported " list_name ":"); \
>>> - while (*p != term) { \
>>> - get_name(*p); \
>>> - printf(" %s", name); \
>>> - p++; \
>>> - } \
>>> - printf("\n"); \
>>> - } \
>>> +#define PRINT_CODEC_SUPPORTED(codec, config, type, name, elem, cond, fmt, ...) \
>>> + do { \
>>> + const type *elem = NULL; \
>>> + avcodec_get_supported_config(NULL, codec, config, 0, \
>>> + (const void **) &elem); \
>>> + if (elem) { \
>>> + printf(" Supported " name ":"); \
>>> + while (cond) { \
>>> + printf(" " fmt, __VA_ARGS__); \
>>> + elem++; \
>>> + } \
>>> + printf("\n"); \
>>> + } \
>>> + } while (0)
>>> +
>>> +static char *get_channel_layout_desc(const AVChannelLayout *layout,
>>> + char desc[], int desc_size)
>>> +{
>>> + av_channel_layout_describe(layout, desc, desc_size);
>>> + return desc;
>>> +}
>>>
>>> static void print_codec(const AVCodec *c)
>>> {
>>> int encoder = av_codec_is_encoder(c);
>>> + char desc[128];
>>>
>>> printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
>>> c->long_name ? c->long_name : "");
>>> @@ -343,35 +353,19 @@ static void print_codec(const AVCodec *c)
>>> printf("\n");
>>> }
>>>
>>> - if (c->supported_framerates) {
>>> - const AVRational *fps = c->supported_framerates;
>>> -
>>> - printf(" Supported framerates:");
>>> - while (fps->num) {
>>> - printf(" %d/%d", fps->num, fps->den);
>>> - fps++;
>>> - }
>>> - printf("\n");
>>> - }
>>> - PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
>>> - AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
>>> - PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
>>> - GET_SAMPLE_RATE_NAME);
>>> - PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
>>> - AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
>>> -
>>> - if (c->ch_layouts) {
>>> - const AVChannelLayout *p = c->ch_layouts;
>>> -
>>> - printf(" Supported channel layouts:");
>>> - while (p->nb_channels) {
>>> - char name[128];
>>> - av_channel_layout_describe(p, name, sizeof(name));
>>> - printf(" %s", name);
>>> - p++;
>>> - }
>>> - printf("\n");
>>> - }
>>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_FRAME_RATE, AVRational, "framerates",
>>> + fps, fps->num, "%d/%d", fps->num, fps->den);
>>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_PIX_FORMAT, enum AVPixelFormat,
>>> + "pixel formats", fmt, *fmt != AV_PIX_FMT_NONE,
>>> + "%s", av_get_pix_fmt_name(*fmt));
>>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_RATE, int, "sample rates",
>>> + rate, *rate != 0, "%d", *rate);
>>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_FORMAT, enum AVSampleFormat,
>>> + "sample formats", fmt, *fmt != AV_SAMPLE_FMT_NONE,
>>> + "%s", av_get_sample_fmt_name(*fmt));
>>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_CHANNEL_LAYOUT, AVChannelLayout,
>>> + "channel layouts", layout, layout->nb_channels,
>>> + "%s", get_channel_layout_desc(layout, desc, sizeof(desc)));
>>
>> Since you're rewriting everything, might as well go and port this to
>> AVBprint, so we're not limited to 128 bytes for the channel layout.
>> You can use av_bprintf() to write to the buffer using the different
>> specifiers, then printf() the final bprint buffer to stdout.
>
> I implemented something like this initially, but it is IMO premature
> optimization as there is no multi-threading going on in this code, so no
> risk of colliding printf() calls. printf() already internally buffers
> data, so we are not gaining anything by buffering it inside an AVBPrint
> a second time.
>
> That said, using an AVBPrint instead of a fixed size buffer is a good
> idea for the channel layout specifically, something like this:
>
>
> diff --git a/fftools/opt_common.c b/fftools/opt_common.c
> index 1bf66580192..fae68949f89 100644
> --- a/fftools/opt_common.c
> +++ b/fftools/opt_common.c
> @@ -277,17 +277,17 @@ int show_buildconf(void *optctx, const char *opt, const char *arg)
> } \
> } while (0)
>
> -static char *get_channel_layout_desc(const AVChannelLayout *layout,
> - char desc[], int desc_size)
> +static char *get_channel_layout_desc(const AVChannelLayout *layout, AVBPrint *bp)
> {
> - av_channel_layout_describe(layout, desc, desc_size);
> - return desc;
> + av_bprint_clear(bp);
I don't think this is needed if it's called immediately after
av_bprint_init().
> + av_channel_layout_describe_bprintf(layout, bp);
> + return bp->str;
> }
>
> static void print_codec(const AVCodec *c)
> {
> int encoder = av_codec_is_encoder(c);
> - char desc[128];
> + AVBPrint desc;
>
> printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
> c->long_name ? c->long_name : "");
> @@ -363,9 +363,12 @@ static void print_codec(const AVCodec *c)
> PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_FORMAT, enum AVSampleFormat,
> "sample formats", fmt, *fmt != AV_SAMPLE_FMT_NONE,
> "%s", av_get_sample_fmt_name(*fmt));
> +
> + av_bprint_init(&desc, AV_BPRINT_SIZE_AUTOMATIC);
> PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_CHANNEL_LAYOUT, AVChannelLayout,
> "channel layouts", layout, layout->nb_channels,
> - "%s", get_channel_layout_desc(layout, desc, sizeof(desc)));
> + "%s", get_channel_layout_desc(layout, &desc));
> + av_bprint_finalize(&desc, NULL);
Yeah, this is good. Thanks.
>
> if (c->priv_class) {
> show_help_children(c->priv_class,
>
>>
>>>
>>> if (c->priv_class) {
>>> show_help_children(c->priv_class,
>>> @@ -566,8 +560,14 @@ static void show_help_bsf(const char *name)
>>> }
>>>
>>> printf("Bit stream filter %s\n", bsf->name);
>>> - PRINT_CODEC_SUPPORTED(bsf, codec_ids, enum AVCodecID, "codecs",
>>> - AV_CODEC_ID_NONE, GET_CODEC_NAME);
>>> + if (bsf->codec_ids) {
>>> + const enum AVCodecID *id = bsf->codec_ids;
>>> + printf(" Supported codecs:");
>>> + while (*id != AV_CODEC_ID_NONE) {
>>> + printf(" %s", avcodec_descriptor_get(*id)->name);
>>> + id++;
>>> + }
>>> + }
>>> if (bsf->priv_class)
>>> show_help_children(bsf->priv_class, AV_OPT_FLAG_BSF_PARAM);
>>> }
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
2024-04-06 23:16 ` Michael Niedermayer
@ 2024-04-07 11:47 ` Anton Khirnov
2024-04-08 11:15 ` Niklas Haas
1 sibling, 0 replies; 24+ messages in thread
From: Anton Khirnov @ 2024-04-07 11:47 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Michael Niedermayer (2024-04-07 01:16:39)
> On Fri, Apr 05, 2024 at 08:57:11PM +0200, Niklas Haas wrote:
> > From: Niklas Haas <git@haasn.dev>
> >
> > This replaces the myriad of existing lists in AVCodec by a unified API
> > call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
> > substantially, while also making this more trivially extensible.
> >
> > In addition to the already covered lists, add two new entries for color
> > space and color range, mirroring the newly added negotiable fields in
> > libavfilter.
> >
> > I decided to drop the explicit length field from the API proposed by
> > Andreas Rheinhardt, because having it in place ended up complicating
> > both the codec side and the client side implementations, while also
> > being strictly less flexible (it's trivial to recover a length given
> > a terminator, but requires allocation to add a terminator given
> > a length). Using a terminator also presents less of a porting challenge
> > for existing users of the current API.
> >
> > Once the deprecation period passes for the existing public fields, the
> > rough plan is to move the commonly used fields (such as
> > pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
> > configuration types, and then implement the rarely used fields with
> > custom callbacks.
> > ---
> > doc/APIchanges | 5 ++++
> > libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++
> > libavcodec/avcodec.h | 27 ++++++++++++++++++++
> > libavcodec/codec.h | 19 +++++++++++---
> > libavcodec/codec_internal.h | 21 +++++++++++++++
> > libavcodec/version.h | 4 +--
> > 6 files changed, 121 insertions(+), 6 deletions(-)
>
> If the API is changed, it should be to an API that allows externally
> maintained codecs.
> (it would result in more developers working on codecs)
????
This seems like a complete non sequitur in relation to this patch.
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
2024-04-06 23:16 ` Michael Niedermayer
2024-04-07 11:47 ` Anton Khirnov
@ 2024-04-08 11:15 ` Niklas Haas
1 sibling, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-08 11:15 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, 07 Apr 2024 01:16:39 +0200 Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Fri, Apr 05, 2024 at 08:57:11PM +0200, Niklas Haas wrote:
> > From: Niklas Haas <git@haasn.dev>
> >
> > This replaces the myriad of existing lists in AVCodec by a unified API
> > call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
> > substantially, while also making this more trivially extensible.
> >
> > In addition to the already covered lists, add two new entries for color
> > space and color range, mirroring the newly added negotiable fields in
> > libavfilter.
> >
> > I decided to drop the explicit length field from the API proposed by
> > Andreas Rheinhardt, because having it in place ended up complicating
> > both the codec side and the client side implementations, while also
> > being strictly less flexible (it's trivial to recover a length given
> > a terminator, but requires allocation to add a terminator given
> > a length). Using a terminator also presents less of a porting challenge
> > for existing users of the current API.
> >
> > Once the deprecation period passes for the existing public fields, the
> > rough plan is to move the commonly used fields (such as
> > pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
> > configuration types, and then implement the rarely used fields with
> > custom callbacks.
> > ---
> > doc/APIchanges | 5 ++++
> > libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++
> > libavcodec/avcodec.h | 27 ++++++++++++++++++++
> > libavcodec/codec.h | 19 +++++++++++---
> > libavcodec/codec_internal.h | 21 +++++++++++++++
> > libavcodec/version.h | 4 +--
> > 6 files changed, 121 insertions(+), 6 deletions(-)
>
> If the API is changed, it should be to an API that allows externally
> maintained codecs.
> (it would result in more developers working on codecs)
The only way this could work is by making all of FFCodec public, which
is orthogonal to the API proposed here.
>
> 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
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 08/11] fftools/opt_common: switch to avcodec_get_supported_config()
2024-04-07 0:10 ` James Almer
@ 2024-04-08 11:15 ` Niklas Haas
0 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-04-08 11:15 UTC (permalink / raw)
To: ffmpeg-devel
On Sat, 06 Apr 2024 21:10:45 -0300 James Almer <jamrial@gmail.com> wrote:
> On 4/6/2024 8:38 AM, Niklas Haas wrote:
> > On Fri, 05 Apr 2024 16:36:50 -0300 James Almer <jamrial@gmail.com> wrote:
> >> On 4/5/2024 3:57 PM, Niklas Haas wrote:
> >>> From: Niklas Haas <git@haasn.dev>
> >>>
> >>> While rewriting this macro, I decided to make it a bit more flexible so
> >>> it can work for all of the fields (including future fields) in a more
> >>> generic way.
> >>> ---
> >>> fftools/opt_common.c | 86 ++++++++++++++++++++++----------------------
> >>> 1 file changed, 43 insertions(+), 43 deletions(-)
> >>>
> >>> diff --git a/fftools/opt_common.c b/fftools/opt_common.c
> >>> index 947a226d8d1..1bf66580192 100644
> >>> --- a/fftools/opt_common.c
> >>> +++ b/fftools/opt_common.c
> >>> @@ -262,22 +262,32 @@ int show_buildconf(void *optctx, const char *opt, const char *arg)
> >>> return 0;
> >>> }
> >>>
> >>> -#define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
> >>> - if (codec->field) { \
> >>> - const type *p = codec->field; \
> >>> - \
> >>> - printf(" Supported " list_name ":"); \
> >>> - while (*p != term) { \
> >>> - get_name(*p); \
> >>> - printf(" %s", name); \
> >>> - p++; \
> >>> - } \
> >>> - printf("\n"); \
> >>> - } \
> >>> +#define PRINT_CODEC_SUPPORTED(codec, config, type, name, elem, cond, fmt, ...) \
> >>> + do { \
> >>> + const type *elem = NULL; \
> >>> + avcodec_get_supported_config(NULL, codec, config, 0, \
> >>> + (const void **) &elem); \
> >>> + if (elem) { \
> >>> + printf(" Supported " name ":"); \
> >>> + while (cond) { \
> >>> + printf(" " fmt, __VA_ARGS__); \
> >>> + elem++; \
> >>> + } \
> >>> + printf("\n"); \
> >>> + } \
> >>> + } while (0)
> >>> +
> >>> +static char *get_channel_layout_desc(const AVChannelLayout *layout,
> >>> + char desc[], int desc_size)
> >>> +{
> >>> + av_channel_layout_describe(layout, desc, desc_size);
> >>> + return desc;
> >>> +}
> >>>
> >>> static void print_codec(const AVCodec *c)
> >>> {
> >>> int encoder = av_codec_is_encoder(c);
> >>> + char desc[128];
> >>>
> >>> printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
> >>> c->long_name ? c->long_name : "");
> >>> @@ -343,35 +353,19 @@ static void print_codec(const AVCodec *c)
> >>> printf("\n");
> >>> }
> >>>
> >>> - if (c->supported_framerates) {
> >>> - const AVRational *fps = c->supported_framerates;
> >>> -
> >>> - printf(" Supported framerates:");
> >>> - while (fps->num) {
> >>> - printf(" %d/%d", fps->num, fps->den);
> >>> - fps++;
> >>> - }
> >>> - printf("\n");
> >>> - }
> >>> - PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
> >>> - AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
> >>> - PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
> >>> - GET_SAMPLE_RATE_NAME);
> >>> - PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
> >>> - AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
> >>> -
> >>> - if (c->ch_layouts) {
> >>> - const AVChannelLayout *p = c->ch_layouts;
> >>> -
> >>> - printf(" Supported channel layouts:");
> >>> - while (p->nb_channels) {
> >>> - char name[128];
> >>> - av_channel_layout_describe(p, name, sizeof(name));
> >>> - printf(" %s", name);
> >>> - p++;
> >>> - }
> >>> - printf("\n");
> >>> - }
> >>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_FRAME_RATE, AVRational, "framerates",
> >>> + fps, fps->num, "%d/%d", fps->num, fps->den);
> >>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_PIX_FORMAT, enum AVPixelFormat,
> >>> + "pixel formats", fmt, *fmt != AV_PIX_FMT_NONE,
> >>> + "%s", av_get_pix_fmt_name(*fmt));
> >>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_RATE, int, "sample rates",
> >>> + rate, *rate != 0, "%d", *rate);
> >>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_FORMAT, enum AVSampleFormat,
> >>> + "sample formats", fmt, *fmt != AV_SAMPLE_FMT_NONE,
> >>> + "%s", av_get_sample_fmt_name(*fmt));
> >>> + PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_CHANNEL_LAYOUT, AVChannelLayout,
> >>> + "channel layouts", layout, layout->nb_channels,
> >>> + "%s", get_channel_layout_desc(layout, desc, sizeof(desc)));
> >>
> >> Since you're rewriting everything, might as well go and port this to
> >> AVBprint, so we're not limited to 128 bytes for the channel layout.
> >> You can use av_bprintf() to write to the buffer using the different
> >> specifiers, then printf() the final bprint buffer to stdout.
> >
> > I implemented something like this initially, but it is IMO premature
> > optimization as there is no multi-threading going on in this code, so no
> > risk of colliding printf() calls. printf() already internally buffers
> > data, so we are not gaining anything by buffering it inside an AVBPrint
> > a second time.
> >
> > That said, using an AVBPrint instead of a fixed size buffer is a good
> > idea for the channel layout specifically, something like this:
> >
> >
> > diff --git a/fftools/opt_common.c b/fftools/opt_common.c
> > index 1bf66580192..fae68949f89 100644
> > --- a/fftools/opt_common.c
> > +++ b/fftools/opt_common.c
> > @@ -277,17 +277,17 @@ int show_buildconf(void *optctx, const char *opt, const char *arg)
> > } \
> > } while (0)
> >
> > -static char *get_channel_layout_desc(const AVChannelLayout *layout,
> > - char desc[], int desc_size)
> > +static char *get_channel_layout_desc(const AVChannelLayout *layout, AVBPrint *bp)
> > {
> > - av_channel_layout_describe(layout, desc, desc_size);
> > - return desc;
> > + av_bprint_clear(bp);
>
> I don't think this is needed if it's called immediately after
> av_bprint_init().
get_channel_layout_desc() is called in a loop.
>
> > + av_channel_layout_describe_bprintf(layout, bp);
> > + return bp->str;
> > }
> >
> > static void print_codec(const AVCodec *c)
> > {
> > int encoder = av_codec_is_encoder(c);
> > - char desc[128];
> > + AVBPrint desc;
> >
> > printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
> > c->long_name ? c->long_name : "");
> > @@ -363,9 +363,12 @@ static void print_codec(const AVCodec *c)
> > PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_SAMPLE_FORMAT, enum AVSampleFormat,
> > "sample formats", fmt, *fmt != AV_SAMPLE_FMT_NONE,
> > "%s", av_get_sample_fmt_name(*fmt));
> > +
> > + av_bprint_init(&desc, AV_BPRINT_SIZE_AUTOMATIC);
> > PRINT_CODEC_SUPPORTED(c, AV_CODEC_CONFIG_CHANNEL_LAYOUT, AVChannelLayout,
> > "channel layouts", layout, layout->nb_channels,
> > - "%s", get_channel_layout_desc(layout, desc, sizeof(desc)));
> > + "%s", get_channel_layout_desc(layout, &desc));
> > + av_bprint_finalize(&desc, NULL);
>
> Yeah, this is good. Thanks.
>
> >
> > if (c->priv_class) {
> > show_help_children(c->priv_class,
> >
> >>
> >>>
> >>> if (c->priv_class) {
> >>> show_help_children(c->priv_class,
> >>> @@ -566,8 +560,14 @@ static void show_help_bsf(const char *name)
> >>> }
> >>>
> >>> printf("Bit stream filter %s\n", bsf->name);
> >>> - PRINT_CODEC_SUPPORTED(bsf, codec_ids, enum AVCodecID, "codecs",
> >>> - AV_CODEC_ID_NONE, GET_CODEC_NAME);
> >>> + if (bsf->codec_ids) {
> >>> + const enum AVCodecID *id = bsf->codec_ids;
> >>> + printf(" Supported codecs:");
> >>> + while (*id != AV_CODEC_ID_NONE) {
> >>> + printf(" %s", avcodec_descriptor_get(*id)->name);
> >>> + id++;
> >>> + }
> >>> + }
> >>> if (bsf->priv_class)
> >>> show_help_children(bsf->priv_class, AV_OPT_FLAG_BSF_PARAM);
> >>> }
> >> _______________________________________________
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >> To unsubscribe, visit link above, or email
> >> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
` (11 preceding siblings ...)
2024-04-06 23:16 ` Michael Niedermayer
@ 2024-04-08 20:18 ` Michael Niedermayer
2024-04-08 20:23 ` Michael Niedermayer
2024-04-08 21:55 ` Niklas Haas
12 siblings, 2 replies; 24+ messages in thread
From: Michael Niedermayer @ 2024-04-08 20:18 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2230 bytes --]
On Fri, Apr 05, 2024 at 08:57:11PM +0200, Niklas Haas wrote:
> From: Niklas Haas <git@haasn.dev>
>
> This replaces the myriad of existing lists in AVCodec by a unified API
> call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
> substantially, while also making this more trivially extensible.
>
> In addition to the already covered lists, add two new entries for color
> space and color range, mirroring the newly added negotiable fields in
> libavfilter.
>
> I decided to drop the explicit length field from the API proposed by
> Andreas Rheinhardt, because having it in place ended up complicating
> both the codec side and the client side implementations, while also
> being strictly less flexible (it's trivial to recover a length given
> a terminator, but requires allocation to add a terminator given
> a length). Using a terminator also presents less of a porting challenge
> for existing users of the current API.
>
> Once the deprecation period passes for the existing public fields, the
> rough plan is to move the commonly used fields (such as
> pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
> configuration types, and then implement the rarely used fields with
> custom callbacks.
> ---
> doc/APIchanges | 5 ++++
> libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++
> libavcodec/avcodec.h | 27 ++++++++++++++++++++
> libavcodec/codec.h | 19 +++++++++++---
> libavcodec/codec_internal.h | 21 +++++++++++++++
> libavcodec/version.h | 4 +--
> 6 files changed, 121 insertions(+), 6 deletions(-)
This patchset seems to overlap a bit with AVOptionRanges
I think ideally the user should at some point be able to query using some
API on a AVCodecContext/AVCodecParameters/AVFormatContex/AVStream
what for that specific instance are supported settings for each field
The API here seems to use a enum, which can make sense but it differs from
how AVOption works which doesnt use enums to identify fields
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Never trust a computer, one day, it may think you are the virus. -- Compn
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
2024-04-08 20:18 ` Michael Niedermayer
@ 2024-04-08 20:23 ` Michael Niedermayer
2024-04-08 21:55 ` Niklas Haas
1 sibling, 0 replies; 24+ messages in thread
From: Michael Niedermayer @ 2024-04-08 20:23 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2553 bytes --]
On Mon, Apr 08, 2024 at 10:18:33PM +0200, Michael Niedermayer wrote:
> On Fri, Apr 05, 2024 at 08:57:11PM +0200, Niklas Haas wrote:
> > From: Niklas Haas <git@haasn.dev>
> >
> > This replaces the myriad of existing lists in AVCodec by a unified API
> > call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
> > substantially, while also making this more trivially extensible.
> >
> > In addition to the already covered lists, add two new entries for color
> > space and color range, mirroring the newly added negotiable fields in
> > libavfilter.
> >
> > I decided to drop the explicit length field from the API proposed by
> > Andreas Rheinhardt, because having it in place ended up complicating
> > both the codec side and the client side implementations, while also
> > being strictly less flexible (it's trivial to recover a length given
> > a terminator, but requires allocation to add a terminator given
> > a length). Using a terminator also presents less of a porting challenge
> > for existing users of the current API.
> >
> > Once the deprecation period passes for the existing public fields, the
> > rough plan is to move the commonly used fields (such as
> > pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
> > configuration types, and then implement the rarely used fields with
> > custom callbacks.
> > ---
> > doc/APIchanges | 5 ++++
> > libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++
> > libavcodec/avcodec.h | 27 ++++++++++++++++++++
> > libavcodec/codec.h | 19 +++++++++++---
> > libavcodec/codec_internal.h | 21 +++++++++++++++
> > libavcodec/version.h | 4 +--
> > 6 files changed, 121 insertions(+), 6 deletions(-)
>
> This patchset seems to overlap a bit with AVOptionRanges
>
> I think ideally the user should at some point be able to query using some
> API on a AVCodecContext/AVCodecParameters/AVFormatContex/AVStream
> what for that specific instance are supported settings for each field
let me clarify this a bit more, what i envission is some generic API
that can take any AVClass/AVOption suporting struct and query a instance
of it for supported ranges/lists of a AVOption field.
some AVCodec passed into that call in addition to a AVCodecContext would
be more messy in a generic API
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
No great genius has ever existed without some touch of madness. -- Aristotle
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
2024-04-08 20:18 ` Michael Niedermayer
2024-04-08 20:23 ` Michael Niedermayer
@ 2024-04-08 21:55 ` Niklas Haas
2024-04-10 22:09 ` Michael Niedermayer
1 sibling, 1 reply; 24+ messages in thread
From: Niklas Haas @ 2024-04-08 21:55 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Mon, 08 Apr 2024 22:18:33 +0200 Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Fri, Apr 05, 2024 at 08:57:11PM +0200, Niklas Haas wrote:
> > From: Niklas Haas <git@haasn.dev>
> >
> > This replaces the myriad of existing lists in AVCodec by a unified API
> > call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
> > substantially, while also making this more trivially extensible.
> >
> > In addition to the already covered lists, add two new entries for color
> > space and color range, mirroring the newly added negotiable fields in
> > libavfilter.
> >
> > I decided to drop the explicit length field from the API proposed by
> > Andreas Rheinhardt, because having it in place ended up complicating
> > both the codec side and the client side implementations, while also
> > being strictly less flexible (it's trivial to recover a length given
> > a terminator, but requires allocation to add a terminator given
> > a length). Using a terminator also presents less of a porting challenge
> > for existing users of the current API.
> >
> > Once the deprecation period passes for the existing public fields, the
> > rough plan is to move the commonly used fields (such as
> > pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
> > configuration types, and then implement the rarely used fields with
> > custom callbacks.
> > ---
> > doc/APIchanges | 5 ++++
> > libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++
> > libavcodec/avcodec.h | 27 ++++++++++++++++++++
> > libavcodec/codec.h | 19 +++++++++++---
> > libavcodec/codec_internal.h | 21 +++++++++++++++
> > libavcodec/version.h | 4 +--
> > 6 files changed, 121 insertions(+), 6 deletions(-)
>
> This patchset seems to overlap a bit with AVOptionRanges
>
> I think ideally the user should at some point be able to query using some
> API on a AVCodecContext/AVCodecParameters/AVFormatContex/AVStream
> what for that specific instance are supported settings for each field
>
> The API here seems to use a enum, which can make sense but it differs from
> how AVOption works which doesnt use enums to identify fields
I didn't know AVOptionRanges exists; indeed it can be seen as somewhat
overlapping here. That said, there is a vital distinction here: AVOptionRanges
represents *static* limits on what options can be set (e.g. via
`av_opt_set_int`), whereas this API represents *dynamic* limits on what can be
coded.
In particular, the list of supported colorspaces etc. can *depend* on the value
of other options. Currently, only strict_std_compliance, but I can easily see
this list growing in the future (e.g. for different profiles, dolbyvision,
...).
That aside, I personally find an API based on strings and doubles rather
cumbersome to use, especially when downstream clients expect an enum list.
>
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Never trust a computer, one day, it may think you are the virus. -- Compn
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
2024-04-08 21:55 ` Niklas Haas
@ 2024-04-10 22:09 ` Michael Niedermayer
2024-05-02 10:16 ` Niklas Haas
0 siblings, 1 reply; 24+ messages in thread
From: Michael Niedermayer @ 2024-04-10 22:09 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 3922 bytes --]
On Mon, Apr 08, 2024 at 11:55:02PM +0200, Niklas Haas wrote:
> On Mon, 08 Apr 2024 22:18:33 +0200 Michael Niedermayer <michael@niedermayer.cc> wrote:
> > On Fri, Apr 05, 2024 at 08:57:11PM +0200, Niklas Haas wrote:
> > > From: Niklas Haas <git@haasn.dev>
> > >
> > > This replaces the myriad of existing lists in AVCodec by a unified API
> > > call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
> > > substantially, while also making this more trivially extensible.
> > >
> > > In addition to the already covered lists, add two new entries for color
> > > space and color range, mirroring the newly added negotiable fields in
> > > libavfilter.
> > >
> > > I decided to drop the explicit length field from the API proposed by
> > > Andreas Rheinhardt, because having it in place ended up complicating
> > > both the codec side and the client side implementations, while also
> > > being strictly less flexible (it's trivial to recover a length given
> > > a terminator, but requires allocation to add a terminator given
> > > a length). Using a terminator also presents less of a porting challenge
> > > for existing users of the current API.
> > >
> > > Once the deprecation period passes for the existing public fields, the
> > > rough plan is to move the commonly used fields (such as
> > > pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
> > > configuration types, and then implement the rarely used fields with
> > > custom callbacks.
> > > ---
> > > doc/APIchanges | 5 ++++
> > > libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++
> > > libavcodec/avcodec.h | 27 ++++++++++++++++++++
> > > libavcodec/codec.h | 19 +++++++++++---
> > > libavcodec/codec_internal.h | 21 +++++++++++++++
> > > libavcodec/version.h | 4 +--
> > > 6 files changed, 121 insertions(+), 6 deletions(-)
> >
> > This patchset seems to overlap a bit with AVOptionRanges
> >
> > I think ideally the user should at some point be able to query using some
> > API on a AVCodecContext/AVCodecParameters/AVFormatContex/AVStream
> > what for that specific instance are supported settings for each field
> >
> > The API here seems to use a enum, which can make sense but it differs from
> > how AVOption works which doesnt use enums to identify fields
>
> I didn't know AVOptionRanges exists; indeed it can be seen as somewhat
> overlapping here. That said, there is a vital distinction here: AVOptionRanges
> represents *static* limits on what options can be set (e.g. via
> `av_opt_set_int`), whereas this API represents *dynamic* limits on what can be
> coded.
AVOptionRanges where definitly not intended to be static
see the docs:
* The returned list may depend on other fields in obj like for example profile.
that would not be static
>
> In particular, the list of supported colorspaces etc. can *depend* on the value
> of other options. Currently, only strict_std_compliance, but I can easily see
> this list growing in the future (e.g. for different profiles, dolbyvision,
> ...).
>
> That aside, I personally find an API based on strings and doubles rather
> cumbersome to use, especially when downstream clients expect an enum list.
AVOption* is intended to be a generic API.
For example something that an App can query to build a drop down menu in a GUI
for each parameter
For this, it must be possible to iterate over all paremeters, then for each
iterate over all possible settings if its a discrete type or range if its a
continous type. And then present the user with the corresponding GUI elements
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Does the universe only have a finite lifespan? No, its going to go on
forever, its just that you wont like living in it. -- Hiranya Peiri
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config()
2024-04-10 22:09 ` Michael Niedermayer
@ 2024-05-02 10:16 ` Niklas Haas
0 siblings, 0 replies; 24+ messages in thread
From: Niklas Haas @ 2024-05-02 10:16 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Thu, 11 Apr 2024 00:09:05 +0200 Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Mon, Apr 08, 2024 at 11:55:02PM +0200, Niklas Haas wrote:
> > On Mon, 08 Apr 2024 22:18:33 +0200 Michael Niedermayer <michael@niedermayer.cc> wrote:
> > > On Fri, Apr 05, 2024 at 08:57:11PM +0200, Niklas Haas wrote:
> > > > From: Niklas Haas <git@haasn.dev>
> > > >
> > > > This replaces the myriad of existing lists in AVCodec by a unified API
> > > > call, allowing us to (ultimately) trim down the sizeof(AVCodec) quite
> > > > substantially, while also making this more trivially extensible.
> > > >
> > > > In addition to the already covered lists, add two new entries for color
> > > > space and color range, mirroring the newly added negotiable fields in
> > > > libavfilter.
> > > >
> > > > I decided to drop the explicit length field from the API proposed by
> > > > Andreas Rheinhardt, because having it in place ended up complicating
> > > > both the codec side and the client side implementations, while also
> > > > being strictly less flexible (it's trivial to recover a length given
> > > > a terminator, but requires allocation to add a terminator given
> > > > a length). Using a terminator also presents less of a porting challenge
> > > > for existing users of the current API.
> > > >
> > > > Once the deprecation period passes for the existing public fields, the
> > > > rough plan is to move the commonly used fields (such as
> > > > pix_fmt/sample_fmt) into FFCodec, possibly as a union of audio and video
> > > > configuration types, and then implement the rarely used fields with
> > > > custom callbacks.
> > > > ---
> > > > doc/APIchanges | 5 ++++
> > > > libavcodec/avcodec.c | 51 +++++++++++++++++++++++++++++++++++++
> > > > libavcodec/avcodec.h | 27 ++++++++++++++++++++
> > > > libavcodec/codec.h | 19 +++++++++++---
> > > > libavcodec/codec_internal.h | 21 +++++++++++++++
> > > > libavcodec/version.h | 4 +--
> > > > 6 files changed, 121 insertions(+), 6 deletions(-)
> > >
> > > This patchset seems to overlap a bit with AVOptionRanges
> > >
> > > I think ideally the user should at some point be able to query using some
> > > API on a AVCodecContext/AVCodecParameters/AVFormatContex/AVStream
> > > what for that specific instance are supported settings for each field
> > >
> > > The API here seems to use a enum, which can make sense but it differs from
> > > how AVOption works which doesnt use enums to identify fields
> >
> > I didn't know AVOptionRanges exists; indeed it can be seen as somewhat
> > overlapping here. That said, there is a vital distinction here: AVOptionRanges
> > represents *static* limits on what options can be set (e.g. via
> > `av_opt_set_int`), whereas this API represents *dynamic* limits on what can be
> > coded.
>
> AVOptionRanges where definitly not intended to be static
>
> see the docs:
> * The returned list may depend on other fields in obj like for example profile.
>
> that would not be static
>
>
>
> >
> > In particular, the list of supported colorspaces etc. can *depend* on the value
> > of other options. Currently, only strict_std_compliance, but I can easily see
> > this list growing in the future (e.g. for different profiles, dolbyvision,
> > ...).
> >
> > That aside, I personally find an API based on strings and doubles rather
> > cumbersome to use, especially when downstream clients expect an enum list.
>
> AVOption* is intended to be a generic API.
> For example something that an App can query to build a drop down menu in a GUI
> for each parameter
>
> For this, it must be possible to iterate over all paremeters, then for each
> iterate over all possible settings if its a discrete type or range if its a
> continous type. And then present the user with the corresponding GUI elements
>
> thx
Okay, then I do not present as strong an objection as I thought. That
said, I still think that downstream API users will be very thankful for
having a replacement API that's easy to migrate to, rather one that's
IMO rather difficult to use (and which requires both FPU and malloc to
access what used to be just a static list).
What do other people think? Should we introduce this new API as-is, or
should it be scrapped in favor of reusing AVOptionRanges?
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2024-05-02 10:17 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05 18:57 [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 02/11] avcodec/encode: switch to avcodec_get_supported_config() Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 03/11] avcodec/allcodecs: add backcompat for new config API Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 04/11] avcodec/libx265: switch to get_supported_config() Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 05/11] avcodec/libvpxenc: " Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 06/11] avcodec/libaomenc: " Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 07/11] avcodec/codec_internal: nuke init_static_data() Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 08/11] fftools/opt_common: switch to avcodec_get_supported_config() Niklas Haas
2024-04-05 19:36 ` James Almer
2024-04-06 11:38 ` Niklas Haas
2024-04-07 0:10 ` James Almer
2024-04-08 11:15 ` Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 09/11] fftools: drop unused/hacky macros Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 10/11] fftools/ffmpeg_mux_init: switch to avcodec_get_supported_config() Niklas Haas
2024-04-05 18:57 ` [FFmpeg-devel] [PATCH 11/11] fftools/ffmpeg_filter: " Niklas Haas
2024-04-05 19:01 ` [FFmpeg-devel] [PATCH 01/11] avcodec: add avcodec_get_supported_config() Niklas Haas
2024-04-06 23:16 ` Michael Niedermayer
2024-04-07 11:47 ` Anton Khirnov
2024-04-08 11:15 ` Niklas Haas
2024-04-08 20:18 ` Michael Niedermayer
2024-04-08 20:23 ` Michael Niedermayer
2024-04-08 21:55 ` Niklas Haas
2024-04-10 22:09 ` Michael Niedermayer
2024-05-02 10:16 ` Niklas Haas
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git