fix mem leak for delete[] SharedPtrMessage array, explicit free elems. remove srs_freepa. 0.9.95
正在显示
15 个修改的文件
包含
209 行增加
和
174 行删除
| @@ -50,7 +50,7 @@ void SrsCodecBuffer::append(void* data, int len) | @@ -50,7 +50,7 @@ void SrsCodecBuffer::append(void* data, int len) | ||
| 50 | void SrsCodecBuffer::free() | 50 | void SrsCodecBuffer::free() |
| 51 | { | 51 | { |
| 52 | size = 0; | 52 | size = 0; |
| 53 | - srs_freepa(bytes); | 53 | + srs_freep(bytes); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | SrsCodecSample::SrsCodecSample() | 56 | SrsCodecSample::SrsCodecSample() |
| @@ -125,12 +125,12 @@ SrsCodec::SrsCodec() | @@ -125,12 +125,12 @@ SrsCodec::SrsCodec() | ||
| 125 | 125 | ||
| 126 | SrsCodec::~SrsCodec() | 126 | SrsCodec::~SrsCodec() |
| 127 | { | 127 | { |
| 128 | - srs_freepa(avc_extra_data); | ||
| 129 | - srs_freepa(aac_extra_data); | 128 | + srs_freep(avc_extra_data); |
| 129 | + srs_freep(aac_extra_data); | ||
| 130 | 130 | ||
| 131 | srs_freep(stream); | 131 | srs_freep(stream); |
| 132 | - srs_freepa(sequenceParameterSetNALUnit); | ||
| 133 | - srs_freepa(pictureParameterSetNALUnit); | 132 | + srs_freep(sequenceParameterSetNALUnit); |
| 133 | + srs_freep(pictureParameterSetNALUnit); | ||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | int SrsCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample) | 136 | int SrsCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample) |
| @@ -207,7 +207,7 @@ int SrsCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample) | @@ -207,7 +207,7 @@ int SrsCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample) | ||
| 207 | // 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33. | 207 | // 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33. |
| 208 | aac_extra_size = stream->left(); | 208 | aac_extra_size = stream->left(); |
| 209 | if (aac_extra_size > 0) { | 209 | if (aac_extra_size > 0) { |
| 210 | - srs_freepa(aac_extra_data); | 210 | + srs_freep(aac_extra_data); |
| 211 | aac_extra_data = new char[aac_extra_size]; | 211 | aac_extra_data = new char[aac_extra_size]; |
| 212 | memcpy(aac_extra_data, stream->current(), aac_extra_size); | 212 | memcpy(aac_extra_data, stream->current(), aac_extra_size); |
| 213 | } | 213 | } |
| @@ -321,7 +321,7 @@ int SrsCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample) | @@ -321,7 +321,7 @@ int SrsCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample) | ||
| 321 | // 5.2.4.1.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16 | 321 | // 5.2.4.1.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16 |
| 322 | avc_extra_size = stream->left(); | 322 | avc_extra_size = stream->left(); |
| 323 | if (avc_extra_size > 0) { | 323 | if (avc_extra_size > 0) { |
| 324 | - srs_freepa(avc_extra_data); | 324 | + srs_freep(avc_extra_data); |
| 325 | avc_extra_data = new char[avc_extra_size]; | 325 | avc_extra_data = new char[avc_extra_size]; |
| 326 | memcpy(avc_extra_data, stream->current(), avc_extra_size); | 326 | memcpy(avc_extra_data, stream->current(), avc_extra_size); |
| 327 | } | 327 | } |
| @@ -366,7 +366,7 @@ int SrsCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample) | @@ -366,7 +366,7 @@ int SrsCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample) | ||
| 366 | return ret; | 366 | return ret; |
| 367 | } | 367 | } |
| 368 | if (sequenceParameterSetLength > 0) { | 368 | if (sequenceParameterSetLength > 0) { |
| 369 | - srs_freepa(sequenceParameterSetNALUnit); | 369 | + srs_freep(sequenceParameterSetNALUnit); |
| 370 | sequenceParameterSetNALUnit = new char[sequenceParameterSetLength]; | 370 | sequenceParameterSetNALUnit = new char[sequenceParameterSetLength]; |
| 371 | memcpy(sequenceParameterSetNALUnit, stream->current(), sequenceParameterSetLength); | 371 | memcpy(sequenceParameterSetNALUnit, stream->current(), sequenceParameterSetLength); |
| 372 | stream->skip(sequenceParameterSetLength); | 372 | stream->skip(sequenceParameterSetLength); |
| @@ -396,7 +396,7 @@ int SrsCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample) | @@ -396,7 +396,7 @@ int SrsCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample) | ||
| 396 | return ret; | 396 | return ret; |
| 397 | } | 397 | } |
| 398 | if (pictureParameterSetLength > 0) { | 398 | if (pictureParameterSetLength > 0) { |
| 399 | - srs_freepa(pictureParameterSetNALUnit); | 399 | + srs_freep(pictureParameterSetNALUnit); |
| 400 | pictureParameterSetNALUnit = new char[pictureParameterSetLength]; | 400 | pictureParameterSetNALUnit = new char[pictureParameterSetLength]; |
| 401 | memcpy(pictureParameterSetNALUnit, stream->current(), pictureParameterSetLength); | 401 | memcpy(pictureParameterSetNALUnit, stream->current(), pictureParameterSetLength); |
| 402 | stream->skip(pictureParameterSetLength); | 402 | stream->skip(pictureParameterSetLength); |
| @@ -93,7 +93,7 @@ SrsFileBuffer::SrsFileBuffer() | @@ -93,7 +93,7 @@ SrsFileBuffer::SrsFileBuffer() | ||
| 93 | 93 | ||
| 94 | SrsFileBuffer::~SrsFileBuffer() | 94 | SrsFileBuffer::~SrsFileBuffer() |
| 95 | { | 95 | { |
| 96 | - srs_freepa(start); | 96 | + srs_freep(start); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | int SrsFileBuffer::fullfill(const char* filename) | 99 | int SrsFileBuffer::fullfill(const char* filename) |
| @@ -117,7 +117,7 @@ int SrsFileBuffer::fullfill(const char* filename) | @@ -117,7 +117,7 @@ int SrsFileBuffer::fullfill(const char* filename) | ||
| 117 | goto finish; | 117 | goto finish; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | - srs_freepa(start); | 120 | + srs_freep(start); |
| 121 | pos = last = start = new char[filesize]; | 121 | pos = last = start = new char[filesize]; |
| 122 | end = start + filesize; | 122 | end = start + filesize; |
| 123 | 123 | ||
| @@ -407,15 +407,15 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, vector<string>& args) | @@ -407,15 +407,15 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, vector<string>& args) | ||
| 407 | 407 | ||
| 408 | if (found) { | 408 | if (found) { |
| 409 | int len = buffer->pos - pstart; | 409 | int len = buffer->pos - pstart; |
| 410 | - char* word = new char[len]; | ||
| 411 | - memcpy(word, pstart, len); | ||
| 412 | - word[len - 1] = 0; | 410 | + char* aword = new char[len]; |
| 411 | + memcpy(aword, pstart, len); | ||
| 412 | + aword[len - 1] = 0; | ||
| 413 | 413 | ||
| 414 | - string word_str = word; | 414 | + string word_str = aword; |
| 415 | if (!word_str.empty()) { | 415 | if (!word_str.empty()) { |
| 416 | args.push_back(word_str); | 416 | args.push_back(word_str); |
| 417 | } | 417 | } |
| 418 | - srs_freepa(word); | 418 | + srs_freep(aword); |
| 419 | 419 | ||
| 420 | if (ch == ';') { | 420 | if (ch == ';') { |
| 421 | return ERROR_SYSTEM_CONFIG_DIRECTIVE; | 421 | return ERROR_SYSTEM_CONFIG_DIRECTIVE; |
| @@ -87,7 +87,7 @@ void SrsConnection::stop() | @@ -87,7 +87,7 @@ void SrsConnection::stop() | ||
| 87 | { | 87 | { |
| 88 | srs_close_stfd(stfd); | 88 | srs_close_stfd(stfd); |
| 89 | srs_freep(pthread); | 89 | srs_freep(pthread); |
| 90 | - srs_freepa(ip); | 90 | + srs_freep(ip); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | int SrsConnection::get_peer_ip() | 93 | int SrsConnection::get_peer_ip() |
| @@ -474,20 +474,33 @@ int SrsEdgeForwarder::cycle() | @@ -474,20 +474,33 @@ int SrsEdgeForwarder::cycle() | ||
| 474 | srs_verbose("no packets to forward."); | 474 | srs_verbose("no packets to forward."); |
| 475 | continue; | 475 | continue; |
| 476 | } | 476 | } |
| 477 | - SrsAutoFree(SrsSharedPtrMessage*, msgs, true); | ||
| 478 | 477 | ||
| 479 | - // all msgs to forward. | 478 | + // all msgs to forward to origin. |
| 479 | + // @remark, becareful, all msgs must be free explicitly, | ||
| 480 | + // free by send_and_free_message or srs_freep. | ||
| 480 | for (int i = 0; i < count; i++) { | 481 | for (int i = 0; i < count; i++) { |
| 481 | SrsSharedPtrMessage* msg = msgs[i]; | 482 | SrsSharedPtrMessage* msg = msgs[i]; |
| 482 | 483 | ||
| 483 | srs_assert(msg); | 484 | srs_assert(msg); |
| 484 | msgs[i] = NULL; | 485 | msgs[i] = NULL; |
| 485 | 486 | ||
| 487 | + // never use free msgs array, for it will memory leak. | ||
| 488 | + // if error, directly free msgs. | ||
| 489 | + if (ret != ERROR_SUCCESS) { | ||
| 490 | + srs_freep(msg); | ||
| 491 | + continue; | ||
| 492 | + } | ||
| 493 | + | ||
| 486 | if ((ret = client->send_and_free_message(msg)) != ERROR_SUCCESS) { | 494 | if ((ret = client->send_and_free_message(msg)) != ERROR_SUCCESS) { |
| 487 | srs_error("edge publish forwarder send message to server failed. ret=%d", ret); | 495 | srs_error("edge publish forwarder send message to server failed. ret=%d", ret); |
| 488 | - return ret; | 496 | + break; |
| 489 | } | 497 | } |
| 490 | } | 498 | } |
| 499 | + // free the array itself. | ||
| 500 | + srs_freep(msgs); | ||
| 501 | + if (ret != ERROR_SUCCESS) { | ||
| 502 | + return ret; | ||
| 503 | + } | ||
| 491 | } | 504 | } |
| 492 | 505 | ||
| 493 | return ret; | 506 | return ret; |
| @@ -360,7 +360,7 @@ int SrsFFMPEG::start() | @@ -360,7 +360,7 @@ int SrsFFMPEG::start() | ||
| 360 | } | 360 | } |
| 361 | srs_trace("start transcoder, log: %s, params: %s", | 361 | srs_trace("start transcoder, log: %s, params: %s", |
| 362 | log_file.c_str(), pparam); | 362 | log_file.c_str(), pparam); |
| 363 | - srs_freepa(pparam); | 363 | + srs_freep(pparam); |
| 364 | } | 364 | } |
| 365 | 365 | ||
| 366 | // TODO: fork or vfork? | 366 | // TODO: fork or vfork? |
| @@ -352,20 +352,33 @@ int SrsForwarder::forward() | @@ -352,20 +352,33 @@ int SrsForwarder::forward() | ||
| 352 | srs_verbose("no packets to forward."); | 352 | srs_verbose("no packets to forward."); |
| 353 | continue; | 353 | continue; |
| 354 | } | 354 | } |
| 355 | - SrsAutoFree(SrsSharedPtrMessage*, msgs, true); | ||
| 356 | 355 | ||
| 357 | // all msgs to forward. | 356 | // all msgs to forward. |
| 357 | + // @remark, becareful, all msgs must be free explicitly, | ||
| 358 | + // free by send_and_free_message or srs_freep. | ||
| 358 | for (int i = 0; i < count; i++) { | 359 | for (int i = 0; i < count; i++) { |
| 359 | SrsSharedPtrMessage* msg = msgs[i]; | 360 | SrsSharedPtrMessage* msg = msgs[i]; |
| 360 | 361 | ||
| 361 | srs_assert(msg); | 362 | srs_assert(msg); |
| 362 | msgs[i] = NULL; | 363 | msgs[i] = NULL; |
| 363 | 364 | ||
| 365 | + // never use free msgs array, for it will memory leak. | ||
| 366 | + // if error, directly free msgs. | ||
| 367 | + if (ret != ERROR_SUCCESS) { | ||
| 368 | + srs_freep(msg); | ||
| 369 | + continue; | ||
| 370 | + } | ||
| 371 | + | ||
| 364 | if ((ret = client->send_and_free_message(msg)) != ERROR_SUCCESS) { | 372 | if ((ret = client->send_and_free_message(msg)) != ERROR_SUCCESS) { |
| 365 | srs_error("forwarder send message to server failed. ret=%d", ret); | 373 | srs_error("forwarder send message to server failed. ret=%d", ret); |
| 366 | - return ret; | 374 | + break; |
| 367 | } | 375 | } |
| 368 | } | 376 | } |
| 377 | + // free the array itself. | ||
| 378 | + srs_freep(msgs); | ||
| 379 | + if (ret != ERROR_SUCCESS) { | ||
| 380 | + return ret; | ||
| 381 | + } | ||
| 369 | } | 382 | } |
| 370 | 383 | ||
| 371 | return ret; | 384 | return ret; |
| @@ -523,7 +523,7 @@ SrsHttpMessage::~SrsHttpMessage() | @@ -523,7 +523,7 @@ SrsHttpMessage::~SrsHttpMessage() | ||
| 523 | srs_freep(_body); | 523 | srs_freep(_body); |
| 524 | srs_freep(_uri); | 524 | srs_freep(_uri); |
| 525 | srs_freep(_match); | 525 | srs_freep(_match); |
| 526 | - srs_freepa(_http_ts_send_buffer); | 526 | + srs_freep(_http_ts_send_buffer); |
| 527 | } | 527 | } |
| 528 | 528 | ||
| 529 | char* SrsHttpMessage::http_ts_send_buffer() | 529 | char* SrsHttpMessage::http_ts_send_buffer() |
| @@ -513,9 +513,10 @@ int SrsRtmpConn::playing(SrsSource* source) | @@ -513,9 +513,10 @@ int SrsRtmpConn::playing(SrsSource* source) | ||
| 513 | srs_verbose("no packets in queue."); | 513 | srs_verbose("no packets in queue."); |
| 514 | continue; | 514 | continue; |
| 515 | } | 515 | } |
| 516 | - SrsAutoFree(SrsSharedPtrMessage*, msgs, true); | ||
| 517 | 516 | ||
| 518 | // sendout messages | 517 | // sendout messages |
| 518 | + // @remark, becareful, all msgs must be free explicitly, | ||
| 519 | + // free by send_and_free_message or srs_freep. | ||
| 519 | for (int i = 0; i < count; i++) { | 520 | for (int i = 0; i < count; i++) { |
| 520 | SrsSharedPtrMessage* msg = msgs[i]; | 521 | SrsSharedPtrMessage* msg = msgs[i]; |
| 521 | 522 | ||
| @@ -525,6 +526,13 @@ int SrsRtmpConn::playing(SrsSource* source) | @@ -525,6 +526,13 @@ int SrsRtmpConn::playing(SrsSource* source) | ||
| 525 | 526 | ||
| 526 | srs_assert(msg); | 527 | srs_assert(msg); |
| 527 | 528 | ||
| 529 | + // never use free msgs array, for it will memory leak. | ||
| 530 | + // if error, directly free msgs. | ||
| 531 | + if (ret != ERROR_SUCCESS) { | ||
| 532 | + srs_freep(msg); | ||
| 533 | + continue; | ||
| 534 | + } | ||
| 535 | + | ||
| 528 | // foreach msg, collect the duration. | 536 | // foreach msg, collect the duration. |
| 529 | // @remark: never use msg when sent it, for the protocol sdk will free it. | 537 | // @remark: never use msg when sent it, for the protocol sdk will free it. |
| 530 | if (starttime < 0 || starttime > msg->header.timestamp) { | 538 | if (starttime < 0 || starttime > msg->header.timestamp) { |
| @@ -535,9 +543,14 @@ int SrsRtmpConn::playing(SrsSource* source) | @@ -535,9 +543,14 @@ int SrsRtmpConn::playing(SrsSource* source) | ||
| 535 | 543 | ||
| 536 | if ((ret = rtmp->send_and_free_message(msg)) != ERROR_SUCCESS) { | 544 | if ((ret = rtmp->send_and_free_message(msg)) != ERROR_SUCCESS) { |
| 537 | srs_error("send message to client failed. ret=%d", ret); | 545 | srs_error("send message to client failed. ret=%d", ret); |
| 538 | - return ret; | 546 | + break; |
| 539 | } | 547 | } |
| 540 | } | 548 | } |
| 549 | + // free the array itself. | ||
| 550 | + srs_freep(msgs); | ||
| 551 | + if (ret != ERROR_SUCCESS) { | ||
| 552 | + return ret; | ||
| 553 | + } | ||
| 541 | 554 | ||
| 542 | // if duration specified, and exceed it, stop play live. | 555 | // if duration specified, and exceed it, stop play live. |
| 543 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/45 | 556 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/45 |
| @@ -844,7 +844,7 @@ int SrsSource::on_meta_data(SrsMessage* msg, SrsOnMetaDataPacket* metadata) | @@ -844,7 +844,7 @@ int SrsSource::on_meta_data(SrsMessage* msg, SrsOnMetaDataPacket* metadata) | ||
| 844 | char* payload = NULL; | 844 | char* payload = NULL; |
| 845 | if ((ret = metadata->encode(size, payload)) != ERROR_SUCCESS) { | 845 | if ((ret = metadata->encode(size, payload)) != ERROR_SUCCESS) { |
| 846 | srs_error("encode metadata error. ret=%d", ret); | 846 | srs_error("encode metadata error. ret=%d", ret); |
| 847 | - srs_freepa(payload); | 847 | + srs_freep(payload); |
| 848 | return ret; | 848 | return ret; |
| 849 | } | 849 | } |
| 850 | srs_verbose("encode metadata success."); | 850 | srs_verbose("encode metadata success."); |
trunk/src/core/srs_core.hpp
100755 → 100644
| 1 | -/* | ||
| 2 | -The MIT License (MIT) | ||
| 3 | - | ||
| 4 | -Copyright (c) 2013-2014 winlin | ||
| 5 | - | ||
| 6 | -Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | -this software and associated documentation files (the "Software"), to deal in | ||
| 8 | -the Software without restriction, including without limitation the rights to | ||
| 9 | -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | -the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | -subject to the following conditions: | ||
| 12 | - | ||
| 13 | -The above copyright notice and this permission notice shall be included in all | ||
| 14 | -copies or substantial portions of the Software. | ||
| 15 | - | ||
| 16 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | -*/ | ||
| 23 | - | ||
| 24 | -#ifndef SRS_CORE_HPP | ||
| 25 | -#define SRS_CORE_HPP | ||
| 26 | - | ||
| 27 | -/* | ||
| 28 | -#include <srs_core.hpp> | ||
| 29 | -*/ | ||
| 30 | - | ||
| 31 | -// current release version | ||
| 32 | -#define VERSION_MAJOR "0" | ||
| 33 | -#define VERSION_MINOR "9" | ||
| 34 | -#define VERSION_REVISION "94" | ||
| 35 | -#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | ||
| 36 | -// server info. | ||
| 37 | -#define RTMP_SIG_SRS_KEY "srs" | ||
| 38 | -#define RTMP_SIG_SRS_ROLE "origin/edge server" | ||
| 39 | -#define RTMP_SIG_SRS_NAME RTMP_SIG_SRS_KEY"(simple rtmp server)" | ||
| 40 | -#define RTMP_SIG_SRS_URL_SHORT "github.com/winlinvip/simple-rtmp-server" | ||
| 41 | -#define RTMP_SIG_SRS_URL "https://"RTMP_SIG_SRS_URL_SHORT | ||
| 42 | -#define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin" | ||
| 43 | -#define RTMP_SIG_SRS_EMAIL "winlin@vip.126.com" | ||
| 44 | -#define RTMP_SIG_SRS_LICENSE "The MIT License (MIT)" | ||
| 45 | -#define RTMP_SIG_SRS_COPYRIGHT "Copyright (c) 2013-2014 winlin" | ||
| 46 | -#define RTMP_SIG_SRS_PRIMARY_AUTHROS "winlin,wenjie.zhao" | ||
| 47 | -#define RTMP_SIG_SRS_CONTRIBUTORS_URL RTMP_SIG_SRS_URL"/blob/master/AUTHORS.txt" | ||
| 48 | - | ||
| 49 | -/** | ||
| 50 | -* the core provides the common defined macros, utilities, | ||
| 51 | -* user must include the srs_core.hpp before any header, or maybe | ||
| 52 | -* build failed. | ||
| 53 | -*/ | ||
| 54 | - | ||
| 55 | -// for 32bit os, 2G big file limit for unistd io, | ||
| 56 | -// ie. read/write/lseek to use 64bits size for huge file. | ||
| 57 | -#ifndef _FILE_OFFSET_BITS | ||
| 58 | - #define _FILE_OFFSET_BITS 64 | ||
| 59 | -#endif | ||
| 60 | - | ||
| 61 | -// for int64_t print using PRId64 format. | ||
| 62 | -#ifndef __STDC_FORMAT_MACROS | ||
| 63 | - #define __STDC_FORMAT_MACROS | ||
| 64 | -#endif | ||
| 65 | -#include <inttypes.h> | ||
| 66 | - | ||
| 67 | -#include <assert.h> | ||
| 68 | -#define srs_assert(expression) assert(expression) | ||
| 69 | - | ||
| 70 | -#include <stddef.h> | ||
| 71 | -#include <sys/types.h> | ||
| 72 | - | ||
| 73 | -// generated by configure. | ||
| 74 | -#include <srs_auto_headers.hpp> | ||
| 75 | - | ||
| 76 | -// free the p and set to NULL. | ||
| 77 | -// p must be a T*. | ||
| 78 | -#define srs_freep(p) \ | ||
| 79 | - if (p) { \ | ||
| 80 | - delete p; \ | ||
| 81 | - p = NULL; \ | ||
| 82 | - } \ | ||
| 83 | - (void)0 | ||
| 84 | -// free the p which represents a array | ||
| 85 | -#define srs_freepa(p) \ | ||
| 86 | - if (p) { \ | ||
| 87 | - delete[] p; \ | ||
| 88 | - p = NULL; \ | ||
| 89 | - } \ | ||
| 90 | - (void)0 | ||
| 91 | - | ||
| 92 | -// compare | ||
| 93 | -#define srs_min(a, b) (((a) < (b))? (a) : (b)) | ||
| 94 | -#define srs_max(a, b) (((a) < (b))? (b) : (a)) | ||
| 95 | - | ||
| 96 | -// signal defines. | ||
| 97 | -#define SIGNAL_RELOAD SIGHUP | ||
| 98 | - | ||
| 99 | -#include <string> | ||
| 100 | -// replace old_str to new_str of str | ||
| 101 | -extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str); | ||
| 102 | -// trim char in trim_chars of str | ||
| 103 | -extern std::string srs_string_trim_end(std::string str, std::string trim_chars); | ||
| 104 | -// trim char in trim_chars of str | ||
| 105 | -extern std::string srs_string_trim_start(std::string str, std::string trim_chars); | ||
| 106 | -// remove char in remove_chars of str | ||
| 107 | -extern std::string srs_string_remove(std::string str, std::string remove_chars); | ||
| 108 | -// whether string end with | ||
| 109 | -extern bool srs_string_ends_with(std::string str, std::string flag); | ||
| 110 | - | ||
| 111 | -// dns resolve utility, return the resolved ip address. | ||
| 112 | -extern std::string srs_dns_resolve(std::string host); | ||
| 113 | -// whether system is little endian | ||
| 114 | -extern bool srs_is_little_endian(); | ||
| 115 | - | ||
| 116 | -/** | ||
| 117 | -* disable copy constructor of class | ||
| 118 | -*/ | ||
| 119 | -#define disable_default_copy(className)\ | ||
| 120 | - private:\ | ||
| 121 | - /** \ | ||
| 122 | - * disable the copy constructor and operator=, donot allow directly copy. \ | ||
| 123 | - */ \ | ||
| 124 | - className(const className&); \ | ||
| 125 | - className& operator= (const className&) | ||
| 126 | - | ||
| 127 | -// const time for st to convert to us | ||
| 128 | -#define SRS_TIME_MILLISECONDS 1000 | ||
| 129 | -#define SRS_TIME_SECONDS 1000000 | ||
| 130 | - | ||
| 131 | -#endif | 1 | +/* |
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_CORE_HPP | ||
| 25 | +#define SRS_CORE_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_core.hpp> | ||
| 29 | +*/ | ||
| 30 | + | ||
| 31 | +// current release version | ||
| 32 | +#define VERSION_MAJOR "0" | ||
| 33 | +#define VERSION_MINOR "9" | ||
| 34 | +#define VERSION_REVISION "95" | ||
| 35 | +#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | ||
| 36 | +// server info. | ||
| 37 | +#define RTMP_SIG_SRS_KEY "srs" | ||
| 38 | +#define RTMP_SIG_SRS_ROLE "origin/edge server" | ||
| 39 | +#define RTMP_SIG_SRS_NAME RTMP_SIG_SRS_KEY"(simple rtmp server)" | ||
| 40 | +#define RTMP_SIG_SRS_URL_SHORT "github.com/winlinvip/simple-rtmp-server" | ||
| 41 | +#define RTMP_SIG_SRS_URL "https://"RTMP_SIG_SRS_URL_SHORT | ||
| 42 | +#define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin" | ||
| 43 | +#define RTMP_SIG_SRS_EMAIL "winlin@vip.126.com" | ||
| 44 | +#define RTMP_SIG_SRS_LICENSE "The MIT License (MIT)" | ||
| 45 | +#define RTMP_SIG_SRS_COPYRIGHT "Copyright (c) 2013-2014 winlin" | ||
| 46 | +#define RTMP_SIG_SRS_PRIMARY_AUTHROS "winlin,wenjie.zhao" | ||
| 47 | +#define RTMP_SIG_SRS_CONTRIBUTORS_URL RTMP_SIG_SRS_URL"/blob/master/AUTHORS.txt" | ||
| 48 | + | ||
| 49 | +/** | ||
| 50 | +* the core provides the common defined macros, utilities, | ||
| 51 | +* user must include the srs_core.hpp before any header, or maybe | ||
| 52 | +* build failed. | ||
| 53 | +*/ | ||
| 54 | + | ||
| 55 | +// for 32bit os, 2G big file limit for unistd io, | ||
| 56 | +// ie. read/write/lseek to use 64bits size for huge file. | ||
| 57 | +#ifndef _FILE_OFFSET_BITS | ||
| 58 | + #define _FILE_OFFSET_BITS 64 | ||
| 59 | +#endif | ||
| 60 | + | ||
| 61 | +// for int64_t print using PRId64 format. | ||
| 62 | +#ifndef __STDC_FORMAT_MACROS | ||
| 63 | + #define __STDC_FORMAT_MACROS | ||
| 64 | +#endif | ||
| 65 | +#include <inttypes.h> | ||
| 66 | + | ||
| 67 | +#include <assert.h> | ||
| 68 | +#define srs_assert(expression) assert(expression) | ||
| 69 | + | ||
| 70 | +#include <stddef.h> | ||
| 71 | +#include <sys/types.h> | ||
| 72 | + | ||
| 73 | +// generated by configure. | ||
| 74 | +#include <srs_auto_headers.hpp> | ||
| 75 | + | ||
| 76 | +// free the p and set to NULL. | ||
| 77 | +// p must be a T*. | ||
| 78 | +#define srs_freep(p) \ | ||
| 79 | + if (p) { \ | ||
| 80 | + delete p; \ | ||
| 81 | + p = NULL; \ | ||
| 82 | + } \ | ||
| 83 | + (void)0 | ||
| 84 | +// sometimes, the freepa is useless, | ||
| 85 | +// it's recomments to free each elem explicit. | ||
| 86 | +// so we remove the srs_freepa utility. | ||
| 87 | + | ||
| 88 | +// compare | ||
| 89 | +#define srs_min(a, b) (((a) < (b))? (a) : (b)) | ||
| 90 | +#define srs_max(a, b) (((a) < (b))? (b) : (a)) | ||
| 91 | + | ||
| 92 | +// signal defines. | ||
| 93 | +#define SIGNAL_RELOAD SIGHUP | ||
| 94 | + | ||
| 95 | +#include <string> | ||
| 96 | +// replace old_str to new_str of str | ||
| 97 | +extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str); | ||
| 98 | +// trim char in trim_chars of str | ||
| 99 | +extern std::string srs_string_trim_end(std::string str, std::string trim_chars); | ||
| 100 | +// trim char in trim_chars of str | ||
| 101 | +extern std::string srs_string_trim_start(std::string str, std::string trim_chars); | ||
| 102 | +// remove char in remove_chars of str | ||
| 103 | +extern std::string srs_string_remove(std::string str, std::string remove_chars); | ||
| 104 | +// whether string end with | ||
| 105 | +extern bool srs_string_ends_with(std::string str, std::string flag); | ||
| 106 | + | ||
| 107 | +// dns resolve utility, return the resolved ip address. | ||
| 108 | +extern std::string srs_dns_resolve(std::string host); | ||
| 109 | +// whether system is little endian | ||
| 110 | +extern bool srs_is_little_endian(); | ||
| 111 | + | ||
| 112 | +/** | ||
| 113 | +* disable copy constructor of class | ||
| 114 | +*/ | ||
| 115 | +#define disable_default_copy(className)\ | ||
| 116 | + private:\ | ||
| 117 | + /** \ | ||
| 118 | + * disable the copy constructor and operator=, donot allow directly copy. \ | ||
| 119 | + */ \ | ||
| 120 | + className(const className&); \ | ||
| 121 | + className& operator= (const className&) | ||
| 122 | + | ||
| 123 | +// const time for st to convert to us | ||
| 124 | +#define SRS_TIME_MILLISECONDS 1000 | ||
| 125 | +#define SRS_TIME_SECONDS 1000000 | ||
| 126 | + | ||
| 127 | +#endif |
| @@ -340,7 +340,7 @@ int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, | @@ -340,7 +340,7 @@ int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, | ||
| 340 | 340 | ||
| 341 | msg = new SrsSharedPtrMessage(); | 341 | msg = new SrsSharedPtrMessage(); |
| 342 | if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) { | 342 | if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) { |
| 343 | - srs_freepa(data); | 343 | + srs_freep(data); |
| 344 | return ret; | 344 | return ret; |
| 345 | } | 345 | } |
| 346 | } else if (type == SRS_RTMP_TYPE_VIDEO) { | 346 | } else if (type == SRS_RTMP_TYPE_VIDEO) { |
| @@ -349,7 +349,7 @@ int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, | @@ -349,7 +349,7 @@ int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, | ||
| 349 | 349 | ||
| 350 | msg = new SrsSharedPtrMessage(); | 350 | msg = new SrsSharedPtrMessage(); |
| 351 | if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) { | 351 | if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) { |
| 352 | - srs_freepa(data); | 352 | + srs_freep(data); |
| 353 | return ret; | 353 | return ret; |
| 354 | } | 354 | } |
| 355 | } else if (type == SRS_RTMP_TYPE_SCRIPT) { | 355 | } else if (type == SRS_RTMP_TYPE_SCRIPT) { |
| @@ -358,7 +358,7 @@ int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, | @@ -358,7 +358,7 @@ int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, | ||
| 358 | 358 | ||
| 359 | msg = new SrsSharedPtrMessage(); | 359 | msg = new SrsSharedPtrMessage(); |
| 360 | if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) { | 360 | if ((ret = msg->initialize(&header, data, size)) != ERROR_SUCCESS) { |
| 361 | - srs_freepa(data); | 361 | + srs_freep(data); |
| 362 | return ret; | 362 | return ret; |
| 363 | } | 363 | } |
| 364 | } | 364 | } |
| @@ -370,7 +370,7 @@ int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, | @@ -370,7 +370,7 @@ int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, | ||
| 370 | } | 370 | } |
| 371 | } else { | 371 | } else { |
| 372 | // directly free data if not sent out. | 372 | // directly free data if not sent out. |
| 373 | - srs_freepa(data); | 373 | + srs_freep(data); |
| 374 | } | 374 | } |
| 375 | 375 | ||
| 376 | return ret; | 376 | return ret; |
| @@ -336,10 +336,10 @@ namespace srs | @@ -336,10 +336,10 @@ namespace srs | ||
| 336 | void srs_key_block_free(key_block* key) | 336 | void srs_key_block_free(key_block* key) |
| 337 | { | 337 | { |
| 338 | if (key->random0) { | 338 | if (key->random0) { |
| 339 | - srs_freepa(key->random0); | 339 | + srs_freep(key->random0); |
| 340 | } | 340 | } |
| 341 | if (key->random1) { | 341 | if (key->random1) { |
| 342 | - srs_freepa(key->random1); | 342 | + srs_freep(key->random1); |
| 343 | } | 343 | } |
| 344 | } | 344 | } |
| 345 | 345 | ||
| @@ -427,10 +427,10 @@ namespace srs | @@ -427,10 +427,10 @@ namespace srs | ||
| 427 | void srs_digest_block_free(digest_block* digest) | 427 | void srs_digest_block_free(digest_block* digest) |
| 428 | { | 428 | { |
| 429 | if (digest->random0) { | 429 | if (digest->random0) { |
| 430 | - srs_freepa(digest->random0); | 430 | + srs_freep(digest->random0); |
| 431 | } | 431 | } |
| 432 | if (digest->random1) { | 432 | if (digest->random1) { |
| 433 | - srs_freepa(digest->random1); | 433 | + srs_freep(digest->random1); |
| 434 | } | 434 | } |
| 435 | } | 435 | } |
| 436 | 436 |
| @@ -192,9 +192,9 @@ SrsHandshakeBytes::SrsHandshakeBytes() | @@ -192,9 +192,9 @@ SrsHandshakeBytes::SrsHandshakeBytes() | ||
| 192 | 192 | ||
| 193 | SrsHandshakeBytes::~SrsHandshakeBytes() | 193 | SrsHandshakeBytes::~SrsHandshakeBytes() |
| 194 | { | 194 | { |
| 195 | - srs_freepa(c0c1); | ||
| 196 | - srs_freepa(s0s1s2); | ||
| 197 | - srs_freepa(c2); | 195 | + srs_freep(c0c1); |
| 196 | + srs_freep(s0s1s2); | ||
| 197 | + srs_freep(c2); | ||
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | int SrsHandshakeBytes::read_c0c1(ISrsProtocolReaderWriter* io) | 200 | int SrsHandshakeBytes::read_c0c1(ISrsProtocolReaderWriter* io) |
| @@ -1538,7 +1538,7 @@ SrsCommonMessage::SrsCommonMessage() | @@ -1538,7 +1538,7 @@ SrsCommonMessage::SrsCommonMessage() | ||
| 1538 | 1538 | ||
| 1539 | SrsCommonMessage::~SrsCommonMessage() | 1539 | SrsCommonMessage::~SrsCommonMessage() |
| 1540 | { | 1540 | { |
| 1541 | - srs_freepa(payload); | 1541 | + srs_freep(payload); |
| 1542 | } | 1542 | } |
| 1543 | 1543 | ||
| 1544 | SrsSharedPtrMessage::__SrsSharedPtr::__SrsSharedPtr() | 1544 | SrsSharedPtrMessage::__SrsSharedPtr::__SrsSharedPtr() |
| @@ -1550,7 +1550,7 @@ SrsSharedPtrMessage::__SrsSharedPtr::__SrsSharedPtr() | @@ -1550,7 +1550,7 @@ SrsSharedPtrMessage::__SrsSharedPtr::__SrsSharedPtr() | ||
| 1550 | 1550 | ||
| 1551 | SrsSharedPtrMessage::__SrsSharedPtr::~__SrsSharedPtr() | 1551 | SrsSharedPtrMessage::__SrsSharedPtr::~__SrsSharedPtr() |
| 1552 | { | 1552 | { |
| 1553 | - srs_freepa(payload); | 1553 | + srs_freep(payload); |
| 1554 | } | 1554 | } |
| 1555 | 1555 | ||
| 1556 | SrsSharedPtrMessage::SrsSharedPtrMessage() | 1556 | SrsSharedPtrMessage::SrsSharedPtrMessage() |
| @@ -1678,14 +1678,14 @@ int SrsPacket::encode(int& psize, char*& ppayload) | @@ -1678,14 +1678,14 @@ int SrsPacket::encode(int& psize, char*& ppayload) | ||
| 1678 | 1678 | ||
| 1679 | if ((ret = stream.initialize(payload, size)) != ERROR_SUCCESS) { | 1679 | if ((ret = stream.initialize(payload, size)) != ERROR_SUCCESS) { |
| 1680 | srs_error("initialize the stream failed. ret=%d", ret); | 1680 | srs_error("initialize the stream failed. ret=%d", ret); |
| 1681 | - srs_freepa(payload); | 1681 | + srs_freep(payload); |
| 1682 | return ret; | 1682 | return ret; |
| 1683 | } | 1683 | } |
| 1684 | } | 1684 | } |
| 1685 | 1685 | ||
| 1686 | if ((ret = encode_packet(&stream)) != ERROR_SUCCESS) { | 1686 | if ((ret = encode_packet(&stream)) != ERROR_SUCCESS) { |
| 1687 | srs_error("encode the packet failed. ret=%d", ret); | 1687 | srs_error("encode the packet failed. ret=%d", ret); |
| 1688 | - srs_freepa(payload); | 1688 | + srs_freep(payload); |
| 1689 | return ret; | 1689 | return ret; |
| 1690 | } | 1690 | } |
| 1691 | 1691 |
-
请 注册 或 登录 后发表评论