680a61a307330c43a0d5237c964feea660c53d8c
[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 frames 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 frames to hold in the input buffer.
30    * Note: this is only used as advisory; the browser may allocate more or fewer
31    * based on available resources. How many frames to buffer depends on usage -
32    * request at least 2 to make sure latency doesn't cause lost frames. If
33    * the plugin expects to hold on to more than one frame at a time (e.g. to do
34    * multi-frame processing), it should request that many more.
35    */
36   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERED_FRAMES = 1,
37
38   /**
39    * The sample rate of audio frames. The attribute value is a
40    * <code>PP_AudioFrame_SampleRate</code>.
41    */
42   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_RATE = 2,
43
44   /**
45    * The sample size of audio frames in bytes. The attribute value is a
46    * <code>PP_AudioFrame_SampleSize</code>.
47    */
48   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_SIZE = 3,
49
50   /**
51    * The number of channels in audio frames.
52    *
53    * Supported values: 1, 2
54    */
55   PP_MEDIASTREAMAUDIOTRACK_ATTRIB_CHANNELS = 4,
56
57   /**
58    * The duration of audio frames 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 frame buffers for incoming frames.
79    * If the application doesn't want to drop frames, then the
80    * <code>PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERED_FRAMES</code> should be
81    * chosen such that inter-frame processing time variability won't overrun the
82    * input buffer. If the buffer is overfilled, then frames will be dropped.
83    * The application can detect this by examining the timestamp on returned
84    * frames. If <code>Configure()</code> is not called, default settings will be
85    * used.
86    * Example usage from plugin code:
87    * @code
88    * int32_t attribs[] = {
89    *     PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERED_FRAMES, 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 GetFrame 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 frame from the MediaStream track.
151    * If internal processing is slower than the incoming frame rate, new frames
152    * will be dropped from the incoming stream. Once the input buffer is full,
153    * frames will be dropped until <code>RecycleFrame()</code> is called to free
154    * a spot for another frame to be buffered.
155    * If there are no frames 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 frame is received or an
158    * error happens.
159    *
160    * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
161    * resource.
162    * @param[out] frame A <code>PP_Resource</code> corresponding to an AudioFrame
163    * resource.
164    * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
165    * completion of GetFrame().
166    *
167    * @return An int32_t containing a result code from <code>pp_errors.h</code>.
168    * Returns PP_ERROR_NOMEMORY if <code>max_buffered_frames</code> frames buffer
169    * was not allocated successfully.
170    */
171   int32_t GetFrame([in] PP_Resource audio_track,
172                    [out] PP_Resource frame,
173                    [in] PP_CompletionCallback callback);
174
175   /**
176    * Recycles a frame returned by <code>GetFrame()</code>, so the track can
177    * reuse the underlying buffer of this frame. And the frame will become
178    * invalid. The caller should release all references it holds to
179    * <code>frame</code> and not use it anymore.
180    *
181    * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
182    * resource.
183    * @param[in] frame A <code>PP_Resource</code> corresponding to an AudioFrame
184    * resource returned by <code>GetFrame()</code>.
185    *
186    * @return An int32_t containing a result code from <code>pp_errors.h</code>.
187    */
188   int32_t RecycleFrame([in] PP_Resource audio_track,
189                        [in] PP_Resource frame);
190
191   /**
192    * Closes the MediaStream audio track and disconnects it from the audio
193    * source. After calling <code>Close()</code>, no new frames will be received.
194    *
195    * @param[in] audio_track A <code>PP_Resource</code> corresponding to a
196    * MediaStream audio track resource.
197    */
198   void Close([in] PP_Resource audio_track);
199 };
200