| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "webrtc/pc/channel.h" | 27 #include "webrtc/pc/channel.h" |
| 28 #include "webrtc/pc/remoteaudiosource.h" | 28 #include "webrtc/pc/remoteaudiosource.h" |
| 29 #include "webrtc/pc/videotracksource.h" | 29 #include "webrtc/pc/videotracksource.h" |
| 30 | 30 |
| 31 namespace webrtc { | 31 namespace webrtc { |
| 32 | 32 |
| 33 // Internal class used by PeerConnection. | 33 // Internal class used by PeerConnection. |
| 34 class RtpReceiverInternal : public RtpReceiverInterface { | 34 class RtpReceiverInternal : public RtpReceiverInterface { |
| 35 public: | 35 public: |
| 36 virtual void Stop() = 0; | 36 virtual void Stop() = 0; |
| 37 // This SSRC is used as an identifier for the receiver between the API layer |
| 38 // and the WebRtcVideoEngine2, WebRtcVoiceEngine layer. |
| 39 virtual uint32_t ssrc() const = 0; |
| 37 }; | 40 }; |
| 38 | 41 |
| 39 class AudioRtpReceiver : public ObserverInterface, | 42 class AudioRtpReceiver : public ObserverInterface, |
| 40 public AudioSourceInterface::AudioObserver, | 43 public AudioSourceInterface::AudioObserver, |
| 41 public rtc::RefCountedObject<RtpReceiverInternal>, | 44 public rtc::RefCountedObject<RtpReceiverInternal>, |
| 42 public sigslot::has_slots<> { | 45 public sigslot::has_slots<> { |
| 43 public: | 46 public: |
| 44 AudioRtpReceiver(MediaStreamInterface* stream, | 47 // An SSRC of 0 will create a receiver that will match the first SSRC it |
| 45 const std::string& track_id, | 48 // sees. |
| 49 // TODO(deadbeef): Use rtc::Optional, or have another constructor that |
| 50 // doesn't take an SSRC, and make this one DCHECK(ssrc != 0). |
| 51 AudioRtpReceiver(const std::string& track_id, |
| 46 uint32_t ssrc, | 52 uint32_t ssrc, |
| 47 cricket::VoiceChannel* channel); | 53 cricket::VoiceChannel* channel); |
| 48 | 54 |
| 49 virtual ~AudioRtpReceiver(); | 55 virtual ~AudioRtpReceiver(); |
| 50 | 56 |
| 51 // ObserverInterface implementation | 57 // ObserverInterface implementation |
| 52 void OnChanged() override; | 58 void OnChanged() override; |
| 53 | 59 |
| 54 // AudioSourceInterface::AudioObserver implementation | 60 // AudioSourceInterface::AudioObserver implementation |
| 55 void OnSetVolume(double volume) override; | 61 void OnSetVolume(double volume) override; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 67 return cricket::MEDIA_TYPE_AUDIO; | 73 return cricket::MEDIA_TYPE_AUDIO; |
| 68 } | 74 } |
| 69 | 75 |
| 70 std::string id() const override { return id_; } | 76 std::string id() const override { return id_; } |
| 71 | 77 |
| 72 RtpParameters GetParameters() const override; | 78 RtpParameters GetParameters() const override; |
| 73 bool SetParameters(const RtpParameters& parameters) override; | 79 bool SetParameters(const RtpParameters& parameters) override; |
| 74 | 80 |
| 75 // RtpReceiverInternal implementation. | 81 // RtpReceiverInternal implementation. |
| 76 void Stop() override; | 82 void Stop() override; |
| 83 uint32_t ssrc() const override { return ssrc_; } |
| 77 | 84 |
| 78 void SetObserver(RtpReceiverObserverInterface* observer) override; | 85 void SetObserver(RtpReceiverObserverInterface* observer) override; |
| 79 | 86 |
| 80 // Does not take ownership. | 87 // Does not take ownership. |
| 81 // Should call SetChannel(nullptr) before |channel| is destroyed. | 88 // Should call SetChannel(nullptr) before |channel| is destroyed. |
| 82 void SetChannel(cricket::VoiceChannel* channel); | 89 void SetChannel(cricket::VoiceChannel* channel); |
| 83 | 90 |
| 84 private: | 91 private: |
| 85 void Reconfigure(); | 92 void Reconfigure(); |
| 86 void OnFirstPacketReceived(cricket::BaseChannel* channel); | 93 void OnFirstPacketReceived(cricket::BaseChannel* channel); |
| 87 | 94 |
| 88 const std::string id_; | 95 const std::string id_; |
| 89 const uint32_t ssrc_; | 96 const uint32_t ssrc_; |
| 90 cricket::VoiceChannel* channel_; | 97 cricket::VoiceChannel* channel_; |
| 91 const rtc::scoped_refptr<AudioTrackInterface> track_; | 98 const rtc::scoped_refptr<AudioTrackInterface> track_; |
| 92 bool cached_track_enabled_; | 99 bool cached_track_enabled_; |
| 93 double cached_volume_ = 1; | 100 double cached_volume_ = 1; |
| 94 bool stopped_ = false; | 101 bool stopped_ = false; |
| 95 RtpReceiverObserverInterface* observer_ = nullptr; | 102 RtpReceiverObserverInterface* observer_ = nullptr; |
| 96 bool received_first_packet_ = false; | 103 bool received_first_packet_ = false; |
| 97 }; | 104 }; |
| 98 | 105 |
| 99 class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInternal>, | 106 class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInternal>, |
| 100 public sigslot::has_slots<> { | 107 public sigslot::has_slots<> { |
| 101 public: | 108 public: |
| 102 VideoRtpReceiver(MediaStreamInterface* stream, | 109 // An SSRC of 0 will create a receiver that will match the first SSRC it |
| 103 const std::string& track_id, | 110 // sees. |
| 111 VideoRtpReceiver(const std::string& track_id, |
| 104 rtc::Thread* worker_thread, | 112 rtc::Thread* worker_thread, |
| 105 uint32_t ssrc, | 113 uint32_t ssrc, |
| 106 cricket::VideoChannel* channel); | 114 cricket::VideoChannel* channel); |
| 107 | 115 |
| 108 virtual ~VideoRtpReceiver(); | 116 virtual ~VideoRtpReceiver(); |
| 109 | 117 |
| 110 rtc::scoped_refptr<VideoTrackInterface> video_track() const { | 118 rtc::scoped_refptr<VideoTrackInterface> video_track() const { |
| 111 return track_.get(); | 119 return track_.get(); |
| 112 } | 120 } |
| 113 | 121 |
| 114 // RtpReceiverInterface implementation | 122 // RtpReceiverInterface implementation |
| 115 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { | 123 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
| 116 return track_.get(); | 124 return track_.get(); |
| 117 } | 125 } |
| 118 | 126 |
| 119 cricket::MediaType media_type() const override { | 127 cricket::MediaType media_type() const override { |
| 120 return cricket::MEDIA_TYPE_VIDEO; | 128 return cricket::MEDIA_TYPE_VIDEO; |
| 121 } | 129 } |
| 122 | 130 |
| 123 std::string id() const override { return id_; } | 131 std::string id() const override { return id_; } |
| 124 | 132 |
| 125 RtpParameters GetParameters() const override; | 133 RtpParameters GetParameters() const override; |
| 126 bool SetParameters(const RtpParameters& parameters) override; | 134 bool SetParameters(const RtpParameters& parameters) override; |
| 127 | 135 |
| 128 // RtpReceiverInternal implementation. | 136 // RtpReceiverInternal implementation. |
| 129 void Stop() override; | 137 void Stop() override; |
| 138 uint32_t ssrc() const override { return ssrc_; } |
| 130 | 139 |
| 131 void SetObserver(RtpReceiverObserverInterface* observer) override; | 140 void SetObserver(RtpReceiverObserverInterface* observer) override; |
| 132 | 141 |
| 133 // Does not take ownership. | 142 // Does not take ownership. |
| 134 // Should call SetChannel(nullptr) before |channel| is destroyed. | 143 // Should call SetChannel(nullptr) before |channel| is destroyed. |
| 135 void SetChannel(cricket::VideoChannel* channel); | 144 void SetChannel(cricket::VideoChannel* channel); |
| 136 | 145 |
| 137 private: | 146 private: |
| 138 void OnFirstPacketReceived(cricket::BaseChannel* channel); | 147 void OnFirstPacketReceived(cricket::BaseChannel* channel); |
| 139 | 148 |
| 140 std::string id_; | 149 std::string id_; |
| 141 uint32_t ssrc_; | 150 uint32_t ssrc_; |
| 142 cricket::VideoChannel* channel_; | 151 cricket::VideoChannel* channel_; |
| 143 // |broadcaster_| is needed since the decoder can only handle one sink. | 152 // |broadcaster_| is needed since the decoder can only handle one sink. |
| 144 // It might be better if the decoder can handle multiple sinks and consider | 153 // It might be better if the decoder can handle multiple sinks and consider |
| 145 // the VideoSinkWants. | 154 // the VideoSinkWants. |
| 146 rtc::VideoBroadcaster broadcaster_; | 155 rtc::VideoBroadcaster broadcaster_; |
| 147 // |source_| is held here to be able to change the state of the source when | 156 // |source_| is held here to be able to change the state of the source when |
| 148 // the VideoRtpReceiver is stopped. | 157 // the VideoRtpReceiver is stopped. |
| 149 rtc::scoped_refptr<VideoTrackSource> source_; | 158 rtc::scoped_refptr<VideoTrackSource> source_; |
| 150 rtc::scoped_refptr<VideoTrackInterface> track_; | 159 rtc::scoped_refptr<VideoTrackInterface> track_; |
| 151 bool stopped_ = false; | 160 bool stopped_ = false; |
| 152 RtpReceiverObserverInterface* observer_ = nullptr; | 161 RtpReceiverObserverInterface* observer_ = nullptr; |
| 153 bool received_first_packet_ = false; | 162 bool received_first_packet_ = false; |
| 154 }; | 163 }; |
| 155 | 164 |
| 156 } // namespace webrtc | 165 } // namespace webrtc |
| 157 | 166 |
| 158 #endif // WEBRTC_PC_RTPRECEIVER_H_ | 167 #endif // WEBRTC_PC_RTPRECEIVER_H_ |
| OLD | NEW |