OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 // | |
5 // Tests PPB_MediaStreamAudioTrack interface. | |
6 | |
7 #include "ppapi/tests/test_media_stream_audio_track.h" | |
8 | |
9 #include "ppapi/c/private/ppb_testing_private.h" | |
10 #include "ppapi/cpp/audio_buffer.h" | |
11 #include "ppapi/cpp/completion_callback.h" | |
12 #include "ppapi/cpp/instance.h" | |
13 #include "ppapi/cpp/var.h" | |
14 #include "ppapi/tests/test_utils.h" | |
15 #include "ppapi/tests/testing_instance.h" | |
16 | |
17 REGISTER_TEST_CASE(MediaStreamAudioTrack); | |
18 | |
19 namespace { | |
20 | |
21 const int32_t kTimes = 3; | |
22 const char kJSCode[] = | |
23 "function gotStream(stream) {" | |
24 " test_stream = stream;" | |
25 " var track = stream.getAudioTracks()[0];" | |
26 " var plugin = document.getElementById('plugin');" | |
27 " plugin.postMessage({track: track});" | |
dmichael (off chromium)
2014/02/21 19:30:57
nit: It might be clearer to use a different name f
Peng
2014/02/21 20:28:24
Done.
| |
28 "}" | |
29 "var constraints = {" | |
30 " audio: true," | |
31 " video: false," | |
32 "};" | |
33 "navigator.webkitGetUserMedia(constraints," | |
dmichael (off chromium)
2014/02/21 19:30:57
Would it be worthwhile to do something like:
getUs
Peng
2014/02/21 20:28:24
getUserMedia = ... does not work, have to use navi
| |
34 " gotStream, function() {});"; | |
35 } | |
36 | |
37 TestMediaStreamAudioTrack::TestMediaStreamAudioTrack(TestingInstance* instance) | |
38 : TestCase(instance), | |
39 event_(instance_->pp_instance()) { | |
40 } | |
41 | |
42 bool TestMediaStreamAudioTrack::Init() { | |
43 return true; | |
44 } | |
45 | |
46 TestMediaStreamAudioTrack::~TestMediaStreamAudioTrack() { | |
47 } | |
48 | |
49 void TestMediaStreamAudioTrack::RunTests(const std::string& filter) { | |
50 RUN_TEST(Create, filter); | |
51 RUN_TEST(GetBuffer, filter); | |
52 } | |
53 | |
54 void TestMediaStreamAudioTrack::HandleMessage(const pp::Var& message) { | |
55 if (message.is_dictionary()) { | |
56 pp::Var var_track = pp::VarDictionary(message).Get("track"); | |
57 if (var_track.is_resource()) { | |
58 audio_track_ = pp::MediaStreamAudioTrack(var_track.AsResource()); | |
59 } | |
60 } | |
61 event_.Signal(); | |
62 } | |
63 | |
64 std::string TestMediaStreamAudioTrack::TestCreate() { | |
65 // Create a track. | |
66 instance_->EvalScript(kJSCode); | |
67 event_.Wait(); | |
68 event_.Reset(); | |
69 | |
70 ASSERT_FALSE(audio_track_.is_null()); | |
71 ASSERT_FALSE(audio_track_.HasEnded()); | |
72 ASSERT_FALSE(audio_track_.GetId().empty()); | |
73 | |
74 // Close the track. | |
75 audio_track_.Close(); | |
76 ASSERT_TRUE(audio_track_.HasEnded()); | |
77 audio_track_ = pp::MediaStreamAudioTrack(); | |
78 PASS(); | |
79 } | |
80 | |
81 std::string TestMediaStreamAudioTrack::TestGetBuffer() { | |
82 // Create a track. | |
83 instance_->EvalScript(kJSCode); | |
84 event_.Wait(); | |
85 event_.Reset(); | |
86 | |
87 ASSERT_FALSE(audio_track_.is_null()); | |
88 ASSERT_FALSE(audio_track_.HasEnded()); | |
89 ASSERT_FALSE(audio_track_.GetId().empty()); | |
90 | |
91 PP_TimeDelta timestamp = 0.0; | |
92 | |
93 // Get |kTimes| buffers. | |
94 for (int i = 0; i < kTimes; ++i) { | |
95 TestCompletionCallbackWithOutput<pp::AudioBuffer> cc( | |
96 instance_->pp_instance(), false); | |
97 cc.WaitForResult(audio_track_.GetBuffer(cc.GetCallback())); | |
98 ASSERT_EQ(PP_OK, cc.result()); | |
99 pp::AudioBuffer buffer = cc.output(); | |
100 ASSERT_FALSE(buffer.is_null()); | |
101 ASSERT_EQ(buffer.GetSampleRate(), PP_AUDIOBUFFER_SAMPLERATE_44100); | |
102 ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_16_BITS); | |
103 | |
104 ASSERT_GE(buffer.GetTimestamp(), timestamp); | |
105 timestamp = buffer.GetTimestamp(); | |
106 | |
107 ASSERT_GT(buffer.GetDataBufferSize(), 0U); | |
108 ASSERT_TRUE(buffer.GetDataBuffer() != NULL); | |
109 | |
110 audio_track_.RecycleBuffer(buffer); | |
111 | |
112 ASSERT_EQ(buffer.GetSampleRate(), PP_AUDIOBUFFER_SAMPLERATE_UNKNOWN); | |
dmichael (off chromium)
2014/02/21 19:30:57
A short comment above this might help. E.g.:
"A re
Peng
2014/02/21 20:28:24
Done.
| |
113 ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_UNKNOWN); | |
114 ASSERT_EQ(buffer.GetDataBufferSize(), 0U); | |
115 ASSERT_TRUE(buffer.GetDataBuffer() == NULL); | |
116 } | |
117 | |
118 // Close the track. | |
119 audio_track_.Close(); | |
120 ASSERT_TRUE(audio_track_.HasEnded()); | |
121 audio_track_ = pp::MediaStreamAudioTrack(); | |
122 PASS(); | |
123 } | |
OLD | NEW |