OLD | NEW |
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_PROTOCOL_AUDIO_WRITER_H_ | 5 #ifndef REMOTING_PROTOCOL_AUDIO_WRITER_H_ |
6 #define REMOTING_PROTOCOL_AUDIO_WRITER_H_ | 6 #define REMOTING_PROTOCOL_AUDIO_WRITER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "remoting/protocol/audio_stub.h" | 14 #include "remoting/protocol/audio_stub.h" |
15 #include "remoting/protocol/buffered_socket_writer.h" | 15 #include "remoting/protocol/buffered_socket_writer.h" |
| 16 #include "remoting/protocol/channel_dispatcher_base.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 class StreamSocket; | 19 class StreamSocket; |
19 } // namespace net | 20 } // namespace net |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
22 namespace protocol { | 23 namespace protocol { |
23 | 24 |
24 class Session; | 25 class Session; |
25 class SessionConfig; | 26 class SessionConfig; |
26 | 27 |
27 class AudioWriter : public AudioStub { | 28 class AudioWriter : public ChannelDispatcherBase, |
| 29 public AudioStub { |
28 public: | 30 public: |
29 virtual ~AudioWriter(); | 31 // Once AudioWriter is created, the Init() method of ChannelDispatcherBase |
30 | 32 // should be used to initialize it for the session. |
31 // The callback is called when initialization is finished. The | |
32 // parameter is set to true on success. | |
33 typedef base::Callback<void(bool)> InitializedCallback; | |
34 | |
35 static scoped_ptr<AudioWriter> Create(const SessionConfig& config); | 33 static scoped_ptr<AudioWriter> Create(const SessionConfig& config); |
36 | 34 |
37 // Initializes the writer. | 35 virtual ~AudioWriter(); |
38 void Init(Session* session, const InitializedCallback& callback); | |
39 | |
40 // Stops writing. Must be called on the network thread before this | |
41 // object is destroyed. | |
42 void Close(); | |
43 | |
44 // Returns true if the channel is connected. | |
45 bool is_connected(); | |
46 | 36 |
47 // AudioStub interface. | 37 // AudioStub interface. |
48 virtual void ProcessAudioPacket(scoped_ptr<AudioPacket> packet, | 38 virtual void ProcessAudioPacket(scoped_ptr<AudioPacket> packet, |
49 const base::Closure& done) OVERRIDE; | 39 const base::Closure& done) OVERRIDE; |
50 | 40 |
| 41 protected: |
| 42 virtual void OnInitialized() OVERRIDE; |
| 43 |
51 private: | 44 private: |
52 AudioWriter(); | 45 AudioWriter(); |
53 | 46 |
54 void OnChannelReady(scoped_ptr<net::StreamSocket> socket); | |
55 | |
56 Session* session_; | |
57 | |
58 InitializedCallback initialized_callback_; | |
59 | |
60 // TODO(sergeyu): Remove |channel_| and let |buffered_writer_| own it. | |
61 scoped_ptr<net::StreamSocket> channel_; | |
62 | |
63 BufferedSocketWriter buffered_writer_; | 47 BufferedSocketWriter buffered_writer_; |
64 | 48 |
65 DISALLOW_COPY_AND_ASSIGN(AudioWriter); | 49 DISALLOW_COPY_AND_ASSIGN(AudioWriter); |
66 }; | 50 }; |
67 | 51 |
68 } // namespace protocol | 52 } // namespace protocol |
69 } // namespace remoting | 53 } // namespace remoting |
70 | 54 |
71 #endif // REMOTING_PROTOCOL_AUDIO_WRITER_H_ | 55 #endif // REMOTING_PROTOCOL_AUDIO_WRITER_H_ |
OLD | NEW |