Chromium Code Reviews| 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_PLUGIN_PEPPER_AUDIO_PLAYER_H_ | 5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_AUDIO_PLAYER_H_ |
| 6 #define REMOTING_CLIENT_PLUGIN_PEPPER_AUDIO_PLAYER_H_ | 6 #define REMOTING_CLIENT_PLUGIN_PEPPER_AUDIO_PLAYER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "ppapi/cpp/audio.h" | 15 #include "ppapi/cpp/audio.h" |
| 16 #include "ppapi/cpp/instance.h" | 16 #include "ppapi/cpp/instance.h" |
| 17 #include "remoting/client/audio_player.h" | 17 #include "remoting/client/audio_player.h" |
| 18 #include "remoting/proto/audio.pb.h" | |
| 18 | 19 |
| 19 namespace remoting { | 20 namespace remoting { |
| 20 | 21 |
| 21 class AudioPacket; | |
| 22 | |
| 23 class PepperAudioPlayer : public AudioPlayer { | 22 class PepperAudioPlayer : public AudioPlayer { |
| 24 public: | 23 public: |
| 25 explicit PepperAudioPlayer(pp::Instance* instance); | 24 explicit PepperAudioPlayer(pp::Instance* instance); |
| 26 virtual ~PepperAudioPlayer(); | 25 virtual ~PepperAudioPlayer(); |
| 27 | 26 |
| 28 // Returns true if successful, false otherwise. | 27 // Returns true if successful, false otherwise. |
| 29 virtual bool Start() OVERRIDE; | 28 virtual bool Start() OVERRIDE; |
| 30 | 29 |
| 31 virtual void ProcessAudioPacket(scoped_ptr<AudioPacket> packet) OVERRIDE; | 30 virtual void ProcessAudioPacket(scoped_ptr<AudioPacket> packet) OVERRIDE; |
| 32 | 31 |
| 33 virtual bool IsRunning() const OVERRIDE; | 32 virtual bool IsRunning() const OVERRIDE; |
| 34 | 33 |
| 35 private: | 34 private: |
| 36 typedef std::list<AudioPacket*> AudioPacketQueue; | 35 typedef std::list<AudioPacket*> AudioPacketQueue; |
| 37 | 36 |
| 37 bool DoStart(); | |
| 38 void DoStop(); | |
| 39 | |
| 40 PP_AudioSampleRate ConvertToPepperSampleRate( | |
| 41 AudioPacket::SamplingRate sampling_rate); | |
| 42 | |
| 43 void ResetAudioPlayer(AudioPacket::SamplingRate sampling_rate); | |
| 44 | |
| 38 // Function called by the browser when it needs more audio samples. | 45 // Function called by the browser when it needs more audio samples. |
| 39 static void PepperAudioPlayerCallback(void* samples, | 46 static void PepperAudioPlayerCallback(void* samples, |
| 40 uint32_t buffer_size, | 47 uint32_t buffer_size, |
| 41 void* data); | 48 void* data); |
| 42 | 49 |
| 43 void FillWithSamples(void* samples, uint32_t buffer_size); | 50 void FillWithSamples(void* samples, uint32_t buffer_size); |
| 44 | 51 |
| 52 pp::Instance* instance_; | |
| 45 pp::Audio audio_; | 53 pp::Audio audio_; |
| 46 | 54 |
| 55 AudioPacket::SamplingRate sampling_rate_; | |
| 56 | |
| 47 // The count of sample frames per channel in an audio buffer. | 57 // The count of sample frames per channel in an audio buffer. |
| 48 uint32_t samples_per_frame_; | 58 uint32_t samples_per_frame_; |
| 49 | 59 |
| 50 // Protects |queued_packets_| and |bytes_consumed_|. | 60 // Protects |queued_packets_| and |bytes_consumed_|. |
| 51 // This is necessary to prevent races, | 61 // This is necessary to prevent races, |
| 52 // because Pepper will callback on a separate thread. | 62 // because Pepper will callback on a separate thread. |
| 53 base::Lock lock_; | 63 base::Lock lock_; |
| 54 | 64 |
| 55 AudioPacketQueue queued_packets_; | 65 AudioPacketQueue queued_packets_; |
| 56 | 66 |
| 57 // The number of bytes from |queued_packets_| that have been consumed. | 67 // The number of bytes from |queued_packets_| that have been consumed. |
| 58 size_t bytes_consumed_; | 68 size_t bytes_consumed_; |
| 59 | 69 |
| 70 // Equal to true, only if Start() has been called. | |
|
Sergey Ulanov
2012/07/23 22:01:47
this comment seems to be redundant. maybe just ren
kxing
2012/07/23 22:58:47
Done.
| |
| 60 bool running_; | 71 bool running_; |
| 61 | 72 |
| 62 DISALLOW_COPY_AND_ASSIGN(PepperAudioPlayer); | 73 DISALLOW_COPY_AND_ASSIGN(PepperAudioPlayer); |
| 63 }; | 74 }; |
| 64 | 75 |
| 65 } // namespace remoting | 76 } // namespace remoting |
| 66 | 77 |
| 67 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_AUDIO_PLAYER_H_ | 78 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_AUDIO_PLAYER_H_ |
| OLD | NEW |