| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 namespace webrtc { | 45 namespace webrtc { |
| 46 | 46 |
| 47 // TrackHandler listen to events on a MediaStreamTrackInterface that is | 47 // TrackHandler listen to events on a MediaStreamTrackInterface that is |
| 48 // connected to a certain PeerConnection. | 48 // connected to a certain PeerConnection. |
| 49 class TrackHandler : public ObserverInterface { | 49 class TrackHandler : public ObserverInterface { |
| 50 public: | 50 public: |
| 51 TrackHandler(MediaStreamTrackInterface* track, uint32 ssrc); | 51 TrackHandler(MediaStreamTrackInterface* track, uint32 ssrc); |
| 52 virtual ~TrackHandler(); | 52 virtual ~TrackHandler(); |
| 53 virtual void OnChanged(); | 53 virtual void OnChanged(); |
| 54 // Associate |track_| with |ssrc_|. Can be called multiple times. | |
| 55 virtual void Start() = 0; | |
| 56 // Stop using |track_| on this PeerConnection. | 54 // Stop using |track_| on this PeerConnection. |
| 57 virtual void Stop() = 0; | 55 virtual void Stop() = 0; |
| 58 | 56 |
| 59 MediaStreamTrackInterface* track() { return track_; } | 57 MediaStreamTrackInterface* track() { return track_; } |
| 60 uint32 ssrc() const { return ssrc_; } | 58 uint32 ssrc() const { return ssrc_; } |
| 61 | 59 |
| 62 protected: | 60 protected: |
| 63 virtual void OnStateChanged() = 0; | 61 virtual void OnStateChanged() = 0; |
| 64 virtual void OnEnabledChanged() = 0; | 62 virtual void OnEnabledChanged() = 0; |
| 65 | 63 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 96 | 94 |
| 97 // LocalAudioTrackHandler listen to events on a local AudioTrack instance | 95 // LocalAudioTrackHandler listen to events on a local AudioTrack instance |
| 98 // connected to a PeerConnection and orders the |provider| to executes the | 96 // connected to a PeerConnection and orders the |provider| to executes the |
| 99 // requested change. | 97 // requested change. |
| 100 class LocalAudioTrackHandler : public TrackHandler { | 98 class LocalAudioTrackHandler : public TrackHandler { |
| 101 public: | 99 public: |
| 102 LocalAudioTrackHandler(AudioTrackInterface* track, | 100 LocalAudioTrackHandler(AudioTrackInterface* track, |
| 103 uint32 ssrc, | 101 uint32 ssrc, |
| 104 AudioProviderInterface* provider); | 102 AudioProviderInterface* provider); |
| 105 virtual ~LocalAudioTrackHandler(); | 103 virtual ~LocalAudioTrackHandler(); |
| 106 void Start() override; | 104 |
| 107 void Stop() override; | 105 void Stop() override; |
| 108 | 106 |
| 109 protected: | 107 protected: |
| 110 void OnStateChanged() override; | 108 void OnStateChanged() override; |
| 111 void OnEnabledChanged() override; | 109 void OnEnabledChanged() override; |
| 112 | 110 |
| 113 private: | 111 private: |
| 114 AudioTrackInterface* audio_track_; | 112 AudioTrackInterface* audio_track_; |
| 115 AudioProviderInterface* provider_; | 113 AudioProviderInterface* provider_; |
| 116 | 114 |
| 117 // Used to pass the data callback from the |audio_track_| to the other | 115 // Used to pass the data callback from the |audio_track_| to the other |
| 118 // end of cricket::AudioRenderer. | 116 // end of cricket::AudioRenderer. |
| 119 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; | 117 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; |
| 120 }; | 118 }; |
| 121 | 119 |
| 122 // RemoteAudioTrackHandler listen to events on a remote AudioTrack instance | 120 // RemoteAudioTrackHandler listen to events on a remote AudioTrack instance |
| 123 // connected to a PeerConnection and orders the |provider| to executes the | 121 // connected to a PeerConnection and orders the |provider| to executes the |
| 124 // requested change. | 122 // requested change. |
| 125 class RemoteAudioTrackHandler : public AudioSourceInterface::AudioObserver, | 123 class RemoteAudioTrackHandler : public AudioSourceInterface::AudioObserver, |
| 126 public TrackHandler { | 124 public TrackHandler { |
| 127 public: | 125 public: |
| 128 RemoteAudioTrackHandler(AudioTrackInterface* track, | 126 RemoteAudioTrackHandler(AudioTrackInterface* track, |
| 129 uint32 ssrc, | 127 uint32 ssrc, |
| 130 AudioProviderInterface* provider); | 128 AudioProviderInterface* provider); |
| 131 virtual ~RemoteAudioTrackHandler(); | 129 virtual ~RemoteAudioTrackHandler(); |
| 132 void Start() override; | |
| 133 void Stop() override; | 130 void Stop() override; |
| 134 | 131 |
| 135 protected: | 132 protected: |
| 136 void OnStateChanged() override; | 133 void OnStateChanged() override; |
| 137 void OnEnabledChanged() override; | 134 void OnEnabledChanged() override; |
| 138 | 135 |
| 139 private: | 136 private: |
| 140 // AudioSourceInterface::AudioObserver implementation. | 137 // AudioSourceInterface::AudioObserver implementation. |
| 141 void OnSetVolume(double volume) override; | 138 void OnSetVolume(double volume) override; |
| 142 | 139 |
| 143 AudioTrackInterface* audio_track_; | 140 AudioTrackInterface* audio_track_; |
| 144 AudioProviderInterface* provider_; | 141 AudioProviderInterface* provider_; |
| 145 }; | 142 }; |
| 146 | 143 |
| 147 // LocalVideoTrackHandler listen to events on a local VideoTrack instance | 144 // LocalVideoTrackHandler listen to events on a local VideoTrack instance |
| 148 // connected to a PeerConnection and orders the |provider| to executes the | 145 // connected to a PeerConnection and orders the |provider| to executes the |
| 149 // requested change. | 146 // requested change. |
| 150 class LocalVideoTrackHandler : public TrackHandler { | 147 class LocalVideoTrackHandler : public TrackHandler { |
| 151 public: | 148 public: |
| 152 LocalVideoTrackHandler(VideoTrackInterface* track, | 149 LocalVideoTrackHandler(VideoTrackInterface* track, |
| 153 uint32 ssrc, | 150 uint32 ssrc, |
| 154 VideoProviderInterface* provider); | 151 VideoProviderInterface* provider); |
| 155 virtual ~LocalVideoTrackHandler(); | 152 virtual ~LocalVideoTrackHandler(); |
| 156 void Start() override; | |
| 157 void Stop() override; | 153 void Stop() override; |
| 158 | 154 |
| 159 protected: | 155 protected: |
| 160 void OnStateChanged() override; | 156 void OnStateChanged() override; |
| 161 void OnEnabledChanged() override; | 157 void OnEnabledChanged() override; |
| 162 | 158 |
| 163 private: | 159 private: |
| 164 VideoTrackInterface* local_video_track_; | 160 VideoTrackInterface* local_video_track_; |
| 165 VideoProviderInterface* provider_; | 161 VideoProviderInterface* provider_; |
| 166 }; | 162 }; |
| 167 | 163 |
| 168 // RemoteVideoTrackHandler listen to events on a remote VideoTrack instance | 164 // RemoteVideoTrackHandler listen to events on a remote VideoTrack instance |
| 169 // connected to a PeerConnection and orders the |provider| to execute | 165 // connected to a PeerConnection and orders the |provider| to execute |
| 170 // requested changes. | 166 // requested changes. |
| 171 class RemoteVideoTrackHandler : public TrackHandler { | 167 class RemoteVideoTrackHandler : public TrackHandler { |
| 172 public: | 168 public: |
| 173 RemoteVideoTrackHandler(VideoTrackInterface* track, | 169 RemoteVideoTrackHandler(VideoTrackInterface* track, |
| 174 uint32 ssrc, | 170 uint32 ssrc, |
| 175 VideoProviderInterface* provider); | 171 VideoProviderInterface* provider); |
| 176 virtual ~RemoteVideoTrackHandler(); | 172 virtual ~RemoteVideoTrackHandler(); |
| 177 void Start() override; | |
| 178 void Stop() override; | 173 void Stop() override; |
| 179 | 174 |
| 180 protected: | 175 protected: |
| 181 void OnStateChanged() override; | 176 void OnStateChanged() override; |
| 182 void OnEnabledChanged() override; | 177 void OnEnabledChanged() override; |
| 183 | 178 |
| 184 private: | 179 private: |
| 185 VideoTrackInterface* remote_video_track_; | 180 VideoTrackInterface* remote_video_track_; |
| 186 VideoProviderInterface* provider_; | 181 VideoProviderInterface* provider_; |
| 187 }; | 182 }; |
| 188 | 183 |
| 189 class MediaStreamHandler : public ObserverInterface { | 184 class MediaStreamHandler : public ObserverInterface { |
| 190 public: | 185 public: |
| 191 MediaStreamHandler(MediaStreamInterface* stream, | 186 MediaStreamHandler(MediaStreamInterface* stream, |
| 192 AudioProviderInterface* audio_provider, | 187 AudioProviderInterface* audio_provider, |
| 193 VideoProviderInterface* video_provider); | 188 VideoProviderInterface* video_provider); |
| 194 ~MediaStreamHandler(); | 189 ~MediaStreamHandler(); |
| 195 MediaStreamInterface* stream(); | 190 MediaStreamInterface* stream(); |
| 196 void Stop(); | 191 void Stop(); |
| 197 | 192 |
| 198 virtual void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) = 0; | 193 virtual void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) = 0; |
| 199 virtual void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) = 0; | 194 virtual void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) = 0; |
| 200 virtual void RestartAllTracks() = 0; | |
| 201 | 195 |
| 202 virtual void RemoveTrack(MediaStreamTrackInterface* track); | 196 virtual void RemoveTrack(MediaStreamTrackInterface* track); |
| 203 void OnChanged() override; | 197 void OnChanged() override; |
| 204 | 198 |
| 205 protected: | 199 protected: |
| 206 TrackHandler* FindTrackHandler(MediaStreamTrackInterface* track); | 200 TrackHandler* FindTrackHandler(MediaStreamTrackInterface* track); |
| 207 rtc::scoped_refptr<MediaStreamInterface> stream_; | 201 rtc::scoped_refptr<MediaStreamInterface> stream_; |
| 208 AudioProviderInterface* audio_provider_; | 202 AudioProviderInterface* audio_provider_; |
| 209 VideoProviderInterface* video_provider_; | 203 VideoProviderInterface* video_provider_; |
| 210 typedef std::vector<TrackHandler*> TrackHandlers; | 204 typedef std::vector<TrackHandler*> TrackHandlers; |
| 211 TrackHandlers track_handlers_; | 205 TrackHandlers track_handlers_; |
| 212 }; | 206 }; |
| 213 | 207 |
| 214 class LocalMediaStreamHandler : public MediaStreamHandler { | 208 class LocalMediaStreamHandler : public MediaStreamHandler { |
| 215 public: | 209 public: |
| 216 LocalMediaStreamHandler(MediaStreamInterface* stream, | 210 LocalMediaStreamHandler(MediaStreamInterface* stream, |
| 217 AudioProviderInterface* audio_provider, | 211 AudioProviderInterface* audio_provider, |
| 218 VideoProviderInterface* video_provider); | 212 VideoProviderInterface* video_provider); |
| 219 ~LocalMediaStreamHandler(); | 213 ~LocalMediaStreamHandler(); |
| 220 | 214 |
| 221 void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) override; | 215 void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) override; |
| 222 void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) override; | 216 void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) override; |
| 223 void RestartAllTracks() override; | |
| 224 }; | 217 }; |
| 225 | 218 |
| 226 class RemoteMediaStreamHandler : public MediaStreamHandler { | 219 class RemoteMediaStreamHandler : public MediaStreamHandler { |
| 227 public: | 220 public: |
| 228 RemoteMediaStreamHandler(MediaStreamInterface* stream, | 221 RemoteMediaStreamHandler(MediaStreamInterface* stream, |
| 229 AudioProviderInterface* audio_provider, | 222 AudioProviderInterface* audio_provider, |
| 230 VideoProviderInterface* video_provider); | 223 VideoProviderInterface* video_provider); |
| 231 ~RemoteMediaStreamHandler(); | 224 ~RemoteMediaStreamHandler(); |
| 232 void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) override; | 225 void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) override; |
| 233 void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) override; | 226 void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) override; |
| 234 void RestartAllTracks() override; | |
| 235 }; | 227 }; |
| 236 | 228 |
| 237 // Container for MediaStreamHandlers of currently known local and remote | 229 // Container for MediaStreamHandlers of currently known local and remote |
| 238 // MediaStreams. | 230 // MediaStreams. |
| 239 class MediaStreamHandlerContainer { | 231 class MediaStreamHandlerContainer { |
| 240 public: | 232 public: |
| 241 MediaStreamHandlerContainer(AudioProviderInterface* audio_provider, | 233 MediaStreamHandlerContainer(AudioProviderInterface* audio_provider, |
| 242 VideoProviderInterface* video_provider); | 234 VideoProviderInterface* video_provider); |
| 243 ~MediaStreamHandlerContainer(); | 235 ~MediaStreamHandlerContainer(); |
| 244 | 236 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 257 AudioTrackInterface* audio_track, | 249 AudioTrackInterface* audio_track, |
| 258 uint32 ssrc); | 250 uint32 ssrc); |
| 259 // Create a RemoteVideoTrackHandler and associate |video_track| with |ssrc|. | 251 // Create a RemoteVideoTrackHandler and associate |video_track| with |ssrc|. |
| 260 void AddRemoteVideoTrack(MediaStreamInterface* stream, | 252 void AddRemoteVideoTrack(MediaStreamInterface* stream, |
| 261 VideoTrackInterface* video_track, | 253 VideoTrackInterface* video_track, |
| 262 uint32 ssrc); | 254 uint32 ssrc); |
| 263 // Remove the TrackHandler for |track|. | 255 // Remove the TrackHandler for |track|. |
| 264 void RemoveRemoteTrack(MediaStreamInterface* stream, | 256 void RemoveRemoteTrack(MediaStreamInterface* stream, |
| 265 MediaStreamTrackInterface* track); | 257 MediaStreamTrackInterface* track); |
| 266 | 258 |
| 267 // Make all remote track handlers reassociate their corresponding tracks | |
| 268 // with their corresponding SSRCs. | |
| 269 void RestartAllRemoteTracks(); | |
| 270 | |
| 271 // Remove all TrackHandlers for tracks in |stream| and make sure | 259 // Remove all TrackHandlers for tracks in |stream| and make sure |
| 272 // the audio_provider and video_provider is notified that the tracks has been | 260 // the audio_provider and video_provider is notified that the tracks has been |
| 273 // removed. | 261 // removed. |
| 274 void RemoveLocalStream(MediaStreamInterface* stream); | 262 void RemoveLocalStream(MediaStreamInterface* stream); |
| 275 | 263 |
| 276 // Create a LocalAudioTrackHandler and associate |audio_track| with |ssrc|. | 264 // Create a LocalAudioTrackHandler and associate |audio_track| with |ssrc|. |
| 277 void AddLocalAudioTrack(MediaStreamInterface* stream, | 265 void AddLocalAudioTrack(MediaStreamInterface* stream, |
| 278 AudioTrackInterface* audio_track, | 266 AudioTrackInterface* audio_track, |
| 279 uint32 ssrc); | 267 uint32 ssrc); |
| 280 // Create a LocalVideoTrackHandler and associate |video_track| with |ssrc|. | 268 // Create a LocalVideoTrackHandler and associate |video_track| with |ssrc|. |
| 281 void AddLocalVideoTrack(MediaStreamInterface* stream, | 269 void AddLocalVideoTrack(MediaStreamInterface* stream, |
| 282 VideoTrackInterface* video_track, | 270 VideoTrackInterface* video_track, |
| 283 uint32 ssrc); | 271 uint32 ssrc); |
| 284 // Remove the TrackHandler for |track|. | 272 // Remove the TrackHandler for |track|. |
| 285 void RemoveLocalTrack(MediaStreamInterface* stream, | 273 void RemoveLocalTrack(MediaStreamInterface* stream, |
| 286 MediaStreamTrackInterface* track); | 274 MediaStreamTrackInterface* track); |
| 287 | 275 |
| 288 // Make all local track handlers reassociate their corresponding tracks | |
| 289 // with their corresponding SSRCs. | |
| 290 void RestartAllLocalTracks(); | |
| 291 | |
| 292 private: | 276 private: |
| 293 typedef std::list<MediaStreamHandler*> StreamHandlerList; | 277 typedef std::list<MediaStreamHandler*> StreamHandlerList; |
| 294 MediaStreamHandler* FindStreamHandler(const StreamHandlerList& handlers, | 278 MediaStreamHandler* FindStreamHandler(const StreamHandlerList& handlers, |
| 295 MediaStreamInterface* stream); | 279 MediaStreamInterface* stream); |
| 296 MediaStreamHandler* CreateRemoteStreamHandler(MediaStreamInterface* stream); | 280 MediaStreamHandler* CreateRemoteStreamHandler(MediaStreamInterface* stream); |
| 297 MediaStreamHandler* CreateLocalStreamHandler(MediaStreamInterface* stream); | 281 MediaStreamHandler* CreateLocalStreamHandler(MediaStreamInterface* stream); |
| 298 void DeleteStreamHandler(StreamHandlerList* streamhandlers, | 282 void DeleteStreamHandler(StreamHandlerList* streamhandlers, |
| 299 MediaStreamInterface* stream); | 283 MediaStreamInterface* stream); |
| 300 | 284 |
| 301 StreamHandlerList local_streams_handlers_; | 285 StreamHandlerList local_streams_handlers_; |
| 302 StreamHandlerList remote_streams_handlers_; | 286 StreamHandlerList remote_streams_handlers_; |
| 303 AudioProviderInterface* audio_provider_; | 287 AudioProviderInterface* audio_provider_; |
| 304 VideoProviderInterface* video_provider_; | 288 VideoProviderInterface* video_provider_; |
| 305 }; | 289 }; |
| 306 | 290 |
| 307 } // namespace webrtc | 291 } // namespace webrtc |
| 308 | 292 |
| 309 #endif // TALK_APP_WEBRTC_MEDIASTREAMHANDLER_H_ | 293 #endif // TALK_APP_WEBRTC_MEDIASTREAMHANDLER_H_ |
| OLD | NEW |