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

Side by Side Diff: components/copresence/mediums/audio/audio_player.h

Issue 461803003: Stop playing/recording when not needed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_ 5 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_
6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_ 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "media/audio/audio_io.h" 14 #include "media/audio/audio_io.h"
15 15
16 namespace media { 16 namespace media {
17 class AudioBus; 17 class AudioBus;
18 class AudioBusRefCounted; 18 class AudioBusRefCounted;
19 } 19 }
20 20
21 namespace copresence { 21 namespace copresence {
22 22
23 // The AudioPlayer class will play a set of samples till it is told to stop. 23 // The AudioPlayer class will play a set of samples till it is told to stop.
24 class AudioPlayer : public media::AudioOutputStream::AudioSourceCallback { 24 class AudioPlayer : public media::AudioOutputStream::AudioSourceCallback {
25 public: 25 public:
26 AudioPlayer(); 26 AudioPlayer();
27 27
28 // Initializes the object. Do not use this object before calling this method. 28 // Initializes the object. Do not use this object before calling this method.
29 void Initialize(); 29 virtual void Initialize();
30 30
31 // Play the given samples. These samples will keep on being played in a loop 31 // Play the given samples. These samples will keep on being played in a loop
32 // till we explicitly tell the player to stop playing. 32 // till we explicitly tell the player to stop playing.
33 void Play(const scoped_refptr<media::AudioBusRefCounted>& samples); 33 virtual void Play(const scoped_refptr<media::AudioBusRefCounted>& samples);
34 34
35 // Stop playing. 35 // Stop playing.
36 void Stop(); 36 virtual void Stop();
37
38 virtual bool IsPlaying();
xiyuan 2014/08/12 18:57:50 nit: Make it a non-virtual accessor?
rkc 2014/08/13 00:29:00 Done.
37 39
38 // Cleans up and deletes this object. Do not use object after this call. 40 // Cleans up and deletes this object. Do not use object after this call.
39 void Finalize(); 41 virtual void Finalize();
40 42
41 // Takes ownership of the stream. 43 // Takes ownership of the stream.
42 void set_output_stream_for_testing( 44 void set_output_stream_for_testing(
43 media::AudioOutputStream* output_stream_for_testing) { 45 media::AudioOutputStream* output_stream_for_testing) {
44 output_stream_for_testing_.reset(output_stream_for_testing); 46 output_stream_for_testing_.reset(output_stream_for_testing);
45 } 47 }
46 48
49 protected:
50 virtual ~AudioPlayer();
51
52 bool is_playing_;
xiyuan 2014/08/12 18:57:50 nit: prefer to have protected setter accessor than
rkc 2014/08/13 00:29:00 Done.
53
47 private: 54 private:
48 friend class AudioPlayerTest; 55 friend class AudioPlayerTest;
49 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, BasicPlayAndStop); 56 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, BasicPlayAndStop);
50 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, OutOfOrderPlayAndStopMultiple); 57 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, OutOfOrderPlayAndStopMultiple);
51 58
52 virtual ~AudioPlayer();
53
54 // Methods to do our various operations; all of these need to be run on the 59 // Methods to do our various operations; all of these need to be run on the
55 // audio thread. 60 // audio thread.
56 void InitializeOnAudioThread(); 61 void InitializeOnAudioThread();
57 void PlayOnAudioThread( 62 void PlayOnAudioThread(
58 const scoped_refptr<media::AudioBusRefCounted>& samples); 63 const scoped_refptr<media::AudioBusRefCounted>& samples);
59 void StopOnAudioThread(); 64 void StopOnAudioThread();
60 void StopAndCloseOnAudioThread(); 65 void StopAndCloseOnAudioThread();
61 void FinalizeOnAudioThread(); 66 void FinalizeOnAudioThread();
62 67
63 // AudioOutputStream::AudioSourceCallback overrides: 68 // AudioOutputStream::AudioSourceCallback overrides:
64 // Following methods could be called from *ANY* thread. 69 // Following methods could be called from *ANY* thread.
65 virtual int OnMoreData(media::AudioBus* dest, 70 virtual int OnMoreData(media::AudioBus* dest,
66 media::AudioBuffersState /* state */) OVERRIDE; 71 media::AudioBuffersState /* state */) OVERRIDE;
67 virtual void OnError(media::AudioOutputStream* /* stream */) OVERRIDE; 72 virtual void OnError(media::AudioOutputStream* /* stream */) OVERRIDE;
68 73
69 // Flushes the audio loop, making sure that any queued operations are 74 // Flushes the audio loop, making sure that any queued operations are
70 // performed. 75 // performed.
71 void FlushAudioLoopForTesting(); 76 void FlushAudioLoopForTesting();
72 77
73 // Self-deleting object. 78 // Self-deleting object.
74 media::AudioOutputStream* stream_; 79 media::AudioOutputStream* stream_;
75 80
76 scoped_ptr<media::AudioOutputStream> output_stream_for_testing_; 81 scoped_ptr<media::AudioOutputStream> output_stream_for_testing_;
77 82
78 bool is_playing_;
79
80 // All fields below here are protected by this lock. 83 // All fields below here are protected by this lock.
81 base::Lock state_lock_; 84 base::Lock state_lock_;
82 85
83 scoped_refptr<media::AudioBusRefCounted> samples_; 86 scoped_refptr<media::AudioBusRefCounted> samples_;
84 87
85 // Index to the frame in the samples that we need to play next. 88 // Index to the frame in the samples that we need to play next.
86 int frame_index_; 89 int frame_index_;
87 90
88 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); 91 DISALLOW_COPY_AND_ASSIGN(AudioPlayer);
89 }; 92 };
90 93
91 } // namespace copresence 94 } // namespace copresence
92 95
93 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_ 96 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698