Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1100)

Side by Side Diff: media/filters/ffmpeg_demuxer.h

Issue 14217008: Remove reference counting from media::DemuxerStream and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/filters/ffmpeg_audio_decoder_unittest.cc ('k') | media/filters/ffmpeg_demuxer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 25 #include <string>
26 #include <vector> 26 #include <vector>
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/threading/thread.h" 31 #include "base/threading/thread.h"
31 #include "media/base/audio_decoder_config.h" 32 #include "media/base/audio_decoder_config.h"
32 #include "media/base/decoder_buffer.h" 33 #include "media/base/decoder_buffer.h"
33 #include "media/base/decoder_buffer_queue.h" 34 #include "media/base/decoder_buffer_queue.h"
34 #include "media/base/demuxer.h" 35 #include "media/base/demuxer.h"
35 #include "media/base/pipeline.h" 36 #include "media/base/pipeline.h"
36 #include "media/base/video_decoder_config.h" 37 #include "media/base/video_decoder_config.h"
37 #include "media/filters/blocking_url_protocol.h" 38 #include "media/filters/blocking_url_protocol.h"
38 39
39 // FFmpeg forward declarations. 40 // FFmpeg forward declarations.
(...skipping 16 matching lines...) Expand all
56 class FFmpegH264ToAnnexBBitstreamConverter; 57 class FFmpegH264ToAnnexBBitstreamConverter;
57 class ScopedPtrAVFreePacket; 58 class ScopedPtrAVFreePacket;
58 59
59 typedef scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket; 60 typedef scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> ScopedAVPacket;
60 61
61 class FFmpegDemuxerStream : public DemuxerStream { 62 class FFmpegDemuxerStream : public DemuxerStream {
62 public: 63 public:
63 // Keeps a copy of |demuxer| and initializes itself using information 64 // Keeps a copy of |demuxer| and initializes itself using information
64 // inside |stream|. Both parameters must outlive |this|. 65 // inside |stream|. Both parameters must outlive |this|.
65 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream); 66 FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream);
67 virtual ~FFmpegDemuxerStream();
66 68
67 // Enqueues the given AVPacket. It is invalid to queue a |packet| after 69 // Enqueues the given AVPacket. It is invalid to queue a |packet| after
68 // SetEndOfStream() has been called. 70 // SetEndOfStream() has been called.
69 void EnqueuePacket(ScopedAVPacket packet); 71 void EnqueuePacket(ScopedAVPacket packet);
70 72
71 // Enters the end of stream state. After delivering remaining queued buffers 73 // Enters the end of stream state. After delivering remaining queued buffers
72 // only end of stream buffers will be delivered. 74 // only end of stream buffers will be delivered.
73 void SetEndOfStream(); 75 void SetEndOfStream();
74 76
75 // Drops queued buffers and clears end of stream state. 77 // Drops queued buffers and clears end of stream state.
(...skipping 15 matching lines...) Expand all
91 // Returns the range of buffered data in this stream. 93 // Returns the range of buffered data in this stream.
92 Ranges<base::TimeDelta> GetBufferedRanges() const; 94 Ranges<base::TimeDelta> GetBufferedRanges() const;
93 95
94 // Returns elapsed time based on the already queued packets. 96 // Returns elapsed time based on the already queued packets.
95 // Used to determine stream duration when it's not known ahead of time. 97 // Used to determine stream duration when it's not known ahead of time.
96 base::TimeDelta GetElapsedTime() const; 98 base::TimeDelta GetElapsedTime() const;
97 99
98 // Returns true if this stream has capacity for additional data. 100 // Returns true if this stream has capacity for additional data.
99 bool HasAvailableCapacity(); 101 bool HasAvailableCapacity();
100 102
101 protected:
102 virtual ~FFmpegDemuxerStream();
103
104 private: 103 private:
105 friend class FFmpegDemuxerTest; 104 friend class FFmpegDemuxerTest;
106 105
107 // 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
108 // NotifyCapacityAvailable() if capacity is still available. 107 // NotifyCapacityAvailable() if capacity is still available.
109 void SatisfyPendingRead(); 108 void SatisfyPendingRead();
110 109
111 // Converts an FFmpeg stream timestamp into a base::TimeDelta. 110 // Converts an FFmpeg stream timestamp into a base::TimeDelta.
112 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, 111 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base,
113 int64 timestamp); 112 int64 timestamp);
(...skipping 27 matching lines...) Expand all
141 const FFmpegNeedKeyCB& need_key_cb); 140 const FFmpegNeedKeyCB& need_key_cb);
142 virtual ~FFmpegDemuxer(); 141 virtual ~FFmpegDemuxer();
143 142
144 // Demuxer implementation. 143 // Demuxer implementation.
145 virtual void Initialize(DemuxerHost* host, 144 virtual void Initialize(DemuxerHost* host,
146 const PipelineStatusCB& status_cb) OVERRIDE; 145 const PipelineStatusCB& status_cb) OVERRIDE;
147 virtual void Stop(const base::Closure& callback) OVERRIDE; 146 virtual void Stop(const base::Closure& callback) OVERRIDE;
148 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; 147 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE;
149 virtual void OnAudioRendererDisabled() OVERRIDE; 148 virtual void OnAudioRendererDisabled() OVERRIDE;
150 virtual void SetPlaybackRate(float playback_rate) OVERRIDE; 149 virtual void SetPlaybackRate(float playback_rate) OVERRIDE;
151 virtual scoped_refptr<DemuxerStream> GetStream( 150 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE;
152 DemuxerStream::Type type) OVERRIDE;
153 virtual base::TimeDelta GetStartTime() const OVERRIDE; 151 virtual base::TimeDelta GetStartTime() const OVERRIDE;
154 152
155 // Calls |need_key_cb_| with the initialization data encountered in the file. 153 // Calls |need_key_cb_| with the initialization data encountered in the file.
156 void FireNeedKey(const std::string& init_data_type, 154 void FireNeedKey(const std::string& init_data_type,
157 const std::string& encryption_key_id); 155 const std::string& encryption_key_id);
158 156
159 // Allow FFmpegDemuxerStream to notify us when there is updated information 157 // Allow FFmpegDemuxerStream to notify us when there is updated information
160 // about capacity and what buffered data is available. 158 // about capacity and what buffered data is available.
161 void NotifyCapacityAvailable(); 159 void NotifyCapacityAvailable();
162 void NotifyBufferingChanged(); 160 void NotifyBufferingChanged();
(...skipping 21 matching lines...) Expand all
184 bool StreamsHaveAvailableCapacity(); 182 bool StreamsHaveAvailableCapacity();
185 183
186 // Signal all FFmpegDemuxerStreams that the stream has ended. 184 // Signal all FFmpegDemuxerStreams that the stream has ended.
187 void StreamHasEnded(); 185 void StreamHasEnded();
188 186
189 // Called by |url_protocol_| whenever |data_source_| returns a read error. 187 // Called by |url_protocol_| whenever |data_source_| returns a read error.
190 void OnDataSourceError(); 188 void OnDataSourceError();
191 189
192 // Returns the stream from |streams_| that matches |type| as an 190 // Returns the stream from |streams_| that matches |type| as an
193 // FFmpegDemuxerStream. 191 // FFmpegDemuxerStream.
194 scoped_refptr<FFmpegDemuxerStream> GetFFmpegStream( 192 FFmpegDemuxerStream* GetFFmpegStream(DemuxerStream::Type type) const;
195 DemuxerStream::Type type) const;
196 193
197 DemuxerHost* host_; 194 DemuxerHost* host_;
198 195
199 scoped_refptr<base::MessageLoopProxy> message_loop_; 196 scoped_refptr<base::MessageLoopProxy> message_loop_;
200 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_; 197 base::WeakPtrFactory<FFmpegDemuxer> weak_factory_;
201 base::WeakPtr<FFmpegDemuxer> weak_this_; 198 base::WeakPtr<FFmpegDemuxer> weak_this_;
202 199
203 // Thread on which all blocking FFmpeg operations are executed. 200 // Thread on which all blocking FFmpeg operations are executed.
204 base::Thread blocking_thread_; 201 base::Thread blocking_thread_;
205 202
206 // Tracks if there's an outstanding av_read_frame() operation. 203 // Tracks if there's an outstanding av_read_frame() operation.
207 // 204 //
208 // TODO(scherkus): Allow more than one read in flight for higher read 205 // TODO(scherkus): Allow more than one read in flight for higher read
209 // throughput using demuxer_bench to verify improvements. 206 // throughput using demuxer_bench to verify improvements.
210 bool pending_read_; 207 bool pending_read_;
211 208
212 // Tracks if there's an outstanding av_seek_frame() operation. Used to discard 209 // Tracks if there's an outstanding av_seek_frame() operation. Used to discard
213 // results of pre-seek av_read_frame() operations. 210 // results of pre-seek av_read_frame() operations.
214 bool pending_seek_; 211 bool pending_seek_;
215 212
216 // |streams_| mirrors the AVStream array in |format_context_|. It contains 213 // |streams_| mirrors the AVStream array in |format_context_|. It contains
217 // FFmpegDemuxerStreams encapsluating AVStream objects at the same index. 214 // FFmpegDemuxerStreams encapsluating AVStream objects at the same index.
218 // 215 //
219 // Since we only support a single audio and video stream, |streams_| will 216 // Since we only support a single audio and video stream, |streams_| will
220 // contain NULL entries for additional audio/video streams as well as for 217 // contain NULL entries for additional audio/video streams as well as for
221 // stream types that we do not currently support. 218 // stream types that we do not currently support.
222 // 219 //
223 // Once initialized, operations on FFmpegDemuxerStreams should be carried out 220 // Once initialized, operations on FFmpegDemuxerStreams should be carried out
224 // on the demuxer thread. 221 // on the demuxer thread.
225 typedef std::vector<scoped_refptr<FFmpegDemuxerStream> > StreamVector; 222 typedef ScopedVector<FFmpegDemuxerStream> StreamVector;
226 StreamVector streams_; 223 StreamVector streams_;
227 224
228 // Reference to the data source. Asynchronous read requests are submitted to 225 // Reference to the data source. Asynchronous read requests are submitted to
229 // this object. 226 // this object.
230 scoped_refptr<DataSource> data_source_; 227 scoped_refptr<DataSource> data_source_;
231 228
232 // Derived bitrate after initialization has completed. 229 // Derived bitrate after initialization has completed.
233 int bitrate_; 230 int bitrate_;
234 231
235 // The first timestamp of the opened media file. This is used to set the 232 // The first timestamp of the opened media file. This is used to set the
(...skipping 14 matching lines...) Expand all
250 scoped_ptr<FFmpegGlue> glue_; 247 scoped_ptr<FFmpegGlue> glue_;
251 248
252 const FFmpegNeedKeyCB need_key_cb_; 249 const FFmpegNeedKeyCB need_key_cb_;
253 250
254 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); 251 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer);
255 }; 252 };
256 253
257 } // namespace media 254 } // namespace media
258 255
259 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ 256 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_audio_decoder_unittest.cc ('k') | media/filters/ffmpeg_demuxer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698