deadbeef | 6979b02 | 2015-09-24 23:47:53 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
deadbeef | 6979b02 | 2015-09-24 23:47:53 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 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. |
deadbeef | 6979b02 | 2015-09-24 23:47:53 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "pc/rtp_receiver.h" |
deadbeef | 6979b02 | 2015-09-24 23:47:53 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include <stddef.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 14 | |
Henrik Boström | 9e6fd2b | 2017-11-21 12:41:51 | [diff] [blame] | 15 | #include <utility> |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 18 | #include "api/media_stream_proxy.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 19 | #include "pc/media_stream.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 20 | #include "rtc_base/location.h" |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
Harald Alvestrand | c72af93 | 2018-01-11 16:18:19 | [diff] [blame] | 24 | // This function is only expected to be called on the signalling thread. |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 25 | int RtpReceiverInternal::GenerateUniqueId() { |
Harald Alvestrand | c72af93 | 2018-01-11 16:18:19 | [diff] [blame] | 26 | static int g_unique_id = 0; |
| 27 | |
| 28 | return ++g_unique_id; |
| 29 | } |
| 30 | |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 31 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> |
| 32 | RtpReceiverInternal::CreateStreamsFromIds(std::vector<std::string> stream_ids) { |
Henrik Boström | 199e27b | 2018-07-04 18:51:53 | [diff] [blame] | 33 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams( |
| 34 | stream_ids.size()); |
| 35 | for (size_t i = 0; i < stream_ids.size(); ++i) { |
| 36 | streams[i] = MediaStreamProxy::Create( |
| 37 | rtc::Thread::Current(), MediaStream::Create(std::move(stream_ids[i]))); |
| 38 | } |
| 39 | return streams; |
| 40 | } |
| 41 | |
Benjamin Wright | 84583f6 | 2018-10-04 21:22:34 | [diff] [blame] | 42 | // Attempt to attach the frame decryptor to the current media channel on the |
| 43 | // correct worker thread only if both the media channel exists and a ssrc has |
| 44 | // been allocated to the stream. |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 45 | void RtpReceiverInternal::MaybeAttachFrameDecryptorToMediaChannel( |
Benjamin Wright | 84583f6 | 2018-10-04 21:22:34 | [diff] [blame] | 46 | const absl::optional<uint32_t>& ssrc, |
Benjamin Wright | bfd412e | 2018-09-10 21:06:02 | [diff] [blame] | 47 | rtc::Thread* worker_thread, |
Benjamin Wright | 84583f6 | 2018-10-04 21:22:34 | [diff] [blame] | 48 | rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor, |
Benjamin Wright | c462a6e | 2018-10-26 20:16:16 | [diff] [blame] | 49 | cricket::MediaChannel* media_channel, |
| 50 | bool stopped) { |
| 51 | if (media_channel && frame_decryptor && ssrc.has_value() && !stopped) { |
Benjamin Wright | 6cc9cca | 2018-10-10 00:29:54 | [diff] [blame] | 52 | worker_thread->Invoke<void>(RTC_FROM_HERE, [&] { |
Benjamin Wright | 84583f6 | 2018-10-04 21:22:34 | [diff] [blame] | 53 | media_channel->SetFrameDecryptor(*ssrc, frame_decryptor); |
Benjamin Wright | bfd412e | 2018-09-10 21:06:02 | [diff] [blame] | 54 | }); |
| 55 | } |
| 56 | } |
| 57 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 58 | } // namespace webrtc |