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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 518 } |
519 MaybeCreateDefaultStream(); | 519 MaybeCreateDefaultStream(); |
520 } | 520 } |
521 | 521 |
522 void MediaStreamSignaling::OnLocalDescriptionChanged( | 522 void MediaStreamSignaling::OnLocalDescriptionChanged( |
523 const SessionDescriptionInterface* desc) { | 523 const SessionDescriptionInterface* desc) { |
524 const cricket::ContentInfo* audio_content = | 524 const cricket::ContentInfo* audio_content = |
525 GetFirstAudioContent(desc->description()); | 525 GetFirstAudioContent(desc->description()); |
526 if (audio_content) { | 526 if (audio_content) { |
527 if (audio_content->rejected) { | 527 if (audio_content->rejected) { |
528 RejectRemoteTracks(cricket::MEDIA_TYPE_AUDIO); | 528 SetRemoteTracksState(cricket::MEDIA_TYPE_AUDIO, |
| 529 MediaStreamTrackInterface::kEnded); |
| 530 } else { |
| 531 // This is needed in case the local description caused the track to be |
| 532 // rejected, then later accepted, without being destroyed. |
| 533 SetRemoteTracksState(cricket::MEDIA_TYPE_AUDIO, |
| 534 MediaStreamTrackInterface::kLive); |
529 } | 535 } |
530 const cricket::AudioContentDescription* audio_desc = | 536 const cricket::AudioContentDescription* audio_desc = |
531 static_cast<const cricket::AudioContentDescription*>( | 537 static_cast<const cricket::AudioContentDescription*>( |
532 audio_content->description); | 538 audio_content->description); |
533 UpdateLocalTracks(audio_desc->streams(), audio_desc->type()); | 539 UpdateLocalTracks(audio_desc->streams(), audio_desc->type()); |
534 } | 540 } |
535 | 541 |
536 const cricket::ContentInfo* video_content = | 542 const cricket::ContentInfo* video_content = |
537 GetFirstVideoContent(desc->description()); | 543 GetFirstVideoContent(desc->description()); |
538 if (video_content) { | 544 if (video_content) { |
539 if (video_content->rejected) { | 545 if (video_content->rejected) { |
540 RejectRemoteTracks(cricket::MEDIA_TYPE_VIDEO); | 546 SetRemoteTracksState(cricket::MEDIA_TYPE_VIDEO, |
| 547 MediaStreamTrackInterface::kEnded); |
| 548 } else { |
| 549 // This is needed in case the local description caused the track to be |
| 550 // rejected, then later accepted, without being destroyed. |
| 551 SetRemoteTracksState(cricket::MEDIA_TYPE_VIDEO, |
| 552 MediaStreamTrackInterface::kLive); |
541 } | 553 } |
542 const cricket::VideoContentDescription* video_desc = | 554 const cricket::VideoContentDescription* video_desc = |
543 static_cast<const cricket::VideoContentDescription*>( | 555 static_cast<const cricket::VideoContentDescription*>( |
544 video_content->description); | 556 video_content->description); |
545 UpdateLocalTracks(video_desc->streams(), video_desc->type()); | 557 UpdateLocalTracks(video_desc->streams(), video_desc->type()); |
546 } | 558 } |
547 | 559 |
548 const cricket::ContentInfo* data_content = | 560 const cricket::ContentInfo* data_content = |
549 GetFirstDataContent(desc->description()); | 561 GetFirstDataContent(desc->description()); |
550 if (data_content) { | 562 if (data_content) { |
551 const cricket::DataContentDescription* data_desc = | 563 const cricket::DataContentDescription* data_desc = |
552 static_cast<const cricket::DataContentDescription*>( | 564 static_cast<const cricket::DataContentDescription*>( |
553 data_content->description); | 565 data_content->description); |
554 if (rtc::starts_with( | 566 if (rtc::starts_with( |
555 data_desc->protocol().data(), cricket::kMediaProtocolRtpPrefix)) { | 567 data_desc->protocol().data(), cricket::kMediaProtocolRtpPrefix)) { |
556 UpdateLocalRtpDataChannels(data_desc->streams()); | 568 UpdateLocalRtpDataChannels(data_desc->streams()); |
557 } | 569 } |
558 } | 570 } |
559 } | 571 } |
560 | 572 |
561 void MediaStreamSignaling::OnAudioChannelClose() { | 573 void MediaStreamSignaling::OnAudioChannelClose() { |
562 RejectRemoteTracks(cricket::MEDIA_TYPE_AUDIO); | 574 SetRemoteTracksState(cricket::MEDIA_TYPE_AUDIO, |
| 575 MediaStreamTrackInterface::kEnded); |
563 } | 576 } |
564 | 577 |
565 void MediaStreamSignaling::OnVideoChannelClose() { | 578 void MediaStreamSignaling::OnVideoChannelClose() { |
566 RejectRemoteTracks(cricket::MEDIA_TYPE_VIDEO); | 579 SetRemoteTracksState(cricket::MEDIA_TYPE_VIDEO, |
| 580 MediaStreamTrackInterface::kEnded); |
567 } | 581 } |
568 | 582 |
569 void MediaStreamSignaling::OnDataChannelClose() { | 583 void MediaStreamSignaling::OnDataChannelClose() { |
570 // Use a temporary copy of the RTP/SCTP DataChannel list because the | 584 // Use a temporary copy of the RTP/SCTP DataChannel list because the |
571 // DataChannel may callback to us and try to modify the list. | 585 // DataChannel may callback to us and try to modify the list. |
572 RtpDataChannels temp_rtp_dcs; | 586 RtpDataChannels temp_rtp_dcs; |
573 temp_rtp_dcs.swap(rtp_data_channels_); | 587 temp_rtp_dcs.swap(rtp_data_channels_); |
574 RtpDataChannels::iterator it1 = temp_rtp_dcs.begin(); | 588 RtpDataChannels::iterator it1 = temp_rtp_dcs.begin(); |
575 for (; it1 != temp_rtp_dcs.end(); ++it1) { | 589 for (; it1 != temp_rtp_dcs.end(); ++it1) { |
576 it1->second->OnDataEngineClose(); | 590 it1->second->OnDataEngineClose(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 if (video_track) { | 685 if (video_track) { |
672 video_track->set_state(webrtc::MediaStreamTrackInterface::kEnded); | 686 video_track->set_state(webrtc::MediaStreamTrackInterface::kEnded); |
673 stream->RemoveTrack(video_track); | 687 stream->RemoveTrack(video_track); |
674 stream_observer_->OnRemoveRemoteVideoTrack(stream, video_track); | 688 stream_observer_->OnRemoveRemoteVideoTrack(stream, video_track); |
675 } | 689 } |
676 } else { | 690 } else { |
677 ASSERT(false && "Invalid media type"); | 691 ASSERT(false && "Invalid media type"); |
678 } | 692 } |
679 } | 693 } |
680 | 694 |
681 void MediaStreamSignaling::RejectRemoteTracks(cricket::MediaType media_type) { | 695 void MediaStreamSignaling::SetRemoteTracksState( |
| 696 cricket::MediaType media_type, |
| 697 MediaStreamTrackInterface::TrackState state) { |
682 TrackInfos* current_tracks = GetRemoteTracks(media_type); | 698 TrackInfos* current_tracks = GetRemoteTracks(media_type); |
683 for (TrackInfos::iterator track_it = current_tracks->begin(); | 699 for (TrackInfos::iterator track_it = current_tracks->begin(); |
684 track_it != current_tracks->end(); ++track_it) { | 700 track_it != current_tracks->end(); ++track_it) { |
685 const TrackInfo& info = *track_it; | 701 const TrackInfo& info = *track_it; |
686 MediaStreamInterface* stream = remote_streams_->find(info.stream_label); | 702 MediaStreamInterface* stream = remote_streams_->find(info.stream_label); |
687 if (media_type == cricket::MEDIA_TYPE_AUDIO) { | 703 if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
688 AudioTrackInterface* track = stream->FindAudioTrack(info.track_id); | 704 AudioTrackInterface* track = stream->FindAudioTrack(info.track_id); |
689 // There's no guarantee the track is still available, e.g. the track may | 705 // There's no guarantee the track is still available, e.g. the track may |
690 // have been removed from the stream by javascript. | 706 // have been removed from the stream by javascript. |
691 if (track) { | 707 if (track) { |
692 track->set_state(webrtc::MediaStreamTrackInterface::kEnded); | 708 track->set_state(state); |
693 } | 709 } |
694 } | 710 } |
695 if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 711 if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
696 VideoTrackInterface* track = stream->FindVideoTrack(info.track_id); | 712 VideoTrackInterface* track = stream->FindVideoTrack(info.track_id); |
697 // There's no guarantee the track is still available, e.g. the track may | 713 // There's no guarantee the track is still available, e.g. the track may |
698 // have been removed from the stream by javascript. | 714 // have been removed from the stream by javascript. |
699 if (track) { | 715 if (track) { |
700 track->set_state(webrtc::MediaStreamTrackInterface::kEnded); | 716 track->set_state(state); |
701 } | 717 } |
702 } | 718 } |
703 } | 719 } |
704 } | 720 } |
705 | 721 |
706 void MediaStreamSignaling::UpdateEndedRemoteMediaStreams() { | 722 void MediaStreamSignaling::UpdateEndedRemoteMediaStreams() { |
707 std::vector<scoped_refptr<MediaStreamInterface> > streams_to_remove; | 723 std::vector<scoped_refptr<MediaStreamInterface> > streams_to_remove; |
708 for (size_t i = 0; i < remote_streams_->count(); ++i) { | 724 for (size_t i = 0; i < remote_streams_->count(); ++i) { |
709 MediaStreamInterface*stream = remote_streams_->at(i); | 725 MediaStreamInterface*stream = remote_streams_->at(i); |
710 if (stream->GetAudioTracks().empty() && stream->GetVideoTracks().empty()) { | 726 if (stream->GetAudioTracks().empty() && stream->GetVideoTracks().empty()) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 int MediaStreamSignaling::FindDataChannelBySid(int sid) const { | 1037 int MediaStreamSignaling::FindDataChannelBySid(int sid) const { |
1022 for (size_t i = 0; i < sctp_data_channels_.size(); ++i) { | 1038 for (size_t i = 0; i < sctp_data_channels_.size(); ++i) { |
1023 if (sctp_data_channels_[i]->id() == sid) { | 1039 if (sctp_data_channels_[i]->id() == sid) { |
1024 return static_cast<int>(i); | 1040 return static_cast<int>(i); |
1025 } | 1041 } |
1026 } | 1042 } |
1027 return -1; | 1043 return -1; |
1028 } | 1044 } |
1029 | 1045 |
1030 } // namespace webrtc | 1046 } // namespace webrtc |
OLD | NEW |