#ifndef COMPONENTS_CAST_RECEIVER_BROWSER_STREAMING_CONTROLLER_BASE_H_
#define COMPONENTS_CAST_RECEIVER_BROWSER_STREAMING_CONTROLLER_BASE_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/sequence_checker.h"
#include "components/cast_receiver/browser/streaming_controller.h"
#include "components/cast_streaming/browser/public/receiver_config.h"
#include "components/cast_streaming/browser/public/receiver_session.h"
#include "components/cast_streaming/common/public/mojom/demuxer_connector.mojom.h"
#include "components/cast_streaming/common/public/mojom/renderer_controller.mojom.h"
#include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
namespace cast_api_bindings {
class MessagePort;
}
namespace content {
class NavigationHandle;
}
namespace cast_receiver {
class StreamingControllerBase : public StreamingController,
public content::WebContentsObserver {
public:
static std::unique_ptr<StreamingController> Create(
std::unique_ptr<cast_api_bindings::MessagePort> message_port,
content::WebContents* web_contents);
~StreamingControllerBase() override;
protected:
StreamingControllerBase(
std::unique_ptr<cast_api_bindings::MessagePort> message_port,
content::WebContents* web_contents);
virtual void StartPlayback(
cast_streaming::ReceiverSession* receiver_session,
mojo::AssociatedRemote<cast_streaming::mojom::DemuxerConnector>
demuxer_connector,
mojo::AssociatedRemote<cast_streaming::mojom::RendererController>
renderer_connection) = 0;
virtual void ProcessConfig(cast_streaming::ReceiverConfig& config);
private:
void ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) final;
void InitializeReceiverSession(
cast_streaming::ReceiverConfig config,
cast_streaming::ReceiverSession::Client* client) final;
void StartPlaybackAsync(PlaybackStartedCB cb) final;
void TryStartPlayback();
SEQUENCE_CHECKER(sequence_checker_);
PlaybackStartedCB playback_started_cb_;
std::optional<cast_streaming::ReceiverConfig> config_ = std::nullopt;
raw_ptr<cast_streaming::ReceiverSession::Client> client_ = nullptr;
mojo::AssociatedRemote<cast_streaming::mojom::DemuxerConnector>
demuxer_connector_;
mojo::AssociatedRemote<cast_streaming::mojom::RendererController>
renderer_connection_;
std::unique_ptr<cast_api_bindings::MessagePort> message_port_;
std::unique_ptr<cast_streaming::ReceiverSession> receiver_session_;
};
}
#endif