summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-06-16 22:07:48 +0200
committerwm4 <wm4@nowhere>2013-06-16 22:07:48 +0200
commitd81b71c7f7cb6f5b3a047fbfeeb41d4888e7c5b6 (patch)
tree0d50b238c1a798db9ef09838800c99653c06e408 /demux
parent4d3a2c7e0dac38546f5fc2c7737a6ec1f09e30f6 (diff)
parentf794444309a826478fefa00bf13d660793066b81 (diff)
downloadmpv-d81b71c7f7cb6f5b3a047fbfeeb41d4888e7c5b6.tar.bz2
mpv-d81b71c7f7cb6f5b3a047fbfeeb41d4888e7c5b6.tar.xz
Merge branch 'cache_new'
Diffstat (limited to 'demux')
-rw-r--r--demux/aviheader.c3
-rw-r--r--demux/demux_asf.c1
-rw-r--r--demux/demux_avi.c1
-rw-r--r--demux/demux_lavf.c65
-rw-r--r--demux/demux_ts.c5
-rw-r--r--demux/ebml.c5
6 files changed, 35 insertions, 45 deletions
diff --git a/demux/aviheader.c b/demux/aviheader.c
index 2226be25d4..c1b9c59692 100644
--- a/demux/aviheader.c
+++ b/demux/aviheader.c
@@ -479,7 +479,6 @@ if (priv->isodml && (index_mode==-1 || index_mode==0 || index_mode==1)) {
// read the standard indices
for (cx = &priv->suidx[0], i=0; i<priv->suidx_size; cx++, i++) {
- stream_reset(demuxer->stream);
for (j=0; j<cx->nEntriesInUse; j++) {
int ret1, ret2;
memset(&cx->stdidx[j], 0, 32);
@@ -543,7 +542,6 @@ if (priv->isodml && (index_mode==-1 || index_mode==0 || index_mode==1)) {
{
uint32_t id;
uint32_t db = 0;
- stream_reset (demuxer->stream);
// find out the video stream id. I have seen files with 01db.
for (idx = &((AVIINDEXENTRY *)priv->idx)[0], i=0; i<priv->idx_size; i++, idx++){
@@ -590,7 +588,6 @@ freeout:
if(index_mode>=2 || (priv->idx_size==0 && index_mode==1)){
int idx_pos = 0;
// build index for file:
- stream_reset(demuxer->stream);
stream_seek(demuxer->stream,demuxer->movi_start);
priv->idx_size=0;
diff --git a/demux/demux_asf.c b/demux/demux_asf.c
index 0b8da6930f..f800e09dc3 100644
--- a/demux/demux_asf.c
+++ b/demux/demux_asf.c
@@ -628,7 +628,6 @@ static demuxer_t* demux_open_asf(demuxer_t* demuxer)
init_priv(asf);
if (!read_asf_header(demuxer,asf))
return NULL;
- stream_reset(demuxer->stream);
stream_seek(demuxer->stream,demuxer->movi_start);
// demuxer->idx_pos=0;
// demuxer->endpos=avi_header.movi_end;
diff --git a/demux/demux_avi.c b/demux/demux_avi.c
index daf542bfac..a07f022cde 100644
--- a/demux/demux_avi.c
+++ b/demux/demux_avi.c
@@ -456,7 +456,6 @@ static demuxer_t* demux_open_avi(demuxer_t* demuxer){
demuxer->video->id=-1; // autodetect
}
- stream_reset(demuxer->stream);
stream_seek(demuxer->stream,demuxer->movi_start);
if(priv->idx_size>1){
// decide index format:
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index d3b64d3009..d8e8109c93 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -47,7 +47,7 @@
#include "core/m_option.h"
#define INITIAL_PROBE_SIZE STREAM_BUFFER_SIZE
-#define PROBE_BUF_SIZE (2 * 1024 * 1024)
+#define PROBE_BUF_SIZE FFMIN(STREAM_MAX_BUFFER_SIZE, 2 * 1024 * 1024)
#define OPT_BASE_STRUCT struct MPOpts
@@ -143,7 +143,6 @@ static int64_t mp_seek(void *opaque, int64_t pos, int whence)
return -1;
current_pos = stream_tell(stream);
if (stream_seek(stream, pos) == 0) {
- stream_reset(stream);
stream_seek(stream, current_pos);
return -1;
}
@@ -190,18 +189,15 @@ static int lavf_check_file(demuxer_t *demuxer)
{
struct MPOpts *opts = demuxer->opts;
struct lavfdopts *lavfdopts = &opts->lavfdopts;
- AVProbeData avpd;
+ struct stream *s = demuxer->stream;
lavf_priv_t *priv;
- int probe_data_size = 0;
- int read_size = INITIAL_PROBE_SIZE;
- int score;
assert(!demuxer->priv);
demuxer->priv = talloc_zero(NULL, lavf_priv_t);
priv = demuxer->priv;
priv->autoselect_sub = -1;
- priv->filename = demuxer->stream->url;
+ priv->filename = s->url;
if (!priv->filename) {
priv->filename = "mp:unknown";
mp_msg(MSGT_DEMUX, MSGL_WARN, "Stream url is not set!\n");
@@ -210,7 +206,7 @@ static int lavf_check_file(demuxer_t *demuxer)
priv->filename = remove_prefix(priv->filename, prefixes);
char *avdevice_format = NULL;
- if (demuxer->stream->type == STREAMTYPE_AVDEVICE) {
+ if (s->type == STREAMTYPE_AVDEVICE) {
// always require filename in the form "format:filename"
char *sep = strchr(priv->filename, ':');
if (!sep) {
@@ -237,7 +233,7 @@ static int lavf_check_file(demuxer_t *demuxer)
const char *format = lavfdopts->format;
if (!format)
- format = demuxer->stream->lavf_type;
+ format = s->lavf_type;
if (!format)
format = avdevice_format;
if (format) {
@@ -262,38 +258,43 @@ static int lavf_check_file(demuxer_t *demuxer)
if (lavfdopts->probescore)
min_probe = lavfdopts->probescore;
- avpd.buf = av_mallocz(FFMAX(BIO_BUFFER_SIZE, PROBE_BUF_SIZE) +
- FF_INPUT_BUFFER_PADDING_SIZE);
- do {
- read_size = stream_read(demuxer->stream, avpd.buf + probe_data_size,
- read_size);
- if (read_size < 0) {
- av_free(avpd.buf);
- return 0;
- }
- probe_data_size += read_size;
- avpd.filename = priv->filename;
- avpd.buf_size = probe_data_size;
+ AVProbeData avpd = {
+ .filename = priv->filename,
+ .buf_size = 0,
+ .buf = av_mallocz(PROBE_BUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE),
+ };
+
+ while (avpd.buf_size < PROBE_BUF_SIZE) {
+ int nsize = av_clip(avpd.buf_size * 2, INITIAL_PROBE_SIZE,
+ PROBE_BUF_SIZE);
+ int read_size = stream_read(s, avpd.buf + avpd.buf_size,
+ nsize - avpd.buf_size);
+ if (read_size <= 0)
+ break;
- score = 0;
- priv->avif = av_probe_input_format2(&avpd, probe_data_size > 0, &score);
+ avpd.buf_size += read_size;
+
+ int score = 0;
+ priv->avif = av_probe_input_format2(&avpd, avpd.buf_size > 0, &score);
if (priv->avif) {
mp_msg(MSGT_HEADER, MSGL_V, "Found '%s' at score=%d size=%d.\n",
- priv->avif->name, score, probe_data_size);
- }
+ priv->avif->name, score, avpd.buf_size);
- if (priv->avif && score >= min_probe)
- break;
- if (priv->avif && expected_format) {
- if (strcmp(priv->avif->name, expected_format) == 0 &&
- score >= expected_format_probescore)
+ if (score >= min_probe)
break;
+
+ if (expected_format) {
+ if (strcmp(priv->avif->name, expected_format) == 0 &&
+ score >= expected_format_probescore)
+ break;
+ }
}
priv->avif = NULL;
- read_size = FFMIN(2 * read_size, PROBE_BUF_SIZE - probe_data_size);
- } while (read_size > 0 && probe_data_size < PROBE_BUF_SIZE);
+ }
+
+ stream_unread_buffer(s, avpd.buf, avpd.buf_size);
av_free(avpd.buf);
if (!priv->avif) {
diff --git a/demux/demux_ts.c b/demux/demux_ts.c
index 8b2a2d84ba..a16891907d 100644
--- a/demux/demux_ts.c
+++ b/demux/demux_ts.c
@@ -470,7 +470,6 @@ static int ts_check_file(demuxer_t * demuxer)
if(_read < buf_size-1)
{
mp_msg(MSGT_DEMUX, MSGL_V, "COULDN'T READ ENOUGH DATA, EXITING TS_CHECK\n");
- stream_reset(demuxer->stream);
return 0;
}
@@ -992,9 +991,6 @@ static demuxer_t *demux_open_ts(demuxer_t * demuxer)
demuxer->type= DEMUXER_TYPE_MPEG_TS;
demuxer->ts_resets_possible = true;
-
- stream_reset(demuxer->stream);
-
packet_size = ts_check_file(demuxer);
if(!packet_size)
return NULL;
@@ -1079,7 +1075,6 @@ static demuxer_t *demux_open_ts(demuxer_t * demuxer)
start_pos - priv->ts.packet_size;
demuxer->movi_start = start_pos;
demuxer->reference_clock = MP_NOPTS_VALUE;
- stream_reset(demuxer->stream);
stream_seek(demuxer->stream, start_pos); //IF IT'S FROM A PIPE IT WILL FAIL, BUT WHO CARES?
diff --git a/demux/ebml.c b/demux/ebml.c
index 52332cd0c5..98ab1ef306 100644
--- a/demux/ebml.c
+++ b/demux/ebml.c
@@ -308,11 +308,10 @@ int ebml_read_skip_or_resync_cluster(stream_t *s, uint64_t *length)
*length = len + l;
int64_t pos = stream_tell(s);
- stream_skip(s, len);
// When reading corrupted elements, len will often be a random high number,
- // and stream_skip() will set EOF.
- if (s->eof) {
+ // and stream_skip() will fail when skipping past EOF.
+ if (!stream_skip(s, len)) {
stream_seek(s, pos);
goto resync;
}