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 #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 11 matching lines...) Expand all Loading... | |
22 | 22 |
23 // Always try to use three threads for video decoding. There is little reason | 23 // Always try to use three threads for video decoding. There is little reason |
24 // not to since current day CPUs tend to be multi-core and we measured | 24 // not to since current day CPUs tend to be multi-core and we measured |
25 // performance benefits on older machines such as P4s with hyperthreading. | 25 // performance benefits on older machines such as P4s with hyperthreading. |
26 // | 26 // |
27 // Handling decoding on separate threads also frees up the pipeline thread to | 27 // Handling decoding on separate threads also frees up the pipeline thread to |
28 // continue processing. Although it'd be nice to have the option of a single | 28 // continue processing. Although it'd be nice to have the option of a single |
29 // decoding thread, FFmpeg treats having one thread the same as having zero | 29 // decoding thread, FFmpeg treats having one thread the same as having zero |
30 // threads (i.e., avcodec_decode_video() will execute on the calling thread). | 30 // threads (i.e., avcodec_decode_video() will execute on the calling thread). |
31 // Yet another reason for having two threads :) | 31 // Yet another reason for having two threads :) |
32 static const int kDecodeThreads = 2; | 32 static const int kDecodeThreads = 1; |
Ami GONE FROM CHROMIUM
2012/01/27 23:44:58
??
acolwell GONE FROM CHROMIUM
2012/01/29 03:00:41
This was to temporarily make valgrind shutup about
| |
33 static const int kMaxDecodeThreads = 16; | 33 static const int kMaxDecodeThreads = 16; |
34 | 34 |
35 // Returns the number of threads given the FFmpeg CodecID. Also inspects the | 35 // Returns the number of threads given the FFmpeg CodecID. Also inspects the |
36 // command line for a valid --video-threads flag. | 36 // command line for a valid --video-threads flag. |
37 static int GetThreadCount(CodecID codec_id) { | 37 static int GetThreadCount(CodecID codec_id) { |
38 // TODO(scherkus): As of 07/21/2011 we still can't enable Theora multithreaded | 38 // TODO(scherkus): As of 07/21/2011 we still can't enable Theora multithreaded |
39 // decoding due to bugs in FFmpeg. Dig in and send fixes upstream! | 39 // decoding due to bugs in FFmpeg. Dig in and send fixes upstream! |
40 // | 40 // |
41 // Refer to http://crbug.com/93932 for tsan suppressions on decoding. | 41 // Refer to http://crbug.com/93932 for tsan suppressions on decoding. |
42 int decode_threads = (codec_id == CODEC_ID_THEORA ? 1 : kDecodeThreads); | 42 int decode_threads = (codec_id == CODEC_ID_THEORA ? 1 : kDecodeThreads); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 message_loop_->PostTask(FROM_HERE, base::Bind( | 214 message_loop_->PostTask(FROM_HERE, base::Bind( |
215 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer)); | 215 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer)); |
216 } | 216 } |
217 | 217 |
218 void FFmpegVideoDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& buffer) { | 218 void FFmpegVideoDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& buffer) { |
219 DCHECK_EQ(MessageLoop::current(), message_loop_); | 219 DCHECK_EQ(MessageLoop::current(), message_loop_); |
220 DCHECK_NE(state_, kUninitialized); | 220 DCHECK_NE(state_, kUninitialized); |
221 DCHECK_NE(state_, kDecodeFinished); | 221 DCHECK_NE(state_, kDecodeFinished); |
222 DCHECK(!read_cb_.is_null()); | 222 DCHECK(!read_cb_.is_null()); |
223 | 223 |
224 if (!buffer) { | |
Ami GONE FROM CHROMIUM
2012/01/27 23:44:58
GpuVideoDecoder::RequestBufferDecode needs to simi
acolwell GONE FROM CHROMIUM
2012/01/29 03:00:41
Done.
| |
225 DeliverFrame(NULL); | |
226 return; | |
227 } | |
228 | |
224 // During decode, because reads are issued asynchronously, it is possible to | 229 // During decode, because reads are issued asynchronously, it is possible to |
225 // receive multiple end of stream buffers since each read is acked. When the | 230 // receive multiple end of stream buffers since each read is acked. When the |
226 // first end of stream buffer is read, FFmpeg may still have frames queued | 231 // first end of stream buffer is read, FFmpeg may still have frames queued |
227 // up in the decoder so we need to go through the decode loop until it stops | 232 // up in the decoder so we need to go through the decode loop until it stops |
228 // giving sensible data. After that, the decoder should output empty | 233 // giving sensible data. After that, the decoder should output empty |
229 // frames. There are three states the decoder can be in: | 234 // frames. There are three states the decoder can be in: |
230 // | 235 // |
231 // kNormal: This is the starting state. Buffers are decoded. Decode errors | 236 // kNormal: This is the starting state. Buffers are decoded. Decode errors |
232 // are discarded. | 237 // are discarded. |
233 // kFlushCodec: There isn't any more input data. Call avcodec_decode_video2 | 238 // kFlushCodec: There isn't any more input data. Call avcodec_decode_video2 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { | 406 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { |
402 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); | 407 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); |
403 size_t width = codec_context_->width; | 408 size_t width = codec_context_->width; |
404 size_t height = codec_context_->height; | 409 size_t height = codec_context_->height; |
405 | 410 |
406 return VideoFrame::CreateFrame(format, width, height, | 411 return VideoFrame::CreateFrame(format, width, height, |
407 kNoTimestamp(), kNoTimestamp()); | 412 kNoTimestamp(), kNoTimestamp()); |
408 } | 413 } |
409 | 414 |
410 } // namespace media | 415 } // namespace media |
OLD | NEW |