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

Unified Diff: media/cast/transport/transport/udp_transport.cc

Issue 252923007: Cast: Fix two video freezing problems (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mac fix Created 6 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/cast/transport/transport/udp_transport.h ('k') | media/cast/transport/transport_audio_sender.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/cast/transport/transport/udp_transport.cc
diff --git a/media/cast/transport/transport/udp_transport.cc b/media/cast/transport/transport/udp_transport.cc
index 578b9593e9a6bd8333bb78ad42b3a590acd0edee..bcce4f72f3172d1764e5d588cb880ae093908827 100644
--- a/media/cast/transport/transport/udp_transport.cc
+++ b/media/cast/transport/transport/udp_transport.cc
@@ -52,6 +52,7 @@ UdpTransport::UdpTransport(
net_log,
net::NetLog::Source())),
send_pending_(false),
+ receive_pending_(false),
client_connected_(false),
status_callback_(status_callback),
weak_factory_(this) {
@@ -84,7 +85,18 @@ void UdpTransport::StartReceiving(
NOTREACHED() << "Either local or remote address has to be defined.";
}
- ReceiveNextPacket(net::ERR_IO_PENDING);
+ ScheduleReceiveNextPacket();
+}
+
+void UdpTransport::ScheduleReceiveNextPacket() {
+ DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread());
+ if (!packet_receiver_.is_null() && !receive_pending_) {
+ receive_pending_ = true;
+ io_thread_proxy_->PostTask(FROM_HERE,
+ base::Bind(&UdpTransport::ReceiveNextPacket,
+ weak_factory_.GetWeakPtr(),
+ net::ERR_IO_PENDING));
+ }
}
void UdpTransport::ReceiveNextPacket(int length_or_status) {
@@ -104,16 +116,18 @@ void UdpTransport::ReceiveNextPacket(int length_or_status) {
&recv_addr_,
base::Bind(&UdpTransport::ReceiveNextPacket,
weak_factory_.GetWeakPtr()));
- if (length_or_status == net::ERR_IO_PENDING)
+ if (length_or_status == net::ERR_IO_PENDING) {
+ receive_pending_ = true;
return;
+ }
}
// Note: At this point, either a packet is ready or an error has occurred.
-
if (length_or_status < 0) {
VLOG(1) << "Failed to receive packet: Status code is "
- << length_or_status << ". Stop receiving packets.";
+ << length_or_status;
status_callback_.Run(TRANSPORT_SOCKET_ERROR);
+ receive_pending_ = false;
return;
}
@@ -181,6 +195,8 @@ bool UdpTransport::SendPacket(PacketRef packet, const base::Closure& cb) {
status_callback_.Run(TRANSPORT_SOCKET_ERROR);
return true;
} else {
+ // Successful send, re-start reading if needed.
+ ScheduleReceiveNextPacket();
return true;
}
}
@@ -195,6 +211,9 @@ void UdpTransport::OnSent(const scoped_refptr<net::IOBuffer>& buf,
if (result < 0) {
LOG(ERROR) << "Failed to send packet: " << result << ".";
status_callback_.Run(TRANSPORT_SOCKET_ERROR);
+ } else {
+ // Successful send, re-start reading if needed.
+ ScheduleReceiveNextPacket();
}
if (!cb.is_null()) {
« no previous file with comments | « media/cast/transport/transport/udp_transport.h ('k') | media/cast/transport/transport_audio_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698