Skip to content

Commit 42ad4c2

Browse files
Backport all of the demux_opts changes.
1 parent ee5e23c commit 42ad4c2

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

demux/demux.c

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,6 @@ static const demuxer_desc_t *const demuxer_list[] = {
8282
NULL
8383
};
8484

85-
/* XXX: Finish backporting upstream a343666ab5121e7a3388be9aa2d8731d6d1f2f64.
86-
* Update 73e72749f2899eab1a40049fcd27ccb271abf311 accordingly as well.
87-
*/
88-
struct demux_opts {
89-
int enable_cache;
90-
bool disk_cache;
91-
int64_t max_bytes;
92-
int64_t max_bytes_bw;
93-
bool donate_fw;
94-
double min_secs;
95-
double hyst_secs;
96-
bool force_seekable;
97-
double min_secs_cache;
98-
bool access_references;
99-
int seekable_cache;
100-
bool create_ccs;
101-
char *record_file;
102-
int video_back_preroll;
103-
int audio_back_preroll;
104-
int back_batch[STREAM_TYPE_COUNT];
105-
double back_seek_size;
106-
char *meta_cp;
107-
bool force_retry_eof;
108-
};
109-
11085
#define OPT_BASE_STRUCT struct demux_opts
11186

11287
static bool get_demux_sub_opts(int index, const struct m_sub_options **sub);
@@ -189,9 +164,6 @@ struct demux_internal {
189164

190165
// -- All the following fields are protected by lock.
191166

192-
struct demux_opts *opts;
193-
struct m_config_cache *opts_cache;
194-
195167
bool thread_terminate;
196168
bool threading;
197169
bool shutdown_async;
@@ -1024,7 +996,7 @@ static void demux_add_sh_stream_locked(struct demux_internal *in,
1024996

1025997
switch (ds->type) {
1026998
case STREAM_AUDIO:
1027-
ds->back_preroll = in->opts->audio_back_preroll;
999+
ds->back_preroll = in->d_thread->opts->audio_back_preroll;
10281000
if (ds->back_preroll < 0) { // auto
10291001
ds->back_preroll = mp_codec_is_lossless(sh->codec->codec) ? 0 : 1;
10301002
if (sh->codec->codec && (strcmp(sh->codec->codec, "opus") == 0 ||
@@ -1034,7 +1006,7 @@ static void demux_add_sh_stream_locked(struct demux_internal *in,
10341006
}
10351007
break;
10361008
case STREAM_VIDEO:
1037-
ds->back_preroll = in->opts->video_back_preroll;
1009+
ds->back_preroll = in->d_thread->opts->video_back_preroll;
10381010
if (ds->back_preroll < 0)
10391011
ds->back_preroll = 0; // auto
10401012
break;
@@ -1464,7 +1436,7 @@ static void find_backward_restart_pos(struct demux_stream *ds)
14641436

14651437
// Number of renderable keyframes to return to user.
14661438
// (Excludes preroll, which is decoded by user, but then discarded.)
1467-
int batch = MPMAX(in->opts->back_batch[ds->type], 1);
1439+
int batch = MPMAX(in->d_thread->opts->back_batch[ds->type], 1);
14681440
// Number of keyframes to return to the user in total.
14691441
int total = batch + ds->back_preroll;
14701442

@@ -1576,7 +1548,7 @@ static void find_backward_restart_pos(struct demux_stream *ds)
15761548
in->back_any_need_recheck = true;
15771549
mp_cond_signal(&in->wakeup);
15781550
} else {
1579-
ds->back_seek_pos -= in->opts->back_seek_size;
1551+
ds->back_seek_pos -= in->d_thread->opts->back_seek_size;
15801552
in->need_back_seek = true;
15811553
}
15821554
}
@@ -1983,13 +1955,13 @@ static void record_packet(struct demux_internal *in, struct demux_packet *dp)
19831955
{
19841956
// (should preferably be outside of the lock)
19851957
if (in->enable_recording && !in->recorder &&
1986-
in->opts->record_file && in->opts->record_file[0])
1958+
in->d_thread->opts->record_file && in->d_thread->opts->record_file[0])
19871959
{
19881960
// Later failures shouldn't make it retry and overwrite the previously
19891961
// recorded file.
19901962
in->enable_recording = false;
19911963

1992-
in->recorder = recorder_create(in, in->opts->record_file);
1964+
in->recorder = recorder_create(in, in->d_thread->opts->record_file);
19931965
if (!in->recorder)
19941966
MP_ERR(in, "Disabling recording.\n");
19951967
}
@@ -2069,7 +2041,7 @@ static void add_packet_locked(struct sh_stream *stream, demux_packet_t *dp)
20692041

20702042
record_packet(in, dp);
20712043

2072-
if (in->cache && in->opts->disk_cache && !dp->is_wrapped_avframe) {
2044+
if (in->cache && in->d_thread->opts->disk_cache && !dp->is_wrapped_avframe) {
20732045
int64_t pos = demux_cache_write(in->cache, dp);
20742046
if (pos >= 0) {
20752047
demux_packet_unref_contents(dp);
@@ -2324,7 +2296,7 @@ static void prune_old_packets(struct demux_internal *in)
23242296
uint64_t max_avail = in->max_bytes_bw;
23252297
// Backward cache (if enabled at all) can use unused forward cache.
23262298
// Still leave 1 byte free, so the read_packet logic doesn't get stuck.
2327-
if (max_avail && in->max_bytes > (fw_bytes + 1) && in->opts->donate_fw)
2299+
if (max_avail && in->max_bytes > (fw_bytes + 1) && in->d_thread->opts->donate_fw)
23282300
max_avail += in->max_bytes - (fw_bytes + 1);
23292301
if (in->total_bytes - fw_bytes <= max_avail)
23302302
break;
@@ -2471,7 +2443,7 @@ static void execute_seek(struct demux_internal *in)
24712443

24722444
static void update_opts(struct demux_internal *in)
24732445
{
2474-
struct demux_opts *opts = in->opts;
2446+
struct demux_opts *opts = in->d_thread->opts;
24752447

24762448
in->min_secs = opts->min_secs;
24772449
in->hyst_secs = opts->hyst_secs;
@@ -2537,10 +2509,10 @@ static void update_opts(struct demux_internal *in)
25372509
// Make demuxing progress. Return whether progress was made.
25382510
static bool thread_work(struct demux_internal *in)
25392511
{
2540-
struct demux_opts *opts = in->opts;
2512+
struct demux_opts *opts = in->d_thread->opts;
25412513
int64_t old_max_bytes = opts->max_bytes;
25422514
int64_t old_max_bytes_bw = opts->max_bytes_bw;
2543-
if (m_config_cache_update(in->opts_cache)) {
2515+
if (m_config_cache_update(in->d_thread->opts_cache)) {
25442516
update_opts(in);
25452517
if (opts->max_bytes + opts->max_bytes_bw < old_max_bytes + old_max_bytes_bw)
25462518
demux_packet_pool_clear(in->packet_pool);
@@ -2668,7 +2640,7 @@ static int dequeue_packet(struct demux_stream *ds, double min_pts,
26682640
return 1;
26692641
}
26702642

2671-
if (!in->reading && (!in->eof || in->opts->force_retry_eof)) {
2643+
if (!in->reading && (!in->eof || in->d_thread->opts->force_retry_eof)) {
26722644
in->reading = true; // enable demuxer thread prefetching
26732645
mp_cond_signal(&in->wakeup);
26742646
}
@@ -3319,6 +3291,8 @@ static struct demuxer *open_given_type(struct dmpv_global *global,
33193291
.events = DEMUX_EVENT_ALL,
33203292
.duration = -1,
33213293
.depth = params ? params->depth : 0,
3294+
.opts = opts,
3295+
.opts_cache = opts_cache,
33223296
};
33233297

33243298
struct demux_internal *in = demuxer->in = talloc_ptrtype(demuxer, in);
@@ -3329,8 +3303,6 @@ static struct demuxer *open_given_type(struct dmpv_global *global,
33293303
.stats = stats_ctx_create(in, global, "demuxer"),
33303304
.can_cache = params && params->is_top_level,
33313305
.can_record = params && params->stream_record,
3332-
.opts = opts,
3333-
.opts_cache = opts_cache,
33343306
.d_thread = talloc(demuxer, struct demuxer),
33353307
.d_user = demuxer,
33363308
.after_seek = true, // (assumed identical to initial demuxer state)
@@ -4641,7 +4613,7 @@ static void demux_convert_tags_charset(struct demuxer *demuxer)
46414613
{
46424614
struct demux_internal *in = demuxer->in;
46434615

4644-
char *cp = in->opts->meta_cp;
4616+
char *cp = in->d_thread->opts->meta_cp;
46454617
if (!cp || mp_charset_is_utf8(cp))
46464618
return;
46474619

demux/demux.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,29 @@ enum demux_event {
9393
struct demuxer;
9494
struct timeline;
9595

96+
// Demuxer options (public for access from various parts of code)
97+
struct demux_opts {
98+
int enable_cache;
99+
bool disk_cache;
100+
int64_t max_bytes;
101+
int64_t max_bytes_bw;
102+
bool donate_fw;
103+
double min_secs;
104+
double hyst_secs;
105+
bool force_seekable;
106+
double min_secs_cache;
107+
bool access_references;
108+
int seekable_cache;
109+
bool create_ccs;
110+
char *record_file;
111+
int video_back_preroll;
112+
int audio_back_preroll;
113+
int back_batch[STREAM_TYPE_COUNT];
114+
double back_seek_size;
115+
char *meta_cp;
116+
bool force_retry_eof;
117+
};
118+
96119
/**
97120
* Demuxer description structure
98121
*/
@@ -234,6 +257,10 @@ typedef struct demuxer {
234257
struct demux_packet_pool *packet_pool;
235258
struct demuxer_params *params;
236259

260+
// Demuxer options - public for access by demuxer implementations
261+
struct demux_opts *opts;
262+
struct m_config_cache *opts_cache;
263+
237264
// internal to demux.c
238265
struct demux_internal *in;
239266

0 commit comments

Comments
 (0)