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

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

Issue 10447035: Introducing DecoderBuffer and general Buffer cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Buffer Bonanza! Created 8 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
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 #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/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 202
203 void FFmpegVideoDecoder::ReadFromDemuxerStream() { 203 void FFmpegVideoDecoder::ReadFromDemuxerStream() {
204 DCHECK_NE(state_, kUninitialized); 204 DCHECK_NE(state_, kUninitialized);
205 DCHECK_NE(state_, kDecodeFinished); 205 DCHECK_NE(state_, kDecodeFinished);
206 DCHECK(!read_cb_.is_null()); 206 DCHECK(!read_cb_.is_null());
207 207
208 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this)); 208 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this));
209 } 209 }
210 210
211 void FFmpegVideoDecoder::DecodeBuffer(const scoped_refptr<Buffer>& buffer) { 211 void FFmpegVideoDecoder::DecodeBuffer(
212 const scoped_refptr<DecoderBuffer>& buffer) {
212 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read 213 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read
213 // callback on the same execution stack so we can get rid of forced task post. 214 // callback on the same execution stack so we can get rid of forced task post.
214 message_loop_->PostTask(FROM_HERE, base::Bind( 215 message_loop_->PostTask(FROM_HERE, base::Bind(
215 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer)); 216 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer));
216 } 217 }
217 218
218 void FFmpegVideoDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& buffer) { 219 void FFmpegVideoDecoder::DoDecodeBuffer(
220 const scoped_refptr<DecoderBuffer>& buffer) {
219 DCHECK_EQ(MessageLoop::current(), message_loop_); 221 DCHECK_EQ(MessageLoop::current(), message_loop_);
220 DCHECK_NE(state_, kUninitialized); 222 DCHECK_NE(state_, kUninitialized);
221 DCHECK_NE(state_, kDecodeFinished); 223 DCHECK_NE(state_, kDecodeFinished);
222 DCHECK(!read_cb_.is_null()); 224 DCHECK(!read_cb_.is_null());
223 225
224 if (!reset_cb_.is_null()) { 226 if (!reset_cb_.is_null()) {
225 DeliverFrame(NULL); 227 DeliverFrame(NULL);
226 DoReset(); 228 DoReset();
227 return; 229 return;
228 } 230 }
(...skipping 26 matching lines...) Expand all
255 // kFlushCodec -> kDecodeFinished: 257 // kFlushCodec -> kDecodeFinished:
256 // When avcodec_decode_video2() returns 0 data or errors out. 258 // When avcodec_decode_video2() returns 0 data or errors out.
257 // (any state) -> kNormal: 259 // (any state) -> kNormal:
258 // Any time Reset() is called. 260 // Any time Reset() is called.
259 261
260 // Transition to kFlushCodec on the first end of stream buffer. 262 // Transition to kFlushCodec on the first end of stream buffer.
261 if (state_ == kNormal && buffer->IsEndOfStream()) { 263 if (state_ == kNormal && buffer->IsEndOfStream()) {
262 state_ = kFlushCodec; 264 state_ = kFlushCodec;
263 } 265 }
264 266
265 scoped_refptr<Buffer> unencrypted_buffer = buffer; 267 scoped_refptr<DecoderBuffer> unencrypted_buffer = buffer;
266 if (buffer->GetDecryptConfig() && buffer->GetDataSize()) { 268 if (buffer->GetDecryptConfig() && buffer->GetDataSize()) {
267 unencrypted_buffer = decryptor_.Decrypt(buffer); 269 unencrypted_buffer = decryptor_.Decrypt(buffer);
268 if (!unencrypted_buffer || !unencrypted_buffer->GetDataSize()) { 270 if (!unencrypted_buffer || !unencrypted_buffer->GetDataSize()) {
269 state_ = kDecodeFinished; 271 state_ = kDecodeFinished;
270 base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL); 272 base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL);
271 return; 273 return;
272 } 274 }
273 } 275 }
274 276
275 scoped_refptr<VideoFrame> video_frame; 277 scoped_refptr<VideoFrame> video_frame;
(...skipping 20 matching lines...) Expand all
296 } 298 }
297 299
298 ReadFromDemuxerStream(); 300 ReadFromDemuxerStream();
299 return; 301 return;
300 } 302 }
301 303
302 DeliverFrame(video_frame); 304 DeliverFrame(video_frame);
303 } 305 }
304 306
305 bool FFmpegVideoDecoder::Decode( 307 bool FFmpegVideoDecoder::Decode(
306 const scoped_refptr<Buffer>& buffer, 308 const scoped_refptr<DecoderBuffer>& buffer,
307 scoped_refptr<VideoFrame>* video_frame) { 309 scoped_refptr<VideoFrame>* video_frame) {
308 DCHECK(video_frame); 310 DCHECK(video_frame);
309 311
310 // Create a packet for input data. 312 // Create a packet for input data.
311 // Due to FFmpeg API changes we no longer have const read-only pointers. 313 // Due to FFmpeg API changes we no longer have const read-only pointers.
312 AVPacket packet; 314 AVPacket packet;
313 av_init_packet(&packet); 315 av_init_packet(&packet);
314 packet.data = const_cast<uint8*>(buffer->GetData()); 316 packet.data = const_cast<uint8*>(buffer->GetData());
315 packet.size = buffer->GetDataSize(); 317 packet.size = buffer->GetDataSize();
316 318
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { 421 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() {
420 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); 422 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt);
421 size_t width = codec_context_->width; 423 size_t width = codec_context_->width;
422 size_t height = codec_context_->height; 424 size_t height = codec_context_->height;
423 425
424 return VideoFrame::CreateFrame(format, width, height, 426 return VideoFrame::CreateFrame(format, width, height,
425 kNoTimestamp(), kNoTimestamp()); 427 kNoTimestamp(), kNoTimestamp());
426 } 428 }
427 429
428 } // namespace media 430 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698