Mercurial > mplayer.hg
changeset 25883:baf32110d3fc
Use defines to give names to the different seek flags.
A better solution should be considered later, esp. for the many
broken demuxers that do not treat these flags correctly.
author | reimar |
---|---|
date | Tue, 29 Jan 2008 15:11:38 +0000 |
parents | 2ad528dd42a0 |
children | f6697d25b040 |
files | libmpdemux/demux_aac.c libmpdemux/demux_asf.c libmpdemux/demux_audio.c libmpdemux/demux_avi.c libmpdemux/demux_avs.c libmpdemux/demux_film.c libmpdemux/demux_fli.c libmpdemux/demux_lavf.c libmpdemux/demux_mf.c libmpdemux/demux_mkv.c libmpdemux/demux_mov.c libmpdemux/demux_mpc.c libmpdemux/demux_mpg.c libmpdemux/demux_nut.c libmpdemux/demux_ogg.c libmpdemux/demux_rawaudio.c libmpdemux/demux_rawdv.c libmpdemux/demux_rawvideo.c libmpdemux/demux_real.c libmpdemux/demux_ts.c libmpdemux/demux_ty.c libmpdemux/demux_vqf.c libmpdemux/demux_xmms.c libmpdemux/demuxer.c libmpdemux/demuxer.h mplayer.c |
diffstat | 26 files changed, 65 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpdemux/demux_aac.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_aac.c Tue Jan 29 15:11:38 2008 +0000 @@ -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);
--- a/libmpdemux/demux_asf.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_asf.c Tue Jan 29 15:11:38 2008 +0000 @@ -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);
--- a/libmpdemux/demux_audio.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_audio.c Tue Jan 29 15:11:38 2008 +0000 @@ -646,8 +646,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 +658,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);
--- a/libmpdemux/demux_avi.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_avi.c Tue Jan 29 15:11:38 2008 +0000 @@ -571,12 +571,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; }
--- a/libmpdemux/demux_avs.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_avs.c Tue Jan 29 15:11:38 2008 +0000 @@ -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;
--- a/libmpdemux/demux_film.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_film.c Tue Jan 29 15:11:38 2008 +0000 @@ -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
--- a/libmpdemux/demux_fli.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_fli.c Tue Jan 29 15:11:38 2008 +0000 @@ -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 {
--- a/libmpdemux/demux_lavf.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_lavf.c Tue Jan 29 15:11:38 2008 +0000 @@ -614,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;
--- a/libmpdemux/demux_mf.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_mf.c Tue Jan 29 15:11:38 2008 +0000 @@ -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;
--- a/libmpdemux/demux_mkv.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_mkv.c Tue Jan 29 15:11:38 2008 +0000 @@ -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 {
--- a/libmpdemux/demux_mov.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_mov.c Tue Jan 29 15:11:38 2008 +0000 @@ -2202,19 +2202,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);
--- a/libmpdemux/demux_mpc.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_mpc.c Tue Jan 29 15:11:38 2008 +0000 @@ -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);
--- a/libmpdemux/demux_mpg.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_mpg.c Tue Jan 29 15:11:38 2008 +0000 @@ -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 {
--- a/libmpdemux/demux_nut.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_nut.c Tue Jan 29 15:11:38 2008 +0000 @@ -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;
--- a/libmpdemux/demux_ogg.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_ogg.c Tue Jan 29 15:11:38 2008 +0000 @@ -1366,8 +1366,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 +1392,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) {
--- a/libmpdemux/demux_rawaudio.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_rawaudio.c Tue Jan 29 15:11:38 2008 +0000 @@ -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);
--- a/libmpdemux/demux_rawdv.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_rawdv.c Tue Jan 29 15:11:38 2008 +0000 @@ -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;
--- a/libmpdemux/demux_rawvideo.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_rawvideo.c Tue Jan 29 15:11:38 2008 +0000 @@ -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);
--- a/libmpdemux/demux_real.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_real.c Tue Jan 29 15:11:38 2008 +0000 @@ -1813,10 +1813,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])
--- a/libmpdemux/demux_ts.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_ts.c Tue Jan 29 15:11:38 2008 +0000 @@ -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 {
--- a/libmpdemux/demux_ty.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_ty.c Tue Jan 29 15:11:38 2008 +0000 @@ -760,9 +760,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
--- a/libmpdemux/demux_vqf.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_vqf.c Tue Jan 29 15:11:38 2008 +0000 @@ -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);
--- a/libmpdemux/demux_xmms.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demux_xmms.c Tue Jan 29 15:11:38 2008 +0000 @@ -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;
--- a/libmpdemux/demuxer.c Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demuxer.c Tue Jan 29 15:11:38 2008 +0000 @@ -980,7 +980,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) @@ -988,7 +988,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;
--- a/libmpdemux/demuxer.h Tue Jan 29 14:58:10 2008 +0000 +++ b/libmpdemux/demuxer.h Tue Jan 29 15:11:38 2008 +0000 @@ -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;
--- a/mplayer.c Tue Jan 29 14:58:10 2008 +0000 +++ b/mplayer.c Tue Jan 29 15:11:38 2008 +0000 @@ -2483,8 +2483,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 +3626,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 +3831,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; }