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
January 2024
- 98 participants
- 412 discussions
2
3
Analogous to the (a)showinfo lavfi filters, logs basic packet
information. Mainly useful for debugging/testing/development.
---
Changelog | 1 +
doc/bitstream_filters.texi | 4 +++
libavcodec/bitstream_filters.c | 1 +
libavcodec/bsf/Makefile | 1 +
libavcodec/bsf/showinfo.c | 66 ++++++++++++++++++++++++++++++++++
5 files changed, 73 insertions(+)
create mode 100644 libavcodec/bsf/showinfo.c
diff --git a/Changelog b/Changelog
index c1fd66b4bd..c5fb21d198 100644
--- a/Changelog
+++ b/Changelog
@@ -23,6 +23,7 @@ version <next>:
- ffmpeg CLI -bsf option may now be used for input as well as output
- ffmpeg CLI options may now be used as -/opt <path>, which is equivalent
to -opt <contents of file <path>>
+- showinfo bitstream filter
version 6.1:
- libaribcaption decoder
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index dc4f85bac0..d5bac105ff 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -887,6 +887,10 @@ For example, to set PTS equal to DTS (not recommended if B-frames are involved):
ffmpeg -i INPUT -c:a copy -bsf:a setts=pts=DTS out.mkv
@end example
+@section showinfo
+Log basic packet information. Mainly useful for testing, debugging,
+and development.
+
@anchor{text2movsub}
@section text2movsub
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 1e9a676a3d..1bae113d92 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -58,6 +58,7 @@ extern const FFBitStreamFilter ff_pgs_frame_merge_bsf;
extern const FFBitStreamFilter ff_prores_metadata_bsf;
extern const FFBitStreamFilter ff_remove_extradata_bsf;
extern const FFBitStreamFilter ff_setts_bsf;
+extern const FFBitStreamFilter ff_showinfo_bsf;
extern const FFBitStreamFilter ff_text2movsub_bsf;
extern const FFBitStreamFilter ff_trace_headers_bsf;
extern const FFBitStreamFilter ff_truehd_core_bsf;
diff --git a/libavcodec/bsf/Makefile b/libavcodec/bsf/Makefile
index 7831b0f2aa..62609eb24e 100644
--- a/libavcodec/bsf/Makefile
+++ b/libavcodec/bsf/Makefile
@@ -36,6 +36,7 @@ OBJS-$(CONFIG_PGS_FRAME_MERGE_BSF) += bsf/pgs_frame_merge.o
OBJS-$(CONFIG_PRORES_METADATA_BSF) += bsf/prores_metadata.o
OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += bsf/remove_extradata.o
OBJS-$(CONFIG_SETTS_BSF) += bsf/setts.o
+OBJS-$(CONFIG_SHOWINFO_BSF) += bsf/showinfo.o
OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += bsf/movsub.o
OBJS-$(CONFIG_TRACE_HEADERS_BSF) += bsf/trace_headers.o
OBJS-$(CONFIG_TRUEHD_CORE_BSF) += bsf/truehd_core.o
diff --git a/libavcodec/bsf/showinfo.c b/libavcodec/bsf/showinfo.c
new file mode 100644
index 0000000000..dc1ac8ceb6
--- /dev/null
+++ b/libavcodec/bsf/showinfo.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2024 Anton Khirnov <anton(a)khirnov.net>
+ *
+ * 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 <stdint.h>
+
+#include "bsf.h"
+#include "bsf_internal.h"
+
+#include "libavutil/log.h"
+#include "libavutil/timestamp.h"
+
+typedef struct ShowinfoContext {
+ uint64_t nb_packets;
+} ShowinfoContext;
+
+static int showinfo_filter(AVBSFContext *ctx, AVPacket *pkt)
+{
+ ShowinfoContext *priv = ctx->priv_data;
+
+ while (1) {
+ int ret;
+
+ ret = ff_bsf_get_packet_ref(ctx, pkt);
+ if (ret < 0)
+ return ret;
+
+ av_log(ctx, AV_LOG_INFO,
+ "n:%7"PRIu64" "
+ "size:%7d "
+ "pts:%s pt:%s "
+ "dts:%s dt:%s "
+ "ds:%"PRId64" d:%s "
+ "\n",
+ priv->nb_packets, pkt->size,
+ av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ctx->time_base_in),
+ av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ctx->time_base_in),
+ pkt->duration, av_ts2timestr(pkt->duration, &ctx->time_base_in));
+
+ priv->nb_packets++;
+
+ return 0;
+ }
+}
+
+const FFBitStreamFilter ff_showinfo_bsf = {
+ .p.name = "showinfo",
+ .filter = showinfo_filter,
+ .priv_data_size = sizeof(ShowinfoContext),
+};
--
2.42.0
4
5
[PATCH 1/5] avformat/mov_chan: do not assume channels are in native order
by Marton Balint 12 Feb '24
by Marton Balint 12 Feb '24
12 Feb '24
Existing code could have caused wrong channel order signalling or reduced
channel count if a channel designation appeared multiple times. This is
actually an old bug, but the conversion to the new channel layout API made it
visible, because now the code overrides the proper channel count with the one
calculated from the mask.
Signed-off-by: Marton Balint <cus(a)passwd.hu>
---
libavformat/mov_chan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c
index f3d51899e1..5cb2de3820 100644
--- a/libavformat/mov_chan.c
+++ b/libavformat/mov_chan.c
@@ -530,7 +530,7 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
size -= 20;
if (layout_tag == 0) {
uint64_t mask_incr = mov_get_channel_mask(label);
- if (mask_incr == 0) {
+ if (mask_incr == 0 || mask_incr <= label_mask) {
label_mask = 0;
break;
}
--
2.35.3
3
23
[PATCH v4 1/8] avcodec/vvc/vvc_inter_template: move put/put_luma/put_chroma template to h2656_inter_template.c
by toqsxw@outlook.com 11 Feb '24
by toqsxw@outlook.com 11 Feb '24
11 Feb '24
From: Wu Jianhua <toqsxw(a)outlook.com>
Signed-off-by: Wu Jianhua <toqsxw(a)outlook.com>
---
libavcodec/h26x/h2656_inter_template.c | 577 +++++++++++++++++++++++++
libavcodec/vvc/vvc_inter_template.c | 559 +-----------------------
2 files changed, 578 insertions(+), 558 deletions(-)
create mode 100644 libavcodec/h26x/h2656_inter_template.c
diff --git a/libavcodec/h26x/h2656_inter_template.c b/libavcodec/h26x/h2656_inter_template.c
new file mode 100644
index 0000000000..864f6c7e7d
--- /dev/null
+++ b/libavcodec/h26x/h2656_inter_template.c
@@ -0,0 +1,577 @@
+/*
+ * inter prediction template for HEVC/VVC
+ *
+ * Copyright (C) 2022 Nuo Mi
+ * Copyright (C) 2024 Wu Jianhua
+ *
+ * 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
+ */
+
+#define CHROMA_EXTRA_BEFORE 1
+#define CHROMA_EXTRA 3
+#define LUMA_EXTRA_BEFORE 3
+#define LUMA_EXTRA 7
+
+static void FUNC(put_pixels)(int16_t *dst,
+ const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ const pixel *src = (const pixel *)_src;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = src[x] << (14 - BIT_DEPTH);
+ src += src_stride;
+ dst += MAX_PB_SIZE;
+ }
+}
+
+static void FUNC(put_uni_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
+ const int8_t *hf, const int8_t *vf, const int width)
+{
+ const pixel *src = (const pixel *)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+
+ for (int y = 0; y < height; y++) {
+ memcpy(dst, src, width * sizeof(pixel));
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
+
+static void FUNC(put_uni_w_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
+ const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
+ const int width)
+{
+ const pixel *src = (const pixel *)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int shift = denom + 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+ const int ox = _ox * (1 << (BIT_DEPTH - 8));
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ const int v = (src[x] << (14 - BIT_DEPTH));
+ dst[x] = av_clip_pixel(((v * wx + offset) >> shift) + ox);
+ }
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
+
+#define LUMA_FILTER(src, stride) \
+ (filter[0] * src[x - 3 * stride] + \
+ filter[1] * src[x - 2 * stride] + \
+ filter[2] * src[x - stride] + \
+ filter[3] * src[x ] + \
+ filter[4] * src[x + stride] + \
+ filter[5] * src[x + 2 * stride] + \
+ filter[6] * src[x + 3 * stride] + \
+ filter[7] * src[x + 4 * stride])
+
+static void FUNC(put_luma_h)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ const pixel *src = (const pixel*)_src;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ dst += MAX_PB_SIZE;
+ }
+}
+
+static void FUNC(put_luma_v)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ const pixel *src = (pixel*)_src;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const int8_t *filter = vf;
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = LUMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ dst += MAX_PB_SIZE;
+ }
+}
+
+static void FUNC(put_luma_hv)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ int16_t tmp_array[(MAX_PB_SIZE + LUMA_EXTRA) * MAX_PB_SIZE];
+ int16_t *tmp = tmp_array;
+ const pixel *src = (const pixel*)_src;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+
+ src -= LUMA_EXTRA_BEFORE * src_stride;
+ for (int y = 0; y < height + LUMA_EXTRA; y++) {
+ for (int x = 0; x < width; x++)
+ tmp[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ tmp += MAX_PB_SIZE;
+ }
+
+ tmp = tmp_array + LUMA_EXTRA_BEFORE * MAX_PB_SIZE;
+ filter = vf;
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = LUMA_FILTER(tmp, MAX_PB_SIZE) >> 6;
+ tmp += MAX_PB_SIZE;
+ dst += MAX_PB_SIZE;
+ }
+}
+
+static void FUNC(put_uni_luma_h)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ const pixel *src = (const pixel*)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+ const int shift = 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ const int val = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+ dst[x] = av_clip_pixel((val + offset) >> shift);
+ }
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
+
+static void FUNC(put_uni_luma_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+
+ const pixel *src = (const pixel*)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = vf;
+ const int shift = 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ const int val = LUMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8);
+ dst[x] = av_clip_pixel((val + offset) >> shift);
+ }
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
+
+static void FUNC(put_uni_luma_hv)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ int16_t tmp_array[(MAX_PB_SIZE + LUMA_EXTRA) * MAX_PB_SIZE];
+ int16_t *tmp = tmp_array;
+ const pixel *src = (const pixel*)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+ const int shift = 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ src -= LUMA_EXTRA_BEFORE * src_stride;
+ for (int y = 0; y < height + LUMA_EXTRA; y++) {
+ for (int x = 0; x < width; x++)
+ tmp[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ tmp += MAX_PB_SIZE;
+ }
+
+ tmp = tmp_array + LUMA_EXTRA_BEFORE * MAX_PB_SIZE;
+ filter = vf;
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ const int val = LUMA_FILTER(tmp, MAX_PB_SIZE) >> 6;
+ dst[x] = av_clip_pixel((val + offset) >> shift);
+ }
+ tmp += MAX_PB_SIZE;
+ dst += dst_stride;
+ }
+
+}
+
+static void FUNC(put_uni_luma_w_h)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride, int height,
+ const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
+ const int width)
+{
+ const pixel *src = (const pixel*)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+ const int ox = _ox * (1 << (BIT_DEPTH - 8));
+ const int shift = denom + 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = av_clip_pixel((((LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
+
+static void FUNC(put_uni_luma_w_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
+ const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
+ const int width)
+{
+ const pixel *src = (const pixel*)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = vf;
+ const int ox = _ox * (1 << (BIT_DEPTH - 8));
+ const int shift = denom + 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = av_clip_pixel((((LUMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
+
+static void FUNC(put_uni_luma_w_hv)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride, const int height, const int denom,
+ const int wx, const int _ox, const int8_t *hf, const int8_t *vf, const int width)
+{
+ int16_t tmp_array[(MAX_PB_SIZE + LUMA_EXTRA) * MAX_PB_SIZE];
+ int16_t *tmp = tmp_array;
+ const pixel *src = (const pixel*)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+ const int ox = _ox * (1 << (BIT_DEPTH - 8));
+ const int shift = denom + 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ src -= LUMA_EXTRA_BEFORE * src_stride;
+ for (int y = 0; y < height + LUMA_EXTRA; y++) {
+ for (int x = 0; x < width; x++)
+ tmp[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ tmp += MAX_PB_SIZE;
+ }
+
+ tmp = tmp_array + LUMA_EXTRA_BEFORE * MAX_PB_SIZE;
+ filter = vf;
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = av_clip_pixel((((LUMA_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
+ tmp += MAX_PB_SIZE;
+ dst += dst_stride;
+ }
+}
+
+#define CHROMA_FILTER(src, stride) \
+ (filter[0] * src[x - stride] + \
+ filter[1] * src[x] + \
+ filter[2] * src[x + stride] + \
+ filter[3] * src[x + 2 * stride])
+
+static void FUNC(put_chroma_h)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ const pixel *src = (const pixel *)_src;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ dst += MAX_PB_SIZE;
+ }
+}
+
+static void FUNC(put_chroma_v)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ const pixel *src = (const pixel *)_src;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const int8_t *filter = vf;
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = CHROMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ dst += MAX_PB_SIZE;
+ }
+}
+
+static void FUNC(put_chroma_hv)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ int16_t tmp_array[(MAX_PB_SIZE + CHROMA_EXTRA) * MAX_PB_SIZE];
+ int16_t *tmp = tmp_array;
+ const pixel *src = (const pixel *)_src;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+
+ src -= CHROMA_EXTRA_BEFORE * src_stride;
+
+ for (int y = 0; y < height + CHROMA_EXTRA; y++) {
+ for (int x = 0; x < width; x++)
+ tmp[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ tmp += MAX_PB_SIZE;
+ }
+
+ tmp = tmp_array + CHROMA_EXTRA_BEFORE * MAX_PB_SIZE;
+ filter = vf;
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = CHROMA_FILTER(tmp, MAX_PB_SIZE) >> 6;
+ tmp += MAX_PB_SIZE;
+ dst += MAX_PB_SIZE;
+ }
+}
+
+static void FUNC(put_uni_chroma_h)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ const pixel *src = (const pixel *)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+ const int shift = 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = av_clip_pixel(((CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
+
+static void FUNC(put_uni_chroma_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ const pixel *src = (const pixel *)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = vf;
+ const int shift = 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = av_clip_pixel(((CHROMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8)) + offset) >> shift);
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
+
+static void FUNC(put_uni_chroma_hv)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride,
+ const int height, const int8_t *hf, const int8_t *vf, const int width)
+{
+ int16_t tmp_array[(MAX_PB_SIZE + CHROMA_EXTRA) * MAX_PB_SIZE];
+ int16_t *tmp = tmp_array;
+ const pixel *src = (const pixel *)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+ const int shift = 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ src -= CHROMA_EXTRA_BEFORE * src_stride;
+
+ for (int y = 0; y < height + CHROMA_EXTRA; y++) {
+ for (int x = 0; x < width; x++)
+ tmp[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ tmp += MAX_PB_SIZE;
+ }
+
+ tmp = tmp_array + CHROMA_EXTRA_BEFORE * MAX_PB_SIZE;
+ filter = vf;
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = av_clip_pixel(((CHROMA_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
+ tmp += MAX_PB_SIZE;
+ dst += dst_stride;
+ }
+}
+
+static void FUNC(put_uni_chroma_w_h)(uint8_t *_dst, ptrdiff_t _dst_stride,
+ const uint8_t *_src, ptrdiff_t _src_stride, int height, int denom, int wx, int ox,
+ const int8_t *hf, const int8_t *vf, int width)
+{
+ const pixel *src = (const pixel *)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+ const int shift = denom + 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ ox = ox * (1 << (BIT_DEPTH - 8));
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ dst[x] = av_clip_pixel((((CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
+ }
+ dst += dst_stride;
+ src += src_stride;
+ }
+}
+
+static void FUNC(put_uni_chroma_w_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
+ const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
+ const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
+ const int width)
+{
+ const pixel *src = (const pixel *)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = vf;
+ const int shift = denom + 14 - BIT_DEPTH;
+ const int ox = _ox * (1 << (BIT_DEPTH - 8));
+#if BIT_DEPTH < 14
+ int offset = 1 << (shift - 1);
+#else
+ int offset = 0;
+#endif
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ dst[x] = av_clip_pixel((((CHROMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
+ }
+ dst += dst_stride;
+ src += src_stride;
+ }
+}
+
+static void FUNC(put_uni_chroma_w_hv)(uint8_t *_dst, ptrdiff_t _dst_stride,
+ const uint8_t *_src, ptrdiff_t _src_stride, int height, int denom, int wx, int ox,
+ const int8_t *hf, const int8_t *vf, int width)
+{
+ int16_t tmp_array[(MAX_PB_SIZE + CHROMA_EXTRA) * MAX_PB_SIZE];
+ int16_t *tmp = tmp_array;
+ const pixel *src = (const pixel *)_src;
+ pixel *dst = (pixel *)_dst;
+ const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
+ const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
+ const int8_t *filter = hf;
+ const int shift = denom + 14 - BIT_DEPTH;
+#if BIT_DEPTH < 14
+ const int offset = 1 << (shift - 1);
+#else
+ const int offset = 0;
+#endif
+
+ src -= CHROMA_EXTRA_BEFORE * src_stride;
+
+ for (int y = 0; y < height + CHROMA_EXTRA; y++) {
+ for (int x = 0; x < width; x++)
+ tmp[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
+ src += src_stride;
+ tmp += MAX_PB_SIZE;
+ }
+
+ tmp = tmp_array + CHROMA_EXTRA_BEFORE * MAX_PB_SIZE;
+ filter = vf;
+
+ ox = ox * (1 << (BIT_DEPTH - 8));
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++)
+ dst[x] = av_clip_pixel((((CHROMA_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
+ tmp += MAX_PB_SIZE;
+ dst += dst_stride;
+ }
+}
diff --git a/libavcodec/vvc/vvc_inter_template.c b/libavcodec/vvc/vvc_inter_template.c
index 7160907778..e5cff079fb 100644
--- a/libavcodec/vvc/vvc_inter_template.c
+++ b/libavcodec/vvc/vvc_inter_template.c
@@ -20,564 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-////////////////////////////////////////////////////////////////////////////////
-//
-////////////////////////////////////////////////////////////////////////////////
-static void FUNC(put_pixels)(int16_t *dst,
- const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- const pixel *src = (const pixel *)_src;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = src[x] << (14 - BIT_DEPTH);
- src += src_stride;
- dst += MAX_PB_SIZE;
- }
-}
-
-static void FUNC(put_uni_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
- const int8_t *hf, const int8_t *vf, const int width)
-{
- const pixel *src = (const pixel *)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
-
- for (int y = 0; y < height; y++) {
- memcpy(dst, src, width * sizeof(pixel));
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-static void FUNC(put_uni_w_pixels)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
- const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
- const int width)
-{
- const pixel *src = (const pixel *)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int shift = denom + 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
- const int ox = _ox * (1 << (BIT_DEPTH - 8));
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- const int v = (src[x] << (14 - BIT_DEPTH));
- dst[x] = av_clip_pixel(((v * wx + offset) >> shift) + ox);
- }
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-////////////////////////////////////////////////////////////////////////////////
-#define LUMA_FILTER(src, stride) \
- (filter[0] * src[x - 3 * stride] + \
- filter[1] * src[x - 2 * stride] + \
- filter[2] * src[x - stride] + \
- filter[3] * src[x ] + \
- filter[4] * src[x + stride] + \
- filter[5] * src[x + 2 * stride] + \
- filter[6] * src[x + 3 * stride] + \
- filter[7] * src[x + 4 * stride])
-
-static void FUNC(put_luma_h)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- const pixel *src = (const pixel*)_src;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const int8_t *filter = hf;
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
- src += src_stride;
- dst += MAX_PB_SIZE;
- }
-}
-
-static void FUNC(put_luma_v)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- const pixel *src = (pixel*)_src;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const int8_t *filter = vf;
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = LUMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8);
- src += src_stride;
- dst += MAX_PB_SIZE;
- }
-}
-
-static void FUNC(put_luma_hv)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- int16_t tmp_array[(MAX_PB_SIZE + LUMA_EXTRA) * MAX_PB_SIZE];
- int16_t *tmp = tmp_array;
- const pixel *src = (const pixel*)_src;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const int8_t *filter = hf;
-
- src -= LUMA_EXTRA_BEFORE * src_stride;
- for (int y = 0; y < height + LUMA_EXTRA; y++) {
- for (int x = 0; x < width; x++)
- tmp[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
- src += src_stride;
- tmp += MAX_PB_SIZE;
- }
-
- tmp = tmp_array + LUMA_EXTRA_BEFORE * MAX_PB_SIZE;
- filter = vf;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = LUMA_FILTER(tmp, MAX_PB_SIZE) >> 6;
- tmp += MAX_PB_SIZE;
- dst += MAX_PB_SIZE;
- }
-}
-
-static void FUNC(put_uni_luma_h)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- const pixel *src = (const pixel*)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = hf;
- const int shift = 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- const int val = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
- dst[x] = av_clip_pixel((val + offset) >> shift);
- }
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-static void FUNC(put_uni_luma_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
-
- const pixel *src = (const pixel*)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = vf;
- const int shift = 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- const int val = LUMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8);
- dst[x] = av_clip_pixel((val + offset) >> shift);
- }
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-static void FUNC(put_uni_luma_hv)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- int16_t tmp_array[(MAX_PB_SIZE + LUMA_EXTRA) * MAX_PB_SIZE];
- int16_t *tmp = tmp_array;
- const pixel *src = (const pixel*)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const int8_t *filter = hf;
- const int shift = 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- src -= LUMA_EXTRA_BEFORE * src_stride;
- for (int y = 0; y < height + LUMA_EXTRA; y++) {
- for (int x = 0; x < width; x++)
- tmp[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
- src += src_stride;
- tmp += MAX_PB_SIZE;
- }
-
- tmp = tmp_array + LUMA_EXTRA_BEFORE * MAX_PB_SIZE;
- filter = vf;
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- const int val = LUMA_FILTER(tmp, MAX_PB_SIZE) >> 6;
- dst[x] = av_clip_pixel((val + offset) >> shift);
- }
- tmp += MAX_PB_SIZE;
- dst += dst_stride;
- }
-
-}
-
-static void FUNC(put_uni_luma_w_h)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride, int height,
- const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
- const int width)
-{
- const pixel *src = (const pixel*)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = hf;
- const int ox = _ox * (1 << (BIT_DEPTH - 8));
- const int shift = denom + 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = av_clip_pixel((((LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-static void FUNC(put_uni_luma_w_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
- const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
- const int width)
-{
- const pixel *src = (const pixel*)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = vf;
- const int ox = _ox * (1 << (BIT_DEPTH - 8));
- const int shift = denom + 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = av_clip_pixel((((LUMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-static void FUNC(put_uni_luma_w_hv)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride, const int height, const int denom,
- const int wx, const int _ox, const int8_t *hf, const int8_t *vf, const int width)
-{
- int16_t tmp_array[(MAX_PB_SIZE + LUMA_EXTRA) * MAX_PB_SIZE];
- int16_t *tmp = tmp_array;
- const pixel *src = (const pixel*)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = hf;
- const int ox = _ox * (1 << (BIT_DEPTH - 8));
- const int shift = denom + 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- src -= LUMA_EXTRA_BEFORE * src_stride;
- for (int y = 0; y < height + LUMA_EXTRA; y++) {
- for (int x = 0; x < width; x++)
- tmp[x] = LUMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
- src += src_stride;
- tmp += MAX_PB_SIZE;
- }
-
- tmp = tmp_array + LUMA_EXTRA_BEFORE * MAX_PB_SIZE;
- filter = vf;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = av_clip_pixel((((LUMA_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
- tmp += MAX_PB_SIZE;
- dst += dst_stride;
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-////////////////////////////////////////////////////////////////////////////////
-#define CHROMA_FILTER(src, stride) \
- (filter[0] * src[x - stride] + \
- filter[1] * src[x] + \
- filter[2] * src[x + stride] + \
- filter[3] * src[x + 2 * stride])
-
-static void FUNC(put_chroma_h)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- const pixel *src = (const pixel *)_src;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const int8_t *filter = hf;
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
- src += src_stride;
- dst += MAX_PB_SIZE;
- }
-}
-
-static void FUNC(put_chroma_v)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- const pixel *src = (const pixel *)_src;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const int8_t *filter = vf;
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = CHROMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8);
- src += src_stride;
- dst += MAX_PB_SIZE;
- }
-}
-
-static void FUNC(put_chroma_hv)(int16_t *dst, const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- int16_t tmp_array[(MAX_PB_SIZE + CHROMA_EXTRA) * MAX_PB_SIZE];
- int16_t *tmp = tmp_array;
- const pixel *src = (const pixel *)_src;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const int8_t *filter = hf;
-
- src -= CHROMA_EXTRA_BEFORE * src_stride;
-
- for (int y = 0; y < height + CHROMA_EXTRA; y++) {
- for (int x = 0; x < width; x++)
- tmp[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
- src += src_stride;
- tmp += MAX_PB_SIZE;
- }
-
- tmp = tmp_array + CHROMA_EXTRA_BEFORE * MAX_PB_SIZE;
- filter = vf;
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = CHROMA_FILTER(tmp, MAX_PB_SIZE) >> 6;
- tmp += MAX_PB_SIZE;
- dst += MAX_PB_SIZE;
- }
-}
-
-static void FUNC(put_uni_chroma_h)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- const pixel *src = (const pixel *)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = hf;
- const int shift = 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = av_clip_pixel(((CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8)) + offset) >> shift);
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-static void FUNC(put_uni_chroma_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- const pixel *src = (const pixel *)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = vf;
- const int shift = 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = av_clip_pixel(((CHROMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8)) + offset) >> shift);
- src += src_stride;
- dst += dst_stride;
- }
-}
-
-static void FUNC(put_uni_chroma_hv)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride,
- const int height, const int8_t *hf, const int8_t *vf, const int width)
-{
- int16_t tmp_array[(MAX_PB_SIZE + CHROMA_EXTRA) * MAX_PB_SIZE];
- int16_t *tmp = tmp_array;
- const pixel *src = (const pixel *)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = hf;
- const int shift = 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- src -= CHROMA_EXTRA_BEFORE * src_stride;
-
- for (int y = 0; y < height + CHROMA_EXTRA; y++) {
- for (int x = 0; x < width; x++)
- tmp[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
- src += src_stride;
- tmp += MAX_PB_SIZE;
- }
-
- tmp = tmp_array + CHROMA_EXTRA_BEFORE * MAX_PB_SIZE;
- filter = vf;
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = av_clip_pixel(((CHROMA_FILTER(tmp, MAX_PB_SIZE) >> 6) + offset) >> shift);
- tmp += MAX_PB_SIZE;
- dst += dst_stride;
- }
-}
-
-static void FUNC(put_uni_chroma_w_h)(uint8_t *_dst, ptrdiff_t _dst_stride,
- const uint8_t *_src, ptrdiff_t _src_stride, int height, int denom, int wx, int ox,
- const int8_t *hf, const int8_t *vf, int width)
-{
- const pixel *src = (const pixel *)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = hf;
- const int shift = denom + 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- ox = ox * (1 << (BIT_DEPTH - 8));
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- dst[x] = av_clip_pixel((((CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
- }
- dst += dst_stride;
- src += src_stride;
- }
-}
-
-static void FUNC(put_uni_chroma_w_v)(uint8_t *_dst, const ptrdiff_t _dst_stride,
- const uint8_t *_src, const ptrdiff_t _src_stride, const int height,
- const int denom, const int wx, const int _ox, const int8_t *hf, const int8_t *vf,
- const int width)
-{
- const pixel *src = (const pixel *)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = vf;
- const int shift = denom + 14 - BIT_DEPTH;
- const int ox = _ox * (1 << (BIT_DEPTH - 8));
-#if BIT_DEPTH < 14
- int offset = 1 << (shift - 1);
-#else
- int offset = 0;
-#endif
-
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- dst[x] = av_clip_pixel((((CHROMA_FILTER(src, src_stride) >> (BIT_DEPTH - 8)) * wx + offset) >> shift) + ox);
- }
- dst += dst_stride;
- src += src_stride;
- }
-}
-
-static void FUNC(put_uni_chroma_w_hv)(uint8_t *_dst, ptrdiff_t _dst_stride,
- const uint8_t *_src, ptrdiff_t _src_stride, int height, int denom, int wx, int ox,
- const int8_t *hf, const int8_t *vf, int width)
-{
- int16_t tmp_array[(MAX_PB_SIZE + CHROMA_EXTRA) * MAX_PB_SIZE];
- int16_t *tmp = tmp_array;
- const pixel *src = (const pixel *)_src;
- pixel *dst = (pixel *)_dst;
- const ptrdiff_t src_stride = _src_stride / sizeof(pixel);
- const ptrdiff_t dst_stride = _dst_stride / sizeof(pixel);
- const int8_t *filter = hf;
- const int shift = denom + 14 - BIT_DEPTH;
-#if BIT_DEPTH < 14
- const int offset = 1 << (shift - 1);
-#else
- const int offset = 0;
-#endif
-
- src -= CHROMA_EXTRA_BEFORE * src_stride;
-
- for (int y = 0; y < height + CHROMA_EXTRA; y++) {
- for (int x = 0; x < width; x++)
- tmp[x] = CHROMA_FILTER(src, 1) >> (BIT_DEPTH - 8);
- src += src_stride;
- tmp += MAX_PB_SIZE;
- }
-
- tmp = tmp_array + CHROMA_EXTRA_BEFORE * MAX_PB_SIZE;
- filter = vf;
-
- ox = ox * (1 << (BIT_DEPTH - 8));
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++)
- dst[x] = av_clip_pixel((((CHROMA_FILTER(tmp, MAX_PB_SIZE) >> 6) * wx + offset) >> shift) + ox);
- tmp += MAX_PB_SIZE;
- dst += dst_stride;
- }
-}
+#include "libavcodec/h26x/h2656_inter_template.c"
static void FUNC(avg)(uint8_t *_dst, const ptrdiff_t _dst_stride,
const int16_t *src0, const int16_t *src1, const int width, const int height)
--
2.34.1
3
4
2
8
09 Feb '24
The function signature for bytestream2_seek is (gb, offset, whence);
Before this patch, the code passed (gb, SEEK_SET, offset), which is
incorrect.
Siged-off-by: Leo Izen <leo.izen(a)gmail.com>
---
libavcodec/tiff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index adb49e4525..3ce441aa2c 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -1701,7 +1701,7 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
break;
case TIFF_ICC_PROFILE:
gb_temp = s->gb;
- bytestream2_seek(&gb_temp, SEEK_SET, off);
+ bytestream2_seek(&gb_temp, off, SEEK_SET);
if (bytestream2_get_bytes_left(&gb_temp) < count)
return AVERROR_INVALIDDATA;
--
2.43.0
1
1
09 Feb '24
These inline implementations of AV_COPY64, AV_SWAP64 and AV_ZERO64
are known to clobber the FPU state - which has to be restored
with the 'emms' instruction afterwards.
This was known and signaled with the FF_COPY_SWAP_ZERO_USES_MMX
define, which calling code seems to have been supposed to check,
in order to call emms_c() after using them. See
0b1972d4096df5879038f0af776f87f41e90ebd4,
29c4c0886d143790fcbeddbe40a23dfc6f56345c and
df215e575850e41b19aeb1fd99e53372a6b3d537 for history on earlier
fixes in the same area.
However, new code can use these AV_*64() macros without knowing
about the need to call emms_c().
Just get rid of these dangerous inline assembly snippets; this
doesn't make any difference for 64 bit architectures anyway.
Signed-off-by: Martin Storsjö <martin(a)martin.st>
---
libavcodec/dca_core.c | 16 ----------------
libavutil/x86/intreadwrite.h | 36 ------------------------------------
2 files changed, 52 deletions(-)
diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 60508fabb9..5dd727fc72 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -770,10 +770,6 @@ static void erase_adpcm_history(DCACoreDecoder *s)
for (ch = 0; ch < DCA_CHANNELS; ch++)
for (band = 0; band < DCA_SUBBANDS; band++)
AV_ZERO128(s->subband_samples[ch][band] - DCA_ADPCM_COEFFS);
-
-#ifdef FF_COPY_SWAP_ZERO_USES_MMX
- emms_c();
-#endif
}
static int alloc_sample_buffer(DCACoreDecoder *s)
@@ -837,10 +833,6 @@ static int parse_frame_data(DCACoreDecoder *s, enum HeaderType header, int xch_b
}
}
-#ifdef FF_COPY_SWAP_ZERO_USES_MMX
- emms_c();
-#endif
-
return 0;
}
@@ -1283,10 +1275,6 @@ static void erase_x96_adpcm_history(DCACoreDecoder *s)
for (ch = 0; ch < DCA_CHANNELS; ch++)
for (band = 0; band < DCA_SUBBANDS_X96; band++)
AV_ZERO128(s->x96_subband_samples[ch][band] - DCA_ADPCM_COEFFS);
-
-#ifdef FF_COPY_SWAP_ZERO_USES_MMX
- emms_c();
-#endif
}
static int alloc_x96_sample_buffer(DCACoreDecoder *s)
@@ -1516,10 +1504,6 @@ static int parse_x96_frame_data(DCACoreDecoder *s, int exss, int xch_base)
}
}
-#ifdef FF_COPY_SWAP_ZERO_USES_MMX
- emms_c();
-#endif
-
return 0;
}
diff --git a/libavutil/x86/intreadwrite.h b/libavutil/x86/intreadwrite.h
index 40f375b013..5e57d6a8cd 100644
--- a/libavutil/x86/intreadwrite.h
+++ b/libavutil/x86/intreadwrite.h
@@ -27,42 +27,6 @@
#if HAVE_MMX
-#if !HAVE_FAST_64BIT && defined(__MMX__)
-
-#define FF_COPY_SWAP_ZERO_USES_MMX
-
-#define AV_COPY64 AV_COPY64
-static av_always_inline void AV_COPY64(void *d, const void *s)
-{
- __asm__("movq %1, %%mm0 \n\t"
- "movq %%mm0, %0 \n\t"
- : "=m"(*(uint64_t*)d)
- : "m" (*(const uint64_t*)s)
- : "mm0");
-}
-
-#define AV_SWAP64 AV_SWAP64
-static av_always_inline void AV_SWAP64(void *a, void *b)
-{
- __asm__("movq %1, %%mm0 \n\t"
- "movq %0, %%mm1 \n\t"
- "movq %%mm0, %0 \n\t"
- "movq %%mm1, %1 \n\t"
- : "+m"(*(uint64_t*)a), "+m"(*(uint64_t*)b)
- ::"mm0", "mm1");
-}
-
-#define AV_ZERO64 AV_ZERO64
-static av_always_inline void AV_ZERO64(void *d)
-{
- __asm__("pxor %%mm0, %%mm0 \n\t"
- "movq %%mm0, %0 \n\t"
- : "=m"(*(uint64_t*)d)
- :: "mm0");
-}
-
-#endif /* !HAVE_FAST_64BIT && defined(__MMX__) */
-
#ifdef __SSE__
#define AV_COPY128 AV_COPY128
--
2.34.1
3
4
From: Haihao Xiang <haihao.xiang(a)intel.com>
2M is suitable for more cases, e.g. 4K video.
Signed-off-by: Haihao Xiang <haihao.xiang(a)intel.com>
---
libavcodec/qsvenc_av1.c | 2 +-
libavcodec/qsvenc_h264.c | 2 +-
libavcodec/qsvenc_hevc.c | 2 +-
libavcodec/qsvenc_mpeg2.c | 2 +-
libavcodec/qsvenc_vp9.c | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/qsvenc_av1.c b/libavcodec/qsvenc_av1.c
index c697845d7b..78c92c1844 100644
--- a/libavcodec/qsvenc_av1.c
+++ b/libavcodec/qsvenc_av1.c
@@ -129,7 +129,7 @@ static const AVClass class = {
};
static const FFCodecDefault qsv_enc_defaults[] = {
- { "b", "1M" },
+ { "b", "2M" },
{ "g", "-1" },
{ "bf", "-1" },
{ "refs", "0" },
diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
index 071a9a79e9..37b39cb441 100644
--- a/libavcodec/qsvenc_h264.c
+++ b/libavcodec/qsvenc_h264.c
@@ -178,7 +178,7 @@ static const AVClass class = {
};
static const FFCodecDefault qsv_enc_defaults[] = {
- { "b", "1M" },
+ { "b", "2M" },
{ "refs", "0" },
{ "g", "-1" },
{ "bf", "-1" },
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index c5b7ac7cc4..181d06cb00 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -374,7 +374,7 @@ static const AVClass class = {
};
static const FFCodecDefault qsv_enc_defaults[] = {
- { "b", "1M" },
+ { "b", "2M" },
{ "refs", "0" },
{ "g", "248" },
{ "bf", "-1" },
diff --git a/libavcodec/qsvenc_mpeg2.c b/libavcodec/qsvenc_mpeg2.c
index 22f1ff7c0d..012cec3a58 100644
--- a/libavcodec/qsvenc_mpeg2.c
+++ b/libavcodec/qsvenc_mpeg2.c
@@ -82,7 +82,7 @@ static const AVClass class = {
};
static const FFCodecDefault qsv_enc_defaults[] = {
- { "b", "1M" },
+ { "b", "2M" },
{ "refs", "0" },
// same as the x264 default
{ "g", "250" },
diff --git a/libavcodec/qsvenc_vp9.c b/libavcodec/qsvenc_vp9.c
index d0340ef94b..8658b8ec2d 100644
--- a/libavcodec/qsvenc_vp9.c
+++ b/libavcodec/qsvenc_vp9.c
@@ -93,7 +93,7 @@ static const AVClass class = {
};
static const FFCodecDefault qsv_enc_defaults[] = {
- { "b", "1M" },
+ { "b", "2M" },
{ "refs", "0" },
{ "g", "250" },
{ "trellis", "-1" },
--
2.34.1
4
7
[PATCH v2 01/12] lavu/hwcontext_qsv: update AVQSVFramesContext to support dynamic frame pools
by Xiang, Haihao 08 Feb '24
by Xiang, Haihao 08 Feb '24
08 Feb '24
From: Haihao Xiang <haihao.xiang(a)intel.com>
Add AVQSVFramesContext.info and update the description
Signed-off-by: Haihao Xiang <haihao.xiang(a)intel.com>
---
Rebased https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=9639
against the latest master with a few changes.
doc/APIchanges | 3 +++
libavutil/hwcontext_qsv.c | 4 ++--
libavutil/hwcontext_qsv.h | 31 +++++++++++++++++++++++++++----
libavutil/version.h | 2 +-
4 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index a3e4ebbccd..b68156ee94 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
API changes, most recent first:
+2023-12-xx - xxxxxxxxxx - lavu 58.36.100 - hwcontext_qsv.h
+ Add AVQSVFramesContext.info
+
2023-12-18 - 74279227dd2 - lavc 60.36.100 - packet.h
Add AV_PKT_DATA_IAMF_MIX_GAIN_PARAM, AV_PKT_DATA_IAMF_DEMIXING_INFO_PARAM
and AV_PKT_DATA_IAMF_RECON_GAIN_INFO_PARAM.
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index a67552b5ac..071489f070 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -613,7 +613,7 @@ static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
QSVFramesContext *s = ctx->internal->priv;
AVQSVFramesContext *hwctx = ctx->hwctx;
mfxFrameInfo *i = &req->Info;
- mfxFrameInfo *i1 = &hwctx->surfaces[0].Info;
+ mfxFrameInfo *i1 = hwctx->nb_surfaces ? &hwctx->surfaces[0].Info : hwctx->info;
if (!(req->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) ||
!(req->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) ||
@@ -1173,7 +1173,7 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx,
MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
par.AsyncDepth = 1;
- par.vpp.In = frames_hwctx->surfaces[0].Info;
+ par.vpp.In = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info : *frames_hwctx->info;
/* Apparently VPP requires the frame rate to be set to some value, otherwise
* init will fail (probably for the framerate conversion filter). Since we
diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
index e2dba8ad83..5950e38500 100644
--- a/libavutil/hwcontext_qsv.h
+++ b/libavutil/hwcontext_qsv.h
@@ -25,8 +25,8 @@
* @file
* An API-specific header for AV_HWDEVICE_TYPE_QSV.
*
- * This API does not support dynamic frame pools. AVHWFramesContext.pool must
- * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1 struct.
+ * AVHWFramesContext.pool must contain AVBufferRefs whose data pointer points
+ * to a mfxFrameSurface1 struct.
*/
/**
@@ -51,11 +51,34 @@ typedef struct AVQSVDeviceContext {
* This struct is allocated as AVHWFramesContext.hwctx
*/
typedef struct AVQSVFramesContext {
- mfxFrameSurface1 *surfaces;
+ /**
+ * A pointer to a mfxFrameSurface1 or mfxFrameInfo struct
+ *
+ * When nb_surfaces is non-zero, it is a pointer to a mfxFrameSurface1
+ * struct.
+ *
+ * When nb_surfaces is 0, it is a pointer to a mfxFrameInfo struct, all
+ * buffers allocated from the pool have the same mfxFrameInfo.
+ */
+ union {
+ mfxFrameSurface1 *surfaces;
+ mfxFrameInfo *info;
+ };
+
+ /**
+ * Number of frames in the pool
+ *
+ * It is 0 for dynamic frame pools or AVHWFramesContext.initial_pool_size
+ * for fixed frame pools.
+ *
+ * Note only oneVPL GPU runtime 2.9+ can support dynamic frame pools
+ * on d3d11va or vaapi
+ */
int nb_surfaces;
/**
- * A combination of MFX_MEMTYPE_* describing the frame pool.
+ * Set by user. It is a combination of MFX_MEMTYPE_* describing the frame
+ * pool.
*/
int frame_type;
} AVQSVFramesContext;
diff --git a/libavutil/version.h b/libavutil/version.h
index 7664cd97bd..3b4c50e9a9 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 58
-#define LIBAVUTIL_VERSION_MINOR 35
+#define LIBAVUTIL_VERSION_MINOR 36
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
--
2.34.1
2
18
Hello, I am happy to share a DVD demuxer for ffmpeg powered by libdvdread and libdvdnav.
I have been working on this on/off throughout the year and think it is in a good spot
to share at the ML now. This was a major learning experience for me in many ways and
am open to any feedback on how I could improve it to be better. In fact, there is still
one issue I can't seem to figure out how to solve (in discussion below). Regardless,
a good number of DVDs I have tried seem to work out of the box. This is a full-service
demuxer with chapters, subtitles (and their palettes), as well as language metadata.
At a high level, the demuxer uses libdvdread for metadata of the disc, libdvdnav for
the actual playback, and the MPEG-PS demuxer for the underlying VOB stream.
First, the basic usage, is quite straightforward:
ffmpeg -f dvdvideo -title NN -i DVD.iso|/dev/srX|/path/to/DVD ...
Where NN can be replaced by your known title number in the disc
As the demuxer effectively works at a PGC level, multi-PGC titles are not supported.
But to provide this flexibility as there are many weirdly authored DVDs out there,
one can specify an exact PGC via -pgc option and an associated program (PG, can start at 1).
I am hoping and willing to improve this to be a robust demuxer wherever possible, but to
that extent there is still an issue I can't figure out how to solve: Dealing with DTS discontinuities
and PTS generation.
Right now, as a band-aid, I am adding AVFMT_FLAG_GENPTS (line 1408)
to the MPEG-PS subdemuxer. This works with most discs and the output seems OK. On discs with discontinuities, however,
this causes the demuxing to hang which is obviously unacceptable also. Removing the flag causes the discs
to not hang, but then the output for all discs becomes choppy for obvious reasons (invalid PTS).
It could be because I have some misunderstandings on how things work within ffmpeg,
but I have tried to the point now where I thought it best to ask the experts for help if you can spot
what I am doing wrong. I am really motivated to make this work and good quality.
Thank you!
---
configure | 8 +
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/avlanguage.c | 10 +-
libavformat/dvdvideodec.c | 1599 +++++++++++++++++++++++++++++++++++++
5 files changed, 1617 insertions(+), 2 deletions(-)
create mode 100644 libavformat/dvdvideodec.c
diff --git a/configure b/configure
index d77c053226..65e5968194 100755
--- a/configure
+++ b/configure
@@ -227,6 +227,8 @@ External library support:
--enable-libdavs2 enable AVS2 decoding via libdavs2 [no]
--enable-libdc1394 enable IIDC-1394 grabbing using libdc1394
and libraw1394 [no]
+ --enable-libdvdnav enable libdvdnav, needed for DVD demuxing [no]
+ --enable-libdvdread enable libdvdread, needed for DVD demuxing [no]
--enable-libfdk-aac enable AAC de/encoding via libfdk-aac [no]
--enable-libflite enable flite (voice synthesis) support via libflite [no]
--enable-libfontconfig enable libfontconfig, useful for drawtext filter [no]
@@ -1802,6 +1804,8 @@ EXTERNAL_LIBRARY_GPL_LIST="
frei0r
libcdio
libdavs2
+ libdvdnav
+ libdvdread
librubberband
libvidstab
libx264
@@ -3494,6 +3498,8 @@ dts_demuxer_select="dca_parser"
dtshd_demuxer_select="dca_parser"
dv_demuxer_select="dvprofile"
dv_muxer_select="dvprofile"
+dvdvideo_demuxer_select="mpegps_demuxer"
+dvdvideo_demuxer_deps="libdvdnav libdvdread"
dxa_demuxer_select="riffdec"
eac3_demuxer_select="ac3_parser"
evc_demuxer_select="evc_frame_merge_bsf evc_parser"
@@ -6723,6 +6729,8 @@ enabled libdav1d && require_pkg_config libdav1d "dav1d >= 0.5.0" "dav1d
enabled libdavs2 && require_pkg_config libdavs2 "davs2 >= 1.6.0" davs2.h davs2_decoder_open
enabled libdc1394 && require_pkg_config libdc1394 libdc1394-2 dc1394/dc1394.h dc1394_new
enabled libdrm && require_pkg_config libdrm libdrm xf86drm.h drmGetVersion
+enabled libdvdnav && require_pkg_config libdvdnav "dvdnav >= 6.1.1" dvdnav/dvdnav.h dvdnav_open2
+enabled libdvdread && require_pkg_config libdvdread "dvdread >= 6.1.2" dvdread/dvd_reader.h DVDOpen2 -ldvdread
enabled libfdk_aac && { check_pkg_config libfdk_aac fdk-aac "fdk-aac/aacenc_lib.h" aacEncOpen ||
{ require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac &&
warn "using libfdk without pkg-config"; } }
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2db83aff81..45dba53044 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -192,6 +192,7 @@ OBJS-$(CONFIG_DTS_MUXER) += rawenc.o
OBJS-$(CONFIG_DV_MUXER) += dvenc.o
OBJS-$(CONFIG_DVBSUB_DEMUXER) += dvbsub.o rawdec.o
OBJS-$(CONFIG_DVBTXT_DEMUXER) += dvbtxt.o rawdec.o
+OBJS-$(CONFIG_DVDVIDEO_DEMUXER) += dvdvideodec.o
OBJS-$(CONFIG_DXA_DEMUXER) += dxa.o
OBJS-$(CONFIG_EA_CDATA_DEMUXER) += eacdata.o
OBJS-$(CONFIG_EA_DEMUXER) += electronicarts.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index c8bb4e3866..dc2acf575c 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -150,6 +150,7 @@ extern const AVInputFormat ff_dv_demuxer;
extern const FFOutputFormat ff_dv_muxer;
extern const AVInputFormat ff_dvbsub_demuxer;
extern const AVInputFormat ff_dvbtxt_demuxer;
+extern const AVInputFormat ff_dvdvideo_demuxer;
extern const AVInputFormat ff_dxa_demuxer;
extern const AVInputFormat ff_ea_demuxer;
extern const AVInputFormat ff_ea_cdata_demuxer;
diff --git a/libavformat/avlanguage.c b/libavformat/avlanguage.c
index 782a58adb2..202d9aa835 100644
--- a/libavformat/avlanguage.c
+++ b/libavformat/avlanguage.c
@@ -29,7 +29,7 @@ typedef struct LangEntry {
uint16_t next_equivalent;
} LangEntry;
-static const uint16_t lang_table_counts[] = { 484, 20, 184 };
+static const uint16_t lang_table_counts[] = { 484, 20, 190 };
static const uint16_t lang_table_offsets[] = { 0, 484, 504 };
static const LangEntry lang_table[] = {
@@ -539,7 +539,7 @@ static const LangEntry lang_table[] = {
/*0501*/ { "slk", 647 },
/*0502*/ { "sqi", 652 },
/*0503*/ { "zho", 686 },
- /*----- AV_LANG_ISO639_1 entries (184) -----*/
+ /*----- AV_LANG_ISO639_1 entries (190) -----*/
/*0504*/ { "aa" , 0 },
/*0505*/ { "ab" , 1 },
/*0506*/ { "ae" , 33 },
@@ -724,6 +724,12 @@ static const LangEntry lang_table[] = {
/*0685*/ { "za" , 478 },
/*0686*/ { "zh" , 78 },
/*0687*/ { "zu" , 480 },
+ /*0688*/ { "in" , 195 }, /* deprecated */
+ /*0689*/ { "iw" , 172 }, /* deprecated */
+ /*0690*/ { "ji" , 472 }, /* deprecated */
+ /*0691*/ { "jw" , 202 }, /* deprecated */
+ /*0692*/ { "mo" , 358 }, /* deprecated */
+ /*0693*/ { "sh" , 693 }, /* deprecated (no equivalent) */
{ "", 0 }
};
diff --git a/libavformat/dvdvideodec.c b/libavformat/dvdvideodec.c
new file mode 100644
index 0000000000..2b22a7de4f
--- /dev/null
+++ b/libavformat/dvdvideodec.c
@@ -0,0 +1,1599 @@
+/*
+ * DVD-Video demuxer (powered by libdvdnav/libdvdread)
+ *
+ * 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
+ */
+
+/**
+ * DVD-Video is not a directly accessible, linear container format in the
+ * traditional sense. Instead, it allows for complex and programmatic
+ * playback of carefully muxed streams. A typical DVD player relies on
+ * user GUI interaction to drive the direction of the demuxing.
+ * Ultimately, the logical playback sequence is defined by a title's PGC
+ * and a user selected "angle". An additional layer of control is defined by
+ * NAV packets in the MPEG-PS, but as these are processed by libdvdnav,
+ * they are witheld from the output of this demuxer.
+ *
+ * Therefore, the high-level approach is as follows:
+ * 1) Open the volume with libdvdread
+ * 2) Gather information about the user-requested title and PGC coordinates
+ * 3) Request playback at the coordinates and chosen angle with libdvdnav
+ * 4) Seek playback to first cell at the coordinates (skipping stills, etc.)
+ * 5) Begin the playback (reading and demuxing) of MPEG-PS blocks
+ * 6) End playback if the PGC or angle change
+ * 7) Close resources
+ **/
+
+/**
+ * Issues/bug tracker (TODO):
+ * - SDDS is not supported yet
+ * - Are we handling backwards cell changes and PTT changes correctly?
+ * - Some codec parameters/metadata is not being explicitly set:
+ * -> ChannelLayout, color/chroma info, DAR, frame size for MP1/MP2 audio
+ * - Additional PGC validations?
+**/
+
+#include <dvdread/dvd_reader.h>
+#include <dvdread/ifo_read.h>
+#include <dvdread/ifo_types.h>
+#include <dvdread/nav_read.h>
+#include <dvdnav/dvdnav.h>
+
+#include "libavutil/avstring.h"
+#include "libavutil/avutil.h"
+#include "libavutil/colorspace.h"
+#include "libavutil/mem.h"
+#include "libavutil/opt.h"
+#include "libavutil/samplefmt.h"
+
+#include "libavcodec/avcodec.h"
+#include "libavformat/avio_internal.h"
+#include "libavformat/avlanguage.h"
+#include "libavformat/avformat.h"
+#include "libavformat/demux.h"
+#include "libavformat/internal.h"
+#include "libavformat/url.h"
+
+#define ZERO_Q (AVRational) { 0, 1 }
+
+#define DVDVIDEO_PS_MAX_SEARCH_BLOCKS 128
+#define DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE 1024
+
+#define DVDVIDEO_TIME_BASE_Q (AVRational) { 1, 90000 }
+#define DVDVIDEO_TIME_BASE_MILLIS_Q (AVRational) { 1, 1000 }
+#define DVDVIDEO_PTS_WRAP_BITS 32
+#define DVDVIDEO_BLOCK_SIZE 2048
+
+#define DVDVIDEO_NTSC_FRAMERATE_Q (AVRational) { 30000, 1001 }
+#define DVDVIDEO_NTSC_HEIGHT 480
+#define DVDVIDEO_PAL_FRAMERATE_Q (AVRational) { 25, 1 }
+#define DVDVIDEO_PAL_HEIGHT 576
+#define DVDVIDEO_D1_WIDTH 720
+#define DVDVIDEO_4CIF_WIDTH 704
+#define DVDVIDEO_D1_HALF_WIDTH 352
+#define DVDVIDEO_CIF_WIDTH 352
+#define DVDVIDEO_PIXEL_FORMAT AV_PIX_FMT_YUV420P
+
+#define DVDVIDEO_STARTCODE_VIDEO 0x1E0
+#define DVDVIDEO_STARTCODE_OFFSET_AUDIO_AC3 0x80
+#define DVDVIDEO_STARTCODE_OFFSET_AUDIO_MP1 0x1C0
+#define DVDVIDEO_STARTCODE_OFFSET_AUDIO_MP2 0x1C0
+#define DVDVIDEO_STARTCODE_OFFSET_AUDIO_PCM 0xA0
+#define DVDVIDEO_STARTCODE_OFFSET_AUDIO_DTS 0x88
+#define DVDVIDEO_STARTCODE_OFFSET_SUBP 0x20
+
+#define DVDVIDEO_TITLE_NUMBER_MAX 99
+#define DVDVIDEO_PTT_NUMBER_MAX 99
+#define DVDVIDEO_PGC_NUMBER_MAX 32767
+#define DVDVIDEO_PG_NUMBER_MAX 255
+#define DVDVIDEO_ANGLE_NUMBER_MAX 9
+#define DVDVIDEO_VTS_NUMBER_MAX 99
+#define DVDVIDEO_TT_NUMBER_MAX 99
+#define DVDVIDEO_REGION_NUMBER_MAX 8
+#define DVDVIDEO_AUDIO_CONTROL_ENABLED_MASK 0x8000
+#define DVDVIDEO_SUBP_CONTROL_ENABLED_MASK 0x80000000
+#define DVDVIDEO_VTS_AUDIO_STREAMS_MAX 8
+#define DVDVIDEO_VTS_SUBP_STREAMS_MAX 32
+
+/* ("palette: ") + ("rrggbb, "*15) + ("rrggbb") + \n + \0 */
+#define DVDVIDEO_SUBP_CLUT_RGB_EXTRADATA_SIZE (9 + (8 * 15) + 6 + 1 + 1)
+#define DVDVIDEO_SUBP_CLUT_LEN 16
+#define DVDVIDEO_SUBP_CLUT_SIZE DVDVIDEO_SUBP_CLUT_LEN * sizeof(uint32_t)
+
+/* convert binary-coded decimal to decimal */
+#define BCD2D(__x__) (((__x__ & 0xF0) >> 4) * 10 + (__x__ & 0x0F))
+
+/* crop table for YUV to RGB subpicture palette conversion */
+#define DVDVIDEO_YUV_NEG_CROP_MAX 1024
+#define times4(x) x, x, x, x
+#define times256(x) times4(times4(times4(times4(times4(x)))))
+
+const uint8_t dvdvideo_yuv_crop_tab[256 + 2 * DVDVIDEO_YUV_NEG_CROP_MAX] = {
+times256(0x00),
+0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
+0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
+0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
+0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
+0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
+0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
+0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
+0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
+0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
+0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
+0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,
+0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,
+0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
+0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,
+times256(0xFF)
+};
+
+enum DVDVideoVTSMPEGVersion {
+ DVDVIDEO_VTS_MPEG_VERSION_MPEG1 = 0,
+ DVDVIDEO_VTS_MPEG_VERSION_MPEG2 = 1
+};
+
+enum DVDVideoVTSPictureFormat {
+ DVDVIDEO_VTS_PICTURE_FORMAT_NTSC = 0,
+ DVDVIDEO_VTS_PICTURE_FORMAT_PAL = 1
+};
+
+enum DVDVideoVTSPictureSize {
+ DVDVIDEO_VTS_PICTURE_SIZE_D1 = 0,
+ DVDVIDEO_VTS_PICTURE_SIZE_4CIF = 1,
+ DVDVIDEO_VTS_PICTURE_SIZE_D1_HALF = 2,
+ DVDVIDEO_VTS_PICTURE_SIZE_CIF = 3
+};
+
+enum DVDVideoVTSPictureDAR {
+ DVDVIDEO_VTS_PICTURE_DAR_4_3 = 0,
+ DVDVIDEO_VTS_PICTURE_DAR_16_9 = 3
+};
+
+enum DVDVideoVTSPermittedFullscreenDisplay {
+ DVDVIDEO_VTS_SPU_PFD_ANY = 0,
+ DVDVIDEO_VTS_SPU_PFD_PANSCAN_ONLY = 1,
+ DVDVIDEO_VTS_SPU_PFD_LETTERBOX_ONLY = 2
+};
+
+enum DVDVideoVTSAudioFormat {
+ DVDVIDEO_VTS_AUDIO_FORMAT_AC3 = 0,
+ DVDVIDEO_VTS_AUDIO_FORMAT_MP1 = 2,
+ DVDVIDEO_VTS_AUDIO_FORMAT_MP2 = 3,
+ DVDVIDEO_VTS_AUDIO_FORMAT_PCM = 4,
+ DVDVIDEO_VTS_AUDIO_FORMAT_SDDS = 5,
+ DVDVIDEO_VTS_AUDIO_FORMAT_DTS = 6
+};
+
+enum FFDVDVideoVTSAudioSampleRate {
+ DVDVIDEO_VTS_AUDIO_SAMPLE_RATE_48K = 0,
+ DVDVIDEO_VTS_AUDIO_SAMPLE_RATE_96K = 1
+};
+
+enum FFDVDVideoVTSAudioQuantization {
+ DVDVIDEO_VTS_AUDIO_QUANTIZATION_16 = 0,
+ DVDVIDEO_VTS_AUDIO_QUANTIZATION_20 = 1,
+ DVDVIDEO_VTS_AUDIO_QUANTIZATION_24 = 2
+};
+
+typedef struct DVDVideoDemuxContext {
+ const AVClass *class;
+
+ /* options */
+ int opt_title; /* the user-provided title number (1-indexed) */
+ int opt_ptt; /* the user-provided PTT number (1-indexed) */
+ int opt_pgc; /* the user-provided PGC number (1-indexed) */
+ int opt_pg; /* the user-provided PG number (1-indexed) */
+ int opt_angle; /* the user-provided angle number (1-indexed) */
+ int opt_region; /* the user-provided region identification digit */
+
+ /* subdemux */
+ const AVInputFormat *mpeg_fmt; /* inner MPEG-PS (VOB) demuxer */
+ AVFormatContext *mpeg_ctx; /* context for inner demuxer */
+ uint8_t *mpeg_buf; /* buffer for inner demuxer */
+ FFIOContext mpeg_pb; /* buffer context for inner demuxer */
+
+ /* volume */
+ dvd_reader_t *vol_dvdread; /* handle to libdvdread */
+ ifo_handle_t *vol_vmg_ifo; /* handle to the VMG (VIDEO_TS.IFO) */
+
+ /* playback */
+ ifo_handle_t *play_vts_ifo; /* handle to the active VTS (VTS_nn_n.IFO) */
+ pgc_t *play_pgc; /* handle to the active PGC */
+ int play_vtsn; /* number of the active VTS (video title set) */
+ int play_pgcn; /* number of the active PGC (program chain) */
+ dvdnav_t *play_dvdnav; /* handle to libdvdnav */
+} DVDVideoDemuxContext;
+
+static void dvdvideo_libdvdread_log(void *opaque, dvd_logger_level_t level,
+ const char *msg, va_list msg_va)
+{
+ AVFormatContext *s = opaque;
+ int lavu_level;
+
+ char msg_buf[DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE] = {0};
+ vsnprintf(msg_buf, DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE, msg, msg_va);
+
+ switch (level) {
+ case DVD_LOGGER_LEVEL_ERROR:
+ lavu_level = AV_LOG_ERROR;
+ break;
+ case DVD_LOGGER_LEVEL_WARN:
+ lavu_level = AV_LOG_WARNING;
+ break;
+ case DVD_LOGGER_LEVEL_INFO:
+ lavu_level = AV_LOG_INFO;
+ break;
+ case DVD_LOGGER_LEVEL_DEBUG:
+ default:
+ lavu_level = AV_LOG_DEBUG;
+ }
+
+ /* libdvdread messages don't have line terminators */
+ av_log(s, lavu_level, "libdvdread: %s\n", msg_buf);
+}
+
+static void dvdvideo_libdvdnav_log(void *opaque, dvdnav_logger_level_t level,
+ const char *msg, va_list msg_va)
+{
+ AVFormatContext *s = opaque;
+ int lavu_level;
+
+ char msg_buf[DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE] = {0};
+ vsnprintf(msg_buf, DVDVIDEO_LIBDVDX_LOG_BUFFER_SIZE, msg, msg_va);
+
+ switch (level) {
+ case DVDNAV_LOGGER_LEVEL_ERROR:
+ lavu_level = AV_LOG_ERROR;
+ break;
+ case DVDNAV_LOGGER_LEVEL_WARN:
+ lavu_level = AV_LOG_WARNING;
+ break;
+ case DVDNAV_LOGGER_LEVEL_INFO:
+ lavu_level = AV_LOG_INFO;
+ break;
+ case DVDNAV_LOGGER_LEVEL_DEBUG:
+ default:
+ lavu_level = AV_LOG_DEBUG;
+ }
+
+ /* libdvdnav messages don't have line terminators */
+ av_log(s, lavu_level, "libdvdnav: %s\n", msg_buf);
+}
+
+static char *dvdvideo_lang_code_to_iso639__2(const uint16_t lang_code)
+{
+ char lang_code_str[3] = {0};
+
+ if (lang_code && lang_code != 0xFFFF) {
+ lang_code_str[0] = (lang_code >> 8) & 0xFF;
+ lang_code_str[1] = lang_code & 0xFF;
+ }
+
+ return (char *) ff_convert_lang_to(lang_code_str, AV_LANG_ISO639_2_BIBL);
+}
+
+static int64_t dvdvideo_time_to_millis(dvd_time_t *time)
+{
+ double fps;
+ int64_t ms;
+
+ int64_t sec = (int64_t) (BCD2D(time->hour)) * 60 * 60;
+ sec += (int64_t) (BCD2D(time->minute)) * 60;
+ sec += (int64_t) (BCD2D(time->second));
+
+ /* the 2 high bits are the frame rate */
+ switch ((time->frame_u & 0xC0) >> 6)
+ {
+ case 1:
+ fps = 25.0;
+ break;
+ case 3:
+ fps = 29.97;
+ break;
+ default:
+ fps = 2500.0;
+ break;
+ }
+ ms = BCD2D(time->frame_u & 0x3F) * 1000.0 / fps;
+
+ return (sec * 1000) + ms;
+}
+
+static int dvdvideo_volume_is_title_valid_in_context(AVFormatContext *s,
+ int title)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ return title >= 1
+ && title <= DVDVIDEO_TITLE_NUMBER_MAX
+ && title <= c->vol_vmg_ifo->tt_srpt->nr_of_srpts
+ && c->vol_vmg_ifo->tt_srpt->title[title - 1].nr_of_ptts > 0;
+}
+
+static int dvdvideo_volume_is_title_valid_in_vts(title_info_t title_info,
+ ifo_handle_t *vts_ifo)
+{
+ return title_info.vts_ttn >= 1
+ && title_info.vts_ttn <= DVDVIDEO_TT_NUMBER_MAX
+ && title_info.vts_ttn <= vts_ifo->vts_ptt_srpt->nr_of_srpts
+ && vts_ifo->vtsi_mat->nr_of_vts_audio_streams
+ <= DVDVIDEO_VTS_AUDIO_STREAMS_MAX
+ && vts_ifo->vtsi_mat->nr_of_vts_subp_streams
+ <= DVDVIDEO_VTS_SUBP_STREAMS_MAX;
+}
+
+static int dvdvideo_volume_is_angle_valid_in_title(int angle,
+ title_info_t title_info)
+{
+ return angle >= 1
+ && angle <= DVDVIDEO_ANGLE_NUMBER_MAX
+ && angle <= title_info.nr_of_angles;
+}
+
+static int dvdvideo_volume_is_pgc_valid_and_sequential(pgc_t *pgc)
+{
+ return pgc
+ && pgc->program_map
+ && pgc->cell_playback != NULL
+ && pgc->pg_playback_mode == 0
+ && pgc->nr_of_programs > 0
+ && pgc->nr_of_cells > 0;
+}
+
+static int dvdvideo_volume_is_pgcn_in_vts(int pgcn, ifo_handle_t *vts_ifo)
+{
+ return pgcn >= 1
+ && pgcn <= DVDVIDEO_PGC_NUMBER_MAX
+ && pgcn <= vts_ifo->vts_pgcit->nr_of_pgci_srp;
+}
+
+static int dvdvideo_volume_is_pgn_in_pgc(int pgn, pgc_t *pgc)
+{
+ return pgn >= 1
+ && pgn <= DVDVIDEO_PG_NUMBER_MAX
+ && pgn <= pgc->nr_of_programs;
+}
+
+static int dvdvideo_volume_open(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ dvd_reader_t *dvdread;
+ ifo_handle_t *vmg_ifo;
+
+ dvd_logger_cb dvdread_log_cb = { .pf_log = dvdvideo_libdvdread_log };
+ dvdread = DVDOpen2(s, &dvdread_log_cb, s->url);
+
+ if (!dvdread) {
+ av_log(s, AV_LOG_ERROR, "Unable to initialize libdvdread\n");
+
+ return AVERROR_EXTERNAL;
+ }
+
+ if (!(vmg_ifo = ifoOpen(dvdread, 0))) {
+ DVDClose(dvdread);
+
+ av_log(s, AV_LOG_ERROR,
+ "Unable to open VIDEO_TS.IFO. "
+ "Input does not have a valid DVD-Video structure "
+ "or is not a compliant UDF DVD-Video image.\n");
+
+ return AVERROR_INVALIDDATA;
+ }
+
+ c->vol_dvdread = dvdread;
+ c->vol_vmg_ifo = vmg_ifo;
+
+ return 0;
+}
+
+static void dvdvideo_volume_close(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ if (c->vol_vmg_ifo) {
+ ifoClose(c->vol_vmg_ifo);
+ c->vol_vmg_ifo = NULL;
+ }
+
+ if (c->vol_dvdread) {
+ DVDClose(c->vol_dvdread);
+ c->vol_dvdread = NULL;
+ }
+}
+
+static int dvdvideo_volume_open_vts_ifo(AVFormatContext *s, int vtsn,
+ ifo_handle_t **p_vts_ifo)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ ifo_handle_t *vts_ifo;
+
+ if (vtsn < 1
+ || vtsn > DVDVIDEO_VTS_NUMBER_MAX
+ || !(vts_ifo = ifoOpen(c->vol_dvdread, vtsn))) {
+ return AVERROR_INVALIDDATA;
+ }
+
+ for (int i = 0; i < vts_ifo->vts_c_adt->nr_of_vobs; i++) {
+ int start_sector = vts_ifo->vts_c_adt->cell_adr_table[i].start_sector;
+ int end_sector = vts_ifo->vts_c_adt->cell_adr_table[i].last_sector;
+
+ if ((start_sector & 0xFFFFFF) == 0xFFFFFF
+ || (end_sector & 0xFFFFFF) == 0xFFFFFF
+ || start_sector >= end_sector) {
+ ifoClose(vts_ifo);
+
+ av_log(s, AV_LOG_WARNING, "VTS has invalid cell address table\n");
+
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
+ (*p_vts_ifo) = vts_ifo;
+
+ return 0;
+}
+
+static int dvdvideo_playback_open(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ int ret;
+
+ ifo_handle_t *vts_ifo;
+ dvdnav_logger_cb dvdnav_log_cb;
+ dvdnav_status_t dvdnav_status;
+ dvdnav_t *dvdnav;
+
+ title_info_t title_info;
+ int pgcn;
+ int pgn;
+ pgc_t *pgc;
+
+ int32_t disc_region_mask;
+ int32_t player_region_mask;
+ int cell_search_has_vts = 0;
+
+ /* if the title is valid, open its VTS IFO */
+ if (!dvdvideo_volume_is_title_valid_in_context(s, c->opt_title)) {
+ av_log(s, AV_LOG_ERROR, "Title not found or invalid\n");
+
+ return AVERROR_STREAM_NOT_FOUND;
+ }
+
+ title_info = c->vol_vmg_ifo->tt_srpt->title[c->opt_title - 1];
+
+ if ((ret = dvdvideo_volume_open_vts_ifo(s,
+ title_info.title_set_nr, &vts_ifo)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Title VTS could not be opened\n");
+
+ return ret;
+ }
+
+ if (!dvdvideo_volume_is_title_valid_in_vts(title_info, vts_ifo)) {
+ av_log(s, AV_LOG_ERROR, "Title VTS is invalid\n");
+
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (!dvdvideo_volume_is_angle_valid_in_title(c->opt_angle, title_info)) {
+ av_log(s, AV_LOG_ERROR, "Angle not found or invalid\n");
+
+ return AVERROR_INVALIDDATA;
+ }
+
+ /* determine our PGC and PG (playback coordinates) */
+ if (c->opt_pgc > 0 && c->opt_pg > 0) {
+ if (c->opt_ptt > 0) {
+ av_log(s, AV_LOG_WARNING,
+ "PTT option ignored as PGC and PG are provided\n");
+ }
+
+ pgcn = c->opt_pgc;
+ pgn = c->opt_pg;
+ } else {
+ if (c->opt_ptt > title_info.nr_of_ptts) {
+ av_log(s, AV_LOG_ERROR, "PTT not found\n");
+
+ return AVERROR_STREAM_NOT_FOUND;
+ }
+
+ pgcn = vts_ifo->vts_ptt_srpt->title[title_info.vts_ttn - 1].ptt[c->opt_ptt - 1].pgcn;
+ pgn = vts_ifo->vts_ptt_srpt->title[title_info.vts_ttn - 1].ptt[c->opt_ptt - 1].pgn;
+ }
+
+ if (!dvdvideo_volume_is_pgcn_in_vts(pgcn, vts_ifo)) {
+ av_log(s, AV_LOG_ERROR, "PGC not found\n");
+
+ return AVERROR_STREAM_NOT_FOUND;
+ }
+
+ pgc = vts_ifo->vts_pgcit->pgci_srp[pgcn - 1].pgc;
+
+ if (!dvdvideo_volume_is_pgc_valid_and_sequential(pgc)) {
+ av_log(s, AV_LOG_ERROR, "PGC not valid\n");
+
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (!dvdvideo_volume_is_pgn_in_pgc(pgn, pgc)) {
+ av_log(s, AV_LOG_ERROR, "PG not found\n");
+
+ return AVERROR_STREAM_NOT_FOUND;
+ }
+
+ /* set up libdvdnav */
+ dvdnav_log_cb = (dvdnav_logger_cb) { .pf_log = dvdvideo_libdvdnav_log };
+ dvdnav_status = dvdnav_open2(&dvdnav, NULL, &dvdnav_log_cb, s->url);
+
+ if (!dvdnav) {
+ av_log(s, AV_LOG_ERROR, "Unable to initialize libdvdnav\n");
+
+ return AVERROR_EXTERNAL;
+ }
+
+ if (dvdnav_status != DVDNAV_STATUS_OK) {
+ goto end_search_error_dvdnav;
+ }
+
+ if (dvdnav_set_readahead_flag(dvdnav, 0) != DVDNAV_STATUS_OK) {
+ goto end_search_error_dvdnav;
+ }
+
+ if (dvdnav_set_PGC_positioning_flag(dvdnav, 1) != DVDNAV_STATUS_OK) {
+ goto end_search_error_dvdnav;
+ }
+
+ if (dvdnav_get_region_mask(dvdnav, &disc_region_mask) != DVDNAV_STATUS_OK) {
+ goto end_search_error_dvdnav;
+ }
+
+ if (c->opt_region > 0) {
+ player_region_mask = (1 << (c->opt_region - 1));
+ } else {
+ player_region_mask = disc_region_mask;
+ }
+
+ if (dvdnav_set_region_mask(dvdnav, player_region_mask) != DVDNAV_STATUS_OK) {
+ goto end_search_error_dvdnav;
+ }
+
+ if (dvdnav_program_play(dvdnav, c->opt_title, pgcn, pgn) != DVDNAV_STATUS_OK) {
+ goto end_search_error_dvdnav;
+ }
+
+ if (dvdnav_angle_change(dvdnav, c->opt_angle) != DVDNAV_STATUS_OK) {
+ goto end_search_error_dvdnav;
+ }
+
+ /* lock on to title's VTS and chosen PGC/PGN coordinates */
+ for (int i = 0; i < DVDVIDEO_PS_MAX_SEARCH_BLOCKS; i++) {
+ int nav_event;
+ int nav_len;
+ dvdnav_vts_change_event_t *vts_event;
+ uint8_t nav_buf[DVDVIDEO_BLOCK_SIZE] = {0};
+
+ if (ff_check_interrupt(&s->interrupt_callback)) {
+ return AVERROR_EXIT;
+ }
+
+ if (dvdnav_get_next_block(dvdnav, nav_buf, &nav_event, &nav_len)
+ != DVDNAV_STATUS_OK) {
+ goto end_search_error_dvdnav;
+ }
+
+ if (nav_len > DVDVIDEO_BLOCK_SIZE) {
+ av_log(s, AV_LOG_ERROR, "Invalid block (too big)\n");
+
+ ret = AVERROR(ENOMEM);
+
+ goto end_search_error;
+ }
+
+ av_log(s, AV_LOG_TRACE, "nav event=%d len=%d\n", nav_event, nav_len);
+
+ switch (nav_event) {
+ case DVDNAV_VTS_CHANGE:
+ vts_event = (dvdnav_vts_change_event_t *) nav_buf;
+
+ if (cell_search_has_vts) {
+ if (vts_event->new_vtsN != title_info.title_set_nr
+ || vts_event->new_domain != DVD_DOMAIN_VTSTitle) {
+ av_log(s, AV_LOG_ERROR, "Unexpected VTS change\n");
+
+ ret = AVERROR_INPUT_CHANGED;
+
+ goto end_search_error;
+ }
+ continue;
+ }
+
+ if (vts_event->new_vtsN == title_info.title_set_nr
+ && vts_event->new_domain == DVD_DOMAIN_VTSTitle) {
+ cell_search_has_vts = 1;
+ }
+
+ continue;
+ case DVDNAV_CELL_CHANGE:
+ // if we need more info about the cell:
+ // dvdnav_cell_change_event_t *event_data =
+ // (dvdnav_cell_change_event_t *) nav_buf;
+ int check_title;
+ int check_pgcn;
+ int check_pgn;
+
+ if (!cell_search_has_vts) {
+ continue;
+ }
+
+ dvdnav_current_title_program(dvdnav, &check_title,
+ &check_pgcn, &check_pgn);
+
+ if (check_title == c->opt_title && check_pgcn == pgcn
+ && check_pgn == pgn && dvdnav_is_domain_vts(dvdnav)) {
+ goto end_ready;
+ }
+
+ continue;
+ case DVDNAV_STILL_FRAME:
+ dvdnav_still_skip(dvdnav);
+
+ continue;
+ case DVDNAV_WAIT:
+ dvdnav_wait_skip(dvdnav);
+
+ continue;
+ case DVDNAV_STOP:
+ ret = AVERROR_INPUT_CHANGED;
+
+ goto end_search_error;
+ default:
+ continue;
+ }
+ }
+
+end_search_error_dvdnav:
+ ret = AVERROR_EXTERNAL;
+ av_log(s, AV_LOG_ERROR, "libdvdnav: %s\n", dvdnav_err_to_string(dvdnav));
+ av_log(s, AV_LOG_ERROR, "Error starting playback\n");
+
+end_search_error:
+ dvdnav_close(dvdnav);
+ ifoClose(vts_ifo);
+
+ return ret;
+
+end_ready:
+ /* update the context */
+ c->play_vts_ifo = vts_ifo;
+ c->play_pgc = pgc;
+ c->play_vtsn = title_info.title_set_nr;
+ c->play_pgcn = pgcn;
+ c->play_dvdnav = dvdnav;
+
+ return 0;
+}
+
+static void dvdvideo_playback_close(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ if (c->play_dvdnav) {
+ dvdnav_close(c->play_dvdnav);
+ c->play_dvdnav = NULL;
+ }
+
+ if (c->play_vts_ifo) {
+ ifoClose(c->play_vts_ifo);
+ c->play_vts_ifo = NULL;
+ }
+}
+
+static int dvdvideo_video_stream_analyze(video_attr_t video_attr,
+ enum AVCodecID *p_codec_id, AVRational *p_framerate,
+ int *p_height, int *p_width)
+{
+ enum AVCodecID codec_id = AV_CODEC_ID_NONE;
+ AVRational framerate = ZERO_Q;
+ int height = 0;
+ int width = 0;
+
+ switch (video_attr.mpeg_version) {
+ case DVDVIDEO_VTS_MPEG_VERSION_MPEG1:
+ codec_id = AV_CODEC_ID_MPEG1VIDEO;
+ break;
+ case DVDVIDEO_VTS_MPEG_VERSION_MPEG2:
+ codec_id = AV_CODEC_ID_MPEG2VIDEO;
+ break;
+ }
+
+ switch (video_attr.video_format) {
+ case DVDVIDEO_VTS_PICTURE_FORMAT_NTSC:
+ framerate = DVDVIDEO_NTSC_FRAMERATE_Q;
+ height = DVDVIDEO_NTSC_HEIGHT;
+ break;
+ case DVDVIDEO_VTS_PICTURE_FORMAT_PAL:
+ framerate = DVDVIDEO_PAL_FRAMERATE_Q;
+ height = DVDVIDEO_PAL_HEIGHT;
+ break;
+ }
+
+ if (height > 0) {
+ switch (video_attr.picture_size) {
+ case DVDVIDEO_VTS_PICTURE_SIZE_D1:
+ width = DVDVIDEO_D1_WIDTH;
+ break;
+ case DVDVIDEO_VTS_PICTURE_SIZE_4CIF:
+ width = DVDVIDEO_4CIF_WIDTH;
+ break;
+ case DVDVIDEO_VTS_PICTURE_SIZE_D1_HALF:
+ width = DVDVIDEO_D1_HALF_WIDTH;
+ break;
+ case DVDVIDEO_VTS_PICTURE_SIZE_CIF:
+ width = DVDVIDEO_CIF_WIDTH;
+ height /= 2;
+ break;
+ }
+ }
+
+ if (codec_id == AV_CODEC_ID_NONE || av_cmp_q(framerate, ZERO_Q) == 0
+ || width < 1 || height < 1) {
+ return AVERROR_INVALIDDATA;
+ }
+
+ (*p_codec_id) = codec_id;
+ (*p_framerate) = framerate;
+ (*p_height) = height;
+ (*p_width) = width;
+
+ return 0;
+}
+
+static int dvdvideo_video_stream_to_avstream(AVFormatContext *s,
+ enum AVCodecID codec_id, AVRational framerate,
+ int height, int width,
+ enum AVStreamParseType need_parsing)
+{
+ AVStream *st;
+ FFStream *sti;
+
+ st = avformat_new_stream(s, NULL);
+ if (!st) {
+ return AVERROR(ENOMEM);
+ }
+
+ st->id = DVDVIDEO_STARTCODE_VIDEO;
+ st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+ st->codecpar->codec_id = codec_id;
+ st->codecpar->width = width;
+ st->codecpar->height = height;
+ st->codecpar->format = DVDVIDEO_PIXEL_FORMAT;
+
+ st->codecpar->framerate = framerate;
+#if FF_API_R_FRAME_RATE
+ st->r_frame_rate = framerate;
+#endif
+ st->avg_frame_rate = framerate;
+
+ avpriv_set_pts_info(st, DVDVIDEO_PTS_WRAP_BITS,
+ DVDVIDEO_TIME_BASE_Q.num, DVDVIDEO_TIME_BASE_Q.den);
+
+ sti = ffstream(st);
+ sti->request_probe = 0;
+ sti->need_parsing = need_parsing;
+ sti->avctx->framerate = framerate;
+
+ return 0;
+}
+
+static int dvdvideo_video_stream_register(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ enum AVCodecID codec_id;
+ AVRational framerate;
+ int height;
+ int width;
+
+ int ret;
+
+ if ((ret = dvdvideo_video_stream_analyze(c->play_vts_ifo->vtsi_mat->vts_video_attr, &codec_id,
+ &framerate, &height, &width)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Invalid video parameters in VTS IFO\n");
+
+ return ret;
+ }
+
+ if ((ret = dvdvideo_video_stream_to_avstream(c->mpeg_ctx, codec_id,
+ framerate, height, width, AVSTREAM_PARSE_FULL)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to allocate video stream (subdemux)\n");
+
+ return ret;
+ }
+
+ if ((ret = dvdvideo_video_stream_to_avstream(s, codec_id,
+ framerate, height, width, AVSTREAM_PARSE_NONE)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to allocate video stream\n");
+
+ return ret;
+ }
+
+ return 0;
+}
+
+static int dvdvideo_audio_stream_analyze(audio_attr_t audio_attr,
+ uint16_t audio_control, enum AVCodecID *p_codec_id, int *p_startcode,
+ int *p_sample_rate, int *p_sample_bits,
+ int *p_nb_channels, char **lang_iso639__2)
+{
+ enum AVCodecID codec_id = AV_CODEC_ID_NONE;
+ int startcode = 0;
+ int sample_rate = 0;
+ int sample_bits = 0;
+ int nb_channels = 0;
+
+ int position = (audio_control & 0x7F00) >> 8;
+
+ switch (audio_attr.audio_format) {
+ case DVDVIDEO_VTS_AUDIO_FORMAT_AC3:
+ codec_id = AV_CODEC_ID_AC3;
+ sample_rate = 48000;
+ startcode = DVDVIDEO_STARTCODE_OFFSET_AUDIO_AC3 + position;
+ break;
+ case DVDVIDEO_VTS_AUDIO_FORMAT_MP1:
+ codec_id = AV_CODEC_ID_MP1;
+ sample_rate = 48000;
+ startcode = DVDVIDEO_STARTCODE_OFFSET_AUDIO_MP1 + position;
+ break;
+ case DVDVIDEO_VTS_AUDIO_FORMAT_MP2:
+ codec_id = AV_CODEC_ID_MP2;
+ sample_rate = 48000;
+ startcode = DVDVIDEO_STARTCODE_OFFSET_AUDIO_MP2 + position;
+ break;
+ case DVDVIDEO_VTS_AUDIO_FORMAT_PCM:
+ codec_id = AV_CODEC_ID_PCM_DVD;
+
+ switch (audio_attr.sample_frequency) {
+ case DVDVIDEO_VTS_AUDIO_SAMPLE_RATE_48K:
+ sample_rate = 48000;
+ break;
+ case DVDVIDEO_VTS_AUDIO_SAMPLE_RATE_96K:
+ sample_rate = 96000;
+ break;
+ }
+
+ switch (audio_attr.quantization) {
+ case DVDVIDEO_VTS_AUDIO_QUANTIZATION_16:
+ sample_bits = 16;
+ break;
+ case DVDVIDEO_VTS_AUDIO_QUANTIZATION_20:
+ sample_bits = 20;
+ break;
+ case DVDVIDEO_VTS_AUDIO_QUANTIZATION_24:
+ sample_bits = 24;
+ break;
+ }
+
+ startcode = DVDVIDEO_STARTCODE_OFFSET_AUDIO_PCM + position;
+ break;
+ case DVDVIDEO_VTS_AUDIO_FORMAT_DTS:
+ codec_id = AV_CODEC_ID_DTS;
+ sample_rate = 48000;
+ startcode = DVDVIDEO_STARTCODE_OFFSET_AUDIO_DTS + position;
+ break;
+ }
+
+ nb_channels = audio_attr.channels + 1;
+
+ if (codec_id == AV_CODEC_ID_NONE || startcode == 0
+ || sample_rate == 0 || nb_channels == 0) {
+ return AVERROR_INVALIDDATA;
+ }
+
+ (*p_codec_id) = codec_id;
+ (*p_startcode) = startcode;
+ (*p_sample_rate) = sample_rate;
+ (*p_sample_bits) = sample_bits;
+ (*p_nb_channels) = nb_channels;
+ (*lang_iso639__2) = dvdvideo_lang_code_to_iso639__2(audio_attr.lang_code);
+
+ return 0;
+}
+
+static int dvdvideo_audio_stream_to_avstream(AVFormatContext *s,
+ enum AVCodecID codec_id, int startcode, int sample_rate,
+ int sample_bits, int nb_channels, char *lang_iso639__2,
+ enum AVStreamParseType need_parsing)
+{
+ AVStream *st;
+ FFStream *sti;
+
+ st = avformat_new_stream(s, NULL);
+ if (!st) {
+ return AVERROR(ENOMEM);
+ }
+
+ st->id = startcode;
+ st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+ st->codecpar->codec_id = codec_id;
+ st->codecpar->sample_rate = sample_rate;
+ st->codecpar->ch_layout.nb_channels = nb_channels;
+
+ if (sample_bits > 0) {
+ st->codecpar->format = sample_bits == 16 ?
+ AV_SAMPLE_FMT_S16
+ : AV_SAMPLE_FMT_S32;
+ st->codecpar->bits_per_coded_sample = sample_bits;
+ st->codecpar->bits_per_raw_sample = sample_bits;
+ }
+
+ if (lang_iso639__2) {
+ av_dict_set(&st->metadata, "language", lang_iso639__2, 0);
+ }
+
+ avpriv_set_pts_info(st, DVDVIDEO_PTS_WRAP_BITS,
+ DVDVIDEO_TIME_BASE_Q.num, DVDVIDEO_TIME_BASE_Q.den);
+
+ sti = ffstream(st);
+ sti->request_probe = 0;
+ sti->need_parsing = need_parsing;
+
+ return 0;
+}
+
+static int dvdvideo_audio_stream_register_all(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ for (int i = 0; i < c->play_vts_ifo->vtsi_mat->nr_of_vts_audio_streams; i++) {
+ enum AVCodecID codec_id;
+ int startcode;
+ int sample_rate;
+ int sample_bits;
+ int nb_channels;
+ char *lang_iso639__2;
+ int ret;
+
+ if (!(c->play_pgc->audio_control[i]
+ & DVDVIDEO_AUDIO_CONTROL_ENABLED_MASK)) {
+ continue;
+ }
+
+ if ((ret = dvdvideo_audio_stream_analyze(
+ c->play_vts_ifo->vtsi_mat->vts_audio_attr[i],
+ c->play_pgc->audio_control[i], &codec_id, &startcode,
+ &sample_rate, &sample_bits, &nb_channels,
+ &lang_iso639__2)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Invalid audio parameters in VTS IFO\n");
+
+ return ret;
+ }
+
+ if (c->play_vts_ifo->vtsi_mat->
+ vts_audio_attr[i].application_mode == 1) {
+ av_log(s, AV_LOG_ERROR,
+ "Audio stream uses karaoke extension which is unsupported\n");
+
+ return AVERROR_PATCHWELCOME;
+ }
+
+ for (int j = 0; j < s->nb_streams; j++) {
+ if (s->streams[j]->id == startcode) {
+ av_log(s, AV_LOG_WARNING,
+ "Audio stream has duplicate entry in VTS IFO\n");
+
+ continue;
+ }
+ }
+
+ if ((ret = dvdvideo_audio_stream_to_avstream(c->mpeg_ctx, codec_id,
+ startcode, sample_rate, sample_bits, nb_channels,
+ lang_iso639__2, AVSTREAM_PARSE_FULL)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to allocate video stream (subdemux)\n");
+
+ return ret;
+ }
+
+ if ((ret = dvdvideo_audio_stream_to_avstream(s, codec_id,
+ startcode, sample_rate, sample_bits, nb_channels,
+ lang_iso639__2, AVSTREAM_PARSE_NONE)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to allocate audio stream\n");
+
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int dvdvideo_subtitle_clut_rgb_extradata_cat(
+ const uint32_t *clut_rgb, size_t clut_rgb_size,
+ char *dst, size_t dst_size)
+{
+ if (dst_size < DVDVIDEO_SUBP_CLUT_RGB_EXTRADATA_SIZE) {
+ return AVERROR(ENOMEM);
+ }
+
+ if (clut_rgb_size != DVDVIDEO_SUBP_CLUT_SIZE) {
+ return AVERROR(EINVAL);
+ }
+
+ snprintf(dst, dst_size, "palette: ");
+
+ for (int i = 0; i < DVDVIDEO_SUBP_CLUT_LEN; i++) {
+ av_strlcatf(dst, dst_size,
+ "%06"PRIx32"%s", clut_rgb[i], i != 15 ? ", " : "");
+ }
+
+ av_strlcat(dst, "\n", 1);
+
+ return 0;
+}
+
+static int dvdvideo_subtitle_clut_yuv_to_rgb(uint32_t *clut,
+ const size_t clut_size)
+{
+ const uint8_t *cm = dvdvideo_yuv_crop_tab + DVDVIDEO_YUV_NEG_CROP_MAX;
+
+ int i, y, cb, cr;
+ uint8_t r, g, b;
+ int r_add, g_add, b_add;
+
+ if (clut_size != DVDVIDEO_SUBP_CLUT_SIZE) {
+ return AVERROR(EINVAL);
+ }
+
+ for (i = 0; i < DVDVIDEO_SUBP_CLUT_LEN; i++) {
+ y = (clut[i] >> 16) & 0xFF;
+ cr = (clut[i] >> 8) & 0xFF;
+ cb = clut[i] & 0xFF;
+
+ YUV_TO_RGB1_CCIR(cb, cr);
+ YUV_TO_RGB2_CCIR(r, g, b, y);
+
+ clut[i] = (r << 16) | (g << 8) | b;
+ }
+
+ return 0;
+}
+
+static int dvdvideo_subtitle_stream_to_avstream(AVFormatContext *s,
+ int startcode,
+ char *clut_rgb_extradata_buf, int clut_rgb_extradata_buf_size,
+ char *lang_iso639__2, enum AVStreamParseType need_parsing)
+{
+ AVStream *st;
+ FFStream *sti;
+ int ret;
+
+ st = avformat_new_stream(s, NULL);
+ if (!st) {
+ return AVERROR(ENOMEM);
+ }
+
+ st->id = startcode;
+ st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ st->codecpar->codec_id = AV_CODEC_ID_DVD_SUBTITLE;
+
+ if ((ret = ff_alloc_extradata(st->codecpar,
+ clut_rgb_extradata_buf_size)) != 0) {
+ return ret;
+ }
+
+ memcpy(st->codecpar->extradata, clut_rgb_extradata_buf,
+ st->codecpar->extradata_size);
+
+ if (lang_iso639__2) {
+ av_dict_set(&st->metadata, "language", lang_iso639__2, 0);
+ }
+
+ avpriv_set_pts_info(st, DVDVIDEO_PTS_WRAP_BITS,
+ DVDVIDEO_TIME_BASE_Q.num, DVDVIDEO_TIME_BASE_Q.den);
+
+ sti = ffstream(st);
+ sti->request_probe = 0;
+ sti->need_parsing = need_parsing;
+
+ return 0;
+}
+
+static int dvdvideo_subtitle_stream_register(AVFormatContext *s,
+ int position,
+ char *clut_rgb_extradata_buf, int clut_rgb_extradata_buf_size,
+ char *lang_iso639__2)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ int ret;
+
+ int startcode = DVDVIDEO_STARTCODE_OFFSET_SUBP + position;
+
+ for (int i = 0; i < s->nb_streams; i++) {
+ /* don't need to warn the user about this, since params won't change */
+ if (s->streams[i]->id == startcode) {
+ av_log(s, AV_LOG_TRACE,
+ "Subtitle stream has duplicate entry in VTS IFO\n");
+ return 0;
+ }
+ }
+
+ if ((ret = dvdvideo_subtitle_stream_to_avstream(c->mpeg_ctx, startcode,
+ clut_rgb_extradata_buf, clut_rgb_extradata_buf_size,
+ lang_iso639__2, AVSTREAM_PARSE_FULL)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to allocate subtitle stream (subdemux)\n");
+
+ return ret;
+ }
+
+ if ((ret = dvdvideo_subtitle_stream_to_avstream(s, startcode,
+ clut_rgb_extradata_buf, clut_rgb_extradata_buf_size,
+ lang_iso639__2, AVSTREAM_PARSE_NONE)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to allocate subtitle stream\n");
+
+ return ret;
+ }
+
+ return 0;
+}
+
+static int dvdvideo_subtitle_stream_register_all(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ int ret;
+ uint32_t clut_rgb[DVDVIDEO_SUBP_CLUT_SIZE] = {0};
+ char clut_rgb_extradata_buf[DVDVIDEO_SUBP_CLUT_RGB_EXTRADATA_SIZE] = {0};
+
+ if (c->play_vts_ifo->vtsi_mat->nr_of_vts_subp_streams < 1) {
+ return 0;
+ }
+
+ /* initialize the palette (same for all streams in this PGC) */
+ memcpy(clut_rgb, c->play_pgc->palette, DVDVIDEO_SUBP_CLUT_SIZE);
+
+ if ((ret = dvdvideo_subtitle_clut_yuv_to_rgb(
+ clut_rgb, DVDVIDEO_SUBP_CLUT_SIZE)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to convert subtitle palette\n");
+
+ return ret;
+ }
+
+ if ((ret = dvdvideo_subtitle_clut_rgb_extradata_cat(
+ clut_rgb, DVDVIDEO_SUBP_CLUT_SIZE,
+ clut_rgb_extradata_buf, DVDVIDEO_SUBP_CLUT_RGB_EXTRADATA_SIZE)) != 0) {
+ av_log(s, AV_LOG_ERROR, "Unable to set up subtitle extradata\n");
+
+ return ret;
+ }
+
+ for (int i = 0; i < c->play_vts_ifo->
+ vtsi_mat->nr_of_vts_subp_streams; i++) {
+ uint32_t subp_control;
+ subp_attr_t subp_attr;
+ video_attr_t video_attr;
+ char *lang_iso639__2;
+
+ subp_control = c->play_pgc->subp_control[i];
+
+ if (!(subp_control & DVDVIDEO_SUBP_CONTROL_ENABLED_MASK)) {
+ continue;
+ }
+
+ subp_attr = c->play_vts_ifo->vtsi_mat->vts_subp_attr[i];
+ video_attr = c->play_vts_ifo->vtsi_mat->vts_video_attr;
+ lang_iso639__2 = dvdvideo_lang_code_to_iso639__2(subp_attr.lang_code);
+
+ /* there can be several presentations for one SPU */
+ /* for now, be flexible with the DAR check due to weird authoring */
+ if (video_attr.display_aspect_ratio > 0) {
+ /* 16:9 */
+ ret = dvdvideo_subtitle_stream_register(s,
+ ((subp_control >> 16) & 0x1F),
+ clut_rgb_extradata_buf,
+ DVDVIDEO_SUBP_CLUT_RGB_EXTRADATA_SIZE,
+ lang_iso639__2);
+ if (ret != 0) {
+ return ret;
+ }
+
+ if (video_attr.permitted_df == DVDVIDEO_VTS_SPU_PFD_LETTERBOX_ONLY
+ || video_attr.permitted_df == DVDVIDEO_VTS_SPU_PFD_ANY) {
+ ret = dvdvideo_subtitle_stream_register(s,
+ ((subp_control >> 8) & 0x1F),
+ clut_rgb_extradata_buf,
+ DVDVIDEO_SUBP_CLUT_RGB_EXTRADATA_SIZE,
+ lang_iso639__2);
+ if (ret != 0) {
+ return ret;
+ }
+ }
+
+ if (video_attr.permitted_df == DVDVIDEO_VTS_SPU_PFD_PANSCAN_ONLY
+ || video_attr.permitted_df == DVDVIDEO_VTS_SPU_PFD_ANY) {
+ ret = dvdvideo_subtitle_stream_register(s,
+ (subp_control & 0x1F),
+ clut_rgb_extradata_buf,
+ DVDVIDEO_SUBP_CLUT_RGB_EXTRADATA_SIZE,
+ lang_iso639__2);
+ if (ret != 0) {
+ return ret;
+ }
+ }
+ } else {
+ /* 4:3 */
+ ret = dvdvideo_subtitle_stream_register(s,
+ ((subp_control >> 24) & 0x1F),
+ clut_rgb_extradata_buf,
+ DVDVIDEO_SUBP_CLUT_RGB_EXTRADATA_SIZE,
+ lang_iso639__2);
+ if (ret != 0) {
+ return ret;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int dvdvideo_subdemux_nested_io_open(AVFormatContext *s,
+ AVIOContext **pb, const char *url, int flags, AVDictionary **opts)
+{
+ av_log(s, AV_LOG_ERROR, "Nested io_open not supported for this format\n");
+
+ return AVERROR(EPERM);
+}
+
+static int dvdvideo_subdemux_read_data(void *opaque, uint8_t *buf,
+ int buf_size)
+{
+ AVFormatContext *s = opaque;
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ if (buf_size != DVDVIDEO_BLOCK_SIZE) {
+ av_log(s, AV_LOG_ERROR, "Invalid buffer size\n");
+
+ return AVERROR(ENOMEM);
+ }
+
+ for (int i = 0; i < DVDVIDEO_PS_MAX_SEARCH_BLOCKS; i++) {
+ int nav_event;
+ int nav_len;
+
+ int check_title;
+ int check_pgcn;
+ int check_pgn;
+ int check_angle;
+ int check_nb_angles;
+
+ uint8_t nav_buf[DVDVIDEO_BLOCK_SIZE] = {0};
+
+ if (ff_check_interrupt(&s->interrupt_callback)) {
+ return AVERROR_EXIT;
+ }
+
+ if (dvdnav_get_next_block(c->play_dvdnav,
+ nav_buf, &nav_event, &nav_len) != DVDNAV_STATUS_OK) {
+ av_log(s, AV_LOG_ERROR, "Error reading block\n");
+
+ goto end_dvdnav_error;
+ }
+
+ if (nav_len > DVDVIDEO_BLOCK_SIZE) {
+ av_log(s, AV_LOG_ERROR, "Invalid block (too big)\n");
+
+ return AVERROR(ENOMEM);
+ }
+
+ if (nav_event != DVDNAV_BLOCK_OK && nav_event != DVDNAV_NAV_PACKET) {
+ av_log(s, AV_LOG_TRACE, "nav event=%d len=%d\n", nav_event, nav_len);
+ }
+
+ if (dvdnav_current_title_program(c->play_dvdnav, &check_title,
+ &check_pgcn, &check_pgn) != DVDNAV_STATUS_OK) {
+ goto end_dvdnav_error;
+ }
+
+ if (check_title != c->opt_title || check_pgcn != c->play_pgcn
+ || !dvdnav_is_domain_vts(c->play_dvdnav)) {
+ return AVERROR_EOF;
+ }
+
+ if (dvdnav_get_angle_info(c->play_dvdnav, &check_angle,
+ &check_nb_angles) != DVDNAV_STATUS_OK) {
+ goto end_dvdnav_error;
+ }
+
+ if (check_angle != c->opt_angle) {
+ av_log(s, AV_LOG_ERROR, "Unexpected angle change\n");
+
+ return AVERROR_INPUT_CHANGED;
+ }
+
+ switch (nav_event) {
+ case DVDNAV_BLOCK_OK:
+ if (nav_len != DVDVIDEO_BLOCK_SIZE) {
+ av_log(s, AV_LOG_ERROR, "Invalid block\n");
+
+ return AVERROR_INVALIDDATA;
+ }
+
+ memcpy(buf, &nav_buf, nav_len);
+
+ return nav_len;
+ case DVDNAV_HIGHLIGHT:
+ case DVDNAV_VTS_CHANGE:
+ case DVDNAV_STILL_FRAME:
+ case DVDNAV_STOP:
+ case DVDNAV_WAIT:
+ return AVERROR_EOF;
+ default:
+ continue;
+ }
+ }
+
+ av_log(s, AV_LOG_ERROR, "Unable to find next MPEG block\n");
+
+ return AVERROR_UNKNOWN;
+
+end_dvdnav_error:
+ av_log(s, AV_LOG_ERROR, "libdvdnav: %s\n", dvdnav_err_to_string(c->play_dvdnav));
+
+ return AVERROR_EXTERNAL;
+}
+
+static int64_t dvdvideo_subdemux_seek_data(void *opaque, int64_t offset,
+ int whence)
+{
+ AVFormatContext *s = opaque;
+
+ av_log(s, AV_LOG_ERROR,
+ "dvdvideo_subdemux_seek_data(): not implemented\n");
+
+ return AVERROR_PATCHWELCOME;
+}
+
+static int dvdvideo_subdemux_open(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ int ret;
+
+ const AVInputFormat *mpeg_fmt;
+ AVFormatContext *mpeg_ctx;
+ uint8_t *mpeg_buf;
+
+ if (!(mpeg_fmt = av_find_input_format("mpeg"))) {
+ return AVERROR_DEMUXER_NOT_FOUND;
+ }
+
+ if (!(mpeg_ctx = avformat_alloc_context())) {
+ return AVERROR(ENOMEM);
+ }
+
+ if (!(mpeg_buf = av_malloc(DVDVIDEO_BLOCK_SIZE))) {
+ avformat_free_context(mpeg_ctx);
+
+ return AVERROR(ENOMEM);
+ }
+
+ ffio_init_context(&c->mpeg_pb, mpeg_buf, DVDVIDEO_BLOCK_SIZE, 0,
+ s, dvdvideo_subdemux_read_data, NULL, dvdvideo_subdemux_seek_data);
+ c->mpeg_pb.pub.seekable = 0;
+
+ if ((ret = ff_copy_whiteblacklists(mpeg_ctx, s)) != 0) {
+ avformat_free_context(mpeg_ctx);
+
+ return ret;
+ }
+
+ /* TODO: fix the PTS issues (ask about this in ML) */
+ /* AVFMT_FLAG_GENPTS works in some scenarios, but in others, the reading process hangs */
+ mpeg_ctx->flags = AVFMT_FLAG_CUSTOM_IO | AVFMT_FLAG_GENPTS;
+
+ mpeg_ctx->probesize = 0;
+ mpeg_ctx->max_analyze_duration = 0;
+
+ mpeg_ctx->interrupt_callback = s->interrupt_callback;
+ mpeg_ctx->pb = &c->mpeg_pb.pub;
+ mpeg_ctx->io_open = dvdvideo_subdemux_nested_io_open;
+
+ if ((ret = avformat_open_input(&mpeg_ctx, "", mpeg_fmt, NULL)) != 0) {
+ avformat_free_context(mpeg_ctx);
+
+ return ret;
+ }
+
+ c->mpeg_fmt = mpeg_fmt;
+ c->mpeg_ctx = mpeg_ctx;
+ c->mpeg_buf = mpeg_buf;
+
+ return 0;
+}
+
+static void dvdvideo_subdemux_close(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ av_freep(&c->mpeg_pb.pub.buffer);
+ memset(&c->mpeg_pb, 0x00, sizeof(c->mpeg_pb));
+ av_freep(&c->mpeg_pb);
+
+ avformat_close_input(&c->mpeg_ctx);
+}
+
+static int dvdvideo_chapters_register(AVFormatContext *s)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+ int start_time = 0;
+ int cell = 0;
+
+ for (int i = 0; i < c->play_pgc->nr_of_programs; i++) {
+ int64_t ms = 0;
+ int next = c->play_pgc->program_map[i + 1];
+
+ if (i == c->play_pgc->nr_of_programs - 1) {
+ next = c->play_pgc->nr_of_cells + 1;
+ }
+
+ while (cell < next - 1) {
+ /* only consider first cell of multi-angle cells */
+ if (c->play_pgc->cell_playback[cell].block_mode <= 1) {
+ ms = ms + dvdvideo_time_to_millis(
+ &c->play_pgc->cell_playback[cell].playback_time);
+ }
+ cell++;
+ }
+
+ if (!avpriv_new_chapter(s, i, DVDVIDEO_TIME_BASE_MILLIS_Q,
+ start_time, start_time + ms, NULL)) {
+ av_log(s, AV_LOG_ERROR, "Unable to allocate chapter");
+ return AVERROR(ENOMEM);
+ }
+
+ start_time += ms;
+ }
+
+ return 0;
+}
+
+static int dvdvideo_read_header(AVFormatContext *s)
+{
+ int ret;
+
+ if ((ret = dvdvideo_volume_open(s)) != 0) {
+ return ret;
+ }
+
+ if ((ret = dvdvideo_playback_open(s)) != 0) {
+ return ret;
+ }
+
+ if ((ret = dvdvideo_subdemux_open(s)) != 0) {
+ return ret;
+ }
+
+ if ((ret = dvdvideo_video_stream_register(s)) != 0) {
+ return ret;
+ }
+
+ if ((ret = dvdvideo_audio_stream_register_all(s)) != 0) {
+ return ret;
+ }
+
+ if ((ret = dvdvideo_subtitle_stream_register_all(s)) != 0) {
+ return ret;
+ }
+
+ if ((ret = dvdvideo_chapters_register(s)) != 0) {
+ return ret;
+ }
+
+ return 0;
+}
+
+static int dvdvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ DVDVideoDemuxContext *c = s->priv_data;
+
+ while (!ff_check_interrupt(&s->interrupt_callback)) {
+ int subdemux_ret;
+ AVPacket *subdemux_pkt;
+
+ subdemux_pkt = av_packet_alloc();
+ if (!subdemux_pkt) {
+ return AVERROR(ENOMEM);
+ }
+
+ subdemux_ret = av_read_frame(c->mpeg_ctx, subdemux_pkt);
+ if (subdemux_ret >= 0) {
+ if (c->mpeg_ctx->nb_streams != s->nb_streams) {
+ av_log(s, AV_LOG_ERROR, "Unexpected stream during playback\n");
+
+ av_packet_unref(subdemux_pkt);
+
+ return AVERROR_INPUT_CHANGED;
+ }
+
+ av_packet_move_ref(pkt, subdemux_pkt);
+
+ return 0;
+ }
+
+ return subdemux_ret;
+ }
+
+ return AVERROR_EOF;
+}
+
+static int dvdvideo_read_seek(AVFormatContext *s, int stream_index,
+ int64_t timestamp, int flags)
+{
+ av_log(s, AV_LOG_ERROR, "dvdvideo_read_seek(): not implemented\n");
+
+ return AVERROR_PATCHWELCOME;
+}
+
+static int dvdvideo_close(AVFormatContext *s)
+{
+ dvdvideo_subdemux_close(s);
+ dvdvideo_playback_close(s);
+ dvdvideo_volume_close(s);
+
+ return 0;
+}
+
+static int dvdvideo_probe(const AVProbeData *p)
+{
+ av_log(NULL, AV_LOG_ERROR, "dvdvideo_probe(): not implemented\n");
+
+ return AVERROR_PATCHWELCOME;
+}
+
+#define OFFSET(x) offsetof(DVDVideoDemuxContext, x)
+static const AVOption dvdvideo_options[] = {
+ {"title", "Title Number", OFFSET(opt_title), AV_OPT_TYPE_INT, { .i64=1 }, 1, DVDVIDEO_TITLE_NUMBER_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ {"ptt", "Entry PTT Number", OFFSET(opt_ptt), AV_OPT_TYPE_INT, { .i64=1 }, 1, DVDVIDEO_PTT_NUMBER_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ {"pgc", "Entry PGC Number (0=auto)", OFFSET(opt_pgc), AV_OPT_TYPE_INT, { .i64=0 }, 0, DVDVIDEO_PGC_NUMBER_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ {"pg", "Entry PG Number (0=auto)", OFFSET(opt_pg), AV_OPT_TYPE_INT, { .i64=0 }, 0, DVDVIDEO_PG_NUMBER_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ {"angle", "Video Angle Number", OFFSET(opt_angle), AV_OPT_TYPE_INT, { .i64=1 }, 1, DVDVIDEO_ANGLE_NUMBER_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ {"region", "Playback Region Number (0=free)", OFFSET(opt_region), AV_OPT_TYPE_INT, { .i64=0 }, 0, DVDVIDEO_REGION_NUMBER_MAX, AV_OPT_FLAG_DECODING_PARAM },
+ {NULL}
+};
+
+static const AVClass dvdvideo_class = {
+ .class_name = "DVD-Video demuxer",
+ .item_name = av_default_item_name,
+ .option = dvdvideo_options,
+ .version = LIBAVUTIL_VERSION_INT
+};
+
+const AVInputFormat ff_dvdvideo_demuxer = {
+ .name = "dvdvideo",
+ .long_name = NULL_IF_CONFIG_SMALL("DVD-Video"),
+ .priv_class = &dvdvideo_class,
+ .priv_data_size = sizeof(DVDVideoDemuxContext),
+ .flags = AVFMT_NOFILE | AVFMT_NO_BYTE_SEEK | AVFMT_NOGENSEARCH | AVFMT_NOBINSEARCH | AVFMT_SHOW_IDS | AVFMT_TS_DISCONT,
+ .flags_internal = FF_FMT_INIT_CLEANUP,
+ .read_probe = dvdvideo_probe,
+ .read_close = dvdvideo_close,
+ .read_header = dvdvideo_read_header,
+ .read_packet = dvdvideo_read_packet,
+ .read_seek = dvdvideo_read_seek
+};
--
2.34.1
5
26