| 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/vpx_video_decoder.h" | 5 #include "media/filters/vpx_video_decoder.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_to_current_loop.h" |
| 12 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/sys_byteorder.h" | 20 #include "base/sys_byteorder.h" |
| 20 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.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/demuxer_stream.h" | 23 #include "media/base/demuxer_stream.h" |
| 24 #include "media/base/limits.h" | 24 #include "media/base/limits.h" |
| 25 #include "media/base/media_switches.h" | 25 #include "media/base/media_switches.h" |
| 26 #include "media/base/pipeline.h" | 26 #include "media/base/pipeline.h" |
| 27 #include "media/base/video_decoder_config.h" | 27 #include "media/base/video_decoder_config.h" |
| 28 #include "media/base/video_frame.h" | 28 #include "media/base/video_frame.h" |
| 29 #include "media/base/video_util.h" | 29 #include "media/base/video_util.h" |
| 30 | 30 |
| 31 // Include libvpx header files. | 31 // Include libvpx header files. |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 void *user_priv, vpx_codec_frame_buffer *fb) { | 174 void *user_priv, vpx_codec_frame_buffer *fb) { |
| 175 VP9FrameBuffer* frame_buffer = static_cast<VP9FrameBuffer*>(fb->priv); | 175 VP9FrameBuffer* frame_buffer = static_cast<VP9FrameBuffer*>(fb->priv); |
| 176 --frame_buffer->ref_cnt; | 176 --frame_buffer->ref_cnt; |
| 177 return 0; | 177 return 0; |
| 178 } | 178 } |
| 179 | 179 |
| 180 base::Closure VpxVideoDecoder::MemoryPool::CreateFrameCallback( | 180 base::Closure VpxVideoDecoder::MemoryPool::CreateFrameCallback( |
| 181 void* fb_priv_data) { | 181 void* fb_priv_data) { |
| 182 VP9FrameBuffer* frame_buffer = static_cast<VP9FrameBuffer*>(fb_priv_data); | 182 VP9FrameBuffer* frame_buffer = static_cast<VP9FrameBuffer*>(fb_priv_data); |
| 183 ++frame_buffer->ref_cnt; | 183 ++frame_buffer->ref_cnt; |
| 184 return BindToCurrentLoop( | 184 return base::BindToCurrentLoop( |
| 185 base::Bind(&MemoryPool::OnVideoFrameDestroyed, this, | 185 base::Bind(&MemoryPool::OnVideoFrameDestroyed, this, |
| 186 frame_buffer)); | 186 frame_buffer)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void VpxVideoDecoder::MemoryPool::OnVideoFrameDestroyed( | 189 void VpxVideoDecoder::MemoryPool::OnVideoFrameDestroyed( |
| 190 VP9FrameBuffer* frame_buffer) { | 190 VP9FrameBuffer* frame_buffer) { |
| 191 --frame_buffer->ref_cnt; | 191 --frame_buffer->ref_cnt; |
| 192 } | 192 } |
| 193 | 193 |
| 194 VpxVideoDecoder::VpxVideoDecoder( | 194 VpxVideoDecoder::VpxVideoDecoder( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 217 DCHECK(decode_cb_.is_null()); | 217 DCHECK(decode_cb_.is_null()); |
| 218 | 218 |
| 219 if (!ConfigureDecoder(config)) { | 219 if (!ConfigureDecoder(config)) { |
| 220 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 220 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
| 221 return; | 221 return; |
| 222 } | 222 } |
| 223 | 223 |
| 224 // Success! | 224 // Success! |
| 225 config_ = config; | 225 config_ = config; |
| 226 state_ = kNormal; | 226 state_ = kNormal; |
| 227 output_cb_ = BindToCurrentLoop(output_cb); | 227 output_cb_ = base::BindToCurrentLoop(output_cb); |
| 228 status_cb.Run(PIPELINE_OK); | 228 status_cb.Run(PIPELINE_OK); |
| 229 } | 229 } |
| 230 | 230 |
| 231 static vpx_codec_ctx* InitializeVpxContext(vpx_codec_ctx* context, | 231 static vpx_codec_ctx* InitializeVpxContext(vpx_codec_ctx* context, |
| 232 const VideoDecoderConfig& config) { | 232 const VideoDecoderConfig& config) { |
| 233 context = new vpx_codec_ctx(); | 233 context = new vpx_codec_ctx(); |
| 234 vpx_codec_dec_cfg_t vpx_config = {0}; | 234 vpx_codec_dec_cfg_t vpx_config = {0}; |
| 235 vpx_config.w = config.coded_size().width(); | 235 vpx_config.w = config.coded_size().width(); |
| 236 vpx_config.h = config.coded_size().height(); | 236 vpx_config.h = config.coded_size().height(); |
| 237 vpx_config.threads = GetThreadCount(config); | 237 vpx_config.threads = GetThreadCount(config); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 void VpxVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, | 304 void VpxVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 305 const DecodeCB& decode_cb) { | 305 const DecodeCB& decode_cb) { |
| 306 DCHECK(task_runner_->BelongsToCurrentThread()); | 306 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 307 DCHECK(!decode_cb.is_null()); | 307 DCHECK(!decode_cb.is_null()); |
| 308 CHECK_NE(state_, kUninitialized); | 308 CHECK_NE(state_, kUninitialized); |
| 309 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; | 309 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; |
| 310 | 310 |
| 311 decode_cb_ = BindToCurrentLoop(decode_cb); | 311 decode_cb_ = base::BindToCurrentLoop(decode_cb); |
| 312 | 312 |
| 313 if (state_ == kError) { | 313 if (state_ == kError) { |
| 314 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); | 314 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); |
| 315 return; | 315 return; |
| 316 } | 316 } |
| 317 | 317 |
| 318 // Return empty frames if decoding has finished. | 318 // Return empty frames if decoding has finished. |
| 319 if (state_ == kDecodeFinished) { | 319 if (state_ == kDecodeFinished) { |
| 320 base::ResetAndReturn(&decode_cb_).Run(kOk); | 320 base::ResetAndReturn(&decode_cb_).Run(kOk); |
| 321 return; | 321 return; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); | 521 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); |
| 522 return; | 522 return; |
| 523 } | 523 } |
| 524 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], | 524 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], |
| 525 vpx_image_alpha->stride[VPX_PLANE_Y], | 525 vpx_image_alpha->stride[VPX_PLANE_Y], |
| 526 vpx_image_alpha->d_h, | 526 vpx_image_alpha->d_h, |
| 527 video_frame->get()); | 527 video_frame->get()); |
| 528 } | 528 } |
| 529 | 529 |
| 530 } // namespace media | 530 } // namespace media |
| OLD | NEW |