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

Side by Side Diff: media/filters/ffmpeg_video_decoder.cc

Issue 8763010: Replace AudioDecoder::ProduceAudioSamples/ConsumeAudioSamples with read callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac tests Created 9 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/filters/ffmpeg_audio_decoder_unittest.cc ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "media/filters/ffmpeg_video_decoder.h" 5 #include "media/filters/ffmpeg_video_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return; 164 return;
165 } 165 }
166 166
167 avcodec_flush_buffers(codec_context_); 167 avcodec_flush_buffers(codec_context_);
168 pts_stream_.Flush(); 168 pts_stream_.Flush();
169 state_ = kNormal; 169 state_ = kNormal;
170 callback.Run(); 170 callback.Run();
171 } 171 }
172 172
173 void FFmpegVideoDecoder::Read(const ReadCB& callback) { 173 void FFmpegVideoDecoder::Read(const ReadCB& callback) {
174 // TODO(scherkus): forced task post since VideoRendererBase::FrameReady() will 174 // Complete operation asynchronously on different stack of execution as per
175 // call Read() on FFmpegVideoDecoder's thread as we executed |read_cb_|. 175 // the API contract of VideoDecoder::Read()
176 message_loop_->PostTask(FROM_HERE, base::Bind( 176 message_loop_->PostTask(FROM_HERE, base::Bind(
177 &FFmpegVideoDecoder::DoRead, this, callback)); 177 &FFmpegVideoDecoder::DoRead, this, callback));
178 } 178 }
179 179
180 const gfx::Size& FFmpegVideoDecoder::natural_size() { 180 const gfx::Size& FFmpegVideoDecoder::natural_size() {
181 return natural_size_; 181 return natural_size_;
182 } 182 }
183 183
184 void FFmpegVideoDecoder::DoRead(const ReadCB& callback) { 184 void FFmpegVideoDecoder::DoRead(const ReadCB& callback) {
185 DCHECK_EQ(MessageLoop::current(), message_loop_); 185 DCHECK_EQ(MessageLoop::current(), message_loop_);
186 CHECK(!callback.is_null()); 186 DCHECK(!callback.is_null());
187 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; 187 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported.";
188 188
189 // This can happen during shutdown after Stop() has been called. 189 // This can happen during shutdown after Stop() has been called.
190 if (state_ == kUninitialized) { 190 if (state_ == kUninitialized) {
191 return; 191 return;
192 } 192 }
193 193
194 // Return empty frames if decoding has finished. 194 // Return empty frames if decoding has finished.
195 if (state_ == kDecodeFinished) { 195 if (state_ == kDecodeFinished) {
196 callback.Run(VideoFrame::CreateEmptyFrame()); 196 callback.Run(VideoFrame::CreateEmptyFrame());
197 return; 197 return;
198 } 198 }
199 199
200 read_cb_ = callback; 200 read_cb_ = callback;
201 ReadFromDemuxerStream(); 201 ReadFromDemuxerStream();
202 } 202 }
203 203
204 204
205 void FFmpegVideoDecoder::ReadFromDemuxerStream() { 205 void FFmpegVideoDecoder::ReadFromDemuxerStream() {
206 DCHECK_NE(state_, kUninitialized); 206 DCHECK_NE(state_, kUninitialized);
207 DCHECK_NE(state_, kDecodeFinished); 207 DCHECK_NE(state_, kDecodeFinished);
208 DCHECK(!read_cb_.is_null()); 208 DCHECK(!read_cb_.is_null());
209 209
210 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this)); 210 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this));
211 } 211 }
212 212
213 void FFmpegVideoDecoder::DecodeBuffer(const scoped_refptr<Buffer>& buffer) { 213 void FFmpegVideoDecoder::DecodeBuffer(const scoped_refptr<Buffer>& buffer) {
214 // TODO(scherkus): forced task post since FFmpegDemuxerStream::Read() can 214 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read
215 // immediately execute our callback on FFmpegVideoDecoder's thread. 215 // callback on the same execution stack so we can get rid of forced task post.
216 message_loop_->PostTask(FROM_HERE, base::Bind( 216 message_loop_->PostTask(FROM_HERE, base::Bind(
217 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer)); 217 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer));
218 } 218 }
219 219
220 void FFmpegVideoDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& buffer) { 220 void FFmpegVideoDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& buffer) {
221 DCHECK_EQ(MessageLoop::current(), message_loop_); 221 DCHECK_EQ(MessageLoop::current(), message_loop_);
222 DCHECK_NE(state_, kUninitialized); 222 DCHECK_NE(state_, kUninitialized);
223 DCHECK_NE(state_, kDecodeFinished); 223 DCHECK_NE(state_, kDecodeFinished);
224 DCHECK(!read_cb_.is_null()); 224 DCHECK(!read_cb_.is_null());
225 225
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { 415 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() {
416 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); 416 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt);
417 size_t width = codec_context_->width; 417 size_t width = codec_context_->width;
418 size_t height = codec_context_->height; 418 size_t height = codec_context_->height;
419 419
420 return VideoFrame::CreateFrame(format, width, height, 420 return VideoFrame::CreateFrame(format, width, height,
421 kNoTimestamp, kNoTimestamp); 421 kNoTimestamp, kNoTimestamp);
422 } 422 }
423 423
424 } // namespace media 424 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_audio_decoder_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698