mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix the memory leak error
This commit is contained in:
parent
005f821441
commit
af5e7f002f
6 changed files with 36 additions and 24 deletions
|
@ -1,5 +1,5 @@
|
||||||
# the listen ports, split by space.
|
# the listen ports, split by space.
|
||||||
listen 1935;
|
listen 1936;
|
||||||
# the default chunk size is 128, max is 65536,
|
# the default chunk size is 128, max is 65536,
|
||||||
# some client does not support chunk size change,
|
# some client does not support chunk size change,
|
||||||
# however, most clients supports it and it can improve
|
# however, most clients supports it and it can improve
|
||||||
|
@ -10,7 +10,7 @@ chunk_size 65000;
|
||||||
# for which cannot identify the required vhost.
|
# for which cannot identify the required vhost.
|
||||||
vhost __defaultVhost__ {
|
vhost __defaultVhost__ {
|
||||||
enabled on;
|
enabled on;
|
||||||
gop_cache on;
|
gop_cache off;
|
||||||
hls on;
|
hls on;
|
||||||
hls_path ./objs/nginx/html;
|
hls_path ./objs/nginx/html;
|
||||||
hls_fragment 5;
|
hls_fragment 5;
|
||||||
|
|
|
@ -384,7 +384,7 @@ int SrsClient::process_publish_message(SrsSource* source, SrsCommonMessage* msg,
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
// process audio packet
|
// process audio packet
|
||||||
if (msg->header.is_audio()) {
|
if (false && msg->header.is_audio()) {
|
||||||
if ((ret = source->on_audio(msg)) != ERROR_SUCCESS) {
|
if ((ret = source->on_audio(msg)) != ERROR_SUCCESS) {
|
||||||
srs_error("source process audio message failed. ret=%d", ret);
|
srs_error("source process audio message failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -41,7 +41,7 @@ void SrsCodecBuffer::append(void* data, int len)
|
||||||
{
|
{
|
||||||
srs_assert(data);
|
srs_assert(data);
|
||||||
srs_assert(len > 0);
|
srs_assert(len > 0);
|
||||||
|
|
||||||
bytes = (char*)realloc(bytes, size + len);
|
bytes = (char*)realloc(bytes, size + len);
|
||||||
memcpy(bytes + size, data, len);
|
memcpy(bytes + size, data, len);
|
||||||
size += len;
|
size += len;
|
||||||
|
|
|
@ -1356,11 +1356,26 @@ bool SrsSharedPtrMessage::can_decode()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsSharedPtrMessage::initialize(ISrsMessage* msg, char* payload, int size)
|
int SrsSharedPtrMessage::initialize(SrsCommonMessage* source)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
srs_assert(msg != NULL);
|
if ((ret = initialize(source, (char*)source->payload, source->size)) != ERROR_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// detach the payload from source
|
||||||
|
source->payload = NULL;
|
||||||
|
source->size = 0;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SrsSharedPtrMessage::initialize(SrsCommonMessage* source, char* payload, int size)
|
||||||
|
{
|
||||||
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
srs_assert(source != NULL);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
ret = ERROR_SYSTEM_ASSERT_FAILED;
|
ret = ERROR_SYSTEM_ASSERT_FAILED;
|
||||||
srs_error("should not set the payload twice. ret=%d", ret);
|
srs_error("should not set the payload twice. ret=%d", ret);
|
||||||
|
@ -1369,20 +1384,18 @@ int SrsSharedPtrMessage::initialize(ISrsMessage* msg, char* payload, int size)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
header = msg->header;
|
header = source->header;
|
||||||
header.payload_length = size;
|
header.payload_length = size;
|
||||||
|
|
||||||
ptr = new SrsSharedPtr();
|
ptr = new SrsSharedPtr();
|
||||||
|
|
||||||
// should copy the payload once
|
// direct attach the data of common message.
|
||||||
// TODO: maybe can directly attach the common message.
|
ptr->payload = payload;
|
||||||
ptr->payload = new char[size];
|
|
||||||
memcpy(ptr->payload, payload, size);
|
|
||||||
ptr->size = size;
|
ptr->size = size;
|
||||||
|
|
||||||
if (msg->header.is_video()) {
|
if (source->header.is_video()) {
|
||||||
ptr->perfer_cid = RTMP_CID_Video;
|
ptr->perfer_cid = RTMP_CID_Video;
|
||||||
} else if (msg->header.is_audio()) {
|
} else if (source->header.is_audio()) {
|
||||||
ptr->perfer_cid = RTMP_CID_Audio;
|
ptr->perfer_cid = RTMP_CID_Audio;
|
||||||
} else {
|
} else {
|
||||||
ptr->perfer_cid = RTMP_CID_OverConnection2;
|
ptr->perfer_cid = RTMP_CID_OverConnection2;
|
||||||
|
|
|
@ -375,8 +375,15 @@ public:
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* set the shared payload.
|
* set the shared payload.
|
||||||
|
* we will detach the payload of source,
|
||||||
|
* so ensure donot use it before.
|
||||||
*/
|
*/
|
||||||
virtual int initialize(ISrsMessage* msg, char* payload, int size);
|
virtual int initialize(SrsCommonMessage* source);
|
||||||
|
/**
|
||||||
|
* set the shared payload.
|
||||||
|
* we will use the payload, donot use the payload of source.
|
||||||
|
*/
|
||||||
|
virtual int initialize(SrsCommonMessage* source, char* payload, int size);
|
||||||
virtual SrsSharedPtrMessage* copy();
|
virtual SrsSharedPtrMessage* copy();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -370,7 +370,7 @@ int SrsSource::on_audio(SrsCommonMessage* audio)
|
||||||
|
|
||||||
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
||||||
SrsAutoFree(SrsSharedPtrMessage, msg, false);
|
SrsAutoFree(SrsSharedPtrMessage, msg, false);
|
||||||
if ((ret = msg->initialize(audio, (char*)audio->payload, audio->size)) != ERROR_SUCCESS) {
|
if ((ret = msg->initialize(audio)) != ERROR_SUCCESS) {
|
||||||
srs_error("initialize the audio failed. ret=%d", ret);
|
srs_error("initialize the audio failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -383,10 +383,6 @@ int SrsSource::on_audio(SrsCommonMessage* audio)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// detach the original audio
|
|
||||||
audio->payload = NULL;
|
|
||||||
audio->size = 0;
|
|
||||||
|
|
||||||
// copy to all consumer
|
// copy to all consumer
|
||||||
std::vector<SrsConsumer*>::iterator it;
|
std::vector<SrsConsumer*>::iterator it;
|
||||||
for (it = consumers.begin(); it != consumers.end(); ++it) {
|
for (it = consumers.begin(); it != consumers.end(); ++it) {
|
||||||
|
@ -422,7 +418,7 @@ int SrsSource::on_video(SrsCommonMessage* video)
|
||||||
|
|
||||||
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
|
||||||
SrsAutoFree(SrsSharedPtrMessage, msg, false);
|
SrsAutoFree(SrsSharedPtrMessage, msg, false);
|
||||||
if ((ret = msg->initialize(video, (char*)video->payload, video->size)) != ERROR_SUCCESS) {
|
if ((ret = msg->initialize(video)) != ERROR_SUCCESS) {
|
||||||
srs_error("initialize the video failed. ret=%d", ret);
|
srs_error("initialize the video failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -435,10 +431,6 @@ int SrsSource::on_video(SrsCommonMessage* video)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// detach the original audio
|
|
||||||
video->payload = NULL;
|
|
||||||
video->size = 0;
|
|
||||||
|
|
||||||
// copy to all consumer
|
// copy to all consumer
|
||||||
std::vector<SrsConsumer*>::iterator it;
|
std::vector<SrsConsumer*>::iterator it;
|
||||||
for (it = consumers.begin(); it != consumers.end(); ++it) {
|
for (it = consumers.begin(); it != consumers.end(); ++it) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue