+++ /dev/null
---- a/libavcodec/aaccoder.c
-+++ b/libavcodec/aaccoder.c
-@@ -60,6 +60,8 @@
- * replace low energy non zero bands */
- #define NOISE_LAMBDA_REPLACE 1.948f
-
-+#undef B0
-+
- #include "libavcodec/aaccoder_trellis.h"
-
- /**
---- a/libavcodec/hevc_mvs.c
-+++ b/libavcodec/hevc_mvs.c
-@@ -25,6 +25,8 @@
- #include "hevcdec.h"
- #include "threadframe.h"
-
-+#undef B0
-+
- static const uint8_t l0_l1_cand_idx[12][2] = {
- { 0, 1, },
- { 1, 0, },
---- a/libavcodec/opus_pvq.c
-+++ b/libavcodec/opus_pvq.c
-@@ -31,6 +31,8 @@
- #define CELT_PVQ_U(n, k) (ff_celt_pvq_u_row[FFMIN(n, k)][FFMAX(n, k)])
- #define CELT_PVQ_V(n, k) (CELT_PVQ_U(n, k) + CELT_PVQ_U(n, (k) + 1))
-
-+#undef B0
-+
- static inline int16_t celt_cos(int16_t x)
- {
- x = (MUL16(x, x) + 4096) >> 13;
+++ /dev/null
---- a/fftools/cmdutils.c
-+++ b/fftools/cmdutils.c
-@@ -59,7 +59,7 @@
- AVDictionary *swr_opts;
- AVDictionary *format_opts, *codec_opts;
-
--int hide_banner = 0;
-+int hide_banner = 1;
-
- void uninit_opts(void)
- {
+++ /dev/null
---- a/libavutil/hwcontext_cuda.c
-+++ b/libavutil/hwcontext_cuda.c
-@@ -286,9 +286,11 @@
- CudaFunctions *cu = hwctx->internal->cuda_dl;
-
- if (hwctx->internal->is_allocated && hwctx->cuda_ctx) {
-+#ifdef CUDA_PRIMARY_CTX
- if (hwctx->internal->flags & AV_CUDA_USE_PRIMARY_CONTEXT)
- CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal->cuda_device));
- else
-+#endif
- CHECK_CU(cu->cuCtxDestroy(hwctx->cuda_ctx));
-
- hwctx->cuda_ctx = NULL;
-@@ -338,7 +340,7 @@
- cu = hwctx->internal->cuda_dl;
-
- hwctx->internal->flags = flags;
--
-+#ifdef CUDA_PRIMARY_CTX
- if (flags & AV_CUDA_USE_PRIMARY_CONTEXT) {
- ret = CHECK_CU(cu->cuDevicePrimaryCtxGetState(hwctx->internal->cuda_device,
- &dev_flags, &dev_active));
-@@ -359,7 +361,9 @@
- hwctx->internal->cuda_device));
- if (ret < 0)
- return ret;
-- } else {
-+ } else
-+#endif
-+ {
- ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
- hwctx->internal->cuda_device));
- if (ret < 0)
+++ /dev/null
---- a/libavformat/mpegtsenc.c
-+++ b/libavformat/mpegtsenc.c
-@@ -84,9 +84,11 @@
- int64_t pat_period; /* PAT/PMT period in PCR time base */
- int64_t nit_period; /* NIT period in PCR time base */
- int nb_services;
-- int64_t first_pcr;
- int first_dts_checked;
-- int64_t next_pcr;
-+ int64_t pcr_pos, pcr;
-+ int64_t first_pcr, next_pcr;
-+ int64_t delay;
-+ int pcr_stream_pid;
- int mux_rate; ///< set to 1 when VBR
- int pes_payload_size;
- int64_t total_size;
-@@ -252,7 +254,7 @@
- int data_st_warning;
-
- int64_t pcr_period; /* PCR period in PCR time base */
-- int64_t last_pcr;
-+ int64_t pcr_timer;
-
- /* For Opus */
- int opus_queued_samples;
-@@ -945,18 +947,18 @@
- return 0;
- }
-
--static int64_t get_pcr(const MpegTSWrite *ts)
-+static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb)
- {
-- return av_rescale(ts->total_size + 11, 8 * PCR_TIME_BASE, ts->mux_rate) +
-- ts->first_pcr;
-+ int64_t pos = avio_tell(pb) + 11;
-+ return ts->pcr + (ts->mux_rate == 1 ? (pos - ts->pcr_pos) * 8 :
-+ av_rescale(pos - ts->pcr_pos, 8 * PCR_TIME_BASE, ts->mux_rate));
- }
-
- static void write_packet(AVFormatContext *s, const uint8_t *packet)
- {
- MpegTSWrite *ts = s->priv_data;
- if (ts->m2ts_mode) {
-- int64_t pcr = get_pcr(s->priv_data);
-- uint32_t tp_extra_header = pcr % 0x3fffffff;
-+ uint32_t tp_extra_header = get_pcr(ts, s->pb) % 0x3fffffff;
- tp_extra_header = AV_RB32(&tp_extra_header);
- avio_write(s->pb, (unsigned char *) &tp_extra_header,
- sizeof(tp_extra_header));
-@@ -1042,9 +1044,6 @@
- else
- ts_st->pcr_period = 1;
- }
--
-- // output a PCR as soon as possible
-- ts_st->last_pcr = ts->first_pcr - ts_st->pcr_period;
- }
-
- static void select_pcr_streams(AVFormatContext *s)
-@@ -1107,6 +1106,7 @@
-
- if (s->max_delay < 0) /* Not set by the caller */
- s->max_delay = 0;
-+ ts->delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
-
- // round up to a whole number of TS packets
- ts->pes_payload_size = (ts->pes_payload_size + 14 + 183) / 184 * 184 - 14;
-@@ -1166,7 +1166,9 @@
- /* MPEG pid values < 16 are reserved. Applications which set st->id in
- * this range are assigned a calculated pid. */
- if (st->id < 16) {
-- if (ts->m2ts_mode) {
-+ if (ts->start_pid >= 0)
-+ ts_st->pid = ts->start_pid + i;
-+ else if (ts->m2ts_mode) {
- switch (st->codecpar->codec_type) {
- case AVMEDIA_TYPE_VIDEO:
- ts_st->pid = ts->m2ts_video_pid++;
-@@ -1193,9 +1195,9 @@
- av_log(s, AV_LOG_ERROR, "Cannot automatically assign PID for stream %d\n", st->index);
- return AVERROR(EINVAL);
- }
-- } else {
-- ts_st->pid = ts->start_pid + i;
- }
-+ else
-+ ts_st->pid = START_PID + i;
- } else {
- ts_st->pid = st->id;
- }
-@@ -1263,9 +1265,14 @@
- ts->last_pat_ts = AV_NOPTS_VALUE;
- ts->last_sdt_ts = AV_NOPTS_VALUE;
- ts->last_nit_ts = AV_NOPTS_VALUE;
-- ts->pat_period = av_rescale(ts->pat_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-- ts->sdt_period = av_rescale(ts->sdt_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-- ts->nit_period = av_rescale(ts->nit_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->pat_period = ts->pat_period_us < 0 ? -1 :
-+ av_rescale(ts->pat_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->sdt_period = ts->sdt_period_us < 0 ? -1 :
-+ av_rescale(ts->sdt_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->nit_period = ts->nit_period_us < 0 ? -1 :
-+ av_rescale(ts->nit_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->pcr = 0;
-+ ts->pcr_pos = 0;
-
- /* assign provider name */
- provider = av_dict_get(s->metadata, "service_provider", NULL, 0);
-@@ -1281,8 +1288,8 @@
- av_log(s, AV_LOG_VERBOSE, "muxrate %d, ", ts->mux_rate);
- av_log(s, AV_LOG_VERBOSE,
- "sdt every %"PRId64" ms, pat/pmt every %"PRId64" ms",
-- av_rescale(ts->sdt_period, 1000, PCR_TIME_BASE),
-- av_rescale(ts->pat_period, 1000, PCR_TIME_BASE));
-+ ts->sdt_period < 0 ? -1 : av_rescale(ts->sdt_period, 1000, PCR_TIME_BASE),
-+ ts->pat_period < 0 ? -1 : av_rescale(ts->pat_period, 1000, PCR_TIME_BASE));
- if (ts->flags & MPEGTS_FLAG_NIT)
- av_log(s, AV_LOG_VERBOSE, ", nit every %"PRId64" ms", av_rescale(ts->nit_period, 1000, PCR_TIME_BASE));
- av_log(s, AV_LOG_VERBOSE, "\n");
-@@ -1291,36 +1298,40 @@
- }
-
- /* send SDT, NIT, PAT and PMT tables regularly */
--static void retransmit_si_info(AVFormatContext *s, int force_pat, int force_sdt, int force_nit, int64_t pcr)
-+static void retransmit_si_info(AVFormatContext *s, int force_pat, int force_sdt, int force_nit)
- {
- MpegTSWrite *ts = s->priv_data;
- int i;
-
-- if ((pcr != AV_NOPTS_VALUE && ts->last_sdt_ts == AV_NOPTS_VALUE) ||
-- (pcr != AV_NOPTS_VALUE && pcr - ts->last_sdt_ts >= ts->sdt_period) ||
-- force_sdt
-- ) {
-- if (pcr != AV_NOPTS_VALUE)
-- ts->last_sdt_ts = FFMAX(pcr, ts->last_sdt_ts);
-- mpegts_write_sdt(s);
-- }
-- if ((pcr != AV_NOPTS_VALUE && ts->last_pat_ts == AV_NOPTS_VALUE) ||
-- (pcr != AV_NOPTS_VALUE && pcr - ts->last_pat_ts >= ts->pat_period) ||
-- force_pat) {
-- if (pcr != AV_NOPTS_VALUE)
-- ts->last_pat_ts = FFMAX(pcr, ts->last_pat_ts);
-- mpegts_write_pat(s);
-- for (i = 0; i < ts->nb_services; i++)
-- mpegts_write_pmt(s, ts->services[i]);
-- }
-- if ((pcr != AV_NOPTS_VALUE && ts->last_nit_ts == AV_NOPTS_VALUE) ||
-- (pcr != AV_NOPTS_VALUE && pcr - ts->last_nit_ts >= ts->nit_period) ||
-- force_nit
-- ) {
-- if (pcr != AV_NOPTS_VALUE)
-- ts->last_nit_ts = FFMAX(pcr, ts->last_nit_ts);
-+ if (ts->sdt_period >= 0) {
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ if (ts->last_sdt_ts == AV_NOPTS_VALUE || pcr >= ts->last_sdt_ts + ts->sdt_period)
-+ force_sdt = 1;
-+ if (force_sdt) {
-+ ts->last_sdt_ts = pcr;
-+ mpegts_write_sdt(s);
-+ }
-+ }
-+ if (ts->pat_period >= 0) {
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ if (ts->last_pat_ts == AV_NOPTS_VALUE || pcr >= ts->last_pat_ts + ts->pat_period)
-+ force_pat = 1;
-+ if (force_pat) {
-+ ts->last_pat_ts = pcr;
-+ mpegts_write_pat(s);
-+ for (i = 0; i < ts->nb_services; i++)
-+ mpegts_write_pmt(s, ts->services[i]);
-+ }
-+ }
-+ if (ts->nit_period >= 0) {
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ if (ts->last_nit_ts == AV_NOPTS_VALUE || pcr >= ts->last_nit_ts + ts->nit_period)
-+ force_nit = 1;
-+ if (force_nit) {
-+ ts->last_nit_ts = pcr;
- if (ts->flags & MPEGTS_FLAG_NIT)
- mpegts_write_nit(s);
-+ }
- }
- }
-
-@@ -1357,25 +1368,29 @@
- static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st)
- {
- MpegTSWrite *ts = s->priv_data;
-- MpegTSWriteStream *ts_st = st->priv_data;
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ MpegTSWriteStream *ts_st = st ? st->priv_data : 0;
-+ uint32_t pcr_pid = ts_st ? ts_st->pid : ts->pcr_stream_pid;
- uint8_t *q;
- uint8_t buf[TS_PACKET_SIZE];
-
- q = buf;
- *q++ = 0x47;
-- *q++ = ts_st->pid >> 8;
-- *q++ = ts_st->pid;
-- *q++ = 0x20 | ts_st->cc; /* Adaptation only */
-+ *q++ = pcr_pid >> 8;
-+ *q++ = pcr_pid;
-+ uint32_t flags = 0x20; /* Adaptation only */
- /* Continuity Count field does not increment (see 13818-1 section 2.4.3.3) */
-+ if(ts_st) flags |= ts_st->cc;
-+ *q++ = flags;
- *q++ = TS_PACKET_SIZE - 5; /* Adaptation Field Length */
- *q++ = 0x10; /* Adaptation flags: PCR present */
-- if (ts_st->discontinuity) {
-+ if (ts_st && ts_st->discontinuity) {
- q[-1] |= 0x80;
- ts_st->discontinuity = 0;
- }
-
- /* PCR coded into 6 bytes */
-- q += write_pcr_bits(q, get_pcr(ts));
-+ q += write_pcr_bits(q, pcr);
-
- /* stuffing bytes */
- memset(q, 0xFF, TS_PACKET_SIZE - (q - buf));
-@@ -1475,9 +1490,9 @@
- int afc_len, stuffing_len;
- int is_dvb_subtitle = (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE);
- int is_dvb_teletext = (st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT);
-- int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
- int force_pat = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key;
- int force_sdt = 0;
-+ int64_t pcr;
- int force_nit = 0;
-
- av_assert0(ts_st->payload != buf || st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO);
-@@ -1494,21 +1509,19 @@
-
- is_start = 1;
- while (payload_size > 0) {
-- int64_t pcr = AV_NOPTS_VALUE;
-- if (ts->mux_rate > 1)
-- pcr = get_pcr(ts);
-- else if (dts != AV_NOPTS_VALUE)
-- pcr = (dts - delay) * 300;
--
-- retransmit_si_info(s, force_pat, force_sdt, force_nit, pcr);
-- force_pat = 0;
-- force_sdt = 0;
-- force_nit = 0;
-+ // add 11, pcr references the last byte of program clock reference base
-+ ts->pcr_pos = avio_tell(s->pb) + 11;
-+ pcr = ts->pcr = ts->mux_rate != 1 ?
-+ av_rescale(ts->pcr_pos, 8 * PCR_TIME_BASE, ts->mux_rate) :
-+ (dts == AV_NOPTS_VALUE ? 0 : (dts - ts->delay) * 300);
-+ if (force_pat || force_sdt || force_nit) {
-+ retransmit_si_info(s, force_pat, force_sdt, force_nit);
-+ force_pat = force_sdt = force_nit = 0;
-+ }
-
- write_pcr = 0;
- if (ts->mux_rate > 1) {
- /* Send PCR packets for all PCR streams if needed */
-- pcr = get_pcr(ts);
- if (pcr >= ts->next_pcr) {
- int64_t next_pcr = INT64_MAX;
- for (int i = 0; i < s->nb_streams; i++) {
-@@ -1518,36 +1531,43 @@
- AVStream *st2 = s->streams[st2_index];
- MpegTSWriteStream *ts_st2 = st2->priv_data;
- if (ts_st2->pcr_period) {
-- if (pcr - ts_st2->last_pcr >= ts_st2->pcr_period) {
-- ts_st2->last_pcr = FFMAX(pcr - ts_st2->pcr_period, ts_st2->last_pcr + ts_st2->pcr_period);
-- if (st2 != st) {
-+ if (pcr >= ts_st2->pcr_timer) {
-+ ts_st2->pcr_timer = pcr + ts_st2->pcr_period;
-+ if (st2 != st) {
- mpegts_insert_pcr_only(s, st2);
-- pcr = get_pcr(ts);
- } else {
- write_pcr = 1;
- }
- }
-- next_pcr = FFMIN(next_pcr, ts_st2->last_pcr + ts_st2->pcr_period);
-+ next_pcr = FFMIN(next_pcr, ts_st2->pcr_timer);
- }
- }
- ts->next_pcr = next_pcr;
- }
-- if (dts != AV_NOPTS_VALUE && (dts - pcr / 300) > delay) {
-- /* pcr insert gets priority over null packet insert */
-- if (write_pcr)
-- mpegts_insert_pcr_only(s, st);
-- else
-- mpegts_insert_null_packet(s);
-- /* recalculate write_pcr and possibly retransmit si_info */
-- continue;
-- }
-- } else if (ts_st->pcr_period && pcr != AV_NOPTS_VALUE) {
-- if (pcr - ts_st->last_pcr >= ts_st->pcr_period && is_start) {
-- ts_st->last_pcr = FFMAX(pcr - ts_st->pcr_period, ts_st->last_pcr + ts_st->pcr_period);
-+ }
-+ else if (ts_st->pcr_period) {
-+ if (pcr >= ts_st->pcr_timer) {
-+ ts_st->pcr_timer = pcr + ts_st->pcr_period;
- write_pcr = 1;
- }
- }
-
-+ if (write_pcr && ts->pcr_stream_pid >= 0) {
-+ mpegts_insert_pcr_only(s, 0);
-+ continue;
-+ }
-+
-+ if (ts->mux_rate > 1 && dts != AV_NOPTS_VALUE &&
-+ (dts - pcr / 300) > ts->delay) {
-+ /* pcr insert gets priority over null packet insert */
-+ if (write_pcr)
-+ mpegts_insert_pcr_only(s, st);
-+ else
-+ mpegts_insert_null_packet(s);
-+ /* recalculate write_pcr and possibly retransimit si_info */
-+ continue;
-+ }
-+
- /* prepare packet header */
- q = buf;
- *q++ = 0x47;
-@@ -1576,7 +1596,6 @@
- if (write_pcr) {
- set_af_flag(buf, 0x10);
- q = get_ts_payload_start(buf);
-- // add 11, pcr references the last byte of program clock reference base
- if (dts != AV_NOPTS_VALUE && dts < pcr / 300)
- av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n");
- extend_af(buf, write_pcr_bits(q, pcr));
-@@ -1840,8 +1859,8 @@
- uint8_t *data = NULL;
- MpegTSWrite *ts = s->priv_data;
- MpegTSWriteStream *ts_st = st->priv_data;
-- const int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE) * 2;
-- const int64_t max_audio_delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE) / 2;
-+ const int64_t delay_ticks2 = ts->delay * 2;
-+ const int64_t max_audio_delay = ts->delay / 2;
- int64_t dts = pkt->dts, pts = pkt->pts;
- int opus_samples = 0;
- size_t side_data_size;
-@@ -1861,9 +1880,9 @@
-
- if (ts->copyts < 1) {
- if (pts != AV_NOPTS_VALUE)
-- pts += delay;
-+ pts += delay_ticks2;
- if (dts != AV_NOPTS_VALUE)
-- dts += delay;
-+ dts += delay_ticks2;
- }
-
- if (!ts_st->first_timestamp_checked && (pts == AV_NOPTS_VALUE || dts == AV_NOPTS_VALUE)) {
-@@ -2262,8 +2281,10 @@
- 0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_HEVC_DIGITAL_HDTV }, 0x01, 0xff, ENC, "mpegts_service_type" },
- { "mpegts_pmt_start_pid", "Set the first pid of the PMT.",
- OFFSET(pmt_start_pid), AV_OPT_TYPE_INT, { .i64 = 0x1000 }, FIRST_OTHER_PID, LAST_OTHER_PID, ENC },
-+ { "mpegts_pcr_stream_pid", "create seperate PCR stream on this pid.",
-+ OFFSET(pcr_stream_pid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 0x1f00, ENC },
- { "mpegts_start_pid", "Set the first pid.",
-- OFFSET(start_pid), AV_OPT_TYPE_INT, { .i64 = 0x0100 }, FIRST_OTHER_PID, LAST_OTHER_PID, ENC },
-+ OFFSET(start_pid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, LAST_OTHER_PID, ENC },
- { "mpegts_m2ts_mode", "Enable m2ts mode.", OFFSET(m2ts_mode), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, ENC },
- { "muxrate", NULL, OFFSET(mux_rate), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, ENC },
- { "pes_payload_size", "Minimum PES packet payload in bytes",
-@@ -2287,10 +2308,10 @@
- OFFSET(omit_video_pes_length), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
- { "pcr_period", "PCR retransmission time in milliseconds",
- OFFSET(pcr_period_ms), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, ENC },
-- { "pat_period", "PAT/PMT retransmission time limit in seconds",
-+ { "pat_period", "PAT/PMT retransmission time limit in ms, -1 no pat",
- OFFSET(pat_period_us), AV_OPT_TYPE_DURATION, { .i64 = PAT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
-- { "sdt_period", "SDT retransmission time limit in seconds",
-- OFFSET(sdt_period_us), AV_OPT_TYPE_DURATION, { .i64 = SDT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
-+ { "sdt_period", "SDT retransmission time limit in ms, -1 no sdt",
-+ OFFSET(sdt_period_us), AV_OPT_TYPE_INT64, { .i64 = SDT_RETRANS_TIME * 1000LL }, -1, INT64_MAX, ENC },
- { "nit_period", "NIT retransmission time limit in seconds",
- OFFSET(nit_period_us), AV_OPT_TYPE_DURATION, { .i64 = NIT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
- { NULL },
---- a/libavformat/mpegts.h
-+++ b/libavformat/mpegts.h
-@@ -64,6 +64,7 @@
- /* PID from 0x1FFC to 0x1FFE may be assigned as needed to PMT, elementary
- * streams and other data tables */
- #define NULL_PID 0x1FFF /* Null packet (used for fixed bandwidth padding) */
-+#define START_PID 0x0400
-
- /* m2ts pids */
- #define M2TS_PMT_PID 0x0100
---- a/libavformat/bluray.c
-+++ b/libavformat/bluray.c
-@@ -28,7 +28,7 @@
- #include "libavutil/opt.h"
-
- #define BLURAY_PROTO_PREFIX "bluray:"
--#define MIN_PLAYLIST_LENGTH 180 /* 3 min */
-+#define MIN_PLAYLIST_LENGTH 0
-
- typedef struct {
- const AVClass *class;
---- a/doc/muxers.texi
-+++ b/doc/muxers.texi
-@@ -1934,7 +1934,8 @@
- Maximum time in seconds between PAT/PMT tables. Default is @code{0.1}.
-
- @item sdt_period @var{duration}
--Maximum time in seconds between SDT tables. Default is @code{0.5}.
-+Maximum time in seconds between SDT tables. Default is @code{0.5}. Regardless
-+of this setting no SDT is written in m2ts mode.
-
- @item nit_period @var{duration}
- Maximum time in seconds between NIT tables. Default is @code{0.5}.
+++ /dev/null
---- a/libavformat/avformat.h
-+++ b/libavformat/avformat.h
-@@ -499,6 +499,9 @@
- The user or muxer can override this through
- AVFormatContext.avoid_negative_ts
- */
-+#define AVFMT_SEEK_NOSTREAMS 0x80000 /**< Stream index ignored by seek,
-+ or some streams fail to seek
-+ */
-
- #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */
-
-@@ -670,7 +673,8 @@
- /**
- * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
- * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
-- * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
-+ * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS,
-+ * AVFMT_SEEK_NOSTREAMS
- */
- int flags;
-
---- a/libavformat/dv.c
-+++ b/libavformat/dv.c
-@@ -640,6 +640,7 @@
- const AVInputFormat ff_dv_demuxer = {
- .name = "dv",
- .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .priv_data_size = sizeof(RawDVContext),
- .read_probe = dv_probe,
- .read_header = dv_read_header,
---- a/libavformat/matroskadec.c
-+++ b/libavformat/matroskadec.c
-@@ -4427,6 +4427,7 @@
- const AVInputFormat ff_webm_dash_manifest_demuxer = {
- .name = "webm_dash_manifest",
- .long_name = NULL_IF_CONFIG_SMALL("WebM DASH Manifest"),
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .priv_class = &webm_dash_class,
- .priv_data_size = sizeof(MatroskaDemuxContext),
- .flags_internal = FF_FMT_INIT_CLEANUP,
-@@ -4439,6 +4440,7 @@
- const AVInputFormat ff_matroska_demuxer = {
- .name = "matroska,webm",
- .long_name = NULL_IF_CONFIG_SMALL("Matroska / WebM"),
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .extensions = "mkv,mk3d,mka,mks,webm",
- .priv_data_size = sizeof(MatroskaDemuxContext),
- .flags_internal = FF_FMT_INIT_CLEANUP,
---- a/libavformat/seek.c
-+++ b/libavformat/seek.c
-@@ -600,6 +600,13 @@
- return seek_frame_byte(s, stream_index, timestamp, flags);
- }
-
-+ if (stream_index != -1 && (s->iformat->flags & AVFMT_SEEK_NOSTREAMS)) {
-+ timestamp = av_rescale_q(timestamp,
-+ s->streams[stream_index]->time_base,
-+ AV_TIME_BASE_Q);
-+ stream_index = -1;
-+ }
-+
- if (stream_index < 0) {
- stream_index = av_find_default_stream_index(s);
- if (stream_index < 0)
+++ /dev/null
---- a/libavformat/avidec.c
-+++ b/libavformat/avidec.c
-@@ -1995,6 +1995,7 @@
- .priv_data_size = sizeof(AVIContext),
- .flags_internal = FF_FMT_INIT_CLEANUP,
- .extensions = "avi",
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .read_probe = avi_probe,
- .read_header = avi_read_header,
- .read_packet = avi_read_packet,
+++ /dev/null
---- a/libavfilter/formats.c
-+++ b/libavfilter/formats.c
-@@ -110,11 +110,13 @@
- possibly causing a lossy conversion elsewhere in the graph.
- To avoid that, pretend that there are no common formats to force the
- insertion of a conversion filter. */
-- if (type == AVMEDIA_TYPE_VIDEO)
-+ if (type == AVMEDIA_TYPE_VIDEO) {
- for (i = 0; i < a->nb_formats; i++) {
- const AVPixFmtDescriptor *const adesc = av_pix_fmt_desc_get(a->formats[i]);
-+ if( !adesc ) continue;
- for (j = 0; j < b->nb_formats; j++) {
- const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
-+ if( !bdesc ) continue;
- alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
- chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
- if (a->formats[i] == b->formats[j]) {
-@@ -123,6 +125,7 @@
- }
- }
- }
-+ }
-
- // If chroma or alpha can be lost through merging then do not merge
- if (alpha2 > alpha1 || chroma2 > chroma1)
+++ /dev/null
-X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/blobdiff_plain/30bd4831e6213cee64ed950d69d1732194cc6464..6f53f0d09ea4c9c7f7354f018a87ef840315207d:/libavformat/mov.c
-
-diff --git a/libavformat/mov.c b/libavformat/mov.c
-index a644f9ac62..2b1131b911 100644
---- a/libavformat/mov.c
-+++ b/libavformat/mov.c
-@@ -3949,8 +3949,11 @@ static int build_open_gop_key_points(AVStream *st)
-
- /* Build an unrolled index of the samples */
- sc->sample_offsets_count = 0;
-- for (uint32_t i = 0; i < sc->ctts_count; i++)
-+ for (uint32_t i = 0; i < sc->ctts_count; i++) {
-+ if (sc->ctts_data[i].count > INT_MAX - sc->sample_offsets_count)
-+ return AVERROR(ENOMEM);
- sc->sample_offsets_count += sc->ctts_data[i].count;
-+ }
- av_freep(&sc->sample_offsets);
- sc->sample_offsets = av_calloc(sc->sample_offsets_count, sizeof(*sc->sample_offsets));
- if (!sc->sample_offsets)
-@@ -3969,8 +3972,11 @@ static int build_open_gop_key_points(AVStream *st)
- /* Build a list of open-GOP key samples */
- sc->open_key_samples_count = 0;
- for (uint32_t i = 0; i < sc->sync_group_count; i++)
-- if (sc->sync_group[i].index == cra_index)
-+ if (sc->sync_group[i].index == cra_index) {
-+ if (sc->sync_group[i].count > INT_MAX - sc->open_key_samples_count)
-+ return AVERROR(ENOMEM);
- sc->open_key_samples_count += sc->sync_group[i].count;
-+ }
- av_freep(&sc->open_key_samples);
- sc->open_key_samples = av_calloc(sc->open_key_samples_count, sizeof(*sc->open_key_samples));
- if (!sc->open_key_samples)
-@@ -3981,6 +3987,8 @@ static int build_open_gop_key_points(AVStream *st)
- if (sg->index == cra_index)
- for (uint32_t j = 0; j < sg->count; j++)
- sc->open_key_samples[k++] = sample_id;
-+ if (sg->count > INT_MAX - sample_id)
-+ return AVERROR_PATCHWELCOME;
- sample_id += sg->count;
- }
-
+++ /dev/null
---- a/libavcodec/vdpau_mpeg12.c
-+++ a/libavcodec/vdpau_mpeg12.c
-@@ -116,6 +116,7 @@
- .frame_priv_data_size = sizeof(struct vdpau_picture_context),
- .init = vdpau_mpeg1_init,
- .uninit = ff_vdpau_common_uninit,
-+ .frame_params = ff_vdpau_common_frame_params,
- .priv_data_size = sizeof(VDPAUContext),
- .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
- };
+++ /dev/null
---- a/libavcodec/h263dec.c
-+++ b/libavcodec/h263dec.c
-@@ -685,7 +685,7 @@
- if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
- ff_mpeg4_frame_end(avctx, buf, buf_size);
-
-- if (!s->divx_packed && avctx->hwaccel)
-+ if (s->divx_packed && avctx->hwaccel)
- ff_thread_finish_setup(avctx);
-
- av_assert1(s->current_picture.f->pict_type == s->current_picture_ptr->f->pict_type);
+++ /dev/null
---- a/libavformat/mpegenc.c
-+++ b/libavformat/mpegenc.c
-@@ -976,9 +976,9 @@
- PacketDesc *pkt_desc;
-
- while ((pkt_desc = stream->predecode_packet) &&
-+ pkt_desc != stream->premux_packet &&
- scr > pkt_desc->dts) { // FIXME: > vs >=
-- if (stream->buffer_index < pkt_desc->size ||
-- stream->predecode_packet == stream->premux_packet) {
-+ if (stream->buffer_index < pkt_desc->size) {
- av_log(ctx, AV_LOG_ERROR,
- "buffer underflow st=%d bufi=%d size=%d\n",
- i, stream->buffer_index, pkt_desc->size);
+++ /dev/null
-X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/blobdiff_plain/ccc684993276248d64c328a810fb7714af2f4c70..effadce6c756247ea8bae32dc13bb3e6f464f0eb:/libavcodec/x86/mathops.h
-
-diff --git a/libavcodec/x86/mathops.h b/libavcodec/x86/mathops.h
-index 6298f5ed19..ca7e2dffc1 100644
---- a/libavcodec/x86/mathops.h
-+++ b/libavcodec/x86/mathops.h
-@@ -35,12 +35,20 @@
- static av_always_inline av_const int MULL(int a, int b, unsigned shift)
- {
- int rt, dummy;
-+ if (__builtin_constant_p(shift))
- __asm__ (
- "imull %3 \n\t"
- "shrdl %4, %%edx, %%eax \n\t"
- :"=a"(rt), "=d"(dummy)
-- :"a"(a), "rm"(b), "ci"((uint8_t)shift)
-+ :"a"(a), "rm"(b), "i"(shift & 0x1F)
- );
-+ else
-+ __asm__ (
-+ "imull %3 \n\t"
-+ "shrdl %4, %%edx, %%eax \n\t"
-+ :"=a"(rt), "=d"(dummy)
-+ :"a"(a), "rm"(b), "c"((uint8_t)shift)
-+ );
- return rt;
- }
-
-@@ -113,19 +121,31 @@ __asm__ volatile(\
- // avoid +32 for shift optimization (gcc should do that ...)
- #define NEG_SSR32 NEG_SSR32
- static inline int32_t NEG_SSR32( int32_t a, int8_t s){
-+ if (__builtin_constant_p(s))
- __asm__ ("sarl %1, %0\n\t"
- : "+r" (a)
-- : "ic" ((uint8_t)(-s))
-+ : "i" (-s & 0x1F)
- );
-+ else
-+ __asm__ ("sarl %1, %0\n\t"
-+ : "+r" (a)
-+ : "c" ((uint8_t)(-s))
-+ );
- return a;
- }
-
- #define NEG_USR32 NEG_USR32
- static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
-+ if (__builtin_constant_p(s))
- __asm__ ("shrl %1, %0\n\t"
- : "+r" (a)
-- : "ic" ((uint8_t)(-s))
-+ : "i" (-s & 0x1F)
- );
-+ else
-+ __asm__ ("shrl %1, %0\n\t"
-+ : "+r" (a)
-+ : "c" ((uint8_t)(-s))
-+ );
- return a;
- }
-
+++ /dev/null
---- a/libavutil/hwcontext_vdpau.c
-+++ b/libavutil/hwcontext_vdpau.c
-@@ -47,6 +47,11 @@
- { 0, AV_PIX_FMT_NONE, },
- };
-
-+static const VDPAUPixFmtMap pix_fmts_420j[] = {
-+ { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUVJ420P },
-+ { 0, AV_PIX_FMT_NONE, },
-+};
-+
- static const VDPAUPixFmtMap pix_fmts_422[] = {
- { VDP_YCBCR_FORMAT_NV12, AV_PIX_FMT_NV16 },
- { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUV422P },
-@@ -71,6 +76,7 @@
- const VDPAUPixFmtMap *map;
- } vdpau_pix_fmts[] = {
- { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUV420P, pix_fmts_420 },
-+ { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUVJ420P, pix_fmts_420j },
- { VDP_CHROMA_TYPE_422, AV_PIX_FMT_YUV422P, pix_fmts_422 },
- { VDP_CHROMA_TYPE_444, AV_PIX_FMT_YUV444P, pix_fmts_444 },
- #ifdef VDP_YCBCR_FORMAT_P016
+++ /dev/null
---- a/libavcodec/encode.c
-+++ b/libavcodec/encode.c
-@@ -191,7 +191,7 @@
- }
-
- if (!frame->buf[0]) {
-- if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
-+ if (avci->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
- (avci->frame_thread_encoder && avctx->active_thread_type & FF_THREAD_FRAME)))
- return AVERROR_EOF;
-
-@@ -243,8 +243,10 @@
- avpkt->flags |= avci->intra_only_flag;
- }
-
-- if (avci->draining && !got_packet)
-+ if (avci->draining && !got_packet) {
-+ fflush(stderr);
- avci->draining_done = 1;
-+ }
-
- end:
- if (ret < 0 || !got_packet)
-@@ -365,10 +367,16 @@
- if (avci->draining)
- return AVERROR_EOF;
-
-- if (avci->buffer_frame->buf[0])
-+ if (avci->buffer_frame->buf[0]) {
-+ if (!frame) {
-+ fflush(stderr);
-+ av_frame_unref(avci->buffer_frame);
-+ }
- return AVERROR(EAGAIN);
-+ }
-
- if (!frame) {
-+ fflush(stderr);
- avci->draining = 1;
- } else {
- ret = encode_send_frame_internal(avctx, frame);
+++ /dev/null
-From c13d95934327ddad4db30f6aee93cd2aa6a26a57 Mon Sep 17 00:00:00 2001
-From: OvchinnikovDmitrii <ovchinnikov.dmitrii@gmail.com>
-Date: Thu, 6 Oct 2022 15:49:59 +0200
-Subject: [PATCH 1/1] lavc/libvpx: increase thread limit to 64
-
-This change improves the performance and multicore scalability of the vp9
-codec for streaming single-pass encoded videos by taking advantage of up
-to 64 cores in the system. The current thread limit for ffmpeg codecs is 16
-(MAX_AUTO_THREADS in pthread_internal.h) due to a limitation in H.264 codec
-that prevents more than 16 threads being used.
-
-Experiments show that increasing the thread limit to 64 for vp9 improves
-the performance for encoding 4K raw videos for streaming by up to 47%
-compared to 16 threads, and from 20-30% for 32 threads, with the same quality
-as measured by the VMAF score.
-
-Rationale for this change:
-Vp9 uses tiling to split the video frame into multiple columns; tiles must
-be at least 256 pixels wide, so there is a limit to how many tiles can be
-used. The tiles can be processed in parallel, and more tiles mean more CPU
-threads can be used. 4K videos can make use of 16 threads, and 8K videos
-can use 32. Row-mt can double the number of threads so 64 threads can be used.
-
-Signed-off-by: James Zern <jzern@google.com>
----
- libavcodec/libvpx.h | 2 ++
- libavcodec/libvpxdec.c | 2 +-
- libavcodec/libvpxenc.c | 2 +-
- 3 files changed, 4 insertions(+), 2 deletions(-)
-
-diff --git a/libavcodec/libvpx.h b/libavcodec/libvpx.h
-index 0caed8cdcb..331feb8745 100644
---- a/libavcodec/libvpx.h
-+++ b/libavcodec/libvpx.h
-@@ -25,6 +25,8 @@
-
- #include "codec_internal.h"
-
-+#define MAX_VPX_THREADS 64
-+
- void ff_vp9_init_static(FFCodec *codec);
- #if 0
- enum AVPixelFormat ff_vpx_imgfmt_to_pixfmt(vpx_img_fmt_t img);
-diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
-index 9cd2c56caf..0ae19c3f72 100644
---- a/libavcodec/libvpxdec.c
-+++ b/libavcodec/libvpxdec.c
-@@ -88,7 +88,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
- const struct vpx_codec_iface *iface)
- {
- struct vpx_codec_dec_cfg deccfg = {
-- .threads = FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16)
-+ .threads = FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), MAX_VPX_THREADS)
- };
-
- av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
-diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
-index 9aa5510c28..339d4d8146 100644
---- a/libavcodec/libvpxenc.c
-+++ b/libavcodec/libvpxenc.c
-@@ -942,7 +942,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
- enccfg.g_timebase.num = avctx->time_base.num;
- enccfg.g_timebase.den = avctx->time_base.den;
- enccfg.g_threads =
-- FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16);
-+ FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), MAX_VPX_THREADS);
- enccfg.g_lag_in_frames= ctx->lag_in_frames;
-
- if (avctx->flags & AV_CODEC_FLAG_PASS1)
---
-2.25.1
-
+++ /dev/null
-From: Lynne <dev@lynne.ee>
-Date: Sun, 25 Dec 2022 00:03:30 +0000 (+0100)
-Subject: hwcontext_vulkan: remove optional encode/decode extensions from the list
-X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/commitdiff_plain/7268323193d55365f914de39fadd5dbdb1f68976?hp=30d432f205538f6ef6c86ed0a90e27cdd735cd2b
-
-hwcontext_vulkan: remove optional encode/decode extensions from the list
-
-They're not currently used, so they don't need to be there.
-Vulkan stabilized the decode extensions less than a week ago, and their
-name prefixes were changed from EXT to KHR. It's a bit too soon to be
-depending on it, so rather than bumping, just remove these for now.
-
-(cherry picked from commit eb0455d64690eed0068e5cb202f72ecdf899837c)
----
-
-diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
-index 237caa4bc0..3bc0dc8a40 100644
---- a/libavutil/hwcontext_vulkan.c
-+++ b/libavutil/hwcontext_vulkan.c
-@@ -354,14 +354,6 @@ static const VulkanOptExtension optional_device_exts[] = {
- { VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, FF_VK_EXT_EXTERNAL_WIN32_MEMORY },
- { VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME, FF_VK_EXT_EXTERNAL_WIN32_SEM },
- #endif
--
-- /* Video encoding/decoding */
-- { VK_KHR_VIDEO_QUEUE_EXTENSION_NAME, FF_VK_EXT_NO_FLAG },
-- { VK_KHR_VIDEO_DECODE_QUEUE_EXTENSION_NAME, FF_VK_EXT_NO_FLAG },
-- { VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME, FF_VK_EXT_NO_FLAG },
-- { VK_EXT_VIDEO_ENCODE_H264_EXTENSION_NAME, FF_VK_EXT_NO_FLAG },
-- { VK_EXT_VIDEO_DECODE_H264_EXTENSION_NAME, FF_VK_EXT_NO_FLAG },
-- { VK_EXT_VIDEO_DECODE_H265_EXTENSION_NAME, FF_VK_EXT_NO_FLAG },
- };
-
- /* Converts return values to strings */
+++ /dev/null
---- a/libavcodec/wrapped_avframe.c
-+++ b/libavcodec/wrapped_avframe.c
-@@ -33,6 +33,38 @@
- #include "libavutil/buffer.h"
- #include "libavutil/pixdesc.h"
-
-+
-+
-+static const enum AVPixelFormat pix_fmts_all[] = {
-+ AV_PIX_FMT_YUV411P,
-+ AV_PIX_FMT_YUV420P,
-+ AV_PIX_FMT_YUVJ420P,
-+ AV_PIX_FMT_YUV422P,
-+ AV_PIX_FMT_YUVJ422P,
-+ AV_PIX_FMT_YUV444P,
-+ AV_PIX_FMT_YUVJ444P,
-+ AV_PIX_FMT_YUV420P10,
-+ AV_PIX_FMT_YUV422P10,
-+ AV_PIX_FMT_YUV444P10,
-+ AV_PIX_FMT_YUV420P12,
-+ AV_PIX_FMT_YUV422P12,
-+ AV_PIX_FMT_YUV444P12,
-+ AV_PIX_FMT_YUV420P14,
-+ AV_PIX_FMT_YUV422P14,
-+ AV_PIX_FMT_YUV444P14,
-+ AV_PIX_FMT_YUV420P16,
-+ AV_PIX_FMT_YUV422P16,
-+ AV_PIX_FMT_YUV444P16,
-+ AV_PIX_FMT_GRAY8,
-+ AV_PIX_FMT_GRAY9,
-+ AV_PIX_FMT_GRAY10,
-+ AV_PIX_FMT_GRAY12,
-+ AV_PIX_FMT_GRAY16,
-+ AV_PIX_FMT_NONE
-+};
-+
-+
-+
- static void wrapped_avframe_release_buffer(void *unused, uint8_t *data)
- {
- AVFrame *frame = (AVFrame *)data;
-@@ -109,6 +141,7 @@
- .p.id = AV_CODEC_ID_WRAPPED_AVFRAME,
- FF_CODEC_ENCODE_CB(wrapped_avframe_encode),
- .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
-+ .p.pix_fmts = pix_fmts_all,
- };
-
- const FFCodec ff_wrapped_avframe_decoder = {
-@@ -118,4 +151,5 @@
- .p.id = AV_CODEC_ID_WRAPPED_AVFRAME,
- FF_CODEC_DECODE_CB(wrapped_avframe_decode),
- .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
-+
- };
+++ /dev/null
---- a/libavformat/yuv4mpegenc.c
-+++ b/libavformat/yuv4mpegenc.c
-@@ -259,7 +259,7 @@
- av_log(s, AV_LOG_ERROR, "'%s' is not an official yuv4mpegpipe pixel format. "
- "Use '-strict -1' to encode to this pixel format.\n",
- av_get_pix_fmt_name(s->streams[0]->codecpar->format));
-- return AVERROR(EINVAL);
-+ //return AVERROR(EINVAL);
- }
- av_log(s, AV_LOG_WARNING, "Warning: generating non standard YUV stream. "
- "Mjpegtools will not work.\n");
+++ /dev/null
---- a/libavcodec/aaccoder.c
-+++ b/libavcodec/aaccoder.c
-@@ -60,6 +60,8 @@
- * replace low energy non zero bands */
- #define NOISE_LAMBDA_REPLACE 1.948f
-
-+#undef B0
-+
- #include "libavcodec/aaccoder_trellis.h"
-
- typedef float (*quantize_and_encode_band_func)(struct AACEncContext *s, PutBitContext *pb,
-
---- a/libavcodec/hevc_mvs.c
-+++ b/libavcodec/hevc_mvs.c
-@@ -25,6 +25,8 @@
- #include "hevcdec.h"
- #include "threadframe.h"
-
-+#undef B0
-+
- static const uint8_t l0_l1_cand_idx[12][2] = {
- { 0, 1, },
- { 1, 0, },
---- a/libavcodec/opus_pvq.c
-+++ b/libavcodec/opus_pvq.c
-@@ -36,6 +36,8 @@
- #define CELT_PVQ_U(n, k) (ff_celt_pvq_u_row[FFMIN(n, k)][FFMAX(n, k)])
- #define CELT_PVQ_V(n, k) (CELT_PVQ_U(n, k) + CELT_PVQ_U(n, (k) + 1))
-
-+#undef B0
-+
- static inline int16_t celt_cos(int16_t x)
- {
- x = (MUL16(x, x) + 4096) >> 13;
+++ /dev/null
---- a/fftools/cmdutils.c
-+++ b/fftools/cmdutils.c
-@@ -59,7 +59,7 @@
- AVDictionary *swr_opts;
- AVDictionary *format_opts, *codec_opts;
-
--int hide_banner = 0;
-+int hide_banner = 1;
-
- void uninit_opts(void)
- {
+++ /dev/null
---- a/libavutil/hwcontext_cuda.c.orig 2023-11-11 03:25:17.000000000 +0300
-+++ b/libavutil/hwcontext_cuda.c 2023-11-12 17:52:01.243063419 +0300
-@@ -361,11 +361,13 @@
- hwctx->internal->cuda_device));
- if (ret < 0)
- return ret;
-+#if 0
- } else if (flags & AV_CUDA_USE_CURRENT_CONTEXT) {
- ret = CHECK_CU(cu->cuCtxGetCurrent(&hwctx->cuda_ctx));
- if (ret < 0)
- return ret;
- av_log(device_ctx, AV_LOG_INFO, "Using current CUDA context.\n");
-+#endif
- } else {
- ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
- hwctx->internal->cuda_device));
+++ /dev/null
---- a/libavformat/mpegtsenc.c
-+++ b/libavformat/mpegtsenc.c
-@@ -87,9 +87,11 @@
- int64_t pat_period; /* PAT/PMT period in PCR time base */
- int64_t nit_period; /* NIT period in PCR time base */
- int nb_services;
-- int64_t first_pcr;
- int first_dts_checked;
-- int64_t next_pcr;
-+ int64_t pcr_pos, pcr;
-+ int64_t first_pcr, next_pcr;
-+ int64_t delay;
-+ int pcr_stream_pid;
- int mux_rate; ///< set to 1 when VBR
- int pes_payload_size;
- int64_t total_size;
-@@ -256,7 +258,7 @@
- int data_st_warning;
-
- int64_t pcr_period; /* PCR period in PCR time base */
-- int64_t last_pcr;
-+ int64_t pcr_timer;
-
- /* For Opus */
- int opus_queued_samples;
-@@ -954,18 +956,18 @@
- return 0;
- }
-
--static int64_t get_pcr(const MpegTSWrite *ts)
-+static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb)
- {
-- return av_rescale(ts->total_size + 11, 8 * PCR_TIME_BASE, ts->mux_rate) +
-- ts->first_pcr;
-+ int64_t pos = avio_tell(pb) + 11;
-+ return ts->pcr + (ts->mux_rate == 1 ? (pos - ts->pcr_pos) * 8 :
-+ av_rescale(pos - ts->pcr_pos, 8 * PCR_TIME_BASE, ts->mux_rate));
- }
-
- static void write_packet(AVFormatContext *s, const uint8_t *packet)
- {
- MpegTSWrite *ts = s->priv_data;
- if (ts->m2ts_mode) {
-- int64_t pcr = get_pcr(s->priv_data);
-- uint32_t tp_extra_header = pcr % 0x3fffffff;
-+ uint32_t tp_extra_header = get_pcr(ts, s->pb) % 0x3fffffff;
- tp_extra_header = AV_RB32(&tp_extra_header);
- avio_write(s->pb, (unsigned char *) &tp_extra_header,
- sizeof(tp_extra_header));
-@@ -1051,9 +1053,6 @@
- else
- ts_st->pcr_period = 1;
- }
--
-- // output a PCR as soon as possible
-- ts_st->last_pcr = ts->first_pcr - ts_st->pcr_period;
- }
-
- static void select_pcr_streams(AVFormatContext *s)
-@@ -1116,6 +1115,7 @@
-
- if (s->max_delay < 0) /* Not set by the caller */
- s->max_delay = 0;
-+ ts->delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
-
- // round up to a whole number of TS packets
- ts->pes_payload_size = (ts->pes_payload_size + 14 + 183) / 184 * 184 - 14;
-@@ -1175,7 +1175,9 @@
- /* MPEG pid values < 16 are reserved. Applications which set st->id in
- * this range are assigned a calculated pid. */
- if (st->id < 16) {
-- if (ts->m2ts_mode) {
-+ if (ts->start_pid >= 0)
-+ ts_st->pid = ts->start_pid + i;
-+ else if (ts->m2ts_mode) {
- switch (st->codecpar->codec_type) {
- case AVMEDIA_TYPE_VIDEO:
- ts_st->pid = ts->m2ts_video_pid++;
-@@ -1202,9 +1204,9 @@
- av_log(s, AV_LOG_ERROR, "Cannot automatically assign PID for stream %d\n", st->index);
- return AVERROR(EINVAL);
- }
-- } else {
-- ts_st->pid = ts->start_pid + i;
- }
-+ else
-+ ts_st->pid = START_PID + i;
- } else {
- ts_st->pid = st->id;
- }
-@@ -1272,9 +1274,14 @@
- ts->last_pat_ts = AV_NOPTS_VALUE;
- ts->last_sdt_ts = AV_NOPTS_VALUE;
- ts->last_nit_ts = AV_NOPTS_VALUE;
-- ts->pat_period = av_rescale(ts->pat_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-- ts->sdt_period = av_rescale(ts->sdt_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-- ts->nit_period = av_rescale(ts->nit_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->pat_period = ts->pat_period_us < 0 ? -1 :
-+ av_rescale(ts->pat_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->sdt_period = ts->sdt_period_us < 0 ? -1 :
-+ av_rescale(ts->sdt_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->nit_period = ts->nit_period_us < 0 ? -1 :
-+ av_rescale(ts->nit_period_us, PCR_TIME_BASE, AV_TIME_BASE);
-+ ts->pcr = 0;
-+ ts->pcr_pos = 0;
-
- /* assign provider name */
- provider = av_dict_get(s->metadata, "service_provider", NULL, 0);
-@@ -1290,8 +1297,8 @@
- av_log(s, AV_LOG_VERBOSE, "muxrate %d, ", ts->mux_rate);
- av_log(s, AV_LOG_VERBOSE,
- "sdt every %"PRId64" ms, pat/pmt every %"PRId64" ms",
-- av_rescale(ts->sdt_period, 1000, PCR_TIME_BASE),
-- av_rescale(ts->pat_period, 1000, PCR_TIME_BASE));
-+ ts->sdt_period < 0 ? -1 : av_rescale(ts->sdt_period, 1000, PCR_TIME_BASE),
-+ ts->pat_period < 0 ? -1 : av_rescale(ts->pat_period, 1000, PCR_TIME_BASE));
- if (ts->flags & MPEGTS_FLAG_NIT)
- av_log(s, AV_LOG_VERBOSE, ", nit every %"PRId64" ms", av_rescale(ts->nit_period, 1000, PCR_TIME_BASE));
- av_log(s, AV_LOG_VERBOSE, "\n");
-@@ -1300,36 +1307,40 @@
- }
-
- /* send SDT, NIT, PAT and PMT tables regularly */
--static void retransmit_si_info(AVFormatContext *s, int force_pat, int force_sdt, int force_nit, int64_t pcr)
-+static void retransmit_si_info(AVFormatContext *s, int force_pat, int force_sdt, int force_nit)
- {
- MpegTSWrite *ts = s->priv_data;
- int i;
-
-- if ((pcr != AV_NOPTS_VALUE && ts->last_sdt_ts == AV_NOPTS_VALUE) ||
-- (pcr != AV_NOPTS_VALUE && pcr - ts->last_sdt_ts >= ts->sdt_period) ||
-- force_sdt
-- ) {
-- if (pcr != AV_NOPTS_VALUE)
-- ts->last_sdt_ts = FFMAX(pcr, ts->last_sdt_ts);
-- mpegts_write_sdt(s);
-- }
-- if ((pcr != AV_NOPTS_VALUE && ts->last_pat_ts == AV_NOPTS_VALUE) ||
-- (pcr != AV_NOPTS_VALUE && pcr - ts->last_pat_ts >= ts->pat_period) ||
-- force_pat) {
-- if (pcr != AV_NOPTS_VALUE)
-- ts->last_pat_ts = FFMAX(pcr, ts->last_pat_ts);
-- mpegts_write_pat(s);
-- for (i = 0; i < ts->nb_services; i++)
-- mpegts_write_pmt(s, ts->services[i]);
-- }
-- if ((pcr != AV_NOPTS_VALUE && ts->last_nit_ts == AV_NOPTS_VALUE) ||
-- (pcr != AV_NOPTS_VALUE && pcr - ts->last_nit_ts >= ts->nit_period) ||
-- force_nit
-- ) {
-- if (pcr != AV_NOPTS_VALUE)
-- ts->last_nit_ts = FFMAX(pcr, ts->last_nit_ts);
-+ if (ts->sdt_period >= 0) {
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ if (ts->last_sdt_ts == AV_NOPTS_VALUE || pcr >= ts->last_sdt_ts + ts->sdt_period)
-+ force_sdt = 1;
-+ if (force_sdt) {
-+ ts->last_sdt_ts = pcr;
-+ mpegts_write_sdt(s);
-+ }
-+ }
-+ if (ts->pat_period >= 0) {
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ if (ts->last_pat_ts == AV_NOPTS_VALUE || pcr >= ts->last_pat_ts + ts->pat_period)
-+ force_pat = 1;
-+ if (force_pat) {
-+ ts->last_pat_ts = pcr;
-+ mpegts_write_pat(s);
-+ for (i = 0; i < ts->nb_services; i++)
-+ mpegts_write_pmt(s, ts->services[i]);
-+ }
-+ }
-+ if (ts->nit_period >= 0) {
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ if (ts->last_nit_ts == AV_NOPTS_VALUE || pcr >= ts->last_nit_ts + ts->nit_period)
-+ force_nit = 1;
-+ if (force_nit) {
-+ ts->last_nit_ts = pcr;
- if (ts->flags & MPEGTS_FLAG_NIT)
- mpegts_write_nit(s);
-+ }
- }
- }
-
-@@ -1366,25 +1377,29 @@
- static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st)
- {
- MpegTSWrite *ts = s->priv_data;
-- MpegTSWriteStream *ts_st = st->priv_data;
-+ int64_t pcr = get_pcr(ts, s->pb);
-+ MpegTSWriteStream *ts_st = st ? st->priv_data : 0;
-+ uint32_t pcr_pid = ts_st ? ts_st->pid : ts->pcr_stream_pid;
- uint8_t *q;
- uint8_t buf[TS_PACKET_SIZE];
-
- q = buf;
- *q++ = 0x47;
-- *q++ = ts_st->pid >> 8;
-- *q++ = ts_st->pid;
-- *q++ = 0x20 | ts_st->cc; /* Adaptation only */
-+ *q++ = pcr_pid >> 8;
-+ *q++ = pcr_pid;
-+ uint32_t flags = 0x20; /* Adaptation only */
- /* Continuity Count field does not increment (see 13818-1 section 2.4.3.3) */
-+ if(ts_st) flags |= ts_st->cc;
-+ *q++ = flags;
- *q++ = TS_PACKET_SIZE - 5; /* Adaptation Field Length */
- *q++ = 0x10; /* Adaptation flags: PCR present */
-- if (ts_st->discontinuity) {
-+ if (ts_st && ts_st->discontinuity) {
- q[-1] |= 0x80;
- ts_st->discontinuity = 0;
- }
-
- /* PCR coded into 6 bytes */
-- q += write_pcr_bits(q, get_pcr(ts));
-+ q += write_pcr_bits(q, pcr);
-
- /* stuffing bytes */
- memset(q, 0xFF, TS_PACKET_SIZE - (q - buf));
-@@ -1485,9 +1500,9 @@
- int afc_len, stuffing_len;
- int is_dvb_subtitle = (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE);
- int is_dvb_teletext = (st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT);
-- int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
- int force_pat = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key;
- int force_sdt = 0;
-+ int64_t pcr;
- int force_nit = 0;
-
- av_assert0(ts_st->payload != buf || st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO);
-@@ -1504,21 +1519,19 @@
-
- is_start = 1;
- while (payload_size > 0) {
-- int64_t pcr = AV_NOPTS_VALUE;
-- if (ts->mux_rate > 1)
-- pcr = get_pcr(ts);
-- else if (dts != AV_NOPTS_VALUE)
-- pcr = (dts - delay) * 300;
--
-- retransmit_si_info(s, force_pat, force_sdt, force_nit, pcr);
-- force_pat = 0;
-- force_sdt = 0;
-- force_nit = 0;
-+ // add 11, pcr references the last byte of program clock reference base
-+ ts->pcr_pos = avio_tell(s->pb) + 11;
-+ pcr = ts->pcr = ts->mux_rate != 1 ?
-+ av_rescale(ts->pcr_pos, 8 * PCR_TIME_BASE, ts->mux_rate) :
-+ (dts == AV_NOPTS_VALUE ? 0 : (dts - ts->delay) * 300);
-+ if (force_pat || force_sdt || force_nit) {
-+ retransmit_si_info(s, force_pat, force_sdt, force_nit);
-+ force_pat = force_sdt = force_nit = 0;
-+ }
-
- write_pcr = 0;
- if (ts->mux_rate > 1) {
- /* Send PCR packets for all PCR streams if needed */
-- pcr = get_pcr(ts);
- if (pcr >= ts->next_pcr) {
- int64_t next_pcr = INT64_MAX;
- for (int i = 0; i < s->nb_streams; i++) {
-@@ -1528,36 +1541,43 @@
- AVStream *st2 = s->streams[st2_index];
- MpegTSWriteStream *ts_st2 = st2->priv_data;
- if (ts_st2->pcr_period) {
-- if (pcr - ts_st2->last_pcr >= ts_st2->pcr_period) {
-- ts_st2->last_pcr = FFMAX(pcr - ts_st2->pcr_period, ts_st2->last_pcr + ts_st2->pcr_period);
-- if (st2 != st) {
-+ if (pcr >= ts_st2->pcr_timer) {
-+ ts_st2->pcr_timer = pcr + ts_st2->pcr_period;
-+ if (st2 != st) {
- mpegts_insert_pcr_only(s, st2);
-- pcr = get_pcr(ts);
- } else {
- write_pcr = 1;
- }
- }
-- next_pcr = FFMIN(next_pcr, ts_st2->last_pcr + ts_st2->pcr_period);
-+ next_pcr = FFMIN(next_pcr, ts_st2->pcr_timer);
- }
- }
- ts->next_pcr = next_pcr;
- }
-- if (dts != AV_NOPTS_VALUE && (dts - pcr / 300) > delay) {
-- /* pcr insert gets priority over null packet insert */
-- if (write_pcr)
-- mpegts_insert_pcr_only(s, st);
-- else
-- mpegts_insert_null_packet(s);
-- /* recalculate write_pcr and possibly retransmit si_info */
-- continue;
-- }
-- } else if (ts_st->pcr_period && pcr != AV_NOPTS_VALUE) {
-- if (pcr - ts_st->last_pcr >= ts_st->pcr_period && is_start) {
-- ts_st->last_pcr = FFMAX(pcr - ts_st->pcr_period, ts_st->last_pcr + ts_st->pcr_period);
-+ }
-+ else if (ts_st->pcr_period) {
-+ if (pcr >= ts_st->pcr_timer) {
-+ ts_st->pcr_timer = pcr + ts_st->pcr_period;
- write_pcr = 1;
- }
- }
-
-+ if (write_pcr && ts->pcr_stream_pid >= 0) {
-+ mpegts_insert_pcr_only(s, 0);
-+ continue;
-+ }
-+
-+ if (ts->mux_rate > 1 && dts != AV_NOPTS_VALUE &&
-+ (dts - pcr / 300) > ts->delay) {
-+ /* pcr insert gets priority over null packet insert */
-+ if (write_pcr)
-+ mpegts_insert_pcr_only(s, st);
-+ else
-+ mpegts_insert_null_packet(s);
-+ /* recalculate write_pcr and possibly retransimit si_info */
-+ continue;
-+ }
-+
- /* prepare packet header */
- q = buf;
- *q++ = 0x47;
-@@ -1587,7 +1607,6 @@
- if (write_pcr) {
- set_af_flag(buf, 0x10);
- q = get_ts_payload_start(buf);
-- // add 11, pcr references the last byte of program clock reference base
- if (dts != AV_NOPTS_VALUE && dts < pcr / 300)
- av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n");
- extend_af(buf, write_pcr_bits(q, pcr));
-@@ -1851,8 +1870,8 @@
- uint8_t *data = NULL;
- MpegTSWrite *ts = s->priv_data;
- MpegTSWriteStream *ts_st = st->priv_data;
-- const int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE) * 2;
-- const int64_t max_audio_delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE) / 2;
-+ const int64_t delay_ticks2 = ts->delay * 2;
-+ const int64_t max_audio_delay = ts->delay / 2;
- int64_t dts = pkt->dts, pts = pkt->pts;
- int opus_samples = 0;
- size_t side_data_size;
-@@ -1872,9 +1891,9 @@
-
- if (ts->copyts < 1) {
- if (pts != AV_NOPTS_VALUE)
-- pts += delay;
-+ pts += delay_ticks2;
- if (dts != AV_NOPTS_VALUE)
-- dts += delay;
-+ dts += delay_ticks2;
- }
-
- if (!ts_st->first_timestamp_checked && (pts == AV_NOPTS_VALUE || dts == AV_NOPTS_VALUE)) {
-@@ -2305,8 +2324,10 @@
- 0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_HEVC_DIGITAL_HDTV }, 0x01, 0xff, ENC, "mpegts_service_type" },
- { "mpegts_pmt_start_pid", "Set the first pid of the PMT.",
- OFFSET(pmt_start_pid), AV_OPT_TYPE_INT, { .i64 = 0x1000 }, FIRST_OTHER_PID, LAST_OTHER_PID, ENC },
-+ { "mpegts_pcr_stream_pid", "create seperate PCR stream on this pid.",
-+ OFFSET(pcr_stream_pid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 0x1f00, ENC },
- { "mpegts_start_pid", "Set the first pid.",
-- OFFSET(start_pid), AV_OPT_TYPE_INT, { .i64 = 0x0100 }, FIRST_OTHER_PID, LAST_OTHER_PID, ENC },
-+ OFFSET(start_pid), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, LAST_OTHER_PID, ENC },
- { "mpegts_m2ts_mode", "Enable m2ts mode.", OFFSET(m2ts_mode), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, ENC },
- { "muxrate", NULL, OFFSET(mux_rate), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, ENC },
- { "pes_payload_size", "Minimum PES packet payload in bytes",
-@@ -2332,10 +2353,10 @@
- OFFSET(omit_video_pes_length), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
- { "pcr_period", "PCR retransmission time in milliseconds",
- OFFSET(pcr_period_ms), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, ENC },
-- { "pat_period", "PAT/PMT retransmission time limit in seconds",
-+ { "pat_period", "PAT/PMT retransmission time limit in ms, -1 no pat",
- OFFSET(pat_period_us), AV_OPT_TYPE_DURATION, { .i64 = PAT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
-- { "sdt_period", "SDT retransmission time limit in seconds",
-- OFFSET(sdt_period_us), AV_OPT_TYPE_DURATION, { .i64 = SDT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
-+ { "sdt_period", "SDT retransmission time limit in ms, -1 no sdt",
-+ OFFSET(sdt_period_us), AV_OPT_TYPE_INT64, { .i64 = SDT_RETRANS_TIME * 1000LL }, -1, INT64_MAX, ENC },
- { "nit_period", "NIT retransmission time limit in seconds",
- OFFSET(nit_period_us), AV_OPT_TYPE_DURATION, { .i64 = NIT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
- { NULL },
---- a/libavformat/mpegts.h
-+++ b/libavformat/mpegts.h
-@@ -64,6 +64,7 @@
- /* PID from 0x1FFC to 0x1FFE may be assigned as needed to PMT, elementary
- * streams and other data tables */
- #define NULL_PID 0x1FFF /* Null packet (used for fixed bandwidth padding) */
-+#define START_PID 0x0400
-
- /* m2ts pids */
- #define M2TS_PMT_PID 0x0100
---- a/libavformat/bluray.c
-+++ b/libavformat/bluray.c
-@@ -27,7 +27,7 @@
- #include "libavutil/opt.h"
-
- #define BLURAY_PROTO_PREFIX "bluray:"
--#define MIN_PLAYLIST_LENGTH 180 /* 3 min */
-+#define MIN_PLAYLIST_LENGTH 0
-
- typedef struct {
- const AVClass *class;
-
---- a/doc/muxers.texi
-+++ b/doc/muxers.texi
-@@ -1932,7 +1932,8 @@
- Maximum time in seconds between PAT/PMT tables. Default is @code{0.1}.
-
- @item sdt_period @var{duration}
--Maximum time in seconds between SDT tables. Default is @code{0.5}.
-+Maximum time in seconds between SDT tables. Default is @code{0.5}. Regardless
-+of this setting no SDT is written in m2ts mode.
-
- @item nit_period @var{duration}
- Maximum time in seconds between NIT tables. Default is @code{0.5}.
+++ /dev/null
---- a/libavformat/avformat.h
-+++ b/libavformat/avformat.h
-@@ -500,6 +500,9 @@
- The user or muxer can override this through
- AVFormatContext.avoid_negative_ts
- */
-+#define AVFMT_SEEK_NOSTREAMS 0x80000 /**< Stream index ignored by seek,
-+ or some streams fail to seek
-+ */
-
- #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */
-
-@@ -563,7 +566,8 @@
- /**
- * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
- * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
-- * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
-+ * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS,
-+ * AVFMT_SEEK_NOSTREAMS
- */
- int flags;
-
---- a/libavformat/dv.c
-+++ b/libavformat/dv.c
-@@ -713,6 +713,7 @@
- const AVInputFormat ff_dv_demuxer = {
- .name = "dv",
- .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .priv_data_size = sizeof(RawDVContext),
- .read_probe = dv_probe,
- .read_header = dv_read_header,
---- a/libavformat/matroskadec.c
-+++ b/libavformat/matroskadec.c
-@@ -4780,6 +4780,7 @@
- const AVInputFormat ff_webm_dash_manifest_demuxer = {
- .name = "webm_dash_manifest",
- .long_name = NULL_IF_CONFIG_SMALL("WebM DASH Manifest"),
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .priv_class = &webm_dash_class,
- .priv_data_size = sizeof(MatroskaDemuxContext),
- .flags_internal = FF_FMT_INIT_CLEANUP,
-@@ -4792,6 +4793,7 @@
- const AVInputFormat ff_matroska_demuxer = {
- .name = "matroska,webm",
- .long_name = NULL_IF_CONFIG_SMALL("Matroska / WebM"),
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .extensions = "mkv,mk3d,mka,mks,webm",
- .priv_data_size = sizeof(MatroskaDemuxContext),
- .flags_internal = FF_FMT_INIT_CLEANUP,
---- a/libavformat/seek.c
-+++ b/libavformat/seek.c
-@@ -605,6 +605,13 @@
- return seek_frame_byte(s, stream_index, timestamp, flags);
- }
-
-+ if (stream_index != -1 && (s->iformat->flags & AVFMT_SEEK_NOSTREAMS)) {
-+ timestamp = av_rescale_q(timestamp,
-+ s->streams[stream_index]->time_base,
-+ AV_TIME_BASE_Q);
-+ stream_index = -1;
-+ }
-+
- if (stream_index < 0) {
- stream_index = av_find_default_stream_index(s);
- if (stream_index < 0)
+++ /dev/null
---- a/libavformat/avidec.c
-+++ b/libavformat/avidec.c
-@@ -2016,6 +2016,7 @@
- .priv_data_size = sizeof(AVIContext),
- .flags_internal = FF_FMT_INIT_CLEANUP,
- .extensions = "avi",
-+ .flags = AVFMT_SEEK_NOSTREAMS,
- .read_probe = avi_probe,
- .read_header = avi_read_header,
- .read_packet = avi_read_packet,
+++ /dev/null
---- a/libavfilter/formats.c
-+++ b/libavfilter/formats.c
-@@ -110,11 +110,13 @@
- possibly causing a lossy conversion elsewhere in the graph.
- To avoid that, pretend that there are no common formats to force the
- insertion of a conversion filter. */
-- if (type == AVMEDIA_TYPE_VIDEO)
-+ if (type == AVMEDIA_TYPE_VIDEO) {
- for (i = 0; i < a->nb_formats; i++) {
- const AVPixFmtDescriptor *const adesc = av_pix_fmt_desc_get(a->formats[i]);
-+ if( !adesc ) continue;
- for (j = 0; j < b->nb_formats; j++) {
- const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
-+ if( !bdesc ) continue;
- alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
- chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
- if (a->formats[i] == b->formats[j]) {
-@@ -123,6 +125,7 @@
- }
- }
- }
-+ }
-
- // If chroma or alpha can be lost through merging then do not merge
- if (alpha2 > alpha1 || chroma2 > chroma1)
+++ /dev/null
---- a/libavcodec/vdpau_mpeg12.c
-+++ b/libavcodec/vdpau_mpeg12.c
-@@ -117,6 +117,7 @@
- .frame_priv_data_size = sizeof(struct vdpau_picture_context),
- .init = vdpau_mpeg1_init,
- .uninit = ff_vdpau_common_uninit,
-+ .frame_params = ff_vdpau_common_frame_params,
- .priv_data_size = sizeof(VDPAUContext),
- .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
- };
+++ /dev/null
---- a/libavcodec/h263dec.c
-+++ b/libavcodec/h263dec.c
-@@ -623,7 +623,7 @@
- if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
- ff_mpeg4_frame_end(avctx, buf, buf_size);
-
-- if (!s->divx_packed && avctx->hwaccel)
-+ if (s->divx_packed && avctx->hwaccel)
- ff_thread_finish_setup(avctx);
-
- av_assert1(s->current_picture.f->pict_type == s->current_picture_ptr->f->pict_type);
+++ /dev/null
---- a/libavformat/mpegenc.c
-+++ b/libavformat/mpegenc.c
-@@ -987,9 +987,9 @@
- PacketDesc *pkt_desc;
-
- while ((pkt_desc = stream->predecode_packet) &&
-+ pkt_desc != stream->premux_packet &&
- scr > pkt_desc->dts) { // FIXME: > vs >=
-- if (stream->buffer_index < pkt_desc->size ||
-- stream->predecode_packet == stream->premux_packet) {
-+ if (stream->buffer_index < pkt_desc->size) {
- av_log(ctx, AV_LOG_ERROR,
- "buffer underflow st=%d bufi=%d size=%d\n",
- i, stream->buffer_index, pkt_desc->size);
+++ /dev/null
---- a/libavutil/hwcontext_vdpau.c
-+++ b/libavutil/hwcontext_vdpau.c
-@@ -47,6 +47,11 @@
- { 0, AV_PIX_FMT_NONE, },
- };
-
-+static const VDPAUPixFmtMap pix_fmts_420j[] = {
-+ { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUVJ420P },
-+ { 0, AV_PIX_FMT_NONE, },
-+};
-+
- static const VDPAUPixFmtMap pix_fmts_422[] = {
- { VDP_YCBCR_FORMAT_NV12, AV_PIX_FMT_NV16 },
- { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUV422P },
-@@ -71,6 +76,7 @@
- const VDPAUPixFmtMap *map;
- } vdpau_pix_fmts[] = {
- { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUV420P, pix_fmts_420 },
-+ { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUVJ420P, pix_fmts_420j },
- { VDP_CHROMA_TYPE_422, AV_PIX_FMT_YUV422P, pix_fmts_422 },
- { VDP_CHROMA_TYPE_444, AV_PIX_FMT_YUV444P, pix_fmts_444 },
- #ifdef VDP_YCBCR_FORMAT_P016
+++ /dev/null
---- a/libavcodec/encode.c
-+++ b/libavcodec/encode.c
-@@ -331,7 +331,7 @@
- }
-
- if (!frame->buf[0]) {
-- if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
-+ if (avci->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
- avci->frame_thread_encoder))
- return AVERROR_EOF;
-
-@@ -350,8 +350,10 @@
- ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
- }
-
-- if (avci->draining && !got_packet)
-+ if (avci->draining && !got_packet) {
-+ fflush(stderr);
- avci->draining_done = 1;
-+ }
-
- return ret;
- }
-@@ -526,10 +528,16 @@
- if (avci->draining)
- return AVERROR_EOF;
-
-- if (avci->buffer_frame->buf[0])
-+ if (avci->buffer_frame->buf[0]) {
-+ if (!frame) {
-+ fflush(stderr);
-+ av_frame_unref(avci->buffer_frame);
-+ }
- return AVERROR(EAGAIN);
-+ }
-
- if (!frame) {
-+ fflush(stderr);
- avci->draining = 1;
- } else {
- ret = encode_send_frame_internal(avctx, frame);
+++ /dev/null
---- a/libavcodec/pcm-dvdenc.c
-+++ b/libavcodec/pcm-dvdenc.c
-@@ -38,6 +38,12 @@ static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx)
- int quant, freq, frame_size;
-
- switch (avctx->sample_rate) {
-+ case 32000:
-+ freq = 3;
-+ break;
-+ case 44100:
-+ freq = 2;
-+ break;
- case 48000:
- freq = 0;
- break;
-@@ -181,7 +187,7 @@ const FFCodec ff_pcm_dvd_encoder = {
- .priv_data_size = sizeof(PCMDVDContext),
- .init = pcm_dvd_encode_init,
- FF_CODEC_ENCODE_CB(pcm_dvd_encode_frame),
-- .p.supported_samplerates = (const int[]) { 48000, 96000, 0},
-+ .p.supported_samplerates = (const int[]) { 32000, 44100, 48000, 96000, 0},
- CODEC_OLD_CHANNEL_LAYOUTS(AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO,
- AV_CH_LAYOUT_5POINT1, AV_CH_LAYOUT_7POINT1)
- .p.ch_layouts = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
---
-2.43.0
+++ /dev/null
-From fef22c87ada4517441701e6e61e062c9f4399c8e Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= <jeebjp@gmail.com>
-Date: Wed, 14 Feb 2024 22:40:54 +0200
-Subject: [PATCH] {avcodec,tests}: rename the bundled Mesa AV1 vulkan video
- headers
-
-This together with adjusting the inclusion define allows for the
-build to not fail with latest Vulkan-Headers that contain the
-stabilized Vulkan AV1 decoding definitions.
-
-Compilation fails currently as the AV1 header is getting included
-via hwcontext_vulkan.h -> <vulkan/vulkan.h> -> vulkan_core.h, which
-finally includes vk_video/vulkan_video_codec_av1std.h and the decode
-header, leading to the bundled header to never defining anything
-due to the inclusion define being the same.
-
-This fix is imperfect, as it leads to additional re-definition
-warnings for things such as
-VK_STD_VULKAN_VIDEO_CODEC_AV1_DECODE_SPEC_VERSION. , but it is
-not clear how to otherwise have the bundled version trump the
-actually standardized one for a short-term compilation fix.
-
-(cherry picked from commit e06ce6d2b45edac4a2df04f304e18d4727417d24)
----
- libavcodec/Makefile | 4 ++--
- libavcodec/vulkan_video.h | 4 ++--
- ...v1std_decode.h => vulkan_video_codec_av1std_decode_mesa.h} | 4 ++--
- ..._video_codec_av1std.h => vulkan_video_codec_av1std_mesa.h} | 4 ++--
- tests/ref/fate/source | 4 ++--
- 5 files changed, 10 insertions(+), 10 deletions(-)
- rename libavcodec/{vulkan_video_codec_av1std_decode.h => vulkan_video_codec_av1std_decode_mesa.h} (89%)
- rename libavcodec/{vulkan_video_codec_av1std.h => vulkan_video_codec_av1std_mesa.h} (99%)
-
-diff --git a/libavcodec/Makefile b/libavcodec/Makefile
-index ec57e53e300f9..eb25707ef5db9 100644
---- a/libavcodec/Makefile
-+++ b/libavcodec/Makefile
-@@ -1284,7 +1284,7 @@ SKIPHEADERS += %_tablegen.h \
- aacenc_quantization.h \
- aacenc_quantization_misc.h \
- bitstream_template.h \
-- vulkan_video_codec_av1std.h \
-+ vulkan_video_codec_av1std_mesa.h \
- $(ARCH)/vpx_arith.h \
-
- SKIPHEADERS-$(CONFIG_AMF) += amfenc.h
-@@ -1306,7 +1306,7 @@ SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h
- SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_decode.h vaapi_hevc.h vaapi_encode.h
- SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h vdpau_internal.h
- SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX) += videotoolbox.h vt_internal.h
--SKIPHEADERS-$(CONFIG_VULKAN) += vulkan.h vulkan_video.h vulkan_decode.h vulkan_video_codec_av1std_decode.h
-+SKIPHEADERS-$(CONFIG_VULKAN) += vulkan.h vulkan_video.h vulkan_decode.h vulkan_video_codec_av1std_decode_mesa.h
- SKIPHEADERS-$(CONFIG_V4L2_M2M) += v4l2_buffers.h v4l2_context.h v4l2_m2m.h
- SKIPHEADERS-$(CONFIG_ZLIB) += zlib_wrapper.h
-
-diff --git a/libavcodec/vulkan_video.h b/libavcodec/vulkan_video.h
-index b28e3fe0bde85..51f44dd54314d 100644
---- a/libavcodec/vulkan_video.h
-+++ b/libavcodec/vulkan_video.h
-@@ -23,8 +23,8 @@
- #include "vulkan.h"
-
- #include <vk_video/vulkan_video_codecs_common.h>
--#include "vulkan_video_codec_av1std.h"
--#include "vulkan_video_codec_av1std_decode.h"
-+#include "vulkan_video_codec_av1std_mesa.h"
-+#include "vulkan_video_codec_av1std_decode_mesa.h"
-
- #define CODEC_VER_MAJ(ver) (ver >> 22)
- #define CODEC_VER_MIN(ver) ((ver >> 12) & ((1 << 10) - 1))
-diff --git a/libavcodec/vulkan_video_codec_av1std_decode.h b/libavcodec/vulkan_video_codec_av1std_decode_mesa.h
-similarity index 89%
-rename from libavcodec/vulkan_video_codec_av1std_decode.h
-rename to libavcodec/vulkan_video_codec_av1std_decode_mesa.h
-index a697c00593c63..e2f37b4e6e0dc 100644
---- a/libavcodec/vulkan_video_codec_av1std_decode.h
-+++ b/libavcodec/vulkan_video_codec_av1std_decode_mesa.h
-@@ -14,8 +14,8 @@
- * limitations under the License.
- */
-
--#ifndef VULKAN_VIDEO_CODEC_AV1STD_DECODE_H_
--#define VULKAN_VIDEO_CODEC_AV1STD_DECODE_H_ 1
-+#ifndef VULKAN_VIDEO_CODEC_AV1STD_DECODE_MESA_H_
-+#define VULKAN_VIDEO_CODEC_AV1STD_DECODE_MESA_H_ 1
-
- /*
- ** This header is NOT YET generated from the Khronos Vulkan XML API Registry.
-diff --git a/libavcodec/vulkan_video_codec_av1std.h b/libavcodec/vulkan_video_codec_av1std_mesa.h
-similarity index 99%
-rename from libavcodec/vulkan_video_codec_av1std.h
-rename to libavcodec/vulkan_video_codec_av1std_mesa.h
-index c46236c457238..c91589eee2bfe 100644
---- a/libavcodec/vulkan_video_codec_av1std.h
-+++ b/libavcodec/vulkan_video_codec_av1std_mesa.h
-@@ -14,8 +14,8 @@
- * limitations under the License.
- */
-
--#ifndef VULKAN_VIDEO_CODEC_AV1STD_H_
--#define VULKAN_VIDEO_CODEC_AV1STD_H_ 1
-+#ifndef VULKAN_VIDEO_CODEC_AV1STD_MESA_H_
-+#define VULKAN_VIDEO_CODEC_AV1STD_MESA_H_ 1
-
- /*
- ** This header is NOT YET generated from the Khronos Vulkan XML API Registry.
-diff --git a/tests/ref/fate/source b/tests/ref/fate/source
-index c575789dd55e7..8bb58b61f144e 100644
---- a/tests/ref/fate/source
-+++ b/tests/ref/fate/source
-@@ -23,8 +23,8 @@ compat/djgpp/math.h
- compat/float/float.h
- compat/float/limits.h
- libavcodec/bitstream_template.h
--libavcodec/vulkan_video_codec_av1std.h
--libavcodec/vulkan_video_codec_av1std_decode.h
-+libavcodec/vulkan_video_codec_av1std_decode_mesa.h
-+libavcodec/vulkan_video_codec_av1std_mesa.h
- tools/decode_simple.h
- Use of av_clip() where av_clip_uintp2() could be used:
- Use of av_clip() where av_clip_intp2() could be used:
+++ /dev/null
---- a/libavcodec/wrapped_avframe.c
-+++ b/libavcodec/wrapped_avframe.c
-@@ -33,6 +33,38 @@
- #include "libavutil/buffer.h"
- #include "libavutil/pixdesc.h"
-
-+
-+
-+static const enum AVPixelFormat pix_fmts_all[] = {
-+ AV_PIX_FMT_YUV411P,
-+ AV_PIX_FMT_YUV420P,
-+ AV_PIX_FMT_YUVJ420P,
-+ AV_PIX_FMT_YUV422P,
-+ AV_PIX_FMT_YUVJ422P,
-+ AV_PIX_FMT_YUV444P,
-+ AV_PIX_FMT_YUVJ444P,
-+ AV_PIX_FMT_YUV420P10,
-+ AV_PIX_FMT_YUV422P10,
-+ AV_PIX_FMT_YUV444P10,
-+ AV_PIX_FMT_YUV420P12,
-+ AV_PIX_FMT_YUV422P12,
-+ AV_PIX_FMT_YUV444P12,
-+ AV_PIX_FMT_YUV420P14,
-+ AV_PIX_FMT_YUV422P14,
-+ AV_PIX_FMT_YUV444P14,
-+ AV_PIX_FMT_YUV420P16,
-+ AV_PIX_FMT_YUV422P16,
-+ AV_PIX_FMT_YUV444P16,
-+ AV_PIX_FMT_GRAY8,
-+ AV_PIX_FMT_GRAY9,
-+ AV_PIX_FMT_GRAY10,
-+ AV_PIX_FMT_GRAY12,
-+ AV_PIX_FMT_GRAY16,
-+ AV_PIX_FMT_NONE
-+};
-+
-+
-+
- static void wrapped_avframe_release_buffer(void *unused, uint8_t *data)
- {
- AVFrame *frame = (AVFrame *)data;
-@@ -111,6 +143,7 @@
- .p.id = AV_CODEC_ID_WRAPPED_AVFRAME,
- .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
- FF_CODEC_ENCODE_CB(wrapped_avframe_encode),
-+ .p.pix_fmts = pix_fmts_all,
- };
-
- const FFCodec ff_wrapped_avframe_decoder = {
+++ /dev/null
---- a/libavformat/yuv4mpegenc.c
-+++ b/libavformat/yuv4mpegenc.c
-@@ -268,7 +268,7 @@
- av_log(s, AV_LOG_ERROR, "'%s' is not an official yuv4mpegpipe pixel format. "
- "Use '-strict -1' to encode to this pixel format.\n",
- av_get_pix_fmt_name(s->streams[0]->codecpar->format));
-- return AVERROR(EINVAL);
-+ //return AVERROR(EINVAL);
- }
- av_log(s, AV_LOG_WARNING, "Warning: generating non standard YUV stream. "
- "Mjpegtools will not work.\n");