Index: ppapi/tests/test_media_stream_audio_track.cc |
diff --git a/ppapi/tests/test_media_stream_audio_track.cc b/ppapi/tests/test_media_stream_audio_track.cc |
index 636e7b515d887113614d6e97a1932855a186e744..66a2957685da2e744ff55691409f7b9552348a23 100644 |
--- a/ppapi/tests/test_media_stream_audio_track.cc |
+++ b/ppapi/tests/test_media_stream_audio_track.cc |
@@ -21,6 +21,8 @@ namespace { |
// 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.
|
// content/renderer/pepper/pepper_media_stream_audio_track_host.cc. |
const int32_t kMaxNumberOfBuffers = 1000; |
+const int32_t kMinDuration = 10; |
+const int32_t kMaxDuration = 10000; |
const int32_t kTimes = 3; |
const char kJSCode[] = |
"function gotStream(stream) {" |
@@ -201,6 +203,60 @@ std::string TestMediaStreamAudioTrack::TestConfigure() { |
} |
} |
+ // Configure buffer duration. |
+ struct { |
+ int32_t duration; |
+ int32_t expect_result; |
+ } durations[] = { |
+ { kMinDuration, PP_OK }, |
+ { 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.
|
+ { 123, PP_OK }, |
+ { kMinDuration - 1, PP_ERROR_BADARGUMENT }, |
+ { kMaxDuration + 1, PP_ERROR_BADARGUMENT }, |
+ }; |
+ 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.
|
+ TestCompletionCallback cc_configure(instance_->pp_instance(), false); |
+ int32_t attrib_list[] = { |
+ PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION, durations[i].duration, |
+ PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE, |
+ }; |
+ cc_configure.WaitForResult( |
+ audio_track_.Configure(attrib_list, cc_configure.GetCallback())); |
+ ASSERT_EQ(durations[i].expect_result, cc_configure.result()); |
+ |
+ // Get some buffers. This always works, but the buffer size will vary. |
+ for (int j = 0; j < kTimes; ++j) { |
+ TestCompletionCallbackWithOutput<pp::AudioBuffer> cc_get_buffer( |
+ instance_->pp_instance(), false); |
+ cc_get_buffer.WaitForResult( |
+ audio_track_.GetBuffer(cc_get_buffer.GetCallback())); |
+ ASSERT_EQ(PP_OK, cc_get_buffer.result()); |
+ pp::AudioBuffer buffer = cc_get_buffer.output(); |
+ ASSERT_FALSE(buffer.is_null()); |
+ ASSERT_TRUE(IsSampleRateValid(buffer.GetSampleRate())); |
+ ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_16_BITS); |
+ |
+ ASSERT_GE(buffer.GetTimestamp(), timestamp); |
+ timestamp = buffer.GetTimestamp(); |
+ |
+ ASSERT_TRUE(buffer.GetDataBuffer() != NULL); |
+ if (durations[i].expect_result == PP_OK) { |
+ uint32_t buffer_size = buffer.GetDataBufferSize(); |
+ uint32_t channels = buffer.GetNumberOfChannels(); |
+ uint32_t sample_rate = buffer.GetSampleRate(); |
+ uint32_t bytes_per_frame = channels * 2; |
+ int32_t duration = durations[i].duration; |
+ ASSERT_EQ(buffer_size % bytes_per_frame, 0U); |
+ ASSERT_EQ(buffer_size, |
+ (duration * sample_rate * bytes_per_frame) / 1000); |
+ } else { |
+ ASSERT_GT(buffer.GetDataBufferSize(), 0U); |
+ } |
+ |
+ audio_track_.RecycleBuffer(buffer); |
+ } |
+ } |
+ |
// Configure should fail while plugin holds buffers. |
{ |
TestCompletionCallbackWithOutput<pp::AudioBuffer> cc_get_buffer( |