| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Implements the Demuxer interface using FFmpeg's libavformat. At this time | 5 // Implements the Demuxer interface using FFmpeg's libavformat. At this time |
| 6 // will support demuxing any audio/video format thrown at it. The streams | 6 // will support demuxing any audio/video format thrown at it. The streams |
| 7 // output mime types audio/x-ffmpeg and video/x-ffmpeg and include an integer | 7 // output mime types audio/x-ffmpeg and video/x-ffmpeg and include an integer |
| 8 // key FFmpegCodecID which contains the CodecID enumeration value. The CodecIDs | 8 // key FFmpegCodecID which contains the CodecID enumeration value. The CodecIDs |
| 9 // can be used to create and initialize the corresponding FFmpeg decoder. | 9 // can be used to create and initialize the corresponding FFmpeg decoder. |
| 10 // | 10 // |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // already been demuxed without having the demuxer thread sending the | 123 // already been demuxed without having the demuxer thread sending the |
| 124 // buffers. |lock_| must be acquired before any access to |buffer_queue_|, | 124 // buffers. |lock_| must be acquired before any access to |buffer_queue_|, |
| 125 // |read_queue_|, or |stopped_|. | 125 // |read_queue_|, or |stopped_|. |
| 126 base::Lock lock_; | 126 base::Lock lock_; |
| 127 | 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); | 128 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer, public FFmpegURLProtocol { | 131 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer, public FFmpegURLProtocol { |
| 132 public: | 132 public: |
| 133 FFmpegDemuxer(MessageLoop* message_loop, bool local_source); | 133 FFmpegDemuxer(MessageLoop* message_loop, |
| 134 const scoped_refptr<DataSource>& data_source, |
| 135 bool local_source); |
| 134 virtual ~FFmpegDemuxer(); | 136 virtual ~FFmpegDemuxer(); |
| 135 | 137 |
| 136 // Posts a task to perform additional demuxing. | 138 // Posts a task to perform additional demuxing. |
| 137 virtual void PostDemuxTask(); | 139 virtual void PostDemuxTask(); |
| 138 | 140 |
| 139 void Initialize( | |
| 140 DataSource* data_source, const PipelineStatusCB& status_cb); | |
| 141 | |
| 142 // Demuxer implementation. | 141 // Demuxer implementation. |
| 142 virtual void set_host(DemuxerHost* demuxer_host) OVERRIDE; |
| 143 virtual void Initialize(const PipelineStatusCB& status_cb) OVERRIDE; |
| 143 virtual void Stop(const base::Closure& callback) OVERRIDE; | 144 virtual void Stop(const base::Closure& callback) OVERRIDE; |
| 144 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 145 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
| 145 virtual void OnAudioRendererDisabled() OVERRIDE; | 146 virtual void OnAudioRendererDisabled() OVERRIDE; |
| 146 virtual void set_host(DemuxerHost* demuxer_host) OVERRIDE; | |
| 147 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 147 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
| 148 virtual scoped_refptr<DemuxerStream> GetStream( | 148 virtual scoped_refptr<DemuxerStream> GetStream( |
| 149 DemuxerStream::Type type) OVERRIDE; | 149 DemuxerStream::Type type) OVERRIDE; |
| 150 virtual void SetPreload(Preload preload) OVERRIDE; | |
| 151 virtual base::TimeDelta GetStartTime() const OVERRIDE; | 150 virtual base::TimeDelta GetStartTime() const OVERRIDE; |
| 152 virtual int GetBitrate() OVERRIDE; | 151 virtual int GetBitrate() OVERRIDE; |
| 153 virtual bool IsLocalSource() OVERRIDE; | 152 virtual bool IsLocalSource() OVERRIDE; |
| 154 virtual bool IsSeekable() OVERRIDE; | 153 virtual bool IsSeekable() OVERRIDE; |
| 155 | 154 |
| 156 // FFmpegURLProtocol implementation. | 155 // FFmpegURLProtocol implementation. |
| 157 virtual size_t Read(size_t size, uint8* data) OVERRIDE; | 156 virtual size_t Read(size_t size, uint8* data) OVERRIDE; |
| 158 virtual bool GetPosition(int64* position_out) OVERRIDE; | 157 virtual bool GetPosition(int64* position_out) OVERRIDE; |
| 159 virtual bool SetPosition(int64 position) OVERRIDE; | 158 virtual bool SetPosition(int64 position) OVERRIDE; |
| 160 virtual bool GetSize(int64* size_out) OVERRIDE; | 159 virtual bool GetSize(int64* size_out) OVERRIDE; |
| 161 virtual bool IsStreaming() OVERRIDE; | 160 virtual bool IsStreaming() OVERRIDE; |
| 162 | 161 |
| 163 // Provide access to FFmpegDemuxerStream. | 162 // Provide access to FFmpegDemuxerStream. |
| 164 MessageLoop* message_loop(); | 163 MessageLoop* message_loop(); |
| 165 | 164 |
| 166 // For testing purposes. | 165 // For testing purposes. |
| 167 void disable_first_seek_hack_for_testing() { first_seek_hack_ = false; } | 166 void disable_first_seek_hack_for_testing() { first_seek_hack_ = false; } |
| 168 | 167 |
| 169 private: | 168 private: |
| 170 // Only allow a factory to create this class. | 169 // Only allow a factory to create this class. |
| 171 friend class MockFFmpegDemuxer; | 170 friend class MockFFmpegDemuxer; |
| 172 FRIEND_TEST_ALL_PREFIXES(FFmpegDemuxerTest, ProtocolRead); | 171 FRIEND_TEST_ALL_PREFIXES(FFmpegDemuxerTest, ProtocolRead); |
| 173 | 172 |
| 174 // Carries out initialization on the demuxer thread. | 173 // Carries out initialization on the demuxer thread. |
| 175 void InitializeTask( | 174 void InitializeTask(const PipelineStatusCB& status_cb); |
| 176 DataSource* data_source, const PipelineStatusCB& status_cb); | |
| 177 | 175 |
| 178 // Carries out a seek on the demuxer thread. | 176 // Carries out a seek on the demuxer thread. |
| 179 void SeekTask(base::TimeDelta time, const PipelineStatusCB& cb); | 177 void SeekTask(base::TimeDelta time, const PipelineStatusCB& cb); |
| 180 | 178 |
| 181 // Carries out demuxing and satisfying stream reads on the demuxer thread. | 179 // Carries out demuxing and satisfying stream reads on the demuxer thread. |
| 182 void DemuxTask(); | 180 void DemuxTask(); |
| 183 | 181 |
| 184 // Carries out stopping the demuxer streams on the demuxer thread. | 182 // Carries out stopping the demuxer streams on the demuxer thread. |
| 185 void StopTask(const base::Closure& callback); | 183 void StopTask(const base::Closure& callback); |
| 186 | 184 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // signaled when the demuxer is being stopped. | 234 // signaled when the demuxer is being stopped. |
| 237 base::WaitableEvent read_event_; | 235 base::WaitableEvent read_event_; |
| 238 | 236 |
| 239 // Flag to indicate if read has ever failed. Once set to true, it will | 237 // Flag to indicate if read has ever failed. Once set to true, it will |
| 240 // never be reset. This flag is set true and accessed in Read(). | 238 // never be reset. This flag is set true and accessed in Read(). |
| 241 bool read_has_failed_; | 239 bool read_has_failed_; |
| 242 | 240 |
| 243 int last_read_bytes_; | 241 int last_read_bytes_; |
| 244 int64 read_position_; | 242 int64 read_position_; |
| 245 | 243 |
| 246 // Initialization can happen before set_host() is called, in which case we | 244 // Derived bitrate after initialization has completed. |
| 247 // store these bits for deferred reporting to the DemuxerHost when we get one. | 245 int bitrate_; |
| 248 base::TimeDelta max_duration_; | |
| 249 PipelineStatus deferred_status_; | |
| 250 | 246 |
| 251 // Used to skip the implicit "first seek" to avoid resetting FFmpeg's internal | 247 // Used to skip the implicit "first seek" to avoid resetting FFmpeg's internal |
| 252 // state. | 248 // state. |
| 253 bool first_seek_hack_; | 249 bool first_seek_hack_; |
| 254 | 250 |
| 255 // The first timestamp of the opened media file. This is used to set the | 251 // The first timestamp of the opened media file. This is used to set the |
| 256 // starting clock value to match the timestamps in the media file. Default | 252 // starting clock value to match the timestamps in the media file. Default |
| 257 // is 0. | 253 // is 0. |
| 258 base::TimeDelta start_time_; | 254 base::TimeDelta start_time_; |
| 259 | 255 |
| 260 // Whether audio has been disabled for this demuxer (in which case this class | 256 // Whether audio has been disabled for this demuxer (in which case this class |
| 261 // drops packets destined for AUDIO demuxer streams on the floor). | 257 // drops packets destined for AUDIO demuxer streams on the floor). |
| 262 bool audio_disabled_; | 258 bool audio_disabled_; |
| 263 | 259 |
| 264 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 260 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
| 265 }; | 261 }; |
| 266 | 262 |
| 267 } // namespace media | 263 } // namespace media |
| 268 | 264 |
| 269 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 265 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
| OLD | NEW |