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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #include "base/callback.h" | 28 #include "base/callback.h" |
29 #include "base/gtest_prod_util.h" | 29 #include "base/gtest_prod_util.h" |
30 #include "base/memory/scoped_vector.h" | 30 #include "base/memory/scoped_vector.h" |
31 #include "base/threading/thread.h" | 31 #include "base/threading/thread.h" |
32 #include "media/base/audio_decoder_config.h" | 32 #include "media/base/audio_decoder_config.h" |
33 #include "media/base/decoder_buffer.h" | 33 #include "media/base/decoder_buffer.h" |
34 #include "media/base/decoder_buffer_queue.h" | 34 #include "media/base/decoder_buffer_queue.h" |
35 #include "media/base/demuxer.h" | 35 #include "media/base/demuxer.h" |
36 #include "media/base/pipeline.h" | 36 #include "media/base/pipeline.h" |
| 37 #include "media/base/text_track.h" |
37 #include "media/base/video_decoder_config.h" | 38 #include "media/base/video_decoder_config.h" |
38 #include "media/filters/blocking_url_protocol.h" | 39 #include "media/filters/blocking_url_protocol.h" |
39 | 40 |
40 // FFmpeg forward declarations. | 41 // FFmpeg forward declarations. |
41 struct AVPacket; | 42 struct AVPacket; |
42 struct AVRational; | 43 struct AVRational; |
43 struct AVStream; | 44 struct AVStream; |
44 | 45 |
45 namespace media { | 46 namespace media { |
46 | 47 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // Returns the range of buffered data in this stream. | 87 // Returns the range of buffered data in this stream. |
87 Ranges<base::TimeDelta> GetBufferedRanges() const; | 88 Ranges<base::TimeDelta> GetBufferedRanges() const; |
88 | 89 |
89 // Returns elapsed time based on the already queued packets. | 90 // Returns elapsed time based on the already queued packets. |
90 // Used to determine stream duration when it's not known ahead of time. | 91 // Used to determine stream duration when it's not known ahead of time. |
91 base::TimeDelta GetElapsedTime() const; | 92 base::TimeDelta GetElapsedTime() const; |
92 | 93 |
93 // Returns true if this stream has capacity for additional data. | 94 // Returns true if this stream has capacity for additional data. |
94 bool HasAvailableCapacity(); | 95 bool HasAvailableCapacity(); |
95 | 96 |
| 97 TextKind GetTextKind() const; |
| 98 |
| 99 // Returns the value associated with |key| in the metadata for the avstream. |
| 100 // Returns an empty string if the key is not present. |
| 101 std::string GetMetadata(const char* key) const; |
| 102 |
96 private: | 103 private: |
97 friend class FFmpegDemuxerTest; | 104 friend class FFmpegDemuxerTest; |
98 | 105 |
99 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling | 106 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling |
100 // NotifyCapacityAvailable() if capacity is still available. | 107 // NotifyCapacityAvailable() if capacity is still available. |
101 void SatisfyPendingRead(); | 108 void SatisfyPendingRead(); |
102 | 109 |
103 // Converts an FFmpeg stream timestamp into a base::TimeDelta. | 110 // Converts an FFmpeg stream timestamp into a base::TimeDelta. |
104 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, | 111 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, |
105 int64 timestamp); | 112 int64 timestamp); |
(...skipping 18 matching lines...) Expand all Loading... |
124 std::string encryption_key_id_; | 131 std::string encryption_key_id_; |
125 | 132 |
126 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); | 133 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); |
127 }; | 134 }; |
128 | 135 |
129 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { | 136 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { |
130 public: | 137 public: |
131 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 138 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, |
132 DataSource* data_source, | 139 DataSource* data_source, |
133 const NeedKeyCB& need_key_cb, | 140 const NeedKeyCB& need_key_cb, |
| 141 bool enable_text, |
134 const scoped_refptr<MediaLog>& media_log); | 142 const scoped_refptr<MediaLog>& media_log); |
135 virtual ~FFmpegDemuxer(); | 143 virtual ~FFmpegDemuxer(); |
136 | 144 |
137 // Demuxer implementation. | 145 // Demuxer implementation. |
138 virtual void Initialize(DemuxerHost* host, | 146 virtual void Initialize(DemuxerHost* host, |
139 const PipelineStatusCB& status_cb) OVERRIDE; | 147 const PipelineStatusCB& status_cb) OVERRIDE; |
140 virtual void Stop(const base::Closure& callback) OVERRIDE; | 148 virtual void Stop(const base::Closure& callback) OVERRIDE; |
141 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 149 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
142 virtual void OnAudioRendererDisabled() OVERRIDE; | 150 virtual void OnAudioRendererDisabled() OVERRIDE; |
143 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; | 151 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // Signal all FFmpegDemuxerStreams that the stream has ended. | 186 // Signal all FFmpegDemuxerStreams that the stream has ended. |
179 void StreamHasEnded(); | 187 void StreamHasEnded(); |
180 | 188 |
181 // Called by |url_protocol_| whenever |data_source_| returns a read error. | 189 // Called by |url_protocol_| whenever |data_source_| returns a read error. |
182 void OnDataSourceError(); | 190 void OnDataSourceError(); |
183 | 191 |
184 // Returns the stream from |streams_| that matches |type| as an | 192 // Returns the stream from |streams_| that matches |type| as an |
185 // FFmpegDemuxerStream. | 193 // FFmpegDemuxerStream. |
186 FFmpegDemuxerStream* GetFFmpegStream(DemuxerStream::Type type) const; | 194 FFmpegDemuxerStream* GetFFmpegStream(DemuxerStream::Type type) const; |
187 | 195 |
| 196 // Called after the streams have been collected from the media, to allow |
| 197 // the text renderer to bind each text stream to the cue rendering engine. |
| 198 void AddTextStreams(); |
| 199 |
188 DemuxerHost* host_; | 200 DemuxerHost* host_; |
189 | 201 |
190 scoped_refptr<base::MessageLoopProxy> message_loop_; | 202 scoped_refptr<base::MessageLoopProxy> message_loop_; |
191 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; | 203 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; |
192 base::WeakPtr<FFmpegDemuxer> weak_this_; | 204 base::WeakPtr<FFmpegDemuxer> weak_this_; |
193 | 205 |
194 // Thread on which all blocking FFmpeg operations are executed. | 206 // Thread on which all blocking FFmpeg operations are executed. |
195 base::Thread blocking_thread_; | 207 base::Thread blocking_thread_; |
196 | 208 |
197 // Tracks if there's an outstanding av_read_frame() operation. | 209 // Tracks if there's an outstanding av_read_frame() operation. |
(...skipping 29 matching lines...) Expand all Loading... |
227 | 239 |
228 // The first timestamp of the opened media file. This is used to set the | 240 // The first timestamp of the opened media file. This is used to set the |
229 // starting clock value to match the timestamps in the media file. Default | 241 // starting clock value to match the timestamps in the media file. Default |
230 // is 0. | 242 // is 0. |
231 base::TimeDelta start_time_; | 243 base::TimeDelta start_time_; |
232 | 244 |
233 // Whether audio has been disabled for this demuxer (in which case this class | 245 // Whether audio has been disabled for this demuxer (in which case this class |
234 // drops packets destined for AUDIO demuxer streams on the floor). | 246 // drops packets destined for AUDIO demuxer streams on the floor). |
235 bool audio_disabled_; | 247 bool audio_disabled_; |
236 | 248 |
| 249 // Whether text streams have been enabled for this demuxer. |
| 250 bool text_enabled_; |
| 251 |
237 // Set if we know duration of the audio stream. Used when processing end of | 252 // Set if we know duration of the audio stream. Used when processing end of |
238 // stream -- at this moment we definitely know duration. | 253 // stream -- at this moment we definitely know duration. |
239 bool duration_known_; | 254 bool duration_known_; |
240 | 255 |
241 // FFmpegURLProtocol implementation and corresponding glue bits. | 256 // FFmpegURLProtocol implementation and corresponding glue bits. |
242 BlockingUrlProtocol url_protocol_; | 257 BlockingUrlProtocol url_protocol_; |
243 scoped_ptr<FFmpegGlue> glue_; | 258 scoped_ptr<FFmpegGlue> glue_; |
244 | 259 |
245 const NeedKeyCB need_key_cb_; | 260 const NeedKeyCB need_key_cb_; |
246 | 261 |
247 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 262 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
248 }; | 263 }; |
249 | 264 |
250 } // namespace media | 265 } // namespace media |
251 | 266 |
252 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 267 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
OLD | NEW |