Commit 743cf5ff authored by mikhal@google.com's avatar mikhal@google.com

Cast: Switching recevier to use media::VideoFrame

This is a follow up on a previous cl that switched Cast sender to use VideoFrame.

Review URL: https://codereview.chromium.org/82593005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238536 0039d316-1c4b-4281-b951-d872f2087c98
parent 250cefef
include_rules = [ include_rules = [
"+crypto", "+crypto",
"+media",
"+net", "+net",
"+third_party/webrtc", "+third_party/webrtc",
"+third_party/libyuv", "+third_party/libyuv",
......
...@@ -107,10 +107,11 @@ ...@@ -107,10 +107,11 @@
'<(DEPTH)/', '<(DEPTH)/',
], ],
'dependencies': [ 'dependencies': [
'cast_config',
'<(DEPTH)/ui/gfx/gfx.gyp:gfx', '<(DEPTH)/ui/gfx/gfx.gyp:gfx',
'<(DEPTH)/net/net.gyp:net_test_support', '<(DEPTH)/net/net.gyp:net_test_support',
'cast_config',
'<(DEPTH)/media/cast/cast_sender.gyp:*', '<(DEPTH)/media/cast/cast_sender.gyp:*',
'<(DEPTH)/media/media.gyp:media',
'<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/opus/opus.gyp:opus', '<(DEPTH)/third_party/opus/opus.gyp:opus',
'<(DEPTH)/media/cast/test/transport/transport.gyp:cast_transport', '<(DEPTH)/media/cast/test/transport/transport.gyp:cast_transport',
...@@ -127,10 +128,11 @@ ...@@ -127,10 +128,11 @@
'<(DEPTH)/', '<(DEPTH)/',
], ],
'dependencies': [ 'dependencies': [
'cast_config',
'<(DEPTH)/ui/gfx/gfx.gyp:gfx', '<(DEPTH)/ui/gfx/gfx.gyp:gfx',
'<(DEPTH)/net/net.gyp:net_test_support', '<(DEPTH)/net/net.gyp:net_test_support',
'cast_config',
'<(DEPTH)/media/cast/cast_receiver.gyp:*', '<(DEPTH)/media/cast/cast_receiver.gyp:*',
'<(DEPTH)/media/media.gyp:media',
'<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/media/cast/test/transport/transport.gyp:cast_transport', '<(DEPTH)/media/cast/test/transport/transport.gyp:cast_transport',
'<(DEPTH)/media/cast/test/utility/utility.gyp:cast_test_utility', '<(DEPTH)/media/cast/test/utility/utility.gyp:cast_test_utility',
......
...@@ -140,24 +140,6 @@ struct VideoReceiverConfig { ...@@ -140,24 +140,6 @@ struct VideoReceiverConfig {
std::string aes_iv_mask; // Binary string of size kAesKeySize. std::string aes_iv_mask; // Binary string of size kAesKeySize.
}; };
// DEPRECATED: Do not use in new code. Please migrate existing code to use
// media::VideoFrame.
struct I420VideoPlane {
int stride;
int length;
uint8* data;
};
// DEPRECATED: Do not use in new code. Please migrate existing code to use
// media::VideoFrame.
struct I420VideoFrame {
int width;
int height;
I420VideoPlane y_plane;
I420VideoPlane u_plane;
I420VideoPlane v_plane;
};
struct EncodedVideoFrame { struct EncodedVideoFrame {
EncodedVideoFrame(); EncodedVideoFrame();
~EncodedVideoFrame(); ~EncodedVideoFrame();
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
#include "media/cast/cast_config.h" #include "media/cast/cast_config.h"
#include "media/cast/cast_environment.h" #include "media/cast/cast_environment.h"
namespace media {
class VideoFrame;
}
namespace media { namespace media {
namespace cast { namespace cast {
// Callback in which the raw audio frame and play-out time will be returned // Callback in which the raw audio frame and play-out time will be returned
...@@ -29,7 +33,8 @@ typedef base::Callback<void(scoped_ptr<EncodedAudioFrame>, ...@@ -29,7 +33,8 @@ typedef base::Callback<void(scoped_ptr<EncodedAudioFrame>,
// Callback in which the raw frame and render time will be returned once // Callback in which the raw frame and render time will be returned once
// decoding is complete. // decoding is complete.
typedef base::Callback<void(scoped_ptr<I420VideoFrame>, const base::TimeTicks&)> typedef base::Callback<void(const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks&)>
VideoFrameDecodedCallback; VideoFrameDecodedCallback;
// Callback in which the encoded video frame and render time will be returned. // Callback in which the encoded video frame and render time will be returned.
......
...@@ -43,14 +43,16 @@ class EncodeDecodeTestFrameCallback : ...@@ -43,14 +43,16 @@ class EncodeDecodeTestFrameCallback :
PopulateVideoFrame(original_frame_.get(), start_value); PopulateVideoFrame(original_frame_.get(), start_value);
} }
void DecodeComplete(scoped_ptr<I420VideoFrame> decoded_frame, void DecodeComplete(const scoped_refptr<media::VideoFrame>& decoded_frame,
const base::TimeTicks& render_time) { const base::TimeTicks& render_time) {
++num_called_; ++num_called_;
// Compare resolution. // Compare resolution.
EXPECT_EQ(original_frame_->coded_size().width(), decoded_frame->width); EXPECT_EQ(original_frame_->coded_size().width(),
EXPECT_EQ(original_frame_->coded_size().height(), decoded_frame->height); decoded_frame->coded_size().width());
EXPECT_EQ(original_frame_->coded_size().height(),
decoded_frame->coded_size().height());
// Compare data. // Compare data.
EXPECT_GT(I420PSNR(*(original_frame_.get()), *(decoded_frame.get())), 40.0); EXPECT_GT(I420PSNR(original_frame_, decoded_frame), 40.0);
} }
int num_called() const { int num_called() const {
......
...@@ -273,7 +273,7 @@ class TestReceiverVideoCallback : ...@@ -273,7 +273,7 @@ class TestReceiverVideoCallback :
expected_frame_.push_back(expected_video_frame); expected_frame_.push_back(expected_video_frame);
} }
void CheckVideoFrame(scoped_ptr<I420VideoFrame> video_frame, void CheckVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& render_time) { const base::TimeTicks& render_time) {
++num_called_; ++num_called_;
...@@ -290,8 +290,8 @@ class TestReceiverVideoCallback : ...@@ -290,8 +290,8 @@ class TestReceiverVideoCallback :
<< "time_since_capture - upper_bound == " << "time_since_capture - upper_bound == "
<< (time_since_capture - upper_bound).InMicroseconds() << " usec"; << (time_since_capture - upper_bound).InMicroseconds() << " usec";
EXPECT_LE(expected_video_frame.capture_time, render_time); EXPECT_LE(expected_video_frame.capture_time, render_time);
EXPECT_EQ(expected_video_frame.width, video_frame->width); EXPECT_EQ(expected_video_frame.width, video_frame->coded_size().width());
EXPECT_EQ(expected_video_frame.height, video_frame->height); EXPECT_EQ(expected_video_frame.height, video_frame->coded_size().height());
gfx::Size size(expected_video_frame.width, expected_video_frame.height); gfx::Size size(expected_video_frame.width, expected_video_frame.height);
scoped_refptr<media::VideoFrame> expected_I420_frame = scoped_refptr<media::VideoFrame> expected_I420_frame =
...@@ -299,8 +299,7 @@ class TestReceiverVideoCallback : ...@@ -299,8 +299,7 @@ class TestReceiverVideoCallback :
VideoFrame::I420, size, gfx::Rect(size), size, base::TimeDelta()); VideoFrame::I420, size, gfx::Rect(size), size, base::TimeDelta());
PopulateVideoFrame(expected_I420_frame, expected_video_frame.start_value); PopulateVideoFrame(expected_I420_frame, expected_video_frame.start_value);
double psnr = I420PSNR(*(expected_I420_frame.get()), *(video_frame.get())); EXPECT_GE(I420PSNR(expected_I420_frame, video_frame), kVideoAcceptedPSNR);
EXPECT_GE(psnr, kVideoAcceptedPSNR);
} }
int number_times_called() { return num_called_;} int number_times_called() { return num_called_;}
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include "media/cast/test/linux_output_window.h" #include "media/cast/test/linux_output_window.h"
#include "base/logging.h" #include "base/logging.h"
#include "media/base/video_frame.h"
#include "third_party/libyuv/include/libyuv/convert.h" #include "third_party/libyuv/include/libyuv/convert.h"
#include "ui/gfx/size.h"
namespace media { namespace media {
namespace cast { namespace cast {
...@@ -108,22 +110,23 @@ void LinuxOutputWindow::CreateWindow(int x_pos, ...@@ -108,22 +110,23 @@ void LinuxOutputWindow::CreateWindow(int x_pos,
XSync(display_, false); XSync(display_, false);
} }
void LinuxOutputWindow::RenderFrame(const I420VideoFrame& video_frame) { void LinuxOutputWindow::RenderFrame(
libyuv::I420ToARGB(video_frame.y_plane.data, const scoped_refptr<media::VideoFrame>& video_frame) {
video_frame.y_plane.stride, libyuv::I420ToARGB(video_frame->data(VideoFrame::kYPlane),
video_frame.u_plane.data, video_frame->stride(VideoFrame::kYPlane),
video_frame.u_plane.stride, video_frame->data(VideoFrame::kUPlane),
video_frame.v_plane.data, video_frame->stride(VideoFrame::kUPlane),
video_frame.v_plane.stride, video_frame->data(VideoFrame::kVPlane),
video_frame->stride(VideoFrame::kVPlane),
render_buffer_, render_buffer_,
video_frame.width * 4, // Stride. video_frame->coded_size().width() * 4, // Stride.
video_frame.width, video_frame->coded_size().width(),
video_frame.height); video_frame->coded_size().height());
// Place image in window. // Place image in window.
XShmPutImage(display_, window_, gc_, image_, 0, 0, 0, 0, XShmPutImage(display_, window_, gc_, image_, 0, 0, 0, 0,
video_frame.width, video_frame->coded_size().width(),
video_frame.height, true); video_frame->coded_size().height(), true);
// Very important for the image to update properly! // Very important for the image to update properly!
XSync(display_, false); XSync(display_, false);
......
...@@ -11,7 +11,15 @@ ...@@ -11,7 +11,15 @@
#include <sys/shm.h> #include <sys/shm.h>
#include <X11/extensions/XShm.h> #include <X11/extensions/XShm.h>
#include "media/cast/cast_config.h" #include <string>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
namespace media {
class VideoFrame;
}
namespace media { namespace media {
namespace cast { namespace cast {
...@@ -26,7 +34,7 @@ class LinuxOutputWindow { ...@@ -26,7 +34,7 @@ class LinuxOutputWindow {
const std::string& name); const std::string& name);
virtual ~LinuxOutputWindow(); virtual ~LinuxOutputWindow();
void RenderFrame(const I420VideoFrame& video_frame); void RenderFrame(const scoped_refptr<media::VideoFrame>& video_frame);
private: private:
void CreateWindow(int x_pos, void CreateWindow(int x_pos,
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/time/default_tick_clock.h" #include "base/time/default_tick_clock.h"
#include "media/base/video_frame.h"
#include "media/cast/cast_config.h" #include "media/cast/cast_config.h"
#include "media/cast/cast_environment.h" #include "media/cast/cast_environment.h"
#include "media/cast/cast_receiver.h" #include "media/cast/cast_receiver.h"
...@@ -157,10 +158,10 @@ class ReceiveProcess : public base::RefCountedThreadSafe<ReceiveProcess> { ...@@ -157,10 +158,10 @@ class ReceiveProcess : public base::RefCountedThreadSafe<ReceiveProcess> {
private: private:
friend class base::RefCountedThreadSafe<ReceiveProcess>; friend class base::RefCountedThreadSafe<ReceiveProcess>;
void DisplayFrame(scoped_ptr<I420VideoFrame> frame, void DisplayFrame(const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& render_time) { const base::TimeTicks& render_time) {
#ifdef OS_LINUX #ifdef OS_LINUX
render_.RenderFrame(*frame); render_.RenderFrame(video_frame);
#endif // OS_LINUX #endif // OS_LINUX
// Print out the delta between frames. // Print out the delta between frames.
if (!last_render_time_.is_null()){ if (!last_render_time_.is_null()){
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "net/base/rand_callback.h" #include "net/base/rand_callback.h"
#include "net/base/test_completion_callback.h" #include "net/base/test_completion_callback.h"
...@@ -35,7 +35,7 @@ void CreateUDPAddress(std::string ip_str, int port, net::IPEndPoint* address) { ...@@ -35,7 +35,7 @@ void CreateUDPAddress(std::string ip_str, int port, net::IPEndPoint* address) {
class LocalUdpTransportData class LocalUdpTransportData
: public base::RefCountedThreadSafe<LocalUdpTransportData> { : public base::RefCountedThreadSafe<LocalUdpTransportData> {
public: public:
LocalUdpTransportData(net::DatagramServerSocket* udp_socket, LocalUdpTransportData(net::UDPServerSocket* udp_socket,
scoped_refptr<base::TaskRunner> io_thread_proxy) scoped_refptr<base::TaskRunner> io_thread_proxy)
: udp_socket_(udp_socket), : udp_socket_(udp_socket),
buffer_(new net::IOBufferWithSize(kMaxPacketSize)), buffer_(new net::IOBufferWithSize(kMaxPacketSize)),
...@@ -93,7 +93,7 @@ class LocalUdpTransportData ...@@ -93,7 +93,7 @@ class LocalUdpTransportData
private: private:
friend class base::RefCountedThreadSafe<LocalUdpTransportData>; friend class base::RefCountedThreadSafe<LocalUdpTransportData>;
net::DatagramServerSocket* udp_socket_; net::UDPServerSocket* udp_socket_;
net::IPEndPoint bind_address_; net::IPEndPoint bind_address_;
PacketReceiver* packet_receiver_; PacketReceiver* packet_receiver_;
scoped_refptr<net::IOBufferWithSize> buffer_; scoped_refptr<net::IOBufferWithSize> buffer_;
...@@ -105,7 +105,7 @@ class LocalUdpTransportData ...@@ -105,7 +105,7 @@ class LocalUdpTransportData
class LocalPacketSender : public PacketSender, class LocalPacketSender : public PacketSender,
public base::RefCountedThreadSafe<LocalPacketSender> { public base::RefCountedThreadSafe<LocalPacketSender> {
public: public:
LocalPacketSender(net::DatagramServerSocket* udp_socket, LocalPacketSender(net::UDPServerSocket* udp_socket,
scoped_refptr<base::TaskRunner> io_thread_proxy) scoped_refptr<base::TaskRunner> io_thread_proxy)
: udp_socket_(udp_socket), : udp_socket_(udp_socket),
send_address_(), send_address_(),
...@@ -162,7 +162,7 @@ class LocalPacketSender : public PacketSender, ...@@ -162,7 +162,7 @@ class LocalPacketSender : public PacketSender,
private: private:
friend class base::RefCountedThreadSafe<LocalPacketSender>; friend class base::RefCountedThreadSafe<LocalPacketSender>;
net::DatagramServerSocket* udp_socket_; // Not owned by this class. net::UDPServerSocket* udp_socket_; // Not owned by this class.
net::IPEndPoint send_address_; net::IPEndPoint send_address_;
int loss_limit_; int loss_limit_;
scoped_refptr<base::TaskRunner> io_thread_proxy_; scoped_refptr<base::TaskRunner> io_thread_proxy_;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "media/cast/cast_config.h" #include "media/cast/cast_config.h"
#include "media/cast/cast_environment.h" #include "media/cast/cast_environment.h"
#include "net/udp/udp_server_socket.h" #include "net/udp/udp_server_socket.h"
#include "net/udp/udp_socket.h"
namespace media { namespace media {
...@@ -42,7 +41,7 @@ class Transport { ...@@ -42,7 +41,7 @@ class Transport {
void StopReceiving(); void StopReceiving();
private: private:
scoped_ptr<net::DatagramServerSocket> udp_socket_; scoped_ptr<net::UDPServerSocket> udp_socket_;
scoped_refptr<LocalPacketSender> packet_sender_; scoped_refptr<LocalPacketSender> packet_sender_;
scoped_refptr<LocalUdpTransportData> local_udp_transport_data_; scoped_refptr<LocalUdpTransportData> local_udp_transport_data_;
scoped_refptr<base::TaskRunner> io_thread_proxy_; scoped_refptr<base::TaskRunner> io_thread_proxy_;
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include <math.h> #include <math.h>
#include <cstdio> #include <cstdio>
#include "media/base/video_frame.h"
#include "media/cast/test/video_utility.h" #include "media/cast/test/video_utility.h"
#include "third_party/libyuv/include/libyuv/compare.h" #include "third_party/libyuv/include/libyuv/compare.h"
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
...@@ -13,30 +12,19 @@ ...@@ -13,30 +12,19 @@
namespace media { namespace media {
namespace cast { namespace cast {
double I420PSNR(const I420VideoFrame& frame1, const I420VideoFrame& frame2) { double I420PSNR(const scoped_refptr<media::VideoFrame>& frame1,
// Frames should have equal resolution. const scoped_refptr<media::VideoFrame>& frame2) {
if (frame1.width != frame2.width || frame1.height != frame2.height) return -1; if (frame1->coded_size().width() != frame2->coded_size().width() ||
return libyuv::I420Psnr(frame1.y_plane.data, frame1.y_plane.stride, frame1->coded_size().height() != frame2->coded_size().height()) return -1;
frame1.u_plane.data, frame1.u_plane.stride,
frame1.v_plane.data, frame1.v_plane.stride,
frame2.y_plane.data, frame2.y_plane.stride,
frame2.u_plane.data, frame2.u_plane.stride,
frame2.v_plane.data, frame2.v_plane.stride,
frame1.width, frame1.height);
}
double I420PSNR(const VideoFrame& frame1, const I420VideoFrame& frame2) {
if (frame1.coded_size().width() != frame2.width ||
frame1.coded_size().height() != frame2.height) return -1;
return libyuv::I420Psnr( return libyuv::I420Psnr(
frame1.data(VideoFrame::kYPlane), frame1.stride(VideoFrame::kYPlane), frame1->data(VideoFrame::kYPlane), frame1->stride(VideoFrame::kYPlane),
frame1.data(VideoFrame::kUPlane), frame1.stride(VideoFrame::kUPlane), frame1->data(VideoFrame::kUPlane), frame1->stride(VideoFrame::kUPlane),
frame1.data(VideoFrame::kVPlane), frame1.stride(VideoFrame::kVPlane), frame1->data(VideoFrame::kVPlane), frame1->stride(VideoFrame::kVPlane),
frame2.y_plane.data, frame2.y_plane.stride, frame2->data(VideoFrame::kYPlane), frame2->stride(VideoFrame::kYPlane),
frame2.u_plane.data, frame2.u_plane.stride, frame2->data(VideoFrame::kUPlane), frame2->stride(VideoFrame::kUPlane),
frame2.v_plane.data, frame2.v_plane.stride, frame2->data(VideoFrame::kVPlane), frame2->stride(VideoFrame::kVPlane),
frame2.width, frame2.height); frame1->coded_size().width(), frame1->coded_size().height());
} }
void PopulateVideoFrame(VideoFrame* frame, int start_value) { void PopulateVideoFrame(VideoFrame* frame, int start_value) {
...@@ -64,37 +52,6 @@ void PopulateVideoFrame(VideoFrame* frame, int start_value) { ...@@ -64,37 +52,6 @@ void PopulateVideoFrame(VideoFrame* frame, int start_value) {
} }
} }
void PopulateVideoFrame(I420VideoFrame* frame, int start_value) {
int half_width = (frame->width + 1) / 2;
int half_height = (frame->height + 1) / 2;
frame->y_plane.stride = frame->width;
frame->y_plane.length = frame->width * frame->height;
frame->y_plane.data = new uint8[frame->y_plane.length];
frame->u_plane.stride = half_width;
frame->u_plane.length = half_width * half_height;
frame->u_plane.data = new uint8[frame->u_plane.length];
frame->v_plane.stride = half_width;
frame->v_plane.length = half_width * half_height;
frame->v_plane.data = new uint8[frame->v_plane.length];
// Set Y.
for (int i = 0; i < frame->y_plane.length; ++i) {
frame->y_plane.data[i] = static_cast<uint8>(start_value + i);
}
// Set U.
for (int i = 0; i < frame->u_plane.length; ++i) {
frame->u_plane.data[i] = static_cast<uint8>(start_value + i);
}
// Set V.
for (int i = 0; i < frame->v_plane.length; ++i) {
frame->v_plane.data[i] = static_cast<uint8>(start_value + i);
}
}
bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) { bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) {
int width = frame->coded_size().width(); int width = frame->coded_size().width();
int height = frame->coded_size().height(); int height = frame->coded_size().height();
......
...@@ -5,23 +5,18 @@ ...@@ -5,23 +5,18 @@
// Utility functions for video testing. // Utility functions for video testing.
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "media/cast/cast_config.h"
namespace media { namespace media {
namespace cast { namespace cast {
// Compute and return PSNR between two frames. // Compute and return PSNR between two frames.
double I420PSNR(const I420VideoFrame& frame1, const I420VideoFrame& frame2); double I420PSNR(const scoped_refptr<media::VideoFrame>& frame1,
const scoped_refptr<media::VideoFrame>& frame2);
// Temporary function to handle the transition
// from I420VideoFrame->media::VideoFrame.
double I420PSNR(const VideoFrame& frame1, const I420VideoFrame& frame2);
// Populate a video frame with values starting with the given start value. // Populate a video frame with values starting with the given start value.
// Width, height and stride should be set in advance. // Width, height and stride should be set in advance.
// Memory is allocated within the function. // Memory is allocated within the function.
void PopulateVideoFrame(VideoFrame* frame, int start_value); void PopulateVideoFrame(VideoFrame* frame, int start_value);
void PopulateVideoFrame(I420VideoFrame* frame, int start_value);
// Populate a video frame from a file. // Populate a video frame from a file.
// Returns true if frame was populated, false if not (EOF). // Returns true if frame was populated, false if not (EOF).
......
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
#include "third_party/libvpx/source/libvpx/vpx/vp8dx.h" #include "third_party/libvpx/source/libvpx/vpx/vp8dx.h"
#include "ui/gfx/size.h"
namespace media { namespace media {
namespace cast { namespace cast {
...@@ -68,31 +71,23 @@ bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame, ...@@ -68,31 +71,23 @@ bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame,
return false; 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);
// The img is only valid until the next call to vpx_codec_decode. DCHECK(VideoFrame::IsValidConfig(VideoFrame::I420, visible_size,
// Populate the decoded image. gfx::Rect(visible_size), full_size));
decoded_frame->width = img->d_w; // Temp timing setting - will sort out timing in a follow up cl.
decoded_frame->height = img->d_h; scoped_refptr<VideoFrame> decoded_frame =
VideoFrame::CreateFrame(VideoFrame::I420, visible_size,
decoded_frame->y_plane.stride = img->stride[VPX_PLANE_Y]; gfx::Rect(visible_size), full_size, base::TimeDelta());
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]; // Copy each plane individually (need to account for stride).
memcpy(decoded_frame->y_plane.data, img->planes[VPX_PLANE_Y], // TODO(mikhal): Eliminate copy once http://crbug.com/321856 is resolved.
decoded_frame->y_plane.length); CopyPlane(VideoFrame::kYPlane, img->planes[VPX_PLANE_Y],
img->stride[VPX_PLANE_Y], img->d_h, decoded_frame.get());
decoded_frame->u_plane.stride = img->stride[VPX_PLANE_U]; CopyPlane(VideoFrame::kUPlane, img->planes[VPX_PLANE_U],
decoded_frame->u_plane.length = img->stride[VPX_PLANE_U] * (img->d_h + 1) / 2; img->stride[VPX_PLANE_U], (img->d_h + 1) / 2, decoded_frame.get());
decoded_frame->u_plane.data = new uint8[decoded_frame->u_plane.length]; CopyPlane(VideoFrame::kVPlane, img->planes[VPX_PLANE_V],
memcpy(decoded_frame->u_plane.data, img->planes[VPX_PLANE_U], img->stride[VPX_PLANE_V], (img->d_h + 1) / 2, decoded_frame.get());
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);
// Log:: Decoding complete (should be called from the main thread). // Log:: Decoding complete (should be called from the main thread).
cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, base::Bind( cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, base::Bind(
...@@ -101,8 +96,7 @@ bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame, ...@@ -101,8 +96,7 @@ bool Vp8Decoder::Decode(const EncodedVideoFrame* encoded_frame,
VLOG(1) << "Decoded frame " << frame_id_int; VLOG(1) << "Decoded frame " << frame_id_int;
// Frame decoded - return frame to the user via callback. // Frame decoded - return frame to the user via callback.
cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE,
base::Bind(frame_decoded_cb, base::Passed(&decoded_frame), base::Bind(frame_decoded_cb, decoded_frame, render_time));
render_time));
return true; return true;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
typedef struct vpx_codec_ctx vpx_dec_ctx_t; typedef struct vpx_codec_ctx vpx_dec_ctx_t;
// TODO(mikhal): Look into reusing VpxVideoDecoder.
namespace media { namespace media {
namespace cast { namespace cast {
......
...@@ -14,6 +14,7 @@ namespace media { ...@@ -14,6 +14,7 @@ namespace media {
namespace cast { namespace cast {
class Vp8Decoder; class Vp8Decoder;
class VideoFrame;
// This class is not thread safe; it's only called from the cast video decoder // This class is not thread safe; it's only called from the cast video decoder
// thread. // thread.
......
...@@ -29,7 +29,7 @@ class DecodeTestFrameCallback : ...@@ -29,7 +29,7 @@ class DecodeTestFrameCallback :
public: public:
DecodeTestFrameCallback() {} DecodeTestFrameCallback() {}
void DecodeComplete(scoped_ptr<I420VideoFrame> decoded_frame, void DecodeComplete(const scoped_refptr<media::VideoFrame>& decoded_frame,
const base::TimeTicks& render_time) {} const base::TimeTicks& render_time) {}
protected: protected:
virtual ~DecodeTestFrameCallback() {} virtual ~DecodeTestFrameCallback() {}
......
...@@ -30,8 +30,8 @@ class TestVideoReceiverCallback : ...@@ -30,8 +30,8 @@ class TestVideoReceiverCallback :
: num_called_(0) {} : num_called_(0) {}
// TODO(mikhal): Set and check expectations. // TODO(mikhal): Set and check expectations.
void DecodeComplete(scoped_ptr<I420VideoFrame> video_frame, void DecodeComplete(const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& render_time) { const base::TimeTicks& render_time) {
++num_called_; ++num_called_;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment