| 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 CHROME_RENDERER_MEDIA_CAST_RECEIVER_AUDIO_VALVE_H_ | 5 #ifndef CHROME_RENDERER_MEDIA_CAST_RECEIVER_AUDIO_VALVE_H_ |
| 6 #define CHROME_RENDERER_MEDIA_CAST_RECEIVER_AUDIO_VALVE_H_ | 6 #define CHROME_RENDERER_MEDIA_CAST_RECEIVER_AUDIO_VALVE_H_ |
| 7 | 7 |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "base/time/time.h" |
| 9 #include "media/base/audio_capturer_source.h" | 10 #include "media/base/audio_capturer_source.h" |
| 11 #include "media/base/audio_push_fifo.h" |
| 10 | 12 |
| 11 namespace media { | 13 namespace media { |
| 12 class AudioBus; | 14 class AudioBus; |
| 13 } | 15 } |
| 14 | 16 |
| 15 // Forwards calls to |cb| until Stop is called. | 17 // Forwards calls to |cb| until Stop is called. If the client requested a |
| 18 // different buffer size than that provided by the Cast Receiver, AudioPushFifo |
| 19 // is used to rectify that. |
| 20 // |
| 16 // Thread-safe. | 21 // Thread-safe. |
| 17 // All functions may block depending on contention. | 22 // All functions may block depending on contention. |
| 18 class CastReceiverAudioValve : | 23 class CastReceiverAudioValve : |
| 19 public media::AudioCapturerSource::CaptureCallback, | |
| 20 public base::RefCountedThreadSafe<CastReceiverAudioValve> { | 24 public base::RefCountedThreadSafe<CastReceiverAudioValve> { |
| 21 public: | 25 public: |
| 22 explicit CastReceiverAudioValve( | 26 CastReceiverAudioValve(const media::AudioParameters& params, |
| 23 media::AudioCapturerSource::CaptureCallback* cb); | 27 media::AudioCapturerSource::CaptureCallback* cb); |
| 24 | 28 |
| 25 // AudioCapturerSource::CaptureCallback implementation. | 29 // Called on an unknown thread to provide more decoded audio data from the |
| 26 void Capture(const media::AudioBus* audio_source, | 30 // Cast Receiver. |
| 27 int audio_delay_milliseconds, | 31 void DeliverDecodedAudio(const media::AudioBus* audio_bus, |
| 28 double volume, | 32 base::TimeTicks playout_time); |
| 29 bool key_pressed) override; | |
| 30 void OnCaptureError(const std::string& message) override; | |
| 31 | 33 |
| 32 // When this returns, no more calls will be forwarded to |cb|. | 34 // When this returns, no more calls will be forwarded to |cb|. |
| 33 void Stop(); | 35 void Stop(); |
| 34 | 36 |
| 35 private: | 37 private: |
| 36 friend class base::RefCountedThreadSafe<CastReceiverAudioValve>; | 38 friend class base::RefCountedThreadSafe<CastReceiverAudioValve>; |
| 37 ~CastReceiverAudioValve() override; | 39 |
| 40 ~CastReceiverAudioValve(); |
| 41 |
| 42 // Called by AudioPushFifo zero or more times during the call to Capture(). |
| 43 // Delivers audio data in the required buffer size to |cb_|. |
| 44 void DeliverRebufferedAudio(const media::AudioBus& audio_bus, |
| 45 int frame_offset); |
| 46 |
| 38 media::AudioCapturerSource::CaptureCallback* cb_; | 47 media::AudioCapturerSource::CaptureCallback* cb_; |
| 39 base::Lock lock_; | 48 base::Lock lock_; |
| 49 |
| 50 media::AudioPushFifo fifo_; |
| 51 const int sample_rate_; |
| 52 |
| 53 // Used to pass the current playout time between DeliverDecodedAudio() and |
| 54 // DeviliverRebufferedAudio(). |
| 55 base::TimeTicks current_playout_time_; |
| 40 }; | 56 }; |
| 41 | 57 |
| 42 #endif // CHROME_RENDERER_MEDIA_CAST_RECEIVER_AUDIO_VALVE_H_ | 58 #endif // CHROME_RENDERER_MEDIA_CAST_RECEIVER_AUDIO_VALVE_H_ |
| OLD | NEW |