Changeset 10851
- Timestamp:
- 12/02/09 19:58:45 (4 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgPlugins/ffmpeg
- Files:
-
- 10 modified
-
FFmpegClocks.cpp (modified) (4 diffs)
-
FFmpegClocks.hpp (modified) (4 diffs)
-
FFmpegDecoder.cpp (modified) (3 diffs)
-
FFmpegDecoder.hpp (modified) (5 diffs)
-
FFmpegDecoderAudio.cpp (modified) (4 diffs)
-
FFmpegDecoderAudio.hpp (modified) (3 diffs)
-
FFmpegDecoderVideo.cpp (modified) (3 diffs)
-
FFmpegDecoderVideo.hpp (modified) (2 diffs)
-
FFmpegImageStream.cpp (modified) (3 diffs)
-
FFmpegImageStream.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegClocks.cpp
r9816 r10851 31 31 m_video_clock(0), 32 32 m_start_time(0), 33 m_pause_time(0), 34 m_seek_time(0), 33 35 m_last_frame_delay(0.040), 34 36 m_last_frame_pts(0), … … 38 40 m_audio_delay(0.0), 39 41 m_audio_disabled(false), 40 m_rewind(false) 42 m_rewind(false), 43 m_paused(false), 44 m_last_current_time(0.0) 41 45 { 42 46 … … 58 62 m_audio_buffer_end_pts = start_time; 59 63 m_audio_timer.setStartTick(); 64 } 65 66 void FFmpegClocks::pause(bool pause) 67 { 68 if(pause) 69 m_paused = true; 70 else 71 m_paused = false; 60 72 } 61 73 … … 206 218 } 207 219 220 void FFmpegClocks::setPauseTime(double pause_time) 221 { 222 m_pause_time += pause_time; 223 } 224 225 void FFmpegClocks::setSeekTime(double seek_time) 226 { 227 m_seek_time = getAudioTime() - seek_time; 228 } 229 208 230 209 231 210 232 double FFmpegClocks::getAudioTime() const 211 233 { 212 return m_audio_buffer_end_pts + m_audio_timer.time_s() - m_audio_delay; 213 } 214 215 234 return m_audio_buffer_end_pts + m_audio_timer.time_s() - m_pause_time - m_audio_delay; 235 } 236 237 238 double FFmpegClocks::getCurrentTime() 239 { 240 if(!m_paused) 241 m_last_current_time = getAudioTime() - m_seek_time; // synced with audio 242 243 return m_last_current_time; 244 } 216 245 217 246 } // namespace osgFFmpeg -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegClocks.hpp
r10161 r10851 23 23 24 24 void reset(double start_time); 25 void pause(bool pause); 25 26 void rewindAudio(); 26 27 void rewindVideo(); … … 36 37 37 38 double getStartTime() const; 39 double getCurrentTime(); 40 void setPauseTime(double pause_time); 41 void setSeekTime(double seek_time); 38 42 39 43 private: … … 50 54 51 55 double m_start_time; 56 double m_pause_time; 57 double m_seek_time; 52 58 double m_last_frame_delay; 53 59 double m_last_frame_pts; … … 56 62 double m_audio_buffer_end_pts; 57 63 double m_audio_delay; 58 Timer m_audio_timer; 59 bool m_audio_disabled; 60 bool m_rewind; 64 Timer m_audio_timer; 65 bool m_audio_disabled; 66 bool m_rewind; 67 bool m_paused; 68 double m_last_current_time; 69 61 70 62 71 }; -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp
r10809 r10851 214 214 } 215 215 216 void FFmpegDecoder::resume()217 {218 m_pending_packet.clear();219 220 flushAudioQueue();221 flushVideoQueue();222 m_state = NORMAL;223 }224 225 216 void FFmpegDecoder::findAudioStream() 226 217 { … … 295 286 // If we reach the end of the stream, change the decoder state 296 287 if (loop()) 288 { 289 m_clocks.reset(m_start); 297 290 rewindButDontFlushQueues(); 291 } 298 292 else 299 293 m_state = END_OF_STREAM; … … 394 388 const int64_t seek_target = av_rescale_q(pos, AvTimeBaseQ, m_video_stream->time_base); 395 389 390 m_clocks.setSeekTime(time); 391 396 392 if (av_seek_frame(m_format_context.get(), m_video_index, seek_target, 0/*AVSEEK_FLAG_BYTE |*/ /*AVSEEK_FLAG_BACKWARD*/) < 0) 397 393 throw std::runtime_error("av_seek_frame failed()"); -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.hpp
r10809 r10851 71 71 void seek(double time); 72 72 void pause(); 73 void resume();74 73 75 74 void loop(bool loop); … … 77 76 78 77 double duration() const; 78 double reference(); 79 79 80 80 FFmpegDecoderAudio & audio_decoder(); … … 109 109 110 110 FormatContextPtr m_format_context; 111 AVStream * m_audio_stream;112 AVStream * m_video_stream;111 AVStream * m_audio_stream; 112 AVStream * m_video_stream; 113 113 114 114 int m_audio_index; … … 117 117 FFmpegClocks m_clocks; 118 118 FFmpegPacket m_pending_packet; 119 PacketQueue m_audio_queue;120 PacketQueue m_video_queue;119 PacketQueue m_audio_queue; 120 PacketQueue m_video_queue; 121 121 122 FFmpegDecoderAudio m_audio_decoder;123 FFmpegDecoderVideo m_video_decoder;122 FFmpegDecoderAudio m_audio_decoder; 123 FFmpegDecoderVideo m_video_decoder; 124 124 125 double m_duration;126 double m_start;125 double m_duration; 126 double m_start; 127 127 128 State m_state;128 State m_state; 129 129 bool m_loop; 130 130 }; … … 149 149 { 150 150 return double(m_format_context->duration) / AV_TIME_BASE; 151 } 152 153 inline double FFmpegDecoder::reference() 154 { 155 return m_clocks.getCurrentTime(); 151 156 } 152 157 -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp
r10414 r10851 26 26 m_audio_buf_index(0), 27 27 m_end_of_stream(false), 28 m_paused(true), 28 29 m_exit(false) 29 30 { … … 89 90 } 90 91 92 void FFmpegDecoderAudio::pause(bool pause) 93 { 94 if(pause) 95 m_paused = true; 96 else 97 m_paused = false; 98 } 91 99 92 100 void FFmpegDecoderAudio::close(bool waitForThreadToExit) … … 185 193 while (! m_exit) 186 194 { 195 196 if(m_paused) 197 { 198 m_clocks.pause(true); 199 m_pause_timer.setStartTick(); 200 201 while(m_paused) 202 { 203 microSleep(10000); 204 } 205 206 m_clocks.setPauseTime(m_pause_timer.time_s()); 207 m_clocks.pause(false); 208 } 209 187 210 // If skipping audio, make sure the audio stream is still consumed. 188 211 if (skip_audio) … … 194 217 packet.clear(); 195 218 } 196 197 219 // Else, just idle in this thread. 198 220 // Note: If m_audio_sink has an audio callback, this thread will still be awaken -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp
r9869 r10851 4 4 5 5 #include <OpenThreads/Thread> 6 7 #include <osg/Timer> 6 8 7 9 #include "FFmpegClocks.hpp" … … 30 32 31 33 void open(AVStream * stream); 34 void pause(bool pause); 32 35 void close(bool waitForThreadToExit); 33 36 … … 52 55 53 56 54 PacketQueue & m_packets;55 FFmpegClocks & m_clocks;56 AVStream * m_stream;57 AVCodecContext * m_context;58 FFmpegPacket m_packet;59 const uint8_t * m_packet_data;60 int m_bytes_remaining;57 PacketQueue & m_packets; 58 FFmpegClocks & m_clocks; 59 AVStream * m_stream; 60 AVCodecContext * m_context; 61 FFmpegPacket m_packet; 62 const uint8_t * m_packet_data; 63 int m_bytes_remaining; 61 64 62 Buffer m_audio_buffer;63 size_t m_audio_buf_size;64 size_t m_audio_buf_index;65 Buffer m_audio_buffer; 66 size_t m_audio_buf_size; 67 size_t m_audio_buf_index; 65 68 66 int m_frequency;67 int m_nb_channels;68 osg::AudioStream::SampleFormat m_sample_format;69 int m_frequency; 70 int m_nb_channels; 71 osg::AudioStream::SampleFormat m_sample_format; 69 72 70 SinkPtr m_audio_sink;73 SinkPtr m_audio_sink; 71 74 72 bool m_end_of_stream; 73 volatile bool m_exit; 75 osg::Timer m_pause_timer; 76 77 bool m_end_of_stream; 78 bool m_paused; 79 volatile bool m_exit; 74 80 }; 75 81 -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
r10414 r10851 21 21 m_user_data(0), 22 22 m_publish_func(0), 23 m_paused(true), 23 24 m_exit(false) 24 25 #ifdef USE_SWSCALE … … 118 119 } 119 120 121 void FFmpegDecoderVideo::pause(bool pause) 122 { 123 if(pause) 124 m_paused = true; 125 else 126 m_paused = false; 127 } 120 128 121 129 void FFmpegDecoderVideo::run() … … 193 201 publishFrame(frame_delay, m_clocks.audioDisabled()); 194 202 } 203 } 204 205 while(m_paused && !m_exit) 206 { 207 microSleep(10000); 195 208 } 196 209 -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp
r10161 r10851 66 66 67 67 void open(AVStream * stream); 68 void pause(bool pause); 68 69 void close(bool waitForThreadToExit); 69 70 … … 121 122 bool m_alpha_channel; 122 123 124 bool m_paused; 123 125 volatile bool m_exit; 124 126 -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp
r10809 r10851 157 157 { 158 158 return m_decoder->duration(); 159 } 160 161 162 double FFmpegImageStream::getReferenceTime () const 163 { 164 return m_decoder->reference(); 159 165 } 160 166 … … 265 271 m_decoder->video_decoder().start(); 266 272 267 m_decoder->resume(); 273 m_decoder->video_decoder().pause(false); 274 m_decoder->audio_decoder().pause(false); 268 275 } 269 276 … … 277 284 if (_status == PLAYING) 278 285 { 279 m_decoder->pause(); 286 m_decoder->video_decoder().pause(true); 287 m_decoder->audio_decoder().pause(true); 280 288 } 281 289 -
OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.hpp
r10809 r10851 35 35 36 36 virtual double getLength() const; 37 virtual double getReferenceTime () const; 37 38 virtual double getFrameRate() const; 38 39 … … 72 73 Mutex m_mutex; 73 74 Condition m_frame_published_cond; 74 bool m_frame_published_flag;75 bool m_frame_published_flag; 75 76 double m_seek_time; 76 77 };
