| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2015 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 // This file contains classes that implement RtpReceiverInterface. | |
| 12 // An RtpReceiver associates a MediaStreamTrackInterface with an underlying | |
| 13 // transport (provided by cricket::VoiceChannel/cricket::VideoChannel) | |
| 14 | |
| 15 #ifndef WEBRTC_API_RTPRECEIVER_H_ | |
| 16 #define WEBRTC_API_RTPRECEIVER_H_ | |
| 17 | |
| 18 #include <stdint.h> | |
| 19 | |
| 20 #include <string> | |
| 21 | |
| 22 #include "webrtc/api/mediastreaminterface.h" | |
| 23 #include "webrtc/api/rtpreceiverinterface.h" | |
| 24 #include "webrtc/api/remoteaudiosource.h" | |
| 25 #include "webrtc/api/videotracksource.h" | |
| 26 #include "webrtc/base/sigslot.h" | |
| 27 #include "webrtc/media/base/videobroadcaster.h" | |
| 28 #include "webrtc/pc/channel.h" | |
| 29 | |
| 30 namespace webrtc { | |
| 31 | |
| 32 // Internal class used by PeerConnection. | |
| 33 class RtpReceiverInternal : public RtpReceiverInterface { | |
| 34 public: | |
| 35 virtual void Stop() = 0; | |
| 36 }; | |
| 37 | |
| 38 class AudioRtpReceiver : public ObserverInterface, | |
| 39 public AudioSourceInterface::AudioObserver, | |
| 40 public rtc::RefCountedObject<RtpReceiverInternal>, | |
| 41 public sigslot::has_slots<> { | |
| 42 public: | |
| 43 AudioRtpReceiver(MediaStreamInterface* stream, | |
| 44 const std::string& track_id, | |
| 45 uint32_t ssrc, | |
| 46 cricket::VoiceChannel* channel); | |
| 47 | |
| 48 virtual ~AudioRtpReceiver(); | |
| 49 | |
| 50 // ObserverInterface implementation | |
| 51 void OnChanged() override; | |
| 52 | |
| 53 // AudioSourceInterface::AudioObserver implementation | |
| 54 void OnSetVolume(double volume) override; | |
| 55 | |
| 56 rtc::scoped_refptr<AudioTrackInterface> audio_track() const { | |
| 57 return track_.get(); | |
| 58 } | |
| 59 | |
| 60 // RtpReceiverInterface implementation | |
| 61 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { | |
| 62 return track_.get(); | |
| 63 } | |
| 64 | |
| 65 cricket::MediaType media_type() const override { | |
| 66 return cricket::MEDIA_TYPE_AUDIO; | |
| 67 } | |
| 68 | |
| 69 std::string id() const override { return id_; } | |
| 70 | |
| 71 RtpParameters GetParameters() const override; | |
| 72 bool SetParameters(const RtpParameters& parameters) override; | |
| 73 | |
| 74 // RtpReceiverInternal implementation. | |
| 75 void Stop() override; | |
| 76 | |
| 77 void SetObserver(RtpReceiverObserverInterface* observer) override; | |
| 78 | |
| 79 // Does not take ownership. | |
| 80 // Should call SetChannel(nullptr) before |channel| is destroyed. | |
| 81 void SetChannel(cricket::VoiceChannel* channel); | |
| 82 | |
| 83 private: | |
| 84 void Reconfigure(); | |
| 85 void OnFirstPacketReceived(cricket::BaseChannel* channel); | |
| 86 | |
| 87 const std::string id_; | |
| 88 const uint32_t ssrc_; | |
| 89 cricket::VoiceChannel* channel_; | |
| 90 const rtc::scoped_refptr<AudioTrackInterface> track_; | |
| 91 bool cached_track_enabled_; | |
| 92 double cached_volume_ = 1; | |
| 93 bool stopped_ = false; | |
| 94 RtpReceiverObserverInterface* observer_ = nullptr; | |
| 95 bool received_first_packet_ = false; | |
| 96 }; | |
| 97 | |
| 98 class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInternal>, | |
| 99 public sigslot::has_slots<> { | |
| 100 public: | |
| 101 VideoRtpReceiver(MediaStreamInterface* stream, | |
| 102 const std::string& track_id, | |
| 103 rtc::Thread* worker_thread, | |
| 104 uint32_t ssrc, | |
| 105 cricket::VideoChannel* channel); | |
| 106 | |
| 107 virtual ~VideoRtpReceiver(); | |
| 108 | |
| 109 rtc::scoped_refptr<VideoTrackInterface> video_track() const { | |
| 110 return track_.get(); | |
| 111 } | |
| 112 | |
| 113 // RtpReceiverInterface implementation | |
| 114 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { | |
| 115 return track_.get(); | |
| 116 } | |
| 117 | |
| 118 cricket::MediaType media_type() const override { | |
| 119 return cricket::MEDIA_TYPE_VIDEO; | |
| 120 } | |
| 121 | |
| 122 std::string id() const override { return id_; } | |
| 123 | |
| 124 RtpParameters GetParameters() const override; | |
| 125 bool SetParameters(const RtpParameters& parameters) override; | |
| 126 | |
| 127 // RtpReceiverInternal implementation. | |
| 128 void Stop() override; | |
| 129 | |
| 130 void SetObserver(RtpReceiverObserverInterface* observer) override; | |
| 131 | |
| 132 // Does not take ownership. | |
| 133 // Should call SetChannel(nullptr) before |channel| is destroyed. | |
| 134 void SetChannel(cricket::VideoChannel* channel); | |
| 135 | |
| 136 private: | |
| 137 void OnFirstPacketReceived(cricket::BaseChannel* channel); | |
| 138 | |
| 139 std::string id_; | |
| 140 uint32_t ssrc_; | |
| 141 cricket::VideoChannel* channel_; | |
| 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_; | |
| 150 bool stopped_ = false; | |
| 151 RtpReceiverObserverInterface* observer_ = nullptr; | |
| 152 bool received_first_packet_ = false; | |
| 153 }; | |
| 154 | |
| 155 } // namespace webrtc | |
| 156 | |
| 157 #endif // WEBRTC_API_RTPRECEIVER_H_ | |
| OLD | NEW |