1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-21 23:36:58 +00:00

stream: kill start_pos, remove --sb option

stream.start_pos was needed for optical media only, and (apparently) not
for very good reasons. Just get rid of it.

For stream_dvd, we don't need to do anything. Byte seeking was already
removed from it earlier.

For stream_cdda and stream_vcd, emulate the start_pos by offsetting the
stream pos as seen by the rest of mpv.

The bits in discnav.c and loadfile.c were for dealing with the code
seeking back to the start in demux.c. Handle this differently by
assuming the demuxer is always initialized with the stream at start
position, and instead seek back if initializing the demuxer fails.

Remove the --sb option, which worked by modifying stream.start_pos. If
someone really wants this option, it could be added back by creating a
"slice" stream (actually ffmpeg already has such a thing).
This commit is contained in:
wm4 2014-05-24 14:03:07 +02:00
parent 3316cf5f9b
commit e3c20bf350
21 changed files with 34 additions and 55 deletions

View File

@ -583,7 +583,7 @@ Property list
``file-size``
Length in bytes of the source file/stream. (This is the same as
``${stream-end} - ${stream-start}``. For ordered chapters and such, the
``${stream-end}``. For ordered chapters and such, the
size of the currently played segment is returned.)
``path``
@ -610,9 +610,6 @@ Property list
``stream-pos`` (RW)
Raw byte position in source stream.
``stream-start``
Raw start byte offset in source stream (rarely different from 0).
``stream-end``
Raw end position in bytes in source stream.

View File

@ -1832,10 +1832,6 @@ OPTIONS
This behavior is disabled by default, but is always available when quitting
the player with Shift+Q.
``--sb=<n>``
Seek to byte position. Useful for playback from CD-ROM images or VOB files
with junk at the beginning. See also ``--start``.
``--screen=<default|0-32>``
In multi-monitor configurations (i.e. a single desktop that spans across
multiple displays), this option tells mpv which screen to display the

View File

@ -599,7 +599,7 @@ static struct demuxer *open_given_type(struct mpv_global *global,
.metadata = talloc_zero(demuxer, struct mp_tags),
};
demuxer->params = params; // temporary during open()
stream_seek(stream, stream->start_pos);
int64_t start_pos = stream_tell(stream);
mp_verbose(log, "Trying demuxer: %s (force-level: %s)\n",
desc->name, d_level(check));
@ -634,6 +634,7 @@ static struct demuxer *open_given_type(struct mpv_global *global,
}
free_demuxer(demuxer);
stream_seek(stream, start_pos);
return NULL;
}

View File

@ -140,10 +140,10 @@ static int64_t mp_seek(void *opaque, int64_t pos, int whence)
else if (whence == SEEK_END && stream->end_pos > 0)
pos += stream->end_pos;
else if (whence == SEEK_SET)
pos += stream->start_pos;
/* ok */;
else if (whence == AVSEEK_SIZE && stream->end_pos > 0) {
stream_update_size(stream);
return stream->end_pos - stream->start_pos;
return stream->end_pos;
} else
return -1;
@ -155,7 +155,7 @@ static int64_t mp_seek(void *opaque, int64_t pos, int whence)
return -1;
}
return pos - stream->start_pos;
return pos;
}
static int64_t mp_read_seek(void *opaque, int stream_idx, int64_t ts, int flags)
@ -828,7 +828,7 @@ static void demux_seek_lavf(demuxer_t *demuxer, float rel_seek_secs, int flags)
!(priv->avif->flags & AVFMT_NO_BYTE_SEEK))
{
avsflags |= AVSEEK_FLAG_BYTE;
priv->last_pts = (s->end_pos - s->start_pos) * rel_seek_secs;
priv->last_pts = s->end_pos * rel_seek_secs;
} else if (priv->avfc->duration != 0 &&
priv->avfc->duration != AV_NOPTS_VALUE)
{

View File

@ -200,7 +200,7 @@ static int raw_fill_buffer(demuxer_t *demuxer)
return 0;
struct demux_packet *dp = new_demux_packet(p->frame_size * p->read_frames);
dp->pos = stream_tell(demuxer->stream) - demuxer->stream->start_pos;
dp->pos = stream_tell(demuxer->stream);
dp->pts = (dp->pos / p->frame_size) / p->frame_rate;
int len = stream_read(demuxer->stream, dp->buffer, dp->len);
@ -215,11 +215,10 @@ static void raw_seek(demuxer_t *demuxer, float rel_seek_secs, int flags)
struct priv *p = demuxer->priv;
stream_t *s = demuxer->stream;
stream_update_size(s);
int64_t start = s->start_pos;
int64_t end = s->end_pos;
int64_t pos = (flags & SEEK_ABSOLUTE) ? start : stream_tell(s);
int64_t pos = (flags & SEEK_ABSOLUTE) ? 0 : stream_tell(s);
if (flags & SEEK_FACTOR)
pos += (end - start) * rel_seek_secs;
pos += end * rel_seek_secs;
else
pos += rel_seek_secs * p->frame_rate * p->frame_size;
if (pos < 0)
@ -237,12 +236,11 @@ static int raw_control(demuxer_t *demuxer, int cmd, void *arg)
case DEMUXER_CTRL_GET_TIME_LENGTH: {
stream_t *s = demuxer->stream;
stream_update_size(s);
int64_t start = s->start_pos;
int64_t end = s->end_pos;
if (!end)
return DEMUXER_CTRL_DONTKNOW;
*((double *) arg) = ((end - start) / p->frame_size) / p->frame_rate;
*((double *) arg) = (end / p->frame_size) / p->frame_rate;
return DEMUXER_CTRL_OK;
}
default:

View File

@ -281,8 +281,6 @@ const m_option_t mp_opts[] = {
OPT_CHOICE_OR_INT("frames", play_frames, M_OPT_FIXED, 0, INT_MAX,
({"all", -1})),
// seek to byte/seconds position
OPT_INT64("sb", seek_to_byte, 0),
OPT_REL_TIME("start", play_start, 0),
OPT_REL_TIME("end", play_end, 0),
OPT_REL_TIME("length", play_length, 0),

View File

@ -149,7 +149,6 @@ typedef struct MPOpts {
struct m_rel_time play_length;
int play_frames;
double step_sec;
int64_t seek_to_byte;
int position_resume;
int position_save_on_quit;
int pause;

View File

@ -206,7 +206,7 @@ static int mp_property_file_size(m_option_t *prop, int action, void *arg,
if (!mpctx->stream)
return M_PROPERTY_UNAVAILABLE;
int64_t size = mpctx->stream->end_pos - mpctx->stream->start_pos;
int64_t size = mpctx->stream->end_pos;
switch (action) {
case M_PROPERTY_GET: {
@ -297,16 +297,6 @@ static int mp_property_stream_pos(m_option_t *prop, int action, void *arg,
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Stream start offset (RO)
static int mp_property_stream_start(m_option_t *prop, int action,
void *arg, MPContext *mpctx)
{
struct stream *stream = mpctx->stream;
if (!stream)
return M_PROPERTY_UNAVAILABLE;
return m_property_int64_ro(prop, action, arg, stream->start_pos);
}
/// Stream end offset (RO)
static int mp_property_stream_end(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
@ -2345,8 +2335,6 @@ static const m_option_t mp_properties[] = {
0, 0, 0, NULL },
{ "stream-pos", mp_property_stream_pos, CONF_TYPE_INT64,
M_OPT_MIN, 0, 0, NULL },
{ "stream-start", mp_property_stream_start, CONF_TYPE_INT64,
M_OPT_MIN, 0, 0, NULL },
{ "stream-end", mp_property_stream_end, CONF_TYPE_INT64,
M_OPT_MIN, 0, 0, NULL },
{ "stream-time-pos", mp_property_stream_time_pos, CONF_TYPE_TIME,

View File

@ -123,8 +123,6 @@ void mp_nav_reset(struct MPContext *mpctx)
nav->nav_draining = false;
nav->nav_still_frame = 0;
mp_input_disable_section(mpctx->input, "discnav-menu");
// Prevent demuxer init code to seek to the "start"
mpctx->stream->start_pos = stream_tell(mpctx->stream);
stream_control(mpctx->stream, STREAM_CTRL_RESUME_CACHE, NULL);
update_state(mpctx);
}

View File

@ -1110,8 +1110,6 @@ static void play_current_file(struct MPContext *mpctx)
}
mpctx->initialized_flags |= INITIALIZED_STREAM;
mpctx->stream->start_pos += opts->seek_to_byte;
if (opts->stream_dump && opts->stream_dump[0]) {
stream_dump(mpctx);
goto terminate_playback;
@ -1267,10 +1265,8 @@ goto_reopen_demuxer: ;
else
dir = DVB_CHANNEL_LOWER;
if (dvb_step_channel(mpctx->stream, dir)) {
if (dvb_step_channel(mpctx->stream, dir))
mpctx->stop_play = PT_RELOAD_DEMUXER;
mpctx->stream->start_pos = stream_tell(mpctx->stream);
}
}
#endif
goto terminate_playback;

View File

@ -173,8 +173,8 @@ void stream_dump(struct MPContext *mpctx)
while (mpctx->stop_play == KEEP_PLAYING && !stream->eof) {
if (!opts->quiet && ((stream->pos / (1024 * 1024)) % 2) == 1) {
uint64_t pos = stream->pos - stream->start_pos;
uint64_t end = stream->end_pos - stream->start_pos;
uint64_t pos = stream->pos;
uint64_t end = stream->end_pos;
MP_MSG(mpctx, MSGL_STATUS, "Dumping %lld/%lld...",
(long long int)pos, (long long int)end);
}

View File

@ -472,11 +472,11 @@ double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
ans = MPCLAMP((pos - start) / len, 0, 1);
} else {
struct stream *s = demuxer->stream;
int64_t size = s->end_pos - s->start_pos;
int64_t size = s->end_pos;
int64_t fpos = demuxer->filepos >= 0 ?
demuxer->filepos : stream_tell(demuxer->stream);
if (size > 0)
ans = MPCLAMP((double)(fpos - s->start_pos) / size, 0, 1);
ans = MPCLAMP(fpos / (double)size, 0, 1);
}
if (use_range) {
if (mpctx->opts->play_frames > 0)

View File

@ -815,7 +815,6 @@ int stream_enable_cache(stream_t **stream, struct mp_cache_opts *opts)
cache->safe_origin = orig->safe_origin;
cache->opts = orig->opts;
cache->global = orig->global;
cache->start_pos = orig->start_pos;
cache->end_pos = orig->end_pos;
cache->log = mp_log_new(cache, cache->global->log, "cache");

View File

@ -147,7 +147,7 @@ typedef struct stream {
int sector_size; // sector size (seek will be aligned on this size if non 0)
int read_chunk; // maximum amount of data to read at once to limit latency
unsigned int buf_pos, buf_len;
int64_t pos, start_pos, end_pos;
int64_t pos, end_pos;
int eof;
int mode; //STREAM_READ or STREAM_WRITE
bool streaming; // known to be a network stream if true

View File

@ -202,6 +202,8 @@ static int seek(stream_t *s, int64_t newpos)
int seek_to_track = 0;
int i;
newpos += priv->start_sector * CDIO_CD_FRAMESIZE_RAW;
sec = newpos / CDIO_CD_FRAMESIZE_RAW;
if (newpos < 0 || sec > p->end_sector) {
p->sector = p->end_sector + 1;
@ -388,8 +390,8 @@ static int open_cdda(stream_t *st, int m)
priv->sector = priv->start_sector;
st->priv = priv;
st->start_pos = priv->start_sector * CDIO_CD_FRAMESIZE_RAW;
st->end_pos = (priv->end_sector + 1) * CDIO_CD_FRAMESIZE_RAW;
st->end_pos =
(priv->end_sector + 1 - priv->start_sector) * CDIO_CD_FRAMESIZE_RAW;
st->sector_size = CDIO_CD_FRAMESIZE_RAW;
st->fill_buffer = fill_buffer;

View File

@ -918,7 +918,6 @@ static int open_s(stream_t *stream, int mode)
stream->fill_buffer = fill_buffer;
stream->control = control;
stream->close = stream_dvd_close;
stream->start_pos = (int64_t)d->cur_pack*2048;
stream->end_pos = (int64_t)(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048;
MP_VERBOSE(stream, "DVD start=%d end=%d \n",d->cur_pack,d->cur_pgc->cell_playback[d->last_cell-1].last_sector);
stream->priv = (void*)d;

View File

@ -59,7 +59,7 @@
#include "osdep/io.h"
static int fill_buffer(stream_t *s, char* buffer, int max_len){
if(s->pos > s->end_pos) /// don't past end of current track
if(s->pos > s->end_pos) /// don't read past end of current track
return 0;
if (max_len < VCD_SECTOR_DATA)
return -1;
@ -67,7 +67,9 @@ static int fill_buffer(stream_t *s, char* buffer, int max_len){
}
static int seek(stream_t *s,int64_t newpos) {
vcd_set_msf(s->priv,newpos/VCD_SECTOR_DATA);
mp_vcd_priv_t *vcd = s->priv;
newpos += vcd->start;
vcd_set_msf(vcd,newpos/VCD_SECTOR_DATA);
return 1;
}
@ -162,8 +164,7 @@ static int open_s(stream_t *stream,int mode)
#endif
stream->sector_size = VCD_SECTOR_DATA;
stream->start_pos=ret;
stream->end_pos=ret2;
stream->end_pos=ret2-ret;
stream->priv = vcd;
stream->fill_buffer = fill_buffer;
@ -171,6 +172,9 @@ static int open_s(stream_t *stream,int mode)
stream->close = close_s;
stream->demuxer = "lavf"; // mpegps ( or "vcd"?)
vcd->start = ret;
seek(stream, 0);
return STREAM_OK;
}

View File

@ -42,6 +42,7 @@ static int sun_vcd_read(mp_vcd_priv_t*, int*);
#endif
struct mp_vcd_priv_st {
int start;
stream_t *stream;
int fd;
struct cdrom_tocentry entry;

View File

@ -50,6 +50,7 @@ typedef struct
typedef struct mp_vcd_priv_st
{
int start;
stream_t *stream;
int fd;
cdsector_t buf;

View File

@ -61,6 +61,7 @@ typedef struct ioc_read_toc_single_entry vcd_tocentry;
#endif
typedef struct mp_vcd_priv_st {
int start;
int fd;
vcd_tocentry entry;
#ifdef VCD_NETBSD

View File

@ -34,6 +34,7 @@ typedef struct mp_vcd_priv_st mp_vcd_priv_t;
we cache the information in mp_vcd_priv_st.
*/
struct mp_vcd_priv_st {
int start;
HANDLE hd;
CDROM_TOC toc;
unsigned sect;