summaryrefslogtreecommitdiffstats
path: root/media/cast/test
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 /media/cast/test
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
Diffstat (limited to 'media/cast/test')
-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
6 files changed, 114 insertions, 73 deletions
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