summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-11-16 21:04:28 +0100
committerwm4 <wm4@nowhere>2013-11-16 21:46:17 +0100
commita2a24b957ec7dae8b9d312af8292b5e5e82d77be (patch)
treec4d9ad9cd7196a5f3ea5f8d83b570e55fb27b3a9 /demux
parent0cdbc6db6ea1ee6cdeedec6c8bd84e692d5f82d3 (diff)
downloadmpv-a2a24b957ec7dae8b9d312af8292b5e5e82d77be.tar.bz2
mpv-a2a24b957ec7dae8b9d312af8292b5e5e82d77be.tar.xz
demux: simplify handling of filepos field
demuxer->filepos contains the byte offset of the last read packet. This is so that the player can estimate the current playback position, if no proper timestamps are available. Simplify it to use demux_packet->pos in the generic demuxer code, instead of bothering every demuxer implementation about it. (Note that this is still a bit incorrect: it relfects the position of the last packet read by the demuxer, not that returned to the user. But that was already broken, and is not that trivial to fix.)
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c4
-rw-r--r--demux/demux_lavf.c4
-rw-r--r--demux/demux_mkv.c11
-rw-r--r--demux/demux_packet.h2
4 files changed, 12 insertions, 9 deletions
diff --git a/demux/demux.c b/demux/demux.c
index d9cf3b37dd..983a96c90a 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -133,6 +133,7 @@ static struct demux_packet *create_packet(size_t len)
.pts = MP_NOPTS_VALUE,
.duration = -1,
.stream_pts = MP_NOPTS_VALUE,
+ .pos = -1,
};
return dp;
}
@@ -339,6 +340,9 @@ int demuxer_add_packet(demuxer_t *demuxer, struct sh_stream *stream,
* appear. */
ds->eof = 0;
+ if (dp->pos >= 0)
+ demuxer->filepos = dp->pos;
+
mp_dbg(MSGT_DEMUXER, MSGL_DBG2,
"DEMUX: Append packet to %s, len=%d pts=%5.3f pos=%"PRIu64" "
"[packs: A=%d V=%d S=%d]\n", stream_type_name(stream->type),
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index 946c76fb84..33c8d1b667 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -707,8 +707,6 @@ static int read_more_av_packets(demuxer_t *demux)
if (priv->num_packets >= MAX_PKT_QUEUE)
return -1;
- demux->filepos = stream_tell(demux->stream);
-
AVPacket *pkt = talloc(NULL, AVPacket);
if (av_read_frame(priv->avfc, pkt) < 0) {
talloc_free(pkt);
@@ -795,7 +793,7 @@ static int demux_lavf_fill_buffer(demuxer_t *demux)
if (pkt->convergence_duration > 0)
dp->duration = pkt->convergence_duration * av_q2d(st->time_base);
}
- dp->pos = demux->filepos;
+ dp->pos = pkt->pos;
dp->keyframe = pkt->flags & AV_PKT_FLAG_KEY;
// Use only one stream for stream_pts, otherwise PTS might be jumpy.
if (stream->type == STREAM_VIDEO) {
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 092b86fa62..5258bee5d5 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -2004,7 +2004,7 @@ static void handle_realvideo(demuxer_t *demuxer, mkv_track_t *track,
track->stream->video->bih->biCompression,
&track->rv_kf_base, &track->rv_kf_pts, NULL);
}
- dp->pos = demuxer->filepos;
+ dp->pos = mkv_d->last_filepos;
dp->keyframe = keyframe;
demuxer_add_packet(demuxer, track->stream, dp);
@@ -2083,7 +2083,7 @@ static void handle_realaudio(demuxer_t *demuxer, mkv_track_t *track,
(track->ra_pts == mkv_d->last_pts) ? 0 : (mkv_d->last_pts);
track->ra_pts = mkv_d->last_pts;
if (track->sub_packet_cnt == 0)
- track->audio_filepos = demuxer->filepos;
+ track->audio_filepos = mkv_d->last_filepos;
if (++(track->sub_packet_cnt) == sph) {
int apk_usize = track->stream->audio->wf->nBlockAlign;
track->sub_packet_cnt = 0;
@@ -2108,7 +2108,7 @@ static void handle_realaudio(demuxer_t *demuxer, mkv_track_t *track,
dp->pts = mkv_d->last_pts;
track->ra_pts = mkv_d->last_pts;
- dp->pos = demuxer->filepos;
+ dp->pos = mkv_d->last_filepos;
dp->keyframe = keyframe;
demuxer_add_packet(demuxer, track->stream, dp);
}
@@ -2225,6 +2225,7 @@ struct block_info {
mkv_track_t *track;
bstr data;
void *alloc;
+ int64_t filepos;
};
static void free_block(struct block_info *block)
@@ -2260,7 +2261,7 @@ static int read_block(demuxer_t *demuxer, struct block_info *block)
if (!block->alloc)
goto exit;
block->data = (bstr){block->alloc, length};
- demuxer->filepos = stream_tell(s);
+ block->filepos = stream_tell(s);
if (stream_read(s, block->data.start, block->data.len) != block->data.len)
goto exit;
@@ -2350,7 +2351,7 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info)
if (use_this_block) {
mkv_d->last_pts = current_pts;
- mkv_d->last_filepos = demuxer->filepos;
+ mkv_d->last_filepos = block_info->filepos;
for (int i = 0; i < laces; i++) {
bstr block = bstr_splice(data, 0, lace_size[i]);
diff --git a/demux/demux_packet.h b/demux/demux_packet.h
index 25731d914a..0d1a6e6f03 100644
--- a/demux/demux_packet.h
+++ b/demux/demux_packet.h
@@ -28,7 +28,7 @@ typedef struct demux_packet {
double pts;
double duration;
double stream_pts;
- int64_t pos; // position in index (AVI) or file (MPG)
+ int64_t pos; // position in source file byte stream
unsigned char *buffer;
bool keyframe;
struct demux_packet *next;