libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd/cvd_src videofilebuffer.cc


From: Colin Starr
Subject: [libcvd-members] libcvd/cvd_src videofilebuffer.cc
Date: Mon, 19 Nov 2007 14:03:10 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Colin Starr <ccs36>     07/11/19 14:03:10

Modified files:
        cvd_src        : videofilebuffer.cc 

Log message:
        Inserted a check in seek_to() to throw exception if user tries to seek 
past the end of the video stream. 

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/videofilebuffer.cc?cvsroot=libcvd&r1=1.14&r2=1.15

Patches:
Index: videofilebuffer.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/videofilebuffer.cc,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- videofilebuffer.cc  26 Mar 2007 17:23:36 -0000      1.14
+++ videofilebuffer.cc  19 Nov 2007 14:03:10 -0000      1.15
@@ -365,20 +365,22 @@
 //
 void RawVideoFileBuffer::seek_to(double t)
 {      
-       // The call to av_seek_frame only searches to the nearest keyframe. To 
continue from there, we
-       // must decode and read one frame at a time until we get to the desired 
point.
-
-       // Hack: I do not know how to obtain the current frame number or 
timestamp after the call to 
-       // av_seek_frame without performing another read_frame. This will 
obviously read one extra frame.
-       // So we must subtract one frame from the position we are actually 
searching for.
-       // t is defined as frame_number * frame_rate.
+       // The call to av_seek_frame only searches to the keyframe immediately 
prior to the desired frame.
+       // To continue from there, we must decode one frame at a time until we 
reach the required frame.
 
+       // Check that we are not seeking beyond the end of the video.
+       if (t * AV_TIME_BASE + 0.5 > pFormatContext->duration)
+         throw Exceptions::VideoFileBuffer::BadSeek(t);
+
+       // Hack: I don't know how to find the current frame number after 
calling av_seek_frame() without
+       // calling read_frame() again. This obviously reads one extra frame, so 
we subtract one frame from 
+       // the position we are searching for. (t = frame_number * frame_rate)
        double frame_rate = 
av_q2d(pFormatContext->streams[video_stream]->r_frame_rate);
        int frame_num = static_cast<int>(t * frame_rate + 0.5);
        t = (frame_num - 1) / frame_rate;
 
        int64_t targetPts = static_cast<int64_t>(t * AV_TIME_BASE + 0.5);
-       // Handling the case where t == 0.
+       // If t was initially zero, it is now negative. Fix this.
        int64_t seekToPts = targetPts < 0 ? 0 : targetPts;
 
        #if LIBAVFORMAT_BUILD >= 4623




reply via email to

[Prev in Thread] Current Thread [Next in Thread]