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

Side by Side Diff: media/muxers/webm_muxer_unittest.cc

Issue 2691373005: Support alpha channel recording for VPX in MediaRecorder (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
vignesh 2017/03/08 17:26:14 A test for video with alpha channel data here woul
emircan 2017/03/08 23:53:58 I added one. I actually worked on a test similar t
vignesh 2017/03/09 07:13:46 Here's the element structure for a block with alph
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/muxers/webm_muxer.h" 5 #include "media/muxers/webm_muxer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 const scoped_refptr<VideoFrame> video_frame = 104 const scoped_refptr<VideoFrame> video_frame =
105 VideoFrame::CreateBlackFrame(frame_size); 105 VideoFrame::CreateBlackFrame(frame_size);
106 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); 106 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz");
107 107
108 EXPECT_CALL(*this, WriteCallback(_)) 108 EXPECT_CALL(*this, WriteCallback(_))
109 .Times(AtLeast(1)) 109 .Times(AtLeast(1))
110 .WillRepeatedly( 110 .WillRepeatedly(
111 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); 111 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
112 EXPECT_TRUE(webm_muxer_.OnEncodedVideo( 112 EXPECT_TRUE(webm_muxer_.OnEncodedVideo(
113 WebmMuxer::VideoParameters(video_frame), 113 WebmMuxer::VideoParameters(video_frame),
114 base::WrapUnique(new std::string(encoded_data)), base::TimeTicks::Now(), 114 base::WrapUnique(new std::string(encoded_data)), nullptr,
115 false /* keyframe */)); 115 base::TimeTicks::Now(), false /* keyframe */));
116 116
117 // First time around WriteCallback() is pinged a number of times to write the 117 // First time around WriteCallback() is pinged a number of times to write the
118 // Matroska header, but at the end it dumps |encoded_data|. 118 // Matroska header, but at the end it dumps |encoded_data|.
119 EXPECT_EQ(last_encoded_length_, encoded_data.size()); 119 EXPECT_EQ(last_encoded_length_, encoded_data.size());
120 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); 120 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_);
121 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); 121 EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_));
122 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); 122 EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive);
123 123
124 const int64_t begin_of_second_block = accumulated_position_; 124 const int64_t begin_of_second_block = accumulated_position_;
125 EXPECT_CALL(*this, WriteCallback(_)) 125 EXPECT_CALL(*this, WriteCallback(_))
126 .Times(AtLeast(1)) 126 .Times(AtLeast(1))
127 .WillRepeatedly( 127 .WillRepeatedly(
128 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); 128 WithArgs<0>(Invoke(this, &WebmMuxerTest::SaveEncodedDataLen)));
129 EXPECT_TRUE(webm_muxer_.OnEncodedVideo( 129 EXPECT_TRUE(webm_muxer_.OnEncodedVideo(
130 video_frame, base::WrapUnique(new std::string(encoded_data)), 130 video_frame, base::WrapUnique(new std::string(encoded_data)), nullptr,
131 base::TimeTicks::Now(), false /* keyframe */)); 131 base::TimeTicks::Now(), false /* keyframe */));
132 132
133 // The second time around the callbacks should include a SimpleBlock header, 133 // The second time around the callbacks should include a SimpleBlock header,
134 // namely the track index, a timestamp and a flags byte, for a total of 6B. 134 // namely the track index, a timestamp and a flags byte, for a total of 6B.
135 EXPECT_EQ(last_encoded_length_, encoded_data.size()); 135 EXPECT_EQ(last_encoded_length_, encoded_data.size());
136 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); 136 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_);
137 const uint32_t kSimpleBlockSize = 6u; 137 const uint32_t kSimpleBlockSize = 6u;
138 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + 138 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize +
139 encoded_data.size()), 139 encoded_data.size()),
140 accumulated_position_); 140 accumulated_position_);
141 141
142 // Force an error in libwebm and expect OnEncodedVideo to fail. 142 // Force an error in libwebm and expect OnEncodedVideo to fail.
143 webm_muxer_.ForceOneLibWebmErrorForTesting(); 143 webm_muxer_.ForceOneLibWebmErrorForTesting();
144 EXPECT_FALSE( 144 EXPECT_FALSE(webm_muxer_.OnEncodedVideo(
145 webm_muxer_.OnEncodedVideo(WebmMuxer::VideoParameters(video_frame), 145 WebmMuxer::VideoParameters(video_frame),
146 base::MakeUnique<std::string>(encoded_data), 146 base::MakeUnique<std::string>(encoded_data), nullptr,
147 base::TimeTicks::Now(), true /* keyframe */)); 147 base::TimeTicks::Now(), true /* keyframe */));
148 } 148 }
149 149
150 TEST_P(WebmMuxerTest, OnEncodedAudioTwoFrames) { 150 TEST_P(WebmMuxerTest, OnEncodedAudioTwoFrames) {
151 if (GetParam().num_video_tracks > 0) 151 if (GetParam().num_video_tracks > 0)
152 return; 152 return;
153 153
154 const int sample_rate = 48000; 154 const int sample_rate = 48000;
155 const int bits_per_sample = 16; 155 const int bits_per_sample = 16;
156 const int frames_per_buffer = 480; 156 const int frames_per_buffer = 480;
157 media::AudioParameters audio_params( 157 media::AudioParameters audio_params(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 if (GetParam().num_video_tracks == 0 || GetParam().num_audio_tracks == 0) 208 if (GetParam().num_video_tracks == 0 || GetParam().num_audio_tracks == 0)
209 return; 209 return;
210 210
211 // First send a video keyframe. 211 // First send a video keyframe.
212 const gfx::Size frame_size(160, 80); 212 const gfx::Size frame_size(160, 80);
213 const scoped_refptr<VideoFrame> video_frame = 213 const scoped_refptr<VideoFrame> video_frame =
214 VideoFrame::CreateBlackFrame(frame_size); 214 VideoFrame::CreateBlackFrame(frame_size);
215 const std::string encoded_video("thisisanencodedvideopacket"); 215 const std::string encoded_video("thisisanencodedvideopacket");
216 EXPECT_TRUE(webm_muxer_.OnEncodedVideo( 216 EXPECT_TRUE(webm_muxer_.OnEncodedVideo(
217 WebmMuxer::VideoParameters(video_frame), 217 WebmMuxer::VideoParameters(video_frame),
218 base::WrapUnique(new std::string(encoded_video)), base::TimeTicks::Now(), 218 base::WrapUnique(new std::string(encoded_video)), nullptr,
219 true /* keyframe */)); 219 base::TimeTicks::Now(), true /* keyframe */));
220 // A few encoded non key frames. 220 // A few encoded non key frames.
221 const int kNumNonKeyFrames = 2; 221 const int kNumNonKeyFrames = 2;
222 for (int i = 0; i < kNumNonKeyFrames; ++i) { 222 for (int i = 0; i < kNumNonKeyFrames; ++i) {
223 EXPECT_TRUE(webm_muxer_.OnEncodedVideo( 223 EXPECT_TRUE(webm_muxer_.OnEncodedVideo(
224 WebmMuxer::VideoParameters(video_frame), 224 WebmMuxer::VideoParameters(video_frame),
225 base::WrapUnique(new std::string(encoded_video)), 225 base::WrapUnique(new std::string(encoded_video)), nullptr,
226 base::TimeTicks::Now(), false /* keyframe */)); 226 base::TimeTicks::Now(), false /* keyframe */));
227 } 227 }
228 228
229 const int sample_rate = 48000; 229 const int sample_rate = 48000;
230 const int bits_per_sample = 16; 230 const int bits_per_sample = 16;
231 const int frames_per_buffer = 480; 231 const int frames_per_buffer = 480;
232 media::AudioParameters audio_params( 232 media::AudioParameters audio_params(
233 media::AudioParameters::Format::AUDIO_PCM_LOW_LATENCY, 233 media::AudioParameters::Format::AUDIO_PCM_LOW_LATENCY,
234 media::CHANNEL_LAYOUT_MONO, sample_rate, bits_per_sample, 234 media::CHANNEL_LAYOUT_MONO, sample_rate, bits_per_sample,
235 frames_per_buffer); 235 frames_per_buffer);
(...skipping 28 matching lines...) Expand all
264 {kCodecVP9, 0, 1}, 264 {kCodecVP9, 0, 1},
265 {kCodecVP9, 1, 1}, 265 {kCodecVP9, 1, 1},
266 {kCodecH264, 1, 0}, 266 {kCodecH264, 1, 0},
267 {kCodecH264, 0, 1}, 267 {kCodecH264, 0, 1},
268 {kCodecH264, 1, 1}, 268 {kCodecH264, 1, 1},
269 }; 269 };
270 270
271 INSTANTIATE_TEST_CASE_P(, WebmMuxerTest, ValuesIn(kTestCases)); 271 INSTANTIATE_TEST_CASE_P(, WebmMuxerTest, ValuesIn(kTestCases));
272 272
273 } // namespace media 273 } // namespace media
OLDNEW
« media/muxers/webm_muxer.cc ('K') | « media/muxers/webm_muxer_fuzzertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698