| 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 CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/renderer/media/media_stream_audio_deliverer.h" | 15 #include "content/renderer/media/media_stream_audio_deliverer.h" |
| 16 #include "content/renderer/media/media_stream_source.h" | 16 #include "content/renderer/media/media_stream_source.h" |
| 17 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 17 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 19 | 19 |
| 20 namespace base { |
| 21 class SingleThreadTaskRunner; |
| 22 } |
| 23 |
| 20 namespace content { | 24 namespace content { |
| 21 | 25 |
| 22 class MediaStreamAudioTrack; | 26 class MediaStreamAudioTrack; |
| 23 | 27 |
| 24 // Represents a source of audio, and manages the delivery of audio data between | 28 // Represents a source of audio, and manages the delivery of audio data between |
| 25 // the source implementation and one or more MediaStreamAudioTracks. This is a | 29 // the source implementation and one or more MediaStreamAudioTracks. This is a |
| 26 // base class providing all the necessary functionality to connect tracks and | 30 // base class providing all the necessary functionality to connect tracks and |
| 27 // have audio data delivered to them. Subclasses provide the actual audio source | 31 // have audio data delivered to them. Subclasses provide the actual audio source |
| 28 // implementation (e.g., media::AudioCapturerSource), and should implement the | 32 // implementation (e.g., media::AudioCapturerSource), and should implement the |
| 29 // EnsureSourceIsStarted() and EnsureSourceIsStopped() methods, and call | 33 // EnsureSourceIsStarted() and EnsureSourceIsStopped() methods, and call |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // source to the sinks. This may be called at any time, before or after | 120 // source to the sinks. This may be called at any time, before or after |
| 117 // tracks have been connected; but must be called at least once before | 121 // tracks have been connected; but must be called at least once before |
| 118 // DeliverDataToTracks(). This method is thread-safe. | 122 // DeliverDataToTracks(). This method is thread-safe. |
| 119 void SetFormat(const media::AudioParameters& params); | 123 void SetFormat(const media::AudioParameters& params); |
| 120 | 124 |
| 121 // Called by subclasses to deliver audio data to the currently-connected | 125 // Called by subclasses to deliver audio data to the currently-connected |
| 122 // tracks. This method is thread-safe. | 126 // tracks. This method is thread-safe. |
| 123 void DeliverDataToTracks(const media::AudioBus& audio_bus, | 127 void DeliverDataToTracks(const media::AudioBus& audio_bus, |
| 124 base::TimeTicks reference_time); | 128 base::TimeTicks reference_time); |
| 125 | 129 |
| 130 // Called by subclasses when capture error occurs. |
| 131 // Note: This can be called on any thread, and will post a task to the main |
| 132 // thread to stop the source soon. |
| 133 void StopSourceOnError(const std::string& why); |
| 134 |
| 126 private: | 135 private: |
| 127 // MediaStreamSource override. | 136 // MediaStreamSource override. |
| 128 void DoStopSource() final; | 137 void DoStopSource() final; |
| 129 | 138 |
| 130 // Removes |track| from the list of instances that get a copy of the source | 139 // Removes |track| from the list of instances that get a copy of the source |
| 131 // audio data. The "stop callback" that was provided to the track calls | 140 // audio data. The "stop callback" that was provided to the track calls |
| 132 // this. | 141 // this. |
| 133 void StopAudioDeliveryTo(MediaStreamAudioTrack* track); | 142 void StopAudioDeliveryTo(MediaStreamAudioTrack* track); |
| 134 | 143 |
| 135 // True if the source of audio is a local device. False if the source is | 144 // True if the source of audio is a local device. False if the source is |
| 136 // remote (e.g., streamed-in from a server). | 145 // remote (e.g., streamed-in from a server). |
| 137 const bool is_local_source_; | 146 const bool is_local_source_; |
| 138 | 147 |
| 139 // In debug builds, check that all methods that could cause object graph | |
| 140 // or data flow changes are being called on the main thread. | |
| 141 base::ThreadChecker thread_checker_; | |
| 142 | |
| 143 // Set to true once this source has been permanently stopped. | 148 // Set to true once this source has been permanently stopped. |
| 144 bool is_stopped_; | 149 bool is_stopped_; |
| 145 | 150 |
| 146 // Manages tracks connected to this source and the audio format and data flow. | 151 // Manages tracks connected to this source and the audio format and data flow. |
| 147 MediaStreamAudioDeliverer<MediaStreamAudioTrack> deliverer_; | 152 MediaStreamAudioDeliverer<MediaStreamAudioTrack> deliverer_; |
| 148 | 153 |
| 154 // The task runner for main thread. Also used to check that all methods that |
| 155 // could cause object graph or data flow changes are being called on the main |
| 156 // thread. |
| 157 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 158 |
| 149 // Provides weak pointers so that MediaStreamAudioTracks won't call | 159 // Provides weak pointers so that MediaStreamAudioTracks won't call |
| 150 // StopAudioDeliveryTo() if this instance dies first. | 160 // StopAudioDeliveryTo() if this instance dies first. |
| 151 base::WeakPtrFactory<MediaStreamAudioSource> weak_factory_; | 161 base::WeakPtrFactory<MediaStreamAudioSource> weak_factory_; |
| 152 | 162 |
| 153 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioSource); | 163 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioSource); |
| 154 }; | 164 }; |
| 155 | 165 |
| 156 } // namespace content | 166 } // namespace content |
| 157 | 167 |
| 158 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ | 168 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_SOURCE_H_ |
| OLD | NEW |