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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, | 112 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, |
113 int64 timestamp); | 113 int64 timestamp); |
114 | 114 |
115 FFmpegDemuxer* demuxer_; | 115 FFmpegDemuxer* demuxer_; |
116 scoped_refptr<base::MessageLoopProxy> message_loop_; | 116 scoped_refptr<base::MessageLoopProxy> message_loop_; |
117 AVStream* stream_; | 117 AVStream* stream_; |
118 AudioDecoderConfig audio_config_; | 118 AudioDecoderConfig audio_config_; |
119 VideoDecoderConfig video_config_; | 119 VideoDecoderConfig video_config_; |
120 Type type_; | 120 Type type_; |
121 base::TimeDelta duration_; | 121 base::TimeDelta duration_; |
122 bool stopped_; | |
123 bool end_of_stream_; | 122 bool end_of_stream_; |
124 base::TimeDelta last_packet_timestamp_; | 123 base::TimeDelta last_packet_timestamp_; |
125 Ranges<base::TimeDelta> buffered_ranges_; | 124 Ranges<base::TimeDelta> buffered_ranges_; |
126 | 125 |
127 DecoderBufferQueue buffer_queue_; | 126 DecoderBufferQueue buffer_queue_; |
128 ReadCB read_cb_; | 127 ReadCB read_cb_; |
129 | 128 |
130 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; | 129 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; |
131 bool bitstream_converter_enabled_; | 130 bool bitstream_converter_enabled_; |
132 | 131 |
133 std::string encryption_key_id_; | 132 std::string encryption_key_id_; |
134 | 133 |
135 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); | 134 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); |
136 }; | 135 }; |
137 | 136 |
138 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { | 137 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { |
139 public: | 138 public: |
140 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 139 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
141 const scoped_refptr<DataSource>& data_source, | 140 const scoped_refptr<DataSource>& data_source, |
142 const FFmpegNeedKeyCB& need_key_cb); | 141 const FFmpegNeedKeyCB& need_key_cb); |
| 142 virtual ~FFmpegDemuxer(); |
143 | 143 |
144 // Demuxer implementation. | 144 // Demuxer implementation. |
145 virtual void Initialize(DemuxerHost* host, | 145 virtual void Initialize(DemuxerHost* host, |
146 const PipelineStatusCB& status_cb) OVERRIDE; | 146 const PipelineStatusCB& status_cb) OVERRIDE; |
147 virtual void Stop(const base::Closure& callback) OVERRIDE; | 147 virtual void Stop(const base::Closure& callback) OVERRIDE; |
148 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 148 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
149 virtual void OnAudioRendererDisabled() OVERRIDE; | 149 virtual void OnAudioRendererDisabled() OVERRIDE; |
150 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 150 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
151 virtual scoped_refptr<DemuxerStream> GetStream( | 151 virtual scoped_refptr<DemuxerStream> GetStream( |
152 DemuxerStream::Type type) OVERRIDE; | 152 DemuxerStream::Type type) OVERRIDE; |
153 virtual base::TimeDelta GetStartTime() const OVERRIDE; | 153 virtual base::TimeDelta GetStartTime() const OVERRIDE; |
154 | 154 |
155 // Calls |need_key_cb_| with the initialization data encountered in the file. | 155 // Calls |need_key_cb_| with the initialization data encountered in the file. |
156 void FireNeedKey(const std::string& init_data_type, | 156 void FireNeedKey(const std::string& init_data_type, |
157 const std::string& encryption_key_id); | 157 const std::string& encryption_key_id); |
158 | 158 |
159 // Allow FFmpegDemuxerStream to notify us when there is updated information | 159 // Allow FFmpegDemuxerStream to notify us when there is updated information |
160 // about capacity and what buffered data is available. | 160 // about capacity and what buffered data is available. |
161 void NotifyCapacityAvailable(); | 161 void NotifyCapacityAvailable(); |
162 void NotifyBufferingChanged(); | 162 void NotifyBufferingChanged(); |
163 | 163 |
164 private: | 164 private: |
165 // To allow tests access to privates. | 165 // To allow tests access to privates. |
166 friend class FFmpegDemuxerTest; | 166 friend class FFmpegDemuxerTest; |
167 | 167 |
168 virtual ~FFmpegDemuxer(); | |
169 | |
170 // FFmpeg callbacks during initialization. | 168 // FFmpeg callbacks during initialization. |
171 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); | 169 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); |
172 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); | 170 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); |
173 | 171 |
174 // FFmpeg callbacks during seeking. | 172 // FFmpeg callbacks during seeking. |
175 void OnSeekFrameDone(const PipelineStatusCB& cb, int result); | 173 void OnSeekFrameDone(const PipelineStatusCB& cb, int result); |
176 | 174 |
177 // FFmpeg callbacks during reading + helper method to initiate reads. | 175 // FFmpeg callbacks during reading + helper method to initiate reads. |
178 void ReadFrameIfNeeded(); | 176 void ReadFrameIfNeeded(); |
179 void OnReadFrameDone(ScopedAVPacket packet, int result); | 177 void OnReadFrameDone(ScopedAVPacket packet, int result); |
(...skipping 12 matching lines...) Expand all Loading... |
192 void OnDataSourceError(); | 190 void OnDataSourceError(); |
193 | 191 |
194 // Returns the stream from |streams_| that matches |type| as an | 192 // Returns the stream from |streams_| that matches |type| as an |
195 // FFmpegDemuxerStream. | 193 // FFmpegDemuxerStream. |
196 scoped_refptr<FFmpegDemuxerStream> GetFFmpegStream( | 194 scoped_refptr<FFmpegDemuxerStream> GetFFmpegStream( |
197 DemuxerStream::Type type) const; | 195 DemuxerStream::Type type) const; |
198 | 196 |
199 DemuxerHost* host_; | 197 DemuxerHost* host_; |
200 | 198 |
201 scoped_refptr<base::MessageLoopProxy> message_loop_; | 199 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 200 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; |
| 201 base::WeakPtr<FFmpegDemuxer> weak_this_; |
202 | 202 |
203 // Thread on which all blocking FFmpeg operations are executed. | 203 // Thread on which all blocking FFmpeg operations are executed. |
204 base::Thread blocking_thread_; | 204 base::Thread blocking_thread_; |
205 | 205 |
206 // Tracks if there's an outstanding av_read_frame() operation. | 206 // Tracks if there's an outstanding av_read_frame() operation. |
207 // | 207 // |
208 // TODO(scherkus): Allow more than one read in flight for higher read | 208 // TODO(scherkus): Allow more than one read in flight for higher read |
209 // throughput using demuxer_bench to verify improvements. | 209 // throughput using demuxer_bench to verify improvements. |
210 bool pending_read_; | 210 bool pending_read_; |
211 | 211 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 scoped_ptr<FFmpegGlue> glue_; | 250 scoped_ptr<FFmpegGlue> glue_; |
251 | 251 |
252 const FFmpegNeedKeyCB need_key_cb_; | 252 const FFmpegNeedKeyCB need_key_cb_; |
253 | 253 |
254 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 254 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
255 }; | 255 }; |
256 | 256 |
257 } // namespace media | 257 } // namespace media |
258 | 258 |
259 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 259 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
OLD | NEW |