[MPlayer-dev-eng] [RFC] defines for demux seek flags
Reimar Döffinger
Reimar.Doeffinger at stud.uni-karlsruhe.de
Mon Jan 28 19:54:37 CET 2008
On Mon, Jan 28, 2008 at 06:10:42PM +0200, Uoti Urpala wrote:
> to something which doesn't incorrectly imply a range of 0...100, but
> haven't come up with any good names. 'portion'/'proportion' don't sound
> good to me either.
I've been using 'factor' while testing my idea of doing it (attached one
variant).
But looking at it again and the number of demuxers that make a mess of
it or just do not do it correctly at all I do wonder if there is any
sense in having these flags at all, or at least having them passed to
the demuxers...
-------------- next part --------------
Index: mplayer.c
===================================================================
--- mplayer.c (revision 25894)
+++ mplayer.c (working copy)
@@ -2483,8 +2484,8 @@
}
-// style & 1 == 0 means seek relative to current position, == 1 means absolute
-// style & 2 == 0 means amount in seconds, == 2 means fraction of file length
+// style & SEEK_ABSOLUTE == 0 means seek relative to current position, == 1 means absolute
+// style & SEEK_FACTOR == 0 means amount in seconds, == 2 means fraction of file length
// return -1 if seek failed (non-seekable stream?), 0 otherwise
static int seek(MPContext *mpctx, double amount, int style)
{
@@ -3626,7 +3630,7 @@
}
if (seek_to_sec) {
- seek(mpctx, seek_to_sec, 1);
+ seek(mpctx, seek_to_sec, SEEK_ABSOLUTE);
end_at.pos += seek_to_sec;
}
@@ -3831,7 +3835,7 @@
if(mpctx->loop_times==1) mpctx->loop_times=-1;
play_n_frames=play_n_frames_mf;
mpctx->eof=0;
- abs_seek_pos=1; rel_seek_secs=seek_to_sec;
+ abs_seek_pos=SEEK_ABSOLUTE; rel_seek_secs=seek_to_sec;
loop_seek = 1;
}
Index: libmpdemux/demux_asf.c
===================================================================
--- libmpdemux/demux_asf.c (revision 25894)
+++ libmpdemux/demux_asf.c (working copy)
@@ -522,7 +522,7 @@
//================= seek in ASF ==========================
float p_rate=asf->packetrate; // packets / sec
- off_t rel_seek_packs=(flags&2)? // FIXME: int may be enough?
+ off_t rel_seek_packs=(flags&SEEK_FACTOR)? // FIXME: int may be enough?
(rel_seek_secs*(demuxer->movi_end-demuxer->movi_start)/asf->packetsize):
(rel_seek_secs*p_rate);
off_t rel_seek_bytes=rel_seek_packs*asf->packetsize;
@@ -530,7 +530,7 @@
//printf("ASF: packs: %d duration: %d \n",(int)fileh.packets,*((int*)&fileh.duration));
// printf("ASF_seek: %d secs -> %d packs -> %d bytes \n",
// rel_seek_secs,rel_seek_packs,rel_seek_bytes);
- newpos=((flags&1)?demuxer->movi_start:demuxer->filepos)+rel_seek_bytes;
+ newpos=((flags&SEEK_ABSOLUTE)?demuxer->movi_start:demuxer->filepos)+rel_seek_bytes;
if(newpos<0 || newpos<demuxer->movi_start) newpos=demuxer->movi_start;
// printf("\r -- asf: newpos=%d -- \n",newpos);
stream_seek(demuxer->stream,newpos);
Index: libmpdemux/demux_ts.c
===================================================================
--- libmpdemux/demux_ts.c (revision 25894)
+++ libmpdemux/demux_ts.c (working copy)
@@ -3107,8 +3107,8 @@
video_stats = sh_video->i_bps;
}
- newpos = (flags & 1) ? demuxer->movi_start : demuxer->filepos;
- if(flags & 2) // float seek 0..1
+ newpos = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : demuxer->filepos;
+ if(flags & SEEK_FACTOR) // float seek 0..1
newpos+=(demuxer->movi_end-demuxer->movi_start)*rel_seek_secs;
else
{
Index: libmpdemux/demux_film.c
===================================================================
--- libmpdemux/demux_film.c (revision 25894)
+++ libmpdemux/demux_film.c (working copy)
@@ -49,9 +49,9 @@
static void demux_seek_film(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags)
{
film_data_t *film_data = (film_data_t *)demuxer->priv;
- int new_current_chunk=(flags&1)?0:film_data->current_chunk;
+ int new_current_chunk=(flags&SEEK_ABSOLUTE)?0:film_data->current_chunk;
- if(flags&2)
+ if(flags&SEEK_FACTOR)
new_current_chunk += rel_seek_secs * film_data->total_chunks; // 0..1
else
new_current_chunk += rel_seek_secs * film_data->chunks_per_second; // secs
Index: libmpdemux/demux_ty.c
===================================================================
--- libmpdemux/demux_ty.c (revision 25894)
+++ libmpdemux/demux_ty.c (working copy)
@@ -760,9 +766,9 @@
//================= seek in MPEG ==========================
demuxer->filepos = stream_tell( demuxer->stream );
- newpos = ( flags & 1 ) ? demuxer->movi_start : demuxer->filepos;
+ newpos = ( flags & SEEK_ABSOLUTE ) ? demuxer->movi_start : demuxer->filepos;
- if( flags & 2 )
+ if( flags & SEEK_FACTOR )
// float seek 0..1
newpos += ( demuxer->movi_end - demuxer->movi_start ) * rel_seek_secs;
else
Index: libmpdemux/demux_mov.c
===================================================================
--- libmpdemux/demux_mov.c (revision 25894)
+++ libmpdemux/demux_mov.c (working copy)
@@ -2202,19 +2206,19 @@
static float mov_seek_track(mov_track_t* trak,float pts,int flags){
// printf("MOV track seek called %5.3f \n",pts);
- if(flags&2) pts*=trak->length; else pts*=(float)trak->timescale;
+ if(flags&SEEK_FACTOR) pts*=trak->length; else pts*=(float)trak->timescale;
if(trak->samplesize){
int sample=pts/trak->duration;
// printf("MOV track seek - chunk: %d (pts: %5.3f dur=%d) \n",sample,pts,trak->duration);
- if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative
+ if(!(flags&SEEK_ABSOLUTE)) sample+=trak->chunks[trak->pos].sample; // relative
trak->pos=0;
while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos;
if (trak->pos == trak->chunks_size) return -1;
pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale;
} else {
unsigned int ipts;
- if(!(flags&1)) pts+=trak->samples[trak->pos].pts;
+ if(!(flags&SEEK_ABSOLUTE)) pts+=trak->samples[trak->pos].pts;
if(pts<0) pts=0;
ipts=pts;
//printf("MOV track seek - sample: %d \n",ipts);
Index: libmpdemux/demux_mf.c
===================================================================
--- libmpdemux/demux_mf.c (revision 25894)
+++ libmpdemux/demux_mf.c (working copy)
@@ -18,9 +18,9 @@
static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
mf_t * mf = (mf_t *)demuxer->priv;
sh_video_t * sh_video = demuxer->video->sh;
- int newpos = (flags & 1)?0:mf->curr_frame - 1;
+ int newpos = (flags & SEEK_ABSOLUTE)?0:mf->curr_frame - 1;
- if ( flags & 2 ) newpos+=rel_seek_secs*(mf->nr_of_files - 1);
+ if ( flags & SEEK_FACTOR ) newpos+=rel_seek_secs*(mf->nr_of_files - 1);
else newpos+=rel_seek_secs * sh_video->fps;
if ( newpos < 0 ) newpos=0;
if( newpos >= mf->nr_of_files) newpos=mf->nr_of_files - 1;
Index: libmpdemux/demux_fli.c
===================================================================
--- libmpdemux/demux_fli.c (revision 25894)
+++ libmpdemux/demux_fli.c (working copy)
@@ -25,8 +25,8 @@
static void demux_seek_fli(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
fli_frames_t *frames = (fli_frames_t *)demuxer->priv;
sh_video_t *sh_video = demuxer->video->sh;
- int newpos=(flags&1)?0:frames->current_frame;
- if(flags&2){
+ int newpos=(flags&SEEK_ABSOLUTE)?0:frames->current_frame;
+ if(flags&SEEK_FACTOR){
// float 0..1
newpos+=rel_seek_secs*frames->num_frames;
} else {
Index: libmpdemux/demux_rawaudio.c
===================================================================
--- libmpdemux/demux_rawaudio.c (revision 25894)
+++ libmpdemux/demux_rawaudio.c (working copy)
@@ -84,8 +84,8 @@
sh_audio_t* sh_audio = demuxer->audio->sh;
off_t base,pos;
- base = (flags & 1) ? demuxer->movi_start : stream_tell(s);
- if(flags & 2)
+ base = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : stream_tell(s);
+ if(flags & SEEK_FACTOR)
pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
else
pos = base + (rel_seek_secs*sh_audio->i_bps);
Index: libmpdemux/demux_mpc.c
===================================================================
--- libmpdemux/demux_mpc.c (revision 25894)
+++ libmpdemux/demux_mpc.c (working copy)
@@ -156,9 +156,9 @@
da_priv_t* priv = demuxer->priv;
stream_t* s = demuxer->stream;
float target = rel_seek_secs;
- if (flags & 2)
+ if (flags & SEEK_FACTOR)
target *= priv->length;
- if (!(flags & 1))
+ if (!(flags & SEEK_ABSOLUTE))
target += priv->last_pts;
if (target < priv->last_pts) {
stream_seek(s, demuxer->movi_start);
Index: libmpdemux/demux_mpg.c
===================================================================
--- libmpdemux/demux_mpg.c (revision 25894)
+++ libmpdemux/demux_mpg.c (working copy)
@@ -893,14 +893,14 @@
float oldpts = 0;
off_t oldpos = demuxer->filepos;
float newpts = 0;
- off_t newpos = (flags & 1) ? demuxer->movi_start : oldpos;
+ off_t newpos = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : oldpos;
if(mpg_d)
oldpts = mpg_d->last_pts;
- newpts = (flags & 1) ? 0.0 : oldpts;
+ newpts = (flags & SEEK_ABSOLUTE) ? 0.0 : oldpts;
//================= seek in MPEG ==========================
//calculate the pts to seek to
- if(flags & 2) {
+ if(flags & SEEK_FACTOR) {
if (mpg_d && mpg_d->first_to_final_pts_len > 0.0)
newpts += mpg_d->first_to_final_pts_len * rel_seek_secs;
else
@@ -909,7 +909,7 @@
newpts += rel_seek_secs;
if (newpts < 0) newpts = 0;
- if(flags&2){
+ if(flags&SEEK_FACTOR){
// float seek 0..1
newpos+=(demuxer->movi_end-demuxer->movi_start)*rel_seek_secs;
} else {
Index: libmpdemux/demux_real.c
===================================================================
--- libmpdemux/demux_real.c (revision 25894)
+++ libmpdemux/demux_real.c (working copy)
@@ -1813,10 +1821,9 @@
if (!streams)
return;
- if (flags & 1)
- /* seek absolute */
+ if (flags & SEEK_ABSOLUTE)
priv->current_apacket = priv->current_vpacket = 0;
- if (flags & 2) // percent seek
+ if (flags & SEEK_FACTOR)
rel_seek_secs *= priv->duration;
if ((streams & 1) && priv->current_vpacket >= priv->index_table_size[vid])
Index: libmpdemux/demux_audio.c
===================================================================
--- libmpdemux/demux_audio.c (revision 25894)
+++ libmpdemux/demux_audio.c (working copy)
@@ -646,8 +648,8 @@
s = demuxer->stream;
priv = demuxer->priv;
- if(priv->frmt == MP3 && hr_mp3_seek && !(flags & 2)) {
- len = (flags & 1) ? rel_seek_secs - priv->next_pts : rel_seek_secs;
+ if(priv->frmt == MP3 && hr_mp3_seek && !(flags & SEEK_FACTOR)) {
+ len = (flags & SEEK_ABSOLUTE) ? rel_seek_secs - priv->next_pts : rel_seek_secs;
if(len < 0) {
stream_seek(s,demuxer->movi_start);
len = priv->next_pts + len;
@@ -658,8 +660,8 @@
return;
}
- base = flags&1 ? demuxer->movi_start : stream_tell(s);
- if(flags&2)
+ base = flags&SEEK_ABSOLUTE ? demuxer->movi_start : stream_tell(s);
+ if(flags&SEEK_FACTOR)
pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
else
pos = base + (rel_seek_secs*sh_audio->i_bps);
Index: libmpdemux/demux_ogg.c
===================================================================
--- libmpdemux/demux_ogg.c (revision 25894)
+++ libmpdemux/demux_ogg.c (working copy)
@@ -1366,8 +1368,8 @@
old_pos = ogg_d->pos;
//calculate the granulepos to seek to
- gp = flags & 1 ? 0 : os->lastpos;
- if(flags & 2) {
+ gp = flags & SEEK_ABSOLUTE ? 0 : os->lastpos;
+ if(flags & SEEK_FACTOR) {
if (ogg_d->final_granulepos > 0)
gp += ogg_d->final_granulepos * rel_seek_secs;
else
@@ -1392,8 +1394,8 @@
pos = ogg_d->syncpoints[sp].page_pos;
precision = 0;
} else {
- pos = flags & 1 ? 0 : ogg_d->pos;
- if(flags & 2)
+ pos = flags & SEEK_ABSOLUTE ? 0 : ogg_d->pos;
+ if(flags & SEEK_FACTOR)
pos += (demuxer->movi_end - demuxer->movi_start) * rel_seek_secs;
else {
if (ogg_d->final_granulepos > 0) {
Index: libmpdemux/demux_xmms.c
===================================================================
--- libmpdemux/demux_xmms.c (revision 25894)
+++ libmpdemux/demux_xmms.c (working copy)
@@ -350,8 +350,8 @@
if(priv->ip->get_time()<0) return;
- pos = (flags & 1) ? 0 : priv->spos / sh_audio->wf->nAvgBytesPerSec;
- if (flags & 2)
+ pos = (flags & SEEK_ABSOLUTE) ? 0 : priv->spos / sh_audio->wf->nAvgBytesPerSec;
+ if (flags & SEEK_FACTOR)
pos+= rel_seek_secs*xmms_length;
else
pos+= rel_seek_secs;
Index: libmpdemux/demux_lavf.c
===================================================================
--- libmpdemux/demux_lavf.c (revision 25894)
+++ libmpdemux/demux_lavf.c (working copy)
@@ -612,12 +614,12 @@
int avsflags = 0;
mp_msg(MSGT_DEMUX,MSGL_DBG2,"demux_seek_lavf(%p, %f, %f, %d)\n", demuxer, rel_seek_secs, audio_delay, flags);
- if (flags & 1) { // absolute seek
+ if (flags & SEEK_ABSOLUTE) {
priv->last_pts = priv->avfc->start_time;
} else {
if (rel_seek_secs < 0) avsflags = AVSEEK_FLAG_BACKWARD;
}
- if (flags & 2) { // percent seek
+ if (flags & SEEK_FACTOR) {
if (priv->avfc->duration == 0 || priv->avfc->duration == AV_NOPTS_VALUE)
return;
priv->last_pts += rel_seek_secs * priv->avfc->duration;
Index: libmpdemux/demux_vqf.c
===================================================================
--- libmpdemux/demux_vqf.c (revision 25894)
+++ libmpdemux/demux_vqf.c (working copy)
@@ -186,8 +186,8 @@
sh_audio_t* sh_audio = demuxer->audio->sh;
off_t base,pos;
- base = (flags & 1) ? demuxer->movi_start : stream_tell(s);
- if(flags & 2)
+ base = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : stream_tell(s);
+ if(flags & SEEK_FACTOR)
pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
else
pos = base + (rel_seek_secs*sh_audio->i_bps);
Index: libmpdemux/demux_nut.c
===================================================================
--- libmpdemux/demux_nut.c (revision 25894)
+++ libmpdemux/demux_nut.c (working copy)
@@ -247,12 +247,12 @@
int ret;
const int tmp[] = { 0, -1 };
- if (!(flags & 1)) {
+ if (!(flags & SEEK_ABSOLUTE)) {
nutflags |= 1; // relative
if (time_pos > 0) nutflags |= 2; // forwards
}
- if (flags & 2) // percent
+ if (flags & SEEK_FACTOR)
time_pos *= priv->s[0].max_pts *
(double)priv->s[0].time_base.num /
priv->s[0].time_base.den;
Index: libmpdemux/demuxer.c
===================================================================
--- libmpdemux/demuxer.c (revision 25894)
+++ libmpdemux/demuxer.c (working copy)
@@ -973,7 +973,7 @@
if(sh_video) sh_video->timer=0; // !!!!!!
#endif
- if(flags & 1) // absolute seek
+ if(flags & SEEK_ABSOLUTE)
pts = 0.0f;
else {
if(demuxer->stream_pts == MP_NOPTS_VALUE)
@@ -981,7 +981,7 @@
pts = demuxer->stream_pts;
}
- if(flags & 2) { // percent seek
+ if(flags & SEEK_FACTOR) {
if(stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, &tmp) == STREAM_UNSUPPORTED)
goto dmx_seek;
pts += tmp * rel_seek_secs;
Index: libmpdemux/demuxer.h
===================================================================
--- libmpdemux/demuxer.h (revision 25894)
+++ libmpdemux/demuxer.h (working copy)
@@ -83,6 +83,9 @@
#define DEMUXER_CTRL_SWITCH_VIDEO 14
#define DEMUXER_CTRL_IDENTIFY_PROGRAM 15
+#define SEEK_ABSOLUTE (1 << 0)
+#define SEEK_FACTOR (1 << 1)
+
// Holds one packet/frame/whatever
typedef struct demux_packet_st {
int len;
Index: libmpdemux/demux_avi.c
===================================================================
--- libmpdemux/demux_avi.c (revision 25894)
+++ libmpdemux/demux_avi.c (working copy)
@@ -571,12 +586,12 @@
int video_chunk_pos=d_video->pos;
int i;
- if(flags&1){
+ if(flags&SEEK_ABSOLUTE){
// seek absolute
video_chunk_pos=0;
}
- if(flags&2){
+ if(flags&SEEK_FACTOR){
rel_seek_frames=rel_seek_secs*priv->numberofframes;
}
Index: libmpdemux/demux_rawvideo.c
===================================================================
--- libmpdemux/demux_rawvideo.c (revision 25894)
+++ libmpdemux/demux_rawvideo.c (working copy)
@@ -124,8 +124,8 @@
sh_video_t* sh_video = demuxer->video->sh;
off_t pos;
- pos = (flags & 1) ? demuxer->movi_start : stream_tell(s);
- if(flags & 2)
+ pos = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : stream_tell(s);
+ if(flags & SEEK_FACTOR)
pos += ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
else
pos += (rel_seek_secs*sh_video->i_bps);
Index: libmpdemux/demux_rawdv.c
===================================================================
--- libmpdemux/demux_rawdv.c (revision 25894)
+++ libmpdemux/demux_rawdv.c (working copy)
@@ -38,8 +38,8 @@
{
rawdv_frames_t *frames = (rawdv_frames_t *)demuxer->priv;
sh_video_t *sh_video = demuxer->video->sh;
- off_t newpos=(flags&1)?0:frames->current_frame;
- if(flags&2)
+ off_t newpos=(flags&SEEK_ABSOLUTE)?0:frames->current_frame;
+ if(flags&SEEK_FACTOR)
{
// float 0..1
newpos+=rel_seek_secs*frames->frame_number;
Index: libmpdemux/demux_aac.c
===================================================================
--- libmpdemux/demux_aac.c (revision 25894)
+++ libmpdemux/demux_aac.c (working copy)
@@ -218,7 +218,7 @@
ds_free_packs(d_audio);
- time = (flags & 1) ? rel_seek_secs - priv->last_pts : rel_seek_secs;
+ time = (flags & SEEK_ABSOLUTE) ? rel_seek_secs - priv->last_pts : rel_seek_secs;
if(time < 0)
{
stream_seek(demuxer->stream, demuxer->movi_start);
Index: libmpdemux/demux_avs.c
===================================================================
--- libmpdemux/demux_avs.c (revision 25894)
+++ libmpdemux/demux_avs.c (working copy)
@@ -418,10 +418,8 @@
//mp_msg(MSGT_DEMUX, MSGL_V, "AVS: seek rel_seek_secs = %f - flags = %x\n", rel_seek_secs, flags);
- // seek absolute
- if (flags&1) video_pos=0;
- // seek precent
- if (flags&2) rel_seek_secs *= duration;
+ if (flags&SEEK_ABSOLUTE) video_pos=0;
+ if (flags&SEEK_FACTOR) rel_seek_secs *= duration;
video_pos += rel_seek_secs;
if (video_pos < 0) video_pos = 0;
Index: libmpdemux/demux_mkv.c
===================================================================
--- libmpdemux/demux_mkv.c (revision 25894)
+++ libmpdemux/demux_mkv.c (working copy)
@@ -2534,7 +2534,8 @@
mkv_d->has_first_tc = 1;
}
demux_mkv_seek (demuxer,
- demuxer->chapters[dvd_chapter-1].start/1000.0, 0.0, 1);
+ demuxer->chapters[dvd_chapter-1].start/1000.0, 0.0,
+ SEEK_ABSOLUTE);
}
}
@@ -3289,14 +3290,14 @@
demux_mkv_seek (demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags)
{
free_cached_dps (demuxer);
- if (!(flags & 2)) /* time in secs */
+ if (!(flags & SEEK_FACTOR)) /* time in secs */
{
mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
stream_t *s = demuxer->stream;
int64_t target_timecode = 0, diff, min_diff=0xFFFFFFFFFFFFFFFLL;
int i;
- if (!(flags & 1)) /* relative seek */
+ if (!(flags & SEEK_ABSOLUTE)) /* relative seek */
target_timecode = (int64_t) (mkv_d->last_pts * 1000.0);
target_timecode += (int64_t)(rel_seek_secs * 1000.0);
if (target_timecode < 0)
@@ -3371,7 +3372,7 @@
diff = target_timecode + mkv_d->first_tc -
(int64_t) mkv_d->indexes[i].timecode * mkv_d->tc_scale / 1000000.0;
- if ((flags & 1 || target_timecode <= mkv_d->last_pts*1000)) {
+ if ((flags & SEEK_ABSOLUTE || target_timecode <= mkv_d->last_pts*1000)) {
// Absolute seek or seek backward: find the last index
// position before target time
if (diff < 0 || diff >= min_diff)
@@ -3408,7 +3409,7 @@
demux_mkv_fill_buffer(demuxer, NULL);
}
- else if ((demuxer->movi_end <= 0) || !(flags & 1))
+ else if ((demuxer->movi_end <= 0) || !(flags & SEEK_ABSOLUTE))
mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n");
else
{
More information about the MPlayer-dev-eng
mailing list