| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 if (track && track->kind() != MediaStreamTrackInterface::kVideoKind) { | 266 if (track && track->kind() != MediaStreamTrackInterface::kVideoKind) { |
| 267 LOG(LS_ERROR) << "SetTrack called on video RtpSender with " << track->kind() | 267 LOG(LS_ERROR) << "SetTrack called on video RtpSender with " << track->kind() |
| 268 << " track."; | 268 << " track."; |
| 269 return false; | 269 return false; |
| 270 } | 270 } |
| 271 VideoTrackInterface* video_track = static_cast<VideoTrackInterface*>(track); | 271 VideoTrackInterface* video_track = static_cast<VideoTrackInterface*>(track); |
| 272 | 272 |
| 273 // Detach from old track. | 273 // Detach from old track. |
| 274 if (track_) { | 274 if (track_) { |
| 275 track_->UnregisterObserver(this); | 275 track_->UnregisterObserver(this); |
| 276 track_->RemoveSink(sink_); |
| 277 sink_ = nullptr; |
| 276 } | 278 } |
| 277 | 279 |
| 278 // Attach to new track. | 280 // Attach to new track. |
| 279 bool prev_can_send_track = can_send_track(); | 281 bool prev_can_send_track = can_send_track(); |
| 280 track_ = video_track; | 282 track_ = video_track; |
| 281 if (track_) { | 283 if (track_) { |
| 282 cached_track_enabled_ = track_->enabled(); | 284 cached_track_enabled_ = track_->enabled(); |
| 283 track_->RegisterObserver(this); | 285 track_->RegisterObserver(this); |
| 284 } | 286 } |
| 285 | 287 |
| 286 // Update video provider. | 288 // Update video provider. |
| 287 if (can_send_track()) { | 289 if (can_send_track()) { |
| 288 VideoSourceInterface* source = track_->GetSource(); | 290 VideoSourceInterface* source = track_->GetSource(); |
| 291 sink_ = provider_->GetSink(ssrc_); |
| 292 RTC_CHECK(sink_); |
| 289 // TODO(deadbeef): If SetTrack is called with a disabled track, and the | 293 // TODO(deadbeef): If SetTrack is called with a disabled track, and the |
| 290 // previous track was enabled, this could cause a frame from the new track | 294 // previous track was enabled, this could cause a frame from the new track |
| 291 // to slip out. Really, what we need is for SetCaptureDevice and | 295 // to slip out. Really, what we need is for SetCaptureDevice and |
| 292 // SetVideoSend | 296 // SetVideoSend |
| 293 // to be combined into one atomic operation, all the way down to | 297 // to be combined into one atomic operation, all the way down to |
| 294 // WebRtcVideoSendStream. | 298 // WebRtcVideoSendStream. |
| 295 provider_->SetCaptureDevice(ssrc_, | 299 provider_->SetCaptureDevice(ssrc_, |
| 296 source ? source->GetVideoCapturer() : nullptr); | 300 source ? source->GetVideoCapturer() : nullptr); |
| 297 SetVideoSend(); | 301 SetVideoSend(); |
| 302 track_->AddSink(sink_); |
| 298 } else if (prev_can_send_track) { | 303 } else if (prev_can_send_track) { |
| 299 provider_->SetCaptureDevice(ssrc_, nullptr); | 304 provider_->SetCaptureDevice(ssrc_, nullptr); |
| 300 provider_->SetVideoSend(ssrc_, false, nullptr); | 305 provider_->SetVideoSend(ssrc_, false, nullptr); |
| 301 } | 306 } |
| 302 return true; | 307 return true; |
| 303 } | 308 } |
| 304 | 309 |
| 305 void VideoRtpSender::SetSsrc(uint32_t ssrc) { | 310 void VideoRtpSender::SetSsrc(uint32_t ssrc) { |
| 306 if (stopped_ || ssrc == ssrc_) { | 311 if (stopped_ || ssrc == ssrc_) { |
| 307 return; | 312 return; |
| 308 } | 313 } |
| 309 // If we are already sending with a particular SSRC, stop sending. | 314 // If we are already sending with a particular SSRC, stop sending. |
| 310 if (can_send_track()) { | 315 if (can_send_track()) { |
| 311 provider_->SetCaptureDevice(ssrc_, nullptr); | 316 provider_->SetCaptureDevice(ssrc_, nullptr); |
| 312 provider_->SetVideoSend(ssrc_, false, nullptr); | 317 provider_->SetVideoSend(ssrc_, false, nullptr); |
| 318 track_->RemoveSink(sink_); |
| 319 sink_ = nullptr; |
| 313 } | 320 } |
| 314 ssrc_ = ssrc; | 321 ssrc_ = ssrc; |
| 315 if (can_send_track()) { | 322 if (can_send_track()) { |
| 316 VideoSourceInterface* source = track_->GetSource(); | 323 VideoSourceInterface* source = track_->GetSource(); |
| 317 provider_->SetCaptureDevice(ssrc_, | 324 provider_->SetCaptureDevice(ssrc_, |
| 318 source ? source->GetVideoCapturer() : nullptr); | 325 source ? source->GetVideoCapturer() : nullptr); |
| 319 SetVideoSend(); | 326 SetVideoSend(); |
| 327 sink_ = provider_->GetSink(ssrc_); |
| 328 track_->AddSink(sink_); |
| 320 } | 329 } |
| 321 } | 330 } |
| 322 | 331 |
| 323 void VideoRtpSender::Stop() { | 332 void VideoRtpSender::Stop() { |
| 324 // TODO(deadbeef): Need to do more here to fully stop sending packets. | 333 // TODO(deadbeef): Need to do more here to fully stop sending packets. |
| 325 if (stopped_) { | 334 if (stopped_) { |
| 326 return; | 335 return; |
| 327 } | 336 } |
| 328 if (track_) { | 337 if (track_) { |
| 329 track_->UnregisterObserver(this); | 338 track_->UnregisterObserver(this); |
| 339 RTC_DCHECK(sink_); |
| 340 RTC_DCHECK(sink_ == provider_->GetSink(ssrc_)); |
| 341 track_->RemoveSink(sink_); |
| 330 } | 342 } |
| 331 if (can_send_track()) { | 343 if (can_send_track()) { |
| 332 provider_->SetCaptureDevice(ssrc_, nullptr); | 344 provider_->SetCaptureDevice(ssrc_, nullptr); |
| 333 provider_->SetVideoSend(ssrc_, false, nullptr); | 345 provider_->SetVideoSend(ssrc_, false, nullptr); |
| 334 } | 346 } |
| 335 stopped_ = true; | 347 stopped_ = true; |
| 336 } | 348 } |
| 337 | 349 |
| 338 void VideoRtpSender::SetVideoSend() { | 350 void VideoRtpSender::SetVideoSend() { |
| 339 RTC_DCHECK(!stopped_ && can_send_track()); | 351 RTC_DCHECK(!stopped_ && can_send_track()); |
| 340 const cricket::VideoOptions* options = nullptr; | 352 const cricket::VideoOptions* options = nullptr; |
| 341 VideoSourceInterface* source = track_->GetSource(); | 353 VideoSourceInterface* source = track_->GetSource(); |
| 342 if (track_->enabled() && source) { | 354 if (track_->enabled() && source) { |
| 343 options = source->options(); | 355 options = source->options(); |
| 344 } | 356 } |
| 345 provider_->SetVideoSend(ssrc_, track_->enabled(), options); | 357 provider_->SetVideoSend(ssrc_, track_->enabled(), options); |
| 346 } | 358 } |
| 347 | 359 |
| 348 } // namespace webrtc | 360 } // namespace webrtc |
| OLD | NEW |