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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 typedef std::unique_ptr<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket; | 62 typedef std::unique_ptr<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket; |
63 | 63 |
64 class MEDIA_EXPORT FFmpegDemuxerStream : public DemuxerStream { | 64 class MEDIA_EXPORT FFmpegDemuxerStream : public DemuxerStream { |
65 public: | 65 public: |
66 // Attempts to create FFmpegDemuxerStream form the given AVStream. Will return | 66 // Attempts to create FFmpegDemuxerStream form the given AVStream. Will return |
67 // null if the AVStream cannot be translated into a valid decoder config. | 67 // null if the AVStream cannot be translated into a valid decoder config. |
68 // | 68 // |
69 // FFmpegDemuxerStream keeps a copy of |demuxer| and initializes itself using | 69 // FFmpegDemuxerStream keeps a copy of |demuxer| and initializes itself using |
70 // information inside |stream|. Both parameters must outlive |this|. | 70 // information inside |stream|. Both parameters must outlive |this|. |
71 static std::unique_ptr<FFmpegDemuxerStream> Create( | 71 static std::unique_ptr<FFmpegDemuxerStream> Create(FFmpegDemuxer* demuxer, |
72 FFmpegDemuxer* demuxer, | 72 AVStream* stream, |
73 AVStream* stream, | 73 MediaLog* media_log); |
74 const scoped_refptr<MediaLog>& media_log); | |
75 | 74 |
76 ~FFmpegDemuxerStream() override; | 75 ~FFmpegDemuxerStream() override; |
77 | 76 |
78 // Enqueues the given AVPacket. It is invalid to queue a |packet| after | 77 // Enqueues the given AVPacket. It is invalid to queue a |packet| after |
79 // SetEndOfStream() has been called. | 78 // SetEndOfStream() has been called. |
80 void EnqueuePacket(ScopedAVPacket packet); | 79 void EnqueuePacket(ScopedAVPacket packet); |
81 | 80 |
82 // Enters the end of stream state. After delivering remaining queued buffers | 81 // Enters the end of stream state. After delivering remaining queued buffers |
83 // only end of stream buffers will be delivered. | 82 // only end of stream buffers will be delivered. |
84 void SetEndOfStream(); | 83 void SetEndOfStream(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 friend class FFmpegDemuxerTest; | 147 friend class FFmpegDemuxerTest; |
149 | 148 |
150 // Use FFmpegDemuxerStream::Create to construct. | 149 // Use FFmpegDemuxerStream::Create to construct. |
151 // Audio/Video streams must include their respective DecoderConfig. At most | 150 // Audio/Video streams must include their respective DecoderConfig. At most |
152 // one DecoderConfig should be provided (leaving the other nullptr). Both | 151 // one DecoderConfig should be provided (leaving the other nullptr). Both |
153 // configs should be null for text streams. | 152 // configs should be null for text streams. |
154 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, | 153 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, |
155 AVStream* stream, | 154 AVStream* stream, |
156 std::unique_ptr<AudioDecoderConfig> audio_config, | 155 std::unique_ptr<AudioDecoderConfig> audio_config, |
157 std::unique_ptr<VideoDecoderConfig> video_config, | 156 std::unique_ptr<VideoDecoderConfig> video_config, |
158 scoped_refptr<MediaLog> media_log); | 157 MediaLog* media_log); |
159 | 158 |
160 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling | 159 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling |
161 // NotifyCapacityAvailable() if capacity is still available. | 160 // NotifyCapacityAvailable() if capacity is still available. |
162 void SatisfyPendingRead(); | 161 void SatisfyPendingRead(); |
163 | 162 |
164 // Converts an FFmpeg stream timestamp into a base::TimeDelta. | 163 // Converts an FFmpeg stream timestamp into a base::TimeDelta. |
165 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, | 164 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, |
166 int64_t timestamp); | 165 int64_t timestamp); |
167 | 166 |
168 // Resets any currently active bitstream converter. | 167 // Resets any currently active bitstream converter. |
169 void ResetBitstreamConverter(); | 168 void ResetBitstreamConverter(); |
170 | 169 |
171 // Create new bitstream converter, destroying active converter if present. | 170 // Create new bitstream converter, destroying active converter if present. |
172 void InitBitstreamConverter(); | 171 void InitBitstreamConverter(); |
173 | 172 |
174 FFmpegDemuxer* demuxer_; | 173 FFmpegDemuxer* demuxer_; |
175 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 174 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
176 AVStream* stream_; | 175 AVStream* stream_; |
177 base::TimeDelta start_time_; | 176 base::TimeDelta start_time_; |
178 std::unique_ptr<AudioDecoderConfig> audio_config_; | 177 std::unique_ptr<AudioDecoderConfig> audio_config_; |
179 std::unique_ptr<VideoDecoderConfig> video_config_; | 178 std::unique_ptr<VideoDecoderConfig> video_config_; |
180 scoped_refptr<MediaLog> media_log_; | 179 MediaLog* media_log_; |
181 Type type_; | 180 Type type_; |
182 Liveness liveness_; | 181 Liveness liveness_; |
183 base::TimeDelta duration_; | 182 base::TimeDelta duration_; |
184 bool end_of_stream_; | 183 bool end_of_stream_; |
185 base::TimeDelta last_packet_timestamp_; | 184 base::TimeDelta last_packet_timestamp_; |
186 base::TimeDelta last_packet_duration_; | 185 base::TimeDelta last_packet_duration_; |
187 Ranges<base::TimeDelta> buffered_ranges_; | 186 Ranges<base::TimeDelta> buffered_ranges_; |
188 VideoRotation video_rotation_; | 187 VideoRotation video_rotation_; |
189 bool is_enabled_; | 188 bool is_enabled_; |
190 bool waiting_for_keyframe_; | 189 bool waiting_for_keyframe_; |
(...skipping 12 matching lines...) Expand all Loading... |
203 | 202 |
204 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); | 203 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); |
205 }; | 204 }; |
206 | 205 |
207 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { | 206 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { |
208 public: | 207 public: |
209 FFmpegDemuxer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 208 FFmpegDemuxer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
210 DataSource* data_source, | 209 DataSource* data_source, |
211 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 210 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
212 const MediaTracksUpdatedCB& media_tracks_updated_cb, | 211 const MediaTracksUpdatedCB& media_tracks_updated_cb, |
213 const scoped_refptr<MediaLog>& media_log); | 212 MediaLog* media_log); |
214 ~FFmpegDemuxer() override; | 213 ~FFmpegDemuxer() override; |
215 | 214 |
216 // Demuxer implementation. | 215 // Demuxer implementation. |
217 std::string GetDisplayName() const override; | 216 std::string GetDisplayName() const override; |
218 void Initialize(DemuxerHost* host, | 217 void Initialize(DemuxerHost* host, |
219 const PipelineStatusCB& status_cb, | 218 const PipelineStatusCB& status_cb, |
220 bool enable_text_tracks) override; | 219 bool enable_text_tracks) override; |
221 void AbortPendingReads() override; | 220 void AbortPendingReads() override; |
222 void Stop() override; | 221 void Stop() override; |
223 void StartWaitingForSeek(base::TimeDelta seek_time) override; | 222 void StartWaitingForSeek(base::TimeDelta seek_time) override; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // | 324 // |
326 // Once initialized, operations on FFmpegDemuxerStreams should be carried out | 325 // Once initialized, operations on FFmpegDemuxerStreams should be carried out |
327 // on the demuxer thread. | 326 // on the demuxer thread. |
328 using StreamVector = std::vector<std::unique_ptr<FFmpegDemuxerStream>>; | 327 using StreamVector = std::vector<std::unique_ptr<FFmpegDemuxerStream>>; |
329 StreamVector streams_; | 328 StreamVector streams_; |
330 | 329 |
331 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to | 330 // Provides asynchronous IO to this demuxer. Consumed by |url_protocol_| to |
332 // integrate with libavformat. | 331 // integrate with libavformat. |
333 DataSource* data_source_; | 332 DataSource* data_source_; |
334 | 333 |
335 scoped_refptr<MediaLog> media_log_; | 334 MediaLog* media_log_; |
336 | 335 |
337 // Derived bitrate after initialization has completed. | 336 // Derived bitrate after initialization has completed. |
338 int bitrate_; | 337 int bitrate_; |
339 | 338 |
340 // The first timestamp of the audio or video stream, whichever is lower. This | 339 // The first timestamp of the audio or video stream, whichever is lower. This |
341 // is used to adjust timestamps so that external consumers always see a zero | 340 // is used to adjust timestamps so that external consumers always see a zero |
342 // based timeline. | 341 // based timeline. |
343 base::TimeDelta start_time_; | 342 base::TimeDelta start_time_; |
344 | 343 |
345 // Finds the stream with the lowest known start time (i.e. not kNoTimestamp | 344 // Finds the stream with the lowest known start time (i.e. not kNoTimestamp |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 base::WeakPtr<FFmpegDemuxer> weak_this_; | 378 base::WeakPtr<FFmpegDemuxer> weak_this_; |
380 base::WeakPtrFactory<FFmpegDemuxer> cancel_pending_seek_factory_; | 379 base::WeakPtrFactory<FFmpegDemuxer> cancel_pending_seek_factory_; |
381 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; | 380 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; |
382 | 381 |
383 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 382 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
384 }; | 383 }; |
385 | 384 |
386 } // namespace media | 385 } // namespace media |
387 | 386 |
388 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 387 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
OLD | NEW |