diff --git a/talk/app/webrtc/mediastreamsignaling.cc b/talk/app/webrtc/mediastreamsignaling.cc index c43cd6b662..3c3112107a 100644 --- a/talk/app/webrtc/mediastreamsignaling.cc +++ b/talk/app/webrtc/mediastreamsignaling.cc @@ -594,9 +594,9 @@ void MediaStreamSignaling::UpdateRemoteStreamsList( TrackInfos::iterator track_it = current_tracks->begin(); while (track_it != current_tracks->end()) { const TrackInfo& info = *track_it; - cricket::StreamParams params; - if (!cricket::GetStreamBySsrc(streams, info.ssrc, ¶ms) || - params.id != info.track_id) { + const cricket::StreamParams* params = + cricket::GetStreamBySsrc(streams, info.ssrc); + if (!params || params->id != info.track_id) { OnRemoteTrackRemoved(info.stream_label, info.track_id, media_type); track_it = current_tracks->erase(track_it); } else { @@ -781,9 +781,10 @@ void MediaStreamSignaling::UpdateLocalTracks( TrackInfos::iterator track_it = current_tracks->begin(); while (track_it != current_tracks->end()) { const TrackInfo& info = *track_it; - cricket::StreamParams params; - if (!cricket::GetStreamBySsrc(streams, info.ssrc, ¶ms) || - params.id != info.track_id || params.sync_label != info.stream_label) { + const cricket::StreamParams* params = + cricket::GetStreamBySsrc(streams, info.ssrc); + if (!params || params->id != info.track_id || + params->sync_label != info.stream_label) { OnLocalTrackRemoved(info.stream_label, info.track_id, info.ssrc, media_type); track_it = current_tracks->erase(track_it); diff --git a/talk/app/webrtc/webrtcsession.cc b/talk/app/webrtc/webrtcsession.cc index 81e6c0fbd5..54018f223a 100644 --- a/talk/app/webrtc/webrtcsession.cc +++ b/talk/app/webrtc/webrtcsession.cc @@ -209,12 +209,13 @@ static bool GetAudioSsrcByTrackId( const cricket::MediaContentDescription* audio_content = static_cast( audio_info->description); - cricket::StreamParams stream; - if (!cricket::GetStreamByIds(audio_content->streams(), "", track_id, - &stream)) { + const cricket::StreamParams* stream = + cricket::GetStreamByIds(audio_content->streams(), "", track_id); + if (!stream) { return false; } - *ssrc = stream.first_ssrc(); + + *ssrc = stream->first_ssrc(); return true; } @@ -222,7 +223,6 @@ static bool GetTrackIdBySsrc(const SessionDescription* session_description, uint32 ssrc, std::string* track_id) { ASSERT(track_id != NULL); - cricket::StreamParams stream_out; const cricket::ContentInfo* audio_info = cricket::GetFirstAudioContent(session_description); if (audio_info) { @@ -230,8 +230,10 @@ static bool GetTrackIdBySsrc(const SessionDescription* session_description, static_cast( audio_info->description); - if (cricket::GetStreamBySsrc(audio_content->streams(), ssrc, &stream_out)) { - *track_id = stream_out.id; + const auto* found = + cricket::GetStreamBySsrc(audio_content->streams(), ssrc); + if (found) { + *track_id = found->id; return true; } } @@ -243,8 +245,10 @@ static bool GetTrackIdBySsrc(const SessionDescription* session_description, static_cast( video_info->description); - if (cricket::GetStreamBySsrc(video_content->streams(), ssrc, &stream_out)) { - *track_id = stream_out.id; + const auto* found = + cricket::GetStreamBySsrc(video_content->streams(), ssrc); + if (found) { + *track_id = found->id; return true; } } diff --git a/talk/media/base/fakemediaengine.h b/talk/media/base/fakemediaengine.h index c5de3230ef..391ec37215 100644 --- a/talk/media/base/fakemediaengine.h +++ b/talk/media/base/fakemediaengine.h @@ -160,10 +160,10 @@ template class RtpHelper : public Base { return receive_streams_; } bool HasRecvStream(uint32 ssrc) const { - return GetStreamBySsrc(receive_streams_, ssrc, NULL); + return GetStreamBySsrc(receive_streams_, ssrc) != nullptr; } bool HasSendStream(uint32 ssrc) const { - return GetStreamBySsrc(send_streams_, ssrc, NULL); + return GetStreamBySsrc(send_streams_, ssrc) != nullptr; } // TODO(perkj): This is to support legacy unit test that only check one // sending stream. diff --git a/talk/media/base/rtpdataengine.cc b/talk/media/base/rtpdataengine.cc index 0acc43a8f8..24b6e84afb 100644 --- a/talk/media/base/rtpdataengine.cc +++ b/talk/media/base/rtpdataengine.cc @@ -174,8 +174,7 @@ bool RtpDataMediaChannel::AddSendStream(const StreamParams& stream) { return false; } - StreamParams found_stream; - if (GetStreamBySsrc(send_streams_, stream.first_ssrc(), &found_stream)) { + if (GetStreamBySsrc(send_streams_, stream.first_ssrc())) { LOG(LS_WARNING) << "Not adding data send stream '" << stream.id << "' with ssrc=" << stream.first_ssrc() << " because stream already exists."; @@ -195,8 +194,7 @@ bool RtpDataMediaChannel::AddSendStream(const StreamParams& stream) { } bool RtpDataMediaChannel::RemoveSendStream(uint32 ssrc) { - StreamParams found_stream; - if (!GetStreamBySsrc(send_streams_, ssrc, &found_stream)) { + if (!GetStreamBySsrc(send_streams_, ssrc)) { return false; } @@ -211,8 +209,7 @@ bool RtpDataMediaChannel::AddRecvStream(const StreamParams& stream) { return false; } - StreamParams found_stream; - if (GetStreamBySsrc(recv_streams_, stream.first_ssrc(), &found_stream)) { + if (GetStreamBySsrc(recv_streams_, stream.first_ssrc())) { LOG(LS_WARNING) << "Not adding data recv stream '" << stream.id << "' with ssrc=" << stream.first_ssrc() << " because stream already exists."; @@ -269,13 +266,13 @@ void RtpDataMediaChannel::OnPacketReceived( return; } - StreamParams found_stream; - if (!GetStreamBySsrc(recv_streams_, header.ssrc, &found_stream)) { + if (!GetStreamBySsrc(recv_streams_, header.ssrc)) { LOG(LS_WARNING) << "Received packet for unknown ssrc: " << header.ssrc; return; } // Uncomment this for easy debugging. + // const auto* found_stream = GetStreamBySsrc(recv_streams_, header.ssrc); // LOG(LS_INFO) << "Received packet" // << " groupid=" << found_stream.groupid // << ", ssrc=" << header.ssrc @@ -318,8 +315,9 @@ bool RtpDataMediaChannel::SendData( return false; } - StreamParams found_stream; - if (!GetStreamBySsrc(send_streams_, params.ssrc, &found_stream)) { + const StreamParams* found_stream = + GetStreamBySsrc(send_streams_, params.ssrc); + if (!found_stream) { LOG(LS_WARNING) << "Not sending data because ssrc is unknown: " << params.ssrc; return false; @@ -363,7 +361,7 @@ bool RtpDataMediaChannel::SendData( packet.AppendData(payload.data(), payload.length()); LOG(LS_VERBOSE) << "Sent RTP data packet: " - << " stream=" << found_stream.id + << " stream=" << found_stream->id << " ssrc=" << header.ssrc << ", seqnum=" << header.seq_num << ", timestamp=" << header.timestamp diff --git a/talk/media/base/streamparams.cc b/talk/media/base/streamparams.cc index e3dc57d9da..782c31e28d 100644 --- a/talk/media/base/streamparams.cc +++ b/talk/media/base/streamparams.cc @@ -30,23 +30,28 @@ #include #include +namespace cricket { namespace { - // NOTE: There is no check here for duplicate streams, so check before // adding. -void AddStream(std::vector* streams, - const cricket::StreamParams& stream) { +void AddStream(std::vector* streams, const StreamParams& stream) { streams->push_back(stream); } - } -namespace cricket { - const char kFecSsrcGroupSemantics[] = "FEC"; const char kFidSsrcGroupSemantics[] = "FID"; const char kSimSsrcGroupSemantics[] = "SIM"; +bool GetStream(const StreamParamsVec& streams, + const StreamSelector& selector, + StreamParams* stream_out) { + const StreamParams* found = GetStream(streams, selector); + if (found && stream_out) + *stream_out = *found; + return found != nullptr; +} + bool MediaStreams::GetAudioStream( const StreamSelector& selector, StreamParams* stream) { return GetStream(audio_, selector, stream); @@ -208,58 +213,6 @@ bool StreamParams::GetSecondarySsrc(const std::string& semantics, return false; } -bool GetStream(const StreamParamsVec& streams, - const StreamSelector& selector, - StreamParams* stream_out) { - for (StreamParamsVec::const_iterator stream = streams.begin(); - stream != streams.end(); ++stream) { - if (selector.Matches(*stream)) { - if (stream_out != NULL) { - *stream_out = *stream; - } - return true; - } - } - return false; -} - -bool GetStreamBySsrc(const StreamParamsVec& streams, uint32 ssrc, - StreamParams* stream_out) { - return GetStream(streams, StreamSelector(ssrc), stream_out); -} - -bool GetStreamByIds(const StreamParamsVec& streams, - const std::string& groupid, - const std::string& id, - StreamParams* stream_out) { - return GetStream(streams, StreamSelector(groupid, id), stream_out); -} - -bool RemoveStream(StreamParamsVec* streams, - const StreamSelector& selector) { - bool ret = false; - for (StreamParamsVec::iterator stream = streams->begin(); - stream != streams->end(); ) { - if (selector.Matches(*stream)) { - stream = streams->erase(stream); - ret = true; - } else { - ++stream; - } - } - return ret; -} - -bool RemoveStreamBySsrc(StreamParamsVec* streams, uint32 ssrc) { - return RemoveStream(streams, StreamSelector(ssrc)); -} - -bool RemoveStreamByIds(StreamParamsVec* streams, - const std::string& groupid, - const std::string& id) { - return RemoveStream(streams, StreamSelector(groupid, id)); -} - bool IsOneSsrcStream(const StreamParams& sp) { if (sp.ssrcs.size() == 1 && sp.ssrc_groups.empty()) { return true; diff --git a/talk/media/base/streamparams.h b/talk/media/base/streamparams.h index 9bb22899bb..6e24fa3b96 100644 --- a/talk/media/base/streamparams.h +++ b/talk/media/base/streamparams.h @@ -274,25 +274,82 @@ struct ViewRequest { StaticVideoViews static_video_views; }; -// Finds the stream in streams. Returns true if found. +template +const StreamParams* GetStream(const StreamParamsVec& streams, + Condition condition) { + StreamParamsVec::const_iterator found = + std::find_if(streams.begin(), streams.end(), condition); + return found == streams.end() ? nullptr : &(*found); +} + +inline const StreamParams* GetStreamBySsrc(const StreamParamsVec& streams, + uint32 ssrc) { + return GetStream(streams, + [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); +} + +inline const StreamParams* GetStreamByIds(const StreamParamsVec& streams, + const std::string& groupid, + const std::string& id) { + return GetStream(streams, + [&groupid, &id](const StreamParams& sp) { + return sp.groupid == groupid && sp.id == id; + }); +} + +inline const StreamParams* GetStream(const StreamParamsVec& streams, + const StreamSelector& selector) { + return GetStream(streams, + [&selector](const StreamParams& sp) { return selector.Matches(sp); }); +} + +//////////////////////////////////////////////////////////////////////////////// +// Deprecated methods that will be removed one of these days. +// Please use the methods with the same name above. bool GetStream(const StreamParamsVec& streams, const StreamSelector& selector, StreamParams* stream_out); -bool GetStreamBySsrc(const StreamParamsVec& streams, uint32 ssrc, - StreamParams* stream_out); -bool GetStreamByIds(const StreamParamsVec& streams, - const std::string& groupid, - const std::string& id, - StreamParams* stream_out); +inline bool GetStreamBySsrc(const StreamParamsVec& streams, uint32 ssrc, + StreamParams* stream_out) { + return GetStream(streams, StreamSelector(ssrc), stream_out); +} +inline bool GetStreamByIds(const StreamParamsVec& streams, + const std::string& groupid, + const std::string& id, + StreamParams* stream_out) { + return GetStream(streams, StreamSelector(groupid, id), stream_out); +} +// End deprecated methods. +//////////////////////////////////////////////////////////////////////////////// + +template +bool RemoveStream(StreamParamsVec* streams, Condition condition) { + auto iter(std::remove_if(streams->begin(), streams->end(), condition)); + if (iter == streams->end()) + return false; + streams->erase(iter, streams->end()); + return true; +} // Removes the stream from streams. Returns true if a stream is // found and removed. -bool RemoveStream(StreamParamsVec* streams, - const StreamSelector& selector); -bool RemoveStreamBySsrc(StreamParamsVec* streams, uint32 ssrc); -bool RemoveStreamByIds(StreamParamsVec* streams, - const std::string& groupid, - const std::string& id); +inline bool RemoveStream(StreamParamsVec* streams, + const StreamSelector& selector) { + return RemoveStream(streams, + [&selector](const StreamParams& sp) { return selector.Matches(sp); }); +} +inline bool RemoveStreamBySsrc(StreamParamsVec* streams, uint32 ssrc) { + return RemoveStream(streams, + [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); +} +inline bool RemoveStreamByIds(StreamParamsVec* streams, + const std::string& groupid, + const std::string& id) { + return RemoveStream(streams, + [&groupid, &id](const StreamParams& sp) { + return sp.groupid == groupid && sp.id == id; + }); +} // Checks if |sp| defines parameters for a single primary stream. There may // be an RTX stream associated with the primary stream. Leaving as non-static so diff --git a/talk/session/media/bundlefilter.cc b/talk/session/media/bundlefilter.cc index 1d2a0313bc..cd02a19174 100755 --- a/talk/session/media/bundlefilter.cc +++ b/talk/session/media/bundlefilter.cc @@ -84,9 +84,9 @@ void BundleFilter::AddPayloadType(int payload_type) { } bool BundleFilter::AddStream(const StreamParams& stream) { - if (GetStreamBySsrc(streams_, stream.first_ssrc(), NULL)) { - LOG(LS_WARNING) << "Stream already added to filter"; - return false; + if (GetStreamBySsrc(streams_, stream.first_ssrc())) { + LOG(LS_WARNING) << "Stream already added to filter"; + return false; } streams_.push_back(stream); return true; @@ -101,10 +101,7 @@ bool BundleFilter::HasStreams() const { } bool BundleFilter::FindStream(uint32 ssrc) const { - if (ssrc == 0) { - return false; - } - return (GetStreamBySsrc(streams_, ssrc, NULL)); + return ssrc == 0 ? false : GetStreamBySsrc(streams_, ssrc) != nullptr; } bool BundleFilter::FindPayloadType(int pl_type) const { diff --git a/talk/session/media/channel.cc b/talk/session/media/channel.cc index c31fe45e24..dbcdbb06b3 100644 --- a/talk/session/media/channel.cc +++ b/talk/session/media/channel.cc @@ -1030,10 +1030,9 @@ bool BaseChannel::UpdateLocalStreams_w(const std::vector& streams, if (action == CA_UPDATE) { for (StreamParamsVec::const_iterator it = streams.begin(); it != streams.end(); ++it) { - StreamParams existing_stream; - bool stream_exist = GetStreamByIds(local_streams_, it->groupid, - it->id, &existing_stream); - if (!stream_exist && it->has_ssrcs()) { + const StreamParams* existing_stream = + GetStreamByIds(local_streams_, it->groupid, it->id); + if (!existing_stream && it->has_ssrcs()) { if (media_channel()->AddSendStream(*it)) { local_streams_.push_back(*it); LOG(LS_INFO) << "Add send stream ssrc: " << it->first_ssrc(); @@ -1043,15 +1042,15 @@ bool BaseChannel::UpdateLocalStreams_w(const std::vector& streams, SafeSetError(desc.str(), error_desc); return false; } - } else if (stream_exist && !it->has_ssrcs()) { - if (!media_channel()->RemoveSendStream(existing_stream.first_ssrc())) { + } else if (existing_stream && !it->has_ssrcs()) { + if (!media_channel()->RemoveSendStream(existing_stream->first_ssrc())) { std::ostringstream desc; desc << "Failed to remove send stream with ssrc " << it->first_ssrc() << "."; SafeSetError(desc.str(), error_desc); return false; } - RemoveStreamBySsrc(&local_streams_, existing_stream.first_ssrc()); + RemoveStreamBySsrc(&local_streams_, existing_stream->first_ssrc()); } else { LOG(LS_WARNING) << "Ignore unsupported stream update"; } @@ -1064,7 +1063,7 @@ bool BaseChannel::UpdateLocalStreams_w(const std::vector& streams, bool ret = true; for (StreamParamsVec::const_iterator it = local_streams_.begin(); it != local_streams_.end(); ++it) { - if (!GetStreamBySsrc(streams, it->first_ssrc(), NULL)) { + if (!GetStreamBySsrc(streams, it->first_ssrc())) { if (!media_channel()->RemoveSendStream(it->first_ssrc())) { std::ostringstream desc; desc << "Failed to remove send stream with ssrc " @@ -1077,7 +1076,7 @@ bool BaseChannel::UpdateLocalStreams_w(const std::vector& streams, // Check for new streams. for (StreamParamsVec::const_iterator it = streams.begin(); it != streams.end(); ++it) { - if (!GetStreamBySsrc(local_streams_, it->first_ssrc(), NULL)) { + if (!GetStreamBySsrc(local_streams_, it->first_ssrc())) { if (media_channel()->AddSendStream(*it)) { LOG(LS_INFO) << "Add send ssrc: " << it->ssrcs[0]; } else { @@ -1104,10 +1103,9 @@ bool BaseChannel::UpdateRemoteStreams_w( if (action == CA_UPDATE) { for (StreamParamsVec::const_iterator it = streams.begin(); it != streams.end(); ++it) { - StreamParams existing_stream; - bool stream_exists = GetStreamByIds(remote_streams_, it->groupid, - it->id, &existing_stream); - if (!stream_exists && it->has_ssrcs()) { + const StreamParams* existing_stream = + GetStreamByIds(remote_streams_, it->groupid, it->id); + if (!existing_stream && it->has_ssrcs()) { if (AddRecvStream_w(*it)) { remote_streams_.push_back(*it); LOG(LS_INFO) << "Add remote stream ssrc: " << it->first_ssrc(); @@ -1117,19 +1115,18 @@ bool BaseChannel::UpdateRemoteStreams_w( SafeSetError(desc.str(), error_desc); return false; } - } else if (stream_exists && !it->has_ssrcs()) { - if (!RemoveRecvStream_w(existing_stream.first_ssrc())) { + } else if (existing_stream && !it->has_ssrcs()) { + if (!RemoveRecvStream_w(existing_stream->first_ssrc())) { std::ostringstream desc; desc << "Failed to remove remote stream with ssrc " << it->first_ssrc() << "."; SafeSetError(desc.str(), error_desc); return false; } - RemoveStreamBySsrc(&remote_streams_, existing_stream.first_ssrc()); + RemoveStreamBySsrc(&remote_streams_, existing_stream->first_ssrc()); } else { LOG(LS_WARNING) << "Ignore unsupported stream update." - << " Stream exists? " << stream_exists - << " existing stream = " << existing_stream.ToString() + << " Stream exists? " << (existing_stream != nullptr) << " new stream = " << it->ToString(); } } @@ -1141,7 +1138,7 @@ bool BaseChannel::UpdateRemoteStreams_w( bool ret = true; for (StreamParamsVec::const_iterator it = remote_streams_.begin(); it != remote_streams_.end(); ++it) { - if (!GetStreamBySsrc(streams, it->first_ssrc(), NULL)) { + if (!GetStreamBySsrc(streams, it->first_ssrc())) { if (!RemoveRecvStream_w(it->first_ssrc())) { std::ostringstream desc; desc << "Failed to remove remote stream with ssrc " @@ -1154,7 +1151,7 @@ bool BaseChannel::UpdateRemoteStreams_w( // Check for new streams. for (StreamParamsVec::const_iterator it = streams.begin(); it != streams.end(); ++it) { - if (!GetStreamBySsrc(remote_streams_, it->first_ssrc(), NULL)) { + if (!GetStreamBySsrc(remote_streams_, it->first_ssrc())) { if (AddRecvStream_w(*it)) { LOG(LS_INFO) << "Add remote ssrc: " << it->ssrcs[0]; } else { @@ -1923,7 +1920,7 @@ bool VideoChannel::ApplyViewRequest_w(const ViewRequest& request) { // Check if the view request has invalid streams. for (StaticVideoViews::const_iterator it = request.static_video_views.begin(); it != request.static_video_views.end(); ++it) { - if (!GetStream(local_streams(), it->selector, NULL)) { + if (!GetStream(local_streams(), it->selector)) { LOG(LS_WARNING) << "View request for (" << it->selector.ssrc << ", '" << it->selector.groupid << "', '" diff --git a/talk/session/media/mediasession.cc b/talk/session/media/mediasession.cc index 4f7d4b2ab0..41a5e1d6e8 100644 --- a/talk/session/media/mediasession.cc +++ b/talk/session/media/mediasession.cc @@ -222,12 +222,11 @@ static bool GenerateCname(const StreamParamsVec& params_vec, if (synch_label != stream_it->sync_label) continue; - StreamParams param; // groupid is empty for StreamParams generated using // MediaSessionDescriptionFactory. - if (GetStreamByIds(params_vec, "", stream_it->id, - ¶m)) { - *cname = param.cname; + const StreamParams* param = GetStreamByIds(params_vec, "", stream_it->id); + if (param) { + *cname = param->cname; return true; } } @@ -254,7 +253,7 @@ static void GenerateSsrcs(const StreamParamsVec& params_vec, uint32 candidate; do { candidate = rtc::CreateRandomNonZeroId(); - } while (GetStreamBySsrc(params_vec, candidate, NULL) || + } while (GetStreamBySsrc(params_vec, candidate) || std::count(ssrcs->begin(), ssrcs->end(), candidate) > 0); ssrcs->push_back(candidate); } @@ -270,7 +269,7 @@ static bool GenerateSctpSid(const StreamParamsVec& params_vec, } while (true) { uint32 candidate = rtc::CreateRandomNonZeroId() % kMaxSctpSid; - if (!GetStreamBySsrc(params_vec, candidate, NULL)) { + if (!GetStreamBySsrc(params_vec, candidate)) { *sid = candidate; return true; } @@ -462,11 +461,11 @@ static bool AddStreamParams( if (stream_it->type != media_type) continue; // Wrong media type. - StreamParams param; + const StreamParams* param = + GetStreamByIds(*current_streams, "", stream_it->id); // groupid is empty for StreamParams generated using // MediaSessionDescriptionFactory. - if (!GetStreamByIds(*current_streams, "", stream_it->id, - ¶m)) { + if (!param) { // This is a new stream. // Get a CNAME. Either new or same as one of the other synched streams. std::string cname; @@ -506,7 +505,7 @@ static bool AddStreamParams( // This is necessary so that we can use the CNAME for other media types. current_streams->push_back(stream_param); } else { - content_description->AddStream(param); + content_description->AddStream(*param); } } return true; diff --git a/talk/session/media/mediasession.h b/talk/session/media/mediasession.h index 462ddd22e4..bf3bb7260d 100644 --- a/talk/session/media/mediasession.h +++ b/talk/session/media/mediasession.h @@ -544,13 +544,6 @@ const VideoContentDescription* GetFirstVideoContentDescription( const SessionDescription* sdesc); const DataContentDescription* GetFirstDataContentDescription( const SessionDescription* sdesc); -bool GetStreamBySsrc( - const SessionDescription* sdesc, MediaType media_type, - uint32 ssrc, StreamParams* stream_out); -bool GetStreamByIds( - const SessionDescription* sdesc, MediaType media_type, - const std::string& groupid, const std::string& id, - StreamParams* stream_out); // Functions for translating media candidate names. diff --git a/webrtc/libjingle/examples/call/callclient.cc b/webrtc/libjingle/examples/call/callclient.cc index 6005fc8db5..b2c5c946bc 100644 --- a/webrtc/libjingle/examples/call/callclient.cc +++ b/webrtc/libjingle/examples/call/callclient.cc @@ -771,16 +771,16 @@ void CallClient::SendData(const std::string& streamid, return; } - cricket::StreamParams stream; - if (!cricket::GetStreamByIds( - data->streams(), "", streamid, &stream)) { + const cricket::StreamParams* stream = + cricket::GetStreamByIds(data->streams(), "", streamid) + if (!stream) { LOG(LS_WARNING) << "Could not send data: no such stream: " << streamid << "."; return; } cricket::SendDataParams params; - params.ssrc = stream.first_ssrc(); + params.ssrc = stream->first_ssrc(); rtc::Buffer payload(text.data(), text.length()); cricket::SendDataResult result; bool sent = call_->SendData(session, params, payload, &result); @@ -862,15 +862,16 @@ void CallClient::OnDataReceived(cricket::Call*, if (!session) return; - cricket::StreamParams stream; const std::vector* data_streams = call_->GetDataRecvStreams(session); + const cricket::StreamParams* stream = + data_streams ? GetStreamBySsrc(*data_streams, params.ssrc) : nullptr; std::string text(payload.data(), payload.length()); - if (data_streams && GetStreamBySsrc(*data_streams, params.ssrc, &stream)) { + if (stream) { console_->PrintLine( "Received data from '%s' on stream '%s' (ssrc=%u): %s", - stream.groupid.c_str(), stream.id.c_str(), - params.ssrc, text.c_str()); + stream->groupid.c_str(), stream->id.c_str(), + params->ssrc, text.c_str()); } else { console_->PrintLine( "Received data (ssrc=%u): %s", diff --git a/webrtc/libjingle/session/media/call.cc b/webrtc/libjingle/session/media/call.cc index 2857531dcd..c75c5d438d 100644 --- a/webrtc/libjingle/session/media/call.cc +++ b/webrtc/libjingle/session/media/call.cc @@ -183,11 +183,10 @@ bool Call::SendViewRequest(Session* session, StaticVideoViews::const_iterator it; for (it = view_request.static_video_views.begin(); it != view_request.static_video_views.end(); ++it) { - StreamParams found_stream; bool found = false; MediaStreams* recv_streams = GetMediaStreams(session); if (recv_streams) - found = recv_streams->GetVideoStream(it->selector, &found_stream); + found = recv_streams->GetVideoStream(it->selector, nullptr); if (!found) { LOG(LS_WARNING) << "Trying to send view request for (" << it->selector.ssrc << ", '" @@ -983,10 +982,11 @@ void FindStreamChanges(const std::vector& streams, std::vector* removed_streams) { for (std::vector::const_iterator update = updates.begin(); update != updates.end(); ++update) { - StreamParams stream; - if (GetStreamByIds(streams, update->groupid, update->id, &stream)) { + const StreamParams* stream = + GetStreamByIds(streams, update->groupid, update->id); + if (stream) { if (!update->has_ssrcs()) { - removed_streams->push_back(stream); + removed_streams->push_back(*stream); } } else { // There's a bug on reflector that will send s even