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

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

Issue 12383016: Merge AssociateStreamWithProducer message into CreateStream message for both audio output and input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_input_ipc.h ('k') | media/audio/audio_output_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Audio rendering unit utilizing audio output stream provided by browser 5 // Audio rendering unit utilizing audio output stream provided by browser
6 // process through IPC. 6 // process through IPC.
7 // 7 //
8 // Relationship of classes. 8 // Relationship of classes.
9 // 9 //
10 // AudioOutputController AudioOutputDevice 10 // AudioOutputController AudioOutputDevice
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "media/audio/audio_device_thread.h" 67 #include "media/audio/audio_device_thread.h"
68 #include "media/audio/audio_output_ipc.h" 68 #include "media/audio/audio_output_ipc.h"
69 #include "media/audio/audio_parameters.h" 69 #include "media/audio/audio_parameters.h"
70 #include "media/audio/scoped_loop_observer.h" 70 #include "media/audio/scoped_loop_observer.h"
71 #include "media/base/audio_renderer_sink.h" 71 #include "media/base/audio_renderer_sink.h"
72 72
73 namespace media { 73 namespace media {
74 74
75 class MEDIA_EXPORT AudioOutputDevice 75 class MEDIA_EXPORT AudioOutputDevice
76 : NON_EXPORTED_BASE(public AudioRendererSink), 76 : NON_EXPORTED_BASE(public AudioRendererSink),
77 public AudioOutputIPCDelegate, 77 NON_EXPORTED_BASE(public AudioOutputIPCDelegate),
78 NON_EXPORTED_BASE(public ScopedLoopObserver) { 78 NON_EXPORTED_BASE(public ScopedLoopObserver) {
79 public: 79 public:
80 // NOTE: Clients must call Initialize() before using.
81 AudioOutputDevice(scoped_ptr<AudioOutputIPC> ipc,
82 const scoped_refptr<base::MessageLoopProxy>& io_loop);
83
80 // AudioRendererSink implementation. 84 // AudioRendererSink implementation.
81 virtual void Initialize(const AudioParameters& params, 85 virtual void Initialize(const AudioParameters& params,
82 RenderCallback* callback) OVERRIDE; 86 RenderCallback* callback) OVERRIDE;
83 virtual void Start() OVERRIDE; 87 virtual void Start() OVERRIDE;
84 virtual void Stop() OVERRIDE; 88 virtual void Stop() OVERRIDE;
85 virtual void Play() OVERRIDE; 89 virtual void Play() OVERRIDE;
86 virtual void Pause() OVERRIDE; 90 virtual void Pause() OVERRIDE;
87 virtual bool SetVolume(double volume) OVERRIDE; 91 virtual bool SetVolume(double volume) OVERRIDE;
88 92
89 // Methods called on IO thread ---------------------------------------------- 93 // Methods called on IO thread ----------------------------------------------
90 // AudioOutputIPCDelegate methods. 94 // AudioOutputIPCDelegate methods.
91 virtual void OnStateChanged(AudioOutputIPCDelegate::State state) OVERRIDE; 95 virtual void OnStateChanged(AudioOutputIPCDelegate::State state) OVERRIDE;
92 virtual void OnStreamCreated(base::SharedMemoryHandle handle, 96 virtual void OnStreamCreated(base::SharedMemoryHandle handle,
93 base::SyncSocket::Handle socket_handle, 97 base::SyncSocket::Handle socket_handle,
94 int length) OVERRIDE; 98 int length) OVERRIDE;
95 virtual void OnIPCClosed() OVERRIDE; 99 virtual void OnIPCClosed() OVERRIDE;
96 100
97 // Creates an uninitialized AudioOutputDevice. Clients must call Initialize()
98 // before using.
99 AudioOutputDevice(AudioOutputIPC* ipc,
100 const scoped_refptr<base::MessageLoopProxy>& io_loop);
101
102 protected: 101 protected:
103 // Magic required by ref_counted.h to avoid any code deleting the object 102 // Magic required by ref_counted.h to avoid any code deleting the object
104 // accidentally while there are references to it. 103 // accidentally while there are references to it.
105 friend class base::RefCountedThreadSafe<AudioOutputDevice>; 104 friend class base::RefCountedThreadSafe<AudioOutputDevice>;
106 virtual ~AudioOutputDevice(); 105 virtual ~AudioOutputDevice();
107 106
108 // Accessors for subclasses (via IO thread only).
109 int stream_id() const { return stream_id_; }
110 AudioOutputIPC* audio_output_ipc() const { return ipc_; }
111
112 private: 107 private:
113 // Note: The ordering of members in this enum is critical to correct behavior! 108 // Note: The ordering of members in this enum is critical to correct behavior!
114 enum State { 109 enum State {
115 IPC_CLOSED, // No more IPCs can take place. 110 IPC_CLOSED, // No more IPCs can take place.
116 IDLE, // Not started. 111 IDLE, // Not started.
117 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. 112 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back.
118 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). 113 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop().
119 PLAYING, // Playing back. Can Pause()/Stop(). 114 PLAYING, // Playing back. Can Pause()/Stop().
120 }; 115 };
121 116
122 // Methods called on IO thread ---------------------------------------------- 117 // Methods called on IO thread ----------------------------------------------
123 // The following methods are tasks posted on the IO thread that needs to 118 // The following methods are tasks posted on the IO thread that need to
124 // be executed on that thread. They interact with AudioMessageFilter and 119 // be executed on that thread. They use AudioOutputIPC to send IPC messages
125 // sends IPC messages on that thread. 120 // upon state changes.
126 void CreateStreamOnIOThread(const AudioParameters& params); 121 void CreateStreamOnIOThread(const AudioParameters& params);
127 void PlayOnIOThread(); 122 void PlayOnIOThread();
128 void PauseOnIOThread(); 123 void PauseOnIOThread();
129 void ShutDownOnIOThread(); 124 void ShutDownOnIOThread();
130 void SetVolumeOnIOThread(double volume); 125 void SetVolumeOnIOThread(double volume);
131 126
132 // MessageLoop::DestructionObserver implementation for the IO loop. 127 // MessageLoop::DestructionObserver implementation for the IO loop.
133 // If the IO loop dies before we do, we shut down the audio thread from here. 128 // If the IO loop dies before we do, we shut down the audio thread from here.
134 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 129 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
135 130
136 AudioParameters audio_parameters_; 131 AudioParameters audio_parameters_;
137 132
138 RenderCallback* callback_; 133 RenderCallback* callback_;
139 134
140 // A pointer to the IPC layer that takes care of sending requests over to 135 // A pointer to the IPC layer that takes care of sending requests over to
141 // the AudioRendererHost. 136 // the AudioRendererHost. Only valid when state_ != IPC_CLOSED and must only
142 AudioOutputIPC* ipc_; 137 // be accessed on the IO thread.
143 138 scoped_ptr<AudioOutputIPC> ipc_;
144 // Our stream ID on the message filter. Only accessed on the IO thread.
145 // Must only be modified on the IO thread.
146 int stream_id_;
147 139
148 // Current state (must only be accessed from the IO thread). See comments for 140 // Current state (must only be accessed from the IO thread). See comments for
149 // State enum above. 141 // State enum above.
150 State state_; 142 State state_;
151 143
152 // State of Play() / Pause() calls before OnStreamCreated() is called. 144 // State of Play() / Pause() calls before OnStreamCreated() is called.
153 bool play_on_start_; 145 bool play_on_start_;
154 146
155 // Our audio thread callback class. See source file for details. 147 // Our audio thread callback class. See source file for details.
156 class AudioThreadCallback; 148 class AudioThreadCallback;
(...skipping 11 matching lines...) Expand all
168 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept 160 // TODO(scherkus): Replace this by changing AudioRendererSink to either accept
169 // the callback via Start(). See http://crbug.com/151051 for details. 161 // the callback via Start(). See http://crbug.com/151051 for details.
170 bool stopping_hack_; 162 bool stopping_hack_;
171 163
172 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice); 164 DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice);
173 }; 165 };
174 166
175 } // namespace media 167 } // namespace media
176 168
177 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_ 169 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_
OLDNEW
« no previous file with comments | « media/audio/audio_input_ipc.h ('k') | media/audio/audio_output_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698