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