e1c27187029e588cec20deafb7677cda0065822f
[platform/framework/web/crosswalk.git] / src / ppapi / api / ppb_media_stream_audio_track.idl
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
6 /**
7  * Defines the <code>PPB_MediaStreamAudioTrack</code> interface. Used for
8  * receiving audio samples from a MediaStream audio track in the browser.
9  * This interface is still in development (Dev API status) and may change.
10  */
11
12 [generate_thunk]
13
14 label Chrome {
15   [channel=dev] M34 = 0.1
16 };
17
18 /**
19  * This enumeration contains audio track attributes which are used by
20  * <code>Configure()</code>.
21  */
22 enum PP_MediaStreamAudioTrack_Attrib {
23   /**
24    * Attribute list terminator.
25    */
26   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE = 0,
27
28   /**
29    * The maximum number of buffers to hold audio samples.
30    * Note: this is only used as advisory; the browser may allocate more or fewer
31    * based on available resources. How many buffers depends on usage -
32    * request at least 2 to make sure latency doesn't cause lost samples. If
33    * the plugin expects to hold on to more than one buffer at a time (e.g. to do
34    * multi-buffer processing), it should request that many more.
35    */
36   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS = 1,
37
38   /**
39    * The sample rate of audio data in buffers. The attribute value is a
40    * <code>PP_AudioBuffer_SampleRate</code>.
41    */
42   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_RATE = 2,
43
44   /**
45    * The sample size of audio data in buffers in bytes. The attribute value is a
46    * <code>PP_AudioBuffer_SampleSize</code>.
47    */
48   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_SIZE = 3,
49
50   /**
51    * The number of channels in audio buffers.
52    *
53    * Supported values: 1, 2
54    */
55   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_CHANNELS = 4,
56
57   /**
58    * The duration of an audio buffer in milliseconds.
59    *
60    * Valid range: 10 to 10000
61    */
62   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION = 5
63 };
64
65 interface PPB_MediaStreamAudioTrack {
66   /**
67    * Determines if a resource is a MediaStream audio track resource.
68    *
69    * @param[in] resource The <code>PP_Resource</code> to test.
70    *
71    * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
72    * resource is a Mediastream audio track resource or <code>PP_FALSE</code>
73    * otherwise.
74    */
75   PP_Bool IsMediaStreamAudioTrack([in] PP_Resource resource);
76
77   /**
78    * Configures underlying buffers for incoming audio samples.
79    * If the application doesn't want to drop samples, then the
80    * <code>PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS</code> should be
81    * chosen such that inter-buffer processing time variability won't overrun all
82    * the input buffers. If all buffers are filled, then samples will be
83    * dropped. The application can detect this by examining the timestamp on
84    * returned buffers. If <code>Configure()</code> is not called, default
85    * settings will be used.
86    * Example usage from plugin code:
87    * @code
88    * int32_t attribs[] = {
89    *     PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, 4,
90    *     PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION, 10,
91    *     PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE};
92    * track_if->Configure(track, attribs, callback);
93    * @endcode
94    *
95    * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
96    * resource.
97    * @param[in] attrib_list A list of attribute name-value pairs in which each
98    * attribute is immediately followed by the corresponding desired value.
99    * The list is terminated by
100    * <code>PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE</code>.
101    * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
102    * completion of <code>Configure()</code>.
103    *
104    * @return An int32_t containing a result code from <code>pp_errors.h</code>.
105    */
106   int32_t Configure([in] PP_Resource audio_track,
107                     [in] int32_t[] attrib_list,
108                     [in] PP_CompletionCallback callback);
109
110   /**
111    * Gets attribute value for a given attribute name.
112    *
113    * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
114    * resource.
115    * @param[in] attrib A <code>PP_MediaStreamAudioTrack_Attrib</code> for
116    * querying.
117    * @param[out] value A int32_t for storing the attribute value on success.
118    * Otherwise, the value will not be changed.
119    *
120    * @return An int32_t containing a result code from <code>pp_errors.h</code>.
121    */
122   int32_t GetAttrib([in] PP_Resource audio_track,
123                     [in] PP_MediaStreamAudioTrack_Attrib attrib,
124                     [out] int32_t value);
125
126   /**
127    * Returns the track ID of the underlying MediaStream audio track.
128    *
129    * @param[in] audio_track The <code>PP_Resource</code> to check.
130    *
131    * @return A <code>PP_Var</code> containing the MediaStream track ID as
132    * a string.
133    */
134   PP_Var GetId([in] PP_Resource audio_track);
135
136   /**
137    * Checks whether the underlying MediaStream track has ended.
138    * Calls to GetBuffer while the track has ended are safe to make and will
139    * complete, but will fail.
140    *
141    * @param[in] audio_track The <code>PP_Resource</code> to check.
142    *
143    * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
144    * MediaStream track has ended or <code>PP_FALSE</code> otherwise.
145    */
146   [on_failure=PP_TRUE]
147   PP_Bool HasEnded([in] PP_Resource audio_track);
148
149   /**
150    * Gets the next audio buffer from the MediaStream track.
151    * If internal processing is slower than the incoming buffer rate, new buffers
152    * will be dropped from the incoming stream. Once all buffers are full,
153    * audio samples will be dropped until <code>RecycleBuffer()</code> is called
154    * to free a slot for another buffer.
155    * If there are no audio data in the input buffer,
156    * <code>PP_OK_COMPLETIONPENDING</code> will be returned immediately and the
157    * <code>callback</code> will be called, when a new buffer of audio samples
158    * is received or an error happens.
159    *
160    * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
161    * resource.
162    * @param[out] buffer A <code>PP_Resource</code> corresponding to
163    * an AudioBuffer resource.
164    * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
165    * completion of GetBuffer().
166    *
167    * @return An int32_t containing a result code from <code>pp_errors.h</code>.
168    */
169   int32_t GetBuffer([in] PP_Resource audio_track,
170                     [out] PP_Resource buffer,
171                     [in] PP_CompletionCallback callback);
172
173   /**
174    * Recycles a buffer returned by <code>GetBuffer()</code>, so the track can
175    * reuse the buffer. And the buffer will become invalid. The caller should
176    * release all references it holds to <code>buffer</code> and not use it
177    * anymore.
178    *
179    * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
180    * resource.
181    * @param[in] buffer A <code>PP_Resource</code> corresponding to
182    * an AudioBuffer resource returned by <code>GetBuffer()</code>.
183    *
184    * @return An int32_t containing a result code from <code>pp_errors.h</code>.
185    */
186   int32_t RecycleBuffer([in] PP_Resource audio_track,
187                         [in] PP_Resource buffer);
188
189   /**
190    * Closes the MediaStream audio track and disconnects it from the audio
191    * source. After calling <code>Close()</code>, no new buffers will be
192    * received.
193    *
194    * @param[in] audio_track A <code>PP_Resource</code> corresponding to a
195    * MediaStream audio track resource.
196    */
197   void Close([in] PP_Resource audio_track);
198 };
199