Chromium Code Reviews| 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 #include <math.h> | 5 #include <math.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "media/cast/test/utility/udp_proxy.h" | 9 #include "media/cast/test/utility/udp_proxy.h" |
| 10 | 10 |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 ComputeRates(); | 431 ComputeRates(); |
| 432 } | 432 } |
| 433 | 433 |
| 434 InterruptedPoissonProcess::~InterruptedPoissonProcess() { | 434 InterruptedPoissonProcess::~InterruptedPoissonProcess() { |
| 435 } | 435 } |
| 436 | 436 |
| 437 void InterruptedPoissonProcess::InitOnIOThread( | 437 void InterruptedPoissonProcess::InitOnIOThread( |
| 438 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 438 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 439 base::TickClock* clock) { | 439 base::TickClock* clock) { |
| 440 // Already initialized and started. | 440 // Already initialized and started. |
| 441 if (task_runner_ && clock_) | 441 if (task_runner_.get() && clock_) |
| 442 return; | 442 return; |
| 443 task_runner_ = task_runner; | 443 task_runner_ = task_runner; |
| 444 clock_ = clock; | 444 clock_ = clock; |
| 445 UpdateRates(); | 445 UpdateRates(); |
| 446 SwitchOn(); | 446 SwitchOn(); |
| 447 SendPacket(); | 447 SendPacket(); |
| 448 } | 448 } |
| 449 | 449 |
| 450 scoped_ptr<PacketPipe> InterruptedPoissonProcess::NewBuffer(size_t size) { | 450 scoped_ptr<PacketPipe> InterruptedPoissonProcess::NewBuffer(size_t size) { |
| 451 scoped_ptr<InternalBuffer> buffer( | 451 scoped_ptr<InternalBuffer> buffer( |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 // If it didn't work we just drop the packet at and call it a day. | 685 // If it didn't work we just drop the packet at and call it a day. |
| 686 scoped_refptr<net::IOBuffer> buf = | 686 scoped_refptr<net::IOBuffer> buf = |
| 687 new net::WrappedIOBuffer(reinterpret_cast<char*>(&packet->front())); | 687 new net::WrappedIOBuffer(reinterpret_cast<char*>(&packet->front())); |
| 688 size_t buf_size = packet->size(); | 688 size_t buf_size = packet->size(); |
| 689 int result; | 689 int result; |
| 690 if (destination.address().empty()) { | 690 if (destination.address().empty()) { |
| 691 VLOG(1) << "Destination has not been set yet."; | 691 VLOG(1) << "Destination has not been set yet."; |
| 692 result = net::ERR_INVALID_ARGUMENT; | 692 result = net::ERR_INVALID_ARGUMENT; |
| 693 } else { | 693 } else { |
| 694 VLOG(1) << "Destination:" << destination.ToString(); | 694 VLOG(1) << "Destination:" << destination.ToString(); |
| 695 result = socket_->SendTo(buf, | 695 result = socket_->SendTo(buf.get(), |
|
ddorwin
2014/08/25 21:26:39
I believe this is a pointer to a RefCounted object
dcheng
2014/08/25 21:33:25
Right, but before it was depending on the conversi
hubbe
2014/08/27 00:46:21
Explicit conversion is fine here.
The buffers life
| |
| 696 static_cast<int>(buf_size), | 696 static_cast<int>(buf_size), |
| 697 destination, | 697 destination, |
| 698 base::Bind(&UDPProxyImpl::AllowWrite, | 698 base::Bind(&UDPProxyImpl::AllowWrite, |
| 699 weak_factory_.GetWeakPtr(), | 699 weak_factory_.GetWeakPtr(), |
| 700 buf, | 700 buf, |
| 701 base::Passed(&packet))); | 701 base::Passed(&packet))); |
| 702 } | 702 } |
| 703 if (result == net::ERR_IO_PENDING) { | 703 if (result == net::ERR_IO_PENDING) { |
| 704 blocked_ = true; | 704 blocked_ = true; |
| 705 } else if (result < 0) { | 705 } else if (result < 0) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 ProcessPacket(recv_buf, len); | 766 ProcessPacket(recv_buf, len); |
| 767 PollRead(); | 767 PollRead(); |
| 768 } | 768 } |
| 769 | 769 |
| 770 void PollRead() { | 770 void PollRead() { |
| 771 while (true) { | 771 while (true) { |
| 772 packet_.reset(new Packet(kMaxPacketSize)); | 772 packet_.reset(new Packet(kMaxPacketSize)); |
| 773 scoped_refptr<net::IOBuffer> recv_buf = | 773 scoped_refptr<net::IOBuffer> recv_buf = |
| 774 new net::WrappedIOBuffer(reinterpret_cast<char*>(&packet_->front())); | 774 new net::WrappedIOBuffer(reinterpret_cast<char*>(&packet_->front())); |
| 775 int len = socket_->RecvFrom( | 775 int len = socket_->RecvFrom( |
| 776 recv_buf, | 776 recv_buf.get(), |
|
ddorwin
2014/08/25 21:26:40
ditto
dcheng
2014/08/25 21:33:25
See above.
| |
| 777 kMaxPacketSize, | 777 kMaxPacketSize, |
| 778 &recv_address_, | 778 &recv_address_, |
| 779 base::Bind(&UDPProxyImpl::ReadCallback, | 779 base::Bind( |
| 780 base::Unretained(this), | 780 &UDPProxyImpl::ReadCallback, base::Unretained(this), recv_buf)); |
| 781 recv_buf)); | |
| 782 if (len == net::ERR_IO_PENDING) | 781 if (len == net::ERR_IO_PENDING) |
| 783 break; | 782 break; |
| 784 ProcessPacket(recv_buf, len); | 783 ProcessPacket(recv_buf, len); |
| 785 } | 784 } |
| 786 } | 785 } |
| 787 | 786 |
| 788 void AllowWrite(scoped_refptr<net::IOBuffer> buf, | 787 void AllowWrite(scoped_refptr<net::IOBuffer> buf, |
| 789 scoped_ptr<Packet> packet, | 788 scoped_ptr<Packet> packet, |
| 790 int unused_len) { | 789 int unused_len) { |
| 791 DCHECK(blocked_); | 790 DCHECK(blocked_); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 831 destination, | 830 destination, |
| 832 to_dest_pipe.Pass(), | 831 to_dest_pipe.Pass(), |
| 833 from_dest_pipe.Pass(), | 832 from_dest_pipe.Pass(), |
| 834 net_log)); | 833 net_log)); |
| 835 return ret.Pass(); | 834 return ret.Pass(); |
| 836 } | 835 } |
| 837 | 836 |
| 838 } // namespace test | 837 } // namespace test |
| 839 } // namespace cast | 838 } // namespace cast |
| 840 } // namespace media | 839 } // namespace media |
| OLD | NEW |