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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // If |buffer_queue_| is not empty will execute on caller's thread, otherwise | 77 // If |buffer_queue_| is not empty will execute on caller's thread, otherwise |
78 // will post ReadTask to execute on demuxer's thread. Read will acquire | 78 // will post ReadTask to execute on demuxer's thread. Read will acquire |
79 // |lock_| for the life of the function so that means |read_cb| must | 79 // |lock_| for the life of the function so that means |read_cb| must |
80 // not make calls into FFmpegDemuxerStream directly or that may cause a | 80 // not make calls into FFmpegDemuxerStream directly or that may cause a |
81 // deadlock. |read_cb| should execute as quickly as possible because | 81 // deadlock. |read_cb| should execute as quickly as possible because |
82 // |lock_| is held throughout the life of the callback. | 82 // |lock_| is held throughout the life of the callback. |
83 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 83 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
84 virtual void EnableBitstreamConverter() OVERRIDE; | 84 virtual void EnableBitstreamConverter() OVERRIDE; |
85 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; | 85 virtual const AudioDecoderConfig& audio_decoder_config() OVERRIDE; |
86 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; | 86 virtual const VideoDecoderConfig& video_decoder_config() OVERRIDE; |
| 87 virtual Ranges<base::TimeDelta> GetBufferedRanges() OVERRIDE; |
87 | 88 |
88 // Returns elapsed time based on the already queued packets. | 89 // Returns elapsed time based on the already queued packets. |
89 // Used to determine stream duration when it's not known ahead of time. | 90 // Used to determine stream duration when it's not known ahead of time. |
90 base::TimeDelta GetElapsedTime() const; | 91 base::TimeDelta GetElapsedTime() const; |
91 | 92 |
92 protected: | 93 protected: |
93 virtual ~FFmpegDemuxerStream(); | 94 virtual ~FFmpegDemuxerStream(); |
94 | 95 |
95 private: | 96 private: |
96 friend class FFmpegDemuxerTest; | 97 friend class FFmpegDemuxerTest; |
(...skipping 11 matching lines...) Expand all Loading... |
108 int64 timestamp); | 109 int64 timestamp); |
109 | 110 |
110 FFmpegDemuxer* demuxer_; | 111 FFmpegDemuxer* demuxer_; |
111 AVStream* stream_; | 112 AVStream* stream_; |
112 AudioDecoderConfig audio_config_; | 113 AudioDecoderConfig audio_config_; |
113 VideoDecoderConfig video_config_; | 114 VideoDecoderConfig video_config_; |
114 Type type_; | 115 Type type_; |
115 base::TimeDelta duration_; | 116 base::TimeDelta duration_; |
116 bool discontinuous_; | 117 bool discontinuous_; |
117 bool stopped_; | 118 bool stopped_; |
| 119 base::TimeDelta last_packet_timestamp_; |
| 120 Ranges<base::TimeDelta> buffered_ranges_; |
118 | 121 |
119 typedef std::deque<scoped_refptr<DecoderBuffer> > BufferQueue; | 122 typedef std::deque<scoped_refptr<DecoderBuffer> > BufferQueue; |
120 BufferQueue buffer_queue_; | 123 BufferQueue buffer_queue_; |
121 | 124 |
122 typedef std::deque<ReadCB> ReadQueue; | 125 typedef std::deque<ReadCB> ReadQueue; |
123 ReadQueue read_queue_; | 126 ReadQueue read_queue_; |
124 | 127 |
125 // Used to translate bitstream formats. | 128 // Used to translate bitstream formats. |
126 scoped_ptr<BitstreamConverter> bitstream_converter_; | 129 scoped_ptr<BitstreamConverter> bitstream_converter_; |
127 | 130 |
128 // Used to synchronize access to |buffer_queue_|, |read_queue_|, and | 131 // Used to synchronize access to |buffer_queue_|, |read_queue_|, and |
129 // |stopped_|. This is so other threads can get access to buffers that have | 132 // |stopped_|. This is so other threads can get access to buffers that have |
130 // already been demuxed without having the demuxer thread sending the | 133 // already been demuxed without having the demuxer thread sending the |
131 // buffers. |lock_| must be acquired before any access to |buffer_queue_|, | 134 // buffers. |lock_| must be acquired before any access to |buffer_queue_|, |
132 // |read_queue_|, or |stopped_|. | 135 // |read_queue_|, or |stopped_|. |
133 base::Lock lock_; | 136 mutable base::Lock lock_; |
134 | 137 |
135 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); | 138 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); |
136 }; | 139 }; |
137 | 140 |
138 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer, public FFmpegURLProtocol { | 141 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer, public FFmpegURLProtocol { |
139 public: | 142 public: |
140 FFmpegDemuxer(MessageLoop* message_loop, | 143 FFmpegDemuxer(MessageLoop* message_loop, |
141 const scoped_refptr<DataSource>& data_source); | 144 const scoped_refptr<DataSource>& data_source); |
142 | 145 |
143 // Posts a task to perform additional demuxing. | 146 // Posts a task to perform additional demuxing. |
(...skipping 14 matching lines...) Expand all Loading... |
158 // FFmpegURLProtocol implementation. | 161 // FFmpegURLProtocol implementation. |
159 virtual size_t Read(size_t size, uint8* data) OVERRIDE; | 162 virtual size_t Read(size_t size, uint8* data) OVERRIDE; |
160 virtual bool GetPosition(int64* position_out) OVERRIDE; | 163 virtual bool GetPosition(int64* position_out) OVERRIDE; |
161 virtual bool SetPosition(int64 position) OVERRIDE; | 164 virtual bool SetPosition(int64 position) OVERRIDE; |
162 virtual bool GetSize(int64* size_out) OVERRIDE; | 165 virtual bool GetSize(int64* size_out) OVERRIDE; |
163 virtual bool IsStreaming() OVERRIDE; | 166 virtual bool IsStreaming() OVERRIDE; |
164 | 167 |
165 // Provide access to FFmpegDemuxerStream. | 168 // Provide access to FFmpegDemuxerStream. |
166 MessageLoop* message_loop(); | 169 MessageLoop* message_loop(); |
167 | 170 |
| 171 // Allow FFmpegDemuxerStream to notify us when there is updated information |
| 172 // about what buffered data is available. |
| 173 void NotifyBufferingChanged(); |
| 174 |
168 private: | 175 private: |
169 // To allow tests access to privates. | 176 // To allow tests access to privates. |
170 friend class FFmpegDemuxerTest; | 177 friend class FFmpegDemuxerTest; |
171 | 178 |
172 virtual ~FFmpegDemuxer(); | 179 virtual ~FFmpegDemuxer(); |
173 | 180 |
174 // Carries out initialization on the demuxer thread. | 181 // Carries out initialization on the demuxer thread. |
175 void InitializeTask(DemuxerHost* host, const PipelineStatusCB& status_cb); | 182 void InitializeTask(DemuxerHost* host, const PipelineStatusCB& status_cb); |
176 | 183 |
177 // Carries out a seek on the demuxer thread. | 184 // Carries out a seek on the demuxer thread. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // Set if we know duration of the audio stream. Used when processing end of | 262 // Set if we know duration of the audio stream. Used when processing end of |
256 // stream -- at this moment we definitely know duration. | 263 // stream -- at this moment we definitely know duration. |
257 bool duration_known_; | 264 bool duration_known_; |
258 | 265 |
259 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); | 266 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); |
260 }; | 267 }; |
261 | 268 |
262 } // namespace media | 269 } // namespace media |
263 | 270 |
264 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ | 271 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ |
OLD | NEW |