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

Side by Side Diff: remoting/client/audio_player.h

Issue 2052723002: Adding an interface to allow extention of the audio player for CRD and iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding missing dep on proto for test. Created 4 years, 6 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
OLDNEW
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 ~AudioPlayer() override;
28 29
29 void ProcessAudioPacket(std::unique_ptr<AudioPacket> packet); 30 void ProcessAudioPacket(std::unique_ptr<AudioPacket> packet);
Sergey Ulanov 2016/06/18 00:43:38 Why do we need to both ProcessAudioPacket() and Ad
nicholss 2016/06/20 17:47:52 Process is the deprecated way for the audio player
30 31
32 // AudioConsumer implementation.
33 void AddAudioPacket(std::unique_ptr<AudioPacket> packet) override;
34
31 protected: 35 protected:
32 AudioPlayer(); 36 AudioPlayer();
33 37
34 // Return the recommended number of samples to include in a frame. 38 // Return the recommended number of samples to include in a frame.
35 virtual uint32_t GetSamplesPerFrame() = 0; 39 virtual uint32_t GetSamplesPerFrame() = 0;
36 40
37 // Resets the audio player and starts playback. 41 // Resets the audio player and starts playback.
38 // Returns true on success. 42 // Returns true on success.
39 virtual bool ResetAudioPlayer(AudioPacket::SamplingRate sampling_rate) = 0; 43 virtual bool ResetAudioPlayer(AudioPacket::SamplingRate sampling_rate) = 0;
40 44
41 // Function called by the browser when it needs more audio samples. 45 // Function called by the browser when it needs more audio samples.
42 static void AudioPlayerCallback(void* samples, 46 static void AudioPlayerCallback(void* samples,
43 uint32_t buffer_size, 47 uint32_t buffer_size,
44 void* data); 48 void* data);
45 49
46 // Function called by the subclass when it needs more audio samples to fill 50 // 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. 51 // its buffer. Will fill the buffer with 0's if no sample is available.
48 void FillWithSamples(void* samples, uint32_t buffer_size); 52 void FillWithSamples(void* samples, uint32_t buffer_size);
49 53
50 private: 54 private:
51 friend class AudioPlayerTest; 55 friend class AudioPlayerTest;
52 56
53 typedef std::list<AudioPacket*> AudioPacketQueue; 57 typedef std::list<std::unique_ptr<AudioPacket>> AudioPacketQueue;
54 58
55 void ResetQueue(); 59 void ResetQueue();
56 60
57 AudioPacket::SamplingRate sampling_rate_; 61 AudioPacket::SamplingRate sampling_rate_;
58 62
59 bool start_failed_; 63 bool start_failed_;
60 64
61 // Protects |queued_packets_|, |queued_samples_ and |bytes_consumed_|. This is 65 // Protects |queued_packets_|, |queued_samples_ and |bytes_consumed_|. This is
62 // necessary to prevent races, because Pepper will call the callback on a 66 // necessary to prevent races, because Pepper will call the callback on a
63 // separate thread. 67 // separate thread.
64 base::Lock lock_; 68 base::Lock lock_;
65 69
66 AudioPacketQueue queued_packets_; 70 AudioPacketQueue queued_packets_;
67 int queued_bytes_; 71 int queued_bytes_;
68 72
69 // The number of bytes from |queued_packets_| that have been consumed. 73 // The number of bytes from |queued_packets_| that have been consumed.
70 size_t bytes_consumed_; 74 size_t bytes_consumed_;
71 75
72 DISALLOW_COPY_AND_ASSIGN(AudioPlayer); 76 DISALLOW_COPY_AND_ASSIGN(AudioPlayer);
73 }; 77 };
74 78
75 } // namespace remoting 79 } // namespace remoting
76 80
77 #endif // REMOTING_CLIENT_AUDIO_PLAYER_H_ 81 #endif // REMOTING_CLIENT_AUDIO_PLAYER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698