deadbeef | 6979b02 | 2015-09-24 16:47:53 -0700 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
deadbeef | 6979b02 | 2015-09-24 16:47:53 -0700 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [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 16:47:53 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 11 | // This file contains classes that implement RtpReceiverInterface. |
| 12 | // An RtpReceiver associates a MediaStreamTrackInterface with an underlying |
| 13 | // transport (provided by AudioProviderInterface/VideoProviderInterface) |
| 14 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 15 | #ifndef WEBRTC_API_RTPRECEIVER_H_ |
| 16 | #define WEBRTC_API_RTPRECEIVER_H_ |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 17 | |
| 18 | #include <string> |
| 19 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 20 | #include "webrtc/api/mediastreamprovider.h" |
| 21 | #include "webrtc/api/rtpreceiverinterface.h" |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame^] | 22 | #include "webrtc/api/videotracksource.h" |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 23 | #include "webrtc/base/basictypes.h" |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame^] | 24 | #include "webrtc/media/base/videobroadcaster.h" |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
| 28 | class AudioRtpReceiver : public ObserverInterface, |
| 29 | public AudioSourceInterface::AudioObserver, |
| 30 | public rtc::RefCountedObject<RtpReceiverInterface> { |
| 31 | public: |
| 32 | AudioRtpReceiver(AudioTrackInterface* track, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 33 | uint32_t ssrc, |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 34 | AudioProviderInterface* provider); |
| 35 | |
| 36 | virtual ~AudioRtpReceiver(); |
| 37 | |
| 38 | // ObserverInterface implementation |
| 39 | void OnChanged() override; |
| 40 | |
| 41 | // AudioSourceInterface::AudioObserver implementation |
| 42 | void OnSetVolume(double volume) override; |
| 43 | |
| 44 | // RtpReceiverInterface implementation |
| 45 | rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
| 46 | return track_.get(); |
| 47 | } |
| 48 | |
| 49 | std::string id() const override { return id_; } |
| 50 | |
| 51 | void Stop() override; |
| 52 | |
| 53 | private: |
| 54 | void Reconfigure(); |
| 55 | |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 56 | const std::string id_; |
| 57 | const rtc::scoped_refptr<AudioTrackInterface> track_; |
| 58 | const uint32_t ssrc_; |
| 59 | AudioProviderInterface* provider_; // Set to null in Stop(). |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 60 | bool cached_track_enabled_; |
| 61 | }; |
| 62 | |
| 63 | class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInterface> { |
| 64 | public: |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame^] | 65 | VideoRtpReceiver(MediaStreamInterface* stream, |
| 66 | const std::string& track_id, |
| 67 | rtc::Thread* worker_thread, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 68 | uint32_t ssrc, |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 69 | VideoProviderInterface* provider); |
| 70 | |
| 71 | virtual ~VideoRtpReceiver(); |
| 72 | |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame^] | 73 | rtc::scoped_refptr<VideoTrackInterface> video_track() const { |
| 74 | return track_.get(); |
| 75 | } |
| 76 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 77 | // RtpReceiverInterface implementation |
| 78 | rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
| 79 | return track_.get(); |
| 80 | } |
| 81 | |
| 82 | std::string id() const override { return id_; } |
| 83 | |
| 84 | void Stop() override; |
| 85 | |
| 86 | private: |
| 87 | std::string id_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 88 | uint32_t ssrc_; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 89 | VideoProviderInterface* provider_; |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame^] | 90 | // |broadcaster_| is needed since the decoder can only handle one sink. |
| 91 | // It might be better if the decoder can handle multiple sinks and consider |
| 92 | // the VideoSinkWants. |
| 93 | rtc::VideoBroadcaster broadcaster_; |
| 94 | // |source_| is held here to be able to change the state of the source when |
| 95 | // the VideoRtpReceiver is stopped. |
| 96 | rtc::scoped_refptr<VideoTrackSource> source_; |
| 97 | rtc::scoped_refptr<VideoTrackInterface> track_; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // namespace webrtc |
| 101 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 102 | #endif // WEBRTC_API_RTPRECEIVER_H_ |