OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_TRACK_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
11 #include "base/bind.h" | |
12 #include "base/callback.h" | 11 #include "base/callback.h" |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
15 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
16 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
17 #include "content/renderer/media/media_stream_audio_deliverer.h" | 16 #include "content/renderer/media/media_stream_audio_deliverer.h" |
18 #include "content/renderer/media/media_stream_track.h" | 17 #include "content/renderer/media/media_stream_track.h" |
19 | 18 |
20 namespace content { | 19 namespace content { |
21 | 20 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 65 |
67 // MediaStreamTrack override. | 66 // MediaStreamTrack override. |
68 void SetEnabled(bool enabled) override; | 67 void SetEnabled(bool enabled) override; |
69 void SetContentHint( | 68 void SetContentHint( |
70 blink::WebMediaStreamTrack::ContentHintType content_hint) override; | 69 blink::WebMediaStreamTrack::ContentHintType content_hint) override; |
71 | 70 |
72 // Returns a unique class identifier. Some subclasses override and use this | 71 // Returns a unique class identifier. Some subclasses override and use this |
73 // method to provide safe down-casting to their type. | 72 // method to provide safe down-casting to their type. |
74 virtual void* GetClassIdentifier() const; | 73 virtual void* GetClassIdentifier() const; |
75 | 74 |
76 void SetFormatConfiguredCallback(base::OnceCallback<void()> callback) { | |
77 base::AutoLock guard(format_set_guard_); | |
78 format_set_callback_ = std::move(callback); | |
79 } | |
80 | |
81 private: | 75 private: |
82 friend class MediaStreamAudioSource; | 76 friend class MediaStreamAudioSource; |
83 friend class MediaStreamAudioDeliverer<MediaStreamAudioTrack>; | 77 friend class MediaStreamAudioDeliverer<MediaStreamAudioTrack>; |
84 | 78 |
85 // Called by MediaStreamAudioSource to notify this track that the flow of | 79 // Called by MediaStreamAudioSource to notify this track that the flow of |
86 // audio data has started from the source. |stop_callback| is run by Stop() | 80 // audio data has started from the source. |stop_callback| is run by Stop() |
87 // when the source must halt the flow of audio data to this track. | 81 // when the source must halt the flow of audio data to this track. |
88 void Start(const base::Closure& stop_callback); | 82 void Start(const base::Closure& stop_callback); |
89 | 83 |
90 // Called by the MediaStreamAudioDeliverer to notify this track of an audio | 84 // Called by the MediaStreamAudioDeliverer to notify this track of an audio |
91 // format change. In turn, all MediaStreamAudioSinks will be notified before | 85 // format change. In turn, all MediaStreamAudioSinks will be notified before |
92 // the next chunk of audio is delivered to them. | 86 // the next chunk of audio is delivered to them. |
93 void OnSetFormat(const media::AudioParameters& params); | 87 void OnSetFormat(const media::AudioParameters& params); |
94 | 88 |
95 // Called by the MediaStreamAudioDeliverer to deliver audio data to this | 89 // Called by the MediaStreamAudioDeliverer to deliver audio data to this |
96 // track, which in turn delivers the audio to one or more | 90 // track, which in turn delivers the audio to one or more |
97 // MediaStreamAudioSinks. While this track is disabled, silent audio will be | 91 // MediaStreamAudioSinks. While this track is disabled, silent audio will be |
98 // delivered to the sinks instead of the content of |audio_bus|. | 92 // delivered to the sinks instead of the content of |audio_bus|. |
99 void OnData(const media::AudioBus& audio_bus, base::TimeTicks reference_time); | 93 void OnData(const media::AudioBus& audio_bus, base::TimeTicks reference_time); |
100 | 94 |
101 void getSettings(blink::WebMediaStreamTrack::Settings& settings) override; | 95 void getSettings(blink::WebMediaStreamTrack::Settings& settings) override; |
102 | 96 |
103 private: | 97 private: |
104 bool format_is_set(); | |
105 | |
106 // In debug builds, check that all methods that could cause object graph | 98 // In debug builds, check that all methods that could cause object graph |
107 // or data flow changes are being called on the main thread. | 99 // or data flow changes are being called on the main thread. |
108 base::ThreadChecker thread_checker_; | 100 base::ThreadChecker thread_checker_; |
109 | 101 |
110 // Callback provided to Start() which is run when the audio flow must halt. | 102 // Callback provided to Start() which is run when the audio flow must halt. |
111 base::Closure stop_callback_; | 103 base::Closure stop_callback_; |
112 | 104 |
113 // Manages sinks connected to this track and the audio format and data flow. | 105 // Manages sinks connected to this track and the audio format and data flow. |
114 MediaStreamAudioDeliverer<MediaStreamAudioSink> deliverer_; | 106 MediaStreamAudioDeliverer<MediaStreamAudioSink> deliverer_; |
115 | 107 |
116 // While false (0), silent audio is delivered to the sinks. | 108 // While false (0), silent audio is delivered to the sinks. |
117 base::subtle::Atomic32 is_enabled_; | 109 base::subtle::Atomic32 is_enabled_; |
118 | 110 |
119 // Buffer used to deliver silent audio data while this track is disabled. | 111 // Buffer used to deliver silent audio data while this track is disabled. |
120 std::unique_ptr<media::AudioBus> silent_bus_; | 112 std::unique_ptr<media::AudioBus> silent_bus_; |
121 | 113 |
122 // True if the track knows its configuration (OnSetFormat has been called). | |
123 bool format_is_set_ = false; | |
124 base::OnceCallback<void()> format_set_callback_; | |
125 base::Lock format_set_guard_; | |
126 | |
127 // Provides weak pointers that are valid until Stop() is called. | 114 // Provides weak pointers that are valid until Stop() is called. |
128 base::WeakPtrFactory<MediaStreamAudioTrack> weak_factory_; | 115 base::WeakPtrFactory<MediaStreamAudioTrack> weak_factory_; |
129 | 116 |
130 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); | 117 DISALLOW_COPY_AND_ASSIGN(MediaStreamAudioTrack); |
131 }; | 118 }; |
132 | 119 |
133 } // namespace content | 120 } // namespace content |
134 | 121 |
135 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ | 122 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_TRACK_H_ |
OLD | NEW |