Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: media/cast/video_receiver/codecs/vp8/vp8_decoder.cc

Issue 82593005: Cast: Switching recevier to use media::VideoFrame (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing includes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 void LogFrameDecodedEvent(CastEnvironment* const cast_environment, 18 void LogFrameDecodedEvent(CastEnvironment* const cast_environment,
16 uint32 frame_id) { 19 uint32 frame_id) {
17 // TODO(mikhal): Sort out passing of rtp_timestamp. 20 // TODO(mikhal): Sort out passing of rtp_timestamp.
18 // cast_environment->Logging()->InsertFrameEvent(kVideoFrameDecoded, 21 // cast_environment->Logging()->InsertFrameEvent(kVideoFrameDecoded,
19 // 0, frame_id); 22 // 0, frame_id);
20 } 23 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 VLOG(1) << "Failed to decode VP8 frame."; 61 VLOG(1) << "Failed to decode VP8 frame.";
59 return false; 62 return false;
60 } 63 }
61 64
62 img = vpx_codec_get_frame(decoder_.get(), &iter); 65 img = vpx_codec_get_frame(decoder_.get(), &iter);
63 if (img == NULL) { 66 if (img == NULL) {
64 VLOG(1) << "Skip rendering VP8 frame:" << frame_id_int; 67 VLOG(1) << "Skip rendering VP8 frame:" << frame_id_int;
65 return false; 68 return false;
66 } 69 }
67 70
68 scoped_ptr<I420VideoFrame> decoded_frame(new I420VideoFrame()); 71 gfx::Size visible_size(img->d_w, img->d_h);
72 gfx::Size full_size(img->stride[VPX_PLANE_Y], img->d_h);
73 DCHECK(VideoFrame::IsValidConfig(VideoFrame::I420, visible_size,
74 gfx::Rect(visible_size), full_size));
75 // Temp timing setting - will sort out timing in a follow up cl.
76 scoped_refptr<VideoFrame> decoded_frame =
77 VideoFrame::CreateFrame(VideoFrame::I420, visible_size,
78 gfx::Rect(visible_size), full_size, base::TimeDelta());
69 79
70 // The img is only valid until the next call to vpx_codec_decode. 80 // Copy each plane individually (need to account for stride).
71 // Populate the decoded image. 81 // TODO(mikhal): Eliminate copy once http://crbug.com/321856 is resolved.
72 decoded_frame->width = img->d_w; 82 CopyPlane(VideoFrame::kYPlane, img->planes[VPX_PLANE_Y],
73 decoded_frame->height = img->d_h; 83 img->stride[VPX_PLANE_Y], img->d_h, decoded_frame.get());
74 84 CopyPlane(VideoFrame::kUPlane, img->planes[VPX_PLANE_U],
75 decoded_frame->y_plane.stride = img->stride[VPX_PLANE_Y]; 85 img->stride[VPX_PLANE_U], (img->d_h + 1) / 2, decoded_frame.get());
76 decoded_frame->y_plane.length = img->stride[VPX_PLANE_Y] * img->d_h; 86 CopyPlane(VideoFrame::kVPlane, img->planes[VPX_PLANE_V],
77 decoded_frame->y_plane.data = new uint8[decoded_frame->y_plane.length]; 87 img->stride[VPX_PLANE_V], (img->d_h + 1) / 2, decoded_frame.get());
78 memcpy(decoded_frame->y_plane.data, img->planes[VPX_PLANE_Y],
79 decoded_frame->y_plane.length);
80
81 decoded_frame->u_plane.stride = img->stride[VPX_PLANE_U];
82 decoded_frame->u_plane.length = img->stride[VPX_PLANE_U] * (img->d_h + 1) / 2;
83 decoded_frame->u_plane.data = new uint8[decoded_frame->u_plane.length];
84 memcpy(decoded_frame->u_plane.data, img->planes[VPX_PLANE_U],
85 decoded_frame->u_plane.length);
86
87 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;
89 decoded_frame->v_plane.data = new uint8[decoded_frame->v_plane.length];
90
91 memcpy(decoded_frame->v_plane.data, img->planes[VPX_PLANE_V],
92 decoded_frame->v_plane.length);
93 88
94 // Log:: Decoding complete (should be called from the main thread). 89 // Log:: Decoding complete (should be called from the main thread).
95 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, base::Bind( 90 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, base::Bind(
96 LogFrameDecodedEvent, cast_environment_,encoded_frame->frame_id)); 91 LogFrameDecodedEvent, cast_environment_,encoded_frame->frame_id));
97 VLOG(1) << "Decoded frame " << frame_id_int; 92 VLOG(1) << "Decoded frame " << frame_id_int;
98 93
99 // Frame decoded - return frame to the user via callback. 94 // Frame decoded - return frame to the user via callback.
100 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, 95 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE,
101 base::Bind(frame_decoded_cb, base::Passed(&decoded_frame), 96 base::Bind(frame_decoded_cb, decoded_frame, render_time));
102 render_time));
103 97
104 return true; 98 return true;
105 } 99 }
106 100
107 } // namespace cast 101 } // namespace cast
108 } // namespace media 102 } // namespace media
109 103
OLDNEW
« no previous file with comments | « media/cast/video_receiver/codecs/vp8/vp8_decoder.h ('k') | media/cast/video_receiver/video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698