Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: ppapi/c/ppb_audio.h

Issue 6502007: Rewrote/added documentation for audio (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ppapi/c/ppb_audio_config.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2011 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 #ifndef PPAPI_C_PPB_AUDIO_H_ 5 #ifndef PPAPI_C_PPB_AUDIO_H_
6 #define PPAPI_C_PPB_AUDIO_H_ 6 #define PPAPI_C_PPB_AUDIO_H_
7 7
8 #include "ppapi/c/pp_bool.h" 8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/c/pp_instance.h" 9 #include "ppapi/c/pp_instance.h"
10 #include "ppapi/c/pp_module.h" 10 #include "ppapi/c/pp_module.h"
11 #include "ppapi/c/pp_resource.h" 11 #include "ppapi/c/pp_resource.h"
12 #include "ppapi/c/pp_stdint.h" 12 #include "ppapi/c/pp_stdint.h"
13 13
14 #define PPB_AUDIO_INTERFACE "PPB_Audio;0.5" 14 #define PPB_AUDIO_INTERFACE "PPB_Audio;0.5"
15 15
16 /** 16 /**
17 * @file 17 * @file
18 * Defines the API ... 18 * This file defines the PPB_Audio interface for handling audio resources on
19 * the browser. Refer to the
20 * <a href="/chrome/nativeclient/docs/audio.html">Pepper Audio API Code
21 * Walkthrough</a> for information on using this interface.
19 */ 22 */
20 23
21 /** 24 /**
22 * @addtogroup Typedefs 25 * @addtogroup Typedefs
23 * @{ 26 * @{
24 */ 27 */
25 // Callback function type for SetCallback. 28
29 /**
30 * PPB_Audio_Callback defines the type of an audio callback function used to
31 * fill the audio buffer with data.
32 */
26 typedef void (*PPB_Audio_Callback)(void* sample_buffer, 33 typedef void (*PPB_Audio_Callback)(void* sample_buffer,
27 size_t buffer_size_in_bytes, 34 size_t buffer_size_in_bytes,
28 void* user_data); 35 void* user_data);
29 /** 36 /**
30 * @} 37 * @}
31 */ 38 */
32 39
33 /** 40 /**
34 * @addtogroup Structs 41 * @addtogroup Interfaces
35 * @{ 42 * @{
36 */ 43 */
37 // Callback-based audio interface. User of audio must set the callback that will 44 /**
38 // be called each time that the buffer needs to be filled. 45 * The PPB_Audio interface contains pointers to several functions for handling
39 // 46 * audio resources on the browser. This interface is a callback-based audio
40 // A C++ example: 47 * interface. Users of audio must set the callback that will be called each time
41 // 48 * that the buffer needs to be filled.
42 // void audio_callback(void* sample_buffer, 49 *
43 // size_t buffer_size_in_bytes, 50 * A C++ example:
44 // void* user_data) { 51 *
45 // ... fill in the buffer with samples ... 52 * void audio_callback(void* sample_buffer,
46 // } 53 * size_t buffer_size_in_bytes,
47 // 54 * void* user_data) {
48 // uint32_t obtained; 55 * ... fill in the buffer with samples ...
49 // AudioConfig config(PP_AUDIOSAMPLERATE_44100, 4096, &obtained); 56 * }
50 // Audio audio(config, audio_callback, NULL); 57 *
51 // audio.StartPlayback(); 58 * uint32_t obtained;
52 // 59 * AudioConfig config(PP_AUDIOSAMPLERATE_44100, 4096, &obtained);
60 * Audio audio(config, audio_callback, NULL);
61 * audio.StartPlayback();
62 */
53 struct PPB_Audio { 63 struct PPB_Audio {
54 // Creates a paused audio interface. No sound will be heard until 64 /**
55 // StartPlayback() is called. The callback is called with the buffer address 65 * Create is a pointer to a function that creates an audio resource.
56 // and given user data whenever the buffer needs to be filled. From within the 66 * No sound will be heard until StartPlayback() is called. The callback
57 // callback, you should not call PPB_Audio functions. The callback will be 67 * is called with the buffer address and given user data whenever the
58 // called on a different thread than the one which created the interface. For 68 * buffer needs to be filled. From within the callback, you should not
59 // performance-critical applications (i.e. low-latency audio), the callback 69 * call PPB_Audio functions. The callback will be called on a different
60 // should avoid blocking or calling functions that can obtain locks, such as 70 * thread than the one which created the interface. For performance-critical
61 // malloc. The layout and the size of the buffer passed to the audio callback 71 * applications (i.e. low-latency audio), the callback should avoid blocking
62 // will be determined by the device configuration and is specified in the 72 * or calling functions that can obtain locks, such as malloc. The layout and
63 // AudioConfig documentation. If the configuration cannot be honored, or the 73 * the size of the buffer passed to the audio callback will be determined by
64 // callback is null, the function returns 0. 74 * the device configuration and is specified in the AudioConfig documentation.
75 *
76 * @param[in] instance A PP_Instance indentifying one instance of a module.
77 * @param[in] config A PP_Resource containing the audio config resource.
78 * @param[in] audio_callback A PPB_Audio_Callback callback function that the
79 * browser calls when it needs more samples to play.
80 * @param[in] user_data A pointer to user data used in the callback function.
81 * @return A PP_Resource containing the audio resource if successful or
82 * 0 if the configuration cannot be honored or the callback is null.
83 */
65 PP_Resource (*Create)(PP_Instance instance, PP_Resource config, 84 PP_Resource (*Create)(PP_Instance instance, PP_Resource config,
66 PPB_Audio_Callback audio_callback, void* user_data); 85 PPB_Audio_Callback audio_callback, void* user_data);
67
68 /** 86 /**
69 * Returns PP_TRUE if the given resource is an Audio resource, PP_FALSE 87 * IsAudio is a pointer to a function that determines if the given
70 * otherwise. 88 * resource is an audio resource.
89 *
90 * @param[in] resource A PP_Resource containing a resource.
91 * @return A PP_BOOL containing containing PP_TRUE if the given resource is
92 * an Audio resource, otherwise PP_FALSE.
71 */ 93 */
72 PP_Bool (*IsAudio)(PP_Resource resource); 94 PP_Bool (*IsAudio)(PP_Resource resource);
73 95
74 // Get the current configuration. 96 /**
97 * GetCurrrentConfig is a pointer to a function that returns an audio config
98 * resource for the given audio resource.
99 *
100 * @param[in] config A PP_Resource containing the audio resource.
101 * @return A PP_Resource containing the audio config resource if successful.
102 */
75 PP_Resource (*GetCurrentConfig)(PP_Resource audio); 103 PP_Resource (*GetCurrentConfig)(PP_Resource audio);
76 104
77 // Start the playback. Begin periodically calling the callback. If called 105 /**
78 // while playback is already in progress, will return PP_TRUE and be a no-op. 106 * StartPlayback is a pointer to a function that starts the playback of
79 // On error, return PP_FALSE. 107 * the audio resource and begins periodically calling the callback.
108 *
109 * @param[in] config A PP_Resource containing the audio resource.
110 * @return A PP_BOOL containing PP_TRUE if successful, otherwise PP_FALSE.
111 * Also returns PP_TRUE (and be a no-op) if called while playback is already
112 * in progress.
113 */
80 PP_Bool (*StartPlayback)(PP_Resource audio); 114 PP_Bool (*StartPlayback)(PP_Resource audio);
81 115
82 // Stop the playback. If playback is already stopped, this is a no-op and 116 /**
83 // returns PP_TRUE. On error, returns PP_FALSE. If a callback is in progress, 117 * StopPlayback is a pointer to a function that stops the playback of
84 // StopPlayback will block until callback completes. 118 * the audio resource.
119 *
120 * @param[in] config A PP_Resource containing the audio resource.
121 * @return A PP_BOOL containing PP_TRUE if successful, otherwise PP_FALSE.
122 * Also returns PP_TRUE (and is a no-op) if called while playback is already
123 * stopped. If a callback is in progress, StopPlayback will block until the
124 * callback completes.
125 */
85 PP_Bool (*StopPlayback)(PP_Resource audio); 126 PP_Bool (*StopPlayback)(PP_Resource audio);
86 }; 127 };
87 /** 128 /**
88 * @} 129 * @}
89 */ 130 */
90 131
91 #endif /* PPAPI_C_PPB_DEVICE_CONTEXT_AUDIO_H_ */ 132 #endif /* PPAPI_C_PPB_DEVICE_CONTEXT_AUDIO_H_ */
92 133
OLDNEW
« no previous file with comments | « no previous file | ppapi/c/ppb_audio_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698