| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016 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_RESTARTABLE_AUDIO_OUTPUT_DEVICE_IMPL_H_ |
| 6 #define MEDIA_AUDIO_RESTARTABLE_AUDIO_OUTPUT_DEVICE_IMPL_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "media/audio/audio_parameters.h" |
| 12 #include "media/base/audio_renderer_sink.h" |
| 13 #include "media/base/media_export.h" |
| 14 #include "media/base/output_device.h" |
| 15 |
| 16 // Adapter class to implement RestartableAudioOutputDevice interface on top of |
| 17 // AudioOutputDevice. Used by RestartableAudioOutputDeviceFactory to instanciate |
| 18 // the interface in cases when audio output should not go through |
| 19 // AudioRendererMixer (as opposite to AudioRendererMixerInput implementation of |
| 20 // the interface). |
| 21 // |
| 22 // Behavior differences from AudioOutputDevice: |
| 23 // (1) Restartable, i.e. Start() can be called again after Stop(). |
| 24 // - This is not utilized now, but implemented in order to be aligned with |
| 25 // AudioRendererMixerInput, which is a restartable sink. |
| 26 // (2) Does not play on start (similar to AudioRendererMixerInput) |
| 27 // (3) Play/Pause do not take an effect if Start() has not been called. |
| 28 // - Similar to AudioRendererMixerInput. |
| 29 // |
| 30 // Behaviour differences from AudioRendererMixerInput: |
| 31 // (1) SwitchOutputDevice() is not implemented. |
| 32 // - Used for media elements playout only, and there is not plan to use |
| 33 // RestartableAudioOutputDeviceImpl as a sink for their playout. |
| 34 namespace media { |
| 35 class AudioOutputDevice; |
| 36 |
| 37 class MEDIA_EXPORT RestartableAudioOutputDeviceImpl |
| 38 : public RestartableAudioRendererSink, |
| 39 public OutputDevice { |
| 40 public: |
| 41 // TODO(olka): If device switching needs to be supported, these callbacks |
| 42 // should receive session_id, device_id and security_origin as parameters. |
| 43 typedef base::Callback<scoped_refptr<AudioOutputDevice>()> GetSinkCB; |
| 44 typedef base::Callback<AudioParameters()> GetHWParamsCB; |
| 45 |
| 46 RestartableAudioOutputDeviceImpl(const GetSinkCB& get_sink_cb, |
| 47 const GetHWParamsCB& get_hw_params_cb); |
| 48 |
| 49 //----AudioRendererSink implementation. |
| 50 // NOTE: Clients must call Initialize() before starting it for the first time. |
| 51 // Calling Initialize() between Stop() and subsequent Start() is optional, |
| 52 void Initialize(const AudioParameters& params, |
| 53 RenderCallback* callback) override; |
| 54 void Start() override; |
| 55 void Stop() override; |
| 56 |
| 57 // Play/Pause take an effect only when the device is already started. This is |
| 58 // to copy AudioRendererMixerInput behavior. |
| 59 void Play() override; |
| 60 void Pause() override; |
| 61 |
| 62 bool SetVolume(double volume) override; |
| 63 OutputDevice* GetOutputDevice() override; |
| 64 |
| 65 //----OutputDevice implementation. |
| 66 AudioParameters GetOutputParameters() override; |
| 67 OutputDeviceStatus GetDeviceStatus() override; |
| 68 |
| 69 protected: |
| 70 // Magic required by ref_counted.h to avoid any code deleting the object |
| 71 // accidentally while there are references to it. |
| 72 friend class base::RefCountedThreadSafe<RestartableAudioOutputDeviceImpl>; |
| 73 ~RestartableAudioOutputDeviceImpl() override; |
| 74 |
| 75 private: |
| 76 // kStopped -> kStarted -> kPlaying <-> kPaused |
| 77 // ^ | | | |
| 78 // '-----------+-----------+-----------' |
| 79 enum State { kStopped = 0, kStarted, kPlaying, kPaused }; |
| 80 |
| 81 // Unsupported OutputDevice implementation |
| 82 void SwitchOutputDevice(const std::string& device_id, |
| 83 const url::Origin& security_origin, |
| 84 const SwitchOutputDeviceCB& callback) override; |
| 85 |
| 86 // Internal state. |
| 87 State state_; |
| 88 |
| 89 // Output volume. |
| 90 double volume_; |
| 91 |
| 92 // Output audio parameters. |
| 93 AudioParameters params_; |
| 94 |
| 95 // Source of audio data which is provided to the sink. |
| 96 AudioRendererSink::RenderCallback* render_cb_; |
| 97 |
| 98 // Factory callback to create a new sink, provided during construction. |
| 99 const GetSinkCB get_sink_cb_; |
| 100 |
| 101 // Callback to access hardware output parameters, provided during |
| 102 // construction. |
| 103 const GetHWParamsCB get_hw_params_cb_; |
| 104 |
| 105 scoped_refptr<AudioOutputDevice> sink_; |
| 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(RestartableAudioOutputDeviceImpl); |
| 108 }; |
| 109 |
| 110 } // namespace media |
| 111 |
| 112 #endif // MEDIA_AUDIO_RESTARTABLE_AUDIO_OUTPUT_DEVICE_IMPL_H_ |
| OLD | NEW |