From b55a55f0eaef95f064d0773f7e1708b8e457bc45 Mon Sep 17 00:00:00 2001 From: "kxing@chromium.org" Date: Fri, 15 Jun 2012 00:58:37 +0000 Subject: 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 --- remoting/protocol/audio_writer.cc | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 remoting/protocol/audio_writer.cc (limited to 'remoting/protocol/audio_writer.cc') 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 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 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 -- cgit v1.1