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.
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.
15 [channel=dev] M34 = 0.1
19 * This enumeration contains audio track attributes which are used by
20 * <code>Configure()</code>.
22 enum PP_MediaStreamAudioTrack_Attrib {
24 * Attribute list terminator.
26 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE = 0,
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.
36 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERED_FRAMES = 1,
39 * The sample rate of audio frames. The attribute value is a
40 * <code>PP_AudioFrame_SampleRate</code>.
42 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_RATE = 2,
45 * The sample size of audio frames in bytes. The attribute value is a
46 * <code>PP_AudioFrame_SampleSize</code>.
48 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_SAMPLE_SIZE = 3,
51 * The number of channels in audio frames.
53 * Supported values: 1, 2
55 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_CHANNELS = 4,
58 * The duration of audio frames in milliseconds.
60 * Valid range: 10 to 10000
62 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION = 5
65 interface PPB_MediaStreamAudioTrack {
67 * Determines if a resource is a MediaStream audio track resource.
69 * @param[in] resource The <code>PP_Resource</code> to test.
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>
75 PP_Bool IsMediaStreamAudioTrack([in] PP_Resource resource);
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
86 * Example usage from plugin 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);
95 * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
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>.
104 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
106 int32_t Configure([in] PP_Resource audio_track,
107 [in] int32_t[] attrib_list,
108 [in] PP_CompletionCallback callback);
111 * Gets attribute value for a given attribute name.
113 * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
115 * @param[in] attrib A <code>PP_MediaStreamAudioTrack_Attrib</code> for
117 * @param[out] value A int32_t for storing the attribute value on success.
118 * Otherwise, the value will not be changed.
120 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
122 int32_t GetAttrib([in] PP_Resource audio_track,
123 [in] PP_MediaStreamAudioTrack_Attrib attrib,
124 [out] int32_t value);
127 * Returns the track ID of the underlying MediaStream audio track.
129 * @param[in] audio_track The <code>PP_Resource</code> to check.
131 * @return A <code>PP_Var</code> containing the MediaStream track ID as
134 PP_Var GetId([in] PP_Resource audio_track);
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.
141 * @param[in] audio_track The <code>PP_Resource</code> to check.
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.
147 PP_Bool HasEnded([in] PP_Resource audio_track);
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
160 * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
162 * @param[out] frame A <code>PP_Resource</code> corresponding to an AudioFrame
164 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
165 * completion of GetFrame().
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.
171 int32_t GetFrame([in] PP_Resource audio_track,
172 [out] PP_Resource frame,
173 [in] PP_CompletionCallback callback);
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.
181 * @param[in] audio_track A <code>PP_Resource</code> corresponding to an audio
183 * @param[in] frame A <code>PP_Resource</code> corresponding to an AudioFrame
184 * resource returned by <code>GetFrame()</code>.
186 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
188 int32_t RecycleFrame([in] PP_Resource audio_track,
189 [in] PP_Resource frame);
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.
195 * @param[in] audio_track A <code>PP_Resource</code> corresponding to a
196 * MediaStream audio track resource.
198 void Close([in] PP_Resource audio_track);