1 // Copyright 2018 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_AUDIO_PLAYBACK_STREAM_H_ 6 #define REMOTING_CLIENT_AUDIO_AUDIO_PLAYBACK_STREAM_H_ 7 8 #include <memory> 9 10 #include "base/macros.h" 11 #include "base/memory/ref_counted.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/single_thread_task_runner.h" 14 #include "base/threading/thread_checker.h" 15 #include "remoting/protocol/audio_stub.h" 16 17 namespace remoting { 18 19 class AudioPlaybackSink; 20 21 // An AudioStub implementation that buffers AudioPackets and feeds them to 22 // an AudioPlaybackSink. 23 // AudioPlaybackStream must be used and destroyed on the same thread after it 24 // is created, while it will use and destroy |audio_sink| on the thread of 25 // |audio_task_runner|. 26 class AudioPlaybackStream : public protocol::AudioStub { 27 public: 28 // |audio_sink|: The AudioPlaybackSink that receives audio data. 29 // |audio_task_runner|: The task runner where |audio_sink| will be run. 30 AudioPlaybackStream( 31 std::unique_ptr<AudioPlaybackSink> audio_sink, 32 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner); 33 34 ~AudioPlaybackStream() override; 35 36 // AudioStub implementations. 37 void ProcessAudioPacket(std::unique_ptr<AudioPacket> packet, 38 base::OnceClosure done) override; 39 40 private: 41 class Core; 42 43 THREAD_CHECKER(thread_checker_); 44 45 std::unique_ptr<Core> core_; 46 47 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; 48 49 DISALLOW_COPY_AND_ASSIGN(AudioPlaybackStream); 50 }; 51 52 } // namespace remoting 53 54 #endif // REMOTING_CLIENT_AUDIO_AUDIO_PLAYBACK_STREAM_H_ 55