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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: media/cast/video_receiver/codecs/vp8/vp8_decoder.cc
diff --git a/media/cast/video_receiver/codecs/vp8/vp8_decoder.cc b/media/cast/video_receiver/codecs/vp8/vp8_decoder.cc
index 84d4fa9d5588ff18dead29733561de17e37e038e..03d2487aef83e8c68572aad38879789ea7016a59 100644
--- a/media/cast/video_receiver/codecs/vp8/vp8_decoder.cc
+++ b/media/cast/video_receiver/codecs/vp8/vp8_decoder.cc
@@ -7,7 +7,9 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "media/base/video_frame.h"
#include "third_party/libvpx/source/libvpx/vpx/vp8dx.h"
+#include "ui/gfx/size.h"
namespace media {
namespace cast {
@@ -58,43 +60,51 @@ bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame,
return false;
}
- scoped_ptr<I420VideoFrame> decoded_frame(new I420VideoFrame());
+ gfx::Size visible_size(img->d_w, img->d_h);
+ gfx::Size full_size(img->stride[VPX_PLANE_Y], img->d_h);
+ DCHECK(VideoFrame::IsValidConfig(VideoFrame::I420, visible_size,
+ gfx::Rect(visible_size), full_size));
+ // Temp timing setting - will sort out timing in a follow up cl.
+ scoped_refptr<VideoFrame> decoded_frame =
+ VideoFrame::CreateFrame(VideoFrame::I420, visible_size,
+ gfx::Rect(visible_size), full_size, base::TimeDelta());
+
+ // Copy each plane individually (need to account for stride).
+ CopyPlane(VideoFrame::kYPlane, img->planes[VPX_PLANE_Y],
+ img->stride[VPX_PLANE_Y], img->d_h, decoded_frame.get());
+ CopyPlane(VideoFrame::kUPlane, img->planes[VPX_PLANE_U],
+ img->stride[VPX_PLANE_U], (img->d_h + 1) / 2, decoded_frame.get());
+ CopyPlane(VideoFrame::kVPlane, img->planes[VPX_PLANE_V],
+ img->stride[VPX_PLANE_V], (img->d_h + 1) / 2, decoded_frame.get());
- // The img is only valid until the next call to vpx_codec_decode.
- // Populate the decoded image.
- decoded_frame->width = img->d_w;
- decoded_frame->height = img->d_h;
-
- decoded_frame->y_plane.stride = img->stride[VPX_PLANE_Y];
- decoded_frame->y_plane.length = img->stride[VPX_PLANE_Y] * img->d_h;
- decoded_frame->y_plane.data = new uint8[decoded_frame->y_plane.length];
- memcpy(decoded_frame->y_plane.data, img->planes[VPX_PLANE_Y],
- decoded_frame->y_plane.length);
-
- decoded_frame->u_plane.stride = img->stride[VPX_PLANE_U];
- decoded_frame->u_plane.length = img->stride[VPX_PLANE_U] * (img->d_h + 1) / 2;
- decoded_frame->u_plane.data = new uint8[decoded_frame->u_plane.length];
- memcpy(decoded_frame->u_plane.data, img->planes[VPX_PLANE_U],
- decoded_frame->u_plane.length);
-
- decoded_frame->v_plane.stride = img->stride[VPX_PLANE_V];
- decoded_frame->v_plane.length = img->stride[VPX_PLANE_V] * (img->d_h + 1) / 2;
- decoded_frame->v_plane.data = new uint8[decoded_frame->v_plane.length];
-
- memcpy(decoded_frame->v_plane.data, img->planes[VPX_PLANE_V],
- decoded_frame->v_plane.length);
-
- cast_environment_->Logging()->InsertFrameEvent(kVideoFrameDecoded,
- kFrameIdUnknown, encoded_frame->frame_id);
VLOG(1) << "Decoded frame " << frame_id_int;
// Frame decoded - return frame to the user via callback.
cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE,
- base::Bind(frame_decoded_cb, base::Passed(&decoded_frame), render_time));
+ base::Bind(frame_decoded_cb, decoded_frame, render_time));
return true;
}
+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.
+ int rows, VideoFrame* frame) {
+ uint8* dest = frame->data(plane);
+ int dest_stride = frame->stride(plane);
+
+ // Clamp in case source frame has smaller stride.
+ int bytes_to_copy_per_row = std::min(frame->row_bytes(plane), stride);
+
+ // Clamp in case source frame has smaller height.
+ int rows_to_copy = std::min(frame->rows(plane), rows);
+
+ // Copy!
+ for (int row = 0; row < rows_to_copy; ++row) {
+ memcpy(dest, source, bytes_to_copy_per_row);
+ source += stride;
+ dest += dest_stride;
+ }
+}
+
} // namespace cast
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698