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

Unified Diff: media/muxers/webm_muxer_unittest.cc

Issue 2633623002: MediaRecorder: handle libwebm::Segment::AddFrame() errors and wire up to Blink (Closed)
Patch Set: I can haz moar testing? Created 3 years, 11 months 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
« no previous file with comments | « media/muxers/webm_muxer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/muxers/webm_muxer_unittest.cc
diff --git a/media/muxers/webm_muxer_unittest.cc b/media/muxers/webm_muxer_unittest.cc
index a65a8850be821a7524821c901903c1ea7cd2a574..8dcceb88b2aaf29863be6da7fc8de7f9891ad473 100644
--- a/media/muxers/webm_muxer_unittest.cc
+++ b/media/muxers/webm_muxer_unittest.cc
@@ -33,13 +33,13 @@ using ::testing::WithArgs;
namespace media {
-struct kTestParams {
+struct TestParams {
VideoCodec codec;
size_t num_video_tracks;
size_t num_audio_tracks;
};
-class WebmMuxerTest : public TestWithParam<kTestParams> {
+class WebmMuxerTest : public TestWithParam<TestParams> {
public:
WebmMuxerTest()
: webm_muxer_(
@@ -109,9 +109,10 @@ TEST_P(WebmMuxerTest, OnEncodedVideoTwoFrames) {
.Times(AtLeast(1))
.WillRepeatedly(
WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
- webm_muxer_.OnEncodedVideo(WebmMuxer::VideoParameters(video_frame),
- base::WrapUnique(new std::string(encoded_data)),
- base::TimeTicks::Now(), false /* keyframe */);
+ EXPECT_TRUE(webm_muxer_.OnEncodedVideo(
+ WebmMuxer::VideoParameters(video_frame),
+ base::WrapUnique(new std::string(encoded_data)), base::TimeTicks::Now(),
+ false /* keyframe */));
// First time around WriteCallback() is pinged a number of times to write the
// Matroska header, but at the end it dumps |encoded_data|.
@@ -125,9 +126,9 @@ TEST_P(WebmMuxerTest, OnEncodedVideoTwoFrames) {
.Times(AtLeast(1))
.WillRepeatedly(
WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
- webm_muxer_.OnEncodedVideo(video_frame,
- base::WrapUnique(new std::string(encoded_data)),
- base::TimeTicks::Now(), false /* keyframe */);
+ EXPECT_TRUE(webm_muxer_.OnEncodedVideo(
+ video_frame, base::WrapUnique(new std::string(encoded_data)),
+ base::TimeTicks::Now(), false /* keyframe */));
// The second time around the callbacks should include a SimpleBlock header,
// namely the track index, a timestamp and a flags byte, for a total of 6B.
@@ -137,6 +138,13 @@ TEST_P(WebmMuxerTest, OnEncodedVideoTwoFrames) {
EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize +
encoded_data.size()),
accumulated_position_);
+
+ // Force an error in libwebm and expect OnEncodedVideo to fail.
+ webm_muxer_.ForceOneLibWebmErrorForTesting();
+ EXPECT_FALSE(
+ webm_muxer_.OnEncodedVideo(WebmMuxer::VideoParameters(video_frame),
+ base::MakeUnique<std::string>(encoded_data),
+ base::TimeTicks::Now(), true /* keyframe */));
}
TEST_P(WebmMuxerTest, OnEncodedAudioTwoFrames) {
@@ -157,9 +165,9 @@ TEST_P(WebmMuxerTest, OnEncodedAudioTwoFrames) {
.Times(AtLeast(1))
.WillRepeatedly(
WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
- webm_muxer_.OnEncodedAudio(audio_params,
- base::MakeUnique<std::string>(encoded_data),
- base::TimeTicks::Now());
+ EXPECT_TRUE(webm_muxer_.OnEncodedAudio(
+ audio_params, base::MakeUnique<std::string>(encoded_data),
+ base::TimeTicks::Now()));
// First time around WriteCallback() is pinged a number of times to write the
// Matroska header, but at the end it dumps |encoded_data|.
@@ -173,9 +181,9 @@ TEST_P(WebmMuxerTest, OnEncodedAudioTwoFrames) {
.Times(AtLeast(1))
.WillRepeatedly(
WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
- webm_muxer_.OnEncodedAudio(audio_params,
- base::MakeUnique<std::string>(encoded_data),
- base::TimeTicks::Now());
+ EXPECT_TRUE(webm_muxer_.OnEncodedAudio(
+ audio_params, base::MakeUnique<std::string>(encoded_data),
+ base::TimeTicks::Now()));
// The second time around the callbacks should include a SimpleBlock header,
// namely the track index, a timestamp and a flags byte, for a total of 6B.
@@ -185,6 +193,12 @@ TEST_P(WebmMuxerTest, OnEncodedAudioTwoFrames) {
EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize +
encoded_data.size()),
accumulated_position_);
+
+ // Force an error in libwebm and expect OnEncodedAudio to fail.
+ webm_muxer_.ForceOneLibWebmErrorForTesting();
+ EXPECT_FALSE(webm_muxer_.OnEncodedAudio(
+ audio_params, base::MakeUnique<std::string>(encoded_data),
+ base::TimeTicks::Now()));
}
// This test verifies that when video data comes before audio data, we save the
@@ -194,24 +208,24 @@ TEST_P(WebmMuxerTest, VideoIsStoredWhileWaitingForAudio) {
if (GetParam().num_video_tracks == 0 || GetParam().num_audio_tracks == 0)
return;
- // First send a video keyframe
+ // First send a video keyframe.
const gfx::Size frame_size(160, 80);
const scoped_refptr<VideoFrame> video_frame =
VideoFrame::CreateBlackFrame(frame_size);
const std::string encoded_video("thisisanencodedvideopacket");
- webm_muxer_.OnEncodedVideo(WebmMuxer::VideoParameters(video_frame),
- base::WrapUnique(new std::string(encoded_video)),
- base::TimeTicks::Now(), true /* keyframe */);
+ EXPECT_TRUE(webm_muxer_.OnEncodedVideo(
+ WebmMuxer::VideoParameters(video_frame),
+ base::WrapUnique(new std::string(encoded_video)), base::TimeTicks::Now(),
+ true /* keyframe */));
// A few encoded non key frames.
const int kNumNonKeyFrames = 2;
for (int i = 0; i < kNumNonKeyFrames; ++i) {
- webm_muxer_.OnEncodedVideo(WebmMuxer::VideoParameters(video_frame),
- base::WrapUnique(new std::string(encoded_video)),
- base::TimeTicks::Now(), false /* keyframe */);
+ EXPECT_TRUE(webm_muxer_.OnEncodedVideo(
+ WebmMuxer::VideoParameters(video_frame),
+ base::WrapUnique(new std::string(encoded_video)),
+ base::TimeTicks::Now(), false /* keyframe */));
}
- // Send some audio. The header will be written and muxing will proceed
- // normally.
const int sample_rate = 48000;
const int bits_per_sample = 16;
const int frames_per_buffer = 480;
@@ -221,7 +235,13 @@ TEST_P(WebmMuxerTest, VideoIsStoredWhileWaitingForAudio) {
frames_per_buffer);
const std::string encoded_audio("thisisanencodedaudiopacket");
- // We should first get the encoded video frames, then the encoded audio frame.
+ // Force one libwebm error and verify OnEncodedAudio() fails.
+ webm_muxer_.ForceOneLibWebmErrorForTesting();
+ EXPECT_FALSE(webm_muxer_.OnEncodedAudio(
+ audio_params, base::WrapUnique(new std::string(encoded_audio)),
+ base::TimeTicks::Now()));
+
+ // We should get the queued encoded video frames, then an encoded audio frame.
Sequence s;
EXPECT_CALL(*this, WriteCallback(Eq(encoded_video)))
.Times(1 + kNumNonKeyFrames)
@@ -231,12 +251,12 @@ TEST_P(WebmMuxerTest, VideoIsStoredWhileWaitingForAudio) {
EXPECT_CALL(*this, WriteCallback(
AllOf(Not(Eq(encoded_video)), Not(Eq(encoded_audio)))))
.Times(AnyNumber());
- webm_muxer_.OnEncodedAudio(audio_params,
- base::WrapUnique(new std::string(encoded_audio)),
- base::TimeTicks::Now());
+ EXPECT_TRUE(webm_muxer_.OnEncodedAudio(
+ audio_params, base::WrapUnique(new std::string(encoded_audio)),
+ base::TimeTicks::Now()));
}
-const kTestParams kTestCases[] = {
+const TestParams kTestCases[] = {
{kCodecVP8, 1 /* num_video_tracks */, 0 /*num_audio_tracks*/},
{kCodecVP8, 0, 1},
{kCodecVP8, 1, 1},
« no previous file with comments | « media/muxers/webm_muxer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698