Re: [FFmpeg-devel] [PATCH 1/2] avutil/hwcontext_videotoolbox: create real buffer pool

2022-03-30 Thread zhilizhao(赵志立)
Ping for patch 1/2. rcombs has reviewed the patch on IRC. I decided to
drop patch 2/2.


> 11:05 rcombs: quink_: seems reasonable to me
> 11:06 quink_: rcombs: thanks : )
> 11:06 rcombs: not entirely sure what the deal with the second commit is but 
> ¯\_(ツ)_/¯ it's harmless so w/e


> On Mar 10, 2022, at 12:37 PM, Zhao Zhili  wrote:
> 
> vt_get_buffer shouldn't do buffer pool's job.
> ---
> libavutil/hwcontext_videotoolbox.c | 71 ++
> 1 file changed, 34 insertions(+), 37 deletions(-)
> 
> diff --git a/libavutil/hwcontext_videotoolbox.c 
> b/libavutil/hwcontext_videotoolbox.c
> index 026127d412..e442a95007 100644
> --- a/libavutil/hwcontext_videotoolbox.c
> +++ b/libavutil/hwcontext_videotoolbox.c
> @@ -210,9 +210,36 @@ static int vt_pool_alloc(AVHWFramesContext *ctx)
> return AVERROR_EXTERNAL;
> }
> 
> -static AVBufferRef *vt_dummy_pool_alloc(void *opaque, size_t size)
> +static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
> +{
> +CVPixelBufferRelease((CVPixelBufferRef)data);
> +}
> +
> +static AVBufferRef *vt_pool_alloc_buffer(void *opaque, size_t size)
> {
> -return NULL;
> +CVPixelBufferRef pixbuf;
> +AVBufferRef *buf;
> +CVReturn err;
> +AVHWFramesContext *ctx = opaque;
> +VTFramesContext *fctx = ctx->internal->priv;
> +
> +err = CVPixelBufferPoolCreatePixelBuffer(
> +NULL,
> +fctx->pool,
> +&pixbuf
> +);
> +if (err != kCVReturnSuccess) {
> +av_log(ctx, AV_LOG_ERROR, "Failed to create pixel buffer from pool: 
> %d\n", err);
> +return NULL;
> +}
> +
> +buf = av_buffer_create((uint8_t *)pixbuf, size,
> +   videotoolbox_buffer_release, NULL, 0);
> +if (!buf) {
> +CVPixelBufferRelease(pixbuf);
> +return NULL;
> +}
> +return buf;
> }
> 
> static void vt_frames_uninit(AVHWFramesContext *ctx)
> @@ -238,9 +265,9 @@ static int vt_frames_init(AVHWFramesContext *ctx)
> return AVERROR(ENOSYS);
> }
> 
> -// create a dummy pool so av_hwframe_get_buffer doesn't EINVAL
> if (!ctx->pool) {
> -ctx->internal->pool_internal = av_buffer_pool_init2(0, ctx, 
> vt_dummy_pool_alloc, NULL);
> +ctx->internal->pool_internal = av_buffer_pool_init2(
> +sizeof(CVPixelBufferRef), ctx, vt_pool_alloc_buffer, NULL);
> if (!ctx->internal->pool_internal)
> return AVERROR(ENOMEM);
> }
> @@ -252,41 +279,11 @@ static int vt_frames_init(AVHWFramesContext *ctx)
> return 0;
> }
> 
> -static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
> -{
> -CVPixelBufferRelease((CVPixelBufferRef)data);
> -}
> -
> static int vt_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
> {
> -VTFramesContext *fctx = ctx->internal->priv;
> -
> -if (ctx->pool && ctx->pool->size != 0) {
> -frame->buf[0] = av_buffer_pool_get(ctx->pool);
> -if (!frame->buf[0])
> -return AVERROR(ENOMEM);
> -} else {
> -CVPixelBufferRef pixbuf;
> -AVBufferRef *buf = NULL;
> -CVReturn err;
> -
> -err = CVPixelBufferPoolCreatePixelBuffer(
> -NULL,
> -fctx->pool,
> -&pixbuf
> -);
> -if (err != kCVReturnSuccess) {
> -av_log(ctx, AV_LOG_ERROR, "Failed to create pixel buffer from 
> pool: %d\n", err);
> -return AVERROR_EXTERNAL;
> -}
> -
> -buf = av_buffer_create((uint8_t *)pixbuf, 1, 
> videotoolbox_buffer_release, NULL, 0);
> -if (!buf) {
> -CVPixelBufferRelease(pixbuf);
> -return AVERROR(ENOMEM);
> -}
> -frame->buf[0] = buf;
> -}
> +frame->buf[0] = av_buffer_pool_get(ctx->pool);
> +if (!frame->buf[0])
> +return AVERROR(ENOMEM);
> 
> frame->data[3] = frame->buf[0]->data;
> frame->format  = AV_PIX_FMT_VIDEOTOOLBOX;
> -- 
> 2.31.1
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

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


[FFmpeg-devel] [PATCH] avformat/matroska: Support HDR10+ metadata in Matroska.

2022-03-30 Thread Mohammad Izadi
From: Gyan Doshi 

The fate test file can be found here: 
https://drive.google.com/file/d/1jGW3f94rglLfr5WGmMQe3SEnp1YkbMRy/view?usp=drivesdk
The video file needs to be copied to fate-suite/mkv/
---
 libavcodec/dynamic_hdr10_plus.c | 269 +---
 libavcodec/dynamic_hdr10_plus.h |  35 ++-
 libavformat/matroska.h  |   5 +
 libavformat/matroskadec.c   |  30 ++-
 libavformat/matroskaenc.c   |  44 +++-
 tests/fate/matroska.mak |   6 +
 tests/ref/fate/matroska-hdr10-plus-metadata | 152 +++
 7 files changed, 484 insertions(+), 57 deletions(-)
 create mode 100644 tests/ref/fate/matroska-hdr10-plus-metadata

diff --git a/libavcodec/dynamic_hdr10_plus.c b/libavcodec/dynamic_hdr10_plus.c
index 34a44aac65..ce15569196 100644
--- a/libavcodec/dynamic_hdr10_plus.c
+++ b/libavcodec/dynamic_hdr10_plus.c
@@ -18,6 +18,12 @@
 
 #include "dynamic_hdr10_plus.h"
 #include "get_bits.h"
+#include "put_bits.h"
+
+static const uint8_t usa_country_code = 0xB5;
+static const uint16_t smpte_provider_code = 0x003C;
+static const uint16_t smpte2094_40_provider_oriented_code = 0x0001;
+static const uint16_t smpte2094_40_application_identifier = 0x04;
 
 static const int64_t luminance_den = 1;
 static const int32_t peak_luminance_den = 15;
@@ -27,8 +33,8 @@ static const int32_t knee_point_den = 4095;
 static const int32_t bezier_anchor_den = 1023;
 static const int32_t saturation_weight_den = 8;
 
-int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const 
uint8_t *data,
- int size)
+int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus* s, const 
uint8_t* data,
+int size)
 {
 GetBitContext gbc, *gb = &gbc;
 int ret;
@@ -40,10 +46,12 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 if (ret < 0)
 return ret;
 
-if (get_bits_left(gb) < 10)
+if (get_bits_left(gb) < 8)
 return AVERROR_INVALIDDATA;
+ s->application_version = get_bits(gb, 8);
 
-s->application_version = get_bits(gb, 8);
+if (get_bits_left(gb) < 2)
+return AVERROR_INVALIDDATA;
 s->num_windows = get_bits(gb, 2);
 
 if (s->num_windows < 1 || s->num_windows > 3) {
@@ -56,15 +64,11 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 for (int w = 1; w < s->num_windows; w++) {
 // The corners are set to absolute coordinates here. They should be
 // converted to the relative coordinates (in [0, 1]) in the decoder.
-AVHDRPlusColorTransformParams *params = &s->params[w];
-params->window_upper_left_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_upper_left_corner_y =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_x =
-(AVRational){get_bits(gb, 16), 1};
-params->window_lower_right_corner_y =
-(AVRational){get_bits(gb, 16), 1};
+AVHDRPlusColorTransformParams* params = &s->params[w];
+params->window_upper_left_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_upper_left_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_x = (AVRational) { get_bits(gb, 16), 
1 };
+params->window_lower_right_corner_y = (AVRational) { get_bits(gb, 16), 
1 };
 
 params->center_of_ellipse_x = get_bits(gb, 16);
 params->center_of_ellipse_y = get_bits(gb, 16);
@@ -78,8 +82,7 @@ int ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus 
*s, const uint8_t
 if (get_bits_left(gb) < 28)
 return AVERROR_INVALIDDATA;
 
-s->targeted_system_display_maximum_luminance =
-(AVRational){get_bits_long(gb, 27), luminance_den};
+s->targeted_system_display_maximum_luminance = (AVRational) { 
get_bits_long(gb, 27), luminance_den };
 s->targeted_system_display_actual_peak_luminance_flag = get_bits1(gb);
 
 if (s->targeted_system_display_actual_peak_luminance_flag) {
@@ -99,22 +102,19 @@ int 
ff_parse_itu_t_t35_to_dynamic_hdr10_plus(AVDynamicHDRPlus *s, const uint8_t
 
 for (int i = 0; i < rows; i++) {
 for (int j = 0; j < cols; j++) {
-s->targeted_system_display_actual_peak_luminance[i][j] =
-(AVRational){get_bits(gb, 4), peak_luminance_den};
+s->targeted_system_display_actual_peak_luminance[i][j] = 
(AVRational) { get_bits(gb, 4), peak_luminance_den };
 }
 }
 }
 for (int w = 0; w < s->num_windows; w++) {
-AVHDRPlusColorTransformParams *params = &s->params[w];
+AVHDRPlusColorTransformParams* params = &s->params[w];
 if (get_bits_left(gb) < (3 * 17 + 17 + 4))
 return AVERROR_INVALIDDATA;
 
 for (int i = 0; i < 3; i++) {
-params->maxscl[i] =
- 

[FFmpeg-devel] [PATCH 7/7] avformat/demux: Avoid stack packet when decoding frame

2022-03-30 Thread Andreas Rheinhardt
Possible now that avcodec_decode_subtitle2() accepts a const AVPacket*.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/demux.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index ef189d9d8e..ed5c811a01 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1983,7 +1983,7 @@ static int has_codec_parameters(const AVStream *st, const 
char **errmsg_ptr)
 
 /* returns 1 or 0 if or if not decoded data was returned, or a negative error 
*/
 static int try_decode_frame(AVFormatContext *s, AVStream *st,
-const AVPacket *avpkt, AVDictionary **options)
+const AVPacket *pkt, AVDictionary **options)
 {
 FFStream *const sti = ffstream(st);
 AVCodecContext *const avctx = sti->avctx;
@@ -1991,9 +1991,9 @@ static int try_decode_frame(AVFormatContext *s, AVStream 
*st,
 int got_picture = 1, ret = 0;
 AVFrame *frame = av_frame_alloc();
 AVSubtitle subtitle;
-AVPacket pkt = *avpkt;
 int do_skip_frame = 0;
 enum AVDiscard skip_frame;
+int pkt_to_send = pkt->size > 0;
 
 if (!frame)
 return AVERROR(ENOMEM);
@@ -2042,7 +2042,7 @@ static int try_decode_frame(AVFormatContext *s, AVStream 
*st,
 avctx->skip_frame = AVDISCARD_ALL;
 }
 
-while ((pkt.size > 0 || (!pkt.data && got_picture)) &&
+while ((pkt_to_send || (!pkt->data && got_picture)) &&
ret >= 0 &&
(!has_codec_parameters(st, NULL) || 
!has_decode_delay_been_guessed(st) ||
 (!sti->codec_info_nb_frames &&
@@ -2050,11 +2050,11 @@ static int try_decode_frame(AVFormatContext *s, 
AVStream *st,
 got_picture = 0;
 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO ||
 avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-ret = avcodec_send_packet(avctx, &pkt);
+ret = avcodec_send_packet(avctx, pkt);
 if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
 break;
 if (ret >= 0)
-pkt.size = 0;
+pkt_to_send = 0;
 ret = avcodec_receive_frame(avctx, frame);
 if (ret >= 0)
 got_picture = 1;
@@ -2062,11 +2062,11 @@ static int try_decode_frame(AVFormatContext *s, 
AVStream *st,
 ret = 0;
 } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
 ret = avcodec_decode_subtitle2(avctx, &subtitle,
-   &got_picture, &pkt);
+   &got_picture, pkt);
 if (got_picture)
 avsubtitle_free(&subtitle);
 if (ret >= 0)
-pkt.size = 0;
+pkt_to_send = 0;
 }
 if (ret >= 0) {
 if (got_picture)
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH 6/7] avcodec: Make avcodec_decoder_subtitles2 accept a const AVPacket*

2022-03-30 Thread Andreas Rheinhardt
From: Andreas Rheinhardt 

Signed-off-by: Andreas Rheinhardt 
---
 doc/APIchanges| 3 +++
 fftools/ffmpeg.c  | 4 ++--
 fftools/ffprobe.c | 2 +-
 libavcodec/avcodec.h  | 3 +--
 libavcodec/decode.c   | 9 -
 libavcodec/version.h  | 2 +-
 tools/target_dec_fuzzer.c | 4 ++--
 7 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 1a9f0a303e..326a3c721c 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2022-03-30 - xx - lavc 59.26.100 - avcodec.h
+  avcodec_decode_subtitle2() now accepts const AVPacket*.
+
 2022-03-16 - xx - all libraries - version_major.h
   Add lib/version_major.h as new installed headers, which only
   contain the major version number (and corresponding API deprecation
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 6d62bdc7b0..979e33c9ab 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2491,8 +2491,8 @@ fail:
 return err < 0 ? err : ret;
 }
 
-static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int 
*got_output,
-   int *decode_failed)
+static int transcode_subtitles(InputStream *ist, const AVPacket *pkt,
+   int *got_output, int *decode_failed)
 {
 AVSubtitle subtitle;
 int free_sub = 1;
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 05c167eeb5..d2aacb6a0d 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2629,7 +2629,7 @@ static void show_frame(WriterContext *w, AVFrame *frame, 
AVStream *stream,
 
 static av_always_inline int process_frame(WriterContext *w,
   InputFile *ifile,
-  AVFrame *frame, AVPacket *pkt,
+  AVFrame *frame, const AVPacket *pkt,
   int *packet_new)
 {
 AVFormatContext *fmt_ctx = ifile->fmt_ctx;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 4dae23d06e..64804c2a50 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2544,8 +2544,7 @@ enum AVChromaLocation avcodec_chroma_pos_to_enum(int 
xpos, int ypos);
  * @param[in] avpkt The input AVPacket containing the input buffer.
  */
 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
-int *got_sub_ptr,
-AVPacket *avpkt);
+ int *got_sub_ptr, const AVPacket *avpkt);
 
 /**
  * Supply raw packet data as input to a decoder.
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index e51a39e70a..8bb6e8c265 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -751,8 +751,8 @@ static void get_subtitle_defaults(AVSubtitle *sub)
 }
 
 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
-static int recode_subtitle(AVCodecContext *avctx, AVPacket **outpkt,
-   AVPacket *inpkt, AVPacket *buf_pkt)
+static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt,
+   const AVPacket *inpkt, AVPacket *buf_pkt)
 {
 #if CONFIG_ICONV
 iconv_t cd = (iconv_t)-1;
@@ -832,8 +832,7 @@ static int utf8_check(const uint8_t *str)
 }
 
 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
- int *got_sub_ptr,
- AVPacket *avpkt)
+ int *got_sub_ptr, const AVPacket *avpkt)
 {
 int ret = 0;
 
@@ -853,7 +852,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, 
AVSubtitle *sub,
 
 if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
 AVCodecInternal *avci = avctx->internal;
-AVPacket *pkt;
+const AVPacket *pkt;
 
 ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
 if (ret < 0)
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a744e7469f..26ee41eb1f 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  25
+#define LIBAVCODEC_VERSION_MINOR  26
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c
index 288aa63313..bb9fad613d 100644
--- a/tools/target_dec_fuzzer.c
+++ b/tools/target_dec_fuzzer.c
@@ -81,8 +81,8 @@ static const FFCodec *AVCodecInitialize(enum AVCodecID 
codec_id)
 return ffcodec(res);
 }
 
-static int subtitle_handler(AVCodecContext *avctx, void *frame,
-int *got_sub_ptr, AVPacket *avpkt)
+static int subtitle_handler(AVCodecContext *avctx, AVFrame *unused,
+int *got_sub_ptr, const AVPacket *avpkt)
 {
 AVSubtitle sub;
 int ret = avcodec_decode_subtitle2(avctx, &sub, got_sub_ptr, avpkt);
-- 
2.3

[FFmpeg-devel] [PATCH 5/7] avcodec/codec_internal: Constify AVPacket in decode_sub cb

2022-03-30 Thread Andreas Rheinhardt
No subtitle decoder ever modifies the AVPacket given to it.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/assdec.c  | 2 +-
 libavcodec/ccaption_dec.c| 2 +-
 libavcodec/codec_internal.h  | 2 +-
 libavcodec/dvbsubdec.c   | 2 +-
 libavcodec/dvdsubdec.c   | 2 +-
 libavcodec/jacosubdec.c  | 2 +-
 libavcodec/libaribb24.c  | 2 +-
 libavcodec/libzvbi-teletextdec.c | 2 +-
 libavcodec/microdvddec.c | 2 +-
 libavcodec/movtextdec.c  | 2 +-
 libavcodec/mpl2dec.c | 2 +-
 libavcodec/pgssubdec.c   | 2 +-
 libavcodec/realtextdec.c | 2 +-
 libavcodec/samidec.c | 2 +-
 libavcodec/srtdec.c  | 2 +-
 libavcodec/subviewerdec.c| 2 +-
 libavcodec/textdec.c | 2 +-
 libavcodec/webvttdec.c   | 2 +-
 libavcodec/xsubdec.c | 2 +-
 19 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index b94629ea1d..f43b500aa7 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -41,7 +41,7 @@ static av_cold int ass_decode_init(AVCodecContext *avctx)
 }
 
 static int ass_decode_frame(AVCodecContext *avctx, AVSubtitle *sub,
-int *got_sub_ptr, AVPacket *avpkt)
+int *got_sub_ptr, const AVPacket *avpkt)
 {
 if (avpkt->size <= 0)
 return avpkt->size;
diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index e33fb36824..34f0513b1a 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -839,7 +839,7 @@ static int process_cc608(CCaptionSubContext *ctx, uint8_t 
hi, uint8_t lo)
 }
 
 static int decode(AVCodecContext *avctx, AVSubtitle *sub,
-  int *got_sub, AVPacket *avpkt)
+  int *got_sub, const AVPacket *avpkt)
 {
 CCaptionSubContext *ctx = avctx->priv_data;
 int64_t in_time = sub->pts;
diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h
index a14f6592fe..5df286ce52 100644
--- a/libavcodec/codec_internal.h
+++ b/libavcodec/codec_internal.h
@@ -184,7 +184,7 @@ typedef struct FFCodec {
  * Apart from that this is like the decode callback.
  */
 int (*decode_sub)(struct AVCodecContext *avctx, struct AVSubtitle *sub,
-  int *got_frame_ptr, struct AVPacket *avpkt);
+  int *got_frame_ptr, const struct AVPacket *avpkt);
 /**
  * Decode API with decoupled packet/frame dataflow.
  * cb is in this state if cb_type is FF_CODEC_CB_TYPE_RECEIVE_FRAME.
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 58e18cfece..6e510d12c7 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -1608,7 +1608,7 @@ static int dvbsub_display_end_segment(AVCodecContext 
*avctx, const uint8_t *buf,
 }
 
 static int dvbsub_decode(AVCodecContext *avctx, AVSubtitle *sub,
- int *got_sub_ptr, AVPacket *avpkt)
+ int *got_sub_ptr, const AVPacket *avpkt)
 {
 const uint8_t *buf = avpkt->data;
 int buf_size = avpkt->size;
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 2951e74736..2aa6983490 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -549,7 +549,7 @@ static int append_to_cached_buf(AVCodecContext *avctx,
 }
 
 static int dvdsub_decode(AVCodecContext *avctx, AVSubtitle *sub,
- int *data_size, AVPacket *avpkt)
+ int *data_size, const AVPacket *avpkt)
 {
 DVDSubContext *ctx = avctx->priv_data;
 const uint8_t *buf = avpkt->data;
diff --git a/libavcodec/jacosubdec.c b/libavcodec/jacosubdec.c
index 245ae1..e3bf9f4226 100644
--- a/libavcodec/jacosubdec.c
+++ b/libavcodec/jacosubdec.c
@@ -163,7 +163,7 @@ static void jacosub_to_ass(AVCodecContext *avctx, AVBPrint 
*dst, const char *src
 }
 
 static int jacosub_decode_frame(AVCodecContext *avctx, AVSubtitle *sub,
-int *got_sub_ptr, AVPacket *avpkt)
+int *got_sub_ptr, const AVPacket *avpkt)
 {
 int ret;
 const char *ptr = avpkt->data;
diff --git a/libavcodec/libaribb24.c b/libavcodec/libaribb24.c
index e1a26e5659..9658e1d5ac 100644
--- a/libavcodec/libaribb24.c
+++ b/libavcodec/libaribb24.c
@@ -284,7 +284,7 @@ next_region:
 }
 
 static int libaribb24_decode(AVCodecContext *avctx, AVSubtitle *sub,
- int *got_sub_ptr, AVPacket *pkt)
+ int *got_sub_ptr, const AVPacket *pkt)
 {
 Libaribb24Context *b24 = avctx->priv_data;
 size_t parsed_data_size = 0;
diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c
index 79a1237431..92466cc11e 100644
--- a/libavcodec/libzvbi-teletextdec.c
+++ b/libavcodec/libzvbi-teletextdec.c
@@ -638,7 +638,7 @@ static int slice_to_vbi_lines(TeletextContext *ctx, 
uint8_t* buf, int size)
 }
 
 static int teletext_decod

[FFmpeg-devel] [PATCH 2/7] avcodec/codec_internal: Add FFCodec.decode_sub

2022-03-30 Thread Andreas Rheinhardt
This increases type-safety by avoiding conversions from/through void*.
It also avoids the boilerplate "AVSubtitle *sub = data;" line
for subtitle decoders. Its only downside is that it increases
sizeof(FFCodec), yet this can be more than offset lateron.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/assdec.c  | 10 --
 libavcodec/ccaption_dec.c|  6 +++---
 libavcodec/codec_internal.h  | 11 ---
 libavcodec/decode.c  |  2 +-
 libavcodec/dvbsubdec.c   |  8 +++-
 libavcodec/dvdsubdec.c   |  8 +++-
 libavcodec/jacosubdec.c  |  7 +++
 libavcodec/libaribb24.c  |  6 +++---
 libavcodec/libzvbi-teletextdec.c |  6 +++---
 libavcodec/microdvddec.c |  7 +++
 libavcodec/movtextdec.c  |  7 +++
 libavcodec/mpl2dec.c |  5 ++---
 libavcodec/pgssubdec.c   | 13 ++---
 libavcodec/realtextdec.c |  7 +++
 libavcodec/samidec.c |  7 +++
 libavcodec/srtdec.c  |  9 -
 libavcodec/subviewerdec.c|  7 +++
 libavcodec/tests/avcodec.c   |  7 ---
 libavcodec/textdec.c | 13 ++---
 libavcodec/utils.c   |  2 +-
 libavcodec/webvttdec.c   |  7 +++
 libavcodec/xsubdec.c |  8 
 22 files changed, 76 insertions(+), 87 deletions(-)

diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index 86d3e3e5a8..bf1260a947 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -40,11 +40,9 @@ static av_cold int ass_decode_init(AVCodecContext *avctx)
 return 0;
 }
 
-static int ass_decode_frame(AVCodecContext *avctx, void *data, int 
*got_sub_ptr,
-AVPacket *avpkt)
+static int ass_decode_frame(AVCodecContext *avctx, AVSubtitle *sub,
+int *got_sub_ptr, AVPacket *avpkt)
 {
-AVSubtitle *sub = data;
-
 if (avpkt->size <= 0)
 return avpkt->size;
 
@@ -70,7 +68,7 @@ const FFCodec ff_ssa_decoder = {
 .p.type   = AVMEDIA_TYPE_SUBTITLE,
 .p.id = AV_CODEC_ID_ASS,
 .init = ass_decode_init,
-.decode   = ass_decode_frame,
+.decode_sub   = ass_decode_frame,
 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
@@ -82,7 +80,7 @@ const FFCodec ff_ass_decoder = {
 .p.type   = AVMEDIA_TYPE_SUBTITLE,
 .p.id = AV_CODEC_ID_ASS,
 .init = ass_decode_init,
-.decode   = ass_decode_frame,
+.decode_sub   = ass_decode_frame,
 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 371c8d18b7..32ee3a715d 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -838,10 +838,10 @@ static int process_cc608(CCaptionSubContext *ctx, uint8_t 
hi, uint8_t lo)
 return ret;
 }
 
-static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket 
*avpkt)
+static int decode(AVCodecContext *avctx, AVSubtitle *sub,
+  int *got_sub, AVPacket *avpkt)
 {
 CCaptionSubContext *ctx = avctx->priv_data;
-AVSubtitle *sub = data;
 int64_t in_time = sub->pts;
 int64_t start_time;
 int64_t end_time;
@@ -955,6 +955,6 @@ const FFCodec ff_ccaption_decoder = {
 .init   = init_decoder,
 .close  = close_decoder,
 .flush  = flush_decoder,
-.decode = decode,
+.decode_sub = decode,
 .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h
index 596cdbebd2..5c57c438f9 100644
--- a/libavcodec/codec_internal.h
+++ b/libavcodec/codec_internal.h
@@ -148,19 +148,24 @@ typedef struct FFCodec {
 int (*encode2)(struct AVCodecContext *avctx, struct AVPacket *avpkt,
const struct AVFrame *frame, int *got_packet_ptr);
 /**
- * Decode picture or subtitle data.
+ * Decode picture data.
  *
  * @param  avctx  codec context
  * @param  outdatacodec type dependent output struct
  * @param[out] got_frame_ptr  decoder sets to 0 or 1 to indicate that a
- *non-empty frame or subtitle was returned in
- *outdata.
+ *non-empty frame was returned in outdata.
  * @param[in]  avpkt  AVPacket containing the data to be decoded
  * @return amount of bytes read from the packet on success, negative error
  * code on failure
  */
 int (*decode)(struct AVCodecContext *avctx, void *outdata,
   int *got_frame_ptr, struct AVPacket *avpkt);
+/**
+ * Decode subtitle data. Same as decode except that it uses
+ * a struct AVSubtitle structure for output.
+ */
+int (*decode_sub)(struct AVCodecContext *avctx, struct AVSubtitle *sub,
+  int *got_frame_ptr, struct AVPacket *avpkt);
 

[FFmpeg-devel] [PATCH 1/7] avcodec/options: Fix AVClassCategory of decoders with .receive_frame

2022-03-30 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/options.c b/libavcodec/options.c
index 91ab994994..2e05d29e1e 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -68,7 +68,7 @@ static const AVClass *codec_child_class_iterate(void **iter)
 static AVClassCategory get_category(void *ptr)
 {
 AVCodecContext* avctx = ptr;
-if (avctx->codec && ffcodec(avctx->codec)->decode)
+if (avctx->codec && av_codec_is_decoder(avctx->codec))
 return AV_CLASS_CATEGORY_DECODER;
 else
 return AV_CLASS_CATEGORY_ENCODER;
-- 
2.32.0

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

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


[FFmpeg-devel] [PATCH] avfilter/alimiter: Remove the delay introduced by lookahead buffer

2022-03-30 Thread Wang Cao
The change essentially removes the delay introduces by lookahead buffer.
The valid audio data in the internal buffer is also flushed to ensure
the integrity of output.

Signed-off-by: Wang Cao 
---
 doc/filters.texi   |   2 -
 libavfilter/af_alimiter.c  |  97 +-
 tests/ref/fate/filter-alimiter | 518 -
 3 files changed, 344 insertions(+), 273 deletions(-)

Thanks a lot for your time to review my patch. I have made "zero_delay"
option to default. Now the output samples will only be written after the
lookahead buffer is full. We also uses "request_frame" to flush the
internal buffers so that all valid input audio samples are written.

diff --git a/doc/filters.texi b/doc/filters.texi
index d70ac3e237..5d1adf88e1 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1943,8 +1943,6 @@ aiir=z=1.3057 0 0 0:p=1.3057 2.3892 2.1860 1:f=sf:r=d
 
 The limiter prevents an input signal from rising over a desired threshold.
 This limiter uses lookahead technology to prevent your signal from distorting.
-It means that there is a small delay after the signal is processed. Keep in 
mind
-that the delay it produces is the attack time you set.
 
 The filter accepts the following options:
 
diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
index 133f98f165..e1fcf98574 100644
--- a/libavfilter/af_alimiter.c
+++ b/libavfilter/af_alimiter.c
@@ -30,6 +30,7 @@
 
 #include "audio.h"
 #include "avfilter.h"
+#include "bufferqueue.h"
 #include "formats.h"
 #include "internal.h"
 
@@ -55,6 +56,13 @@ typedef struct AudioLimiterContext {
 int *nextpos;
 double *nextdelta;
 
+int total_samples_to_flush;
+int lookahead_buffer_full;
+
+struct FFBufQueue output_frame_queue;
+int output_sample_pos;
+int output_frame_pos;
+
 double delta;
 int nextiter;
 int nextlen;
@@ -129,6 +137,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 AVFrame *out;
 double *buf;
 int n, c, i;
+int can_free_input_frame = 0;
+double peak = 0;
 
 if (av_frame_is_writable(in)) {
 out = in;
@@ -138,12 +148,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 av_frame_free(&in);
 return AVERROR(ENOMEM);
 }
+can_free_input_frame = 1;
 av_frame_copy_props(out, in);
 }
-dst = (double *)out->data[0];
+
+if (ff_bufqueue_is_full(&s->output_frame_queue)) {
+// In the runtime, the total number of frames in the queue is bounded 
by
+// attack_time, sample rate and frame size.
+return AVERROR_BUG;
+}
+
+ff_bufqueue_add(ctx, &s->output_frame_queue, out);
 
 for (n = 0; n < in->nb_samples; n++) {
-double peak = 0;
+out = ff_bufqueue_peek(&s->output_frame_queue, s->output_frame_pos);
+dst = (double *)out->data[0];
+dst += s->output_sample_pos * channels;
+peak = 0;
 
 for (c = 0; c < channels; c++) {
 double sample = src[c] * level_in;
@@ -213,8 +234,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
 s->att += s->delta;
 
-for (c = 0; c < channels; c++)
-dst[c] = buf[c] * s->att;
+// Checks lookahead buffer (s->buffer) has been filled
+if (!s->lookahead_buffer_full && (s->pos + channels) % buffer_size == 
0) {
+s->lookahead_buffer_full = 1;
+}
+if (s->lookahead_buffer_full) {
+for (c = 0; c < channels; c++) {
+dst[c] = buf[c] * s->att;
+dst[c] = av_clipd(dst[c], -limit, limit) * level * level_out;
+}
+s->output_sample_pos++;
+if (s->output_sample_pos == out->nb_samples) {
+s->output_frame_pos++;
+s->output_sample_pos = 0;
+}
+}
 
 if ((s->pos + channels) % buffer_size == nextpos[s->nextiter]) {
 if (s->auto_release) {
@@ -261,18 +295,55 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 if (s->delta != 0. && fabs(s->delta) < 0.01)
 s->delta = 0.;
 
-for (c = 0; c < channels; c++)
-dst[c] = av_clipd(dst[c], -limit, limit) * level * level_out;
-
 s->pos = (s->pos + channels) % buffer_size;
 src += channels;
-dst += channels;
 }
-
-if (in != out)
+if (can_free_input_frame) {
 av_frame_free(&in);
+}
 
-return ff_filter_frame(outlink, out);
+if (s->output_frame_pos > 0) {
+s->output_frame_pos--;
+out = ff_bufqueue_get(&s->output_frame_queue);
+return ff_filter_frame(outlink, out);
+}
+return 0;
+}
+
+static int request_frame(AVFilterLink* outlink) 
+{
+AVFilterContext *ctx = outlink->src;
+AudioLimiterContext *s = (AudioLimiterContext*)ctx->priv;
+int ret;
+AVFilterLink *inlink;
+AVFrame *out;
+AVFrame *silence_frame;
+
+ret = ff_request_frame(ctx->inputs

[FFmpeg-devel] [PATCH] avcodec/mediacodecdec_common: stop the codec before releasing it

2022-03-30 Thread Matthieu Bouron
Fixes the following warnings/errors on codec release:

E/BufferQueueProducer: 
[SurfaceTexture-0-31763-0](id:7c130001,api:3,p:31763,c:31763) detachBuffer: 
slot 0 is not owned by the producer (state = FREE)
E/BufferQueueProducer: 
[SurfaceTexture-0-31763-0](id:7c130001,api:3,p:31763,c:31763) detachBuffer: 
slot 1 is not owned by the producer (state = FREE)
E/BufferQueueProducer: 
[SurfaceTexture-0-31763-0](id:7c130001,api:3,p:31763,c:31763) detachBuffer: 
slot 2 is not owned by the producer (state = FREE)
[...]
---
 libavcodec/mediacodecdec_common.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/mediacodecdec_common.c 
b/libavcodec/mediacodecdec_common.c
index cb18aed401..d99881c11f 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -232,6 +232,7 @@ static void ff_mediacodec_dec_unref(MediaCodecDecContext *s)
 
 if (atomic_fetch_sub(&s->refcount, 1) == 1) {
 if (s->codec) {
+ff_AMediaCodec_stop(s->codec);
 ff_AMediaCodec_delete(s->codec);
 s->codec = NULL;
 }
-- 
2.35.1

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

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


[FFmpeg-devel] [PATCH 7/8] avcodec/vbnenc: add VBN encoder

2022-03-30 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 Changelog  |   2 +-
 configure  |   1 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/vbnenc.c| 173 +
 libavcodec/version.h   |   2 +-
 libavformat/img2enc.c  |   2 +-
 libavformat/version.h  |   4 +-
 8 files changed, 181 insertions(+), 5 deletions(-)
 create mode 100644 libavcodec/vbnenc.c

diff --git a/Changelog b/Changelog
index 7bad88dabc..c3fbba5221 100644
--- a/Changelog
+++ b/Changelog
@@ -6,7 +6,7 @@ version 5.1:
 - dropped obsolete XvMC hwaccel
 - pcm-bluray encoder
 - DFPWM audio encoder/decoder and raw muxer/demuxer
-- Vizrt Binary Image decoder
+- Vizrt Binary Image encoder/decoder
 
 
 version 5.0:
diff --git a/configure b/configure
index 90c99ff85e..9c8965852b 100755
--- a/configure
+++ b/configure
@@ -2960,6 +2960,7 @@ utvideo_decoder_select="bswapdsp llviddsp"
 utvideo_encoder_select="bswapdsp huffman llvidencdsp"
 vble_decoder_select="llviddsp"
 vbn_decoder_select="texturedsp"
+vbn_encoder_select="texturedspenc"
 vc1_decoder_select="blockdsp h263_decoder h264qpel intrax8 mpegvideodec vc1dsp"
 vc1image_decoder_select="vc1_decoder"
 vorbis_decoder_select="mdct"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 90700085b8..90f46035d9 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -709,6 +709,7 @@ OBJS-$(CONFIG_V410_DECODER)+= v410dec.o
 OBJS-$(CONFIG_V410_ENCODER)+= v410enc.o
 OBJS-$(CONFIG_VB_DECODER)  += vb.o
 OBJS-$(CONFIG_VBN_DECODER) += vbndec.o
+OBJS-$(CONFIG_VBN_ENCODER) += vbnenc.o
 OBJS-$(CONFIG_VBLE_DECODER)+= vble.o
 OBJS-$(CONFIG_VC1_DECODER) += vc1dec.o vc1_block.o 
vc1_loopfilter.o \
   vc1_mc.o vc1_pred.o vc1.o vc1data.o \
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index f0a7ea7fd4..585918da93 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -347,6 +347,7 @@ extern const FFCodec ff_v408_decoder;
 extern const FFCodec ff_v410_encoder;
 extern const FFCodec ff_v410_decoder;
 extern const FFCodec ff_vb_decoder;
+extern const FFCodec ff_vbn_encoder;
 extern const FFCodec ff_vbn_decoder;
 extern const FFCodec ff_vble_decoder;
 extern const FFCodec ff_vc1_decoder;
diff --git a/libavcodec/vbnenc.c b/libavcodec/vbnenc.c
new file mode 100644
index 00..51f618c7d9
--- /dev/null
+++ b/libavcodec/vbnenc.c
@@ -0,0 +1,173 @@
+/*
+ * Vizrt Binary Image encoder
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Vizrt Binary Image encoder
+ */
+
+#include "avcodec.h"
+#include "bytestream.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "texturedsp.h"
+#include "vbn.h"
+
+#include "libavutil/imgutils.h"
+#include "libavutil/frame.h"
+#include "libavutil/opt.h"
+
+typedef struct VBNContext {
+AVClass *class;
+TextureDSPContext dxtc;
+PutByteContext pb;
+int format;
+TextureDSPThreadContext enc;
+} VBNContext;
+
+static int vbn_encode(AVCodecContext *avctx, AVPacket *pkt,
+  const AVFrame *frame, int *got_packet)
+{
+VBNContext *ctx = avctx->priv_data;
+PutByteContext *pb = &ctx->pb;
+int ret;
+ptrdiff_t linesize;
+int64_t pkt_size;
+
+ret = av_image_check_size2(frame->width, frame->height, INT_MAX, 
frame->format, 0, avctx);
+if (ret < 0)
+return ret;
+
+if (ctx->format == VBN_FORMAT_DXT1 || ctx->format == VBN_FORMAT_DXT5) {
+if (frame->width % TEXTURE_BLOCK_W || frame->height % TEXTURE_BLOCK_H) 
{
+av_log(avctx, AV_LOG_ERROR, "Video size %dx%d is not multiple of 
4\n", frame->width, frame->height);
+return AVERROR(EINVAL);
+}
+if (frame->format != AV_PIX_FMT_RGBA) {
+av_log(avctx, AV_LOG_ERROR, "DXT formats only support RGBA pixel 
format\n");
+return AVERROR(EINVAL);
+}
+ctx->enc.raw_ratio = 16;
+ctx->enc.slice_count = av_clip(avctx->thread_count, 1, avctx->height / 
TEXTURE_BLOCK_H);
+}
+
+switch (ctx->format) {
+case VBN_FORMAT_DXT1:
+linesize = frame->width / 2;
+ctx->enc.tex_funct = ctx->dxtc.dxt1_block;
+ctx->

[FFmpeg-devel] [PATCH 8/8] fate: add fate tests for VBN encoder and decoder

2022-03-30 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 tests/Makefile   |  1 +
 tests/fate-run.sh| 11 +++
 tests/fate/vbn.mak   | 36 
 tests/ref/fate/vbn-dxt1  | 11 +++
 tests/ref/fate/vbn-dxt5  | 11 +++
 tests/ref/fate/vbn-raw-rgb24 |  9 +
 tests/ref/fate/vbn-raw-rgba  | 11 +++
 7 files changed, 90 insertions(+)
 create mode 100644 tests/fate/vbn.mak
 create mode 100644 tests/ref/fate/vbn-dxt1
 create mode 100644 tests/ref/fate/vbn-dxt5
 create mode 100644 tests/ref/fate/vbn-raw-rgb24
 create mode 100644 tests/ref/fate/vbn-raw-rgba

diff --git a/tests/Makefile b/tests/Makefile
index 9f33394856..e3b41a4f7b 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -191,6 +191,7 @@ include $(SRC_PATH)/tests/fate/speedhq.mak
 include $(SRC_PATH)/tests/fate/subtitles.mak
 include $(SRC_PATH)/tests/fate/truehd.mak
 include $(SRC_PATH)/tests/fate/utvideo.mak
+include $(SRC_PATH)/tests/fate/vbn.mak
 include $(SRC_PATH)/tests/fate/video.mak
 include $(SRC_PATH)/tests/fate/voice.mak
 include $(SRC_PATH)/tests/fate/vorbis.mak
diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index 5e8d607d88..3022aa44a6 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -382,6 +382,17 @@ refcmp_metadata(){
 -f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f 
${base}/refcmp-metadata.awk -
 }
 
+refcmp_metadata_files(){
+refcmp=$1
+pixfmt=$2
+file1=$3
+file2=$4
+fuzz=${5:-0.001}
+ffmpeg -auto_conversion_filters $FLAGS -i $file1 $FLAGS -i $file2 
$ENC_OPTS \
+-lavfi 
"[0:v]format=${pixfmt}[v0];[1:v]format=${pixfmt}[v1];[v0][v1]${refcmp},metadata=print:file=-"
 \
+-f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f 
${base}/refcmp-metadata.awk -
+}
+
 pixfmt_conversion(){
 conversion="${test#pixfmt-}"
 outdir="tests/data/pixfmt"
diff --git a/tests/fate/vbn.mak b/tests/fate/vbn.mak
new file mode 100644
index 00..044b110ac1
--- /dev/null
+++ b/tests/fate/vbn.mak
@@ -0,0 +1,36 @@
+fate-vbn-%: VBN_FILE = tests/data/$(subst fate-vbn-,,$(@)).vbn
+fate-vbn-%: PIX_FMT = rgba
+fate-vbn-raw-rgb24: PIX_FMT = rgb24
+fate-vbn-%: SRC = $(TARGET_SAMPLES)/png1/lena-$(PIX_FMT).png
+fate-vbn-%: CMD = refcmp_metadata_files psnr $(PIX_FMT) $(VBN_FILE) $(SRC)
+
+fate-vbn-dxt1: tests/data/dxt1.vbn
+fate-vbn-dxt5: tests/data/dxt5.vbn
+fate-vbn-raw-rgba: tests/data/raw-rgba.vbn
+fate-vbn-raw-rgb24: tests/data/raw-rgb24.vbn
+
+FATE_VBN += fate-vbn-dxt1
+FATE_VBN += fate-vbn-dxt5
+FATE_VBN += fate-vbn-raw-rgba
+FATE_VBN += fate-vbn-raw-rgb24
+
+tests/data/dxt1.vbn: TAG = GEN
+tests/data/dxt1.vbn: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< -nostdin -i 
$(TARGET_SAMPLES)/png1/lena-rgba.png -nostdin -c:v vbn -format dxt1 
$(TARGET_PATH)/$@ -y 2>/dev/null
+
+tests/data/dxt5.vbn: TAG = GEN
+tests/data/dxt5.vbn: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< -nostdin -i 
$(TARGET_SAMPLES)/png1/lena-rgba.png -nostdin -c:v vbn -format dxt5 
$(TARGET_PATH)/$@ -y 2>/dev/null
+
+tests/data/raw-rgba.vbn: TAG = GEN
+tests/data/raw-rgba.vbn: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< -nostdin -i 
$(TARGET_SAMPLES)/png1/lena-rgba.png -nostdin -c:v vbn -format raw 
$(TARGET_PATH)/$@ -y 2>/dev/null
+
+tests/data/raw-rgb24.vbn: TAG = GEN
+tests/data/raw-rgb24.vbn: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+   $(M)$(TARGET_EXEC) $(TARGET_PATH)/$< -nostdin -i 
$(TARGET_SAMPLES)/png1/lena-rgb24.png -nostdin -c:v vbn -format raw 
$(TARGET_PATH)/$@ -y 2>/dev/null
+
+VBN_REFCMP_DEPS = PSNR_FILTER METADATA_FILTER VBN_ENCODER VBN_DECODER 
IMAGE2_MUXER IMAGE2_DEMUXER PNG_DECODER
+
+FATE_SAMPLES_FFMPEG-$(call ALLYES, $(VBN_REFCMP_DEPS)) += $(FATE_VBN)
+fate-vbn: $(FATE_VBN)
diff --git a/tests/ref/fate/vbn-dxt1 b/tests/ref/fate/vbn-dxt1
new file mode 100644
index 00..0afd94
--- /dev/null
+++ b/tests/ref/fate/vbn-dxt1
@@ -0,0 +1,11 @@
+frame:0pts:0   pts_time:0
+lavfi.psnr.mse.r=36.794250
+lavfi.psnr.psnr.r=32.473003
+lavfi.psnr.mse.g=33.350525
+lavfi.psnr.psnr.g=32.899776
+lavfi.psnr.mse.b=28.317383
+lavfi.psnr.psnr.b=33.610271
+lavfi.psnr.mse.a=21186.988281
+lavfi.psnr.psnr.a=4.870111
+lavfi.psnr.mse_avg=5321.362793
+lavfi.psnr.psnr_avg=10.870575
diff --git a/tests/ref/fate/vbn-dxt5 b/tests/ref/fate/vbn-dxt5
new file mode 100644
index 00..dbec0bd13d
--- /dev/null
+++ b/tests/ref/fate/vbn-dxt5
@@ -0,0 +1,11 @@
+frame:0pts:0   pts_time:0
+lavfi.psnr.mse.r=36.794250
+lavfi.psnr.psnr.r=32.473003
+lavfi.psnr.mse.g=33.350525
+lavfi.psnr.psnr.g=32.899776
+lavfi.psnr.mse.b=28.317383
+lavfi.psnr.psnr.b=33.610271
+lavfi.psnr.mse.a=0.000183
+lavfi.psnr.psnr.a=85.503792
+lavfi.psnr.mse_avg=24.615585
+lavfi.psnr.psnr_avg=34.218700
diff --git a/tests/ref/fate/vbn-raw-rgb24 b/tests/ref/fate/vbn-raw-rgb24
new file mode 100644
index 00..06143c27b6
--- /dev/null
+++ b/test

[FFmpeg-devel] [PATCH 5/8] avcodec/hapenc: use the common texturedsp encode function

2022-03-30 Thread Marton Balint
And add slice thread capabilities.

Signed-off-by: Marton Balint 
---
 libavcodec/hap.h|  4 +---
 libavcodec/hapenc.c | 34 --
 2 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/libavcodec/hap.h b/libavcodec/hap.h
index 7e065e4838..fb5a4c4123 100644
--- a/libavcodec/hap.h
+++ b/libavcodec/hap.h
@@ -80,9 +80,7 @@ typedef struct HapContext {
 int texture_count;  /* 2 for HAQA, 1 for other version */
 int texture_section_size; /* size of the part of the texture section (for 
HAPQA) */
 
-/* Pointer to the selected compress function (encoder only) */
-int (*tex_fun)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
-
+TextureDSPThreadContext enc;
 TextureDSPThreadContext dec[2];
 } HapContext;
 
diff --git a/libavcodec/hapenc.c b/libavcodec/hapenc.c
index ee03fef449..148331a3dd 100644
--- a/libavcodec/hapenc.c
+++ b/libavcodec/hapenc.c
@@ -56,18 +56,14 @@ enum HapHeaderLength {
 static int compress_texture(AVCodecContext *avctx, uint8_t *out, int 
out_length, const AVFrame *f)
 {
 HapContext *ctx = avctx->priv_data;
-int i, j;
 
 if (ctx->tex_size > out_length)
 return AVERROR_BUFFER_TOO_SMALL;
 
-for (j = 0; j < avctx->height; j += 4) {
-for (i = 0; i < avctx->width; i += 4) {
-uint8_t *p = f->data[0] + i * 4 + j * f->linesize[0];
-const int step = ctx->tex_fun(out, f->linesize[0], p);
-out += step;
-}
-}
+ctx->enc.tex_data.out = out;
+ctx->enc.frame_data.in = f->data[0];
+ctx->enc.stride = f->linesize[0];
+avctx->execute2(avctx, ff_texturedsp_compress_thread, &ctx->enc, NULL, 
ctx->enc.slice_count);
 
 return 0;
 }
@@ -236,7 +232,6 @@ static int hap_encode(AVCodecContext *avctx, AVPacket *pkt,
 static av_cold int hap_init(AVCodecContext *avctx)
 {
 HapContext *ctx = avctx->priv_data;
-int ratio;
 int corrected_chunk_count;
 int ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
 
@@ -256,32 +251,34 @@ static av_cold int hap_init(AVCodecContext *avctx)
 
 switch (ctx->opt_tex_fmt) {
 case HAP_FMT_RGBDXT1:
-ratio = 8;
+ctx->enc.tex_ratio = 8;
 avctx->codec_tag = MKTAG('H', 'a', 'p', '1');
 avctx->bits_per_coded_sample = 24;
-ctx->tex_fun = ctx->dxtc.dxt1_block;
+ctx->enc.tex_funct = ctx->dxtc.dxt1_block;
 break;
 case HAP_FMT_RGBADXT5:
-ratio = 4;
+ctx->enc.tex_ratio = 16;
 avctx->codec_tag = MKTAG('H', 'a', 'p', '5');
 avctx->bits_per_coded_sample = 32;
-ctx->tex_fun = ctx->dxtc.dxt5_block;
+ctx->enc.tex_funct = ctx->dxtc.dxt5_block;
 break;
 case HAP_FMT_YCOCGDXT5:
-ratio = 4;
+ctx->enc.tex_ratio = 16;
 avctx->codec_tag = MKTAG('H', 'a', 'p', 'Y');
 avctx->bits_per_coded_sample = 24;
-ctx->tex_fun = ctx->dxtc.dxt5ys_block;
+ctx->enc.tex_funct = ctx->dxtc.dxt5ys_block;
 break;
 default:
 av_log(avctx, AV_LOG_ERROR, "Invalid format %02X\n", ctx->opt_tex_fmt);
 return AVERROR_INVALIDDATA;
 }
+ctx->enc.raw_ratio = 16;
+ctx->enc.slice_count = av_clip(avctx->thread_count, 1, avctx->height / 
TEXTURE_BLOCK_H);
 
 /* Texture compression ratio is constant, so can we computer
  * beforehand the final size of the uncompressed buffer. */
-ctx->tex_size   = FFALIGN(avctx->width,  TEXTURE_BLOCK_W) *
-  FFALIGN(avctx->height, TEXTURE_BLOCK_H) * 4 / ratio;
+ctx->tex_size   = avctx->width  / TEXTURE_BLOCK_W *
+  avctx->height / TEXTURE_BLOCK_H * ctx->enc.tex_ratio;
 
 switch (ctx->opt_compressor) {
 case HAP_COMP_NONE:
@@ -294,7 +291,7 @@ static av_cold int hap_init(AVCodecContext *avctx)
 case HAP_COMP_SNAPPY:
 /* Round the chunk count to divide evenly on DXT block edges */
 corrected_chunk_count = av_clip(ctx->opt_chunk_count, 1, 
HAP_MAX_CHUNKS);
-while ((ctx->tex_size / (64 / ratio)) % corrected_chunk_count != 0) {
+while ((ctx->tex_size / ctx->enc.tex_ratio) % corrected_chunk_count != 
0) {
 corrected_chunk_count--;
 }
 
@@ -356,6 +353,7 @@ const FFCodec ff_hap_encoder = {
 .p.id   = AV_CODEC_ID_HAP,
 .priv_data_size = sizeof(HapContext),
 .p.priv_class   = &hapenc_class,
+.p.capabilities = AV_CODEC_CAP_SLICE_THREADS,
 .init   = hap_init,
 .encode2= hap_encode,
 .close  = hap_close,
-- 
2.31.1

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

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


[FFmpeg-devel] [PATCH 6/8] avcodec/vbndec: add VBN decoder

2022-03-30 Thread Marton Balint
Add support for decoding Vizrt Binary Image (VBN) files.

LZW-compressed data is not supported yet.

Signed-off-by: Marton Balint 
---
 Changelog|   1 +
 configure|   1 +
 libavcodec/Makefile  |   1 +
 libavcodec/allcodecs.c   |   1 +
 libavcodec/codec_desc.c  |   7 ++
 libavcodec/codec_id.h|   1 +
 libavcodec/vbn.h |  50 ++
 libavcodec/vbndec.c  | 196 +++
 libavformat/allformats.c |   1 +
 libavformat/img2.c   |   1 +
 libavformat/img2dec.c|  12 +++
 11 files changed, 272 insertions(+)
 create mode 100644 libavcodec/vbn.h
 create mode 100644 libavcodec/vbndec.c

diff --git a/Changelog b/Changelog
index ac614f8f05..7bad88dabc 100644
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,7 @@ version 5.1:
 - dropped obsolete XvMC hwaccel
 - pcm-bluray encoder
 - DFPWM audio encoder/decoder and raw muxer/demuxer
+- Vizrt Binary Image decoder
 
 
 version 5.0:
diff --git a/configure b/configure
index e4d36aa639..90c99ff85e 100755
--- a/configure
+++ b/configure
@@ -2959,6 +2959,7 @@ txd_decoder_select="texturedsp"
 utvideo_decoder_select="bswapdsp llviddsp"
 utvideo_encoder_select="bswapdsp huffman llvidencdsp"
 vble_decoder_select="llviddsp"
+vbn_decoder_select="texturedsp"
 vc1_decoder_select="blockdsp h263_decoder h264qpel intrax8 mpegvideodec vc1dsp"
 vc1image_decoder_select="vc1_decoder"
 vorbis_decoder_select="mdct"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb8b0e824b..90700085b8 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -708,6 +708,7 @@ OBJS-$(CONFIG_V408_ENCODER)+= v408enc.o
 OBJS-$(CONFIG_V410_DECODER)+= v410dec.o
 OBJS-$(CONFIG_V410_ENCODER)+= v410enc.o
 OBJS-$(CONFIG_VB_DECODER)  += vb.o
+OBJS-$(CONFIG_VBN_DECODER) += vbndec.o
 OBJS-$(CONFIG_VBLE_DECODER)+= vble.o
 OBJS-$(CONFIG_VC1_DECODER) += vc1dec.o vc1_block.o 
vc1_loopfilter.o \
   vc1_mc.o vc1_pred.o vc1.o vc1data.o \
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 22d56760ec..f0a7ea7fd4 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -347,6 +347,7 @@ extern const FFCodec ff_v408_decoder;
 extern const FFCodec ff_v410_encoder;
 extern const FFCodec ff_v410_decoder;
 extern const FFCodec ff_vb_decoder;
+extern const FFCodec ff_vbn_decoder;
 extern const FFCodec ff_vble_decoder;
 extern const FFCodec ff_vc1_decoder;
 extern const FFCodec ff_vc1_crystalhd_decoder;
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 81f3b3c640..c08854cc93 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1863,6 +1863,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("GEM Raster image"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_VBN,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "vbn",
+.long_name = NULL_IF_CONFIG_SMALL("Vizrt Binary Image"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* various PCM "codecs" */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 3ffb9bd22e..43c72ce8e4 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -308,6 +308,7 @@ enum AVCodecID {
 AV_CODEC_ID_SIMBIOSIS_IMX,
 AV_CODEC_ID_SGA_VIDEO,
 AV_CODEC_ID_GEM,
+AV_CODEC_ID_VBN,
 
 /* various PCM "codecs" */
 AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
start of audio codecs
diff --git a/libavcodec/vbn.h b/libavcodec/vbn.h
new file mode 100644
index 00..8660786de8
--- /dev/null
+++ b/libavcodec/vbn.h
@@ -0,0 +1,50 @@
+/*
+ * VBN format definitions
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * VBN format definitions.
+ */
+
+#ifndef AVCODEC_VBN_H
+#define AVCODEC_VBN_H
+
+#define VBN_MAGIC  0x900df11e
+#define VBN_MAJOR   3
+#define VBN_MINOR   4
+
+#define VBN_HEADER_SIZE   192
+
+#define VBN_FORMAT_RAW  0
+#define VBN_FORMAT_LZ   1
+#define VBN_FORMAT_DXT1 2
+#define VBN_FORMAT_DXT5 3
+
+#def

[FFmpeg-devel] [PATCH 4/8] avcodec/hapdec: use the common texturedsp decode function

2022-03-30 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavcodec/hap.h|  11 ++---
 libavcodec/hapdec.c | 110 ++--
 2 files changed, 28 insertions(+), 93 deletions(-)

diff --git a/libavcodec/hap.h b/libavcodec/hap.h
index 00c3dbb32d..7e065e4838 100644
--- a/libavcodec/hap.h
+++ b/libavcodec/hap.h
@@ -72,23 +72,18 @@ typedef struct HapContext {
 HapChunk *chunks;
 int *chunk_results;  /* Results from threaded operations */
 
-int tex_rat; /* Compression ratio */
-int tex_rat2; /* Compression ratio of the second texture */
-const uint8_t *tex_data; /* Compressed texture */
 uint8_t *tex_buf;/* Buffer for compressed texture */
 size_t tex_size; /* Size of the compressed texture */
 
 size_t max_snappy;   /* Maximum compressed size for snappy buffer */
 
-int slice_count; /* Number of slices for threaded operations */
-
 int texture_count;  /* 2 for HAQA, 1 for other version */
 int texture_section_size; /* size of the part of the texture section (for 
HAPQA) */
-int uncompress_pix_size; /* nb of byte / pixel for the target picture */
 
-/* Pointer to the selected compress or decompress function */
+/* Pointer to the selected compress function (encoder only) */
 int (*tex_fun)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
-int (*tex_fun2)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
+
+TextureDSPThreadContext dec[2];
 } HapContext;
 
 /*
diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index 4a7ac15a8e..685d65d8b8 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -247,60 +247,6 @@ static int decompress_chunks_thread(AVCodecContext *avctx, 
void *arg,
 return 0;
 }
 
-static int decompress_texture_thread_internal(AVCodecContext *avctx, void *arg,
-  int slice, int thread_nb, int 
texture_num)
-{
-HapContext *ctx = avctx->priv_data;
-AVFrame *frame = arg;
-const uint8_t *d = ctx->tex_data;
-int w_block = avctx->coded_width / TEXTURE_BLOCK_W;
-int h_block = avctx->coded_height / TEXTURE_BLOCK_H;
-int x, y;
-int start_slice, end_slice;
-int base_blocks_per_slice = h_block / ctx->slice_count;
-int remainder_blocks = h_block % ctx->slice_count;
-
-/* When the frame height (in blocks) doesn't divide evenly between the
- * number of slices, spread the remaining blocks evenly between the first
- * operations */
-start_slice = slice * base_blocks_per_slice;
-/* Add any extra blocks (one per slice) that have been added before this 
slice */
-start_slice += FFMIN(slice, remainder_blocks);
-
-end_slice = start_slice + base_blocks_per_slice;
-/* Add an extra block if there are still remainder blocks to be accounted 
for */
-if (slice < remainder_blocks)
-end_slice++;
-
-for (y = start_slice; y < end_slice; y++) {
-uint8_t *p = frame->data[0] + y * frame->linesize[0] * TEXTURE_BLOCK_H;
-int off  = y * w_block;
-for (x = 0; x < w_block; x++) {
-if (texture_num == 0) {
-ctx->tex_fun(p + x * 4 * ctx->uncompress_pix_size, 
frame->linesize[0],
- d + (off + x) * ctx->tex_rat);
-} else {
-ctx->tex_fun2(p + x * 4 * ctx->uncompress_pix_size, 
frame->linesize[0],
-  d + (off + x) * ctx->tex_rat2);
-}
-}
-}
-
-return 0;
-}
-
-static int decompress_texture_thread(AVCodecContext *avctx, void *arg,
- int slice, int thread_nb)
-{
-return decompress_texture_thread_internal(avctx, arg, slice, thread_nb, 0);
-}
-
-static int decompress_texture2_thread(AVCodecContext *avctx, void *arg,
-  int slice, int thread_nb)
-{
-return decompress_texture_thread_internal(avctx, arg, slice, thread_nb, 1);
-}
-
 static int hap_decode(AVCodecContext *avctx, void *data,
   int *got_frame, AVPacket *avpkt)
 {
@@ -310,12 +256,9 @@ static int hap_decode(AVCodecContext *avctx, void *data,
 int section_size;
 enum HapSectionType section_type;
 int start_texture_section = 0;
-int tex_rat[2] = {0, 0};
 
 bytestream2_init(&ctx->gbc, avpkt->data, avpkt->size);
 
-tex_rat[0] = ctx->tex_rat;
-
 /* check for multi texture header */
 if (ctx->texture_count == 2) {
 ret = ff_hap_parse_section_header(&ctx->gbc, §ion_size, 
§ion_type);
@@ -326,7 +269,6 @@ static int hap_decode(AVCodecContext *avctx, void *data,
 return AVERROR_INVALIDDATA;
 }
 start_texture_section = 4;
-tex_rat[1] = ctx->tex_rat2;
 }
 
 /* Get the output frame ready to receive data */
@@ -344,7 +286,7 @@ static int hap_decode(AVCodecContext *avctx, void *data,
 
 if (ctx->tex_size != (avctx->coded_width  / TEXTURE_BLOCK_W)
 *(avct

[FFmpeg-devel] [PATCH 3/8] avcodec/dds: use the common texture dsp decode function

2022-03-30 Thread Marton Balint
Signed-off-by: Marton Balint 
---
 libavcodec/dds.c | 135 +--
 1 file changed, 48 insertions(+), 87 deletions(-)

diff --git a/libavcodec/dds.c b/libavcodec/dds.c
index 32690e1fd7..2254d18df8 100644
--- a/libavcodec/dds.c
+++ b/libavcodec/dds.c
@@ -106,12 +106,7 @@ typedef struct DDSContext {
 int bpp;
 enum DDSPostProc postproc;
 
-const uint8_t *tex_data; // Compressed texture
-int tex_ratio;   // Compression ratio
-int slice_count; // Number of slices for threaded operations
-
-/* Pointer to the selected compress or decompress function. */
-int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
+TextureDSPThreadContext dec;
 } DDSContext;
 
 static int parse_pixel_format(AVCodecContext *avctx)
@@ -170,35 +165,36 @@ static int parse_pixel_format(AVCodecContext *avctx)
 avctx->pix_fmt = AV_PIX_FMT_RGBA;
 
 if (ctx->compressed) {
+ctx->dec.raw_ratio = 16;
 switch (fourcc) {
 case MKTAG('D', 'X', 'T', '1'):
-ctx->tex_ratio = 8;
-ctx->tex_funct = ctx->texdsp.dxt1a_block;
+ctx->dec.tex_ratio = 8;
+ctx->dec.tex_funct = ctx->texdsp.dxt1a_block;
 break;
 case MKTAG('D', 'X', 'T', '2'):
-ctx->tex_ratio = 16;
-ctx->tex_funct = ctx->texdsp.dxt2_block;
+ctx->dec.tex_ratio = 16;
+ctx->dec.tex_funct = ctx->texdsp.dxt2_block;
 break;
 case MKTAG('D', 'X', 'T', '3'):
-ctx->tex_ratio = 16;
-ctx->tex_funct = ctx->texdsp.dxt3_block;
+ctx->dec.tex_ratio = 16;
+ctx->dec.tex_funct = ctx->texdsp.dxt3_block;
 break;
 case MKTAG('D', 'X', 'T', '4'):
-ctx->tex_ratio = 16;
-ctx->tex_funct = ctx->texdsp.dxt4_block;
+ctx->dec.tex_ratio = 16;
+ctx->dec.tex_funct = ctx->texdsp.dxt4_block;
 break;
 case MKTAG('D', 'X', 'T', '5'):
-ctx->tex_ratio = 16;
+ctx->dec.tex_ratio = 16;
 if (ycocg_scaled)
-ctx->tex_funct = ctx->texdsp.dxt5ys_block;
+ctx->dec.tex_funct = ctx->texdsp.dxt5ys_block;
 else if (ycocg_classic)
-ctx->tex_funct = ctx->texdsp.dxt5y_block;
+ctx->dec.tex_funct = ctx->texdsp.dxt5y_block;
 else
-ctx->tex_funct = ctx->texdsp.dxt5_block;
+ctx->dec.tex_funct = ctx->texdsp.dxt5_block;
 break;
 case MKTAG('R', 'X', 'G', 'B'):
-ctx->tex_ratio = 16;
-ctx->tex_funct = ctx->texdsp.dxt5_block;
+ctx->dec.tex_ratio = 16;
+ctx->dec.tex_funct = ctx->texdsp.dxt5_block;
 /* This format may be considered as a normal map,
  * but it is handled differently in a separate postproc. */
 ctx->postproc = DDS_SWIZZLE_RXGB;
@@ -206,25 +202,25 @@ static int parse_pixel_format(AVCodecContext *avctx)
 break;
 case MKTAG('A', 'T', 'I', '1'):
 case MKTAG('B', 'C', '4', 'U'):
-ctx->tex_ratio = 8;
-ctx->tex_funct = ctx->texdsp.rgtc1u_block;
+ctx->dec.tex_ratio = 8;
+ctx->dec.tex_funct = ctx->texdsp.rgtc1u_block;
 break;
 case MKTAG('B', 'C', '4', 'S'):
-ctx->tex_ratio = 8;
-ctx->tex_funct = ctx->texdsp.rgtc1s_block;
+ctx->dec.tex_ratio = 8;
+ctx->dec.tex_funct = ctx->texdsp.rgtc1s_block;
 break;
 case MKTAG('A', 'T', 'I', '2'):
 /* RGT2 variant with swapped R and G (3Dc)*/
-ctx->tex_ratio = 16;
-ctx->tex_funct = ctx->texdsp.dxn3dc_block;
+ctx->dec.tex_ratio = 16;
+ctx->dec.tex_funct = ctx->texdsp.dxn3dc_block;
 break;
 case MKTAG('B', 'C', '5', 'U'):
-ctx->tex_ratio = 16;
-ctx->tex_funct = ctx->texdsp.rgtc2u_block;
+ctx->dec.tex_ratio = 16;
+ctx->dec.tex_funct = ctx->texdsp.rgtc2u_block;
 break;
 case MKTAG('B', 'C', '5', 'S'):
-ctx->tex_ratio = 16;
-ctx->tex_funct = ctx->texdsp.rgtc2s_block;
+ctx->dec.tex_ratio = 16;
+ctx->dec.tex_funct = ctx->texdsp.rgtc2s_block;
 break;
 case MKTAG('U', 'Y', 'V', 'Y'):
 ctx->compressed = 0;
@@ -299,40 +295,40 @@ static int parse_pixel_format(AVCodecContext *avctx)
 avctx->colorspace = AVCOL_SPC_RGB;
 case DXGI_FORMAT_BC1_TYPELESS:
 case DXGI_FORMAT_BC1_UNORM:
-ctx->tex_ratio = 8;
-ctx->tex_funct = ctx->texdsp.dxt1a_block;
+ctx->dec.tex_ratio = 8;
+ctx->dec.tex_funct = ctx->texdsp.dxt1a_block;
 break;
 case DXGI_FORMAT_BC2_UNORM_SRGB:
  

[FFmpeg-devel] [PATCH 2/8] avcodec/texturedsp: add TextureDSPThreadContext for common decode/encode function

2022-03-30 Thread Marton Balint
This will allow using a common threaded decode or encode function from most
codecs using texture DSP functions.

Signed-off-by: Marton Balint 
---
 libavcodec/texturedsp.c  |  4 +++
 libavcodec/texturedsp.h  | 23 +
 libavcodec/texturedsp_template.c | 57 
 libavcodec/texturedspenc.c   |  4 +++
 4 files changed, 88 insertions(+)
 create mode 100644 libavcodec/texturedsp_template.c

diff --git a/libavcodec/texturedsp.c b/libavcodec/texturedsp.c
index b7dd8baa12..b8938213ef 100644
--- a/libavcodec/texturedsp.c
+++ b/libavcodec/texturedsp.c
@@ -652,3 +652,7 @@ av_cold void ff_texturedsp_init(TextureDSPContext *c)
 c->rgtc2u_block   = rgtc2u_block;
 c->dxn3dc_block   = dxn3dc_block;
 }
+
+#define TEXTUREDSP_FUNC_NAME ff_texturedsp_decompress_thread
+#define TEXTUREDSP_TEX_FUNC(a, b, c) tex_funct(a, b, c)
+#include "texturedsp_template.c"
diff --git a/libavcodec/texturedsp.h b/libavcodec/texturedsp.h
index 90ceb2b6aa..e15d3c2b02 100644
--- a/libavcodec/texturedsp.h
+++ b/libavcodec/texturedsp.h
@@ -39,6 +39,8 @@
 #include 
 #include 
 
+#include "avcodec.h"
+
 #define TEXTURE_BLOCK_W 4
 #define TEXTURE_BLOCK_H 4
 
@@ -60,7 +62,28 @@ typedef struct TextureDSPContext {
 int (*dxn3dc_block)  (uint8_t *dst, ptrdiff_t stride, const uint8_t 
*block);
 } TextureDSPContext;
 
+typedef struct TextureDSPThreadContext {
+union {
+const uint8_t *in;   // Input frame data
+uint8_t *out;// Output frame data
+} frame_data;
+ptrdiff_t stride;// Frame linesize
+union {
+const uint8_t *in;   // Compressed texture for decompression
+uint8_t *out;// Compressed texture of compression
+} tex_data;
+int tex_ratio;   // Number of compressed bytes in a texture 
block
+int raw_ratio;   // Number bytes in a line of a raw block
+int slice_count; // Number of slices for threaded operations
+
+/* Pointer to the selected compress or decompress function. */
+int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
+} TextureDSPThreadContext;
+
 void ff_texturedsp_init(TextureDSPContext *c);
 void ff_texturedspenc_init(TextureDSPContext *c);
 
+int ff_texturedsp_decompress_thread(AVCodecContext *avctx, void *arg, int 
slice, int thread_nb);
+int ff_texturedsp_compress_thread(AVCodecContext *avctx, void *arg, int slice, 
int thread_nb);
+
 #endif /* AVCODEC_TEXTUREDSP_H */
diff --git a/libavcodec/texturedsp_template.c b/libavcodec/texturedsp_template.c
new file mode 100644
index 00..bd193aa97c
--- /dev/null
+++ b/libavcodec/texturedsp_template.c
@@ -0,0 +1,57 @@
+/*
+ * Texture block compression and decompression
+ * Copyright (C) 2015 Vittorio Giovara 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+int TEXTUREDSP_FUNC_NAME(AVCodecContext *avctx, void *arg,
+ int slice, int thread_nb)
+{
+TextureDSPThreadContext *ctx = arg;
+uint8_t *d = ctx->tex_data.out;
+int w_block = avctx->coded_width / TEXTURE_BLOCK_W;
+int h_block = avctx->coded_height / TEXTURE_BLOCK_H;
+int x, y;
+int start_slice, end_slice;
+int base_blocks_per_slice = h_block / ctx->slice_count;
+int remainder_blocks = h_block % ctx->slice_count;
+
+/* When the frame height (in blocks) doesn't divide evenly between the
+ * number of slices, spread the remaining blocks evenly between the first
+ * operations */
+start_slice = slice * base_blocks_per_slice;
+/* Add any extra blocks (one per slice) that have been added before this 
slice */
+start_slice += FFMIN(slice, remainder_blocks);
+
+end_slice = start_slice + base_blocks_per_slice;
+/* Add an extra block if there are still remainder blocks to be accounted 
for */
+if (slice < remainder_blocks)
+end_slice++;
+
+for (y = start_slice; y < end_slice; y++) {
+uint8_t *p = ctx->frame_data.out + y * ctx->stride * TEXTURE_BLOCK_H;
+int off = y * w_block;
+for (x = 0; x < w_block; x++) {
+ctx->TEXTUREDSP_TEX_FUNC(p + x * ctx->raw_ratio, ctx->stride,
+ d + (off + x) * ctx->tex_ratio);

[FFmpeg-devel] [PATCH 1/8] fate/filter-refcmp-*: make refcmp_metadata fail on empty input

2022-03-30 Thread Marton Balint
On empty input the awk script was always successful which caused the
filter-refcmp tests to always succeed.

Also fix the command lines for refcmp_metadata compare function because it
needs auto conversion filters, and update reference of test
filter-refcmp-psnr-rgb because it was missed in
a7fc78c1a638a32c3695c06f727774c740d675c2 but was never noticed due to the
original issue...

Signed-off-by: Marton Balint 
---
 tests/fate-run.sh |  2 +-
 tests/ref/fate/filter-refcmp-psnr-rgb | 80 +--
 tests/refcmp-metadata.awk |  3 +
 3 files changed, 44 insertions(+), 41 deletions(-)

diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index fbfc0a925d..5e8d607d88 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -377,7 +377,7 @@ refcmp_metadata(){
 refcmp=$1
 pixfmt=$2
 fuzz=${3:-0.001}
-ffmpeg $FLAGS $ENC_OPTS \
+ffmpeg -auto_conversion_filters $FLAGS $ENC_OPTS \
 -lavfi 
"testsrc2=size=300x200:rate=1:duration=5,format=${pixfmt},split[ref][tmp];[tmp]avgblur=4[enc];[enc][ref]${refcmp},metadata=print:file=-"
 \
 -f null /dev/null | awk -v ref=${ref} -v fuzz=${fuzz} -f 
${base}/refcmp-metadata.awk -
 }
diff --git a/tests/ref/fate/filter-refcmp-psnr-rgb 
b/tests/ref/fate/filter-refcmp-psnr-rgb
index f06db575ac..20abd3dc5a 100644
--- a/tests/ref/fate/filter-refcmp-psnr-rgb
+++ b/tests/ref/fate/filter-refcmp-psnr-rgb
@@ -1,45 +1,45 @@
 frame:0pts:0   pts_time:0
-lavfi.psnr.mse.r=1381.80
-lavfi.psnr.psnr.r=16.73
-lavfi.psnr.mse.g=896.00
-lavfi.psnr.psnr.g=18.61
-lavfi.psnr.mse.b=277.38
-lavfi.psnr.psnr.b=23.70
-lavfi.psnr.mse_avg=851.73
-lavfi.psnr.psnr_avg=18.83
+lavfi.psnr.mse.r=1367.642090
+lavfi.psnr.psnr.r=16.771078
+lavfi.psnr.mse.g=885.804382
+lavfi.psnr.psnr.g=18.657425
+lavfi.psnr.mse.b=274.825073
+lavfi.psnr.psnr.b=23.740240
+lavfi.psnr.mse_avg=842.757202
+lavfi.psnr.psnr_avg=18.873779
 frame:1pts:1   pts_time:1
-lavfi.psnr.mse.r=1380.37
-lavfi.psnr.psnr.r=16.73
-lavfi.psnr.mse.g=975.91
-lavfi.psnr.psnr.g=18.24
-lavfi.psnr.mse.b=435.72
-lavfi.psnr.psnr.b=21.74
-lavfi.psnr.mse_avg=930.67
-lavfi.psnr.psnr_avg=18.44
+lavfi.psnr.mse.r=1356.681152
+lavfi.psnr.psnr.r=16.806026
+lavfi.psnr.mse.g=958.161560
+lavfi.psnr.psnr.g=18.316416
+lavfi.psnr.mse.b=428.238312
+lavfi.psnr.psnr.b=21.813948
+lavfi.psnr.mse_avg=914.360352
+lavfi.psnr.psnr_avg=18.519630
 frame:2pts:2   pts_time:2
-lavfi.psnr.mse.r=1403.20
-lavfi.psnr.psnr.r=16.66
-lavfi.psnr.mse.g=954.05
-lavfi.psnr.psnr.g=18.34
-lavfi.psnr.mse.b=494.22
-lavfi.psnr.psnr.b=21.19
-lavfi.psnr.mse_avg=950.49
-lavfi.psnr.psnr_avg=18.35
+lavfi.psnr.mse.r=1387.254883
+lavfi.psnr.psnr.r=16.709242
+lavfi.psnr.mse.g=939.230957
+lavfi.psnr.psnr.g=18.403080
+lavfi.psnr.mse.b=493.913757
+lavfi.psnr.psnr.b=21.194292
+lavfi.psnr.mse_avg=940.133179
+lavfi.psnr.psnr_avg=18.398911
 frame:3pts:3   pts_time:3
-lavfi.psnr.mse.r=1452.80
-lavfi.psnr.psnr.r=16.51
-lavfi.psnr.mse.g=1001.02
-lavfi.psnr.psnr.g=18.13
-lavfi.psnr.mse.b=557.39
-lavfi.psnr.psnr.b=20.67
-lavfi.psnr.mse_avg=1003.74
-lavfi.psnr.psnr_avg=18.11
+lavfi.psnr.mse.r=1433.291260
+lavfi.psnr.psnr.r=16.567459
+lavfi.psnr.mse.g=990.005859
+lavfi.psnr.psnr.g=18.174425
+lavfi.psnr.mse.b=550.512329
+lavfi.psnr.psnr.b=20.723133
+lavfi.psnr.mse_avg=991.269836
+lavfi.psnr.psnr_avg=18.168884
 frame:4pts:4   pts_time:4
-lavfi.psnr.mse.r=1401.25
-lavfi.psnr.psnr.r=16.67
-lavfi.psnr.mse.g=1009.80
-lavfi.psnr.psnr.g=18.09
-lavfi.psnr.mse.b=602.42
-lavfi.psnr.psnr.b=20.33
-lavfi.psnr.mse_avg=1004.49
-lavfi.psnr.psnr_avg=18.11
+lavfi.psnr.mse.r=1385.949341
+lavfi.psnr.psnr.r=16.713329
+lavfi.psnr.mse.g=997.065796
+lavfi.psnr.psnr.g=18.143566
+lavfi.psnr.mse.b=601.962952
+lavfi.psnr.psnr.b=20.335106
+lavfi.psnr.mse_avg=994.992676
+lavfi.psnr.psnr_avg=18.152605
diff --git a/tests/refcmp-metadata.awk b/tests/refcmp-metadata.awk
index fa21aad0e0..e7ed5ae809 100644
--- a/tests/refcmp-metadata.awk
+++ b/tests/refcmp-metadata.awk
@@ -50,12 +50,15 @@ BEGIN {
 }
 
 END {
+result = result && (NR != 0);
 if (result) {
 for (i = 1; i <= ref_nr; i++)
 print ref_lines[i];
 } else {
 for (i = 1; i <= NR; i++)
 print cmp_lines[i];
+if (NR == 0)
+print "[refcmp] no input";
 if (NR != ref_nr)
 print "[refcmp] lines: " NR " != " ref_nr > "/dev/stderr";
 if (delta_max >= fuzz)
-- 
2.31.1

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

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


Re: [FFmpeg-devel] [PATCH] MAINTAINERS: add myself as maintainer for libsrt protocol

2022-03-30 Thread Marton Balint




On Fri, 25 Mar 2022, Zhao Zhili wrote:


Signed-off-by: Zhao Zhili 
---
MAINTAINERS | 1 +
1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 931cf4bd2c..5daa6f8e03 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -516,6 +516,7 @@ Protocols:
  bluray.c  Petri Hintukainen
  ftp.c Lukasz Marek
  http.cRonald S. Bultje
+  libsrt.c  Zhao Zhili
  libssh.c  Lukasz Marek
  libzmq.c  Andriy Gelman
  mms*.cRonald S. Bultje


LGTM, thanks.

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

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


[FFmpeg-devel] [PATCH] avcodec/libvpxenc: enable dynamic max quantizer parameter reconfiguration

2022-03-30 Thread Danil Chapovalov
---
 doc/encoders.texi  | 3 +++
 libavcodec/libvpxenc.c | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 4b8cc69c0d..a304f865a6 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1996,8 +1996,11 @@ kilobits/s.
 @item keyint_min (@emph{kf-min-dist})
 
 @item qmin (@emph{min-q})
+Minimum (Best Quality) Quantizer.
 
 @item qmax (@emph{max-q})
+Maximum (Worst Quality) Quantizer.
+Can be changed per-frame.
 
 @item bufsize (@emph{buf-sz}, @emph{buf-optimal-sz})
 Set ratecontrol buffer size (in bits). Note @command{vpxenc}'s options are
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index dff1d06b0e..463a658bb0 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -1625,6 +1625,12 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket 
*pkt,
 vpx_svc_layer_id_t layer_id;
 int layer_id_valid = 0;
 
+if (avctx->qmax >= 0 && enccfg->rc_max_quantizer != avctx->qmax) {
+struct vpx_codec_enc_cfg cfg = *enccfg;
+cfg.rc_max_quantizer = avctx->qmax;
+vpx_codec_enc_config_set(&ctx->encoder, &cfg);
+}
+
 if (frame) {
 const AVFrameSideData *sd = av_frame_get_side_data(frame, 
AV_FRAME_DATA_REGIONS_OF_INTEREST);
 rawimg  = &ctx->rawimg;
-- 
2.35.1.1021.g381101b075-goog

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

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


Re: [FFmpeg-devel] [PATCH] Add decoding of > 32-bit residuals to FLAC

2022-03-30 Thread Martijn van Beurden
First of all, thanks for reviewing

Op wo 30 mrt. 2022 om 12:42 schreef Andreas Rheinhardt
:
> Can this happen with real encoders or has this file been specifically
> crafted? What is the performance impact of this patch on ordinary files?

This file has been crafted. It seems unlikely to occur in the wild,
but it is not impossible.

Anyway, I found this 'problem' while doing some research for the IETF
CELLAR working group, which is in the process of creating an RFC on
FLAC. Perhaps I sent in this patch too hastily, on second thought it
might be better to fix this in FLAC encoder implementations, of which
there are few, instead of FLAC decoders, of which there are many. As
the IETF is in the process of amending the FLAC specification anyway,
such a provision could very well be included.

Sorry for sending this patch in too soon, once more thanks for reviewing this.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 2/2] avfilter/src_movie: add option to set decoding thread type

2022-03-30 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi|  3 +++
 libavfilter/src_movie.c | 11 +--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 1d56d24819..af332041e8 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -28790,6 +28790,9 @@ timestamps.
 @item dec_threads
 Specifies the number of threads for decoding
 
+@item dec_thread_type
+Specifies the thread type for decoding.
+
 @item format_opts
 Specify format options for the opened file. Format options can be specified
 as a list of @var{key}=@var{value} pairs separated by ':'. The following 
example
diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index 78b87cf444..09d107ee8f 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -72,6 +72,7 @@ typedef struct MovieContext {
 int64_t discontinuity_threshold;
 int64_t ts_offset;
 int dec_threads;
+int thread_type;
 int got_eagain;
 
 AVFormatContext *format_ctx;
@@ -98,6 +99,10 @@ static const AVOption movie_options[]= {
 { "loop", "set loop count",  OFFSET(loop_count),   
AV_OPT_TYPE_INT,{.i64 =  1},  0,INT_MAX, FLAGS },
 { "discontinuity", "set discontinuity threshold", 
OFFSET(discontinuity_threshold), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, 
INT64_MAX, FLAGS },
 { "dec_threads",  "set the number of threads for decoding", 
OFFSET(dec_threads), AV_OPT_TYPE_INT, {.i64 =  0}, 0, INT_MAX, FLAGS },
+{ "dec_thread_type","set the type of threads for decoding", 
OFFSET(thread_type), AV_OPT_TYPE_INT, {.i64 =  0}, 0, 2, FLAGS, .unit = 
"thread_type" },
+{ "auto", "auto",0, AV_OPT_TYPE_CONST, 
{.i64 = 0}, 0, 0, FLAGS, .unit = "thread_type" },
+{ "frame","more than one frame at once", 0, AV_OPT_TYPE_CONST, 
{.i64 = 1}, 0, 0, FLAGS, .unit = "thread_type" },
+{ "slice","more than one part of single frame at once", 0, 
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, FLAGS, .unit = "thread_type" },
 { "format_opts",  "set format options for the opened file", 
OFFSET(format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
 { NULL },
 };
@@ -158,7 +163,7 @@ static AVStream *find_stream(void *log, AVFormatContext 
*avf, const char *spec)
 return found;
 }
 
-static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads)
+static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads, 
int thread_type)
 {
 const AVCodec *codec;
 int ret;
@@ -180,6 +185,8 @@ static int open_stream(AVFilterContext *ctx, MovieStream 
*st, int dec_threads)
 if (!dec_threads)
 dec_threads = ff_filter_get_nb_threads(ctx);
 st->codec_ctx->thread_count = dec_threads;
+if (thread_type)
+st->codec_ctx->thread_type = thread_type;
 
 if ((ret = avcodec_open2(st->codec_ctx, codec, NULL)) < 0) {
 av_log(ctx, AV_LOG_ERROR, "Failed to open codec\n");
@@ -324,7 +331,7 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
 if (ret < 0)
 return ret;
 }
-ret = open_stream(ctx, &movie->st[i], movie->dec_threads);
+ret = open_stream(ctx, &movie->st[i], movie->dec_threads, 
movie->thread_type);
 if (ret < 0)
 return ret;
 }
-- 
2.35.1

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

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


[FFmpeg-devel] [PATCH 1/2] avfilter/src_movie: switch to activate()

2022-03-30 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavfilter/src_movie.c | 76 -
 1 file changed, 45 insertions(+), 31 deletions(-)

diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index 711854c23c..78b87cf444 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -46,6 +46,7 @@
 
 #include "audio.h"
 #include "avfilter.h"
+#include "filters.h"
 #include "formats.h"
 #include "internal.h"
 #include "video.h"
@@ -55,6 +56,7 @@ typedef struct MovieStream {
 AVCodecContext *codec_ctx;
 int64_t discontinuity_threshold;
 int64_t last_pts;
+int got_eof;
 } MovieStream;
 
 typedef struct MovieContext {
@@ -70,6 +72,7 @@ typedef struct MovieContext {
 int64_t discontinuity_threshold;
 int64_t ts_offset;
 int dec_threads;
+int got_eagain;
 
 AVFormatContext *format_ctx;
 
@@ -100,7 +103,6 @@ static const AVOption movie_options[]= {
 };
 
 static int movie_config_output_props(AVFilterLink *outlink);
-static int movie_request_frame(AVFilterLink *outlink);
 
 static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec)
 {
@@ -314,7 +316,6 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
 if (!pad.name)
 return AVERROR(ENOMEM);
 pad.config_props  = movie_config_output_props;
-pad.request_frame = movie_request_frame;
 if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
 return ret;
 if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
@@ -554,47 +555,60 @@ static int movie_push_frame(AVFilterContext *ctx, 
unsigned out_id)
 return 0;
 }
 
-static int movie_request_frame(AVFilterLink *outlink)
+static int activate(AVFilterContext *ctx)
 {
-AVFilterContext *ctx = outlink->src;
 MovieContext  *movie = ctx->priv;
-unsigned out_id = FF_OUTLINK_IDX(outlink);
-
-while (1) {
-int got_eagain = 0, got_eof = 0;
-int ret = 0;
+int ret = 0, x = 0;
 
-/* check all decoders for available output */
-for (int i = 0; i < ctx->nb_outputs; i++) {
+/* check all decoders for available output */
+for (int i = 0; i < ctx->nb_outputs; i++) {
+if (ff_outlink_frame_wanted(ctx->outputs[i])) {
 ret = movie_push_frame(ctx, i);
 if (ret == AVERROR(EAGAIN))
-got_eagain++;
+movie->got_eagain++;
 else if (ret == AVERROR_EOF)
-got_eof++;
+movie->st[i].got_eof++;
 else if (ret < 0)
 return ret;
-else if (i == out_id)
-return 0;
+x++;
 }
+}
 
-if (got_eagain) {
-/* all decoders require more input -> read a new packet */
-ret = movie_decode_packet(ctx);
+if (movie->got_eagain) {
+/* all decoders require more input -> read a new packet */
+movie->got_eagain = 0;
+ret = movie_decode_packet(ctx);
+if (ret < 0 && ret != AVERROR(EAGAIN))
+return ret;
+ff_filter_set_ready(ctx, 100);
+return 0;
+} else {
+int nb_eofs = 0;
+
+for (int i = 0; i < ctx->nb_outputs; i++) {
+if (movie->st[i].got_eof && movie->loop_count == 1)
+ff_outlink_set_status(ctx->outputs[i], AVERROR_EOF, 
movie->st[i].last_pts);
+nb_eofs++;
+}
+
+if (nb_eofs != ctx->nb_outputs) {
+ff_filter_set_ready(ctx, 100);
+return 0;
+}
+
+if (movie->loop_count != 1) {
+ret = rewind_file(ctx);
 if (ret < 0)
 return ret;
-} else if (got_eof) {
-/* all decoders flushed */
-if (movie->loop_count != 1) {
-ret = rewind_file(ctx);
-if (ret < 0)
-return ret;
-movie->loop_count -= movie->loop_count > 1;
-av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");
-continue;
-}
-return AVERROR_EOF;
+movie->loop_count -= movie->loop_count > 1;
+av_log(ctx, AV_LOG_VERBOSE, "Stream finished, looping.\n");
+for (int i = 0; i < ctx->nb_outputs; i++)
+movie->st[i].got_eof = 0;
 }
+return 0;
 }
+
+return FFERROR_NOT_READY;
 }
 
 static int process_command(AVFilterContext *ctx, const char *cmd, const char 
*args,
@@ -651,7 +665,7 @@ const AVFilter ff_avsrc_movie = {
 .init  = movie_common_init,
 .uninit= movie_uninit,
 FILTER_QUERY_FUNC(movie_query_formats),
-
+.activate  = activate,
 .inputs= NULL,
 .outputs   = NULL,
 .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
@@ -670,7 +684,7 @@ const AVFilter ff_avsrc_amovie = {
 .init  = movie_common_init,
 .uninit= movie_uninit,
 FILTER_QUERY_FUNC(movie_query_formats),
-
+.activat

[FFmpeg-devel] minterpolate filter with Multi-Threading Support?

2022-03-30 Thread Thibault MORISSE
Hi FFMPEG Community,

minterpolate filter gives really great results, however since it's single
threaded, it's super duper slow.

Is there a way to request for multi-thread support?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] [PATCH] libavformat/mov: Expose Quicktime poster_time value as metadata TAG.

2022-03-30 Thread Bryce Newman
Hello,
I was wondering if there are any comments on this patch request?
Thank you in advance.
Bryce



Bryce Chester Newman | Principal Developer
 
p: +12069255045 | 



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

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


Re: [FFmpeg-devel] [PATCH v10 1/1] avformat: Add IPFS protocol support.

2022-03-30 Thread Mark Gaiser
On Wed, Mar 30, 2022 at 3:57 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Mark Gaiser:
> > On Wed, Mar 30, 2022 at 2:21 PM Andreas Rheinhardt <
> > andreas.rheinha...@outlook.com> wrote:
> >
> >> Mark Gaiser:
> >>> This patch adds support for:
> >>> - ffplay ipfs://
> >>> - ffplay ipns://
> >>>
> >>> IPFS data can be played from so called "ipfs gateways".
> >>> A gateway is essentially a webserver that gives access to the
> >>> distributed IPFS network.
> >>>
> >>> This protocol support (ipfs and ipns) therefore translates
> >>> ipfs:// and ipns:// to a http:// url. This resulting url is
> >>> then handled by the http protocol. It could also be https
> >>> depending on the gateway provided.
> >>>
> >>> To use this protocol, a gateway must be provided.
> >>> If you do nothing it will try to find it in your
> >>> $HOME/.ipfs/gateway file. The ways to set it manually are:
> >>> 1. Define a -gateway  to the gateway.
> >>> 2. Define $IPFS_GATEWAY with the full http link to the gateway.
> >>> 3. Define $IPFS_PATH and point it to the IPFS data path.
> >>> 4. Have IPFS running in your local user folder (under $HOME/.ipfs).
> >>>
> >>> Signed-off-by: Mark Gaiser 
> >>> ---
> >>>  configure |   2 +
> >>>  doc/protocols.texi|  30 
> >>>  libavformat/Makefile  |   2 +
> >>>  libavformat/ipfsgateway.c | 309 ++
> >>>  libavformat/protocols.c   |   2 +
> >>>  5 files changed, 345 insertions(+)
> >>>  create mode 100644 libavformat/ipfsgateway.c
> >>>
> >>> diff --git a/configure b/configure
> >>> index e4d36aa639..55af90957a 100755
> >>> --- a/configure
> >>> +++ b/configure
> >>> @@ -3579,6 +3579,8 @@ udp_protocol_select="network"
> >>>  udplite_protocol_select="network"
> >>>  unix_protocol_deps="sys_un_h"
> >>>  unix_protocol_select="network"
> >>> +ipfs_protocol_select="https_protocol"
> >>> +ipns_protocol_select="https_protocol"
> >>>
> >>>  # external library protocols
> >>>  libamqp_protocol_deps="librabbitmq"
> >>> diff --git a/doc/protocols.texi b/doc/protocols.texi
> >>> index d207df0b52..7c9c0a4808 100644
> >>> --- a/doc/protocols.texi
> >>> +++ b/doc/protocols.texi
> >>> @@ -2025,5 +2025,35 @@ decoding errors.
> >>>
> >>>  @end table
> >>>
> >>> +@section ipfs
> >>> +
> >>> +InterPlanetary File System (IPFS) protocol support. One can access
> >> files stored
> >>> +on the IPFS network through so called gateways. Those are http(s)
> >> endpoints.
> >>> +This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to
> >> be send
> >>> +to such a gateway. Users can (and should) host their own node which
> >> means this
> >>> +protocol will use your local machine gateway to access files on the
> >> IPFS network.
> >>> +
> >>> +If a user doesn't have a node of their own then the public gateway
> >> dweb.link is
> >>> +used by default.
> >>> +
> >>> +You can use this protocol in 2 ways. Using IPFS:
> >>> +@example
> >>> +ffplay ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
> >>> +@end example
> >>> +
> >>> +Or the IPNS protocol (IPNS is mutable IPFS):
> >>> +@example
> >>> +ffplay ipns://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
> >>> +@end example
> >>> +
> >>> +You can also change the gateway to be used:
> >>> +
> >>> +@table @option
> >>> +
> >>> +@item gateway
> >>> +Defines the gateway to use. When nothing is provided the protocol will
> >> first try
> >>> +your local gateway. If that fails dweb.link will be used.
> >>> +
> >>> +@end table
> >>>
> >>>  @c man end PROTOCOLS
> >>> diff --git a/libavformat/Makefile b/libavformat/Makefile
> >>> index d7182d6bd8..e3233fd7ac 100644
> >>> --- a/libavformat/Makefile
> >>> +++ b/libavformat/Makefile
> >>> @@ -660,6 +660,8 @@ OBJS-$(CONFIG_SRTP_PROTOCOL) +=
> >> srtpproto.o srtp.o
> >>>  OBJS-$(CONFIG_SUBFILE_PROTOCOL)  += subfile.o
> >>>  OBJS-$(CONFIG_TEE_PROTOCOL)  += teeproto.o tee_common.o
> >>>  OBJS-$(CONFIG_TCP_PROTOCOL)  += tcp.o
> >>> +OBJS-$(CONFIG_IPFS_PROTOCOL) += ipfsgateway.o
> >>> +OBJS-$(CONFIG_IPNS_PROTOCOL) += ipfsgateway.o
> >>>  TLS-OBJS-$(CONFIG_GNUTLS)+= tls_gnutls.o
> >>>  TLS-OBJS-$(CONFIG_LIBTLS)+= tls_libtls.o
> >>>  TLS-OBJS-$(CONFIG_MBEDTLS)   += tls_mbedtls.o
> >>> diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c
> >>> new file mode 100644
> >>> index 00..1a039589c0
> >>> --- /dev/null
> >>> +++ b/libavformat/ipfsgateway.c
> >>> @@ -0,0 +1,309 @@
> >>> +/*
> >>> + * IPFS and IPNS protocol support through IPFS Gateway.
> >>> + * Copyright (c) 2022 Mark Gaiser
> >>> + *
> >>> + * This file is part of FFmpeg.
> >>> + *
> >>> + * FFmpeg is free software; you can redistribute it and/or
> >>> + * modify it under the terms of the GNU Lesser General Public
> >>> + * License as published by the Free Software Foundation; either
> >>> + * version 2.1 of the License, or (at your option) any later version.
> >

Re: [FFmpeg-devel] [PATCH] doc/bitstream_filters: fix for the syntax of code

2022-03-30 Thread lance . lmwang
On Wed, Mar 30, 2022 at 08:11:11PM +0530, Gyan Doshi wrote:
> 
> 
> On 2022-03-30 07:21 pm, lance.lmw...@gmail.com wrote:
> > From: Limin Wang 
> > 
> > Signed-off-by: Limin Wang 
> > ---
> >   doc/bitstream_filters.texi | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> > index 0b354fd..fc2c71f 100644
> > --- a/doc/bitstream_filters.texi
> > +++ b/doc/bitstream_filters.texi
> > @@ -328,7 +328,7 @@ See H.264 section D.1.27 and D.2.27 for syntax and 
> > semantics.
> >   Default is pass.
> > -Insert mode works in conjunction with @code {rotate} and @code{flip} 
> > options.
> > +Insert mode works in conjunction with @code{rotate} and @code{flip} 
> > options.
> 
> The space doesn't lead to a rendering error. LGTM, anyway.

Yes, it's for My build system have several warning message when make.

> 
> Gyan
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

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


[FFmpeg-devel] [PATCH v10 5/5] fate/jpegxl: add Jpeg XL demux and parse FATE test

2022-03-30 Thread Leo Izen
Add a fate test for the Jpeg XL parser in libavcodec and
its image2 wrapper inside libavformat.
---
 tests/fate/image.mak| 10 ++
 tests/ref/fate/jxl-parse-codestream |  6 ++
 tests/ref/fate/jxl-parse-container  |  6 ++
 3 files changed, 22 insertions(+)
 create mode 100644 tests/ref/fate/jxl-parse-codestream
 create mode 100644 tests/ref/fate/jxl-parse-container

diff --git a/tests/fate/image.mak b/tests/fate/image.mak
index 573d398915..15b6145c58 100644
--- a/tests/fate/image.mak
+++ b/tests/fate/image.mak
@@ -357,6 +357,16 @@ FATE_JPEGLS-$(call DEMDEC, IMAGE2, JPEGLS) += 
$(FATE_JPEGLS)
 FATE_IMAGE += $(FATE_JPEGLS-yes)
 fate-jpegls: $(FATE_JPEGLS-yes)
 
+FATE_JPEGXL += fate-jxl-parse-codestream
+fate-jxl-parse-codestream: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/belgium.jxl 
-c:v copy
+
+FATE_JPEGXL += fate-jxl-parse-container
+fate-jxl-parse-container: CMD = framecrc -i 
$(TARGET_SAMPLES)/jxl/lenna-256.jxl -c:v copy
+
+FATE_JPEGXL-$(call DEMDEC, IMAGE2) += $(FATE_JPEGXL)
+FATE_IMAGE += $(FATE_JPEGXL-yes)
+fate-jxl: $(FATE_JPEGXL-yes)
+
 FATE_IMAGE-$(call DEMDEC, IMAGE2, QDRAW) += fate-pict
 fate-pict: CMD = framecrc -i $(TARGET_SAMPLES)/quickdraw/TRU256.PCT -pix_fmt 
rgb24
 
diff --git a/tests/ref/fate/jxl-parse-codestream 
b/tests/ref/fate/jxl-parse-codestream
new file mode 100644
index 00..b2fe5035ac
--- /dev/null
+++ b/tests/ref/fate/jxl-parse-codestream
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 768x512
+#sar 0: 0/1
+0,  0,  0,1,   32, 0xa2930a20
diff --git a/tests/ref/fate/jxl-parse-container 
b/tests/ref/fate/jxl-parse-container
new file mode 100644
index 00..99233d612a
--- /dev/null
+++ b/tests/ref/fate/jxl-parse-container
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 256x256
+#sar 0: 0/1
+0,  0,  0,1, 8088, 0xbbfea9bd
-- 
2.35.1

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

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


[FFmpeg-devel] [PATCH v10 4/5] avformat/image2: add Jpeg XL as image2 format

2022-03-30 Thread Leo Izen
This commit adds support to libavformat for muxing
and demuxing Jpeg XL images as image2 streams.
---
 libavformat/allformats.c |  1 +
 libavformat/img2.c   |  1 +
 libavformat/img2dec.c| 21 +
 libavformat/img2enc.c|  6 +++---
 libavformat/mov.c|  1 +
 libavformat/version.h|  4 ++--
 6 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 587ad59b3c..941f3643f8 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -510,6 +510,7 @@ extern const AVInputFormat  ff_image_gif_pipe_demuxer;
 extern const AVInputFormat  ff_image_j2k_pipe_demuxer;
 extern const AVInputFormat  ff_image_jpeg_pipe_demuxer;
 extern const AVInputFormat  ff_image_jpegls_pipe_demuxer;
+extern const AVInputFormat  ff_image_jpegxl_pipe_demuxer;
 extern const AVInputFormat  ff_image_pam_pipe_demuxer;
 extern const AVInputFormat  ff_image_pbm_pipe_demuxer;
 extern const AVInputFormat  ff_image_pcx_pipe_demuxer;
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 4153102c92..13b1b997b8 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -87,6 +87,7 @@ const IdStrMap ff_img_tags[] = {
 { AV_CODEC_ID_GEM,"img"  },
 { AV_CODEC_ID_GEM,"ximg" },
 { AV_CODEC_ID_GEM,"timg" },
+{ AV_CODEC_ID_JPEGXL, "jxl"  },
 { AV_CODEC_ID_NONE,   NULL   }
 };
 
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index b9c06c5b54..32cadacb9d 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -32,6 +32,7 @@
 #include "libavutil/parseutils.h"
 #include "libavutil/intreadwrite.h"
 #include "libavcodec/gif.h"
+#include "libavcodec/jpegxl.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "internal.h"
@@ -836,6 +837,25 @@ static int jpegls_probe(const AVProbeData *p)
 return 0;
 }
 
+static int jpegxl_probe(const AVProbeData *p)
+{
+const uint8_t *b = p->buf;
+
+/* ISOBMFF-based container */
+/* 0x4a584c20 == "JXL " */
+if (AV_RL64(b) == FF_JPEGXL_CONTAINER_SIGNATURE_LE)
+return AVPROBE_SCORE_EXTENSION + 1;
+#if CONFIG_JPEGXL_PARSER
+/* Raw codestreams all start with 0xff0a */
+if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
+return 0;
+if (avpriv_jpegxl_verify_codestream_header(NULL, p->buf, p->buf_size) == 0)
+return AVPROBE_SCORE_MAX - 2;
+#endif
+return 0;
+}
+
+
 static int pcx_probe(const AVProbeData *p)
 {
 const uint8_t *b = p->buf;
@@ -1165,6 +1185,7 @@ IMAGEAUTO_DEMUXER(gif,   GIF)
 IMAGEAUTO_DEMUXER_EXT(j2k,   JPEG2000, J2K)
 IMAGEAUTO_DEMUXER_EXT(jpeg,  MJPEG, JPEG)
 IMAGEAUTO_DEMUXER(jpegls,JPEGLS)
+IMAGEAUTO_DEMUXER(jpegxl,JPEGXL)
 IMAGEAUTO_DEMUXER(pam,   PAM)
 IMAGEAUTO_DEMUXER(pbm,   PBM)
 IMAGEAUTO_DEMUXER(pcx,   PCX)
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 9b3b8741c8..e6ec6a50aa 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -263,9 +263,9 @@ static const AVClass img2mux_class = {
 const AVOutputFormat ff_image2_muxer = {
 .name   = "image2",
 .long_name  = NULL_IF_CONFIG_SMALL("image2 sequence"),
-.extensions = 
"bmp,dpx,exr,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,png,"
-  
"ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,im24,"
-  "sunras,xbm,xface,pix,y",
+.extensions = 
"bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,"
+  
"png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,"
+  "im24,sunras,xbm,xface,pix,y",
 .priv_data_size = sizeof(VideoMuxData),
 .video_codec= AV_CODEC_ID_MJPEG,
 .write_header   = write_header,
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6c847de164..c4b8873b0a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7697,6 +7697,7 @@ static int mov_probe(const AVProbeData *p)
 if (tag == MKTAG('f','t','y','p') &&
(   AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' 
')
 || AV_RL32(p->buf + offset + 8) == MKTAG('j','p','x',' 
')
+|| AV_RL32(p->buf + offset + 8) == MKTAG('j','x','l',' 
')
 )) {
 score = FFMAX(score, 5);
 } else {
diff --git a/libavformat/version.h b/libavformat/version.h
index f4a26c2870..683184d5da 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,8 +31,8 @@
 
 #include "version_major.h"
 
-#define LIBAVFORMAT_VERSION_MINOR  20
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MINOR  21
+#define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
-- 
2.35.1

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

[FFmpeg-devel] [PATCH v10 3/5] avcodec/libjxl: add Jpeg XL encoding via libjxl

2022-03-30 Thread Leo Izen
This commit adds encoding support to libavcodec
for Jpeg XL images via the external library libjxl.
---
 configure  |   3 +-
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libjxlenc.c | 379 +
 4 files changed, 383 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libjxlenc.c

diff --git a/configure b/configure
index 969b13eba3..85a1a8b53c 100755
--- a/configure
+++ b/configure
@@ -240,7 +240,7 @@ External library support:
   --enable-libiec61883 enable iec61883 via libiec61883 [no]
   --enable-libilbc enable iLBC de/encoding via libilbc [no]
   --enable-libjack enable JACK audio sound server [no]
-  --enable-libjxl  enable JPEG XL decoding via libjxl [no]
+  --enable-libjxl  enable JPEG XL de/encoding via libjxl [no]
   --enable-libklvanc   enable Kernel Labs VANC processing [no]
   --enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
   --enable-liblensfun  enable lensfun lens correction [no]
@@ -3332,6 +3332,7 @@ libgsm_ms_encoder_deps="libgsm"
 libilbc_decoder_deps="libilbc"
 libilbc_encoder_deps="libilbc"
 libjxl_decoder_deps="libjxl libjxl_threads"
+libjxl_encoder_deps="libjxl libjxl_threads"
 libkvazaar_encoder_deps="libkvazaar"
 libmodplug_demuxer_deps="libmodplug"
 libmp3lame_encoder_deps="libmp3lame"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c00b0d3246..b208cc0097 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1061,6 +1061,7 @@ OBJS-$(CONFIG_LIBGSM_MS_ENCODER)  += libgsmenc.o
 OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o
 OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
 OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
+OBJS-$(CONFIG_LIBJXL_ENCODER) += libjxlenc.o libjxl.o
 OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
 OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a9cd69dfce..db92fb7af5 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -750,6 +750,7 @@ extern const FFCodec ff_libgsm_ms_decoder;
 extern const FFCodec ff_libilbc_encoder;
 extern const FFCodec ff_libilbc_decoder;
 extern const FFCodec ff_libjxl_decoder;
+extern const FFCodec ff_libjxl_encoder;
 extern const FFCodec ff_libmp3lame_encoder;
 extern const FFCodec ff_libopencore_amrnb_encoder;
 extern const FFCodec ff_libopencore_amrnb_decoder;
diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
new file mode 100644
index 00..deacc0f1f8
--- /dev/null
+++ b/libavcodec/libjxlenc.c
@@ -0,0 +1,379 @@
+/*
+ * JPEG XL encoding support via libjxl
+ * Copyright (c) 2021 Leo Izen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * JPEG XL encoder using libjxl
+ */
+
+#include "libavutil/avutil.h"
+#include "libavutil/error.h"
+#include "libavutil/frame.h"
+#include "libavutil/libm.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/pixfmt.h"
+#include "libavutil/version.h"
+
+#include "avcodec.h"
+#include "codec_internal.h"
+
+#include 
+#include 
+#include "libjxl.h"
+
+typedef struct LibJxlEncodeContext {
+AVClass *class;
+void *runner;
+JxlEncoder *encoder;
+JxlEncoderFrameSettings *options;
+int effort;
+float distance;
+int modular;
+uint8_t *buffer;
+size_t buffer_size;
+} LibJxlEncodeContext;
+
+/**
+ * Map a quality setting for -qscale roughly from libjpeg
+ * quality numbers to libjxl's butteraugli distance for
+ * photographic content.
+ *
+ * Setting distance explicitly is preferred, but this will
+ * allow qscale to be used as a fallback.
+ *
+ * This function is continuous and injective on [0, 100] which
+ * makes it monotonic.
+ *
+ * @param  quality 0.0 to 100.0 quality setting, libjpeg quality
+ * @return Butteraugli distance between 0.0 and 15.0
+ */
+static float quality_to_distance(float quality)
+{
+if (quality >= 100.0)
+return 0.0;
+else if (quality >= 90.0)
+return (100.0 - quality) * 0.10;
+else if (quality >= 30.0)
+return 0.1 + (100.0 - quality) * 0.09;
+  

[FFmpeg-devel] [PATCH v10 2/5] avcodec/libjxl: add Jpeg XL decoding via libjxl

2022-03-30 Thread Leo Izen
This commit adds decoding support to libavcodec
for Jpeg XL images via the external library libjxl.
---
 MAINTAINERS   |   1 +
 configure |   5 +
 doc/general_contents.texi |   7 +
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/libjxl.c   |  70 +
 libavcodec/libjxl.h   |  48 ++
 libavcodec/libjxldec.c| 301 ++
 8 files changed, 434 insertions(+)
 create mode 100644 libavcodec/libjxl.c
 create mode 100644 libavcodec/libjxl.h
 create mode 100644 libavcodec/libjxldec.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 9ab08bad8e..fd79234d23 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -195,6 +195,7 @@ Codecs:
   libcodec2.c   Tomas Härdin
   libdirac* David Conrad
   libdavs2.cHuiwen Ren
+  libjxl*.c, libjxl.h   Leo Izen
   libgsm.c  Michel Bardiaux
   libkvazaar.c  Arttu Ylä-Outinen
   libopenh264enc.c  Martin Storsjo, Linjie Fu
diff --git a/configure b/configure
index e4d36aa639..969b13eba3 100755
--- a/configure
+++ b/configure
@@ -240,6 +240,7 @@ External library support:
   --enable-libiec61883 enable iec61883 via libiec61883 [no]
   --enable-libilbc enable iLBC de/encoding via libilbc [no]
   --enable-libjack enable JACK audio sound server [no]
+  --enable-libjxl  enable JPEG XL decoding via libjxl [no]
   --enable-libklvanc   enable Kernel Labs VANC processing [no]
   --enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
   --enable-liblensfun  enable lensfun lens correction [no]
@@ -1833,6 +1834,7 @@ EXTERNAL_LIBRARY_LIST="
 libiec61883
 libilbc
 libjack
+libjxl
 libklvanc
 libkvazaar
 libmodplug
@@ -3329,6 +3331,7 @@ libgsm_ms_decoder_deps="libgsm"
 libgsm_ms_encoder_deps="libgsm"
 libilbc_decoder_deps="libilbc"
 libilbc_encoder_deps="libilbc"
+libjxl_decoder_deps="libjxl libjxl_threads"
 libkvazaar_encoder_deps="libkvazaar"
 libmodplug_demuxer_deps="libmodplug"
 libmp3lame_encoder_deps="libmp3lame"
@@ -6541,6 +6544,8 @@ enabled libgsm&& { for gsm_hdr in "gsm.h" 
"gsm/gsm.h"; do
check_lib libgsm "${gsm_hdr}" gsm_create 
-lgsm && break;
done || die "ERROR: libgsm not found"; }
 enabled libilbc   && require libilbc ilbc.h WebRtcIlbcfix_InitDecode 
-lilbc $pthreads_extralibs
+enabled libjxl&& require_pkg_config libjxl "libjxl >= 0.7.0" 
jxl/decode.h JxlDecoderVersion &&
+ require_pkg_config libjxl_threads "libjxl_threads 
>= 0.7.0" jxl/thread_parallel_runner.h JxlThreadParallelRunner
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index fcd9da1b34..a893347fbe 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -171,6 +171,13 @@ Go to @url{https://github.com/TimothyGu/libilbc} and 
follow the instructions for
 installing the library. Then pass @code{--enable-libilbc} to configure to
 enable it.
 
+@section libjxl
+
+JPEG XL is an image format intended to fully replace legacy JPEG for an 
extended
+period of life. See @url{https://jpegxl.info/} for more information, and see
+@url{https://github.com/libjxl/libjxl} for the library source. You can pass
+@code{--enable-libjxl} to configure in order enable the libjxl wrapper.
+
 @section libvpx
 
 FFmpeg can make use of the libvpx library for VP8/VP9 decoding and encoding.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3723601b3d..c00b0d3246 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1060,6 +1060,7 @@ OBJS-$(CONFIG_LIBGSM_MS_DECODER)  += libgsmdec.o
 OBJS-$(CONFIG_LIBGSM_MS_ENCODER)  += libgsmenc.o
 OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o
 OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
+OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
 OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
 OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 22d56760ec..a9cd69dfce 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -749,6 +749,7 @@ extern const FFCodec ff_libgsm_ms_encoder;
 extern const FFCodec ff_libgsm_ms_decoder;
 extern const FFCodec ff_libilbc_encoder;
 extern const FFCodec ff_libilbc_decoder;
+extern const FFCodec ff_libjxl_decoder;
 extern const FFCodec ff_libmp3lame_encoder;
 extern const FFCodec ff_libope

[FFmpeg-devel] [PATCH v10 1/5] avcodec/jpegxl: add Jpeg XL image codec and parser

2022-03-30 Thread Leo Izen
This commit adds support to libavcodec to read and parse
encoded Jpeg XL images. Jpeg XL is intended to be an
extended-life replacement to legacy mjpeg.
---
 MAINTAINERS|   2 +
 libavcodec/Makefile|   1 +
 libavcodec/codec_desc.c|   9 +
 libavcodec/codec_id.h  |   1 +
 libavcodec/jpegxl.h|  43 ++
 libavcodec/jpegxl_parser.c | 950 +
 libavcodec/parsers.c   |   1 +
 libavcodec/version.h   |   2 +-
 8 files changed, 1008 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/jpegxl.h
 create mode 100644 libavcodec/jpegxl_parser.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 76e1332ad8..9ab08bad8e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -188,6 +188,7 @@ Codecs:
   interplayvideo.c  Mike Melanson
   jni*, ffjni*  Matthieu Bouron
   jpeg2000* Nicolas Bertrand
+  jpegxl.h, jpegxl_parser.c Leo Izen
   jvdec.c   Peter Ross
   lcl*.cRoberto Togni, Reimar Doeffinger
   libcelt_dec.c Nicolas George
@@ -617,6 +618,7 @@ Haihao Xiang (haihao) 1F0C 31E8 B4FE F7A4 4DC1 DC99 
E0F5 76D4 76FC 437F
 Jaikrishnan Menon 61A1 F09F 01C9 2D45 78E1 C862 25DC 8831 AF70 D368
 James Almer   7751 2E8C FD94 A169 57E6 9A7A 1463 01AD 7376 59E0
 Jean Delvare  7CA6 9F44 60F1 BDC4 1FD2 C858 A552 6B9B B3CD 4E6A
+Leo Izen (thebombzen) B6FD 3CFC 7ACF 83FC 9137 6945 5A71 C331 FD2F A19A
 Loren Merritt ABD9 08F4 C920 3F65 D8BE 35D7 1540 DAA7 060F 56DE
 Lynne FE50 139C 6805 72CA FD52 1F8D A2FE A5F0 3F03 4464
 Michael Niedermayer   9FF2 128B 147E F673 0BAD F133 611E C787 040B 0FAB
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb8b0e824b..3723601b3d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -44,6 +44,7 @@ OBJS = ac3_parser.o   
  \
dv_profile.o \
encode.o \
imgconvert.o \
+   jpegxl_parser.o  \
jni.o\
mathtables.o \
mediacodec.o \
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 81f3b3c640..1b82870aaa 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1863,6 +1863,15 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("GEM Raster image"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_JPEGXL,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "jpegxl",
+.long_name = NULL_IF_CONFIG_SMALL("JPEG XL"),
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
+ AV_CODEC_PROP_LOSSLESS,
+.mime_types= MT("image/jxl"),
+},
 
 /* various PCM "codecs" */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 3ffb9bd22e..dbc4f3a208 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -308,6 +308,7 @@ enum AVCodecID {
 AV_CODEC_ID_SIMBIOSIS_IMX,
 AV_CODEC_ID_SGA_VIDEO,
 AV_CODEC_ID_GEM,
+AV_CODEC_ID_JPEGXL,
 
 /* various PCM "codecs" */
 AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
start of audio codecs
diff --git a/libavcodec/jpegxl.h b/libavcodec/jpegxl.h
new file mode 100644
index 00..a0f266c4ff
--- /dev/null
+++ b/libavcodec/jpegxl.h
@@ -0,0 +1,43 @@
+/*
+ * JPEG XL header
+ * Copyright (c) 2021 Leo Izen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * JPEG XL header
+ */
+
+#ifndef AVCODEC_JPEGXL_H
+#define AVCODEC_JPEGXL_H
+
+#include 
+
+/* these are also used in avformat/img2dec.c */
+#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE 0x0aff
+#define FF_JPEGXL_CODESTREAM_SIGNAT

Re: [FFmpeg-devel] [PATCH] doc/bitstream_filters: fix for the syntax of code

2022-03-30 Thread Gyan Doshi




On 2022-03-30 07:21 pm, lance.lmw...@gmail.com wrote:

From: Limin Wang 

Signed-off-by: Limin Wang 
---
  doc/bitstream_filters.texi | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 0b354fd..fc2c71f 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -328,7 +328,7 @@ See H.264 section D.1.27 and D.2.27 for syntax and 
semantics.
  
  Default is pass.
  
-Insert mode works in conjunction with @code {rotate} and @code{flip} options.

+Insert mode works in conjunction with @code{rotate} and @code{flip} options.


The space doesn't lead to a rendering error. LGTM, anyway.

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

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


Re: [FFmpeg-devel] [PATCH 10/10] avcodec/vc1: Arm 32-bit NEON unescape fast path

2022-03-30 Thread Martin Storsjö

On Fri, 25 Mar 2022, Ben Avison wrote:


checkasm benchmarks on 1.5 GHz Cortex-A72 are as follows.

vc1dsp.vc1_unescape_buffer_c: 918624.7
vc1dsp.vc1_unescape_buffer_neon: 142958.0

Signed-off-by: Ben Avison 
---
libavcodec/arm/vc1dsp_init_neon.c |  61 +++
libavcodec/arm/vc1dsp_neon.S  | 118 ++
2 files changed, 179 insertions(+)


LGTM

// Martin

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

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


Re: [FFmpeg-devel] [PATCH 09/10] avcodec/vc1: Arm 64-bit NEON unescape fast path

2022-03-30 Thread Martin Storsjö

On Fri, 25 Mar 2022, Ben Avison wrote:


checkasm benchmarks on 1.5 GHz Cortex-A72 are as follows.

vc1dsp.vc1_unescape_buffer_c: 655617.7
vc1dsp.vc1_unescape_buffer_neon: 118237.0

Signed-off-by: Ben Avison 
---
libavcodec/aarch64/vc1dsp_init_aarch64.c |  61 
libavcodec/aarch64/vc1dsp_neon.S | 176 +++
2 files changed, 237 insertions(+)


LGTM

// Martin

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

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


Re: [FFmpeg-devel] [PATCH] doc/bitstream_filters: fix for the syntax of code

2022-03-30 Thread Michael Niedermayer
On Wed, Mar 30, 2022 at 09:51:45PM +0800, lance.lmw...@gmail.com wrote:
> From: Limin Wang 
> 
> Signed-off-by: Limin Wang 
> ---
>  doc/bitstream_filters.texi | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

LGTM

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Never trust a computer, one day, it may think you are the virus. -- Compn


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 08/10] avcodec/idctdsp: Arm 64-bit NEON block add and clamp fast paths

2022-03-30 Thread Martin Storsjö

On Fri, 25 Mar 2022, Ben Avison wrote:


checkasm benchmarks on 1.5 GHz Cortex-A72 are as follows.

idctdsp.add_pixels_clamped_c: 323.0
idctdsp.add_pixels_clamped_neon: 41.5
idctdsp.put_pixels_clamped_c: 243.0
idctdsp.put_pixels_clamped_neon: 30.0
idctdsp.put_signed_pixels_clamped_c: 225.7
idctdsp.put_signed_pixels_clamped_neon: 37.7

Signed-off-by: Ben Avison 
---
libavcodec/aarch64/Makefile   |   3 +-
libavcodec/aarch64/idctdsp_init_aarch64.c |  26 +++--
libavcodec/aarch64/idctdsp_neon.S | 130 ++
3 files changed, 150 insertions(+), 9 deletions(-)
create mode 100644 libavcodec/aarch64/idctdsp_neon.S


Generally LGTM


+// Clamp 16-bit signed block coefficients to signed 8-bit (biased by 128)
+// On entry:
+//   x0 -> array of 64x 16-bit coefficients
+//   x1 -> 8-bit results
+//   x2 = row stride for results, bytes
+function ff_put_signed_pixels_clamped_neon, export=1
+ld1 {v0.16b, v1.16b, v2.16b, v3.16b}, [x0], #64
+moviv4.8b, #128
+ld1 {v16.16b, v17.16b, v18.16b, v19.16b}, [x0]
+sqxtn   v0.8b, v0.8h
+sqxtn   v1.8b, v1.8h
+sqxtn   v2.8b, v2.8h
+sqxtn   v3.8b, v3.8h
+sqxtn   v5.8b, v16.8h
+add v0.8b, v0.8b, v4.8b


Here you could save 4 add instructions with sqxtn2 and adding .16b 
vectors, but I'm not sure if it's wortwhile. (It reduces the checkasm 
numbers by 0.7 for Cortex A72, by 0.3 for A73, but increases the runtime 
by 1.0 on A53.) Stranegely enough, I get much smaller numbers on my A72 
than you got. I get these:


idctdsp.add_pixels_clamped_c: 306.7
idctdsp.add_pixels_clamped_neon: 25.7
idctdsp.put_pixels_clamped_c: 217.2
idctdsp.put_pixels_clamped_neon: 15.2
idctdsp.put_signed_pixels_clamped_c: 216.7
idctdsp.put_signed_pixels_clamped_neon: 19.2

(The _c numbers are of course highly compiler dependent, but the assembly 
numbers should generally match quite closely. And AFAIK they should be 
measured in clock cycles, so CPU frequency shouldn't really play a role 
either.)


// Martin

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

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


Re: [FFmpeg-devel] [PATCH 07/10] avcodec/vc1: Arm 64-bit NEON inverse transform fast paths

2022-03-30 Thread Martin Storsjö

On Wed, 30 Mar 2022, Martin Storsjö wrote:


On Fri, 25 Mar 2022, Ben Avison wrote:


checkasm benchmarks on 1.5 GHz Cortex-A72 are as follows.

vc1dsp.vc1_inv_trans_4x4_c: 158.2
vc1dsp.vc1_inv_trans_4x4_neon: 65.7
vc1dsp.vc1_inv_trans_4x4_dc_c: 86.5
vc1dsp.vc1_inv_trans_4x4_dc_neon: 26.5
vc1dsp.vc1_inv_trans_4x8_c: 335.2
vc1dsp.vc1_inv_trans_4x8_neon: 106.2
vc1dsp.vc1_inv_trans_4x8_dc_c: 151.2
vc1dsp.vc1_inv_trans_4x8_dc_neon: 25.5
vc1dsp.vc1_inv_trans_8x4_c: 365.7
vc1dsp.vc1_inv_trans_8x4_neon: 97.2
vc1dsp.vc1_inv_trans_8x4_dc_c: 139.7
vc1dsp.vc1_inv_trans_8x4_dc_neon: 16.5
vc1dsp.vc1_inv_trans_8x8_c: 547.7
vc1dsp.vc1_inv_trans_8x8_neon: 137.0
vc1dsp.vc1_inv_trans_8x8_dc_c: 268.2
vc1dsp.vc1_inv_trans_8x8_dc_neon: 30.5

Signed-off-by: Ben Avison 
---
libavcodec/aarch64/vc1dsp_init_aarch64.c |  19 +
libavcodec/aarch64/vc1dsp_neon.S | 678 +++
2 files changed, 697 insertions(+)


Looks generally reasonable. Is it possible to factorize out the individual 
transforms (so that you'd e.g. invoke the same macro twice in the 8x8 and 4x4 
functions) without too much loss? The downshift which differs between thw two 
could either be left outside of the macro, or the downshift amount could be 
made a macro parameter.


Another aspect: I forgot the aspect that we have existing arm assembly for 
the idct. In some cases, there's value in keeping the implementations 
similar if possible and relevant. But your implementation seems quite 
straightforward, and seems to get better benchmark numbers on the same 
cores, so I guess it's fine to diverge and add a new from-scratch 
implementation here.


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

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


Re: [FFmpeg-devel] [PATCH v10 1/1] avformat: Add IPFS protocol support.

2022-03-30 Thread Andreas Rheinhardt
Mark Gaiser:
> On Wed, Mar 30, 2022 at 2:21 PM Andreas Rheinhardt <
> andreas.rheinha...@outlook.com> wrote:
> 
>> Mark Gaiser:
>>> This patch adds support for:
>>> - ffplay ipfs://
>>> - ffplay ipns://
>>>
>>> IPFS data can be played from so called "ipfs gateways".
>>> A gateway is essentially a webserver that gives access to the
>>> distributed IPFS network.
>>>
>>> This protocol support (ipfs and ipns) therefore translates
>>> ipfs:// and ipns:// to a http:// url. This resulting url is
>>> then handled by the http protocol. It could also be https
>>> depending on the gateway provided.
>>>
>>> To use this protocol, a gateway must be provided.
>>> If you do nothing it will try to find it in your
>>> $HOME/.ipfs/gateway file. The ways to set it manually are:
>>> 1. Define a -gateway  to the gateway.
>>> 2. Define $IPFS_GATEWAY with the full http link to the gateway.
>>> 3. Define $IPFS_PATH and point it to the IPFS data path.
>>> 4. Have IPFS running in your local user folder (under $HOME/.ipfs).
>>>
>>> Signed-off-by: Mark Gaiser 
>>> ---
>>>  configure |   2 +
>>>  doc/protocols.texi|  30 
>>>  libavformat/Makefile  |   2 +
>>>  libavformat/ipfsgateway.c | 309 ++
>>>  libavformat/protocols.c   |   2 +
>>>  5 files changed, 345 insertions(+)
>>>  create mode 100644 libavformat/ipfsgateway.c
>>>
>>> diff --git a/configure b/configure
>>> index e4d36aa639..55af90957a 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -3579,6 +3579,8 @@ udp_protocol_select="network"
>>>  udplite_protocol_select="network"
>>>  unix_protocol_deps="sys_un_h"
>>>  unix_protocol_select="network"
>>> +ipfs_protocol_select="https_protocol"
>>> +ipns_protocol_select="https_protocol"
>>>
>>>  # external library protocols
>>>  libamqp_protocol_deps="librabbitmq"
>>> diff --git a/doc/protocols.texi b/doc/protocols.texi
>>> index d207df0b52..7c9c0a4808 100644
>>> --- a/doc/protocols.texi
>>> +++ b/doc/protocols.texi
>>> @@ -2025,5 +2025,35 @@ decoding errors.
>>>
>>>  @end table
>>>
>>> +@section ipfs
>>> +
>>> +InterPlanetary File System (IPFS) protocol support. One can access
>> files stored
>>> +on the IPFS network through so called gateways. Those are http(s)
>> endpoints.
>>> +This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to
>> be send
>>> +to such a gateway. Users can (and should) host their own node which
>> means this
>>> +protocol will use your local machine gateway to access files on the
>> IPFS network.
>>> +
>>> +If a user doesn't have a node of their own then the public gateway
>> dweb.link is
>>> +used by default.
>>> +
>>> +You can use this protocol in 2 ways. Using IPFS:
>>> +@example
>>> +ffplay ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
>>> +@end example
>>> +
>>> +Or the IPNS protocol (IPNS is mutable IPFS):
>>> +@example
>>> +ffplay ipns://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
>>> +@end example
>>> +
>>> +You can also change the gateway to be used:
>>> +
>>> +@table @option
>>> +
>>> +@item gateway
>>> +Defines the gateway to use. When nothing is provided the protocol will
>> first try
>>> +your local gateway. If that fails dweb.link will be used.
>>> +
>>> +@end table
>>>
>>>  @c man end PROTOCOLS
>>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>>> index d7182d6bd8..e3233fd7ac 100644
>>> --- a/libavformat/Makefile
>>> +++ b/libavformat/Makefile
>>> @@ -660,6 +660,8 @@ OBJS-$(CONFIG_SRTP_PROTOCOL) +=
>> srtpproto.o srtp.o
>>>  OBJS-$(CONFIG_SUBFILE_PROTOCOL)  += subfile.o
>>>  OBJS-$(CONFIG_TEE_PROTOCOL)  += teeproto.o tee_common.o
>>>  OBJS-$(CONFIG_TCP_PROTOCOL)  += tcp.o
>>> +OBJS-$(CONFIG_IPFS_PROTOCOL) += ipfsgateway.o
>>> +OBJS-$(CONFIG_IPNS_PROTOCOL) += ipfsgateway.o
>>>  TLS-OBJS-$(CONFIG_GNUTLS)+= tls_gnutls.o
>>>  TLS-OBJS-$(CONFIG_LIBTLS)+= tls_libtls.o
>>>  TLS-OBJS-$(CONFIG_MBEDTLS)   += tls_mbedtls.o
>>> diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c
>>> new file mode 100644
>>> index 00..1a039589c0
>>> --- /dev/null
>>> +++ b/libavformat/ipfsgateway.c
>>> @@ -0,0 +1,309 @@
>>> +/*
>>> + * IPFS and IPNS protocol support through IPFS Gateway.
>>> + * Copyright (c) 2022 Mark Gaiser
>>> + *
>>> + * This file is part of FFmpeg.
>>> + *
>>> + * FFmpeg is free software; you can redistribute it and/or
>>> + * modify it under the terms of the GNU Lesser General Public
>>> + * License as published by the Free Software Foundation; either
>>> + * version 2.1 of the License, or (at your option) any later version.
>>> + *
>>> + * FFmpeg is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> + * Lesser General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU Lesser Genera

[FFmpeg-devel] [PATCH] doc/bitstream_filters: fix for the syntax of code

2022-03-30 Thread lance . lmwang
From: Limin Wang 

Signed-off-by: Limin Wang 
---
 doc/bitstream_filters.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index 0b354fd..fc2c71f 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -328,7 +328,7 @@ See H.264 section D.1.27 and D.2.27 for syntax and 
semantics.
 
 Default is pass.
 
-Insert mode works in conjunction with @code {rotate} and @code{flip} options.
+Insert mode works in conjunction with @code{rotate} and @code{flip} options.
 Any pre-existing Display orientation messages will be removed in insert or 
remove mode.
 Extract mode attaches the display matrix to the packet as side data.
 
-- 
1.8.3.1

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

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


Re: [FFmpeg-devel] [PATCH 07/10] avcodec/vc1: Arm 64-bit NEON inverse transform fast paths

2022-03-30 Thread Martin Storsjö

On Fri, 25 Mar 2022, Ben Avison wrote:


checkasm benchmarks on 1.5 GHz Cortex-A72 are as follows.

vc1dsp.vc1_inv_trans_4x4_c: 158.2
vc1dsp.vc1_inv_trans_4x4_neon: 65.7
vc1dsp.vc1_inv_trans_4x4_dc_c: 86.5
vc1dsp.vc1_inv_trans_4x4_dc_neon: 26.5
vc1dsp.vc1_inv_trans_4x8_c: 335.2
vc1dsp.vc1_inv_trans_4x8_neon: 106.2
vc1dsp.vc1_inv_trans_4x8_dc_c: 151.2
vc1dsp.vc1_inv_trans_4x8_dc_neon: 25.5
vc1dsp.vc1_inv_trans_8x4_c: 365.7
vc1dsp.vc1_inv_trans_8x4_neon: 97.2
vc1dsp.vc1_inv_trans_8x4_dc_c: 139.7
vc1dsp.vc1_inv_trans_8x4_dc_neon: 16.5
vc1dsp.vc1_inv_trans_8x8_c: 547.7
vc1dsp.vc1_inv_trans_8x8_neon: 137.0
vc1dsp.vc1_inv_trans_8x8_dc_c: 268.2
vc1dsp.vc1_inv_trans_8x8_dc_neon: 30.5

Signed-off-by: Ben Avison 
---
libavcodec/aarch64/vc1dsp_init_aarch64.c |  19 +
libavcodec/aarch64/vc1dsp_neon.S | 678 +++
2 files changed, 697 insertions(+)


Looks generally reasonable. Is it possible to factorize out the individual 
transforms (so that you'd e.g. invoke the same macro twice in the 8x8 and 
4x4 functions) without too much loss? The downshift which differs between 
thw two could either be left outside of the macro, or the downshift amount 
could be made a macro parameter.


// Martin

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

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


Re: [FFmpeg-devel] [PATCH v9 3/5] avcodec/libjxl: add Jpeg XL encoding via libjxl

2022-03-30 Thread Andreas Rheinhardt
Leo Izen:
> 
> On 3/30/22 07:12, Andreas Rheinhardt wrote:
>> buffer_size is not used after libjxl_encode_close() at all, as this is
>> the codec's close callback; libjxl_encode_frame() meanwhile may be
>> called again after freeing and if it reaches JxlEncoderProcessOutput(),
>> the latter would be called with next_out == NULL and available != 0.
>> JxlEncoderProcessOutput() might check for this (and error out) or it may
>> just crash.
>>
> Can encode2 really be called again if it returns with AVERROR(ENOMEM)? I
> was under the impression that this preventing further calls.
> 

Why should this be so? (E.g. a user might close other processes in order
to free up memory upon receiving AVERROR(ENOMEM) and try again.)

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

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


Re: [FFmpeg-devel] [PATCH v9 3/5] avcodec/libjxl: add Jpeg XL encoding via libjxl

2022-03-30 Thread Leo Izen



On 3/30/22 07:12, Andreas Rheinhardt wrote:

buffer_size is not used after libjxl_encode_close() at all, as this is
the codec's close callback; libjxl_encode_frame() meanwhile may be
called again after freeing and if it reaches JxlEncoderProcessOutput(),
the latter would be called with next_out == NULL and available != 0.
JxlEncoderProcessOutput() might check for this (and error out) or it may
just crash.

Can encode2 really be called again if it returns with AVERROR(ENOMEM)? I 
was under the impression that this preventing further calls.


Leo Izen (thebombzen)


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

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


Re: [FFmpeg-devel] [PATCH v10 1/1] avformat: Add IPFS protocol support.

2022-03-30 Thread Mark Gaiser
On Wed, Mar 30, 2022 at 2:21 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Mark Gaiser:
> > This patch adds support for:
> > - ffplay ipfs://
> > - ffplay ipns://
> >
> > IPFS data can be played from so called "ipfs gateways".
> > A gateway is essentially a webserver that gives access to the
> > distributed IPFS network.
> >
> > This protocol support (ipfs and ipns) therefore translates
> > ipfs:// and ipns:// to a http:// url. This resulting url is
> > then handled by the http protocol. It could also be https
> > depending on the gateway provided.
> >
> > To use this protocol, a gateway must be provided.
> > If you do nothing it will try to find it in your
> > $HOME/.ipfs/gateway file. The ways to set it manually are:
> > 1. Define a -gateway  to the gateway.
> > 2. Define $IPFS_GATEWAY with the full http link to the gateway.
> > 3. Define $IPFS_PATH and point it to the IPFS data path.
> > 4. Have IPFS running in your local user folder (under $HOME/.ipfs).
> >
> > Signed-off-by: Mark Gaiser 
> > ---
> >  configure |   2 +
> >  doc/protocols.texi|  30 
> >  libavformat/Makefile  |   2 +
> >  libavformat/ipfsgateway.c | 309 ++
> >  libavformat/protocols.c   |   2 +
> >  5 files changed, 345 insertions(+)
> >  create mode 100644 libavformat/ipfsgateway.c
> >
> > diff --git a/configure b/configure
> > index e4d36aa639..55af90957a 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3579,6 +3579,8 @@ udp_protocol_select="network"
> >  udplite_protocol_select="network"
> >  unix_protocol_deps="sys_un_h"
> >  unix_protocol_select="network"
> > +ipfs_protocol_select="https_protocol"
> > +ipns_protocol_select="https_protocol"
> >
> >  # external library protocols
> >  libamqp_protocol_deps="librabbitmq"
> > diff --git a/doc/protocols.texi b/doc/protocols.texi
> > index d207df0b52..7c9c0a4808 100644
> > --- a/doc/protocols.texi
> > +++ b/doc/protocols.texi
> > @@ -2025,5 +2025,35 @@ decoding errors.
> >
> >  @end table
> >
> > +@section ipfs
> > +
> > +InterPlanetary File System (IPFS) protocol support. One can access
> files stored
> > +on the IPFS network through so called gateways. Those are http(s)
> endpoints.
> > +This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to
> be send
> > +to such a gateway. Users can (and should) host their own node which
> means this
> > +protocol will use your local machine gateway to access files on the
> IPFS network.
> > +
> > +If a user doesn't have a node of their own then the public gateway
> dweb.link is
> > +used by default.
> > +
> > +You can use this protocol in 2 ways. Using IPFS:
> > +@example
> > +ffplay ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
> > +@end example
> > +
> > +Or the IPNS protocol (IPNS is mutable IPFS):
> > +@example
> > +ffplay ipns://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
> > +@end example
> > +
> > +You can also change the gateway to be used:
> > +
> > +@table @option
> > +
> > +@item gateway
> > +Defines the gateway to use. When nothing is provided the protocol will
> first try
> > +your local gateway. If that fails dweb.link will be used.
> > +
> > +@end table
> >
> >  @c man end PROTOCOLS
> > diff --git a/libavformat/Makefile b/libavformat/Makefile
> > index d7182d6bd8..e3233fd7ac 100644
> > --- a/libavformat/Makefile
> > +++ b/libavformat/Makefile
> > @@ -660,6 +660,8 @@ OBJS-$(CONFIG_SRTP_PROTOCOL) +=
> srtpproto.o srtp.o
> >  OBJS-$(CONFIG_SUBFILE_PROTOCOL)  += subfile.o
> >  OBJS-$(CONFIG_TEE_PROTOCOL)  += teeproto.o tee_common.o
> >  OBJS-$(CONFIG_TCP_PROTOCOL)  += tcp.o
> > +OBJS-$(CONFIG_IPFS_PROTOCOL) += ipfsgateway.o
> > +OBJS-$(CONFIG_IPNS_PROTOCOL) += ipfsgateway.o
> >  TLS-OBJS-$(CONFIG_GNUTLS)+= tls_gnutls.o
> >  TLS-OBJS-$(CONFIG_LIBTLS)+= tls_libtls.o
> >  TLS-OBJS-$(CONFIG_MBEDTLS)   += tls_mbedtls.o
> > diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c
> > new file mode 100644
> > index 00..1a039589c0
> > --- /dev/null
> > +++ b/libavformat/ipfsgateway.c
> > @@ -0,0 +1,309 @@
> > +/*
> > + * IPFS and IPNS protocol support through IPFS Gateway.
> > + * Copyright (c) 2022 Mark Gaiser
> > + *
> > + * This file is part of FFmpeg.
> > + *
> > + * FFmpeg is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License as published by the Free Software Foundation; either
> > + * version 2.1 of the License, or (at your option) any later version.
> > + *
> > + * FFmpeg is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * Lesser General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU Lesser General Public
> > + * License alo

Re: [FFmpeg-devel] [PATCH 06/10] avcodec/vc1: Arm 32-bit NEON deblocking filter fast paths

2022-03-30 Thread Martin Storsjö

On Fri, 25 Mar 2022, Ben Avison wrote:


checkasm benchmarks on 1.5 GHz Cortex-A72 are as follows. Note that the C
version can still outperform the NEON version in specific cases. The balance
between different code paths is stream-dependent, but in practice the best
case happens about 5% of the time, the worst case happens about 40% of the
time, and the complexity of the remaining cases fall somewhere in between.
Therefore, taking the average of the best and worst case timings is
probably a conservative estimate of the degree by which the NEON code
improves performance.

vc1dsp.vc1_h_loop_filter4_bestcase_c: 19.0
vc1dsp.vc1_h_loop_filter4_bestcase_neon: 48.5
vc1dsp.vc1_h_loop_filter4_worstcase_c: 144.7
vc1dsp.vc1_h_loop_filter4_worstcase_neon: 76.2
vc1dsp.vc1_h_loop_filter8_bestcase_c: 41.0
vc1dsp.vc1_h_loop_filter8_bestcase_neon: 75.0
vc1dsp.vc1_h_loop_filter8_worstcase_c: 294.0
vc1dsp.vc1_h_loop_filter8_worstcase_neon: 102.7
vc1dsp.vc1_h_loop_filter16_bestcase_c: 54.7
vc1dsp.vc1_h_loop_filter16_bestcase_neon: 130.0
vc1dsp.vc1_h_loop_filter16_worstcase_c: 569.7
vc1dsp.vc1_h_loop_filter16_worstcase_neon: 186.7
vc1dsp.vc1_v_loop_filter4_bestcase_c: 20.2
vc1dsp.vc1_v_loop_filter4_bestcase_neon: 47.2
vc1dsp.vc1_v_loop_filter4_worstcase_c: 164.2
vc1dsp.vc1_v_loop_filter4_worstcase_neon: 68.5
vc1dsp.vc1_v_loop_filter8_bestcase_c: 43.5
vc1dsp.vc1_v_loop_filter8_bestcase_neon: 55.2
vc1dsp.vc1_v_loop_filter8_worstcase_c: 316.2
vc1dsp.vc1_v_loop_filter8_worstcase_neon: 72.7
vc1dsp.vc1_v_loop_filter16_bestcase_c: 62.2
vc1dsp.vc1_v_loop_filter16_bestcase_neon: 103.7
vc1dsp.vc1_v_loop_filter16_worstcase_c: 646.5
vc1dsp.vc1_v_loop_filter16_worstcase_neon: 110.7

Signed-off-by: Ben Avison 
---
libavcodec/arm/vc1dsp_init_neon.c |  14 +
libavcodec/arm/vc1dsp_neon.S  | 643 ++
2 files changed, 657 insertions(+)



+@ VC-1 in-loop deblocking filter for 8 pixel pairs at boundary of 
vertically-neighbouring blocks
+@ On entry:
+@   r0 -> top-left pel of lower block
+@   r1 = row stride, bytes
+@   r2 = PQUANT bitstream parameter
+function ff_vc1_v_loop_filter8_neon, export=1
+sub r3, r0, r1, lsl #2
+vldrd0, .Lcoeffs
+vld1.32 {d1}, [r0], r1  @ P5
+vld1.32 {d2}, [r3], r1  @ P1
+vld1.32 {d3}, [r3], r1  @ P2
+vld1.32 {d4}, [r0], r1  @ P6
+vld1.32 {d5}, [r3], r1  @ P3
+vld1.32 {d6}, [r0], r1  @ P7


Oh btw - I presume these loads can be done with alignment? And same for 
some of the stores too? At least for some older cores, the alignment 
specifier helps a lot - so for 32 bit assembly, I try to add as much 
alignment specifiers as possible.


// Martin

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

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


Re: [FFmpeg-devel] [PATCH] MAINTAINERS: add myself as maintainer for libsrt protocol

2022-03-30 Thread lance . lmwang
On Fri, Mar 25, 2022 at 03:40:33PM +0800, Zhao Zhili wrote:
> Signed-off-by: Zhao Zhili 
> ---
>  MAINTAINERS | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 931cf4bd2c..5daa6f8e03 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -516,6 +516,7 @@ Protocols:
>bluray.c  Petri Hintukainen
>ftp.c Lukasz Marek
>http.cRonald S. Bultje
> +  libsrt.c  Zhao Zhili
>libssh.c  Lukasz Marek
>libzmq.c  Andriy Gelman
>mms*.cRonald S. Bultje
> -- 
> 2.31.1
> 
LGTM

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

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


Re: [FFmpeg-devel] [PATCH 06/10] avcodec/vc1: Arm 32-bit NEON deblocking filter fast paths

2022-03-30 Thread Martin Storsjö

On Fri, 25 Mar 2022, Ben Avison wrote:


checkasm benchmarks on 1.5 GHz Cortex-A72 are as follows. Note that the C
version can still outperform the NEON version in specific cases. The balance
between different code paths is stream-dependent, but in practice the best
case happens about 5% of the time, the worst case happens about 40% of the
time, and the complexity of the remaining cases fall somewhere in between.
Therefore, taking the average of the best and worst case timings is
probably a conservative estimate of the degree by which the NEON code
improves performance.

vc1dsp.vc1_h_loop_filter4_bestcase_c: 19.0
vc1dsp.vc1_h_loop_filter4_bestcase_neon: 48.5
vc1dsp.vc1_h_loop_filter4_worstcase_c: 144.7
vc1dsp.vc1_h_loop_filter4_worstcase_neon: 76.2
vc1dsp.vc1_h_loop_filter8_bestcase_c: 41.0
vc1dsp.vc1_h_loop_filter8_bestcase_neon: 75.0
vc1dsp.vc1_h_loop_filter8_worstcase_c: 294.0
vc1dsp.vc1_h_loop_filter8_worstcase_neon: 102.7
vc1dsp.vc1_h_loop_filter16_bestcase_c: 54.7
vc1dsp.vc1_h_loop_filter16_bestcase_neon: 130.0
vc1dsp.vc1_h_loop_filter16_worstcase_c: 569.7
vc1dsp.vc1_h_loop_filter16_worstcase_neon: 186.7
vc1dsp.vc1_v_loop_filter4_bestcase_c: 20.2
vc1dsp.vc1_v_loop_filter4_bestcase_neon: 47.2
vc1dsp.vc1_v_loop_filter4_worstcase_c: 164.2
vc1dsp.vc1_v_loop_filter4_worstcase_neon: 68.5
vc1dsp.vc1_v_loop_filter8_bestcase_c: 43.5
vc1dsp.vc1_v_loop_filter8_bestcase_neon: 55.2
vc1dsp.vc1_v_loop_filter8_worstcase_c: 316.2
vc1dsp.vc1_v_loop_filter8_worstcase_neon: 72.7
vc1dsp.vc1_v_loop_filter16_bestcase_c: 62.2
vc1dsp.vc1_v_loop_filter16_bestcase_neon: 103.7
vc1dsp.vc1_v_loop_filter16_worstcase_c: 646.5
vc1dsp.vc1_v_loop_filter16_worstcase_neon: 110.7

Signed-off-by: Ben Avison 
---
libavcodec/arm/vc1dsp_init_neon.c |  14 +
libavcodec/arm/vc1dsp_neon.S  | 643 ++
2 files changed, 657 insertions(+)


Looks like a close analogue to the arm64 case (i.e. looks good!), only the 
open question of code sharing/reuse between horizontal and vertical.


// Martin

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

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


Re: [FFmpeg-devel] [PATCH 05/10] avcodec/vc1: Arm 64-bit NEON deblocking filter fast paths

2022-03-30 Thread Martin Storsjö

On Fri, 25 Mar 2022, Ben Avison wrote:


checkasm benchmarks on 1.5 GHz Cortex-A72 are as follows. Note that the C
version can still outperform the NEON version in specific cases. The balance
between different code paths is stream-dependent, but in practice the best
case happens about 5% of the time, the worst case happens about 40% of the
time, and the complexity of the remaining cases fall somewhere in between.
Therefore, taking the average of the best and worst case timings is
probably a conservative estimate of the degree by which the NEON code
improves performance.

vc1dsp.vc1_h_loop_filter4_bestcase_c: 10.7
vc1dsp.vc1_h_loop_filter4_bestcase_neon: 43.5
vc1dsp.vc1_h_loop_filter4_worstcase_c: 184.5
vc1dsp.vc1_h_loop_filter4_worstcase_neon: 73.7
vc1dsp.vc1_h_loop_filter8_bestcase_c: 31.2
vc1dsp.vc1_h_loop_filter8_bestcase_neon: 62.2
vc1dsp.vc1_h_loop_filter8_worstcase_c: 358.2
vc1dsp.vc1_h_loop_filter8_worstcase_neon: 88.2
vc1dsp.vc1_h_loop_filter16_bestcase_c: 51.0
vc1dsp.vc1_h_loop_filter16_bestcase_neon: 107.7
vc1dsp.vc1_h_loop_filter16_worstcase_c: 722.7
vc1dsp.vc1_h_loop_filter16_worstcase_neon: 140.5
vc1dsp.vc1_v_loop_filter4_bestcase_c: 9.7
vc1dsp.vc1_v_loop_filter4_bestcase_neon: 43.0
vc1dsp.vc1_v_loop_filter4_worstcase_c: 178.7
vc1dsp.vc1_v_loop_filter4_worstcase_neon: 69.0
vc1dsp.vc1_v_loop_filter8_bestcase_c: 30.2
vc1dsp.vc1_v_loop_filter8_bestcase_neon: 50.7
vc1dsp.vc1_v_loop_filter8_worstcase_c: 353.0
vc1dsp.vc1_v_loop_filter8_worstcase_neon: 69.2
vc1dsp.vc1_v_loop_filter16_bestcase_c: 60.0
vc1dsp.vc1_v_loop_filter16_bestcase_neon: 90.0
vc1dsp.vc1_v_loop_filter16_worstcase_c: 714.2
vc1dsp.vc1_v_loop_filter16_worstcase_neon: 97.2

Signed-off-by: Ben Avison 
---
libavcodec/aarch64/Makefile  |   1 +
libavcodec/aarch64/vc1dsp_init_aarch64.c |  14 +
libavcodec/aarch64/vc1dsp_neon.S | 698 +++
3 files changed, 713 insertions(+)
create mode 100644 libavcodec/aarch64/vc1dsp_neon.S

diff --git a/libavcodec/aarch64/vc1dsp_neon.S b/libavcodec/aarch64/vc1dsp_neon.S
new file mode 100644
index 00..70391b4179
--- /dev/null
+++ b/libavcodec/aarch64/vc1dsp_neon.S
@@ -0,0 +1,698 @@
+/*
+ * VC1 AArch64 NEON optimisations
+ *
+ * Copyright (c) 2022 Ben Avison 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/aarch64/asm.S"
+
+.align  5
+.Lcoeffs:
+.quad   0x00050002
+


This constant is problematic when building with MSVC/armasm64.exe (via 
gas-preprocessor). (gas-preprocessor, processing assembly for use with 
armasm, can't handle any completely general gas assembly, but works fine 
as long as one sticks to the general code patterns/macros we use.)


The issue here is that this is a naked label before the first 
function/endfunc/const/endconst block. In practice it works fine if this 
follows after an existing function though. (gas-preprocessor currently 
needs an explicit .text directive, to set it up to emit code to the .text 
section. I guess I could look into handling that implicitly too.)


In practice, this issue disappears further ahead in the patch stack when 
other functions are added above this in the source file though, so it's 
not really an issue - I just thought I'd mention it.



+// VC-1 in-loop deblocking filter for 4 pixel pairs at boundary of 
vertically-neighbouring blocks
+// On entry:
+//   x0 -> top-left pel of lower block
+//   w1 = row stride, bytes
+//   w2 = PQUANT bitstream parameter
+function ff_vc1_v_loop_filter4_neon, export=1
+sub x3, x0, w1, sxtw #2
+sxtwx1, w1  // technically, stride is 
signed int
+ldr d0, .Lcoeffs
+ld1 {v1.s}[0], [x0], x1 // P5
+ld1 {v2.s}[0], [x3], x1 // P1
+ld1 {v3.s}[0], [x3], x1 // P2
+ld1 {v4.s}[0], [x0], x1 // P6
+ld1 {v5.s}[0], [x3], x1 // P3
+ld1 {v6.s}[0], [x0], x1 // P7
+ld1 {v7.s}[0], [x3] // P4
+ld1 {v16.s}[0], [x0]// P8
+ushll   v17.8h, v1.8b, #1   // 2*P5
+dup v18.8h, w2  // pq
+ushll   v2.8h, v2.8b, #1// 2*P1
+

[FFmpeg-devel] [PATCH v5 21/21] avdevice/dshow: capabilities query also works on opened device

2022-03-30 Thread Diederick Niehorster
While the capabilities API is in principle meant to be used with an
allocated format context belonging to an unopened device, small changes
make it work for an opened dshow device as well. So hereby done.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/dshow.c | 110 +---
 libavdevice/dshow_capture.h |   3 +
 2 files changed, 66 insertions(+), 47 deletions(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 3cae7d265e..1e4025983a 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -849,7 +849,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum 
dshowDeviceType devtype,
 void *caps = NULL;
 int i, n, size, r;
 int wait_for_better = 0;
-int use_default;
+int use_default, already_opened;
 
 // format parameters requested by user
 // if none are requested by user, the values will below be set to
@@ -875,6 +875,9 @@ dshow_cycle_formats(AVFormatContext *avctx, enum 
dshowDeviceType devtype,
 if (!caps)
 goto end;
 
+// get if device is already opened
+already_opened = ctx->device_name[0] || ctx->device_name[1];
+
 /**
  * If we should open the device with the default format,
  * then:
@@ -1153,7 +1156,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum 
dshowDeviceType devtype,
 // in ranges, try to apply in all cases, and store
 // caps if successfully applied
 if (!wait_for_better || ranges) {
-if (IAMStreamConfig_SetFormat(config, type) != S_OK)
+if (!already_opened && IAMStreamConfig_SetFormat(config, type) != 
S_OK) // skip if device already opened
 goto next;
 else if (ranges) {
 // format matched and could be set successfully.
@@ -1494,12 +1497,19 @@ dshow_list_device_options(AVFormatContext *avctx, 
ICreateDevEnum *devenum,
 char *device_unique_name = NULL;
 int r;
 
-if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, 
&device_filter, &device_unique_name, NULL)) < 0)
-return r;
-ctx->device_filter[devtype] = device_filter;
-ctx->device_unique_name[devtype] = device_unique_name;
+if (!ctx->device_filter[devtype]) {
+if ((r = dshow_cycle_devices(avctx, devenum, devtype, sourcetype, 
&device_filter, &device_unique_name, NULL)) < 0)
+return r;
+
+// put them in context so they'll be cleaned up again
+ctx->device_filter[devtype] = device_filter;
+ctx->device_unique_name[devtype] = device_unique_name;
+} else
+device_filter = ctx->device_filter[devtype];
+
 if ((r = dshow_cycle_pins(avctx, devtype, sourcetype, device_filter, 
ranges ? &device_pin : NULL, ranges, query_type)) < 0)
 return r;
+
 return 0;
 }
 
@@ -2319,7 +2329,8 @@ fail1:
 return ret;
 }
 
-// fake class to point av_opt_query_ranges to our query_ranges function
+// fake class to point av_opt functions to capabilities that can be queried,
+// and av_opt_query_ranges to our query_ranges function
 static const AVClass dshow_dev_caps_class = {
 .class_name   = "",
 .item_name= av_default_item_name,
@@ -2337,49 +2348,51 @@ static int dshow_create_device_capabilities(struct 
AVFormatContext *avctx, AVDev
 // set class so queries work
 caps->av_class = &dshow_dev_caps_class;
 
-if (ctx->device_name[0] || ctx->device_name[1]) {
-av_log(avctx, AV_LOG_ERROR, "You cannot query device capabilities on 
an opened device\n");
-ret = AVERROR(EIO);
-goto fail;
-}
+// check if device setup is needed or we will be querying capabilities of 
an already opened device
+ctx->cap_query_already_opened = ctx->device_name[0] || ctx->device_name[1];
+if (ctx->cap_query_already_opened)
+av_log(avctx, AV_LOG_WARNING, "Querying device capabilities on an 
opened device: may yield false positives\n");
 
-if (!parse_device_name(avctx)) {
-av_log(avctx, AV_LOG_ERROR, "You must set a device name 
(AVFormatContext url) to specify which device to query capabilities from\n");
-ret = AVERROR(EINVAL);
-goto fail;
-}
-
-CoInitialize(0);
-if (CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
- &IID_ICreateDevEnum, (void **) &devenum)) {
-av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n");
-ret = AVERROR(EIO);
-goto fail;
-}
+// if device not already opened, check that what user specified can be 
opened
+if (!ctx->cap_query_already_opened) {
+if (!parse_device_name(avctx)) {
+av_log(avctx, AV_LOG_ERROR, "You must set a device name 
(AVFormatContext url) to specify which device to query capabilities from\n");
+ret = AVERROR(EINVAL);
+goto fail;
+}
 
-// check devices can be found
-if (ctx->device_name[VideoDevice]) {
-IBaseFilter *device_filter = NULL;
-char *device_un

[FFmpeg-devel] [PATCH v5 20/21] Makefile/examples: cosmetics

2022-03-30 Thread Diederick Niehorster
Signed-off-by: Diederick Niehorster 
---
 doc/examples/Makefile | 48 +--
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/doc/examples/Makefile b/doc/examples/Makefile
index de707bb3ca..7988ed4226 100644
--- a/doc/examples/Makefile
+++ b/doc/examples/Makefile
@@ -1,27 +1,27 @@
-EXAMPLES-$(CONFIG_AVIO_LIST_DIR_EXAMPLE) += avio_list_dir
-EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE)  += avio_reading
-EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE)  += decode_audio
-EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE)  += decode_video
-EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding
-EXAMPLES-$(CONFIG_DEVICE_GET_CAPABILITIES_EXAMPLE) += device_get_capabilities
-EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE)  += encode_audio
-EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE)  += encode_video
-EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE)   += extract_mvs
-EXAMPLES-$(CONFIG_FILTER_AUDIO_EXAMPLE)  += filter_audio
-EXAMPLES-$(CONFIG_FILTERING_AUDIO_EXAMPLE)   += filtering_audio
-EXAMPLES-$(CONFIG_FILTERING_VIDEO_EXAMPLE)   += filtering_video
-EXAMPLES-$(CONFIG_HTTP_MULTICLIENT_EXAMPLE)  += http_multiclient
-EXAMPLES-$(CONFIG_HW_DECODE_EXAMPLE) += hw_decode
-EXAMPLES-$(CONFIG_METADATA_EXAMPLE)  += metadata
-EXAMPLES-$(CONFIG_MUXING_EXAMPLE)+= muxing
-EXAMPLES-$(CONFIG_QSVDEC_EXAMPLE)+= qsvdec
-EXAMPLES-$(CONFIG_REMUXING_EXAMPLE)  += remuxing
-EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE)  += resampling_audio
-EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE) += scaling_video
-EXAMPLES-$(CONFIG_TRANSCODE_AAC_EXAMPLE) += transcode_aac
-EXAMPLES-$(CONFIG_TRANSCODING_EXAMPLE)   += transcoding
-EXAMPLES-$(CONFIG_VAAPI_ENCODE_EXAMPLE)  += vaapi_encode
-EXAMPLES-$(CONFIG_VAAPI_TRANSCODE_EXAMPLE)   += vaapi_transcode
+EXAMPLES-$(CONFIG_AVIO_LIST_DIR_EXAMPLE) += avio_list_dir
+EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE)  += avio_reading
+EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE)  += decode_audio
+EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE)  += decode_video
+EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding
+EXAMPLES-$(CONFIG_DEVICE_GET_CAPABILITIES_EXAMPLE)   += device_get_capabilities
+EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE)  += encode_audio
+EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE)  += encode_video
+EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE)   += extract_mvs
+EXAMPLES-$(CONFIG_FILTER_AUDIO_EXAMPLE)  += filter_audio
+EXAMPLES-$(CONFIG_FILTERING_AUDIO_EXAMPLE)   += filtering_audio
+EXAMPLES-$(CONFIG_FILTERING_VIDEO_EXAMPLE)   += filtering_video
+EXAMPLES-$(CONFIG_HTTP_MULTICLIENT_EXAMPLE)  += http_multiclient
+EXAMPLES-$(CONFIG_HW_DECODE_EXAMPLE) += hw_decode
+EXAMPLES-$(CONFIG_METADATA_EXAMPLE)  += metadata
+EXAMPLES-$(CONFIG_MUXING_EXAMPLE)+= muxing
+EXAMPLES-$(CONFIG_QSVDEC_EXAMPLE)+= qsvdec
+EXAMPLES-$(CONFIG_REMUXING_EXAMPLE)  += remuxing
+EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE)  += resampling_audio
+EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE) += scaling_video
+EXAMPLES-$(CONFIG_TRANSCODE_AAC_EXAMPLE) += transcode_aac
+EXAMPLES-$(CONFIG_TRANSCODING_EXAMPLE)   += transcoding
+EXAMPLES-$(CONFIG_VAAPI_ENCODE_EXAMPLE)  += vaapi_encode
+EXAMPLES-$(CONFIG_VAAPI_TRANSCODE_EXAMPLE)   += vaapi_transcode
 
 EXAMPLES   := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)$(EXESUF))
 EXAMPLES_G := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)_g$(EXESUF))
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 19/21] doc/examples: adding device_get_capabilities example

2022-03-30 Thread Diederick Niehorster
This example also shows use of get_device_list API.

Also improve capability API doc in avdevice.h: now point to this example
instead of rough example code given in the header.

Signed-off-by: Diederick Niehorster 
---
 configure  |   2 +
 doc/examples/.gitignore|   1 +
 doc/examples/Makefile  |   1 +
 doc/examples/Makefile.example  |   1 +
 doc/examples/device_get_capabilities.c | 243 +
 libavdevice/avdevice.h |  33 +---
 6 files changed, 249 insertions(+), 32 deletions(-)
 create mode 100644 doc/examples/device_get_capabilities.c

diff --git a/configure b/configure
index e4d36aa639..be78a2119e 100755
--- a/configure
+++ b/configure
@@ -1726,6 +1726,7 @@ EXAMPLE_LIST="
 decode_audio_example
 decode_video_example
 demuxing_decoding_example
+device_get_capabilities_example
 encode_audio_example
 encode_video_example
 extract_mvs_example
@@ -3751,6 +3752,7 @@ avio_reading_deps="avformat avcodec avutil"
 decode_audio_example_deps="avcodec avutil"
 decode_video_example_deps="avcodec avutil"
 demuxing_decoding_example_deps="avcodec avformat avutil"
+device_get_capabilities_example_deps="avdevice avformat avutil"
 encode_audio_example_deps="avcodec avutil"
 encode_video_example_deps="avcodec avutil"
 extract_mvs_example_deps="avcodec avformat avutil"
diff --git a/doc/examples/.gitignore b/doc/examples/.gitignore
index 44960e1de7..256f33a600 100644
--- a/doc/examples/.gitignore
+++ b/doc/examples/.gitignore
@@ -3,6 +3,7 @@
 /decode_audio
 /decode_video
 /demuxing_decoding
+/device_get_capabilities
 /encode_audio
 /encode_video
 /extract_mvs
diff --git a/doc/examples/Makefile b/doc/examples/Makefile
index 81bfd34d5d..de707bb3ca 100644
--- a/doc/examples/Makefile
+++ b/doc/examples/Makefile
@@ -3,6 +3,7 @@ EXAMPLES-$(CONFIG_AVIO_READING_EXAMPLE)  += avio_reading
 EXAMPLES-$(CONFIG_DECODE_AUDIO_EXAMPLE)  += decode_audio
 EXAMPLES-$(CONFIG_DECODE_VIDEO_EXAMPLE)  += decode_video
 EXAMPLES-$(CONFIG_DEMUXING_DECODING_EXAMPLE) += demuxing_decoding
+EXAMPLES-$(CONFIG_DEVICE_GET_CAPABILITIES_EXAMPLE) += device_get_capabilities
 EXAMPLES-$(CONFIG_ENCODE_AUDIO_EXAMPLE)  += encode_audio
 EXAMPLES-$(CONFIG_ENCODE_VIDEO_EXAMPLE)  += encode_video
 EXAMPLES-$(CONFIG_EXTRACT_MVS_EXAMPLE)   += extract_mvs
diff --git a/doc/examples/Makefile.example b/doc/examples/Makefile.example
index a232d97f98..b861b9cc74 100644
--- a/doc/examples/Makefile.example
+++ b/doc/examples/Makefile.example
@@ -16,6 +16,7 @@ EXAMPLES=   avio_list_dir  \
 decode_audio   \
 decode_video   \
 demuxing_decoding  \
+device_get_capabilities\
 encode_audio   \
 encode_video   \
 extract_mvs\
diff --git a/doc/examples/device_get_capabilities.c 
b/doc/examples/device_get_capabilities.c
new file mode 100644
index 00..1cfbca64eb
--- /dev/null
+++ b/doc/examples/device_get_capabilities.c
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2021 Diederick Niehorster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * @file
+ * avdevice getting capabilities example.
+ *
+ * Shows how to use the avdevice capabilities API to probe
+ * device capabilities (supported codecs, pixel formats, sample
+ * formats, resolutions, channel counts, etc)
+ * @example device_get_capabilities.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int print_option_ranges(enum AVOptionType type, AVOptionRanges *ranges)
+{
+for (int range_index = 0; range_index < ranges->nb_ranges; range_index++) {
+int ret;
+char *out_val = NULL;
+AVBPrint bp;
+av_bprint_init(&bp, 0, AV_BPRINT_SIZ

[FFmpeg-devel] [PATCH v5 18/21] avformat: add avformat_alloc_input_context()

2022-03-30 Thread Diederick Niehorster
avformat_alloc_input_context function analogous to
avformat_alloc_output_context2, except that it does not take a filename
argument as guessing the format by just the filename does not make sense.
avformat_alloc_input_context can be used e.g. with the avdevice
capabilities API, which needs an allocated input format with priv_data
(and default options) set, but device should not be opened.

Added some checks to avformat_open_input, for the case that a
AVFormatContext* allocated by avformat_alloc_input_context is provided:
1.  if avformat_open_input's AVInputFormat *fmt argument is not NULL,
clean up any already set s->iformat
2.  if s->url is already set and avformat_open_input's filename argument
is not NULL, free current url and replace by provided filename
3.  if s->url is already set and avformat_open_input's filename argument
is NULL, do not set s->url to "", but keep current url
4.  if s->priv_data has already been allocated, do not do so again.
4b. do reset options to default and apply provided options (if any)
5.  add 4b to docs of avformat_open_input

Bump libavformat version.

Signed-off-by: Diederick Niehorster 
---
 libavformat/avformat.h | 29 +++--
 libavformat/demux.c| 74 ++
 libavformat/version.h  |  2 +-
 3 files changed, 95 insertions(+), 10 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 027a914e13..004d81640f 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2024,6 +2024,26 @@ AVProgram *av_new_program(AVFormatContext *s, int id);
  * @}
  */
 
+ /**
+  * Allocate an AVFormatContext for an input format.
+  * avformat_free_context() can be used to free the context and
+  * everything allocated by the framework within it. NB: in general
+  * the correct format cannot be known (unless the user has extra
+  * information) until the file is opened. If forcing a format by
+  * this method, but it turns out not to match the file's format
+  * upon avformat_open_input(), the latter will throw an error.
+  *
+  * @param *ctx is set to the created format context, or to NULL in
+  * case of failure
+  * @param iformat format to use for allocating the context, if NULL
+  * format_name is used instead
+  * @param format_name the name of input format to use for allocating the
+  * context
+  * @return >= 0 in case of success, a negative AVERROR code in case of
+  * failure
+  */
+int avformat_alloc_input_context(AVFormatContext **ctx, const AVInputFormat 
*iformat,
+ const char *format_name);
 
 /**
  * Allocate an AVFormatContext for an output format.
@@ -2119,9 +2139,9 @@ int av_probe_input_buffer(AVIOContext *pb, const 
AVInputFormat **fmt,
  * Open an input stream and read the header. The codecs are not opened.
  * The stream must be closed with avformat_close_input().
  *
- * @param ps Pointer to user-supplied AVFormatContext (allocated by 
avformat_alloc_context).
- *   May be a pointer to NULL, in which case an AVFormatContext is 
allocated by this
- *   function and written into ps.
+ * @param ps Pointer to user-supplied AVFormatContext (allocated by 
avformat_alloc_context, or
+ *   avformat_alloc_input_context). May be a pointer to NULL, in which 
case an
+ *   AVFormatContext is allocated by this function and written into ps.
  *   Note that a user-supplied AVFormatContext will be freed on 
failure.
  * @param url URL of the stream to open.
  * @param fmt If non-NULL, this parameter forces a specific input format.
@@ -2129,6 +2149,9 @@ int av_probe_input_buffer(AVIOContext *pb, const 
AVInputFormat **fmt,
  * @param options  A dictionary filled with AVFormatContext and 
demuxer-private options.
  * On return this parameter will be destroyed and replaced 
with a dict containing
  * options that were not found. May be NULL.
+ * Note that if a AVFormatContext allocated by 
avformat_alloc_input_context
+ * is provided, any demuxer-private options will be 
overwritten by their defaults
+ * before applying this new set of demuxer-private options, if 
any. 
  *
  * @return 0 on success, a negative AVERROR on failure.
  *
diff --git a/libavformat/demux.c b/libavformat/demux.c
index ef189d9d8e..52442b2e55 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -217,6 +217,56 @@ FF_ENABLE_DEPRECATION_WARNINGS
 return 0;
 }
 
+
+int avformat_alloc_input_context(AVFormatContext** avctx, const AVInputFormat* 
iformat,
+const char* format)
+{
+AVFormatContext* s = avformat_alloc_context();
+int ret = 0;
+
+*avctx = NULL;
+if (!s)
+goto nomem;
+
+if (!iformat) {
+if (format) {
+iformat = av_find_input_format(format);
+if (!iformat) {
+av_log(s, AV_LOG_ERROR, "Requested input format '%s' not 
found\n", format);
+ret = AVERROR(EINVAL);
+

Re: [FFmpeg-devel] [PATCH v10 1/1] avformat: Add IPFS protocol support.

2022-03-30 Thread Andreas Rheinhardt
Mark Gaiser:
> This patch adds support for:
> - ffplay ipfs://
> - ffplay ipns://
> 
> IPFS data can be played from so called "ipfs gateways".
> A gateway is essentially a webserver that gives access to the
> distributed IPFS network.
> 
> This protocol support (ipfs and ipns) therefore translates
> ipfs:// and ipns:// to a http:// url. This resulting url is
> then handled by the http protocol. It could also be https
> depending on the gateway provided.
> 
> To use this protocol, a gateway must be provided.
> If you do nothing it will try to find it in your
> $HOME/.ipfs/gateway file. The ways to set it manually are:
> 1. Define a -gateway  to the gateway.
> 2. Define $IPFS_GATEWAY with the full http link to the gateway.
> 3. Define $IPFS_PATH and point it to the IPFS data path.
> 4. Have IPFS running in your local user folder (under $HOME/.ipfs).
> 
> Signed-off-by: Mark Gaiser 
> ---
>  configure |   2 +
>  doc/protocols.texi|  30 
>  libavformat/Makefile  |   2 +
>  libavformat/ipfsgateway.c | 309 ++
>  libavformat/protocols.c   |   2 +
>  5 files changed, 345 insertions(+)
>  create mode 100644 libavformat/ipfsgateway.c
> 
> diff --git a/configure b/configure
> index e4d36aa639..55af90957a 100755
> --- a/configure
> +++ b/configure
> @@ -3579,6 +3579,8 @@ udp_protocol_select="network"
>  udplite_protocol_select="network"
>  unix_protocol_deps="sys_un_h"
>  unix_protocol_select="network"
> +ipfs_protocol_select="https_protocol"
> +ipns_protocol_select="https_protocol"
>  
>  # external library protocols
>  libamqp_protocol_deps="librabbitmq"
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index d207df0b52..7c9c0a4808 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -2025,5 +2025,35 @@ decoding errors.
>  
>  @end table
>  
> +@section ipfs
> +
> +InterPlanetary File System (IPFS) protocol support. One can access files 
> stored 
> +on the IPFS network through so called gateways. Those are http(s) endpoints.
> +This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to be 
> send 
> +to such a gateway. Users can (and should) host their own node which means 
> this 
> +protocol will use your local machine gateway to access files on the IPFS 
> network.
> +
> +If a user doesn't have a node of their own then the public gateway dweb.link 
> is 
> +used by default.
> +
> +You can use this protocol in 2 ways. Using IPFS:
> +@example
> +ffplay ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
> +@end example
> +
> +Or the IPNS protocol (IPNS is mutable IPFS):
> +@example
> +ffplay ipns://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
> +@end example
> +
> +You can also change the gateway to be used:
> +
> +@table @option
> +
> +@item gateway
> +Defines the gateway to use. When nothing is provided the protocol will first 
> try 
> +your local gateway. If that fails dweb.link will be used.
> +
> +@end table
>  
>  @c man end PROTOCOLS
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index d7182d6bd8..e3233fd7ac 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -660,6 +660,8 @@ OBJS-$(CONFIG_SRTP_PROTOCOL) += srtpproto.o 
> srtp.o
>  OBJS-$(CONFIG_SUBFILE_PROTOCOL)  += subfile.o
>  OBJS-$(CONFIG_TEE_PROTOCOL)  += teeproto.o tee_common.o
>  OBJS-$(CONFIG_TCP_PROTOCOL)  += tcp.o
> +OBJS-$(CONFIG_IPFS_PROTOCOL) += ipfsgateway.o
> +OBJS-$(CONFIG_IPNS_PROTOCOL) += ipfsgateway.o
>  TLS-OBJS-$(CONFIG_GNUTLS)+= tls_gnutls.o
>  TLS-OBJS-$(CONFIG_LIBTLS)+= tls_libtls.o
>  TLS-OBJS-$(CONFIG_MBEDTLS)   += tls_mbedtls.o
> diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c
> new file mode 100644
> index 00..1a039589c0
> --- /dev/null
> +++ b/libavformat/ipfsgateway.c
> @@ -0,0 +1,309 @@
> +/*
> + * IPFS and IPNS protocol support through IPFS Gateway.
> + * Copyright (c) 2022 Mark Gaiser
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "avformat.h"
> +#include "libavutil/avassert.h"

Unused.

> +#include "libavutil/avstring.h"
> +#include "libavutil/internal.h"
> +#include "libavutil/opt

[FFmpeg-devel] [PATCH v5 17/21] avdevice/dshow: cosmetics

2022-03-30 Thread Diederick Niehorster
Signed-off-by: Diederick Niehorster 
---
 libavdevice/dshow.c | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 58476a0f40..3cae7d265e 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -933,6 +933,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum 
dshowDeviceType devtype,
 AVOptionRange *new_range[3] = { NULL };
 int nb_range = 0;
 struct dshow_format_info *fmt_info = NULL;
+
 r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps);
 if (r != S_OK)
 goto next;
@@ -1558,7 +1559,8 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum 
*devenum,
 goto error;
 }
 }
-if (ctx->device_filter[otherDevType]) {
+
+if (ctx->device_filter[otherDevType]) {
 // avoid adding add two instances of the same device to the graph, one 
for video, one for audio
 // a few devices don't support this (could also do this check earlier 
to avoid double crossbars, etc. but they seem OK)
 if (strcmp(device_filter_unique_name, 
ctx->device_unique_name[otherDevType]) == 0) {
@@ -2441,16 +2443,16 @@ static const AVClass dshow_class = {
 };
 
 const AVInputFormat ff_dshow_demuxer = {
-.name   = "dshow",
-.long_name  = NULL_IF_CONFIG_SMALL("DirectShow capture"),
-.priv_data_size = sizeof(struct dshow_ctx),
-.read_header= dshow_read_header,
-.read_packet= dshow_read_packet,
-.read_close = dshow_read_close,
-.get_device_list= dshow_get_device_list,
-.control_message= dshow_control_message,
+.name   = "dshow",
+.long_name  = NULL_IF_CONFIG_SMALL("DirectShow capture"),
+.priv_data_size = sizeof(struct dshow_ctx),
+.read_header= dshow_read_header,
+.read_packet= dshow_read_packet,
+.read_close = dshow_read_close,
+.get_device_list= dshow_get_device_list,
+.control_message= dshow_control_message,
 .create_device_capabilities = dshow_create_device_capabilities,
-.free_device_capabilities = dshow_free_device_capabilities,
-.flags  = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | 
AVFMT_NO_BYTE_SEEK,
-.priv_class = &dshow_class,
+.free_device_capabilities   = dshow_free_device_capabilities,
+.flags  = AVFMT_NOFILE | AVFMT_NOBINSEARCH | 
AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
+.priv_class = &dshow_class,
 };
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 16/21] avdevice/dshow: implement capabilities API

2022-03-30 Thread Diederick Niehorster
This implements avdevice_capabilities_create and
avdevice_capabilities_free for the dshow device.

This enables configuration discovery of DirectShow devices through the
API, which is important for my use case. It enables making proper GUIs
presenting users with options, instead of asking them to discover a
dshow device's capabilities through the list_options option with an
FFmpeg tool, and listing what they want to configure in dumb text boxes.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/dshow.c   | 430 --
 libavdevice/version.h |   2 +-
 2 files changed, 412 insertions(+), 20 deletions(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 0d5f731030..58476a0f40 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -27,6 +27,7 @@
 #include "libavformat/internal.h"
 #include "libavformat/riff.h"
 #include "avdevice.h"
+#include "internal.h"
 #include "libavcodec/raw.h"
 #include "objidl.h"
 #include "shlwapi.h"
@@ -830,11 +831,15 @@ static void dshow_get_default_format(IPin *pin, 
IAMStreamConfig *config, enum ds
  * try to set parameters specified through AVOptions, or the pin's
  * default format if no such parameters were set. If successful,
  * return 1 in *pformat_set.
- * If pformat_set is NULL, list all pin capabilities.
+ * If pformat_set is NULL or the ranges input is not NULL, list all
+ * pin capabilities.
+ * When listing pin capabilities, if ranges is NULL, output to log,
+ * else store capabilities in ranges.
  */
 static void
 dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
-IPin *pin, int *pformat_set)
+IPin *pin, int *pformat_set,
+AVOptionRanges *ranges, enum AVDeviceCapabilitiesQueryType 
query_type)
 {
 struct dshow_ctx *ctx = avctx->priv_data;
 IAMStreamConfig *config = NULL;
@@ -878,7 +883,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum 
dshowDeviceType devtype,
  *one, with most info exposed (see comment below).
  */
 use_default = !dshow_should_set_format(avctx, devtype);
-if (use_default && pformat_set)
+if (use_default && pformat_set && !ranges)
 {
 // get default
 dshow_get_default_format(pin, config, devtype, &type);
@@ -924,7 +929,9 @@ dshow_cycle_formats(AVFormatContext *avctx, enum 
dshowDeviceType devtype,
 // exposes contains a VIDEOINFOHEADER2. Fall back to the VIDEOINFOHEADER
 // format if no corresponding VIDEOINFOHEADER2 is found when we finish
 // iterating.
-for (i = 0; i < n && !format_set; i++) {
+for (i = 0; i < n && (!format_set || ranges); i++) {
+AVOptionRange *new_range[3] = { NULL };
+int nb_range = 0;
 struct dshow_format_info *fmt_info = NULL;
 r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps);
 if (r != S_OK)
@@ -960,7 +967,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum 
dshowDeviceType devtype,
 wait_for_better = 0;
 }
 
-if (!pformat_set) {
+if (!pformat_set && !ranges) {
 const char *chroma = 
av_chroma_location_name(fmt_info->chroma_loc);
 if (fmt_info->pix_fmt == AV_PIX_FMT_NONE) {
 const AVCodec *codec = 
avcodec_find_decoder(fmt_info->codec_id);
@@ -1024,6 +1031,60 @@ dshow_cycle_formats(AVFormatContext *avctx, enum 
dshowDeviceType devtype,
 bih->biWidth  = requested_width;
 bih->biHeight = requested_height;
 }
+
+if (ranges) {
+for (int j = 0; j < ranges->nb_components; j++) {
+new_range[j] = av_mallocz(sizeof(**new_range));
+if (!new_range[j])
+goto next;
+new_range[j]->value_max = -1.;  // init (min:0, max:-1 
means value not set)
+++nb_range;
+
+switch (query_type)
+{
+case AV_DEV_CAP_QUERY_CODEC:
+if (dshow_pixfmt(bih->biCompression, bih->biBitCount) 
== AV_PIX_FMT_NONE) {
+const AVCodecTag *const tags[] = { 
avformat_get_riff_video_tags(), NULL };
+new_range[j]->value_min = av_codec_get_id(tags, 
bih->biCompression);
+}
+else
+new_range[j]->value_min = AV_CODEC_ID_RAWVIDEO;
+new_range[j]->value_max = new_range[j]->value_min;
+break;
+case AV_DEV_CAP_QUERY_PIXEL_FORMAT:
+new_range[j]->value_min = new_range[j]->value_max = 
dshow_pixfmt(bih->biCompression, bih->biBitCount);
+new_range[j]->value_min;
+break;
+case AV_DEV_CAP_QUERY_FRAME_SIZE:
+{
+switch (j)
+ 

[FFmpeg-devel] [PATCH v5 15/21] avdevice/dshow: when closing, set context fields back to zero

2022-03-30 Thread Diederick Niehorster
After the avdevice capabilities API is implemented, the format context
may be reused after querying device capabilities in a later
avformat_open_input call. To enable this reuse, after releasing
resources, make sure to also set the corresponding pointers back to
NULL. This correctly indicates their state after cleanup.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/dshow.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index d35224beb5..0d5f731030 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -264,14 +264,18 @@ dshow_read_close(AVFormatContext *s)
 ICaptureGraphBuilder2_Release(ctx->graph_builder2[VideoDevice]);
 if (ctx->graph_builder2[AudioDevice])
 ICaptureGraphBuilder2_Release(ctx->graph_builder2[AudioDevice]);
+ctx->graph_builder2[0] = NULL;
+ctx->graph_builder2[1] = NULL;
 
 if (ctx->control) {
 IMediaControl_Stop(ctx->control);
 IMediaControl_Release(ctx->control);
 }
+ctx->control = NULL;
 
 if (ctx->media_event)
 IMediaEvent_Release(ctx->media_event);
+ctx->media_event = NULL;
 
 if (ctx->graph) {
 IEnumFilters *fenum;
@@ -289,25 +293,34 @@ dshow_read_close(AVFormatContext *s)
 IEnumFilters_Release(fenum);
 }
 IGraphBuilder_Release(ctx->graph);
+ctx->graph = NULL;
 }
 
 if (ctx->capture_pin[VideoDevice])
 ff_dshow_pin_Release(ctx->capture_pin[VideoDevice]);
 if (ctx->capture_pin[AudioDevice])
 ff_dshow_pin_Release(ctx->capture_pin[AudioDevice]);
+ctx->capture_pin[0] = NULL;
+ctx->capture_pin[1] = NULL;
 if (ctx->capture_filter[VideoDevice])
 ff_dshow_filter_Release(ctx->capture_filter[VideoDevice]);
 if (ctx->capture_filter[AudioDevice])
 ff_dshow_filter_Release(ctx->capture_filter[AudioDevice]);
+ctx->capture_filter[0] = NULL;
+ctx->capture_filter[1] = NULL;
 
 if (ctx->device_pin[VideoDevice])
 IPin_Release(ctx->device_pin[VideoDevice]);
 if (ctx->device_pin[AudioDevice])
 IPin_Release(ctx->device_pin[AudioDevice]);
+ctx->device_pin[0] = NULL;
+ctx->device_pin[1] = NULL;
 if (ctx->device_filter[VideoDevice])
 IBaseFilter_Release(ctx->device_filter[VideoDevice]);
 if (ctx->device_filter[AudioDevice])
 IBaseFilter_Release(ctx->device_filter[AudioDevice]);
+ctx->device_filter[0] = NULL;
+ctx->device_filter[1] = NULL;
 
 av_freep(&ctx->device_name[0]);
 av_freep(&ctx->device_name[1]);
@@ -316,10 +329,13 @@ dshow_read_close(AVFormatContext *s)
 
 if(ctx->mutex)
 CloseHandle(ctx->mutex);
+ctx->mutex = NULL;
 if(ctx->event[0])
 CloseHandle(ctx->event[0]);
 if(ctx->event[1])
 CloseHandle(ctx->event[1]);
+ctx->event[0] = NULL;
+ctx->event[1] = NULL;
 
 pktl = ctx->pktl;
 while (pktl) {
@@ -328,6 +344,7 @@ dshow_read_close(AVFormatContext *s)
 av_free(pktl);
 pktl = next;
 }
+ctx->pktl = NULL;
 
 CoUninitialize();
 
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 14/21] avdevice/dshow: move audio format helpers

2022-03-30 Thread Diederick Niehorster
Needs to be moved up in file for upcoming implementation of
avdevice_capabilities_create.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/dshow.c | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index a780351170..d35224beb5 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -79,6 +79,26 @@ static enum AVPixelFormat dshow_pixfmt(DWORD biCompression, 
WORD biBitCount)
 return avpriv_pix_fmt_find(PIX_FMT_LIST_RAW, biCompression); // all others
 }
 
+static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt)
+{
+switch (sample_fmt) {
+case AV_SAMPLE_FMT_U8:  return AV_CODEC_ID_PCM_U8;
+case AV_SAMPLE_FMT_S16: return AV_CODEC_ID_PCM_S16LE;
+case AV_SAMPLE_FMT_S32: return AV_CODEC_ID_PCM_S32LE;
+default:return AV_CODEC_ID_NONE; /* Should never happen. */
+}
+}
+
+static enum AVSampleFormat sample_fmt_bits_per_sample(int bits)
+{
+switch (bits) {
+case 8:  return AV_SAMPLE_FMT_U8;
+case 16: return AV_SAMPLE_FMT_S16;
+case 32: return AV_SAMPLE_FMT_S32;
+default: return AV_SAMPLE_FMT_NONE; /* Should never happen. */
+}
+}
+
 static enum AVColorRange dshow_color_range(DXVA2_ExtendedFormat *fmt_info)
 {
 switch (fmt_info->NominalRange)
@@ -1610,26 +1630,6 @@ static int dshow_control_message(AVFormatContext *avctx, 
int type, void *data, s
 return ret;
 }
 
-static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt)
-{
-switch (sample_fmt) {
-case AV_SAMPLE_FMT_U8:  return AV_CODEC_ID_PCM_U8;
-case AV_SAMPLE_FMT_S16: return AV_CODEC_ID_PCM_S16LE;
-case AV_SAMPLE_FMT_S32: return AV_CODEC_ID_PCM_S32LE;
-default:return AV_CODEC_ID_NONE; /* Should never happen. */
-}
-}
-
-static enum AVSampleFormat sample_fmt_bits_per_sample(int bits)
-{
-switch (bits) {
-case 8:  return AV_SAMPLE_FMT_U8;
-case 16: return AV_SAMPLE_FMT_S16;
-case 32: return AV_SAMPLE_FMT_S32;
-default: return AV_SAMPLE_FMT_NONE; /* Should never happen. */
-}
-}
-
 static int
 dshow_add_device(AVFormatContext *avctx,
  enum dshowDeviceType devtype)
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 13/21] avdevice: improve capabilities' option API

2022-03-30 Thread Diederick Niehorster
This adds avdevice_capabilities_get_class() to allow examining the
capabilities that can be queried/set through the capabilities API, and
avdevice_capabilities_bprint_num() which allows printing the value
returned when querying a capability. These values (min_value and
max_value of an AVOptionRange) are doubles and this function formats
them properly, e.g. 1. for a AV_OPT_TYPE_PIXEL_FMT -> yuyv422.

bump minor version.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/avdevice.c | 80 ++
 libavdevice/avdevice.h | 27 ++
 libavdevice/version.h  |  4 +--
 3 files changed, 109 insertions(+), 2 deletions(-)

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 863f8df477..e2c60618d3 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -19,6 +19,9 @@
 #include "libavutil/avassert.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/avutil.h"
+#include "libavcodec/codec_id.h"
 #include "libavformat/version.h"
 #include "avdevice.h"
 #include "internal.h"
@@ -141,6 +144,83 @@ int avdevice_capabilities_create(AVDeviceCapabilitiesQuery 
**caps, AVFormatConte
 return ret;
 }
 
+static const AVClass avdevice_capabilities_context_class = {
+.class_name = "AVDeviceCapabilitiesQuery",
+.item_name = av_default_item_name,
+.option = ff_device_capabilities,
+.version = LIBAVUTIL_VERSION_INT
+};
+
+const AVClass *avdevice_capabilities_get_class(void)
+{
+return &avdevice_capabilities_context_class;
+}
+
+int avdevice_capabilities_bprint_num(AVBPrint *bp, const char *name, double 
val)
+{
+int opt_type_set = 0, is_codec = 0;
+enum AVOptionType type;  // will be set below, opt_type_set tracks if has 
been set
+const AVClass *cap_class = avdevice_capabilities_get_class();
+
+// may fail, e.g. if name of a component of a multi-component option was 
provided as input
+const AVOption *field = av_opt_find(&cap_class, name, NULL, 0, 
AV_OPT_SEARCH_FAKE_OBJ);
+if (field) {
+type = field->type;
+opt_type_set = 1;
+}
+
+// based on name, a type override or other extra info may be needed
+if (opt_type_set && type==AV_OPT_TYPE_INT && strcmp(name, "codec")==0)
+is_codec = 1;
+// next three are for the three components of a AV_OPT_TYPE_IMAGE_SIZE
+// NB: these wont be found by av_opt_find above
+else if (
+strcmp(name, 
ff_device_get_query_component_name(AV_DEV_CAP_QUERY_WINDOW_SIZE, 0))==0 ||
+strcmp(name, 
ff_device_get_query_component_name(AV_DEV_CAP_QUERY_WINDOW_SIZE, 1))==0 ||
+strcmp(name, 
ff_device_get_query_component_name(AV_DEV_CAP_QUERY_WINDOW_SIZE, 2))==0
+) {
+type = AV_OPT_TYPE_INT;
+opt_type_set = 1;
+}
+
+// now, format if type set, else error
+if (!opt_type_set) {
+av_log(NULL, AV_LOG_ERROR, "A device capability with the name '%s' is 
not known\n", name);
+return AVERROR_OPTION_NOT_FOUND;
+}
+
+switch (type)
+{
+case AV_OPT_TYPE_INT:
+{
+int temp = lrint(val);
+if (is_codec)
+av_bprintf(bp, "%s", (char *)avcodec_get_name((enum 
AVCodecID)lrint(val)));
+else
+av_bprintf(bp, "%d", temp);
+break;
+}
+case AV_OPT_TYPE_PIXEL_FMT:
+av_bprintf(bp, "%s", (char *)av_x_if_null(av_get_pix_fmt_name((enum 
AVPixelFormat)lrint(val)), "none"));
+break;
+case AV_OPT_TYPE_SAMPLE_FMT:
+av_bprintf(bp, "%s", (char *)av_x_if_null(av_get_sample_fmt_name((enum 
AVSampleFormat)lrint(val)), "none"));
+break;
+case AV_OPT_TYPE_DOUBLE:
+av_bprintf(bp, "%f", val);
+break;
+case AV_OPT_TYPE_CHANNEL_LAYOUT:
+av_bprintf(bp, "0x%"PRIx64, llrint(val));
+break;
+
+default:
+av_log(NULL, AV_LOG_ERROR, "avdevice_capabilities_bprint_num is not 
implemented for this option type\n", name);
+return AVERROR_PATCHWELCOME;
+}
+
+return 0;
+}
+
 void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, 
AVFormatContext *s)
 {
 if (!s || !caps || !(*caps))
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index a815d65f12..5f9dfccc34 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -64,6 +64,7 @@
 #include "libavutil/log.h"
 #include "libavutil/opt.h"
 #include "libavutil/dict.h"
+#include "libavutil/bprint.h"
 #include "libavformat/avformat.h"
 
 /**
@@ -418,6 +419,16 @@ int avdevice_dev_to_app_control_message(struct 
AVFormatContext *s,
  */
 typedef struct AVDeviceCapabilitiesQuery AVDeviceCapabilitiesQuery;
 
+/**
+ * Get the AVClass for AVDeviceCapabilitiesQuery. It can be used
+ * in combination with AV_OPT_SEARCH_FAKE_OBJ for examining
+ * which capabilities can be queried through the
+ * AVDeviceCapabilitiesQuery API.
+ *
+ * @see av_opt_find(), av_opt_next().
+ */
+const AVClass *avdevice_capabilities_get_class(vo

[FFmpeg-devel] [PATCH v5 12/21] avdevice: change device capabilities option type

2022-03-30 Thread Diederick Niehorster
Changes fps option from AVRational to double. This since any device
capability query results are returned in AVOptionRanges, which hold the
value as doubles, which can't contain AVRationals.

Also updated documentation of other capabilities, some had the wrong
option type listed.

micro version bump as this capabilities API is unused for now.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/avdevice.c | 4 ++--
 libavdevice/avdevice.h | 6 +++---
 libavdevice/internal.h | 4 +++-
 libavdevice/version.h  | 2 +-
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 1cc9cd3923..863f8df477 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -51,8 +51,8 @@ const AVOption ff_device_capabilities[] = {
 {.str = NULL}, -1, INT_MAX, E|D|V },
 { "frame_size", "frame size", OFFSET(frame_width), AV_OPT_TYPE_IMAGE_SIZE,
 {.str = NULL}, -1, INT_MAX, E|D|V },
-{ "fps", "fps", OFFSET(fps), AV_OPT_TYPE_RATIONAL,
-{.dbl = -1}, -1, INT_MAX, E|D|V },
+{ "fps", "fps", OFFSET(fps), AV_OPT_TYPE_DOUBLE,
+{.dbl = NAN}, 0, INT_MAX, E|D|V },
 { NULL }
 };
 
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index 6d45c74616..a815d65f12 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -360,7 +360,7 @@ int avdevice_dev_to_app_control_message(struct 
AVFormatContext *s,
  *  type: AV_OPT_TYPE_INT (AVCodecID value)
  *  - Capabilities valid for audio devices:
  *- sample_format:  supported sample formats.
- *  type: AV_OPT_TYPE_INT (AVSampleFormat value)
+ *  type: AV_OPT_TYPE_SAMPLE_FMT
  *- sample_rate:supported sample rates.
  *  type: AV_OPT_TYPE_INT
  *- channels:   supported number of channels.
@@ -369,13 +369,13 @@ int avdevice_dev_to_app_control_message(struct 
AVFormatContext *s,
  *  type: AV_OPT_TYPE_INT64
  *  - Capabilities valid for video devices:
  *- pixel_format:   supported pixel formats.
- *  type: AV_OPT_TYPE_INT (AVPixelFormat value)
+ *  type: AV_OPT_TYPE_PIXEL_FMT
  *- window_size:supported window sizes (describes size of the window 
size presented to the user).
  *  type: AV_OPT_TYPE_IMAGE_SIZE
  *- frame_size: supported frame sizes (describes size of provided 
video frames).
  *  type: AV_OPT_TYPE_IMAGE_SIZE
  *- fps:supported fps values
- *  type: AV_OPT_TYPE_RATIONAL
+ *  type: AV_OPT_TYPE_DOUBLE
  *
  * Value of the capability may be set by user using av_opt_set() function
  * and AVDeviceCapabilitiesQuery object. Following queries will
diff --git a/libavdevice/internal.h b/libavdevice/internal.h
index eee493a4c7..5f0bd403dd 100644
--- a/libavdevice/internal.h
+++ b/libavdevice/internal.h
@@ -50,7 +50,9 @@ struct AVDeviceCapabilitiesQuery {
 int window_height;
 int frame_width;
 int frame_height;
-AVRational fps;
+// NB: an AVRational cannot be represented in the AVOptionRange
+// output of av_opt_query_ranges, so we store fps as double instead
+double fps;
 };
 
 /**
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 09156778db..181987d287 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -31,7 +31,7 @@
 #include "version_major.h"
 
 #define LIBAVDEVICE_VERSION_MINOR   1
-#define LIBAVDEVICE_VERSION_MICRO 100
+#define LIBAVDEVICE_VERSION_MICRO 101
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
LIBAVDEVICE_VERSION_MINOR, \
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 11/21] avdevice: Add internal helpers for querying device capabilities

2022-03-30 Thread Diederick Niehorster
Signed-off-by: Diederick Niehorster 
---
 libavdevice/internal.h | 31 +++
 libavdevice/utils.c| 48 ++
 2 files changed, 79 insertions(+)

diff --git a/libavdevice/internal.h b/libavdevice/internal.h
index bef3a4bd2d..eee493a4c7 100644
--- a/libavdevice/internal.h
+++ b/libavdevice/internal.h
@@ -58,4 +58,35 @@ struct AVDeviceCapabilitiesQuery {
  */
 extern const AVOption ff_device_capabilities[];
 
+/**
+ * Enumeration indicating which device capability is being queried.
+ */
+enum AVDeviceCapabilitiesQueryType {
+AV_DEV_CAP_QUERY_NONE = 0,
+// both audio and video
+AV_DEV_CAP_QUERY_CODEC,
+// audio
+AV_DEV_CAP_QUERY_SAMPLE_FORMAT,
+AV_DEV_CAP_QUERY_SAMPLE_RATE,
+AV_DEV_CAP_QUERY_CHANNELS,
+AV_DEV_CAP_QUERY_CHANNEL_LAYOUT,
+// video
+AV_DEV_CAP_QUERY_PIXEL_FORMAT,
+AV_DEV_CAP_QUERY_WINDOW_SIZE,
+AV_DEV_CAP_QUERY_FRAME_SIZE,
+AV_DEV_CAP_QUERY_FPS
+};
+
+/**
+ * Find AVDeviceCapabilitiesQueryType enumeration by means of options name.
+ * Returns AV_DEV_CAP_QUERY_NONE if not found.
+ */
+enum AVDeviceCapabilitiesQueryType ff_device_get_query_type(const char* 
option_name);
+
+/**
+ * Get component name from AVDeviceCapabilitiesQueryType enumeration and 
component index.
+ * (Some options have multiple components, e.g. AV_DEV_CAP_QUERY_FRAME_SIZE).
+ */
+const char* ff_device_get_query_component_name(enum 
AVDeviceCapabilitiesQueryType query_type, int component);
+
 #endif
diff --git a/libavdevice/utils.c b/libavdevice/utils.c
index d9a52c53ab..de9023f215 100644
--- a/libavdevice/utils.c
+++ b/libavdevice/utils.c
@@ -19,6 +19,7 @@
 #include "internal.h"
 #include "libavutil/opt.h"
 #include "libavformat/avformat.h"
+#include "libavutil/avassert.h"
 
 int ff_alloc_input_device_context(AVFormatContext **avctx, const AVInputFormat 
*iformat, const char *format)
 {
@@ -57,3 +58,50 @@ int ff_alloc_input_device_context(AVFormatContext **avctx, 
const AVInputFormat *
 avformat_free_context(s);
 return ret;
 }
+
+typedef struct AVDeviceCapabilitiesQueryTypeEntry {
+const char* name;
+enum AVDeviceCapabilitiesQueryType  query_type;
+} AVDeviceCapabilitiesQueryTypeEntry;
+
+static const AVDeviceCapabilitiesQueryTypeEntry query_table[] = {
+// both audio and video
+{ "codec",  AV_DEV_CAP_QUERY_CODEC },
+// audio
+{ "sample_format",  AV_DEV_CAP_QUERY_SAMPLE_FORMAT },
+{ "sample_rate",AV_DEV_CAP_QUERY_SAMPLE_RATE },
+{ "channels",   AV_DEV_CAP_QUERY_CHANNELS },
+{ "channel_layout", AV_DEV_CAP_QUERY_CHANNEL_LAYOUT },
+// video
+{ "pixel_format",   AV_DEV_CAP_QUERY_PIXEL_FORMAT },
+{ "frame_size", AV_DEV_CAP_QUERY_FRAME_SIZE },
+{ "window_size",AV_DEV_CAP_QUERY_WINDOW_SIZE },
+{ "fps",AV_DEV_CAP_QUERY_FPS },
+};
+
+enum AVDeviceCapabilitiesQueryType ff_device_get_query_type(const char* 
option_name)
+{
+for (int i = 0; i < FF_ARRAY_ELEMS(query_table); ++i) {
+if (!strcmp(query_table[i].name, option_name))
+return query_table[i].query_type;
+}
+// not found
+return AV_DEV_CAP_QUERY_NONE;
+}
+
+const char* ff_device_get_query_component_name(enum 
AVDeviceCapabilitiesQueryType query_type, int component)
+{
+if (query_type == AV_DEV_CAP_QUERY_WINDOW_SIZE || query_type == 
AV_DEV_CAP_QUERY_FRAME_SIZE) {
+// special case: different name for each component
+return component == 0 ? "pixel_count" : (component == 1 ? "width" : 
(component == 2 ? "height" : ""));
+}
+else {
+av_assert0(component == 0);
+for (int i = 0; i < FF_ARRAY_ELEMS(query_table); ++i) {
+if (query_table[i].query_type == query_type)
+return query_table[i].name;
+}
+}
+// not found
+return NULL;
+}
\ No newline at end of file
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 10/21] avutil/opt: document AVOptionRange min_value > max_value

2022-03-30 Thread Diederick Niehorster
AVOptionRange needs a way to encode that an option is not set. Here i
provide a documentation solution. When a range is invalid (value_min >
value_max), it should be considered unset/value not available.

When querying a range of formats of an avdevice, sometimes for a given
format the queried option is not available. This is not an error as the
user is asking for a valid capability, it just doesn't always apply to
all the matching formats of the device. This cannot be communicated
through a single special value (like 0 or -1) as that has the same
problem asany special value solution. Documenting that an invalid range
means value not available allows communicating this situation without
adding a field to the AVOptionRange struct.

This further documents that an AVOptionRange denotes a single value when
value_min == value_max, and a range only when value_max > value_min.
This makes the is_range field superfluous.

Signed-off-by: Diederick Niehorster 
---
 libavutil/opt.c | 2 +-
 libavutil/opt.h | 5 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 8ffb10449b..ebffbb2f36 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -1979,9 +1979,9 @@ int av_opt_query_ranges_default(AVOptionRanges 
**ranges_arg, void *obj, const ch
 ranges->range[0] = range;
 ranges->nb_ranges = 1;
 ranges->nb_components = 1;
-range->is_range = 1;
 range->value_min = field->min;
 range->value_max = field->max;
+range->is_range = field->max > field->min;
 
 switch (field->type) {
 case AV_OPT_TYPE_BOOL:
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 461b5d3b6b..4e7d7433e9 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -316,6 +316,11 @@ typedef struct AVOptionRange {
  * Value range.
  * For string ranges this represents the min/max length.
  * For dimensions this represents the min/max pixel count or width/height 
in multi-component case.
+ * If value_min  < value_max, the struct encodes a range.
+ * If value_min == value_max, the struct encodes a single value.
+ * If value_min  > value_max, the range is empty (a value is not 
available).
+ *Good sentinel values to use when a range is 
empty
+ *are value_min=0, value_max=-1, but this is 
not required.
  */
 double value_min, value_max;
 /**
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 09/21] avdevice: capabilities API details no longer public

2022-03-30 Thread Diederick Niehorster
Bumping avdevice major version (API removed, even if it cannot have been used 
by anyone)

Signed-off-by: Diederick Niehorster 
---
 libavdevice/avdevice.c  |  2 +-
 libavdevice/avdevice.h  | 28 +---
 libavdevice/internal.h  | 33 +
 libavdevice/version.h   |  2 +-
 libavdevice/version_major.h |  2 +-
 5 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 2e8261e0d2..1cc9cd3923 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -34,7 +34,7 @@ const char av_device_ffversion[] = "FFmpeg version " 
FFMPEG_VERSION;
 #define V AV_OPT_FLAG_VIDEO_PARAM
 #define OFFSET(x) offsetof(AVDeviceCapabilitiesQuery, x)
 
-const AVOption av_device_capabilities[] = {
+const AVOption ff_device_capabilities[] = {
 { "codec", "codec", OFFSET(codec), AV_OPT_TYPE_INT,
 {.i64 = AV_CODEC_ID_NONE}, AV_CODEC_ID_NONE, INT_MAX, E|D|A|V },
 { "sample_format", "sample format", OFFSET(sample_format), 
AV_OPT_TYPE_SAMPLE_FMT,
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index 9724e7edf5..6d45c74616 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -416,33 +416,7 @@ int avdevice_dev_to_app_control_message(struct 
AVFormatContext *s,
  *  avformat_free_context(oc);
  * @endcode
  */
-
-/**
- * Structure describes device capabilities.
- *
- * It is used by devices in conjunction with av_device_capabilities AVOption 
table
- * to implement capabilities probing API based on AVOption API. Should not be 
used directly.
- */
-typedef struct AVDeviceCapabilitiesQuery {
-const AVClass *av_class;
-AVFormatContext *device_context;
-enum AVCodecID codec;
-enum AVSampleFormat sample_format;
-enum AVPixelFormat pixel_format;
-int sample_rate;
-int channels;
-int64_t channel_layout;
-int window_width;
-int window_height;
-int frame_width;
-int frame_height;
-AVRational fps;
-} AVDeviceCapabilitiesQuery;
-
-/**
- * AVOption table used by devices to implement device capabilities API. Should 
not be used by a user.
- */
-extern const AVOption av_device_capabilities[];
+typedef struct AVDeviceCapabilitiesQuery AVDeviceCapabilitiesQuery;
 
 /**
  * Initialize capabilities probing API based on AVOption API.
diff --git a/libavdevice/internal.h b/libavdevice/internal.h
index 67c90e1f87..bef3a4bd2d 100644
--- a/libavdevice/internal.h
+++ b/libavdevice/internal.h
@@ -19,10 +19,43 @@
 #ifndef AVDEVICE_INTERNAL_H
 #define AVDEVICE_INTERNAL_H
 
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixfmt.h"
+#include "libavutil/rational.h"
+#include "libavutil/samplefmt.h"
+#include "libavcodec/codec_id.h"
 #include "libavformat/avformat.h"
 
 av_warn_unused_result
 int ff_alloc_input_device_context(struct AVFormatContext **avctx, const 
AVInputFormat *iformat,
   const char *format);
 
+/**
+ * Structure describes device capabilities.
+ *
+ * It is used by devices in conjunction with ff_device_capabilities AVOption 
table
+ * to implement capabilities probing API based on AVOption API.
+ */
+struct AVDeviceCapabilitiesQuery {
+const AVClass *av_class;
+AVFormatContext *device_context;
+enum AVCodecID codec;
+enum AVSampleFormat sample_format;
+enum AVPixelFormat pixel_format;
+int sample_rate;
+int channels;
+int64_t channel_layout;
+int window_width;
+int window_height;
+int frame_width;
+int frame_height;
+AVRational fps;
+};
+
+/**
+ * AVOption table used by devices to implement device capabilities API.
+ */
+extern const AVOption ff_device_capabilities[];
+
 #endif
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 7c132f2174..09156778db 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -30,7 +30,7 @@
 
 #include "version_major.h"
 
-#define LIBAVDEVICE_VERSION_MINOR   9
+#define LIBAVDEVICE_VERSION_MINOR   1
 #define LIBAVDEVICE_VERSION_MICRO 100
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
diff --git a/libavdevice/version_major.h b/libavdevice/version_major.h
index d255ff6992..b32de7325d 100644
--- a/libavdevice/version_major.h
+++ b/libavdevice/version_major.h
@@ -25,7 +25,7 @@
  * Libavdevice version macros
  */
 
-#define LIBAVDEVICE_VERSION_MAJOR  59
+#define LIBAVDEVICE_VERSION_MAJOR  60
 
 /**
  * FF_API_* defines may be placed below to indicate public API that will be
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 08/21] avdevice/avdevice: clean up avdevice_capabilities_create

2022-03-30 Thread Diederick Niehorster
Draw implementation in line with that of avdevice_list_devices

Signed-off-by: Diederick Niehorster 
---
 libavdevice/avdevice.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index d367189532..2e8261e0d2 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -113,11 +113,14 @@ int 
avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte
  AVDictionary **device_options)
 {
 int ret;
-av_assert0(s && caps);
+av_assert0(s);
+av_assert0(caps);
 av_assert0(s->iformat || s->oformat);
 if ((s->oformat && !s->oformat->create_device_capabilities) ||
-(s->iformat && !s->iformat->create_device_capabilities))
+(s->iformat && !s->iformat->create_device_capabilities)) {
+*caps = NULL;
 return AVERROR(ENOSYS);
+}
 *caps = av_mallocz(sizeof(**caps));
 if (!(*caps))
 return AVERROR(ENOMEM);
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 07/21] avdevice/avdevice: Revert "Deprecate AVDevice Capabilities API"

2022-03-30 Thread Diederick Niehorster
This reverts commit 4f49ca7bbc75a9db4cdf93f27f95a668c751f160. The next
few patches clean up the API and implement this capability for
avdevice/dshow.

Bumping avformat and avdevice version.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/avdevice.c | 71 ++
 libavdevice/avdevice.h |  5 ---
 libavdevice/version.h  |  4 +--
 libavformat/avformat.h | 21 +
 libavformat/version.h  |  2 +-
 5 files changed, 89 insertions(+), 14 deletions(-)

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 43d3406670..d367189532 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -28,11 +28,39 @@
 #include "libavutil/ffversion.h"
 const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
 
-#if FF_API_DEVICE_CAPABILITIES
+#define E AV_OPT_FLAG_ENCODING_PARAM
+#define D AV_OPT_FLAG_DECODING_PARAM
+#define A AV_OPT_FLAG_AUDIO_PARAM
+#define V AV_OPT_FLAG_VIDEO_PARAM
+#define OFFSET(x) offsetof(AVDeviceCapabilitiesQuery, x)
+
 const AVOption av_device_capabilities[] = {
+{ "codec", "codec", OFFSET(codec), AV_OPT_TYPE_INT,
+{.i64 = AV_CODEC_ID_NONE}, AV_CODEC_ID_NONE, INT_MAX, E|D|A|V },
+{ "sample_format", "sample format", OFFSET(sample_format), 
AV_OPT_TYPE_SAMPLE_FMT,
+{.i64 = AV_SAMPLE_FMT_NONE}, AV_SAMPLE_FMT_NONE, INT_MAX, E|D|A },
+{ "sample_rate", "sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT,
+{.i64 = -1}, -1, INT_MAX, E|D|A },
+{ "channels", "channels", OFFSET(channels), AV_OPT_TYPE_INT,
+{.i64 = -1}, -1, INT_MAX, E|D|A },
+{ "channel_layout", "channel layout", OFFSET(channel_layout), 
AV_OPT_TYPE_CHANNEL_LAYOUT,
+{.i64 = -1}, -1, INT_MAX, E|D|A },
+{ "pixel_format", "pixel format", OFFSET(pixel_format), 
AV_OPT_TYPE_PIXEL_FMT,
+{.i64 = AV_PIX_FMT_NONE}, AV_PIX_FMT_NONE, INT_MAX, E|D|V },
+{ "window_size", "window size", OFFSET(window_width), 
AV_OPT_TYPE_IMAGE_SIZE,
+{.str = NULL}, -1, INT_MAX, E|D|V },
+{ "frame_size", "frame size", OFFSET(frame_width), AV_OPT_TYPE_IMAGE_SIZE,
+{.str = NULL}, -1, INT_MAX, E|D|V },
+{ "fps", "fps", OFFSET(fps), AV_OPT_TYPE_RATIONAL,
+{.dbl = -1}, -1, INT_MAX, E|D|V },
 { NULL }
 };
-#endif
+
+#undef E
+#undef D
+#undef A
+#undef V
+#undef OFFSET
 
 unsigned avdevice_version(void)
 {
@@ -81,18 +109,49 @@ int avdevice_dev_to_app_control_message(struct 
AVFormatContext *s, enum AVDevToA
 return s->control_message_cb(s, type, data, data_size);
 }
 
-#if FF_API_DEVICE_CAPABILITIES
 int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, 
AVFormatContext *s,
  AVDictionary **device_options)
 {
-return AVERROR(ENOSYS);
+int ret;
+av_assert0(s && caps);
+av_assert0(s->iformat || s->oformat);
+if ((s->oformat && !s->oformat->create_device_capabilities) ||
+(s->iformat && !s->iformat->create_device_capabilities))
+return AVERROR(ENOSYS);
+*caps = av_mallocz(sizeof(**caps));
+if (!(*caps))
+return AVERROR(ENOMEM);
+(*caps)->device_context = s;
+if (((ret = av_opt_set_dict(s->priv_data, device_options)) < 0))
+goto fail;
+if (s->iformat) {
+if ((ret = s->iformat->create_device_capabilities(s, *caps)) < 0)
+goto fail;
+} else {
+if ((ret = s->oformat->create_device_capabilities(s, *caps)) < 0)
+goto fail;
+}
+av_opt_set_defaults(*caps);
+return 0;
+  fail:
+av_freep(caps);
+return ret;
 }
 
 void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, 
AVFormatContext *s)
 {
-return;
+if (!s || !caps || !(*caps))
+return;
+av_assert0(s->iformat || s->oformat);
+if (s->iformat) {
+if (s->iformat->free_device_capabilities)
+s->iformat->free_device_capabilities(s, *caps);
+} else {
+if (s->oformat->free_device_capabilities)
+s->oformat->free_device_capabilities(s, *caps);
+}
+av_freep(caps);
 }
-#endif
 
 int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
 {
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index 74e9518a8e..9724e7edf5 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -347,7 +347,6 @@ int avdevice_dev_to_app_control_message(struct 
AVFormatContext *s,
 enum AVDevToAppMessageType type,
 void *data, size_t data_size);
 
-#if FF_API_DEVICE_CAPABILITIES
 /**
  * Following API allows user to probe device capabilities (supported codecs,
  * pixel formats, sample formats, resolutions, channel counts, etc).
@@ -443,7 +442,6 @@ typedef struct AVDeviceCapabilitiesQuery {
 /**
  * AVOption table used by devices to implement device capabilities API. Should 
not be used by a user.
  */
-attribute_deprecated
 extern const AVOption av_device_capabilities[];
 
 /**
@@ -463,7 +461,6 @@ extern co

[FFmpeg-devel] [PATCH v5 06/21] avdevice/dshow: add config dialog command for crossbar and tv tuner

2022-03-30 Thread Diederick Niehorster
The "show config dialog" command message can now also trigger dialog
boxes for the crossbar connecting pins filter the analog tuner
audio / analog tuner filters.

Bumping avdevice version.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/dshow.c  | 51 ++--
 libavdevice/dshow_capture.h  | 10 
 libavdevice/dshow_crossbar.c | 91 +++-
 libavdevice/version.h|  2 +-
 4 files changed, 115 insertions(+), 39 deletions(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 78194406b5..a780351170 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -240,6 +240,11 @@ dshow_read_close(AVFormatContext *s)
 struct dshow_ctx *ctx = s->priv_data;
 PacketListEntry *pktl;
 
+if (ctx->graph_builder2[VideoDevice])
+ICaptureGraphBuilder2_Release(ctx->graph_builder2[VideoDevice]);
+if (ctx->graph_builder2[AudioDevice])
+ICaptureGraphBuilder2_Release(ctx->graph_builder2[AudioDevice]);
+
 if (ctx->control) {
 IMediaControl_Stop(ctx->control);
 IMediaControl_Release(ctx->control);
@@ -1464,6 +1469,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum 
*devenum,
 av_log(avctx, AV_LOG_ERROR, "Could not create CaptureGraphBuilder2\n");
 goto error;
 }
+ctx->graph_builder2[devtype] = graph_builder2;
 ICaptureGraphBuilder2_SetFiltergraph(graph_builder2, graph);
 if (r != S_OK) {
 av_log(avctx, AV_LOG_ERROR, "Could not set graph for 
CaptureGraphBuilder2\n");
@@ -1488,9 +1494,6 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum 
*devenum,
 ret = 0;
 
 error:
-if (graph_builder2 != NULL)
-ICaptureGraphBuilder2_Release(graph_builder2);
-
 if (pers_stream)
 IPersistStream_Release(pers_stream);
 
@@ -1536,10 +1539,48 @@ static int dshow_control_message(AVFormatContext 
*avctx, int type, void *data, s
 ff_dshow_show_filter_properties(ctx->device_filter[devtype], 
avctx);
 } else if (dialog & 1<<2) {
 // crossbar_connection_dialog
-// TODO
+if (ctx->device_filter[devtype] && ctx->graph_builder2[devtype]) {
+IAMCrossbar *cross_bar = NULL;
+IBaseFilter *cross_bar_base_filter = NULL;
+hr = 
ff_dshow_get_crossbar_and_filter(ctx->graph_builder2[devtype], 
ctx->device_filter[devtype], cross_bar, &cross_bar_base_filter);
+
+if (hr == S_OK && cross_bar_base_filter)
+ff_dshow_show_filter_properties(cross_bar_base_filter, 
avctx);
+
+if (cross_bar)
+IAMCrossbar_Release(cross_bar);
+if (cross_bar_base_filter)
+IBaseFilter_Release(cross_bar_base_filter);
+}
 } else if (dialog & 1<<3) {
 // tv_tuner_dialog
-// TODO
+if (ctx->device_filter[devtype] && ctx->graph_builder2[devtype]) {
+if (devtype == VideoDevice) {
+IAMTVTuner *tv_tuner_filter = NULL;
+IBaseFilter *tv_tuner_base_filter = NULL;
+hr = 
ff_dshow_get_tvtuner_and_filter(ctx->graph_builder2[devtype], 
ctx->device_filter[devtype], tv_tuner_filter, tv_tuner_base_filter);
+
+if (hr == S_OK && tv_tuner_base_filter)
+ff_dshow_show_filter_properties(tv_tuner_base_filter, 
avctx);
+
+if (tv_tuner_filter)
+IAMTVTuner_Release(tv_tuner_filter);
+if (tv_tuner_base_filter)
+IBaseFilter_Release(tv_tuner_base_filter);
+} else {
+IAMAudioInputMixer *tv_audio_filter = NULL;
+IBaseFilter *tv_audio_base_filter = NULL;
+hr = 
ff_dshow_get_audiomixer_and_filter(ctx->graph_builder2[devtype], 
ctx->device_filter[devtype], tv_audio_filter, tv_audio_base_filter);
+
+if (hr == S_OK && tv_audio_base_filter)
+ff_dshow_show_filter_properties(tv_audio_base_filter, 
avctx);
+
+if (tv_audio_filter)
+IAMAudioInputMixer_Release(tv_audio_filter);
+if (tv_audio_base_filter)
+IBaseFilter_Release(tv_audio_base_filter);
+}
+}
 }
 break;
 }
diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h
index d0dd35a670..94ba9896b7 100644
--- a/libavdevice/dshow_capture.h
+++ b/libavdevice/dshow_capture.h
@@ -318,6 +318,7 @@ struct dshow_ctx {
 IPin*device_pin[2];
 DShowFilter *capture_filter[2];
 DShowPin*capture_pin[2];
+ICaptureGraphBuilder2 *graph_builder2[2];
 
 HANDLE mutex;
 HANDLE event[2]; /* event[0] is set by DirectShow
@@ -352,6 +353,15 @@ struct dshow_ctx {
 HRESULT ff_dshow_try_setup_crossbar_options(ICaptureGraphBuilder2 
*graph_bui

[FFmpeg-devel] [PATCH v5 05/21] avdevice/dshow: accept show config dialog control message

2022-03-30 Thread Diederick Niehorster
DirectShow source will pop up its configuration dialog when
AV_APP_TO_DEV_CONFIG is received. Implementation for several other
possible configuration dialogs is more involved and will be provided in
the next commit.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/dshow.c | 29 -
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 652e093204..78194406b5 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -1508,6 +1508,7 @@ static int dshow_control_message(AVFormatContext *avctx, 
int type, void *data, s
 struct dshow_ctx *ctx = avctx->priv_data;
 int run_state = ctx->is_running;
 HRESULT hr;
+int ret = 0;
 
 switch (type) {
 case AV_APP_TO_DEV_PAUSE:
@@ -1519,6 +1520,32 @@ static int dshow_control_message(AVFormatContext *avctx, 
int type, void *data, s
 case AV_APP_TO_DEV_TOGGLE_PAUSE:
 run_state = !run_state;
 break;
+case AV_APP_TO_DEV_CONFIG: {
+/* For documentation of dialog variable, see ffmpeg-devices.html in 
docs */
+int dialog;
+enum dshowDeviceType devtype;
+
+if (!data)
+av_log(avctx, AV_LOG_ERROR, "Use the data argument to indicate 
which dialog should be shown.");
+dialog = *(int *) data;
+devtype = (dialog & 1) ? AudioDevice : VideoDevice;
+
+if (dialog & 1<<1) {
+// device_dialog
+if (ctx->device_filter[devtype])
+ff_dshow_show_filter_properties(ctx->device_filter[devtype], 
avctx);
+} else if (dialog & 1<<2) {
+// crossbar_connection_dialog
+// TODO
+} else if (dialog & 1<<3) {
+// tv_tuner_dialog
+// TODO
+}
+break;
+}
+
+default:
+ret = AVERROR(ENOSYS);
 }
 
 // if play state change requested, apply
@@ -1539,7 +1566,7 @@ static int dshow_control_message(AVFormatContext *avctx, 
int type, void *data, s
 ctx->is_running = run_state;
 }
 
-return 0;
+return ret;
 }
 
 static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt)
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 04/21] avdevice: add control message requesting to show config dialog

2022-03-30 Thread Diederick Niehorster
This control message can be used to programmatically ask a device to
show one of its configuration dialogs.

Adding documentation of this message's int argument.

Bumping avdevice version.

Signed-off-by: Diederick Niehorster 
---
 doc/indevs.texi| 34 ++
 libavdevice/avdevice.h | 10 ++
 libavdevice/version.h  |  4 ++--
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 9d8020311a..0302859552 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -682,6 +682,40 @@ $ ffmpeg -f dshow -show_video_device_dialog true 
-crossbar_video_input_pin_numbe
 
 @end itemize
 
+@subsection Libavdevice user notes
+
+The dshow device supports the @code{avdevice_app_to_dev_control_message}
+interface.
+
+It understands the @code{AV_APP_TO_DEV_PAUSE}, @code{AV_APP_TO_DEV_PLAY}
+and @code{AV_APP_TO_DEV_TOGGLE_PAUSE} commands, which respective stop and
+start whether data is captured from the connected device, and toggle
+capture state.
+
+It furthermore understands the @code{AV_APP_TO_DEV_CONFIG} message, which
+requests the device to show a configuration dialog (if available). An
+@code{int} should be passed along with this command to indicate which
+configuration dialog should be shown. The bits in this @code{int} have
+the following meaning:
+
+@itemize @bullet
+@item
+1st bit: If set, the dialog for the audio device will be shown. If not set
+the dialog for the video device will be shown.
+
+@item
+2nd bit: If set, show property dialog for the audio or video capture device,
+allowing to change audio or video filter properties and configurations
+manually.
+
+@item
+3rd bit: If set, show property dialog where crossbar pin routings of the
+audio/video device can be manually modified.
+
+@item
+4th bit: If set, show property dialog where TV channels and frequencies can be 
manually modified (in case of video device), or TV audio (like mono vs. stereo, 
Language A, B or C) can be manually modified in case of audio device.
+@end itemize
+
 @section fbdev
 
 Linux framebuffer input device.
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index db16a2f27e..74e9518a8e 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -206,6 +206,16 @@ enum AVAppToDevMessageType {
  */
 AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'),
 AV_APP_TO_DEV_GET_MUTE   = MKBETAG('G', 'M', 'U', 'T'),
+
+/**
+ * Request to show configuration dialog.
+ * 
+ * If device has a configuration dialog of type indicated by
+ * data, show it.
+ * 
+ * data: int (device-specific).
+ */
+AV_APP_TO_DEV_CONFIG = MKBETAG('C', 'O', 'N', 'F'),
 };
 
 /**
diff --git a/libavdevice/version.h b/libavdevice/version.h
index fb1dccb6b3..f27f9ad9bf 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -30,8 +30,8 @@
 
 #include "version_major.h"
 
-#define LIBAVDEVICE_VERSION_MINOR   7
-#define LIBAVDEVICE_VERSION_MICRO 101
+#define LIBAVDEVICE_VERSION_MINOR   8
+#define LIBAVDEVICE_VERSION_MICRO 100
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
LIBAVDEVICE_VERSION_MINOR, \
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 03/21] avdevice/dshow: implement control_message interface

2022-03-30 Thread Diederick Niehorster
This allows programmatic users of avdevice to start and stop the
DirectShow Capture graph (i.e. receive frames or not). This is important
because now the buffer fills up and starts dropping samples when
enqueued packets are not read out immediately after the demuxer is
opened.

Bumping avdevice version.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/dshow.c | 42 +
 libavdevice/dshow_capture.h |  1 +
 libavdevice/version.h   |  2 +-
 3 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index abb8325bc3..652e093204 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -1503,6 +1503,45 @@ error:
 return ret;
 }
 
+static int dshow_control_message(AVFormatContext *avctx, int type, void *data, 
size_t data_size)
+{
+struct dshow_ctx *ctx = avctx->priv_data;
+int run_state = ctx->is_running;
+HRESULT hr;
+
+switch (type) {
+case AV_APP_TO_DEV_PAUSE:
+run_state = 0;
+break;
+case AV_APP_TO_DEV_PLAY:
+run_state = 1;
+break;
+case AV_APP_TO_DEV_TOGGLE_PAUSE:
+run_state = !run_state;
+break;
+}
+
+// if play state change requested, apply
+if (run_state != ctx->is_running) {
+if (run_state)
+hr = IMediaControl_Run(ctx->control);
+else
+hr = IMediaControl_Pause(ctx->control);
+
+if (hr == S_FALSE) {
+OAFilterState pfs;
+hr = IMediaControl_GetState(ctx->control, 0, &pfs);
+}
+if (hr != S_OK) {
+av_log(avctx, AV_LOG_ERROR, "Could not run/pause graph\n");
+return AVERROR(EIO);
+}
+ctx->is_running = run_state;
+}
+
+return 0;
+}
+
 static enum AVCodecID waveform_codec_id(enum AVSampleFormat sample_fmt)
 {
 switch (sample_fmt) {
@@ -1747,6 +1786,7 @@ static int dshow_read_header(AVFormatContext *avctx)
 }
 // don't exit yet, allow it to list crossbar options in 
dshow_open_device
 }
+ctx->is_running = 0;
 if (ctx->device_name[VideoDevice]) {
 if ((r = dshow_open_device(avctx, devenum, VideoDevice, 
VideoSourceDevice)) < 0 ||
 (r = dshow_add_device(avctx, VideoDevice)) < 0) {
@@ -1820,6 +1860,7 @@ static int dshow_read_header(AVFormatContext *avctx)
 av_log(avctx, AV_LOG_ERROR, "Could not run graph (sometimes caused by 
a device already in use by other application)\n");
 goto error;
 }
+ctx->is_running = 1;
 
 ret = 0;
 
@@ -1932,6 +1973,7 @@ const AVInputFormat ff_dshow_demuxer = {
 .read_packet= dshow_read_packet,
 .read_close = dshow_read_close,
 .get_device_list= dshow_get_device_list,
+.control_message= dshow_control_message,
 .flags  = AVFMT_NOFILE | AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | 
AVFMT_NO_BYTE_SEEK,
 .priv_class = &dshow_class,
 };
diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h
index b548cd7afc..d0dd35a670 100644
--- a/libavdevice/dshow_capture.h
+++ b/libavdevice/dshow_capture.h
@@ -331,6 +331,7 @@ struct dshow_ctx {
 
 IMediaControl *control;
 IMediaEvent *media_event;
+int is_running;
 
 enum AVPixelFormat pixel_format;
 enum AVCodecID video_codec_id;
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 4efe7f8649..fb1dccb6b3 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -31,7 +31,7 @@
 #include "version_major.h"
 
 #define LIBAVDEVICE_VERSION_MINOR   7
-#define LIBAVDEVICE_VERSION_MICRO 100
+#define LIBAVDEVICE_VERSION_MICRO 101
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
LIBAVDEVICE_VERSION_MINOR, \
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 02/21] avformat: add control_message function to AVInputFormat

2022-03-30 Thread Diederick Niehorster
Control messages are useful for programmatic control of not only outdevs
but also indevs.

Bumping avformat version.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/avdevice.c | 8 +---
 libavformat/avformat.h | 6 ++
 libavformat/version.h  | 2 +-
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 98934abfb7..43d3406670 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -66,9 +66,11 @@ const char * avdevice_license(void)
 int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum 
AVAppToDevMessageType type,
 void *data, size_t data_size)
 {
-if (!s->oformat || !s->oformat->control_message)
-return AVERROR(ENOSYS);
-return s->oformat->control_message(s, type, data, data_size);
+if (s->oformat && s->oformat->control_message)
+return s->oformat->control_message(s, type, data, data_size);
+if (s->iformat && s->iformat->control_message)
+return s->iformat->control_message(s, type, data, data_size);
+return AVERROR(ENOSYS);
 }
 
 int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum 
AVDevToAppMessageType type,
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 350912e272..06db024559 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -785,6 +785,12 @@ typedef struct AVInputFormat {
  */
 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t 
min_ts, int64_t ts, int64_t max_ts, int flags);
 
+/**
+ * Allows sending messages from application to device.
+ */
+int (*control_message)(struct AVFormatContext *s, int type,
+   void *data, size_t data_size);
+
 /**
  * Returns device list with it properties.
  * @see avdevice_list_devices() for more details.
diff --git a/libavformat/version.h b/libavformat/version.h
index bb6a7d4510..d195704a31 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 
 #include "version_major.h"
 
-#define LIBAVFORMAT_VERSION_MINOR  21
+#define LIBAVFORMAT_VERSION_MINOR  22
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
2.28.0.windows.1

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

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


[FFmpeg-devel] [PATCH v5 01/21] avdevice: lock to minor version of avformat

2022-03-30 Thread Diederick Niehorster
As per discussion on the list (
https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281513.html, see
especially https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281586.html),
to resolve the the unholy ABI-relationship between libavdevice and
libavformat and allow easier working on the part of the avdevice API
that lives in avformat, lock avdevice to a specific major and minor
version of avformat.

Documentation of this restriction added.

Signed-off-by: Diederick Niehorster 
---
 libavdevice/avdevice.c | 13 +
 libavdevice/avdevice.h | 10 ++
 libavdevice/version.h  | 13 -
 libavformat/avformat.h |  3 +++
 libavformat/utils.c|  5 +
 libavformat/version.h  | 14 --
 libavutil/avutil.h |  3 +++
 libavutil/macros.h |  3 +++
 8 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 833d200054..98934abfb7 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -19,6 +19,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
+#include "libavformat/version.h"
 #include "avdevice.h"
 #include "internal.h"
 #include "config.h"
@@ -39,6 +40,18 @@ unsigned avdevice_version(void)
 return LIBAVDEVICE_VERSION_INT;
 }
 
+unsigned avdevice_version_same_minor(void)
+{
+// check version of loaded lavf has same major and minor version as
+// this library was compiled against
+// NB: this function doesn't have to be called, dynamic linker will
+// signal error when avformat of wrong major or minor version is found.
+if ((avformat_version_same_minor()) & ~0xFF != (LIBAVFORMAT_VERSION_INT & 
~0xFF))
+abort();
+
+return avdevice_version();
+}
+
 const char * avdevice_configuration(void)
 {
 return FFMPEG_CONFIGURATION;
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index 0b32e59fed..db16a2f27e 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -47,6 +47,16 @@
  *
  * To use libavdevice, simply call avdevice_register_all() to register all
  * compiled muxers and demuxers. They all use standard libavformat API.
+ * 
+ * Note that libavdevice is locked to be used with the same major and minor
+ * version of libavformat that it was built against. Attempting to use a 
+ * shared build of FFmpeg or its libavdevice library with a libavformat of
+ * a different major or minor version will generate a dynamic linker error.
+ * This is achieved by the internal function check_avformat_same_minor() in 
+ * avdevice.c. This function does not have to be called, its call to
+ * avformat_version_same_minor() (a macro which expands to a name with the
+ * specific major and minor version of avformat embedded in it) is sufficient
+ * to trigger link failure.
  *
  * @{
  */
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 09c1d778dc..4efe7f8649 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -26,10 +26,11 @@
  */
 
 #include "libavutil/version.h"
+#include "libavutil/macros.h"
 
 #include "version_major.h"
 
-#define LIBAVDEVICE_VERSION_MINOR   6
+#define LIBAVDEVICE_VERSION_MINOR   7
 #define LIBAVDEVICE_VERSION_MICRO 100
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
@@ -42,4 +43,14 @@
 
 #define LIBAVDEVICE_IDENT   "Lavd" AV_STRINGIFY(LIBAVDEVICE_VERSION)
 
+/**
+ * avdevice_version_same_minor() expands to a function with
+ * the same minor and major version it was compiled against
+ * encoded in it. Enables locking to the minor version of
+ * other libraries they were compiled against. Does not have
+ * to be called by user.
+ */
+#define avdevice_version_same_minor 
AV_MAKE_MAJOR_MINOR_FUNC_NAME(device,LIBAVFORMAT_VERSION_MAJOR,LIBAVFORMAT_VERSION_MINOR)
+unsigned avdevice_version_same_minor(void);
+
 #endif /* AVDEVICE_VERSION_H */
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index f12fa7d904..350912e272 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -64,6 +64,9 @@
  * set by user for input, always set by user for output (unless you are dealing
  * with an AVFMT_NOFILE format).
  *
+ * Note that libavdevice is locked to a specific major and minor version of
+ * libavformat, see @ref lavd "libavdevice" for more details.
+ *
  * @section lavf_options Passing options to (de)muxers
  * It is possible to configure lavf muxers and demuxers using the @ref 
avoptions
  * mechanism. Generic (format-independent) libavformat options are provided by
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 3f253c2045..6d9c4e778a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -64,6 +64,11 @@ unsigned avformat_version(void)
 return LIBAVFORMAT_VERSION_INT;
 }
 
+unsigned avformat_version_same_minor(void)
+{
+return avformat_version();
+}
+
 const char *avformat_configuration(void)
 {
 return FFMPEG_CONFIGURATION;
diff --git a/libavformat/version.h b/libavformat/version.h
ind

[FFmpeg-devel] [PATCH v5 00/21] avdevice (mostly dshow) enhancements

2022-03-30 Thread Diederick Niehorster
This patch series implements a series of features, mostly enhancing the
dshow avdevice, but also adding new functionality to avformat.
This whole patchset enabled users of the FFmpeg API to fully
query and control a dshow device, making FFmpeg a nice backend for any
program that needs access to, e.g., a webcam.

Different from v3 and v4, part of the patches has now been accepted, so
only remaining features are in this set. Importantly, as per discussion
on the list (
https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281513.html, see
especially https://ffmpeg.org/pipermail/ffmpeg-devel/2021-June/281586.html),
to resolve the the unholy ABI-relationship between libavdevice and
libavformat and allow easier working on the part of the avdevice API
that lives in avformat, avdevice is now locked to a specific major and minor
version of avformat. This is documented in libavdevice/avdevice.h.

Regarding new functionality added to avformat:
Querying the capabilities of a dshow device is also possible on a
device that is already opened. I expect/guess however that it may not be
possible to achieve that for all of the avdevices, so in principle it is
important that this patchset adds the ability to create an allocated but
unopened AVFormatContext+AVInputFormat with the new function
avformat_alloc_input_context(). This is tested in the new
device_get_capabilities example.

Diederick Niehorster (21):
  avdevice: lock to minor version of avformat
  avformat: add control_message function to AVInputFormat
  avdevice/dshow: implement control_message interface
  avdevice: add control message requesting to show config dialog
  avdevice/dshow: accept show config dialog control message
  avdevice/dshow: add config dialog command for crossbar and tv tuner
  avdevice/avdevice: Revert "Deprecate AVDevice Capabilities API"
  avdevice/avdevice: clean up avdevice_capabilities_create
  avdevice: capabilities API details no longer public
  avutil/opt: document AVOptionRange min_value > max_value
  avdevice: Add internal helpers for querying device capabilities
  avdevice: change device capabilities option type
  avdevice: improve capabilities' option API
  avdevice/dshow: move audio format helpers
  avdevice/dshow: when closing, set context fields back to zero
  avdevice/dshow: implement capabilities API
  avdevice/dshow: cosmetics
  avformat: add avformat_alloc_input_context()
  doc/examples: adding device_get_capabilities example
  Makefile/examples: cosmetics
  avdevice/dshow: capabilities query also works on opened device

 configure  |   2 +
 doc/examples/.gitignore|   1 +
 doc/examples/Makefile  |  47 +-
 doc/examples/Makefile.example  |   1 +
 doc/examples/device_get_capabilities.c | 243 ++
 doc/indevs.texi|  34 ++
 libavdevice/avdevice.c | 177 ++-
 libavdevice/avdevice.h | 111 ++---
 libavdevice/dshow.c| 641 +++--
 libavdevice/dshow_capture.h|  14 +
 libavdevice/dshow_crossbar.c   |  91 ++--
 libavdevice/internal.h |  66 +++
 libavdevice/utils.c|  48 ++
 libavdevice/version.h  |  15 +-
 libavdevice/version_major.h|   2 +-
 libavformat/avformat.h |  59 ++-
 libavformat/demux.c|  74 ++-
 libavformat/utils.c|   5 +
 libavformat/version.h  |  14 +-
 libavutil/avutil.h |   3 +
 libavutil/macros.h |   3 +
 libavutil/opt.c|   2 +-
 libavutil/opt.h|   5 +
 23 files changed, 1462 insertions(+), 196 deletions(-)
 create mode 100644 doc/examples/device_get_capabilities.c

-- 
2.28.0.windows.1

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

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


Re: [FFmpeg-devel] [PATCH] test: tiny_ssim: Don't include config.h

2022-03-30 Thread Martin Storsjö

On Sun, 27 Mar 2022, Martin Storsjö wrote:


tiny_ssim is built for the build host, not for the target platform.
Therefore, it mustn't include the config.h header, which is set up
specifically for the target platform and compiler.

This fixes cross building for older WinStore platforms, where
config.h contains "#define getenv(x) NULL".

Signed-off-by: Martin Storsjö 
---
tests/tiny_ssim.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/tests/tiny_ssim.c b/tests/tiny_ssim.c
index 08f8e92a03..9740652288 100644
--- a/tests/tiny_ssim.c
+++ b/tests/tiny_ssim.c
@@ -27,7 +27,6 @@
 * overlapped 8x8 block sums, rather than the original gaussian weights.
 */

-#include "config.h"
#include 
#include 
#include 
--
2.25.1


Acked by Lynne on irc, thus pushed.

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

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


Re: [FFmpeg-devel] [PATCH] vc1dsp: Change remaining stride parameters to ptrdiff_t

2022-03-30 Thread Martin Storsjö

On Tue, 29 Mar 2022, Ben Avison wrote:


On 29/03/2022 13:44, Martin Storsjö wrote:

The existing x86 assembly for loop filters uses the stride as a
full register without clearing/sign extending the upper half
of the registers on x86_64.

This avoids crashes if the caller would have passed nonzero bits
in the previously undefined upper 32 bits of the parameters.


Looks perfectly reasonable to me. I'll hold off making matching changes 
to my upcoming Arm versions until this gets merged. (My 64-bit Arm 
versions followed the old prototype and sign-extended the strides from 
32 to 64 bits, but that won't be necessary any more.)


Acked by Lynne on irc too - so I pushed it now.

// Martin

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

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


[FFmpeg-devel] [PATCH v10 1/1] avformat: Add IPFS protocol support.

2022-03-30 Thread Mark Gaiser
This patch adds support for:
- ffplay ipfs://
- ffplay ipns://

IPFS data can be played from so called "ipfs gateways".
A gateway is essentially a webserver that gives access to the
distributed IPFS network.

This protocol support (ipfs and ipns) therefore translates
ipfs:// and ipns:// to a http:// url. This resulting url is
then handled by the http protocol. It could also be https
depending on the gateway provided.

To use this protocol, a gateway must be provided.
If you do nothing it will try to find it in your
$HOME/.ipfs/gateway file. The ways to set it manually are:
1. Define a -gateway  to the gateway.
2. Define $IPFS_GATEWAY with the full http link to the gateway.
3. Define $IPFS_PATH and point it to the IPFS data path.
4. Have IPFS running in your local user folder (under $HOME/.ipfs).

Signed-off-by: Mark Gaiser 
---
 configure |   2 +
 doc/protocols.texi|  30 
 libavformat/Makefile  |   2 +
 libavformat/ipfsgateway.c | 309 ++
 libavformat/protocols.c   |   2 +
 5 files changed, 345 insertions(+)
 create mode 100644 libavformat/ipfsgateway.c

diff --git a/configure b/configure
index e4d36aa639..55af90957a 100755
--- a/configure
+++ b/configure
@@ -3579,6 +3579,8 @@ udp_protocol_select="network"
 udplite_protocol_select="network"
 unix_protocol_deps="sys_un_h"
 unix_protocol_select="network"
+ipfs_protocol_select="https_protocol"
+ipns_protocol_select="https_protocol"
 
 # external library protocols
 libamqp_protocol_deps="librabbitmq"
diff --git a/doc/protocols.texi b/doc/protocols.texi
index d207df0b52..7c9c0a4808 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -2025,5 +2025,35 @@ decoding errors.
 
 @end table
 
+@section ipfs
+
+InterPlanetary File System (IPFS) protocol support. One can access files 
stored 
+on the IPFS network through so called gateways. Those are http(s) endpoints.
+This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to be send 
+to such a gateway. Users can (and should) host their own node which means this 
+protocol will use your local machine gateway to access files on the IPFS 
network.
+
+If a user doesn't have a node of their own then the public gateway dweb.link 
is 
+used by default.
+
+You can use this protocol in 2 ways. Using IPFS:
+@example
+ffplay ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
+@end example
+
+Or the IPNS protocol (IPNS is mutable IPFS):
+@example
+ffplay ipns://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
+@end example
+
+You can also change the gateway to be used:
+
+@table @option
+
+@item gateway
+Defines the gateway to use. When nothing is provided the protocol will first 
try 
+your local gateway. If that fails dweb.link will be used.
+
+@end table
 
 @c man end PROTOCOLS
diff --git a/libavformat/Makefile b/libavformat/Makefile
index d7182d6bd8..e3233fd7ac 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -660,6 +660,8 @@ OBJS-$(CONFIG_SRTP_PROTOCOL) += srtpproto.o 
srtp.o
 OBJS-$(CONFIG_SUBFILE_PROTOCOL)  += subfile.o
 OBJS-$(CONFIG_TEE_PROTOCOL)  += teeproto.o tee_common.o
 OBJS-$(CONFIG_TCP_PROTOCOL)  += tcp.o
+OBJS-$(CONFIG_IPFS_PROTOCOL) += ipfsgateway.o
+OBJS-$(CONFIG_IPNS_PROTOCOL) += ipfsgateway.o
 TLS-OBJS-$(CONFIG_GNUTLS)+= tls_gnutls.o
 TLS-OBJS-$(CONFIG_LIBTLS)+= tls_libtls.o
 TLS-OBJS-$(CONFIG_MBEDTLS)   += tls_mbedtls.o
diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c
new file mode 100644
index 00..1a039589c0
--- /dev/null
+++ b/libavformat/ipfsgateway.c
@@ -0,0 +1,309 @@
+/*
+ * IPFS and IPNS protocol support through IPFS Gateway.
+ * Copyright (c) 2022 Mark Gaiser
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+#include "libavutil/tree.h"
+#include 
+#if HAVE_IO_H
+#include 
+#endif
+#if HAVE_UNISTD_H
+#include 
+#endif
+#include "os_support.h"
+#include "url.h"
+#include 
+#include 
+
+typedef struct IPFSGatewayContext {
+AVClass *class;
+URLContext *inner;
+// Is filled by the -gateway a

[FFmpeg-devel] [PATCH v10 0/1] Add IPFS protocol support.

2022-03-30 Thread Mark Gaiser
Hi,

This patch series adds support for IPFS.
V10:
- Removed free on c->gateway in ipfs_close to fix a double free.
V9:
- dweb.link as fallback gateway. This is managed by Protocol Labs (like IPFS).
- Change all errors to warnings as not having a gateway still gives you a 
  working video playback.
- Changed the console output to be more clear.
V8:
- Removed unnecessary change to set the first gateway_buffer character to 0.
  It made no sense as the buffer is always overwritten in the function context.
- Change %li to %zu (it's intended to print the sizeof in all cases)
V7:
- Removed sanitize_ipfs_gateway. Only the http/https check stayed and that's
  now in translate_ipfs_to_http.
- Added a check for ipfs_cid. It's only to show an error is someone happens to
  profide `ffplay ipfs://` without a cid.
- All snprintf usages are now checked.
- Adding a / to a gateway if it didn't end with it is now done in the same line
  that composes the full resulting url.
- And a couple more minor things.
V6:
- Moved the gateway buffer (now called gateway_buffer) to IPFSGatewayContext
- Changed nearly all PATH_MAX uses to sizeof(...) uses for future flexibility
- The rest is relatively minor feedback changes
V5:
- "c->gateway" is now not modified anymore
- Moved most variables to the stack
- Even more strict checks with the auto detection logic
- Errors are now AVERROR :)
- Added more logging and changed some debug ones to info ones as they are 
  valuable to aid debugging as a user when something goes wrong.
V3 (V4):
- V4: title issue from V3..
- A lot of style changes
- Made url checks a lot more strict
- av_asprintf leak fixes
- So many changes that a diff to v2 is again not sensible.
V2:
- Squashed and changed so much that a diff to v1 was not sensible.

The following is a short summary. In the IPFS ecosystem you access it's content
by a "Content IDentifier" (CID). This CID is, in simplified terms, a hash of 
the content. IPFS itself is a distributed network where any user can run a node
to be part of the network and access files by their CID. If any reachable node 
within that network has the CID, you can get it.

IPFS (as a technology) has two protocols, ipfs and ipns.
The ipfs protocol is the immutable way to access content.
The ipns protocol is a mutable layer on top of it. It's essentially a new CID 
that points to a ipfs CID. This "pointer" if you will can be changed to point 
to something else.
Much more information on how this technology works can be found here [1].

This patch series allows to interact natively with IPFS. That means being able
to access files like:
- ffplay ipfs://
- ffplay ipns://

There are multiple ways to access files on the IPFS network. This patch series
uses the gateway driven way. An IPFS node - by default - exposes a local 
gateway (say http://localhost:8080) which is then used to get content from IPFS.
The gateway functionality on the IPFS side contains optimizations to
be as ideal to streaming data as it can be. Optimizations that the http protocol
in ffmpeg also has and are thus reused for free in this approach.

A note on other "more appropiate" ways, as I received some feedback on that.
For ffmpeg purposes the gateway approach is ideal! There is a "libipfs" but
that would spin up an ipfs node with the overhead of:
- bootstrapping
- connecting to nodes
- finding other nodes to connect too
- finally finding your file

This alternative approach could take minutes before a file is played. The
gateway approach immediately connects to an already running node thus gives
the file the fastest.

Much of the logic in this patch series is to find that gateway and essentially 
rewrite:

"ipfs://"

to:

"http://localhost:8080/ipfs/"

Once that's found it's forwared to the protocol handler where eventually the
http protocol is going to handle it. Note that it could also be https. There's 
enough flexibility in the implementation to allow the user to provide a 
gateway. There are also public https gateways which can be used just as well.

After this patch is accepted, I'll work on getting IPFS supported in:
- mpv (requires this ffmpeg patch)
- vlc (prefers this patch but can be made to work without this patch)
- kodi (requires this ffmpeg patch)

Best regards,
Mark Gaiser

[1] https://docs.ipfs.io/concepts/

Mark Gaiser (1):
  avformat: Add IPFS protocol support.

 configure |   2 +
 doc/protocols.texi|  30 
 libavformat/Makefile  |   2 +
 libavformat/ipfsgateway.c | 309 ++
 libavformat/protocols.c   |   2 +
 5 files changed, 345 insertions(+)
 create mode 100644 libavformat/ipfsgateway.c

-- 
2.35.1

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

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


Re: [FFmpeg-devel] [PATCH v9 4/5] avformat/image2: add Jpeg XL as image2 format

2022-03-30 Thread Andreas Rheinhardt
Leo Izen:
> On 3/24/22 14:38, Michael Niedermayer wrote:
>> make -j32 tools/probetest && tools/probetest 256 4096
>>
>> testing size=1
>> testing size=2
>> testing size=4
>> Assertion n>=0 && n<=32 failed at libavcodec/get_bits.h:549
>> Aborted (core dumped)
> Not sure where this failure is coming from as I cannot reproduce it.
> 

It's an av_assert2() assert, i.e. only enabled with --assert-level=2
when running configure. And it is expected that this happens, given that
the get_bits-functions are not supposed to be used for skipping.
Actually, setting assert-level=2 should be done when developing FFmpeg;
it is the equivalent of enabling asserts (for non-release builds).

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

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


Re: [FFmpeg-devel] [PATCH v9 3/5] avcodec/libjxl: add Jpeg XL encoding via libjxl

2022-03-30 Thread Andreas Rheinhardt
Leo Izen:
> On 3/23/22 11:08, Andreas Rheinhardt wrote:
>>> +    temp = av_realloc(ctx->buffer, ctx->buffer_size);
>>> +    if (!temp) {
>>> +    av_freep(&ctx->buffer);
>> If you free this, you will be in a scenario where ctx->buffer is NULL,
>> yet ctx->buffer_size is > 0. This is inconsistent and might lead to
>> crashs in JxlEncoderProcessOutput. So don't free this and only set
>> buffer_size after the reallocation succeeded.
> Does it matter what ctx->buffer_size is if ctx->buffer is NULL?
> On 3/23/22 11:08, Andreas Rheinhardt wrote:
>> Unnecessary: av_freep() resets ctx->buffer and resetting buffer_size is
>> unnecessary.
> 
> Here, you claim that resetting buffer_size is unnecessary but above you
> insist it is necessary. I'm confused here.
> 

buffer_size is not used after libjxl_encode_close() at all, as this is
the codec's close callback; libjxl_encode_frame() meanwhile may be
called again after freeing and if it reaches JxlEncoderProcessOutput(),
the latter would be called with next_out == NULL and available != 0.
JxlEncoderProcessOutput() might check for this (and error out) or it may
just crash.

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/pcm_rechunk_bsf: unref packet before putting a new one in

2022-03-30 Thread Michael Niedermayer
On Tue, Mar 29, 2022 at 06:33:06PM -0300, James Almer wrote:
> On 3/29/2022 6:24 PM, Michael Niedermayer wrote:
> > Fixes: memleak
> > Fixes: 
> > 45982/clusterfuzz-testcase-minimized-ffmpeg_BSF_PCM_RECHUNK_fuzzer-5562089618407424
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >   libavcodec/pcm_rechunk_bsf.c | 1 +
> >   1 file changed, 1 insertion(+)
> > 
> > diff --git a/libavcodec/pcm_rechunk_bsf.c b/libavcodec/pcm_rechunk_bsf.c
> > index 108d9e90b9..3f43934fe9 100644
> > --- a/libavcodec/pcm_rechunk_bsf.c
> > +++ b/libavcodec/pcm_rechunk_bsf.c
> > @@ -153,6 +153,7 @@ static int rechunk_filter(AVBSFContext *ctx, AVPacket 
> > *pkt)
> >   }
> >   }
> > +av_packet_unref(s->in_pkt);
> 
> This looks to me like it revealed a bug in the code above, which is meant to
> ensure s->in_pkt will be blank at this point. It should be fixed there
> instead.

IIRC the problem was a input packet with size 0
the code seems to assume 0 meaning no packet

I can check more explicitly for that after ff_bsf_get_packet_ref()
and unref there, its more code through

thx


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] Add decoding of > 32-bit residuals to FLAC

2022-03-30 Thread Andreas Rheinhardt
Martijn van Beurden:
> The size of residuals in a FLAC file coding for 24-bit PCM can
> exceed the range of a 32-bit signed integer. One pathological
> example with residuals exceeding [-2^33,2^33) can be found here:
> http://www.audiograaf.nl/misc_stuff/Extreme%20residual%20LPC%20order%2014.flac

Can this happen with real encoders or has this file been specifically
crafted? What is the performance impact of this patch on ordinary files?

> 
> The theorectical maximum bit depth for a residual in a FLAC file is

^

> 32 + 1 + 15 + 5 - 0 = 53 bit (max bit depth + extra bit for side
> channel + max lpc coeff precision + log2(max_order) - min
> lpc shift)
> 
> This patch adds detection of the possibilty of such residuals

   ^

> occuring and an alternate data path wide enough to handle them

   ^

> ---
>  libavcodec/flacdec.c | 107 ++-
>  libavcodec/golomb.h  |  56 ++
>  2 files changed, 152 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
> index dd6026f9de..3be1b63411 100644
> --- a/libavcodec/flacdec.c
> +++ b/libavcodec/flacdec.c
> @@ -64,6 +64,8 @@ typedef struct FLACContext {
>  uint8_t *decoded_buffer;
>  unsigned int decoded_buffer_size;
>  int buggy_lpc;  ///< use workaround for old lavc 
> encoded files
> +int64_t *residual64;///< to keep residuals exceeding 
> int32_t
> +unsigned int residual64_size;
>  
>  FLACDSPContext dsp;
>  } FLACContext;
> @@ -149,6 +151,10 @@ static int allocate_buffers(FLACContext *s)
>  if (!s->decoded_buffer)
>  return AVERROR(ENOMEM);
>  
> +av_fast_malloc(&s->residual64, &s->residual64_size, 
> 8*s->flac_stream_info.max_blocksize);
> +if (!s->residual64)
> +return AVERROR(ENOMEM);

Why not move this allocation to decode_residuals64() so that it is not
performed for ordinary files?

> +
>  ret = av_samples_fill_arrays((uint8_t **)s->decoded, NULL,
>   s->decoded_buffer,
>   s->flac_stream_info.channels,
> @@ -279,6 +285,66 @@ static int decode_residuals(FLACContext *s, int32_t 
> *decoded, int pred_order)
>  return 0;
>  }
>  
> +static int decode_residuals64(FLACContext *s, int64_t *decoded, int 
> pred_order)
> +{
> +GetBitContext gb = s->gb;
> +int i, tmp, partition, method_type, rice_order;
> +int rice_bits, rice_esc;
> +int samples;
> +
> +method_type = get_bits(&gb, 2);
> +rice_order  = get_bits(&gb, 4);
> +
> +samples   = s->blocksize >> rice_order;
> +rice_bits = 4 + method_type;
> +rice_esc  = (1 << rice_bits) - 1;
> +
> +decoded += pred_order;
> +i= pred_order;
> +
> +if (method_type > 1) {
> +av_log(s->avctx, AV_LOG_ERROR, "illegal residual coding method %d\n",
> +   method_type);
> +return AVERROR_INVALIDDATA;
> +}
> +
> +if (samples << rice_order != s->blocksize) {
> +av_log(s->avctx, AV_LOG_ERROR, "invalid rice order: %i blocksize 
> %i\n",
> +   rice_order, s->blocksize);
> +return AVERROR_INVALIDDATA;
> +}
> +
> +if (pred_order > samples) {
> +av_log(s->avctx, AV_LOG_ERROR, "invalid predictor order: %i > %i\n",
> +   pred_order, samples);
> +return AVERROR_INVALIDDATA;
> +}

Everything in this function up until this point coincides with
decode_residuals(). So shouldn't the check for whether the 64bit
codepath is used by put here? (Would it help for this check to know
rice_bits?)

> +
> +for (partition = 0; partition < (1 << rice_order); partition++) {
> +tmp = get_bits(&gb, rice_bits);
> +if (tmp == rice_esc) {
> +tmp = get_bits(&gb, 5);
> +for (; i < samples; i++)
> +*decoded++ = get_sbits_long(&gb, tmp);
> +} else {
> +for (; i < samples; i++) {
> +int64_t v = get_sr_golomb64_flac(&gb, tmp, 1);
> +if (v == INT64_MAX) {
> +av_log(s->avctx, AV_LOG_ERROR, "invalid residual\n");
> +return AVERROR_INVALIDDATA;
> +}
> +
> +*decoded++ = v;
> +}
> +}
> +i = 0;
> +}
> +
> +s->gb = gb;
> +
> +return 0;
> +}
> +
>  static int decode_subframe_fixed(FLACContext *s, int32_t *decoded,
>   int pred_order, int bps)
>  {
> @@ -358,6 +424,21 @@ static void lpc_analyze_remodulate(SUINT32 *decoded, 
> const int coeffs[32],
>  }
>  }
>  
> +static void lpc_residual64(int32_t *decoded, const int64_t *residual,
> +   const int coeffs[32], int pred_order,
> +   int qlevel, int len)
> +{
> +int i, j;

These lines could be avoided if you declared them in the for loop (i.e.
"for (int i = pred_o

Re: [FFmpeg-devel] [PATCH 2/2] avcodec/libsvtav1: clean up unconditional override of avctx bit rate

2022-03-30 Thread Jan Ekström
On Wed, Mar 30, 2022 at 5:21 AM James Almer  wrote:
>
> On 3/27/2022 3:02 PM, Jan Ekström wrote:
> > This value is only documented to be utilized if rate control is
> > set to one of the bit rate based modes. These modes are not the
> > default and thus the wrapper itself configures a bit rate according
> > to the avctx if bit rate based encoding is requested, making the
> > relevant value already be set when relevant.
>
> You can pass about anything with svtav1-params, which can change
> param->target_bit_rate. It's better to reflect that in the AVCodecContext.
>

Yea, of course then you need to put it under if
(param->rate_control_mode > 0) since the bit rate value by default is
not unset but 2mbps, and thus you need to only apply the value IFF bit
rate based rate control is utilized.

Since that is what removing this override was fixing, you would get a
bit rate value of 2mbps even though that was not utilized nor set by
anything (other than being the default).

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

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


Re: [FFmpeg-devel] [PATCH v9 1/1] avformat: Add IPFS protocol support.

2022-03-30 Thread Mark Gaiser
On Mon, Mar 28, 2022 at 7:00 PM Mark Gaiser  wrote:

> On Mon, Mar 28, 2022 at 6:44 PM Michael Niedermayer <
> mich...@niedermayer.cc> wrote:
>
>> On Mon, Mar 28, 2022 at 06:34:33PM +0200, Mark Gaiser wrote:
>> > On Mon, Mar 28, 2022 at 6:19 PM Michael Niedermayer <
>> mich...@niedermayer.cc>
>> > wrote:
>> >
>> > > On Fri, Mar 18, 2022 at 03:50:05PM +0100, Mark Gaiser wrote:
>> > > > This patch adds support for:
>> > > > - ffplay ipfs://
>> > > > - ffplay ipns://
>> > > >
>> > > > IPFS data can be played from so called "ipfs gateways".
>> > > > A gateway is essentially a webserver that gives access to the
>> > > > distributed IPFS network.
>> > > >
>> > > > This protocol support (ipfs and ipns) therefore translates
>> > > > ipfs:// and ipns:// to a http:// url. This resulting url is
>> > > > then handled by the http protocol. It could also be https
>> > > > depending on the gateway provided.
>> > > >
>> > > > To use this protocol, a gateway must be provided.
>> > > > If you do nothing it will try to find it in your
>> > > > $HOME/.ipfs/gateway file. The ways to set it manually are:
>> > > > 1. Define a -gateway  to the gateway.
>> > > > 2. Define $IPFS_GATEWAY with the full http link to the gateway.
>> > > > 3. Define $IPFS_PATH and point it to the IPFS data path.
>> > > > 4. Have IPFS running in your local user folder (under $HOME/.ipfs).
>> > > >
>> > > > Signed-off-by: Mark Gaiser 
>> > > > ---
>> > > >  configure |   2 +
>> > > >  doc/protocols.texi|  30 
>> > > >  libavformat/Makefile  |   2 +
>> > > >  libavformat/ipfsgateway.c | 310
>> ++
>> > > >  libavformat/protocols.c   |   2 +
>> > > >  5 files changed, 346 insertions(+)
>> > > >  create mode 100644 libavformat/ipfsgateway.c
>> > >
>> > > Theres some trailing whitespace which needs to be removed
>> > > our git scripts block trailing whitespace in most files
>> > >
>> > > [...]
>> > > > +static int ipfs_close(URLContext *h)
>> > > > +{
>> > > > +IPFSGatewayContext *c = h->priv_data;
>> > > > +av_free(c->gateway);
>> > >
>> > > this results in a double free
>> > >
>> >
>> > I believe one of the earlier feedback rounds told me to put it here.
>> > It's not free'd anywhere else.
>>
>> ==22837== Invalid free() / delete / delete[] / realloc()
>> ==22837==at 0x4C32D3B: free (in
>> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
>> ==22837==by 0x117FF88: av_opt_free (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x5C58CF: ffurl_closep (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x5C5AF2: ffurl_close (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x5CA206: avio_close (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x3021C0: ffmpeg_cleanup (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x2F5FA0: exit_program (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x2E34A1: main (in ffmpeg/ffmpeg_g)
>> ==22837==  Address 0x2ced8760 is 0 bytes inside a block of size 17 free'd
>> ==22837==at 0x4C32D3B: free (in
>> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
>> ==22837==by 0x7372BD: ipfs_close (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x5C588C: ffurl_closep (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x5C5AF2: ffurl_close (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x5CA206: avio_close (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x3021C0: ffmpeg_cleanup (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x2F5FA0: exit_program (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x2E34A1: main (in ffmpeg/ffmpeg_g)
>> ==22837==  Block was alloc'd at
>> ==22837==at 0x4C31A3F: malloc (in
>> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
>> ==22837==by 0x4C33D84: realloc (in
>> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
>> ==22837==by 0x117E120: av_strdup (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x1181DEF: av_opt_set (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x118272D: av_opt_set_dict2 (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x5C598C: ffurl_open_whitelist (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x5CA4DD: ffio_open_whitelist (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x6B88FB: io_open_default (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x5E0E9E: avformat_open_input (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x2EB32B: open_input_file (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x2EF00B: ffmpeg_parse_options (in ffmpeg/ffmpeg_g)
>> ==22837==by 0x2E3301: main (in ffmpeg/ffmpeg_g)
>>
>>
>> >
>> > Then again, in those earlier rounds I was manipulating c-gateway which
>> > right now isn't the case at all anymore.
>> >
>> > If all that's stopping it from merging is this single line, could you
>> > perhaps merge it and remove this line while at it?
>> > I'm kinda reluctant to make another patch and wait 1-2 weeks again...
>>
>> I do not know why its there or who asked for it to be put there.
>> I dont want to just remove something while merging that someone else
>> asked to be added
>>
>
> It's fine, you can remove it.
> I just checked with crypto.c (which I use as an example).
>
> d->gateway is an AVOption and is never changed in code.

Re: [FFmpeg-devel] [PATCH v4 1/2] lavc/vaapi_encode: add support for maxframesize

2022-03-30 Thread Wang, Fei W



> -Original Message-
> From: Xiang, Haihao 
> Sent: Tuesday, March 29, 2022 8:07 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Wang, Fei W ; linjie...@intel.com
> Subject: Re: [FFmpeg-devel] [PATCH v4 1/2] lavc/vaapi_encode: add support for
> maxframesize
> 
> On Tue, 2022-03-22 at 22:11 +0800, Fei Wang wrote:
> > From: Linjie Fu 
> >
> > Add support for max frame size:
> > - max_frame_size (bytes) to indicate the max allowed size for frame.
> >
> > If the frame size exceeds the limitation, encoder will to control the
> > frame size by adjusting QP value.
> > - MFS_NUM_PASSES to indicate number of passes for QP adjust.
> > - MFS_DELTA_QP to indicate adjust qp value per pass.
> >
> > To simplify the usage, default QP adjust is set to delta_qp[4] = {1, 1, 1, 
> > 1}.
> > Use new_qp for encoder if frame size exceeds the limitation:
> > new_qp = base_qp + delta_qp[0] + delta_qp[1] + ...
> >
> > ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -f rawvideo \
> > -v verbose -s:v 352x288 -i ./input.yuv -vf format=nv12,hwupload \
> > -c:v h264_vaapi -profile:v main -g 30 -bf 3 -max_frame_size 4 \
> > -vframes 100 -y ./max_frame_size.h264
> >
> > Max frame size was enabled since VA-API version (1, 3, 0), but query
> > is available since (1, 5, 0). It will be passed as a parameter in
> > picParam and should be set for each frame.
> >
> > Signed-off-by: Linjie Fu 
> > Signed-off-by: Fei Wang 
> > ---
> > 1. re-send the 2 legacy patch:
> >
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20190715105936.4860-1-
> linjie...@intel.com/
> >
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/2019071511.5069-1-
> linjie...@intel.com/
> >
> >  libavcodec/vaapi_encode.c | 67
> > +++
> >  libavcodec/vaapi_encode.h | 19 +--
> >  2 files changed, 84 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> > index ffd6cb1c25..b2782e6f9e 100644
> > --- a/libavcodec/vaapi_encode.c
> > +++ b/libavcodec/vaapi_encode.c
> > @@ -365,6 +365,17 @@ static int vaapi_encode_issue(AVCodecContext
> *avctx,
> >  goto fail;
> >  }
> >
> > +#if VA_CHECK_VERSION(1, 5, 0)
> > +if (ctx->max_frame_size) {
> > +err = vaapi_encode_make_misc_param_buffer(avctx, pic,
> > +
> > +VAEncMiscParameterTypeMultiPassFr
> > ameSize,
> > +&ctx->mfs_params,
> > +sizeof(ctx->mfs_params));
> > +if (err < 0)
> > +goto fail;
> > +}
> > +#endif
> > +
> >  if (pic->type == PICTURE_TYPE_IDR) {
> >  if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE &&
> >  ctx->codec->write_sequence_header) { @@ -1869,6 +1880,54
> > @@ rc_mode_found:
> >  return 0;
> >  }
> >
> > +static av_cold int vaapi_encode_init_max_frame_size(AVCodecContext
> > +*avctx) { #if VA_CHECK_VERSION(1, 5, 0)
> > +VAAPIEncodeContext  *ctx = avctx->priv_data;
> > +VAConfigAttrib  attr = { VAConfigAttribMaxFrameSize };
> > +VAStatus vas;
> > +int i;
> > +
> > +vas = vaGetConfigAttributes(ctx->hwctx->display,
> > +ctx->va_profile,
> > +ctx->va_entrypoint,
> > +&attr, 1);
> > +if (vas != VA_STATUS_SUCCESS) {
> > +ctx->max_frame_size = 0;
> > +av_log(avctx, AV_LOG_ERROR, "Failed to query max frame size "
> > +   "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
> > +return AVERROR_EXTERNAL;
> > +}
> > +
> > +if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
> > +ctx->max_frame_size = 0;
> > +av_log(avctx, AV_LOG_WARNING, "Max frame size attribute "
> > +   "is not supported.\n");
> > +} else {
> > +ctx->delta_qp = av_calloc(MFS_NUM_PASSES, sizeof(uint8_t));
> > +if (!ctx->delta_qp) {
> > +return AVERROR(ENOMEM);
> > +}
> > +for (i = 0; i  > +ctx->delta_qp[i] = MFS_DELTA_QP;
> > +
> > +ctx->mfs_params = (VAEncMiscParameterBufferMultiPassFrameSize){
> > +.max_frame_size = ctx->max_frame_size,
> > +.num_passes = MFS_NUM_PASSES,
> > +.delta_qp   = ctx->delta_qp,
> > +};
> > +
> > +av_log(avctx, AV_LOG_VERBOSE, "Max Frame Size: %d bytes.\n ",
> > +   ctx->max_frame_size);
> > +}
> > +#else
> > +av_log(avctx, AV_LOG_WARNING, "Max Frame Size is "
> > +"not supported with this VA
> > +version.\n"); #endif
> > +
> > +return 0;
> > +}
> > +
> >  static av_cold int vaapi_encode_init_gop_structure(AVCodecContext
> > *avctx)  {
> >  VAAPIEncodeContext *ctx = avctx->priv_data; @@ -2475,6 +2534,12
> > @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
> >  goto fail;
> >  }
> >
> > +