OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/renderer_host/p2p/socket_host_tcp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/sys_byteorder.h" | 12 #include "base/sys_byteorder.h" |
13 #include "content/common/p2p_messages.h" | 13 #include "content/common/p2p_messages.h" |
14 #include "ipc/ipc_sender.h" | 14 #include "ipc/ipc_sender.h" |
15 #include "jingle/glue/fake_ssl_client_socket.h" | 15 #include "jingle/glue/fake_ssl_client_socket.h" |
16 #include "jingle/glue/proxy_resolving_client_socket.h" | 16 #include "jingle/glue/proxy_resolving_client_socket.h" |
17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
20 #include "net/socket/client_socket_factory.h" | 20 #include "net/socket/client_socket_factory.h" |
21 #include "net/socket/client_socket_handle.h" | 21 #include "net/socket/client_socket_handle.h" |
22 #include "net/socket/ssl_client_socket.h" | 22 #include "net/socket/ssl_client_socket.h" |
23 #include "net/socket/tcp_client_socket.h" | 23 #include "net/socket/tcp_client_socket.h" |
24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
25 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
26 #include "third_party/webrtc/base/asyncpacketsocket.h" | 26 #include "third_party/libjingle/source/talk/media/base/rtputils.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 typedef uint16_t PacketLength; | 30 typedef uint16_t PacketLength; |
31 const int kPacketHeaderSize = sizeof(PacketLength); | 31 const int kPacketHeaderSize = sizeof(PacketLength); |
32 const int kReadBufferSize = 4096; | 32 const int kReadBufferSize = 4096; |
33 const int kPacketLengthOffset = 2; | 33 const int kPacketLengthOffset = 2; |
34 const int kTurnChannelDataHeaderSize = 4; | 34 const int kTurnChannelDataHeaderSize = 4; |
35 const int kRecvSocketBufferSize = 128 * 1024; | 35 const int kRecvSocketBufferSize = 128 * 1024; |
36 const int kSendSocketBufferSize = 128 * 1024; | 36 const int kSendSocketBufferSize = 128 * 1024; |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 | 521 |
522 void P2PSocketHostTcp::DoSend(const net::IPEndPoint& to, | 522 void P2PSocketHostTcp::DoSend(const net::IPEndPoint& to, |
523 const std::vector<char>& data, | 523 const std::vector<char>& data, |
524 const rtc::PacketOptions& options) { | 524 const rtc::PacketOptions& options) { |
525 int size = kPacketHeaderSize + data.size(); | 525 int size = kPacketHeaderSize + data.size(); |
526 scoped_refptr<net::DrainableIOBuffer> buffer = | 526 scoped_refptr<net::DrainableIOBuffer> buffer = |
527 new net::DrainableIOBuffer(new net::IOBuffer(size), size); | 527 new net::DrainableIOBuffer(new net::IOBuffer(size), size); |
528 *reinterpret_cast<uint16_t*>(buffer->data()) = base::HostToNet16(data.size()); | 528 *reinterpret_cast<uint16_t*>(buffer->data()) = base::HostToNet16(data.size()); |
529 memcpy(buffer->data() + kPacketHeaderSize, &data[0], data.size()); | 529 memcpy(buffer->data() + kPacketHeaderSize, &data[0], data.size()); |
530 | 530 |
531 packet_processing_helpers::ApplyPacketOptions( | 531 cricket::ApplyPacketOptions( |
532 buffer->data() + kPacketHeaderSize, | 532 reinterpret_cast<uint8_t*>(buffer->data()) + kPacketHeaderSize, |
533 buffer->BytesRemaining() - kPacketHeaderSize, | 533 buffer->BytesRemaining() - kPacketHeaderSize, options.packet_time_params, |
534 options, 0); | 534 (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds()); |
535 | 535 |
536 WriteOrQueue(buffer); | 536 WriteOrQueue(buffer); |
537 } | 537 } |
538 | 538 |
539 // P2PSocketHostStunTcp | 539 // P2PSocketHostStunTcp |
540 P2PSocketHostStunTcp::P2PSocketHostStunTcp( | 540 P2PSocketHostStunTcp::P2PSocketHostStunTcp( |
541 IPC::Sender* message_sender, | 541 IPC::Sender* message_sender, |
542 int socket_id, | 542 int socket_id, |
543 P2PSocketType type, | 543 P2PSocketType type, |
544 net::URLRequestContextGetter* url_context) | 544 net::URLRequestContextGetter* url_context) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 return; | 594 return; |
595 } | 595 } |
596 | 596 |
597 // Add any pad bytes to the total size. | 597 // Add any pad bytes to the total size. |
598 int size = data.size() + pad_bytes; | 598 int size = data.size() + pad_bytes; |
599 | 599 |
600 scoped_refptr<net::DrainableIOBuffer> buffer = | 600 scoped_refptr<net::DrainableIOBuffer> buffer = |
601 new net::DrainableIOBuffer(new net::IOBuffer(size), size); | 601 new net::DrainableIOBuffer(new net::IOBuffer(size), size); |
602 memcpy(buffer->data(), &data[0], data.size()); | 602 memcpy(buffer->data(), &data[0], data.size()); |
603 | 603 |
604 packet_processing_helpers::ApplyPacketOptions( | 604 cricket::ApplyPacketOptions( |
605 buffer->data(), data.size(), options, 0); | 605 reinterpret_cast<uint8_t*>(buffer->data()), data.size(), |
| 606 options.packet_time_params, |
| 607 (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds()); |
606 | 608 |
607 if (pad_bytes) { | 609 if (pad_bytes) { |
608 char padding[4] = {0}; | 610 char padding[4] = {0}; |
609 DCHECK_LE(pad_bytes, 4); | 611 DCHECK_LE(pad_bytes, 4); |
610 memcpy(buffer->data() + data.size(), padding, pad_bytes); | 612 memcpy(buffer->data() + data.size(), padding, pad_bytes); |
611 } | 613 } |
612 WriteOrQueue(buffer); | 614 WriteOrQueue(buffer); |
613 | 615 |
614 if (dump_outgoing_rtp_packet_) | 616 if (dump_outgoing_rtp_packet_) |
615 DumpRtpPacket(buffer->data(), data.size(), false); | 617 DumpRtpPacket(buffer->data(), data.size(), false); |
(...skipping 17 matching lines...) Expand all Loading... |
633 } else { | 635 } else { |
634 packet_size += kTurnChannelDataHeaderSize; | 636 packet_size += kTurnChannelDataHeaderSize; |
635 // Calculate any padding if present. | 637 // Calculate any padding if present. |
636 if (packet_size % 4) | 638 if (packet_size % 4) |
637 *pad_bytes = 4 - packet_size % 4; | 639 *pad_bytes = 4 - packet_size % 4; |
638 } | 640 } |
639 return packet_size; | 641 return packet_size; |
640 } | 642 } |
641 | 643 |
642 } // namespace content | 644 } // namespace content |
OLD | NEW |