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. 4 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_SINK_H_ 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_SINK_H_ 7 8 #include <vector> 9 10 #include "base/logging.h" 11 #include "base/memory/ref_counted.h" 12 #include "media/audio/audio_parameters.h" 13 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 14 15 namespace content { 16 17 class MediaStreamAudioSink; 18 class PeerConnectionAudioSink; 19 20 // Interface for reference counted holder of audio stream audio track sink. 21 class MediaStreamAudioTrackSink 22 : public base::RefCountedThreadSafe<MediaStreamAudioTrackSink> { 23 public: 24 virtual int OnData(const int16* audio_data, 25 int sample_rate, 26 int number_of_channels, 27 int number_of_frames, 28 const std::vector<int>& channels, 29 int audio_delay_milliseconds, 30 int current_volume, 31 bool need_audio_processing, 32 bool key_pressed) = 0; 33 34 virtual void OnSetFormat(const media::AudioParameters& params) = 0; 35 36 virtual void OnReadyStateChanged( 37 blink::WebMediaStreamSource::ReadyState state) = 0; 38 39 virtual void Reset() = 0; 40 41 virtual bool IsEqual(const MediaStreamAudioSink* other) const = 0; 42 virtual bool IsEqual(const PeerConnectionAudioSink* other) const = 0; 43 44 // Wrapper which allows to use std::find_if() when adding and removing 45 // sinks to/from the list. 46 struct WrapsMediaStreamSink { 47 WrapsMediaStreamSink(MediaStreamAudioSink* sink) : sink_(sink) {} 48 bool operator()( 49 const scoped_refptr<MediaStreamAudioTrackSink>& owner) const { 50 return owner->IsEqual(sink_); 51 } 52 MediaStreamAudioSink* sink_; 53 }; 54 struct WrapsPeerConnectionSink { 55 WrapsPeerConnectionSink(PeerConnectionAudioSink* sink) : sink_(sink) {} 56 bool operator()( 57 const scoped_refptr<MediaStreamAudioTrackSink>& owner) const { 58 return owner->IsEqual(sink_); 59 } 60 PeerConnectionAudioSink* sink_; 61 }; 62 63 protected: 64 virtual ~MediaStreamAudioTrackSink() {} 65 66 private: 67 friend class base::RefCountedThreadSafe<MediaStreamAudioTrackSink>; 68 }; 69 70 } // namespace content 71 72 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_SINK_H_ 73