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 // |
11 // FFmpegDemuxer sets the duration of pipeline during initialization by using | 11 // FFmpegDemuxer sets the duration of pipeline during initialization by using |
12 // the duration of the longest audio/video stream. | 12 // the duration of the longest audio/video stream. |
13 // | 13 // |
14 // NOTE: since FFmpegDemuxer reads packets sequentially without seeking, media | 14 // NOTE: since FFmpegDemuxer reads packets sequentially without seeking, media |
15 // files with very large drift between audio/video streams may result in | 15 // files with very large drift between audio/video streams may result in |
16 // excessive memory consumption. | 16 // excessive memory consumption. |
17 // | 17 // |
18 // When stopped, FFmpegDemuxer and FFmpegDemuxerStream release all callbacks | 18 // When stopped, FFmpegDemuxer and FFmpegDemuxerStream release all callbacks |
19 // and buffered packets. Reads from a stopped FFmpegDemuxerStream will not be | 19 // and buffered packets. Reads from a stopped FFmpegDemuxerStream will not be |
20 // replied to. | 20 // replied to. |
21 | 21 |
22 #ifndef MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 22 #ifndef MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
23 #define MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 23 #define MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
24 | 24 |
25 #include <stddef.h> | 25 #include <stddef.h> |
26 #include <stdint.h> | 26 #include <stdint.h> |
27 | 27 |
| 28 #include <memory> |
28 #include <string> | 29 #include <string> |
29 #include <utility> | 30 #include <utility> |
30 #include <vector> | 31 #include <vector> |
31 | 32 |
32 #include "base/callback.h" | 33 #include "base/callback.h" |
33 #include "base/macros.h" | 34 #include "base/macros.h" |
34 #include "base/memory/scoped_ptr.h" | |
35 #include "base/memory/scoped_vector.h" | 35 #include "base/memory/scoped_vector.h" |
36 #include "base/threading/thread.h" | 36 #include "base/threading/thread.h" |
37 #include "media/base/audio_decoder_config.h" | 37 #include "media/base/audio_decoder_config.h" |
38 #include "media/base/decoder_buffer.h" | 38 #include "media/base/decoder_buffer.h" |
39 #include "media/base/decoder_buffer_queue.h" | 39 #include "media/base/decoder_buffer_queue.h" |
40 #include "media/base/demuxer.h" | 40 #include "media/base/demuxer.h" |
41 #include "media/base/pipeline_status.h" | 41 #include "media/base/pipeline_status.h" |
42 #include "media/base/text_track_config.h" | 42 #include "media/base/text_track_config.h" |
43 #include "media/base/video_decoder_config.h" | 43 #include "media/base/video_decoder_config.h" |
44 #include "media/ffmpeg/ffmpeg_deleters.h" | 44 #include "media/ffmpeg/ffmpeg_deleters.h" |
45 #include "media/filters/blocking_url_protocol.h" | 45 #include "media/filters/blocking_url_protocol.h" |
46 | 46 |
47 // FFmpeg forward declarations. | 47 // FFmpeg forward declarations. |
48 struct AVPacket; | 48 struct AVPacket; |
49 struct AVRational; | 49 struct AVRational; |
50 struct AVStream; | 50 struct AVStream; |
51 | 51 |
52 namespace media { | 52 namespace media { |
53 | 53 |
54 class MediaLog; | 54 class MediaLog; |
55 class FFmpegBitstreamConverter; | 55 class FFmpegBitstreamConverter; |
56 class FFmpegDemuxer; | 56 class FFmpegDemuxer; |
57 class FFmpegGlue; | 57 class FFmpegGlue; |
58 | 58 |
59 typedef scoped_ptr<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket; | 59 typedef std::unique_ptr<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket; |
60 | 60 |
61 class FFmpegDemuxerStream : public DemuxerStream { | 61 class FFmpegDemuxerStream : public DemuxerStream { |
62 public: | 62 public: |
63 // Attempts to create FFmpegDemuxerStream form the given AVStream. Will return | 63 // Attempts to create FFmpegDemuxerStream form the given AVStream. Will return |
64 // null if the AVStream cannot be translated into a valid decoder config. | 64 // null if the AVStream cannot be translated into a valid decoder config. |
65 // | 65 // |
66 // FFmpegDemuxerStream keeps a copy of |demuxer| and initializes itself using | 66 // FFmpegDemuxerStream keeps a copy of |demuxer| and initializes itself using |
67 // information inside |stream|. Both parameters must outlive |this|. | 67 // information inside |stream|. Both parameters must outlive |this|. |
68 static scoped_ptr<FFmpegDemuxerStream> Create( | 68 static std::unique_ptr<FFmpegDemuxerStream> Create( |
69 FFmpegDemuxer* demuxer, | 69 FFmpegDemuxer* demuxer, |
70 AVStream* stream, | 70 AVStream* stream, |
71 const scoped_refptr<MediaLog>& media_log); | 71 const scoped_refptr<MediaLog>& media_log); |
72 | 72 |
73 ~FFmpegDemuxerStream() override; | 73 ~FFmpegDemuxerStream() override; |
74 | 74 |
75 // Enqueues the given AVPacket. It is invalid to queue a |packet| after | 75 // Enqueues the given AVPacket. It is invalid to queue a |packet| after |
76 // SetEndOfStream() has been called. | 76 // SetEndOfStream() has been called. |
77 void EnqueuePacket(ScopedAVPacket packet); | 77 void EnqueuePacket(ScopedAVPacket packet); |
78 | 78 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 private: | 135 private: |
136 friend class FFmpegDemuxerTest; | 136 friend class FFmpegDemuxerTest; |
137 | 137 |
138 // Use FFmpegDemuxerStream::Create to construct. | 138 // Use FFmpegDemuxerStream::Create to construct. |
139 // Audio/Video streams must include their respective DecoderConfig. At most | 139 // Audio/Video streams must include their respective DecoderConfig. At most |
140 // one DecoderConfig should be provided (leaving the other nullptr). Both | 140 // one DecoderConfig should be provided (leaving the other nullptr). Both |
141 // configs should be null for text streams. | 141 // configs should be null for text streams. |
142 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, | 142 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, |
143 AVStream* stream, | 143 AVStream* stream, |
144 scoped_ptr<AudioDecoderConfig> audio_config, | 144 std::unique_ptr<AudioDecoderConfig> audio_config, |
145 scoped_ptr<VideoDecoderConfig> video_config); | 145 std::unique_ptr<VideoDecoderConfig> video_config); |
146 | 146 |
147 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling | 147 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling |
148 // NotifyCapacityAvailable() if capacity is still available. | 148 // NotifyCapacityAvailable() if capacity is still available. |
149 void SatisfyPendingRead(); | 149 void SatisfyPendingRead(); |
150 | 150 |
151 // Converts an FFmpeg stream timestamp into a base::TimeDelta. | 151 // Converts an FFmpeg stream timestamp into a base::TimeDelta. |
152 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, | 152 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, |
153 int64_t timestamp); | 153 int64_t timestamp); |
154 | 154 |
155 // Resets any currently active bitstream converter. | 155 // Resets any currently active bitstream converter. |
156 void ResetBitstreamConverter(); | 156 void ResetBitstreamConverter(); |
157 | 157 |
158 // Create new bitstream converter, destroying active converter if present. | 158 // Create new bitstream converter, destroying active converter if present. |
159 void InitBitstreamConverter(); | 159 void InitBitstreamConverter(); |
160 | 160 |
161 FFmpegDemuxer* demuxer_; | 161 FFmpegDemuxer* demuxer_; |
162 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 162 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
163 AVStream* stream_; | 163 AVStream* stream_; |
164 scoped_ptr<AudioDecoderConfig> audio_config_; | 164 std::unique_ptr<AudioDecoderConfig> audio_config_; |
165 scoped_ptr<VideoDecoderConfig> video_config_; | 165 std::unique_ptr<VideoDecoderConfig> video_config_; |
166 Type type_; | 166 Type type_; |
167 Liveness liveness_; | 167 Liveness liveness_; |
168 base::TimeDelta duration_; | 168 base::TimeDelta duration_; |
169 bool end_of_stream_; | 169 bool end_of_stream_; |
170 base::TimeDelta last_packet_timestamp_; | 170 base::TimeDelta last_packet_timestamp_; |
171 base::TimeDelta last_packet_duration_; | 171 base::TimeDelta last_packet_duration_; |
172 Ranges<base::TimeDelta> buffered_ranges_; | 172 Ranges<base::TimeDelta> buffered_ranges_; |
173 VideoRotation video_rotation_; | 173 VideoRotation video_rotation_; |
174 | 174 |
175 DecoderBufferQueue buffer_queue_; | 175 DecoderBufferQueue buffer_queue_; |
176 ReadCB read_cb_; | 176 ReadCB read_cb_; |
177 | 177 |
178 #if defined(USE_PROPRIETARY_CODECS) | 178 #if defined(USE_PROPRIETARY_CODECS) |
179 scoped_ptr<FFmpegBitstreamConverter> bitstream_converter_; | 179 std::unique_ptr<FFmpegBitstreamConverter> bitstream_converter_; |
180 #endif | 180 #endif |
181 | 181 |
182 std::string encryption_key_id_; | 182 std::string encryption_key_id_; |
183 bool fixup_negative_timestamps_; | 183 bool fixup_negative_timestamps_; |
184 | 184 |
185 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); | 185 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); |
186 }; | 186 }; |
187 | 187 |
188 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { | 188 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { |
189 public: | 189 public: |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 base::Time timeline_offset_; | 320 base::Time timeline_offset_; |
321 | 321 |
322 // Whether text streams have been enabled for this demuxer. | 322 // Whether text streams have been enabled for this demuxer. |
323 bool text_enabled_; | 323 bool text_enabled_; |
324 | 324 |
325 // Set if we know duration of the audio stream. Used when processing end of | 325 // Set if we know duration of the audio stream. Used when processing end of |
326 // stream -- at this moment we definitely know duration. | 326 // stream -- at this moment we definitely know duration. |
327 bool duration_known_; | 327 bool duration_known_; |
328 | 328 |
329 // FFmpegURLProtocol implementation and corresponding glue bits. | 329 // FFmpegURLProtocol implementation and corresponding glue bits. |
330 scoped_ptr<BlockingUrlProtocol> url_protocol_; | 330 std::unique_ptr<BlockingUrlProtocol> url_protocol_; |
331 scoped_ptr<FFmpegGlue> glue_; | 331 std::unique_ptr<FFmpegGlue> glue_; |
332 | 332 |
333 const EncryptedMediaInitDataCB encrypted_media_init_data_cb_; | 333 const EncryptedMediaInitDataCB encrypted_media_init_data_cb_; |
334 | 334 |
335 const MediaTracksUpdatedCB media_tracks_updated_cb_; | 335 const MediaTracksUpdatedCB media_tracks_updated_cb_; |
336 | 336 |
337 // NOTE: Weak pointers must be invalidated before all other member variables. | 337 // NOTE: Weak pointers must be invalidated before all other member variables. |
338 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; | 338 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; |
339 | 339 |
340 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 340 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
341 }; | 341 }; |
342 | 342 |
343 } // namespace media | 343 } // namespace media |
344 | 344 |
345 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 345 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
OLD | NEW |