Skip to content

Commit 289db3e

Browse files
committed
demux/demux_textsub: allow configuring probe size
1 parent 917a2cb commit 289db3e

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

demux/demux_textsub.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,36 @@
1515
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
#include <limits.h>
1819
#include <math.h>
1920

2021
#include <subrandr/subrandr.h>
2122

2223
#include "common/common.h"
2324
#include "demux/packet.h"
2425
#include "misc/bstr.h"
26+
#include "options/m_config.h"
27+
#include "options/m_option.h"
2528
#include "stream/stream.h"
2629
#include "demux.h"
2730

31+
#define OPT_BASE_STRUCT struct demux_textsub_opts
32+
struct demux_textsub_opts {
33+
int probesize;
34+
};
35+
36+
const struct m_sub_options demux_textsub_conf = {
37+
.opts = (const m_option_t[]) {
38+
{"demuxer-textsub-probesize", OPT_INT(probesize), M_RANGE(32, INT_MAX)},
39+
{0}
40+
},
41+
.size = sizeof(struct demux_textsub_opts),
42+
.defaults = &(const struct demux_textsub_opts){
43+
.probesize = 128,
44+
},
45+
.change_flags = UPDATE_DEMUXER,
46+
};
47+
2848
struct format_codec_info {
2949
const char *codec;
3050
const char *codec_desc;
@@ -48,8 +68,6 @@ static const struct textsub_ext TEXT_FORMAT_EXTS[] = {
4868
{NULL}
4969
};
5070

51-
static const int SUBRANDR_PROBE_SIZE = 128;
52-
5371
struct demux_textsub_priv {
5472
bstr content;
5573
bool exhausted;
@@ -60,13 +78,15 @@ static int demux_open_textsub(struct demuxer *demuxer, enum demux_check check)
6078
bstr filename = bstr0(demuxer->filename);
6179
struct format_codec_info codec_info = {NULL, NULL};
6280

81+
struct demux_textsub_opts *opts = mp_get_config_group(demuxer, demuxer->global, &demux_textsub_conf);
82+
6383
for (const struct textsub_ext *ext = TEXT_FORMAT_EXTS; ext->ext; ++ext) {
6484
if (bstr_endswith0(filename, ext->ext))
6585
codec_info = ext->codec_info;
6686
}
6787

6888
if (!codec_info.codec) {
69-
int probe_size = stream_peek(demuxer->stream, SUBRANDR_PROBE_SIZE);
89+
int probe_size = stream_peek(demuxer->stream, opts->probesize);
7090
uint8_t *probe_buffer = demuxer->stream->buffer;
7191

7292
sbr_subtitle_format fmt = sbr_probe_text((const char *)probe_buffer, (size_t)probe_size);

options/options.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ extern const struct m_sub_options demux_rawvideo_conf;
7070
extern const struct m_sub_options demux_playlist_conf;
7171
extern const struct m_sub_options demux_lavf_conf;
7272
extern const struct m_sub_options demux_mkv_conf;
73+
#if HAVE_SUBRANDR
74+
extern const struct m_sub_options demux_textsub_conf;
75+
#endif
7376
extern const struct m_sub_options vd_lavc_conf;
7477
extern const struct m_sub_options ad_lavc_conf;
7578
extern const struct m_sub_options hwdec_conf;
@@ -693,6 +696,9 @@ static const m_option_t mp_opts[] = {
693696
{"demuxer-rawvideo", OPT_SUBSTRUCT(demux_rawvideo, demux_rawvideo_conf)},
694697
{"", OPT_SUBSTRUCT(demux_playlist, demux_playlist_conf)},
695698
{"demuxer-mkv", OPT_SUBSTRUCT(demux_mkv, demux_mkv_conf)},
699+
#if HAVE_SUBRANDR
700+
{"", OPT_SUBSTRUCT(demux_textsub, demux_textsub_conf)},
701+
#endif
696702

697703
// ------------------------- subtitles options --------------------
698704

options/options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ typedef struct MPOpts {
365365
struct demux_playlist_opts *demux_playlist;
366366
struct demux_lavf_opts *demux_lavf;
367367
struct demux_mkv_opts *demux_mkv;
368+
#if HAVE_SUBRANDR
369+
struct demux_textsub_opts *demux_textsub;
370+
#endif
368371

369372
struct demux_opts *demux_opts;
370373
struct demux_cache_opts *demux_cache_opts;

0 commit comments

Comments
 (0)