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..87ca97387fd77e4a8f9beaf07348222dba928df0 100644 |
--- a/ppapi/tests/test_media_stream_audio_track.cc |
+++ b/ppapi/tests/test_media_stream_audio_track.cc |
@@ -18,9 +18,11 @@ REGISTER_TEST_CASE(MediaStreamAudioTrack); |
namespace { |
-// Real max defined in |
+// Real constants defined in |
// 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) {" |
@@ -145,6 +147,53 @@ std::string TestMediaStreamAudioTrack::TestGetBuffer() { |
PASS(); |
} |
+std::string TestMediaStreamAudioTrack::CheckConfigure( |
+ int32_t attrib_list[], int32_t expected_result) { |
+ TestCompletionCallback cc_configure(instance_->pp_instance(), false); |
+ cc_configure.WaitForResult( |
+ audio_track_.Configure(attrib_list, cc_configure.GetCallback())); |
+ ASSERT_EQ(expected_result, cc_configure.result()); |
+ PASS(); |
+} |
+ |
+std::string TestMediaStreamAudioTrack::CheckGetBuffer( |
+ int times, int expected_duration) { |
+ PP_TimeDelta timestamp = 0.0; |
+ for (int j = 0; j < times; ++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(); |
+ |
+ // TODO(amistry): Figure out how to inject a predictable audio pattern, such |
+ // as a sawtooth, and check the buffer data to make sure it's correct. |
+ ASSERT_TRUE(buffer.GetDataBuffer() != NULL); |
+ if (expected_duration > 0) { |
+ 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 = expected_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); |
+ } |
+ PASS(); |
+} |
+ |
std::string TestMediaStreamAudioTrack::TestConfigure() { |
Peng
2014/07/24 15:38:37
The test is disabled in https://codereview.chromiu
Anand Mistry (off Chromium)
2014/07/25 03:38:15
Done.
|
// Create a track. |
instance_->EvalScript(kJSCode); |
@@ -155,8 +204,6 @@ std::string TestMediaStreamAudioTrack::TestConfigure() { |
ASSERT_FALSE(audio_track_.HasEnded()); |
ASSERT_FALSE(audio_track_.GetId().empty()); |
- PP_TimeDelta timestamp = 0.0; |
- |
// Configure number of buffers. |
struct { |
int32_t buffers; |
@@ -170,36 +217,46 @@ std::string TestMediaStreamAudioTrack::TestConfigure() { |
{ 0, PP_OK }, // Use default. |
}; |
for (size_t i = 0; i < sizeof(buffers) / sizeof(buffers[0]); ++i) { |
- TestCompletionCallback cc_configure(instance_->pp_instance(), false); |
int32_t attrib_list[] = { |
PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, buffers[i].buffers, |
PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE, |
}; |
- cc_configure.WaitForResult( |
- audio_track_.Configure(attrib_list, cc_configure.GetCallback())); |
- ASSERT_EQ(buffers[i].expect_result, cc_configure.result()); |
- |
+ ASSERT_SUBTEST_SUCCESS(CheckConfigure(attrib_list, |
+ buffers[i].expect_result)); |
// Get some buffers. This should also succeed when configure fails. |
- 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_SUBTEST_SUCCESS(CheckGetBuffer(kTimes, -1)); |
+ } |
- ASSERT_GT(buffer.GetDataBufferSize(), 0U); |
- ASSERT_TRUE(buffer.GetDataBuffer() != NULL); |
+ // Configure buffer duration. |
+ struct { |
+ int32_t duration; |
+ int32_t expect_result; |
+ } durations[] = { |
+ { kMinDuration, PP_OK }, |
+ { 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) { |
+ int32_t attrib_list[] = { |
+ PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION, durations[i].duration, |
+ PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE, |
+ }; |
+ ASSERT_SUBTEST_SUCCESS(CheckConfigure(attrib_list, |
+ durations[i].expect_result)); |
- audio_track_.RecycleBuffer(buffer); |
- } |
+ // Get some buffers. This always works, but the buffer size will vary. |
+ int duration = |
+ durations[i].expect_result == PP_OK ? durations[i].duration : -1; |
+ ASSERT_SUBTEST_SUCCESS(CheckGetBuffer(kTimes, duration)); |
} |
+ // Test kMaxDuration separately since each GetBuffer will take 10 seconds. |
+ int32_t attrib_list[] = { |
+ PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION, kMaxDuration, |
+ PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE, |
+ }; |
+ ASSERT_SUBTEST_SUCCESS(CheckConfigure(attrib_list, PP_OK)); |
+ |
// Configure should fail while plugin holds buffers. |
{ |