This PR modernizes the memory management architecture in SRS by refactoring RTMP message handling to use shared pointers (SrsSharedPtr<SrsMemoryBlock>) instead of manual memory management. This change improves memory safety, reduces the risk of memory leaks, and provides a cleaner abstraction for message payload handling. * Introduced `SrsMemoryBlock`: A dedicated class for managing memory buffers with size information * Replaced manual memory management: `SrsCommonMessage` and `SrsSharedPtrMessage` now use `SrsSharedPtr<SrsMemoryBlock>` instead of raw pointers * Updated `SrsRtpPacket`: Now uses `SrsSharedPtr<SrsMemoryBlock>` for shared buffer management --------- Co-authored-by: OSSRS-AI <winlinam@gmail.com>
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
//
|
|
// Copyright (c) 2013-2025 The SRS Authors
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
//
|
|
|
|
#include <srs_protocol_format.hpp>
|
|
|
|
#include <srs_core_autofree.hpp>
|
|
#include <srs_kernel_buffer.hpp>
|
|
#include <srs_kernel_codec.hpp>
|
|
#include <srs_kernel_error.hpp>
|
|
#include <srs_kernel_utility.hpp>
|
|
#include <srs_protocol_rtmp_stack.hpp>
|
|
|
|
SrsRtmpFormat::SrsRtmpFormat()
|
|
{
|
|
}
|
|
|
|
SrsRtmpFormat::~SrsRtmpFormat()
|
|
{
|
|
}
|
|
|
|
srs_error_t SrsRtmpFormat::on_metadata(SrsOnMetaDataPacket *meta)
|
|
{
|
|
// TODO: FIXME: Try to initialize format from metadata.
|
|
return srs_success;
|
|
}
|
|
|
|
srs_error_t SrsRtmpFormat::on_audio(SrsSharedPtrMessage *shared_audio)
|
|
{
|
|
SrsSharedPtrMessage *msg = shared_audio;
|
|
char *data = msg->payload();
|
|
int size = msg->size();
|
|
|
|
return SrsFormat::on_audio(msg->timestamp, data, size);
|
|
}
|
|
|
|
srs_error_t SrsRtmpFormat::on_audio(int64_t timestamp, char *data, int size)
|
|
{
|
|
return SrsFormat::on_audio(timestamp, data, size);
|
|
}
|
|
|
|
srs_error_t SrsRtmpFormat::on_video(SrsSharedPtrMessage *shared_video)
|
|
{
|
|
SrsSharedPtrMessage *msg = shared_video;
|
|
char *data = msg->payload();
|
|
int size = msg->size();
|
|
|
|
return SrsFormat::on_video(msg->timestamp, data, size);
|
|
}
|
|
|
|
srs_error_t SrsRtmpFormat::on_video(int64_t timestamp, char *data, int size)
|
|
{
|
|
return SrsFormat::on_video(timestamp, data, size);
|
|
}
|