OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_ | |
6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/gtest_prod_util.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/synchronization/lock.h" | |
14 #include "media/audio/audio_io.h" | |
15 | |
16 namespace media { | |
17 class AudioBus; | |
18 class AudioBusRefCounted; | |
19 } | |
20 | |
21 namespace copresence { | |
22 | |
23 // The AudioPlayer class will play a set of samples till it is told to stop. | |
24 class AudioPlayer : public media::AudioOutputStream::AudioSourceCallback { | |
25 public: | |
26 AudioPlayer(); | |
27 | |
28 // This constructor is only for testing. | |
29 explicit AudioPlayer(media::AudioOutputStream* output_stream_for_testing); | |
Daniel Erat
2014/07/28 21:18:18
document ownership of the stream
rkc
2014/07/29 00:33:35
Done.
| |
30 | |
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. | |
33 void Play(const scoped_refptr<media::AudioBusRefCounted>& samples); | |
34 // Stop playing. | |
35 void Stop(); | |
36 | |
37 // Cleans up and deletes this object. Do not use object after this call. | |
38 void Finalize(); | |
39 | |
40 private: | |
41 friend class AudioPlayerTest; | |
42 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, BasicPlayAndStop); | |
43 FRIEND_TEST_ALL_PREFIXES(AudioPlayerTest, OutOfOrderPlayAndStopMultiple); | |
44 | |
45 virtual ~AudioPlayer(); | |
46 | |
47 // Methods to do our various operations; all of these need to be run on the | |
48 // audio thread. | |
49 void InitializeOnAudioThread(); | |
50 void PlayOnAudioThread( | |
51 const scoped_refptr<media::AudioBusRefCounted>& samples); | |
52 void StopOnAudioThread(); | |
53 void StopAndCloseOnAudioThread(); | |
54 void FinalizeOnAudioThread(); | |
55 | |
56 // AudioOutputStream::AudioSourceCallback overrides: | |
57 // Following methods could be called from *ANY* thread. | |
58 virtual int OnMoreData(media::AudioBus* dest, | |
59 media::AudioBuffersState /* state */) OVERRIDE; | |
60 virtual void OnError(media::AudioOutputStream* /* stream */) OVERRIDE; | |
61 | |
62 // These are used by unit tests, do NOT use in production code. | |
63 void FlushAudioLoop(); | |
64 bool IsPlaying(); | |
65 | |
66 media::AudioOutputStream* stream_; | |
Daniel Erat
2014/07/28 21:18:18
document ownership of this object
rkc
2014/07/29 00:33:35
Done.
| |
67 | |
68 // All fields below here are protected by this lock. | |
69 base::Lock state_lock_; | |
70 | |
71 scoped_refptr<media::AudioBusRefCounted> samples_; | |
72 // Index to the frame in the samples that we need to play next. | |
Daniel Erat
2014/07/28 21:18:18
nit: add blanks line before this line and between
rkc
2014/07/29 00:33:35
Done.
| |
73 int frame_index_; | |
74 bool is_playing_; | |
75 | |
76 media::AudioOutputStream* output_stream_for_testing_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); | |
79 }; | |
80 | |
81 } // namespace copresence | |
82 | |
83 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_PLAYER_ | |
OLD | NEW |