Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: media/audio/restartable_audio_output_device_impl.h

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

Powered by Google App Engine
This is Rietveld 408576698