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 void LogFrameDecodedEvent(CastEnvironment* const cast_environment, | 15 void LogFrameDecodedEvent(CastEnvironment* const cast_environment, |
16 uint32 frame_id) { | 16 uint32 frame_id) { |
17 // TODO(mikhal): Sort out passing of rtp_timestamp. | 17 // TODO(mikhal): Sort out passing of rtp_timestamp. |
18 // cast_environment->Logging()->InsertFrameEvent(kVideoFrameDecoded, | 18 // cast_environment->Logging()->InsertFrameEvent(kVideoFrameDecoded, |
19 // 0, frame_id); | 19 // 0, frame_id); |
20 } | 20 } |
21 | 21 |
22 Vp8Decoder::Vp8Decoder(int number_of_cores, | 22 Vp8Decoder::Vp8Decoder(scoped_refptr<CastEnvironment> cast_environment) |
23 scoped_refptr<CastEnvironment> cast_environment) | |
24 : decoder_(new vpx_dec_ctx_t()), | 23 : decoder_(new vpx_dec_ctx_t()), |
25 cast_environment_(cast_environment) { | 24 cast_environment_(cast_environment) { |
26 InitDecode(number_of_cores); | 25 // Make sure that we initialize the decoder from the correct thread. |
| 26 cast_environment_->PostTask(CastEnvironment::VIDEO_DECODER, FROM_HERE, |
| 27 base::Bind(&Vp8Decoder::InitDecoder, base::Unretained(this))); |
27 } | 28 } |
28 | 29 |
29 Vp8Decoder::~Vp8Decoder() {} | 30 Vp8Decoder::~Vp8Decoder() {} |
30 | 31 |
31 void Vp8Decoder::InitDecode(int number_of_cores) { | 32 void Vp8Decoder::InitDecoder() { |
32 vpx_codec_dec_cfg_t cfg; | 33 vpx_codec_dec_cfg_t cfg; |
33 cfg.threads = number_of_cores; | 34 // Initializing to use one core. |
| 35 cfg.threads = 1; |
34 vpx_codec_flags_t flags = VPX_CODEC_USE_POSTPROC; | 36 vpx_codec_flags_t flags = VPX_CODEC_USE_POSTPROC; |
35 | 37 |
36 if (vpx_codec_dec_init(decoder_.get(), vpx_codec_vp8_dx(), &cfg, flags)) { | 38 if (vpx_codec_dec_init(decoder_.get(), vpx_codec_vp8_dx(), &cfg, flags)) { |
37 DCHECK(false) << "VP8 decode error"; | 39 DCHECK(false) << "VP8 decode error"; |
38 } | 40 } |
39 } | 41 } |
40 | 42 |
41 bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame, | 43 bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame, |
42 const base::TimeTicks render_time, | 44 const base::TimeTicks render_time, |
43 const VideoFrameDecodedCallback& frame_decoded_cb) { | 45 const VideoFrameDecodedCallback& frame_decoded_cb) { |
| 46 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::VIDEO_DECODER)); |
44 const int frame_id_int = static_cast<int>(encoded_frame->frame_id); | 47 const int frame_id_int = static_cast<int>(encoded_frame->frame_id); |
45 VLOG(1) << "VP8 decode frame:" << frame_id_int | 48 VLOG(1) << "VP8 decode frame:" << frame_id_int |
46 << " sized:" << encoded_frame->data.size(); | 49 << " sized:" << encoded_frame->data.size(); |
47 | 50 |
48 if (encoded_frame->data.empty()) return false; | 51 if (encoded_frame->data.empty()) return false; |
49 | 52 |
50 vpx_codec_iter_t iter = NULL; | 53 vpx_codec_iter_t iter = NULL; |
51 vpx_image_t* img; | 54 vpx_image_t* img; |
52 if (vpx_codec_decode( | 55 if (vpx_codec_decode( |
53 decoder_.get(), | 56 decoder_.get(), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 decoded_frame->v_plane.stride = img->stride[VPX_PLANE_V]; | 90 decoded_frame->v_plane.stride = img->stride[VPX_PLANE_V]; |
88 decoded_frame->v_plane.length = img->stride[VPX_PLANE_V] * (img->d_h + 1) / 2; | 91 decoded_frame->v_plane.length = img->stride[VPX_PLANE_V] * (img->d_h + 1) / 2; |
89 decoded_frame->v_plane.data = new uint8[decoded_frame->v_plane.length]; | 92 decoded_frame->v_plane.data = new uint8[decoded_frame->v_plane.length]; |
90 | 93 |
91 memcpy(decoded_frame->v_plane.data, img->planes[VPX_PLANE_V], | 94 memcpy(decoded_frame->v_plane.data, img->planes[VPX_PLANE_V], |
92 decoded_frame->v_plane.length); | 95 decoded_frame->v_plane.length); |
93 | 96 |
94 // Log:: Decoding complete (should be called from the main thread). | 97 // Log:: Decoding complete (should be called from the main thread). |
95 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, base::Bind( | 98 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, base::Bind( |
96 LogFrameDecodedEvent, cast_environment_,encoded_frame->frame_id)); | 99 LogFrameDecodedEvent, cast_environment_,encoded_frame->frame_id)); |
| 100 |
97 VLOG(1) << "Decoded frame " << frame_id_int; | 101 VLOG(1) << "Decoded frame " << frame_id_int; |
98 | |
99 // Frame decoded - return frame to the user via callback. | 102 // Frame decoded - return frame to the user via callback. |
100 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 103 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
101 base::Bind(frame_decoded_cb, base::Passed(&decoded_frame), | 104 base::Bind(frame_decoded_cb, base::Passed(&decoded_frame), |
102 render_time)); | 105 render_time)); |
103 | 106 |
104 return true; | 107 return true; |
105 } | 108 } |
106 | 109 |
107 } // namespace cast | 110 } // namespace cast |
108 } // namespace media | 111 } // namespace media |
109 | 112 |
OLD | NEW |