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

Side by Side Diff: ppapi/tests/test_media_stream_audio_track.cc

Issue 414643003: Support configuring the audio buffer duration in the Pepper MediaStream API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests! Created 6 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
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 // Tests PPB_MediaStreamAudioTrack interface. 5 // Tests PPB_MediaStreamAudioTrack interface.
6 6
7 #include "ppapi/tests/test_media_stream_audio_track.h" 7 #include "ppapi/tests/test_media_stream_audio_track.h"
8 8
9 #include "ppapi/c/private/ppb_testing_private.h" 9 #include "ppapi/c/private/ppb_testing_private.h"
10 #include "ppapi/cpp/audio_buffer.h" 10 #include "ppapi/cpp/audio_buffer.h"
11 #include "ppapi/cpp/completion_callback.h" 11 #include "ppapi/cpp/completion_callback.h"
12 #include "ppapi/cpp/instance.h" 12 #include "ppapi/cpp/instance.h"
13 #include "ppapi/cpp/var.h" 13 #include "ppapi/cpp/var.h"
14 #include "ppapi/tests/test_utils.h" 14 #include "ppapi/tests/test_utils.h"
15 #include "ppapi/tests/testing_instance.h" 15 #include "ppapi/tests/testing_instance.h"
16 16
17 REGISTER_TEST_CASE(MediaStreamAudioTrack); 17 REGISTER_TEST_CASE(MediaStreamAudioTrack);
18 18
19 namespace { 19 namespace {
20 20
21 // Real max defined in 21 // Real max defined in
dmichael (off chromium) 2014/07/23 20:08:42 s/max/constants
Anand Mistry (off Chromium) 2014/07/24 01:28:28 Done.
22 // content/renderer/pepper/pepper_media_stream_audio_track_host.cc. 22 // content/renderer/pepper/pepper_media_stream_audio_track_host.cc.
23 const int32_t kMaxNumberOfBuffers = 1000; 23 const int32_t kMaxNumberOfBuffers = 1000;
24 const int32_t kMinDuration = 10;
25 const int32_t kMaxDuration = 10000;
24 const int32_t kTimes = 3; 26 const int32_t kTimes = 3;
25 const char kJSCode[] = 27 const char kJSCode[] =
26 "function gotStream(stream) {" 28 "function gotStream(stream) {"
27 " test_stream = stream;" 29 " test_stream = stream;"
28 " var track = stream.getAudioTracks()[0];" 30 " var track = stream.getAudioTracks()[0];"
29 " var plugin = document.getElementById('plugin');" 31 " var plugin = document.getElementById('plugin');"
30 " plugin.postMessage(track);" 32 " plugin.postMessage(track);"
31 "}" 33 "}"
32 "var constraints = {" 34 "var constraints = {"
33 " audio: true," 35 " audio: true,"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 ASSERT_GE(buffer.GetTimestamp(), timestamp); 196 ASSERT_GE(buffer.GetTimestamp(), timestamp);
195 timestamp = buffer.GetTimestamp(); 197 timestamp = buffer.GetTimestamp();
196 198
197 ASSERT_GT(buffer.GetDataBufferSize(), 0U); 199 ASSERT_GT(buffer.GetDataBufferSize(), 0U);
198 ASSERT_TRUE(buffer.GetDataBuffer() != NULL); 200 ASSERT_TRUE(buffer.GetDataBuffer() != NULL);
199 201
200 audio_track_.RecycleBuffer(buffer); 202 audio_track_.RecycleBuffer(buffer);
201 } 203 }
202 } 204 }
203 205
206 // Configure buffer duration.
207 struct {
208 int32_t duration;
209 int32_t expect_result;
210 } durations[] = {
211 { kMinDuration, PP_OK },
212 { kMaxDuration, PP_OK }, // This will take ~30 seconds.
dmichael (off chromium) 2014/07/23 20:08:42 We can't have the test take that long. Maybe you
Anand Mistry (off Chromium) 2014/07/24 01:28:28 Done.
213 { 123, PP_OK },
214 { kMinDuration - 1, PP_ERROR_BADARGUMENT },
215 { kMaxDuration + 1, PP_ERROR_BADARGUMENT },
216 };
217 for (size_t i = 0; i < sizeof(durations) / sizeof(durations[0]); ++i) {
dmichael (off chromium) 2014/07/23 20:08:42 Instead of duplicating this part, perhaps you can
Anand Mistry (off Chromium) 2014/07/24 01:28:28 Done.
218 TestCompletionCallback cc_configure(instance_->pp_instance(), false);
219 int32_t attrib_list[] = {
220 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION, durations[i].duration,
221 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE,
222 };
223 cc_configure.WaitForResult(
224 audio_track_.Configure(attrib_list, cc_configure.GetCallback()));
225 ASSERT_EQ(durations[i].expect_result, cc_configure.result());
226
227 // Get some buffers. This always works, but the buffer size will vary.
228 for (int j = 0; j < kTimes; ++j) {
229 TestCompletionCallbackWithOutput<pp::AudioBuffer> cc_get_buffer(
230 instance_->pp_instance(), false);
231 cc_get_buffer.WaitForResult(
232 audio_track_.GetBuffer(cc_get_buffer.GetCallback()));
233 ASSERT_EQ(PP_OK, cc_get_buffer.result());
234 pp::AudioBuffer buffer = cc_get_buffer.output();
235 ASSERT_FALSE(buffer.is_null());
236 ASSERT_TRUE(IsSampleRateValid(buffer.GetSampleRate()));
237 ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_16_BITS);
238
239 ASSERT_GE(buffer.GetTimestamp(), timestamp);
240 timestamp = buffer.GetTimestamp();
241
242 ASSERT_TRUE(buffer.GetDataBuffer() != NULL);
243 if (durations[i].expect_result == PP_OK) {
244 uint32_t buffer_size = buffer.GetDataBufferSize();
245 uint32_t channels = buffer.GetNumberOfChannels();
246 uint32_t sample_rate = buffer.GetSampleRate();
247 uint32_t bytes_per_frame = channels * 2;
248 int32_t duration = durations[i].duration;
249 ASSERT_EQ(buffer_size % bytes_per_frame, 0U);
250 ASSERT_EQ(buffer_size,
251 (duration * sample_rate * bytes_per_frame) / 1000);
252 } else {
253 ASSERT_GT(buffer.GetDataBufferSize(), 0U);
254 }
255
256 audio_track_.RecycleBuffer(buffer);
257 }
258 }
259
204 // Configure should fail while plugin holds buffers. 260 // Configure should fail while plugin holds buffers.
205 { 261 {
206 TestCompletionCallbackWithOutput<pp::AudioBuffer> cc_get_buffer( 262 TestCompletionCallbackWithOutput<pp::AudioBuffer> cc_get_buffer(
207 instance_->pp_instance(), false); 263 instance_->pp_instance(), false);
208 cc_get_buffer.WaitForResult( 264 cc_get_buffer.WaitForResult(
209 audio_track_.GetBuffer(cc_get_buffer.GetCallback())); 265 audio_track_.GetBuffer(cc_get_buffer.GetCallback()));
210 ASSERT_EQ(PP_OK, cc_get_buffer.result()); 266 ASSERT_EQ(PP_OK, cc_get_buffer.result());
211 pp::AudioBuffer buffer = cc_get_buffer.output(); 267 pp::AudioBuffer buffer = cc_get_buffer.output();
212 int32_t attrib_list[] = { 268 int32_t attrib_list[] = {
213 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, 0, 269 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, 0,
214 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE, 270 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE,
215 }; 271 };
216 TestCompletionCallback cc_configure(instance_->pp_instance(), false); 272 TestCompletionCallback cc_configure(instance_->pp_instance(), false);
217 cc_configure.WaitForResult( 273 cc_configure.WaitForResult(
218 audio_track_.Configure(attrib_list, cc_configure.GetCallback())); 274 audio_track_.Configure(attrib_list, cc_configure.GetCallback()));
219 ASSERT_EQ(PP_ERROR_INPROGRESS, cc_configure.result()); 275 ASSERT_EQ(PP_ERROR_INPROGRESS, cc_configure.result());
220 audio_track_.RecycleBuffer(buffer); 276 audio_track_.RecycleBuffer(buffer);
221 } 277 }
222 278
223 // Close the track. 279 // Close the track.
224 audio_track_.Close(); 280 audio_track_.Close();
225 ASSERT_TRUE(audio_track_.HasEnded()); 281 ASSERT_TRUE(audio_track_.HasEnded());
226 audio_track_ = pp::MediaStreamAudioTrack(); 282 audio_track_ = pp::MediaStreamAudioTrack();
227 PASS(); 283 PASS();
228 } 284 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698