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

content / browser / media / audio_stream_broker_helper.cc [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/media/audio_stream_broker_helper.h"

#include "base/functional/bind.h"
#include "base/location.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/public/browser/browser_thread.h"

namespace content {

void NotifyFrameHostOfAudioStreamStarted(int render_process_id,
                                         int render_frame_id,
                                         bool is_capturing) {
  auto impl = [](int render_process_id, int render_frame_id,
                 bool is_capturing) {
    if (auto* host =
            RenderFrameHostImpl::FromID(render_process_id, render_frame_id)) {
      const auto type =
          is_capturing
              ? RenderFrameHostImpl::MediaStreamType::kCapturingMediaStream
              : RenderFrameHostImpl::MediaStreamType::kPlayingAudioStream;
      host->OnMediaStreamAdded(type);
    }
  };
  GetUIThreadTaskRunner({})->PostTask(
      FROM_HERE,
      base::BindOnce(impl, render_process_id, render_frame_id, is_capturing));
}

void NotifyFrameHostOfAudioStreamStopped(int render_process_id,
                                         int render_frame_id,
                                         bool is_capturing) {
  auto impl = [](int render_process_id, int render_frame_id,
                 bool is_capturing) {
    RenderFrameHostImpl* host =
        RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
    const auto type =
        is_capturing
            ? RenderFrameHostImpl::MediaStreamType::kCapturingMediaStream
            : RenderFrameHostImpl::MediaStreamType::kPlayingAudioStream;
    if (host && host->HasMediaStreams(type)) {
      host->OnMediaStreamRemoved(type);
    }
  };
  GetUIThreadTaskRunner({})->PostTask(
      FROM_HERE,
      base::BindOnce(impl, render_process_id, render_frame_id, is_capturing));
}

}  // namespace content