OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/rtp_video_writer.h" | 5 #include "remoting/protocol/rtp_video_writer.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/task.h" | 8 #include "base/task.h" |
8 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
9 #include "remoting/base/compound_buffer.h" | 10 #include "remoting/base/compound_buffer.h" |
| 11 #include "remoting/base/constants.h" |
10 #include "remoting/proto/video.pb.h" | 12 #include "remoting/proto/video.pb.h" |
11 #include "remoting/protocol/rtp_writer.h" | 13 #include "remoting/protocol/rtp_writer.h" |
12 #include "remoting/protocol/session.h" | 14 #include "remoting/protocol/session.h" |
13 | 15 |
14 namespace remoting { | 16 namespace remoting { |
15 namespace protocol { | 17 namespace protocol { |
16 | 18 |
17 namespace { | 19 namespace { |
18 const int kMtu = 1200; | 20 const int kMtu = 1200; |
19 } // namespace | 21 } // namespace |
20 | 22 |
21 RtpVideoWriter::RtpVideoWriter() { } | 23 RtpVideoWriter::RtpVideoWriter() |
| 24 : initialized_(false) { |
| 25 } |
22 | 26 |
23 RtpVideoWriter::~RtpVideoWriter() { | 27 RtpVideoWriter::~RtpVideoWriter() { |
24 Close(); | 28 Close(); |
25 } | 29 } |
26 | 30 |
27 void RtpVideoWriter::Init(protocol::Session* session) { | 31 void RtpVideoWriter::Init(protocol::Session* session, |
28 rtp_writer_.Init(session->video_rtp_channel()); | 32 const InitializedCallback& callback) { |
| 33 initialized_callback_ = callback; |
| 34 session->CreateDatagramChannel( |
| 35 kVideoRtpChannelName, |
| 36 base::Bind(&RtpVideoWriter::OnChannelReady, base::Unretained(this))); |
| 37 session->CreateDatagramChannel( |
| 38 kVideoRtcpChannelName, |
| 39 base::Bind(&RtpVideoWriter::OnChannelReady, base::Unretained(this))); |
| 40 } |
| 41 |
| 42 void RtpVideoWriter::OnChannelReady(const std::string& name, |
| 43 net::Socket* socket) { |
| 44 if (!socket) { |
| 45 if (!initialized_) { |
| 46 initialized_ = true; |
| 47 initialized_callback_.Run(false); |
| 48 } |
| 49 return; |
| 50 } |
| 51 |
| 52 if (name == kVideoRtpChannelName) { |
| 53 DCHECK(!rtp_channel_.get()); |
| 54 rtp_channel_.reset(socket); |
| 55 rtp_writer_.Init(socket); |
| 56 } else if (name == kVideoRtcpChannelName) { |
| 57 DCHECK(!rtcp_channel_.get()); |
| 58 rtcp_channel_.reset(socket); |
| 59 // TODO(sergeyu): Use RTCP channel somehow. |
| 60 } |
| 61 |
| 62 if (rtp_channel_.get() && rtcp_channel_.get()) { |
| 63 DCHECK(!initialized_); |
| 64 initialized_ = true; |
| 65 initialized_callback_.Run(true); |
| 66 } |
29 } | 67 } |
30 | 68 |
31 void RtpVideoWriter::Close() { | 69 void RtpVideoWriter::Close() { |
32 rtp_writer_.Close(); | 70 rtp_writer_.Close(); |
| 71 rtp_channel_.reset(); |
| 72 rtcp_channel_.reset(); |
33 } | 73 } |
34 | 74 |
35 void RtpVideoWriter::ProcessVideoPacket(const VideoPacket* packet, Task* done) { | 75 void RtpVideoWriter::ProcessVideoPacket(const VideoPacket* packet, Task* done) { |
36 CHECK(packet->format().encoding() == VideoPacketFormat::ENCODING_VP8) | 76 CHECK(packet->format().encoding() == VideoPacketFormat::ENCODING_VP8) |
37 << "Only VP8 is supported in RTP."; | 77 << "Only VP8 is supported in RTP."; |
38 | 78 |
39 CompoundBuffer payload; | 79 CompoundBuffer payload; |
40 // TODO(sergeyu): This copy would not be necessary CompoundBuffer was used | 80 // TODO(sergeyu): This copy would not be necessary CompoundBuffer was used |
41 // inside of VideoPacket. | 81 // inside of VideoPacket. |
42 payload.AppendCopyOf(packet->data().data(), packet->data().size()); | 82 payload.AppendCopyOf(packet->data().data(), packet->data().size()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 done->Run(); | 129 done->Run(); |
90 delete done; | 130 delete done; |
91 } | 131 } |
92 | 132 |
93 int RtpVideoWriter::GetPendingPackets() { | 133 int RtpVideoWriter::GetPendingPackets() { |
94 return rtp_writer_.GetPendingPackets(); | 134 return rtp_writer_.GetPendingPackets(); |
95 } | 135 } |
96 | 136 |
97 } // namespace protocol | 137 } // namespace protocol |
98 } // namespace remoting | 138 } // namespace remoting |
OLD | NEW |