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