OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_CAST_REMOTING_SENDER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_CAST_REMOTING_SENDER_H_ |
| 7 |
| 8 #include "base/callback_forward.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "media/mojo/interfaces/remoting.mojom.h" |
| 11 #include "mojo/public/cpp/bindings/binding.h" |
| 12 |
| 13 // RTP sender for a single Cast Remoting RTP stream. The client calls Send() to |
| 14 // instruct the sender to read from a Mojo data pipe and transmit the data using |
| 15 // a CastTransport. This entire class executes on the IO BrowserThread. |
| 16 // |
| 17 // This class is instantiated and owned by CastTransportHostFilter in response |
| 18 // to IPC messages from an extension process to create RTP streams for the media |
| 19 // remoting use case. CastTransportHostFilter is also responsible for destroying |
| 20 // the instance in response to later IPCs. |
| 21 // |
| 22 // The Media Router provider extension controls the entire set-up process: |
| 23 // First, it uses the cast.streaming APIs to create remoting API streams (which |
| 24 // instantiates one or more CastRemotingSenders). Then, it sends a message via |
| 25 // Media Router to a CastRemotingConnector to indicate the bitstream transport |
| 26 // is ready. Finally, CastRemotingConnector calls FindAndBind() to look-up the |
| 27 // CastRemotingSender instances and establish the Mojo bindings and data flows. |
| 28 // |
| 29 // TODO(miu): Merge with CastRemotingSender from xjz's recent change. |
| 30 class CastRemotingSender : public media::mojom::RemotingDataStreamSender { |
| 31 public: |
| 32 explicit CastRemotingSender(int32_t rtp_stream_id); |
| 33 ~CastRemotingSender() final; |
| 34 |
| 35 // Look-up a CastRemotingSender instance by its |rtp_stream_id| and then bind |
| 36 // to the given |request|. The client of the RemotingDataStreamSender will |
| 37 // then instruct this CastRemotingSender when to read from the data |pipe| and |
| 38 // send the data to the Cast Receiver. If the bind fails, or an error occurs |
| 39 // reading from the data pipe during later operation, the |error_callback| is |
| 40 // run. |
| 41 // |
| 42 // Threading note: This function is thread-safe, but its internal |
| 43 // implementation runs on the IO BrowserThread. If |error_callback| is run, it |
| 44 // will execute on the thread that called this function. |
| 45 static void FindAndBind(int32_t rtp_stream_id, |
| 46 mojo::ScopedDataPipeConsumerHandle pipe, |
| 47 media::mojom::RemotingDataStreamSenderRequest request, |
| 48 const base::Closure& error_callback); |
| 49 |
| 50 private: |
| 51 // media::mojom::RemotingDataStreamSender implementation. |
| 52 void ConsumeDataChunk(uint32_t offset, uint32_t size, |
| 53 uint32_t total_payload_size) final; |
| 54 void SendFrame() final; |
| 55 void CancelInFlightData() final; |
| 56 |
| 57 const int32_t rtp_stream_id_; |
| 58 mojo::Binding<RemotingDataStreamSender> binding_; |
| 59 base::Closure error_callback_; |
| 60 mojo::ScopedDataPipeConsumerHandle pipe_; |
| 61 |
| 62 // The next frame's payload data. Populated by one or more calls to |
| 63 // ConsumeDataChunk(). |
| 64 std::string next_frame_data_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(CastRemotingSender); |
| 67 }; |
| 68 |
| 69 #endif // CHROME_BROWSER_MEDIA_CAST_REMOTING_SENDER_H_ |
OLD | NEW |