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 "media/base/video_frame.h" | |
11 #include "media/base/video_util.h" | |
10 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h" | 12 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h" |
13 #include "ui/gfx/size.h" | |
11 | 14 |
12 namespace media { | 15 namespace media { |
13 namespace cast { | 16 namespace cast { |
14 | 17 |
15 Vp8Decoder::Vp8Decoder(int number_of_cores, | 18 Vp8Decoder::Vp8Decoder(int number_of_cores, |
16 scoped_refptr<CastEnvironment> cast_environment) | 19 scoped_refptr<CastEnvironment> cast_environment) |
17 : decoder_(new vpx_dec_ctx_t()), | 20 : decoder_(new vpx_dec_ctx_t()), |
18 cast_environment_(cast_environment) { | 21 cast_environment_(cast_environment) { |
19 InitDecode(number_of_cores); | 22 InitDecode(number_of_cores); |
20 } | 23 } |
(...skipping 30 matching lines...) Expand all Loading... | |
51 VLOG(1) << "Failed to decode VP8 frame."; | 54 VLOG(1) << "Failed to decode VP8 frame."; |
52 return false; | 55 return false; |
53 } | 56 } |
54 | 57 |
55 img = vpx_codec_get_frame(decoder_.get(), &iter); | 58 img = vpx_codec_get_frame(decoder_.get(), &iter); |
56 if (img == NULL) { | 59 if (img == NULL) { |
57 VLOG(1) << "Skip rendering VP8 frame:" << frame_id_int; | 60 VLOG(1) << "Skip rendering VP8 frame:" << frame_id_int; |
58 return false; | 61 return false; |
59 } | 62 } |
60 | 63 |
61 scoped_ptr<I420VideoFrame> decoded_frame(new I420VideoFrame()); | 64 gfx::Size visible_size(img->d_w, img->d_h); |
65 gfx::Size full_size(img->stride[VPX_PLANE_Y], img->d_h); | |
66 DCHECK(VideoFrame::IsValidConfig(VideoFrame::I420, visible_size, | |
67 gfx::Rect(visible_size), full_size)); | |
68 // Temp timing setting - will sort out timing in a follow up cl. | |
69 scoped_refptr<VideoFrame> decoded_frame = | |
70 VideoFrame::CreateFrame(VideoFrame::I420, visible_size, | |
71 gfx::Rect(visible_size), full_size, base::TimeDelta()); | |
62 | 72 |
63 // The img is only valid until the next call to vpx_codec_decode. | 73 // Copy each plane individually (need to account for stride). |
scherkus (not reviewing)
2013/12/02 18:24:35
do you plan on keeping this copy around forever?
mikhal1
2013/12/03 16:57:06
Added a TODO.
On 2013/12/02 18:24:35, scherkus wro
| |
64 // Populate the decoded image. | 74 CopyPlane(VideoFrame::kYPlane, img->planes[VPX_PLANE_Y], |
65 decoded_frame->width = img->d_w; | 75 img->stride[VPX_PLANE_Y], img->d_h, decoded_frame.get()); |
66 decoded_frame->height = img->d_h; | 76 CopyPlane(VideoFrame::kUPlane, img->planes[VPX_PLANE_U], |
77 img->stride[VPX_PLANE_U], (img->d_h + 1) / 2, decoded_frame.get()); | |
78 CopyPlane(VideoFrame::kVPlane, img->planes[VPX_PLANE_V], | |
79 img->stride[VPX_PLANE_V], (img->d_h + 1) / 2, decoded_frame.get()); | |
67 | 80 |
68 decoded_frame->y_plane.stride = img->stride[VPX_PLANE_Y]; | |
69 decoded_frame->y_plane.length = img->stride[VPX_PLANE_Y] * img->d_h; | |
70 decoded_frame->y_plane.data = new uint8[decoded_frame->y_plane.length]; | |
71 memcpy(decoded_frame->y_plane.data, img->planes[VPX_PLANE_Y], | |
72 decoded_frame->y_plane.length); | |
73 | |
74 decoded_frame->u_plane.stride = img->stride[VPX_PLANE_U]; | |
75 decoded_frame->u_plane.length = img->stride[VPX_PLANE_U] * (img->d_h + 1) / 2; | |
76 decoded_frame->u_plane.data = new uint8[decoded_frame->u_plane.length]; | |
77 memcpy(decoded_frame->u_plane.data, img->planes[VPX_PLANE_U], | |
78 decoded_frame->u_plane.length); | |
79 | |
80 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; | |
82 decoded_frame->v_plane.data = new uint8[decoded_frame->v_plane.length]; | |
83 | |
84 memcpy(decoded_frame->v_plane.data, img->planes[VPX_PLANE_V], | |
85 decoded_frame->v_plane.length); | |
86 | |
87 cast_environment_->Logging()->InsertFrameEvent(kVideoFrameDecoded, | |
88 kFrameIdUnknown, encoded_frame->frame_id); | |
89 VLOG(1) << "Decoded frame " << frame_id_int; | 81 VLOG(1) << "Decoded frame " << frame_id_int; |
90 | 82 |
91 // Frame decoded - return frame to the user via callback. | 83 // Frame decoded - return frame to the user via callback. |
92 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 84 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
93 base::Bind(frame_decoded_cb, base::Passed(&decoded_frame), render_time)); | 85 base::Bind(frame_decoded_cb, decoded_frame, render_time)); |
94 | 86 |
95 return true; | 87 return true; |
96 } | 88 } |
97 | 89 |
98 } // namespace cast | 90 } // namespace cast |
99 } // namespace media | 91 } // namespace media |
100 | 92 |
OLD | NEW |