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

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

Issue 2621993002: Makes AudioOutputProxy -> AudioOutputDispatcher reference weak. (Closed)
Patch Set: Created 3 years, 11 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
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 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_ 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h"
10 #include "base/threading/non_thread_safe.h" 11 #include "base/threading/non_thread_safe.h"
11 #include "media/audio/audio_io.h" 12 #include "media/audio/audio_io.h"
12 #include "media/base/audio_parameters.h" 13 #include "media/base/audio_parameters.h"
13 14
14 namespace media { 15 namespace media {
15 16
16 class AudioOutputDispatcher; 17 class AudioOutputDispatcher;
17 18
18 // AudioOutputProxy is an audio otput stream that uses resources more 19 // AudioOutputProxy is an audio otput stream that uses resources more
19 // efficiently than a regular audio output stream: it opens audio 20 // efficiently than a regular audio output stream: it opens audio
20 // device only when sound is playing, i.e. between Start() and Stop() 21 // device only when sound is playing, i.e. between Start() and Stop()
21 // (there is still one physical stream per each audio output proxy in 22 // (there is still one physical stream per each audio output proxy in
22 // playing state). 23 // playing state).
23 // 24 //
24 // AudioOutputProxy uses AudioOutputDispatcher to open and close 25 // AudioOutputProxy uses AudioOutputDispatcher to open and close
25 // physical output streams. 26 // physical output streams.
26 class MEDIA_EXPORT AudioOutputProxy 27 class MEDIA_EXPORT AudioOutputProxy
27 : public AudioOutputStream, 28 : public AudioOutputStream,
28 public NON_EXPORTED_BASE(base::NonThreadSafe) { 29 public NON_EXPORTED_BASE(base::NonThreadSafe) {
29 public: 30 public:
30 // Caller keeps ownership of |dispatcher|. 31 // Caller keeps ownership of |dispatcher|.
31 explicit AudioOutputProxy(AudioOutputDispatcher* dispatcher); 32 explicit AudioOutputProxy(base::WeakPtr<AudioOutputDispatcher> dispatcher);
32 33
33 // AudioOutputStream interface. 34 // AudioOutputStream interface.
34 bool Open() override; 35 bool Open() override;
35 void Start(AudioSourceCallback* callback) override; 36 void Start(AudioSourceCallback* callback) override;
36 void Stop() override; 37 void Stop() override;
37 void SetVolume(double volume) override; 38 void SetVolume(double volume) override;
38 void GetVolume(double* volume) override; 39 void GetVolume(double* volume) override;
39 void Close() override; 40 void Close() override;
40 41
41 AudioOutputDispatcher* get_dispatcher_for_testing() const { 42 AudioOutputDispatcher* get_dispatcher_for_testing() const {
42 return dispatcher_; 43 return dispatcher_.get();
43 } 44 }
44 45
45 private: 46 private:
46 enum State { 47 enum State {
47 kCreated, 48 kCreated,
48 kOpened, 49 kOpened,
49 kPlaying, 50 kPlaying,
50 kClosed, 51 kClosed,
51 kOpenError, 52 kOpenError,
52 kStartError, 53 kStartError,
53 }; 54 };
54 55
55 ~AudioOutputProxy() override; 56 ~AudioOutputProxy() override;
56 57
57 AudioOutputDispatcher* dispatcher_; 58 base::WeakPtr<AudioOutputDispatcher> dispatcher_;
58 State state_; 59 State state_;
59 60
60 // Need to save volume here, so that we can restore it in case the stream 61 // Need to save volume here, so that we can restore it in case the stream
61 // is stopped, and then started again. 62 // is stopped, and then started again.
62 double volume_; 63 double volume_;
63 64
64 DISALLOW_COPY_AND_ASSIGN(AudioOutputProxy); 65 DISALLOW_COPY_AND_ASSIGN(AudioOutputProxy);
65 }; 66 };
66 67
67 } // namespace media 68 } // namespace media
68 69
69 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_ 70 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698