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

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

Issue 419073002: Add the copresence DirectiveHandler. (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
(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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698