Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: webrtc/api/peerconnection.cc

Issue 1972793003: Use scoped_refptr for On(Add|Remove)Stream and OnDataChannel. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding "deprecated" comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 if (rtc::starts_with(data_desc->protocol().data(), 1142 if (rtc::starts_with(data_desc->protocol().data(),
1143 cricket::kMediaProtocolRtpPrefix)) { 1143 cricket::kMediaProtocolRtpPrefix)) {
1144 UpdateRemoteRtpDataChannels(GetActiveStreams(data_desc)); 1144 UpdateRemoteRtpDataChannels(GetActiveStreams(data_desc));
1145 } 1145 }
1146 } 1146 }
1147 1147
1148 // Iterate new_streams and notify the observer about new MediaStreams. 1148 // Iterate new_streams and notify the observer about new MediaStreams.
1149 for (size_t i = 0; i < new_streams->count(); ++i) { 1149 for (size_t i = 0; i < new_streams->count(); ++i) {
1150 MediaStreamInterface* new_stream = new_streams->at(i); 1150 MediaStreamInterface* new_stream = new_streams->at(i);
1151 stats_->AddStream(new_stream); 1151 stats_->AddStream(new_stream);
1152 // Call both the raw pointer and scoped_refptr versions of the method
1153 // for compatibility.
1152 observer_->OnAddStream(new_stream); 1154 observer_->OnAddStream(new_stream);
1155 observer_->OnAddStream(
1156 rtc::scoped_refptr<MediaStreamInterface>(new_stream));
1153 } 1157 }
1154 1158
1155 UpdateEndedRemoteMediaStreams(); 1159 UpdateEndedRemoteMediaStreams();
1156 1160
1157 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer); 1161 SetSessionDescriptionMsg* msg = new SetSessionDescriptionMsg(observer);
1158 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg); 1162 signaling_thread()->Post(this, MSG_SET_SESSIONDESCRIPTION_SUCCESS, msg);
1159 } 1163 }
1160 1164
1161 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) { 1165 bool PeerConnection::SetConfiguration(const RTCConfiguration& config) {
1162 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration"); 1166 TRACE_EVENT0("webrtc", "PeerConnection::SetConfiguration");
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 1708
1705 void PeerConnection::UpdateEndedRemoteMediaStreams() { 1709 void PeerConnection::UpdateEndedRemoteMediaStreams() {
1706 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_to_remove; 1710 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_to_remove;
1707 for (size_t i = 0; i < remote_streams_->count(); ++i) { 1711 for (size_t i = 0; i < remote_streams_->count(); ++i) {
1708 MediaStreamInterface* stream = remote_streams_->at(i); 1712 MediaStreamInterface* stream = remote_streams_->at(i);
1709 if (stream->GetAudioTracks().empty() && stream->GetVideoTracks().empty()) { 1713 if (stream->GetAudioTracks().empty() && stream->GetVideoTracks().empty()) {
1710 streams_to_remove.push_back(stream); 1714 streams_to_remove.push_back(stream);
1711 } 1715 }
1712 } 1716 }
1713 1717
1714 for (const auto& stream : streams_to_remove) { 1718 for (auto& stream : streams_to_remove) {
1715 remote_streams_->RemoveStream(stream); 1719 remote_streams_->RemoveStream(stream);
1716 observer_->OnRemoveStream(stream); 1720 // Call both the raw pointer and scoped_refptr versions of the method
1721 // for compatibility.
1722 observer_->OnRemoveStream(stream.get());
1723 observer_->OnRemoveStream(std::move(stream));
1717 } 1724 }
1718 } 1725 }
1719 1726
1720 void PeerConnection::UpdateLocalTracks( 1727 void PeerConnection::UpdateLocalTracks(
1721 const std::vector<cricket::StreamParams>& streams, 1728 const std::vector<cricket::StreamParams>& streams,
1722 cricket::MediaType media_type) { 1729 cricket::MediaType media_type) {
1723 TrackInfos* current_tracks = GetLocalTracks(media_type); 1730 TrackInfos* current_tracks = GetLocalTracks(media_type);
1724 1731
1725 // Find removed tracks. I.e., tracks where the track id, stream label or ssrc 1732 // Find removed tracks. I.e., tracks where the track id, stream label or ssrc
1726 // don't match the new StreamParam. 1733 // don't match the new StreamParam.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 void PeerConnection::CreateRemoteRtpDataChannel(const std::string& label, 1884 void PeerConnection::CreateRemoteRtpDataChannel(const std::string& label,
1878 uint32_t remote_ssrc) { 1885 uint32_t remote_ssrc) {
1879 rtc::scoped_refptr<DataChannel> channel( 1886 rtc::scoped_refptr<DataChannel> channel(
1880 InternalCreateDataChannel(label, nullptr)); 1887 InternalCreateDataChannel(label, nullptr));
1881 if (!channel.get()) { 1888 if (!channel.get()) {
1882 LOG(LS_WARNING) << "Remote peer requested a DataChannel but" 1889 LOG(LS_WARNING) << "Remote peer requested a DataChannel but"
1883 << "CreateDataChannel failed."; 1890 << "CreateDataChannel failed.";
1884 return; 1891 return;
1885 } 1892 }
1886 channel->SetReceiveSsrc(remote_ssrc); 1893 channel->SetReceiveSsrc(remote_ssrc);
1887 observer_->OnDataChannel( 1894 auto proxy_channel = DataChannelProxy::Create(signaling_thread(), channel);
1888 DataChannelProxy::Create(signaling_thread(), channel)); 1895 // Call both the raw pointer and scoped_refptr versions of the method
1896 // for compatibility.
1897 observer_->OnDataChannel(proxy_channel.get());
1898 observer_->OnDataChannel(std::move(proxy_channel));
1889 } 1899 }
1890 1900
1891 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel( 1901 rtc::scoped_refptr<DataChannel> PeerConnection::InternalCreateDataChannel(
1892 const std::string& label, 1902 const std::string& label,
1893 const InternalDataChannelInit* config) { 1903 const InternalDataChannelInit* config) {
1894 if (IsClosed()) { 1904 if (IsClosed()) {
1895 return nullptr; 1905 return nullptr;
1896 } 1906 }
1897 if (session_->data_channel_type() == cricket::DCT_NONE) { 1907 if (session_->data_channel_type() == cricket::DCT_NONE) {
1898 LOG(LS_ERROR) 1908 LOG(LS_ERROR)
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 void PeerConnection::OnDataChannelOpenMessage( 2018 void PeerConnection::OnDataChannelOpenMessage(
2009 const std::string& label, 2019 const std::string& label,
2010 const InternalDataChannelInit& config) { 2020 const InternalDataChannelInit& config) {
2011 rtc::scoped_refptr<DataChannel> channel( 2021 rtc::scoped_refptr<DataChannel> channel(
2012 InternalCreateDataChannel(label, &config)); 2022 InternalCreateDataChannel(label, &config));
2013 if (!channel.get()) { 2023 if (!channel.get()) {
2014 LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message."; 2024 LOG(LS_ERROR) << "Failed to create DataChannel from the OPEN message.";
2015 return; 2025 return;
2016 } 2026 }
2017 2027
2018 observer_->OnDataChannel( 2028 auto proxy_channel = DataChannelProxy::Create(signaling_thread(), channel);
2019 DataChannelProxy::Create(signaling_thread(), channel)); 2029 // Call both the raw pointer and scoped_refptr versions of the method
2030 // for compatibility.
2031 observer_->OnDataChannel(proxy_channel.get());
2032 observer_->OnDataChannel(std::move(proxy_channel));
2020 } 2033 }
2021 2034
2022 RtpSenderInterface* PeerConnection::FindSenderById(const std::string& id) { 2035 RtpSenderInterface* PeerConnection::FindSenderById(const std::string& id) {
2023 auto it = 2036 auto it =
2024 std::find_if(senders_.begin(), senders_.end(), 2037 std::find_if(senders_.begin(), senders_.end(),
2025 [id](const rtc::scoped_refptr<RtpSenderInterface>& sender) { 2038 [id](const rtc::scoped_refptr<RtpSenderInterface>& sender) {
2026 return sender->id() == id; 2039 return sender->id() == id;
2027 }); 2040 });
2028 return it != senders_.end() ? it->get() : nullptr; 2041 return it != senders_.end() ? it->get() : nullptr;
2029 } 2042 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const { 2091 DataChannel* PeerConnection::FindDataChannelBySid(int sid) const {
2079 for (const auto& channel : sctp_data_channels_) { 2092 for (const auto& channel : sctp_data_channels_) {
2080 if (channel->id() == sid) { 2093 if (channel->id() == sid) {
2081 return channel; 2094 return channel;
2082 } 2095 }
2083 } 2096 }
2084 return nullptr; 2097 return nullptr;
2085 } 2098 }
2086 2099
2087 } // namespace webrtc 2100 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698