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

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

Issue 637223011: Redesign the copresence audio handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 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 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_H_ 5 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_IMPL_H_
6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_ 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_IMPL_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 "components/copresence/mediums/audio/audio_player.h"
14 #include "media/audio/audio_io.h" 15 #include "media/audio/audio_io.h"
15 16
16 namespace media { 17 namespace media {
17 class AudioBus; 18 class AudioBus;
18 class AudioBusRefCounted; 19 class AudioBusRefCounted;
19 } 20 }
20 21
21 namespace copresence { 22 namespace copresence {
22 23
23 // The AudioPlayer class will play a set of samples till it is told to stop. 24 // The AudioPlayerImpl class will play a set of samples till it is told to stop.
24 class AudioPlayer : public media::AudioOutputStream::AudioSourceCallback { 25 class AudioPlayerImpl final
26 : public AudioPlayer,
27 public media::AudioOutputStream::AudioSourceCallback {
25 public: 28 public:
26 AudioPlayer(); 29 AudioPlayerImpl();
27 30
28 // Initializes the object. Do not use this object before calling this method. 31 // AudioPlayer overrides:
29 virtual void Initialize(); 32 virtual void Initialize() override;
Daniel Erat 2014/10/22 16:34:35 nit: remove 'virtual' for all of these too since y
rkc 2014/10/22 18:21:48 Done.
30 33 virtual void Play(
31 // Play the given samples. These samples will keep on being played in a loop 34 const scoped_refptr<media::AudioBusRefCounted>& samples) override;
32 // till we explicitly tell the player to stop playing. 35 virtual void Stop() override;
33 virtual void Play(const scoped_refptr<media::AudioBusRefCounted>& samples); 36 virtual void Finalize() override;
34 37 virtual bool IsPlaying() override;
35 // Stop playing.
36 virtual void Stop();
37
38 // Cleans up and deletes this object. Do not use object after this call.
39 virtual void Finalize();
40
41 bool IsPlaying();
42 38
43 // Takes ownership of the stream. 39 // Takes ownership of the stream.
44 void set_output_stream_for_testing( 40 void set_output_stream_for_testing(
45 media::AudioOutputStream* output_stream_for_testing) { 41 media::AudioOutputStream* output_stream_for_testing) {
46 output_stream_for_testing_.reset(output_stream_for_testing); 42 output_stream_for_testing_.reset(output_stream_for_testing);
47 } 43 }
48 44
49 protected:
50 virtual ~AudioPlayer();
51 void set_is_playing(bool is_playing) { is_playing_ = is_playing; }
52
53 private: 45 private:
54 friend class AudioPlayerTest; 46 friend class AudioPlayerTest;
55 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, BasicPlayAndStop); 47 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, BasicPlayAndStop);
56 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, OutOfOrderPlayAndStopMultiple); 48 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, OutOfOrderPlayAndStopMultiple);
57 49
50 virtual ~AudioPlayerImpl();
51
58 // Methods to do our various operations; all of these need to be run on the 52 // Methods to do our various operations; all of these need to be run on the
59 // audio thread. 53 // audio thread.
60 void InitializeOnAudioThread(); 54 void InitializeOnAudioThread();
61 void PlayOnAudioThread( 55 void PlayOnAudioThread(
62 const scoped_refptr<media::AudioBusRefCounted>& samples); 56 const scoped_refptr<media::AudioBusRefCounted>& samples);
63 void StopOnAudioThread(); 57 void StopOnAudioThread();
64 void StopAndCloseOnAudioThread(); 58 void StopAndCloseOnAudioThread();
65 void FinalizeOnAudioThread(); 59 void FinalizeOnAudioThread();
66 60
67 // AudioOutputStream::AudioSourceCallback overrides: 61 // AudioOutputStream::AudioSourceCallback overrides:
(...skipping 14 matching lines...) Expand all
82 scoped_ptr<media::AudioOutputStream> output_stream_for_testing_; 76 scoped_ptr<media::AudioOutputStream> output_stream_for_testing_;
83 77
84 // All fields below here are protected by this lock. 78 // All fields below here are protected by this lock.
85 base::Lock state_lock_; 79 base::Lock state_lock_;
86 80
87 scoped_refptr<media::AudioBusRefCounted> samples_; 81 scoped_refptr<media::AudioBusRefCounted> samples_;
88 82
89 // Index to the frame in the samples that we need to play next. 83 // Index to the frame in the samples that we need to play next.
90 int frame_index_; 84 int frame_index_;
91 85
92 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); 86 DISALLOW_COPY_AND_ASSIGN(AudioPlayerImpl);
93 }; 87 };
94 88
95 } // namespace copresence 89 } // namespace copresence
96 90
97 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_H_ 91 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698