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