| 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/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/trace_event.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 "media/base/bind_to_current_loop.h" | 21 #include "media/base/bind_to_current_loop.h" |
| 21 #include "media/base/decoder_buffer.h" | 22 #include "media/base/decoder_buffer.h" |
| 22 #include "media/base/demuxer_stream.h" | 23 #include "media/base/demuxer_stream.h" |
| 23 #include "media/base/limits.h" | 24 #include "media/base/limits.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 } | 361 } |
| 361 | 362 |
| 362 bool VpxVideoDecoder::VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, | 363 bool VpxVideoDecoder::VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, |
| 363 scoped_refptr<VideoFrame>* video_frame) { | 364 scoped_refptr<VideoFrame>* video_frame) { |
| 364 DCHECK(video_frame); | 365 DCHECK(video_frame); |
| 365 DCHECK(!buffer->end_of_stream()); | 366 DCHECK(!buffer->end_of_stream()); |
| 366 | 367 |
| 367 // Pass |buffer| to libvpx. | 368 // Pass |buffer| to libvpx. |
| 368 int64 timestamp = buffer->timestamp().InMicroseconds(); | 369 int64 timestamp = buffer->timestamp().InMicroseconds(); |
| 369 void* user_priv = reinterpret_cast<void*>(×tamp); | 370 void* user_priv = reinterpret_cast<void*>(×tamp); |
| 370 vpx_codec_err_t status = vpx_codec_decode(vpx_codec_, | 371 |
| 371 buffer->data(), | 372 { |
| 372 buffer->data_size(), | 373 TRACE_EVENT1("video", "vpx_codec_decode", "timestamp", timestamp); |
| 373 user_priv, | 374 vpx_codec_err_t status = vpx_codec_decode(vpx_codec_, |
| 374 0); | 375 buffer->data(), |
| 375 if (status != VPX_CODEC_OK) { | 376 buffer->data_size(), |
| 376 LOG(ERROR) << "vpx_codec_decode() failed, status=" << status; | 377 user_priv, |
| 377 return false; | 378 0); |
| 379 if (status != VPX_CODEC_OK) { |
| 380 LOG(ERROR) << "vpx_codec_decode() failed, status=" << status; |
| 381 return false; |
| 382 } |
| 378 } | 383 } |
| 379 | 384 |
| 380 // Gets pointer to decoded data. | 385 // Gets pointer to decoded data. |
| 381 vpx_codec_iter_t iter = NULL; | 386 vpx_codec_iter_t iter = NULL; |
| 382 const vpx_image_t* vpx_image = vpx_codec_get_frame(vpx_codec_, &iter); | 387 const vpx_image_t* vpx_image = vpx_codec_get_frame(vpx_codec_, &iter); |
| 383 if (!vpx_image) { | 388 if (!vpx_image) { |
| 384 *video_frame = NULL; | 389 *video_frame = NULL; |
| 385 return true; | 390 return true; |
| 386 } | 391 } |
| 387 | 392 |
| 388 if (vpx_image->user_priv != reinterpret_cast<void*>(×tamp)) { | 393 if (vpx_image->user_priv != reinterpret_cast<void*>(×tamp)) { |
| 389 LOG(ERROR) << "Invalid output timestamp."; | 394 LOG(ERROR) << "Invalid output timestamp."; |
| 390 return false; | 395 return false; |
| 391 } | 396 } |
| 392 | 397 |
| 393 const vpx_image_t* vpx_image_alpha = NULL; | 398 const vpx_image_t* vpx_image_alpha = NULL; |
| 394 if (vpx_codec_alpha_ && buffer->side_data_size() >= 8) { | 399 if (vpx_codec_alpha_ && buffer->side_data_size() >= 8) { |
| 395 // Pass alpha data to libvpx. | 400 // Pass alpha data to libvpx. |
| 396 int64 timestamp_alpha = buffer->timestamp().InMicroseconds(); | 401 int64 timestamp_alpha = buffer->timestamp().InMicroseconds(); |
| 397 void* user_priv_alpha = reinterpret_cast<void*>(×tamp_alpha); | 402 void* user_priv_alpha = reinterpret_cast<void*>(×tamp_alpha); |
| 398 | 403 |
| 399 // First 8 bytes of side data is side_data_id in big endian. | 404 // First 8 bytes of side data is side_data_id in big endian. |
| 400 const uint64 side_data_id = base::NetToHost64( | 405 const uint64 side_data_id = base::NetToHost64( |
| 401 *(reinterpret_cast<const uint64*>(buffer->side_data()))); | 406 *(reinterpret_cast<const uint64*>(buffer->side_data()))); |
| 402 if (side_data_id == 1) { | 407 if (side_data_id == 1) { |
| 403 status = vpx_codec_decode(vpx_codec_alpha_, | 408 { |
| 404 buffer->side_data() + 8, | 409 TRACE_EVENT1("video", "vpx_codec_decode_alpha", |
| 405 buffer->side_data_size() - 8, | 410 "timestamp_alpha", timestamp_alpha); |
| 406 user_priv_alpha, | 411 vpx_codec_err_t status = vpx_codec_decode(vpx_codec_alpha_, |
| 407 0); | 412 buffer->side_data() + 8, |
| 408 | 413 buffer->side_data_size() - 8, |
| 409 if (status != VPX_CODEC_OK) { | 414 user_priv_alpha, |
| 410 LOG(ERROR) << "vpx_codec_decode() failed on alpha, status=" << status; | 415 0); |
| 411 return false; | 416 if (status != VPX_CODEC_OK) { |
| 417 LOG(ERROR) << "vpx_codec_decode() failed on alpha, status=" << status; |
| 418 return false; |
| 419 } |
| 412 } | 420 } |
| 413 | 421 |
| 414 // Gets pointer to decoded data. | 422 // Gets pointer to decoded data. |
| 415 vpx_codec_iter_t iter_alpha = NULL; | 423 vpx_codec_iter_t iter_alpha = NULL; |
| 416 vpx_image_alpha = vpx_codec_get_frame(vpx_codec_alpha_, &iter_alpha); | 424 vpx_image_alpha = vpx_codec_get_frame(vpx_codec_alpha_, &iter_alpha); |
| 417 if (!vpx_image_alpha) { | 425 if (!vpx_image_alpha) { |
| 418 *video_frame = NULL; | 426 *video_frame = NULL; |
| 419 return true; | 427 return true; |
| 420 } | 428 } |
| 421 | 429 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); | 502 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); |
| 495 return; | 503 return; |
| 496 } | 504 } |
| 497 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], | 505 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], |
| 498 vpx_image->stride[VPX_PLANE_Y], | 506 vpx_image->stride[VPX_PLANE_Y], |
| 499 vpx_image->d_h, | 507 vpx_image->d_h, |
| 500 video_frame->get()); | 508 video_frame->get()); |
| 501 } | 509 } |
| 502 | 510 |
| 503 } // namespace media | 511 } // namespace media |
| OLD | NEW |