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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "media/base/bind_to_current_loop.h" | 21 #include "media/base/bind_to_current_loop.h" |
22 #include "media/base/decoder_buffer.h" | 22 #include "media/base/decoder_buffer.h" |
23 #include "media/base/limits.h" | 23 #include "media/base/limits.h" |
| 24 #include "media/base/media_log.h" |
24 #include "media/base/media_switches.h" | 25 #include "media/base/media_switches.h" |
25 #include "media/base/timestamp_constants.h" | 26 #include "media/base/timestamp_constants.h" |
26 #include "media/base/video_frame.h" | 27 #include "media/base/video_frame.h" |
27 #include "media/base/video_util.h" | 28 #include "media/base/video_util.h" |
28 #include "media/ffmpeg/ffmpeg_common.h" | 29 #include "media/ffmpeg/ffmpeg_common.h" |
29 #include "media/filters/ffmpeg_glue.h" | 30 #include "media/filters/ffmpeg_glue.h" |
30 | 31 |
31 namespace media { | 32 namespace media { |
32 | 33 |
33 // Always use 2 or more threads for video decoding. Most machines today will | 34 // Always use 2 or more threads for video decoding. Most machines today will |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 if (opaque) | 106 if (opaque) |
106 static_cast<VideoFrame*>(opaque)->Release(); | 107 static_cast<VideoFrame*>(opaque)->Release(); |
107 } | 108 } |
108 | 109 |
109 // static | 110 // static |
110 bool FFmpegVideoDecoder::IsCodecSupported(VideoCodec codec) { | 111 bool FFmpegVideoDecoder::IsCodecSupported(VideoCodec codec) { |
111 FFmpegGlue::InitializeFFmpeg(); | 112 FFmpegGlue::InitializeFFmpeg(); |
112 return avcodec_find_decoder(VideoCodecToCodecID(codec)) != nullptr; | 113 return avcodec_find_decoder(VideoCodecToCodecID(codec)) != nullptr; |
113 } | 114 } |
114 | 115 |
115 FFmpegVideoDecoder::FFmpegVideoDecoder() | 116 FFmpegVideoDecoder::FFmpegVideoDecoder(scoped_refptr<MediaLog> media_log) |
116 : state_(kUninitialized), decode_nalus_(false) { | 117 : media_log_(std::move(media_log)), |
| 118 state_(kUninitialized), |
| 119 decode_nalus_(false) { |
117 thread_checker_.DetachFromThread(); | 120 thread_checker_.DetachFromThread(); |
118 } | 121 } |
119 | 122 |
120 int FFmpegVideoDecoder::GetVideoBuffer(struct AVCodecContext* codec_context, | 123 int FFmpegVideoDecoder::GetVideoBuffer(struct AVCodecContext* codec_context, |
121 AVFrame* frame, | 124 AVFrame* frame, |
122 int flags) { | 125 int flags) { |
123 // Don't use |codec_context_| here! With threaded decoding, | 126 // Don't use |codec_context_| here! With threaded decoding, |
124 // it will contain unsynchronized width/height/pix_fmt values, | 127 // it will contain unsynchronized width/height/pix_fmt values, |
125 // whereas |codec_context| contains the current threads's | 128 // whereas |codec_context| contains the current threads's |
126 // updated width/height/pix_fmt, which can change for adaptive | 129 // updated width/height/pix_fmt, which can change for adaptive |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 codec_context_->reordered_opaque = buffer->timestamp().InMicroseconds(); | 354 codec_context_->reordered_opaque = buffer->timestamp().InMicroseconds(); |
352 } | 355 } |
353 | 356 |
354 int frame_decoded = 0; | 357 int frame_decoded = 0; |
355 int result = avcodec_decode_video2(codec_context_.get(), | 358 int result = avcodec_decode_video2(codec_context_.get(), |
356 av_frame_.get(), | 359 av_frame_.get(), |
357 &frame_decoded, | 360 &frame_decoded, |
358 &packet); | 361 &packet); |
359 // Log the problem if we can't decode a video frame and exit early. | 362 // Log the problem if we can't decode a video frame and exit early. |
360 if (result < 0) { | 363 if (result < 0) { |
361 LOG(ERROR) << "Error decoding video: " << buffer->AsHumanReadableString(); | 364 MEDIA_LOG(DEBUG, media_log_) |
| 365 << "avcodec_decode_video2(): " << AVErrorToString(result) << ", at " |
| 366 << buffer->AsHumanReadableString(); |
362 return false; | 367 return false; |
363 } | 368 } |
364 | 369 |
365 // FFmpeg says some codecs might have multiple frames per packet. Previous | 370 // FFmpeg says some codecs might have multiple frames per packet. Previous |
366 // discussions with rbultje@ indicate this shouldn't be true for the codecs | 371 // discussions with rbultje@ indicate this shouldn't be true for the codecs |
367 // we use. | 372 // we use. |
368 DCHECK_EQ(result, packet.size); | 373 DCHECK_EQ(result, packet.size); |
369 | 374 |
370 // If no frame was produced then signal that more data is required to | 375 // If no frame was produced then signal that more data is required to |
371 // produce more frames. This can happen under two circumstances: | 376 // produce more frames. This can happen under two circumstances: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { | 433 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { |
429 ReleaseFFmpegResources(); | 434 ReleaseFFmpegResources(); |
430 return false; | 435 return false; |
431 } | 436 } |
432 | 437 |
433 av_frame_.reset(av_frame_alloc()); | 438 av_frame_.reset(av_frame_alloc()); |
434 return true; | 439 return true; |
435 } | 440 } |
436 | 441 |
437 } // namespace media | 442 } // namespace media |
OLD | NEW |