OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef MEDIA_CAST_NET_UDP_TRANSPORT_H_ | 5 #ifndef MEDIA_CAST_NET_UDP_TRANSPORT_H_ |
6 #define MEDIA_CAST_NET_UDP_TRANSPORT_H_ | 6 #define MEDIA_CAST_NET_UDP_TRANSPORT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/values.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "media/cast/cast_environment.h" | 16 #include "media/cast/cast_environment.h" |
16 #include "media/cast/net/cast_transport_config.h" | 17 #include "media/cast/net/cast_transport_config.h" |
17 #include "media/cast/net/cast_transport_sender.h" | 18 #include "media/cast/net/cast_transport_sender.h" |
| 19 #include "media/cast/net/pacing/paced_sender.h" |
18 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
19 #include "net/base/ip_endpoint.h" | 21 #include "net/base/ip_endpoint.h" |
20 #include "net/udp/diff_serv_code_point.h" | 22 #include "net/udp/diff_serv_code_point.h" |
21 #include "net/udp/udp_socket.h" | 23 #include "net/udp/udp_socket.h" |
22 | 24 |
23 namespace net { | 25 namespace net { |
24 class NetLog; | 26 class NetLog; |
25 } // namespace net | 27 } // namespace net |
26 | 28 |
27 namespace media { | 29 namespace media { |
28 namespace cast { | 30 namespace cast { |
29 | 31 |
30 // This class implements UDP transport mechanism for Cast. | 32 // This class implements UDP transport mechanism for Cast. |
31 class UdpTransport : public PacketSender { | 33 class UdpTransport : public PacketSender { |
32 public: | 34 public: |
33 // Construct a UDP transport. | 35 // Construct a UDP transport. |
34 // All methods must be called on |io_thread_proxy|. | 36 // All methods must be called on |io_thread_proxy|. |
35 // |local_end_point| specifies the address and port to bind and listen | 37 // |local_end_point| specifies the address and port to bind and listen |
36 // to incoming packets. If the value is 0.0.0.0:0 then a bind is not | 38 // to incoming packets. If the value is 0.0.0.0:0 then a bind is not |
37 // performed. | 39 // performed. |
38 // |remote_end_point| specifies the address and port to send packets | 40 // |remote_end_point| specifies the address and port to send packets |
39 // to. If the value is 0.0.0.0:0 the the end point is set to the source | 41 // to. If the value is 0.0.0.0:0 the the end point is set to the source |
40 // address of the first packet received. | 42 // address of the first packet received. |
41 // |send_buffer_size| specifies the size of the socket send buffer. | 43 // |send_buffer_size| specifies the size of the socket send buffer. |
42 UdpTransport( | 44 UdpTransport( |
43 net::NetLog* net_log, | 45 net::NetLog* net_log, |
44 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_proxy, | 46 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_proxy, |
45 const net::IPEndPoint& local_end_point, | 47 const net::IPEndPoint& local_end_point, |
46 const net::IPEndPoint& remote_end_point, | 48 const net::IPEndPoint& remote_end_point, |
47 int32_t send_buffer_size, | |
48 const CastTransportStatusCallback& status_callback); | 49 const CastTransportStatusCallback& status_callback); |
49 ~UdpTransport() final; | 50 ~UdpTransport() final; |
50 | 51 |
51 // Start receiving packets. Packets are submitted to |packet_receiver|. | 52 // Start receiving packets. Packets are submitted to |packet_receiver|. |
52 void StartReceiving(const PacketReceiverCallbackWithStatus& packet_receiver); | 53 void StartReceiving( |
53 void StopReceiving(); | 54 const PacketReceiverCallbackWithStatus& packet_receiver) final; |
| 55 void StopReceiving() final; |
54 | 56 |
55 // Set a new DSCP value to the socket. The value will be set right before | 57 // Set a new DSCP value to the socket. The value will be set right before |
56 // the next send. | 58 // the next send. |
57 void SetDscp(net::DiffServCodePoint dscp); | 59 void SetDscp(net::DiffServCodePoint dscp); |
58 | 60 |
| 61 // Set UdpTransport options. |
| 62 // Possible keys are: |
| 63 // "pacer_max_burst_size": int |
| 64 // - Specifies how many pakcets to send per 10 ms, maximum. |
| 65 // "send_buffer_min_size": int |
| 66 // - Specifies the minimum socket send buffer size. |
| 67 // "DSCP" (value ignored) |
| 68 // - Turns DSCP on (higher IP Precedence and Type of Service). |
| 69 // "disable_non_blocking_io" (value ignored) |
| 70 // - Windows only. Turns off non-blocking IO for the socket. |
| 71 // Note: Non-blocking IO is, by default, enabled on all platforms. |
| 72 void SetUdpOptions(const base::DictionaryValue& options); |
| 73 |
| 74 // This has to be called before |StartReceiving()| to change the |
| 75 // |send_buffer_size_|. Calling |SetUdpOptions()| will automatically call it. |
| 76 void SetSendBufferSize(int32_t send_buffer_size); |
| 77 |
59 #if defined(OS_WIN) | 78 #if defined(OS_WIN) |
60 // Switch to use non-blocking IO. Must be called before StartReceiving(). | 79 // Switch to use non-blocking IO. Must be called before StartReceiving(). |
61 void UseNonBlockingIO(); | 80 void UseNonBlockingIO(); |
62 #endif | 81 #endif |
63 | 82 |
64 // PacketSender implementations. | 83 // PacketSender implementations. |
65 bool SendPacket(PacketRef packet, const base::Closure& cb) final; | 84 bool SendPacket(PacketRef packet, const base::Closure& cb) final; |
66 int64_t GetBytesSent() final; | 85 int64_t GetBytesSent() final; |
67 | 86 |
68 private: | 87 private: |
(...skipping 30 matching lines...) Expand all Loading... |
99 // NOTE: Weak pointers must be invalidated before all other member variables. | 118 // NOTE: Weak pointers must be invalidated before all other member variables. |
100 base::WeakPtrFactory<UdpTransport> weak_factory_; | 119 base::WeakPtrFactory<UdpTransport> weak_factory_; |
101 | 120 |
102 DISALLOW_COPY_AND_ASSIGN(UdpTransport); | 121 DISALLOW_COPY_AND_ASSIGN(UdpTransport); |
103 }; | 122 }; |
104 | 123 |
105 } // namespace cast | 124 } // namespace cast |
106 } // namespace media | 125 } // namespace media |
107 | 126 |
108 #endif // MEDIA_CAST_NET_UDP_TRANSPORT_H_ | 127 #endif // MEDIA_CAST_NET_UDP_TRANSPORT_H_ |
OLD | NEW |