Changeset 10892
- Timestamp:
- 12/15/09 12:27:28 (3 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgPlugins/ffmpeg
- Files:
-
- 5 modified
-
FFmpegClocks.cpp (modified) (8 diffs)
-
FFmpegClocks.hpp (modified) (2 diffs)
-
FFmpegDecoder.cpp (modified) (2 diffs)
-
FFmpegDecoderAudio.cpp (modified) (1 diff)
-
FFmpegDecoderVideo.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegClocks.cpp
r10851 r10892 40 40 m_audio_delay(0.0), 41 41 m_audio_disabled(false), 42 m_rewind(false),43 42 m_paused(false), 44 43 m_last_current_time(0.0) … … 60 59 m_frame_time = start_time; 61 60 61 m_pause_time = 0; 62 m_seek_time = 0; 63 62 64 m_audio_buffer_end_pts = start_time; 63 65 m_audio_timer.setStartTick(); … … 69 71 m_paused = true; 70 72 else 73 { 71 74 m_paused = false; 72 } 73 74 75 76 void FFmpegClocks::rewindAudio() 77 { 78 ScopedLock lock(m_mutex); 79 75 if(!m_audio_disabled) m_audio_timer.setStartTick(); 76 } 77 } 78 79 80 81 void FFmpegClocks::rewind() 82 { 83 ScopedLock lock(m_mutex); 84 85 m_pause_time = 0; 86 m_seek_time = 0; 87 80 88 m_audio_buffer_end_pts = m_start_time; 81 89 m_audio_timer.setStartTick(); 82 90 83 m_rewind = ! m_rewind; 84 } 85 86 87 88 void FFmpegClocks::rewindVideo() 89 { 90 ScopedLock lock(m_mutex); 91 m_last_frame_delay = 0.040; 92 m_frame_time = m_start_time; 91 93 92 94 if (m_audio_disabled) 93 95 return; 94 96 95 m_video_clock = m_start_time; 96 97 m_video_clock = m_start_time; 98 } 99 100 void FFmpegClocks::seek(double seek_time) 101 { 102 ScopedLock lock(m_mutex); 103 104 m_video_clock = seek_time; 97 105 m_last_frame_delay = 0.040; 98 m_last_frame_pts = m_start_time - m_last_frame_delay; 99 m_frame_time = m_start_time; 100 101 m_rewind = ! m_rewind; 102 } 103 106 m_frame_time = seek_time; 107 } 104 108 105 109 … … 180 184 181 185 // If incorrect delay, use previous one 186 182 187 if (delay <= 0.0 || delay >= 1.0) 188 { 183 189 delay = m_last_frame_delay; 190 if(!m_audio_disabled) m_frame_time = pts - delay; 191 } 192 184 193 185 194 // Save for next time … … 194 203 195 204 const double audio_time = getAudioTime(); 196 const double actual_delay = (! m_rewind) ? 197 clamp(m_frame_time - audio_time, -0.5*delay, 2.5*delay) : 198 m_last_actual_delay; // when rewinding audio or video (but the other has yet to be), get the last used delay 205 const double actual_delay = clamp(m_frame_time - audio_time, -0.5*delay, 2.5*delay); 199 206 200 207 //m_frame_time += delay; … … 225 232 void FFmpegClocks::setSeekTime(double seek_time) 226 233 { 227 m_seek_time = getAudioTime() - seek_time;234 m_seek_time += getAudioTime() - seek_time; 228 235 } 229 236 … … 232 239 double FFmpegClocks::getAudioTime() const 233 240 { 234 return m_audio_buffer_end_pts + m_audio_timer.time_s() - m_pause_time - m_audio_delay; 241 if(m_audio_disabled) 242 return m_audio_buffer_end_pts + m_audio_timer.time_s() - m_pause_time - m_audio_delay - m_seek_time; 243 else 244 return m_audio_buffer_end_pts + m_audio_timer.time_s() - m_audio_delay; 235 245 } 236 246 … … 239 249 { 240 250 if(!m_paused) 241 m_last_current_time = getAudioTime() - m_seek_time; // synced with audio251 m_last_current_time = getAudioTime(); 242 252 243 253 return m_last_current_time; -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegClocks.hpp
r10851 r10892 24 24 void reset(double start_time); 25 25 void pause(bool pause); 26 void rewindAudio();27 void rewind Video();26 void seek(double seek_time); 27 void rewind(); 28 28 29 29 void audioSetBufferEndPts(double pts); … … 64 64 Timer m_audio_timer; 65 65 bool m_audio_disabled; 66 bool m_rewind;67 66 bool m_paused; 68 67 double m_last_current_time; -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp
r10851 r10892 368 368 throw std::runtime_error("av_seek_frame failed()"); 369 369 370 m_clocks.rewind(); 370 371 m_state = REWINDING; 371 372 } … … 393 394 throw std::runtime_error("av_seek_frame failed()"); 394 395 396 m_clocks.seek(time); 395 397 m_state = SEEKING; 396 398 } -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp
r10851 r10892 323 323 { 324 324 avcodec_flush_buffers(m_context); 325 m_clocks.rewindAudio();326 325 } 327 326 -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
r10851 r10892 228 228 { 229 229 avcodec_flush_buffers(m_context); 230 m_clocks.rewindVideo();231 230 } 232 231 }
