OLD | NEW |
---|---|
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 #include "ppapi/proxy/media_stream_audio_track_resource.h" | 5 #include "ppapi/proxy/media_stream_audio_track_resource.h" |
6 | 6 |
7 #include "ppapi/proxy/audio_buffer_resource.h" | 7 #include "ppapi/proxy/audio_buffer_resource.h" |
8 #include "ppapi/proxy/ppapi_messages.h" | |
9 #include "ppapi/shared_impl/media_stream_audio_track_shared.h" | |
8 #include "ppapi/shared_impl/media_stream_buffer.h" | 10 #include "ppapi/shared_impl/media_stream_buffer.h" |
9 #include "ppapi/shared_impl/var.h" | 11 #include "ppapi/shared_impl/var.h" |
10 | 12 |
11 namespace ppapi { | 13 namespace ppapi { |
12 namespace proxy { | 14 namespace proxy { |
13 | 15 |
14 MediaStreamAudioTrackResource::MediaStreamAudioTrackResource( | 16 MediaStreamAudioTrackResource::MediaStreamAudioTrackResource( |
15 Connection connection, | 17 Connection connection, |
16 PP_Instance instance, | 18 PP_Instance instance, |
17 int pending_renderer_id, | 19 int pending_renderer_id, |
(...skipping 13 matching lines...) Expand all Loading... | |
31 } | 33 } |
32 | 34 |
33 PP_Var MediaStreamAudioTrackResource::GetId() { | 35 PP_Var MediaStreamAudioTrackResource::GetId() { |
34 return StringVar::StringToPPVar(id()); | 36 return StringVar::StringToPPVar(id()); |
35 } | 37 } |
36 | 38 |
37 PP_Bool MediaStreamAudioTrackResource::HasEnded() { | 39 PP_Bool MediaStreamAudioTrackResource::HasEnded() { |
38 return PP_FromBool(has_ended()); | 40 return PP_FromBool(has_ended()); |
39 } | 41 } |
40 | 42 |
41 int32_t MediaStreamAudioTrackResource::Configure( | 43 int32_t MediaStreamAudioTrackResource::Configure( |
Peng
2014/05/26 14:48:49
Add browser test please.
See ppapi/tests/test_medi
thembrown
2014/05/27 10:36:02
Done.
| |
42 const int32_t attrib_list[], | 44 const int32_t attrib_list[], |
43 scoped_refptr<TrackedCallback> callback) { | 45 scoped_refptr<TrackedCallback> callback) { |
44 // TODO(penghuang): Implement this function. | 46 if (has_ended()) |
45 return PP_ERROR_NOTSUPPORTED; | 47 return PP_ERROR_FAILED; |
48 | |
49 if (TrackedCallback::IsPending(configure_callback_) || | |
50 TrackedCallback::IsPending(get_buffer_callback_)) { | |
51 return PP_ERROR_INPROGRESS; | |
52 } | |
53 | |
54 // Do not support configure, if audio buffers are hold by plugin. | |
55 if (!buffers_.empty()) | |
56 return PP_ERROR_INPROGRESS; | |
57 | |
58 MediaStreamAudioTrackShared::Attributes attributes; | |
59 int i = 0; | |
60 for (; attrib_list[i] != PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE; i += 2) { | |
61 switch (attrib_list[i]) { | |
62 case PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS: | |
63 attributes.buffers = attrib_list[i + 1]; | |
64 break; | |
65 case PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_RATE: | |
66 case PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_SIZE: | |
67 case PP_MEDIASTREAMAUDIOTRACK_ATTRIB_CHANNELS: | |
68 case PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION: | |
69 return PP_ERROR_NOTSUPPORTED; | |
70 default: | |
71 return PP_ERROR_BADARGUMENT; | |
72 } | |
73 } | |
74 | |
75 if (!MediaStreamAudioTrackShared::VerifyAttributes(attributes)) | |
76 return PP_ERROR_BADARGUMENT; | |
77 | |
78 configure_callback_ = callback; | |
79 Call<PpapiPluginMsg_MediaStreamAudioTrack_ConfigureReply>( | |
80 RENDERER, | |
81 PpapiHostMsg_MediaStreamAudioTrack_Configure(attributes), | |
82 base::Bind(&MediaStreamAudioTrackResource::OnPluginMsgConfigureReply, | |
83 base::Unretained(this)), | |
84 callback); | |
85 return PP_OK_COMPLETIONPENDING; | |
46 } | 86 } |
47 | 87 |
48 int32_t MediaStreamAudioTrackResource::GetAttrib( | 88 int32_t MediaStreamAudioTrackResource::GetAttrib( |
49 PP_MediaStreamAudioTrack_Attrib attrib, | 89 PP_MediaStreamAudioTrack_Attrib attrib, |
50 int32_t* value) { | 90 int32_t* value) { |
51 // TODO(penghuang): Implement this function. | 91 // TODO(penghuang): Implement this function. |
52 return PP_ERROR_NOTSUPPORTED; | 92 return PP_ERROR_NOTSUPPORTED; |
53 } | 93 } |
54 | 94 |
55 int32_t MediaStreamAudioTrackResource::GetBuffer( | 95 int32_t MediaStreamAudioTrackResource::GetBuffer( |
56 PP_Resource* buffer, | 96 PP_Resource* buffer, |
57 scoped_refptr<TrackedCallback> callback) { | 97 scoped_refptr<TrackedCallback> callback) { |
58 if (has_ended()) | 98 if (has_ended()) |
59 return PP_ERROR_FAILED; | 99 return PP_ERROR_FAILED; |
60 | 100 |
61 if (TrackedCallback::IsPending(get_buffer_callback_)) | 101 if (TrackedCallback::IsPending(configure_callback_) || |
102 TrackedCallback::IsPending(get_buffer_callback_)) | |
62 return PP_ERROR_INPROGRESS; | 103 return PP_ERROR_INPROGRESS; |
63 | 104 |
64 *buffer = GetAudioBuffer(); | 105 *buffer = GetAudioBuffer(); |
65 if (*buffer) | 106 if (*buffer) |
66 return PP_OK; | 107 return PP_OK; |
67 | 108 |
68 // TODO(penghuang): Use the callback as hints to determine which thread will | 109 // TODO(penghuang): Use the callback as hints to determine which thread will |
69 // use the resource, so we could deliver buffers to the target thread directly | 110 // use the resource, so we could deliver buffers to the target thread directly |
70 // for better performance. | 111 // for better performance. |
71 get_buffer_output_ = buffer; | 112 get_buffer_output_ = buffer; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 void MediaStreamAudioTrackResource::ReleaseBuffers() { | 178 void MediaStreamAudioTrackResource::ReleaseBuffers() { |
138 BufferMap::iterator it = buffers_.begin(); | 179 BufferMap::iterator it = buffers_.begin(); |
139 while (it != buffers_.end()) { | 180 while (it != buffers_.end()) { |
140 // Just invalidate and release VideoBufferResorce, but keep PP_Resource. | 181 // Just invalidate and release VideoBufferResorce, but keep PP_Resource. |
141 // So plugin can still use |RecycleBuffer()|. | 182 // So plugin can still use |RecycleBuffer()|. |
142 it->second->Invalidate(); | 183 it->second->Invalidate(); |
143 it->second = NULL; | 184 it->second = NULL; |
144 } | 185 } |
145 } | 186 } |
146 | 187 |
188 void MediaStreamAudioTrackResource::OnPluginMsgConfigureReply( | |
189 const ResourceMessageReplyParams& params) { | |
190 if (TrackedCallback::IsPending(configure_callback_)) { | |
191 scoped_refptr<TrackedCallback> callback; | |
192 callback.swap(configure_callback_); | |
193 callback->Run(params.result()); | |
194 } | |
195 } | |
196 | |
147 } // namespace proxy | 197 } // namespace proxy |
148 } // namespace ppapi | 198 } // namespace ppapi |
OLD | NEW |