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 <shampson@webrtc.org>
Reviewed-by: Peter Slatala <psla@webrtc.org>
Commit-Queue: Bjorn Mellem <mellem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25438}
diff --git a/api/media_transport_interface.h b/api/media_transport_interface.h
index 6580370..ca26851 100644
--- a/api/media_transport_interface.h
+++ b/api/media_transport_interface.h
@@ -209,6 +209,25 @@
   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 @@
   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.
 };