diff options
author | kxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-15 00:58:37 +0000 |
---|---|---|
committer | kxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-15 00:58:37 +0000 |
commit | b55a55f0eaef95f064d0773f7e1708b8e457bc45 (patch) | |
tree | d17a434471a8f0fa7b163a7b301aa714c98a5d0e /remoting/protocol/audio_writer.cc | |
parent | 9d890d7411db7f7d0c993d0e94e9f3daf80c7392 (diff) | |
download | chromium_src-b55a55f0eaef95f064d0773f7e1708b8e457bc45.zip chromium_src-b55a55f0eaef95f064d0773f7e1708b8e457bc45.tar.gz chromium_src-b55a55f0eaef95f064d0773f7e1708b8e457bc45.tar.bz2 |
Added files for audio writers.
The structure of AudioWriter and ProtobufAudioWriter are similar
to their video counterparts.
Review URL: https://chromiumcodereview.appspot.com/10535153
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142297 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/audio_writer.cc')
-rw-r--r-- | remoting/protocol/audio_writer.cc | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/remoting/protocol/audio_writer.cc b/remoting/protocol/audio_writer.cc new file mode 100644 index 0000000..dc8a939 --- /dev/null +++ b/remoting/protocol/audio_writer.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/protocol/audio_writer.h" + +#include "base/bind.h" +#include "net/socket/stream_socket.h" +#include "remoting/base/constants.h" +#include "remoting/proto/audio.pb.h" +#include "remoting/protocol/session.h" +#include "remoting/protocol/session_config.h" +#include "remoting/protocol/util.h" + +namespace remoting { +namespace protocol { + +AudioWriter::AudioWriter() + : session_(NULL) { +} + +AudioWriter::~AudioWriter() { + Close(); +} + +void AudioWriter::Init(protocol::Session* session, + const InitializedCallback& callback) { + session_ = session; + initialized_callback_ = callback; + + session_->CreateStreamChannel( + kAudioChannelName, + base::Bind(&AudioWriter::OnChannelReady, base::Unretained(this))); +} + +void AudioWriter::OnChannelReady(scoped_ptr<net::StreamSocket> socket) { + if (!socket.get()) { + initialized_callback_.Run(false); + return; + } + + DCHECK(!channel_.get()); + channel_ = socket.Pass(); + // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer. + buffered_writer_.Init( + channel_.get(), BufferedSocketWriter::WriteFailedCallback()); + + initialized_callback_.Run(true); +} + +void AudioWriter::Close() { + buffered_writer_.Close(); + channel_.reset(); + if (session_) { + session_->CancelChannelCreation(kAudioChannelName); + session_ = NULL; + } +} + +bool AudioWriter::is_connected() { + return channel_.get() != NULL; +} + +void AudioWriter::ProcessAudioPacket(scoped_ptr<AudioPacket> packet, + const base::Closure& done) { + buffered_writer_.Write(SerializeAndFrameMessage(*packet), done); +} + +// static +AudioWriter* AudioWriter::Create(const SessionConfig& config) { + // TODO(kxing): Support different session configurations. + return new AudioWriter(); +} + +} // namespace protocol +} // namespace remoting |