sergeyu | 77b42df8 | 2016-10-04 02:08:38 | [diff] [blame] | 1 | // Copyright 2016 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_PROTOCOL_AUDIO_DECODE_SCHEDULER_H_ |
| 6 | #define REMOTING_PROTOCOL_AUDIO_DECODE_SCHEDULER_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/threading/thread_checker.h" |
| 14 | #include "remoting/protocol/audio_stub.h" |
| 15 | |
| 16 | namespace base { |
| 17 | class SingleThreadTaskRunner; |
| 18 | } // namespace base |
| 19 | |
| 20 | namespace remoting { |
| 21 | |
| 22 | class AudioDecoder; |
| 23 | class AudioPacket; |
| 24 | |
| 25 | namespace protocol { |
| 26 | |
| 27 | class SessionConfig; |
| 28 | class AudioStub; |
| 29 | |
| 30 | class AudioDecodeScheduler : public AudioStub { |
| 31 | public: |
| 32 | AudioDecodeScheduler( |
| 33 | scoped_refptr<base::SingleThreadTaskRunner> audio_decode_task_runner, |
| 34 | base::WeakPtr<AudioStub> audio_consumer); |
| 35 | ~AudioDecodeScheduler() override; |
| 36 | |
| 37 | // Initializes decoder with the information from the protocol config. |
| 38 | void Initialize(const protocol::SessionConfig& config); |
| 39 | |
| 40 | // AudioStub implementation. |
| 41 | void ProcessAudioPacket(std::unique_ptr<AudioPacket> packet, |
| 42 | const base::Closure& done) override; |
| 43 | |
| 44 | private: |
| 45 | void ProcessDecodedPacket(const base::Closure& done, |
| 46 | std::unique_ptr<AudioPacket> packet); |
| 47 | |
| 48 | scoped_refptr<base::SingleThreadTaskRunner> audio_decode_task_runner_; |
| 49 | base::WeakPtr<AudioStub> audio_consumer_; |
| 50 | |
| 51 | // Decoder used on the audio thread. |
| 52 | std::unique_ptr<AudioDecoder> decoder_; |
| 53 | |
| 54 | base::ThreadChecker thread_checker_; |
| 55 | |
| 56 | base::WeakPtrFactory<AudioDecodeScheduler> weak_factory_; |
| 57 | |
| 58 | DISALLOW_COPY_AND_ASSIGN(AudioDecodeScheduler); |
| 59 | }; |
| 60 | |
| 61 | } // namespace protocol |
| 62 | } // namespace remoting |
| 63 | |
| 64 | #endif // REMOTING_PROTOCOL_AUDIO_DECODE_SCHEDULER_H_ |