blob: a1af13cead6030d9f3bda6e28b7c17e6ccf1ed87 [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
deadbeef70ab1a12015-09-28 16:53:55 -070011// This file contains classes that implement RtpReceiverInterface.
12// An RtpReceiver associates a MediaStreamTrackInterface with an underlying
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070013// transport (provided by cricket::VoiceChannel/cricket::VideoChannel)
deadbeef70ab1a12015-09-28 16:53:55 -070014
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#ifndef PC_RTPRECEIVER_H_
16#define PC_RTPRECEIVER_H_
deadbeef70ab1a12015-09-28 16:53:55 -070017
pbosc7c26a02017-01-02 08:42:32 -080018#include <stdint.h>
19
deadbeef70ab1a12015-09-28 16:53:55 -070020#include <string>
Steve Anton36b29d12017-10-30 09:57:42 -070021#include <vector>
deadbeef70ab1a12015-09-28 16:53:55 -070022
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "api/mediastreaminterface.h"
24#include "api/rtpreceiverinterface.h"
25#include "media/base/videobroadcaster.h"
26#include "pc/channel.h"
27#include "pc/remoteaudiosource.h"
28#include "pc/videotracksource.h"
29#include "rtc_base/basictypes.h"
30#include "rtc_base/sigslot.h"
deadbeef70ab1a12015-09-28 16:53:55 -070031
32namespace webrtc {
33
deadbeefa601f5c2016-06-06 14:27:39 -070034// Internal class used by PeerConnection.
35class RtpReceiverInternal : public RtpReceiverInterface {
36 public:
37 virtual void Stop() = 0;
deadbeefe814a0d2017-02-25 18:15:09 -080038 // This SSRC is used as an identifier for the receiver between the API layer
eladalonf1841382017-06-12 01:16:46 -070039 // and the WebRtcVideoEngine, WebRtcVoiceEngine layer.
deadbeefe814a0d2017-02-25 18:15:09 -080040 virtual uint32_t ssrc() const = 0;
deadbeefa601f5c2016-06-06 14:27:39 -070041};
42
deadbeef70ab1a12015-09-28 16:53:55 -070043class AudioRtpReceiver : public ObserverInterface,
44 public AudioSourceInterface::AudioObserver,
zhihuang184a3fd2016-06-14 11:47:14 -070045 public rtc::RefCountedObject<RtpReceiverInternal>,
46 public sigslot::has_slots<> {
deadbeef70ab1a12015-09-28 16:53:55 -070047 public:
deadbeefe814a0d2017-02-25 18:15:09 -080048 // An SSRC of 0 will create a receiver that will match the first SSRC it
49 // sees.
50 // TODO(deadbeef): Use rtc::Optional, or have another constructor that
51 // doesn't take an SSRC, and make this one DCHECK(ssrc != 0).
Henrik Boström9e6fd2b2017-11-21 13:41:51 +010052 AudioRtpReceiver(
53 const std::string& track_id,
54 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams,
55 uint32_t ssrc,
56 cricket::VoiceChannel* channel);
deadbeef70ab1a12015-09-28 16:53:55 -070057
58 virtual ~AudioRtpReceiver();
59
60 // ObserverInterface implementation
61 void OnChanged() override;
62
63 // AudioSourceInterface::AudioObserver implementation
64 void OnSetVolume(double volume) override;
65
perkjd61bf802016-03-24 03:16:19 -070066 rtc::scoped_refptr<AudioTrackInterface> audio_track() const {
67 return track_.get();
68 }
69
deadbeef70ab1a12015-09-28 16:53:55 -070070 // RtpReceiverInterface implementation
71 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
72 return track_.get();
73 }
Henrik Boström9e6fd2b2017-11-21 13:41:51 +010074 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams()
75 const override {
76 return streams_;
77 }
deadbeef70ab1a12015-09-28 16:53:55 -070078
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070079 cricket::MediaType media_type() const override {
80 return cricket::MEDIA_TYPE_AUDIO;
81 }
82
deadbeef70ab1a12015-09-28 16:53:55 -070083 std::string id() const override { return id_; }
84
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -070085 RtpParameters GetParameters() const override;
86 bool SetParameters(const RtpParameters& parameters) override;
87
deadbeefa601f5c2016-06-06 14:27:39 -070088 // RtpReceiverInternal implementation.
89 void Stop() override;
deadbeefe814a0d2017-02-25 18:15:09 -080090 uint32_t ssrc() const override { return ssrc_; }
deadbeefa601f5c2016-06-06 14:27:39 -070091
zhihuang184a3fd2016-06-14 11:47:14 -070092 void SetObserver(RtpReceiverObserverInterface* observer) override;
93
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070094 // Does not take ownership.
95 // Should call SetChannel(nullptr) before |channel| is destroyed.
96 void SetChannel(cricket::VoiceChannel* channel);
zhihuang184a3fd2016-06-14 11:47:14 -070097
hbos8d609f62017-04-10 07:39:05 -070098 std::vector<RtpSource> GetSources() const override;
99
deadbeef70ab1a12015-09-28 16:53:55 -0700100 private:
101 void Reconfigure();
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700102 void OnFirstPacketReceived(cricket::BaseChannel* channel);
deadbeef70ab1a12015-09-28 16:53:55 -0700103
Tommif888bb52015-12-12 01:37:01 +0100104 const std::string id_;
Tommif888bb52015-12-12 01:37:01 +0100105 const uint32_t ssrc_;
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700106 cricket::VoiceChannel* channel_;
perkjd61bf802016-03-24 03:16:19 -0700107 const rtc::scoped_refptr<AudioTrackInterface> track_;
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100108 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_;
deadbeef70ab1a12015-09-28 16:53:55 -0700109 bool cached_track_enabled_;
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700110 double cached_volume_ = 1;
111 bool stopped_ = false;
zhihuang184a3fd2016-06-14 11:47:14 -0700112 RtpReceiverObserverInterface* observer_ = nullptr;
113 bool received_first_packet_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700114};
115
zhihuang184a3fd2016-06-14 11:47:14 -0700116class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInternal>,
117 public sigslot::has_slots<> {
deadbeef70ab1a12015-09-28 16:53:55 -0700118 public:
deadbeefe814a0d2017-02-25 18:15:09 -0800119 // An SSRC of 0 will create a receiver that will match the first SSRC it
120 // sees.
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100121 VideoRtpReceiver(
122 const std::string& track_id,
123 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams,
124 rtc::Thread* worker_thread,
125 uint32_t ssrc,
126 cricket::VideoChannel* channel);
deadbeef70ab1a12015-09-28 16:53:55 -0700127
128 virtual ~VideoRtpReceiver();
129
perkjf0dcfe22016-03-10 18:32:00 +0100130 rtc::scoped_refptr<VideoTrackInterface> video_track() const {
131 return track_.get();
132 }
133
deadbeef70ab1a12015-09-28 16:53:55 -0700134 // RtpReceiverInterface implementation
135 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
136 return track_.get();
137 }
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100138 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams()
139 const override {
140 return streams_;
141 }
deadbeef70ab1a12015-09-28 16:53:55 -0700142
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700143 cricket::MediaType media_type() const override {
144 return cricket::MEDIA_TYPE_VIDEO;
145 }
146
deadbeef70ab1a12015-09-28 16:53:55 -0700147 std::string id() const override { return id_; }
148
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700149 RtpParameters GetParameters() const override;
150 bool SetParameters(const RtpParameters& parameters) override;
151
deadbeefa601f5c2016-06-06 14:27:39 -0700152 // RtpReceiverInternal implementation.
153 void Stop() override;
deadbeefe814a0d2017-02-25 18:15:09 -0800154 uint32_t ssrc() const override { return ssrc_; }
deadbeefa601f5c2016-06-06 14:27:39 -0700155
zhihuang184a3fd2016-06-14 11:47:14 -0700156 void SetObserver(RtpReceiverObserverInterface* observer) override;
157
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700158 // Does not take ownership.
159 // Should call SetChannel(nullptr) before |channel| is destroyed.
160 void SetChannel(cricket::VideoChannel* channel);
zhihuang184a3fd2016-06-14 11:47:14 -0700161
deadbeef70ab1a12015-09-28 16:53:55 -0700162 private:
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700163 void OnFirstPacketReceived(cricket::BaseChannel* channel);
zhihuang184a3fd2016-06-14 11:47:14 -0700164
deadbeef70ab1a12015-09-28 16:53:55 -0700165 std::string id_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200166 uint32_t ssrc_;
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700167 cricket::VideoChannel* channel_;
perkjf0dcfe22016-03-10 18:32:00 +0100168 // |broadcaster_| is needed since the decoder can only handle one sink.
169 // It might be better if the decoder can handle multiple sinks and consider
170 // the VideoSinkWants.
171 rtc::VideoBroadcaster broadcaster_;
172 // |source_| is held here to be able to change the state of the source when
173 // the VideoRtpReceiver is stopped.
174 rtc::scoped_refptr<VideoTrackSource> source_;
175 rtc::scoped_refptr<VideoTrackInterface> track_;
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100176 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_;
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700177 bool stopped_ = false;
zhihuang184a3fd2016-06-14 11:47:14 -0700178 RtpReceiverObserverInterface* observer_ = nullptr;
179 bool received_first_packet_ = false;
deadbeef70ab1a12015-09-28 16:53:55 -0700180};
181
182} // namespace webrtc
183
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200184#endif // PC_RTPRECEIVER_H_