Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | #ifndef PPAPI_CPP_AUDIO_H_ |
| 6 | #define PPAPI_CPP_AUDIO_H_ |
| 7 | |
| 8 | #include "ppapi/c/pp_stdint.h" |
| 9 | #include "ppapi/c/ppb_audio.h" |
| 10 | #include "ppapi/cpp/audio_config.h" |
| 11 | #include "ppapi/cpp/resource.h" |
| 12 | |
| 13 | /// @file |
| 14 | /// This file defines the API to create realtime stereo audio streaming |
| 15 | /// capabilities. |
| 16 | |
| 17 | namespace pp { |
| 18 | |
| 19 | class InstanceHandle; |
| 20 | |
| 21 | /// An audio resource. Refer to the |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 22 | /// <a href="/native-client/devguide/coding/audio.html">Audio</a> |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 23 | /// chapter in the Developer's Guide for information on using this interface. |
| 24 | class Audio : public Resource { |
| 25 | public: |
| 26 | |
| 27 | /// An empty constructor for an Audio resource. |
| 28 | Audio() {} |
| 29 | |
| 30 | /// A constructor that creates an Audio resource. No sound will be heard |
| 31 | /// until StartPlayback() is called. The callback is called with the buffer |
| 32 | /// address and given user data whenever the buffer needs to be filled. |
| 33 | /// From within the callback, you should not call <code>PPB_Audio</code> |
| 34 | /// functions. The callback will be called on a different thread than the one |
| 35 | /// which created the interface. For performance-critical applications (such |
| 36 | /// as low-latency audio), the callback should avoid blocking or calling |
| 37 | /// functions that can obtain locks, such as malloc. The layout and the size |
| 38 | /// of the buffer passed to the audio callback will be determined by |
| 39 | /// the device configuration and is specified in the <code>AudioConfig</code> |
| 40 | /// documentation. |
| 41 | /// |
| 42 | /// @param[in] instance The instance with which this resource will be |
| 43 | /// associated. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 44 | /// @param[in] config An <code>AudioConfig</code> containing the audio config |
| 45 | /// resource. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 46 | /// @param[in] callback A <code>PPB_Audio_Callback</code> callback function |
| 47 | /// that the browser calls when it needs more samples to play. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 48 | /// @param[in] user_data A pointer to user data used in the callback function. |
| 49 | Audio(const InstanceHandle& instance, |
| 50 | const AudioConfig& config, |
| 51 | PPB_Audio_Callback callback, |
| 52 | void* user_data); |
| 53 | |
Torne (Richard Coles) | 58537e2 | 2013-09-12 12:10:22 +0100 | [diff] [blame] | 54 | /// A constructor that creates an Audio resource. |
| 55 | /// |
| 56 | /// @param[in] instance The instance with which this resource will be |
| 57 | /// associated. |
| 58 | /// @param[in] config An <code>AudioConfig</code> containing the audio config |
| 59 | /// resource. |
| 60 | /// @param[in] callback A <code>PPB_Audio_Callback_1_0</code> callback |
| 61 | /// function that the browser calls when it needs more samples to play. |
| 62 | /// @param[in] user_data A pointer to user data used in the callback function. |
| 63 | Audio(const InstanceHandle& instance, |
| 64 | const AudioConfig& config, |
| 65 | PPB_Audio_Callback_1_0 callback, |
| 66 | void* user_data); |
| 67 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 68 | /// Getter function for returning the internal <code>PPB_AudioConfig</code> |
| 69 | /// struct. |
| 70 | /// |
| 71 | /// @return A mutable reference to the PPB_AudioConfig struct. |
| 72 | AudioConfig& config() { return config_; } |
| 73 | |
| 74 | /// Getter function for returning the internal <code>PPB_AudioConfig</code> |
| 75 | /// struct. |
| 76 | /// |
| 77 | /// @return A const reference to the internal <code>PPB_AudioConfig</code> |
| 78 | /// struct. |
| 79 | const AudioConfig& config() const { return config_; } |
| 80 | |
| 81 | /// StartPlayback() starts playback of audio. |
| 82 | /// |
| 83 | /// @return true if successful, otherwise false. |
| 84 | bool StartPlayback(); |
| 85 | |
| 86 | /// StopPlayback stops playback of audio. |
| 87 | /// |
| 88 | /// @return true if successful, otherwise false. |
| 89 | bool StopPlayback(); |
| 90 | |
| 91 | private: |
| 92 | AudioConfig config_; |
Torne (Richard Coles) | 58537e2 | 2013-09-12 12:10:22 +0100 | [diff] [blame] | 93 | bool use_1_0_interface_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | } // namespace pp |
| 97 | |
| 98 | #endif // PPAPI_CPP_AUDIO_H_ |
| 99 | |