File: streaming_controller_base.cc

package info (click to toggle)
chromium 138.0.7204.92-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,576 kB
  • sloc: cpp: 34,933,512; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,956; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (106 lines) | stat: -rw-r--r-- 3,681 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/cast_receiver/browser/streaming_controller_base.h"

#include "base/functional/bind.h"
#include "components/cast/message_port/message_port.h"
#include "components/cast/message_port/platform_message_port.h"
#include "components/cast_receiver/browser/streaming_controller_mirroring.h"
#include "components/cast_receiver/browser/streaming_controller_remoting.h"
#include "components/cast_streaming/browser/public/receiver_session.h"
#include "components/cast_streaming/common/public/features.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"

namespace cast_receiver {

// static
std::unique_ptr<StreamingController> StreamingControllerBase::Create(
    std::unique_ptr<cast_api_bindings::MessagePort> message_port,
    content::WebContents* web_contents) {
  if (cast_streaming::IsCastRemotingEnabled()) {
    return std::make_unique<StreamingControllerRemoting>(
        std::move(message_port), web_contents);
  }

  return std::make_unique<StreamingControllerMirroring>(std::move(message_port),
                                                        web_contents);
}

StreamingControllerBase::StreamingControllerBase(
    std::unique_ptr<cast_api_bindings::MessagePort> message_port,
    content::WebContents* web_contents)
    : content::WebContentsObserver(web_contents),
      message_port_(std::move(message_port)) {
  DCHECK(message_port_);
}

StreamingControllerBase::~StreamingControllerBase() = default;

void StreamingControllerBase::ProcessConfig(
    cast_streaming::ReceiverConfig& config) {}

void StreamingControllerBase::ReadyToCommitNavigation(
    content::NavigationHandle* navigation_handle) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  DCHECK(navigation_handle);

  navigation_handle->GetRenderFrameHost()
      ->GetRemoteAssociatedInterfaces()
      ->GetInterface(&demuxer_connector_);
  navigation_handle->GetRenderFrameHost()
      ->GetRemoteAssociatedInterfaces()
      ->GetInterface(&renderer_connection_);

  DCHECK(demuxer_connector_);
  DCHECK(renderer_connection_);

  TryStartPlayback();
}

void StreamingControllerBase::InitializeReceiverSession(
    cast_streaming::ReceiverConfig config,
    cast_streaming::ReceiverSession::Client* client) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  DCHECK(!client_);

  config_.emplace(std::move(config));
  client_ = client;

  ProcessConfig(*config_);

  TryStartPlayback();
}

void StreamingControllerBase::StartPlaybackAsync(PlaybackStartedCB cb) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  DCHECK(!playback_started_cb_);
  DCHECK(cb);

  playback_started_cb_ = std::move(cb);

  TryStartPlayback();
}

void StreamingControllerBase::TryStartPlayback() {
  if (playback_started_cb_ && demuxer_connector_ && config_) {
    cast_streaming::ReceiverSession::MessagePortProvider message_port_provider =
        base::BindOnce(
            [](std::unique_ptr<cast_api_bindings::MessagePort> port) {
              return port;
            },
            std::move(message_port_));
    receiver_session_ = cast_streaming::ReceiverSession::Create(
        *config_, std::move(message_port_provider), client_);
    DCHECK(receiver_session_);

    StartPlayback(receiver_session_.get(), std::move(demuxer_connector_),
                  std::move(renderer_connection_));
    std::move(playback_started_cb_).Run();
  }
}

}  // namespace cast_receiver