| Index: media/audio/restartable_audio_output_device_impl.h
|
| diff --git a/media/audio/restartable_audio_output_device_impl.h b/media/audio/restartable_audio_output_device_impl.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f014553d11aee68c984b343d2a1ffcb25ea897c8
|
| --- /dev/null
|
| +++ b/media/audio/restartable_audio_output_device_impl.h
|
| @@ -0,0 +1,110 @@
|
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef MEDIA_AUDIO_RESTARTABLE_AUDIO_OUTPUT_DEVICE_IMPL_H_
|
| +#define MEDIA_AUDIO_RESTARTABLE_AUDIO_OUTPUT_DEVICE_IMPL_H_
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "media/audio/audio_parameters.h"
|
| +#include "media/base/media_export.h"
|
| +#include "media/base/restartable_audio_output_device.h"
|
| +
|
| +// Adapter class to implement RestartableAudioOutputDevice interface on top of
|
| +// AudioOutputDevice. Used by RestartableAudioOutputDeviceFactory to instanciate
|
| +// the interface in cases when audio output should not go through
|
| +// AudioRendererMixer (as opposite to AudioRendererMixerInput implementation of
|
| +// the interface).
|
| +//
|
| +// Behavior differences from AudioOutputDevice:
|
| +// (1) Restartable, i.e. Start() can be called again after Stop().
|
| +// - This is not utilized now, but implemented in order to be aligned with
|
| +// AudioRendererMixerInput, which is a restartable sink.
|
| +// (2) Does not play on start (similar to AudioRendererMixerInput)
|
| +// (3) Play/Pause do not take an effect if Start() has not been called.
|
| +// - Similar to AudioRendererMixerInput.
|
| +//
|
| +// Behaviour differences from AudioRendererMixerInput:
|
| +// (1) SwitchOutputDevice() is not implemented.
|
| +// - Used for media elements playout only, and there is not plan to use
|
| +// RestartableAudioOutputDeviceImpl as a sink for their playout.
|
| +namespace media {
|
| +class AudioOutputDevice;
|
| +
|
| +class MEDIA_EXPORT RestartableAudioOutputDeviceImpl
|
| + : public RestartableAudioOutputDevice {
|
| + public:
|
| + // TODO(olka): If device switching needs to be supported, these callbacks
|
| + // should receive session_id, device_id and security_origin as parameters.
|
| + typedef base::Callback<scoped_refptr<AudioOutputDevice>()> GetSinkCB;
|
| + typedef base::Callback<AudioParameters()> GetHWParamsCB;
|
| +
|
| + RestartableAudioOutputDeviceImpl(const GetSinkCB& get_sink_cb,
|
| + const GetHWParamsCB& get_hw_params_cb);
|
| +
|
| + //----AudioRendererSink implementation.
|
| + // NOTE: Clients must call Initialize() before starting it for the first time.
|
| + // Calling Initialize() between Stop() and subsequent Start() is optional,
|
| + void Initialize(const AudioParameters& params,
|
| + RenderCallback* callback) override;
|
| + void Start() override;
|
| + void Stop() override;
|
| +
|
| + // Play/Pause take an effect only when the device is already started. This is
|
| + // to copy AudioRendererMixerInput behavior.
|
| + void Play() override;
|
| + void Pause() override;
|
| +
|
| + bool SetVolume(double volume) override;
|
| + OutputDevice* GetOutputDevice() override;
|
| +
|
| + //----OutputDevice implementation.
|
| + AudioParameters GetOutputParameters() override;
|
| + OutputDeviceStatus GetDeviceStatus() override;
|
| +
|
| + protected:
|
| + // Magic required by ref_counted.h to avoid any code deleting the object
|
| + // accidentally while there are references to it.
|
| + friend class base::RefCountedThreadSafe<RestartableAudioOutputDeviceImpl>;
|
| + ~RestartableAudioOutputDeviceImpl() override;
|
| +
|
| + private:
|
| + // kStopped -> kStarted -> kPlaying <-> kPaused
|
| + // ^ | | |
|
| + // '-----------+-----------+-----------'
|
| + enum State { kStopped = 0, kStarted, kPlaying, kPaused };
|
| +
|
| + // Unsupported OutputDevice implementation
|
| + void SwitchOutputDevice(const std::string& device_id,
|
| + const url::Origin& security_origin,
|
| + const SwitchOutputDeviceCB& callback) override;
|
| +
|
| + // Internal state.
|
| + State state_;
|
| +
|
| + // Output volume.
|
| + double volume_;
|
| +
|
| + // Output audio parameters.
|
| + AudioParameters params_;
|
| +
|
| + // Source of audio data which is provided to the sink.
|
| + AudioRendererSink::RenderCallback* render_cb_;
|
| +
|
| + // Factory callback to create a new sink, provided during construction.
|
| + const GetSinkCB get_sink_cb_;
|
| +
|
| + // Callback to access hardware output parameters, provided during
|
| + // construction.
|
| + const GetHWParamsCB get_hw_params_cb_;
|
| +
|
| + scoped_refptr<AudioOutputDevice> sink_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(RestartableAudioOutputDeviceImpl);
|
| +};
|
| +
|
| +} // namespace media
|
| +
|
| +#endif // MEDIA_AUDIO_RESTARTABLE_AUDIO_OUTPUT_DEVICE_IMPL_H_
|
|
|