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 RtpSenderInterface. | 11 // This file contains classes that implement RtpSenderInterface. |
12 // An RtpSender associates a MediaStreamTrackInterface with an underlying | 12 // An RtpSender associates a MediaStreamTrackInterface with an underlying |
13 // transport (provided by AudioProviderInterface/VideoProviderInterface) | 13 // transport (provided by AudioProviderInterface/VideoProviderInterface) |
14 | 14 |
15 #ifndef WEBRTC_PC_RTPSENDER_H_ | 15 #ifndef WEBRTC_PC_RTPSENDER_H_ |
16 #define WEBRTC_PC_RTPSENDER_H_ | 16 #define WEBRTC_PC_RTPSENDER_H_ |
17 | 17 |
18 #include <memory> | 18 #include <memory> |
19 #include <string> | 19 #include <string> |
20 | 20 |
21 #include "webrtc/api/mediastreaminterface.h" | 21 #include "webrtc/api/mediastreaminterface.h" |
22 #include "webrtc/api/rtpsenderinterface.h" | 22 #include "webrtc/api/rtpsenderinterface.h" |
23 #include "webrtc/base/basictypes.h" | 23 #include "webrtc/base/basictypes.h" |
24 #include "webrtc/base/criticalsection.h" | 24 #include "webrtc/base/criticalsection.h" |
25 #include "webrtc/media/base/audiosource.h" | 25 #include "webrtc/media/base/audiosource.h" |
26 #include "webrtc/pc/channel.h" | 26 #include "webrtc/pc/channel.h" |
| 27 #include "webrtc/pc/dtmfsender.h" |
27 #include "webrtc/pc/statscollector.h" | 28 #include "webrtc/pc/statscollector.h" |
28 | 29 |
29 namespace webrtc { | 30 namespace webrtc { |
30 | 31 |
31 // Internal interface used by PeerConnection. | 32 // Internal interface used by PeerConnection. |
32 class RtpSenderInternal : public RtpSenderInterface { | 33 class RtpSenderInternal : public RtpSenderInterface { |
33 public: | 34 public: |
34 // Used to set the SSRC of the sender, once a local description has been set. | 35 // Used to set the SSRC of the sender, once a local description has been set. |
35 // If |ssrc| is 0, this indiates that the sender should disconnect from the | 36 // If |ssrc| is 0, this indiates that the sender should disconnect from the |
36 // underlying transport (this occurs if the sender isn't seen in a local | 37 // underlying transport (this occurs if the sender isn't seen in a local |
(...skipping 24 matching lines...) Expand all Loading... |
61 size_t number_of_frames) override; | 62 size_t number_of_frames) override; |
62 | 63 |
63 // cricket::AudioSource implementation. | 64 // cricket::AudioSource implementation. |
64 void SetSink(cricket::AudioSource::Sink* sink) override; | 65 void SetSink(cricket::AudioSource::Sink* sink) override; |
65 | 66 |
66 cricket::AudioSource::Sink* sink_; | 67 cricket::AudioSource::Sink* sink_; |
67 // Critical section protecting |sink_|. | 68 // Critical section protecting |sink_|. |
68 rtc::CriticalSection lock_; | 69 rtc::CriticalSection lock_; |
69 }; | 70 }; |
70 | 71 |
71 class AudioRtpSender : public ObserverInterface, | 72 class AudioRtpSender : public DtmfProviderInterface, |
| 73 public ObserverInterface, |
72 public rtc::RefCountedObject<RtpSenderInternal> { | 74 public rtc::RefCountedObject<RtpSenderInternal> { |
73 public: | 75 public: |
74 // StatsCollector provided so that Add/RemoveLocalAudioTrack can be called | 76 // StatsCollector provided so that Add/RemoveLocalAudioTrack can be called |
75 // at the appropriate times. | 77 // at the appropriate times. |
76 // |channel| can be null if one does not exist yet. | 78 // |channel| can be null if one does not exist yet. |
77 AudioRtpSender(AudioTrackInterface* track, | 79 AudioRtpSender(AudioTrackInterface* track, |
78 const std::string& stream_id, | 80 const std::string& stream_id, |
79 cricket::VoiceChannel* channel, | 81 cricket::VoiceChannel* channel, |
80 StatsCollector* stats); | 82 StatsCollector* stats); |
81 | 83 |
82 // Randomly generates stream_id. | 84 // Randomly generates stream_id. |
83 // |channel| can be null if one does not exist yet. | 85 // |channel| can be null if one does not exist yet. |
84 AudioRtpSender(AudioTrackInterface* track, | 86 AudioRtpSender(AudioTrackInterface* track, |
85 cricket::VoiceChannel* channel, | 87 cricket::VoiceChannel* channel, |
86 StatsCollector* stats); | 88 StatsCollector* stats); |
87 | 89 |
88 // Randomly generates id and stream_id. | 90 // Randomly generates id and stream_id. |
89 // |channel| can be null if one does not exist yet. | 91 // |channel| can be null if one does not exist yet. |
90 AudioRtpSender(cricket::VoiceChannel* channel, StatsCollector* stats); | 92 AudioRtpSender(cricket::VoiceChannel* channel, StatsCollector* stats); |
91 | 93 |
92 virtual ~AudioRtpSender(); | 94 virtual ~AudioRtpSender(); |
93 | 95 |
94 // ObserverInterface implementation | 96 // DtmfSenderProvider implementation. |
| 97 bool CanInsertDtmf() override; |
| 98 bool InsertDtmf(int code, int duration) override; |
| 99 sigslot::signal0<>* GetOnDestroyedSignal() override; |
| 100 |
| 101 // ObserverInterface implementation. |
95 void OnChanged() override; | 102 void OnChanged() override; |
96 | 103 |
97 // RtpSenderInterface implementation | 104 // RtpSenderInterface implementation. |
98 bool SetTrack(MediaStreamTrackInterface* track) override; | 105 bool SetTrack(MediaStreamTrackInterface* track) override; |
99 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { | 106 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
100 return track_; | 107 return track_; |
101 } | 108 } |
102 | 109 |
103 uint32_t ssrc() const override { return ssrc_; } | 110 uint32_t ssrc() const override { return ssrc_; } |
104 | 111 |
105 cricket::MediaType media_type() const override { | 112 cricket::MediaType media_type() const override { |
106 return cricket::MEDIA_TYPE_AUDIO; | 113 return cricket::MEDIA_TYPE_AUDIO; |
107 } | 114 } |
108 | 115 |
109 std::string id() const override { return id_; } | 116 std::string id() const override { return id_; } |
110 | 117 |
111 std::vector<std::string> stream_ids() const override { | 118 std::vector<std::string> stream_ids() const override { |
112 std::vector<std::string> ret = {stream_id_}; | 119 std::vector<std::string> ret = {stream_id_}; |
113 return ret; | 120 return ret; |
114 } | 121 } |
115 | 122 |
116 RtpParameters GetParameters() const override; | 123 RtpParameters GetParameters() const override; |
117 bool SetParameters(const RtpParameters& parameters) override; | 124 bool SetParameters(const RtpParameters& parameters) override; |
118 | 125 |
| 126 rtc::scoped_refptr<DtmfSenderInterface> GetDtmfSender() const override; |
| 127 |
119 // RtpSenderInternal implementation. | 128 // RtpSenderInternal implementation. |
120 void SetSsrc(uint32_t ssrc) override; | 129 void SetSsrc(uint32_t ssrc) override; |
121 | 130 |
122 void set_stream_id(const std::string& stream_id) override { | 131 void set_stream_id(const std::string& stream_id) override { |
123 stream_id_ = stream_id; | 132 stream_id_ = stream_id; |
124 } | 133 } |
125 std::string stream_id() const override { return stream_id_; } | 134 std::string stream_id() const override { return stream_id_; } |
126 | 135 |
127 void Stop() override; | 136 void Stop() override; |
128 | 137 |
129 // Does not take ownership. | 138 // Does not take ownership. |
130 // Should call SetChannel(nullptr) before |channel| is destroyed. | 139 // Should call SetChannel(nullptr) before |channel| is destroyed. |
131 void SetChannel(cricket::VoiceChannel* channel) { channel_ = channel; } | 140 void SetChannel(cricket::VoiceChannel* channel) { channel_ = channel; } |
132 | 141 |
133 private: | 142 private: |
134 // TODO(nisse): Since SSRC == 0 is technically valid, figure out | 143 // TODO(nisse): Since SSRC == 0 is technically valid, figure out |
135 // some other way to test if we have a valid SSRC. | 144 // some other way to test if we have a valid SSRC. |
136 bool can_send_track() const { return track_ && ssrc_; } | 145 bool can_send_track() const { return track_ && ssrc_; } |
137 // Helper function to construct options for | 146 // Helper function to construct options for |
138 // AudioProviderInterface::SetAudioSend. | 147 // AudioProviderInterface::SetAudioSend. |
139 void SetAudioSend(); | 148 void SetAudioSend(); |
140 // Helper function to call SetAudioSend with "stop sending" parameters. | 149 // Helper function to call SetAudioSend with "stop sending" parameters. |
141 void ClearAudioSend(); | 150 void ClearAudioSend(); |
142 | 151 |
| 152 void CreateDtmfSender(); |
| 153 |
| 154 sigslot::signal0<> SignalDestroyed; |
| 155 |
143 std::string id_; | 156 std::string id_; |
144 std::string stream_id_; | 157 std::string stream_id_; |
145 cricket::VoiceChannel* channel_ = nullptr; | 158 cricket::VoiceChannel* channel_ = nullptr; |
146 StatsCollector* stats_; | 159 StatsCollector* stats_; |
147 rtc::scoped_refptr<AudioTrackInterface> track_; | 160 rtc::scoped_refptr<AudioTrackInterface> track_; |
| 161 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender_proxy_; |
148 uint32_t ssrc_ = 0; | 162 uint32_t ssrc_ = 0; |
149 bool cached_track_enabled_ = false; | 163 bool cached_track_enabled_ = false; |
150 bool stopped_ = false; | 164 bool stopped_ = false; |
151 | 165 |
152 // Used to pass the data callback from the |track_| to the other end of | 166 // Used to pass the data callback from the |track_| to the other end of |
153 // cricket::AudioSource. | 167 // cricket::AudioSource. |
154 std::unique_ptr<LocalAudioSinkAdapter> sink_adapter_; | 168 std::unique_ptr<LocalAudioSinkAdapter> sink_adapter_; |
155 }; | 169 }; |
156 | 170 |
157 class VideoRtpSender : public ObserverInterface, | 171 class VideoRtpSender : public ObserverInterface, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 std::string id() const override { return id_; } | 204 std::string id() const override { return id_; } |
191 | 205 |
192 std::vector<std::string> stream_ids() const override { | 206 std::vector<std::string> stream_ids() const override { |
193 std::vector<std::string> ret = {stream_id_}; | 207 std::vector<std::string> ret = {stream_id_}; |
194 return ret; | 208 return ret; |
195 } | 209 } |
196 | 210 |
197 RtpParameters GetParameters() const override; | 211 RtpParameters GetParameters() const override; |
198 bool SetParameters(const RtpParameters& parameters) override; | 212 bool SetParameters(const RtpParameters& parameters) override; |
199 | 213 |
| 214 rtc::scoped_refptr<DtmfSenderInterface> GetDtmfSender() const override; |
| 215 |
200 // RtpSenderInternal implementation. | 216 // RtpSenderInternal implementation. |
201 void SetSsrc(uint32_t ssrc) override; | 217 void SetSsrc(uint32_t ssrc) override; |
202 | 218 |
203 void set_stream_id(const std::string& stream_id) override { | 219 void set_stream_id(const std::string& stream_id) override { |
204 stream_id_ = stream_id; | 220 stream_id_ = stream_id; |
205 } | 221 } |
206 std::string stream_id() const override { return stream_id_; } | 222 std::string stream_id() const override { return stream_id_; } |
207 | 223 |
208 void Stop() override; | 224 void Stop() override; |
209 | 225 |
(...skipping 16 matching lines...) Expand all Loading... |
226 uint32_t ssrc_ = 0; | 242 uint32_t ssrc_ = 0; |
227 bool cached_track_enabled_ = false; | 243 bool cached_track_enabled_ = false; |
228 VideoTrackInterface::ContentHint cached_track_content_hint_ = | 244 VideoTrackInterface::ContentHint cached_track_content_hint_ = |
229 VideoTrackInterface::ContentHint::kNone; | 245 VideoTrackInterface::ContentHint::kNone; |
230 bool stopped_ = false; | 246 bool stopped_ = false; |
231 }; | 247 }; |
232 | 248 |
233 } // namespace webrtc | 249 } // namespace webrtc |
234 | 250 |
235 #endif // WEBRTC_PC_RTPSENDER_H_ | 251 #endif // WEBRTC_PC_RTPSENDER_H_ |
OLD | NEW |