Skip to content

Commit

Permalink
Small code review like avoiding redundant objects copy. (lynckia#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
Equod authored and zevarito committed Jul 4, 2018
1 parent 4b4fe08 commit 013ca00
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 63 deletions.
14 changes: 7 additions & 7 deletions erizo/src/erizo/DtlsTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ DtlsTransport::~DtlsTransport() {

void DtlsTransport::start() {
ice_->setIceListener(shared_from_this());
ice_->copyLogContextFrom(this);
ice_->copyLogContextFrom(*this);
ELOG_DEBUG("%s message: starting ice", toLog());
ice_->start();
}
Expand Down Expand Up @@ -279,10 +279,10 @@ void DtlsTransport::onHandshakeCompleted(DtlsSocketContext *ctx, std::string cli
boost::mutex::scoped_lock lock(sessionMutex_);
std::string temp;

if (rtp_timeout_checker_.get() != NULL) {
if (rtp_timeout_checker_) {
rtp_timeout_checker_->cancel();
}
if (rtcp_timeout_checker_.get() != NULL) {
if (rtcp_timeout_checker_) {
rtcp_timeout_checker_->cancel();
}

Expand Down Expand Up @@ -316,14 +316,14 @@ void DtlsTransport::onHandshakeCompleted(DtlsSocketContext *ctx, std::string cli
}
}

void DtlsTransport::onHandshakeFailed(DtlsSocketContext *ctx, const std::string error) {
void DtlsTransport::onHandshakeFailed(DtlsSocketContext *ctx, const std::string& error) {
ELOG_WARN("%s message: Handshake failed, transportName:%s, openSSLerror: %s",
toLog(), transport_name.c_str(), error.c_str());
running_ = false;
updateTransportState(TRANSPORT_FAILED);
}

std::string DtlsTransport::getMyFingerprint() {
std::string DtlsTransport::getMyFingerprint() const {
return dtlsRtp->getFingerprint();
}

Expand Down Expand Up @@ -368,8 +368,8 @@ void DtlsTransport::processLocalSdp(SdpInfo *localSdp_) {
ELOG_DEBUG("%s message: processing local sdp, transportName: %s", toLog(), transport_name.c_str());
localSdp_->isFingerprint = true;
localSdp_->fingerprint = getMyFingerprint();
std::string username = ice_->getLocalUsername();
std::string password = ice_->getLocalPassword();
std::string username(ice_->getLocalUsername());
std::string password(ice_->getLocalPassword());
if (bundle_) {
localSdp_->setCredentials(username, password, VIDEO_TYPE);
localSdp_->setCredentials(username, password, AUDIO_TYPE);
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/DtlsTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DtlsTransport : dtls::DtlsReceiver, public Transport {
std::shared_ptr<IOWorker> io_worker);
virtual ~DtlsTransport();
void connectionStateChanged(IceState newState);
std::string getMyFingerprint();
std::string getMyFingerprint() const;
static bool isDtlsPacket(const char* buf, int len);
void start() override;
void close() override;
Expand All @@ -37,7 +37,7 @@ class DtlsTransport : dtls::DtlsReceiver, public Transport {
void writeDtlsPacket(dtls::DtlsSocketContext *ctx, packetPtr packet);
void onHandshakeCompleted(dtls::DtlsSocketContext *ctx, std::string clientKey, std::string serverKey,
std::string srtp_profile) override;
void onHandshakeFailed(dtls::DtlsSocketContext *ctx, const std::string error) override;
void onHandshakeFailed(dtls::DtlsSocketContext *ctx, const std::string& error) override;
void updateIceState(IceState state, IceConnection *conn) override;
void processLocalSdp(SdpInfo *localSdp_) override;

Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/IceConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ std::weak_ptr<IceConnectionListener> IceConnection::getIceListener() {
return listener_;
}

std::string IceConnection::getLocalUsername() {
const std::string& IceConnection::getLocalUsername() const {
return ufrag_;
}

std::string IceConnection::getLocalPassword() {
const std::string& IceConnection::getLocalPassword() const {
return upass_;
}

Expand Down
6 changes: 3 additions & 3 deletions erizo/src/erizo/IceConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ class IceConnection : public LogContext {
virtual void setIceListener(std::weak_ptr<IceConnectionListener> listener);
virtual std::weak_ptr<IceConnectionListener> getIceListener();

virtual std::string getLocalUsername();
virtual std::string getLocalPassword();
virtual const std::string& getLocalUsername() const;
virtual const std::string& getLocalPassword() const;

private:
virtual std::string iceStateToString(IceState state) const;

protected:
inline std::string toLog() {
inline std::string toLog() const {
return "id: " + ice_config_.connection_id + ", " + printLogContext();
}

Expand Down
56 changes: 28 additions & 28 deletions erizo/src/erizo/MediaStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ MediaStream::MediaStream(std::shared_ptr<Worker> worker,
const std::string& media_stream_label,
bool is_publisher) :
audio_enabled_{false}, video_enabled_{false},
connection_{connection},
connection_{std::move(connection)},
stream_id_{media_stream_id},
mslabel_ {media_stream_label},
bundle_{false},
pipeline_{Pipeline::create()},
worker_{worker},
worker_{std::move(worker)},
audio_muted_{false}, video_muted_{false},
pipeline_initialized_{false},
is_publisher_{is_publisher} {
Expand Down Expand Up @@ -190,7 +190,7 @@ bool MediaStream::setRemoteSdp(std::shared_ptr<SdpInfo> sdp) {
}

bool MediaStream::setLocalSdp(std::shared_ptr<SdpInfo> sdp) {
local_sdp_ = sdp;
local_sdp_ = std::move(sdp);
return true;
}

Expand All @@ -203,41 +203,41 @@ void MediaStream::initializePipeline() {
pipeline_->addService(quality_manager_);
pipeline_->addService(packet_buffer_);

pipeline_->addFront(PacketReader(this));

pipeline_->addFront(RtcpProcessorHandler());
pipeline_->addFront(FecReceiverHandler());
pipeline_->addFront(LayerBitrateCalculationHandler());
pipeline_->addFront(QualityFilterHandler());
pipeline_->addFront(IncomingStatsHandler());
pipeline_->addFront(RtpTrackMuteHandler());
pipeline_->addFront(RtpSlideShowHandler());
pipeline_->addFront(RtpPaddingGeneratorHandler());
pipeline_->addFront(PliPacerHandler());
pipeline_->addFront(BandwidthEstimationHandler());
pipeline_->addFront(RtpPaddingRemovalHandler());
pipeline_->addFront(RtcpFeedbackGenerationHandler());
pipeline_->addFront(RtpRetransmissionHandler());
pipeline_->addFront(SRPacketHandler());
pipeline_->addFront(SenderBandwidthEstimationHandler());
pipeline_->addFront(LayerDetectorHandler());
pipeline_->addFront(OutgoingStatsHandler());
pipeline_->addFront(PacketCodecParser());

pipeline_->addFront(PacketWriter(this));
pipeline_->addFront(std::make_shared<PacketReader>(this));

pipeline_->addFront(std::make_shared<RtcpProcessorHandler>());
pipeline_->addFront(std::make_shared<FecReceiverHandler>());
pipeline_->addFront(std::make_shared<LayerBitrateCalculationHandler>());
pipeline_->addFront(std::make_shared<QualityFilterHandler>());
pipeline_->addFront(std::make_shared<IncomingStatsHandler>());
pipeline_->addFront(std::make_shared<RtpTrackMuteHandler>());
pipeline_->addFront(std::make_shared<RtpSlideShowHandler>());
pipeline_->addFront(std::make_shared<RtpPaddingGeneratorHandler>());
pipeline_->addFront(std::make_shared<PliPacerHandler>());
pipeline_->addFront(std::make_shared<BandwidthEstimationHandler>());
pipeline_->addFront(std::make_shared<RtpPaddingRemovalHandler>());
pipeline_->addFront(std::make_shared<RtcpFeedbackGenerationHandler>());
pipeline_->addFront(std::make_shared<RtpRetransmissionHandler>());
pipeline_->addFront(std::make_shared<SRPacketHandler>());
pipeline_->addFront(std::make_shared<SenderBandwidthEstimationHandler>());
pipeline_->addFront(std::make_shared<LayerDetectorHandler>());
pipeline_->addFront(std::make_shared<OutgoingStatsHandler>());
pipeline_->addFront(std::make_shared<PacketCodecParser>());

pipeline_->addFront(std::make_shared<PacketWriter>(this));
pipeline_->finalize();
pipeline_initialized_ = true;
}

int MediaStream::deliverAudioData_(std::shared_ptr<DataPacket> audio_packet) {
if (audio_enabled_ == true) {
if (audio_enabled_) {
sendPacketAsync(std::make_shared<DataPacket>(*audio_packet));
}
return audio_packet->length;
}

int MediaStream::deliverVideoData_(std::shared_ptr<DataPacket> video_packet) {
if (video_enabled_ == true) {
if (video_enabled_) {
sendPacketAsync(std::make_shared<DataPacket>(*video_packet));
}
return video_packet->length;
Expand Down Expand Up @@ -388,7 +388,7 @@ void MediaStream::notifyMediaStreamEvent(const std::string& type, const std::str
}

void MediaStream::notifyToEventSink(MediaEventPtr event) {
event_sink_->deliverEvent(event);
event_sink_->deliverEvent(std::move(event));
}

int MediaStream::sendPLI() {
Expand Down
14 changes: 7 additions & 7 deletions erizo/src/erizo/WebRtcConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,20 @@ bool WebRtcConnection::createOffer(bool video_enabled, bool audioEnabled, bool b
if (bundle_) {
video_transport_.reset(new DtlsTransport(VIDEO_TYPE, "video", connection_id_, bundle_, true,
listener, ice_config_ , "", "", true, worker_, io_worker_));
video_transport_->copyLogContextFrom(this);
video_transport_->copyLogContextFrom(*this);
video_transport_->start();
} else {
if (video_transport_.get() == nullptr && video_enabled_) {
// For now we don't re/check transports, if they are already created we leave them there
video_transport_.reset(new DtlsTransport(VIDEO_TYPE, "video", connection_id_, bundle_, true,
listener, ice_config_ , "", "", true, worker_, io_worker_));
video_transport_->copyLogContextFrom(this);
video_transport_->copyLogContextFrom(*this);
video_transport_->start();
}
if (audio_transport_.get() == nullptr && audio_enabled_) {
audio_transport_.reset(new DtlsTransport(AUDIO_TYPE, "audio", connection_id_, bundle_, true,
listener, ice_config_, "", "", true, worker_, io_worker_));
audio_transport_->copyLogContextFrom(this);
audio_transport_->copyLogContextFrom(*this);
audio_transport_->start();
}
}
Expand Down Expand Up @@ -339,7 +339,7 @@ bool WebRtcConnection::processRemoteSdp(std::string stream_id) {
video_transport_.reset(new DtlsTransport(VIDEO_TYPE, "video", connection_id_, bundle_, remote_sdp_->isRtcpMux,
listener, ice_config_ , username, password, false,
worker_, io_worker_));
video_transport_->copyLogContextFrom(this);
video_transport_->copyLogContextFrom(*this);
video_transport_->start();
} else {
ELOG_DEBUG("%s message: Updating videoTransport, ufrag: %s, pass: %s",
Expand All @@ -356,7 +356,7 @@ bool WebRtcConnection::processRemoteSdp(std::string stream_id) {
audio_transport_.reset(new DtlsTransport(AUDIO_TYPE, "audio", connection_id_, bundle_, remote_sdp_->isRtcpMux,
listener, ice_config_, username, password, false,
worker_, io_worker_));
audio_transport_->copyLogContextFrom(this);
audio_transport_->copyLogContextFrom(*this);
audio_transport_->start();
} else {
ELOG_DEBUG("%s message: Update audioTransport, ufrag: %s, pass: %s",
Expand Down Expand Up @@ -455,7 +455,7 @@ std::string WebRtcConnection::getJSONCandidate(const std::string& mid, const std

std::ostringstream theString;
theString << "{";
for (std::map<std::string, std::string>::iterator it = object.begin(); it != object.end(); ++it) {
for (std::map<std::string, std::string>::const_iterator it = object.begin(); it != object.end(); ++it) {
theString << "\"" << it->first << "\":\"" << it->second << "\"";
if (++it != object.end()) {
theString << ",";
Expand Down Expand Up @@ -737,7 +737,7 @@ void WebRtcConnection::syncWrite(std::shared_ptr<DataPacket> packet) {
}

void WebRtcConnection::setTransport(std::shared_ptr<Transport> transport) { // Only for Testing purposes
video_transport_ = transport;
video_transport_ = std::move(transport);
bundle_ = true;
}

Expand Down
6 changes: 3 additions & 3 deletions erizo/src/erizo/dtls/DtlsClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ int createCert(const std::string& pAor, int expireDays, int keyLen, X509*& outCe
}


std::string DtlsSocketContext::getFingerprint() {
char fprint[100];
std::string DtlsSocketContext::getFingerprint() const {
char fprint[100] = {};
mSocket->getMyCertFingerprint(fprint);
return std::string(fprint, strlen(fprint));
return std::string(fprint);
}

void DtlsSocketContext::start() {
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/dtls/DtlsSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class DtlsReceiver {
virtual void onDtlsPacket(DtlsSocketContext *ctx, const unsigned char* data, unsigned int len) = 0;
virtual void onHandshakeCompleted(DtlsSocketContext *ctx, std::string clientKey, std::string serverKey,
std::string srtp_profile) = 0;
virtual void onHandshakeFailed(DtlsSocketContext *ctx, const std::string error) = 0;
virtual void onHandshakeFailed(DtlsSocketContext *ctx, const std::string& error) = 0;
};

class DtlsSocketContext {
Expand All @@ -153,7 +153,7 @@ class DtlsSocketContext {
void handshakeFailed(const char *err);
void setDtlsReceiver(DtlsReceiver *recv);
void setDtlsSocket(DtlsSocket *sock) {mSocket = sock;}
std::string getFingerprint();
std::string getFingerprint() const;

void handleTimeout();

Expand Down
12 changes: 6 additions & 6 deletions erizo/src/erizo/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ class LogContext {
LogContext() : context_log_{""} {
}

virtual ~LogContext() {}
virtual ~LogContext() = default;

void setLogContext(std::map<std::string, std::string> context) {
void setLogContext(const std::map<std::string, std::string>& context) {
context_ = context;
context_log_ = "";
for (const std::pair<std::string, std::string> &item : context) {
for (const auto &item : context) {
context_log_ += item.first + ": " + item.second + ", ";
}
}

void copyLogContextFrom(LogContext *log_context) {
setLogContext(log_context->context_);
void copyLogContextFrom(const LogContext& log_context) {
setLogContext(log_context.context_);
}

std::string printLogContext() {
const std::string& printLogContext() const {
return context_log_;
}

Expand Down
6 changes: 3 additions & 3 deletions erizo/src/erizo/media/ExternalOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ void ExternalOutput::initializePipeline() {
pipeline_->addService(quality_manager_);
pipeline_->addService(stats_);

pipeline_->addFront(LayerBitrateCalculationHandler());
pipeline_->addFront(QualityFilterHandler());
pipeline_->addFront(std::make_shared<LayerBitrateCalculationHandler>());
pipeline_->addFront(std::make_shared<QualityFilterHandler>());

pipeline_->addFront(ExternalOuputWriter(shared_from_this()));
pipeline_->addFront(std::make_shared<ExternalOuputWriter>(shared_from_this()));
pipeline_->finalize();
pipeline_initialized_ = true;
}
Expand Down

0 comments on commit 013ca00

Please sign in to comment.