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 290993005: Support configuring number of audio buffers in MediaStream Pepper API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review issues Created 6 years, 7 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 const int32_t kMaxNumberOfBuffers = 1000;
dmichael (off chromium) 2014/05/27 20:22:33 It would be good to reference the file where the r
thembrown 2014/05/28 10:55:59 Done.
21 const int32_t kTimes = 3; 22 const int32_t kTimes = 3;
22 const char kJSCode[] = 23 const char kJSCode[] =
23 "function gotStream(stream) {" 24 "function gotStream(stream) {"
24 " test_stream = stream;" 25 " test_stream = stream;"
25 " var track = stream.getAudioTracks()[0];" 26 " var track = stream.getAudioTracks()[0];"
26 " var plugin = document.getElementById('plugin');" 27 " var plugin = document.getElementById('plugin');"
27 " plugin.postMessage(track);" 28 " plugin.postMessage(track);"
28 "}" 29 "}"
29 "var constraints = {" 30 "var constraints = {"
30 " audio: true," 31 " audio: true,"
(...skipping 15 matching lines...) Expand all
46 case PP_AUDIOBUFFER_SAMPLERATE_44100: 47 case PP_AUDIOBUFFER_SAMPLERATE_44100:
47 case PP_AUDIOBUFFER_SAMPLERATE_48000: 48 case PP_AUDIOBUFFER_SAMPLERATE_48000:
48 case PP_AUDIOBUFFER_SAMPLERATE_96000: 49 case PP_AUDIOBUFFER_SAMPLERATE_96000:
49 case PP_AUDIOBUFFER_SAMPLERATE_192000: 50 case PP_AUDIOBUFFER_SAMPLERATE_192000:
50 return true; 51 return true;
51 default: 52 default:
52 return false; 53 return false;
53 } 54 }
54 } 55 }
55 56
56 } 57 } // namespace
57 58
58 TestMediaStreamAudioTrack::TestMediaStreamAudioTrack(TestingInstance* instance) 59 TestMediaStreamAudioTrack::TestMediaStreamAudioTrack(TestingInstance* instance)
59 : TestCase(instance), 60 : TestCase(instance),
60 event_(instance_->pp_instance()) { 61 event_(instance_->pp_instance()) {
61 } 62 }
62 63
63 bool TestMediaStreamAudioTrack::Init() { 64 bool TestMediaStreamAudioTrack::Init() {
64 return true; 65 return true;
65 } 66 }
66 67
67 TestMediaStreamAudioTrack::~TestMediaStreamAudioTrack() { 68 TestMediaStreamAudioTrack::~TestMediaStreamAudioTrack() {
68 } 69 }
69 70
70 void TestMediaStreamAudioTrack::RunTests(const std::string& filter) { 71 void TestMediaStreamAudioTrack::RunTests(const std::string& filter) {
71 RUN_TEST(Create, filter); 72 RUN_TEST(Create, filter);
72 RUN_TEST(GetBuffer, filter); 73 RUN_TEST(GetBuffer, filter);
74 RUN_TEST(Configure, filter);
73 } 75 }
74 76
75 void TestMediaStreamAudioTrack::HandleMessage(const pp::Var& message) { 77 void TestMediaStreamAudioTrack::HandleMessage(const pp::Var& message) {
76 if (message.is_resource()) { 78 if (message.is_resource()) {
77 audio_track_ = pp::MediaStreamAudioTrack(message.AsResource()); 79 audio_track_ = pp::MediaStreamAudioTrack(message.AsResource());
78 } 80 }
79 event_.Signal(); 81 event_.Signal();
80 } 82 }
81 83
82 std::string TestMediaStreamAudioTrack::TestCreate() { 84 std::string TestMediaStreamAudioTrack::TestCreate() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 ASSERT_EQ(buffer.GetDataBufferSize(), 0U); 135 ASSERT_EQ(buffer.GetDataBufferSize(), 0U);
134 ASSERT_TRUE(buffer.GetDataBuffer() == NULL); 136 ASSERT_TRUE(buffer.GetDataBuffer() == NULL);
135 } 137 }
136 138
137 // Close the track. 139 // Close the track.
138 audio_track_.Close(); 140 audio_track_.Close();
139 ASSERT_TRUE(audio_track_.HasEnded()); 141 ASSERT_TRUE(audio_track_.HasEnded());
140 audio_track_ = pp::MediaStreamAudioTrack(); 142 audio_track_ = pp::MediaStreamAudioTrack();
141 PASS(); 143 PASS();
142 } 144 }
145
146 std::string TestMediaStreamAudioTrack::TestConfigure() {
147 // Create a track.
148 instance_->EvalScript(kJSCode);
149 event_.Wait();
150 event_.Reset();
151
152 ASSERT_FALSE(audio_track_.is_null());
153 ASSERT_FALSE(audio_track_.HasEnded());
154 ASSERT_FALSE(audio_track_.GetId().empty());
155
156 PP_TimeDelta timestamp = 0.0;
157
158 // Configure number of buffers.
159 struct {
160 int32_t buffers;
161 int32_t expect_result;
162 } buffers[] = {
163 { 8, PP_OK },
164 { 100, PP_OK },
165 { kMaxNumberOfBuffers, PP_OK },
166 { -1, PP_ERROR_BADARGUMENT },
167 { kMaxNumberOfBuffers + 1, PP_OK }, // Clipped to max value.
168 { 0, PP_OK }, // Use default.
169 };
170 for (size_t i = 0; i < sizeof(buffers) / sizeof(buffers[0]); ++i) {
171 TestCompletionCallback cc_configure(instance_->pp_instance(), false);
172 int32_t attrib_list[] = {
173 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, buffers[i].buffers,
174 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE,
175 };
176 cc_configure.WaitForResult(
177 audio_track_.Configure(attrib_list, cc_configure.GetCallback()));
178 ASSERT_EQ(buffers[i].expect_result, cc_configure.result());
179
180 // Get some buffers. This should also succeed when configure fails.
181
dmichael (off chromium) 2014/05/27 20:22:33 nit: unnecessary carriage return
thembrown 2014/05/28 10:55:59 Done.
182 for (int j = 0; j < kTimes; ++j) {
183 TestCompletionCallbackWithOutput<pp::AudioBuffer> cc_get_buffer(
184 instance_->pp_instance(), false);
185 cc_get_buffer.WaitForResult(
186 audio_track_.GetBuffer(cc_get_buffer.GetCallback()));
187 ASSERT_EQ(PP_OK, cc_get_buffer.result());
188 pp::AudioBuffer buffer = cc_get_buffer.output();
189 ASSERT_FALSE(buffer.is_null());
190 ASSERT_TRUE(IsSampleRateValid(buffer.GetSampleRate()));
191 ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_16_BITS);
192
193 ASSERT_GE(buffer.GetTimestamp(), timestamp);
194 timestamp = buffer.GetTimestamp();
195
196 ASSERT_GT(buffer.GetDataBufferSize(), 0U);
197 ASSERT_TRUE(buffer.GetDataBuffer() != NULL);
198
199 audio_track_.RecycleBuffer(buffer);
200 }
201 }
202
203 // Configure should fail while plugin holds buffers.
dmichael (off chromium) 2014/05/27 20:22:33 It would probably be good to document this in the
thembrown 2014/05/28 10:55:59 Done.
204 {
205 TestCompletionCallbackWithOutput<pp::AudioBuffer> cc_get_buffer(
206 instance_->pp_instance(), false);
207 cc_get_buffer.WaitForResult(
208 audio_track_.GetBuffer(cc_get_buffer.GetCallback()));
209 ASSERT_EQ(PP_OK, cc_get_buffer.result());
210 pp::AudioBuffer buffer = cc_get_buffer.output();
211 int32_t attrib_list[] = {
212 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, 0,
213 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE,
214 };
215 TestCompletionCallback cc_configure(instance_->pp_instance(), false);
216 cc_configure.WaitForResult(
217 audio_track_.Configure(attrib_list, cc_configure.GetCallback()));
218 ASSERT_EQ(PP_ERROR_INPROGRESS, cc_configure.result());
219 audio_track_.RecycleBuffer(buffer);
220 }
221
222 // Close the track.
223 audio_track_.Close();
224 ASSERT_TRUE(audio_track_.HasEnded());
225 audio_track_ = pp::MediaStreamAudioTrack();
226 PASS();
227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698