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 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 11 | // This file contains classes that implement RtpReceiverInterface. |
| 12 | // An RtpReceiver associates a MediaStreamTrackInterface with an underlying |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 13 | // transport (provided by cricket::VoiceChannel/cricket::VideoChannel) |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 14 | |
Henrik Kjellander | 15583c1 | 2016-02-10 09:53:12 | [diff] [blame] | 15 | #ifndef WEBRTC_API_RTPRECEIVER_H_ |
| 16 | #define WEBRTC_API_RTPRECEIVER_H_ |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 17 | |
pbos | c7c26a0 | 2017-01-02 16:42:32 | [diff] [blame^] | 18 | #include <stdint.h> |
| 19 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 22 | #include "webrtc/api/mediastreaminterface.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 09:53:12 | [diff] [blame] | 23 | #include "webrtc/api/rtpreceiverinterface.h" |
perkj | d61bf80 | 2016-03-24 10:16:19 | [diff] [blame] | 24 | #include "webrtc/api/remoteaudiosource.h" |
perkj | f0dcfe2 | 2016-03-10 17:32:00 | [diff] [blame] | 25 | #include "webrtc/api/videotracksource.h" |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 26 | #include "webrtc/base/sigslot.h" |
perkj | f0dcfe2 | 2016-03-10 17:32:00 | [diff] [blame] | 27 | #include "webrtc/media/base/videobroadcaster.h" |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 28 | #include "webrtc/pc/channel.h" |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
| 31 | |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 32 | // Internal class used by PeerConnection. |
| 33 | class RtpReceiverInternal : public RtpReceiverInterface { |
| 34 | public: |
| 35 | virtual void Stop() = 0; |
| 36 | }; |
| 37 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 38 | class AudioRtpReceiver : public ObserverInterface, |
| 39 | public AudioSourceInterface::AudioObserver, |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 40 | public rtc::RefCountedObject<RtpReceiverInternal>, |
| 41 | public sigslot::has_slots<> { |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 42 | public: |
perkj | d61bf80 | 2016-03-24 10:16:19 | [diff] [blame] | 43 | AudioRtpReceiver(MediaStreamInterface* stream, |
| 44 | const std::string& track_id, |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 45 | uint32_t ssrc, |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 46 | cricket::VoiceChannel* channel); |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 47 | |
| 48 | virtual ~AudioRtpReceiver(); |
| 49 | |
| 50 | // ObserverInterface implementation |
| 51 | void OnChanged() override; |
| 52 | |
| 53 | // AudioSourceInterface::AudioObserver implementation |
| 54 | void OnSetVolume(double volume) override; |
| 55 | |
perkj | d61bf80 | 2016-03-24 10:16:19 | [diff] [blame] | 56 | rtc::scoped_refptr<AudioTrackInterface> audio_track() const { |
| 57 | return track_.get(); |
| 58 | } |
| 59 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 60 | // RtpReceiverInterface implementation |
| 61 | rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
| 62 | return track_.get(); |
| 63 | } |
| 64 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 65 | cricket::MediaType media_type() const override { |
| 66 | return cricket::MEDIA_TYPE_AUDIO; |
| 67 | } |
| 68 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 69 | std::string id() const override { return id_; } |
| 70 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 18:40:30 | [diff] [blame] | 71 | RtpParameters GetParameters() const override; |
| 72 | bool SetParameters(const RtpParameters& parameters) override; |
| 73 | |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 74 | // RtpReceiverInternal implementation. |
| 75 | void Stop() override; |
| 76 | |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 77 | void SetObserver(RtpReceiverObserverInterface* observer) override; |
| 78 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 79 | // Does not take ownership. |
| 80 | // Should call SetChannel(nullptr) before |channel| is destroyed. |
| 81 | void SetChannel(cricket::VoiceChannel* channel); |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 82 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 83 | private: |
| 84 | void Reconfigure(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 85 | void OnFirstPacketReceived(cricket::BaseChannel* channel); |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 86 | |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 87 | const std::string id_; |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 88 | const uint32_t ssrc_; |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 89 | cricket::VoiceChannel* channel_; |
perkj | d61bf80 | 2016-03-24 10:16:19 | [diff] [blame] | 90 | const rtc::scoped_refptr<AudioTrackInterface> track_; |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 91 | bool cached_track_enabled_; |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 92 | double cached_volume_ = 1; |
| 93 | bool stopped_ = false; |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 94 | RtpReceiverObserverInterface* observer_ = nullptr; |
| 95 | bool received_first_packet_ = false; |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 96 | }; |
| 97 | |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 98 | class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInternal>, |
| 99 | public sigslot::has_slots<> { |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 100 | public: |
perkj | f0dcfe2 | 2016-03-10 17:32:00 | [diff] [blame] | 101 | VideoRtpReceiver(MediaStreamInterface* stream, |
| 102 | const std::string& track_id, |
| 103 | rtc::Thread* worker_thread, |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 104 | uint32_t ssrc, |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 105 | cricket::VideoChannel* channel); |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 106 | |
| 107 | virtual ~VideoRtpReceiver(); |
| 108 | |
perkj | f0dcfe2 | 2016-03-10 17:32:00 | [diff] [blame] | 109 | rtc::scoped_refptr<VideoTrackInterface> video_track() const { |
| 110 | return track_.get(); |
| 111 | } |
| 112 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 113 | // RtpReceiverInterface implementation |
| 114 | rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
| 115 | return track_.get(); |
| 116 | } |
| 117 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 118 | cricket::MediaType media_type() const override { |
| 119 | return cricket::MEDIA_TYPE_VIDEO; |
| 120 | } |
| 121 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 122 | std::string id() const override { return id_; } |
| 123 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 18:40:30 | [diff] [blame] | 124 | RtpParameters GetParameters() const override; |
| 125 | bool SetParameters(const RtpParameters& parameters) override; |
| 126 | |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 127 | // RtpReceiverInternal implementation. |
| 128 | void Stop() override; |
| 129 | |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 130 | void SetObserver(RtpReceiverObserverInterface* observer) override; |
| 131 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 132 | // Does not take ownership. |
| 133 | // Should call SetChannel(nullptr) before |channel| is destroyed. |
| 134 | void SetChannel(cricket::VideoChannel* channel); |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 135 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 136 | private: |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 137 | void OnFirstPacketReceived(cricket::BaseChannel* channel); |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 138 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 139 | std::string id_; |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 140 | uint32_t ssrc_; |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 141 | cricket::VideoChannel* channel_; |
perkj | f0dcfe2 | 2016-03-10 17:32:00 | [diff] [blame] | 142 | // |broadcaster_| is needed since the decoder can only handle one sink. |
| 143 | // It might be better if the decoder can handle multiple sinks and consider |
| 144 | // the VideoSinkWants. |
| 145 | rtc::VideoBroadcaster broadcaster_; |
| 146 | // |source_| is held here to be able to change the state of the source when |
| 147 | // the VideoRtpReceiver is stopped. |
| 148 | rtc::scoped_refptr<VideoTrackSource> source_; |
| 149 | rtc::scoped_refptr<VideoTrackInterface> track_; |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 150 | bool stopped_ = false; |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 151 | RtpReceiverObserverInterface* observer_ = nullptr; |
| 152 | bool received_first_packet_ = false; |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | } // namespace webrtc |
| 156 | |
Henrik Kjellander | 15583c1 | 2016-02-10 09:53:12 | [diff] [blame] | 157 | #endif // WEBRTC_API_RTPRECEIVER_H_ |