From c78b0ea615849977a791b78613b8c27c53aecb6b Mon Sep 17 00:00:00 2001 From: Bjorn Mellem Date: Mon, 29 Oct 2018 15:21:31 -0700 Subject: [PATCH] Create a MediaTransportState enum and add a state callback to MediaTransport. Bug: webrtc:9719 Change-Id: Icf7004be5e3a2784fccc1d910c8b77ea3b3d5156 Reviewed-on: https://webrtc-review.googlesource.com/c/108501 Reviewed-by: Seth Hampson Reviewed-by: Peter Slatala Commit-Queue: Bjorn Mellem Cr-Commit-Position: refs/heads/master@{#25438} --- api/media_transport_interface.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/api/media_transport_interface.h b/api/media_transport_interface.h index 6580370a0e..ca26851414 100644 --- a/api/media_transport_interface.h +++ b/api/media_transport_interface.h @@ -209,6 +209,25 @@ class MediaTransportVideoSinkInterface { virtual void OnKeyFrameRequested(uint64_t channel_id) = 0; }; +// State of the media transport. Media transport begins in the pending state. +// It transitions to writable when it is ready to send media. It may transition +// back to pending if the connection is blocked. It may transition to closed at +// any time. Closed is terminal: a transport will never re-open once closed. +enum class MediaTransportState { + kPending, + kWritable, + kClosed, +}; + +// Callback invoked whenever the state of the media transport changes. +class MediaTransportStateCallback { + public: + virtual ~MediaTransportStateCallback() = default; + + // Invoked whenever the state of the media transport changes. + virtual void OnStateChanged(MediaTransportState state) = 0; +}; + // Media transport interface for sending / receiving encoded audio/video frames // and receiving bandwidth estimate update from congestion control. class MediaTransportInterface { @@ -250,6 +269,14 @@ class MediaTransportInterface { virtual void SetTargetTransferRateObserver( webrtc::TargetTransferRateObserver* observer) = 0; + // Sets a state observer callback. Before media transport is destroyed, the + // callback must be unregistered by setting it to nullptr. + // A newly registered callback will be called with the current state. + // Media transport does not invoke this callback concurrently. + // TODO(mellem): Make this pure virtual once all implementations support it. + virtual void SetMediaTransportStateCallback( + MediaTransportStateCallback* callback) {} + // TODO(sukhanov): RtcEventLogs. };