OLD | NEW |
---|---|
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 REMOTING_CLIENT_AUDIO_PLAYER_H_ | 5 #ifndef REMOTING_CLIENT_AUDIO_PLAYER_H_ |
6 #define REMOTING_CLIENT_AUDIO_PLAYER_H_ | 6 #define REMOTING_CLIENT_AUDIO_PLAYER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <list> | 11 #include <list> |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "remoting/client/audio_consumer.h" | |
16 #include "remoting/proto/audio.pb.h" | 17 #include "remoting/proto/audio.pb.h" |
17 | 18 |
18 namespace remoting { | 19 namespace remoting { |
19 | 20 |
20 class AudioPlayer { | 21 class AudioPlayer : public AudioConsumer { |
21 public: | 22 public: |
22 // The number of channels in the audio stream (only supporting stereo audio | 23 // The number of channels in the audio stream (only supporting stereo audio |
23 // for now). | 24 // for now). |
24 static const int kChannels = 2; | 25 static const int kChannels = 2; |
25 static const int kSampleSizeBytes = 2; | 26 static const int kSampleSizeBytes = 2; |
26 | 27 |
27 virtual ~AudioPlayer(); | |
28 | |
29 void ProcessAudioPacket(std::unique_ptr<AudioPacket> packet); | 28 void ProcessAudioPacket(std::unique_ptr<AudioPacket> packet); |
30 | 29 |
31 protected: | 30 protected: |
32 AudioPlayer(); | 31 AudioPlayer(); |
32 ~AudioPlayer() override; | |
33 | 33 |
34 // Return the recommended number of samples to include in a frame. | 34 // Return the recommended number of samples to include in a frame. |
35 virtual uint32_t GetSamplesPerFrame() = 0; | 35 virtual uint32_t GetSamplesPerFrame() = 0; |
36 | 36 |
37 // Resets the audio player and starts playback. | 37 // Resets the audio player and starts playback. |
38 // Returns true on success. | 38 // Returns true on success. |
39 virtual bool ResetAudioPlayer(AudioPacket::SamplingRate sampling_rate) = 0; | 39 virtual bool ResetAudioPlayer(AudioPacket::SamplingRate sampling_rate) = 0; |
40 | 40 |
41 // Function called by the browser when it needs more audio samples. | 41 // Function called by the browser when it needs more audio samples. |
42 static void AudioPlayerCallback(void* samples, | 42 static void AudioPlayerCallback(void* samples, |
43 uint32_t buffer_size, | 43 uint32_t buffer_size, |
44 void* data); | 44 void* data); |
45 | 45 |
46 // Function called by the subclass when it needs more audio samples to fill | 46 // Function called by the subclass when it needs more audio samples to fill |
47 // its buffer. Will fill the buffer with 0's if no sample is available. | 47 // its buffer. Will fill the buffer with 0's if no sample is available. |
48 void FillWithSamples(void* samples, uint32_t buffer_size); | 48 void FillWithSamples(void* samples, uint32_t buffer_size); |
49 | 49 |
50 void AddAudioPacket(std::unique_ptr<AudioPacket> packet) override; | |
Sergey Ulanov
2016/06/09 20:23:45
Add comment:
// AudioConsumer implementation.
al
nicholss
2016/06/09 20:57:08
Done.
| |
51 | |
50 private: | 52 private: |
51 friend class AudioPlayerTest; | 53 friend class AudioPlayerTest; |
52 | 54 |
53 typedef std::list<AudioPacket*> AudioPacketQueue; | 55 typedef std::list<AudioPacket*> AudioPacketQueue; |
54 | 56 |
55 void ResetQueue(); | 57 void ResetQueue(); |
56 | 58 |
57 AudioPacket::SamplingRate sampling_rate_; | 59 AudioPacket::SamplingRate sampling_rate_; |
58 | 60 |
59 bool start_failed_; | 61 bool start_failed_; |
60 | 62 |
61 // Protects |queued_packets_|, |queued_samples_ and |bytes_consumed_|. This is | 63 // Protects |queued_packets_|, |queued_samples_ and |bytes_consumed_|. This is |
62 // necessary to prevent races, because Pepper will call the callback on a | 64 // necessary to prevent races, because Pepper will call the callback on a |
63 // separate thread. | 65 // separate thread. |
64 base::Lock lock_; | 66 base::Lock lock_; |
65 | 67 |
66 AudioPacketQueue queued_packets_; | 68 AudioPacketQueue queued_packets_; |
67 int queued_bytes_; | 69 int queued_bytes_; |
68 | 70 |
69 // The number of bytes from |queued_packets_| that have been consumed. | 71 // The number of bytes from |queued_packets_| that have been consumed. |
70 size_t bytes_consumed_; | 72 size_t bytes_consumed_; |
71 | 73 |
72 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); | 74 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); |
73 }; | 75 }; |
74 | 76 |
75 } // namespace remoting | 77 } // namespace remoting |
76 | 78 |
77 #endif // REMOTING_CLIENT_AUDIO_PLAYER_H_ | 79 #endif // REMOTING_CLIENT_AUDIO_PLAYER_H_ |
OLD | NEW |