Change GetStreamBySsrc to not copy StreamParams.
This is something I stumbled upon while looking at string copying we do (in spades) and did a simple change to not be constantly copying things around needlessly. There's a lot more that can be done in these files of course so this is sort of a reminder for future code edits that it's possible to design interfaces/function in a way that's more performance aware and avoid forcing creation of copies, while still being very simple. Also, we can use lambdas now :) BUG= R=perkj@webrtc.org, pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/41589004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@8131 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
7e5b380437
commit
586f2eda0d
@ -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);
|
||||
|
@ -209,12 +209,13 @@ static bool GetAudioSsrcByTrackId(
|
||||
const cricket::MediaContentDescription* audio_content =
|
||||
static_cast<const cricket::MediaContentDescription*>(
|
||||
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<const cricket::MediaContentDescription*>(
|
||||
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<const cricket::MediaContentDescription*>(
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -160,10 +160,10 @@ template <class Base> 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.
|
||||
|
@ -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
|
||||
|
@ -30,23 +30,28 @@
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
|
||||
namespace cricket {
|
||||
namespace {
|
||||
|
||||
// NOTE: There is no check here for duplicate streams, so check before
|
||||
// adding.
|
||||
void AddStream(std::vector<cricket::StreamParams>* streams,
|
||||
const cricket::StreamParams& stream) {
|
||||
void AddStream(std::vector<StreamParams>* 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;
|
||||
|
@ -274,25 +274,82 @@ struct ViewRequest {
|
||||
StaticVideoViews static_video_views;
|
||||
};
|
||||
|
||||
// Finds the stream in streams. Returns true if found.
|
||||
template <class Condition>
|
||||
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 <class Condition>
|
||||
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
|
||||
|
@ -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 {
|
||||
|
@ -1030,10 +1030,9 @@ bool BaseChannel::UpdateLocalStreams_w(const std::vector<StreamParams>& 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<StreamParams>& 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<StreamParams>& 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<StreamParams>& 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 << "', '"
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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<cricket::StreamParams>* 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",
|
||||
|
@ -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<StreamParams>& streams,
|
||||
std::vector<StreamParams>* removed_streams) {
|
||||
for (std::vector<StreamParams>::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 <stream>s even
|
||||
|
Loading…
x
Reference in New Issue
Block a user