Commit 64a33c33 authored by Xiangjun Zhang's avatar Xiangjun Zhang Committed by Commit Bot

Media Remoting: Get estimated network bandwidth from Remoter.

This CL adds the interface to get estimated network capacity from
Remoter. A follow up CL will check whether the network bandwidth is
sufficient to activate media remoting.

Bug: 739972
Change-Id: Ica6aee81b23894748951fc8f27afcf74dabb6a28
Reviewed-on: https://chromium-review.googlesource.com/587507
Commit-Queue: Xiangjun Zhang <xjz@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491772}
parent e5661098
...@@ -96,6 +96,14 @@ class CastRemotingConnector::RemotingBridge : public media::mojom::Remoter { ...@@ -96,6 +96,14 @@ class CastRemotingConnector::RemotingBridge : public media::mojom::Remoter {
if (connector_) if (connector_)
connector_->SendMessageToSink(this, message); connector_->SendMessageToSink(this, message);
} }
void EstimateTransmissionCapacity(
media::mojom::Remoter::EstimateTransmissionCapacityCallback callback)
final {
if (connector_)
connector_->EstimateTransmissionCapacity(std::move(callback));
else
std::move(callback).Run(0);
}
private: private:
media::mojom::RemotingSourcePtr source_; media::mojom::RemotingSourcePtr source_;
...@@ -386,6 +394,14 @@ void CastRemotingConnector::OnMessageFromSink( ...@@ -386,6 +394,14 @@ void CastRemotingConnector::OnMessageFromSink(
active_bridge_->OnMessageFromSink(message); active_bridge_->OnMessageFromSink(message);
} }
void CastRemotingConnector::EstimateTransmissionCapacity(
media::mojom::Remoter::EstimateTransmissionCapacityCallback callback) {
if (remoter_)
remoter_->EstimateTransmissionCapacity(std::move(callback));
else
std::move(callback).Run(0);
}
void CastRemotingConnector::OnSinkAvailable( void CastRemotingConnector::OnSinkAvailable(
media::mojom::RemotingSinkMetadataPtr metadata) { media::mojom::RemotingSinkMetadataPtr metadata) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
...@@ -142,6 +142,8 @@ class CastRemotingConnector : public base::SupportsUserData::Data, ...@@ -142,6 +142,8 @@ class CastRemotingConnector : public base::SupportsUserData::Data,
media::mojom::RemotingStopReason reason); media::mojom::RemotingStopReason reason);
void SendMessageToSink(RemotingBridge* bridge, void SendMessageToSink(RemotingBridge* bridge,
const std::vector<uint8_t>& message); const std::vector<uint8_t>& message);
void EstimateTransmissionCapacity(
media::mojom::Remoter::EstimateTransmissionCapacityCallback callback);
// Called when RTP streams are started. // Called when RTP streams are started.
void OnDataStreamsStarted( void OnDataStreamsStarted(
......
...@@ -133,6 +133,12 @@ class MockMediaRemoter : public media::mojom::MirrorServiceRemoter { ...@@ -133,6 +133,12 @@ class MockMediaRemoter : public media::mojom::MirrorServiceRemoter {
void OnSinkAvailable() { source_->OnSinkAvailable(GetDefaultSinkMetadata()); } void OnSinkAvailable() { source_->OnSinkAvailable(GetDefaultSinkMetadata()); }
void EstimateTransmissionCapacity(
media::mojom::Remoter::EstimateTransmissionCapacityCallback callback)
final {
std::move(callback).Run(0);
}
void SendMessageToSource(const std::vector<uint8_t>& message) { void SendMessageToSource(const std::vector<uint8_t>& message) {
source_->OnMessageFromSink(message); source_->OnMessageFromSink(message);
} }
......
...@@ -29,6 +29,10 @@ interface MirrorServiceRemoter { ...@@ -29,6 +29,10 @@ interface MirrorServiceRemoter {
// Sends|message| to the sink. |message| is a serialized protobuf from // Sends|message| to the sink. |message| is a serialized protobuf from
// src/media/remoting/proto. // src/media/remoting/proto.
SendMessageToSink(array<uint8> message); SendMessageToSink(array<uint8> message);
// Estimates the transmission capacity. Returns the result in
// bytes per second.
EstimateTransmissionCapacity() => (double rate);
}; };
// Interface used for sending notifications back to the source's control logic, // Interface used for sending notifications back to the source's control logic,
......
...@@ -71,6 +71,10 @@ interface Remoter { ...@@ -71,6 +71,10 @@ interface Remoter {
// Sends |message| to the sink. |message| is a serialized protobuf from // Sends |message| to the sink. |message| is a serialized protobuf from
// src/media/remoting/proto. // src/media/remoting/proto.
SendMessageToSink(array<uint8> message); SendMessageToSink(array<uint8> message);
// Estimates the transmission capacity. Returns the result in
// bytes per second.
EstimateTransmissionCapacity() => (double rate);
}; };
// Interface used for sending notifications back to the local source's control // Interface used for sending notifications back to the local source's control
......
...@@ -110,6 +110,11 @@ class TestRemoter final : public mojom::Remoter { ...@@ -110,6 +110,11 @@ class TestRemoter final : public mojom::Remoter {
send_message_to_sink_cb_.Run(message); send_message_to_sink_cb_.Run(message);
} }
void EstimateTransmissionCapacity(
mojom::Remoter::EstimateTransmissionCapacityCallback callback) override {
std::move(callback).Run(0);
}
// Called when receives RPC messages from receiver. // Called when receives RPC messages from receiver.
void OnMessageFromSink(const std::vector<uint8_t>& message) { void OnMessageFromSink(const std::vector<uint8_t>& message) {
source_->OnMessageFromSink(message); source_->OnMessageFromSink(message);
......
...@@ -152,6 +152,11 @@ void FakeRemoter::Stop(mojom::RemotingStopReason reason) { ...@@ -152,6 +152,11 @@ void FakeRemoter::Stop(mojom::RemotingStopReason reason) {
void FakeRemoter::SendMessageToSink(const std::vector<uint8_t>& message) {} void FakeRemoter::SendMessageToSink(const std::vector<uint8_t>& message) {}
void FakeRemoter::EstimateTransmissionCapacity(
mojom::Remoter::EstimateTransmissionCapacityCallback callback) {
std::move(callback).Run(10000000 / 8.0);
}
void FakeRemoter::Started() { void FakeRemoter::Started() {
source_->OnStarted(); source_->OnStarted();
} }
......
...@@ -67,6 +67,8 @@ class FakeRemoter final : public mojom::Remoter { ...@@ -67,6 +67,8 @@ class FakeRemoter final : public mojom::Remoter {
mojom::RemotingDataStreamSenderRequest video_sender_request) override; mojom::RemotingDataStreamSenderRequest video_sender_request) override;
void Stop(mojom::RemotingStopReason reason) override; void Stop(mojom::RemotingStopReason reason) override;
void SendMessageToSink(const std::vector<uint8_t>& message) override; void SendMessageToSink(const std::vector<uint8_t>& message) override;
void EstimateTransmissionCapacity(
mojom::Remoter::EstimateTransmissionCapacityCallback callback) override;
private: private:
void Started(); void Started();
......
...@@ -416,10 +416,15 @@ void RendererController::WaitForStabilityBeforeStart( ...@@ -416,10 +416,15 @@ void RendererController::WaitForStabilityBeforeStart(
start_trigger, start_trigger,
client_->AudioDecodedByteCount() + client_->VideoDecodedByteCount(), client_->AudioDecodedByteCount() + client_->VideoDecodedByteCount(),
clock_->NowTicks())); clock_->NowTicks()));
session_->EstimateTransmissionCapacity(
base::BindOnce(&RendererController::OnReceivedTransmissionCapacity,
weak_factory_.GetWeakPtr()));
} }
void RendererController::CancelDelayedStart() { void RendererController::CancelDelayedStart() {
delayed_start_stability_timer_.Stop(); delayed_start_stability_timer_.Stop();
transmission_capacity_ = 0;
} }
void RendererController::OnDelayedStartTimerFired( void RendererController::OnDelayedStartTimerFired(
...@@ -437,16 +442,15 @@ void RendererController::OnDelayedStartTimerFired( ...@@ -437,16 +442,15 @@ void RendererController::OnDelayedStartTimerFired(
decoded_bytes_before_delay) * decoded_bytes_before_delay) *
8.0 / elapsed.InSecondsF() / 1000.0; 8.0 / elapsed.InSecondsF() / 1000.0;
DCHECK_GE(kilobits_per_second, 0); DCHECK_GE(kilobits_per_second, 0);
// TODO(xjz): Gets the estimated transmission capacity (kbps) from Remoter. const double capacity_kbps = transmission_capacity_ * 8.0 / 1000.0;
const double capacity = 10000.0;
metrics_recorder_.RecordMediaBitrateVersusCapacity(kilobits_per_second, metrics_recorder_.RecordMediaBitrateVersusCapacity(kilobits_per_second,
capacity); capacity_kbps);
if (kilobits_per_second <= kMaxMediaBitrateCapacityFraction * capacity) { if (kilobits_per_second <= kMaxMediaBitrateCapacityFraction * capacity_kbps) {
StartRemoting(start_trigger); StartRemoting(start_trigger);
} else { } else {
VLOG(1) << "Media remoting is not supported: bitrate(kbps)=" VLOG(1) << "Media remoting is not supported: bitrate(kbps)="
<< kilobits_per_second << kilobits_per_second
<< " transmission_capacity(kbps)=" << capacity; << " transmission_capacity(kbps)=" << capacity_kbps;
encountered_renderer_fatal_error_ = true; encountered_renderer_fatal_error_ = true;
} }
} }
...@@ -465,6 +469,11 @@ void RendererController::StartRemoting(StartTrigger start_trigger) { ...@@ -465,6 +469,11 @@ void RendererController::StartRemoting(StartTrigger start_trigger) {
session_->StartRemoting(this); session_->StartRemoting(this);
} }
void RendererController::OnReceivedTransmissionCapacity(double rate) {
DCHECK_GE(rate, 0);
transmission_capacity_ = rate;
}
void RendererController::OnRendererFatalError(StopTrigger stop_trigger) { void RendererController::OnRendererFatalError(StopTrigger stop_trigger) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
......
...@@ -131,6 +131,9 @@ class RendererController final : public SharedSession::Client, ...@@ -131,6 +131,9 @@ class RendererController final : public SharedSession::Client,
// Helper to request the media pipeline switch to the remoting renderer. // Helper to request the media pipeline switch to the remoting renderer.
void StartRemoting(StartTrigger start_trigger); void StartRemoting(StartTrigger start_trigger);
// Callback to get the estimated transmission capacity from Remoter.
void OnReceivedTransmissionCapacity(double rate);
// Indicates whether remoting is started. // Indicates whether remoting is started.
bool remote_rendering_started_ = false; bool remote_rendering_started_ = false;
...@@ -190,6 +193,9 @@ class RendererController final : public SharedSession::Client, ...@@ -190,6 +193,9 @@ class RendererController final : public SharedSession::Client,
std::unique_ptr<base::TickClock> clock_; std::unique_ptr<base::TickClock> clock_;
// The estimated transmission capacity (bytes/s) from Remoter.
double transmission_capacity_ = 0;
base::WeakPtrFactory<RendererController> weak_factory_; base::WeakPtrFactory<RendererController> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(RendererController); DISALLOW_COPY_AND_ASSIGN(RendererController);
......
...@@ -245,5 +245,11 @@ void SharedSession::SendMessageToSink( ...@@ -245,5 +245,11 @@ void SharedSession::SendMessageToSink(
remoter_->SendMessageToSink(*message); remoter_->SendMessageToSink(*message);
} }
void SharedSession::EstimateTransmissionCapacity(
mojom::Remoter::EstimateTransmissionCapacityCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
remoter_->EstimateTransmissionCapacity(std::move(callback));
}
} // namespace remoting } // namespace remoting
} // namespace media } // namespace media
...@@ -128,6 +128,9 @@ class SharedSession final : public mojom::RemotingSource, ...@@ -128,6 +128,9 @@ class SharedSession final : public mojom::RemotingSource,
RpcBroker* rpc_broker() { return &rpc_broker_; } RpcBroker* rpc_broker() { return &rpc_broker_; }
void EstimateTransmissionCapacity(
mojom::Remoter::EstimateTransmissionCapacityCallback callback);
private: private:
friend class base::RefCountedThreadSafe<SharedSession>; friend class base::RefCountedThreadSafe<SharedSession>;
~SharedSession() override; ~SharedSession() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment