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

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: Adding media to DEPS + rebase 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"
10 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h" 11 #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h"
12 #include "ui/gfx/size.h"
11 13
12 namespace media { 14 namespace media {
13 namespace cast { 15 namespace cast {
14 16
15 Vp8Decoder::Vp8Decoder(int number_of_cores, 17 Vp8Decoder::Vp8Decoder(int number_of_cores,
16 scoped_refptr<CastEnvironment> cast_environment) 18 scoped_refptr<CastEnvironment> cast_environment)
17 : decoder_(new vpx_dec_ctx_t()), 19 : decoder_(new vpx_dec_ctx_t()),
18 cast_environment_(cast_environment) { 20 cast_environment_(cast_environment) {
19 InitDecode(number_of_cores); 21 InitDecode(number_of_cores);
20 } 22 }
(...skipping 30 matching lines...) Expand all
51 VLOG(1) << "Failed to decode VP8 frame."; 53 VLOG(1) << "Failed to decode VP8 frame.";
52 return false; 54 return false;
53 } 55 }
54 56
55 img = vpx_codec_get_frame(decoder_.get(), &iter); 57 img = vpx_codec_get_frame(decoder_.get(), &iter);
56 if (img == NULL) { 58 if (img == NULL) {
57 VLOG(1) << "Skip rendering VP8 frame:" << frame_id_int; 59 VLOG(1) << "Skip rendering VP8 frame:" << frame_id_int;
58 return false; 60 return false;
59 } 61 }
60 62
61 scoped_ptr<I420VideoFrame> decoded_frame(new I420VideoFrame()); 63 gfx::Size visible_size(img->d_w, img->d_h);
64 gfx::Size full_size(img->stride[VPX_PLANE_Y], img->d_h);
65 DCHECK(VideoFrame::IsValidConfig(VideoFrame::I420, visible_size,
66 gfx::Rect(visible_size), full_size));
67 // Temp timing setting - will sort out timing in a follow up cl.
68 scoped_refptr<VideoFrame> decoded_frame =
69 VideoFrame::CreateFrame(VideoFrame::I420, visible_size,
70 gfx::Rect(visible_size), full_size, base::TimeDelta());
62 71
63 // The img is only valid until the next call to vpx_codec_decode. 72 // Copy each plane individually (need to account for stride).
64 // Populate the decoded image. 73 CopyPlane(VideoFrame::kYPlane, img->planes[VPX_PLANE_Y],
65 decoded_frame->width = img->d_w; 74 img->stride[VPX_PLANE_Y], img->d_h, decoded_frame.get());
66 decoded_frame->height = img->d_h; 75 CopyPlane(VideoFrame::kUPlane, img->planes[VPX_PLANE_U],
76 img->stride[VPX_PLANE_U], (img->d_h + 1) / 2, decoded_frame.get());
77 CopyPlane(VideoFrame::kVPlane, img->planes[VPX_PLANE_V],
78 img->stride[VPX_PLANE_V], (img->d_h + 1) / 2, decoded_frame.get());
67 79
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; 80 VLOG(1) << "Decoded frame " << frame_id_int;
90 81
91 // Frame decoded - return frame to the user via callback. 82 // Frame decoded - return frame to the user via callback.
92 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, 83 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE,
93 base::Bind(frame_decoded_cb, base::Passed(&decoded_frame), render_time)); 84 base::Bind(frame_decoded_cb, decoded_frame, render_time));
94 85
95 return true; 86 return true;
96 } 87 }
97 88
89 void Vp8Decoder::CopyPlane(size_t plane, const uint8* source, int stride,
scherkus (not reviewing) 2013/11/27 22:21:54 you may want to look at VpxVideoDecoder::CopyVpxIm
mikhal1 2013/11/27 22:41:30 Done.
90 int rows, VideoFrame* frame) {
91 uint8* dest = frame->data(plane);
92 int dest_stride = frame->stride(plane);
93
94 // Clamp in case source frame has smaller stride.
95 int bytes_to_copy_per_row = std::min(frame->row_bytes(plane), stride);
96
97 // Clamp in case source frame has smaller height.
98 int rows_to_copy = std::min(frame->rows(plane), rows);
99
100 // Copy!
101 for (int row = 0; row < rows_to_copy; ++row) {
102 memcpy(dest, source, bytes_to_copy_per_row);
103 source += stride;
104 dest += dest_stride;
105 }
106 }
107
98 } // namespace cast 108 } // namespace cast
99 } // namespace media 109 } // namespace media
100 110
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698