Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / public / renderer / media_stream_audio_sink.h
blob862c32baa68adbe7b213ce1ce3e22c9158a4eb0b
1 // Copyright 2013 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 CONTENT_PUBLIC_RENDERER_MEDIA_STREAM_AUDIO_SINK_H_
6 #define CONTENT_PUBLIC_RENDERER_MEDIA_STREAM_AUDIO_SINK_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/time/time.h"
12 #include "content/common/content_export.h"
13 #include "content/public/renderer/media_stream_sink.h"
15 namespace blink {
16 class WebMediaStreamTrack;
19 namespace media {
20 class AudioBus;
21 class AudioParameters;
24 namespace content {
26 class CONTENT_EXPORT MediaStreamAudioSink : public MediaStreamSink {
27 public:
28 // Adds a MediaStreamAudioSink to the audio track to receive audio data from
29 // the track.
30 // Called on the main render thread.
31 static void AddToAudioTrack(MediaStreamAudioSink* sink,
32 const blink::WebMediaStreamTrack& track);
34 // Removes a MediaStreamAudioSink from the audio track to stop receiving
35 // audio data from the track.
36 // Called on the main render thread.
37 static void RemoveFromAudioTrack(MediaStreamAudioSink* sink,
38 const blink::WebMediaStreamTrack& track);
40 // Returns the format of the audio track.
41 // Called on the main render thread.
42 static media::AudioParameters GetFormatFromAudioTrack(
43 const blink::WebMediaStreamTrack& track);
45 // Callback called to deliver audio data. The data in |audio_bus| respects the
46 // AudioParameters passed in the last call to OnSetFormat(). Called on
47 // real-time audio thread.
49 // |estimated_capture_time| is the local time at which the first sample frame
50 // in |audio_bus| either: 1) was generated, if it was done so locally; or 2)
51 // should be targeted for play-out, if it was generated from a remote
52 // source. Either way, an implementation should not play-out the audio before
53 // this point-in-time. This value is NOT a high-resolution timestamp, and so
54 // it should not be used as a presentation time; but, instead, it should be
55 // used for buffering playback and for A/V synchronization purposes.
56 virtual void OnData(const media::AudioBus& audio_bus,
57 base::TimeTicks estimated_capture_time) = 0;
59 // Callback called when the format of the audio stream has changed. This is
60 // always called at least once before OnData(), and on the same thread.
61 virtual void OnSetFormat(const media::AudioParameters& params) = 0;
63 protected:
64 ~MediaStreamAudioSink() override {}
67 } // namespace content
69 #endif // CONTENT_PUBLIC_RENDERER_MEDIA_STREAM_AUDIO_SINK_H_