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

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

Issue 577473002: Simplify VideoReader and VideoWriter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « remoting/protocol/protobuf_video_reader.h ('k') | remoting/protocol/protobuf_video_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/protocol/protobuf_video_reader.h"
6
7 #include "base/bind.h"
8 #include "net/socket/stream_socket.h"
9 #include "remoting/base/constants.h"
10 #include "remoting/proto/video.pb.h"
11 #include "remoting/protocol/session.h"
12 #include "remoting/protocol/stream_channel_factory.h"
13
14 namespace remoting {
15 namespace protocol {
16
17 ProtobufVideoReader::ProtobufVideoReader(VideoPacketFormat::Encoding encoding)
18 : encoding_(encoding),
19 channel_factory_(NULL),
20 video_stub_(NULL) {
21 }
22
23 ProtobufVideoReader::~ProtobufVideoReader() {
24 if (channel_factory_)
25 channel_factory_->CancelChannelCreation(kVideoChannelName);
26 }
27
28 void ProtobufVideoReader::Init(protocol::Session* session,
29 VideoStub* video_stub,
30 const InitializedCallback& callback) {
31 channel_factory_ = session->GetTransportChannelFactory();
32 initialized_callback_ = callback;
33 video_stub_ = video_stub;
34
35 channel_factory_->CreateChannel(
36 kVideoChannelName,
37 base::Bind(&ProtobufVideoReader::OnChannelReady, base::Unretained(this)));
38 }
39
40 bool ProtobufVideoReader::is_connected() {
41 return channel_.get() != NULL;
42 }
43
44 void ProtobufVideoReader::OnChannelReady(scoped_ptr<net::StreamSocket> socket) {
45 if (!socket.get()) {
46 initialized_callback_.Run(false);
47 return;
48 }
49
50 DCHECK(!channel_.get());
51 channel_ = socket.Pass();
52 reader_.Init(channel_.get(), base::Bind(&ProtobufVideoReader::OnNewData,
53 base::Unretained(this)));
54 initialized_callback_.Run(true);
55 }
56
57 void ProtobufVideoReader::OnNewData(scoped_ptr<VideoPacket> packet,
58 const base::Closure& done_task) {
59 video_stub_->ProcessVideoPacket(packet.Pass(), done_task);
60 }
61
62 } // namespace protocol
63 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/protobuf_video_reader.h ('k') | remoting/protocol/protobuf_video_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698