Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rtp packetization refactor and unit test #386

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

yezhan10
Copy link
Contributor

@yezhan10 yezhan10 commented Nov 8, 2024

No description provided.

@yezhan10 yezhan10 changed the title rtp packetization refactor and unit test refactor: rtp packetization refactor and unit test Nov 8, 2024
include/MediaFrameListenerBridge.h Outdated Show resolved Hide resolved
include/rtp/RTPPacketizer.h Outdated Show resolved Hide resolved
@@ -25,6 +132,53 @@ class RTPPacketizer
protected:
MediaFrame::Type mediaType;
DWORD codec;
private:
static size_t CalculateAggregationEndIndex(const std::shared_ptr<MediaFrame>& frame, size_t startIdx, uint32_t maxSize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use const MediaFrame::RtpPacketizationInfo& info instead of frame as input

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are going to extract this function, let's move it to an h264xxx.h file instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I prefer to move it to h264Packetizer.h since CalculateAggregationEndIndex() and AggregatePayloads() are not h264 particular. The function would be the same regardless of the codec type, so it makes less sense to me to move them to a file that pertaining to a specific codec.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they make no sense for codecs other than h264

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i thought that stap-a can be applied to other codec as well. We just support stapA for h264 now. If this is the case, I will move it to h264packetizer instead

return last;
}

static void AggregatePayloads(const std::shared_ptr<MediaFrame>& frame, RTPPacket::shared& packet, size_t stapAStartIdx, size_t stapAEndIdx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above


class RTPPacketizer
{
public:
static constexpr uint32_t StapANaluSize = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this declaration doesn't belong here


class RTPPacketizer
{
public:
static constexpr uint32_t StapANaluSize = 2;
static constexpr uint8_t StapAHeader = 0b0'11'11000; // STAP-A header nalu type = 24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

@yezhan10 yezhan10 Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I am following, what's the intended usage of this class? I thought that this class is responsible for packetize stapA regardless the codec type? You want it to be moved to h26xPacketizer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rtpacketizer is codec agnostic, so it doesn't make sense to have any h264 codec specific info here

include/rtp/RTPPacketizer.h Outdated Show resolved Hide resolved
@@ -25,6 +40,9 @@ class RTPPacketizer
protected:
MediaFrame::Type mediaType;
DWORD codec;
private:
static size_t CalculateAggregationEndIndex(const MediaFrame::RtpPacketizationInfo& info, size_t startIdx, uint32_t maxSize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't we agree to move this to somewhere inside h264 code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replied to your previous comment about moving the functions to h264. I think that these two functions are not codec specific operations, so it makes more sense to not move them to a codec specific file?

src/MediaFrameListenerBridge.cpp Outdated Show resolved Hide resolved
{
uint64_t time = frame->GetTime();
uint64_t ms = scheduled.count();
uint32_t frameSize = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint32_t frameSize = 0;
uint32_t frameSize = frame->GetLength();;

@@ -546,6 +375,58 @@ void MediaFrameListenerBridge::UpdateFrameInfoAndStats(const std::shared_ptr<Med
bitrate = acumulator.GetInstant()*8;
}

void MediaFrameListenerBridge::AddRTPPackets(const std::shared_ptr<MediaFrame>& frame, const std::vector<RTPPacket::shared>& rtpPackets, std::chrono::milliseconds scheduled)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void MediaFrameListenerBridge::AddRTPPackets(const std::shared_ptr<MediaFrame>& frame, const std::vector<RTPPacket::shared>& rtpPackets, std::chrono::milliseconds scheduled)
void MediaFrameListenerBridge::EnqueueRTPPackets(const std::shared_ptr<MediaFrame>& frame, const std::vector<RTPPacket::shared>& rtpPackets, std::chrono::milliseconds scheduled)

auto audioFrame = std::static_pointer_cast<AudioFrame>(frame);
//Set correct clock rate for audio codec
auto rate = AudioCodec::GetClockRate(audioFrame->GetCodec());
pendingDuration = frame->GetDuration() * frame->GetClockRate() / rate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo it is better to calculate the pending duration outside and pass it as parameter here


for (size_t i=0; i<rtpPackets.size(); i++)
{
auto packet = rtpPackets[i];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not copy, it will cause a new shared pointer to be created, degrading performance

Suggested change
auto packet = rtpPackets[i];
auto& packet = rtpPackets[i];

void RTPPacketizer::SetPacketsProp(const std::shared_ptr<MediaFrame>& frame, const std::vector<RTPPacket::shared>& rtpPackets, uint64_t lastTimestamp, uint64_t extSeqNum, uint32_t targetBitrateHint)
{
uint32_t rate = 0;
RTPPacketizer::VideoFrameInfo videoInfo {0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the value of having a struct at packetizer level when we are using only internally in this function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants