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

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

Issue 11411332: Replace trampolining in FFmpegDemuxer with explicit thread calling convention checks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years 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/base/bind_to_loop.h.pump ('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 <deque>
26 #include <vector> 25 #include <vector>
27 26
28 #include "base/callback.h" 27 #include "base/callback.h"
29 #include "base/gtest_prod_util.h" 28 #include "base/gtest_prod_util.h"
30 #include "base/threading/thread.h" 29 #include "base/threading/thread.h"
31 #include "media/base/audio_decoder_config.h" 30 #include "media/base/audio_decoder_config.h"
32 #include "media/base/decoder_buffer.h" 31 #include "media/base/decoder_buffer.h"
33 #include "media/base/decoder_buffer_queue.h" 32 #include "media/base/decoder_buffer_queue.h"
34 #include "media/base/demuxer.h" 33 #include "media/base/demuxer.h"
35 #include "media/base/pipeline.h" 34 #include "media/base/pipeline.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 88
90 // Returns true if this stream has capacity for additional data. 89 // Returns true if this stream has capacity for additional data.
91 bool HasAvailableCapacity(); 90 bool HasAvailableCapacity();
92 91
93 protected: 92 protected:
94 virtual ~FFmpegDemuxerStream(); 93 virtual ~FFmpegDemuxerStream();
95 94
96 private: 95 private:
97 friend class FFmpegDemuxerTest; 96 friend class FFmpegDemuxerTest;
98 97
99 // Runs callbacks in |read_queue_| for each available |buffer_queue_|, calling 98 // Runs |read_cb_| if present with the front of |buffer_queue_|, calling
100 // NotifyHasPendingRead() if there are still pending items in |read_queue_|. 99 // NotifyCapacityAvailable() if capacity is still available.
101 void SatisfyPendingReads(); 100 void SatisfyPendingRead();
102 101
103 // Converts an FFmpeg stream timestamp into a base::TimeDelta. 102 // Converts an FFmpeg stream timestamp into a base::TimeDelta.
104 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base, 103 static base::TimeDelta ConvertStreamTimestamp(const AVRational& time_base,
105 int64 timestamp); 104 int64 timestamp);
106 105
107 FFmpegDemuxer* demuxer_; 106 FFmpegDemuxer* demuxer_;
108 scoped_refptr<base::MessageLoopProxy> message_loop_; 107 scoped_refptr<base::MessageLoopProxy> message_loop_;
109 AVStream* stream_; 108 AVStream* stream_;
110 AudioDecoderConfig audio_config_; 109 AudioDecoderConfig audio_config_;
111 VideoDecoderConfig video_config_; 110 VideoDecoderConfig video_config_;
112 Type type_; 111 Type type_;
113 base::TimeDelta duration_; 112 base::TimeDelta duration_;
114 bool stopped_; 113 bool stopped_;
115 bool end_of_stream_; 114 bool end_of_stream_;
116 base::TimeDelta last_packet_timestamp_; 115 base::TimeDelta last_packet_timestamp_;
117 Ranges<base::TimeDelta> buffered_ranges_; 116 Ranges<base::TimeDelta> buffered_ranges_;
118 117
119 DecoderBufferQueue buffer_queue_; 118 DecoderBufferQueue buffer_queue_;
120 119 ReadCB read_cb_;
121 typedef std::deque<ReadCB> ReadQueue;
122 ReadQueue read_queue_;
123 120
124 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_; 121 scoped_ptr<FFmpegH264ToAnnexBBitstreamConverter> bitstream_converter_;
125 bool bitstream_converter_enabled_; 122 bool bitstream_converter_enabled_;
126 123
127 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream); 124 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerStream);
128 }; 125 };
129 126
130 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer { 127 class MEDIA_EXPORT FFmpegDemuxer : public Demuxer {
131 public: 128 public:
132 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop, 129 FFmpegDemuxer(const scoped_refptr<base::MessageLoopProxy>& message_loop,
(...skipping 14 matching lines...) Expand all
147 // about capacity and what buffered data is available. 144 // about capacity and what buffered data is available.
148 void NotifyCapacityAvailable(); 145 void NotifyCapacityAvailable();
149 void NotifyBufferingChanged(); 146 void NotifyBufferingChanged();
150 147
151 private: 148 private:
152 // To allow tests access to privates. 149 // To allow tests access to privates.
153 friend class FFmpegDemuxerTest; 150 friend class FFmpegDemuxerTest;
154 151
155 virtual ~FFmpegDemuxer(); 152 virtual ~FFmpegDemuxer();
156 153
157 // Carries out initialization on the demuxer thread. 154 // FFmpeg callbacks during initialization.
158 void InitializeTask(DemuxerHost* host, const PipelineStatusCB& status_cb);
159 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result); 155 void OnOpenContextDone(const PipelineStatusCB& status_cb, bool result);
160 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result); 156 void OnFindStreamInfoDone(const PipelineStatusCB& status_cb, int result);
161 157
162 // Carries out a seek on the demuxer thread. 158 // FFmpeg callbacks during seeking.
163 void SeekTask(base::TimeDelta time, const PipelineStatusCB& cb);
164 void OnSeekFrameDone(const PipelineStatusCB& cb, int result); 159 void OnSeekFrameDone(const PipelineStatusCB& cb, int result);
165 160
166 // Carries out demuxing and satisfying stream reads on the demuxer thread. 161 // FFmpeg callbacks during reading + helper method to initiate reads.
167 void DemuxTask(); 162 void ReadFrameIfNeeded();
168 void OnReadFrameDone(ScopedAVPacket packet, int result); 163 void OnReadFrameDone(ScopedAVPacket packet, int result);
169 164
170 // Carries out stopping the demuxer streams on the demuxer thread. 165 // DataSource callbacks during stopping.
171 void StopTask(const base::Closure& callback);
172 void OnDataSourceStopped(const base::Closure& callback); 166 void OnDataSourceStopped(const base::Closure& callback);
173 167
174 // Carries out disabling the audio stream on the demuxer thread.
175 void DisableAudioStreamTask();
176
177 // Returns true iff any stream has additional capacity. Note that streams can 168 // Returns true iff any stream has additional capacity. Note that streams can
178 // go over capacity depending on how the file is muxed. 169 // go over capacity depending on how the file is muxed.
179 bool StreamsHaveAvailableCapacity(); 170 bool StreamsHaveAvailableCapacity();
180 171
181 // Signal all FFmpegDemuxerStreams that the stream has ended. 172 // Signal all FFmpegDemuxerStreams that the stream has ended.
182 void StreamHasEnded(); 173 void StreamHasEnded();
183 174
184 // Called by |url_protocol_| whenever |data_source_| returns a read error. 175 // Called by |url_protocol_| whenever |data_source_| returns a read error.
185 void OnDataSourceError(); 176 void OnDataSourceError();
186 177
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // FFmpegURLProtocol implementation and corresponding glue bits. 232 // FFmpegURLProtocol implementation and corresponding glue bits.
242 BlockingUrlProtocol url_protocol_; 233 BlockingUrlProtocol url_protocol_;
243 scoped_ptr<FFmpegGlue> glue_; 234 scoped_ptr<FFmpegGlue> glue_;
244 235
245 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer); 236 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxer);
246 }; 237 };
247 238
248 } // namespace media 239 } // namespace media
249 240
250 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_ 241 #endif // MEDIA_FILTERS_FFMPEG_DEMUXER_H_
OLDNEW
« no previous file with comments | « media/base/bind_to_loop.h.pump ('k') | media/filters/ffmpeg_demuxer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698