ffmpeg-devel
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
June 2025
- 97 participants
- 367 discussions
Instead of the convoluted nested macros, use a convenience
helper function. While this makes the code slightly longer, it
is now much clearer what is happening without running the file
through a preprocessor first.
Additionally do not mess with the internals of the dictionary,
just to save two string copies.
---
libavformat/tee.c | 98 +++++++++++++++++++++++++++++++----------------
1 file changed, 66 insertions(+), 32 deletions(-)
diff --git a/libavformat/tee.c b/libavformat/tee.c
index 0150ee9f22..0a6e9d0c82 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -80,8 +80,9 @@ static const AVClass tee_muxer_class = {
.version = LIBAVUTIL_VERSION_INT,
};
-static inline int parse_slave_failure_policy_option(const char *opt, TeeSlave *tee_slave)
+static inline int parse_slave_failure_policy_option(const char *opt, void *ctx)
{
+ TeeSlave *tee_slave = ctx;
if (!opt) {
tee_slave->on_fail = DEFAULT_SLAVE_FAILURE_POLICY;
return 0;
@@ -97,8 +98,9 @@ static inline int parse_slave_failure_policy_option(const char *opt, TeeSlave *t
return AVERROR(EINVAL);
}
-static int parse_slave_fifo_policy(const char *use_fifo, TeeSlave *tee_slave)
+static int parse_slave_fifo_policy(const char *use_fifo, void *ctx)
{
+ TeeSlave *tee_slave = ctx;
/*TODO - change this to use proper function for parsing boolean
* options when there is one */
if (av_match_name(use_fifo, "true,y,yes,enable,enabled,on,1")) {
@@ -111,8 +113,9 @@ static int parse_slave_fifo_policy(const char *use_fifo, TeeSlave *tee_slave)
return 0;
}
-static int parse_slave_fifo_options(const char *fifo_options, TeeSlave *tee_slave)
+static int parse_slave_fifo_options(const char *fifo_options, void *ctx)
{
+ TeeSlave *tee_slave = ctx;
return av_dict_parse_string(&tee_slave->fifo_options, fifo_options, "=", ":", 0);
}
@@ -152,6 +155,46 @@ static void close_slaves(AVFormatContext *avf)
av_freep(&tee->slaves);
}
+typedef int (*OptionParserFunc)(const char *value, void *context);
+
+/**
+ * Retrieve and optionally copy or process the given dict key's value
+ *
+ * The dictionary value for \p key is retrieved, if it exists the
+ * value is passed to the \p handler function together with the
+ * \c context, if any. If the handler returns an error, it is returned
+ * to the caller.
+ *
+ * If \c out_value is not NULL, the value is also copied and assigned
+ * to that.
+ *
+ * After processing, the key is removed from the dictionary.
+ */
+static int dict_consume_value(AVDictionary **dict, const char *key, char **out_value,
+ OptionParserFunc handler, void *context)
+{
+ const AVDictionaryEntry *entry = av_dict_get(*dict, key, NULL, 0);
+ if (!entry)
+ return 0;
+
+ if (handler) {
+ int ret = handler(entry->value, context);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (out_value) {
+ char *value_copy = av_strdup(entry->value);
+ if (!value_copy)
+ return AVERROR(ENOMEM);
+
+ *out_value = value_copy;
+ }
+
+ av_dict_set(dict, key, NULL, 0);
+ return 0;
+}
+
static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
{
int ret;
@@ -167,35 +210,26 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
if ((ret = ff_tee_parse_slave_options(avf, slave, &options, &filename)) < 0)
return ret;
-#define CONSUME_OPTION(option, field, action) do { \
- AVDictionaryEntry *en = av_dict_get(options, option, NULL, 0); \
- if (en) { \
- field = en->value; \
- { action } \
- av_dict_set(&options, option, NULL, 0); \
- } \
- } while (0)
-#define STEAL_OPTION(option, field) \
- CONSUME_OPTION(option, field, \
- en->value = NULL; /* prevent it from being freed */)
-#define PROCESS_OPTION(option, function, on_error) do { \
- const char *value; \
- CONSUME_OPTION(option, value, if ((ret = function) < 0) \
- { { on_error } goto end; }); \
- } while (0)
-
- STEAL_OPTION("f", format);
- STEAL_OPTION("select", select);
- PROCESS_OPTION("onfail",
- parse_slave_failure_policy_option(value, tee_slave),
- av_log(avf, AV_LOG_ERROR, "Invalid onfail option value, "
- "valid options are 'abort' and 'ignore'\n"););
- PROCESS_OPTION("use_fifo",
- parse_slave_fifo_policy(value, tee_slave),
- av_log(avf, AV_LOG_ERROR, "Error parsing fifo options: %s\n",
- av_err2str(ret)););
- PROCESS_OPTION("fifo_options",
- parse_slave_fifo_options(value, tee_slave), ;);
+ if ((ret = dict_consume_value(&options, "f", &format, NULL, NULL)) < 0)
+ goto end;
+ if ((ret = dict_consume_value(&options, "select", &select, NULL, NULL)) < 0)
+ goto end;
+ if ((ret = dict_consume_value(&options, "onfail", NULL,
+ parse_slave_failure_policy_option, tee_slave)) < 0) {
+ av_log(avf, AV_LOG_ERROR, "Invalid onfail option value, "
+ "valid options are 'abort' and 'ignore'\n");
+ goto end;
+ }
+ if ((ret = dict_consume_value(&options, "use_fifo", NULL,
+ parse_slave_fifo_policy, tee_slave)) < 0) {
+ av_log(avf, AV_LOG_ERROR, "Error parsing fifo options: %s\n",
+ av_err2str(ret));
+ goto end;
+ }
+ if ((ret = dict_consume_value(&options, "fifo_options", NULL,
+ parse_slave_fifo_options, tee_slave)) < 0)
+ goto end;
+
entry = NULL;
while ((entry = av_dict_get(options, "bsfs", entry, AV_DICT_IGNORE_SUFFIX))) {
/* trim out strlen("bsfs") characters from key */
--
2.39.5 (Apple Git-154)
3
13
[PATCH v2] avformat/mov_muxer: Extended MOV muxer to handle APV video content
by Dawid Kozinski 07 Jul '25
by Dawid Kozinski 07 Jul '25
07 Jul '25
- Changes in mov_write_video_tag function to handle APV elementary stream
- Provided structure APVDecoderConfigurationRecord that specifies the decoder configuration information for APV video content
Signed-off-by: Dawid Kozinski <d.kozinski(a)samsung.com>
---
libavformat/Makefile | 2 +-
libavformat/apv.c | 830 ++++++++++++++++++++++++++++++++++++++++
libavformat/apv.h | 88 +++++
libavformat/isom_tags.c | 1 +
libavformat/movenc.c | 52 +++
5 files changed, 972 insertions(+), 1 deletion(-)
create mode 100644 libavformat/apv.c
create mode 100644 libavformat/apv.h
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 6c9992adab..f65cfe3bf0 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -379,7 +379,7 @@ OBJS-$(CONFIG_MOV_DEMUXER) += mov.o mov_chan.o mov_esds.o \
OBJS-$(CONFIG_MOV_MUXER) += movenc.o \
movenchint.o mov_chan.o rtp.o \
movenccenc.o movenc_ttml.o rawutils.o \
- dovi_isom.o evc.o cbs.o cbs_av1.o
+ dovi_isom.o evc.o cbs.o cbs_av1.o apv.o
OBJS-$(CONFIG_MP2_MUXER) += rawenc.o
OBJS-$(CONFIG_MP3_DEMUXER) += mp3dec.o replaygain.o
OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o
diff --git a/libavformat/apv.c b/libavformat/apv.c
new file mode 100644
index 0000000000..4153292164
--- /dev/null
+++ b/libavformat/apv.c
@@ -0,0 +1,830 @@
+/*
+ * APV helper functions for muxers
+ * Copyright (c) 2025 Dawid Kozinski <d.kozinski(a)samsung.com>
+ *
+ * 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 <stdbool.h>
+
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mem.h"
+
+#include "libavcodec/get_bits.h"
+#include "libavcodec/golomb.h"
+#include "libavcodec/apv.h"
+#include "avformat.h"
+#include "avio.h"
+#include "apv.h"
+#include "avio_internal.h"
+
+
+#define TILE_COLS_MAX 20
+#define TILE_ROWS_MAX 20
+#define NUM_TILES_MAX TILE_COLS_MAX*TILE_ROWS_MAX
+
+#define NUM_COMP_MAX 4
+
+#define MB_WIDTH 16
+#define MB_HEIGHT 16
+
+/*****************************************************************************
+ * PBU types
+ *****************************************************************************/
+#define APV_PBU_TYPE_RESERVED (0)
+#define APV_PBU_TYPE_PRIMARY_FRAME (1)
+#define APV_PBU_TYPE_NON_PRIMARY_FRAME (2)
+#define APV_PBU_TYPE_PREVIEW_FRAME (25)
+#define APV_PBU_TYPE_DEPTH_FRAME (26)
+#define APV_PBU_TYPE_ALPHA_FRAME (27)
+#define APV_PBU_TYPE_AU_INFO (65)
+#define APV_PBU_TYPE_METADATA (66)
+#define APV_PBU_TYPE_FILLER (67)
+#define APV_PBU_TYPE_UNKNOWN (-1)
+#define APV_PBU_NUMS (10)
+
+#define APV_FRAME_TYPE_PRIMARY_FRAME (0)
+#define APV_FRAME_TYPE_NON_PRIMARY_FRAME (1)
+#define APV_FRAME_TYPE_PREVIEW_FRAME (2)
+#define APV_FRAME_TYPE_DEPTH_FRAME (3)
+#define APV_FRAME_TYPE_ALPHA_FRAME (4)
+#define APV_FRAME_TYPE_NON_FRAME (-1)
+#define APV_PBU_FRAME_TYPE_NUM (5)
+#define CONFIGURATIONS_MAX (APV_PBU_FRAME_TYPE_NUM)
+
+#define APV_PBU_SIZE_PREFIX_LENGTH (4)
+#define APV_SIGNATURE_LENGTH (4)
+
+typedef struct APVDecoderFrameInfo {
+ uint8_t reserved_zero_6bits; // 6 bits
+ uint8_t color_description_present_flag; // 1 bit
+
+ // The variable indicates whether the capture_time_distance value in the APV bitstream's frame header should be ignored during playback.
+ // If capture_time_distance_ignored is set to true, the capture_time_distance information will not be utilized,
+ // and timing information for playback should be calculated using an alternative method.
+ // If set to false, the capture_time_distance value will be used as is from the frame header.
+ // It is recommended to set this variable to true, allowing the use of MP4 timestamps for playback and recording,
+ // which enables the conventional compression and playback methods based on the timestamp table defined by the ISO-based file format.
+ uint8_t capture_time_distance_ignored; // 1-bit
+
+ uint8_t profile_idc; // 8 bits
+ uint8_t level_idc; // 8 bits
+ uint8_t band_idc; // 8 bits
+ uint32_t frame_width; // 32 bits
+ uint32_t frame_height; // 32 bits
+ uint8_t chroma_format_idc; // 4 bits
+ uint8_t bit_depth_minus8; // 4 bits
+ uint8_t capture_time_distance; // 8 bits
+
+ // if (color_description_present_flag)
+ uint8_t color_primaries; // 8 bits
+ uint8_t transfer_characteristics; // 8 bits
+ uint8_t matrix_coefficients; // 8 bits
+ uint8_t full_range_flag; // 1 bit
+ uint8_t reserved_zero_7bits; // 7 bits
+
+} APVDecoderFrameInfo;
+
+typedef struct APVDecoderConfigurationEntry {
+ uint8_t pbu_type; // 8 bits
+ uint8_t number_of_frame_info; // 8 bits
+
+ APVDecoderFrameInfo** frame_info; // An array of size number_of_frame_info storing elements of type APVDecoderFrameInfo*
+
+} APVDecoderConfigurationEntry;
+
+// ISOBMFF binding for APV
+// @see https://github.com/openapv/openapv/blob/main/readme/apv_isobmff.md
+typedef struct APVDecoderConfigurationRecord {
+ uint8_t configurationVersion; // 8 bits
+ uint8_t number_of_configuration_entry; // 8 bits
+
+ APVDecoderConfigurationEntry configuration_entry[CONFIGURATIONS_MAX]; // table of size number_of_configuration_entry
+
+} APVDecoderConfigurationRecord ;
+
+// 5.3.6. Frame information
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-frame-information
+typedef struct frame_info_t {
+ uint8_t profile_idc; // 8 bits
+ uint8_t level_idc; // 8 bits
+ uint8_t band_idc; // 3 bits
+ uint8_t reserved_zero_5bits; // 5 bits
+
+ uint32_t frame_width; // 24 bits
+ uint32_t frame_height; // 24 bits
+
+ uint8_t chroma_format_idc; // 4 bits
+ uint8_t bit_depth_minus8; // 4 bits
+
+ uint8_t capture_time_distance; // 8 bits
+ uint8_t reserved_zero_8bit; // 8 bits
+} frame_info_t;
+
+// 5.3.7. Quantization matrix
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-quantization-matā¦
+typedef struct quantization_matrix_t {
+ uint8_t q_matrix[3][8][8]; // @todo use NumCmp instead of 3
+} quantization_matrix_t;
+
+// 5.3.8. Tile info
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-tile-info
+typedef struct tile_info_t {
+ uint32_t tile_width_in_mbs; // u(20)
+ uint32_t tile_height_in_mbs; // u(20)
+ uint8_t tile_size_present_in_fh_flag; // u(1)
+ uint32_t tile_size_in_fh[TILE_ROWS_MAX*TILE_COLS_MAX]; // u(32) -> size of table: NumTiles
+
+ // private
+ uint32_t ColStarts[TILE_COLS_MAX];
+ uint32_t RowStarts[TILE_ROWS_MAX];
+
+ uint32_t TileCols; // The value of TileCols MUST be less than or equal to TILE_COLS_MAX.
+ uint32_t TileRows; // The value of TileRows MUST be less than or equal to TILE_ROWS_MAX.
+ uint32_t NumTiles;
+
+} tile_info_t;
+
+
+// 5.3.17. Byte alignment
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-byte-alignment
+typedef struct byte_alignment_t {
+ uint8_t alignment_bit_equal_to_zero; /* equal to 0*/ // f(1)
+} byte_alignment_t;
+
+// 5.3.5. Frame header
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-frame-header
+typedef struct frame_header_t {
+ frame_info_t frame_info;
+ uint8_t reserved_zero_8bits; // 8 bits
+ uint8_t color_description_present_flag; // 1 bits
+
+ uint8_t color_primaries; // 8 bits
+ uint8_t transfer_characteristics; // 8 bits
+ uint8_t matrix_coefficients; // 8 bits
+ uint8_t full_range_flag; // 1 bit
+
+ uint8_t use_q_matrix; // 1 bit
+
+ quantization_matrix_t quantization_matrix;
+ tile_info_t tile_info;
+
+ uint8_t reserved_zero_8bits_2; // 8 bits
+ byte_alignment_t byte_alignment_t;
+} frame_header_t;
+
+// 5.3.11. Filler
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-filler
+typedef struct filler_t {
+ uint8_t *ff_byte; /* is a byte equal to 0xFF */ // f(8)
+} filler_t;
+
+// 5.3.13. Tile header
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-tile-header
+typedef struct tile_header_t {
+ uint16_t tile_header_size; // u(16)
+ uint16_t tile_index; // u(16)
+ uint32_t tile_data_size[NUM_COMP_MAX]; // u(32) table of size NumComps MAX = 4
+ uint8_t tile_qp[NUM_COMP_MAX]; // u(8) table of size NumComps
+ uint8_t reserved_zero_8bits; // u(8)
+ byte_alignment_t byte_alignment;
+
+} tile_header_t;
+
+// 5.3.16. AC coefficient coding
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-ac-coefficient-cā¦
+typedef struct {
+ uint8_t coeff_zero_run;
+ uint8_t abs_ac_coeff_minus1;
+ uint8_t sign_ac_coeff;
+} ac_coeff_coding_t;
+
+// 5.3.15. Macroblock layer
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-macroblock-layer
+typedef struct macroblock_layer_t {
+ uint8_t abs_dc_coeff_diff; // h(v)
+ uint8_t sign_dc_coeff_diff; // u(1)
+ ac_coeff_coding_t ac_coeff_coding;
+} macroblock_layer_t;
+
+// 5.3.14. Tile data
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-tile-data
+typedef struct tile_data_t {
+ macroblock_layer_t macroblock_layer;
+ byte_alignment_t byte_alignment;
+} tile_data_t;
+
+
+// 5.3.11. Filler
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-filler
+typedef struct tile_t {
+ tile_header_t tile_header;
+ uint8_t tile_data;
+ uint8_t ff_byte; /* is a byte equal to 0xFF */ // f(8)
+} tile_t;
+
+// 5.3.4 Frame
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-frame
+typedef struct frame_t {
+ frame_header_t frame_header;
+ uint32_t tile_size[NUM_TILES_MAX]; // table of NumTiles size
+ tile_t tile[NUM_TILES_MAX]; // table of NumTiles size
+ filler_t filler;
+} frame_t;
+
+// 5.3.3. Primitive bitstream unit header
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-primitive-bitstrā¦
+typedef struct pbu_header_t {
+ uint8_t pbu_type; // 8 bits
+ uint16_t group_id; // 16 bits
+ uint8_t reserved_zero_8bits; // 8 bits
+} pbu_header_t;
+
+// 5.3.9. Access unit information
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-access-unit-infoā¦
+typedef struct au_info_t {
+ uint16_t num_frames; // 16 bits
+
+ uint8_t pbu_type; // 8 bits
+ uint16_t group_id; // 16 bits
+ uint8_t reserved_zero_8bits; // 8 bits
+ frame_info_t frame_info;
+
+ uint8_t reserved_zero_8bits_2; // 8 bits
+ byte_alignment_t byte_alignment;
+
+} au_info_t;
+
+typedef struct {
+ uint64_t high;
+ uint64_t low;
+} uint128_t;
+
+// 5.3.10. Metadata
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-metadata
+typedef struct metadata_t {
+ uint16_t metadata_size; // 32 bits
+
+ /* is a byte equal to 0xFF */
+ uint8_t *ff_byte; // f(8) table of size payloadSize
+ uint8_t metadata_payload_type; // u(8)
+
+ /* is a byte equal to 0xFF */
+ uint8_t ff_byte_2; // f(8)
+ uint8_t metadata_payload_size; // u(8)
+
+ // metadata ITU-T T.35
+ uint8_t itu_t_t35_country_code; // u(8)
+ uint8_t itu_t_t35_country_code_extension; // u(8)
+ uint8_t itu_t_t35_payload; // u(8)
+
+ // metadata mdcv (Mastering display color volume metadata)
+ uint16_t primary_chromaticity_x[3]; // u(16)
+ uint16_t primary_chromaticity_y[3]; // u(16)
+ uint16_t white_point_chromaticity_x; // u(16)
+ uint16_t white_point_chromaticity_y; // u(16)
+ uint32_t max_mastering_luminance; // u(32)
+ uint32_t min_mastering_luminance; // u(32)
+
+ // metadata ccl (Content light level information metadata)
+ uint16_t max_cll; // u(16)
+ uint16_t max_fall; // u(16)
+
+ // User defined metadata
+ uint128_t uuid;
+ uint8_t *user_defined_data_payload; // table of size payloadSize - 16
+
+ // Undefined metadata
+ uint8_t *undefined_metadata_payload_byte; // table of size payloadSize
+
+ filler_t filler;
+
+ uint8_t alignment_bit_equal_to_zero;
+} metadata_t;
+
+// 5.3.2. Primitive bitstream unit
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-primitive-bitstrā¦
+typedef struct pbu_t {
+ pbu_header_t pbu_header;
+ frame_t frame;
+ au_info_t au_info;
+ metadata_t metadata;
+ filler_t filler;
+} pbu_t;
+
+static int apv_read_pbu_header(GetBitContext *gb, pbu_header_t *pbu_header)
+{
+ pbu_header->pbu_type = get_bits(gb, 8);
+ pbu_header->group_id = get_bits(gb, 16);
+ pbu_header->reserved_zero_8bits = get_bits(gb, 8);
+
+ return 0;
+}
+
+// @see https://www.ietf.org/archive/id/draft-lim-apv-04.html#name-frame-information
+static int apv_read_frame_info(GetBitContext *gb, frame_info_t *frame_info)
+{
+ uint8_t reserved_zero_5bits;
+ uint8_t reserved_zero_8bits;
+
+ frame_info->profile_idc = get_bits(gb, 8);
+ frame_info->level_idc = get_bits(gb, 8);
+ frame_info->band_idc = get_bits(gb, 3);
+
+ reserved_zero_5bits = get_bits(gb, 5);
+
+ frame_info->frame_width = get_bits(gb,24);
+ frame_info->frame_height = get_bits(gb,24);
+
+ frame_info->chroma_format_idc = get_bits(gb, 4);
+ frame_info->bit_depth_minus8 = get_bits(gb, 4);
+
+ frame_info->capture_time_distance = get_bits(gb, 8);
+ reserved_zero_8bits = get_bits(gb, 8);
+
+ if (reserved_zero_5bits != 0x00)
+ return -1;
+
+ if (reserved_zero_8bits != 0x00)
+ return -1;
+
+ return 0;
+}
+
+static int apv_read_frame_header(GetBitContext *gb, frame_header_t *frame_header)
+{
+ uint8_t reserved_zero_8bits[2];
+
+ apv_read_frame_info(gb, &frame_header->frame_info);
+
+ reserved_zero_8bits[0] = get_bits(gb, 8);
+ if(reserved_zero_8bits[0]!=0) {
+ return -1;
+ }
+
+ frame_header->color_description_present_flag = get_bits(gb, 1);
+ if(frame_header->color_description_present_flag) {
+ frame_header->color_primaries = get_bits(gb, 8);
+ frame_header->transfer_characteristics = get_bits(gb, 8);
+ frame_header->matrix_coefficients = get_bits(gb, 8);
+ frame_header->full_range_flag = get_bits(gb, 1);
+ }
+
+ // The further parsing of AU is not needed
+
+ return 0;
+}
+
+static inline uint32_t apv_read_pbu_size(const uint8_t *bits, int bits_size)
+{
+ uint32_t pbu_size = 0;
+
+ if (bits_size < APV_PBU_SIZE_PREFIX_LENGTH) {
+ av_log(NULL, AV_LOG_ERROR, "Can't read PBU (primitive bitstream unit) size\n");
+ return 0;
+ }
+
+ pbu_size = AV_RB32(bits);
+
+ return pbu_size;
+}
+
+static int apv_read_au_info(GetBitContext *gb, au_info_t *au_info)
+{
+ int ret = 0;
+ au_info->num_frames = get_bits(gb, 16);
+
+ for(int idx=0; idx<au_info->num_frames; idx++) {
+ au_info->pbu_type = get_bits(gb, 8);
+ au_info->group_id = get_bits(gb, 16);
+ au_info->reserved_zero_8bits = get_bits(gb, 8);
+
+ ret = apv_read_frame_info(gb, &au_info->frame_info);
+ if(ret!=0) return ret;
+ }
+ au_info->reserved_zero_8bits_2 = get_bits(gb, 8);
+ if(au_info->reserved_zero_8bits_2!=0) return -1;
+
+ // The further parsing of AU Info is not needed
+
+ return ret;
+}
+
+static int apv_read_frame(GetBitContext *gb, frame_t *frame)
+{
+ apv_read_frame_header(gb, &frame->frame_header);
+
+ // The further parsing of frame is not needed
+
+ return 0;
+}
+
+// primitive bytestream unit
+static int apv_read_pbu(const uint8_t *bs, int bs_size, pbu_t *pbu)
+{
+ GetBitContext gb;
+
+ int ret = init_get_bits8(&gb, bs, bs_size);
+ if (ret < 0)
+ return ret;
+
+ ret = apv_read_pbu_header(&gb, &pbu->pbu_header);
+ if (ret < 0)
+ return ret;
+ if(( 1 <= pbu->pbu_header.pbu_type && pbu->pbu_header.pbu_type <= 2) ||
+ ( 25 <= pbu->pbu_header.pbu_type && pbu->pbu_header.pbu_type <= 27) ) {
+ ret = apv_read_frame(&gb, &pbu->frame);
+ } else if(pbu->pbu_header.pbu_type ==65) {
+ ret = apv_read_au_info(&gb, &pbu->au_info);
+ } else {
+ ret = -1;
+ }
+
+ return ret;
+}
+
+static int apv_number_of_pbu_entry(const uint8_t *data, uint32_t au_size) {
+ uint32_t currReadSize = 0;
+ int ret = 0;
+
+ do {
+ uint32_t pbu_size = apv_read_pbu_size(data + currReadSize, APV_PBU_SIZE_PREFIX_LENGTH);
+ if (pbu_size == 0) return -1;
+
+ currReadSize += APV_PBU_SIZE_PREFIX_LENGTH;
+ currReadSize += pbu_size;
+ ret++;
+ } while(au_size > currReadSize);
+
+ return ret;
+}
+
+static void apvc_init(APVDecoderConfigurationRecord * apvc)
+{
+ memset(apvc, 0, sizeof(APVDecoderConfigurationRecord ));
+ apvc->configurationVersion = 1;
+}
+
+static void apvc_close(APVDecoderConfigurationRecord *apvc)
+{
+ for(int i=0;i<apvc->number_of_configuration_entry;i++) {
+ for(int j=0;j<apvc->configuration_entry[i].number_of_frame_info;j++) {
+ free(apvc->configuration_entry[i].frame_info[j]);
+ }
+ free(apvc->configuration_entry[i].frame_info);
+ apvc->configuration_entry[i].number_of_frame_info = 0;
+ }
+ apvc->number_of_configuration_entry = 0;
+}
+
+static int apvc_write(AVIOContext *pb, APVDecoderConfigurationRecord * apvc)
+{
+ av_log(NULL, AV_LOG_TRACE, "configurationVersion: %"PRIu8"\n",
+ apvc->configurationVersion);
+
+ av_log(NULL, AV_LOG_TRACE, "number_of_configuration_entry: %"PRIu8"\n",
+ apvc->number_of_configuration_entry);
+
+ for(int i=0; i<apvc->number_of_configuration_entry;i++) {
+ av_log(NULL, AV_LOG_TRACE, "pbu_type: %"PRIu8"\n",
+ apvc->configuration_entry[i].pbu_type);
+
+ av_log(NULL, AV_LOG_TRACE, "number_of_frame_info: %"PRIu8"\n",
+ apvc->configuration_entry[i].number_of_frame_info);
+
+ for(int j=0; j < apvc->configuration_entry[i].number_of_frame_info; j++) {
+ av_log(NULL, AV_LOG_TRACE, "color_description_present_flag: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->color_description_present_flag);
+
+ av_log(NULL, AV_LOG_TRACE, "capture_time_distance_ignored: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->capture_time_distance_ignored);
+
+ av_log(NULL, AV_LOG_TRACE, "profile_idc: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->profile_idc);
+
+ av_log(NULL, AV_LOG_TRACE, "level_idc: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->level_idc);
+
+ av_log(NULL, AV_LOG_TRACE, "band_idc: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->band_idc);
+
+ av_log(NULL, AV_LOG_TRACE, "frame_width: %"PRIu32"\n",
+ apvc->configuration_entry[i].frame_info[j]->frame_width);
+
+ av_log(NULL, AV_LOG_TRACE, "frame_height: %"PRIu32"\n",
+ apvc->configuration_entry[i].frame_info[j]->frame_height);
+
+ av_log(NULL, AV_LOG_TRACE, "chroma_format_idc: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->chroma_format_idc);
+
+ av_log(NULL, AV_LOG_TRACE, "bit_depth_minus8: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->bit_depth_minus8);
+
+ av_log(NULL, AV_LOG_TRACE, "capture_time_distance: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->capture_time_distance);
+
+ if(apvc->configuration_entry[i].frame_info[j]->color_description_present_flag) {
+
+ av_log(NULL, AV_LOG_TRACE, "color_primaries: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->color_primaries);
+
+ av_log(NULL, AV_LOG_TRACE, "transfer_characteristics: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->transfer_characteristics);
+
+ av_log(NULL, AV_LOG_TRACE, "matrix_coefficients: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->matrix_coefficients);
+
+ av_log(NULL, AV_LOG_TRACE, "full_range_flag: %"PRIu8"\n",
+ apvc->configuration_entry[i].frame_info[j]->full_range_flag);
+ }
+
+ }
+ }
+
+ /* unsigned int(8) configurationVersion = 1; */
+ avio_w8(pb, apvc->configurationVersion);
+
+ avio_w8(pb, apvc->number_of_configuration_entry);
+
+ for(int i=0; i<apvc->number_of_configuration_entry;i++) {
+ avio_w8(pb, apvc->configuration_entry[i].pbu_type);
+ avio_w8(pb, apvc->configuration_entry[i].number_of_frame_info);
+
+ for(int j=0; j < apvc->configuration_entry[i].number_of_frame_info; j++) {
+
+ /* unsigned int(6) reserved_zero_6bits
+ * unsigned int(1) color_description_present_flag
+ * unsigned int(1) capture_time_distance_ignored
+ */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->reserved_zero_6bits << 2 |
+ apvc->configuration_entry[i].frame_info[j]->color_description_present_flag << 1 |
+ apvc->configuration_entry[i].frame_info[j]->capture_time_distance_ignored);
+
+ /* unsigned int(8) profile_idc */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->profile_idc);
+
+ /* unsigned int(8) level_idc */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->level_idc);
+
+ /* unsigned int(8) band_idc */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->band_idc);
+
+ /* unsigned int(32) frame_width_minus1 */
+ avio_wb32(pb, apvc->configuration_entry[i].frame_info[j]->frame_width);
+
+ /* unsigned int(32) frame_height_minus1 */
+ avio_wb32(pb, apvc->configuration_entry[i].frame_info[j]->frame_height);
+
+ /* unsigned int(4) chroma_format_idc */
+ /* unsigned int(4) bit_depth_minus8 */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->chroma_format_idc << 4 | apvc->configuration_entry[i].frame_info[j]->bit_depth_minus8);
+
+ /* unsigned int(8) capture_time_distance */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->capture_time_distance);
+
+ if(apvc->configuration_entry[i].frame_info[j]->color_description_present_flag) {
+ /* unsigned int(8) color_primaries */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->color_primaries);
+
+ /* unsigned int(8) transfer_characteristics */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->transfer_characteristics);
+
+ /* unsigned int(8) matrix_coefficients */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->matrix_coefficients);
+
+ /* unsigned int(1) full_range_flag */
+ avio_w8(pb, apvc->configuration_entry[i].frame_info[j]->full_range_flag << 7 |
+ apvc->configuration_entry[i].frame_info[j]->reserved_zero_7bits);
+ }
+ }
+ }
+
+ return 0;
+}
+
+int ff_isom_write_apvc(AVIOContext *pb, const uint8_t *data,
+ int size, int ps_array_completeness)
+{
+ APVDecoderConfigurationRecord *apvc = (APVDecoderConfigurationRecord *)data;
+ int ret = 0;
+
+ if (size < 8) {
+ /* We can't write a valid apvC from the provided data */
+ return AVERROR_INVALIDDATA;
+ }
+
+ if(size!=sizeof(APVDecoderConfigurationRecord)) return -1;
+ ret = apvc_write(pb, apvc);
+
+ apvc_close(apvc);
+ return ret;
+}
+
+static int apv_add_frameinfo(APVDecoderConfigurationEntry *configuration_entry, APVDecoderFrameInfo *frame_info) {
+ APVDecoderFrameInfo **temp = NULL;
+ if(configuration_entry->number_of_frame_info == 0) {
+ temp = (APVDecoderFrameInfo **)malloc(sizeof(APVDecoderFrameInfo*));
+ if (temp == NULL) {
+ return AVERROR_INVALIDDATA;
+ }
+ } else {
+ temp = (APVDecoderFrameInfo **)realloc(configuration_entry->frame_info, (configuration_entry->number_of_frame_info + 1) * sizeof(APVDecoderFrameInfo*));
+ if (temp == NULL) {
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
+ temp[configuration_entry->number_of_frame_info] = (APVDecoderFrameInfo*)malloc(sizeof(APVDecoderFrameInfo));
+ memcpy(temp[configuration_entry->number_of_frame_info], frame_info, sizeof(APVDecoderFrameInfo));
+
+ configuration_entry->frame_info = temp;
+
+ configuration_entry->number_of_frame_info++;
+
+ return 0;
+}
+
+static bool apv_cmp_frameinfo(const APVDecoderFrameInfo *a, const APVDecoderFrameInfo *b) {
+ if (a->reserved_zero_6bits != b->reserved_zero_6bits) return false;
+ if (a->color_description_present_flag != b->color_description_present_flag) return false;
+ if (a->capture_time_distance_ignored != b->capture_time_distance_ignored) return false;
+ if (a->profile_idc != b->profile_idc) return false;
+ if (a->level_idc != b->level_idc) return false;
+ if (a->band_idc != b->band_idc) return false;
+ if (a->frame_width != b->frame_width) return false;
+ if (a->frame_height != b->frame_height) return false;
+ if (a->chroma_format_idc != b->chroma_format_idc) return false;
+ if (a->bit_depth_minus8 != b->bit_depth_minus8) return false;
+ if (a->capture_time_distance != b->capture_time_distance) return false;
+ if (a->color_primaries != b->color_primaries) return false;
+ if (a->transfer_characteristics != b->transfer_characteristics) return false;
+ if (a->matrix_coefficients != b->matrix_coefficients) return false;
+ if (a->full_range_flag != b->full_range_flag) return false;
+ if (a->reserved_zero_7bits != b->reserved_zero_7bits) return false;
+
+ return true;
+}
+
+static int apv_set_frameinfo(APVDecoderFrameInfo* frame_info, const pbu_t *pbu) {
+ frame_info->reserved_zero_6bits = 0;
+
+ frame_info->color_description_present_flag = pbu->frame.frame_header.color_description_present_flag;
+ frame_info->capture_time_distance_ignored = 1;
+
+ frame_info->profile_idc = pbu->frame.frame_header.frame_info.profile_idc;
+ frame_info->level_idc = pbu->frame.frame_header.frame_info.level_idc;
+ frame_info->band_idc = pbu->frame.frame_header.frame_info.band_idc;
+
+ frame_info->frame_width = pbu->frame.frame_header.frame_info.frame_width;
+ frame_info->frame_height = pbu->frame.frame_header.frame_info.frame_height;
+
+ frame_info->chroma_format_idc = pbu->frame.frame_header.frame_info.chroma_format_idc;
+ frame_info->bit_depth_minus8 = pbu->frame.frame_header.frame_info.bit_depth_minus8;
+
+ frame_info->capture_time_distance = pbu->frame.frame_header.frame_info.capture_time_distance;
+
+
+ if(frame_info->color_description_present_flag) {
+ frame_info->color_primaries = pbu->frame.frame_header.color_primaries;
+ frame_info->transfer_characteristics = pbu->frame.frame_header.transfer_characteristics;
+ frame_info->matrix_coefficients = pbu->frame.frame_header.matrix_coefficients;
+
+ frame_info->full_range_flag = pbu->frame.frame_header.full_range_flag;
+ frame_info->reserved_zero_7bits = 0;
+ }
+
+ return 0;
+}
+
+int ff_isom_create_apv_dconf_record(uint8_t **data, int *size) {
+ *size = sizeof(APVDecoderConfigurationRecord);
+ *data = (uint8_t*)av_malloc(sizeof(APVDecoderConfigurationRecord));
+ if(*data==NULL) {
+ *size = 0;
+ return AVERROR_INVALIDDATA;
+ }
+ apvc_init((APVDecoderConfigurationRecord*)*data);
+ return 0;
+}
+
+void ff_isom_free_apv_dconf_record(uint8_t **data) {
+ if (data != NULL && *data != NULL) {
+ APVDecoderConfigurationRecord* apvc = (APVDecoderConfigurationRecord*)*data;
+ apvc_close(apvc);
+
+ free(*data);
+ *data = NULL;
+ }
+}
+
+int ff_isom_fill_apv_dconf_record(const uint8_t *apvdcr, const uint8_t *data, int size) {
+
+ uint32_t au_size = 0;
+ uint32_t number_of_pbu_entry = 0;
+
+ uint32_t frame_type = -1;
+ APVDecoderFrameInfo frame_info;
+
+ int bytes_to_read = size;
+ int ret = 0;
+
+ APVDecoderConfigurationRecord* apvc = (APVDecoderConfigurationRecord*)apvdcr;
+ if (size < 8) {
+ /* We can't write a valid apvC from the provided data */
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (bytes_to_read > APV_AU_SIZE_PREFIX_LENGTH) {
+ au_size = apv_read_au_size(data, APV_AU_SIZE_PREFIX_LENGTH);
+ if (au_size == 0) {
+ ret = AVERROR_INVALIDDATA;
+ goto end;
+ }
+
+ data += APV_AU_SIZE_PREFIX_LENGTH;
+ bytes_to_read -= APV_AU_SIZE_PREFIX_LENGTH;
+
+ if (bytes_to_read < au_size) {
+ ret = AVERROR_INVALIDDATA;
+ goto end;
+ }
+
+ data += APV_SIGNATURE_LENGTH;
+ bytes_to_read -= APV_SIGNATURE_LENGTH;
+
+ // pbu (primitive bitstream units number)
+ //
+ number_of_pbu_entry = apv_number_of_pbu_entry(data, bytes_to_read);
+ if (number_of_pbu_entry <= 0) {
+ ret = AVERROR_INVALIDDATA;
+ goto end;
+ }
+
+ for(int i=0;i<number_of_pbu_entry;i++) {
+
+ pbu_t pbu;
+ uint32_t pbu_size = apv_read_pbu_size(data, APV_PBU_SIZE_PREFIX_LENGTH);
+
+ data += APV_AU_SIZE_PREFIX_LENGTH;
+
+ if(!apv_read_pbu(data, pbu_size, &pbu)) {
+
+ switch (pbu.pbu_header.pbu_type)
+ {
+ case APV_PBU_TYPE_PRIMARY_FRAME:
+ frame_type = APV_FRAME_TYPE_PRIMARY_FRAME;
+ break;
+ case APV_PBU_TYPE_NON_PRIMARY_FRAME:
+ frame_type = APV_FRAME_TYPE_NON_PRIMARY_FRAME;
+ break;
+ case APV_PBU_TYPE_PREVIEW_FRAME:
+ frame_type = APV_FRAME_TYPE_PREVIEW_FRAME;
+ break;
+ case APV_PBU_TYPE_DEPTH_FRAME:
+ frame_type = APV_FRAME_TYPE_DEPTH_FRAME;
+ break;
+ case APV_PBU_TYPE_ALPHA_FRAME:
+ frame_type = APV_FRAME_TYPE_ALPHA_FRAME;
+ break;
+ default:
+ frame_type = APV_FRAME_TYPE_NON_FRAME;
+ break;
+ };
+
+ if(frame_type == APV_FRAME_TYPE_NON_FRAME) continue;
+
+ apv_set_frameinfo(&frame_info, &pbu);
+
+ if(apvc->configuration_entry[frame_type].number_of_frame_info == 0) {
+ apv_add_frameinfo(&apvc->configuration_entry[frame_type], &frame_info);
+ apvc->number_of_configuration_entry++;
+ } else {
+ for(i=0; i<apvc->configuration_entry[frame_type].number_of_frame_info;i++) {
+ if(!apv_cmp_frameinfo(apvc->configuration_entry[frame_type].frame_info[i], &frame_info)) {
+ apv_add_frameinfo(&apvc->configuration_entry[i], &frame_info);
+ break;
+ }
+ }
+ }
+ }
+ data += pbu_size;
+ }
+ }
+
+end:
+ return ret;
+}
diff --git a/libavformat/apv.h b/libavformat/apv.h
new file mode 100644
index 0000000000..5347f7cda4
--- /dev/null
+++ b/libavformat/apv.h
@@ -0,0 +1,88 @@
+/*
+ * APV helper functions for muxers
+ * Copyright (c) 2025 Dawid Kozinski <d.kozinski(a)samsung.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_APV_H
+#define AVFORMAT_APV_H
+
+#include <stdint.h>
+
+#include "libavutil/intreadwrite.h"
+#include "libavutil/rational.h"
+#include "libavcodec/apv.h"
+#include "avio.h"
+
+#define APV_AU_SIZE_PREFIX_LENGTH (4)
+
+static inline uint32_t apv_read_au_size(const uint8_t *bits, int bits_size)
+{
+ if (bits_size >= APV_AU_SIZE_PREFIX_LENGTH)
+ return AV_RB32(bits);
+
+ return 0;
+}
+
+/**
+ * Writes APV sample metadata to the provided AVIOContext.
+ *
+ * @param pb pointer to the AVIOContext where the apv sample metadata shall be written
+ * @param buf input data buffer
+ * @param size size in bytes of the input data buffer
+ * @param ps_array_completeness
+ *
+ * @return 0 in case of success, a negative error code in case of failure
+ */
+int ff_isom_write_apvc(AVIOContext *pb, const uint8_t *data,
+ int size, int ps_array_completeness);
+
+/**
+ * @brief Creates and allocates memory for an APV decoder configuration record.
+ *
+ * This function allocates memory for an APVDecoderConfigurationRecord and
+ * initializes it. The size of the record is returned through the `size` parameter.
+ *
+ * @param data Pointer to a pointer where the allocated data will be stored.
+ * @param size Pointer to an integer where the size of the allocated record will be stored.
+ * @return 0 on success, or AVERROR_INVALIDDATA if memory allocation fails.
+ */
+int ff_isom_create_apv_dconf_record(uint8_t **data, int *size);
+
+/**
+ * @brief Frees the memory allocated for the APV decoder configuration record.
+ *
+ * @param data data to be freed
+ */
+void ff_isom_free_apv_dconf_record(uint8_t **data);
+
+/**
+ * @brief Fills an APV decoder configuration record with data.
+ *
+ * This function populates the APVDecoderConfigurationRecord pointed to by
+ * `apvdcr` with the data from `data`, which has a specified size. The data
+ * represents an access unit.
+ *
+ * @param apvdcr Pointer to the APVDecoderConfigurationRecord to be filled.
+ * @param data Pointer to the data to fill the record with.
+ * @param size Size of the data to be copied into the record.
+ * @return 0 on success, or a negative value on error.
+ */
+int ff_isom_fill_apv_dconf_record(const uint8_t *apvc, const uint8_t *data, int size);
+
+#endif // AVFORMAT_APV_H
diff --git a/libavformat/isom_tags.c b/libavformat/isom_tags.c
index f05762beec..6b8ab9c2df 100644
--- a/libavformat/isom_tags.c
+++ b/libavformat/isom_tags.c
@@ -156,6 +156,7 @@ const AVCodecTag ff_codec_movvideo_tags[] = {
{ AV_CODEC_ID_H264, MKTAG('d', 'v', 'a', 'v') }, /* AVC-based Dolby Vision derived from avc3 */
{ AV_CODEC_ID_EVC, MKTAG('e', 'v', 'c', '1') }, /* EVC/MPEG-5 */
+ { AV_CODEC_ID_APV, MKTAG('a', 'p', 'v', '1') }, /* APV */
{ AV_CODEC_ID_VP8, MKTAG('v', 'p', '0', '8') }, /* VP8 */
{ AV_CODEC_ID_VP9, MKTAG('v', 'p', '0', '9') }, /* VP9 */
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4bc8bd1b2a..3d3ce0e3b6 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -37,6 +37,7 @@
#include "av1.h"
#include "avc.h"
#include "evc.h"
+#include "apv.h"
#include "libavcodec/ac3_parser_internal.h"
#include "libavcodec/dnxhddata.h"
#include "libavcodec/flac.h"
@@ -1647,6 +1648,24 @@ static int mov_write_vvcc_tag(AVIOContext *pb, MOVTrack *track)
return update_size(pb, pos);
}
+static int mov_write_apvc_tag(AVIOContext *pb, MOVTrack *track)
+{
+ int64_t pos = avio_tell(pb);
+
+ avio_wb32(pb, 0);
+ ffio_wfourcc(pb, "apvC");
+
+ avio_w8 (pb, 0); /* version */
+ avio_wb24(pb, 0); /* flags */
+
+ if (track->tag == MKTAG('a','p','v','1'))
+ ff_isom_write_apvc(pb, track->vos_data, track->vos_len, 1);
+ else
+ ff_isom_write_apvc(pb, track->vos_data, track->vos_len, 0);
+
+ return update_size(pb, pos);
+}
+
/* also used by all avid codecs (dv, imx, meridien) and their variants */
static int mov_write_avid_tag(AVIOContext *pb, MOVTrack *track)
{
@@ -1906,6 +1925,17 @@ static int mov_get_evc_codec_tag(AVFormatContext *s, MOVTrack *track)
return tag;
}
+static int mov_get_apv_codec_tag(AVFormatContext *s, MOVTrack *track)
+{
+ int tag = track->par->codec_tag;
+
+ if (!tag)
+ tag = MKTAG('a', 'p', 'v', '1');
+
+ return tag;
+}
+
+
static const struct {
enum AVPixelFormat pix_fmt;
uint32_t tag;
@@ -1992,6 +2022,8 @@ static unsigned int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track)
tag = mov_get_h264_codec_tag(s, track);
else if (track->par->codec_id == AV_CODEC_ID_EVC)
tag = mov_get_evc_codec_tag(s, track);
+ else if (track->par->codec_id == AV_CODEC_ID_APV)
+ tag = mov_get_apv_codec_tag(s, track);
else if (track->par->codec_id == AV_CODEC_ID_DNXHD)
tag = mov_get_dnxhd_codec_tag(s, track);
else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {
@@ -2757,6 +2789,8 @@ static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex
}
else if (track->par->codec_id ==AV_CODEC_ID_EVC) {
mov_write_evcc_tag(pb, track);
+ } else if (track->par->codec_id ==AV_CODEC_ID_APV) {
+ mov_write_apvc_tag(pb, track);
} else if (track->par->codec_id == AV_CODEC_ID_VP9) {
mov_write_vpcc_tag(mov->fc, pb, track);
} else if (track->par->codec_id == AV_CODEC_ID_AV1) {
@@ -6713,6 +6747,18 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
memset(trk->vos_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
}
+ if (par->codec_id == AV_CODEC_ID_APV && !trk->vos_len) {
+ ret = ff_isom_create_apv_dconf_record(&trk->vos_data, &trk->vos_len);
+ if (!trk->vos_data) {
+ ret = AVERROR(ENOMEM);
+ goto err;
+ }
+ }
+
+ if (par->codec_id == AV_CODEC_ID_APV && trk->vos_len) {
+ ret = ff_isom_fill_apv_dconf_record(trk->vos_data, pkt->data, size);
+ }
+
if (par->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 &&
(AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
if (!trk->st->nb_frames) {
@@ -6838,6 +6884,11 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
if (ret) {
goto err;
}
+ } else if (par->codec_id == AV_CODEC_ID_APV) {
+ avio_wb32(s->pb, pkt->size);
+ size += 4;
+
+ avio_write(s->pb, pkt->data, pkt->size);
} else {
avio_write(pb, pkt->data, size);
}
@@ -8651,6 +8702,7 @@ static const AVCodecTag codec_mp4_tags[] = {
{ AV_CODEC_ID_VVC, MKTAG('v', 'v', 'c', '1') },
{ AV_CODEC_ID_VVC, MKTAG('v', 'v', 'i', '1') },
{ AV_CODEC_ID_EVC, MKTAG('e', 'v', 'c', '1') },
+ { AV_CODEC_ID_APV, MKTAG('a', 'p', 'v', '1') },
{ AV_CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', '4', 'v') },
{ AV_CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', '4', 'v') },
{ AV_CODEC_ID_MJPEG, MKTAG('m', 'p', '4', 'v') },
--
2.34.1
2
1
[PATCH v1] avformat/mov_demuxer: Extended MOV demuxer to handle APV video content
by Dawid Kozinski 07 Jul '25
by Dawid Kozinski 07 Jul '25
07 Jul '25
- Added apv extension to the list of extensions for ff_mov_demuxer
Signed-off-by: Dawid Kozinski <d.kozinski(a)samsung.com>
---
libavformat/demux.c | 1 +
libavformat/mov.c | 7 ++++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 2795863567..4e76de0629 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -126,6 +126,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st,
{ "truehd", AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO },
{ "evc", AV_CODEC_ID_EVC, AVMEDIA_TYPE_VIDEO },
{ "vvc", AV_CODEC_ID_VVC, AVMEDIA_TYPE_VIDEO },
+ { "apv", AV_CODEC_ID_APV, AVMEDIA_TYPE_VIDEO },
{ 0 }
};
int score;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index cb81b6c4da..b7495b33ed 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2982,6 +2982,7 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb,
case AV_CODEC_ID_VP9:
sti->need_parsing = AVSTREAM_PARSE_FULL;
break;
+ case AV_CODEC_ID_APV:
case AV_CODEC_ID_EVC:
case AV_CODEC_ID_AV1:
/* field_order detection of H264 requires parsing */
@@ -9318,6 +9319,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
#if CONFIG_IAMFDEC
{ MKTAG('i','a','c','b'), mov_read_iacb },
#endif
+{ MKTAG('a','p','v','C'), mov_read_glbl },
{ 0, NULL }
};
@@ -11022,7 +11024,10 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
return FFERROR_REDO;
}
#endif
- else
+ else if(st->codecpar->codec_id == AV_CODEC_ID_APV && sample->size > 4) {
+ const uint32_t au_size = avio_rb32(sc->pb);
+ ret = av_get_packet(sc->pb, pkt, au_size);
+ } else
ret = av_get_packet(sc->pb, pkt, sample->size);
if (ret < 0) {
if (should_retry(sc->pb, ret)) {
--
2.34.1
2
1
07 Jul '25
Resolves an unused variable warning when targeting a recent appleOS
version.
---
libavutil/hwcontext_videotoolbox.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c
index 172683121f..102fa485e5 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -540,8 +540,6 @@ CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteri
static CFDictionaryRef vt_cv_buffer_copy_attachments(CVBufferRef buffer,
CVAttachmentMode attachment_mode)
{
- CFDictionaryRef dict;
-
// Check that our SDK is at least macOS 12 / iOS 15 / tvOS 15
#if (TARGET_OS_OSX && defined(__MAC_12_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0) || \
(TARGET_OS_IOS && defined(__IPHONE_15_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_15_0) || \
@@ -558,7 +556,7 @@ static CFDictionaryRef vt_cv_buffer_copy_attachments(CVBufferRef buffer,
(TARGET_OS_IOS && (!defined(__IPHONE_15_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_15_0)) || \
(TARGET_OS_TV && (!defined(__TVOS_15_0) || __TV_OS_VERSION_MIN_REQUIRED < __TVOS_15_0))
// Fallback on SDKs or runtime versions < macOS 12 / iOS 15 / tvOS 15
- dict = CVBufferGetAttachments(buffer, attachment_mode);
+ CFDictionaryRef dict = CVBufferGetAttachments(buffer, attachment_mode);
return (dict) ? CFDictionaryCreateCopy(NULL, dict) : NULL;
#else
return NULL; // Impossible, just make the compiler happy
--
2.39.5 (Apple Git-154)
1
2
Given that OPENSSL_init_ssl was introduced in 1.1.0 means we can rely on
that to ensure we have at least 1.1.0.
---
configure | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/configure b/configure
index d625461983..25d736170b 100755
--- a/configure
+++ b/configure
@@ -7193,13 +7193,10 @@ enabled omx && require_headers OMX_Core.h && \
enabled openssl && { { check_pkg_config openssl "openssl >= 3.0.0" openssl/ssl.h OPENSSL_init_ssl &&
{ enabled gplv3 || ! enabled gpl || enabled nonfree || die "ERROR: OpenSSL >=3.0.0 requires --enable-version3"; }; } ||
{ enabled gpl && ! enabled nonfree && die "ERROR: OpenSSL <3.0.0 is incompatible with the gpl"; } ||
- check_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
- check_pkg_config openssl openssl openssl/ssl.h SSL_library_init ||
+ check_pkg_config openssl "openssl >= 1.1.0" openssl/ssl.h OPENSSL_init_ssl ||
check_lib openssl openssl/ssl.h OPENSSL_init_ssl -lssl -lcrypto ||
- check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto ||
- check_lib openssl openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
- check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
- die "ERROR: openssl not found"; }
+ check_lib openssl openssl/ssl.h OPENSSL_init_ssl -lssl -lcrypto -lws2_32 -lgdi32 ||
+ die "ERROR: openssl (>= 1.1.0) not found"; }
enabled pocketsphinx && require_pkg_config pocketsphinx pocketsphinx pocketsphinx/pocketsphinx.h ps_init
enabled rkmpp && { require_pkg_config rkmpp rockchip_mpp rockchip/rk_mpi.h mpp_create &&
require_pkg_config rockchip_mpp "rockchip_mpp >= 1.3.7" rockchip/rk_mpi.h mpp_create &&
--
2.39.5 (Apple Git-154)
1
9
[PATCH 1/8] avcodec/psd: Move frame allocation after RLE processing
by Michael Niedermayer 06 Jul '25
by Michael Niedermayer 06 Jul '25
06 Jul '25
Fixes: Timeout
Fixes: 410609448/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PSD_fuzzer-6267226128973824
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael(a)niedermayer.cc>
---
libavcodec/psd.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavcodec/psd.c b/libavcodec/psd.c
index 9c3e4f69052..f0b90ec1bd7 100644
--- a/libavcodec/psd.c
+++ b/libavcodec/psd.c
@@ -418,9 +418,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
s->uncompressed_size = s->line_size * s->height * s->channel_count;
- if ((ret = ff_get_buffer(avctx, picture, 0)) < 0)
- return ret;
-
/* decode picture if need */
if (s->compression == PSD_RLE) {
s->tmp = av_malloc(s->uncompressed_size);
@@ -443,6 +440,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
ptr_data = s->gb.buffer;
}
+ if ((ret = ff_get_buffer(avctx, picture, 0)) < 0)
+ return ret;
+
/* Store data */
if ((avctx->pix_fmt == AV_PIX_FMT_YA8)||(avctx->pix_fmt == AV_PIX_FMT_YA16BE)){/* Interleaved */
ptr = picture->data[0];
--
2.49.0
4
17
[PATCH v2] avutil/hwcontext_d3d12va: added resource Flags support to command line
by Dmitrii Ovchinnikov 06 Jul '25
by Dmitrii Ovchinnikov 06 Jul '25
06 Jul '25
---
libavutil/hwcontext_d3d12va.c | 22 +++++++++++++++++++++-
libavutil/hwcontext_d3d12va.h | 6 ++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index 6507cf69c1..b2b58ac6f8 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -254,7 +254,7 @@ static AVBufferRef *d3d12va_pool_alloc(void *opaque, size_t size)
if (!frame)
return NULL;
- if (FAILED(ID3D12Device_CreateCommittedResource(device_hwctx->device, &props, D3D12_HEAP_FLAG_NONE, &desc,
+ if (FAILED(ID3D12Device_CreateCommittedResource(device_hwctx->device, &props, hwctx->heap_flags, &desc,
D3D12_RESOURCE_STATE_COMMON, NULL, &IID_ID3D12Resource, (void **)&frame->texture))) {
av_log(ctx, AV_LOG_ERROR, "Could not create the texture\n");
goto fail;
@@ -281,6 +281,7 @@ fail:
static int d3d12va_frames_init(AVHWFramesContext *ctx)
{
AVD3D12VAFramesContext *hwctx = ctx->hwctx;
+ AVD3D12VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
int i;
for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
@@ -298,6 +299,9 @@ static int d3d12va_frames_init(AVHWFramesContext *ctx)
return AVERROR(EINVAL);
}
+ hwctx->flags |= device_hwctx->flags;
+ hwctx->heap_flags |= device_hwctx->heap_flags;
+
ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2(sizeof(AVD3D12VAFrame),
ctx, d3d12va_pool_alloc, NULL);
@@ -673,6 +677,22 @@ static int d3d12va_device_create(AVHWDeviceContext *hwdev, const char *device,
}
}
+ ctx->flags = 0;
+ ctx->heap_flags = 0;
+
+ // "shader_resouce" already enabled by default.
+
+ if (av_dict_get(opts, "uav_res", NULL, 0))
+ ctx->flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
+
+ if (av_dict_get(opts, "render_target_res", NULL, 0))
+ ctx->flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
+
+ ctx->heap_flags = D3D12_HEAP_FLAG_NONE;
+
+ if (av_dict_get(opts, "shared_res", NULL, 0))
+ ctx->heap_flags |= D3D12_HEAP_FLAG_SHARED;
+
return 0;
}
diff --git a/libavutil/hwcontext_d3d12va.h b/libavutil/hwcontext_d3d12va.h
index 212a6a6146..2075bd4a48 100644
--- a/libavutil/hwcontext_d3d12va.h
+++ b/libavutil/hwcontext_d3d12va.h
@@ -75,6 +75,11 @@ typedef struct AVD3D12VADeviceContext {
void (*lock)(void *lock_ctx);
void (*unlock)(void *lock_ctx);
void *lock_ctx;
+ /**
+ * Need to pass value to frames context from command line
+ */
+ D3D12_RESOURCE_FLAGS flags;
+ D3D12_HEAP_FLAGS heap_flags;
} AVD3D12VADeviceContext;
/**
@@ -137,6 +142,7 @@ typedef struct AVD3D12VAFramesContext {
* @see https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_reā¦
*/
D3D12_RESOURCE_FLAGS flags;
+ D3D12_HEAP_FLAGS heap_flags;
} AVD3D12VAFramesContext;
#endif /* AVUTIL_HWCONTEXT_D3D12VA_H */
--
2.47.1.windows.1
2
1
06 Jul '25
This patch series fixes memory leaks in `avfilter/asrc_sinc` and
`avformat/sapenc`.
-----BEGIN PGP PUBLIC KEY BLOCK-----
mDMEaEpkmRYJKwYBBAHaRw8BAQdAGwGqH/Dwod+i6kR0/Rhn5GanJ7wK8mM9tWP/
W2qu8Ti0HTUwMjAyNDMzMDA1NkBzbWFpbC5uanUuZWR1LmNuiJkEExYKAEEWIQQC
zskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIbAwUJBaOagAULCQgHAgIiAgYVCgkI
CwIEFgIDAQIeBwIXgAAKCRCZR31bPD+6o8wHAQCLomsA4XfTd8IdG983gGULUJe/
0432buy4nX7AsAc87QEA+/QIsWTR6XLJaLa1sLSQCsZkb86U3c17JzG9oivL8gW4
OARoSmSZEgorBgEEAZdVAQUBAQdAfYrEAWd+6bOXkKvHpFmMvKzxAtlhm6ZQKdAq
+MlJ7wQDAQgHiHgEGBYKACAWIQQCzskBcOehk1y8GoKZR31bPD+6owUCaEpkmQIb
DAAKCRCZR31bPD+6ozWxAQC9OFisWrP/hHXUfj8AnC39r5pf5fEBz7lHvFgWNk2b
XwD7Bl6kvIIW7ReqtgXvcl7u78vEo+e9YeTGTlmAogjpeQk=
=rP+W
-----END PGP PUBLIC KEY BLOCK-----
Lidong Yan (3):
avfilter/asrc_sinc: fix leak in config_input()
avformat/sapenc: fix leak in sap_write_header()
avformat/sapenc: reword fail to cleanup in sap_write_header()
libavfilter/asrc_sinc.c | 18 +++++++++++-------
libavformat/sapenc.c | 34 +++++++++++++++++++---------------
2 files changed, 30 insertions(+), 22 deletions(-)
--
2.50.0.106.gf0135a9047.dirty
2
6
Since v2:
- rebased to current master
- removed "libavcodec/tests: fix gitignore hashtable" which
was applied recently
- added two new patches at the end of the serie
Nicolas Gaullier (21):
tests/Makefile: make easier to check for multiple dependencies
fate/all: add missing dependencies for extradata bsf
fate/demux: fix multiple dependencies
fate/all: switch-fix mov muxer dependency to mp4 muxer dependency
fate/mov: fix multiple dependencies
fate/gapless: fix multiple dependencies
fate/lavf-container: fix multiple dependencies
fate/vorbis: fix multiple dependencies
fate/aac: fix multiple dependencies
fate/audio: fix multiple dependencies
fate/ac3: fix multiple dependencies
fate/cover-art: fix multiple dependencies
fate/hlsenc: fix multiple dependencies
fate/mpeg4: fix multiple dependencies
fate/pcm: fix multiple dependencies
fate/hevc: fix multiple dependencies
fate/all: fix multiple dependencies
fate/all: add missing file protocol dependencies
fate/all: add missing crc/framecrc/md5/framemd5/pipe dependencies
fate/all: fix missing some mov demuxer dependencies
fate/seek: fix missing mpeg4video parser dependency
tests/Makefile | 20 ++++---
tests/fate/aac.mak | 14 ++---
tests/fate/ac3.mak | 10 ++--
tests/fate/acodec.mak | 4 +-
tests/fate/adpcm.mak | 38 ++++++-------
tests/fate/alac.mak | 2 +-
tests/fate/als.mak | 3 +-
tests/fate/amrnb.mak | 2 +-
tests/fate/amrwb.mak | 2 +-
tests/fate/api.mak | 2 +-
tests/fate/apng.mak | 2 +-
tests/fate/atrac.mak | 6 +-
tests/fate/audio.mak | 32 +++++------
tests/fate/caf.mak | 2 +-
tests/fate/cbs.mak | 6 +-
tests/fate/concatdec.mak | 2 +-
tests/fate/cover-art.mak | 24 ++++----
tests/fate/demux.mak | 104 +++++++++++++++++-----------------
tests/fate/dpcm.mak | 4 +-
tests/fate/enc_external.mak | 6 +-
tests/fate/ffmpeg.mak | 10 ++--
tests/fate/fifo-muxer.mak | 2 +-
tests/fate/filter-audio.mak | 24 ++++----
tests/fate/filter-video.mak | 22 +++----
tests/fate/fits.mak | 4 +-
tests/fate/flac.mak | 2 +-
tests/fate/flvenc.mak | 2 +-
tests/fate/gapless.mak | 78 ++++++++++++-------------
tests/fate/gif.mak | 2 +-
tests/fate/h264.mak | 14 +++--
tests/fate/hevc.mak | 10 ++--
tests/fate/hlsenc.mak | 20 ++++---
tests/fate/image.mak | 6 +-
tests/fate/imf.mak | 3 +-
tests/fate/indeo.mak | 18 +++---
tests/fate/lavf-container.mak | 32 +++++------
tests/fate/lavf-video.mak | 2 +-
tests/fate/libavformat.mak | 2 +-
tests/fate/libswresample.mak | 2 +-
tests/fate/lossless-audio.mak | 8 +--
tests/fate/matroska.mak | 31 +++++-----
tests/fate/microsoft.mak | 4 +-
tests/fate/monkeysaudio.mak | 3 +-
tests/fate/mov.mak | 52 +++++++++--------
tests/fate/mp3.mak | 2 +-
tests/fate/mpc.mak | 8 +--
tests/fate/mpeg4.mak | 11 ++--
tests/fate/mpegps.mak | 2 +-
tests/fate/ogg-flac.mak | 2 +-
tests/fate/oma.mak | 2 +-
tests/fate/pcm.mak | 19 ++++---
tests/fate/pixfmt.mak | 1 +
tests/fate/qoa.mak | 6 +-
tests/fate/real.mak | 16 +++---
tests/fate/seek.mak | 11 ++--
tests/fate/segment.mak | 6 +-
tests/fate/subtitles.mak | 7 ++-
tests/fate/vcodec.mak | 4 +-
tests/fate/video.mak | 4 +-
tests/fate/voice.mak | 16 +++---
tests/fate/vorbis.mak | 24 ++++----
tests/fate/vpx.mak | 4 +-
tests/fate/vqf.mak | 4 +-
tests/fate/wavpack.mak | 2 +-
tests/fate/wma.mak | 16 +++---
tests/fate/xvid.mak | 2 +-
66 files changed, 416 insertions(+), 391 deletions(-)
--
2.47.2
2
22
[PATCH v7] libavcodec/riscv: add RVV optimized idct_32x32_8 for HEVC
by daichengrongļ¼ iscas.ac.cn 05 Jul '25
by daichengrongļ¼ iscas.ac.cn 05 Jul '25
05 Jul '25
From: daichengrong <daichengrong(a)iscas.ac.cn>
On Banana PI F3:
hevc_idct_32x32_8_c: 119473.4 ( 1.00x) (rvv_256)
hevc_idct_32x32_8_rvv_i64: 5085.9 (23.49x) (rvv_256)
hevc_idct_32x32_8_c: 119859.3 ( 1.00x) (rvv_128)
hevc_idct_32x32_8_rvv_i64: 10108.9 (11.86x) (rvv_128)
Changes in v7:
Globally optimize VLEN > 128
Cancel explicit transposition
Optimize half-vector operations
Changes in v6:
Optimize data loading and avoid sliding half-sized vectors
Adopt an instruction sorting strategy that is more favorable to in-order cores
Encode more immediate values into instructions
Support register save and restore of different xlen
Optimize for VLEN > 128
Changes in v5:
Improve the continuity of vector operations
Optimize loading matrices from memory to using immediate instructions
Changes in v4:
Optimize unnecessary slide operations
Extract more scalars from vector registers into purpose registers
Changes in v3:
remove the slides in transposition and spill values from vector registers to stack
Changes in v2:
deleted tabs
remove the unnecessary t0 in vsetivli
extract scalars directly into general registers
---
libavcodec/riscv/Makefile | 1 +
libavcodec/riscv/hevcdsp_idct_rvv.S | 662 ++++++++++++++++++++++++++++
libavcodec/riscv/hevcdsp_init.c | 61 ++-
3 files changed, 705 insertions(+), 19 deletions(-)
create mode 100644 libavcodec/riscv/hevcdsp_idct_rvv.S
diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index a80d2fa2e7..dfc33afbee 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -36,6 +36,7 @@ RVV-OBJS-$(CONFIG_H264DSP) += riscv/h264addpx_rvv.o riscv/h264dsp_rvv.o \
OBJS-$(CONFIG_H264QPEL) += riscv/h264qpel_init.o
RVV-OBJS-$(CONFIG_H264QPEL) += riscv/h264qpel_rvv.o
OBJS-$(CONFIG_HEVC_DECODER) += riscv/hevcdsp_init.o
+OBJS-$(CONFIG_HEVC_DECODER) += riscv/hevcdsp_idct_rvv.o
RVV-OBJS-$(CONFIG_HEVC_DECODER) += riscv/h26x/h2656_inter_rvv.o
OBJS-$(CONFIG_HUFFYUV_DECODER) += riscv/huffyuvdsp_init.o
RVV-OBJS-$(CONFIG_HUFFYUV_DECODER) += riscv/huffyuvdsp_rvv.o
diff --git a/libavcodec/riscv/hevcdsp_idct_rvv.S b/libavcodec/riscv/hevcdsp_idct_rvv.S
new file mode 100644
index 0000000000..9b6f5dc3e1
--- /dev/null
+++ b/libavcodec/riscv/hevcdsp_idct_rvv.S
@@ -0,0 +1,662 @@
+/*
+ * Copyright (c) 2025 Institute of Software Chinese Academy of Sciences (ISCAS).
+ *
+ * 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/riscv/asm.S"
+
+.macro lx rd, addr
+#if (__riscv_xlen == 32)
+ lw \rd, \addr
+#elif (__riscv_xlen == 64)
+ ld \rd, \addr
+#else
+ lq \rd, \addr
+#endif
+.endm
+
+.macro sx rd, addr
+#if (__riscv_xlen == 32)
+ sw \rd, \addr
+#elif (__riscv_xlen == 64)
+ sd \rd, \addr
+#else
+ sq \rd, \addr
+#endif
+.endm
+
+.macro load_trans_4x4
+ li s2, 64
+ li s3, 83
+
+ li s5, 36
+ li s6, -64
+ li s7, -83
+.endm
+
+.macro load_trans_8x4
+ li s6, 89
+ li s7, 75
+ li s8, 50
+ li s9, 18
+
+ li s2, -89
+ li s4, -50
+ li s5, -18
+.endm
+
+.macro load_trans_16x4
+ li x12, 90
+ li x13, 87
+ li x14, 80
+ li x15, 70
+
+ li x16, 57
+ li x17, 43
+ li x18, 25
+ li x19, 9
+
+ li x20, -90
+ li x21, -87
+ li x22, -80
+ li x23, -70
+
+ li x24, -57
+ li x25, -43
+ li x26, -25
+ li x27, -9
+.endm
+
+.macro load_trans_32x4
+ li x12, 90
+ li x13, 90
+ li x14, 88
+ li x15, 85
+
+ li x16, 82
+ li x17, 78
+ li x18, 73
+ li x19, 67
+
+ li x20, 61
+ li x21, 54
+ li x22, 46
+ li x23, 38
+
+ li x24, 31
+ li x25, 22
+ li x26, 13
+ li x27, 4
+.endm
+
+.macro add_member32 in, t0, t1, t2, t3, op0, op1, op2, op3
+ .ifc \op0, -
+ neg t0, \t0
+ .endif
+ .ifc \op1, -
+ neg t1, \t1
+ .endif
+ .ifc \op2, -
+ neg t4, \t2
+ .endif
+ .ifc \op3, -
+ neg t5, \t3
+ .endif
+
+ .ifc \op0, -
+ vwmacc.vx v24, t0, \in
+ .else
+ vwmacc.vx v24, \t0, \in
+ .endif
+ .ifc \op1, -
+ vwmacc.vx v25, t1, \in
+ .else
+ vwmacc.vx v25, \t1, \in
+ .endif
+ .ifc \op2, -
+ vwmacc.vx v26, t4, \in
+ .else
+ vwmacc.vx v26, \t2, \in
+ .endif
+ .ifc \op3, -
+ vwmacc.vx v27, t5, \in
+ .else
+ vwmacc.vx v27, \t3, \in
+ .endif
+.endm
+
+.macro tr_block1
+ vwmul.vx v24, v4, x12
+ vwmul.vx v25, v4, x13
+ vwmul.vx v26, v4, x14
+ vwmul.vx v27, v4, x15
+
+ add_member32 v12, x13, x16, x19, x22, +, +, +, +
+ add_member32 v5, x14, x19, x24, x26, +, +, +, -
+ add_member32 v13, x15, x22, x26, x19, +, +, -, -
+ add_member32 v6, x16, x25, x21, x12, +, +, -, -
+ add_member32 v14, x17, x27, x16, x18, +, -, -, -
+ add_member32 v7, x18, x24, x12, x25, +, -, -, -
+ add_member32 v15, x19, x21, x17, x23, +, -, -, +
+
+ add_member32 v16, x20, x18, x22, x16, +, -, -, +
+ add_member32 v20, x21, x15, x27, x14, +, -, -, +
+ add_member32 v17, x22, x13, x23, x21, +, -, +, +
+ add_member32 v21, x23, x14, x18, x27, +, -, +, -
+ add_member32 v18, x24, x17, x13, x20, +, -, +, -
+ add_member32 v22, x25, x20, x15, x13, +, -, +, -
+ add_member32 v19, x26, x23, x20, x17, +, -, +, -
+ add_member32 v23, x27, x26, x25, x24, +, -, +, -
+.endm
+
+.macro tr_block2
+ vwmul.vx v24, v4, x16
+ vwmul.vx v25, v4, x17
+ vwmul.vx v26, v4, x18
+ vwmul.vx v27, v4, x19
+
+ add_member32 v12, x25, x27, x24, x21, +, -, -, -
+ add_member32 v5, x21, x16, x12, x17, -, -, -, -
+ add_member32 v13, x12, x18, x25, x23, -, -, -, +
+ add_member32 v6, x20, x26, x17, x15, -, +, +, +
+ add_member32 v14, x26, x15, x19, x25, +, +, +, -
+ add_member32 v7, x17, x19, x23, x12, +, +, -, -
+ add_member32 v15, x15, x25, x13, x27, +, -, -, +
+
+ add_member32 v16, x24, x14, x26, x13, +, -, -, +
+ add_member32 v20, x22, x20, x16, x26, -, -, +, +
+ add_member32 v17, x13, x24, x20, x14, -, +, +, -
+ add_member32 v21, x19, x13, x22, x24, -, +, -, -
+ add_member32 v18, x27, x21, x14, x16, +, +, -, +
+ add_member32 v22, x18, x23, x27, x22, +, -, -, +
+ add_member32 v19, x14, x13, x15, x18, +, -, +, -
+ add_member32 v23, x23, x22, x21, x20, +, -, +, -
+.endm
+
+.macro tr_block3
+ vwmul.vx v24, v4, x20
+ vwmul.vx v25, v4, x21
+ vwmul.vx v26, v4, x22
+ vwmul.vx v27, v4, x23
+
+ add_member32 v12, x18, x15, x12, x14, -, -, -, -
+ add_member32 v5, x22, x27, x23, x18, -, -, +, +
+ add_member32 v13, x16, x14, x21, x27, +, +, +, -
+ add_member32 v6, x24, x22, x13, x19, +, -, -, -
+ add_member32 v14, x14, x20, x24, x12, -, -, +, +
+ add_member32 v7, x26, x16, x20, x22, -, +, +, -
+ add_member32 v15, x12, x26, x14, x24, +, +, -, -
+ add_member32 v16, x27, x13, x25, x15, -, -, +, +
+ add_member32 v20, x13, x23, x19, x17, -, +, +, -
+ add_member32 v17, x25, x19, x15, x26, +, +, -, +
+ add_member32 v21, x15, x17, x26, x20, +, -, +, +
+ add_member32 v18, x23, x25, x18, x13, -, -, +, -
+ add_member32 v22, x17, x12, x16, x21, -, +, -, +
+ add_member32 v19, x21, x24, x27, x25, +, -, +, +
+ add_member32 v23, x19, x18, x17, x16, +, -, +, -
+.endm
+
+.macro tr_block4
+ vwmul.vx v24, v4, x24
+ vwmul.vx v25, v4, x25
+ vwmul.vx v26, v4, x26
+ vwmul.vx v27, v4, x27
+
+ add_member32 v12, x17, x20, x23, x26, -, -, -, -
+ add_member32 v5, x12, x15, x20, x25, +, +, +, +
+ add_member32 v13, x20, x12, x17, x24, -, -, -, -
+ add_member32 v6, x27, x18, x14, x23, +, +, +, +
+ add_member32 v14, x21, x23, x12, x22, +, -, -, -
+ add_member32 v7, x14, x27, x15, x21, -, -, +, +
+ add_member32 v15, x16, x22, x18, x20, +, +, -, -
+ add_member32 v16, x23, x17, x21, x19, -, -, +, +
+ add_member32 v20, x25, x13, x24, x18, -, +, -, -
+ add_member32 v17, x18, x16, x27, x17, +, -, +, +
+ add_member32 v21, x13, x21, x25, x16, -, +, +, -
+ add_member32 v18, x19, x26, x22, x15, +, -, -, +
+ add_member32 v22, x26, x24, x19, x14, -, -, +, -
+ add_member32 v19, x22, x19, x16, x13, -, +, -, +
+ add_member32 v23, x15, x14, x13, x12, +, -, +, -
+.endm
+
+.macro butterfly e, o, tmp_p, tmp_m
+ vadd.vv \tmp_p, \e, \o
+ vsub.vv \tmp_m, \e, \o
+.endm
+
+.macro butterfly16 in0, in1, in2, in3, in4, in5, in6, in7
+ vadd.vv v20, \in0, \in1
+ vsub.vv \in0, \in0, \in1
+ vadd.vv \in1, \in2, \in3
+ vsub.vv \in2, \in2, \in3
+ vadd.vv \in3, \in4, \in5
+ vsub.vv \in4, \in4, \in5
+ vadd.vv \in5, \in6, \in7
+ vsub.vv \in6, \in6, \in7
+.endm
+
+.macro butterfly32 in0, in1, in2, in3, out
+ vadd.vv \out, \in0, \in1
+ vsub.vv \in0, \in0, \in1
+ vadd.vv \in1, \in2, \in3
+ vsub.vv \in2, \in2, \in3
+.endm
+
+.macro add_member in, tt0, tt1, tt2, tt3, tt4, tt5, tt6, tt7
+ vwmacc.vx v21, \tt0, \in
+ vwmacc.vx v22, \tt1, \in
+ vwmacc.vx v23, \tt2, \in
+ vwmacc.vx v24, \tt3, \in
+ vwmacc.vx v25, \tt4, \in
+ vwmacc.vx v26, \tt5, \in
+ vwmacc.vx v27, \tt6, \in
+ vwmacc.vx v28, \tt7, \in
+.endm
+
+.macro load16xN_rvv avl
+ addi t0, a0, 64
+ addi a2, t0, 256 * 1
+ addi a3, t0, 256 * 2
+ addi a4, t0, 256 * 3
+ addi a5, t0, 256 * 4
+ addi a6, t0, 256 * 5
+ addi a7, t0, 256 * 6
+ addi s9, t0, 256 * 7
+
+ addi t1, t0, 128
+ addi s2, t1, 256 * 1
+ addi s3, t1, 256 * 2
+ addi s4, t1, 256 * 3
+ addi s5, t1, 256 * 4
+ addi s6, t1, 256 * 5
+ addi s7, t1, 256 * 6
+ addi s8, t1, 256 * 7
+
+ vle16.v v4, (t0)
+ vle16.v v5, (a2)
+ vle16.v v6, (a3)
+ vle16.v v7, (a4)
+
+ vle16.v v16, (a5)
+ vle16.v v17, (a6)
+ vle16.v v18, (a7)
+ vle16.v v19, (s9)
+
+ vle16.v v12, (t1)
+ vle16.v v13, (s2)
+ vle16.v v14, (s3)
+ vle16.v v15, (s4)
+
+ vle16.v v20, (s5)
+ vle16.v v21, (s6)
+ vle16.v v22, (s7)
+ vle16.v v23, (s8)
+.endm
+
+.macro load16_rvv in0, in1, in2, in3, off1, off2, step, in4, in5, in6, in7
+ addi t0, a0, \off1
+ addi a2, t0, \step * 1
+ addi a3, t0, \step * 2
+ addi a4, t0, \step * 3
+
+ addi t1, a0, \off2
+ addi s2, t1, \step * 1
+ addi s3, t1, \step * 2
+ addi s4, t1, \step * 3
+
+ vle16.v \in0, (t0)
+ vle16.v \in1, (a2)
+ vle16.v \in2, (a3)
+ vle16.v \in3, (a4)
+
+ vle16.v \in4, (t1)
+ vle16.v \in5, (s2)
+ vle16.v \in6, (s3)
+ vle16.v \in7, (s4)
+.endm
+
+.macro reload16 offset, avl
+ li t0, 2048
+ add t0, sp, t0
+ addi t0, t0, \offset
+ addi t1, t0, 4 * \avl\() * 1
+ addi t2, t0, 4 * \avl\() * 2
+ addi t3, t0, 4 * \avl\() * 3
+
+ vle32.v v28, (t0)
+ vle32.v v29, (t1)
+ vle32.v v30, (t2)
+ vle32.v v31, (t3)
+.endm
+
+.macro storeNx4_rvv in0, in1, in2, in3, off1, off2, step, tmp0, tmp1, tmp2, tmp3
+ li t0, \step
+
+ addi a0, a1, \off1
+ addi t2, a0, 1 * 2
+ addi t4, a0, 2 * 2
+ addi s0, a0, 3 * 2
+
+ addi t1, a1, 62 - \off1\()
+ addi t3, t1, -1 * 2
+ addi t5, t1, -2 * 2
+ addi s1, t1, -3 * 2
+
+ vsse16.v \in0, (a0), t0
+ vsse16.v \in1, (t2), t0
+ vsse16.v \in2, (t4), t0
+ vsse16.v \in3, (s0), t0
+
+ vsse16.v \tmp0, (t1), t0
+ vsse16.v \tmp1, (t3), t0
+ vsse16.v \tmp2, (t5), t0
+ vsse16.v \tmp3, (s1), t0
+.endm
+
+.macro scale_store_rvv shift, step, off1, off2, reload_offset, avl
+ vsetivli zero, \avl\(), e32, m1, ta, ma
+ reload16 \reload_offset, \avl\()
+
+ butterfly32 v28, v24, v29, v25, v2
+ butterfly32 v30, v26, v31, v27, v3
+
+ vsetivli zero, \avl\(), e16, mf2, ta, ma
+ scale v1, v10, v11, v9, v2, v28, v24, v29, v3, v30, v26, v31, \shift
+
+ storeNx4_rvv v1, v10, v11, v9, \off1, \off2, \step, v2, v28, v24, v29
+.endm
+
+.macro store_to_stack_rvv off1, off2, in0, in2, in4, in6, in7, in5, in3, in1, avl
+.if \off1 < 2048
+ addi a2, sp, \off1
+.else
+ li t0, \off1
+ add a2, sp, t0
+.endif
+
+.if \off2 < 2048
+ addi a3, sp, \off2
+.else
+ li t0, \off2
+ add a3, sp, t0
+.endif
+
+ addi a4, a2, \avl\() * 4 * 1
+ addi a5, a3, -\avl\() * 4 * 1
+ addi a6, a2, \avl\() * 4 * 2
+ addi a7, a3, -\avl\() * 4 * 2
+ addi s2, a2, \avl\() * 4 * 3
+ addi s3, a3, -\avl\() * 4 * 3
+
+ vse32.v \in0, (a2)
+ vse32.v \in1, (a3)
+ vse32.v \in2, (a4)
+ vse32.v \in3, (a5)
+ vse32.v \in4, (a6)
+ vse32.v \in5, (a7)
+ vse32.v \in6, (s2)
+ vse32.v \in7, (s3)
+.endm
+
+.macro scale out0, out1, out2, out3, in0, in1, in2, in3, in4, in5, in6, in7, shift
+ vnclip.wi \out0\(), \in0\(), \shift
+ vnclip.wi \out1\(), \in2\(), \shift
+ vnclip.wi \out2\(), \in4\(), \shift
+ vnclip.wi \out3\(), \in6\(), \shift
+
+ vnclip.wi \in0\(), \in1\(), \shift
+ vnclip.wi \in1\(), \in3\(), \shift
+ vnclip.wi \in2\(), \in5\(), \shift
+ vnclip.wi \in3\(), \in7\(), \shift
+.endm
+
+.macro tr_4xN_8 in0, in1, in2, in3, out0, out1, out2, out3, avl
+ vwcvt.x.x.v v8, \in0
+ vsetivli zero, \avl\(), e32, m1, ta, ma
+ vsll.vi v28, v8, 6
+ vmv.v.v v29, v28
+
+ load_trans_4x4
+
+ vsetivli zero, \avl\(), e16, mf2, ta, ma
+ vwmul.vx v30, \in1, s3
+ vwmul.vx v31, \in1, s5
+ vwmacc.vx v28, s2, \in2
+
+ vwmacc.vx v29, s6, \in2
+ vwmacc.vx v30, s5, \in3
+ vwmacc.vx v31, s7, \in3
+
+ vsetivli zero, \avl\(), e32, m1, ta, ma
+ vadd.vv \out0, v28, v30
+ vadd.vv \out1, v29, v31
+ vsub.vv \out2, v29, v31
+ vsub.vv \out3, v28, v30
+.endm
+
+.macro tr16_8xN in0, in1, in2, in3, offset, in4, in5, in6, in7, avl
+ tr_4xN_8 \in0, \in1, \in2, \in3, v24, v25, v26, v27, \avl\()
+ load_trans_8x4
+
+ vsetivli zero, \avl\(), e16, mf2, ta, ma
+ vwmul.vx v28, \in4, s6
+ vwmul.vx v29, \in4, s7
+ vwmul.vx v30, \in4, s8
+ vwmul.vx v31, \in4, s9
+
+ vwmacc.vx v28, s7, \in5
+ vwmacc.vx v29, s5, \in5
+ vwmacc.vx v30, s2, \in5
+ vwmacc.vx v31, s4, \in5
+
+ vwmacc.vx v28, s8, \in6
+ vwmacc.vx v29, s2, \in6
+ vwmacc.vx v30, s9, \in6
+ vwmacc.vx v31, s7, \in6
+
+ vwmacc.vx v28, s9, \in7
+ vwmacc.vx v29, s4, \in7
+ vwmacc.vx v30, s7, \in7
+ vwmacc.vx v31, s2, \in7
+
+ vsetivli zero, \avl\(), e32, m1, ta, ma
+ butterfly v24, v28, v16, v23
+ butterfly v25, v29, v17, v22
+ butterfly v26, v30, v18, v21
+ butterfly v27, v31, v19, v20
+.if \offset < 2048
+ addi t0, sp, \offset
+.else
+ li t0, \offset
+ add t0, sp, t0
+.endif
+
+ addi s2, t0, \avl\() * 4 * 1
+ addi s3, t0, \avl\() * 4 * 2
+ addi s4, t0, \avl\() * 4 * 3
+
+ addi s5, t0, \avl\() * 4 * 4
+ addi s6, t0, \avl\() * 4 * 5
+ addi s7, t0, \avl\() * 4 * 6
+ addi s8, t0, \avl\() * 4 * 7
+
+ vsetivli zero, \avl\(), e32, m1, ta, ma
+ vse32.v v16, (t0)
+ vse32.v v17, (s2)
+ vse32.v v18, (s3)
+ vse32.v v19, (s4)
+
+ vse32.v v20, (s5)
+ vse32.v v21, (s6)
+ vse32.v v22, (s7)
+ vse32.v v23, (s8)
+.endm
+
+.macro tr_16xN_rvv name, shift, offset, step, vlen
+func func_tr_16xN_\name\()_rvv_\vlen\(), zve64x
+ vsetivli zero, (\vlen\() / 32), e16, mf2, ta, ma
+ load16_rvv v16, v17, v18, v19, 0, \step * 64, \step * (2 * 64), v0, v1, v2, v3,
+ tr16_8xN v16, v17, v18, v19, \offset, v0, v1, v2, v3, (\vlen\() / 32)
+
+ vsetivli zero, (\vlen\() / 32), e16, mf2, ta, ma
+ load16_rvv v20, v17, v18, v19, \step * 32, \step * 3 * 32, \step * (2 * 64), v3, v0, v1, v2,
+
+ load_trans_16x4
+
+ vwmul.vx v21, v20, x12
+ vwmul.vx v22, v20, x13
+ vwmul.vx v23, v20, x14
+ vwmul.vx v24, v20, x15
+
+ vwmul.vx v25, v20, x16
+ vwmul.vx v26, v20, x17
+ vwmul.vx v27, v20, x18
+ vwmul.vx v28, v20, x19
+
+ add_member v3, x13, x16, x19, x25, x22, x20, x23, x26
+ add_member v17, x14, x19, x23, x21, x26, x16, x12, x17
+ add_member v0, x15, x25, x21, x19, x12, x18, x22, x24
+ add_member v18, x16, x22, x26, x12, x27, x21, x17, x15
+ add_member v1, x17, x20, x16, x18, x21, x15, x19, x22
+ add_member v19, x18, x23, x12, x22, x17, x19, x24, x13
+ add_member v2, x19, x26, x17, x24, x15, x22, x13, x20
+
+.if \offset < 2048
+ addi t0, sp, \offset
+.else
+ li t0, \offset
+ add t0, sp, t0
+.endif
+ addi s2, t0, (\vlen\() / 8) * 1
+ addi s3, t0, (\vlen\() / 8) * 2
+ addi s4, t0, (\vlen\() / 8) * 3
+
+ vsetivli zero, (\vlen\() / 32), e32, m1, ta, ma
+
+ vle32.v v16, (t0)
+ vle32.v v17, (s2)
+ vle32.v v18, (s3)
+ vle32.v v19, (s4)
+
+ butterfly16 v16, v21, v17, v22, v18, v23, v19, v24
+ store_to_stack_rvv \offset, (\offset + 2 * \vlen\() - (\vlen\() / 8)), v20, v21, v22, v23, v19, v18, v17, v16, (\vlen\() / 32)
+
+.if \offset < 2048 - ( 4 * (\vlen\() / 32) * 4)
+ addi t0, sp, \offset + (4 * (\vlen\() / 32) * 4)
+.else
+ li t0, \offset + ( 4 * (\vlen\() / 32) * 4)
+ add t0, sp, t0
+.endif
+ addi s2, t0, (\vlen\() / 8)
+ addi s3, t0, (\vlen\() / 8) * 2
+ addi s4, t0, (\vlen\() / 8) * 3
+
+ vle32.v v16, (t0)
+ vle32.v v17, (s2)
+ vle32.v v18, (s3)
+ vle32.v v19, (s4)
+
+ butterfly16 v16, v25, v17, v26, v18, v27, v19, v28
+ store_to_stack_rvv (\offset + (\vlen\() / 2)), (\offset + \vlen\() * 2 - \vlen\() / 8 - \vlen\() / 2), v20, v25, v26, v27, v19, v18, v17, v16, (\vlen\() / 32)
+ ret
+endfunc
+.endm
+
+tr_16xN_rvv noscale, 0, 2048, 4, 128
+tr_16xN_rvv noscale, 0, 2048, 4, 256
+
+.macro tr_32xN_rvv name, shift, vlen
+func func_tr_32xN_\name\()_rvv_\vlen\(), zve64x
+ vsetivli zero, (\vlen\() / 32), e16, mf2, ta, ma
+ load16xN_rvv
+
+ load_trans_32x4
+
+ tr_block1
+ scale_store_rvv \shift, 64, 0, (56 + 3 * 64), 0, (\vlen\() / 32)
+
+ tr_block2
+ scale_store_rvv \shift, 64, 8, (48 + 3 * 64), (\vlen\() / 2), (\vlen\() / 32)
+
+ tr_block3
+ scale_store_rvv \shift, 64, 16, (40 + 3 * 64), (\vlen\() / 2) * 2, (\vlen\() / 32)
+
+ tr_block4
+ scale_store_rvv \shift, 64, 24, (32 + 3 * 64), (\vlen\() / 2) * 3, (\vlen\() / 32)
+
+ ret
+endfunc
+.endm
+
+tr_32xN_rvv firstpass, 7, 128
+tr_32xN_rvv secondpass_8, 20 - 8, 128
+
+tr_32xN_rvv firstpass, 7, 256
+tr_32xN_rvv secondpass_8, 20 - 8, 256
+
+.macro idct_32x32 bitdepth, vlen
+func ff_hevc_idct_32x32_\bitdepth\()_rvv_\vlen\(), zve64x
+
+ addi sp, sp, -(__riscv_xlen / 8)*13
+ sx ra, (__riscv_xlen / 8)*(12)(sp)
+.irp i, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
+ sx s\i, (__riscv_xlen / 8)*(11-\i)(sp)
+.endr
+ mv t6, a0
+
+ csrwi vxrm, 1
+
+ li t0, 4224
+ sub sp, sp, t0
+
+.set i, 0
+.rept 1024 / \vlen\()
+.set OFFSET, \vlen\() * i / 16
+ addi a0, t6, OFFSET
+.set OFFSET, \vlen\() * i * 2
+ addi a1, sp, OFFSET
+ jal func_tr_16xN_noscale_rvv_\vlen\()
+ jal func_tr_32xN_firstpass_rvv_\vlen\()
+.set i, i+1
+.endr
+
+.set i, 0
+.rept 1024 / \vlen\()
+.set OFFSET, \vlen\() * i / 16
+ addi a0, sp, OFFSET
+.set OFFSET, \vlen\() * i * 2
+ addi a1, t6, OFFSET
+ jal func_tr_16xN_noscale_rvv_\vlen\()
+ jal func_tr_32xN_secondpass_\bitdepth\()_rvv_\vlen\()
+.set i, i+1
+.endr
+
+ li t0, 4224
+ add sp, sp, t0
+
+ lx ra, (__riscv_xlen / 8)*(12)(sp)
+.irp i, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
+ lx s\i, (__riscv_xlen / 8)*(11-\i)(sp)
+.endr
+ addi sp, sp, (__riscv_xlen / 8)*13
+ ret
+endfunc
+.endm
+
+idct_32x32 8, 128
+idct_32x32 8, 256
diff --git a/libavcodec/riscv/hevcdsp_init.c b/libavcodec/riscv/hevcdsp_init.c
index 1d8326a573..d567c8b433 100644
--- a/libavcodec/riscv/hevcdsp_init.c
+++ b/libavcodec/riscv/hevcdsp_init.c
@@ -27,6 +27,9 @@
#include "libavcodec/hevc/dsp.h"
#include "libavcodec/riscv/h26x/h2656dsp.h"
+void ff_hevc_idct_32x32_8_rvv_128(int16_t *coeffs, int col_limit);
+void ff_hevc_idct_32x32_8_rvv_256(int16_t *coeffs, int col_limit);
+
#define RVV_FNASSIGN(member, v, h, fn, ext) \
member[1][v][h] = ff_h2656_put_pixels_##8_##ext; \
member[3][v][h] = ff_h2656_put_pixels_##8_##ext; \
@@ -40,27 +43,47 @@ void ff_hevc_dsp_init_riscv(HEVCDSPContext *c, const int bit_depth)
const int flags = av_get_cpu_flags();
int vlenb;
- if (!(flags & AV_CPU_FLAG_RVV_I32) || !(flags & AV_CPU_FLAG_RVB))
- return;
-
vlenb = ff_get_rv_vlenb();
- if (vlenb >= 32) {
- switch (bit_depth) {
- case 8:
- RVV_FNASSIGN(c->put_hevc_qpel, 0, 0, pel_pixels, rvv_256);
- RVV_FNASSIGN(c->put_hevc_epel, 0, 0, pel_pixels, rvv_256);
- break;
- default:
- break;
+
+ if (flags & AV_CPU_FLAG_RVV_I64){
+ if (vlenb >= 32) {
+ switch (bit_depth) {
+ case 8:
+ c->idct[3] = ff_hevc_idct_32x32_8_rvv_256;
+ break;
+ default:
+ break;
+ }
+ } else if (vlenb >= 16){
+ switch (bit_depth) {
+ case 8:
+ c->idct[3] = ff_hevc_idct_32x32_8_rvv_128;
+ break;
+ default:
+ break;
+ }
}
- } else if (vlenb >= 16) {
- switch (bit_depth) {
- case 8:
- RVV_FNASSIGN(c->put_hevc_qpel, 0, 0, pel_pixels, rvv_128);
- RVV_FNASSIGN(c->put_hevc_epel, 0, 0, pel_pixels, rvv_128);
- break;
- default:
- break;
+ }
+
+ if ((flags & AV_CPU_FLAG_RVV_I32) && (flags & AV_CPU_FLAG_RVB)){
+ if (vlenb >= 32) {
+ switch (bit_depth) {
+ case 8:
+ RVV_FNASSIGN(c->put_hevc_qpel, 0, 0, pel_pixels, rvv_256);
+ RVV_FNASSIGN(c->put_hevc_epel, 0, 0, pel_pixels, rvv_256);
+ break;
+ default:
+ break;
+ }
+ } else if (vlenb >= 16) {
+ switch (bit_depth) {
+ case 8:
+ RVV_FNASSIGN(c->put_hevc_qpel, 0, 0, pel_pixels, rvv_128);
+ RVV_FNASSIGN(c->put_hevc_epel, 0, 0, pel_pixels, rvv_128);
+ break;
+ default:
+ break;
+ }
}
}
#endif
--
2.25.1
2
1