| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_TRACK_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_TRACK_H_ |
| 7 | |
| 8 #include <list> | |
| 9 #include <string> | |
| 10 | 7 |
| 11 #include "base/macros.h" | 8 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 13 #include "base/synchronization/lock.h" | 10 #include "content/renderer/media/media_stream_audio_level_calculator.h" |
| 14 #include "base/threading/thread_checker.h" | 11 #include "content/renderer/media/media_stream_audio_processor.h" |
| 15 #include "content/renderer/media/media_stream_audio_track.h" | 12 #include "content/renderer/media/media_stream_audio_track.h" |
| 16 #include "content/renderer/media/tagged_list.h" | |
| 17 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | |
| 18 #include "media/audio/audio_parameters.h" | |
| 19 | |
| 20 namespace media { | |
| 21 class AudioBus; | |
| 22 } | |
| 23 | 13 |
| 24 namespace content { | 14 namespace content { |
| 25 | 15 |
| 26 class MediaStreamAudioLevelCalculator; | 16 class WebRtcLocalAudioTrackAdapter; |
| 27 class MediaStreamAudioProcessor; | |
| 28 class MediaStreamAudioSink; | |
| 29 class MediaStreamAudioSinkOwner; | |
| 30 class MediaStreamAudioTrackSink; | |
| 31 | 17 |
| 32 // A WebRtcLocalAudioTrack manages thread-safe connects/disconnects to sinks, | 18 // A MediaStreamAudioTrack that also holds a WebRtcLocalAudioTrackAdapter and |
| 33 // and the delivery of audio data from the source to the sinks. | 19 // provides an "adapter" bridge between the media stream object graph in the |
| 34 class CONTENT_EXPORT WebRtcLocalAudioTrack | 20 // content namespace and the separate object graph in the webrtc namespace. |
| 21 // |
| 22 // This class is instantiated by ProcessLocalAudioSource. |
| 23 class CONTENT_EXPORT ProcessedLocalAudioTrack final |
| 35 : NON_EXPORTED_BASE(public MediaStreamAudioTrack) { | 24 : NON_EXPORTED_BASE(public MediaStreamAudioTrack) { |
| 36 public: | 25 public: |
| 37 explicit WebRtcLocalAudioTrack( | 26 explicit ProcessedLocalAudioTrack( |
| 38 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter); | 27 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter); |
| 39 | 28 |
| 40 ~WebRtcLocalAudioTrack() override; | 29 ~ProcessedLocalAudioTrack() final; |
| 41 | 30 |
| 42 // Add a sink to the track. This function will trigger a OnSetFormat() | 31 // If |track| is an instance of ProcessedLocalAudioTrack, return a type-casted |
| 43 // call on the |sink|. | 32 // pointer to it. Otherwise, return null. |
| 44 // Called on the main render thread. | 33 static ProcessedLocalAudioTrack* From(MediaStreamAudioTrack* track); |
| 45 void AddSink(MediaStreamAudioSink* sink) override; | |
| 46 | 34 |
| 47 // Remove a sink from the track. | 35 const scoped_refptr<WebRtcLocalAudioTrackAdapter>& adapter() const { |
| 48 // Called on the main render thread. | 36 return adapter_; |
| 49 void RemoveSink(MediaStreamAudioSink* sink) override; | 37 } |
| 50 | 38 |
| 51 // Overrides for MediaStreamTrack. | 39 // Override for MediaStreamTrack. |
| 52 void SetEnabled(bool enabled) override; | 40 void SetEnabled(bool enabled) final; |
| 53 webrtc::AudioTrackInterface* GetAudioAdapter() override; | |
| 54 media::AudioParameters GetOutputFormat() const override; | |
| 55 | |
| 56 // Method called by the capturer to deliver the capture data. | |
| 57 // Called on the capture audio thread. | |
| 58 void Capture(const media::AudioBus& audio_bus, | |
| 59 base::TimeTicks estimated_capture_time); | |
| 60 | |
| 61 // Method called by the capturer to set the audio parameters used by source | |
| 62 // of the capture data.. | |
| 63 // Called on the capture audio thread. | |
| 64 void OnSetFormat(const media::AudioParameters& params); | |
| 65 | 41 |
| 66 // Called by the capturer before the audio data flow begins to set the object | 42 // Called by the capturer before the audio data flow begins to set the object |
| 67 // that provides shared access to the current audio signal level. | 43 // that provides shared access to the current audio signal level. |
| 68 void SetLevel(scoped_refptr<MediaStreamAudioLevelCalculator::Level> level); | 44 void SetLevel(scoped_refptr<MediaStreamAudioLevelCalculator::Level> level); |
| 69 | 45 |
| 70 // Called by the capturer before the audio data flow begins to provide a | 46 // Called by the capturer before the audio data flow begins to provide a |
| 71 // reference to the audio processor so that the track can query stats from it. | 47 // reference to the audio processor so that the track can query stats from it. |
| 72 void SetAudioProcessor(scoped_refptr<MediaStreamAudioProcessor> processor); | 48 void SetAudioProcessor(scoped_refptr<MediaStreamAudioProcessor> processor); |
| 73 | 49 |
| 74 private: | 50 private: |
| 75 typedef TaggedList<MediaStreamAudioTrackSink> SinkList; | |
| 76 | |
| 77 // MediaStreamAudioTrack override. | 51 // MediaStreamAudioTrack override. |
| 78 void OnStop() final; | 52 void* GetClassIdentifier() const final; |
| 79 | 53 |
| 80 // All usage of libjingle is through this adapter. The adapter holds | 54 // All usage of libjingle is through this adapter. The adapter holds |
| 81 // a pointer to this object, but no reference. | 55 // a pointer to this object, but no reference. |
| 82 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_; | 56 const scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_; |
| 83 | 57 |
| 84 // A tagged list of sinks that the audio data is fed to. Tags | 58 DISALLOW_COPY_AND_ASSIGN(ProcessedLocalAudioTrack); |
| 85 // indicate tracks that need to be notified that the audio format | |
| 86 // has changed. | |
| 87 SinkList sinks_; | |
| 88 | |
| 89 // Tests that methods are called on libjingle's signaling thread. | |
| 90 base::ThreadChecker signal_thread_checker_; | |
| 91 | |
| 92 // Used to DCHECK that some methods are called on the capture audio thread. | |
| 93 base::ThreadChecker capture_thread_checker_; | |
| 94 | |
| 95 // Protects |params_| and |sinks_|. | |
| 96 mutable base::Lock lock_; | |
| 97 | |
| 98 // Audio parameters of the audio capture stream. | |
| 99 media::AudioParameters audio_parameters_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(WebRtcLocalAudioTrack); | |
| 102 }; | 59 }; |
| 103 | 60 |
| 104 } // namespace content | 61 } // namespace content |
| 105 | 62 |
| 106 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_LOCAL_AUDIO_TRACK_H_ | 63 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PROCESSED_LOCAL_AUDIO_TRACK_H_ |
| OLD | NEW |