winlin

fix the memory leak error

# the listen ports, split by space.
listen 1935;
listen 1936;
# the default chunk size is 128, max is 65536,
# some client does not support chunk size change,
# however, most clients supports it and it can improve
... ... @@ -10,7 +10,7 @@ chunk_size 65000;
# for which cannot identify the required vhost.
vhost __defaultVhost__ {
enabled on;
gop_cache on;
gop_cache off;
hls on;
hls_path ./objs/nginx/html;
hls_fragment 5;
... ...
... ... @@ -384,7 +384,7 @@ int SrsClient::process_publish_message(SrsSource* source, SrsCommonMessage* msg,
int ret = ERROR_SUCCESS;
// process audio packet
if (msg->header.is_audio()) {
if (false && msg->header.is_audio()) {
if ((ret = source->on_audio(msg)) != ERROR_SUCCESS) {
srs_error("source process audio message failed. ret=%d", ret);
return ret;
... ...
... ... @@ -41,7 +41,7 @@ void SrsCodecBuffer::append(void* data, int len)
{
srs_assert(data);
srs_assert(len > 0);
bytes = (char*)realloc(bytes, size + len);
memcpy(bytes + size, data, len);
size += len;
... ...
... ... @@ -1356,11 +1356,26 @@ bool SrsSharedPtrMessage::can_decode()
return false;
}
int SrsSharedPtrMessage::initialize(ISrsMessage* msg, char* payload, int size)
int SrsSharedPtrMessage::initialize(SrsCommonMessage* source)
{
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) {
ret = ERROR_SYSTEM_ASSERT_FAILED;
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;
}
header = msg->header;
header = source->header;
header.payload_length = size;
ptr = new SrsSharedPtr();
// should copy the payload once
// TODO: maybe can directly attach the common message.
ptr->payload = new char[size];
memcpy(ptr->payload, payload, size);
// direct attach the data of common message.
ptr->payload = payload;
ptr->size = size;
if (msg->header.is_video()) {
if (source->header.is_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;
} else {
ptr->perfer_cid = RTMP_CID_OverConnection2;
... ...
... ... @@ -375,8 +375,15 @@ public:
public:
/**
* 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();
public:
/**
... ...
... ... @@ -370,7 +370,7 @@ int SrsSource::on_audio(SrsCommonMessage* audio)
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
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);
return ret;
}
... ... @@ -383,10 +383,6 @@ int SrsSource::on_audio(SrsCommonMessage* audio)
}
#endif
// detach the original audio
audio->payload = NULL;
audio->size = 0;
// copy to all consumer
std::vector<SrsConsumer*>::iterator it;
for (it = consumers.begin(); it != consumers.end(); ++it) {
... ... @@ -422,7 +418,7 @@ int SrsSource::on_video(SrsCommonMessage* video)
SrsSharedPtrMessage* msg = new SrsSharedPtrMessage();
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);
return ret;
}
... ... @@ -435,10 +431,6 @@ int SrsSource::on_video(SrsCommonMessage* video)
}
#endif
// detach the original audio
video->payload = NULL;
video->size = 0;
// copy to all consumer
std::vector<SrsConsumer*>::iterator it;
for (it = consumers.begin(); it != consumers.end(); ++it) {
... ...