Index: chrome/browser/media/cast_remoting_sender.h |
diff --git a/chrome/browser/media/cast_remoting_sender.h b/chrome/browser/media/cast_remoting_sender.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cd8bd1a42f6c3b31ccbc4d8598190e7045f69c2a |
--- /dev/null |
+++ b/chrome/browser/media/cast_remoting_sender.h |
@@ -0,0 +1,69 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_MEDIA_CAST_REMOTING_SENDER_H_ |
+#define CHROME_BROWSER_MEDIA_CAST_REMOTING_SENDER_H_ |
+ |
+#include "base/callback_forward.h" |
+#include "base/memory/weak_ptr.h" |
+#include "media/mojo/interfaces/remoting.mojom.h" |
+#include "mojo/public/cpp/bindings/binding.h" |
+ |
+// RTP sender for a single Cast Remoting RTP stream. The client calls Send() to |
+// instruct the sender to read from a Mojo data pipe and transmit the data using |
+// a CastTransport. This entire class executes on the IO BrowserThread. |
+// |
+// This class is instantiated and owned by CastTransportHostFilter in response |
+// to IPC messages from an extension process to create RTP streams for the media |
+// remoting use case. CastTransportHostFilter is also responsible for destroying |
+// the instance in response to later IPCs. |
+// |
+// The Media Router provider extension controls the entire set-up process: |
+// First, it uses the cast.streaming APIs to create remoting API streams (which |
+// instantiates one or more CastRemotingSenders). Then, it sends a message via |
+// Media Router to a CastRemotingConnector to indicate the bitstream transport |
+// is ready. Finally, CastRemotingConnector calls FindAndBind() to look-up the |
+// CastRemotingSender instances and establish the Mojo bindings and data flows. |
+// |
+// TODO(miu): Merge with CastRemotingSender from xjz's recent change. |
+class CastRemotingSender : public media::mojom::RemotingDataStreamSender { |
+ public: |
+ explicit CastRemotingSender(int32_t rtp_stream_id); |
+ ~CastRemotingSender() final; |
+ |
+ // Look-up a CastRemotingSender instance by its |rtp_stream_id| and then bind |
+ // to the given |request|. The client of the RemotingDataStreamSender will |
+ // then instruct this CastRemotingSender when to read from the data |pipe| and |
+ // send the data to the Cast Receiver. If the bind fails, or an error occurs |
+ // reading from the data pipe during later operation, the |error_callback| is |
+ // run. |
+ // |
+ // Threading note: This function is thread-safe, but its internal |
+ // implementation runs on the IO BrowserThread. If |error_callback| is run, it |
+ // will execute on the thread that called this function. |
+ static void FindAndBind(int32_t rtp_stream_id, |
+ mojo::ScopedDataPipeConsumerHandle pipe, |
+ media::mojom::RemotingDataStreamSenderRequest request, |
+ const base::Closure& error_callback); |
+ |
+ private: |
+ // media::mojom::RemotingDataStreamSender implementation. |
+ void ConsumeDataChunk(uint32_t offset, uint32_t size, |
+ uint32_t total_payload_size) final; |
+ void SendFrame() final; |
+ void CancelInFlightData() final; |
+ |
+ const int32_t rtp_stream_id_; |
+ mojo::Binding<RemotingDataStreamSender> binding_; |
+ base::Closure error_callback_; |
+ mojo::ScopedDataPipeConsumerHandle pipe_; |
+ |
+ // The next frame's payload data. Populated by one or more calls to |
+ // ConsumeDataChunk(). |
+ std::string next_frame_data_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CastRemotingSender); |
+}; |
+ |
+#endif // CHROME_BROWSER_MEDIA_CAST_REMOTING_SENDER_H_ |