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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads)); | 47 std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads)); |
48 if (threads.empty() || !base::StringToInt(threads, &decode_threads)) | 48 if (threads.empty() || !base::StringToInt(threads, &decode_threads)) |
49 return decode_threads; | 49 return decode_threads; |
50 | 50 |
51 decode_threads = std::max(decode_threads, 0); | 51 decode_threads = std::max(decode_threads, 0); |
52 decode_threads = std::min(decode_threads, kMaxDecodeThreads); | 52 decode_threads = std::min(decode_threads, kMaxDecodeThreads); |
53 return decode_threads; | 53 return decode_threads; |
54 } | 54 } |
55 | 55 |
56 FFmpegVideoDecoder::FFmpegVideoDecoder( | 56 FFmpegVideoDecoder::FFmpegVideoDecoder( |
57 const base::Callback<MessageLoop*()>& message_loop_cb) | 57 const base::Callback<MessageLoop*()>& message_loop_cb, |
| 58 Decryptor* decryptor) |
58 : message_loop_factory_cb_(message_loop_cb), | 59 : message_loop_factory_cb_(message_loop_cb), |
59 message_loop_(NULL), | 60 message_loop_(NULL), |
60 state_(kUninitialized), | 61 state_(kUninitialized), |
61 codec_context_(NULL), | 62 codec_context_(NULL), |
62 av_frame_(NULL), | 63 av_frame_(NULL), |
63 decryptor_(NULL) { | 64 decryptor_(decryptor) { |
64 } | 65 } |
65 | 66 |
66 int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, | 67 int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, |
67 AVFrame* frame) { | 68 AVFrame* frame) { |
68 // Don't use |codec_context_| here! With threaded decoding, | 69 // Don't use |codec_context_| here! With threaded decoding, |
69 // it will contain unsynchronized width/height/pix_fmt values, | 70 // it will contain unsynchronized width/height/pix_fmt values, |
70 // whereas |codec_context| contains the current threads's | 71 // whereas |codec_context| contains the current threads's |
71 // updated width/height/pix_fmt, which can change for adaptive | 72 // updated width/height/pix_fmt, which can change for adaptive |
72 // content. | 73 // content. |
73 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt); | 74 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 247 |
247 DoStop(); | 248 DoStop(); |
248 } | 249 } |
249 | 250 |
250 void FFmpegVideoDecoder::DoStop() { | 251 void FFmpegVideoDecoder::DoStop() { |
251 ReleaseFFmpegResources(); | 252 ReleaseFFmpegResources(); |
252 state_ = kUninitialized; | 253 state_ = kUninitialized; |
253 base::ResetAndReturn(&stop_cb_).Run(); | 254 base::ResetAndReturn(&stop_cb_).Run(); |
254 } | 255 } |
255 | 256 |
256 void FFmpegVideoDecoder::set_decryptor(Decryptor* decryptor) { | |
257 DCHECK_EQ(state_, kUninitialized); | |
258 decryptor_ = decryptor; | |
259 } | |
260 | |
261 FFmpegVideoDecoder::~FFmpegVideoDecoder() { | 257 FFmpegVideoDecoder::~FFmpegVideoDecoder() { |
262 ReleaseFFmpegResources(); | 258 ReleaseFFmpegResources(); |
263 } | 259 } |
264 | 260 |
265 void FFmpegVideoDecoder::DoRead(const ReadCB& read_cb) { | 261 void FFmpegVideoDecoder::DoRead(const ReadCB& read_cb) { |
266 DCHECK_EQ(MessageLoop::current(), message_loop_); | 262 DCHECK_EQ(MessageLoop::current(), message_loop_); |
267 DCHECK(!read_cb.is_null()); | 263 DCHECK(!read_cb.is_null()); |
268 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; | 264 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; |
269 | 265 |
270 // This can happen during shutdown after Stop() has been called. | 266 // This can happen during shutdown after Stop() has been called. |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 av_free(codec_context_); | 516 av_free(codec_context_); |
521 codec_context_ = NULL; | 517 codec_context_ = NULL; |
522 } | 518 } |
523 if (av_frame_) { | 519 if (av_frame_) { |
524 av_free(av_frame_); | 520 av_free(av_frame_); |
525 av_frame_ = NULL; | 521 av_frame_ = NULL; |
526 } | 522 } |
527 } | 523 } |
528 | 524 |
529 } // namespace media | 525 } // namespace media |
OLD | NEW |