Make sure webrtc::VideoSourceInterface is released on the main render thread.
[chromium-blink-merge.git] / ppapi / c / ppb_media_stream_audio_track.h
blob7eae9f3c1485a258cb82de2acaa7e7c52993f798
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 */
6 /* From ppb_media_stream_audio_track.idl modified Fri Mar 28 10:13:34 2014. */
8 #ifndef PPAPI_C_PPB_MEDIA_STREAM_AUDIO_TRACK_H_
9 #define PPAPI_C_PPB_MEDIA_STREAM_AUDIO_TRACK_H_
11 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_macros.h"
14 #include "ppapi/c/pp_resource.h"
15 #include "ppapi/c/pp_stdint.h"
16 #include "ppapi/c/pp_var.h"
18 #define PPB_MEDIASTREAMAUDIOTRACK_INTERFACE_0_1 "PPB_MediaStreamAudioTrack;0.1"
19 #define PPB_MEDIASTREAMAUDIOTRACK_INTERFACE \
20 PPB_MEDIASTREAMAUDIOTRACK_INTERFACE_0_1
22 /**
23 * @file
24 * Defines the <code>PPB_MediaStreamAudioTrack</code> interface. Used for
25 * receiving audio samples from a MediaStream audio track in the browser.
29 /**
30 * @addtogroup Enums
31 * @{
33 /**
34 * This enumeration contains audio track attributes which are used by
35 * <code>Configure()</code>.
37 typedef enum {
38 /**
39 * Attribute list terminator.
41 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE = 0,
42 /**
43 * The maximum number of buffers to hold audio samples.
44 * Note: this is only used as advisory; the browser may allocate more or fewer
45 * based on available resources. How many buffers depends on usage -
46 * request at least 2 to make sure latency doesn't cause lost samples. If
47 * the plugin expects to hold on to more than one buffer at a time (e.g. to do
48 * multi-buffer processing), it should request that many more.
50 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS = 1,
51 /**
52 * The sample rate of audio data in buffers. The attribute value is a
53 * <code>PP_AudioBuffer_SampleRate</code>.
55 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_RATE = 2,
56 /**
57 * The sample size of audio data in buffers in bytes. The attribute value is a
58 * <code>PP_AudioBuffer_SampleSize</code>.
60 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_SIZE = 3,
61 /**
62 * The number of channels in audio buffers.
64 * Supported values: 1, 2
66 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_CHANNELS = 4,
67 /**
68 * The duration of an audio buffer in milliseconds.
70 * Valid range: 10 to 10000
72 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION = 5
73 } PP_MediaStreamAudioTrack_Attrib;
74 /**
75 * @}
78 /**
79 * @addtogroup Interfaces
80 * @{
82 struct PPB_MediaStreamAudioTrack_0_1 {
83 /**
84 * Determines if a resource is a MediaStream audio track resource.
86 * @param[in] resource The <code>PP_Resource</code> to test.
88 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
89 * resource is a Mediastream audio track resource or <code>PP_FALSE</code>
90 * otherwise.
92 PP_Bool (*IsMediaStreamAudioTrack)(PP_Resource resource);
93 /**
94 * Configures underlying buffers for incoming audio samples.
95 * If the application doesn't want to drop samples, then the
96 * <code>PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS</code> should be
97 * chosen such that inter-buffer processing time variability won't overrun all
98 * the input buffers. If all buffers are filled, then samples will be
99 * dropped. The application can detect this by examining the timestamp on
100 * returned buffers. If <code>Configure()</code> is not called, default
101 * settings will be used.
102 * Example usage from plugin code:
103 * @code
104 * int32_t attribs[] = {
105 * PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, 4,
106 * PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION, 10,
107 * PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE};
108 * track_if->Configure(track, attribs, callback);
109 * @endcode
111 * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
112 * resource.
113 * @param[in] attrib_list A list of attribute name-value pairs in which each
114 * attribute is immediately followed by the corresponding desired value.
115 * The list is terminated by
116 * <code>PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE</code>.
117 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
118 * completion of <code>Configure()</code>.
120 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
122 int32_t (*Configure)(PP_Resource audio_track,
123 const int32_t attrib_list[],
124 struct PP_CompletionCallback callback);
126 * Gets attribute value for a given attribute name.
128 * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
129 * resource.
130 * @param[in] attrib A <code>PP_MediaStreamAudioTrack_Attrib</code> for
131 * querying.
132 * @param[out] value A int32_t for storing the attribute value on success.
133 * Otherwise, the value will not be changed.
135 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
137 int32_t (*GetAttrib)(PP_Resource audio_track,
138 PP_MediaStreamAudioTrack_Attrib attrib,
139 int32_t* value);
141 * Returns the track ID of the underlying MediaStream audio track.
143 * @param[in] audio_track The <code>PP_Resource</code> to check.
145 * @return A <code>PP_Var</code> containing the MediaStream track ID as
146 * a string.
148 struct PP_Var (*GetId)(PP_Resource audio_track);
150 * Checks whether the underlying MediaStream track has ended.
151 * Calls to GetBuffer while the track has ended are safe to make and will
152 * complete, but will fail.
154 * @param[in] audio_track The <code>PP_Resource</code> to check.
156 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
157 * MediaStream track has ended or <code>PP_FALSE</code> otherwise.
159 PP_Bool (*HasEnded)(PP_Resource audio_track);
161 * Gets the next audio buffer from the MediaStream track.
162 * If internal processing is slower than the incoming buffer rate, new buffers
163 * will be dropped from the incoming stream. Once all buffers are full,
164 * audio samples will be dropped until <code>RecycleBuffer()</code> is called
165 * to free a slot for another buffer.
166 * If there are no audio data in the input buffer,
167 * <code>PP_OK_COMPLETIONPENDING</code> will be returned immediately and the
168 * <code>callback</code> will be called, when a new buffer of audio samples
169 * is received or an error happens.
171 * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
172 * resource.
173 * @param[out] buffer A <code>PP_Resource</code> corresponding to
174 * an AudioBuffer resource.
175 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
176 * completion of GetBuffer().
178 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
180 int32_t (*GetBuffer)(PP_Resource audio_track,
181 PP_Resource* buffer,
182 struct PP_CompletionCallback callback);
184 * Recycles a buffer returned by <code>GetBuffer()</code>, so the track can
185 * reuse the buffer. And the buffer will become invalid. The caller should
186 * release all references it holds to <code>buffer</code> and not use it
187 * anymore.
189 * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
190 * resource.
191 * @param[in] buffer A <code>PP_Resource</code> corresponding to
192 * an AudioBuffer resource returned by <code>GetBuffer()</code>.
194 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
196 int32_t (*RecycleBuffer)(PP_Resource audio_track, PP_Resource buffer);
198 * Closes the MediaStream audio track and disconnects it from the audio
199 * source. After calling <code>Close()</code>, no new buffers will be
200 * received.
202 * @param[in] audio_track A <code>PP_Resource</code> corresponding to a
203 * MediaStream audio track resource.
205 void (*Close)(PP_Resource audio_track);
208 typedef struct PPB_MediaStreamAudioTrack_0_1 PPB_MediaStreamAudioTrack;
210 * @}
213 #endif /* PPAPI_C_PPB_MEDIA_STREAM_AUDIO_TRACK_H_ */