OLD | NEW |
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/video/ffmpeg_video_decode_engine.h" | 5 #include "media/video/ffmpeg_video_decode_engine.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/task.h" | 9 #include "base/task.h" |
10 #include "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // Create output buffer pool when direct rendering is not used. | 113 // Create output buffer pool when direct rendering is not used. |
114 for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) { | 114 for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) { |
115 scoped_refptr<VideoFrame> video_frame = | 115 scoped_refptr<VideoFrame> video_frame = |
116 VideoFrame::CreateFrame(VideoFrame::YV12, | 116 VideoFrame::CreateFrame(VideoFrame::YV12, |
117 config.width(), | 117 config.width(), |
118 config.height(), | 118 config.height(), |
119 kNoTimestamp, | 119 kNoTimestamp, |
120 kNoTimestamp); | 120 kNoTimestamp); |
121 frame_queue_available_.push_back(video_frame); | 121 frame_queue_available_.push_back(video_frame); |
122 } | 122 } |
123 | |
124 codec_context_->thread_count = decode_threads; | 123 codec_context_->thread_count = decode_threads; |
125 if (codec && | 124 if (codec && |
126 avcodec_open(codec_context_, codec) >= 0 && | 125 avcodec_open(codec_context_, codec) >= 0 && |
127 av_frame_.get()) { | 126 av_frame_.get()) { |
128 info.success = true; | 127 info.success = true; |
129 } | 128 } |
130 event_handler_ = event_handler; | 129 event_handler_ = event_handler; |
131 event_handler_->OnInitializeComplete(info); | 130 event_handler_->OnInitializeComplete(info); |
132 } | 131 } |
133 | 132 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 179 |
181 // This is for codecs not using get_buffer to initialize | 180 // This is for codecs not using get_buffer to initialize |
182 // |av_frame_->reordered_opaque| | 181 // |av_frame_->reordered_opaque| |
183 av_frame_->reordered_opaque = codec_context_->reordered_opaque; | 182 av_frame_->reordered_opaque = codec_context_->reordered_opaque; |
184 | 183 |
185 int frame_decoded = 0; | 184 int frame_decoded = 0; |
186 int result = avcodec_decode_video2(codec_context_, | 185 int result = avcodec_decode_video2(codec_context_, |
187 av_frame_.get(), | 186 av_frame_.get(), |
188 &frame_decoded, | 187 &frame_decoded, |
189 &packet); | 188 &packet); |
| 189 |
190 // Log the problem if we can't decode a video frame and exit early. | 190 // Log the problem if we can't decode a video frame and exit early. |
191 if (result < 0) { | 191 if (result < 0) { |
192 LOG(ERROR) << "Error decoding a video frame with timestamp: " | 192 LOG(ERROR) << "Error decoding a video frame with timestamp: " |
193 << buffer->GetTimestamp().InMicroseconds() << " us, duration: " | 193 << buffer->GetTimestamp().InMicroseconds() << " us, duration: " |
194 << buffer->GetDuration().InMicroseconds() << " us, packet size: " | 194 << buffer->GetDuration().InMicroseconds() << " us, packet size: " |
195 << buffer->GetDataSize() << " bytes"; | 195 << buffer->GetDataSize() << " bytes"; |
196 event_handler_->OnError(); | 196 event_handler_->OnError(); |
197 return; | 197 return; |
198 } | 198 } |
199 | 199 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 296 |
297 event_handler_->OnSeekComplete(); | 297 event_handler_->OnSeekComplete(); |
298 } | 298 } |
299 | 299 |
300 void FFmpegVideoDecodeEngine::ReadInput() { | 300 void FFmpegVideoDecodeEngine::ReadInput() { |
301 DCHECK_EQ(output_eos_reached_, false); | 301 DCHECK_EQ(output_eos_reached_, false); |
302 pending_input_buffers_++; | 302 pending_input_buffers_++; |
303 event_handler_->ProduceVideoSample(NULL); | 303 event_handler_->ProduceVideoSample(NULL); |
304 } | 304 } |
305 | 305 |
| 306 VideoFrame::Format FFmpegVideoDecodeEngine::GetSurfaceFormat() const { |
| 307 // J (Motion JPEG) versions of YUV are full range 0..255. |
| 308 // Regular (MPEG) YUV is 16..240. |
| 309 // For now we will ignore the distinction and treat them the same. |
| 310 switch (codec_context_->pix_fmt) { |
| 311 case PIX_FMT_YUV420P: |
| 312 case PIX_FMT_YUVJ420P: |
| 313 return VideoFrame::YV12; |
| 314 case PIX_FMT_YUV422P: |
| 315 case PIX_FMT_YUVJ422P: |
| 316 return VideoFrame::YV16; |
| 317 default: |
| 318 // TODO(scherkus): More formats here? |
| 319 break; |
| 320 } |
| 321 return VideoFrame::INVALID; |
| 322 } |
| 323 |
306 } // namespace media | 324 } // namespace media |
307 | 325 |
308 // Disable refcounting for this object because this object only lives | 326 // Disable refcounting for this object because this object only lives |
309 // on the video decoder thread and there's no need to refcount it. | 327 // on the video decoder thread and there's no need to refcount it. |
310 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::FFmpegVideoDecodeEngine); | 328 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::FFmpegVideoDecodeEngine); |
OLD | NEW |