blob: f65afd7dc4ca5f1759588ef9663b9632a91ae498 [file] [log] [blame]
deadbeef6979b022015-09-24 16:47:53 -07001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
deadbeef6979b022015-09-24 16:47:53 -07003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
deadbeef6979b022015-09-24 16:47:53 -07009 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#include "pc/rtp_receiver.h"
deadbeef6979b022015-09-24 16:47:53 -070012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <stddef.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Henrik Boström9e6fd2b2017-11-21 13:41:51 +010015#include <utility>
Steve Anton36b29d12017-10-30 09:57:42 -070016#include <vector>
17
Steve Anton10542f22019-01-11 09:11:00 -080018#include "api/media_stream_proxy.h"
19#include "api/media_stream_track_proxy.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "pc/media_stream.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "rtc_base/checks.h"
22#include "rtc_base/location.h"
23#include "rtc_base/logging.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_base/trace_event.h"
deadbeef70ab1a12015-09-28 16:53:55 -070025
26namespace webrtc {
27
Harald Alvestrandc72af932018-01-11 17:18:19 +010028// This function is only expected to be called on the signalling thread.
Ruslan Burakov501bfba2019-02-11 10:29:19 +010029int RtpReceiverInternal::GenerateUniqueId() {
Harald Alvestrandc72af932018-01-11 17:18:19 +010030 static int g_unique_id = 0;
31
32 return ++g_unique_id;
33}
34
Ruslan Burakov501bfba2019-02-11 10:29:19 +010035std::vector<rtc::scoped_refptr<MediaStreamInterface>>
36RtpReceiverInternal::CreateStreamsFromIds(std::vector<std::string> stream_ids) {
Henrik Boström199e27b2018-07-04 20:51:53 +020037 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams(
38 stream_ids.size());
39 for (size_t i = 0; i < stream_ids.size(); ++i) {
40 streams[i] = MediaStreamProxy::Create(
41 rtc::Thread::Current(), MediaStream::Create(std::move(stream_ids[i])));
42 }
43 return streams;
44}
45
Benjamin Wright84583f62018-10-04 14:22:34 -070046// Attempt to attach the frame decryptor to the current media channel on the
47// correct worker thread only if both the media channel exists and a ssrc has
48// been allocated to the stream.
Ruslan Burakov501bfba2019-02-11 10:29:19 +010049void RtpReceiverInternal::MaybeAttachFrameDecryptorToMediaChannel(
Benjamin Wright84583f62018-10-04 14:22:34 -070050 const absl::optional<uint32_t>& ssrc,
Benjamin Wrightbfd412e2018-09-10 14:06:02 -070051 rtc::Thread* worker_thread,
Benjamin Wright84583f62018-10-04 14:22:34 -070052 rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor,
Benjamin Wrightc462a6e2018-10-26 13:16:16 -070053 cricket::MediaChannel* media_channel,
54 bool stopped) {
55 if (media_channel && frame_decryptor && ssrc.has_value() && !stopped) {
Benjamin Wright6cc9cca2018-10-09 17:29:54 -070056 worker_thread->Invoke<void>(RTC_FROM_HERE, [&] {
Benjamin Wright84583f62018-10-04 14:22:34 -070057 media_channel->SetFrameDecryptor(*ssrc, frame_decryptor);
Benjamin Wrightbfd412e2018-09-10 14:06:02 -070058 });
59 }
60}
61
deadbeef70ab1a12015-09-28 16:53:55 -070062} // namespace webrtc