OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cast/video_receiver/codecs/vp8/vp8_decoder.h" | 5 #include "media/cast/video_receiver/codecs/vp8/vp8_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h" | 10 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 namespace cast { | 13 namespace cast { |
14 | 14 |
15 Vp8Decoder::Vp8Decoder(int number_of_cores, | 15 Vp8Decoder::Vp8Decoder(scoped_refptr<CastEnvironment> cast_environment) |
16 scoped_refptr<CastEnvironment> cast_environment) | |
17 : decoder_(new vpx_dec_ctx_t()), | 16 : decoder_(new vpx_dec_ctx_t()), |
18 cast_environment_(cast_environment) { | 17 cast_environment_(cast_environment) {} |
19 InitDecode(number_of_cores); | |
20 } | |
21 | 18 |
22 Vp8Decoder::~Vp8Decoder() {} | 19 Vp8Decoder::~Vp8Decoder() {} |
23 | 20 |
24 void Vp8Decoder::InitDecode(int number_of_cores) { | 21 void Vp8Decoder::InitDecoder() { |
25 vpx_codec_dec_cfg_t cfg; | 22 vpx_codec_dec_cfg_t cfg; |
26 cfg.threads = number_of_cores; | 23 // Initializing to use one core. |
| 24 cfg.threads = 1; |
27 vpx_codec_flags_t flags = VPX_CODEC_USE_POSTPROC; | 25 vpx_codec_flags_t flags = VPX_CODEC_USE_POSTPROC; |
28 | 26 |
29 if (vpx_codec_dec_init(decoder_.get(), vpx_codec_vp8_dx(), &cfg, flags)) { | 27 if (vpx_codec_dec_init(decoder_.get(), vpx_codec_vp8_dx(), &cfg, flags)) { |
30 DCHECK(false) << "VP8 decode error"; | 28 DCHECK(false) << "VP8 decode error"; |
31 } | 29 } |
32 } | 30 } |
33 | 31 |
34 bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame, | 32 bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame, |
35 const base::TimeTicks render_time, | 33 const base::TimeTicks render_time, |
36 const VideoFrameDecodedCallback& frame_decoded_cb) { | 34 const VideoFrameDecodedCallback& frame_decoded_cb) { |
| 35 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::VIDEO_DECODER)); |
37 const int frame_id_int = static_cast<int>(encoded_frame->frame_id); | 36 const int frame_id_int = static_cast<int>(encoded_frame->frame_id); |
38 VLOG(1) << "VP8 decode frame:" << frame_id_int | 37 VLOG(1) << "VP8 decode frame:" << frame_id_int |
39 << " sized:" << encoded_frame->data.size(); | 38 << " sized:" << encoded_frame->data.size(); |
40 | 39 |
41 if (encoded_frame->data.empty()) return false; | 40 if (encoded_frame->data.empty()) return false; |
42 | 41 |
43 vpx_codec_iter_t iter = NULL; | 42 vpx_codec_iter_t iter = NULL; |
44 vpx_image_t* img; | 43 vpx_image_t* img; |
45 if (vpx_codec_decode( | 44 if (vpx_codec_decode( |
46 decoder_.get(), | 45 decoder_.get(), |
(...skipping 30 matching lines...) Expand all Loading... |
77 memcpy(decoded_frame->u_plane.data, img->planes[VPX_PLANE_U], | 76 memcpy(decoded_frame->u_plane.data, img->planes[VPX_PLANE_U], |
78 decoded_frame->u_plane.length); | 77 decoded_frame->u_plane.length); |
79 | 78 |
80 decoded_frame->v_plane.stride = img->stride[VPX_PLANE_V]; | 79 decoded_frame->v_plane.stride = img->stride[VPX_PLANE_V]; |
81 decoded_frame->v_plane.length = img->stride[VPX_PLANE_V] * (img->d_h + 1) / 2; | 80 decoded_frame->v_plane.length = img->stride[VPX_PLANE_V] * (img->d_h + 1) / 2; |
82 decoded_frame->v_plane.data = new uint8[decoded_frame->v_plane.length]; | 81 decoded_frame->v_plane.data = new uint8[decoded_frame->v_plane.length]; |
83 | 82 |
84 memcpy(decoded_frame->v_plane.data, img->planes[VPX_PLANE_V], | 83 memcpy(decoded_frame->v_plane.data, img->planes[VPX_PLANE_V], |
85 decoded_frame->v_plane.length); | 84 decoded_frame->v_plane.length); |
86 | 85 |
87 cast_environment_->Logging()->InsertFrameEvent(kVideoFrameDecoded, | |
88 kFrameIdUnknown, encoded_frame->frame_id); | |
89 VLOG(1) << "Decoded frame " << frame_id_int; | 86 VLOG(1) << "Decoded frame " << frame_id_int; |
90 | |
91 // Frame decoded - return frame to the user via callback. | 87 // Frame decoded - return frame to the user via callback. |
92 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 88 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
93 base::Bind(frame_decoded_cb, base::Passed(&decoded_frame), render_time)); | 89 base::Bind(frame_decoded_cb, base::Passed(&decoded_frame), render_time)); |
94 | 90 |
95 return true; | 91 return true; |
96 } | 92 } |
97 | 93 |
98 } // namespace cast | 94 } // namespace cast |
99 } // namespace media | 95 } // namespace media |
100 | 96 |
OLD | NEW |