blob: 8ddeddea5841e03ac9426fb6f873a8830bd9160b [file] [log] [blame]
Harald Alvestrand1090e442020-10-05 07:01:091/*
2 * Copyright 2020 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "pc/peer_connection_message_handler.h"
12
13#include <utility>
14
15#include "api/jsep.h"
Henrik Boström3e6931b2022-11-11 09:07:3416#include "api/legacy_stats_types.h"
Harald Alvestrand1090e442020-10-05 07:01:0917#include "api/media_stream_interface.h"
18#include "api/peer_connection_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0819#include "api/scoped_refptr.h"
Artem Titovd15a5752021-02-10 13:31:2420#include "api/sequence_checker.h"
Danil Chapovalov5d37ba22022-08-17 12:58:4021#include "api/task_queue/pending_task_safety_flag.h"
Henrik Boströmf7859892022-07-04 12:36:3722#include "pc/legacy_stats_collector_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0823#include "rtc_base/checks.h"
Harald Alvestrand1090e442020-10-05 07:01:0924
25namespace webrtc {
Harald Alvestrand1090e442020-10-05 07:01:0926namespace {
27
Danil Chapovalov5d37ba22022-08-17 12:58:4028template <typename T>
29rtc::scoped_refptr<T> WrapScoped(T* ptr) {
30 return rtc::scoped_refptr<T>(ptr);
31}
Harald Alvestrand1090e442020-10-05 07:01:0932
33} // namespace
34
Harald Alvestrand1090e442020-10-05 07:01:0935void PeerConnectionMessageHandler::PostSetSessionDescriptionSuccess(
36 SetSessionDescriptionObserver* observer) {
Danil Chapovalov5d37ba22022-08-17 12:58:4037 signaling_thread_->PostTask(
38 SafeTask(safety_.flag(),
39 [observer = WrapScoped(observer)] { observer->OnSuccess(); }));
Harald Alvestrand1090e442020-10-05 07:01:0940}
41
42void PeerConnectionMessageHandler::PostSetSessionDescriptionFailure(
43 SetSessionDescriptionObserver* observer,
44 RTCError&& error) {
45 RTC_DCHECK(!error.ok());
Danil Chapovalov5d37ba22022-08-17 12:58:4046 signaling_thread_->PostTask(SafeTask(
47 safety_.flag(),
48 [observer = WrapScoped(observer), error = std::move(error)]() mutable {
49 observer->OnFailure(std::move(error));
50 }));
Harald Alvestrand1090e442020-10-05 07:01:0951}
52
53void PeerConnectionMessageHandler::PostCreateSessionDescriptionFailure(
54 CreateSessionDescriptionObserver* observer,
55 RTCError error) {
56 RTC_DCHECK(!error.ok());
Danil Chapovalov5d37ba22022-08-17 12:58:4057 // Do not protect this task with the safety_.flag() to ensure
58 // observer is invoked even if the PeerConnection is destroyed early.
59 signaling_thread_->PostTask(
60 [observer = WrapScoped(observer), error = std::move(error)]() mutable {
61 observer->OnFailure(std::move(error));
62 });
Harald Alvestrand1090e442020-10-05 07:01:0963}
64
65void PeerConnectionMessageHandler::PostGetStats(
66 StatsObserver* observer,
Henrik Boströmf7859892022-07-04 12:36:3767 LegacyStatsCollectorInterface* legacy_stats,
Harald Alvestrand1090e442020-10-05 07:01:0968 MediaStreamTrackInterface* track) {
Danil Chapovalov5d37ba22022-08-17 12:58:4069 signaling_thread_->PostTask(
70 SafeTask(safety_.flag(), [observer = WrapScoped(observer), legacy_stats,
71 track = WrapScoped(track)] {
72 StatsReports reports;
73 legacy_stats->GetStats(track.get(), &reports);
74 observer->OnComplete(reports);
75 }));
Harald Alvestrand1090e442020-10-05 07:01:0976}
77
78void PeerConnectionMessageHandler::RequestUsagePatternReport(
79 std::function<void()> func,
80 int delay_ms) {
Danil Chapovalov5d37ba22022-08-17 12:58:4081 signaling_thread_->PostDelayedTask(SafeTask(safety_.flag(), std::move(func)),
82 TimeDelta::Millis(delay_ms));
Harald Alvestrand1090e442020-10-05 07:01:0983}
84
85} // namespace webrtc