Skip to content

Commit

Permalink
Slight optimization in the packet's hot path (lynckia#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Jun 22, 2017
1 parent bcc1daf commit cf4015a
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 66 deletions.
14 changes: 7 additions & 7 deletions erizo/src/erizo/WebRtcConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void WebRtcConnection::onTransportData(std::shared_ptr<dataPacket> packet, Trans
return;
}

pipeline_->read(packet);
pipeline_->read(std::move(packet));
}

void WebRtcConnection::read(std::shared_ptr<dataPacket> packet) {
Expand All @@ -480,7 +480,7 @@ void WebRtcConnection::read(std::shared_ptr<dataPacket> packet) {
// DELIVER FEEDBACK (RR, FEEDBACK PACKETS)
if (chead->isFeedback()) {
if (fb_sink_ != nullptr && shouldSendFeedback_) {
fb_sink_->deliverFeedback(packet);
fb_sink_->deliverFeedback(std::move(packet));
}
} else {
// RTP or RTCP Sender Report
Expand All @@ -489,10 +489,10 @@ void WebRtcConnection::read(std::shared_ptr<dataPacket> packet) {
// Deliver data
if (isVideoSourceSSRC(recvSSRC)) {
parseIncomingPayloadType(buf, len, VIDEO_PACKET);
video_sink_->deliverVideoData(packet);
video_sink_->deliverVideoData(std::move(packet));
} else if (isAudioSourceSSRC(recvSSRC)) {
parseIncomingPayloadType(buf, len, AUDIO_PACKET);
audio_sink_->deliverAudioData(packet);
audio_sink_->deliverAudioData(std::move(packet));
} else {
ELOG_DEBUG("%s unknownSSRC: %u, localVideoSSRC: %u, localAudioSSRC: %u",
toLog(), recvSSRC, this->getVideoSourceSSRC(), this->getAudioSourceSSRC());
Expand All @@ -505,7 +505,7 @@ void WebRtcConnection::read(std::shared_ptr<dataPacket> packet) {
ELOG_DEBUG("%s discoveredAudioSourceSSRC:%u", toLog(), recvSSRC);
this->setAudioSourceSSRC(recvSSRC);
}
audio_sink_->deliverAudioData(packet);
audio_sink_->deliverAudioData(std::move(packet));
} else if (packet->type == VIDEO_PACKET && video_sink_ != nullptr) {
parseIncomingPayloadType(buf, len, VIDEO_PACKET);
// Firefox does not send SSRC in SDP
Expand All @@ -514,7 +514,7 @@ void WebRtcConnection::read(std::shared_ptr<dataPacket> packet) {
this->setVideoSourceSSRC(recvSSRC);
}
// change ssrc for RTP packets, don't touch here if RTCP
video_sink_->deliverVideoData(packet);
video_sink_->deliverVideoData(std::move(packet));
}
} // if not bundle
} // if not Feedback
Expand Down Expand Up @@ -865,7 +865,7 @@ void WebRtcConnection::sendPacket(std::shared_ptr<dataPacket> p) {
return;
}

pipeline_->write(p);
pipeline_->write(std::move(p));
}

void WebRtcConnection::setQualityLayer(int spatial_layer, int temporal_layer) {
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/WebRtcConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class PacketReader : public InboundHandler {
}

void read(Context *ctx, std::shared_ptr<dataPacket> packet) override {
connection_->read(packet);
connection_->read(std::move(packet));
}

void notifyUpdate() override {
Expand All @@ -270,7 +270,7 @@ class PacketWriter : public OutboundHandler {
}

void write(Context *ctx, std::shared_ptr<dataPacket> packet) override {
connection_->write(packet);
connection_->write(std::move(packet));
}

void notifyUpdate() override {
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/pipeline/Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ class HandlerAdapter : public Handler {
}

void read(Context* ctx, std::shared_ptr<dataPacket> packet) override {
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
}

void write(Context* ctx, std::shared_ptr<dataPacket> packet) override {
return ctx->fireWrite(packet);
return ctx->fireWrite(std::move(packet));
}

void notifyUpdate() override {
Expand Down
16 changes: 8 additions & 8 deletions erizo/src/erizo/pipeline/HandlerContext-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class ContextImpl
void fireRead(std::shared_ptr<dataPacket> packet) override {
auto guard = this->pipelineWeak_.lock();
if (this->nextIn_) {
this->nextIn_->read(packet);
this->nextIn_->read(std::move(packet));
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ class ContextImpl
void fireWrite(std::shared_ptr<dataPacket> packet) override {
auto guard = this->pipelineWeak_.lock();
if (this->nextOut_) {
this->nextOut_->write(packet);
this->nextOut_->write(std::move(packet));
}
}

Expand All @@ -219,7 +219,7 @@ class ContextImpl
// InboundLink overrides
void read(std::shared_ptr<dataPacket> packet) override {
auto guard = this->pipelineWeak_.lock();
this->handler_->read(this, packet);
this->handler_->read(this, std::move(packet));
}

void readEOF() override {
Expand All @@ -240,7 +240,7 @@ class ContextImpl
// OutboundLink overrides
void write(std::shared_ptr<dataPacket> packet) override {
auto guard = this->pipelineWeak_.lock();
this->handler_->write(this, packet);
this->handler_->write(this, std::move(packet));
}

void close() override {
Expand Down Expand Up @@ -275,7 +275,7 @@ class InboundContextImpl
void fireRead(std::shared_ptr<dataPacket> packet) override {
auto guard = this->pipelineWeak_.lock();
if (this->nextIn_) {
this->nextIn_->read(packet);
this->nextIn_->read(std::move(packet));
}
}

Expand Down Expand Up @@ -311,7 +311,7 @@ class InboundContextImpl
// InboundLink overrides
void read(std::shared_ptr<dataPacket> packet) override {
auto guard = this->pipelineWeak_.lock();
this->handler_->read(this, packet);
this->handler_->read(this, std::move(packet));
}

void readEOF() override {
Expand Down Expand Up @@ -356,7 +356,7 @@ class OutboundContextImpl
void fireWrite(std::shared_ptr<dataPacket> packet) override {
auto guard = this->pipelineWeak_.lock();
if (this->nextOut_) {
return this->nextOut_->write(packet);
return this->nextOut_->write(std::move(packet));
}
}

Expand All @@ -378,7 +378,7 @@ class OutboundContextImpl
// OutboundLink overrides
void write(std::shared_ptr<dataPacket> packet) override {
auto guard = this->pipelineWeak_.lock();
return this->handler_->write(this, packet);
return this->handler_->write(this, std::move(packet));
}

void close() override {
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/pipeline/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void Pipeline::read(std::shared_ptr<dataPacket> packet) {
if (!front_) {
return;
}
front_->read(packet);
front_->read(std::move(packet));
}

void Pipeline::readEOF() {
Expand All @@ -83,7 +83,7 @@ void Pipeline::write(std::shared_ptr<dataPacket> packet) {
if (!back_) {
return;
}
back_->write(packet);
back_->write(std::move(packet));
}

void Pipeline::close() {
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/rtp/BandwidthEstimationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void BandwidthEstimationHandler::read(Context *ctx, std::shared_ptr<dataPacket>
ELOG_DEBUG("Packet not parsed %d", packet->type);
}
}
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
}

bool BandwidthEstimationHandler::parsePacket(std::shared_ptr<dataPacket> packet) {
Expand Down Expand Up @@ -175,7 +175,7 @@ RtpHeaderExtensionMap BandwidthEstimationHandler::getHeaderExtensionMap(std::sha
}

void BandwidthEstimationHandler::write(Context *ctx, std::shared_ptr<dataPacket> packet) {
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
}

void BandwidthEstimationHandler::pickEstimatorFromHeader() {
Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/FecReceiverHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void FecReceiverHandler::write(Context *ctx, std::shared_ptr<dataPacket> packet)
}
}

ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
}

bool FecReceiverHandler::OnRecoveredPacket(const uint8_t* rtp_packet, size_t rtp_packet_length) {
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/rtp/LayerBitrateCalculationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void LayerBitrateCalculationHandler::disable() {

void LayerBitrateCalculationHandler::write(Context *ctx, std::shared_ptr<dataPacket> packet) {
if (!enabled_ || !initialized_) {
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
return;
}

Expand All @@ -42,7 +42,7 @@ void LayerBitrateCalculationHandler::write(Context *ctx, std::shared_ptr<dataPac
});
});
quality_manager_->notifyQualityUpdate();
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
}


Expand Down
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/LayerDetectorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void LayerDetectorHandler::read(Context *ctx, std::shared_ptr<dataPacket> packet
parseLayerInfoFromVP9(packet);
}
}
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
}

int LayerDetectorHandler::getSsrcPosition(uint32_t ssrc) {
Expand Down
4 changes: 2 additions & 2 deletions erizo/src/erizo/rtp/PliPacerHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void PliPacerHandler::read(Context *ctx, std::shared_ptr<dataPacket> packet) {
connection_->getWorker()->unschedule(scheduled_pli_);
scheduled_pli_ = -1;
}
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
}

void PliPacerHandler::sendPLI() {
Expand Down Expand Up @@ -81,7 +81,7 @@ void PliPacerHandler::write(Context *ctx, std::shared_ptr<dataPacket> packet) {
waiting_for_keyframe_ = true;
scheduleNextPLI();
}
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
}

} // namespace erizo
2 changes: 1 addition & 1 deletion erizo/src/erizo/rtp/QualityFilterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void QualityFilterHandler::read(Context *ctx, std::shared_ptr<dataPacket> packet
return;
}

ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
}

void QualityFilterHandler::checkLayers() {
Expand Down
10 changes: 5 additions & 5 deletions erizo/src/erizo/rtp/RtcpFeedbackGenerationHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void RtcpFeedbackGenerationHandler::read(Context *ctx, std::shared_ptr<dataPacke
RtcpHeader *chead = reinterpret_cast<RtcpHeader*>(packet->data);

if (!initialized_) {
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
return;
}

Expand All @@ -34,7 +34,7 @@ void RtcpFeedbackGenerationHandler::read(Context *ctx, std::shared_ptr<dataPacke
} else {
ELOG_DEBUG("message: no RrGenerator found, ssrc: %u", ssrc);
}
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
return;
}
bool should_send_rr = false;
Expand All @@ -59,14 +59,14 @@ void RtcpFeedbackGenerationHandler::read(Context *ctx, std::shared_ptr<dataPacke
if (nacks_enabled_ && generator_it->second->nack_generator != nullptr) {
generator_it->second->nack_generator->addNackPacketToRr(rtcp_packet);
}
ctx->fireWrite(rtcp_packet);
ctx->fireWrite(std::move(rtcp_packet));
}
}
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
}

void RtcpFeedbackGenerationHandler::write(Context *ctx, std::shared_ptr<dataPacket> packet) {
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
}

void RtcpFeedbackGenerationHandler::notifyUpdate() {
Expand Down
6 changes: 3 additions & 3 deletions erizo/src/erizo/rtp/RtcpProcessorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ void RtcpProcessorHandler::read(Context *ctx, std::shared_ptr<dataPacket> packet
}
}
processor_->checkRtcpFb();
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
}

void RtcpProcessorHandler::write(Context *ctx, std::shared_ptr<dataPacket> packet) {
RtcpHeader *chead = reinterpret_cast<RtcpHeader*>(packet->data);
if (chead->isFeedback()) {
int length = processor_->analyzeFeedback(packet->data, packet->length);
if (length) {
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
}
return;
}
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
}

void RtcpProcessorHandler::notifyUpdate() {
Expand Down
8 changes: 4 additions & 4 deletions erizo/src/erizo/rtp/RtpPaddingGeneratorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void RtpPaddingGeneratorHandler::notifyUpdate() {
}

void RtpPaddingGeneratorHandler::read(Context *ctx, std::shared_ptr<dataPacket> packet) {
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
}

void RtpPaddingGeneratorHandler::write(Context *ctx, std::shared_ptr<dataPacket> packet) {
Expand All @@ -80,7 +80,7 @@ void RtpPaddingGeneratorHandler::write(Context *ctx, std::shared_ptr<dataPacket>
ctx->fireWrite(packet);

if (is_higher_sequence_number) {
onVideoPacket(packet);
onVideoPacket(std::move(packet));
}
}

Expand All @@ -101,7 +101,7 @@ void RtpPaddingGeneratorHandler::sendPaddingPacket(std::shared_ptr<dataPacket> p

rtp_header->setSeqNumber(sequence_number.output);
stats_->getNode()["total"]["paddingBitrate"] += padding_packet->length;
getContext()->fireWrite(padding_packet);
getContext()->fireWrite(std::move(padding_packet));
}

void RtpPaddingGeneratorHandler::onPacketWithMarkerSet(std::shared_ptr<dataPacket> packet) {
Expand Down Expand Up @@ -141,7 +141,7 @@ void RtpPaddingGeneratorHandler::onVideoPacket(std::shared_ptr<dataPacket> packe

RtpHeader *rtp_header = reinterpret_cast<RtpHeader*>(packet->data);
if (rtp_header->getMarker()) {
onPacketWithMarkerSet(packet);
onPacketWithMarkerSet(std::move(packet));
}
}

Expand Down
8 changes: 4 additions & 4 deletions erizo/src/erizo/rtp/RtpPaddingRemovalHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ void RtpPaddingRemovalHandler::read(Context *ctx, std::shared_ptr<dataPacket> pa
ssrc);
rtp_header->setSeqNumber(sequence_number_info.output);
}
ctx->fireRead(packet);
ctx->fireRead(std::move(packet));
}

void RtpPaddingRemovalHandler::write(Context *ctx, std::shared_ptr<dataPacket> packet) {
RtcpHeader* rtcp_head = reinterpret_cast<RtcpHeader*>(packet->data);
if (!enabled_ || packet->type != VIDEO_PACKET || !rtcp_head->isFeedback()) {
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
return;
}
uint32_t ssrc = rtcp_head->getSourceSSRC();
std::shared_ptr<SequenceNumberTranslator> translator = getTranslatorForSsrc(ssrc, false);
if (!translator) {
ELOG_DEBUG("No translator for ssrc %u, %s", ssrc, connection_->toLog());
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
return;
}
RtpUtils::forEachRRBlock(packet, [this, translator, ssrc](RtcpHeader *chead) {
Expand Down Expand Up @@ -83,7 +83,7 @@ void RtpPaddingRemovalHandler::write(Context *ctx, std::shared_ptr<dataPacket> p
});
}
});
ctx->fireWrite(packet);
ctx->fireWrite(std::move(packet));
}

bool RtpPaddingRemovalHandler::removePaddingBytes(std::shared_ptr<dataPacket> packet,
Expand Down
Loading

0 comments on commit cf4015a

Please sign in to comment.