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 3 // found in the LICENSE file. 4 5 #ifndef REMOTING_CLIENT_AUDIO_PLAYER_H_ 6 #define REMOTING_CLIENT_AUDIO_PLAYER_H_ 7 8 #include <list> 9 10 #include "base/memory/scoped_ptr.h" 11 #include "base/synchronization/lock.h" 12 #include "remoting/proto/audio.pb.h" 13 14 namespace remoting { 15 16 class AudioPlayer { 17 public: 18 virtual ~AudioPlayer(); 19 20 void ProcessAudioPacket(scoped_ptr<AudioPacket> packet); 21 22 protected: 23 AudioPlayer(); 24 25 // Return the recommended number of samples to include in a frame. 26 virtual uint32 GetSamplesPerFrame() = 0; 27 28 // Resets the audio player and starts playback. 29 // Returns true on success. 30 virtual bool ResetAudioPlayer(AudioPacket::SamplingRate sampling_rate) = 0; 31 32 // Function called by the browser when it needs more audio samples. 33 static void AudioPlayerCallback(void* samples, 34 uint32 buffer_size, 35 void* data); 36 37 private: 38 friend class AudioPlayerTest; 39 40 typedef std::list<AudioPacket*> AudioPacketQueue; 41 42 void ResetQueue(); 43 void FillWithSamples(void* samples, uint32 buffer_size); 44 45 AudioPacket::SamplingRate sampling_rate_; 46 47 bool start_failed_; 48 49 // Protects |queued_packets_|, |queued_samples_ and |bytes_consumed_|. This is 50 // necessary to prevent races, because Pepper will call the callback on a 51 // separate thread. 52 base::Lock lock_; 53 54 AudioPacketQueue queued_packets_; 55 int queued_bytes_; 56 57 // The number of bytes from |queued_packets_| that have been consumed. 58 size_t bytes_consumed_; 59 60 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); 61 }; 62 63 } // namespace remoting 64 65 #endif // REMOTING_CLIENT_AUDIO_PLAYER_H_ 66