From 53e16efd63a49299bd9828bc0d85dc3347feea8f Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Wed, 4 Jul 2012 04:01:59 -0500 Subject: [PATCH] Fixed a small audio buffer issue, and removed more debug code. --- include/Cache.h | 6 +++++- src/Cache.cpp | 3 +++ src/FFmpegReader.cpp | 13 +++---------- src/Main.cpp | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/Cache.h b/include/Cache.h index 05e89d89..443f85bd 100644 --- a/include/Cache.h +++ b/include/Cache.h @@ -27,6 +27,7 @@ namespace openshot { int max_frames; ///< This is the max number of frames to cache map frames; ///< This map holds the frame number and Frame objects deque frame_numbers; ///< This queue holds a sequential list of cached Frame numbers + int current_frame; ///< This is the last requested frame (used to dynamically adjust the max_frames) /// Clean up cached frames that exceed the number in our max_frames variable void CleanUp(); @@ -41,7 +42,7 @@ namespace openshot { /// Add a Frame to the cache void Add(int frame_number, Frame frame); - /// Check for the existance of a frame in the cache + /// Check for the existence of a frame in the cache bool Exists(int frame_number); /// Get a frame from the cache @@ -68,6 +69,9 @@ namespace openshot { /// Set maximum frames to a different amount void SetMaxFrames(int max_frames) { max_frames = max_frames; }; + /// Gets the maximum frames value + int GetMaxFrames() { return max_frames; }; + }; } diff --git a/src/Cache.cpp b/src/Cache.cpp index d63d18a5..6437cb89 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -52,6 +52,9 @@ Frame Cache::GetFrame(int frame_number) // Does frame exists in cache? if (Exists(frame_number)) { + // Set current frame + current_frame = frame_number; + // return the Frame object return frames[frame_number]; } diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 925d5432..6f752ff2 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -4,7 +4,7 @@ using namespace openshot; FFmpegReader::FFmpegReader(string path) throw(InvalidFile, NoStreamsFound, InvalidCodec) : last_video_frame(0), last_audio_frame(0), is_seeking(0), seeking_pts(0), seeking_frame(0), - audio_pts_offset(99999), video_pts_offset(99999), working_cache(30), final_cache(30), path(path), + audio_pts_offset(99999), video_pts_offset(99999), working_cache(130), final_cache(130), path(path), is_video_seek(true), check_interlace(false), check_fps(false), init_settings(false), enable_seek(true) { // , resampleCtx(NULL) @@ -737,8 +737,8 @@ void FFmpegReader::ProcessAudioPacket(int requested_frame, int target_frame, int // Decrement remaining samples remaining_samples -= samples; - // Update working cache - if (remaining_samples > 0) + // Update working cache (if audio is completed for this frame + channel) + if (remaining_samples > 0 || start + samples >= samples_per_frame) // If more samples remain, this frame must all it's audio data now f.SetAudioComplete(channel_filter); @@ -1033,13 +1033,6 @@ void FFmpegReader::CheckWorkingFrames(bool end_of_stream) Frame f = working_cache.GetSmallestFrame(); bool is_ready = f.IsReady(info.has_video, info.has_audio); - if (f.number == 300) - { - cout << "CheckWorkingFrames: frame: " << f.number << endl; - cout << "f.IsReady(): " << f.IsReady(info.has_video, info.has_audio) << endl; - cout << "f.IsAudioReady(): " << f.IsAudioReady(info.has_audio) << endl; - } - // Check if working frame is final if (is_ready || end_of_stream) { diff --git a/src/Main.cpp b/src/Main.cpp index 9689b937..9c3fdbb1 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -17,11 +17,11 @@ int main() // openshot::FFmpegReader r("/home/jonathan/apps/libopenshot/src/examples/test.mp4"); // openshot::FFmpegReader r("/home/jonathan/apps/libopenshot/src/examples/test1.mp4"); // openshot::FFmpegReader r("/home/jonathan/apps/libopenshot/src/examples/piano.wav"); - openshot::FFmpegReader r("/home/jonathan/Videos/sintel-1024-stereo.mp4"); + // openshot::FFmpegReader r("/home/jonathan/Videos/sintel-1024-stereo.mp4"); // openshot::FFmpegReader r("/home/jonathan/Videos/00001.mts"); // openshot::FFmpegReader r("/home/jonathan/Videos/sintel_trailer-720p.mp4"); // openshot::FFmpegReader r("/home/jonathan/Aptana Studio Workspace/OpenShotLibrary/src/examples/piano.wav"); - // openshot::FFmpegReader r("/home/jonathan/Music/Army of Lovers/Crucified/Army of Lovers - Crucified [Single Version].mp3"); + openshot::FFmpegReader r("/home/jonathan/Music/Army of Lovers/Crucified/Army of Lovers - Crucified [Single Version].mp3"); // openshot::FFmpegReader r("/home/jonathan/Documents/OpenShot Art/test.jpeg"); // openshot::FFmpegReader r("/home/jonathan/Videos/60fps.mp4"); // openshot::FFmpegReader r("/home/jonathan/Aptana Studio Workspace/OpenShotLibrary/src/examples/asdf.wdf"); @@ -37,7 +37,7 @@ int main() Frame f = r.GetFrame(frame); //f.Play(); //f.Display(); - //f.DisplayWaveform(false); + f.DisplayWaveform(false); } // Seek to frame 1