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

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

Issue 4229003: Add VideoReader and VideoWriter interfaces. (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') | remoting/protocol/stream_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
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/protocol/rtp_utils.h" 9 #include "remoting/protocol/rtp_utils.h"
10 10
(...skipping 14 matching lines...) Expand all
25 25
26 // Initializes the writer. Must be called on the thread the sockets belong 26 // Initializes the writer. Must be called on the thread the sockets belong
27 // to. 27 // to.
28 void RtpWriter::Init(net::Socket* rtp_socket, net::Socket* rtcp_socket) { 28 void RtpWriter::Init(net::Socket* rtp_socket, net::Socket* rtcp_socket) {
29 buffered_rtp_writer_ = new BufferedDatagramWriter(); 29 buffered_rtp_writer_ = new BufferedDatagramWriter();
30 buffered_rtp_writer_->Init(rtp_socket, NULL); 30 buffered_rtp_writer_->Init(rtp_socket, NULL);
31 rtp_socket_ = rtp_socket; 31 rtp_socket_ = rtp_socket;
32 rtcp_socket_ = rtcp_socket; 32 rtcp_socket_ = rtcp_socket;
33 } 33 }
34 34
35 void RtpWriter::SendPacket(const char* data, int packet_size, 35 void RtpWriter::SendPacket(const char* payload, int payload_size,
36 uint32 timestamp) { 36 uint32 timestamp) {
37 RtpHeader header; 37 RtpHeader header;
38 header.padding = false; 38 header.padding = false;
39 header.extension = false; 39 header.extension = false;
40 header.sources = 0; 40 header.sources = 0;
41 header.payload_type = kRtpPayloadTypePrivate; 41 header.payload_type = kRtpPayloadTypePrivate;
42 header.timestamp = timestamp; 42 header.timestamp = timestamp;
43 43
44 // TODO(sergeyu): RTP requires that SSRC is chosen randomly by each 44 // TODO(sergeyu): RTP requires that SSRC is chosen randomly by each
45 // participant. There are only two participants in chromoting session, 45 // participant. There are only two participants in chromoting session,
46 // so SSRC isn't useful. Implement it in future if neccessary. 46 // so SSRC isn't useful. Implement it in future if neccessary.
47 header.sync_source_id = 0; 47 header.sync_source_id = 0;
48 48
49 // TODO(sergeyu): Add VP8 payload header. 49 // TODO(sergeyu): Add VP8 payload header.
50 50
51 int position = 0; 51 int position = 0;
52 while (position < packet_size) { 52 while (position < payload_size) {
53 // Allocate buffer. 53 // Allocate buffer.
54 int size = std::max(kMtu, packet_size - position); 54 int size = std::min(kMtu, payload_size - position);
55 int header_size = GetRtpHeaderSize(header.sources) + size; 55 int header_size = GetRtpHeaderSize(header.sources);
56 int total_size = size + header_size; 56 int total_size = size + header_size;
57 net::IOBufferWithSize* buffer = new net::IOBufferWithSize(total_size); 57 net::IOBufferWithSize* buffer = new net::IOBufferWithSize(total_size);
58 58
59 // Set marker if this is the last frame. 59 // Set marker if this is the last frame.
60 header.marker = (position + size) == packet_size; 60 header.marker = (position + size) == payload_size;
61 61
62 // TODO(sergeyu): Handle sequence number wrapping. 62 // TODO(sergeyu): Handle sequence number wrapping.
63 header.sequence_number = last_packet_number_; 63 header.sequence_number = last_packet_number_;
64 ++last_packet_number_; 64 ++last_packet_number_;
65 65
66 // Generate header. 66 // Generate header.
67 PackRtpHeader(reinterpret_cast<uint8*>(buffer->data()), buffer->size(), 67 PackRtpHeader(reinterpret_cast<uint8*>(buffer->data()), buffer->size(),
68 header); 68 header);
69 69
70 // Copy data to the buffer. 70 // Copy data to the buffer.
71 memcpy(buffer->data() + header_size, data + position, size); 71 memcpy(buffer->data() + header_size, payload + position, size);
72 72
73 // Send it. 73 // Send it.
74 buffered_rtp_writer_->Write(buffer); 74 buffered_rtp_writer_->Write(buffer);
75 75
76 position += size; 76 position += size;
77 } 77 }
78 78
79 DCHECK_EQ(position, packet_size); 79 DCHECK_EQ(position, payload_size);
80 }
81
82 int RtpWriter::GetPendingPackets() {
83 return buffered_rtp_writer_->GetBufferChunks();
80 } 84 }
81 85
82 // Stop writing and drop pending data. Must be called from the same thread as 86 // Stop writing and drop pending data. Must be called from the same thread as
83 // Init(). 87 // Init().
84 void RtpWriter::Close() { 88 void RtpWriter::Close() {
85 buffered_rtp_writer_->Close(); 89 buffered_rtp_writer_->Close();
86 } 90 }
87 91
88 } // namespace remoting 92 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/rtp_writer.h ('k') | remoting/protocol/stream_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698