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" | |
39 #include "talk/media/base/audiorenderer.h" | 40 #include "talk/media/base/audiorenderer.h" |
40 #include "webrtc/base/basictypes.h" | 41 #include "webrtc/base/basictypes.h" |
41 #include "webrtc/base/criticalsection.h" | 42 #include "webrtc/base/criticalsection.h" |
42 #include "webrtc/base/scoped_ptr.h" | 43 #include "webrtc/base/scoped_ptr.h" |
43 | 44 |
44 namespace webrtc { | 45 namespace webrtc { |
45 | 46 |
46 // LocalAudioSinkAdapter receives data callback as a sink to the local | 47 // LocalAudioSinkAdapter receives data callback as a sink to the local |
47 // AudioTrack, and passes the data to the sink of AudioRenderer. | 48 // AudioTrack, and passes the data to the sink of AudioRenderer. |
48 class LocalAudioSinkAdapter : public AudioTrackSinkInterface, | 49 class LocalAudioSinkAdapter : public AudioTrackSinkInterface, |
(...skipping 14 matching lines...) Expand all Loading... | |
63 void SetSink(cricket::AudioRenderer::Sink* sink) override; | 64 void SetSink(cricket::AudioRenderer::Sink* sink) override; |
64 | 65 |
65 cricket::AudioRenderer::Sink* sink_; | 66 cricket::AudioRenderer::Sink* sink_; |
66 // Critical section protecting |sink_|. | 67 // Critical section protecting |sink_|. |
67 rtc::CriticalSection lock_; | 68 rtc::CriticalSection lock_; |
68 }; | 69 }; |
69 | 70 |
70 class AudioRtpSender : public ObserverInterface, | 71 class AudioRtpSender : public ObserverInterface, |
71 public rtc::RefCountedObject<RtpSenderInterface> { | 72 public rtc::RefCountedObject<RtpSenderInterface> { |
72 public: | 73 public: |
74 // StatsCollector provided so that Add/RemoveLocalAudioTrack can be called | |
75 // at the appropriate times. | |
73 AudioRtpSender(AudioTrackInterface* track, | 76 AudioRtpSender(AudioTrackInterface* track, |
74 uint32_t ssrc, | 77 const std::string& stream_id, |
75 AudioProviderInterface* provider); | 78 AudioProviderInterface* provider, |
79 StatsCollector* stats); | |
80 | |
81 // Randomly generates id and stream_id. | |
82 AudioRtpSender(AudioProviderInterface* provider, StatsCollector* stats); | |
76 | 83 |
77 virtual ~AudioRtpSender(); | 84 virtual ~AudioRtpSender(); |
78 | 85 |
79 // ObserverInterface implementation | 86 // ObserverInterface implementation |
80 void OnChanged() override; | 87 void OnChanged() override; |
81 | 88 |
82 // RtpSenderInterface implementation | 89 // RtpSenderInterface implementation |
83 bool SetTrack(MediaStreamTrackInterface* track) override; | 90 bool SetTrack(MediaStreamTrackInterface* track) override; |
84 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { | 91 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
85 return track_.get(); | 92 return track_.get(); |
86 } | 93 } |
87 | 94 |
95 void SetSsrc(uint32_t ssrc) override; | |
96 | |
97 uint32_t ssrc() const override { return ssrc_; } | |
98 | |
99 cricket::MediaType type() const override { return cricket::MEDIA_TYPE_AUDIO; } | |
pthatcher1
2015/10/22 07:34:14
Should this be media_type()?
Taylor Brandstetter
2015/10/22 19:26:42
Done.
| |
100 | |
88 std::string id() const override { return id_; } | 101 std::string id() const override { return id_; } |
89 | 102 |
103 void set_stream_id(const std::string& stream_id) override { | |
104 stream_id_ = stream_id; | |
105 } | |
106 std::string stream_id() const override { return stream_id_; } | |
107 | |
90 void Stop() override; | 108 void Stop() override; |
91 | 109 |
92 private: | 110 private: |
93 void Reconfigure(); | 111 bool ready_to_send() const { return track_ && ssrc_; } |
pthatcher1
2015/10/22 07:34:14
Since the transport code already has a ready_to_se
Taylor Brandstetter
2015/10/22 19:26:42
"sending" isn't really accurate since this method
| |
112 // Helper function to construct options for | |
113 // AudioProviderInterface::SetAudioSend. | |
114 void SetAudioSend(); | |
94 | 115 |
95 std::string id_; | 116 std::string id_; |
117 std::string stream_id_; | |
118 AudioProviderInterface* provider_; | |
119 StatsCollector* stats_; | |
96 rtc::scoped_refptr<AudioTrackInterface> track_; | 120 rtc::scoped_refptr<AudioTrackInterface> track_; |
97 uint32_t ssrc_; | 121 uint32_t ssrc_ = 0; |
98 AudioProviderInterface* provider_; | 122 bool cached_track_enabled_ = false; |
99 bool cached_track_enabled_; | 123 bool stopped_ = false; |
100 | 124 |
101 // Used to pass the data callback from the |track_| to the other end of | 125 // Used to pass the data callback from the |track_| to the other end of |
102 // cricket::AudioRenderer. | 126 // cricket::AudioRenderer. |
103 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; | 127 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; |
104 }; | 128 }; |
105 | 129 |
106 class VideoRtpSender : public ObserverInterface, | 130 class VideoRtpSender : public ObserverInterface, |
107 public rtc::RefCountedObject<RtpSenderInterface> { | 131 public rtc::RefCountedObject<RtpSenderInterface> { |
108 public: | 132 public: |
109 VideoRtpSender(VideoTrackInterface* track, | 133 VideoRtpSender(VideoTrackInterface* track, |
110 uint32_t ssrc, | 134 const std::string& stream_id, |
111 VideoProviderInterface* provider); | 135 VideoProviderInterface* provider); |
112 | 136 |
137 // Randomly generates id and stream_id. | |
138 explicit VideoRtpSender(VideoProviderInterface* provider); | |
139 | |
113 virtual ~VideoRtpSender(); | 140 virtual ~VideoRtpSender(); |
114 | 141 |
115 // ObserverInterface implementation | 142 // ObserverInterface implementation |
116 void OnChanged() override; | 143 void OnChanged() override; |
117 | 144 |
118 // RtpSenderInterface implementation | 145 // RtpSenderInterface implementation |
119 bool SetTrack(MediaStreamTrackInterface* track) override; | 146 bool SetTrack(MediaStreamTrackInterface* track) override; |
120 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { | 147 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
121 return track_.get(); | 148 return track_.get(); |
122 } | 149 } |
123 | 150 |
151 void SetSsrc(uint32_t ssrc) override; | |
152 | |
153 uint32_t ssrc() const override { return ssrc_; } | |
154 | |
155 cricket::MediaType type() const override { return cricket::MEDIA_TYPE_VIDEO; } | |
156 | |
124 std::string id() const override { return id_; } | 157 std::string id() const override { return id_; } |
125 | 158 |
159 void set_stream_id(const std::string& stream_id) override { | |
160 stream_id_ = stream_id; | |
161 } | |
162 std::string stream_id() const override { return stream_id_; } | |
163 | |
126 void Stop() override; | 164 void Stop() override; |
127 | 165 |
128 private: | 166 private: |
129 void Reconfigure(); | 167 bool ready_to_send() const { return track_ && ssrc_; } |
168 // Helper function to construct options for | |
169 // VideoProviderInterface::SetVideoSend. | |
170 void SetVideoSend(); | |
130 | 171 |
131 std::string id_; | 172 std::string id_; |
173 std::string stream_id_; | |
174 VideoProviderInterface* provider_; | |
132 rtc::scoped_refptr<VideoTrackInterface> track_; | 175 rtc::scoped_refptr<VideoTrackInterface> track_; |
133 uint32_t ssrc_; | 176 uint32_t ssrc_ = 0; |
134 VideoProviderInterface* provider_; | 177 bool cached_track_enabled_ = false; |
135 bool cached_track_enabled_; | 178 bool stopped_ = false; |
136 }; | 179 }; |
137 | 180 |
138 } // namespace webrtc | 181 } // namespace webrtc |
139 | 182 |
140 #endif // TALK_APP_WEBRTC_RTPSENDER_H_ | 183 #endif // TALK_APP_WEBRTC_RTPSENDER_H_ |
OLD | NEW |