OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_STREAM_SINK_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_STREAM_SINK_H_ |
| 7 |
| 8 #include "base/compiler_specific.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/synchronization/lock.h" |
| 11 #include "media/audio/audio_io.h" |
| 12 #include "media/base/audio_renderer_sink.h" |
| 13 #include "media/base/media_export.h" |
| 14 |
| 15 namespace media { |
| 16 |
| 17 // Wrapper which exposes the browser side audio interface (AudioOutputStream) as |
| 18 // if it were a renderer side audio interface (AudioRendererSink). Note: This |
| 19 // will not work for sandboxed renderers. |
| 20 // |
| 21 // TODO(dalecurtis): Delete this class once we have a proper mojo audio service. |
| 22 class MEDIA_EXPORT AudioOutputStreamSink |
| 23 : NON_EXPORTED_BASE(public AudioRendererSink), |
| 24 public AudioOutputStream::AudioSourceCallback { |
| 25 public: |
| 26 AudioOutputStreamSink(); |
| 27 |
| 28 // AudioRendererSink implementation. |
| 29 virtual void Initialize(const AudioParameters& params, |
| 30 RenderCallback* callback) override; |
| 31 virtual void Start() override; |
| 32 virtual void Stop() override; |
| 33 virtual void Pause() override; |
| 34 virtual void Play() override; |
| 35 virtual bool SetVolume(double volume) override; |
| 36 |
| 37 // AudioSourceCallback implementation. |
| 38 virtual int OnMoreData(AudioBus* dest, uint32 total_bytes_delay) override; |
| 39 virtual void OnError(AudioOutputStream* stream) override; |
| 40 |
| 41 private: |
| 42 virtual ~AudioOutputStreamSink(); |
| 43 |
| 44 // Helper methods for running AudioManager methods on the audio thread. |
| 45 void DoStart(); |
| 46 void DoStop(); |
| 47 void DoPause(); |
| 48 void DoPlay(); |
| 49 void DoSetVolume(double volume); |
| 50 |
| 51 // Clears |active_render_callback_| under lock, synchronously stopping render |
| 52 // callbacks from any thread. Must be called before Pause() and Stop() |
| 53 // trampoline to their helper methods on the audio thread. |
| 54 void ClearCallback(); |
| 55 |
| 56 // Parameters provided by Initialize(), cached for use on other threads. |
| 57 AudioParameters params_; |
| 58 |
| 59 // Since Initialize() is only called once for AudioRenderSinks, save the |
| 60 // callback both here and under |active_render_callback_| which will be |
| 61 // cleared during Pause() and Stop() to achieve "synchronous" stoppage. |
| 62 RenderCallback* render_callback_; |
| 63 |
| 64 // The task runner for the audio thread. |
| 65 const scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
| 66 |
| 67 // The actual AudioOutputStream, must only be accessed on the audio thread. |
| 68 AudioOutputStream* stream_; |
| 69 |
| 70 // Lock and callback for forwarding OnMoreData() calls into Render() calls. |
| 71 base::Lock callback_lock_; |
| 72 RenderCallback* active_render_callback_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(AudioOutputStreamSink); |
| 75 }; |
| 76 |
| 77 } // namepace media |
| 78 |
| 79 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_STREAM_SINK_H_ |
OLD | NEW |