| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 // Returns the total buffer size FFMpegDemuxerStream is holding onto. | 129 // Returns the total buffer size FFMpegDemuxerStream is holding onto. |
| 130 size_t MemoryUsage() const; | 130 size_t MemoryUsage() const; |
| 131 | 131 |
| 132 TextKind GetTextKind() const; | 132 TextKind GetTextKind() const; |
| 133 | 133 |
| 134 // Returns the value associated with |key| in the metadata for the avstream. | 134 // Returns the value associated with |key| in the metadata for the avstream. |
| 135 // Returns an empty string if the key is not present. | 135 // Returns an empty string if the key is not present. |
| 136 std::string GetMetadata(const char* key) const; | 136 std::string GetMetadata(const char* key) const; |
| 137 | 137 |
| 138 AVStream* av_stream() const { return stream_; } |
| 139 |
| 140 base::TimeDelta start_time() const { return start_time_; } |
| 141 void set_start_time(base::TimeDelta time) { start_time_ = time; } |
| 142 |
| 138 private: | 143 private: |
| 139 friend class FFmpegDemuxerTest; | 144 friend class FFmpegDemuxerTest; |
| 140 | 145 |
| 141 // Use FFmpegDemuxerStream::Create to construct. | 146 // Use FFmpegDemuxerStream::Create to construct. |
| 142 // Audio/Video streams must include their respective DecoderConfig. At most | 147 // Audio/Video streams must include their respective DecoderConfig. At most |
| 143 // one DecoderConfig should be provided (leaving the other nullptr). Both | 148 // one DecoderConfig should be provided (leaving the other nullptr). Both |
| 144 // configs should be null for text streams. | 149 // configs should be null for text streams. |
| 145 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, | 150 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, |
| 146 AVStream* stream, | 151 AVStream* stream, |
| 147 std::unique_ptr<AudioDecoderConfig> audio_config, | 152 std::unique_ptr<AudioDecoderConfig> audio_config, |
| 148 std::unique_ptr<VideoDecoderConfig> video_config); | 153 std::unique_ptr<VideoDecoderConfig> video_config); |
| 149 | 154 |
| 150 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling | 155 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling |
| 151 // NotifyCapacityAvailable() if capacity is still available. | 156 // NotifyCapacityAvailable() if capacity is still available. |
| 152 void SatisfyPendingRead(); | 157 void SatisfyPendingRead(); |
| 153 | 158 |
| 154 // Converts an FFmpeg stream timestamp into a base::TimeDelta. | 159 // Converts an FFmpeg stream timestamp into a base::TimeDelta. |
| 155 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, | 160 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, |
| 156 int64_t timestamp); | 161 int64_t timestamp); |
| 157 | 162 |
| 158 // Resets any currently active bitstream converter. | 163 // Resets any currently active bitstream converter. |
| 159 void ResetBitstreamConverter(); | 164 void ResetBitstreamConverter(); |
| 160 | 165 |
| 161 // Create new bitstream converter, destroying active converter if present. | 166 // Create new bitstream converter, destroying active converter if present. |
| 162 void InitBitstreamConverter(); | 167 void InitBitstreamConverter(); |
| 163 | 168 |
| 164 FFmpegDemuxer* demuxer_; | 169 FFmpegDemuxer* demuxer_; |
| 165 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 170 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 166 AVStream* stream_; | 171 AVStream* stream_; |
| 172 base::TimeDelta start_time_; |
| 167 std::unique_ptr<AudioDecoderConfig> audio_config_; | 173 std::unique_ptr<AudioDecoderConfig> audio_config_; |
| 168 std::unique_ptr<VideoDecoderConfig> video_config_; | 174 std::unique_ptr<VideoDecoderConfig> video_config_; |
| 169 Type type_; | 175 Type type_; |
| 170 Liveness liveness_; | 176 Liveness liveness_; |
| 171 base::TimeDelta duration_; | 177 base::TimeDelta duration_; |
| 172 bool end_of_stream_; | 178 bool end_of_stream_; |
| 173 base::TimeDelta last_packet_timestamp_; | 179 base::TimeDelta last_packet_timestamp_; |
| 174 base::TimeDelta last_packet_duration_; | 180 base::TimeDelta last_packet_duration_; |
| 175 Ranges<base::TimeDelta> buffered_ranges_; | 181 Ranges<base::TimeDelta> buffered_ranges_; |
| 176 VideoRotation video_rotation_; | 182 VideoRotation video_rotation_; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 scoped_refptr<MediaLog> media_log_; | 315 scoped_refptr<MediaLog> media_log_; |
| 310 | 316 |
| 311 // Derived bitrate after initialization has completed. | 317 // Derived bitrate after initialization has completed. |
| 312 int bitrate_; | 318 int bitrate_; |
| 313 | 319 |
| 314 // The first timestamp of the audio or video stream, whichever is lower. This | 320 // The first timestamp of the audio or video stream, whichever is lower. This |
| 315 // is used to adjust timestamps so that external consumers always see a zero | 321 // is used to adjust timestamps so that external consumers always see a zero |
| 316 // based timeline. | 322 // based timeline. |
| 317 base::TimeDelta start_time_; | 323 base::TimeDelta start_time_; |
| 318 | 324 |
| 319 // The index and start time of the preferred streams for seeking. Filled upon | 325 // Finds a preferred stream for seeking to |seek_time|. Preference is |
| 320 // completion of OnFindStreamInfoDone(). Each info entry represents an index | 326 // typically given to video streams, unless the |seek_time| is earlier than |
| 321 // into |streams_| and the start time of that stream. | 327 // the start time of the video stream. In that case a stream with the earliest |
| 322 // | 328 // start time is preferred. Disabled streams are not considered. |
| 323 // Seek() will attempt to use |preferred_stream_for_seeking_| if the seek | 329 FFmpegDemuxerStream* FindPreferredStreamForSeeking(base::TimeDelta seek_time); |
| 324 // point occurs after its associated start time. Otherwise it will use | |
| 325 // |fallback_stream_for_seeking_|. | |
| 326 typedef std::pair<int, base::TimeDelta> StreamSeekInfo; | |
| 327 StreamSeekInfo preferred_stream_for_seeking_; | |
| 328 StreamSeekInfo fallback_stream_for_seeking_; | |
| 329 | 330 |
| 330 // The Time associated with timestamp 0. Set to a null | 331 // The Time associated with timestamp 0. Set to a null |
| 331 // time if the file doesn't have an association to Time. | 332 // time if the file doesn't have an association to Time. |
| 332 base::Time timeline_offset_; | 333 base::Time timeline_offset_; |
| 333 | 334 |
| 334 // Whether text streams have been enabled for this demuxer. | 335 // Whether text streams have been enabled for this demuxer. |
| 335 bool text_enabled_; | 336 bool text_enabled_; |
| 336 | 337 |
| 337 // Set if we know duration of the audio stream. Used when processing end of | 338 // Set if we know duration of the audio stream. Used when processing end of |
| 338 // stream -- at this moment we definitely know duration. | 339 // stream -- at this moment we definitely know duration. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 350 | 351 |
| 351 // NOTE: Weak pointers must be invalidated before all other member variables. | 352 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 352 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; | 353 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; |
| 353 | 354 |
| 354 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 355 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
| 355 }; | 356 }; |
| 356 | 357 |
| 357 } // namespace media | 358 } // namespace media |
| 358 | 359 |
| 359 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 360 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
| OLD | NEW |