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 media_type() const override { |
| 100 return cricket::MEDIA_TYPE_AUDIO; |
| 101 } |
| 102 |
88 std::string id() const override { return id_; } | 103 std::string id() const override { return id_; } |
89 | 104 |
| 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 |
90 void Stop() override; | 110 void Stop() override; |
91 | 111 |
92 private: | 112 private: |
93 void Reconfigure(); | 113 bool can_send_track() const { return track_ && ssrc_; } |
| 114 // Helper function to construct options for |
| 115 // AudioProviderInterface::SetAudioSend. |
| 116 void SetAudioSend(); |
94 | 117 |
95 std::string id_; | 118 std::string id_; |
| 119 std::string stream_id_; |
| 120 AudioProviderInterface* provider_; |
| 121 StatsCollector* stats_; |
96 rtc::scoped_refptr<AudioTrackInterface> track_; | 122 rtc::scoped_refptr<AudioTrackInterface> track_; |
97 uint32_t ssrc_; | 123 uint32_t ssrc_ = 0; |
98 AudioProviderInterface* provider_; | 124 bool cached_track_enabled_ = false; |
99 bool cached_track_enabled_; | 125 bool stopped_ = false; |
100 | 126 |
101 // Used to pass the data callback from the |track_| to the other end of | 127 // Used to pass the data callback from the |track_| to the other end of |
102 // cricket::AudioRenderer. | 128 // cricket::AudioRenderer. |
103 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; | 129 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; |
104 }; | 130 }; |
105 | 131 |
106 class VideoRtpSender : public ObserverInterface, | 132 class VideoRtpSender : public ObserverInterface, |
107 public rtc::RefCountedObject<RtpSenderInterface> { | 133 public rtc::RefCountedObject<RtpSenderInterface> { |
108 public: | 134 public: |
109 VideoRtpSender(VideoTrackInterface* track, | 135 VideoRtpSender(VideoTrackInterface* track, |
110 uint32_t ssrc, | 136 const std::string& stream_id, |
111 VideoProviderInterface* provider); | 137 VideoProviderInterface* provider); |
112 | 138 |
| 139 // Randomly generates id and stream_id. |
| 140 explicit VideoRtpSender(VideoProviderInterface* provider); |
| 141 |
113 virtual ~VideoRtpSender(); | 142 virtual ~VideoRtpSender(); |
114 | 143 |
115 // ObserverInterface implementation | 144 // ObserverInterface implementation |
116 void OnChanged() override; | 145 void OnChanged() override; |
117 | 146 |
118 // RtpSenderInterface implementation | 147 // RtpSenderInterface implementation |
119 bool SetTrack(MediaStreamTrackInterface* track) override; | 148 bool SetTrack(MediaStreamTrackInterface* track) override; |
120 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { | 149 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
121 return track_.get(); | 150 return track_.get(); |
122 } | 151 } |
123 | 152 |
| 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 |
124 std::string id() const override { return id_; } | 161 std::string id() const override { return id_; } |
125 | 162 |
| 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 |
126 void Stop() override; | 168 void Stop() override; |
127 | 169 |
128 private: | 170 private: |
129 void Reconfigure(); | 171 bool can_send_track() const { return track_ && ssrc_; } |
| 172 // Helper function to construct options for |
| 173 // VideoProviderInterface::SetVideoSend. |
| 174 void SetVideoSend(); |
130 | 175 |
131 std::string id_; | 176 std::string id_; |
| 177 std::string stream_id_; |
| 178 VideoProviderInterface* provider_; |
132 rtc::scoped_refptr<VideoTrackInterface> track_; | 179 rtc::scoped_refptr<VideoTrackInterface> track_; |
133 uint32_t ssrc_; | 180 uint32_t ssrc_ = 0; |
134 VideoProviderInterface* provider_; | 181 bool cached_track_enabled_ = false; |
135 bool cached_track_enabled_; | 182 bool stopped_ = false; |
136 }; | 183 }; |
137 | 184 |
138 } // namespace webrtc | 185 } // namespace webrtc |
139 | 186 |
140 #endif // TALK_APP_WEBRTC_RTPSENDER_H_ | 187 #endif // TALK_APP_WEBRTC_RTPSENDER_H_ |
OLD | NEW |