comparison libmpdemux/demux_mov.c @ 16613:465ad78c43c9

Detect eof when seeking and do _not_ restart the video. Also fixes some invalid reads.
author reimar
date Wed, 28 Sep 2005 15:37:30 +0000
parents 9574fb378080
children 66ce674de624
comparison
equal deleted inserted replaced
16612:e94616c973e3 16613:465ad78c43c9
1848 mov_track_t* trak=NULL; 1848 mov_track_t* trak=NULL;
1849 float pts; 1849 float pts;
1850 int x; 1850 int x;
1851 off_t pos; 1851 off_t pos;
1852 1852
1853 if (ds->eof) return 0;
1853 trak = stream_track(priv, ds); 1854 trak = stream_track(priv, ds);
1854 if (!trak) return 0; 1855 if (!trak) return 0;
1855 1856
1856 if(trak->samplesize){ 1857 if(trak->samplesize){
1857 // read chunk: 1858 // read chunk:
1944 int sample=pts/trak->duration; 1945 int sample=pts/trak->duration;
1945 // printf("MOV track seek - chunk: %d (pts: %5.3f dur=%d) \n",sample,pts,trak->duration); 1946 // printf("MOV track seek - chunk: %d (pts: %5.3f dur=%d) \n",sample,pts,trak->duration);
1946 if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative 1947 if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative
1947 trak->pos=0; 1948 trak->pos=0;
1948 while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos; 1949 while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos;
1950 if (trak->pos == trak->chunks_size) return -1;
1949 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; 1951 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale;
1950 } else { 1952 } else {
1951 unsigned int ipts; 1953 unsigned int ipts;
1952 if(!(flags&1)) pts+=trak->samples[trak->pos].pts; 1954 if(!(flags&1)) pts+=trak->samples[trak->pos].pts;
1953 if(pts<0) pts=0; 1955 if(pts<0) pts=0;
1954 ipts=pts; 1956 ipts=pts;
1955 //printf("MOV track seek - sample: %d \n",ipts); 1957 //printf("MOV track seek - sample: %d \n",ipts);
1956 for(trak->pos=0;trak->pos<trak->samples_size;++trak->pos){ 1958 for(trak->pos=0;trak->pos<trak->samples_size;++trak->pos){
1957 if(trak->samples[trak->pos].pts>=ipts) break; // found it! 1959 if(trak->samples[trak->pos].pts>=ipts) break; // found it!
1958 } 1960 }
1961 if (trak->pos == trak->samples_size) return -1;
1959 if(trak->keyframes_size){ 1962 if(trak->keyframes_size){
1960 // find nearest keyframe 1963 // find nearest keyframe
1961 int i; 1964 int i;
1962 for(i=0;i<trak->keyframes_size;i++){ 1965 for(i=0;i<trak->keyframes_size;i++){
1963 if(trak->keyframes[i]>=trak->pos) break; 1966 if(trak->keyframes[i]>=trak->pos) break;
1964 } 1967 }
1968 if (i == trak->keyframes_size) return -1;
1965 if(i>0 && (trak->keyframes[i]-trak->pos) > (trak->pos-trak->keyframes[i-1])) 1969 if(i>0 && (trak->keyframes[i]-trak->pos) > (trak->pos-trak->keyframes[i-1]))
1966 --i; 1970 --i;
1967 trak->pos=trak->keyframes[i]; 1971 trak->pos=trak->keyframes[i];
1968 // printf("nearest keyframe: %d \n",trak->pos); 1972 // printf("nearest keyframe: %d \n",trak->pos);
1969 } 1973 }
1985 ds=demuxer->video; 1989 ds=demuxer->video;
1986 trak = stream_track(priv, ds); 1990 trak = stream_track(priv, ds);
1987 if (trak) { 1991 if (trak) {
1988 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; 1992 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
1989 //if(!(flags&1)) pts+=ds->pts; 1993 //if(!(flags&1)) pts+=ds->pts;
1990 pts=ds->pts=mov_seek_track(trak,pts,flags); 1994 ds->pts=mov_seek_track(trak,pts,flags);
1995 if (ds->pts < 0) ds->eof = 1;
1996 else pts = ds->pts;
1991 flags=1; // absolute seconds 1997 flags=1; // absolute seconds
1992 } 1998 }
1993 1999
1994 ds=demuxer->audio; 2000 ds=demuxer->audio;
1995 trak = stream_track(priv, ds); 2001 trak = stream_track(priv, ds);
1996 if (trak) { 2002 if (trak) {
1997 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; 2003 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
1998 //if(!(flags&1)) pts+=ds->pts; 2004 //if(!(flags&1)) pts+=ds->pts;
1999 ds->pts=mov_seek_track(trak,pts,flags); 2005 ds->pts=mov_seek_track(trak,pts,flags);
2006 if (ds->pts < 0) ds->eof = 1;
2000 if (demuxer->video->id < 0) 2007 if (demuxer->video->id < 0)
2001 ((sh_audio_t*)ds->sh)->delay = ds->pts; 2008 ((sh_audio_t*)ds->sh)->delay = ds->pts;
2002 } 2009 }
2003 2010
2004 } 2011 }