Re: [FFmpeg-devel] [PATCH v3] avformat/hls: Fixed incorrect behaviour of default

2024-07-16 Thread Steven Liu
Steven Liu  于2024年7月15日周一 21:47写道:
>
> CoderVenkat  于2024年7月15日周一 00:07写道:
> >
> > Apologies
> > Correct file attached in this 
> > mail.___
> I need more time look at the deep for and if logic.
Hi CoderVenkat,

+/* Check only one default audio stream is present in a group */
+for (i = 0; i < hls->nb_varstreams; i++) {
+vs = &(hls->var_streams[i]);
+if (vs->agroup && !vs->has_video) {
+for (j = 0; j < hls->nb_varstreams; j++) {
+if (i != j) {
+temp_vs = &(hls->var_streams[j]);
+if (temp_vs->agroup && !temp_vs->has_video) {
+if (!av_strcasecmp(vs->agroup, temp_vs->agroup) &&
+vs->is_default && temp_vs->is_default) {
+av_log(s, AV_LOG_ERROR, "Two streams in
an agroup can not be default\n");
+goto fail;
+}
+}
+}
+}
+}
+}

Can this logic modify as bellow?

int has_default = 0;
for (i = 0; i < hls->nb_varstreams; i++) {
vs = &(hls->var_streams[i]);
if (vs->is_default == 1)
has_default++;
if (vs->agroup && !vs->has_video && has_default > 1) {
av_log(s, AV_LOG_ERROR, "Two streams in an agroup can not be
default\n");
has_default = 0;
goto fail;
   }
}
has_default = 0;

Thanks
Steven
___
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] [RFC PATCH v2 0/1] avutil/error: Provide better feedback about unknown error codes

2024-07-16 Thread Andrew Sayers
I'm having trouble managing this conversation.  On one hand, you've brought up
several important details that would need to be included in a new patch.
On the other hand, I'm pretty sure we're talking past each other on the big
problems, and need to start over.  So let's fork the discussion.

# First, let's haggle over some details

The patch below fixes a number of small issues brought up by your comments...

Error numbers are always expressed in the code as either uppercase hex numbers
or FourCCs (or ThreeCCs, but you get the point).  This patch prints error codes
as hex, which is no less unintelligible for ordinary users, might make problems
easier to find on Google, and will sometimes make them easier to grep for.

Having said that, this patch prints non-negative numbers in decimal,
because all bets are off if that manages to happen.

A developer could create an error code that just happens to be valid ASCII.
In that situation, the previous patch would have printed something like
"Unrecognised error code \"~!X\"" occurred", which is worse than the current
behaviour.  This patch includes both (hex) number and name in those messages.

This patch adds "please report this bug" for all unknown error messages.
I'll cover the reasoning below, but the relevant detail is that the previous
patch just gave users a different heiroglyphic before abandoning them.

# Second, let's talk about the big picture

Consider the following scenario:

1. a new developer adds some code to FFmpeg that calls an existing function
2. it turns out that function sometimes calls another function that
   returns a variety of internal error codes (FFERROR_REDO among others)
3. their testing uncovers a situation that intermittently returns an unknown
   error number, but they don't notice there are two different numbers
4. they spend a lot of time tracking down an error message based on a random
   number, and eventually fix "the" bug (actually one of two intermittent bugs)
5. the review doesn't catch the other bug, and the new code goes live
6. a user trips over the other bug and sees "Error number  occurred"
7. the user wastes a lot of time trying to work out what they did wrong,
   badmouthing FFmpeg to anyone who will listen as they do
8. they eventually catch the attention of a developer
9. that developer spends a lot of time bisecting the bug
10. the new developer is expected to fix this patch, and feels like they're
to blame for the whole situation

An error message like "Unrecognised error code \"REDO\" occurred, please report
this bug" would give the newbie a fighting chance to catch both bugs at step 3,
would make step 4 much shorter, and would optimise steps 7-10 to almost nothing.

Catching this in a fate test would involve checking for an unknown function
returning an unknown number that gets reused in a context it's subtly
inappropriate for.  I have no idea where to begin with that, and anyway it
wouldn't help a developer in the process of tracking down an intermittent bug.

As mentioned above, the v2 patch adds "please report this bug" in a few places.
Any negative error code can be valid, but returning a raw error number is always
a bug, so it's all the same to users - if they see this message, they're not
expected to fix it themselves, they're expected to let us know.


___
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] [RFC PATCH v2] avutil/error: Provide better feedback about unknown error codes

2024-07-16 Thread Andrew Sayers
AVERROR messages should always be less than zero,
and are usually based on three or four ASCII characters.

For error codes that aren't explicitly handled by error.c (e.g. FFERROR_REDO),
print the ASCII code so the user has a little more information.

If a non-negative number somehow gets passed to this function,
print a message saying this shouldn't happen.
---
 libavutil/error.c | 36 +++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/libavutil/error.c b/libavutil/error.c
index 90bab7b9d3..9706578be6 100644
--- a/libavutil/error.c
+++ b/libavutil/error.c
@@ -119,6 +119,40 @@ int av_strerror(int errnum, char *errbuf, size_t 
errbuf_size)
 }
 if (entry) {
 av_strlcpy(errbuf, entry->str, errbuf_size);
+} else if (
+-errnum <= 0x
+&& ((-errnum >>  0) & 0xFF) >= 0x20 && ((-errnum >>  0) & 0xFF) <= 0x7F
+&& ((-errnum >>  8) & 0xFF) >= 0x20 && ((-errnum >>  8) & 0xFF) <= 0x7F
+&& ((-errnum >> 16) & 0xFF) >= 0x20 && ((-errnum >> 16) & 0xFF) <= 0x7F
+&& (
+   (((-errnum >> 24) & 0xFF) >= 0x20 && ((-errnum >> 24) & 0xFF) <= 
0x7F)
+   || !((-errnum >> 24) & 0xFF)
+)
+) {
+if ((-errnum >> 24) & 0xFF) {
+snprintf(
+errbuf,
+errbuf_size,
+"Error number -0x%x (\"%c%c%c%c\") occurred, please report 
this bug",
+-errnum,
+(-errnum >>  0) & 0xFF,
+(-errnum >>  8) & 0xFF,
+(-errnum >> 16) & 0xFF,
+(-errnum >> 24) & 0xFF
+);
+} else {
+snprintf(
+errbuf,
+errbuf_size,
+"Error number -0x%x (\"%c%c%c\") occurred, please report this 
bug",
+-errnum,
+(-errnum >>  0) & 0xFF,
+(-errnum >>  8) & 0xFF,
+(-errnum >> 16) & 0xFF
+);
+}
+} else if (errnum >= 0) {
+snprintf(errbuf, errbuf_size, "Impossible: non-negative error number 
%d occurred, please report this bug", errnum);
 } else {
 #if HAVE_STRERROR_R
 ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size));
@@ -126,7 +160,7 @@ int av_strerror(int errnum, char *errbuf, size_t 
errbuf_size)
 ret = -1;
 #endif
 if (ret < 0)
-snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
+snprintf(errbuf, errbuf_size, "Error number -0x%X occurred, please 
report this bug", -errnum);
 }
 
 return ret;
-- 
2.45.2

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

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


[FFmpeg-devel] [PATCH 5/5] fftools/ffprobe: implement dv_md_compression

2024-07-16 Thread Niklas Haas
From: Niklas Haas 

---
 fftools/ffprobe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 0b7d4ce0d7..265718467f 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2611,6 +2611,7 @@ static void print_pkt_side_data(WriterContext *w,
 print_int("el_present_flag", dovi->el_present_flag);
 print_int("bl_present_flag", dovi->bl_present_flag);
 print_int("dv_bl_signal_compatibility_id", 
dovi->dv_bl_signal_compatibility_id);
+print_int("dv_md_compression", dovi->dv_md_compression);
 } else if (sd->type == AV_PKT_DATA_AUDIO_SERVICE_TYPE) {
 enum AVAudioServiceType *t = (enum AVAudioServiceType *)sd->data;
 print_int("service_type", *t);
-- 
2.45.2

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

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


[FFmpeg-devel] [PATCH 4/5] avformat/dump: implement dv_md_compression

2024-07-16 Thread Niklas Haas
From: Niklas Haas 

---
 libavformat/dump.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/dump.c b/libavformat/dump.c
index 78b2481d90..5e1f367742 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -416,13 +416,15 @@ static void dump_dovi_conf(void *ctx, const 
AVPacketSideData *sd,
 (const AVDOVIDecoderConfigurationRecord *)sd->data;
 
 av_log(ctx, log_level, "version: %d.%d, profile: %d, level: %d, "
-   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d",
+   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d, "
+   "compression: %d",
dovi->dv_version_major, dovi->dv_version_minor,
dovi->dv_profile, dovi->dv_level,
dovi->rpu_present_flag,
dovi->el_present_flag,
dovi->bl_present_flag,
-   dovi->dv_bl_signal_compatibility_id);
+   dovi->dv_bl_signal_compatibility_id,
+   dovi->dv_md_compression);
 }
 
 static void dump_s12m_timecode(void *ctx, const AVStream *st, const 
AVPacketSideData *sd,
-- 
2.45.2

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

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


[FFmpeg-devel] [PATCH 3/5] avformat/mpegts: implement dv_md_compression

2024-07-16 Thread Niklas Haas
From: Niklas Haas 

---
 libavformat/mpegts.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index c66a1ea6ed..6b02187eb1 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2213,10 +2213,12 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 if (desc_end - *pp >= 1) {  // 8 bits
 buf = get8(pp, desc_end);
 dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 
bits
+dovi->dv_md_compression = (buf >> 2) & 0x03; // 2 bits
 } else {
 // 0 stands for None
 // Dolby Vision V1.2.93 profiles and levels
 dovi->dv_bl_signal_compatibility_id = 0;
+dovi->dv_md_compression = AV_DOVI_COMPRESSION_NONE;
 }
 
 if (!av_packet_side_data_add(&st->codecpar->coded_side_data,
@@ -2228,14 +2230,16 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
AVStream *st, int stream_type
 }
 
 av_log(fc, AV_LOG_TRACE, "DOVI, version: %d.%d, profile: %d, 
level: %d, "
-   "rpu flag: %d, el flag: %d, bl flag: %d, dependency_pid: 
%d, compatibility id: %d\n",
+   "rpu flag: %d, el flag: %d, bl flag: %d, dependency_pid: 
%d, "
+   "compatibility id: %d, compression: %d\n",
dovi->dv_version_major, dovi->dv_version_minor,
dovi->dv_profile, dovi->dv_level,
dovi->rpu_present_flag,
dovi->el_present_flag,
dovi->bl_present_flag,
dependency_pid,
-   dovi->dv_bl_signal_compatibility_id);
+   dovi->dv_bl_signal_compatibility_id,
+   dovi->dv_md_compression);
 }
 break;
 default:
-- 
2.45.2

___
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/5] avformat/dovi_isom: implement dv_md_compression

2024-07-16 Thread Niklas Haas
From: Niklas Haas 

---
 libavformat/dovi_isom.c | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/libavformat/dovi_isom.c b/libavformat/dovi_isom.c
index d49aa5a75f..269374cff9 100644
--- a/libavformat/dovi_isom.c
+++ b/libavformat/dovi_isom.c
@@ -57,11 +57,14 @@ int ff_isom_parse_dvcc_dvvc(void *logctx, AVStream *st,
 
 // Has enough remaining data
 if (size >= 5) {
-dovi->dv_bl_signal_compatibility_id = ((*buf_ptr++) >> 4) & 0x0f; // 4 
bits
+uint8_t buf = *buf_ptr++;
+dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 bits
+dovi->dv_md_compression = (buf >> 2) & 0x03; // 2 bits
 } else {
 // 0 stands for None
 // Dolby Vision V1.2.93 profiles and levels
 dovi->dv_bl_signal_compatibility_id = 0;
+dovi->dv_md_compression = AV_DOVI_COMPRESSION_NONE;
 }
 
 if (!av_packet_side_data_add(&st->codecpar->coded_side_data, 
&st->codecpar->nb_coded_side_data,
@@ -71,13 +74,14 @@ int ff_isom_parse_dvcc_dvvc(void *logctx, AVStream *st,
 }
 
 av_log(logctx, AV_LOG_TRACE, "DOVI in dvcC/dvvC/dvwC box, version: %d.%d, 
profile: %d, level: %d, "
-   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
+   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d, 
compression: %d\n",
dovi->dv_version_major, dovi->dv_version_minor,
dovi->dv_profile, dovi->dv_level,
dovi->rpu_present_flag,
dovi->el_present_flag,
dovi->bl_present_flag,
-   dovi->dv_bl_signal_compatibility_id);
+   dovi->dv_bl_signal_compatibility_id,
+   dovi->dv_md_compression);
 
 return 0;
 }
@@ -97,8 +101,9 @@ void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t 
out[ISOM_DVCC_DVVC_SIZE],
 put_bits(&pb, 1, !!dovi->el_present_flag);
 put_bits(&pb, 1, !!dovi->bl_present_flag);
 put_bits(&pb, 4, dovi->dv_bl_signal_compatibility_id & 0x0f);
+put_bits(&pb, 2, dovi->dv_md_compression & 0x03);
 
-put_bits(&pb, 28, 0); /* reserved */
+put_bits(&pb, 26, 0); /* reserved */
 put_bits32(&pb, 0); /* reserved */
 put_bits32(&pb, 0); /* reserved */
 put_bits32(&pb, 0); /* reserved */
@@ -108,12 +113,14 @@ void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t 
out[ISOM_DVCC_DVVC_SIZE],
 
 av_log(logctx, AV_LOG_DEBUG,
"DOVI in %s box, version: %d.%d, profile: %d, level: %d, "
-   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
+   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d, "
+   "compression: %d\n",
dovi->dv_profile > 10 ? "dvwC" : (dovi->dv_profile > 7 ? "dvvC" : 
"dvcC"),
dovi->dv_version_major, dovi->dv_version_minor,
dovi->dv_profile, dovi->dv_level,
dovi->rpu_present_flag,
dovi->el_present_flag,
dovi->bl_present_flag,
-   dovi->dv_bl_signal_compatibility_id);
+   dovi->dv_bl_signal_compatibility_id,
+   dovi->dv_md_compression);
 }
-- 
2.45.2

___
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/5] avutil/dovi_meta: add dv_md_compression to cfg record

2024-07-16 Thread Niklas Haas
From: Niklas Haas 

This field is used to signal the compression method in use.
---
 doc/APIchanges| 3 +++
 libavutil/dovi_meta.h | 9 +
 libavutil/version.h   | 2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 5751216b24..80ab3012c3 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-07-16 - xx - lavu 59.29.100 - dovi_meta.h
+  Add AVDOVIDecoderConfigurationRecord.dv_md_compression.
+
 2024-07-xx - xx - lavf 61 - avformat.h
   Deprecate avformat_transfer_internal_stream_timing_info()
   and av_stream_get_codec_timebase() without replacement.
diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
index e168075a24..c942d0e133 100644
--- a/libavutil/dovi_meta.h
+++ b/libavutil/dovi_meta.h
@@ -46,6 +46,7 @@
  * uint8_t  el_present_flag
  * uint8_t  bl_present_flag
  * uint8_t  dv_bl_signal_compatibility_id
+ * uint8_t  dv_md_compression, the compression method in use
  * @endcode
  *
  * @note The struct must be allocated with av_dovi_alloc() and
@@ -60,8 +61,16 @@ typedef struct AVDOVIDecoderConfigurationRecord {
 uint8_t el_present_flag;
 uint8_t bl_present_flag;
 uint8_t dv_bl_signal_compatibility_id;
+uint8_t dv_md_compression;
 } AVDOVIDecoderConfigurationRecord;
 
+enum AVDOVICompression {
+AV_DOVI_COMPRESSION_NONE = 0,
+AV_DOVI_COMPRESSION_LIMITED  = 1,
+AV_DOVI_COMPRESSION_RESERVED = 2,
+AV_DOVI_COMPRESSION_EXTENDED = 3,
+};
+
 /**
  * Allocate a AVDOVIDecoderConfigurationRecord structure and initialize its
  * fields to default values.
diff --git a/libavutil/version.h b/libavutil/version.h
index 814892a4d5..852eeef1d6 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR  28
+#define LIBAVUTIL_VERSION_MINOR  29
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.45.2

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

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


Re: [FFmpeg-devel] [PATCH 1/5] avutil/dovi_meta: add dv_md_compression to cfg record

2024-07-16 Thread Cosmin Stejerean via ffmpeg-devel


> On Jul 16, 2024, at 1:23 PM, Niklas Haas  wrote:
> 
> From: Niklas Haas 
> 
> This field is used to signal the compression method in use.
> ---
> doc/APIchanges| 3 +++
> libavutil/dovi_meta.h | 9 +
> libavutil/version.h   | 2 +-
> 3 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 5751216b24..80ab3012c3 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07
> 
> API changes, most recent first:
> 
> +2024-07-16 - xx - lavu 59.29.100 - dovi_meta.h
> +  Add AVDOVIDecoderConfigurationRecord.dv_md_compression.
> +
> 2024-07-xx - xx - lavf 61 - avformat.h
>   Deprecate avformat_transfer_internal_stream_timing_info()
>   and av_stream_get_codec_timebase() without replacement.
> diff --git a/libavutil/dovi_meta.h b/libavutil/dovi_meta.h
> index e168075a24..c942d0e133 100644
> --- a/libavutil/dovi_meta.h
> +++ b/libavutil/dovi_meta.h
> @@ -46,6 +46,7 @@
>  * uint8_t  el_present_flag
>  * uint8_t  bl_present_flag
>  * uint8_t  dv_bl_signal_compatibility_id
> + * uint8_t  dv_md_compression, the compression method in use
>  * @endcode
>  *
>  * @note The struct must be allocated with av_dovi_alloc() and
> @@ -60,8 +61,16 @@ typedef struct AVDOVIDecoderConfigurationRecord {
> uint8_t el_present_flag;
> uint8_t bl_present_flag;
> uint8_t dv_bl_signal_compatibility_id;
> +uint8_t dv_md_compression;
> } AVDOVIDecoderConfigurationRecord;
> 
> +enum AVDOVICompression {
> +AV_DOVI_COMPRESSION_NONE = 0,
> +AV_DOVI_COMPRESSION_LIMITED  = 1,
> +AV_DOVI_COMPRESSION_RESERVED = 2,
> +AV_DOVI_COMPRESSION_EXTENDED = 3,
> +};
> +
> 

Looks good to me.

- Cosmin


___
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 5/5] fftools/ffprobe: implement dv_md_compression

2024-07-16 Thread Cosmin Stejerean via ffmpeg-devel


> On Jul 16, 2024, at 1:23 PM, Niklas Haas  wrote:
> 
> From: Niklas Haas 
> 
> ---
> fftools/ffprobe.c | 1 +
> 1 file changed, 1 insertion(+)
> 
> diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
> index 0b7d4ce0d7..265718467f 100644
> --- a/fftools/ffprobe.c
> +++ b/fftools/ffprobe.c
> @@ -2611,6 +2611,7 @@ static void print_pkt_side_data(WriterContext *w,
> print_int("el_present_flag", dovi->el_present_flag);
> print_int("bl_present_flag", dovi->bl_present_flag);
> print_int("dv_bl_signal_compatibility_id", 
> dovi->dv_bl_signal_compatibility_id);
> +print_int("dv_md_compression", dovi->dv_md_compression);
> } else if (sd->type == AV_PKT_DATA_AUDIO_SERVICE_TYPE) {
> enum AVAudioServiceType *t = (enum AVAudioServiceType *)sd->data;
> print_int("service_type", *t);
> -- 
> 2.45.2
> 
> 

LGTM


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

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


Re: [FFmpeg-devel] [PATCH 2/5] avformat/dovi_isom: implement dv_md_compression

2024-07-16 Thread Cosmin Stejerean via ffmpeg-devel


> On Jul 16, 2024, at 1:23 PM, Niklas Haas  wrote:
> 
> From: Niklas Haas 
> 
> ---
> libavformat/dovi_isom.c | 19 +--
> 1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/dovi_isom.c b/libavformat/dovi_isom.c
> index d49aa5a75f..269374cff9 100644
> --- a/libavformat/dovi_isom.c
> +++ b/libavformat/dovi_isom.c
> @@ -57,11 +57,14 @@ int ff_isom_parse_dvcc_dvvc(void *logctx, AVStream *st,
> 
> // Has enough remaining data
> if (size >= 5) {
> -dovi->dv_bl_signal_compatibility_id = ((*buf_ptr++) >> 4) & 0x0f; // 
> 4 bits
> +uint8_t buf = *buf_ptr++;
> +dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 bits
> +dovi->dv_md_compression = (buf >> 2) & 0x03; // 2 bits

This seems fine based on what this code is currently doing, but I'm curious, 
should this be moved to something like get_bits at some point?

> } else {
> // 0 stands for None
> // Dolby Vision V1.2.93 profiles and levels
> dovi->dv_bl_signal_compatibility_id = 0;
> +dovi->dv_md_compression = AV_DOVI_COMPRESSION_NONE;
> }
> 
> if (!av_packet_side_data_add(&st->codecpar->coded_side_data, 
> &st->codecpar->nb_coded_side_data,
> @@ -71,13 +74,14 @@ int ff_isom_parse_dvcc_dvvc(void *logctx, AVStream *st,
> }
> 
> av_log(logctx, AV_LOG_TRACE, "DOVI in dvcC/dvvC/dvwC box, version: %d.%d, 
> profile: %d, level: %d, "
> -   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
> +   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d, 
> compression: %d\n",
>dovi->dv_version_major, dovi->dv_version_minor,
>dovi->dv_profile, dovi->dv_level,
>dovi->rpu_present_flag,
>dovi->el_present_flag,
>dovi->bl_present_flag,
> -   dovi->dv_bl_signal_compatibility_id);
> +   dovi->dv_bl_signal_compatibility_id,
> +   dovi->dv_md_compression);
> 
> return 0;
> }
> @@ -97,8 +101,9 @@ void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t 
> out[ISOM_DVCC_DVVC_SIZE],
> put_bits(&pb, 1, !!dovi->el_present_flag);
> put_bits(&pb, 1, !!dovi->bl_present_flag);
> put_bits(&pb, 4, dovi->dv_bl_signal_compatibility_id & 0x0f);
> +put_bits(&pb, 2, dovi->dv_md_compression & 0x03);
> 
> -put_bits(&pb, 28, 0); /* reserved */
> +put_bits(&pb, 26, 0); /* reserved */
> put_bits32(&pb, 0); /* reserved */
> put_bits32(&pb, 0); /* reserved */
> put_bits32(&pb, 0); /* reserved */
> @@ -108,12 +113,14 @@ void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t 
> out[ISOM_DVCC_DVVC_SIZE],
> 
> av_log(logctx, AV_LOG_DEBUG,
>"DOVI in %s box, version: %d.%d, profile: %d, level: %d, "
> -   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
> +   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d, "
> +   "compression: %d\n",

would it be more user friendly to log the display value like limited, none, 
extended rather than numeric value here?

>dovi->dv_profile > 10 ? "dvwC" : (dovi->dv_profile > 7 ? "dvvC" : 
> "dvcC"),
>dovi->dv_version_major, dovi->dv_version_minor,
>dovi->dv_profile, dovi->dv_level,
>dovi->rpu_present_flag,
>dovi->el_present_flag,
>dovi->bl_present_flag,
> -   dovi->dv_bl_signal_compatibility_id);
> +   dovi->dv_bl_signal_compatibility_id,
> +   dovi->dv_md_compression);
> }
> -- 
> 

Overall LGTM.

- Cosmin


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

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


Re: [FFmpeg-devel] [PATCH 3/5] avformat/mpegts: implement dv_md_compression

2024-07-16 Thread Cosmin Stejerean via ffmpeg-devel


> On Jul 16, 2024, at 1:23 PM, Niklas Haas  wrote:
> 
> From: Niklas Haas 
> 
> ---
> libavformat/mpegts.c | 8 ++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index c66a1ea6ed..6b02187eb1 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -2213,10 +2213,12 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
> AVStream *st, int stream_type
> if (desc_end - *pp >= 1) {  // 8 bits
> buf = get8(pp, desc_end);
> dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 
> bits
> +dovi->dv_md_compression = (buf >> 2) & 0x03; // 2 bits
> } else {
> // 0 stands for None
> // Dolby Vision V1.2.93 profiles and levels
> dovi->dv_bl_signal_compatibility_id = 0;
> +dovi->dv_md_compression = AV_DOVI_COMPRESSION_NONE;
> }
> 
> if (!av_packet_side_data_add(&st->codecpar->coded_side_data,
> @@ -2228,14 +2230,16 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, 
> AVStream *st, int stream_type
> }
> 
> av_log(fc, AV_LOG_TRACE, "DOVI, version: %d.%d, profile: %d, 
> level: %d, "
> -   "rpu flag: %d, el flag: %d, bl flag: %d, dependency_pid: 
> %d, compatibility id: %d\n",
> +   "rpu flag: %d, el flag: %d, bl flag: %d, dependency_pid: 
> %d, "
> +   "compatibility id: %d, compression: %d\n",
>dovi->dv_version_major, dovi->dv_version_minor,
>dovi->dv_profile, dovi->dv_level,
>dovi->rpu_present_flag,
>dovi->el_present_flag,
>dovi->bl_present_flag,
>dependency_pid,
> -   dovi->dv_bl_signal_compatibility_id);
> +   dovi->dv_bl_signal_compatibility_id,
> +   dovi->dv_md_compression);
> }
> break;
> default:
> 

LGTM, although like the previous patch I'm curious if the logging should be 
using display names instead of integer values for compression.

- Cosmin


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

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


Re: [FFmpeg-devel] [PATCH 4/5] avformat/dump: implement dv_md_compression

2024-07-16 Thread Cosmin Stejerean via ffmpeg-devel


> On Jul 16, 2024, at 1:23 PM, Niklas Haas  wrote:
> 
> From: Niklas Haas 
> 
> ---
> libavformat/dump.c | 6 --
> 1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/dump.c b/libavformat/dump.c
> index 78b2481d90..5e1f367742 100644
> --- a/libavformat/dump.c
> +++ b/libavformat/dump.c
> @@ -416,13 +416,15 @@ static void dump_dovi_conf(void *ctx, const 
> AVPacketSideData *sd,
> (const AVDOVIDecoderConfigurationRecord *)sd->data;
> 
> av_log(ctx, log_level, "version: %d.%d, profile: %d, level: %d, "
> -   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d",
> +   "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d, "
> +   "compression: %d",
>dovi->dv_version_major, dovi->dv_version_minor,
>dovi->dv_profile, dovi->dv_level,
>dovi->rpu_present_flag,
>dovi->el_present_flag,
>dovi->bl_present_flag,
> -   dovi->dv_bl_signal_compatibility_id);
> +   dovi->dv_bl_signal_compatibility_id,
> +   dovi->dv_md_compression);
> }
> 
> static void dump_s12m_timecode(void *ctx, const AVStream *st, const 
> AVPacketSideData *sd,
> 

LGTM

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

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


Re: [FFmpeg-devel] [PATCH] avutil/hwcontext_videotoolbox: Fix build with older SDKs

2024-07-16 Thread Zhao Zhili



> On Jul 9, 2024, at 22:46, Marvin Scholz  wrote:
> 
> I've accidentally used API not available on the checked version.
> Additionally check for the SDK to be new enough to even have the
> CVImageBufferCreateColorSpaceFromAttachments API to not fail
> the build.
> ---
> libavutil/hwcontext_videotoolbox.c | 15 ++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/hwcontext_videotoolbox.c 
> b/libavutil/hwcontext_videotoolbox.c
> index 953155ce32..ab7556936d 100644
> --- a/libavutil/hwcontext_videotoolbox.c
> +++ b/libavutil/hwcontext_videotoolbox.c
> @@ -588,13 +588,26 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
> } else
> CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey);
> 
> +#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100800) || \
> +(TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 10)
> if (__builtin_available(macOS 10.8, iOS 10, *)) {
> -CFDictionaryRef attachments = CVBufferCopyAttachments(pixbuf, 
> kCVAttachmentMode_ShouldPropagate);
> +CFDictionaryRef attachments = NULL;
> +if (__builtin_available(macOS 12.0, iOS 15.0, *))
> +attachments = CVBufferCopyAttachments(pixbuf, 
> kCVAttachmentMode_ShouldPropagate);
> +#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED <= 12) || \
> +(TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED <= 15)
> +else {
> +CFDictionaryRef tmp = CVBufferGetAttachments(pixbuf, 
> kCVAttachmentMode_ShouldPropagate);
> +if (tmp)
> +attachments = CFDictionaryCreateCopy(NULL, tmp);
> +}
> +#endif
> if (attachments) {
> colorspace = 
> CVImageBufferCreateColorSpaceFromAttachments(attachments);
> CFRelease(attachments);
> }
> }
> +#endif
> 
> if (colorspace) {
> CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey,

Rebase and applied, thanks.

> 
> base-commit: 9fb8d13d56f20728141fd7070d8a325720727d57
> -- 
> 2.39.3 (Apple Git-146)
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

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


Re: [FFmpeg-devel] [OSS-Fuzz] Have you considered enabling memory sanitizer?

2024-07-16 Thread Michael Niedermayer
On Mon, Jul 15, 2024 at 01:32:20PM +0200, Kacper Michajlow wrote:
> On Sun, 14 Jul 2024 at 21:55, Michael Niedermayer
>  wrote:
> >
> > On Sat, Jul 13, 2024 at 11:12:40PM +0200, Kacper Michajlow wrote:
> > > On Thu, 27 Jun 2024 at 02:50, Kacper Michajlow  wrote:
> > > >
> > > > On Thu, 27 Jun 2024 at 00:45, Michael Niedermayer
> > > >  wrote:
> > > > >
> > > > > On Wed, Jun 26, 2024 at 09:07:42PM +0200, Kacper Michajlow wrote:
> > > > > > Hi,
> > > > > >
> > > > > > Like in the topic. I think it would be useful to enable MSAN on
> > > > > > OSS-Fuzz. We get some tiny issues and it would be probably good to
> > > > > > have them tracked upstream. All infra is here, so enabling it is as
> > > > > > simple as adding it to the project.yaml. Except libbz2.so and 
> > > > > > libz.so
> > > > > > would have to be built inline instead, looking at the build.sh, they
> > > > > > are prebuilt. The rest should just work (TM), but needs to be 
> > > > > > tested.
> > > > > > You can set an "experimental' flag to have it not create issues on
> > > > > > monorail, initially.
> > > > >
> > > > > I assumed ossfuzz would enable all sanitizers by default
> > > >
> > > > They do not do that by default, because MSAN requires all dependencies
> > > > to be instrumented too. See
> > > > https://google.github.io/oss-fuzz/getting-started/new-project-guide/#sanitizers
> > > >
> > > > Looking at build.sh for ffmpeg, it should be fine to enable it.
> > > > Obviously I have not tested everything, but I was running some tests
> > > > locally with MSAN and also tested it with mpv oss-fuzz builds where we
> > > > build ffmpeg too with MSAN.
> > > >
> > > > - Kacper
> > >
> > > I've sent a PR to enable MSAN and a few other build improvements.
> > > Please take a look https://github.com/google/oss-fuzz/pull/12211
> > >
> >
> > > Also, would it be ok to add myself to auto_ccs for ffmpeg? Mostly to
> > > monitor what issues are reported upstream, as we get some reports in
> > > mpv fuzzing and I never know if I should report it upstream (ffmpeg)
> > > or it is already found by first-party fuzzing and I shouldn't make
> > > more noise.
> >
> > you are welcome to submit bug reports, you are welcome to submit bug fixes
> > if you find issues in FFmpeg.
> >
> > If someones work in FFmpeg or rather FFmpeg benefits from someone having
> > access to the reports, then (s)he should receive access. This seems not
> > to apply here
> 
> I respect your decision.

> However, saying that anyone's (or my)
> contribution doesn't benefit FFmpeg is a strange thing to say for an
> open source project maintainer.

And noone made such a statement. You are reading something thats not written
there


> 
> It's all about time. I don't get paid to do any of this, so
> duplicating issues/reports manually from one system to another, if
> they are already reported, is a monkey's job which I'm not willing to
> do.

ok
for reference i find no mail from you to ffmpeg-security
Is it correct you never reported any of the issues you talk about
neither new nor duplciate ?


> This time could be devoted to actually fixing the issues. I'd like
> to help, but if it is not required, I will focus on other things.

This is the first time i remember you offering to help.
Your request previosuly:

> > > Mostly to
> > > monitor what issues are reported upstream, as we get some reports in
> > > mpv fuzzing and I never know if I should report it upstream (ffmpeg)
> > > or it is already found by first-party fuzzing and I shouldn't make
> > > more noise.

And to that my reply was a "no", iam not agreeing to give access to
someone who wants to mainly monitor upstream.

Also again id like to point out we do not have an issue with duplicate
reports ATM, so we would be fixing something that has not actually happened

Also if i fix an issue i post the corresponding patch to ffmpeg-devel
so the case you write about makes just no sense
if no patch is posted the issue is not fixed and any fix you would submit
would not be duplicated


> 
> It also doesn't help that trac.ffmpeg is a black hole, where only
> Balling seems to be reading those tickets. Frankly, the review process
> is not better, as even trivial fixes take months to merge.

Yes, we do need to improve this. Directing some funds to people
who did maintain trac in the past would solve this.
Let me speak blunt and clear here. I think carl should be paid to
maintain trac.
And the maintaince should switch to a system more similar to linux
its more scalable


> 
> > Also i expect the number of outstanding ossfuzz issues to decrease now
> > after the bulk of coverity issues has been dealt with
> 
> For some class of issues sure, but Coverity bigfixes are most of the
> time workarounding the static analysis limitations. Fuzzing is more
> powerful and analyzes the code as a whole, not small snippets of it.

You misunderstand.
I was doing most ossfuzz fixes, and recently i was switching between a month 
working
"fulltime" on coverity and then a

Re: [FFmpeg-devel] [OSS-Fuzz] Have you considered enabling memory sanitizer?

2024-07-16 Thread Michael Niedermayer
On Mon, Jul 15, 2024 at 02:36:15PM +0200, Vittorio Giovara wrote:
> On Sun, Jul 14, 2024 at 9:55 PM Michael Niedermayer 
> wrote:
> 
> > On Sat, Jul 13, 2024 at 11:12:40PM +0200, Kacper Michajlow wrote:
> > > On Thu, 27 Jun 2024 at 02:50, Kacper Michajlow 
> > wrote:
> > > >
> > > > On Thu, 27 Jun 2024 at 00:45, Michael Niedermayer
> > > >  wrote:
> > > > >
> > > > > On Wed, Jun 26, 2024 at 09:07:42PM +0200, Kacper Michajlow wrote:
> > > > > > Hi,
> > > > > >
> > > > > > Like in the topic. I think it would be useful to enable MSAN on
> > > > > > OSS-Fuzz. We get some tiny issues and it would be probably good to
> > > > > > have them tracked upstream. All infra is here, so enabling it is as
> > > > > > simple as adding it to the project.yaml. Except libbz2.so and
> > libz.so
> > > > > > would have to be built inline instead, looking at the build.sh,
> > they
> > > > > > are prebuilt. The rest should just work (TM), but needs to be
> > tested.
> > > > > > You can set an "experimental' flag to have it not create issues on
> > > > > > monorail, initially.
> > > > >
> > > > > I assumed ossfuzz would enable all sanitizers by default
> > > >
> > > > They do not do that by default, because MSAN requires all dependencies
> > > > to be instrumented too. See
> > > >
> > https://google.github.io/oss-fuzz/getting-started/new-project-guide/#sanitizers
> > > >
> > > > Looking at build.sh for ffmpeg, it should be fine to enable it.
> > > > Obviously I have not tested everything, but I was running some tests
> > > > locally with MSAN and also tested it with mpv oss-fuzz builds where we
> > > > build ffmpeg too with MSAN.
> > > >
> > > > - Kacper
> > >
> > > I've sent a PR to enable MSAN and a few other build improvements.
> > > Please take a look https://github.com/google/oss-fuzz/pull/12211
> > >
> >
> > > Also, would it be ok to add myself to auto_ccs for ffmpeg? Mostly to
> > > monitor what issues are reported upstream, as we get some reports in
> > > mpv fuzzing and I never know if I should report it upstream (ffmpeg)
> > > or it is already found by first-party fuzzing and I shouldn't make
> > > more noise.
> >
> > you are welcome to submit bug reports, you are welcome to submit bug fixes
> > if you find issues in FFmpeg.
> >
> > If someones work in FFmpeg or rather FFmpeg benefits from someone having
> > access to the reports, then (s)he should receive access. This seems not
> > to apply here
> >
> 
> Disagree - this is not the right way to attract new contributors.

no ?
did you do a study ?

try this:
A. "please we need more maintainers" (we tried this i think)
B. gently push someone away
(now people are angry, they want their rights, their access, they want to
 contribute ...)
;)


> 
> Also i expect the number of outstanding ossfuzz issues to decrease now
> > after the bulk of coverity issues has been dealt with
> >
> 
> The majority of coverity issues are false positives, I fail to see the
> relationship here.

I do both coverity and ossfuzz work, and while i have done significantly more
in the last months than i did last year, i still have falling a bit behind with
ossfuzz fixing.

thx

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

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact


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

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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/vvc: Remove NOP condition check in alf_filter_luma

2024-07-16 Thread Nuo Mi
On Tue, Jul 16, 2024 at 10:50 AM Zhao Zhili  wrote:

> From: Zhao Zhili 
>
> If (y + i == vb_above) or (y + i == vb_below), the if body has no
> operation.
>
👍, How did you find this? From a compiler warning or by reading the code?


> ---
>  libavcodec/vvc/filter_template.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/vvc/filter_template.c
> b/libavcodec/vvc/filter_template.c
> index 9b3a0e46f7..32777452b7 100644
> --- a/libavcodec/vvc/filter_template.c
> +++ b/libavcodec/vvc/filter_template.c
> @@ -77,7 +77,7 @@ static void FUNC(alf_filter_luma)(uint8_t *_dst,
> ptrdiff_t dst_stride, const uin
>  const int is_near_vb_below = (y + i >= vb_pos) && (y + i
> <= vb_pos);
>  const int is_near_vb = is_near_vb_above ||
> is_near_vb_below;
>
> -if ((y + i < vb_pos) && ((y + i) >= vb_above)) {
> +if ((y + i < vb_pos) && ((y + i) > vb_above)) {
>  p1 = (y + i == vb_pos - 1) ? p0 : p1;
>  p3 = (y + i >= vb_pos - 2) ? p1 : p3;
>  p5 = (y + i >= vb_pos - 3) ? p3 : p5;
> @@ -85,7 +85,7 @@ static void FUNC(alf_filter_luma)(uint8_t *_dst,
> ptrdiff_t dst_stride, const uin
>  p2 = (y + i == vb_pos - 1) ? p0 : p2;
>  p4 = (y + i >= vb_pos - 2) ? p2 : p4;
>  p6 = (y + i >= vb_pos - 3) ? p4 : p6;
> -} else if ((y + i >= vb_pos) && ((y + i) <= vb_below)) {
> +} else if ((y + i >= vb_pos) && ((y + i) < vb_below)) {
>  p2 = (y + i == vb_pos) ? p0 : p2;
>  p4 = (y + i <= vb_pos + 1) ? p2 : p4;
>  p6 = (y + i <= vb_pos + 2) ? p4 : p6;
> --
> 2.42.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 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/vvc: Add aarch64 neon optimization for ALF

2024-07-16 Thread Nuo Mi
Hi Zhili,
Good job. Appreciate it.
With this patch, we're very close to smooth 4K@30 playback on my M2.

On Tue, Jul 16, 2024 at 12:19 AM Zhao Zhili  wrote:

> From: Zhao Zhili 
>
> vvc_alf_filter_chroma_4x4_8_c: 3.0
> vvc_alf_filter_chroma_4x4_8_neon: 1.0
> vvc_alf_filter_chroma_4x4_10_c: 2.7
> vvc_alf_filter_chroma_4x4_10_neon: 1.0
> vvc_alf_filter_chroma_4x4_12_c: 2.7
> vvc_alf_filter_chroma_4x4_12_neon: 1.0
> vvc_alf_filter_chroma_8x8_8_c: 10.2
> vvc_alf_filter_chroma_8x8_8_neon: 3.0
> vvc_alf_filter_chroma_8x8_10_c: 10.0
> vvc_alf_filter_chroma_8x8_10_neon: 2.5
> vvc_alf_filter_chroma_8x8_12_c: 10.0
> vvc_alf_filter_chroma_8x8_12_neon: 2.5
> vvc_alf_filter_chroma_16x16_8_c: 41.7
> vvc_alf_filter_chroma_16x16_8_neon: 11.2
> vvc_alf_filter_chroma_16x16_10_c: 39.0
> vvc_alf_filter_chroma_16x16_10_neon: 10.0
> vvc_alf_filter_chroma_16x16_12_c: 40.2
> vvc_alf_filter_chroma_16x16_12_neon: 10.2
> vvc_alf_filter_chroma_32x32_8_c: 162.0
> vvc_alf_filter_chroma_32x32_8_neon: 45.0
> vvc_alf_filter_chroma_32x32_10_c: 155.5
> vvc_alf_filter_chroma_32x32_10_neon: 39.5
> vvc_alf_filter_chroma_32x32_12_c: 155.5
> vvc_alf_filter_chroma_32x32_12_neon: 40.0
> vvc_alf_filter_chroma_64x64_8_c: 646.0
> vvc_alf_filter_chroma_64x64_8_neon: 175.5
> vvc_alf_filter_chroma_64x64_10_c: 708.2
> vvc_alf_filter_chroma_64x64_10_neon: 166.7
> vvc_alf_filter_chroma_64x64_12_c: 619.2
> vvc_alf_filter_chroma_64x64_12_neon: 157.2
> vvc_alf_filter_chroma_128x128_8_c: 2611.5
> vvc_alf_filter_chroma_128x128_8_neon: 698.2
> vvc_alf_filter_chroma_128x128_10_c: 2470.0
> vvc_alf_filter_chroma_128x128_10_neon: 616.0
> vvc_alf_filter_chroma_128x128_12_c: 2531.5
> vvc_alf_filter_chroma_128x128_12_neon: 620.2
> vvc_alf_filter_luma_8x8_8_c: 25.2
> vvc_alf_filter_luma_8x8_8_neon: 4.2
> vvc_alf_filter_luma_8x8_10_c: 18.5
> vvc_alf_filter_luma_8x8_10_neon: 4.0
> vvc_alf_filter_luma_8x8_12_c: 19.0
> vvc_alf_filter_luma_8x8_12_neon: 4.0
> vvc_alf_filter_luma_16x16_8_c: 106.5
> vvc_alf_filter_luma_16x16_8_neon: 16.2
> vvc_alf_filter_luma_16x16_10_c: 75.2
> vvc_alf_filter_luma_16x16_10_neon: 14.7
> vvc_alf_filter_luma_16x16_12_c: 79.7
> vvc_alf_filter_luma_16x16_12_neon: 14.7
> vvc_alf_filter_luma_32x32_8_c: 400.5
> vvc_alf_filter_luma_32x32_8_neon: 63.2
> vvc_alf_filter_luma_32x32_10_c: 299.2
> vvc_alf_filter_luma_32x32_10_neon: 57.7
> vvc_alf_filter_luma_32x32_12_c: 299.2
> vvc_alf_filter_luma_32x32_12_neon: 57.7
> vvc_alf_filter_luma_64x64_8_c: 1602.5
> vvc_alf_filter_luma_64x64_8_neon: 251.7
> vvc_alf_filter_luma_64x64_10_c: 1197.0
> vvc_alf_filter_luma_64x64_10_neon: 235.5
> vvc_alf_filter_luma_64x64_12_c: 1220.2
> vvc_alf_filter_luma_64x64_12_neon: 235.7
> vvc_alf_filter_luma_128x128_8_c: 6570.2
> vvc_alf_filter_luma_128x128_8_neon: 1007.7
> vvc_alf_filter_luma_128x128_10_c: 4822.7
> vvc_alf_filter_luma_128x128_10_neon: 936.2
> vvc_alf_filter_luma_128x128_12_c: 4791.2
> vvc_alf_filter_luma_128x128_12_neon: 938.5
>
> Signed-off-by: Zhao Zhili 
> ---
>  libavcodec/aarch64/vvc/Makefile   |   5 +
>  libavcodec/aarch64/vvc/alf.S  | 293 ++
>  libavcodec/aarch64/vvc/alf_template.c | 157 ++
>  libavcodec/aarch64/vvc/dsp_init.c |  57 +
>  libavcodec/vvc/dsp.c  |   4 +-
>  libavcodec/vvc/dsp.h  |   1 +
>  6 files changed, 516 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/aarch64/vvc/Makefile
>  create mode 100644 libavcodec/aarch64/vvc/alf.S
>  create mode 100644 libavcodec/aarch64/vvc/alf_template.c
>  create mode 100644 libavcodec/aarch64/vvc/dsp_init.c
>
> diff --git a/libavcodec/aarch64/vvc/Makefile
> b/libavcodec/aarch64/vvc/Makefile
> new file mode 100644
> index 00..58398d6e3d
> --- /dev/null
> +++ b/libavcodec/aarch64/vvc/Makefile
> @@ -0,0 +1,5 @@
> +clean::
> +   $(RM) $(CLEANSUFFIXES:%=libavcodec/aarch64/vvc/%)
> +
> +OBJS-$(CONFIG_VVC_DECODER) +=
> aarch64/vvc/dsp_init.o
> +NEON-OBJS-$(CONFIG_VVC_DECODER)+=
> aarch64/vvc/alf.o
> diff --git a/libavcodec/aarch64/vvc/alf.S b/libavcodec/aarch64/vvc/alf.S
> new file mode 100644
> index 00..beb36ac66b
> --- /dev/null
> +++ b/libavcodec/aarch64/vvc/alf.S
> @@ -0,0 +1,293 @@
> +/*
> + * Copyright (c) 2024 Zhao Zhili 
> + *
> + * 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
> + * F

[FFmpeg-devel] [PATCH 1/2] avcodec/videotoolboxenc: Fix bitrate doesn't work as expected

2024-07-16 Thread Zhao Zhili
From: Zhao Zhili 

Commit 4ef5e7d4722 add qmin/qmax support to videotoolbox encoder.
The default value of (qmin, qmax) is (2, 31), which makes bitrate
control doesn't work as users' expectations.
---
 libavcodec/videotoolboxenc.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index ce80b8e745..35628341f6 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -2932,6 +2932,12 @@ static const AVOption h264_options[] = {
 { NULL },
 };
 
+static const FFCodecDefault vt_defaults[] = {
+{"qmin", "-1"},
+{"qmax", "-1"},
+{NULL},
+};
+
 static const AVClass h264_videotoolbox_class = {
 .class_name = "h264_videotoolbox",
 .item_name  = av_default_item_name,
@@ -2947,6 +2953,7 @@ const FFCodec ff_h264_videotoolbox_encoder = {
 .p.capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
 .priv_data_size   = sizeof(VTEncContext),
 .p.pix_fmts   = avc_pix_fmts,
+.defaults = vt_defaults,
 .init = vtenc_init,
 FF_CODEC_ENCODE_CB(vtenc_frame),
 .close= vtenc_close,
@@ -2984,6 +2991,7 @@ const FFCodec ff_hevc_videotoolbox_encoder = {
 AV_CODEC_CAP_HARDWARE,
 .priv_data_size   = sizeof(VTEncContext),
 .p.pix_fmts   = hevc_pix_fmts,
+.defaults = vt_defaults,
 .init = vtenc_init,
 FF_CODEC_ENCODE_CB(vtenc_frame),
 .close= vtenc_close,
@@ -3023,6 +3031,7 @@ const FFCodec ff_prores_videotoolbox_encoder = {
 AV_CODEC_CAP_HARDWARE,
 .priv_data_size   = sizeof(VTEncContext),
 .p.pix_fmts   = prores_pix_fmts,
+.defaults = vt_defaults,
 .init = vtenc_init,
 FF_CODEC_ENCODE_CB(vtenc_frame),
 .close= vtenc_close,
-- 
2.42.0

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

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


[FFmpeg-devel] [PATCH 2/2] avcodec/videotoolboxenc: Set default bitrate to zero

2024-07-16 Thread Zhao Zhili
From: Zhao Zhili 

Zero is auto mode. From the doc of videotoolbox:

   The default bit rate is zero, which indicates that the video
   encoder should determine the size of compressed data.

Before the patch, the default bitrate is 20 setting by
avcodec/options_table, which doesn't work for most of cases.
---
 libavcodec/videotoolboxenc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 35628341f6..747681fd05 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -2933,6 +2933,7 @@ static const AVOption h264_options[] = {
 };
 
 static const FFCodecDefault vt_defaults[] = {
+{"b","0"},
 {"qmin", "-1"},
 {"qmax", "-1"},
 {NULL},
-- 
2.42.0

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

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


Re: [FFmpeg-devel] [PATCH 3/6] tools/target_dec_fuzzer: Adjust threshold for RV30

2024-07-16 Thread Michael Niedermayer
On Mon, Apr 01, 2024 at 10:56:04PM +0200, Michael Niedermayer wrote:
> Fixes: Timeout
> Fixes: 
> 67530/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RV30_fuzzer-6635676118351872
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  tools/target_dec_fuzzer.c | 1 +
>  1 file changed, 1 insertion(+)

will apply

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

"You are 36 times more likely to die in a bathtub than at the hands of a
terrorist. Also, you are 2.5 times more likely to become a president and
2 times more likely to become an astronaut, than to die in a terrorist
attack." -- Thoughty2



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] [OSS-Fuzz] Have you considered enabling memory sanitizer?

2024-07-16 Thread Andrew Sayers
On Tue, Jul 16, 2024 at 02:25:04PM +0200, Michael Niedermayer wrote:
> On Mon, Jul 15, 2024 at 02:36:15PM +0200, Vittorio Giovara wrote:
> > Disagree - this is not the right way to attract new contributors.
> 
> no ?
> did you do a study ?
> 
> try this:
> A. "please we need more maintainers" (we tried this i think)
> B. gently push someone away
> (now people are angry, they want their rights, their access, they want to
>  contribute ...)
> ;)

A little off-topic, but I suspect this points to a deeper problem:

When a new person comes along and says "can I contribute my way?", replying
"no, here's the correct way to do it" leaves them with two options:
accept things are done that way for reasons they don't understand,
or go find another project that does things the way they already understand.

If you want more maintainers - that is, people with a deep understanding of the
project - you need to engage new contributors in a discussion about why things
are done that way.  Then over the course of years, they'll learn enough to
become maintainers.

I realise this can be daunting, but think about it this way: if you're right
about the best solution to some problem, arguing your case is a great way to
weed out illogical people who shouldn't become maintainers.  And if you're
wrong, you can hand over a part of the project to a new maintainer, safe in the
knowledge they understand that particular issue better than you.
___
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/mov: sanity check count in IPRP

2024-07-16 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
69230/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-6540512101203968

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavformat/mov.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index ce95842ce58..9042753d221 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8925,6 +8925,11 @@ static int mov_read_iprp(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 flags   = avio_rb24(pb);
 count   = avio_rb32(pb);
 
+if (count * 5LL > a.size) {
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
+
 for (int i = 0; i < count; i++) {
 int item_id = version ? avio_rb32(pb) : avio_rb16(pb);
 int assoc_count = avio_r8(pb);
-- 
2.45.2

___
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] Add Mediacodec audio decoders support

2024-07-16 Thread Matthieu Bouron
On Wed, Jul 10, 2024 at 6:31 PM Matthieu Bouron
 wrote:
>
> On Wed, Jul 10, 2024 at 4:04 PM Zhao Zhili  wrote:
> >
> >
> > > On Jun 12, 2024, at 21:42, Matthieu Bouron  
> > > wrote:
> > >
> > > Hello,
> > >
> > > This patchset adds Mediacodec audio decoders support. Currently, only 
> > > AAC, AMR,
> > > MP3, FLAC, VORBIS and OPUS are supported.
> > >
> > > This is mainly useful to avoid shipping Android builds of FFmpeg that are
> > > subjects to licensing/patents (due to AAC and AMR).
> >
> > I’m not keen on put OS audio decoder/encoder wrapper into FFmpeg. They 
> > don’t bring
> > new features, they don’t improve performance. I know these type of wrapper 
> > exist in current
> > project, but I’m not sure if it’s a good idea to add more.
>
> I agree that on the technical side it doesn't bring new features nor
> performance improvements. It's all about avoiding licensing/patents
> issues with AAC and AMR here.
> In this specific case we already have the wrapper infrastructure, the
> audio part only needs small adjustments to work.
> Moreover, if that helps, I can reduce the scope of the patch to AAC
> and AMR only and get rid of mp3/flac/vorbis/opus support. What do you
> think ?

Ping.

IMHO, this benefits users wanting to ship an Android app that relies
on FFmpeg upstream in countries that are subject to AAC/AMR licensing.
While I agree that it's not great from a purely technical pov since we
already have better native decoders, it will allow the use of FFmpeg
in such situation without the need to use or create another FFmpeg
fork dedicated to Android. Plus, as I said above, we already have the
wrapper and the additional code to make it work for audio is
relatively small and scoped. Restricting the wrapper to AAC/AMR seems
like a good compromise to me.

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

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


Re: [FFmpeg-devel] [PATCH 1/4] avcodec/j2kenc: Merge dwt_norm into lambda

2024-07-16 Thread Michael Niedermayer
On Fri, Jun 21, 2024 at 11:09:45PM +0200, Michael Niedermayer wrote:
> On Fri, Jun 21, 2024 at 11:38:46AM +0200, Andreas Rheinhardt wrote:
> > Michael Niedermayer:
> > > This moves computations out of a loop
> > > 
> > > Fixes: signed integer overflow: 31665934879948800 * 9998 cannot be 
> > > represented in type 'long'
> > > Fixes: 
> > > 69024/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5949662967169024
> > > 
> > > Found-by: continuous fuzzing process 
> > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer 
> > > ---
> > >  libavcodec/j2kenc.c | 9 +
> > >  1 file changed, 5 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
> > > index 8cf82f7216c..91e66d81048 100644
> > > --- a/libavcodec/j2kenc.c
> > > +++ b/libavcodec/j2kenc.c
> > > @@ -1349,7 +1349,7 @@ static void makelayers(Jpeg2000EncoderContext *s, 
> > > Jpeg2000Tile *tile)
> > >  }
> > >  }
> > >  
> > > -static int getcut(Jpeg2000Cblk *cblk, uint64_t lambda, int dwt_norm)
> > > +static int getcut(Jpeg2000Cblk *cblk, uint64_t lambda)
> > >  {
> > >  int passno, res = 0;
> > >  for (passno = 0; passno < cblk->npasses; passno++){
> > > @@ -1361,7 +1361,7 @@ static int getcut(Jpeg2000Cblk *cblk, uint64_t 
> > > lambda, int dwt_norm)
> > >  dd = cblk->passes[passno].disto
> > > - (res ? cblk->passes[res-1].disto : 0);
> > >  
> > > -if (((dd * dwt_norm) >> WMSEDEC_SHIFT) * dwt_norm >= dr * lambda)
> > > +if (dd  >= dr * lambda)
> > >  res = passno+1;
> > >  }
> > >  return res;
> > > @@ -1384,11 +1384,12 @@ static void truncpasses(Jpeg2000EncoderContext 
> > > *s, Jpeg2000Tile *tile)
> > >  Jpeg2000Band *band = reslevel->band + bandno;
> > >  Jpeg2000Prec *prec = band->prec + precno;
> > >  
> > > +int64_t dwt_norm = dwt_norms[codsty->transform == 
> > > FF_DWT53][bandpos][lev] * (int64_t)band->i_stepsize >> 15;
> > > +int64_t lambda_prime = av_rescale(s->lambda, 1 << 
> > > WMSEDEC_SHIFT, dwt_norm * dwt_norm);
> > >  for (cblkno = 0; cblkno < prec->nb_codeblocks_height 
> > > * prec->nb_codeblocks_width; cblkno++){
> > >  Jpeg2000Cblk *cblk = prec->cblk + cblkno;
> > >  
> > > -cblk->ninclpasses = getcut(cblk, s->lambda,
> > > -(int64_t)dwt_norms[codsty->transform == 
> > > FF_DWT53][bandpos][lev] * (int64_t)band->i_stepsize >> 15);
> > > +cblk->ninclpasses = getcut(cblk, lambda_prime);
> > >  cblk->layers[0].data_start = cblk->data;
> > >  cblk->layers[0].cum_passes = cblk->ninclpasses;
> > >  cblk->layers[0].npasses = cblk->ninclpasses;
> > 
> > Does this also fix the UB in the vsynth*-jpeg2000-yuva444p16 tests?
> 
> we will find out when this is applied, it looks like it might

added a note that this may fix UB in these tests to teh commit message and
will apply

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle


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

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


Re: [FFmpeg-devel] [PATCH 1/4] avcodec/j2kenc: Merge dwt_norm into lambda

2024-07-16 Thread Michael Niedermayer
On Thu, Jun 20, 2024 at 09:35:01PM +0200, Michael Niedermayer wrote:
> This moves computations out of a loop
> 
> Fixes: signed integer overflow: 31665934879948800 * 9998 cannot be 
> represented in type 'long'
> Fixes: 
> 69024/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5949662967169024
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/j2kenc.c | 9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)

will apply patchset

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

You can kill me, but you cannot change the truth.


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] avformat/mov: sanity check count in IPRP

2024-07-16 Thread James Almer

On 7/16/2024 10:19 AM, Michael Niedermayer wrote:

Fixes: Timeout
Fixes: 
69230/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-6540512101203968

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
  libavformat/mov.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index ce95842ce58..9042753d221 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8925,6 +8925,11 @@ static int mov_read_iprp(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
  flags   = avio_rb24(pb);
  count   = avio_rb32(pb);
  
+if (count * 5LL > a.size) {

+ret = AVERROR_INVALIDDATA;
+goto fail;
+}


a.size is also read from the aviocontext, so i think it'd be better to 
add an avio_feof() check inside the for loop below, after assoc_count is 
read.



+
  for (int i = 0; i < count; i++) {
  int item_id = version ? avio_rb32(pb) : avio_rb16(pb);
  int assoc_count = avio_r8(pb);

___
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] lavc/vvc_mc: R-V V avg w_avg

2024-07-16 Thread Rémi Denis-Courmont
Le keskiviikkona 10. heinäkuuta 2024, 13.02.44 EEST u...@foxmail.com a écrit :
> From: sunyuechi 
> 
>   C908   X60
> avg_8_2x2_c:1.21.2
> avg_8_2x2_rvv_i32  :0.70.7
> avg_8_2x4_c:2.02.0
> avg_8_2x4_rvv_i32  :1.21.0
> avg_8_2x8_c:3.74.0
> avg_8_2x8_rvv_i32  :1.71.5
> avg_8_2x16_c   :7.27.5
> avg_8_2x16_rvv_i32 :3.02.7
> avg_8_2x32_c   :   14.5   15.2
> avg_8_2x32_rvv_i32 :5.55.0
> avg_8_2x64_c   :   53.5   42.2
> avg_8_2x64_rvv_i32 :   42.0   33.2
> avg_8_2x128_c  :   93.5   86.0
> avg_8_2x128_rvv_i32:   79.2   74.0
> avg_8_4x2_c:1.72.0
> avg_8_4x2_rvv_i32  :1.01.0
> avg_8_4x4_c:3.53.5
> avg_8_4x4_rvv_i32  :1.21.0
> avg_8_4x8_c:6.57.0
> avg_8_4x8_rvv_i32  :1.71.7
> avg_8_4x16_c   :   13.5   14.0
> avg_8_4x16_rvv_i32 :3.02.5
> avg_8_4x32_c   :   26.2   27.5
> avg_8_4x32_rvv_i32 :5.75.0
> avg_8_4x64_c   :   79.0   66.5
> avg_8_4x64_rvv_i32 :   41.7   34.2
> avg_8_4x128_c  :  154.0  128.7
> avg_8_4x128_rvv_i32:   80.5   74.5
> avg_8_8x2_c:3.23.2
> avg_8_8x2_rvv_i32  :1.00.7
> avg_8_8x4_c:6.56.5
> avg_8_8x4_rvv_i32  :1.21.0
> avg_8_8x8_c:   12.5   13.2
> avg_8_8x8_rvv_i32  :2.01.7
> avg_8_8x16_c   :   25.2   26.5
> avg_8_8x16_rvv_i32 :3.22.7
> avg_8_8x32_c   :   50.0   52.7
> avg_8_8x32_rvv_i32 :6.24.7
> avg_8_8x64_c   :  130.0  112.2
> avg_8_8x64_rvv_i32 :   44.2   33.5
> avg_8_8x128_c  :  241.5  226.7
> avg_8_8x128_rvv_i32:   78.7   74.0
> avg_8_16x2_c   :6.26.5
> avg_8_16x2_rvv_i32 :1.20.7
> avg_8_16x4_c   :   12.2   13.0
> avg_8_16x4_rvv_i32 :1.71.0
> avg_8_16x8_c   :   24.7   25.7
> avg_8_16x8_rvv_i32 :3.01.7
> avg_8_16x16_c  :   49.0   51.5
> avg_8_16x16_rvv_i32:5.53.2
> avg_8_16x32_c  :   97.7  102.7
> avg_8_16x32_rvv_i32:   10.55.5
> avg_8_16x64_c  :  219.5  223.5
> avg_8_16x64_rvv_i32:   56.7   34.5
> avg_8_16x128_c :  409.7  426.0
> avg_8_16x128_rvv_i32   :   98.7   73.5
> avg_8_32x2_c   :   12.5   13.0
> avg_8_32x2_rvv_i32 :1.71.0
> avg_8_32x4_c   :   24.2   25.5
> avg_8_32x4_rvv_i32 :3.01.5
> avg_8_32x8_c   :   48.5   50.7
> avg_8_32x8_rvv_i32 :5.22.7
> avg_8_32x16_c  :   96.5  101.2
> avg_8_32x16_rvv_i32:   10.25.0
> avg_8_32x32_c  :  192.7  202.5
> avg_8_32x32_rvv_i32:   19.79.5
> avg_8_32x64_c  :  433.5  415.5
> avg_8_32x64_rvv_i32:   38.7   18.2
> avg_8_32x128_c :  812.0  820.7
> avg_8_32x128_rvv_i32   :  145.2   73.0
>

[FFmpeg-devel] [PATCH 3/3] avcodec/videotoolboxenc: Fix variable type of AV_OPT_TYPE_BOOL

2024-07-16 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/videotoolboxenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 747681fd05..78ef474d7a 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -262,7 +262,7 @@ typedef struct VTEncContext {
 int realtime;
 int frames_before;
 int frames_after;
-bool constant_bit_rate;
+int constant_bit_rate;
 
 int allow_sw;
 int require_sw;
-- 
2.42.0

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

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


Re: [FFmpeg-devel] [PATCH 3/3] avcodec/videotoolboxenc: Fix variable type of AV_OPT_TYPE_BOOL

2024-07-16 Thread Rémi Denis-Courmont
Le tiistaina 16. heinäkuuta 2024, 17.46.53 EEST Zhao Zhili a écrit :
> From: Zhao Zhili 
> 
> ---
>  libavcodec/videotoolboxenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index 747681fd05..78ef474d7a 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -262,7 +262,7 @@ typedef struct VTEncContext {
>  int realtime;
>  int frames_before;
>  int frames_after;
> -bool constant_bit_rate;
> +int constant_bit_rate;
> 
>  int allow_sw;
>  int require_sw;

Shouldn't it be fixed the opposite way, actually assigning to or evaluating as 
a boolean?

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/



___
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] Add Mediacodec audio decoders support

2024-07-16 Thread Zhao Zhili


> On Jul 16, 2024, at 21:20, Matthieu Bouron  wrote:
> 
> On Wed, Jul 10, 2024 at 6:31 PM Matthieu Bouron
>  wrote:
>> 
>> On Wed, Jul 10, 2024 at 4:04 PM Zhao Zhili  wrote:
>>> 
>>> 
 On Jun 12, 2024, at 21:42, Matthieu Bouron  
 wrote:
 
 Hello,
 
 This patchset adds Mediacodec audio decoders support. Currently, only AAC, 
 AMR,
 MP3, FLAC, VORBIS and OPUS are supported.
 
 This is mainly useful to avoid shipping Android builds of FFmpeg that are
 subjects to licensing/patents (due to AAC and AMR).
>>> 
>>> I’m not keen on put OS audio decoder/encoder wrapper into FFmpeg. They 
>>> don’t bring
>>> new features, they don’t improve performance. I know these type of wrapper 
>>> exist in current
>>> project, but I’m not sure if it’s a good idea to add more.
>> 
>> I agree that on the technical side it doesn't bring new features nor
>> performance improvements. It's all about avoiding licensing/patents
>> issues with AAC and AMR here.
>> In this specific case we already have the wrapper infrastructure, the
>> audio part only needs small adjustments to work.
>> Moreover, if that helps, I can reduce the scope of the patch to AAC
>> and AMR only and get rid of mp3/flac/vorbis/opus support. What do you
>> think ?
> 
> Ping.
> 
> IMHO, this benefits users wanting to ship an Android app that relies
> on FFmpeg upstream in countries that are subject to AAC/AMR licensing.
> While I agree that it's not great from a purely technical pov since we
> already have better native decoders, it will allow the use of FFmpeg
> in such situation without the need to use or create another FFmpeg
> fork dedicated to Android. Plus, as I said above, we already have the
> wrapper and the additional code to make it work for audio is
> relatively small and scoped. Restricting the wrapper to AAC/AMR seems
> like a good compromise to me.

Sounds reasonable, but I’d like to get more opinions. cc TC.

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

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

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


Re: [FFmpeg-devel] [PATCH 3/3] avcodec/videotoolboxenc: Fix variable type of AV_OPT_TYPE_BOOL

2024-07-16 Thread James Almer

On 7/16/2024 11:53 AM, Rémi Denis-Courmont wrote:

Le tiistaina 16. heinäkuuta 2024, 17.46.53 EEST Zhao Zhili a écrit :

From: Zhao Zhili 

---
  libavcodec/videotoolboxenc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 747681fd05..78ef474d7a 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -262,7 +262,7 @@ typedef struct VTEncContext {
  int realtime;
  int frames_before;
  int frames_after;
-bool constant_bit_rate;
+int constant_bit_rate;

  int allow_sw;
  int require_sw;


Shouldn't it be fixed the opposite way, actually assigning to or evaluating as
a boolean?


No, because -1 is allowed for AV_OPT_TYPE_BOOL, which is used as 
"undefined" in plenty of options.
And we don't use bool type anywhere as it's not really portable, or at 
least didn't use to. Dunno the current state ever since we moved to c11.

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

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


Re: [FFmpeg-devel] [PATCH 3/3] avcodec/videotoolboxenc: Fix variable type of AV_OPT_TYPE_BOOL

2024-07-16 Thread Rémi Denis-Courmont
Le tiistaina 16. heinäkuuta 2024, 18.10.28 EEST James Almer a écrit :
> No, because -1 is allowed for AV_OPT_TYPE_BOOL, which is used as
> "undefined" in plenty of options.
> And we don't use bool type anywhere as it's not really portable, or at
> least didn't use to. Dunno the current state ever since we moved to c11.

stdbool.h is mandatory in C11. Using booleans is generally better since it 
enables better inference for optimisation and diagnostic passes.

-- 
Rémi Denis-Courmont
http://www.remlab.net/



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

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


Re: [FFmpeg-devel] FFmpeg at IBC

2024-07-16 Thread Rémi Denis-Courmont
Le sunnuntaina 14. heinäkuuta 2024, 10.45.43 EEST Thilo Borgmann via ffmpeg-
devel a écrit :
> Share with us your broken workflows, unfulfilled requirements, ideas for
> enhancements and after show drinks at W8.A23g!

I think that we need to keep in mind who typically attends IBC.

1) The majority are not sufficiently technically versed to know what problem 
their employer has with FFmpeg. The message makes it sound like FFmpeg is 
broken and not fullfilling requirements, and just sucks. Regardless of whether 
we want to talk to those people or not, the message should really be more 
positive.

2) Many there do not understand how open-source operates. It sounds like you 
are offering to solve their problems for free.

IBC attendees are much more likely to be looking for consultants to hire than 
wanting to report bugs.

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/



___
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] hwcontext_vulkan: rewrite queue picking system for the new API

2024-07-16 Thread Lynne via ffmpeg-devel
This allows us to support different video ops on different queues,
as well as any other arbitrary queues we need.
---
 libavutil/hwcontext_vulkan.c | 262 ++-
 1 file changed, 167 insertions(+), 95 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 33d856ddd3..5baf68660a 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1028,16 +1028,51 @@ end:
 }
 
 /* Picks the least used qf with the fewest unneeded flags, or -1 if none found 
*/
-static inline int pick_queue_family(VkQueueFamilyProperties *qf, uint32_t 
num_qf,
+static inline int pick_queue_family(VkQueueFamilyProperties2 *qf, uint32_t 
num_qf,
 VkQueueFlagBits flags)
 {
 int index = -1;
 uint32_t min_score = UINT32_MAX;
 
 for (int i = 0; i < num_qf; i++) {
-const VkQueueFlagBits qflags = qf[i].queueFlags;
+VkQueueFlagBits qflags = qf[i].queueFamilyProperties.queueFlags;
+
+/* Per the spec, reporting transfer caps is optional for these 2 types 
*/
+if ((flags & VK_QUEUE_TRANSFER_BIT) &&
+(qflags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT)))
+qflags |= VK_QUEUE_TRANSFER_BIT;
+
 if (qflags & flags) {
-uint32_t score = av_popcount(qflags) + qf[i].timestampValidBits;
+uint32_t score = av_popcount(qflags) + 
qf[i].queueFamilyProperties.timestampValidBits;
+if (score < min_score) {
+index = i;
+min_score = score;
+}
+}
+}
+
+if (index > -1)
+qf[index].queueFamilyProperties.timestampValidBits++;
+
+return index;
+}
+
+static inline int pick_video_queue_family(VkQueueFamilyProperties2 *qf,
+  VkQueueFamilyVideoPropertiesKHR 
*qf_vid, uint32_t num_qf,
+  VkVideoCodecOperationFlagBitsKHR 
flags)
+{
+int index = -1;
+uint32_t min_score = UINT32_MAX;
+
+for (int i = 0; i < num_qf; i++) {
+const VkQueueFlagBits qflags = qf[i].queueFamilyProperties.queueFlags;
+const VkQueueFlagBits vflags = qf_vid[i].videoCodecOperations;
+
+if (!(qflags & (VK_QUEUE_VIDEO_ENCODE_BIT_KHR | 
VK_QUEUE_VIDEO_DECODE_BIT_KHR)))
+continue;
+
+if (vflags & flags) {
+uint32_t score = av_popcount(vflags) + 
qf[i].queueFamilyProperties.timestampValidBits;
 if (score < min_score) {
 index = i;
 min_score = score;
@@ -1046,7 +1081,7 @@ static inline int 
pick_queue_family(VkQueueFamilyProperties *qf, uint32_t num_qf
 }
 
 if (index > -1)
-qf[index].timestampValidBits++;
+qf[index].queueFamilyProperties.timestampValidBits++;
 
 return index;
 }
@@ -1054,12 +1089,12 @@ static inline int 
pick_queue_family(VkQueueFamilyProperties *qf, uint32_t num_qf
 static int setup_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd)
 {
 uint32_t num;
-float *weights;
-VkQueueFamilyProperties *qf = NULL;
 VulkanDevicePriv *p = ctx->hwctx;
 AVVulkanDeviceContext *hwctx = &p->p;
 FFVulkanFunctions *vk = &p->vkctx.vkfn;
-int graph_index, comp_index, tx_index, enc_index, dec_index;
+
+VkQueueFamilyProperties2 *qf = NULL;
+VkQueueFamilyVideoPropertiesKHR *qf_vid = NULL;
 
 /* First get the number of queue families */
 vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &num, NULL);
@@ -1069,118 +1104,155 @@ static int setup_queue_families(AVHWDeviceContext 
*ctx, VkDeviceCreateInfo *cd)
 }
 
 /* Then allocate memory */
-qf = av_malloc_array(num, sizeof(VkQueueFamilyProperties));
+qf = av_malloc_array(num, sizeof(VkQueueFamilyProperties2));
 if (!qf)
 return AVERROR(ENOMEM);
 
+qf_vid = av_malloc_array(num, sizeof(VkQueueFamilyVideoPropertiesKHR));
+if (!qf_vid)
+return AVERROR(ENOMEM);
+
+for (uint32_t i = 0; i < num; i++) {
+qf_vid[i] = (VkQueueFamilyVideoPropertiesKHR) {
+.sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_VIDEO_PROPERTIES_KHR,
+};
+qf[i] = (VkQueueFamilyProperties2) {
+.sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2,
+.pNext = &qf_vid[i],
+};
+}
+
 /* Finally retrieve the queue families */
-vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &num, qf);
+vk->GetPhysicalDeviceQueueFamilyProperties2(hwctx->phys_dev, &num, qf);
 
 av_log(ctx, AV_LOG_VERBOSE, "Queue families:\n");
 for (int i = 0; i < num; i++) {
 av_log(ctx, AV_LOG_VERBOSE, "%i:%s%s%s%s%s%s%s (queues: %i)\n", i,
-   ((qf[i].queueFlags) & VK_QUEUE_GRAPHICS_BIT) ? " graphics" : "",
-   ((qf[i].queueFlags) & VK_QUEUE_COMPUTE_BIT) ? " compute" : "",
-   ((qf[i].queueFlags) & VK_QUEUE_TRANSFER_BIT) ? " transfer" : "",
-   ((qf[i].queueFlags) 

[FFmpeg-devel] [PATCH 2/2] hwcontext_vulkan: initialize optical flow queues if available

2024-07-16 Thread Lynne via ffmpeg-devel
Lets us implement FPS conversion.
---
 libavutil/hwcontext_vulkan.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 5baf68660a..19338cc069 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1177,6 +1177,7 @@ static int setup_queue_families(AVHWDeviceContext *ctx, 
VkDeviceCreateInfo *cd)
 PICK_QF(VK_QUEUE_GRAPHICS_BIT, VK_VIDEO_CODEC_OPERATION_NONE_KHR);
 PICK_QF(VK_QUEUE_COMPUTE_BIT, VK_VIDEO_CODEC_OPERATION_NONE_KHR);
 PICK_QF(VK_QUEUE_TRANSFER_BIT, VK_VIDEO_CODEC_OPERATION_NONE_KHR);
+PICK_QF(VK_QUEUE_OPTICAL_FLOW_BIT_NV, VK_VIDEO_CODEC_OPERATION_NONE_KHR);
 
 PICK_QF(VK_QUEUE_VIDEO_ENCODE_BIT_KHR, 
VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_KHR);
 PICK_QF(VK_QUEUE_VIDEO_DECODE_BIT_KHR, 
VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR);
-- 
2.45.2.753.g447d99e1c3b
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 3/3] avcodec/videotoolboxenc: Fix variable type of AV_OPT_TYPE_BOOL

2024-07-16 Thread Zhao Zhili


> On Jul 16, 2024, at 23:10, James Almer  wrote:
> 
> On 7/16/2024 11:53 AM, Rémi Denis-Courmont wrote:
>> Le tiistaina 16. heinäkuuta 2024, 17.46.53 EEST Zhao Zhili a écrit :
>>> From: Zhao Zhili 
>>> 
>>> ---
>>>  libavcodec/videotoolboxenc.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>> 
>>> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>>> index 747681fd05..78ef474d7a 100644
>>> --- a/libavcodec/videotoolboxenc.c
>>> +++ b/libavcodec/videotoolboxenc.c
>>> @@ -262,7 +262,7 @@ typedef struct VTEncContext {
>>>  int realtime;
>>>  int frames_before;
>>>  int frames_after;
>>> -bool constant_bit_rate;
>>> +int constant_bit_rate;
>>> 
>>>  int allow_sw;
>>>  int require_sw;
>> Shouldn't it be fixed the opposite way, actually assigning to or evaluating 
>> as
>> a boolean?
> 
> No, because -1 is allowed for AV_OPT_TYPE_BOOL, which is used as "undefined" 
> in plenty of options.
> And we don't use bool type anywhere as it's not really portable, or at least 
> didn't use to. Dunno the current state ever since we moved to c11.

Yes, it’s unlikely to update opt.c to use bool as AV_OPT_TYPE_BOOL.
And maybe it’s still a rule to not use bool in public header file.
For other cases, I see no reason to forbidden it.

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

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

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


Re: [FFmpeg-devel] FFmpeg at IBC

2024-07-16 Thread Vittorio Giovara
On Sun, Jul 14, 2024 at 9:45 AM Thilo Borgmann via ffmpeg-devel <
ffmpeg-devel@ffmpeg.org> wrote:

> Hi,
>
> FFmpeg will have a booth at the next IBC from September 13th to 16th
> 2024 in Amsterdam [1]!
>
> We received a corporate sponsorship for the booth, so there are no costs
> for the FFmpeg project to it (and no obligations, of course).
>
> FFmpeg developers are welcome to join in and help man the booth with me!
>
> Share with us your broken workflows, unfulfilled requirements, ideas for
> enhancements and after show drinks at W8.A23g!
>
> -Thilo
>

Quoting Micheal here, but "where did you discuss the creation of this Booth
with the FFmpeg community?"
-- 
Vittorio
___
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] Add Mediacodec audio decoders support

2024-07-16 Thread Cosmin Stejerean via ffmpeg-devel


> On Jul 16, 2024, at 4:58 PM, Zhao Zhili  wrote:
> 
> 
> 
>> On Jul 16, 2024, at 21:20, Matthieu Bouron  wrote:
>> 
>> On Wed, Jul 10, 2024 at 6:31 PM Matthieu Bouron
>>  wrote:
>>> 
>>> On Wed, Jul 10, 2024 at 4:04 PM Zhao Zhili  wrote:
 
 
> On Jun 12, 2024, at 21:42, Matthieu Bouron  
> wrote:
> 
> Hello,
> 
> This patchset adds Mediacodec audio decoders support. Currently, only 
> AAC, AMR,
> MP3, FLAC, VORBIS and OPUS are supported.
> 
> This is mainly useful to avoid shipping Android builds of FFmpeg that are
> subjects to licensing/patents (due to AAC and AMR).
 
 I’m not keen on put OS audio decoder/encoder wrapper into FFmpeg. They 
 don’t bring
 new features, they don’t improve performance. I know these type of wrapper 
 exist in current
 project, but I’m not sure if it’s a good idea to add more.
>>> 
>>> I agree that on the technical side it doesn't bring new features nor
>>> performance improvements. It's all about avoiding licensing/patents
>>> issues with AAC and AMR here.
>>> In this specific case we already have the wrapper infrastructure, the
>>> audio part only needs small adjustments to work.
>>> Moreover, if that helps, I can reduce the scope of the patch to AAC
>>> and AMR only and get rid of mp3/flac/vorbis/opus support. What do you
>>> think ?
>> 
>> Ping.
>> 
>> IMHO, this benefits users wanting to ship an Android app that relies
>> on FFmpeg upstream in countries that are subject to AAC/AMR licensing.
>> While I agree that it's not great from a purely technical pov since we
>> already have better native decoders, it will allow the use of FFmpeg
>> in such situation without the need to use or create another FFmpeg
>> fork dedicated to Android. Plus, as I said above, we already have the
>> wrapper and the additional code to make it work for audio is
>> relatively small and scoped. Restricting the wrapper to AAC/AMR seems
>> like a good compromise to me.
> 
> Sounds reasonable, but I’d like to get more opinions. cc TC.

To add another data point, the platform decoders might also be more secure due 
to sandboxing. I believe as of Android Q the software decoders provided by 
MediaCodec have been moved to run within a constrained sandbox.

- Cosmin


___
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] Add Mediacodec audio decoders support

2024-07-16 Thread Zhao Zhili


> On Jul 16, 2024, at 23:48, Cosmin Stejerean via ffmpeg-devel 
>  wrote:
> 
> 
> 
>> On Jul 16, 2024, at 4:58 PM, Zhao Zhili  wrote:
>> 
>> 
>> 
>>> On Jul 16, 2024, at 21:20, Matthieu Bouron  
>>> wrote:
>>> 
>>> On Wed, Jul 10, 2024 at 6:31 PM Matthieu Bouron
>>>  wrote:
 
 On Wed, Jul 10, 2024 at 4:04 PM Zhao Zhili  wrote:
> 
> 
>> On Jun 12, 2024, at 21:42, Matthieu Bouron  
>> wrote:
>> 
>> Hello,
>> 
>> This patchset adds Mediacodec audio decoders support. Currently, only 
>> AAC, AMR,
>> MP3, FLAC, VORBIS and OPUS are supported.
>> 
>> This is mainly useful to avoid shipping Android builds of FFmpeg that are
>> subjects to licensing/patents (due to AAC and AMR).
> 
> I’m not keen on put OS audio decoder/encoder wrapper into FFmpeg. They 
> don’t bring
> new features, they don’t improve performance. I know these type of 
> wrapper exist in current
> project, but I’m not sure if it’s a good idea to add more.
 
 I agree that on the technical side it doesn't bring new features nor
 performance improvements. It's all about avoiding licensing/patents
 issues with AAC and AMR here.
 In this specific case we already have the wrapper infrastructure, the
 audio part only needs small adjustments to work.
 Moreover, if that helps, I can reduce the scope of the patch to AAC
 and AMR only and get rid of mp3/flac/vorbis/opus support. What do you
 think ?
>>> 
>>> Ping.
>>> 
>>> IMHO, this benefits users wanting to ship an Android app that relies
>>> on FFmpeg upstream in countries that are subject to AAC/AMR licensing.
>>> While I agree that it's not great from a purely technical pov since we
>>> already have better native decoders, it will allow the use of FFmpeg
>>> in such situation without the need to use or create another FFmpeg
>>> fork dedicated to Android. Plus, as I said above, we already have the
>>> wrapper and the additional code to make it work for audio is
>>> relatively small and scoped. Restricting the wrapper to AAC/AMR seems
>>> like a good compromise to me.
>> 
>> Sounds reasonable, but I’d like to get more opinions. cc TC.
> 
> To add another data point, the platform decoders might also be more secure 
> due to sandboxing. I believe as of Android Q the software decoders provided 
> by MediaCodec have been moved to run within a constrained sandbox.

I don’t think what Android says “secure” apply to use. The sandbox means not to
break the OS and leak information from one APP to another APP, because 
mediacodec
service is shared by all APP. An APP with FFmpeg inside and use software 
decoder/encoder
don’t have such issues since the APP don’t share decoders/encoders with other 
APP.

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

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

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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/vvc: Remove NOP condition check in alf_filter_luma

2024-07-16 Thread Zhao Zhili


> On Jul 16, 2024, at 20:31, Nuo Mi  wrote:
> 
> On Tue, Jul 16, 2024 at 10:50 AM Zhao Zhili  > wrote:
> 
>> From: Zhao Zhili mailto:zhiliz...@tencent.com>>
>> 
>> If (y + i == vb_above) or (y + i == vb_below), the if body has no
>> operation.
>> 
> 👍, How did you find this? From a compiler warning or by reading the code?

There is compiler warning. I found this issue when trying to simplify the logic
before rewrite in ARM assembly.

> 
> 
>> ---
>> libavcodec/vvc/filter_template.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/libavcodec/vvc/filter_template.c
>> b/libavcodec/vvc/filter_template.c
>> index 9b3a0e46f7..32777452b7 100644
>> --- a/libavcodec/vvc/filter_template.c
>> +++ b/libavcodec/vvc/filter_template.c
>> @@ -77,7 +77,7 @@ static void FUNC(alf_filter_luma)(uint8_t *_dst,
>> ptrdiff_t dst_stride, const uin
>> const int is_near_vb_below = (y + i >= vb_pos) && (y + i
>> <= vb_pos);
>> const int is_near_vb = is_near_vb_above ||
>> is_near_vb_below;
>> 
>> -if ((y + i < vb_pos) && ((y + i) >= vb_above)) {
>> +if ((y + i < vb_pos) && ((y + i) > vb_above)) {
>> p1 = (y + i == vb_pos - 1) ? p0 : p1;
>> p3 = (y + i >= vb_pos - 2) ? p1 : p3;
>> p5 = (y + i >= vb_pos - 3) ? p3 : p5;
>> @@ -85,7 +85,7 @@ static void FUNC(alf_filter_luma)(uint8_t *_dst,
>> ptrdiff_t dst_stride, const uin
>> p2 = (y + i == vb_pos - 1) ? p0 : p2;
>> p4 = (y + i >= vb_pos - 2) ? p2 : p4;
>> p6 = (y + i >= vb_pos - 3) ? p4 : p6;
>> -} else if ((y + i >= vb_pos) && ((y + i) <= vb_below)) {
>> +} else if ((y + i >= vb_pos) && ((y + i) < vb_below)) {
>> p2 = (y + i == vb_pos) ? p0 : p2;
>> p4 = (y + i <= vb_pos + 1) ? p2 : p4;
>> p6 = (y + i <= vb_pos + 2) ? p4 : p6;
>> --
>> 2.42.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 mailing list
> ffmpeg-devel@ffmpeg.org 
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org  with 
> subject "unsubscribe".

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

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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/vvc: Remove NOP condition check in alf_filter_luma

2024-07-16 Thread Zhao Zhili


> On Jul 17, 2024, at 00:07, Zhao Zhili  wrote:
> 
> 
> 
>> On Jul 16, 2024, at 20:31, Nuo Mi  wrote:
>> 
>> On Tue, Jul 16, 2024 at 10:50 AM Zhao Zhili > > wrote:
>> 
>>> From: Zhao Zhili mailto:zhiliz...@tencent.com>>
>>> 
>>> If (y + i == vb_above) or (y + i == vb_below), the if body has no
>>> operation.
>>> 
>> 👍, How did you find this? From a compiler warning or by reading the code?
> 
> There is compiler warning. I found this issue when trying to simplify the 
> logic
> before rewrite in ARM assembly.

Oops, I mean there is “no" compiler warning.

> 
>> 
>> 
>>> ---
>>> libavcodec/vvc/filter_template.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>> 
>>> diff --git a/libavcodec/vvc/filter_template.c
>>> b/libavcodec/vvc/filter_template.c
>>> index 9b3a0e46f7..32777452b7 100644
>>> --- a/libavcodec/vvc/filter_template.c
>>> +++ b/libavcodec/vvc/filter_template.c
>>> @@ -77,7 +77,7 @@ static void FUNC(alf_filter_luma)(uint8_t *_dst,
>>> ptrdiff_t dst_stride, const uin
>>>const int is_near_vb_below = (y + i >= vb_pos) && (y + i
>>> <= vb_pos);
>>>const int is_near_vb = is_near_vb_above ||
>>> is_near_vb_below;
>>> 
>>> -if ((y + i < vb_pos) && ((y + i) >= vb_above)) {
>>> +if ((y + i < vb_pos) && ((y + i) > vb_above)) {
>>>p1 = (y + i == vb_pos - 1) ? p0 : p1;
>>>p3 = (y + i >= vb_pos - 2) ? p1 : p3;
>>>p5 = (y + i >= vb_pos - 3) ? p3 : p5;
>>> @@ -85,7 +85,7 @@ static void FUNC(alf_filter_luma)(uint8_t *_dst,
>>> ptrdiff_t dst_stride, const uin
>>>p2 = (y + i == vb_pos - 1) ? p0 : p2;
>>>p4 = (y + i >= vb_pos - 2) ? p2 : p4;
>>>p6 = (y + i >= vb_pos - 3) ? p4 : p6;
>>> -} else if ((y + i >= vb_pos) && ((y + i) <= vb_below)) {
>>> +} else if ((y + i >= vb_pos) && ((y + i) < vb_below)) {
>>>p2 = (y + i == vb_pos) ? p0 : p2;
>>>p4 = (y + i <= vb_pos + 1) ? p2 : p4;
>>>p6 = (y + i <= vb_pos + 2) ? p4 : p6;
>>> --
>>> 2.42.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 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 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] Add Mediacodec audio decoders support

2024-07-16 Thread Cosmin Stejerean via ffmpeg-devel


> On Jul 16, 2024, at 6:04 PM, Zhao Zhili  wrote:
> 
> 
> 
>> On Jul 16, 2024, at 23:48, Cosmin Stejerean via ffmpeg-devel 
>>  wrote:
>> 
>> 
>> 
>>> On Jul 16, 2024, at 4:58 PM, Zhao Zhili  wrote:
>>> 
>>> 
>>> 
 On Jul 16, 2024, at 21:20, Matthieu Bouron  
 wrote:
 
 On Wed, Jul 10, 2024 at 6:31 PM Matthieu Bouron
  wrote:
> 
> On Wed, Jul 10, 2024 at 4:04 PM Zhao Zhili  wrote:
>> 
>> 
>>> On Jun 12, 2024, at 21:42, Matthieu Bouron  
>>> wrote:
>>> 
>>> Hello,
>>> 
>>> This patchset adds Mediacodec audio decoders support. Currently, only 
>>> AAC, AMR,
>>> MP3, FLAC, VORBIS and OPUS are supported.
>>> 
>>> This is mainly useful to avoid shipping Android builds of FFmpeg that 
>>> are
>>> subjects to licensing/patents (due to AAC and AMR).
>> 
>> I’m not keen on put OS audio decoder/encoder wrapper into FFmpeg. They 
>> don’t bring
>> new features, they don’t improve performance. I know these type of 
>> wrapper exist in current
>> project, but I’m not sure if it’s a good idea to add more.
> 
> I agree that on the technical side it doesn't bring new features nor
> performance improvements. It's all about avoiding licensing/patents
> issues with AAC and AMR here.
> In this specific case we already have the wrapper infrastructure, the
> audio part only needs small adjustments to work.
> Moreover, if that helps, I can reduce the scope of the patch to AAC
> and AMR only and get rid of mp3/flac/vorbis/opus support. What do you
> think ?
 
 Ping.
 
 IMHO, this benefits users wanting to ship an Android app that relies
 on FFmpeg upstream in countries that are subject to AAC/AMR licensing.
 While I agree that it's not great from a purely technical pov since we
 already have better native decoders, it will allow the use of FFmpeg
 in such situation without the need to use or create another FFmpeg
 fork dedicated to Android. Plus, as I said above, we already have the
 wrapper and the additional code to make it work for audio is
 relatively small and scoped. Restricting the wrapper to AAC/AMR seems
 like a good compromise to me.
>>> 
>>> Sounds reasonable, but I’d like to get more opinions. cc TC.
>> 
>> To add another data point, the platform decoders might also be more secure 
>> due to sandboxing. I believe as of Android Q the software decoders provided 
>> by MediaCodec have been moved to run within a constrained sandbox.
> 
> I don’t think what Android says “secure” apply to use. The sandbox means not 
> to
> break the OS and leak information from one APP to another APP, because 
> mediacodec
> service is shared by all APP. An APP with FFmpeg inside and use software 
> decoder/encoder
> don’t have such issues since the APP don’t share decoders/encoders with other 
> APP.
> 

It's still an issue if a vulnerability in a software decoder gives an attacker 
access to the same app's data, even if per app sandboxing keeps a compromised 
application from accessing data from other apps. 

For example consider a messaging app. If you receive a message containing media 
that exploits a vulnerability in a software decoder and that gives the attacker 
access to all of your contacts and messages within the app, that's definitely a 
security issue. 
The app itself might also have other permissions to system wide resources, etc. 


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

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


Re: [FFmpeg-devel] FFmpeg at IBC

2024-07-16 Thread Michael Niedermayer
On Tue, Jul 16, 2024 at 05:24:18PM +0200, Vittorio Giovara wrote:
> On Sun, Jul 14, 2024 at 9:45 AM Thilo Borgmann via ffmpeg-devel <
> ffmpeg-devel@ffmpeg.org> wrote:
> 
> > Hi,
> >
> > FFmpeg will have a booth at the next IBC from September 13th to 16th
> > 2024 in Amsterdam [1]!
> >
> > We received a corporate sponsorship for the booth, so there are no costs
> > for the FFmpeg project to it (and no obligations, of course).
> >
> > FFmpeg developers are welcome to join in and help man the booth with me!
> >
> > Share with us your broken workflows, unfulfilled requirements, ideas for
> > enhancements and after show drinks at W8.A23g!
> >
> > -Thilo
> >
> 
> Quoting Micheal here, but "where did you discuss the creation of this Booth
> with the FFmpeg community?"

Given that its not September the 13th yet, and this thread is a discussion,
iam not sure the quote is fitting.

thx

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

There will always be a question for which you do not know the correct answer.


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

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


[FFmpeg-devel] [PATCH 03/39] lavc/ffv1dec: simplify slice index calculation

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1dec.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 5c515e97b6..7066146477 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -259,10 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 int width, height, x, y, ret;
 const int ps  = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
 AVFrame * const p = f->cur;
-int si;
-
-for( si=0; fs != f->slice_context[si]; si ++)
-;
+const int  si = (FFV1Context**)arg - f->slice_context;
 
 if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
 ff_progress_frame_await(&f->last_picture, si);
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 06/39] lavc/ffv1dec: move copy_fields() under HAVE_THREADS

2024-07-16 Thread Anton Khirnov
It is unused otherwise
---
 libavcodec/ffv1dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index dbb7e082a3..6d59355c23 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -1027,6 +1027,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 return buf_size;
 }
 
+#if HAVE_THREADS
 static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc,
 const FFV1Context *fsrc)
 {
@@ -1055,7 +1056,6 @@ static void copy_fields(FFV1Context *fsdst, const 
FFV1Context *fssrc,
 }
 }
 
-#if HAVE_THREADS
 static int update_thread_context(AVCodecContext *dst, const AVCodecContext 
*src)
 {
 FFV1Context *fsrc = src->priv_data;
-- 
2.43.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 08/39] lavc/ffv1: move sample_buffer to the per-slice context

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.c | 35 ---
 libavcodec/ffv1.h |  5 +++--
 libavcodec/ffv1dec.c  | 27 +--
 libavcodec/ffv1dec_template.c |  9 +
 libavcodec/ffv1enc.c  | 30 --
 libavcodec/ffv1enc_template.c |  9 +
 6 files changed, 62 insertions(+), 53 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 25f28287c0..a102425596 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -112,6 +112,8 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 if (!f->slices)
 return AVERROR(ENOMEM);
 
+f->max_slice_count = max_slice_count;
+
 for (i = 0; i < max_slice_count;) {
 FFV1SliceContext *sc = &f->slices[i];
 int sx  = i % f->num_h_slices;
@@ -123,7 +125,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 FFV1Context *fs = av_mallocz(sizeof(*fs));
 
 if (!fs)
-goto memfail;
+return AVERROR(ENOMEM);
 
 f->slice_context[i++] = fs;
 memcpy(fs, f, sizeof(*fs));
@@ -134,19 +136,15 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 sc->slice_x  = sxs;
 sc->slice_y  = sys;
 
-fs->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
-  sizeof(*fs->sample_buffer));
-fs->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
-sizeof(*fs->sample_buffer32));
-if (!fs->sample_buffer || !fs->sample_buffer32)
-goto memfail;
+sc->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
+sizeof(*sc->sample_buffer));
+sc->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
+  sizeof(*sc->sample_buffer32));
+if (!sc->sample_buffer || !sc->sample_buffer32)
+return AVERROR(ENOMEM);
 }
-f->max_slice_count = max_slice_count;
-return 0;
 
-memfail:
-f->max_slice_count = i;
-return AVERROR(ENOMEM);
+return 0;
 }
 
 int ff_ffv1_allocate_initial_states(FFV1Context *f)
@@ -199,14 +197,20 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 
 for (j = 0; j < s->max_slice_count; j++) {
 FFV1Context *fs = s->slice_context[j];
+FFV1SliceContext *sc = &s->slices[j];
+
+av_freep(&sc->sample_buffer);
+av_freep(&sc->sample_buffer32);
+
+if (!fs)
+continue;
+
 for (i = 0; i < s->plane_count; i++) {
 PlaneContext *p = &fs->plane[i];
 
 av_freep(&p->state);
 av_freep(&p->vlc_state);
 }
-av_freep(&fs->sample_buffer);
-av_freep(&fs->sample_buffer32);
 }
 
 av_freep(&avctx->stats_out);
@@ -214,7 +218,8 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 av_freep(&s->initial_states[j]);
 for (i = 0; i < s->max_slice_count; i++) {
 FFV1Context *sf = s->slice_context[i];
-av_freep(&sf->rc_stat2[j]);
+if (sf)
+av_freep(&sf->rc_stat2[j]);
 }
 av_freep(&s->rc_stat2[j]);
 }
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 256904b283..ccb510a483 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -70,6 +70,9 @@ typedef struct PlaneContext {
 #define MAX_SLICES 1024
 
 typedef struct FFV1SliceContext {
+int16_t *sample_buffer;
+int32_t *sample_buffer32;
+
 int slice_width;
 int slice_height;
 int slice_x;
@@ -108,8 +111,6 @@ typedef struct FFV1Context {
 uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
 int run_index;
 int colorspace;
-int16_t *sample_buffer;
-int32_t *sample_buffer32;
 
 int use32bit;
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 28e4a05b21..fcf8977a36 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -117,18 +117,18 @@ static int is_input_end(FFV1Context *s)
 #define RENAME(name) name ## 32
 #include "ffv1dec_template.c"
 
-static int decode_plane(FFV1Context *s, uint8_t *src,
- int w, int h, int stride, int plane_index,
+static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,
+uint8_t *src, int w, int h, int stride, int 
plane_index,
  int pixel_stride)
 {
 int x, y;
 int16_t *sample[2];
-sample[0] = s->sample_buffer + 3;
-sample[1] = s->sample_buffer + w + 6 + 3;
+sample[0] = sc->sample_buffer + 3;
+sample[1] = sc->sample_buffer + w + 6 + 3;
 
 s->run_index = 0;
 
-memset(s->sample_buffer, 0, 2 * (w + 6) * sizeof(*s->sample_buffer));
+memset(sc->sample_buffer, 0, 2 * (w + 6) * sizeof(*sc->sample_buffer));
 
 for (y = 0; y < h; y++) {
 int16_t *temp = sample[0]; // FIXME: try a normal buffer
@@ -333,29 +333,29 @@ s

[FFmpeg-devel] [PATCH 02/39] lavc/ffv1dec: declare loop variables in the loop where possible

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1dec.c | 45 ++--
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 7a0d1909aa..5c515e97b6 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -46,7 +46,7 @@ static inline av_flatten int get_symbol_inline(RangeCoder *c, 
uint8_t *state,
 if (get_rac(c, state + 0))
 return 0;
 else {
-int i, e;
+int e;
 unsigned a;
 e = 0;
 while (get_rac(c, state + 1 + FFMIN(e, 9))) { // 1..10
@@ -56,7 +56,7 @@ static inline av_flatten int get_symbol_inline(RangeCoder *c, 
uint8_t *state,
 }
 
 a = 1;
-for (i = e - 1; i >= 0; i--)
+for (int i = e - 1; i >= 0; i--)
 a += a + get_rac(c, state + 22 + FFMIN(i, 9));  // 22..31
 
 e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); // 11..21
@@ -167,7 +167,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs)
 {
 RangeCoder *c = &fs->c;
 uint8_t state[CONTEXT_SIZE];
-unsigned ps, i, context_count;
+unsigned ps, context_count;
 int sx, sy, sw, sh;
 
 memset(state, 128, sizeof(state));
@@ -197,7 +197,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs)
 if (fs->ac == AC_GOLOMB_RICE && fs->slice_width >= (1<<23))
 return AVERROR_INVALIDDATA;
 
-for (i = 0; i < f->plane_count; i++) {
+for (unsigned i = 0; i < f->plane_count; i++) {
 PlaneContext * const p = &fs->plane[i];
 int idx = get_symbol(c, state, 0);
 if (idx >= (unsigned)f->quant_table_count) {
@@ -259,7 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 int width, height, x, y, ret;
 const int ps  = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
 AVFrame * const p = f->cur;
-int i, si;
+int si;
 
 for( si=0; fs != f->slice_context[si]; si ++)
 ;
@@ -276,7 +276,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (!(p->flags & AV_FRAME_FLAG_KEY))
 fsdst->slice_damaged |= fssrc->slice_damaged;
 
-for (i = 0; i < f->plane_count; i++) {
+for (int i = 0; i < f->plane_count; i++) {
 PlaneContext *psrc = &fssrc->plane[i];
 PlaneContext *pdst = &fsdst->plane[i];
 
@@ -424,7 +424,7 @@ static int read_extra_header(FFV1Context *f)
 {
 RangeCoder *const c = &f->c;
 uint8_t state[CONTEXT_SIZE];
-int i, j, k, ret;
+int ret;
 uint8_t state2[32][CONTEXT_SIZE];
 unsigned crc = 0;
 
@@ -453,7 +453,7 @@ static int read_extra_header(FFV1Context *f)
 f->ac = get_symbol(c, state, 0);
 
 if (f->ac == AC_RANGE_CUSTOM_TAB) {
-for (i = 1; i < 256; i++)
+for (int i = 1; i < 256; i++)
 f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i];
 }
 
@@ -492,7 +492,7 @@ static int read_extra_header(FFV1Context *f)
 return AVERROR_INVALIDDATA;
 }
 
-for (i = 0; i < f->quant_table_count; i++) {
+for (int i = 0; i < f->quant_table_count; i++) {
 f->context_count[i] = read_quant_tables(c, f->quant_tables[i]);
 if (f->context_count[i] < 0) {
 av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
@@ -502,10 +502,10 @@ static int read_extra_header(FFV1Context *f)
 if ((ret = ff_ffv1_allocate_initial_states(f)) < 0)
 return ret;
 
-for (i = 0; i < f->quant_table_count; i++)
+for (int i = 0; i < f->quant_table_count; i++)
 if (get_rac(c, state)) {
-for (j = 0; j < f->context_count[i]; j++)
-for (k = 0; k < CONTEXT_SIZE; k++) {
+for (int j = 0; j < f->context_count[i]; j++)
+for (int k = 0; k < CONTEXT_SIZE; k++) {
 int pred = j ? f->initial_states[i][j - 1][k] : 128;
 f->initial_states[i][j][k] =
 (pred + get_symbol(c, state2[k], 1)) & 0xFF;
@@ -550,7 +550,7 @@ static int read_extra_header(FFV1Context *f)
 static int read_header(FFV1Context *f)
 {
 uint8_t state[CONTEXT_SIZE];
-int i, j, context_count = -1; //-1 to avoid warning
+int context_count = -1; //-1 to avoid warning
 RangeCoder *const c = &f->slice_context[0]->c;
 
 memset(state, 128, sizeof(state));
@@ -566,7 +566,7 @@ static int read_header(FFV1Context *f)
 f->ac = get_symbol(c, state, 0);
 
 if (f->ac == AC_RANGE_CUSTOM_TAB) {
-for (i = 1; i < 256; i++) {
+for (int i = 1; i < 256; i++) {
 int st = get_symbol(c, state, 1) + c->one_state[i];
 if (st < 1 || st > 255) {
 av_log(f->avctx, AV_LOG_ERROR, "invalid state transition 
%d\n", st);
@@ -790,7 +790,7 @@ static int read_header(FFV1Context *f)
 return AVERROR_INVALIDDATA;
 }
 
-for (j = 0; j < f->slice_count; j++) {
+for (int j = 0; j < f->slice_count; j++) {
 FFV1Conte

[FFmpeg-devel] [PATCH 14/39] lavc/ffv1: drop write-only PlaneContext.interlace_bit_state

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.c | 3 ---
 libavcodec/ffv1.h | 1 -
 2 files changed, 4 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index a102425596..6a0aca6429 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -169,9 +169,6 @@ void ff_ffv1_clear_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 for (i = 0; i < f->plane_count; i++) {
 PlaneContext *p = &fs->plane[i];
 
-p->interlace_bit_state[0] = 128;
-p->interlace_bit_state[1] = 128;
-
 if (fs->ac != AC_GOLOMB_RICE) {
 if (f->initial_states[p->quant_table_index]) {
 memcpy(p->state, f->initial_states[p->quant_table_index],
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index a87c2d2a36..a3f3b30b49 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -63,7 +63,6 @@ typedef struct PlaneContext {
 int context_count;
 uint8_t (*state)[CONTEXT_SIZE];
 VlcState *vlc_state;
-uint8_t interlace_bit_state[2];
 } PlaneContext;
 
 #define MAX_SLICES 1024
-- 
2.43.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 16/39] lavc/ffv1: move FFV1Context.slice_{coding_mode, rct_.y_coef} to per-slice context

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.h |  6 +++---
 libavcodec/ffv1dec.c  | 14 +++---
 libavcodec/ffv1dec_template.c | 10 +-
 libavcodec/ffv1enc.c  | 26 +-
 libavcodec/ffv1enc_template.c | 10 +-
 5 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index a3f3b30b49..e466aedbbe 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -77,6 +77,9 @@ typedef struct FFV1SliceContext {
 int slice_y;
 
 int run_index;
+int slice_coding_mode;
+int slice_rct_by_coef;
+int slice_rct_ry_coef;
 
 PutBitContext pb;
 } FFV1SliceContext;
@@ -130,9 +133,6 @@ typedef struct FFV1Context {
 int num_v_slices;
 int num_h_slices;
 int slice_reset_contexts;
-int slice_coding_mode;
-int slice_rct_by_coef;
-int slice_rct_ry_coef;
 
 FFV1SliceContext *slices;
 } FFV1Context;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 6d3db25279..8464697fd3 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -240,11 +240,11 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 
 if (fs->version > 3) {
 fs->slice_reset_contexts = get_rac(c, state);
-fs->slice_coding_mode = get_symbol(c, state, 0);
-if (fs->slice_coding_mode != 1) {
-fs->slice_rct_by_coef = get_symbol(c, state, 0);
-fs->slice_rct_ry_coef = get_symbol(c, state, 0);
-if ((uint64_t)fs->slice_rct_by_coef + 
(uint64_t)fs->slice_rct_ry_coef > 4) {
+sc->slice_coding_mode = get_symbol(c, state, 0);
+if (sc->slice_coding_mode != 1) {
+sc->slice_rct_by_coef = get_symbol(c, state, 0);
+sc->slice_rct_ry_coef = get_symbol(c, state, 0);
+if ((uint64_t)sc->slice_rct_by_coef + 
(uint64_t)sc->slice_rct_ry_coef > 4) {
 av_log(f->avctx, AV_LOG_ERROR, "slice_rct_y_coef out of 
range\n");
 return AVERROR_INVALIDDATA;
 }
@@ -294,8 +294,8 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 }
 
-fs->slice_rct_by_coef = 1;
-fs->slice_rct_ry_coef = 1;
+sc->slice_rct_by_coef = 1;
+sc->slice_rct_ry_coef = 1;
 
 if (f->version > 2) {
 if (ff_ffv1_init_slice_state(f, fs) < 0)
diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index d868617de9..776dc4144f 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -38,7 +38,7 @@ RENAME(decode_line)(FFV1Context *f,
 if (is_input_end(s, gb))
 return AVERROR_INVALIDDATA;
 
-if (s->slice_coding_mode == 1) {
+if (sc->slice_coding_mode == 1) {
 int i;
 for (x = 0; x < w; x++) {
 int v = 0;
@@ -161,10 +161,10 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f,
 
 sample[p][1][-1]= sample[p][0][0  ];
 sample[p][0][ w]= sample[p][0][w-1];
-if (lbd && s->slice_coding_mode == 0)
+if (lbd && sc->slice_coding_mode == 0)
 ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 
1)/2, 9);
 else
-ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 
1)/2, bits + (s->slice_coding_mode != 1));
+ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 
1)/2, bits + (sc->slice_coding_mode != 1));
 if (ret < 0)
 return ret;
 }
@@ -174,10 +174,10 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f,
 int r = sample[2][1][x];
 int a = sample[3][1][x];
 
-if (s->slice_coding_mode != 1) {
+if (sc->slice_coding_mode != 1) {
 b -= offset;
 r -= offset;
-g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 
2;
+g -= (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) 
>> 2;
 b += g;
 r += g;
 }
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index d334220e13..fb373b598b 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -926,13 +926,13 @@ static void encode_slice_header(FFV1Context *f, 
FFV1Context *fs,
 put_symbol(c, state, f->cur_enc_frame->sample_aspect_ratio.num, 0);
 put_symbol(c, state, f->cur_enc_frame->sample_aspect_ratio.den, 0);
 if (f->version > 3) {
-put_rac(c, state, fs->slice_coding_mode == 1);
-if (fs->slice_coding_mode == 1)
+put_rac(c, state, sc->slice_coding_mode == 1);
+if (sc->slice_coding_mode == 1)
 ff_ffv1_clear_slice_state(f, fs);
-put_symbol(c, state, fs->slice_coding_mode, 0);
-if (fs->slice_coding_mode != 1) {
-put_symbol(c, state, fs->slice_rct_by_coef, 0);
-put_symbol(c, state, fs->slice_rct_ry_coef, 0);
+put_symbol(c, state, sc->slice_coding_mode, 0);
+if (sc->slice_coding_mode != 1) {
+p

[FFmpeg-devel] [PATCH 13/39] lavc/ffv1: drop redundant PlaneContext.quant_table

2024-07-16 Thread Anton Khirnov
It is a copy of FFV1Context.quant_tables[quant_table_index].
---
 libavcodec/ffv1.h |  1 -
 libavcodec/ffv1_template.c| 22 +++---
 libavcodec/ffv1dec.c  | 28 
 libavcodec/ffv1dec_template.c | 14 +-
 libavcodec/ffv1enc.c  | 24 
 libavcodec/ffv1enc_template.c | 13 -
 6 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 4d57172d5b..a87c2d2a36 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -59,7 +59,6 @@ typedef struct VlcState {
 } VlcState;
 
 typedef struct PlaneContext {
-int16_t quant_table[MAX_CONTEXT_INPUTS][256];
 int quant_table_index;
 int context_count;
 uint8_t (*state)[CONTEXT_SIZE];
diff --git a/libavcodec/ffv1_template.c b/libavcodec/ffv1_template.c
index c5f61b0182..d15ad11021 100644
--- a/libavcodec/ffv1_template.c
+++ b/libavcodec/ffv1_template.c
@@ -29,25 +29,25 @@ static inline int RENAME(predict)(TYPE *src, TYPE *last)
 return mid_pred(L, L + T - LT, T);
 }
 
-static inline int RENAME(get_context)(PlaneContext *p, TYPE *src,
-  TYPE *last, TYPE *last2)
+static inline int RENAME(get_context)(const int16_t 
quant_table[MAX_CONTEXT_INPUTS][256],
+  TYPE *src, TYPE *last, TYPE *last2)
 {
 const int LT = last[-1];
 const int T  = last[0];
 const int RT = last[1];
 const int L  = src[-1];
 
-if (p->quant_table[3][127] || p->quant_table[4][127]) {
+if (quant_table[3][127] || quant_table[4][127]) {
 const int TT = last2[0];
 const int LL = src[-2];
-return p->quant_table[0][(L - LT) & 0xFF] +
-   p->quant_table[1][(LT - T) & 0xFF] +
-   p->quant_table[2][(T - RT) & 0xFF] +
-   p->quant_table[3][(LL - L) & 0xFF] +
-   p->quant_table[4][(TT - T) & 0xFF];
+return quant_table[0][(L - LT) & 0xFF] +
+   quant_table[1][(LT - T) & 0xFF] +
+   quant_table[2][(T - RT) & 0xFF] +
+   quant_table[3][(LL - L) & 0xFF] +
+   quant_table[4][(TT - T) & 0xFF];
 } else
-return p->quant_table[0][(L - LT) & 0xFF] +
-   p->quant_table[1][(LT - T) & 0xFF] +
-   p->quant_table[2][(T - RT) & 0xFF];
+return quant_table[0][(L - LT) & 0xFF] +
+   quant_table[1][(LT - T) & 0xFF] +
+   quant_table[2][(T - RT) & 0xFF];
 }
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 66d9f63c1a..618020d10f 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -117,7 +117,8 @@ static int is_input_end(FFV1Context *s, GetBitContext *gb)
 #define RENAME(name) name ## 32
 #include "ffv1dec_template.c"
 
-static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,
+static int decode_plane(FFV1Context *f,
+FFV1Context *s, FFV1SliceContext *sc,
 GetBitContext *gb,
 uint8_t *src, int w, int h, int stride, int 
plane_index,
  int pixel_stride)
@@ -141,13 +142,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 sample[0][w]  = sample[0][w - 1];
 
 if (s->avctx->bits_per_raw_sample <= 8) {
-int ret = decode_line(s, sc, gb, w, sample, plane_index, 8);
+int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8);
 if (ret < 0)
 return ret;
 for (x = 0; x < w; x++)
 src[x*pixel_stride + stride * y] = sample[1][x];
 } else {
-int ret = decode_line(s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
+int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
 if (ret < 0)
 return ret;
 if (s->packed_at_lsb) {
@@ -207,7 +208,6 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 return -1;
 }
 p->quant_table_index = idx;
-memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table));
 context_count = f->context_count[idx];
 
 if (p->context_count < context_count) {
@@ -335,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg)
 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
 const int cx= x >> f->chroma_h_shift;
 const int cy= y >> f->chroma_v_shift;
-decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, 
height, p->linesize[0], 0, 1);
+decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], 
width, height, p->linesize[0], 0, 1);
 
 if (f->chroma_planes) {
-decode_plane(fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], 
chroma_width, chroma_height, p->linesize[1], 1, 1);
-de

[FFmpeg-devel] [PATCH 17/39] lavc/ffv1: always use the main context values of ac

2024-07-16 Thread Anton Khirnov
It cannot change between slices.
---
 libavcodec/ffv1.c |  6 +++---
 libavcodec/ffv1dec.c  | 14 ++
 libavcodec/ffv1dec_template.c |  6 +++---
 libavcodec/ffv1enc.c  |  6 +++---
 libavcodec/ffv1enc_template.c |  4 ++--
 5 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 06a77c3a26..581e775ae2 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -59,7 +59,7 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 for (j = 0; j < f->plane_count; j++) {
 PlaneContext *const p = &fs->plane[j];
 
-if (fs->ac != AC_GOLOMB_RICE) {
+if (f->ac != AC_GOLOMB_RICE) {
 if (!p->state)
 p->state = av_malloc_array(p->context_count, CONTEXT_SIZE *
  sizeof(uint8_t));
@@ -78,7 +78,7 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 }
 }
 
-if (fs->ac == AC_RANGE_CUSTOM_TAB) {
+if (f->ac == AC_RANGE_CUSTOM_TAB) {
 //FIXME only redo if state_transition changed
 for (j = 1; j < 256; j++) {
 fs->c. one_state[  j] = f->state_transition[j];
@@ -167,7 +167,7 @@ void ff_ffv1_clear_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 for (i = 0; i < f->plane_count; i++) {
 PlaneContext *p = &fs->plane[i];
 
-if (fs->ac != AC_GOLOMB_RICE) {
+if (f->ac != AC_GOLOMB_RICE) {
 if (f->initial_states[p->quant_table_index]) {
 memcpy(p->state, f->initial_states[p->quant_table_index],
CONTEXT_SIZE * p->context_count);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 8464697fd3..133baa895a 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -94,10 +94,9 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState 
*const state,
 return ret;
 }
 
-static int is_input_end(FFV1Context *s, GetBitContext *gb)
+static int is_input_end(RangeCoder *c, GetBitContext *gb, int ac)
 {
-if (s->ac != AC_GOLOMB_RICE) {
-RangeCoder *const c = &s->c;
+if (ac != AC_GOLOMB_RICE) {
 if (c->overread > MAX_OVERREAD)
 return AVERROR_INVALIDDATA;
 } else {
@@ -197,7 +196,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 av_assert0 (   (unsigned)sc->slice_x + (uint64_t)sc->slice_width  <= 
f->width
 && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= 
f->height);
 
-if (fs->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23))
+if (f->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23))
 return AVERROR_INVALIDDATA;
 
 for (unsigned i = 0; i < f->plane_count; i++) {
@@ -284,7 +283,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 pdst->state = NULL;
 pdst->vlc_state = NULL;
 
-if (fssrc->ac) {
+if (f->ac) {
 pdst->state = av_malloc_array(CONTEXT_SIZE,  
psrc->context_count);
 memcpy(pdst->state, psrc->state, CONTEXT_SIZE * 
psrc->context_count);
 } else {
@@ -319,7 +318,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 x  = sc->slice_x;
 y  = sc->slice_y;
 
-if (fs->ac == AC_GOLOMB_RICE) {
+if (f->ac == AC_GOLOMB_RICE) {
 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
 get_rac(&fs->c, (uint8_t[]) { 129 });
 fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - 
fs->c.bytestream_start - 1 : 0;
@@ -358,7 +357,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
p->data[3] + ps * x + y * p->linesize[3] };
 decode_rgb_frame(f, fs, sc, &gb, planes, width, height, p->linesize);
 }
-if (fs->ac != AC_GOLOMB_RICE && f->version > 2) {
+if (f->ac != AC_GOLOMB_RICE && f->version > 2) {
 int v;
 get_rac(&fs->c, (uint8_t[]) { 129 });
 v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec;
@@ -791,7 +790,6 @@ static int read_header(FFV1Context *f)
 for (int j = 0; j < f->slice_count; j++) {
 FFV1Context *fs = f->slice_context[j];
 FFV1SliceContext *sc = &f->slices[j];
-fs->ac= f->ac;
 fs->packed_at_lsb = f->packed_at_lsb;
 
 fs->slice_damaged = 0;
diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index 776dc4144f..30a13e0faf 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -35,7 +35,7 @@ RENAME(decode_line)(FFV1Context *f,
 int run_mode  = 0;
 int run_index = sc->run_index;
 
-if (is_input_end(s, gb))
+if (is_input_end(c, gb, f->ac))
 return AVERROR_INVALIDDATA;
 
 if (sc->slice_coding_mode == 1) {
@@ -55,7 +55,7 @@ RENAME(decode_line)(FFV1Context *f,
 int diff, context, sign;
 
 if (!(x & 1023)) {
-if (is_input_end(s, gb))
+ 

[FFmpeg-devel] [PATCH 05/39] lavc/ffv1dec: drop a pointless variable in decode_slice()

2024-07-16 Thread Anton Khirnov
fsdst is by construction always equal to fs, there is even an
av_assert1() checking that. Just use fs directly.
---
 libavcodec/ffv1dec.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 60d04f04b9..dbb7e082a3 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -267,16 +267,14 @@ static int decode_slice(AVCodecContext *c, void *arg)
 
 if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
 FFV1Context *fssrc = f->fsrc->slice_context[si];
-FFV1Context *fsdst = f->slice_context[si];
-av_assert1(fsdst->plane_count == fssrc->plane_count);
-av_assert1(fsdst == fs);
+av_assert1(fs->plane_count == fssrc->plane_count);
 
 if (!(p->flags & AV_FRAME_FLAG_KEY))
-fsdst->slice_damaged |= fssrc->slice_damaged;
+fs->slice_damaged |= fssrc->slice_damaged;
 
 for (int i = 0; i < f->plane_count; i++) {
 PlaneContext *psrc = &fssrc->plane[i];
-PlaneContext *pdst = &fsdst->plane[i];
+PlaneContext *pdst = &fs->plane[i];
 
 av_free(pdst->state);
 av_free(pdst->vlc_state);
-- 
2.43.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 15/39] lavc/ffv1: always use the main context values of plane_count/transparency

2024-07-16 Thread Anton Khirnov
They cannot change between slices.
---
 libavcodec/ffv1.c | 2 --
 libavcodec/ffv1dec.c  | 5 ++---
 libavcodec/ffv1dec_template.c | 2 +-
 libavcodec/ffv1enc.c  | 2 +-
 libavcodec/ffv1enc_template.c | 2 +-
 5 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 6a0aca6429..06a77c3a26 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -56,8 +56,6 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 {
 int j, i;
 
-fs->plane_count  = f->plane_count;
-fs->transparency = f->transparency;
 for (j = 0; j < f->plane_count; j++) {
 PlaneContext *const p = &fs->plane[j];
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 618020d10f..6d3db25279 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -270,7 +270,6 @@ static int decode_slice(AVCodecContext *c, void *arg)
 
 if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
 FFV1Context *fssrc = f->fsrc->slice_context[si];
-av_assert1(fs->plane_count == fssrc->plane_count);
 
 if (!(p->flags & AV_FRAME_FLAG_KEY))
 fs->slice_damaged |= fssrc->slice_damaged;
@@ -330,7 +329,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 
 av_assert1(width && height);
-if (f->colorspace == 0 && (f->chroma_planes || !fs->transparency)) {
+if (f->colorspace == 0 && (f->chroma_planes || !f->transparency)) {
 const int chroma_width  = AV_CEIL_RSHIFT(width,  f->chroma_h_shift);
 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
 const int cx= x >> f->chroma_h_shift;
@@ -341,7 +340,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 decode_plane(f, fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], 
chroma_width, chroma_height, p->linesize[1], 1, 1);
 decode_plane(f, fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], 
chroma_width, chroma_height, p->linesize[2], 1, 1);
 }
-if (fs->transparency)
+if (f->transparency)
 decode_plane(f, fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], 
width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 
1);
 } else if (f->colorspace == 0) {
  decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0]
, width, height, p->linesize[0], 0, 2);
diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index 97a28b085a..d868617de9 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -140,7 +140,7 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f,
 int lbd= s->avctx->bits_per_raw_sample <= 8;
 int bits   = s->avctx->bits_per_raw_sample > 0 ? 
s->avctx->bits_per_raw_sample : 8;
 int offset = 1 << bits;
-int transparency = s->transparency;
+int transparency = f->transparency;
 
 for (x = 0; x < 4; x++) {
 sample[x][0] = RENAME(sc->sample_buffer) +  x * 2  * (w + 6) + 3;
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 714e007659..d334220e13 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1072,7 +1072,7 @@ retry:
 ret |= encode_plane(f, fs, sc, p->data[1] + 
ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
 ret |= encode_plane(f, fs, sc, p->data[2] + 
ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
 }
-if (fs->transparency)
+if (f->transparency)
 ret |= encode_plane(f, fs, sc, p->data[3] + ps*x + 
y*p->linesize[3], width, height, p->linesize[3], 2, 1);
 } else if (c->pix_fmt == AV_PIX_FMT_YA8) {
 ret  = encode_plane(f, fs, sc, p->data[0] + ps*x + 
y*p->linesize[0], width, height, p->linesize[0], 0, 2);
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index 4a5580e1a5..0f47a0b424 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -138,7 +138,7 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f,
 int packed = !src[1];
 int bits   = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8;
 int offset = 1 << bits;
-int transparency = s->transparency;
+int transparency = f->transparency;
 int packed_size = (3 + transparency)*2;
 
 sc->run_index = 0;
-- 
2.43.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 31/39] lavc/decode: wrap AV_FRAME_FLAG_DISCARD handling in a loop

2024-07-16 Thread Anton Khirnov
Makes sure discarded frames do not cause EAGAIN to be returned during
flushing, which is forbidden.
---
 libavcodec/decode.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6ad74bd94b..b17cfba26f 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -613,17 +613,22 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 av_assert0(!frame->buf[0]);
 
 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
+while (1) {
 frame->pict_type = dc->initial_pict_type;
 frame->flags|= dc->intra_only_flag;
 ret = codec->cb.receive_frame(avctx, frame);
 emms_c();
 if (!ret) {
-if (avctx->codec->type == AVMEDIA_TYPE_VIDEO)
-ret = (frame->flags & AV_FRAME_FLAG_DISCARD) ? AVERROR(EAGAIN) 
: 0;
-else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
+if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
 int64_t discarded_samples = 0;
 ret = discard_samples(avctx, frame, &discarded_samples);
 }
+if (ret == AVERROR(EAGAIN) || (frame->flags & 
AV_FRAME_FLAG_DISCARD)) {
+av_frame_unref(frame);
+continue;
+}
+}
+break;
 }
 } else
 ret = decode_simple_receive_frame(avctx, frame);
-- 
2.43.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 35/39] lavc/hevcdec: switch to receive_frame()

2024-07-16 Thread Anton Khirnov
Required by following commits, where we will want to output multiple
frames per packet.
---
 libavcodec/hevc/hevcdec.c | 29 -
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 0e4b26dad3..fc87169a1a 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3401,22 +3401,25 @@ static int hevc_decode_extradata(HEVCContext *s, 
uint8_t *buf, int length, int f
 return 0;
 }
 
-static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
- int *got_output, AVPacket *avpkt)
+static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame)
 {
+HEVCContext*s = avctx->priv_data;
+AVCodecInternal *avci = avctx->internal;
+AVPacket   *avpkt = avci->in_pkt;
+
 int ret;
 uint8_t *sd;
 size_t sd_size;
-HEVCContext *s = avctx->priv_data;
 
-if (!avpkt->size) {
-ret = ff_hevc_output_frame(s, rframe, 1);
+av_packet_unref(avpkt);
+ret = ff_decode_get_packet(avctx, avpkt);
+if (ret == AVERROR_EOF) {
+ret = ff_hevc_output_frame(s, frame, 1);
 if (ret < 0)
 return ret;
-
-*got_output = ret;
-return 0;
-}
+return (ret > 0) ? 0 : AVERROR_EOF;
+} else if (ret < 0)
+return ret;
 
 sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size);
 if (sd && sd_size > 0) {
@@ -3440,11 +3443,11 @@ static int hevc_decode_frame(AVCodecContext *avctx, 
AVFrame *rframe,
 return ret;
 
 if (s->output_frame->buf[0]) {
-av_frame_move_ref(rframe, s->output_frame);
-*got_output = 1;
+av_frame_move_ref(frame, s->output_frame);
+return 0;
 }
 
-return avpkt->size;
+return AVERROR(EAGAIN);
 }
 
 static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
@@ -3721,7 +3724,7 @@ const FFCodec ff_hevc_decoder = {
 .p.priv_class  = &hevc_decoder_class,
 .init  = hevc_decode_init,
 .close = hevc_decode_free,
-FF_CODEC_DECODE_CB(hevc_decode_frame),
+FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame),
 .flush = hevc_decode_flush,
 UPDATE_THREAD_CONTEXT(hevc_update_thread_context),
 .p.capabilities= AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
-- 
2.43.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 20/39] lavc/ffv1enc: store per-slice rc_stat(2?) in FFV1SliceContext

2024-07-16 Thread Anton Khirnov
Instead of the per-slice FFV1Context, which will be removed in future
commits.
---
 libavcodec/ffv1.c |  6 ++
 libavcodec/ffv1.h |  3 +++
 libavcodec/ffv1enc.c  | 20 ++--
 libavcodec/ffv1enc_template.c |  4 ++--
 4 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 490baac233..4ef04f6b9b 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -127,7 +127,6 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 
 f->slice_context[i++] = fs;
 memcpy(fs, f, sizeof(*fs));
-memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2));
 
 sc->slice_width  = sxe - sxs;
 sc->slice_height = sye - sys;
@@ -208,9 +207,8 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 for (j = 0; j < s->quant_table_count; j++) {
 av_freep(&s->initial_states[j]);
 for (i = 0; i < s->max_slice_count; i++) {
-FFV1Context *sf = s->slice_context[i];
-if (sf)
-av_freep(&sf->rc_stat2[j]);
+FFV1SliceContext *sc = &s->slices[i];
+av_freep(&sc->rc_stat2[j]);
 }
 av_freep(&s->rc_stat2[j]);
 }
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 01c35dc942..bee7b75614 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -84,6 +84,9 @@ typedef struct FFV1SliceContext {
 PlaneContext plane[MAX_PLANES];
 PutBitContext pb;
 RangeCoder c;
+
+uint64_t rc_stat[256][2];
+uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index d615d3da87..e3d094141c 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -896,11 +896,11 @@ slices_ok:
 return AVERROR(ENOMEM);
 for (i = 0; i < s->quant_table_count; i++)
 for (j = 0; j < s->max_slice_count; j++) {
-FFV1Context *sf = s->slice_context[j];
-av_assert0(!sf->rc_stat2[i]);
-sf->rc_stat2[i] = av_mallocz(s->context_count[i] *
- sizeof(*sf->rc_stat2[i]));
-if (!sf->rc_stat2[i])
+FFV1SliceContext *sc = &s->slices[j];
+av_assert0(!sc->rc_stat2[i]);
+sc->rc_stat2[i] = av_mallocz(s->context_count[i] *
+ sizeof(*sc->rc_stat2[i]));
+if (!sc->rc_stat2[i])
 return AVERROR(ENOMEM);
 }
 }
@@ -1126,16 +1126,16 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 
 av_assert0(f->slice_count == f->max_slice_count);
 for (j = 0; j < f->slice_count; j++) {
-FFV1Context *fs = f->slice_context[j];
+const FFV1SliceContext *sc = &f->slices[j];
 for (i = 0; i < 256; i++) {
-f->rc_stat[i][0] += fs->rc_stat[i][0];
-f->rc_stat[i][1] += fs->rc_stat[i][1];
+f->rc_stat[i][0] += sc->rc_stat[i][0];
+f->rc_stat[i][1] += sc->rc_stat[i][1];
 }
 for (i = 0; i < f->quant_table_count; i++) {
 for (k = 0; k < f->context_count[i]; k++)
 for (m = 0; m < 32; m++) {
-f->rc_stat2[i][k][m][0] += 
fs->rc_stat2[i][k][m][0];
-f->rc_stat2[i][k][m][1] += 
fs->rc_stat2[i][k][m][1];
+f->rc_stat2[i][k][m][0] += 
sc->rc_stat2[i][k][m][0];
+f->rc_stat2[i][k][m][1] += 
sc->rc_stat2[i][k][m][1];
 }
 }
 }
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index c27a2e3a39..c79146d619 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -74,8 +74,8 @@ RENAME(encode_line)(FFV1Context *f,
 
 if (f->ac != AC_GOLOMB_RICE) {
 if (s->flags & AV_CODEC_FLAG_PASS1) {
-put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat,
-  s->rc_stat2[p->quant_table_index][context]);
+put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat,
+  sc->rc_stat2[p->quant_table_index][context]);
 } else {
 put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL);
 }
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 21/39] lavc/ffv1: move ac_byte_count to per-slice context

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.h| 2 +-
 libavcodec/ffv1dec.c | 6 +++---
 libavcodec/ffv1enc.c | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index bee7b75614..ae81940073 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -85,6 +85,7 @@ typedef struct FFV1SliceContext {
 PutBitContext pb;
 RangeCoder c;
 
+int ac_byte_count;   ///< number of bytes used for AC 
coding
 uint64_t rc_stat[256][2];
 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
 } FFV1SliceContext;
@@ -109,7 +110,6 @@ typedef struct FFV1Context {
 const AVFrame *cur_enc_frame;
 int plane_count;
 int ac;  ///< 1=range coder <-> 0=golomb rice
-int ac_byte_count;   ///< number of bytes used for AC 
coding
 int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
 int context_count[MAX_QUANT_TABLES];
 uint8_t state_transition[256];
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index e0344c996b..4dc1f4b1cf 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -322,10 +322,10 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (f->ac == AC_GOLOMB_RICE) {
 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
 get_rac(&sc->c, (uint8_t[]) { 129 });
-fs->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - 
sc->c.bytestream_start - 1 : 0;
+sc->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - 
sc->c.bytestream_start - 1 : 0;
 init_get_bits(&gb,
-  sc->c.bytestream_start + fs->ac_byte_count,
-  (sc->c.bytestream_end - sc->c.bytestream_start - 
fs->ac_byte_count) * 8);
+  sc->c.bytestream_start + sc->ac_byte_count,
+  (sc->c.bytestream_end - sc->c.bytestream_start - 
sc->ac_byte_count) * 8);
 }
 
 av_assert1(width && height);
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index e3d094141c..3a6a0e6d90 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1059,10 +1059,10 @@ retry:
 encode_slice_header(f, fs, sc);
 }
 if (f->ac == AC_GOLOMB_RICE) {
-fs->ac_byte_count = f->version > 2 || (!x && !y) ? 
ff_rac_terminate(&sc->c, f->version > 2) : 0;
+sc->ac_byte_count = f->version > 2 || (!x && !y) ? 
ff_rac_terminate(&sc->c, f->version > 2) : 0;
 init_put_bits(&sc->pb,
-  sc->c.bytestream_start + fs->ac_byte_count,
-  sc->c.bytestream_end - sc->c.bytestream_start - 
fs->ac_byte_count);
+  sc->c.bytestream_start + sc->ac_byte_count,
+  sc->c.bytestream_end - sc->c.bytestream_start - 
sc->ac_byte_count);
 }
 
 if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8) {
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 07/39] lavc/ffv1: add a per-slice context

2024-07-16 Thread Anton Khirnov
FFV1 decoder and encoder currently use the same struct - FFV1Context -
both as codec private data and per-slice context. For this purpose
FFV1Context contains an array of pointers to per-slice FFV1Context
instances.

This pattern is highly confusing, as it is not clear which fields are
per-slice and which per-codec.

Address this by adding a new struct storing only per-slice data. Start
by moving slice_{x,y,width,height} to it.
---
 libavcodec/ffv1.c| 15 ++---
 libavcodec/ffv1.h| 13 +---
 libavcodec/ffv1dec.c | 76 
 libavcodec/ffv1enc.c | 25 ---
 4 files changed, 76 insertions(+), 53 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 6ec24fed4a..25f28287c0 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -108,7 +108,12 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 
 av_assert0(max_slice_count > 0);
 
+f->slices = av_calloc(max_slice_count, sizeof(*f->slices));
+if (!f->slices)
+return AVERROR(ENOMEM);
+
 for (i = 0; i < max_slice_count;) {
+FFV1SliceContext *sc = &f->slices[i];
 int sx  = i % f->num_h_slices;
 int sy  = i / f->num_h_slices;
 int sxs = f->avctx->width  *  sx  / f->num_h_slices;
@@ -124,10 +129,10 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 memcpy(fs, f, sizeof(*fs));
 memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2));
 
-fs->slice_width  = sxe - sxs;
-fs->slice_height = sye - sys;
-fs->slice_x  = sxs;
-fs->slice_y  = sys;
+sc->slice_width  = sxe - sxs;
+sc->slice_height = sye - sys;
+sc->slice_x  = sxs;
+sc->slice_y  = sys;
 
 fs->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
   sizeof(*fs->sample_buffer));
@@ -217,5 +222,7 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 for (i = 0; i < s->max_slice_count; i++)
 av_freep(&s->slice_context[i]);
 
+av_freep(&s->slices);
+
 return 0;
 }
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index d99367ce81..256904b283 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -69,6 +69,13 @@ typedef struct PlaneContext {
 
 #define MAX_SLICES 1024
 
+typedef struct FFV1SliceContext {
+int slice_width;
+int slice_height;
+int slice_x;
+int slice_y;
+} FFV1SliceContext;
+
 typedef struct FFV1Context {
 AVClass *class;
 AVCodecContext *avctx;
@@ -123,14 +130,12 @@ typedef struct FFV1Context {
 int max_slice_count;
 int num_v_slices;
 int num_h_slices;
-int slice_width;
-int slice_height;
-int slice_x;
-int slice_y;
 int slice_reset_contexts;
 int slice_coding_mode;
 int slice_rct_by_coef;
 int slice_rct_ry_coef;
+
+FFV1SliceContext *slices;
 } FFV1Context;
 
 int ff_ffv1_common_init(AVCodecContext *avctx);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 6d59355c23..28e4a05b21 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -164,7 +164,7 @@ static int decode_plane(FFV1Context *s, uint8_t *src,
 }
 
 static int decode_slice_header(const FFV1Context *f, FFV1Context *fs,
-   AVFrame *frame)
+   FFV1SliceContext *sc, AVFrame *frame)
 {
 RangeCoder *c = &fs->c;
 uint8_t state[CONTEXT_SIZE];
@@ -185,17 +185,17 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh)
 return AVERROR_INVALIDDATA;
 
-fs->slice_x  =  sx   * (int64_t)f->width  / f->num_h_slices;
-fs->slice_y  =  sy   * (int64_t)f->height / f->num_v_slices;
-fs->slice_width  = (sx + sw) * (int64_t)f->width  / f->num_h_slices - 
fs->slice_x;
-fs->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - 
fs->slice_y;
+sc->slice_x  =  sx   * (int64_t)f->width  / f->num_h_slices;
+sc->slice_y  =  sy   * (int64_t)f->height / f->num_v_slices;
+sc->slice_width  = (sx + sw) * (int64_t)f->width  / f->num_h_slices - 
sc->slice_x;
+sc->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - 
sc->slice_y;
 
-av_assert0((unsigned)fs->slice_width  <= f->width &&
-(unsigned)fs->slice_height <= f->height);
-av_assert0 (   (unsigned)fs->slice_x + (uint64_t)fs->slice_width  <= 
f->width
-&& (unsigned)fs->slice_y + (uint64_t)fs->slice_height <= 
f->height);
+av_assert0((unsigned)sc->slice_width  <= f->width &&
+(unsigned)sc->slice_height <= f->height);
+av_assert0 (   (unsigned)sc->slice_x + (uint64_t)sc->slice_width  <= 
f->width
+&& (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= 
f->height);
 
-if (fs->ac == AC_GOLOMB_RICE && fs->slice_width >= (1<<23))
+if (fs->ac == AC_GOLOMB_RICE && sc->slice_wi

[FFmpeg-devel] [PATCH 36/39] lavc: add private container FIFO API

2024-07-16 Thread Anton Khirnov
It provides a FIFO for "container" objects like AVFrame/AVPacket and
features an integrated FFRefStructPool-based pool to avoid allocating an
freeing them repeatedly.
---
 libavcodec/container_fifo.c | 195 
 libavcodec/container_fifo.h |  87 
 2 files changed, 282 insertions(+)
 create mode 100644 libavcodec/container_fifo.c
 create mode 100644 libavcodec/container_fifo.h

diff --git a/libavcodec/container_fifo.c b/libavcodec/container_fifo.c
new file mode 100644
index 00..86ed15627b
--- /dev/null
+++ b/libavcodec/container_fifo.c
@@ -0,0 +1,195 @@
+/*
+ * 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/error.h"
+#include "libavutil/fifo.h"
+#include "libavutil/frame.h"
+#include "libavutil/mem.h"
+
+#include "container_fifo.h"
+#include "refstruct.h"
+
+struct ContainerFifo {
+AVFifo *fifo;
+FFRefStructPool*pool;
+
+void* (*container_alloc)(void);
+void  (*container_reset)(void *obj);
+void  (*container_free) (void *obj);
+int   (*fifo_write) (void *dst, void *src);
+int   (*fifo_read)  (void *dst, void *src);
+
+};
+
+static int container_fifo_init_entry(FFRefStructOpaque opaque, void *obj)
+{
+ContainerFifo *cf = opaque.nc;
+void **pobj = obj;
+
+*pobj = cf->container_alloc();
+if (!*pobj)
+return AVERROR(ENOMEM);
+
+return 0;
+}
+
+static void container_fifo_reset_entry(FFRefStructOpaque opaque, void *obj)
+{
+ContainerFifo *cf = opaque.nc;
+cf->container_reset(*(void**)obj);
+}
+
+static void container_fifo_free_entry(FFRefStructOpaque opaque, void *obj)
+{
+ContainerFifo *cf = opaque.nc;
+cf->container_free(*(void**)obj);
+}
+
+ContainerFifo*
+ff_container_fifo_alloc(void* (*container_alloc)(void),
+void  (*container_reset)(void *obj),
+void  (*container_free) (void *obj),
+int   (*fifo_write) (void *dst, void *src),
+int   (*fifo_read)  (void *dst, void *src))
+{
+ContainerFifo *cf;
+
+cf = av_mallocz(sizeof(*cf));
+if (!cf)
+return NULL;
+
+cf->container_alloc = container_alloc;
+cf->container_reset = container_reset;
+cf->container_free  = container_free;
+cf->fifo_write  = fifo_write;
+cf->fifo_read   = fifo_read;
+
+cf->fifo = av_fifo_alloc2(1, sizeof(void*), AV_FIFO_FLAG_AUTO_GROW);
+if (!cf->fifo)
+goto fail;
+
+cf->pool = ff_refstruct_pool_alloc_ext(sizeof(void*), 0, cf,
+   container_fifo_init_entry,
+   container_fifo_reset_entry,
+   container_fifo_free_entry,
+   NULL);
+if (!cf->pool)
+goto fail;
+
+return cf;
+fail:
+ff_container_fifo_free(&cf);
+return NULL;
+}
+
+void ff_container_fifo_free(ContainerFifo **pcf)
+{
+ContainerFifo *cf;
+
+if (!*pcf)
+return;
+
+cf = *pcf;
+
+if (cf->fifo) {
+void *obj;
+while (av_fifo_read(cf->fifo, &obj, 1) >= 0)
+ff_refstruct_unref(&obj);
+av_fifo_freep2(&cf->fifo);
+}
+
+ff_refstruct_pool_uninit(&cf->pool);
+
+av_freep(pcf);
+}
+
+int ff_container_fifo_read(ContainerFifo *cf, void *obj)
+{
+void **psrc;
+int ret;
+
+ret = av_fifo_read(cf->fifo, &psrc, 1);
+if (ret < 0)
+return ret;
+
+ret = cf->fifo_read(obj, *psrc);
+ff_refstruct_unref(&psrc);
+
+return ret;
+}
+
+int ff_container_fifo_write(ContainerFifo *cf, void *obj)
+{
+void **pdst;
+int ret;
+
+pdst = ff_refstruct_pool_get(cf->pool);
+if (!pdst)
+return AVERROR(ENOMEM);
+
+ret = cf->fifo_write(*pdst, obj);
+if (ret < 0)
+goto fail;
+
+ret = av_fifo_write(cf->fifo, &pdst, 1);
+if (ret < 0)
+goto fail;
+
+return 0;
+fail:
+ff_refstruct_unref(&pdst);
+return ret;
+}
+
+size_t ff_container_fifo_can_read(ContainerFifo *cf)
+{
+return av_fifo_can_read(cf->fifo);
+}
+
+static void* frame_alloc(void)
+{
+return av_frame_alloc()

[FFmpeg-devel] [PATCH 39/39] lavc/hevcdec: call ff_thread_finish_setup() even if hwaccel is in use

2024-07-16 Thread Anton Khirnov
Serializing frame threading for non-threadsafe hwaccels is handled at the
generic level, the decoder does not need to care about it.
---
 libavcodec/hevc/hevcdec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 28835f48d6..622d9eeb84 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3027,8 +3027,9 @@ static int hevc_frame_start(HEVCContext *s)
 ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0);
 if (ret < 0)
 goto fail;
-} else
-ff_thread_finish_setup(s->avctx);
+}
+
+ff_thread_finish_setup(s->avctx);
 
 return 0;
 
-- 
2.43.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 34/39] lavc/decode: reindent after previous commit

2024-07-16 Thread Anton Khirnov
---
 libavcodec/decode.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index dd94280f0b..deaecf0c01 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -430,20 +430,20 @@ static inline int decode_simple_internal(AVCodecContext 
*avctx, AVFrame *frame,
 
 got_frame = 0;
 
-frame->pict_type = dc->initial_pict_type;
-frame->flags|= dc->intra_only_flag;
-consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
+frame->pict_type = dc->initial_pict_type;
+frame->flags|= dc->intra_only_flag;
+consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
 
-if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
-frame->pkt_dts = pkt->dts;
-if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
+if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
+frame->pkt_dts = pkt->dts;
+if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
 #if FF_API_FRAME_PKT
 FF_DISABLE_DEPRECATION_WARNINGS
-if(!avctx->has_b_frames)
-frame->pkt_pos = pkt->pos;
+if(!avctx->has_b_frames)
+frame->pkt_pos = pkt->pos;
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
-}
+}
 emms_c();
 
 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 04/39] lavc/ffv1dec: drop FFV1Context.cur

2024-07-16 Thread Anton Khirnov
It is merely a pointer to FFV1Context.picture.f, which can just as well
be used directly.
---
 libavcodec/ffv1.h|  1 -
 libavcodec/ffv1dec.c | 33 +
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index acec22e83e..d99367ce81 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -89,7 +89,6 @@ typedef struct FFV1Context {
 ProgressFrame picture, last_picture;
 struct FFV1Context *fsrc;
 
-AVFrame *cur;
 const AVFrame *cur_enc_frame;
 int plane_count;
 int ac;  ///< 1=range coder <-> 0=golomb rice
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 7066146477..60d04f04b9 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -163,7 +163,8 @@ static int decode_plane(FFV1Context *s, uint8_t *src,
 return 0;
 }
 
-static int decode_slice_header(const FFV1Context *f, FFV1Context *fs)
+static int decode_slice_header(const FFV1Context *f, FFV1Context *fs,
+   AVFrame *frame)
 {
 RangeCoder *c = &fs->c;
 uint8_t state[CONTEXT_SIZE];
@@ -217,23 +218,23 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs)
 
 ps = get_symbol(c, state, 0);
 if (ps == 1) {
-f->cur->flags |= AV_FRAME_FLAG_INTERLACED;
-f->cur->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
+frame->flags |= AV_FRAME_FLAG_INTERLACED;
+frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
 } else if (ps == 2) {
-f->cur->flags |= AV_FRAME_FLAG_INTERLACED;
-f->cur->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
+frame->flags |= AV_FRAME_FLAG_INTERLACED;
+frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
 } else if (ps == 3) {
-f->cur->flags &= ~AV_FRAME_FLAG_INTERLACED;
+frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
 }
-f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0);
-f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0);
+frame->sample_aspect_ratio.num = get_symbol(c, state, 0);
+frame->sample_aspect_ratio.den = get_symbol(c, state, 0);
 
 if (av_image_check_sar(f->width, f->height,
-   f->cur->sample_aspect_ratio) < 0) {
+   frame->sample_aspect_ratio) < 0) {
 av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
-   f->cur->sample_aspect_ratio.num,
-   f->cur->sample_aspect_ratio.den);
-f->cur->sample_aspect_ratio = (AVRational){ 0, 1 };
+   frame->sample_aspect_ratio.num,
+   frame->sample_aspect_ratio.den);
+frame->sample_aspect_ratio = (AVRational){ 0, 1 };
 }
 
 if (fs->version > 3) {
@@ -258,7 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 FFV1Context *f= fs->avctx->priv_data;
 int width, height, x, y, ret;
 const int ps  = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
-AVFrame * const p = f->cur;
+AVFrame * const p = f->picture.f;
 const int  si = (FFV1Context**)arg - f->slice_context;
 
 if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
@@ -299,7 +300,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (f->version > 2) {
 if (ff_ffv1_init_slice_state(f, fs) < 0)
 return AVERROR(ENOMEM);
-if (decode_slice_header(f, fs) < 0) {
+if (decode_slice_header(f, fs, p) < 0) {
 fs->slice_x = fs->slice_y = fs->slice_height = fs->slice_width = 0;
 fs->slice_damaged = 1;
 return AVERROR_INVALIDDATA;
@@ -307,7 +308,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0)
 return ret;
-if ((f->cur->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) {
+if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) {
 ff_ffv1_clear_slice_state(f, fs);
 } else if (fs->slice_damaged) {
 return AVERROR_INVALIDDATA;
@@ -920,7 +921,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 if (ret < 0)
 return ret;
 
-f->cur = p = f->picture.f;
+p = f->picture.f;
 
 p->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P
 p->flags = (p->flags & ~AV_FRAME_FLAG_KEY) | key_frame;
-- 
2.43.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 27/39] lavc/ffv1: change FFV1SliceContext.plane into a RefStruct object

2024-07-16 Thread Anton Khirnov
Frame threading in the FFV1 decoder works in a very unusual way - the
state that needs to be propagated from the previous frame is not decoded
pixels(¹), but each slice's entropy coder state after decoding the slice.

For that purpose, the decoder's update_thread_context() callback stores
a pointer to the previous frame thread's private data. Then, when
decoding each slice, the frame thread uses the standard progress
mechanism to wait for the corresponding slice in the previous frame to
be completed, then copies the entropy coder state from the
previously-stored pointer.

This approach is highly dubious, as update_thread_context() should be
the only point where frame-thread contexts come into direct contact.
There are no guarantees that the stored pointer will be valid at all, or
will contain any particular data after update_thread_context() finishes.

More specifically, this code can break due to the fact that keyframes
reset entropy coder state and thus do not need to wait for the previous
frame. As an example, consider a decoder process with 2 frame threads -
thread 0 with its context 0, and thread 1 with context 1 - decoding a
previous frame P, current frame F, followed by a keyframe K. Then
consider concurrent execution consistent with the following sequence of
events:
* thread 0 starts decoding P
* thread 0 reads P's slice header, then calls
  ff_thread_finish_setup() allowing next frame thread to start
* main thread calls update_thread_context() to transfer state from
  context 0 to context 1; context 1 stores a pointer to context 0's private
  data
* thread 1 starts decoding F
* thread 1 reads F's slice header, then calls
  ff_thread_finish_setup() allowing the next frame thread to start
  decoding
* thread 0 finishes decoding P
* thread 0 starts decoding K; since K is a keyframe, it does not
  wait for F and reallocates the arrays holding entropy coder state
* thread 0 finishes decoding K
* thread 1 reads entropy coder state from its stored pointer to context
  0, however it finds state from K rather than from P

This execution is currently prevented by special-casing FFV1 in the
generic frame threading code, however that is supremely ugly. It also
involves unnecessary copies of the state arrays, when in fact they can
only be used by one thread at a time.

This commit addresses these deficiencies by changing the array of
PlaneContext (each of which contains the allocated state arrays)
embedded in FFV1SliceContext into a RefStruct object. This object can
then be propagated across frame threads in standard manner. Since the
code structure guarantees only one thread accesses it at a time, no
copies are necessary. It is also re-created for keyframes, solving the
above issue cleanly.

Special-casing of FFV1 in the generic frame threading code will be
removed in a later commit.

(¹) except in the case of a damaged slice, when previous frame's pixels
are used directly
---
 libavcodec/ffv1.c| 30 --
 libavcodec/ffv1.h|  4 +++-
 libavcodec/ffv1dec.c | 33 +
 3 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 07cf5564cc..9c219b5ddb 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -31,6 +31,7 @@
 
 #include "avcodec.h"
 #include "ffv1.h"
+#include "refstruct.h"
 
 av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
 {
@@ -52,6 +53,24 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
 return 0;
 }
 
+static void planes_free(FFRefStructOpaque opaque, void *obj)
+{
+PlaneContext *planes = obj;
+
+for (int i = 0; i < MAX_PLANES; i++) {
+PlaneContext *p = &planes[i];
+
+av_freep(&p->state);
+av_freep(&p->vlc_state);
+}
+}
+
+PlaneContext* ff_ffv1_planes_alloc(void)
+{
+return ff_refstruct_alloc_ext(sizeof(PlaneContext) * MAX_PLANES,
+  0, NULL, planes_free);
+}
+
 av_cold int ff_ffv1_init_slice_state(const FFV1Context *f,
  FFV1SliceContext *sc)
 {
@@ -132,6 +151,10 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
   sizeof(*sc->sample_buffer32));
 if (!sc->sample_buffer || !sc->sample_buffer32)
 return AVERROR(ENOMEM);
+
+sc->plane = ff_ffv1_planes_alloc();
+if (!sc->plane)
+return AVERROR(ENOMEM);
 }
 
 return 0;
@@ -188,12 +211,7 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 av_freep(&sc->sample_buffer);
 av_freep(&sc->sample_buffer32);
 
-for (i = 0; i < s->plane_count; i++) {
-PlaneContext *p = &sc->plane[i];
-
-av_freep(&p->state);
-av_freep(&p->vlc_state);
-}
+ff_refstruct_unref(&sc->plane);
 }
 
 av_freep(&avctx->stats_out);
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 9d79219921..edc3f6aef0 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ff

[FFmpeg-devel] [PATCH 33/39] lavc: convert frame threading to the receive_frame() pattern

2024-07-16 Thread Anton Khirnov
Reorganize the code such that the frame threading code does not call the
decoders directly, but instead calls back into the generic decoding
code. This avoids duplicating the logic that wraps the decoder
invocation and allows receive_frame()-based decoders to use frame
threading.

Further work by Timo Rothenpieler .
---
 libavcodec/avcodec.c  |   9 +-
 libavcodec/avcodec_internal.h |  25 +--
 libavcodec/decode.c   |  40 +++--
 libavcodec/internal.h |   7 +
 libavcodec/pthread_frame.c| 278 +-
 5 files changed, 235 insertions(+), 124 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 214dca4566..6065f1b689 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -381,10 +381,13 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
 
 avci->draining  = 0;
 avci->draining_done = 0;
-av_frame_unref(avci->buffer_frame);
-av_packet_unref(avci->buffer_pkt);
+if (avci->buffer_frame)
+av_frame_unref(avci->buffer_frame);
+if (avci->buffer_pkt)
+av_packet_unref(avci->buffer_pkt);
 
-if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
+if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME &&
+!avci->is_frame_mt)
 ff_thread_flush(avctx);
 else if (ffcodec(avctx->codec)->flush)
 ffcodec(avctx->codec)->flush(avctx);
diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h
index 816f39ae76..2f0aaab93b 100644
--- a/libavcodec/avcodec_internal.h
+++ b/libavcodec/avcodec_internal.h
@@ -84,16 +84,23 @@ void ff_thread_free(struct AVCodecContext *s);
 void ff_thread_flush(struct AVCodecContext *avctx);
 
 /**
- * Submit a new frame to a decoding thread.
- * Returns the next available frame in picture. *got_picture_ptr
- * will be 0 if none is available.
- * The return value on success is the size of the consumed packet for
- * compatibility with FFCodec.decode. This means the decoder
- * has to consume the full packet.
+ * Submit available packets for decoding to worker threads, return a
+ * decoded frame if available. Returns AVERROR(EAGAIN) if none is available.
  *
- * Parameters are the same as FFCodec.decode.
+ * Parameters are the same as FFCodec.receive_frame.
  */
-int ff_thread_decode_frame(struct AVCodecContext *avctx, struct AVFrame *frame,
-   int *got_picture_ptr, struct AVPacket *avpkt);
+int ff_thread_receive_frame(AVCodecContext *avctx, AVFrame *frame);
+
+/**
+ * Do the actual decoding and obtain a decoded frame from the decoder, if
+ * available. When frame threading is used, this is invoked by the worker
+ * threads, otherwise by the top layer directly.
+ */
+int ff_decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame);
+
+/**
+ * Get a packet for decoding. This gets invoked by the worker threads.
+ */
+int ff_thread_get_packet(AVCodecContext *avctx, AVPacket *pkt);
 
 #endif // AVCODEC_AVCODEC_INTERNAL_H
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 42cee77ec5..dd94280f0b 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -207,6 +207,11 @@ fail:
 return ret;
 }
 
+#if !HAVE_THREADS
+#define ff_thread_get_packet(avctx, pkt) (AVERROR_BUG)
+#define ff_thread_receive_frame(avctx, frame) (AVERROR_BUG)
+#endif
+
 static int decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
 {
 AVCodecInternal *avci = avctx->internal;
@@ -240,6 +245,13 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket 
*pkt)
 if (avci->draining)
 return AVERROR_EOF;
 
+/* If we are a worker thread, get the next packet from the threading
+ * context. Otherwise we are the main (user-facing) context, so we get the
+ * next packet from the input filterchain.
+ */
+if (avctx->internal->is_frame_mt)
+return ff_thread_get_packet(avctx, pkt);
+
 while (1) {
 int ret = decode_get_packet(avctx, pkt);
 if (ret == AVERROR(EAGAIN) &&
@@ -413,15 +425,11 @@ static inline int decode_simple_internal(AVCodecContext 
*avctx, AVFrame *frame,
 return AVERROR_EOF;
 
 if (!pkt->data &&
-!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
-  avctx->active_thread_type & FF_THREAD_FRAME))
+!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
 return AVERROR_EOF;
 
 got_frame = 0;
 
-if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
-consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
-} else {
 frame->pict_type = dc->initial_pict_type;
 frame->flags|= dc->intra_only_flag;
 consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
@@ -436,7 +444,6 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 }
-}
 emms_c();
 
 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
@@ -603,12 +610,12 @@ static int decode_simple_receive_frame(AVCodecContext 
*avctx, AVFrame

[FFmpeg-devel] [PATCH 38/39] lavc/hevcdec: simplify output logic

2024-07-16 Thread Anton Khirnov
Current code is written around the "simple" decode API's limitation that
a single input packet (AU/coded frame) triggers the output of at most
one output frame. However the spec contains two cases where a coded
frame may cause multiple frames to be output (cf. C.5.2.2.2):
* start of a new sequence
* overflowing sps_max_dec_pic_buffering

The decoder currently contains rather convoluted logic to handle these
cases:
* decode/output/per-frame sequence counters,
* HEVC_FRAME_FLAG_BUMPING
* ff_hevc_bump_frame()
* special clauses in ff_hevc_output_frame()

However, with the receive_frame() API none of that is necessary, as we
can just output multiple frames at once. Previously added ContainerFifo
allows that to be done in a straightforward and efficient manner.
---
 libavcodec/hevc/hevcdec.c |  33 +---
 libavcodec/hevc/hevcdec.h |  32 
 libavcodec/hevc/refs.c| 104 +++---
 3 files changed, 42 insertions(+), 127 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 5e28bfe54e..28835f48d6 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2906,6 +2906,7 @@ static int hevc_frame_start(HEVCContext *s)
 const HEVCSPS *const sps = pps->sps;
 int pic_size_in_ctb  = ((sps->width  >> sps->log2_min_cb_size) + 1) *
((sps->height >> sps->log2_min_cb_size) + 1);
+int new_sequence = IS_IDR(s) || IS_BLA(s) || s->last_eos;
 int ret;
 
 ff_refstruct_replace(&s->pps, pps);
@@ -2925,7 +2926,7 @@ static int hevc_frame_start(HEVCContext *s)
 return pix_fmt;
 s->avctx->pix_fmt = pix_fmt;
 
-s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
+new_sequence = 1;
 }
 
 memset(s->horizontal_bs, 0, s->bs_width * s->bs_height);
@@ -2934,11 +2935,8 @@ static int hevc_frame_start(HEVCContext *s)
 memset(s->is_pcm,0, (sps->min_pu_width + 1) * (sps->min_pu_height 
+ 1));
 memset(s->tab_slice_address, -1, pic_size_in_ctb * 
sizeof(*s->tab_slice_address));
 
-if ((IS_IDR(s) || IS_BLA(s))) {
-s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
-if (IS_IDR(s))
-ff_hevc_clear_refs(s);
-}
+if (IS_IDR(s))
+ff_hevc_clear_refs(s);
 
 s->slice_idx = 0;
 s->first_nal_type= s->nal_unit_type;
@@ -2962,6 +2960,12 @@ static int hevc_frame_start(HEVCContext *s)
 if (pps->tiles_enabled_flag)
 s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << 
sps->log2_ctb_size;
 
+if (new_sequence) {
+ret = ff_hevc_output_frames(s, 0, 0, 
s->sh.no_output_of_prior_pics_flag);
+if (ret < 0)
+return ret;
+}
+
 ret = export_stream_params_from_sei(s);
 if (ret < 0)
 return ret;
@@ -3014,10 +3018,8 @@ static int hevc_frame_start(HEVCContext *s)
 
 s->cur_frame->f->pict_type = 3 - s->sh.slice_type;
 
-if (!IS_IRAP(s))
-ff_hevc_bump_frame(s);
-
-ret = ff_hevc_output_frame(s, 0);
+ret = ff_hevc_output_frames(s, sps->temporal_layer[sps->max_sub_layers - 
1].num_reorder_pics,
+sps->temporal_layer[sps->max_sub_layers - 
1].max_dec_pic_buffering, 0);
 if (ret < 0)
 goto fail;
 
@@ -3262,8 +3264,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL 
*nal)
 break;
 case HEVC_NAL_EOS_NUT:
 case HEVC_NAL_EOB_NUT:
-s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
-break;
 case HEVC_NAL_AUD:
 case HEVC_NAL_FD_NUT:
 case HEVC_NAL_UNSPEC62:
@@ -3420,7 +3420,7 @@ static int hevc_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 av_packet_unref(avpkt);
 ret = ff_decode_get_packet(avctx, avpkt);
 if (ret == AVERROR_EOF) {
-ret = ff_hevc_output_frame(s, 1);
+ret = ff_hevc_output_frames(s, 0, 0, 0);
 if (ret < 0)
 return ret;
 goto do_output;
@@ -3482,7 +3482,6 @@ static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame 
*src)
 dst->poc= src->poc;
 dst->ctb_count  = src->ctb_count;
 dst->flags  = src->flags;
-dst->sequence   = src->sequence;
 
 ff_refstruct_replace(&dst->hwaccel_picture_private,
   src->hwaccel_picture_private);
@@ -3606,8 +3605,6 @@ static int hevc_update_thread_context(AVCodecContext *dst,
 if ((ret = set_sps(s, s0->ps.sps)) < 0)
 return ret;
 
-s->seq_decode = s0->seq_decode;
-s->seq_output = s0->seq_output;
 s->poc_tid0   = s0->poc_tid0;
 s->eos= s0->eos;
 s->no_rasl_output_flag = s0->no_rasl_output_flag;
@@ -3617,10 +3614,6 @@ static int hevc_update_thread_context(AVCodecContext 
*dst,
 
 s->film_grain_warning_shown = s0->film_grain_warning_shown;
 
-if (s0->eos) {
-s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
-}
-
 ret = ff_h2645_sei_ctx_replace(&s->sei.com

[FFmpeg-devel] [PATCH 11/39] lavc/ffv1enc: move bit writer to per-slice context

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.h |  3 ++-
 libavcodec/ffv1enc.c  |  7 ---
 libavcodec/ffv1enc_template.c | 14 +++---
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index c88aa8c30d..dce6e177eb 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -79,13 +79,14 @@ typedef struct FFV1SliceContext {
 int slice_y;
 
 int run_index;
+
+PutBitContext pb;
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
 AVClass *class;
 AVCodecContext *avctx;
 RangeCoder c;
-PutBitContext pb;
 uint64_t rc_stat[256][2];
 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
 int version;
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 8bb9174a1d..5692bfa1fc 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1057,7 +1057,7 @@ retry:
 }
 if (fs->ac == AC_GOLOMB_RICE) {
 fs->ac_byte_count = f->version > 2 || (!x && !y) ? 
ff_rac_terminate(&fs->c, f->version > 2) : 0;
-init_put_bits(&fs->pb,
+init_put_bits(&sc->pb,
   fs->c.bytestream_start + fs->ac_byte_count,
   fs->c.bytestream_end - fs->c.bytestream_start - 
fs->ac_byte_count);
 }
@@ -1209,13 +1209,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 buf_p = pkt->data;
 for (i = 0; i < f->slice_count; i++) {
 FFV1Context *fs = f->slice_context[i];
+FFV1SliceContext *sc = &f->slices[i];
 int bytes;
 
 if (fs->ac != AC_GOLOMB_RICE) {
 bytes = ff_rac_terminate(&fs->c, 1);
 } else {
-flush_put_bits(&fs->pb); // FIXME: nicer padding
-bytes = fs->ac_byte_count + put_bytes_output(&fs->pb);
+flush_put_bits(&sc->pb); // FIXME: nicer padding
+bytes = fs->ac_byte_count + put_bytes_output(&sc->pb);
 }
 if (i > 0 || f->version > 2) {
 av_assert0(bytes < pkt->size / f->slice_count);
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index 4dccd531a8..8b9e53fa1b 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -39,7 +39,7 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc,
 return AVERROR_INVALIDDATA;
 }
 } else {
-if (put_bytes_left(&s->pb, 0) < w * 4) {
+if (put_bytes_left(&sc->pb, 0) < w * 4) {
 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
 return AVERROR_INVALIDDATA;
 }
@@ -86,10 +86,10 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc,
 while (run_count >= 1 << ff_log2_run[run_index]) {
 run_count -= 1 << ff_log2_run[run_index];
 run_index++;
-put_bits(&s->pb, 1, 1);
+put_bits(&sc->pb, 1, 1);
 }
 
-put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count);
+put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count);
 if (run_index)
 run_index--;
 run_count = 0;
@@ -103,21 +103,21 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc,
 
 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
 run_count, run_index, run_mode, x,
-(int)put_bits_count(&s->pb));
+(int)put_bits_count(&sc->pb));
 
 if (run_mode == 0)
-put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);
+put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits);
 }
 }
 if (run_mode) {
 while (run_count >= 1 << ff_log2_run[run_index]) {
 run_count -= 1 << ff_log2_run[run_index];
 run_index++;
-put_bits(&s->pb, 1, 1);
+put_bits(&sc->pb, 1, 1);
 }
 
 if (run_count)
-put_bits(&s->pb, 1, 1);
+put_bits(&sc->pb, 1, 1);
 }
 sc->run_index = run_index;
 
-- 
2.43.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 30/39] lavc/internal: document the precise meaning of AVCodecInternal.draining

2024-07-16 Thread Anton Khirnov
Also, set draining=1 in case a bitstream filter returns an
internally-triggered EOF. While no bitstream filters currently inserted
by decoders will do that, that may change in the future and it is better
to cover this case.
---
 libavcodec/decode.c   | 12 +---
 libavcodec/internal.h |  6 +-
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 791940648d..6ad74bd94b 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -213,8 +213,6 @@ static int decode_get_packet(AVCodecContext *avctx, 
AVPacket *pkt)
 int ret;
 
 ret = av_bsf_receive_packet(avci->bsf, pkt);
-if (ret == AVERROR_EOF)
-avci->draining = 1;
 if (ret < 0)
 return ret;
 
@@ -247,14 +245,14 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket 
*pkt)
 if (ret == AVERROR(EAGAIN) &&
 (!AVPACKET_IS_EMPTY(avci->buffer_pkt) || dc->draining_started)) {
 ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
-if (ret < 0) {
-av_packet_unref(avci->buffer_pkt);
-return ret;
-}
+if (ret >= 0)
+continue;
 
-continue;
+av_packet_unref(avci->buffer_pkt);
 }
 
+if (ret == AVERROR_EOF)
+avci->draining = 1;
 return ret;
 }
 }
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index bc20a797ae..d7b0b9f880 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -123,7 +123,11 @@ typedef struct AVCodecInternal {
 void *hwaccel_priv_data;
 
 /**
- * checks API usage: after codec draining, flush is required to resume 
operation
+ * decoding: AVERROR_EOF has been returned from ff_decode_get_packet(); 
must
+ *   not be used by decoders that use the decode() callback, as 
they
+ *   do not call ff_decode_get_packet() directly.
+ *
+ * encoding: a flush frame has been submitted to avcodec_send_frame().
  */
 int draining;
 
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 19/39] lavc/ffv1: move RangeCoder to per-slice context

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.c |  9 ++--
 libavcodec/ffv1.h |  5 +--
 libavcodec/ffv1dec.c  | 72 
 libavcodec/ffv1dec_template.c |  2 +-
 libavcodec/ffv1enc.c  | 78 ++-
 libavcodec/ffv1enc_template.c |  2 +-
 6 files changed, 85 insertions(+), 83 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 7bc4f1b135..490baac233 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -53,7 +53,7 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
 }
 
 av_cold int ff_ffv1_init_slice_state(const FFV1Context *f,
- FFV1Context *fs, FFV1SliceContext *sc)
+ FFV1SliceContext *sc)
 {
 int j, i;
 
@@ -82,8 +82,8 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f,
 if (f->ac == AC_RANGE_CUSTOM_TAB) {
 //FIXME only redo if state_transition changed
 for (j = 1; j < 256; j++) {
-fs->c. one_state[  j] = f->state_transition[j];
-fs->c.zero_state[256 - j] = 256 - fs->c.one_state[j];
+sc->c. one_state[  j] = f->state_transition[j];
+sc->c.zero_state[256 - j] = 256 - sc->c.one_state[j];
 }
 }
 
@@ -94,8 +94,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f)
 {
 int i, ret;
 for (i = 0; i < f->max_slice_count; i++) {
-FFV1Context *fs = f->slice_context[i];
-if ((ret = ff_ffv1_init_slice_state(f, fs, &f->slices[i])) < 0)
+if ((ret = ff_ffv1_init_slice_state(f, &f->slices[i])) < 0)
 return AVERROR(ENOMEM);
 }
 return 0;
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 68e59b300b..01c35dc942 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -83,12 +83,12 @@ typedef struct FFV1SliceContext {
 
 PlaneContext plane[MAX_PLANES];
 PutBitContext pb;
+RangeCoder c;
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
 AVClass *class;
 AVCodecContext *avctx;
-RangeCoder c;
 uint64_t rc_stat[256][2];
 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
 int version;
@@ -138,8 +138,7 @@ typedef struct FFV1Context {
 } FFV1Context;
 
 int ff_ffv1_common_init(AVCodecContext *avctx);
-int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs,
- FFV1SliceContext *sc);
+int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1SliceContext *sc);
 int ff_ffv1_init_slices_state(FFV1Context *f);
 int ff_ffv1_init_slice_contexts(FFV1Context *f);
 int ff_ffv1_allocate_initial_states(FFV1Context *f);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 4d20512643..e0344c996b 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -167,7 +167,7 @@ static int decode_plane(FFV1Context *f,
 static int decode_slice_header(const FFV1Context *f, FFV1Context *fs,
FFV1SliceContext *sc, AVFrame *frame)
 {
-RangeCoder *c = &fs->c;
+RangeCoder *c = &sc->c;
 uint8_t state[CONTEXT_SIZE];
 unsigned ps, context_count;
 int sx, sy, sw, sh;
@@ -298,7 +298,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 sc->slice_rct_ry_coef = 1;
 
 if (f->version > 2) {
-if (ff_ffv1_init_slice_state(f, fs, sc) < 0)
+if (ff_ffv1_init_slice_state(f, sc) < 0)
 return AVERROR(ENOMEM);
 if (decode_slice_header(f, fs, sc, p) < 0) {
 sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0;
@@ -306,7 +306,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 return AVERROR_INVALIDDATA;
 }
 }
-if ((ret = ff_ffv1_init_slice_state(f, fs, sc)) < 0)
+if ((ret = ff_ffv1_init_slice_state(f, sc)) < 0)
 return ret;
 if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) {
 ff_ffv1_clear_slice_state(f, sc);
@@ -321,11 +321,11 @@ static int decode_slice(AVCodecContext *c, void *arg)
 
 if (f->ac == AC_GOLOMB_RICE) {
 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
-get_rac(&fs->c, (uint8_t[]) { 129 });
-fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - 
fs->c.bytestream_start - 1 : 0;
+get_rac(&sc->c, (uint8_t[]) { 129 });
+fs->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - 
sc->c.bytestream_start - 1 : 0;
 init_get_bits(&gb,
-  fs->c.bytestream_start + fs->ac_byte_count,
-  (fs->c.bytestream_end - fs->c.bytestream_start - 
fs->ac_byte_count) * 8);
+  sc->c.bytestream_start + fs->ac_byte_count,
+  (sc->c.bytestream_end - sc->c.bytestream_start - 
fs->ac_byte_count) * 8);
 }
 
 av_assert1(width && height);
@@ -360,8 +360,8 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 if (f->ac != AC_GOLOMB_RICE && f->version > 2) {
 int v;
-get_rac

[FFmpeg-devel] [PATCH 37/39] lavc/hevcdec: use a ContainerFifo to hold frames scheduled for output

2024-07-16 Thread Anton Khirnov
Instead of a single AVFrame.

Will be useful in future commits, where we will want to produce multiple
output frames for a single coded frame.
---
 libavcodec/Makefile   |  2 +-
 libavcodec/hevc/hevcdec.c | 30 --
 libavcodec/hevc/hevcdec.h |  5 +++--
 libavcodec/hevc/refs.c| 11 +++
 4 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 771e2b597e..e67b729bd3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -431,7 +431,7 @@ OBJS-$(CONFIG_HCA_DECODER) += hcadec.o
 OBJS-$(CONFIG_HCOM_DECODER)+= hcom.o
 OBJS-$(CONFIG_HDR_DECODER) += hdrdec.o
 OBJS-$(CONFIG_HDR_ENCODER) += hdrenc.o
-OBJS-$(CONFIG_HEVC_DECODER)+= aom_film_grain.o h274.o
+OBJS-$(CONFIG_HEVC_DECODER)+= aom_film_grain.o h274.o 
container_fifo.o
 OBJS-$(CONFIG_HEVC_AMF_ENCODER)+= amfenc_hevc.o
 OBJS-$(CONFIG_HEVC_CUVID_DECODER)  += cuviddec.o
 OBJS-$(CONFIG_HEVC_D3D12VA_ENCODER)+= d3d12va_encode_hevc.o 
h265_profile_level.o \
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index fc87169a1a..5e28bfe54e 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3006,6 +3006,10 @@ static int hevc_frame_start(HEVCContext *s)
 s->cur_frame->frame_grain->height = s->cur_frame->f->height;
 if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 
0)) < 0)
 goto fail;
+
+ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f);
+if (ret < 0)
+goto fail;
 }
 
 s->cur_frame->f->pict_type = 3 - s->sh.slice_type;
@@ -3013,8 +3017,7 @@ static int hevc_frame_start(HEVCContext *s)
 if (!IS_IRAP(s))
 ff_hevc_bump_frame(s);
 
-av_frame_unref(s->output_frame);
-ret = ff_hevc_output_frame(s, s->output_frame, 0);
+ret = ff_hevc_output_frame(s, 0);
 if (ret < 0)
 goto fail;
 
@@ -3411,13 +3414,16 @@ static int hevc_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 uint8_t *sd;
 size_t sd_size;
 
+if (ff_container_fifo_can_read(s->output_fifo))
+goto do_output;
+
 av_packet_unref(avpkt);
 ret = ff_decode_get_packet(avctx, avpkt);
 if (ret == AVERROR_EOF) {
-ret = ff_hevc_output_frame(s, frame, 1);
+ret = ff_hevc_output_frame(s, 1);
 if (ret < 0)
 return ret;
-return (ret > 0) ? 0 : AVERROR_EOF;
+goto do_output;
 } else if (ret < 0)
 return ret;
 
@@ -3442,12 +3448,15 @@ static int hevc_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 if (ret < 0)
 return ret;
 
-if (s->output_frame->buf[0]) {
-av_frame_move_ref(frame, s->output_frame);
+do_output:
+if (ff_container_fifo_read(s->output_fifo, frame) >= 0) {
+if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))
+av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
+
 return 0;
 }
 
-return AVERROR(EAGAIN);
+return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN);
 }
 
 static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
@@ -3499,7 +3508,8 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
 av_freep(&s->sao_pixel_buffer_h[i]);
 av_freep(&s->sao_pixel_buffer_v[i]);
 }
-av_frame_free(&s->output_frame);
+
+ff_container_fifo_free(&s->output_fifo);
 
 for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
 ff_hevc_unref_frame(&s->DPB[i], ~0);
@@ -3537,8 +3547,8 @@ static av_cold int hevc_init_context(AVCodecContext 
*avctx)
 s->local_ctx[0].logctx = avctx;
 s->local_ctx[0].common_cabac_state = &s->cabac;
 
-s->output_frame = av_frame_alloc();
-if (!s->output_frame)
+s->output_fifo = ff_container_fifo_alloc_avframe(0);
+if (!s->output_fifo)
 return AVERROR(ENOMEM);
 
 for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index da4d83e661..f2705b8de2 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -31,6 +31,7 @@
 #include "libavcodec/avcodec.h"
 #include "libavcodec/bswapdsp.h"
 #include "libavcodec/cabac.h"
+#include "libavcodec/container_fifo.h"
 #include "libavcodec/dovi_rpu.h"
 #include "libavcodec/get_bits.h"
 #include "libavcodec/h2645_parse.h"
@@ -457,7 +458,7 @@ typedef struct HEVCContext {
 /** 1 if the independent slice segment header was successfully parsed */
 uint8_t slice_initialized;
 
-AVFrame *output_frame;
+ContainerFifo *output_fifo;
 uint8_t *sao_pixel_buffer_h[3];
 uint8_t *sao_pixel_buffer_v[3];
 
@@ -636,7 +637,7 @@ static av_always_inline int ff_hevc_nal_is_nonref(enum 
HEVCNALUnitType type)
  * Find next frame in output order and put a reference to it in frame.
  * @return 1 if a frame was output, 0 otherwise
  */
-int ff_hevc_output_frame(HEVCContext *s, A

[FFmpeg-devel] [PATCH 32/39] lavc/decode: reindent

2024-07-16 Thread Anton Khirnov
---
 libavcodec/decode.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index b17cfba26f..42cee77ec5 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -614,21 +614,21 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 
 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
 while (1) {
-frame->pict_type = dc->initial_pict_type;
-frame->flags|= dc->intra_only_flag;
-ret = codec->cb.receive_frame(avctx, frame);
-emms_c();
-if (!ret) {
-if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
-int64_t discarded_samples = 0;
-ret = discard_samples(avctx, frame, &discarded_samples);
+frame->pict_type = dc->initial_pict_type;
+frame->flags|= dc->intra_only_flag;
+ret = codec->cb.receive_frame(avctx, frame);
+emms_c();
+if (!ret) {
+if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
+int64_t discarded_samples = 0;
+ret = discard_samples(avctx, frame, &discarded_samples);
+}
+if (ret == AVERROR(EAGAIN) || (frame->flags & 
AV_FRAME_FLAG_DISCARD)) {
+av_frame_unref(frame);
+continue;
+}
 }
-if (ret == AVERROR(EAGAIN) || (frame->flags & 
AV_FRAME_FLAG_DISCARD)) {
-av_frame_unref(frame);
-continue;
-}
-}
-break;
+break;
 }
 } else
 ret = decode_simple_receive_frame(avctx, frame);
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 09/39] lavc/ffv1: move run_index to the per-slice context

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.h |  3 ++-
 libavcodec/ffv1dec.c  |  6 +++---
 libavcodec/ffv1dec_template.c | 16 
 libavcodec/ffv1enc.c  |  6 +++---
 libavcodec/ffv1enc_template.c | 16 
 5 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index ccb510a483..68d13a2964 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -77,6 +77,8 @@ typedef struct FFV1SliceContext {
 int slice_height;
 int slice_x;
 int slice_y;
+
+int run_index;
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
@@ -109,7 +111,6 @@ typedef struct FFV1Context {
 int context_count[MAX_QUANT_TABLES];
 uint8_t state_transition[256];
 uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
-int run_index;
 int colorspace;
 
 int use32bit;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index fcf8977a36..a2971d7eea 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -126,7 +126,7 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 sample[0] = sc->sample_buffer + 3;
 sample[1] = sc->sample_buffer + w + 6 + 3;
 
-s->run_index = 0;
+sc->run_index = 0;
 
 memset(sc->sample_buffer, 0, 2 * (w + 6) * sizeof(*sc->sample_buffer));
 
@@ -140,13 +140,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 sample[0][w]  = sample[0][w - 1];
 
 if (s->avctx->bits_per_raw_sample <= 8) {
-int ret = decode_line(s, w, sample, plane_index, 8);
+int ret = decode_line(s, sc, w, sample, plane_index, 8);
 if (ret < 0)
 return ret;
 for (x = 0; x < w; x++)
 src[x*pixel_stride + stride * y] = sample[1][x];
 } else {
-int ret = decode_line(s, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
+int ret = decode_line(s, sc, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
 if (ret < 0)
 return ret;
 if (s->packed_at_lsb) {
diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index b9316e04ca..8e2e38c0b9 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -22,16 +22,16 @@
 
 #include "ffv1_template.c"
 
-static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
- TYPE *sample[2],
- int plane_index, int bits)
+static av_always_inline int
+RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w,
+TYPE *sample[2], int plane_index, int bits)
 {
 PlaneContext *const p = &s->plane[plane_index];
 RangeCoder *const c   = &s->c;
 int x;
 int run_count = 0;
 int run_mode  = 0;
-int run_index = s->run_index;
+int run_index = sc->run_index;
 
 if (is_input_end(s))
 return AVERROR_INVALIDDATA;
@@ -123,7 +123,7 @@ static av_always_inline int RENAME(decode_line)(FFV1Context 
*s, int w,
 
 sample[1][x] = av_zero_extend(RENAME(predict)(sample[1] + x, sample[0] 
+ x) + (SUINT)diff, bits);
 }
-s->run_index = run_index;
+sc->run_index = run_index;
 return 0;
 }
 
@@ -142,7 +142,7 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, 
FFV1SliceContext *sc,
 sample[x][1] = RENAME(sc->sample_buffer) + (x * 2 + 1) * (w + 6) + 3;
 }
 
-s->run_index = 0;
+sc->run_index = 0;
 
 memset(RENAME(sc->sample_buffer), 0, 8 * (w + 6) * 
sizeof(*RENAME(sc->sample_buffer)));
 
@@ -157,9 +157,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, 
FFV1SliceContext *sc,
 sample[p][1][-1]= sample[p][0][0  ];
 sample[p][0][ w]= sample[p][0][w-1];
 if (lbd && s->slice_coding_mode == 0)
-ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9);
+ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, 9);
 else
-ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + 
(s->slice_coding_mode != 1));
+ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, bits 
+ (s->slice_coding_mode != 1));
 if (ret < 0)
 return ret;
 }
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index f6b1919ee4..8bb9174a1d 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -276,7 +276,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 int x, y, i, ret;
 const int ring_size = s->context_model ? 3 : 2;
 int16_t *sample[3];
-s->run_index = 0;
+sc->run_index = 0;
 
 memset(sc->sample_buffer, 0, ring_size * (w + 6) * 
sizeof(*sc->sample_buffer));
 
@@ -289,7 +289,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 if (s->bits_per_raw_sample <= 8) {
 for (x = 0; x < w; x++)
 sample[0][x] = src[x * pixel_stride + stride 

[FFmpeg-devel] [PATCH 18/39] lavc/ffv1: move FFV1Context.plane to per-slice context

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.c | 17 +++--
 libavcodec/ffv1.h |  7 ---
 libavcodec/ffv1dec.c  | 16 
 libavcodec/ffv1dec_template.c |  2 +-
 libavcodec/ffv1enc.c  | 29 -
 libavcodec/ffv1enc_template.c |  2 +-
 6 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 581e775ae2..7bc4f1b135 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -52,12 +52,13 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
 return 0;
 }
 
-av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs)
+av_cold int ff_ffv1_init_slice_state(const FFV1Context *f,
+ FFV1Context *fs, FFV1SliceContext *sc)
 {
 int j, i;
 
 for (j = 0; j < f->plane_count; j++) {
-PlaneContext *const p = &fs->plane[j];
+PlaneContext *const p = &sc->plane[j];
 
 if (f->ac != AC_GOLOMB_RICE) {
 if (!p->state)
@@ -94,7 +95,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f)
 int i, ret;
 for (i = 0; i < f->max_slice_count; i++) {
 FFV1Context *fs = f->slice_context[i];
-if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0)
+if ((ret = ff_ffv1_init_slice_state(f, fs, &f->slices[i])) < 0)
 return AVERROR(ENOMEM);
 }
 return 0;
@@ -160,12 +161,12 @@ int ff_ffv1_allocate_initial_states(FFV1Context *f)
 return 0;
 }
 
-void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs)
+void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc)
 {
 int i, j;
 
 for (i = 0; i < f->plane_count; i++) {
-PlaneContext *p = &fs->plane[i];
+PlaneContext *p = &sc->plane[i];
 
 if (f->ac != AC_GOLOMB_RICE) {
 if (f->initial_states[p->quant_table_index]) {
@@ -191,17 +192,13 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 int i, j;
 
 for (j = 0; j < s->max_slice_count; j++) {
-FFV1Context *fs = s->slice_context[j];
 FFV1SliceContext *sc = &s->slices[j];
 
 av_freep(&sc->sample_buffer);
 av_freep(&sc->sample_buffer32);
 
-if (!fs)
-continue;
-
 for (i = 0; i < s->plane_count; i++) {
-PlaneContext *p = &fs->plane[i];
+PlaneContext *p = &sc->plane[i];
 
 av_freep(&p->state);
 av_freep(&p->vlc_state);
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index e466aedbbe..68e59b300b 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -81,6 +81,7 @@ typedef struct FFV1SliceContext {
 int slice_rct_by_coef;
 int slice_rct_ry_coef;
 
+PlaneContext plane[MAX_PLANES];
 PutBitContext pb;
 } FFV1SliceContext;
 
@@ -106,7 +107,6 @@ typedef struct FFV1Context {
 int plane_count;
 int ac;  ///< 1=range coder <-> 0=golomb rice
 int ac_byte_count;   ///< number of bytes used for AC 
coding
-PlaneContext plane[MAX_PLANES];
 int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
 int context_count[MAX_QUANT_TABLES];
 uint8_t state_transition[256];
@@ -138,11 +138,12 @@ typedef struct FFV1Context {
 } FFV1Context;
 
 int ff_ffv1_common_init(AVCodecContext *avctx);
-int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs);
+int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs,
+ FFV1SliceContext *sc);
 int ff_ffv1_init_slices_state(FFV1Context *f);
 int ff_ffv1_init_slice_contexts(FFV1Context *f);
 int ff_ffv1_allocate_initial_states(FFV1Context *f);
-void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs);
+void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc);
 int ff_ffv1_close(AVCodecContext *avctx);
 
 static av_always_inline int fold(int diff, int bits)
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 133baa895a..4d20512643 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -200,7 +200,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 return AVERROR_INVALIDDATA;
 
 for (unsigned i = 0; i < f->plane_count; i++) {
-PlaneContext * const p = &fs->plane[i];
+PlaneContext * const p = &sc->plane[i];
 int idx = get_symbol(c, state, 0);
 if (idx >= (unsigned)f->quant_table_count) {
 av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n");
@@ -269,13 +269,14 @@ static int decode_slice(AVCodecContext *c, void *arg)
 
 if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
 FFV1Context *fssrc = f->fsrc->slice_context[si];
+const FFV1SliceContext *scsrc = &f->fsrc->slices[si];
 
 if (!(p->flags & AV_FRAME_FLAG_KEY))
 fs->slice_damaged |= fssrc->slice_damaged;
 
 for (int i = 0; i < f->plane_count; i++) {
-PlaneContext *psrc = &fssrc->plane[i];
-

[FFmpeg-devel] [PATCH 28/39] lavc/ffv1dec: fix races in accessing FFV1SliceContext.slice_damaged

2024-07-16 Thread Anton Khirnov
That variable is shared between frame threads in the same defective way
described in the previous commit. Fix it by adding a RefStruct-managed
arrays of flags that is propagated across frame threads in the standard
manner.

Remove now-unused FFV1Context.fsrc
---
 libavcodec/ffv1.c|  2 ++
 libavcodec/ffv1.h|  3 ++-
 libavcodec/ffv1dec.c | 24 ++--
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 9c219b5ddb..333fb3d79b 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -214,6 +214,8 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 ff_refstruct_unref(&sc->plane);
 }
 
+ff_refstruct_unref(&s->slice_damaged);
+
 av_freep(&avctx->stats_out);
 for (j = 0; j < s->quant_table_count; j++) {
 av_freep(&s->initial_states[j]);
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index edc3f6aef0..ae62732650 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -118,7 +118,6 @@ typedef struct FFV1Context {
 int64_t picture_number;
 int key_frame;
 ProgressFrame picture, last_picture;
-struct FFV1Context *fsrc;
 
 const AVFrame *cur_enc_frame;
 int plane_count;
@@ -148,6 +147,8 @@ typedef struct FFV1Context {
 int num_h_slices;
 
 FFV1SliceContext *slices;
+// RefStruct object, per-slice damage flags
+uint8_t  *slice_damaged;
 } FFV1Context;
 
 int ff_ffv1_common_init(AVCodecContext *avctx);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 7dc4a537a9..c9ac850d98 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -263,16 +263,9 @@ static int decode_slice(AVCodecContext *c, void *arg)
 const int  si = sc - f->slices;
 GetBitContext gb;
 
-if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
+if (!(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
 ff_progress_frame_await(&f->last_picture, si);
 
-if (f->fsrc) {
-const FFV1SliceContext *scsrc = &f->fsrc->slices[si];
-
-if (!(p->flags & AV_FRAME_FLAG_KEY))
-sc->slice_damaged |= scsrc->slice_damaged;
-}
-
 sc->slice_rct_by_coef = 1;
 sc->slice_rct_ry_coef = 1;
 
@@ -347,6 +340,8 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 }
 
+f->slice_damaged[si] = sc->slice_damaged;
+
 ff_progress_frame_report(&f->picture, si);
 
 return 0;
@@ -767,11 +762,14 @@ static int read_header(FFV1Context *f)
 return AVERROR_INVALIDDATA;
 }
 
+ff_refstruct_unref(&f->slice_damaged);
+f->slice_damaged = ff_refstruct_allocz(f->slice_count * 
sizeof(*f->slice_damaged));
+if (!f->slice_damaged)
+return AVERROR(ENOMEM);
+
 for (int j = 0; j < f->slice_count; j++) {
 FFV1SliceContext *sc = &f->slices[j];
 
-sc->slice_damaged = 0;
-
 if (f->version == 2) {
 int sx = get_symbol(c, state, 0);
 int sy = get_symbol(c, state, 0);
@@ -1041,8 +1039,6 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
 FFV1SliceContext   *sc  = &fdst->slices[i];
 const FFV1SliceContext *sc0 = &fsrc->slices[i];
 
-sc->slice_damaged = sc0->slice_damaged;
-
 ff_refstruct_replace(&sc->plane, sc0->plane);
 
 if (fsrc->version < 3) {
@@ -1053,12 +1049,12 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
 }
 }
 
+ff_refstruct_replace(&fdst->slice_damaged, fsrc->slice_damaged);
+
 av_assert1(fdst->max_slice_count == fsrc->max_slice_count);
 
 ff_progress_frame_replace(&fdst->picture, &fsrc->picture);
 
-fdst->fsrc = fsrc;
-
 return 0;
 }
 #endif
-- 
2.43.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 01/39] tests/fate/vcodec: add vsynth tests for FFV1 version 2

2024-07-16 Thread Anton Khirnov
---
 tests/fate/vcodec.mak| 3 ++-
 tests/ref/vsynth/vsynth1-ffv1-v2 | 4 
 tests/ref/vsynth/vsynth2-ffv1-v2 | 4 
 tests/ref/vsynth/vsynth3-ffv1-v2 | 4 
 tests/ref/vsynth/vsynth_lena-ffv1-v2 | 4 
 5 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 tests/ref/vsynth/vsynth1-ffv1-v2
 create mode 100644 tests/ref/vsynth/vsynth2-ffv1-v2
 create mode 100644 tests/ref/vsynth/vsynth3-ffv1-v2
 create mode 100644 tests/ref/vsynth/vsynth_lena-ffv1-v2

diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak
index abdc481f8a..b9829be027 100644
--- a/tests/fate/vcodec.mak
+++ b/tests/fate/vcodec.mak
@@ -154,13 +154,14 @@ $(FATE_VCODEC_DV:%=fate-vsynth\%-%): CODEC= dvvideo
 $(FATE_VCODEC_DV:%=fate-vsynth\%-%): FMT  = dv
 $(FATE_VCODEC_DV:%=fate-vsynth\%-%): DECOPTS += $(DEFAULT_SIZE)
 
-FATE_VCODEC-$(call ENCDEC, FFV1, AVI)   += ffv1 ffv1-v0 \
+FATE_VCODEC-$(call ENCDEC, FFV1, AVI)   += ffv1 ffv1-v0 ffv1-v2 \
ffv1-v3-yuv420p \
ffv1-2pass
 FATE_VCODEC_SCALE-$(call ENCDEC, FFV1, AVI) += ffv1-v3-yuv422p10 
ffv1-v3-yuv444p16 \
ffv1-v3-bgr0 ffv1-v3-rgb48
 fate-vsynth%-ffv1:   ENCOPTS = -slices 4
 fate-vsynth%-ffv1-v0:CODEC   = ffv1
+fate-vsynth%-ffv1-v2:ENCOPTS = -level 2 -strict experimental
 fate-vsynth%-ffv1-v3-yuv420p:ENCOPTS = -level 3 -pix_fmt yuv420p
 fate-vsynth%-ffv1-v3-yuv422p10:  ENCOPTS = -level 3 -pix_fmt yuv422p10 \
-sws_flags neighbor+bitexact
diff --git a/tests/ref/vsynth/vsynth1-ffv1-v2 b/tests/ref/vsynth/vsynth1-ffv1-v2
new file mode 100644
index 00..69536fb390
--- /dev/null
+++ b/tests/ref/vsynth/vsynth1-ffv1-v2
@@ -0,0 +1,4 @@
+0f9298229cf53ce257648ccec70c893f *tests/data/fate/vsynth1-ffv1-v2.avi
+2689724 tests/data/fate/vsynth1-ffv1-v2.avi
+c5ccac874dbf808e9088bc3107860042 *tests/data/fate/vsynth1-ffv1-v2.out.rawvideo
+stddev:0.00 PSNR:999.99 MAXDIFF:0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ffv1-v2 b/tests/ref/vsynth/vsynth2-ffv1-v2
new file mode 100644
index 00..0b3f288f8f
--- /dev/null
+++ b/tests/ref/vsynth/vsynth2-ffv1-v2
@@ -0,0 +1,4 @@
+3144d06b9af1af98d072ccf05ff116ba *tests/data/fate/vsynth2-ffv1-v2.avi
+3716500 tests/data/fate/vsynth2-ffv1-v2.avi
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-ffv1-v2.out.rawvideo
+stddev:0.00 PSNR:999.99 MAXDIFF:0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth3-ffv1-v2 b/tests/ref/vsynth/vsynth3-ffv1-v2
new file mode 100644
index 00..3b0397ec02
--- /dev/null
+++ b/tests/ref/vsynth/vsynth3-ffv1-v2
@@ -0,0 +1,4 @@
+72f1126e9e270f019d90f74959bcf0cb *tests/data/fate/vsynth3-ffv1-v2.avi
+60648 tests/data/fate/vsynth3-ffv1-v2.avi
+a038ad7c3c09f776304ef7accdea9c74 *tests/data/fate/vsynth3-ffv1-v2.out.rawvideo
+stddev:0.00 PSNR:999.99 MAXDIFF:0 bytes:86700/86700
diff --git a/tests/ref/vsynth/vsynth_lena-ffv1-v2 
b/tests/ref/vsynth/vsynth_lena-ffv1-v2
new file mode 100644
index 00..5f180462b5
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ffv1-v2
@@ -0,0 +1,4 @@
+4a0dbd5b50fa68fc7d5a8d6d64bd695a *tests/data/fate/vsynth_lena-ffv1-v2.avi
+3546264 tests/data/fate/vsynth_lena-ffv1-v2.avi
+dde5895817ad9d219f79a52d0bdfb001 
*tests/data/fate/vsynth_lena-ffv1-v2.out.rawvideo
+stddev:0.00 PSNR:999.99 MAXDIFF:0 bytes:  7603200/  7603200
-- 
2.43.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 25/39] lavc/ffv1dec: stop using per-slice FFV1Context

2024-07-16 Thread Anton Khirnov
All remaining accesses to them are for fields that have the same value
in the main encoder context.

Drop now-unused FFV1Context.slice_contexts.
---
 libavcodec/ffv1.c | 18 +++-
 libavcodec/ffv1.h |  1 -
 libavcodec/ffv1dec.c  | 54 ++-
 libavcodec/ffv1dec_template.c | 16 +--
 4 files changed, 33 insertions(+), 56 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 4ef04f6b9b..07cf5564cc 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -102,7 +102,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f)
 
 av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 {
-int i, max_slice_count = f->num_h_slices * f->num_v_slices;
+int max_slice_count = f->num_h_slices * f->num_v_slices;
 
 av_assert0(max_slice_count > 0);
 
@@ -112,7 +112,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 
 f->max_slice_count = max_slice_count;
 
-for (i = 0; i < max_slice_count;) {
+for (int i = 0; i < max_slice_count; i++) {
 FFV1SliceContext *sc = &f->slices[i];
 int sx  = i % f->num_h_slices;
 int sy  = i / f->num_h_slices;
@@ -120,22 +120,15 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 int sxe = f->avctx->width  * (sx + 1) / f->num_h_slices;
 int sys = f->avctx->height *  sy  / f->num_v_slices;
 int sye = f->avctx->height * (sy + 1) / f->num_v_slices;
-FFV1Context *fs = av_mallocz(sizeof(*fs));
-
-if (!fs)
-return AVERROR(ENOMEM);
-
-f->slice_context[i++] = fs;
-memcpy(fs, f, sizeof(*fs));
 
 sc->slice_width  = sxe - sxs;
 sc->slice_height = sye - sys;
 sc->slice_x  = sxs;
 sc->slice_y  = sys;
 
-sc->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
+sc->sample_buffer = av_malloc_array((f->width + 6), 3 * MAX_PLANES *
 sizeof(*sc->sample_buffer));
-sc->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
+sc->sample_buffer32 = av_malloc_array((f->width + 6), 3 * MAX_PLANES *
   sizeof(*sc->sample_buffer32));
 if (!sc->sample_buffer || !sc->sample_buffer32)
 return AVERROR(ENOMEM);
@@ -213,9 +206,6 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 av_freep(&s->rc_stat2[j]);
 }
 
-for (i = 0; i < s->max_slice_count; i++)
-av_freep(&s->slice_context[i]);
-
 av_freep(&s->slices);
 
 return 0;
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index c4803654f2..9d79219921 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -141,7 +141,6 @@ typedef struct FFV1Context {
 int gob_count;
 int quant_table_count;
 
-struct FFV1Context *slice_context[MAX_SLICES];
 int slice_count;
 int max_slice_count;
 int num_v_slices;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index bd46930ec7..8bb9b83daa 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -116,8 +116,7 @@ static int is_input_end(RangeCoder *c, GetBitContext *gb, 
int ac)
 #define RENAME(name) name ## 32
 #include "ffv1dec_template.c"
 
-static int decode_plane(FFV1Context *f,
-FFV1Context *s, FFV1SliceContext *sc,
+static int decode_plane(FFV1Context *f, FFV1SliceContext *sc,
 GetBitContext *gb,
 uint8_t *src, int w, int h, int stride, int 
plane_index,
  int pixel_stride)
@@ -140,23 +139,23 @@ static int decode_plane(FFV1Context *f,
 sample[1][-1] = sample[0][0];
 sample[0][w]  = sample[0][w - 1];
 
-if (s->avctx->bits_per_raw_sample <= 8) {
-int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8);
+if (f->avctx->bits_per_raw_sample <= 8) {
+int ret = decode_line(f, sc, gb, w, sample, plane_index, 8);
 if (ret < 0)
 return ret;
 for (x = 0; x < w; x++)
 src[x*pixel_stride + stride * y] = sample[1][x];
 } else {
-int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
+int ret = decode_line(f, sc, gb, w, sample, plane_index, 
f->avctx->bits_per_raw_sample);
 if (ret < 0)
 return ret;
-if (s->packed_at_lsb) {
+if (f->packed_at_lsb) {
 for (x = 0; x < w; x++) {
 ((uint16_t*)(src + stride*y))[x*pixel_stride] = 
sample[1][x];
 }
 } else {
 for (x = 0; x < w; x++) {
-((uint16_t*)(src + stride*y))[x*pixel_stride] = 
sample[1][x] << (16 - s->avctx->bits_per_raw_sample) | ((uint16_t 
**)sample)[1][x] >> (2 * s->avctx->bits_per_raw_sample - 16);
+((uint16_t*

[FFmpeg-devel] [PATCH 10/39] lavc/ffv1dec: move the bitreader to stack

2024-07-16 Thread Anton Khirnov
There is no reason to place it in persistent state.
---
 libavcodec/ffv1.h |  1 -
 libavcodec/ffv1dec.c  | 28 +++-
 libavcodec/ffv1dec_template.c | 23 ---
 3 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 68d13a2964..c88aa8c30d 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -85,7 +85,6 @@ typedef struct FFV1Context {
 AVClass *class;
 AVCodecContext *avctx;
 RangeCoder c;
-GetBitContext gb;
 PutBitContext pb;
 uint64_t rc_stat[256][2];
 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index a2971d7eea..a1f7206871 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -94,14 +94,14 @@ static inline int get_vlc_symbol(GetBitContext *gb, 
VlcState *const state,
 return ret;
 }
 
-static int is_input_end(FFV1Context *s)
+static int is_input_end(FFV1Context *s, GetBitContext *gb)
 {
 if (s->ac != AC_GOLOMB_RICE) {
 RangeCoder *const c = &s->c;
 if (c->overread > MAX_OVERREAD)
 return AVERROR_INVALIDDATA;
 } else {
-if (get_bits_left(&s->gb) < 1)
+if (get_bits_left(gb) < 1)
 return AVERROR_INVALIDDATA;
 }
 return 0;
@@ -118,6 +118,7 @@ static int is_input_end(FFV1Context *s)
 #include "ffv1dec_template.c"
 
 static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,
+GetBitContext *gb,
 uint8_t *src, int w, int h, int stride, int 
plane_index,
  int pixel_stride)
 {
@@ -140,13 +141,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 sample[0][w]  = sample[0][w - 1];
 
 if (s->avctx->bits_per_raw_sample <= 8) {
-int ret = decode_line(s, sc, w, sample, plane_index, 8);
+int ret = decode_line(s, sc, gb, w, sample, plane_index, 8);
 if (ret < 0)
 return ret;
 for (x = 0; x < w; x++)
 src[x*pixel_stride + stride * y] = sample[1][x];
 } else {
-int ret = decode_line(s, sc, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
+int ret = decode_line(s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
 if (ret < 0)
 return ret;
 if (s->packed_at_lsb) {
@@ -262,6 +263,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 AVFrame * const p = f->picture.f;
 const int  si = (FFV1Context**)arg - f->slice_context;
 FFV1SliceContext *sc = &f->slices[si];
+GetBitContext gb;
 
 if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
 ff_progress_frame_await(&f->last_picture, si);
@@ -322,7 +324,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
 get_rac(&fs->c, (uint8_t[]) { 129 });
 fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - 
fs->c.bytestream_start - 1 : 0;
-init_get_bits(&fs->gb,
+init_get_bits(&gb,
   fs->c.bytestream_start + fs->ac_byte_count,
   (fs->c.bytestream_end - fs->c.bytestream_start - 
fs->ac_byte_count) * 8);
 }
@@ -333,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg)
 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
 const int cx= x >> f->chroma_h_shift;
 const int cy= y >> f->chroma_v_shift;
-decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, 
height, p->linesize[0], 0, 1);
+decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, 
height, p->linesize[0], 0, 1);
 
 if (f->chroma_planes) {
-decode_plane(fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], 
chroma_width, chroma_height, p->linesize[1], 1, 1);
-decode_plane(fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], 
chroma_width, chroma_height, p->linesize[2], 1, 1);
+decode_plane(fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], 
chroma_width, chroma_height, p->linesize[1], 1, 1);
+decode_plane(fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], 
chroma_width, chroma_height, p->linesize[2], 1, 1);
 }
 if (fs->transparency)
-decode_plane(fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, 
height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1);
+decode_plane(fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], 
width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 
1);
 } else if (f->colorspace == 0) {
- decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, 
height, p->linesize[0], 0, 2);
- decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0] + 1, width, 
h

[FFmpeg-devel] [PATCH 26/39] lavc/ffv1dec: inline copy_fields() into update_thread_context()

2024-07-16 Thread Anton Khirnov
It is now only called from a single place, so there is no point in it
being a separate function.
---
 libavcodec/ffv1dec.c | 38 --
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 8bb9b83daa..be4a1a2bf3 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -1021,27 +1021,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 }
 
 #if HAVE_THREADS
-static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc,
-const FFV1Context *fsrc)
-{
-fsdst->version = fsrc->version;
-fsdst->micro_version   = fsrc->micro_version;
-fsdst->chroma_planes   = fsrc->chroma_planes;
-fsdst->chroma_h_shift  = fsrc->chroma_h_shift;
-fsdst->chroma_v_shift  = fsrc->chroma_v_shift;
-fsdst->transparency= fsrc->transparency;
-fsdst->plane_count = fsrc->plane_count;
-fsdst->ac  = fsrc->ac;
-fsdst->colorspace  = fsrc->colorspace;
-
-fsdst->ec  = fsrc->ec;
-fsdst->intra   = fsrc->intra;
-fsdst->key_frame_ok= fsrc->key_frame_ok;
-
-fsdst->packed_at_lsb   = fsrc->packed_at_lsb;
-fsdst->slice_count = fsrc->slice_count;
-}
-
 static int update_thread_context(AVCodecContext *dst, const AVCodecContext 
*src)
 {
 FFV1Context *fsrc = src->priv_data;
@@ -1050,7 +1029,22 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
 if (dst == src)
 return 0;
 
-copy_fields(fdst, fsrc, fsrc);
+fdst->version = fsrc->version;
+fdst->micro_version   = fsrc->micro_version;
+fdst->chroma_planes   = fsrc->chroma_planes;
+fdst->chroma_h_shift  = fsrc->chroma_h_shift;
+fdst->chroma_v_shift  = fsrc->chroma_v_shift;
+fdst->transparency= fsrc->transparency;
+fdst->plane_count = fsrc->plane_count;
+fdst->ac  = fsrc->ac;
+fdst->colorspace  = fsrc->colorspace;
+
+fdst->ec  = fsrc->ec;
+fdst->intra   = fsrc->intra;
+fdst->key_frame_ok= fsrc->key_frame_ok;
+
+fdst->packed_at_lsb   = fsrc->packed_at_lsb;
+fdst->slice_count = fsrc->slice_count;
 fdst->use32bit = fsrc->use32bit;
 memcpy(fdst->state_transition, fsrc->state_transition,
sizeof(fdst->state_transition));
-- 
2.43.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 24/39] lavc/ffv1dec: move slice_damaged to per-slice context

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.h|  2 +-
 libavcodec/ffv1dec.c | 18 --
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index cef61f38ec..c4803654f2 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -91,6 +91,7 @@ typedef struct FFV1SliceContext {
 // decoder-only
 struct {
 int slice_reset_contexts;
+int slice_damaged;
 };
 
 // encoder-only
@@ -131,7 +132,6 @@ typedef struct FFV1Context {
 
 int ec;
 int intra;
-int slice_damaged;
 int key_frame_ok;
 int context_model;
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 92e5b2a80b..bd46930ec7 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -268,11 +268,10 @@ static int decode_slice(AVCodecContext *c, void *arg)
 ff_progress_frame_await(&f->last_picture, si);
 
 if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
-FFV1Context *fssrc = f->fsrc->slice_context[si];
 const FFV1SliceContext *scsrc = &f->fsrc->slices[si];
 
 if (!(p->flags & AV_FRAME_FLAG_KEY))
-fs->slice_damaged |= fssrc->slice_damaged;
+sc->slice_damaged |= scsrc->slice_damaged;
 
 for (int i = 0; i < f->plane_count; i++) {
 const PlaneContext *psrc = &scsrc->plane[i];
@@ -302,7 +301,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 return AVERROR(ENOMEM);
 if (decode_slice_header(f, fs, sc, p) < 0) {
 sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0;
-fs->slice_damaged = 1;
+sc->slice_damaged = 1;
 return AVERROR_INVALIDDATA;
 }
 }
@@ -310,7 +309,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 return ret;
 if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) {
 ff_ffv1_clear_slice_state(f, sc);
-} else if (fs->slice_damaged) {
+} else if (sc->slice_damaged) {
 return AVERROR_INVALIDDATA;
 }
 
@@ -364,7 +363,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 v = sc->c.bytestream_end - sc->c.bytestream - 2 - 5*f->ec;
 if (v) {
 av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by 
%d\n", v);
-fs->slice_damaged = 1;
+sc->slice_damaged = 1;
 }
 }
 
@@ -793,7 +792,7 @@ static int read_header(FFV1Context *f)
 FFV1SliceContext *sc = &f->slices[j];
 fs->packed_at_lsb = f->packed_at_lsb;
 
-fs->slice_damaged = 0;
+sc->slice_damaged = 0;
 
 if (f->version == 2) {
 int sx = get_symbol(c, state, 0);
@@ -965,7 +964,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 } else {
 av_log(f->avctx, AV_LOG_ERROR, "\n");
 }
-fs->slice_damaged = 1;
+sc->slice_damaged = 1;
 }
 if (avctx->debug & FF_DEBUG_PICT_INFO) {
 av_log(avctx, AV_LOG_DEBUG, "slice %d, CRC: 0x%08"PRIX32"\n", 
i, AV_RB32(buf_p + v - 4));
@@ -989,9 +988,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
sizeof(void*));
 
 for (int i = f->slice_count - 1; i >= 0; i--) {
-FFV1Context *fs = f->slice_context[i];
 FFV1SliceContext *sc = &f->slices[i];
-if (fs->slice_damaged && f->last_picture.f) {
+if (sc->slice_damaged && f->last_picture.f) {
 const AVPixFmtDescriptor *desc = 
av_pix_fmt_desc_get(avctx->pix_fmt);
 const uint8_t *src[4];
 uint8_t *dst[4];
@@ -1044,7 +1042,6 @@ static void copy_fields(FFV1Context *fsdst, const 
FFV1Context *fssrc,
 
 fsdst->ec  = fsrc->ec;
 fsdst->intra   = fsrc->intra;
-fsdst->slice_damaged   = fssrc->slice_damaged;
 fsdst->key_frame_ok= fsrc->key_frame_ok;
 
 fsdst->packed_at_lsb   = fsrc->packed_at_lsb;
@@ -1077,6 +1074,7 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
 const FFV1SliceContext *sc0 = &fsrc->slices[i];
 
 copy_fields(fsdst, fssrc, fsrc);
+sc->slice_damaged = sc0->slice_damaged;
 
 if (fsrc->version < 3) {
 sc->slice_x = sc0->slice_x;
-- 
2.43.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 29/39] lavc/thread: move generic-layer API to avcodec_internal.h

2024-07-16 Thread Anton Khirnov
thread.h currently contains both API for decoder use and functions
internal to lavc generic layer. Move the latter to avcodec_internal.h,
which is a more appropriate place for them.
---
 libavcodec/avcodec_internal.h | 24 
 libavcodec/pthread.c  |  1 +
 libavcodec/thread.h   | 25 +
 libavcodec/utils.c|  8 
 4 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h
index 0a024378ae..816f39ae76 100644
--- a/libavcodec/avcodec_internal.h
+++ b/libavcodec/avcodec_internal.h
@@ -72,4 +72,28 @@ struct AVCodecInternal *ff_encode_internal_alloc(void);
 
 void ff_codec_close(struct AVCodecContext *avctx);
 
+int ff_thread_init(struct AVCodecContext *s);
+void ff_thread_free(struct AVCodecContext *s);
+
+/**
+ * Wait for decoding threads to finish and reset internal state.
+ * Called by avcodec_flush_buffers().
+ *
+ * @param avctx The context.
+ */
+void ff_thread_flush(struct AVCodecContext *avctx);
+
+/**
+ * Submit a new frame to a decoding thread.
+ * Returns the next available frame in picture. *got_picture_ptr
+ * will be 0 if none is available.
+ * The return value on success is the size of the consumed packet for
+ * compatibility with FFCodec.decode. This means the decoder
+ * has to consume the full packet.
+ *
+ * Parameters are the same as FFCodec.decode.
+ */
+int ff_thread_decode_frame(struct AVCodecContext *avctx, struct AVFrame *frame,
+   int *got_picture_ptr, struct AVPacket *avpkt);
+
 #endif // AVCODEC_AVCODEC_INTERNAL_H
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index ca84b81391..d32e56de0d 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -32,6 +32,7 @@
 #include "libavutil/thread.h"
 
 #include "avcodec.h"
+#include "avcodec_internal.h"
 #include "codec_internal.h"
 #include "pthread_internal.h"
 #include "thread.h"
diff --git a/libavcodec/thread.h b/libavcodec/thread.h
index 5ab12848b4..47c00a0ed2 100644
--- a/libavcodec/thread.h
+++ b/libavcodec/thread.h
@@ -20,7 +20,7 @@
 
 /**
  * @file
- * Multithreading support functions
+ * Multithreading API for decoders
  * @author Alexander Strange 
  */
 
@@ -31,27 +31,6 @@
 
 #include "avcodec.h"
 
-/**
- * Wait for decoding threads to finish and reset internal state.
- * Called by avcodec_flush_buffers().
- *
- * @param avctx The context.
- */
-void ff_thread_flush(AVCodecContext *avctx);
-
-/**
- * Submit a new frame to a decoding thread.
- * Returns the next available frame in picture. *got_picture_ptr
- * will be 0 if none is available.
- * The return value on success is the size of the consumed packet for
- * compatibility with FFCodec.decode. This means the decoder
- * has to consume the full packet.
- *
- * Parameters are the same as FFCodec.decode.
- */
-int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture,
-   int *got_picture_ptr, AVPacket *avpkt);
-
 int ff_thread_can_start_frame(AVCodecContext *avctx);
 
 /**
@@ -74,11 +53,9 @@ void ff_thread_finish_setup(AVCodecContext *avctx);
  */
 int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags);
 
-int ff_thread_init(AVCodecContext *s);
 int ff_slice_thread_execute_with_mainfunc(AVCodecContext *avctx,
 int (*action_func2)(AVCodecContext *c, void *arg, int jobnr, int 
threadnr),
 int (*main_func)(AVCodecContext *c), void *arg, int *ret, int 
job_count);
-void ff_thread_free(AVCodecContext *s);
 int ff_slice_thread_allocz_entries(AVCodecContext *avctx, int count);
 int ff_slice_thread_init_progress(AVCodecContext *avctx);
 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, 
int n);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 337c00e789..b17fc3c7e2 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -806,14 +806,6 @@ int av_get_audio_frame_duration2(AVCodecParameters *par, 
int frame_bytes)
 return FFMAX(0, duration);
 }
 
-#if !HAVE_THREADS
-int ff_thread_init(AVCodecContext *s)
-{
-return -1;
-}
-
-#endif
-
 unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
 {
 unsigned int n = 0;
-- 
2.43.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 12/39] lavc/ffv1: drop redundant FFV1Context.quant_table

2024-07-16 Thread Anton Khirnov
In all cases except decoding version 1 it's either not used, or contains
a copy of a table from quant_tables, which we can just as well use
directly.

When decoding version 1, we can just as well decode into
quant_tables[0], which would otherwise be unused.
---
 libavcodec/ffv1.h|  1 -
 libavcodec/ffv1dec.c | 10 +++---
 libavcodec/ffv1enc.c |  6 ++
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index dce6e177eb..4d57172d5b 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -106,7 +106,6 @@ typedef struct FFV1Context {
 int ac;  ///< 1=range coder <-> 0=golomb rice
 int ac_byte_count;   ///< number of bytes used for AC 
coding
 PlaneContext plane[MAX_PLANES];
-int16_t quant_table[MAX_CONTEXT_INPUTS][256];
 int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
 int context_count[MAX_QUANT_TABLES];
 uint8_t state_transition[256];
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index a1f7206871..66d9f63c1a 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -764,7 +764,7 @@ static int read_header(FFV1Context *f)
 ff_dlog(f->avctx, "%d %d %d\n",
 f->chroma_h_shift, f->chroma_v_shift, f->avctx->pix_fmt);
 if (f->version < 2) {
-context_count = read_quant_tables(c, f->quant_table);
+context_count = read_quant_tables(c, f->quant_tables[0]);
 if (context_count < 0) {
 av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
 return AVERROR_INVALIDDATA;
@@ -834,7 +834,7 @@ static int read_header(FFV1Context *f)
sizeof(p->quant_table));
 context_count = f->context_count[idx];
 } else {
-memcpy(p->quant_table, f->quant_table, sizeof(p->quant_table));
+memcpy(p->quant_table, f->quant_tables[0], 
sizeof(p->quant_table));
 }
 
 if (f->version <= 2) {
@@ -1067,7 +1067,11 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
 fdst->use32bit = fsrc->use32bit;
 memcpy(fdst->state_transition, fsrc->state_transition,
sizeof(fdst->state_transition));
-memcpy(fdst->quant_table, fsrc->quant_table, sizeof(fsrc->quant_table));
+
+// in version 1 there is a single per-keyframe quant table, so
+// we need to propagate it between threads
+if (fsrc->version < 2)
+memcpy(fdst->quant_tables[0], fsrc->quant_tables[0], 
sizeof(fsrc->quant_tables[0]));
 
 for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) {
 FFV1Context *fssrc = fsrc->slice_context[i];
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 5692bfa1fc..1d00a46cdd 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -367,7 +367,7 @@ static void write_header(FFV1Context *f)
 put_symbol(c, state, f->chroma_v_shift, 0);
 put_rac(c, state, f->transparency);
 
-write_quant_tables(c, f->quant_table);
+write_quant_tables(c, f->quant_tables[f->context_model]);
 } else if (f->version < 3) {
 put_symbol(c, state, f->slice_count, 0);
 for (i = 0; i < f->slice_count; i++) {
@@ -735,15 +735,13 @@ static av_cold int encode_init(AVCodecContext *avctx)
 }
 s->context_count[0] = (11 * 11 * 11+ 1) / 2;
 s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2;
-memcpy(s->quant_table, s->quant_tables[s->context_model],
-   sizeof(s->quant_table));
 
 for (i = 0; i < s->plane_count; i++) {
 PlaneContext *const p = &s->plane[i];
 
-memcpy(p->quant_table, s->quant_table, sizeof(p->quant_table));
 p->quant_table_index = s->context_model;
 p->context_count = s->context_count[p->quant_table_index];
+memcpy(p->quant_table, s->quant_tables[p->quant_table_index], 
sizeof(p->quant_table));
 }
 
 if ((ret = ff_ffv1_allocate_initial_states(s)) < 0)
-- 
2.43.0

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

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


Re: [FFmpeg-devel] FFmpeg at IBC

2024-07-16 Thread Rémi Denis-Courmont
Le tiistaina 16. heinäkuuta 2024, 19.57.07 EEST Michael Niedermayer a écrit :
> > Quoting Micheal here, but "where did you discuss the creation of this
> > Booth with the FFmpeg community?"
> 
> Given that its not September the 13th yet, and this thread is a discussion,
> iam not sure the quote is fitting.

Well, you may be right but for the wrong reasons here.

8 weeks may seem like a lot, but accomodation prices in Amsterdam are already 
through the proverbial roof, and it will only get worse, so it is not too 
early to send the confirmation to the mailing list. Though presumably the 
confirmation of the booth only just came up.

More to the point: While it was not so much a discussion as a statement, Thilo 
did notify the mailing list earlier that he was getting an FFmpeg booth a few 
weeks ago. 

Having said that, consultants and commercial support vendors could want to 
pitch their FFmpeg support services there, much like (for example) Collabora 
or VideoLabs. I am concerned however that there will not be much benefit from 
the presence of an open-source project or not-for-profit foundation.

-- 
Rémi Denis-Courmont
http://www.remlab.net/



___
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] Add Mediacodec audio decoders support

2024-07-16 Thread Rémi Denis-Courmont
Le tiistaina 16. heinäkuuta 2024, 18.48.06 EEST Cosmin Stejerean via ffmpeg-
devel a écrit :
> To add another data point, the platform decoders might also be more secure
> due to sandboxing. I believe as of Android Q the software decoders provided
> by MediaCodec have been moved to run within a constrained sandbox.

Platform decoders are in all likelihood strictly less secure than software 
decoders. Software decoders will run in a user-space sandboxed within their 
respective application. Platform decoders will run in a more privileged system 
service, with direct access to a kernel driver in EL1, through that to the 
firmware running on the video DSP.

More performant and energy-efficient. But also way way less secure.

The only viewpoint whence this is more secure, is the content publisher's: 
this model enables DRM with hardware pass-through (but that does not even 
apply if you use FFmpeg as the front end).

-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/



___
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 23/39] lavc/ffv1dec: move slice_reset_contexts to per-slice context

2024-07-16 Thread Anton Khirnov
---
 libavcodec/ffv1.h| 16 +---
 libavcodec/ffv1dec.c |  4 ++--
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index ae81940073..cef61f38ec 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -86,8 +86,19 @@ typedef struct FFV1SliceContext {
 RangeCoder c;
 
 int ac_byte_count;   ///< number of bytes used for AC 
coding
-uint64_t rc_stat[256][2];
-uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
+
+union {
+// decoder-only
+struct {
+int slice_reset_contexts;
+};
+
+// encoder-only
+struct {
+uint64_t rc_stat[256][2];
+uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
+};
+};
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
@@ -135,7 +146,6 @@ typedef struct FFV1Context {
 int max_slice_count;
 int num_v_slices;
 int num_h_slices;
-int slice_reset_contexts;
 
 FFV1SliceContext *slices;
 } FFV1Context;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 4dc1f4b1cf..92e5b2a80b 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -238,7 +238,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 }
 
 if (fs->version > 3) {
-fs->slice_reset_contexts = get_rac(c, state);
+sc->slice_reset_contexts = get_rac(c, state);
 sc->slice_coding_mode = get_symbol(c, state, 0);
 if (sc->slice_coding_mode != 1) {
 sc->slice_rct_by_coef = get_symbol(c, state, 0);
@@ -308,7 +308,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 if ((ret = ff_ffv1_init_slice_state(f, sc)) < 0)
 return ret;
-if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) {
+if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) {
 ff_ffv1_clear_slice_state(f, sc);
 } else if (fs->slice_damaged) {
 return AVERROR_INVALIDDATA;
-- 
2.43.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 22/39] lavc/ffv1enc: stop using per-slice FFV1Context

2024-07-16 Thread Anton Khirnov
All remaining accesses to them are for fields that have the same value
in the main encoder context.
---
 libavcodec/ffv1enc.c  | 57 ---
 libavcodec/ffv1enc_template.c | 24 +++
 2 files changed, 37 insertions(+), 44 deletions(-)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 3a6a0e6d90..ba378a54a4 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -269,13 +269,12 @@ static inline void put_vlc_symbol(PutBitContext *pb, 
VlcState *const state,
 #define RENAME(name) name ## 32
 #include "ffv1enc_template.c"
 
-static int encode_plane(FFV1Context *f,
-FFV1Context *s, FFV1SliceContext *sc,
+static int encode_plane(FFV1Context *f, FFV1SliceContext *sc,
 const uint8_t *src, int w, int h,
  int stride, int plane_index, int pixel_stride)
 {
 int x, y, i, ret;
-const int ring_size = s->context_model ? 3 : 2;
+const int ring_size = f->context_model ? 3 : 2;
 int16_t *sample[3];
 sc->run_index = 0;
 
@@ -287,22 +286,22 @@ static int encode_plane(FFV1Context *f,
 
 sample[0][-1]= sample[1][0  ];
 sample[1][ w]= sample[1][w-1];
-if (s->bits_per_raw_sample <= 8) {
+if (f->bits_per_raw_sample <= 8) {
 for (x = 0; x < w; x++)
 sample[0][x] = src[x * pixel_stride + stride * y];
-if((ret = encode_line(f, s, sc, w, sample, plane_index, 8)) < 0)
+if((ret = encode_line(f, sc, w, sample, plane_index, 8)) < 0)
 return ret;
 } else {
-if (s->packed_at_lsb) {
+if (f->packed_at_lsb) {
 for (x = 0; x < w; x++) {
 sample[0][x] = ((uint16_t*)(src + stride*y))[x];
 }
 } else {
 for (x = 0; x < w; x++) {
-sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - 
s->bits_per_raw_sample);
+sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - 
f->bits_per_raw_sample);
 }
 }
-if((ret = encode_line(f, s, sc, w, sample, plane_index, 
s->bits_per_raw_sample)) < 0)
+if((ret = encode_line(f, sc, w, sample, plane_index, 
f->bits_per_raw_sample)) < 0)
 return ret;
 }
 }
@@ -908,8 +907,7 @@ slices_ok:
 return 0;
 }
 
-static void encode_slice_header(FFV1Context *f, FFV1Context *fs,
-FFV1SliceContext *sc)
+static void encode_slice_header(FFV1Context *f, FFV1SliceContext *sc)
 {
 RangeCoder *c = &sc->c;
 uint8_t state[CONTEXT_SIZE];
@@ -942,7 +940,7 @@ static void encode_slice_header(FFV1Context *f, FFV1Context 
*fs,
 }
 }
 
-static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc,
+static void choose_rct_params(const FFV1Context *f, FFV1SliceContext *sc,
   const uint8_t *src[3], const int stride[3], int 
w, int h)
 {
 #define NB_Y_COEFF 15
@@ -968,7 +966,7 @@ static void choose_rct_params(FFV1Context *fs, 
FFV1SliceContext *sc,
 int stat[NB_Y_COEFF] = {0};
 int x, y, i, p, best;
 int16_t *sample[3];
-int lbd = fs->bits_per_raw_sample <= 8;
+int lbd = f->bits_per_raw_sample <= 8;
 
 for (y = 0; y < h; y++) {
 int lastr=0, lastg=0, lastb=0;
@@ -1027,10 +1025,8 @@ static void choose_rct_params(FFV1Context *fs, 
FFV1SliceContext *sc,
 
 static int encode_slice(AVCodecContext *c, void *arg)
 {
-FFV1Context *fs  = *(void **)arg;
-FFV1Context *f   = fs->avctx->priv_data;
-const int si = (FFV1Context**)arg - f->slice_context;
-FFV1SliceContext *sc = &f->slices[si];
+FFV1SliceContext *sc = arg;
+FFV1Context *f   = c->priv_data;
 int width= sc->slice_width;
 int height   = sc->slice_height;
 int x= sc->slice_x;
@@ -1046,7 +1042,7 @@ static int encode_slice(AVCodecContext *c, void *arg)
 
 sc->slice_coding_mode = 0;
 if (f->version > 3) {
-choose_rct_params(fs, sc, planes, p->linesize, width, height);
+choose_rct_params(f, sc, planes, p->linesize, width, height);
 } else {
 sc->slice_rct_by_coef = 1;
 sc->slice_rct_ry_coef = 1;
@@ -1056,7 +1052,7 @@ retry:
 if (f->key_frame)
 ff_ffv1_clear_slice_state(f, sc);
 if (f->version > 2) {
-encode_slice_header(f, fs, sc);
+encode_slice_header(f, sc);
 }
 if (f->ac == AC_GOLOMB_RICE) {
 sc->ac_byte_count = f->version > 2 || (!x && !y) ? 
ff_rac_terminate(&sc->c, f->version > 2) : 0;
@@ -1071,26 +1067,26 @@ retry:
 const int cx= x >> f->chroma_h_shift;
 const int cy= y >> f->chroma_v_shift;
 
-ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], 
width, height, p->linesize[0], 0, 1);
+ret = encode_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, 
height, p->linesize[0], 0

Re: [FFmpeg-devel] FFmpeg at IBC

2024-07-16 Thread Vittorio Giovara
On Tue, Jul 16, 2024 at 7:06 PM Michael Niedermayer 
wrote:

> On Tue, Jul 16, 2024 at 05:24:18PM +0200, Vittorio Giovara wrote:
> > On Sun, Jul 14, 2024 at 9:45 AM Thilo Borgmann via ffmpeg-devel <
> > ffmpeg-devel@ffmpeg.org> wrote:
> >
> > > Hi,
> > >
> > > FFmpeg will have a booth at the next IBC from September 13th to 16th
> > > 2024 in Amsterdam [1]!
> > >
> > > We received a corporate sponsorship for the booth, so there are no
> costs
> > > for the FFmpeg project to it (and no obligations, of course).
> > >
> > > FFmpeg developers are welcome to join in and help man the booth with
> me!
> > >
> > > Share with us your broken workflows, unfulfilled requirements, ideas
> for
> > > enhancements and after show drinks at W8.A23g!
> > >
> > > -Thilo
> > >
> >
> > Quoting Micheal here, but "where did you discuss the creation of this
> Booth
> > with the FFmpeg community?"
>
> Given that its not September the 13th yet, and this thread is a discussion,
> iam not sure the quote is fitting.
>

I'd like to tackle problems before it's too late :)
-- 
Vittorio
___
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] [OSS-Fuzz] Have you considered enabling memory sanitizer?

2024-07-16 Thread Vittorio Giovara
On Tue, Jul 16, 2024 at 2:25 PM Michael Niedermayer 
wrote:

> On Mon, Jul 15, 2024 at 02:36:15PM +0200, Vittorio Giovara wrote:
> > On Sun, Jul 14, 2024 at 9:55 PM Michael Niedermayer <
> mich...@niedermayer.cc>
> > wrote:
> >
> > > On Sat, Jul 13, 2024 at 11:12:40PM +0200, Kacper Michajlow wrote:
> > > > On Thu, 27 Jun 2024 at 02:50, Kacper Michajlow 
> > > wrote:
> > > > >
> > > > > On Thu, 27 Jun 2024 at 00:45, Michael Niedermayer
> > > > >  wrote:
> > > > > >
> > > > > > On Wed, Jun 26, 2024 at 09:07:42PM +0200, Kacper Michajlow wrote:
> > > > > > > Hi,
> > > > > > >
> > > > > > > Like in the topic. I think it would be useful to enable MSAN on
> > > > > > > OSS-Fuzz. We get some tiny issues and it would be probably
> good to
> > > > > > > have them tracked upstream. All infra is here, so enabling it
> is as
> > > > > > > simple as adding it to the project.yaml. Except libbz2.so and
> > > libz.so
> > > > > > > would have to be built inline instead, looking at the build.sh,
> > > they
> > > > > > > are prebuilt. The rest should just work (TM), but needs to be
> > > tested.
> > > > > > > You can set an "experimental' flag to have it not create
> issues on
> > > > > > > monorail, initially.
> > > > > >
> > > > > > I assumed ossfuzz would enable all sanitizers by default
> > > > >
> > > > > They do not do that by default, because MSAN requires all
> dependencies
> > > > > to be instrumented too. See
> > > > >
> > >
> https://google.github.io/oss-fuzz/getting-started/new-project-guide/#sanitizers
> > > > >
> > > > > Looking at build.sh for ffmpeg, it should be fine to enable it.
> > > > > Obviously I have not tested everything, but I was running some
> tests
> > > > > locally with MSAN and also tested it with mpv oss-fuzz builds
> where we
> > > > > build ffmpeg too with MSAN.
> > > > >
> > > > > - Kacper
> > > >
> > > > I've sent a PR to enable MSAN and a few other build improvements.
> > > > Please take a look https://github.com/google/oss-fuzz/pull/12211
> > > >
> > >
> > > > Also, would it be ok to add myself to auto_ccs for ffmpeg? Mostly to
> > > > monitor what issues are reported upstream, as we get some reports in
> > > > mpv fuzzing and I never know if I should report it upstream (ffmpeg)
> > > > or it is already found by first-party fuzzing and I shouldn't make
> > > > more noise.
> > >
> > > you are welcome to submit bug reports, you are welcome to submit bug
> fixes
> > > if you find issues in FFmpeg.
> > >
> > > If someones work in FFmpeg or rather FFmpeg benefits from someone
> having
> > > access to the reports, then (s)he should receive access. This seems not
> > > to apply here
> > >
> >
> > Disagree - this is not the right way to attract new contributors.
>
> no ?
> did you do a study ?
>

I didn't but I've been to enough open source conferences that I picked up a
few things on community fostering.
When was the last time you attended one?


> try this:
> A. "please we need more maintainers" (we tried this i think)
> B. gently push someone away
> (now people are angry, they want their rights, their access, they want
> to
>  contribute ...)
> ;)
>

C. let's give the tools maintainers need, like gitlab/gitea/whatever, and
accept reasonable security contributions

at least let's define a process to grant people access when requested

> Also i expect the number of outstanding ossfuzz issues to decrease now
> > > after the bulk of coverity issues has been dealt with
> > >
> >
> > The majority of coverity issues are false positives, I fail to see the
> > relationship here.
>
> I do both coverity and ossfuzz work, and while i have done significantly
> more
> in the last months than i did last year, i still have falling a bit behind
> with
> ossfuzz fixing.
>

So what's the problem with having an extra pair of helping hands?
-- 
Vittorio
___
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] libavformat/tls_mbedtls: Changes the return code handling of mbedtls_x509_crt_parse_file

2024-07-16 Thread Mohit Gupta
Sounds good. Sorry first time contributing, should I make another patch
with the change and send that through again with git send-email?

Thanks
Mohit

On Tue, Jul 16, 2024 at 2:26 AM Marth64  wrote:

> > Could do. What level were you thinking? WARN?
>
> How about,
> ```
> av_log(h, AV_LOG_WARNING, "Failed to process %d certificate(s) from
> the CA bundle, ignoring these certificates\n", ret);
> ```
>
>
> Thank you,
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] Add Mediacodec audio decoders support

2024-07-16 Thread Cosmin Stejerean via ffmpeg-devel


> On Jul 16, 2024, at 8:24 PM, Rémi Denis-Courmont  wrote:
> 
> Le tiistaina 16. heinäkuuta 2024, 18.48.06 EEST Cosmin Stejerean via ffmpeg-
> devel a écrit :
>> To add another data point, the platform decoders might also be more secure
>> due to sandboxing. I believe as of Android Q the software decoders provided
>> by MediaCodec have been moved to run within a constrained sandbox.
> 
> Platform decoders are in all likelihood strictly less secure than software 
> decoders. Software decoders will run in a user-space sandboxed within their 
> respective application. Platform decoders will run in a more privileged 
> system 
> service, with direct access to a kernel driver in EL1, through that to the 
> firmware running on the video DSP.
> 
> More performant and energy-efficient. But also way way less secure.
> 
> The only viewpoint whence this is more secure, is the content publisher's: 
> this model enables DRM with hardware pass-through (but that does not even 
> apply if you use FFmpeg as the front end).
> 

Platform provided *software* decoders should be more secure than bundled 
software decoders due to the sandboxing of software decoders in recent versions 
of Android.

Hardware decoders might very well not be for the reasons you mentioned.

- Cosmin
___
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] [OSS-Fuzz] Have you considered enabling memory sanitizer?

2024-07-16 Thread Kacper Michajlow
On Tue, 16 Jul 2024 at 14:14, Michael Niedermayer
 wrote:
>
> On Mon, Jul 15, 2024 at 01:32:20PM +0200, Kacper Michajlow wrote:
> > On Sun, 14 Jul 2024 at 21:55, Michael Niedermayer
> >  wrote:
> > >
> > > On Sat, Jul 13, 2024 at 11:12:40PM +0200, Kacper Michajlow wrote:
> > > > On Thu, 27 Jun 2024 at 02:50, Kacper Michajlow  
> > > > wrote:
> > > > >
> > > > > On Thu, 27 Jun 2024 at 00:45, Michael Niedermayer
> > > > >  wrote:
> > > > > >
> > > > > > On Wed, Jun 26, 2024 at 09:07:42PM +0200, Kacper Michajlow wrote:
> > > > > > > Hi,
> > > > > > >
> > > > > > > Like in the topic. I think it would be useful to enable MSAN on
> > > > > > > OSS-Fuzz. We get some tiny issues and it would be probably good to
> > > > > > > have them tracked upstream. All infra is here, so enabling it is 
> > > > > > > as
> > > > > > > simple as adding it to the project.yaml. Except libbz2.so and 
> > > > > > > libz.so
> > > > > > > would have to be built inline instead, looking at the build.sh, 
> > > > > > > they
> > > > > > > are prebuilt. The rest should just work (TM), but needs to be 
> > > > > > > tested.
> > > > > > > You can set an "experimental' flag to have it not create issues on
> > > > > > > monorail, initially.
> > > > > >
> > > > > > I assumed ossfuzz would enable all sanitizers by default
> > > > >
> > > > > They do not do that by default, because MSAN requires all dependencies
> > > > > to be instrumented too. See
> > > > > https://google.github.io/oss-fuzz/getting-started/new-project-guide/#sanitizers
> > > > >
> > > > > Looking at build.sh for ffmpeg, it should be fine to enable it.
> > > > > Obviously I have not tested everything, but I was running some tests
> > > > > locally with MSAN and also tested it with mpv oss-fuzz builds where we
> > > > > build ffmpeg too with MSAN.
> > > > >
> > > > > - Kacper
> > > >
> > > > I've sent a PR to enable MSAN and a few other build improvements.
> > > > Please take a look https://github.com/google/oss-fuzz/pull/12211
> > > >
> > >
> > > > Also, would it be ok to add myself to auto_ccs for ffmpeg? Mostly to
> > > > monitor what issues are reported upstream, as we get some reports in
> > > > mpv fuzzing and I never know if I should report it upstream (ffmpeg)
> > > > or it is already found by first-party fuzzing and I shouldn't make
> > > > more noise.
> > >
> > > you are welcome to submit bug reports, you are welcome to submit bug fixes
> > > if you find issues in FFmpeg.
> > >
> > > If someones work in FFmpeg or rather FFmpeg benefits from someone having
> > > access to the reports, then (s)he should receive access. This seems not
> > > to apply here
> >
> > I respect your decision.
>
> > However, saying that anyone's (or my)
> > contribution doesn't benefit FFmpeg is a strange thing to say for an
> > open source project maintainer.
>
> And noone made such a statement. You are reading something thats not written
> there
>
>
> >
> > It's all about time. I don't get paid to do any of this, so
> > duplicating issues/reports manually from one system to another, if
> > they are already reported, is a monkey's job which I'm not willing to
> > do.
>
> ok
> for reference i find no mail from you to ffmpeg-security
> Is it correct you never reported any of the issues you talk about
> neither new nor duplciate ?

Correct, I was sending the patches for the issues instead. All related
to our fuzzing results. Maybe nothing significant, but...

https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240317023628.1936-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240509140211.1296-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240510014931.644-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240510020756.1135-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240511104717.231-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240602013818.1047-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240602121448.1069-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240625215030.321-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240626184440.1318-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240627004037.1336-1-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240627004037.1336-2-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240627004037.1336-3-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240627004037.1336-4-kaspe...@gmail.com/
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240710152401.1192-1-kaspe...@gmail.com/

and patch for ossfuzz itself https://github.com/google/oss-fuzz/pull/12211

>
> > This time could be devoted to actually fixing the issues. I'd like
> > to help, but if it is not required, I will focus on other things.
>
> This is the first time i remember you offering to help.
> You

Re: [FFmpeg-devel] [PATCH] avdevice/dshow: Don't skip audio devices if no video device is present

2024-07-16 Thread Roger Pack
LGTM

On Mon, Jul 15, 2024 at 12:51 AM patches via ffmpeg-devel
 wrote:
>
> The search of the current DirectShow device list has been customized so
> that audio devices are always found even if no video device is connected.
>
> Signed-off-by: Jens Frederich 
> ---
>  libavdevice/dshow.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
> index 403e56fe13..57d8e1c0af 100644
> --- a/libavdevice/dshow.c
> +++ b/libavdevice/dshow.c
> @@ -645,7 +645,7 @@ static int dshow_get_device_list(AVFormatContext *avctx, 
> AVDeviceInfoList *devic
>  }
>
>  ret = dshow_cycle_devices(avctx, devenum, VideoDevice, 
> VideoSourceDevice, NULL, NULL, &device_list);
> -if (ret < S_OK)
> +if (ret < S_OK && ret != AVERROR(EIO))
>  goto error;
>  ret = dshow_cycle_devices(avctx, devenum, AudioDevice, 
> AudioSourceDevice, NULL, NULL, &device_list);
>
> --
> 2.43.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 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] avisynth as an internal filter, any objections?

2024-07-16 Thread Roger Pack
Hi all, just wondering, if I were to write a libavfilter that
basically "called out" to avisynth and had it process stuff, would
there be any ideological pushback, or would it possibly be accepted?
Cheers!
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 1/4] avformat/movenc: fix channel count and samplerate fields for IAMF tracks

2024-07-16 Thread Anton Khirnov
Quoting James Almer (2024-07-17 03:49:22)
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 2bea55e33d..5de188f4cf 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1399,6 +1399,11 @@ static int mov_write_audio_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
>  avio_wb16(pb, 16);
>  avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */
>  } else { /* reserved for mp4/3gp */
> +#if CONFIG_IAMFENC
> +if (track->tag == MKTAG('i','a','m','f'))
> +avio_wb16(pb, 0); /* channelcount must be 0 for IAMF */
> +else
> +#endif
>  avio_wb16(pb, track->par->ch_layout.nb_channels);

avio_wb16(pb, track->tag == MKTAG('i', 'a', 'm', 'f') ?
  0 : track->par->ch_layout.nb_channels);

looks more readable to me

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

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


Re: [FFmpeg-devel] [PATCH] avutil/error: Provide better feedback about unknown error codes

2024-07-16 Thread Anton Khirnov
Quoting Marton Balint (2024-07-16 01:01:20)
> I don't really like adding extra code for this, and from an API point of 
> view any negative error code can be valid, so you can't really warn about 
> them.
> 
> If you want to make sure that every ffmpeg error code has a text, then add 
> a fate test for checking it.
> 
> [...]
> 
> FFERROR_REDO is an avformat internal error code, av_strerror() being in 
> avutil cannot properly support it.

+1

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

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


Re: [FFmpeg-devel] [PATCH v2] avcodec/hevc/hevcdec: Do not allow slices to depend on failed slices

2024-07-16 Thread Anton Khirnov
Quoting Michael Niedermayer (2024-07-15 16:48:25)
> An alternative would be to leave the context unchanged on failure of 
> hls_slice_header()
> 
> Fixes: out of array access
> Fixes: NULL pointer dereference
> Fixes: 
> 69584/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5931086299856896
> Fixes: 
> 69724/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5104066422702080
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/hevc/hevcdec.c | 12 
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
> index 0e4b26dad3b..80d59ab1916 100644
> --- a/libavcodec/hevc/hevcdec.c
> +++ b/libavcodec/hevc/hevcdec.c
> @@ -621,6 +621,10 @@ static int hls_slice_header(SliceHeader *sh, const 
> HEVCContext *s, GetBitContext
>  
>  if (pps->dependent_slice_segments_enabled_flag)
>  sh->dependent_slice_segment_flag = get_bits1(gb);
> +if (sh->dependent_slice_segment_flag && !s->slice_initialized) {
> +av_log(s->avctx, AV_LOG_ERROR, "dependent slice failed\n");

The new error message seems worse than the old one. A slice is a passive
object, "slice failed" makes no sense.

> @@ -3155,8 +3156,11 @@ static int decode_slice(HEVCContext *s, const H2645NAL 
> *nal, GetBitContext *gb)
>  int ret;
>  
>  ret = hls_slice_header(&s->sh, s, gb);
> -if (ret < 0)
> +if (ret < 0) {
> +//The code is not capable to rewind from an error, the state now is 
> inconsistant so we cannot use it on depandant slices

^^

ee
Also I'd drop everything before the comma, why mention rewinding that is
not implemented and may not be a good idea anyway.

Otherwise patch LGTM.

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

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


Re: [FFmpeg-devel] [PATCH] avformat/avio: avio_tell() only errors if the context is NULL

2024-07-16 Thread Anton Khirnov
Quoting Michael Niedermayer (2024-07-11 11:49:37)
> Found by code review related to coverity
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/avio.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/avio.h b/libavformat/avio.h
> index ebf611187dc..3be91e4b8a7 100644
> --- a/libavformat/avio.h
> +++ b/libavformat/avio.h
> @@ -489,7 +489,7 @@ int64_t avio_skip(AVIOContext *s, int64_t offset);
>  
>  /**
>   * ftell() equivalent for AVIOContext.
> - * @return position or AVERROR.
> + * @return position or AVERROR in case s is NULL.

It seems weird to document an invalid call.

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

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