summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormikhal@google.com <mikhal@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 02:36:21 +0000
committermikhal@google.com <mikhal@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 02:36:21 +0000
commit6bfe8216bf3258382f19da1a9dd220a9851914e0 (patch)
treeb3c86979be71f8e454af49583448495140c72863
parent93ae0ab84c62e89918d58edfc538d14e8cdc78f2 (diff)
downloadchromium_src-6bfe8216bf3258382f19da1a9dd220a9851914e0.zip
chromium_src-6bfe8216bf3258382f19da1a9dd220a9851914e0.tar.gz
chromium_src-6bfe8216bf3258382f19da1a9dd220a9851914e0.tar.bz2
Switching cast sender to media::VideoFrame
Aligning cast with the media library by using the media::VideoFrame in lieu of a cast specific class. Should reduce a potential memcpy. Follow up cl's include: 1. Switching cast receiver to use VideoFrame. 2. Using the timedelta in VideoFRame instead of an additional variable. Review URL: https://codereview.chromium.org/62703003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236375 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/cast/DEPS1
-rw-r--r--media/cast/cast.gyp2
-rw-r--r--media/cast/cast_sender.h10
-rw-r--r--media/cast/cast_sender_impl.cc16
-rw-r--r--media/cast/cast_sender_impl.h4
-rw-r--r--media/cast/test/encode_decode_test.cc35
-rw-r--r--media/cast/test/end2end_unittest.cc48
-rw-r--r--media/cast/test/sender.cc20
-rw-r--r--media/cast/test/utility/utility.gyp1
-rw-r--r--media/cast/test/video_utility.cc75
-rw-r--r--media/cast/test/video_utility.h8
-rw-r--r--media/cast/video_sender/codecs/vp8/vp8_encoder.cc20
-rw-r--r--media/cast/video_sender/codecs/vp8/vp8_encoder.gypi1
-rw-r--r--media/cast/video_sender/codecs/vp8/vp8_encoder.h6
-rw-r--r--media/cast/video_sender/video_encoder.cc7
-rw-r--r--media/cast/video_sender/video_encoder.h8
-rw-r--r--media/cast/video_sender/video_encoder_unittest.cc83
-rw-r--r--media/cast/video_sender/video_sender.cc4
-rw-r--r--media/cast/video_sender/video_sender.gypi2
-rw-r--r--media/cast/video_sender/video_sender.h8
-rw-r--r--media/cast/video_sender/video_sender_unittest.cc66
21 files changed, 227 insertions, 198 deletions
diff --git a/media/cast/DEPS b/media/cast/DEPS
index 0a3ec8c..b2a2d05 100644
--- a/media/cast/DEPS
+++ b/media/cast/DEPS
@@ -3,4 +3,5 @@ include_rules = [
"+net",
"+third_party/webrtc",
"+third_party/libyuv",
+ "+ui/gfx",
]
diff --git a/media/cast/cast.gyp b/media/cast/cast.gyp
index 520d830..a278ada 100644
--- a/media/cast/cast.gyp
+++ b/media/cast/cast.gyp
@@ -107,6 +107,7 @@
'<(DEPTH)/',
],
'dependencies': [
+ '<(DEPTH)/ui/gfx/gfx.gyp:gfx',
'<(DEPTH)/net/net.gyp:net_test_support',
'cast_config',
'<(DEPTH)/media/cast/cast_sender.gyp:*',
@@ -126,6 +127,7 @@
'<(DEPTH)/',
],
'dependencies': [
+ '<(DEPTH)/ui/gfx/gfx.gyp:gfx',
'<(DEPTH)/net/net.gyp:net_test_support',
'cast_config',
'<(DEPTH)/media/cast/cast_receiver.gyp:*',
diff --git a/media/cast/cast_sender.h b/media/cast/cast_sender.h
index ef73e24..ff9e756 100644
--- a/media/cast/cast_sender.h
+++ b/media/cast/cast_sender.h
@@ -21,6 +21,7 @@
namespace media {
class AudioBus;
+class VideoFrame;
}
namespace media {
@@ -33,9 +34,10 @@ class FrameInput : public base::RefCountedThreadSafe<FrameInput> {
// The callback is called from the main cast thread as soon as
// the encoder is done with the frame; it does not mean that the encoded frame
// has been sent out.
- virtual void InsertRawVideoFrame(const I420VideoFrame* video_frame,
- const base::TimeTicks& capture_time,
- const base::Closure callback) = 0;
+ virtual void InsertRawVideoFrame(
+ const scoped_refptr<media::VideoFrame>& video_frame,
+ const base::TimeTicks& capture_time,
+ const base::Closure& callback) = 0;
// The video_frame must be valid until the callback is called.
// The callback is called from the main cast thread as soon as
@@ -61,8 +63,6 @@ class FrameInput : public base::RefCountedThreadSafe<FrameInput> {
const base::TimeTicks& recorded_time,
const base::Closure callback) = 0;
- static void DeleteVideoFrame(const I420VideoFrame* video_frame);
-
protected:
virtual ~FrameInput() {}
diff --git a/media/cast/cast_sender_impl.cc b/media/cast/cast_sender_impl.cc
index d1a83d3..db24b5d 100644
--- a/media/cast/cast_sender_impl.cc
+++ b/media/cast/cast_sender_impl.cc
@@ -7,18 +7,11 @@
#include "base/callback.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
+#include "media/base/video_frame.h"
namespace media {
namespace cast {
-// static
-void FrameInput::DeleteVideoFrame(const I420VideoFrame* video_frame) {
- delete [] video_frame->y_plane.data;
- delete [] video_frame->u_plane.data;
- delete [] video_frame->v_plane.data;
- delete video_frame;
-}
-
// The LocalFrameInput class posts all incoming frames; audio and video to the
// main cast thread for processing.
// This make the cast sender interface thread safe.
@@ -31,9 +24,10 @@ class LocalFrameInput : public FrameInput {
audio_sender_(audio_sender),
video_sender_(video_sender) {}
- virtual void InsertRawVideoFrame(const I420VideoFrame* video_frame,
- const base::TimeTicks& capture_time,
- const base::Closure callback) OVERRIDE {
+ virtual void InsertRawVideoFrame(
+ const scoped_refptr<media::VideoFrame>& video_frame,
+ const base::TimeTicks& capture_time,
+ const base::Closure& callback) OVERRIDE {
cast_environment_->Logging()->InsertFrameEvent(kVideoFrameReceived,
GetVideoRtpTimestamp(capture_time), kFrameIdUnknown);
diff --git a/media/cast/cast_sender_impl.h b/media/cast/cast_sender_impl.h
index 361322e..f160f74 100644
--- a/media/cast/cast_sender_impl.h
+++ b/media/cast/cast_sender_impl.h
@@ -14,6 +14,10 @@
#include "media/cast/video_sender/video_sender.h"
namespace media {
+ class VideoFrame;
+}
+
+namespace media {
namespace cast {
class AudioSender;
diff --git a/media/cast/test/encode_decode_test.cc b/media/cast/test/encode_decode_test.cc
index 0cf8929..c63357e 100644
--- a/media/cast/test/encode_decode_test.cc
+++ b/media/cast/test/encode_decode_test.cc
@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
+#include "media/base/video_frame.h"
#include "media/cast/cast_environment.h"
#include "media/cast/test/fake_task_runner.h"
#include "media/cast/test/video_utility.h"
@@ -33,23 +34,23 @@ class EncodeDecodeTestFrameCallback :
public:
EncodeDecodeTestFrameCallback()
: num_called_(0) {
- original_frame_.width = kWidth;
- original_frame_.height = kHeight;
+ gfx::Size size(kWidth, kHeight);
+ original_frame_ = media::VideoFrame::CreateFrame(
+ VideoFrame::I420, size, gfx::Rect(size), size, base::TimeDelta());
}
void SetFrameStartValue(int start_value) {
- PopulateVideoFrame(&original_frame_, start_value);
+ PopulateVideoFrame(original_frame_.get(), start_value);
}
void DecodeComplete(scoped_ptr<I420VideoFrame> decoded_frame,
const base::TimeTicks& render_time) {
++num_called_;
- // Compare frames.
// Compare resolution.
- EXPECT_EQ(original_frame_.width, decoded_frame->width);
- EXPECT_EQ(original_frame_.height, decoded_frame->height);
+ EXPECT_EQ(original_frame_->coded_size().width(), decoded_frame->width);
+ EXPECT_EQ(original_frame_->coded_size().height(), decoded_frame->height);
// Compare data.
- EXPECT_GT(I420PSNR(original_frame_, *(decoded_frame.get())), 40.0);
+ EXPECT_GT(I420PSNR(*(original_frame_.get()), *(decoded_frame.get())), 40.0);
}
int num_called() const {
@@ -63,7 +64,7 @@ class EncodeDecodeTestFrameCallback :
friend class base::RefCountedThreadSafe<EncodeDecodeTestFrameCallback>;
int num_called_;
- I420VideoFrame original_frame_;
+ scoped_refptr<media::VideoFrame> original_frame_;
};
} // namespace
@@ -97,23 +98,17 @@ class EncodeDecodeTest : public ::testing::Test {
virtual void SetUp() OVERRIDE {
// Create test frame.
int start_value = 10; // Random value to start from.
- video_frame_.reset(new I420VideoFrame());
- video_frame_->width = encoder_config_.width;
- video_frame_->height = encoder_config_.height;
- PopulateVideoFrame(video_frame_.get(), start_value);
+ gfx::Size size(encoder_config_.width, encoder_config_.height);
+ video_frame_ = media::VideoFrame::CreateFrame(VideoFrame::I420,
+ size, gfx::Rect(size), size, base::TimeDelta());
+ PopulateVideoFrame(video_frame_, start_value);
test_callback_->SetFrameStartValue(start_value);
}
- virtual void TearDown() OVERRIDE {
- delete [] video_frame_->y_plane.data;
- delete [] video_frame_->u_plane.data;
- delete [] video_frame_->v_plane.data;
- }
-
VideoSenderConfig encoder_config_;
scoped_ptr<Vp8Encoder> encoder_;
scoped_ptr<Vp8Decoder> decoder_;
- scoped_ptr<I420VideoFrame> video_frame_;
+ scoped_refptr<media::VideoFrame> video_frame_;
base::SimpleTestTickClock testing_clock_;
scoped_refptr<test::FakeTaskRunner> task_runner_;
scoped_refptr<CastEnvironment> cast_environment_;
@@ -123,7 +118,7 @@ class EncodeDecodeTest : public ::testing::Test {
TEST_F(EncodeDecodeTest, BasicEncodeDecode) {
EncodedVideoFrame encoded_frame;
// Encode frame.
- encoder_->Encode(*(video_frame_.get()), &encoded_frame);
+ encoder_->Encode(video_frame_, &encoded_frame);
EXPECT_GT(encoded_frame.data.size(), GG_UINT64_C(0));
// Decode frame.
decoder_->Decode(&encoded_frame, base::TimeTicks(), base::Bind(
diff --git a/media/cast/test/end2end_unittest.cc b/media/cast/test/end2end_unittest.cc
index 584f249..c461f82 100644
--- a/media/cast/test/end2end_unittest.cc
+++ b/media/cast/test/end2end_unittest.cc
@@ -17,6 +17,7 @@
#include "base/bind_helpers.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/tick_clock.h"
+#include "media/base/video_frame.h"
#include "media/cast/cast_config.h"
#include "media/cast/cast_environment.h"
#include "media/cast/cast_receiver.h"
@@ -53,13 +54,6 @@ static const int kFrameTimerMs = 33;
// retransmitted.
static const int kTimerErrorMs = 11;
-namespace {
-// Dummy callback function that does nothing except to accept ownership of
-// |audio_bus| for destruction.
-void OwnThatAudioBus(scoped_ptr<AudioBus> audio_bus) {
-}
-}
-
// Class that sends the packet direct from sender into the receiver with the
// ability to drop packets between the two.
class LoopBackTransport : public PacketSender {
@@ -299,15 +293,14 @@ class TestReceiverVideoCallback :
EXPECT_EQ(expected_video_frame.width, video_frame->width);
EXPECT_EQ(expected_video_frame.height, video_frame->height);
- I420VideoFrame* expected_I420_frame = new I420VideoFrame();
- expected_I420_frame->width = expected_video_frame.width;
- expected_I420_frame->height = expected_video_frame.height;
+ gfx::Size size(expected_video_frame.width, expected_video_frame.height);
+ scoped_refptr<media::VideoFrame> expected_I420_frame =
+ media::VideoFrame::CreateFrame(
+ VideoFrame::I420, size, gfx::Rect(size), size, base::TimeDelta());
PopulateVideoFrame(expected_I420_frame, expected_video_frame.start_value);
- double psnr = I420PSNR(*expected_I420_frame, *(video_frame.get()));
+ double psnr = I420PSNR(*(expected_I420_frame.get()), *(video_frame.get()));
EXPECT_GE(psnr, kVideoAcceptedPSNR);
-
- FrameInput::DeleteVideoFrame(expected_I420_frame);
}
int number_times_called() { return num_called_;}
@@ -331,6 +324,7 @@ class End2EndTest : public ::testing::Test {
cast_environment_(new CastEnvironment(&testing_clock_, task_runner_,
task_runner_, task_runner_, task_runner_, task_runner_,
GetDefaultCastLoggingConfig())),
+ start_time_(),
sender_to_receiver_(cast_environment_),
receiver_to_sender_(cast_environment_),
test_receiver_audio_callback_(new TestReceiverAudioCallback()),
@@ -419,12 +413,19 @@ class End2EndTest : public ::testing::Test {
virtual ~End2EndTest() {}
void SendVideoFrame(int start_value, const base::TimeTicks& capture_time) {
- I420VideoFrame* video_frame = new I420VideoFrame();
- video_frame->width = video_sender_config_.width;
- video_frame->height = video_sender_config_.height;
+ if (start_time_.is_null())
+ start_time_ = testing_clock_.NowTicks();
+ start_time_ = testing_clock_.NowTicks();
+ base::TimeDelta time_diff = testing_clock_.NowTicks() - start_time_;
+ gfx::Size size(kVideoWidth, kVideoHeight);
+ EXPECT_TRUE(VideoFrame::IsValidConfig(VideoFrame::I420,
+ size, gfx::Rect(size), size));
+ scoped_refptr<media::VideoFrame> video_frame =
+ media::VideoFrame::CreateFrame(
+ VideoFrame::I420, size, gfx::Rect(size), size, time_diff);
PopulateVideoFrame(video_frame, start_value);
frame_input_->InsertRawVideoFrame(video_frame, capture_time,
- base::Bind(FrameInput::DeleteVideoFrame, video_frame));
+ base::Bind(base::DoNothing));
}
void RunTasks(int during_ms) {
@@ -443,6 +444,7 @@ class End2EndTest : public ::testing::Test {
base::SimpleTestTickClock testing_clock_;
scoped_refptr<test::FakeTaskRunner> task_runner_;
scoped_refptr<CastEnvironment> cast_environment_;
+ base::TimeTicks start_time_;
LoopBackTransport sender_to_receiver_;
LoopBackTransport receiver_to_sender_;
@@ -490,7 +492,7 @@ TEST_F(End2EndTest, LoopNoLossPcm16) {
AudioBus* const audio_bus_ptr = audio_bus.get();
frame_input_->InsertAudio(audio_bus_ptr, send_time,
- base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus)));
+ base::Bind(base::DoNothing));
SendVideoFrame(video_start, send_time);
@@ -540,7 +542,7 @@ TEST_F(End2EndTest, LoopNoLossPcm16ExternalDecoder) {
AudioBus* const audio_bus_ptr = audio_bus.get();
frame_input_->InsertAudio(audio_bus_ptr, send_time,
- base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus)));
+ base::Bind(base::DoNothing));
RunTasks(10);
frame_receiver_->GetCodedAudioFrame(
@@ -572,7 +574,7 @@ TEST_F(End2EndTest, LoopNoLossOpus) {
AudioBus* const audio_bus_ptr = audio_bus.get();
frame_input_->InsertAudio(audio_bus_ptr, send_time,
- base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus)));
+ base::Bind(base::DoNothing));
RunTasks(30);
@@ -615,7 +617,7 @@ TEST_F(End2EndTest, DISABLED_StartSenderBeforeReceiver) {
AudioBus* const audio_bus_ptr = audio_bus.get();
frame_input_->InsertAudio(audio_bus_ptr, send_time,
- base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus)));
+ base::Bind(base::DoNothing));
SendVideoFrame(video_start, send_time);
RunTasks(kFrameTimerMs);
@@ -643,7 +645,7 @@ TEST_F(End2EndTest, DISABLED_StartSenderBeforeReceiver) {
AudioBus* const audio_bus_ptr = audio_bus.get();
frame_input_->InsertAudio(audio_bus_ptr, send_time,
- base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus)));
+ base::Bind(base::DoNothing));
test_receiver_video_callback_->AddExpectedResult(video_start,
video_sender_config_.width, video_sender_config_.height, send_time);
@@ -852,7 +854,7 @@ TEST_F(End2EndTest, CryptoAudio) {
}
AudioBus* const audio_bus_ptr = audio_bus.get();
frame_input_->InsertAudio(audio_bus_ptr, send_time,
- base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus)));
+ base::Bind(base::DoNothing));
RunTasks(num_10ms_blocks * 10);
diff --git a/media/cast/test/sender.cc b/media/cast/test/sender.cc
index 90395d4..bce99e3 100644
--- a/media/cast/test/sender.cc
+++ b/media/cast/test/sender.cc
@@ -13,6 +13,7 @@
#include "base/run_loop.h"
#include "base/task_runner.h"
#include "base/time/default_tick_clock.h"
+#include "media/base/video_frame.h"
#include "media/cast/cast_config.h"
#include "media/cast/cast_environment.h"
#include "media/cast/cast_sender.h"
@@ -21,6 +22,7 @@
#include "media/cast/test/transport/transport.h"
#include "media/cast/test/utility/input_helper.h"
#include "media/cast/test/video_utility.h"
+#include "ui/gfx/size.h"
#define DEFAULT_SEND_PORT "2344"
#define DEFAULT_RECEIVE_PORT "2346"
@@ -202,6 +204,7 @@ class SendProcess {
frame_input_(frame_input),
synthetic_count_(0),
clock_(cast_environment->Clock()),
+ start_time_(),
weak_factory_(this) {
audio_bus_factory_.reset(new TestAudioBusFactory(kAudioChannels,
kAudioSamplingFrequency, kSoundFrequency, kSoundVolume));
@@ -222,10 +225,7 @@ class SendProcess {
fclose(video_file_);
}
- void ReleaseVideoFrame(const I420VideoFrame* frame) {
- delete [] frame->y_plane.data;
- delete [] frame->u_plane.data;
- delete [] frame->v_plane.data;
+ void ReleaseVideoFrame(const scoped_refptr<media::VideoFrame>&) {
SendFrame();
}
@@ -245,9 +245,14 @@ class SendProcess {
frame_input_->InsertAudio(audio_bus_ptr, clock_->NowTicks(),
base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus)));
- I420VideoFrame* video_frame = new I420VideoFrame();
- video_frame->width = video_config_.width;
- video_frame->height = video_config_.height;
+ gfx::Size size(video_config_.width, video_config_.height);
+ // TODO(mikhal): Use the provided timestamp.
+ if (start_time_.is_null())
+ start_time_ = clock_->NowTicks();
+ base::TimeDelta time_diff = clock_->NowTicks() - start_time_;
+ scoped_refptr<media::VideoFrame> video_frame =
+ media::VideoFrame::CreateFrame(
+ VideoFrame::I420, size, gfx::Rect(size), size, time_diff);
if (video_file_) {
if (!PopulateVideoFrameFromFile(video_frame, video_file_))
return;
@@ -269,6 +274,7 @@ class SendProcess {
FILE* video_file_;
uint8 synthetic_count_;
base::TickClock* const clock_; // Not owned by this class.
+ base::TimeTicks start_time_;
scoped_ptr<TestAudioBusFactory> audio_bus_factory_;
base::WeakPtrFactory<SendProcess> weak_factory_;
};
diff --git a/media/cast/test/utility/utility.gyp b/media/cast/test/utility/utility.gyp
index 0c635c4..021c2d9 100644
--- a/media/cast/test/utility/utility.gyp
+++ b/media/cast/test/utility/utility.gyp
@@ -11,6 +11,7 @@
'<(DEPTH)/',
],
'dependencies': [
+ '<(DEPTH)/ui/gfx/gfx.gyp:gfx',
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv',
diff --git a/media/cast/test/video_utility.cc b/media/cast/test/video_utility.cc
index 32469e9..30f0019 100644
--- a/media/cast/test/video_utility.cc
+++ b/media/cast/test/video_utility.cc
@@ -5,8 +5,10 @@
#include <math.h>
#include <cstdio>
+#include "media/base/video_frame.h"
#include "media/cast/test/video_utility.h"
#include "third_party/libyuv/include/libyuv/compare.h"
+#include "ui/gfx/size.h"
namespace media {
namespace cast {
@@ -14,7 +16,6 @@ namespace cast {
double I420PSNR(const I420VideoFrame& frame1, const I420VideoFrame& frame2) {
// Frames should have equal resolution.
if (frame1.width != frame2.width || frame1.height != frame2.height) return -1;
-
return libyuv::I420Psnr(frame1.y_plane.data, frame1.y_plane.stride,
frame1.u_plane.data, frame1.u_plane.stride,
frame1.v_plane.data, frame1.v_plane.stride,
@@ -24,6 +25,45 @@ double I420PSNR(const I420VideoFrame& frame1, const I420VideoFrame& frame2) {
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(
+ frame1.data(VideoFrame::kYPlane), frame1.stride(VideoFrame::kYPlane),
+ frame1.data(VideoFrame::kUPlane), frame1.stride(VideoFrame::kUPlane),
+ frame1.data(VideoFrame::kVPlane), frame1.stride(VideoFrame::kVPlane),
+ frame2.y_plane.data, frame2.y_plane.stride,
+ frame2.u_plane.data, frame2.u_plane.stride,
+ frame2.v_plane.data, frame2.v_plane.stride,
+ frame2.width, frame2.height);
+}
+
+void PopulateVideoFrame(VideoFrame* frame, int start_value) {
+ int width = frame->coded_size().width();
+ int height = frame->coded_size().height();
+ int half_width = (width + 1) / 2;
+ int half_height = (height + 1) / 2;
+ uint8* y_plane = frame->data(VideoFrame::kYPlane);
+ uint8* u_plane = frame->data(VideoFrame::kUPlane);
+ uint8* v_plane = frame->data(VideoFrame::kVPlane);
+
+ // Set Y.
+ for (int i = 0; i < width * height; ++i) {
+ y_plane[i] = static_cast<uint8>(start_value + i);
+ }
+
+ // Set U.
+ for (int i = 0; i < half_width * half_height; ++i) {
+ u_plane[i] = static_cast<uint8>(start_value + i);
+ }
+
+ // Set V.
+ for (int i = 0; i < half_width * half_height; ++i) {
+ v_plane[i] = static_cast<uint8>(start_value + i);
+ }
+}
+
void PopulateVideoFrame(I420VideoFrame* frame, int start_value) {
int half_width = (frame->width + 1) / 2;
int half_height = (frame->height + 1) / 2;
@@ -55,32 +95,23 @@ void PopulateVideoFrame(I420VideoFrame* frame, int start_value) {
}
}
-bool PopulateVideoFrameFromFile(I420VideoFrame* frame, FILE* video_file) {
- int half_width = (frame->width + 1) / 2;
- int half_height = (frame->height + 1) / 2;
- size_t frame_size =
- frame->width * frame->height + 2 * half_width * half_height;
+bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) {
+ int width = frame->coded_size().width();
+ int height = frame->coded_size().height();
+ int half_width = (width + 1) / 2;
+ int half_height = (height + 1) / 2;
+ size_t frame_size = width * height + 2 * half_width * half_height;
+ uint8* y_plane = frame->data(VideoFrame::kYPlane);
+ uint8* u_plane = frame->data(VideoFrame::kUPlane);
+ uint8* v_plane = frame->data(VideoFrame::kVPlane);
uint8* raw_data = new uint8[frame_size];
size_t count = fread(raw_data, 1, frame_size, video_file);
if (count != frame_size) return false;
- 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];
-
- memcpy(frame->y_plane.data, raw_data, frame->width * frame->height);
- memcpy(frame->u_plane.data, raw_data + frame->width * frame->height,
- half_width * half_height);
- memcpy(frame->v_plane.data, raw_data + frame->width * frame->height +
+ memcpy(y_plane, raw_data, width * height);
+ memcpy(u_plane, raw_data + width * height, half_width * half_height);
+ memcpy(v_plane, raw_data + width * height +
half_width * half_height, half_width * half_height);
delete [] raw_data;
return true;
diff --git a/media/cast/test/video_utility.h b/media/cast/test/video_utility.h
index 33efa86..464dff2 100644
--- a/media/cast/test/video_utility.h
+++ b/media/cast/test/video_utility.h
@@ -4,6 +4,7 @@
// Utility functions for video testing.
+#include "media/base/video_frame.h"
#include "media/cast/cast_config.h"
namespace media {
@@ -12,14 +13,19 @@ namespace cast {
// Compute and return PSNR between two frames.
double I420PSNR(const I420VideoFrame& frame1, const I420VideoFrame& 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.
// Width, height and stride should be set in advance.
// Memory is allocated within the function.
+void PopulateVideoFrame(VideoFrame* frame, int start_value);
void PopulateVideoFrame(I420VideoFrame* frame, int start_value);
// Populate a video frame from a file.
// Returns true if frame was populated, false if not (EOF).
-bool PopulateVideoFrameFromFile(I420VideoFrame* frame, FILE* video_file);
+bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file);
} // namespace cast
} // namespace media
diff --git a/media/cast/video_sender/codecs/vp8/vp8_encoder.cc b/media/cast/video_sender/codecs/vp8/vp8_encoder.cc
index bea7507..5093d25 100644
--- a/media/cast/video_sender/codecs/vp8/vp8_encoder.cc
+++ b/media/cast/video_sender/codecs/vp8/vp8_encoder.cc
@@ -9,6 +9,7 @@
#include <vector>
#include "base/logging.h"
+#include "media/base/video_frame.h"
#include "media/cast/cast_defines.h"
#include "media/cast/rtp_common/rtp_defines.h"
#include "third_party/libvpx/source/libvpx/vpx/vp8cx.h"
@@ -121,17 +122,20 @@ void Vp8Encoder::InitEncode(int number_of_cores) {
rc_max_intra_target);
}
-bool Vp8Encoder::Encode(const I420VideoFrame& input_image,
+bool Vp8Encoder::Encode(const scoped_refptr<media::VideoFrame>& video_frame,
EncodedVideoFrame* encoded_image) {
// Image in vpx_image_t format.
// Input image is const. VP8's raw image is not defined as const.
- raw_image_->planes[PLANE_Y] = const_cast<uint8*>(input_image.y_plane.data);
- raw_image_->planes[PLANE_U] = const_cast<uint8*>(input_image.u_plane.data);
- raw_image_->planes[PLANE_V] = const_cast<uint8*>(input_image.v_plane.data);
-
- raw_image_->stride[VPX_PLANE_Y] = input_image.y_plane.stride;
- raw_image_->stride[VPX_PLANE_U] = input_image.u_plane.stride;
- raw_image_->stride[VPX_PLANE_V] = input_image.v_plane.stride;
+ raw_image_->planes[PLANE_Y] =
+ const_cast<uint8*>(video_frame->data(VideoFrame::kYPlane));
+ raw_image_->planes[PLANE_U] =
+ const_cast<uint8*>(video_frame->data(VideoFrame::kUPlane));
+ raw_image_->planes[PLANE_V] =
+ const_cast<uint8*>(video_frame->data(VideoFrame::kVPlane));
+
+ raw_image_->stride[VPX_PLANE_Y] = video_frame->stride(VideoFrame::kYPlane);
+ raw_image_->stride[VPX_PLANE_U] = video_frame->stride(VideoFrame::kUPlane);
+ raw_image_->stride[VPX_PLANE_V] = video_frame->stride(VideoFrame::kVPlane);
uint8 latest_frame_id_to_reference;
Vp8Buffers buffer_to_update;
diff --git a/media/cast/video_sender/codecs/vp8/vp8_encoder.gypi b/media/cast/video_sender/codecs/vp8/vp8_encoder.gypi
index 0b12789..fa9c2944 100644
--- a/media/cast/video_sender/codecs/vp8/vp8_encoder.gypi
+++ b/media/cast/video_sender/codecs/vp8/vp8_encoder.gypi
@@ -12,6 +12,7 @@
'vp8_encoder.h',
], # source
'dependencies': [
+ '<(DEPTH)/ui/gfx/gfx.gyp:gfx',
'<(DEPTH)/third_party/libvpx/libvpx.gyp:libvpx',
],
},
diff --git a/media/cast/video_sender/codecs/vp8/vp8_encoder.h b/media/cast/video_sender/codecs/vp8/vp8_encoder.h
index 709ca98..d09cc27 100644
--- a/media/cast/video_sender/codecs/vp8/vp8_encoder.h
+++ b/media/cast/video_sender/codecs/vp8/vp8_encoder.h
@@ -10,6 +10,10 @@
#include "media/cast/cast_config.h"
#include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h"
+namespace media {
+class VideoFrame;
+}
+
// VPX forward declaration.
typedef struct vpx_codec_ctx vpx_enc_ctx_t;
@@ -26,7 +30,7 @@ class Vp8Encoder {
~Vp8Encoder();
// Encode a raw image (as a part of a video stream).
- bool Encode(const I420VideoFrame& input_image,
+ bool Encode(const scoped_refptr<media::VideoFrame>& video_frame,
EncodedVideoFrame* encoded_image);
// Update the encoder with a new target bit rate.
diff --git a/media/cast/video_sender/video_encoder.cc b/media/cast/video_sender/video_encoder.cc
index adc08c1..b55f442 100644
--- a/media/cast/video_sender/video_encoder.cc
+++ b/media/cast/video_sender/video_encoder.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/logging.h"
+#include "media/base/video_frame.h"
namespace media {
namespace cast {
@@ -31,7 +32,7 @@ VideoEncoder::VideoEncoder(scoped_refptr<CastEnvironment> cast_environment,
VideoEncoder::~VideoEncoder() {}
bool VideoEncoder::EncodeVideoFrame(
- const I420VideoFrame* video_frame,
+ const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& capture_time,
const FrameEncodedCallback& frame_encoded_callback,
const base::Closure frame_release_callback) {
@@ -54,7 +55,7 @@ bool VideoEncoder::EncodeVideoFrame(
}
void VideoEncoder::EncodeVideoFrameEncoderThread(
- const I420VideoFrame* video_frame,
+ const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& capture_time,
const CodecDynamicConfig& dynamic_config,
const FrameEncodedCallback& frame_encoded_callback,
@@ -70,7 +71,7 @@ void VideoEncoder::EncodeVideoFrameEncoderThread(
cast_environment_->Logging()->InsertFrameEvent(kVideoFrameSentToEncoder,
rtp_timestamp, kFrameIdUnknown);
scoped_ptr<EncodedVideoFrame> encoded_frame(new EncodedVideoFrame());
- bool retval = vp8_encoder_->Encode(*video_frame, encoded_frame.get());
+ bool retval = vp8_encoder_->Encode(video_frame, encoded_frame.get());
// We are done with the video frame release it.
cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE,
diff --git a/media/cast/video_sender/video_encoder.h b/media/cast/video_sender/video_encoder.h
index ee4d4f5..c154736 100644
--- a/media/cast/video_sender/video_encoder.h
+++ b/media/cast/video_sender/video_encoder.h
@@ -13,6 +13,10 @@
#include "media/cast/video_sender/codecs/vp8/vp8_encoder.h"
namespace media {
+class VideoFrame;
+}
+
+namespace media {
namespace cast {
// This object is called external from the main cast thread and internally from
@@ -34,7 +38,7 @@ class VideoEncoder : public VideoEncoderController,
// the encoder is done with the frame; it does not mean that the encoded frame
// has been sent out.
// Once the encoded frame is ready the frame_encoded_callback is called.
- bool EncodeVideoFrame(const I420VideoFrame* video_frame,
+ bool EncodeVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& capture_time,
const FrameEncodedCallback& frame_encoded_callback,
const base::Closure frame_release_callback);
@@ -50,7 +54,7 @@ class VideoEncoder : public VideoEncoderController,
// The actual encode, called from the video encoder thread.
void EncodeVideoFrameEncoderThread(
- const I420VideoFrame* video_frame,
+ const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& capture_time,
const CodecDynamicConfig& dynamic_config,
const FrameEncodedCallback& frame_encoded_callback,
diff --git a/media/cast/video_sender/video_encoder_unittest.cc b/media/cast/video_sender/video_encoder_unittest.cc
index b492e70..62c5de9 100644
--- a/media/cast/video_sender/video_encoder_unittest.cc
+++ b/media/cast/video_sender/video_encoder_unittest.cc
@@ -7,9 +7,11 @@
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "media/base/video_frame.h"
#include "media/cast/cast_defines.h"
#include "media/cast/cast_environment.h"
#include "media/cast/test/fake_task_runner.h"
+#include "media/cast/test/video_utility.h"
#include "media/cast/video_sender/video_encoder.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -18,10 +20,6 @@ namespace cast {
using testing::_;
-static void ReleaseFrame(const I420VideoFrame* frame) {
- // Empty since we in this test send in the same frame.
-}
-
namespace {
class TestVideoEncoderCallback :
public base::RefCountedThreadSafe<TestVideoEncoderCallback> {
@@ -63,8 +61,7 @@ class TestVideoEncoderCallback :
class VideoEncoderTest : public ::testing::Test {
protected:
VideoEncoderTest()
- : pixels_(320 * 240, 123),
- test_video_encoder_callback_(new TestVideoEncoderCallback()) {
+ : test_video_encoder_callback_(new TestVideoEncoderCallback()) {
video_config_.sender_ssrc = 1;
video_config_.incoming_feedback_ssrc = 2;
video_config_.rtp_payload_type = 127;
@@ -79,17 +76,10 @@ class VideoEncoderTest : public ::testing::Test {
video_config_.max_frame_rate = 30;
video_config_.max_number_of_video_buffers_used = 3;
video_config_.codec = kVp8;
- video_frame_.width = 320;
- video_frame_.height = 240;
- video_frame_.y_plane.stride = video_frame_.width;
- video_frame_.y_plane.length = video_frame_.width;
- video_frame_.y_plane.data = &(pixels_[0]);
- video_frame_.u_plane.stride = video_frame_.width / 2;
- video_frame_.u_plane.length = video_frame_.width / 2;
- video_frame_.u_plane.data = &(pixels_[0]);
- video_frame_.v_plane.stride = video_frame_.width / 2;
- video_frame_.v_plane.length = video_frame_.width / 2;
- video_frame_.v_plane.data = &(pixels_[0]);
+ gfx::Size size(video_config_.width, video_config_.height);
+ video_frame_ = media::VideoFrame::CreateFrame(VideoFrame::I420,
+ size, gfx::Rect(size), size, base::TimeDelta());
+ PopulateVideoFrame(video_frame_, 123);
}
virtual ~VideoEncoderTest() {}
@@ -108,13 +98,12 @@ class VideoEncoderTest : public ::testing::Test {
}
base::SimpleTestTickClock testing_clock_;
- std::vector<uint8> pixels_;
scoped_refptr<TestVideoEncoderCallback> test_video_encoder_callback_;
VideoSenderConfig video_config_;
scoped_refptr<test::FakeTaskRunner> task_runner_;
scoped_refptr<VideoEncoder> video_encoder_;
VideoEncoderController* video_encoder_controller_;
- I420VideoFrame video_frame_;
+ scoped_refptr<media::VideoFrame> video_frame_;
scoped_refptr<CastEnvironment> cast_environment_;
};
@@ -129,22 +118,22 @@ TEST_F(VideoEncoderTest, EncodePattern30fpsRunningOutOfAck) {
base::TimeTicks capture_time;
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(true, 0, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
capture_time += base::TimeDelta::FromMilliseconds(33);
video_encoder_controller_->LatestFrameIdToReference(0);
test_video_encoder_callback_->SetExpectedResult(false, 1, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
capture_time += base::TimeDelta::FromMilliseconds(33);
video_encoder_controller_->LatestFrameIdToReference(1);
test_video_encoder_callback_->SetExpectedResult(false, 2, 1, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
video_encoder_controller_->LatestFrameIdToReference(2);
@@ -152,8 +141,8 @@ TEST_F(VideoEncoderTest, EncodePattern30fpsRunningOutOfAck) {
for (int i = 3; i < 6; ++i) {
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(false, i, 2, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
}
}
@@ -171,22 +160,22 @@ TEST_F(VideoEncoderTest,DISABLED_EncodePattern60fpsRunningOutOfAck) {
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(true, 0, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
video_encoder_controller_->LatestFrameIdToReference(0);
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(false, 1, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
video_encoder_controller_->LatestFrameIdToReference(1);
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(false, 2, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
video_encoder_controller_->LatestFrameIdToReference(2);
@@ -194,8 +183,8 @@ TEST_F(VideoEncoderTest,DISABLED_EncodePattern60fpsRunningOutOfAck) {
for (int i = 3; i < 9; ++i) {
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(false, i, 2, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
}
}
@@ -212,44 +201,44 @@ TEST_F(VideoEncoderTest, DISABLED_EncodePattern60fps200msDelayRunningOutOfAck) {
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(true, 0, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
video_encoder_controller_->LatestFrameIdToReference(0);
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(false, 1, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
video_encoder_controller_->LatestFrameIdToReference(1);
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(false, 2, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
video_encoder_controller_->LatestFrameIdToReference(2);
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(false, 3, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
video_encoder_controller_->LatestFrameIdToReference(3);
capture_time += base::TimeDelta::FromMilliseconds(33);
test_video_encoder_callback_->SetExpectedResult(false, 4, 0, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
video_encoder_controller_->LatestFrameIdToReference(4);
for (int i = 5; i < 17; ++i) {
test_video_encoder_callback_->SetExpectedResult(false, i, 4, capture_time);
- EXPECT_TRUE(video_encoder_->EncodeVideoFrame(&video_frame_, capture_time,
- frame_encoded_callback, base::Bind(ReleaseFrame, &video_frame_)));
+ EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
+ frame_encoded_callback, base::Bind(base::DoNothing)));
task_runner_->RunTasks();
}
}
diff --git a/media/cast/video_sender/video_sender.cc b/media/cast/video_sender/video_sender.cc
index 2591b12..eb560c6 100644
--- a/media/cast/video_sender/video_sender.cc
+++ b/media/cast/video_sender/video_sender.cc
@@ -128,9 +128,9 @@ void VideoSender::InitializeTimers() {
}
void VideoSender::InsertRawVideoFrame(
- const I420VideoFrame* video_frame,
+ const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& capture_time,
- const base::Closure callback) {
+ const base::Closure& callback) {
DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
DCHECK(video_encoder_.get()) << "Invalid state";
diff --git a/media/cast/video_sender/video_sender.gypi b/media/cast/video_sender/video_sender.gypi
index a11f220..7b8b890 100644
--- a/media/cast/video_sender/video_sender.gypi
+++ b/media/cast/video_sender/video_sender.gypi
@@ -24,6 +24,8 @@
'<(DEPTH)/crypto/crypto.gyp:crypto',
'<(DEPTH)/media/cast/rtcp/rtcp.gyp:*',
'<(DEPTH)/media/cast/rtp_sender/rtp_sender.gyp:*',
+ '<(DEPTH)/media/media.gyp:media',
+ '<(DEPTH)/media/media.gyp:shared_memory_support',
'congestion_control',
'cast_vp8_encoder',
],
diff --git a/media/cast/video_sender/video_sender.h b/media/cast/video_sender/video_sender.h
index b18f48b..a2f8734 100644
--- a/media/cast/video_sender/video_sender.h
+++ b/media/cast/video_sender/video_sender.h
@@ -23,6 +23,10 @@ namespace crypto {
}
namespace media {
+class VideoFrame;
+}
+
+namespace media {
namespace cast {
class VideoEncoder;
@@ -52,9 +56,9 @@ class VideoSender : public base::NonThreadSafe,
// the encoder is done with the frame; it does not mean that the encoded frame
// has been sent out.
void InsertRawVideoFrame(
- const I420VideoFrame* video_frame,
+ const scoped_refptr<media::VideoFrame>& video_frame,
const base::TimeTicks& capture_time,
- const base::Closure callback);
+ const base::Closure& callback);
// The video_frame must be valid until the closure callback is called.
// The closure callback is called from the main thread as soon as
diff --git a/media/cast/video_sender/video_sender_unittest.cc b/media/cast/video_sender/video_sender_unittest.cc
index 9c9bffc..8c56602 100644
--- a/media/cast/video_sender/video_sender_unittest.cc
+++ b/media/cast/video_sender/video_sender_unittest.cc
@@ -7,10 +7,12 @@
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/test/simple_test_tick_clock.h"
+#include "media/base/video_frame.h"
#include "media/cast/cast_environment.h"
#include "media/cast/pacing/mock_paced_packet_sender.h"
#include "media/cast/pacing/paced_sender.h"
#include "media/cast/test/fake_task_runner.h"
+#include "media/cast/test/video_utility.h"
#include "media/cast/video_sender/mock_video_encoder_controller.h"
#include "media/cast/video_sender/video_sender.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -19,8 +21,12 @@
namespace media {
namespace cast {
+namespace {
static const int64 kStartMillisecond = GG_INT64_C(12345678900000);
static const uint8 kPixelValue = 123;
+static const int kWidth = 320;
+static const int kHeight = 240;
+}
using testing::_;
using testing::AtLeast;
@@ -37,17 +43,6 @@ class PeerVideoSender : public VideoSender {
}
using VideoSender::OnReceivedCastFeedback;
};
-
-static void ReleaseVideoFrame(const I420VideoFrame* frame) {
- delete [] frame->y_plane.data;
- delete [] frame->u_plane.data;
- delete [] frame->v_plane.data;
- delete frame;
-}
-
-static void ReleaseEncodedFrame(const EncodedVideoFrame* frame) {
- // Do nothing.
-}
} // namespace
class VideoSenderTest : public ::testing::Test {
@@ -65,8 +60,8 @@ class VideoSenderTest : public ::testing::Test {
video_config.incoming_feedback_ssrc = 2;
video_config.rtp_payload_type = 127;
video_config.use_external_encoder = external;
- video_config.width = 320;
- video_config.height = 240;
+ video_config.width = kWidth;
+ video_config.height = kHeight;
video_config.max_bitrate = 5000000;
video_config.min_bitrate = 1000000;
video_config.start_bitrate = 1000000;
@@ -92,29 +87,12 @@ class VideoSenderTest : public ::testing::Test {
GetDefaultCastLoggingConfig());
}
- I420VideoFrame* AllocateNewVideoFrame() {
- I420VideoFrame* video_frame = new I420VideoFrame();
- video_frame->width = 320;
- video_frame->height = 240;
-
- video_frame->y_plane.stride = video_frame->width;
- video_frame->y_plane.length = video_frame->width;
- video_frame->y_plane.data =
- new uint8[video_frame->width * video_frame->height];
- memset(video_frame->y_plane.data, kPixelValue,
- video_frame->width * video_frame->height);
- video_frame->u_plane.stride = video_frame->width / 2;
- video_frame->u_plane.length = video_frame->width / 2;
- video_frame->u_plane.data =
- new uint8[video_frame->width * video_frame->height / 4];
- memset(video_frame->u_plane.data, kPixelValue,
- video_frame->width * video_frame->height / 4);
- video_frame->v_plane.stride = video_frame->width / 2;
- video_frame->v_plane.length = video_frame->width / 2;
- video_frame->v_plane.data =
- new uint8[video_frame->width * video_frame->height / 4];
- memset(video_frame->v_plane.data, kPixelValue,
- video_frame->width * video_frame->height / 4);
+ scoped_refptr<media::VideoFrame> GetNewVideoFrame() {
+ gfx::Size size(kWidth, kHeight);
+ scoped_refptr<media::VideoFrame> video_frame =
+ media::VideoFrame::CreateFrame(VideoFrame::I420, size, gfx::Rect(size),
+ size, base::TimeDelta());
+ PopulateVideoFrame(video_frame, kPixelValue);
return video_frame;
}
@@ -130,11 +108,11 @@ TEST_F(VideoSenderTest, BuiltInEncoder) {
EXPECT_CALL(mock_transport_, SendPackets(_)).Times(1);
InitEncoder(false);
- I420VideoFrame* video_frame = AllocateNewVideoFrame();
+ scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame();
base::TimeTicks capture_time;
video_sender_->InsertRawVideoFrame(video_frame, capture_time,
- base::Bind(&ReleaseVideoFrame, video_frame));
+ base::Bind(base::DoNothing));
task_runner_->RunTasks();
}
@@ -154,7 +132,7 @@ TEST_F(VideoSenderTest, ExternalEncoder) {
video_frame.data.insert(video_frame.data.begin(), 1000, kPixelValue);
video_sender_->InsertCodedVideoFrame(&video_frame, capture_time,
- base::Bind(&ReleaseEncodedFrame, &video_frame));
+ base::Bind(base::DoNothing));
}
TEST_F(VideoSenderTest, RtcpTimer) {
@@ -174,7 +152,7 @@ TEST_F(VideoSenderTest, RtcpTimer) {
video_frame.data.insert(video_frame.data.begin(), 1000, kPixelValue);
video_sender_->InsertCodedVideoFrame(&video_frame, capture_time,
- base::Bind(&ReleaseEncodedFrame, &video_frame));
+ base::Bind(base::DoNothing));
// Make sure that we send at least one RTCP packet.
base::TimeDelta max_rtcp_timeout =
@@ -190,11 +168,11 @@ TEST_F(VideoSenderTest, ResendTimer) {
InitEncoder(false);
- I420VideoFrame* video_frame = AllocateNewVideoFrame();
+ scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame();
base::TimeTicks capture_time;
video_sender_->InsertRawVideoFrame(video_frame, capture_time,
- base::Bind(&ReleaseVideoFrame, video_frame));
+ base::Bind(base::DoNothing));
task_runner_->RunTasks();
@@ -204,9 +182,9 @@ TEST_F(VideoSenderTest, ResendTimer) {
cast_feedback.ack_frame_id_ = 0;
video_sender_->OnReceivedCastFeedback(cast_feedback);
- video_frame = AllocateNewVideoFrame();
+ video_frame = GetNewVideoFrame();
video_sender_->InsertRawVideoFrame(video_frame, capture_time,
- base::Bind(&ReleaseVideoFrame, video_frame));
+ base::Bind(base::DoNothing));
task_runner_->RunTasks();