Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ppapi / cpp / media_stream_audio_track.h
blob19e76b84afc55c82ecbfe9d5c0e928fab2b4687c
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.
5 #ifndef PPAPI_CPP_MEDIA_STREAM_AUDIO_TRACK_H_
6 #define PPAPI_CPP_MEDIA_STREAM_AUDIO_TRACK_H_
8 #include <string>
10 #include "ppapi/c/ppb_media_stream_audio_track.h"
11 #include "ppapi/cpp/resource.h"
12 #include "ppapi/cpp/var.h"
14 /// @file
15 /// This file defines the <code>MediaStreamAudioTrack</code> interface for an
16 /// audio source resource, which receives audio buffers from a MediaStream audio
17 /// track in the browser.
19 namespace pp {
21 class AudioBuffer;
22 class CompletionCallback;
23 template <typename T> class CompletionCallbackWithOutput;
25 /// The <code>MediaStreamAudioTrack</code> class contains methods for
26 /// receiving audio buffers from a MediaStream audio track in the browser.
27 class MediaStreamAudioTrack : public Resource {
28 public:
29 /// Default constructor for creating an is_null()
30 /// <code>MediaStreamAudioTrack</code> object.
31 MediaStreamAudioTrack();
33 /// The copy constructor for <code>MediaStreamAudioTrack</code>.
34 ///
35 /// @param[in] other A reference to a <code>MediaStreamAudioTrack</code>.
36 MediaStreamAudioTrack(const MediaStreamAudioTrack& other);
38 /// Constructs a <code>MediaStreamAudioTrack</code> from
39 /// a <code>Resource</code>.
40 ///
41 /// @param[in] resource A <code>PPB_MediaStreamAudioTrack</code> resource.
42 explicit MediaStreamAudioTrack(const Resource& resource);
44 /// A constructor used when you have received a <code>PP_Resource</code> as a
45 /// return value that has had 1 ref added for you.
46 ///
47 /// @param[in] resource A <code>PPB_MediaStreamAudioTrack</code> resource.
48 MediaStreamAudioTrack(PassRef, PP_Resource resource);
50 ~MediaStreamAudioTrack();
52 /// Configures underlying buffer buffers for incoming audio samples.
53 /// If the application doesn't want to drop samples, then the
54 /// <code>PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS</code> should be
55 /// chosen such that inter-buffer processing time variability won't overrun
56 /// all input buffers. If all buffers are filled, then samples will be
57 /// dropped. The application can detect this by examining the timestamp on
58 /// returned buffers. If <code>Configure()</code> is not called, default
59 /// settings will be used.
60 /// Example usage from plugin code:
61 /// @code
62 /// int32_t attribs[] = {
63 /// PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, 4,
64 /// PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION, 10,
65 /// PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE};
66 /// track.Configure(attribs, callback);
67 /// @endcode
68 ///
69 /// @param[in] attrib_list A list of attribute name-value pairs in which each
70 /// attribute is immediately followed by the corresponding desired value.
71 /// The list is terminated by
72 /// <code>PP_MEDIASTREAMAUDIOTRACK_AUDIO_NONE</code>.
73 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
74 /// completion of <code>Configure()</code>.
75 ///
76 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
77 int32_t Configure(const int32_t attributes[],
78 const CompletionCallback& callback);
80 /// Gets attribute value for a given attribute name.
81 ///
82 /// @param[in] attrib A <code>PP_MediaStreamAudioTrack_Attrib</code> for
83 /// querying.
84 /// @param[out] value A int32_t for storing the attribute value.
85 ///
86 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
87 int32_t GetAttrib(PP_MediaStreamAudioTrack_Attrib attrib,
88 int32_t* value);
90 /// Returns the track ID of the underlying MediaStream audio track.
91 std::string GetId() const;
93 /// Checks whether the underlying MediaStream track has ended.
94 /// Calls to GetBuffer while the track has ended are safe to make and will
95 /// complete, but will fail.
96 bool HasEnded() const;
98 /// Gets the next audio buffer from the MediaStream track.
99 /// If internal processing is slower than the incoming buffer rate,
100 /// new buffers will be dropped from the incoming stream. Once all buffers
101 /// are full, audio samples will be dropped until <code>RecycleBuffer()</code>
102 /// is called to free a spot for another buffer.
103 /// If there are no audio data in the input buffer,
104 /// <code>PP_OK_COMPLETIONPENDING</code> will be returned immediately and the
105 /// <code>callback</code> will be called when a new buffer of audio samples
106 /// is received or some error happens.
108 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
109 /// called upon completion of <code>GetBuffer()</code>. If success,
110 /// an AudioBuffer will be passed into the completion callback function.
112 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
113 int32_t GetBuffer(
114 const CompletionCallbackWithOutput<AudioBuffer>& callback);
116 /// Recycles a buffer returned by <code>GetBuffer()</code>, so the track can
117 /// reuse the buffer. And the buffer will become invalid. The caller should
118 /// release all references it holds to <code>buffer</code> and not use it
119 /// anymore.
121 /// @param[in] buffer A AudioBuffer returned by <code>GetBuffer()</code>.
123 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
124 int32_t RecycleBuffer(const AudioBuffer& buffer);
126 /// Closes the MediaStream audio track, and disconnects it from the audio
127 /// source.
128 /// After calling <code>Close()</code>, no new buffers will be received.
129 void Close();
131 /// Checks whether a <code>Resource</code> is a MediaStream audio track,
132 /// to test whether it is appropriate for use with the
133 /// <code>MediaStreamAudioTrack</code> constructor.
135 /// @param[in] resource A <code>Resource</code> to test.
137 /// @return True if <code>resource</code> is a MediaStream audio track.
138 static bool IsMediaStreamAudioTrack(const Resource& resource);
141 } // namespace pp
143 #endif // PPAPI_CPP_MEDIA_STREAM_AUDIO_TRACK_H_