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

Side by Side Diff: remoting/protocol/audio_reader.cc

Issue 10823323: Add support for multiplexed channels in remoting::protocol::Session interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/audio_reader.h ('k') | remoting/protocol/audio_writer.h » ('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 #include "remoting/protocol/audio_reader.h" 5 #include "remoting/protocol/audio_reader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "net/socket/stream_socket.h" 8 #include "net/socket/stream_socket.h"
9 #include "remoting/base/constants.h" 9 #include "remoting/base/constants.h"
10 #include "remoting/protocol/session.h" 10 #include "remoting/protocol/session.h"
11 #include "remoting/protocol/session_config.h" 11 #include "remoting/protocol/session_config.h"
12 12
13 namespace remoting { 13 namespace remoting {
14 namespace protocol { 14 namespace protocol {
15 15
16 AudioReader::AudioReader(AudioPacket::Encoding encoding) 16 AudioReader::AudioReader(AudioPacket::Encoding encoding)
17 : session_(NULL), 17 : ChannelDispatcherBase(kAudioChannelName),
18 encoding_(encoding), 18 encoding_(encoding),
19 audio_stub_(NULL) { 19 audio_stub_(NULL) {
20 } 20 }
21 21
22 AudioReader::~AudioReader() { 22 AudioReader::~AudioReader() {
23 if (session_)
24 session_->CancelChannelCreation(kAudioChannelName);
25 } 23 }
26 24
27 // static 25 // static
28 scoped_ptr<AudioReader> AudioReader::Create(const SessionConfig& config) { 26 scoped_ptr<AudioReader> AudioReader::Create(const SessionConfig& config) {
29 if (!config.is_audio_enabled()) 27 if (!config.is_audio_enabled())
30 return scoped_ptr<AudioReader>(NULL); 28 return scoped_ptr<AudioReader>(NULL);
31 // TODO(kxing): Support different session configurations. 29 // TODO(kxing): Support different session configurations.
32 return scoped_ptr<AudioReader>(new AudioReader(AudioPacket::ENCODING_RAW)); 30 return scoped_ptr<AudioReader>(new AudioReader(AudioPacket::ENCODING_RAW));
33 } 31 }
34 32
35 void AudioReader::Init(protocol::Session* session, 33 void AudioReader::OnInitialized() {
36 AudioStub* audio_stub, 34 reader_.Init(channel(), base::Bind(&AudioReader::OnNewData,
37 const InitializedCallback& callback) { 35 base::Unretained(this)));
38 session_ = session;
39 initialized_callback_ = callback;
40 audio_stub_ = audio_stub;
41
42 session_->CreateStreamChannel(
43 kAudioChannelName,
44 base::Bind(&AudioReader::OnChannelReady, base::Unretained(this)));
45 }
46
47 bool AudioReader::is_connected() {
48 return channel_.get() != NULL;
49 }
50
51 void AudioReader::OnChannelReady(scoped_ptr<net::StreamSocket> socket) {
52 if (!socket.get()) {
53 initialized_callback_.Run(false);
54 return;
55 }
56
57 DCHECK(!channel_.get());
58 channel_ = socket.Pass();
59 reader_.Init(channel_.get(), base::Bind(&AudioReader::OnNewData,
60 base::Unretained(this)));
61 initialized_callback_.Run(true);
62 } 36 }
63 37
64 void AudioReader::OnNewData(scoped_ptr<AudioPacket> packet, 38 void AudioReader::OnNewData(scoped_ptr<AudioPacket> packet,
65 const base::Closure& done_task) { 39 const base::Closure& done_task) {
66 audio_stub_->ProcessAudioPacket(packet.Pass(), done_task); 40 audio_stub_->ProcessAudioPacket(packet.Pass(), done_task);
67 } 41 }
68 42
69 } // namespace protocol 43 } // namespace protocol
70 } // namespace remoting 44 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/audio_reader.h ('k') | remoting/protocol/audio_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698