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

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: Addressing comments in CL. 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
« no previous file with comments | « remoting/client/audio_decode_scheduler_unittest.cc ('k') | remoting/client/audio_player.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // AudioConsumer implementation.
31 void AddAudioPacket(std::unique_ptr<AudioPacket> packet) override;
30 32
31 protected: 33 protected:
32 AudioPlayer(); 34 AudioPlayer();
33 35
34 // Return the recommended number of samples to include in a frame. 36 // Return the recommended number of samples to include in a frame.
35 virtual uint32_t GetSamplesPerFrame() = 0; 37 virtual uint32_t GetSamplesPerFrame() = 0;
36 38
37 // Resets the audio player and starts playback. 39 // Resets the audio player and starts playback.
38 // Returns true on success. 40 // Returns true on success.
39 virtual bool ResetAudioPlayer(AudioPacket::SamplingRate sampling_rate) = 0; 41 virtual bool ResetAudioPlayer(AudioPacket::SamplingRate sampling_rate) = 0;
40 42
41 // Function called by the browser when it needs more audio samples. 43 // Function called by the browser when it needs more audio samples.
42 static void AudioPlayerCallback(void* samples, 44 static void AudioPlayerCallback(void* samples,
43 uint32_t buffer_size, 45 uint32_t buffer_size,
44 void* data); 46 void* data);
45 47
46 // Function called by the subclass when it needs more audio samples to fill 48 // 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. 49 // its buffer. Will fill the buffer with 0's if no sample is available.
48 void FillWithSamples(void* samples, uint32_t buffer_size); 50 void FillWithSamples(void* samples, uint32_t buffer_size);
49 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<std::unique_ptr<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_
OLDNEW
« no previous file with comments | « remoting/client/audio_decode_scheduler_unittest.cc ('k') | remoting/client/audio_player.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698