Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / ppapi / cpp / audio.h
bloba07fcf58067d0470de2131213bc2f86710401a35
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.
5 #ifndef PPAPI_CPP_AUDIO_H_
6 #define PPAPI_CPP_AUDIO_H_
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"
13 /// @file
14 /// This file defines the API to create realtime stereo audio streaming
15 /// capabilities.
17 namespace pp {
19 class InstanceHandle;
21 /// An audio resource. Refer to the
22 /// <a href="/native-client/devguide/coding/audio">Audio</a>
23 /// chapter in the Developer's Guide for information on using this interface.
24 class Audio : public Resource {
25 public:
27 /// An empty constructor for an Audio resource.
28 Audio() {}
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.
45 /// @param[in] config An <code>AudioConfig</code> containing the audio config
46 /// resource.
48 /// @param[in] callback A <code>PPB_Audio_Callback</code> callback function
49 /// that the browser calls when it needs more samples to play.
51 /// @param[in] user_data A pointer to user data used in the callback function.
52 Audio(const InstanceHandle& instance,
53 const AudioConfig& config,
54 PPB_Audio_Callback callback,
55 void* user_data);
57 /// Getter function for returning the internal <code>PPB_AudioConfig</code>
58 /// struct.
59 ///
60 /// @return A mutable reference to the PPB_AudioConfig struct.
61 AudioConfig& config() { return config_; }
63 /// Getter function for returning the internal <code>PPB_AudioConfig</code>
64 /// struct.
65 ///
66 /// @return A const reference to the internal <code>PPB_AudioConfig</code>
67 /// struct.
68 const AudioConfig& config() const { return config_; }
70 /// StartPlayback() starts playback of audio.
71 ///
72 /// @return true if successful, otherwise false.
73 bool StartPlayback();
75 /// StopPlayback stops playback of audio.
76 ///
77 /// @return true if successful, otherwise false.
78 bool StopPlayback();
80 private:
81 AudioConfig config_;
84 } // namespace pp
86 #endif // PPAPI_CPP_AUDIO_H_