OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 18 matching lines...) Expand all Loading... |
29 // An RtpSender associates a MediaStreamTrackInterface with an underlying | 29 // An RtpSender associates a MediaStreamTrackInterface with an underlying |
30 // transport (provided by AudioProviderInterface/VideoProviderInterface) | 30 // transport (provided by AudioProviderInterface/VideoProviderInterface) |
31 | 31 |
32 #ifndef TALK_APP_WEBRTC_RTPSENDER_H_ | 32 #ifndef TALK_APP_WEBRTC_RTPSENDER_H_ |
33 #define TALK_APP_WEBRTC_RTPSENDER_H_ | 33 #define TALK_APP_WEBRTC_RTPSENDER_H_ |
34 | 34 |
35 #include <string> | 35 #include <string> |
36 | 36 |
37 #include "talk/app/webrtc/mediastreamprovider.h" | 37 #include "talk/app/webrtc/mediastreamprovider.h" |
38 #include "talk/app/webrtc/rtpsenderinterface.h" | 38 #include "talk/app/webrtc/rtpsenderinterface.h" |
39 #include "talk/app/webrtc/statscollector.h" | |
40 #include "talk/media/base/audiorenderer.h" | 39 #include "talk/media/base/audiorenderer.h" |
41 #include "webrtc/base/basictypes.h" | 40 #include "webrtc/base/basictypes.h" |
42 #include "webrtc/base/criticalsection.h" | 41 #include "webrtc/base/criticalsection.h" |
43 #include "webrtc/base/scoped_ptr.h" | 42 #include "webrtc/base/scoped_ptr.h" |
44 | 43 |
45 namespace webrtc { | 44 namespace webrtc { |
46 | 45 |
47 // LocalAudioSinkAdapter receives data callback as a sink to the local | 46 // LocalAudioSinkAdapter receives data callback as a sink to the local |
48 // AudioTrack, and passes the data to the sink of AudioRenderer. | 47 // AudioTrack, and passes the data to the sink of AudioRenderer. |
49 class LocalAudioSinkAdapter : public AudioTrackSinkInterface, | 48 class LocalAudioSinkAdapter : public AudioTrackSinkInterface, |
(...skipping 14 matching lines...) Expand all Loading... |
64 void SetSink(cricket::AudioRenderer::Sink* sink) override; | 63 void SetSink(cricket::AudioRenderer::Sink* sink) override; |
65 | 64 |
66 cricket::AudioRenderer::Sink* sink_; | 65 cricket::AudioRenderer::Sink* sink_; |
67 // Critical section protecting |sink_|. | 66 // Critical section protecting |sink_|. |
68 rtc::CriticalSection lock_; | 67 rtc::CriticalSection lock_; |
69 }; | 68 }; |
70 | 69 |
71 class AudioRtpSender : public ObserverInterface, | 70 class AudioRtpSender : public ObserverInterface, |
72 public rtc::RefCountedObject<RtpSenderInterface> { | 71 public rtc::RefCountedObject<RtpSenderInterface> { |
73 public: | 72 public: |
74 // StatsCollector provided so that Add/RemoveLocalAudioTrack can be called | |
75 // at the appropriate times. | |
76 AudioRtpSender(AudioTrackInterface* track, | 73 AudioRtpSender(AudioTrackInterface* track, |
77 const std::string& stream_id, | 74 uint32_t ssrc, |
78 AudioProviderInterface* provider, | 75 AudioProviderInterface* provider); |
79 StatsCollector* stats); | |
80 | |
81 // Randomly generates id and stream_id. | |
82 AudioRtpSender(AudioProviderInterface* provider, StatsCollector* stats); | |
83 | 76 |
84 virtual ~AudioRtpSender(); | 77 virtual ~AudioRtpSender(); |
85 | 78 |
86 // ObserverInterface implementation | 79 // ObserverInterface implementation |
87 void OnChanged() override; | 80 void OnChanged() override; |
88 | 81 |
89 // RtpSenderInterface implementation | 82 // RtpSenderInterface implementation |
90 bool SetTrack(MediaStreamTrackInterface* track) override; | 83 bool SetTrack(MediaStreamTrackInterface* track) override; |
91 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { | 84 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
92 return track_.get(); | 85 return track_.get(); |
93 } | 86 } |
94 | 87 |
95 void SetSsrc(uint32_t ssrc) override; | |
96 | |
97 uint32_t ssrc() const override { return ssrc_; } | |
98 | |
99 cricket::MediaType media_type() const override { | |
100 return cricket::MEDIA_TYPE_AUDIO; | |
101 } | |
102 | |
103 std::string id() const override { return id_; } | 88 std::string id() const override { return id_; } |
104 | 89 |
105 void set_stream_id(const std::string& stream_id) override { | |
106 stream_id_ = stream_id; | |
107 } | |
108 std::string stream_id() const override { return stream_id_; } | |
109 | |
110 void Stop() override; | 90 void Stop() override; |
111 | 91 |
112 private: | 92 private: |
113 bool can_send_track() const { return track_ && ssrc_; } | 93 void Reconfigure(); |
114 // Helper function to construct options for | |
115 // AudioProviderInterface::SetAudioSend. | |
116 void SetAudioSend(); | |
117 | 94 |
118 std::string id_; | 95 std::string id_; |
119 std::string stream_id_; | 96 rtc::scoped_refptr<AudioTrackInterface> track_; |
| 97 uint32_t ssrc_; |
120 AudioProviderInterface* provider_; | 98 AudioProviderInterface* provider_; |
121 StatsCollector* stats_; | 99 bool cached_track_enabled_; |
122 rtc::scoped_refptr<AudioTrackInterface> track_; | |
123 uint32_t ssrc_ = 0; | |
124 bool cached_track_enabled_ = false; | |
125 bool stopped_ = false; | |
126 | 100 |
127 // Used to pass the data callback from the |track_| to the other end of | 101 // Used to pass the data callback from the |track_| to the other end of |
128 // cricket::AudioRenderer. | 102 // cricket::AudioRenderer. |
129 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; | 103 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; |
130 }; | 104 }; |
131 | 105 |
132 class VideoRtpSender : public ObserverInterface, | 106 class VideoRtpSender : public ObserverInterface, |
133 public rtc::RefCountedObject<RtpSenderInterface> { | 107 public rtc::RefCountedObject<RtpSenderInterface> { |
134 public: | 108 public: |
135 VideoRtpSender(VideoTrackInterface* track, | 109 VideoRtpSender(VideoTrackInterface* track, |
136 const std::string& stream_id, | 110 uint32_t ssrc, |
137 VideoProviderInterface* provider); | 111 VideoProviderInterface* provider); |
138 | 112 |
139 // Randomly generates id and stream_id. | |
140 explicit VideoRtpSender(VideoProviderInterface* provider); | |
141 | |
142 virtual ~VideoRtpSender(); | 113 virtual ~VideoRtpSender(); |
143 | 114 |
144 // ObserverInterface implementation | 115 // ObserverInterface implementation |
145 void OnChanged() override; | 116 void OnChanged() override; |
146 | 117 |
147 // RtpSenderInterface implementation | 118 // RtpSenderInterface implementation |
148 bool SetTrack(MediaStreamTrackInterface* track) override; | 119 bool SetTrack(MediaStreamTrackInterface* track) override; |
149 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { | 120 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
150 return track_.get(); | 121 return track_.get(); |
151 } | 122 } |
152 | 123 |
153 void SetSsrc(uint32_t ssrc) override; | |
154 | |
155 uint32_t ssrc() const override { return ssrc_; } | |
156 | |
157 cricket::MediaType media_type() const override { | |
158 return cricket::MEDIA_TYPE_VIDEO; | |
159 } | |
160 | |
161 std::string id() const override { return id_; } | 124 std::string id() const override { return id_; } |
162 | 125 |
163 void set_stream_id(const std::string& stream_id) override { | |
164 stream_id_ = stream_id; | |
165 } | |
166 std::string stream_id() const override { return stream_id_; } | |
167 | |
168 void Stop() override; | 126 void Stop() override; |
169 | 127 |
170 private: | 128 private: |
171 bool can_send_track() const { return track_ && ssrc_; } | 129 void Reconfigure(); |
172 // Helper function to construct options for | |
173 // VideoProviderInterface::SetVideoSend. | |
174 void SetVideoSend(); | |
175 | 130 |
176 std::string id_; | 131 std::string id_; |
177 std::string stream_id_; | 132 rtc::scoped_refptr<VideoTrackInterface> track_; |
| 133 uint32_t ssrc_; |
178 VideoProviderInterface* provider_; | 134 VideoProviderInterface* provider_; |
179 rtc::scoped_refptr<VideoTrackInterface> track_; | 135 bool cached_track_enabled_; |
180 uint32_t ssrc_ = 0; | |
181 bool cached_track_enabled_ = false; | |
182 bool stopped_ = false; | |
183 }; | 136 }; |
184 | 137 |
185 } // namespace webrtc | 138 } // namespace webrtc |
186 | 139 |
187 #endif // TALK_APP_WEBRTC_RTPSENDER_H_ | 140 #endif // TALK_APP_WEBRTC_RTPSENDER_H_ |
OLD | NEW |