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