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

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

Issue 4925001: Packetizer/Depacketizer for RTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/rtp_writer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_writer.h" 5 #include "remoting/protocol/rtp_writer.h"
6 6
7 #include "net/base/io_buffer.h" 7 #include "net/base/io_buffer.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "remoting/base/compound_buffer.h" 9 #include "remoting/base/compound_buffer.h"
10 #include "remoting/protocol/rtp_utils.h" 10 #include "remoting/protocol/rtp_utils.h"
11 11
12 namespace remoting { 12 namespace remoting {
13 namespace protocol { 13 namespace protocol {
14 14
15 namespace { 15 namespace {
16 const int kMtu = 1200;
17 const uint8 kRtpPayloadTypePrivate = 96; 16 const uint8 kRtpPayloadTypePrivate = 96;
18 } 17 } // namespace
19 18
20 RtpWriter::RtpWriter() 19 RtpWriter::RtpWriter()
21 : rtp_socket_(NULL), 20 : rtp_socket_(NULL),
22 rtcp_socket_(NULL), 21 rtcp_socket_(NULL),
23 last_packet_number_(0) { 22 last_packet_number_(0) {
24 } 23 }
25 24
26 RtpWriter::~RtpWriter() { } 25 RtpWriter::~RtpWriter() { }
27 26
28 // Initializes the writer. Must be called on the thread the sockets belong 27 // Initializes the writer. Must be called on the thread the sockets belong
29 // to. 28 // to.
30 void RtpWriter::Init(net::Socket* rtp_socket, net::Socket* rtcp_socket) { 29 void RtpWriter::Init(net::Socket* rtp_socket, net::Socket* rtcp_socket) {
31 buffered_rtp_writer_ = new BufferedDatagramWriter(); 30 buffered_rtp_writer_ = new BufferedDatagramWriter();
32 buffered_rtp_writer_->Init(rtp_socket, NULL); 31 buffered_rtp_writer_->Init(rtp_socket, NULL);
33 rtp_socket_ = rtp_socket; 32 rtp_socket_ = rtp_socket;
34 rtcp_socket_ = rtcp_socket; 33 rtcp_socket_ = rtcp_socket;
35 } 34 }
36 35
37 void RtpWriter::SendPacket(const CompoundBuffer& payload, uint32 timestamp) { 36 void RtpWriter::SendPacket(uint32 timestamp, bool marker,
37 const Vp8Descriptor& vp8_descriptor,
38 const CompoundBuffer& payload) {
38 RtpHeader header; 39 RtpHeader header;
39 header.padding = false; 40 header.padding = false;
40 header.extension = false; 41 header.extension = false;
41 header.sources = 0; 42 header.sources = 0;
43 header.marker = marker;
42 header.payload_type = kRtpPayloadTypePrivate; 44 header.payload_type = kRtpPayloadTypePrivate;
43 header.timestamp = timestamp; 45 header.timestamp = timestamp;
44 46
45 // TODO(sergeyu): RTP requires that SSRC is chosen randomly by each 47 // TODO(sergeyu): RTP requires that SSRC is chosen randomly by each
46 // participant. There are only two participants in chromoting session, 48 // participant. There are only two participants in chromoting session,
47 // so SSRC isn't useful. Implement it in future if neccessary. 49 // so SSRC isn't useful. Implement it in future if neccessary.
48 header.sync_source_id = 0; 50 header.sync_source_id = 0;
49 51
50 // TODO(sergeyu): Add VP8 payload header. 52 // TODO(sergeyu): Handle sequence number wrapping.
53 header.sequence_number = last_packet_number_;
54 ++last_packet_number_;
51 55
52 int position = 0; 56 int header_size = GetRtpHeaderSize(header);
53 while (position < payload.total_bytes()) { 57 int vp8_descriptor_size = GetVp8DescriptorSize(vp8_descriptor);
54 // Allocate buffer. 58 int payload_size = payload.total_bytes();
55 int size = std::min(kMtu, payload.total_bytes() - position); 59 int total_size = header_size + vp8_descriptor_size + payload_size;
56 int header_size = GetRtpHeaderSize(header.sources);
57 int total_size = size + header_size;
58 net::IOBufferWithSize* buffer = new net::IOBufferWithSize(total_size);
59 60
60 // Set marker if this is the last frame. 61 net::IOBufferWithSize* buffer = new net::IOBufferWithSize(total_size);
61 header.marker = (position + size) == payload.total_bytes();
62 62
63 // TODO(sergeyu): Handle sequence number wrapping. 63 // Pack header.
64 header.sequence_number = last_packet_number_; 64 PackRtpHeader(header, reinterpret_cast<uint8*>(buffer->data()),
65 ++last_packet_number_; 65 header_size);
66 66
67 // Generate header. 67 // Pack VP8 descriptor.
68 PackRtpHeader(reinterpret_cast<uint8*>(buffer->data()), buffer->size(), 68 PackVp8Descriptor(vp8_descriptor,
69 header); 69 reinterpret_cast<uint8*>(buffer->data()) + header_size,
70 vp8_descriptor_size);
70 71
71 // Copy data to the buffer. 72 // Copy payload to the buffer.
72 CompoundBuffer chunk; 73 payload.CopyTo(buffer->data() + header_size + vp8_descriptor_size,
73 chunk.CopyFrom(payload, position, position + size); 74 payload_size);
74 chunk.CopyTo(buffer->data() + header_size, size);
75 75
76 // Send it. 76 // And write the packet.
77 buffered_rtp_writer_->Write(buffer); 77 buffered_rtp_writer_->Write(buffer);
78
79 position += size;
80 }
81
82 DCHECK_EQ(position, payload.total_bytes());
83 } 78 }
84 79
85 int RtpWriter::GetPendingPackets() { 80 int RtpWriter::GetPendingPackets() {
86 return buffered_rtp_writer_->GetBufferChunks(); 81 return buffered_rtp_writer_->GetBufferChunks();
87 } 82 }
88 83
89 // Stop writing and drop pending data. Must be called from the same thread as 84 // Stop writing and drop pending data. Must be called from the same thread as
90 // Init(). 85 // Init().
91 void RtpWriter::Close() { 86 void RtpWriter::Close() {
92 buffered_rtp_writer_->Close(); 87 buffered_rtp_writer_->Close();
93 } 88 }
94 89
95 } // namespace protocol 90 } // namespace protocol
96 } // namespace remoting 91 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/rtp_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698