OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_reader.h" | 5 #include "remoting/protocol/rtp_video_reader.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/task.h" | 8 #include "base/task.h" |
| 9 #include "remoting/base/constants.h" |
8 #include "remoting/proto/video.pb.h" | 10 #include "remoting/proto/video.pb.h" |
9 #include "remoting/protocol/session.h" | 11 #include "remoting/protocol/session.h" |
10 | 12 |
11 namespace remoting { | 13 namespace remoting { |
12 namespace protocol { | 14 namespace protocol { |
13 | 15 |
14 namespace { | 16 namespace { |
15 const int kMaxPacketsInQueue = 1024; | 17 const int kMaxPacketsInQueue = 1024; |
16 const int kReceiverReportsIntervalMs = 1000; | 18 const int kReceiverReportsIntervalMs = 1000; |
17 } // namespace | 19 } // namespace |
18 | 20 |
19 RtpVideoReader::PacketsQueueEntry::PacketsQueueEntry() | 21 RtpVideoReader::PacketsQueueEntry::PacketsQueueEntry() |
20 : received(false), | 22 : received(false), |
21 packet(NULL) { | 23 packet(NULL) { |
22 } | 24 } |
23 | 25 |
24 RtpVideoReader::RtpVideoReader() | 26 RtpVideoReader::RtpVideoReader() |
25 : last_sequence_number_(0), | 27 : initialized_(false), |
| 28 last_sequence_number_(0), |
26 video_stub_(NULL) { | 29 video_stub_(NULL) { |
27 } | 30 } |
28 | 31 |
29 RtpVideoReader::~RtpVideoReader() { | 32 RtpVideoReader::~RtpVideoReader() { |
30 ResetQueue(); | 33 ResetQueue(); |
31 } | 34 } |
32 | 35 |
33 void RtpVideoReader::Init(protocol::Session* session, VideoStub* video_stub) { | 36 void RtpVideoReader::Init(protocol::Session* session, |
34 rtp_reader_.Init(session->video_rtp_channel(), | 37 VideoStub* video_stub, |
35 NewCallback(this, &RtpVideoReader::OnRtpPacket)); | 38 const InitializedCallback& callback) { |
36 rtcp_writer_.Init(session->video_rtcp_channel()); | 39 initialized_callback_ = callback; |
37 video_stub_ = video_stub; | 40 video_stub_ = video_stub; |
| 41 |
| 42 session->CreateDatagramChannel( |
| 43 kVideoRtpChannelName, |
| 44 base::Bind(&RtpVideoReader::OnChannelReady, base::Unretained(this))); |
| 45 session->CreateDatagramChannel( |
| 46 kVideoRtcpChannelName, |
| 47 base::Bind(&RtpVideoReader::OnChannelReady, base::Unretained(this))); |
| 48 } |
| 49 |
| 50 void RtpVideoReader::OnChannelReady(const std::string& name, |
| 51 net::Socket* socket) { |
| 52 if (!socket) { |
| 53 if (!initialized_) { |
| 54 initialized_ = true; |
| 55 initialized_callback_.Run(false); |
| 56 } |
| 57 return; |
| 58 } |
| 59 |
| 60 if (name == kVideoRtpChannelName) { |
| 61 DCHECK(!rtp_channel_.get()); |
| 62 rtp_channel_.reset(socket); |
| 63 rtp_reader_.Init(socket, NewCallback(this, &RtpVideoReader::OnRtpPacket)); |
| 64 } else if (name == kVideoRtcpChannelName) { |
| 65 DCHECK(!rtcp_channel_.get()); |
| 66 rtcp_channel_.reset(socket); |
| 67 rtcp_writer_.Init(socket); |
| 68 } else { |
| 69 NOTREACHED(); |
| 70 } |
| 71 |
| 72 if (rtp_channel_.get() && rtcp_channel_.get()) { |
| 73 DCHECK(!initialized_); |
| 74 initialized_ = true; |
| 75 initialized_callback_.Run(true); |
| 76 } |
38 } | 77 } |
39 | 78 |
40 void RtpVideoReader::ResetQueue() { | 79 void RtpVideoReader::ResetQueue() { |
41 for (PacketsQueue::iterator it = packets_queue_.begin(); | 80 for (PacketsQueue::iterator it = packets_queue_.begin(); |
42 it != packets_queue_.end(); ++it) { | 81 it != packets_queue_.end(); ++it) { |
43 delete it->packet; | 82 delete it->packet; |
44 } | 83 } |
45 packets_queue_.assign(kMaxPacketsInQueue, PacketsQueueEntry()); | 84 packets_queue_.assign(kMaxPacketsInQueue, PacketsQueueEntry()); |
46 } | 85 } |
47 | 86 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 RtcpReceiverReport report; | 220 RtcpReceiverReport report; |
182 rtp_reader_.GetReceiverReport(&report); | 221 rtp_reader_.GetReceiverReport(&report); |
183 rtcp_writer_.SendReport(report); | 222 rtcp_writer_.SendReport(report); |
184 | 223 |
185 last_receiver_report_ = now; | 224 last_receiver_report_ = now; |
186 } | 225 } |
187 } | 226 } |
188 | 227 |
189 } // namespace protocol | 228 } // namespace protocol |
190 } // namespace remoting | 229 } // namespace remoting |
OLD | NEW |