From 368356c223521a393a268ffd15b5ec73832da5be Mon Sep 17 00:00:00 2001 From: Winlin Date: Fri, 18 Nov 2022 11:19:01 +0800 Subject: [PATCH 1/4] Support address sanitizer for utest and fix some leaks. (#3242) * MP4: Fix memory leak when error. * Kernel: Support free global objects for utest. * HTTP: Fix memory leak when error. * MP4: Support more sample rate for audio. * RTMP: Support free field for utest. * UTest: Support address sanitizer. --- trunk/src/app/srs_app_conn.cpp | 7 ++ trunk/src/kernel/srs_kernel_codec.cpp | 55 +++++++++++ trunk/src/kernel/srs_kernel_codec.hpp | 8 ++ trunk/src/kernel/srs_kernel_mp4.cpp | 29 +++--- .../src/protocol/srs_protocol_http_stack.cpp | 2 + .../src/protocol/srs_protocol_rtmp_stack.cpp | 72 ++++++++++++++ .../src/protocol/srs_protocol_rtmp_stack.hpp | 22 +++++ trunk/src/protocol/srs_protocol_utility.cpp | 21 ++-- trunk/src/utest/srs_utest.cpp | 9 +- trunk/src/utest/srs_utest_amf0.cpp | 15 +-- trunk/src/utest/srs_utest_avc.cpp | 18 ++-- trunk/src/utest/srs_utest_http.cpp | 1 + trunk/src/utest/srs_utest_kernel.cpp | 66 +++++++++---- trunk/src/utest/srs_utest_protocol.cpp | 63 +++++++----- trunk/src/utest/srs_utest_rtc.cpp | 5 +- trunk/src/utest/srs_utest_rtmp.cpp | 96 ++++++++----------- trunk/src/utest/srs_utest_service.cpp | 19 ++-- trunk/src/utest/srs_utest_srt.cpp | 6 +- 18 files changed, 360 insertions(+), 154 deletions(-) diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp index b8a3e82a6..0fcada3a6 100644 --- a/trunk/src/app/srs_app_conn.cpp +++ b/trunk/src/app/srs_app_conn.cpp @@ -59,6 +59,13 @@ SrsResourceManager::~SrsResourceManager() clear(); + // Free all objects not in zombies. + std::vector::iterator it; + for (it = conns_.begin(); it != conns_.end(); ++it) { + ISrsResource* resource = *it; + srs_freep(resource); + } + srs_freepa(conns_level0_cache_); } diff --git a/trunk/src/kernel/srs_kernel_codec.cpp b/trunk/src/kernel/srs_kernel_codec.cpp index e62204ad7..799171796 100644 --- a/trunk/src/kernel/srs_kernel_codec.cpp +++ b/trunk/src/kernel/srs_kernel_codec.cpp @@ -68,6 +68,61 @@ string srs_audio_codec_id2str(SrsAudioCodecId codec) } } +SrsAudioSampleRate srs_audio_sample_rate_from_number(uint32_t v) +{ + if (v == 5512) return SrsAudioSampleRate5512; + if (v == 11025) return SrsAudioSampleRate11025; + if (v == 22050) return SrsAudioSampleRate22050; + if (v == 44100) return SrsAudioSampleRate44100; + + if (v == 12000) return SrsAudioSampleRate12000; + if (v == 24000) return SrsAudioSampleRate24000; + if (v == 48000) return SrsAudioSampleRate48000; + + if (v == 8000) return SrsAudioSampleRateNB8kHz; + if (v == 12000) return SrsAudioSampleRateMB12kHz; + if (v == 16000) return SrsAudioSampleRateWB16kHz; + if (v == 24000) return SrsAudioSampleRateSWB24kHz; + if (v == 48000) return SrsAudioSampleRateFB48kHz; + + return SrsAudioSampleRateForbidden; +} + +SrsAudioSampleRate srs_audio_sample_rate_guess_number(uint32_t v) +{ + if (v >= 48000) return SrsAudioSampleRate48000; + if (v >= 44100) return SrsAudioSampleRate44100; + if (v >= 24000) return SrsAudioSampleRate24000; + if (v >= 24000) return SrsAudioSampleRate24000; + if (v >= 22050) return SrsAudioSampleRate22050; + if (v >= 16000) return SrsAudioSampleRateWB16kHz; + if (v >= 12000) return SrsAudioSampleRate12000; + if (v >= 8000) return SrsAudioSampleRateNB8kHz; + if (v >= 5512) return SrsAudioSampleRate5512; + + return SrsAudioSampleRateForbidden; +} + +uint32_t srs_audio_sample_rate2number(SrsAudioSampleRate v) +{ + if (v == SrsAudioSampleRate5512) return 5512; + if (v == SrsAudioSampleRate11025) return 11025; + if (v == SrsAudioSampleRate22050) return 22050; + if (v == SrsAudioSampleRate44100) return 44100; + + if (v == SrsAudioSampleRate12000) return 12000; + if (v == SrsAudioSampleRate24000) return 24000; + if (v == SrsAudioSampleRate48000) return 48000; + + if (v == SrsAudioSampleRateNB8kHz) return 8000; + if (v == SrsAudioSampleRateMB12kHz) return 12000; + if (v == SrsAudioSampleRateWB16kHz) return 16000; + if (v == SrsAudioSampleRateSWB24kHz) return 24000; + if (v == SrsAudioSampleRateFB48kHz) return 48000; + + return 0; +} + string srs_audio_sample_rate2str(SrsAudioSampleRate v) { switch (v) { diff --git a/trunk/src/kernel/srs_kernel_codec.hpp b/trunk/src/kernel/srs_kernel_codec.hpp index dc4659cbf..e4f781bc4 100644 --- a/trunk/src/kernel/srs_kernel_codec.hpp +++ b/trunk/src/kernel/srs_kernel_codec.hpp @@ -196,6 +196,11 @@ enum SrsAudioSampleRate SrsAudioSampleRate11025 = 1, SrsAudioSampleRate22050 = 2, SrsAudioSampleRate44100 = 3, + + // For MP4, extra sampling rate to FLV. + SrsAudioSampleRate12000 = 12, + SrsAudioSampleRate24000 = 24, + SrsAudioSampleRate48000 = 48, // For Opus, support 8, 12, 16, 24, 48KHz // We will write a UINT8 sampling rate after FLV audio tag header. @@ -206,6 +211,9 @@ enum SrsAudioSampleRate SrsAudioSampleRateSWB24kHz = 24, // SWB (super-wideband) SrsAudioSampleRateFB48kHz = 48, // FB (fullband) }; +SrsAudioSampleRate srs_audio_sample_rate_from_number(uint32_t v); +SrsAudioSampleRate srs_audio_sample_rate_guess_number(uint32_t v); +uint32_t srs_audio_sample_rate2number(SrsAudioSampleRate v); std::string srs_audio_sample_rate2str(SrsAudioSampleRate v); /** diff --git a/trunk/src/kernel/srs_kernel_mp4.cpp b/trunk/src/kernel/srs_kernel_mp4.cpp index a8d990f67..fdc4f8c44 100644 --- a/trunk/src/kernel/srs_kernel_mp4.cpp +++ b/trunk/src/kernel/srs_kernel_mp4.cpp @@ -5237,6 +5237,8 @@ srs_error_t SrsMp4BoxReader::read(SrsSimpleStream* stream, SrsMp4Box** ppbox) srs_error_t err = srs_success; SrsMp4Box* box = NULL; + SrsAutoFree(SrsMp4Box, box); + while (true) { // For the first time to read the box, maybe it's a basic box which is only 4bytes header. // When we disconvery the real box, we know the size of the whole box, then read again and decode it. @@ -5277,10 +5279,9 @@ srs_error_t SrsMp4BoxReader::read(SrsSimpleStream* stream, SrsMp4Box** ppbox) continue; } - if (err != srs_success) { - srs_freep(box); - } else { + if (err == srs_success) { *ppbox = box; + box = NULL; } break; @@ -5352,6 +5353,7 @@ srs_error_t SrsMp4Decoder::initialize(ISrsReadSeeker* rs) while (true) { SrsMp4Box* box = NULL; + SrsAutoFree(SrsMp4Box, box); if ((err = load_next_box(&box, 0)) != srs_success) { return srs_error_wrap(err, "load box"); @@ -5375,8 +5377,6 @@ srs_error_t SrsMp4Decoder::initialize(ISrsReadSeeker* rs) } break; } - - srs_freep(box); } if (brand == SrsMp4BoxBrandForbidden) { @@ -5508,14 +5508,8 @@ srs_error_t SrsMp4Decoder::parse_moov(SrsMp4MovieBox* moov) SrsMp4AudioSampleEntry* mp4a = soun? soun->mp4a():NULL; if (mp4a) { uint32_t sr = mp4a->samplerate>>16; - if (sr >= 44100) { - sample_rate = SrsAudioSampleRate44100; - } else if (sr >= 22050) { - sample_rate = SrsAudioSampleRate22050; - } else if (sr >= 11025) { - sample_rate = SrsAudioSampleRate11025; - } else { - sample_rate = SrsAudioSampleRate5512; + if ((sample_rate = srs_audio_sample_rate_from_number(sr)) == SrsAudioSampleRateForbidden) { + sample_rate = srs_audio_sample_rate_guess_number(sr); } if (mp4a->samplesize == 16) { @@ -5580,16 +5574,17 @@ srs_error_t SrsMp4Decoder::load_next_box(SrsMp4Box** ppbox, uint32_t required_bo while (true) { SrsMp4Box* box = NULL; + SrsAutoFree(SrsMp4Box, box); + if ((err = do_load_next_box(&box, required_box_type)) != srs_success) { - srs_freep(box); return srs_error_wrap(err, "load box"); } if (!required_box_type || (uint32_t)box->type == required_box_type) { *ppbox = box; + box = NULL; break; } - srs_freep(box); } return err; @@ -5938,7 +5933,7 @@ srs_error_t SrsMp4Encoder::flush() SrsMp4AudioSampleEntry* mp4a = new SrsMp4AudioSampleEntry(); mp4a->data_reference_index = 1; - mp4a->samplerate = uint32_t(srs_flv_srates[sample_rate]) << 16; + mp4a->samplerate = srs_audio_sample_rate2number(sample_rate); if (sound_bits == SrsAudioSampleBits16bit) { mp4a->samplesize = 16; } else { @@ -6101,7 +6096,7 @@ SrsMp4ObjectType SrsMp4Encoder::get_audio_object_type() case SrsAudioCodecIdAAC: return SrsMp4ObjectTypeAac; case SrsAudioCodecIdMP3: - return (srs_flv_srates[sample_rate] > 24000) ? SrsMp4ObjectTypeMp1a : SrsMp4ObjectTypeMp3; // 11172 - 3 + return (srs_audio_sample_rate2number(sample_rate) > 24000) ? SrsMp4ObjectTypeMp1a : SrsMp4ObjectTypeMp3; // 11172 - 3 default: return SrsMp4ObjectTypeForbidden; } diff --git a/trunk/src/protocol/srs_protocol_http_stack.cpp b/trunk/src/protocol/srs_protocol_http_stack.cpp index ac579d4da..5de1ad4ac 100644 --- a/trunk/src/protocol/srs_protocol_http_stack.cpp +++ b/trunk/src/protocol/srs_protocol_http_stack.cpp @@ -689,12 +689,14 @@ srs_error_t SrsHttpServeMux::handle(std::string pattern, ISrsHttpHandler* handle srs_assert(handler); if (pattern.empty()) { + srs_freep(handler); return srs_error_new(ERROR_HTTP_PATTERN_EMPTY, "empty pattern"); } if (entries.find(pattern) != entries.end()) { SrsHttpMuxEntry* exists = entries[pattern]; if (exists->explicit_match) { + srs_freep(handler); return srs_error_new(ERROR_HTTP_PATTERN_DUPLICATED, "pattern=%s exists", pattern.c_str()); } } diff --git a/trunk/src/protocol/srs_protocol_rtmp_stack.cpp b/trunk/src/protocol/srs_protocol_rtmp_stack.cpp index 4f45d9efd..5d716eace 100644 --- a/trunk/src/protocol/srs_protocol_rtmp_stack.cpp +++ b/trunk/src/protocol/srs_protocol_rtmp_stack.cpp @@ -3331,6 +3331,12 @@ SrsCreateStreamPacket::~SrsCreateStreamPacket() srs_freep(command_object); } +void SrsCreateStreamPacket::set_command_object(SrsAmf0Any* v) +{ + srs_freep(command_object); + command_object = v; +} + srs_error_t SrsCreateStreamPacket::decode(SrsBuffer* stream) { srs_error_t err = srs_success; @@ -3509,6 +3515,12 @@ SrsFMLEStartPacket::~SrsFMLEStartPacket() srs_freep(command_object); } +void SrsFMLEStartPacket::set_command_object(SrsAmf0Any* v) +{ + srs_freep(command_object); + command_object = v; +} + srs_error_t SrsFMLEStartPacket::decode(SrsBuffer* stream) { srs_error_t err = srs_success; @@ -3613,6 +3625,18 @@ SrsFMLEStartResPacket::~SrsFMLEStartResPacket() srs_freep(args); } +void SrsFMLEStartResPacket::set_args(SrsAmf0Any* v) +{ + srs_freep(args); + args = v; +} + +void SrsFMLEStartResPacket::set_command_object(SrsAmf0Any* v) +{ + srs_freep(command_object); + command_object = v; +} + srs_error_t SrsFMLEStartResPacket::decode(SrsBuffer* stream) { srs_error_t err = srs_success; @@ -3691,6 +3715,12 @@ SrsPublishPacket::~SrsPublishPacket() srs_freep(command_object); } +void SrsPublishPacket::set_command_object(SrsAmf0Any* v) +{ + srs_freep(command_object); + command_object = v; +} + srs_error_t SrsPublishPacket::decode(SrsBuffer* stream) { srs_error_t err = srs_success; @@ -3961,6 +3991,18 @@ SrsPlayResPacket::~SrsPlayResPacket() srs_freep(desc); } +void SrsPlayResPacket::set_command_object(SrsAmf0Any* v) +{ + srs_freep(command_object); + command_object = v; +} + +void SrsPlayResPacket::set_desc(SrsAmf0Object* v) +{ + srs_freep(desc); + desc = v; +} + int SrsPlayResPacket::get_prefer_cid() { return RTMP_CID_OverStream; @@ -4012,6 +4054,12 @@ SrsOnBWDonePacket::~SrsOnBWDonePacket() srs_freep(args); } +void SrsOnBWDonePacket::set_args(SrsAmf0Any* v) +{ + srs_freep(args); + args = v; +} + int SrsOnBWDonePacket::get_prefer_cid() { return RTMP_CID_OverConnection; @@ -4061,6 +4109,18 @@ SrsOnStatusCallPacket::~SrsOnStatusCallPacket() srs_freep(data); } +void SrsOnStatusCallPacket::set_args(SrsAmf0Any* v) +{ + srs_freep(args); + args = v; +} + +void SrsOnStatusCallPacket::set_data(SrsAmf0Object* v) +{ + srs_freep(data); + data = v; +} + int SrsOnStatusCallPacket::get_prefer_cid() { return RTMP_CID_OverStream; @@ -4111,6 +4171,12 @@ SrsOnStatusDataPacket::~SrsOnStatusDataPacket() srs_freep(data); } +void SrsOnStatusDataPacket::set_data(SrsAmf0Object* v) +{ + srs_freep(data); + data = v; +} + int SrsOnStatusDataPacket::get_prefer_cid() { return RTMP_CID_OverStream; @@ -4198,6 +4264,12 @@ SrsOnMetaDataPacket::~SrsOnMetaDataPacket() srs_freep(metadata); } +void SrsOnMetaDataPacket::set_metadata(SrsAmf0Object* v) +{ + srs_freep(metadata); + metadata = v; +} + srs_error_t SrsOnMetaDataPacket::decode(SrsBuffer* stream) { srs_error_t err = srs_success; diff --git a/trunk/src/protocol/srs_protocol_rtmp_stack.hpp b/trunk/src/protocol/srs_protocol_rtmp_stack.hpp index 36bd0d28f..d9c76bb10 100644 --- a/trunk/src/protocol/srs_protocol_rtmp_stack.hpp +++ b/trunk/src/protocol/srs_protocol_rtmp_stack.hpp @@ -908,6 +908,8 @@ class SrsCreateStreamPacket : public SrsPacket public: SrsCreateStreamPacket(); virtual ~SrsCreateStreamPacket(); +public: + void set_command_object(SrsAmf0Any* v); // Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); @@ -982,6 +984,8 @@ class SrsFMLEStartPacket : public SrsPacket public: SrsFMLEStartPacket(); virtual ~SrsFMLEStartPacket(); +public: + void set_command_object(SrsAmf0Any* v); // Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); @@ -1014,6 +1018,9 @@ class SrsFMLEStartResPacket : public SrsPacket public: SrsFMLEStartResPacket(double _transaction_id); virtual ~SrsFMLEStartResPacket(); +public: + void set_args(SrsAmf0Any* v); + void set_command_object(SrsAmf0Any* v); // Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); @@ -1057,6 +1064,8 @@ class SrsPublishPacket : public SrsPacket public: SrsPublishPacket(); virtual ~SrsPublishPacket(); +public: + void set_command_object(SrsAmf0Any* v); // Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); @@ -1181,6 +1190,9 @@ class SrsPlayResPacket : public SrsPacket public: SrsPlayResPacket(); virtual ~SrsPlayResPacket(); +public: + void set_command_object(SrsAmf0Any* v); + void set_desc(SrsAmf0Object* v); // Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); @@ -1204,6 +1216,8 @@ class SrsOnBWDonePacket : public SrsPacket public: SrsOnBWDonePacket(); virtual ~SrsOnBWDonePacket(); +public: + void set_args(SrsAmf0Any* v); // Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); @@ -1232,6 +1246,9 @@ class SrsOnStatusCallPacket : public SrsPacket public: SrsOnStatusCallPacket(); virtual ~SrsOnStatusCallPacket(); +public: + void set_args(SrsAmf0Any* v); + void set_data(SrsAmf0Object* v); // Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); @@ -1255,6 +1272,9 @@ class SrsOnStatusDataPacket : public SrsPacket public: SrsOnStatusDataPacket(); virtual ~SrsOnStatusDataPacket(); +public: + void set_data(SrsAmf0Object* v); + SrsAmf0Object* get_data(); // Encode functions for concrete packet to override. public: virtual int get_prefer_cid(); @@ -1303,6 +1323,8 @@ class SrsOnMetaDataPacket : public SrsPacket public: SrsOnMetaDataPacket(); virtual ~SrsOnMetaDataPacket(); +public: + void set_metadata(SrsAmf0Object* v); // Decode functions for concrete packet to override. public: virtual srs_error_t decode(SrsBuffer* stream); diff --git a/trunk/src/protocol/srs_protocol_utility.cpp b/trunk/src/protocol/srs_protocol_utility.cpp index 46c561e24..c52d41b90 100644 --- a/trunk/src/protocol/srs_protocol_utility.cpp +++ b/trunk/src/protocol/srs_protocol_utility.cpp @@ -665,6 +665,17 @@ bool srs_net_device_is_internet(const sockaddr* addr) } vector _srs_system_ips; +void srs_free_global_system_ips() +{ + vector& ips = _srs_system_ips; + + // Release previous IPs. + for (int i = 0; i < (int)ips.size(); i++) { + SrsIPAddress* ip = ips[i]; + srs_freep(ip); + } + ips.clear(); +} void discover_network_iface(ifaddrs* cur, vector& ips, stringstream& ss0, stringstream& ss1, bool ipv6, bool loopback) { @@ -702,14 +713,10 @@ void discover_network_iface(ifaddrs* cur, vector& ips, stringstre void retrieve_local_ips() { - vector& ips = _srs_system_ips; - // Release previous IPs. - for (int i = 0; i < (int)ips.size(); i++) { - SrsIPAddress* ip = ips[i]; - srs_freep(ip); - } - ips.clear(); + srs_free_global_system_ips(); + + vector& ips = _srs_system_ips; // Get the addresses. ifaddrs* ifap; diff --git a/trunk/src/utest/srs_utest.cpp b/trunk/src/utest/srs_utest.cpp index 2c15cf541..df540bc23 100644 --- a/trunk/src/utest/srs_utest.cpp +++ b/trunk/src/utest/srs_utest.cpp @@ -81,6 +81,9 @@ srs_error_t prepare_main() { return err; } +// Free global data, for address sanitizer. +extern void srs_free_global_system_ips(); + // We could do something in the main of utest. // Copy from gtest-1.6.0/src/gtest_main.cc GTEST_API_ int main(int argc, char **argv) { @@ -97,7 +100,11 @@ GTEST_API_ int main(int argc, char **argv) { } testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + int r0 = RUN_ALL_TESTS(); + + srs_free_global_system_ips(); + + return r0; } MockEmptyLog::MockEmptyLog(SrsLogLevel l) diff --git a/trunk/src/utest/srs_utest_amf0.cpp b/trunk/src/utest/srs_utest_amf0.cpp index 78fe2c767..5991932dd 100644 --- a/trunk/src/utest/srs_utest_amf0.cpp +++ b/trunk/src/utest/srs_utest_amf0.cpp @@ -75,7 +75,7 @@ VOID TEST(ProtocolAMF0Test, ScenarioMain) EXPECT_EQ(0x03, bytes[0]); EXPECT_EQ(0x09, bytes[nb_bytes - 1]); } - SrsAutoFree(char, bytes); + SrsAutoFreeA(char, bytes); // decoding amf0 object from bytes // when user know the schema @@ -1301,7 +1301,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesString) EXPECT_TRUE(string("hello") == pp->to_str()); // For copy. - SrsAmf0Any* cp = p->copy(); + SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp); EXPECT_TRUE(string("hello") == cp->to_str()); } @@ -1430,7 +1430,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesBoolean) EXPECT_FALSE(p->to_boolean()); // For copy. - SrsAmf0Any* cp = p->copy(); + SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp); EXPECT_FALSE(cp->to_boolean()); } @@ -1527,7 +1527,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesNumber) EXPECT_TRUE(100.1 == p->to_number()); // For copy. - SrsAmf0Any* cp = p->copy(); + SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp); EXPECT_TRUE(100.1 == cp->to_number()); } @@ -1790,6 +1790,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesObject) // For copy. SrsAmf0Any* cp = p->copy(); + SrsAutoFree(SrsAmf0Any, cp); EXPECT_TRUE(NULL != cp->to_object()); } @@ -1992,7 +1993,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesObjectEOF) HELPER_EXPECT_SUCCESS(pp->read(&b)); // For copy. - SrsAmf0Any* cp = p->copy(); + SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp); EXPECT_TRUE(cp->is_object_eof()); } @@ -2084,7 +2085,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesEcmaArray) EXPECT_TRUE(NULL != pp->to_ecma_array()); // For copy. - SrsAmf0Any* cp = p->copy(); + SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp); EXPECT_TRUE(NULL != cp->to_ecma_array()); } @@ -2211,7 +2212,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesStrictArray) EXPECT_TRUE(NULL != pp->to_strict_array()); // For copy. - SrsAmf0Any* cp = p->copy(); + SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp); EXPECT_TRUE(NULL != cp->to_strict_array()); } diff --git a/trunk/src/utest/srs_utest_avc.cpp b/trunk/src/utest/srs_utest_avc.cpp index b464a7380..faf6d7745 100644 --- a/trunk/src/utest/srs_utest_avc.cpp +++ b/trunk/src/utest/srs_utest_avc.cpp @@ -222,7 +222,7 @@ VOID TEST(SrsAVCTest, H264IPBFrame) EXPECT_EQ(SrsVideoAvcFrameTraitSequenceHeader, uint8_t(flv[1])); EXPECT_EQ(01, flv[2]); EXPECT_EQ(02, flv[3]); EXPECT_EQ(03, flv[4]); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+5, 5).c_str()); - srs_freep(flv); + srs_freepa(flv); } // For muxing I/P/B frame. @@ -493,7 +493,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV) EXPECT_EQ(6, nb_flv); EXPECT_EQ(0x23, (uint8_t)flv[0]); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+1,5).c_str()); - srs_freep(flv); + srs_freepa(flv); } // For Opus frame. @@ -508,7 +508,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV) EXPECT_EQ(6, nb_flv); EXPECT_EQ(0xd3, (uint8_t)flv[0]); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+1,5).c_str()); - srs_freep(flv); + srs_freepa(flv); } // For Speex frame. @@ -523,7 +523,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV) EXPECT_EQ(6, nb_flv); EXPECT_EQ(0xb3, (uint8_t)flv[0]); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+1,5).c_str()); - srs_freep(flv); + srs_freepa(flv); } // For AAC frame. @@ -539,7 +539,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV) EXPECT_EQ(0xa3, (uint8_t)flv[0]); EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); - srs_freep(flv); + srs_freepa(flv); } if (true) { SrsRawAacStream h; @@ -553,7 +553,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV) EXPECT_EQ(0xa6, (uint8_t)flv[0]); EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); - srs_freep(flv); + srs_freepa(flv); } if (true) { SrsRawAacStream h; @@ -567,7 +567,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV) EXPECT_EQ(0xa5, (uint8_t)flv[0]); EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); - srs_freep(flv); + srs_freepa(flv); } if (true) { SrsRawAacStream h; @@ -581,7 +581,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV) EXPECT_EQ(0xa7, (uint8_t)flv[0]); EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); - srs_freep(flv); + srs_freepa(flv); } if (true) { SrsRawAacStream h; @@ -595,7 +595,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV) EXPECT_EQ(0xaf, (uint8_t)flv[0]); EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); - srs_freep(flv); + srs_freepa(flv); } } diff --git a/trunk/src/utest/srs_utest_http.cpp b/trunk/src/utest/srs_utest_http.cpp index 52efafd59..967586183 100644 --- a/trunk/src/utest/srs_utest_http.cpp +++ b/trunk/src/utest/srs_utest_http.cpp @@ -2081,6 +2081,7 @@ VOID TEST(ProtocolHTTPTest, QueryEscape) } else { HELPER_ASSERT_FAILED(SrsHttpUri::query_unescape(d.in, value)); } + srs_freep(d.err); } } diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index 16fc71a9b..461f1aeca 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -227,8 +227,11 @@ MockSrsFileReader::MockSrsFileReader(const char* src, int nb_src) seekable = true; uf = new MockSrsFile(); - uf->write((void*)src, nb_src, NULL); - uf->lseek(0, SEEK_SET, NULL); + srs_error_t err = uf->write((void*)src, nb_src, NULL); + srs_freep(err); + + err = uf->lseek(0, SEEK_SET, NULL); + srs_freep(err); } MockSrsFileReader::~MockSrsFileReader() @@ -255,20 +258,25 @@ bool MockSrsFileReader::is_open() int64_t MockSrsFileReader::tellg() { off_t offset = 0; - lseek(0, SEEK_CUR, &offset); + srs_error_t err = lseek(0, SEEK_CUR, &offset); + srs_freep(err); + return offset; } void MockSrsFileReader::skip(int64_t _size) { int64_t offset = tellg() + _size; - lseek(offset, SEEK_SET, NULL); + srs_error_t err = lseek(offset, SEEK_SET, NULL); + srs_freep(err); } int64_t MockSrsFileReader::seek2(int64_t _offset) { off_t offset = 0; - lseek(_offset, SEEK_SET, &offset); + srs_error_t err = lseek(_offset, SEEK_SET, &offset); + srs_freep(err); + return offset; } @@ -277,7 +285,8 @@ int64_t MockSrsFileReader::filesize() int64_t cur = tellg(); off_t offset = 0; - lseek(0, SEEK_END, &offset); + srs_error_t err = lseek(0, SEEK_END, &offset); + srs_freep(err); seek2(cur); return offset; @@ -298,7 +307,8 @@ srs_error_t MockSrsFileReader::lseek(off_t offset, int whence, off_t* seeked) void MockSrsFileReader::mock_append_data(const char* data, int size) { - uf->write((void*)data, size, NULL); + srs_error_t err = uf->write((void*)data, size, NULL); + srs_freep(err); } void MockSrsFileReader::mock_reset_offset() @@ -1127,6 +1137,11 @@ VOID TEST(KernelFLVTest, CoverVodStreamErrorCase) HELPER_EXPECT_FAILED(d.seek2(1)); } +} + +VOID TEST(KernelFLVTest, CoverVodStreamErrorCase2) +{ + srs_error_t err; if (true) { MockSrsFileReader r("HELLO", 5); @@ -3076,22 +3091,21 @@ VOID TEST(KernelUtility, RTMPUtils2) VOID TEST(KernelErrorTest, CoverAll) { + srs_error_t err; if (true) { - EXPECT_TRUE(srs_is_system_control_error(srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "err"))); - EXPECT_TRUE(srs_is_system_control_error(srs_error_new(ERROR_CONTROL_REPUBLISH, "err"))); - EXPECT_TRUE(srs_is_system_control_error(srs_error_new(ERROR_CONTROL_REDIRECT, "err"))); + EXPECT_TRUE(srs_is_system_control_error(err = srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "err"))); srs_freep(err); + EXPECT_TRUE(srs_is_system_control_error(err = srs_error_new(ERROR_CONTROL_REPUBLISH, "err"))); srs_freep(err); + EXPECT_TRUE(srs_is_system_control_error(err = srs_error_new(ERROR_CONTROL_REDIRECT, "err"))); srs_freep(err); } if (true) { - srs_error_t err = srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "control error"); - EXPECT_TRUE(srs_is_system_control_error(err)); - srs_freep(err); + EXPECT_TRUE(srs_is_system_control_error(err = srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "control error"))); srs_freep(err); } if (true) { - EXPECT_TRUE(srs_is_client_gracefully_close(srs_error_new(ERROR_SOCKET_READ, "err"))); - EXPECT_TRUE(srs_is_client_gracefully_close(srs_error_new(ERROR_SOCKET_READ_FULLY, "err"))); - EXPECT_TRUE(srs_is_client_gracefully_close(srs_error_new(ERROR_SOCKET_WRITE, "err"))); + EXPECT_TRUE(srs_is_client_gracefully_close(err = srs_error_new(ERROR_SOCKET_READ, "err"))); srs_freep(err); + EXPECT_TRUE(srs_is_client_gracefully_close(err = srs_error_new(ERROR_SOCKET_READ_FULLY, "err"))); srs_freep(err); + EXPECT_TRUE(srs_is_client_gracefully_close(err = srs_error_new(ERROR_SOCKET_WRITE, "err"))); srs_freep(err); } if (true) { @@ -5646,8 +5660,11 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder) 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c }; HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + + uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw); + SrsAutoFreeA(uint8_t, cp); HELPER_EXPECT_SUCCESS(enc.write_sample( - SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 0, 0, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw + SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 0, 0, cp, fmt.nb_raw )); } @@ -5656,8 +5673,11 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder) 0xaf, 0x00, 0x12, 0x10 }; HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + + uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw); + SrsAutoFreeA(uint8_t, cp); HELPER_EXPECT_SUCCESS(enc.write_sample( - SrsMp4HandlerTypeSOUN, 0x00, 0, 0, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw + SrsMp4HandlerTypeSOUN, 0x00, 0, 0, cp, fmt.nb_raw )); } @@ -5672,8 +5692,11 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder) 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e }; HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); + + uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw); + SrsAutoFreeA(uint8_t, cp); HELPER_EXPECT_SUCCESS(enc.write_sample( - SrsMp4HandlerTypeSOUN, 0x00, 34, 34, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw + SrsMp4HandlerTypeSOUN, 0x00, 34, 34, cp, fmt.nb_raw )); } @@ -5691,8 +5714,11 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder) 0xb2, 0x72, 0x5a }; HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); + + uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw); + SrsAutoFreeA(uint8_t, cp); HELPER_EXPECT_SUCCESS(enc.write_sample( - SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 40, 40, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw + SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 40, 40, cp, fmt.nb_raw )); } diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index da1cd56b1..1b15e9b20 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -85,6 +85,8 @@ MockBufferIO::MockBufferIO() MockBufferIO::~MockBufferIO() { + srs_freep(in_err); + srs_freep(out_err); } int MockBufferIO::length() @@ -397,7 +399,7 @@ VOID TEST(ProtocolHandshakeTest, VerifyFPC0C1) // manually validate the c1 // @see: calc_c1_digest char* c1s1_joined_bytes = new char[1536 -32]; - SrsAutoFree(char, c1s1_joined_bytes); + SrsAutoFreeA(char, c1s1_joined_bytes); HELPER_ASSERT_SUCCESS( c1.payload->copy_to(&c1, c1s1_joined_bytes, 1536 - 32, false)); bool is_valid; @@ -599,6 +601,13 @@ VOID TEST(ProtocolUtilityTest, GenerateTcUrl) EXPECT_STREQ("rtmp://demo:19351/live", tcUrl.c_str()); } +void srs_utest_free_message_array(SrsMessageArray* arr) +{ + for (int i = 0; i < arr->max; i++) { + srs_freep(arr->msgs[i]); + } +} + /** * shared ptr message array test */ @@ -614,6 +623,9 @@ VOID TEST(ProtocolMsgArrayTest, MessageArray) if (true) { SrsMessageArray arr(3); + + SrsMessageArray* parr = &arr; + SrsAutoFreeH(SrsMessageArray, parr, srs_utest_free_message_array); arr.msgs[0] = msg.copy(); EXPECT_EQ(1, msg.count()); @@ -624,18 +636,21 @@ VOID TEST(ProtocolMsgArrayTest, MessageArray) arr.msgs[2] = msg.copy(); EXPECT_EQ(3, msg.count()); } - EXPECT_EQ(3, msg.count()); + EXPECT_EQ(0, msg.count()); if (true) { SrsMessageArray arr(3); + + SrsMessageArray* parr = &arr; + SrsAutoFreeH(SrsMessageArray, parr, srs_utest_free_message_array); arr.msgs[0] = msg.copy(); - EXPECT_EQ(4, msg.count()); + EXPECT_EQ(1, msg.count()); arr.msgs[2] = msg.copy(); - EXPECT_EQ(5, msg.count()); + EXPECT_EQ(2, msg.count()); } - EXPECT_EQ(5, msg.count()); + EXPECT_EQ(0, msg.count()); } /** @@ -2720,7 +2735,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendVMessage) uint8_t data[] = {0x01, 0x02, 0x03, 0x04}; - SrsCommonMessage* msg = new SrsCommonMessage(); + SrsCommonMessage* msg = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, msg); msg->size = sizeof(data); msg->payload = new char[msg->size]; memcpy(msg->payload, data, msg->size); @@ -2831,7 +2846,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsCreateStreamPacket) SrsProtocol proto(&bio); SrsCreateStreamPacket* pkt = new SrsCreateStreamPacket(); - pkt->command_object = SrsAmf0Any::null(); + pkt->set_command_object(SrsAmf0Any::null()); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); char buf[] = { @@ -2856,7 +2871,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartPacket) SrsFMLEStartPacket* pkt = new SrsFMLEStartPacket(); pkt->command_name = "FMLEStart"; - pkt->command_object = SrsAmf0Any::null(); + pkt->set_command_object(SrsAmf0Any::null()); pkt->stream_name = "livestream"; HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); @@ -2885,8 +2900,8 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartResPacket) SrsFMLEStartResPacket* pkt = new SrsFMLEStartResPacket(1); pkt->command_name = "FMLEStart"; - pkt->command_object = SrsAmf0Any::null(); - pkt->args = args; + pkt->set_command_object(SrsAmf0Any::null()); + pkt->set_args(args); args->set("stream" , SrsAmf0Any::str("livestream")); args->set("start" , SrsAmf0Any::number(0)); @@ -2914,7 +2929,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsPublishPacket) SrsPublishPacket* pkt = new SrsPublishPacket(); pkt->command_name = "publish"; - pkt->command_object = SrsAmf0Any::null(); + pkt->set_command_object(SrsAmf0Any::null()); pkt->stream_name = "livestream"; pkt->type = "live"; @@ -2945,8 +2960,8 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsPlayResPacket) SrsPlayResPacket* pkt = new SrsPlayResPacket(); pkt->command_name = "_result"; - pkt->command_object = SrsAmf0Any::null(); - pkt->desc = args; + pkt->set_command_object(SrsAmf0Any::null()); + pkt->set_desc(args); args->set("stream" , SrsAmf0Any::str("livestream")); args->set("start" , SrsAmf0Any::number(0)); @@ -2979,7 +2994,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnBWDonePacket) SrsOnBWDonePacket* pkt = new SrsOnBWDonePacket(); pkt->command_name = "onBWDone"; - pkt->args = SrsAmf0Any::null(); + pkt->set_args(SrsAmf0Any::null()); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); char buf[] = { @@ -3009,8 +3024,8 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusCallPacket) SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket(); pkt->command_name = "onStatus"; - pkt->args = SrsAmf0Any::null(); - pkt->data = args; + pkt->set_args(SrsAmf0Any::null()); + pkt->set_data(args); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); char buf[] = { @@ -3045,7 +3060,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusDataPacket) SrsOnStatusDataPacket* pkt = new SrsOnStatusDataPacket(); pkt->command_name = "onData"; - pkt->data = args; + pkt->set_data(args); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); char buf[] = { @@ -3104,7 +3119,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnMetaDataPacket) SrsOnMetaDataPacket* pkt = new SrsOnMetaDataPacket(); pkt->name = "onMetaData"; - pkt->metadata = args; + pkt->set_metadata(args); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); uint8_t buf[] = { @@ -3299,7 +3314,7 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow) } if (true) { - SrsCommonMessage* msg = new SrsCommonMessage(); + SrsCommonMessage* msg = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, msg); msg->header.payload_length = msg->size = 4096; msg->payload = new char[msg->size]; @@ -3340,15 +3355,14 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow) } // recv auto send acked size. #1 if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_ASSERT_SUCCESS(proto.recv_message(&msg)); - SrsAutoFree(SrsCommonMessage, msg); ASSERT_TRUE(msg->header.is_ackledgement()); } // send again if (true) { - SrsCommonMessage* msg = new SrsCommonMessage(); + SrsCommonMessage* msg = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, msg); msg->header.payload_length = msg->size = 4096; msg->payload = new char[msg->size]; @@ -3425,12 +3439,11 @@ VOID TEST(ProtocolStackTest, ProtocolPingFlow) } // recv ping if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_ASSERT_SUCCESS(proto.recv_message(&msg)); - SrsAutoFree(SrsCommonMessage, msg); ASSERT_TRUE(msg->header.is_user_control_message()); - SrsPacket* pkt = NULL; + SrsPacket* pkt = NULL; SrsAutoFree(SrsPacket, pkt); HELPER_ASSERT_SUCCESS(proto.decode_message(msg, &pkt)); SrsUserControlPacket* spkt = dynamic_cast(pkt); ASSERT_TRUE(spkt != NULL); diff --git a/trunk/src/utest/srs_utest_rtc.cpp b/trunk/src/utest/srs_utest_rtc.cpp index 42f8993c1..467347f76 100644 --- a/trunk/src/utest/srs_utest_rtc.cpp +++ b/trunk/src/utest/srs_utest_rtc.cpp @@ -68,7 +68,7 @@ VOID TEST(KernelRTCTest, RtpSTAPPayloadException) EXPECT_TRUE(nalu_type == kStapA); ISrsRtpPayloader* payload = new SrsRtpSTAPPayload(); - EXPECT_TRUE((err = payload->decode(&buf)) != srs_success); + HELPER_ASSERT_FAILED(payload->decode(&buf)); srs_freep(payload); } @@ -710,7 +710,8 @@ VOID TEST(KernelRTCTest, NACKFetchRTPPacket) SrsRtcPlayStream play(&s, SrsContextId()); SrsRtcTrackDescription ds; - SrsRtcVideoSendTrack *track = new SrsRtcVideoSendTrack(&s, &ds); + SrsRtcVideoSendTrack* track = new SrsRtcVideoSendTrack(&s, &ds); + SrsAutoFree(SrsRtcVideoSendTrack, track); // The RTP queue will free the packet. if (true) { diff --git a/trunk/src/utest/srs_utest_rtmp.cpp b/trunk/src/utest/srs_utest_rtmp.cpp index 09e266223..b668f193a 100644 --- a/trunk/src/utest/srs_utest_rtmp.cpp +++ b/trunk/src/utest/srs_utest_rtmp.cpp @@ -435,10 +435,9 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages) // Always response ACK message. HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1)); - SrsCommonMessage* msg; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); io.in_buffer.append(&bytes); HELPER_EXPECT_FAILED(p.recv_message(&msg)); - srs_freep(msg); } } @@ -884,8 +883,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage) uint8_t bytes[] = {0x01, 0x00, 0x00}; io.in_buffer.append((char*)bytes, sizeof(bytes)); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_FAILED(p.recv_message(&msg)); } @@ -896,8 +894,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage) uint8_t bytes[] = {0x00, 0x00}; io.in_buffer.append((char*)bytes, sizeof(bytes)); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_FAILED(p.recv_message(&msg)); } @@ -908,8 +905,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage) uint8_t bytes[] = {0x00}; io.in_buffer.append((char*)bytes, sizeof(bytes)); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_FAILED(p.recv_message(&msg)); } @@ -917,8 +913,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage) MockBufferIO io; SrsProtocol p(&io); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_FAILED(p.recv_message(&msg)); } } @@ -934,8 +929,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2) uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3}; io.in_buffer.append((char*)bytes, sizeof(bytes)); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_FAILED(p.recv_message(&msg)); } @@ -948,10 +942,12 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2) uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3}; io.in_buffer.append((char*)bytes, sizeof(bytes)); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); - HELPER_EXPECT_FAILED(p.recv_message(&msg)); + if (true) { + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); + HELPER_EXPECT_FAILED(p.recv_message(&msg)); + } + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); uint8_t bytes2[] = {0x43, 0,0,0, 0,0,5, 0, 0,0,0,0, 1,2,3}; io.in_buffer.append((char*)bytes2, sizeof(bytes2)); HELPER_EXPECT_FAILED(p.recv_message(&msg)); @@ -964,8 +960,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2) uint8_t bytes[] = {0x03}; io.in_buffer.append((char*)bytes, sizeof(bytes)); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_FAILED(p.recv_message(&msg)); } @@ -976,8 +971,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2) uint8_t bytes[] = {0x43, 0,0,0, 0,0,0, 0}; io.in_buffer.append((char*)bytes, sizeof(bytes)); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_FAILED(p.recv_message(&msg)); } } @@ -1060,8 +1054,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4) io.in_buffer.append(&io.out_buffer); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); EXPECT_EQ(256, p.out_chunk_size); @@ -1078,8 +1071,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4) io.in_buffer.append(&io.out_buffer); - SrsCommonMessage* msg; - SrsAutoFree(SrsCommonMessage, msg); + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); EXPECT_EQ(256, p.in_buffer_length); @@ -1534,9 +1526,8 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage) SrsProtocol p(&tio); - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); - srs_freep(msg); EXPECT_EQ(1024, p.in_chunk_size); } @@ -2239,7 +2230,7 @@ VOID TEST(ProtocolRTMPTest, CoverAll) EXPECT_EQ(0, r.get_recv_bytes()); EXPECT_EQ(0, r.get_send_bytes()); - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_FAILED(r.recv_message(&msg)); SrsCallPacket* pkt = new SrsCallPacket(); @@ -2262,7 +2253,7 @@ VOID TEST(ProtocolRTMPTest, CoverAll) EXPECT_EQ(0, r.get_recv_bytes()); EXPECT_EQ(0, r.get_send_bytes()); - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_FAILED(r.recv_message(&msg)); SrsCallPacket* pkt = new SrsCallPacket(); @@ -2585,8 +2576,8 @@ VOID TEST(ProtocolRTMPTest, ConnectAppWithArgs) if (true) { tio.in_buffer.append(&io.out_buffer); - SrsCommonMessage* msg = NULL; - SrsConnectAppPacket* pkt = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); + SrsConnectAppPacket* pkt = NULL; SrsAutoFree(SrsConnectAppPacket, pkt); HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt)); SrsAmf0Any* prop = pkt->command_object->get_property("tcUrl"); @@ -2616,9 +2607,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec) } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); - srs_freep(msg); } } @@ -2633,14 +2623,11 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec) } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_ASSERT_SUCCESS(p.recv_message(&msg)); - SrsPacket* pkt = NULL; + SrsPacket* pkt = NULL; SrsAutoFree(SrsPacket, pkt); HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt)); - - srs_freep(msg); - srs_freep(pkt); } } @@ -2655,9 +2642,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec) } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); - srs_freep(msg); } } @@ -2672,14 +2658,11 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec) } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_ASSERT_SUCCESS(p.recv_message(&msg)); - SrsPacket* pkt = NULL; + SrsPacket* pkt = NULL; SrsAutoFree(SrsPacket, pkt); HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt)); - - srs_freep(msg); - srs_freep(pkt); } } } @@ -2733,17 +2716,15 @@ VOID TEST(ProtocolRTMPTest, CheckStreamID) } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); EXPECT_EQ(1, msg->header.stream_id); - srs_freep(msg); } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); EXPECT_EQ(2, msg->header.stream_id); - srs_freep(msg); } } } @@ -2767,9 +2748,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform) } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); - srs_freep(msg); } } @@ -2788,9 +2768,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform) } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); - srs_freep(msg); } } @@ -2809,9 +2788,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform) } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); - srs_freep(msg); } } @@ -2830,9 +2808,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform) } if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); - srs_freep(msg); } } } @@ -2865,9 +2842,8 @@ VOID TEST(ProtocolRTMPTest, MergeReadHandler) r.set_merge_read(true, &h); if (true) { - SrsCommonMessage* msg = NULL; + SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg); HELPER_EXPECT_SUCCESS(r.recv_message(&msg)); - srs_freep(msg); } EXPECT_TRUE(h.nn > 0); @@ -2925,6 +2901,8 @@ VOID TEST(ProtocolRTMPTest, CreateRTMPMessage) } } +extern void srs_utest_free_message_array(SrsMessageArray* arr); + VOID TEST(ProtocolRTMPTest, OthersAll) { if (true) { @@ -2995,6 +2973,10 @@ VOID TEST(ProtocolRTMPTest, OthersAll) if (true) { SrsMessageArray h(10); + + SrsMessageArray* parr = &h; + SrsAutoFreeH(SrsMessageArray, parr, srs_utest_free_message_array); + h.msgs[0] = new SrsSharedPtrMessage(); h.msgs[1] = new SrsSharedPtrMessage(); EXPECT_TRUE(NULL != h.msgs[0]); diff --git a/trunk/src/utest/srs_utest_service.cpp b/trunk/src/utest/srs_utest_service.cpp index b93cc2f9d..f5f059206 100644 --- a/trunk/src/utest/srs_utest_service.cpp +++ b/trunk/src/utest/srs_utest_service.cpp @@ -636,6 +636,7 @@ VOID TEST(HTTPServerTest, ContentLength) SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); + SrsAutoFree(ISrsHttpMessage, msg); char buf[32]; ssize_t nread = 0; ISrsHttpResponseReader* r = msg->body_reader(); @@ -664,6 +665,7 @@ VOID TEST(HTTPServerTest, HTTPChunked) SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); + SrsAutoFree(ISrsHttpMessage, msg); char buf[32]; ssize_t nread = 0; ISrsHttpResponseReader* r = msg->body_reader(); @@ -720,6 +722,7 @@ VOID TEST(HTTPServerTest, InfiniteChunked) SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); + SrsAutoFree(ISrsHttpMessage, msg); char buf[32]; ssize_t nread = 0; ISrsHttpResponseReader* r = msg->body_reader(); @@ -1110,7 +1113,7 @@ VOID TEST(TCPServerTest, CoverUtility) hints.ai_family = AF_INET; addrinfo* r = NULL; - SrsAutoFree(addrinfo, r); + SrsAutoFreeH(addrinfo, r, freeaddrinfo); ASSERT_TRUE(!getaddrinfo("127.0.0.1", NULL, &hints, &r)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); @@ -1123,7 +1126,7 @@ VOID TEST(TCPServerTest, CoverUtility) hints.ai_family = AF_INET; addrinfo* r = NULL; - SrsAutoFree(addrinfo, r); + SrsAutoFreeH(addrinfo, r, freeaddrinfo); ASSERT_TRUE(!getaddrinfo("192.168.0.1", NULL, &hints, &r)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); @@ -1168,7 +1171,7 @@ VOID TEST(TCPServerTest, CoverUtility) hints.ai_family = AF_INET6; addrinfo* r = NULL; - SrsAutoFree(addrinfo, r); + SrsAutoFreeH(addrinfo, r, freeaddrinfo); ASSERT_TRUE(!getaddrinfo("2001:da8:6000:291:21f:d0ff:fed4:928c", NULL, &hints, &r)); EXPECT_TRUE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); @@ -1179,7 +1182,7 @@ VOID TEST(TCPServerTest, CoverUtility) hints.ai_family = AF_INET6; addrinfo* r = NULL; - SrsAutoFree(addrinfo, r); + SrsAutoFreeH(addrinfo, r, freeaddrinfo); ASSERT_TRUE(!getaddrinfo("3ffe:dead:beef::1", NULL, &hints, &r)); EXPECT_TRUE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); @@ -1192,7 +1195,7 @@ VOID TEST(TCPServerTest, CoverUtility) hints.ai_family = AF_INET6; addrinfo* r = NULL; - SrsAutoFree(addrinfo, r); + SrsAutoFreeH(addrinfo, r, freeaddrinfo); ASSERT_TRUE(!getaddrinfo("::", NULL, &hints, &r)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); @@ -1205,7 +1208,7 @@ VOID TEST(TCPServerTest, CoverUtility) hints.ai_family = AF_INET6; addrinfo* r = NULL; - SrsAutoFree(addrinfo, r); + SrsAutoFreeH(addrinfo, r, freeaddrinfo); ASSERT_TRUE(!getaddrinfo("fec0::", NULL, &hints, &r)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); @@ -1218,7 +1221,7 @@ VOID TEST(TCPServerTest, CoverUtility) hints.ai_family = AF_INET6; addrinfo* r = NULL; - SrsAutoFree(addrinfo, r); + SrsAutoFreeH(addrinfo, r, freeaddrinfo); ASSERT_TRUE(!getaddrinfo("FE80::", NULL, &hints, &r)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); @@ -1231,7 +1234,7 @@ VOID TEST(TCPServerTest, CoverUtility) hints.ai_family = AF_INET6; addrinfo* r = NULL; - SrsAutoFree(addrinfo, r); + SrsAutoFreeH(addrinfo, r, freeaddrinfo); ASSERT_TRUE(!getaddrinfo("::1", NULL, &hints, &r)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); diff --git a/trunk/src/utest/srs_utest_srt.cpp b/trunk/src/utest/srs_utest_srt.cpp index ff2cd0a26..773df5cb8 100644 --- a/trunk/src/utest/srs_utest_srt.cpp +++ b/trunk/src/utest/srs_utest_srt.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -194,6 +195,7 @@ VOID TEST(ServiceStSRTTest, ListenConnectAccept) HELPER_EXPECT_SUCCESS(srs_srt_socket(&srt_client_fd)); SrsSrtSocket* srt_client_socket = new SrsSrtSocket(_srt_eventloop->poller(), srt_client_fd); + SrsAutoFree(SrsSrtSocket, srt_client_socket); // No client connected, accept will timeout. srs_srt_t srt_fd = srs_srt_socket_invalid(); @@ -202,6 +204,7 @@ VOID TEST(ServiceStSRTTest, ListenConnectAccept) err = srt_server.accept(&srt_fd); EXPECT_EQ(srs_error_code(err), ERROR_SRT_TIMEOUT); EXPECT_EQ(srt_fd, srs_srt_socket_invalid()); + srs_freep(err); // Client connect to server HELPER_EXPECT_SUCCESS(srt_client_socket->connect(server_ip, server_port)); @@ -308,6 +311,7 @@ VOID TEST(ServiceStSRTTest, ReadWrite) // Recv msg from client, but client no send any msg, so will be timeout. err = srt_server_accepted_socket->recvmsg(buf, sizeof(buf), &nb_read); EXPECT_EQ(srs_error_code(err), ERROR_SRT_TIMEOUT); + srs_freep(err); } } @@ -524,7 +528,7 @@ VOID TEST(ServiceSRTTest, Encrypt) if (true) { int pbkeylens[4] = {0, 16, 24, 32}; - for (int i = 0; i < sizeof(pbkeylens) / sizeof(pbkeylens[0]); ++i) { + for (int i = 0; i < (int)(sizeof(pbkeylens) / sizeof(pbkeylens[0])); ++i) { srs_srt_t srt_client_fd = srs_srt_socket_invalid(); HELPER_EXPECT_SUCCESS(srs_srt_socket_with_default_option(&srt_client_fd)); HELPER_EXPECT_SUCCESS(srs_srt_set_streamid(srt_client_fd, streamid)); From d3441d23aede8e16c31f3b4603c1f1d14883901a Mon Sep 17 00:00:00 2001 From: Winlin Date: Fri, 18 Nov 2022 18:14:17 +0800 Subject: [PATCH 2/4] For #2532: Windows: Replace ln by cp for windows. v5.0.87 (#3246) 1. Replase ln by cp for windows. 2. Refine OS and CPU arch detecting. 3. Support configure from any directory by `SRS_WORKDIR`. 4. Support output to any directory by `SRS_OUTPUT`. 5. Disable sanitizer for gperf. 6. Use parallels build for make. 7. Refine bash variable check. --- .gitignore | 1 + trunk/auto/apps.sh | 17 +- trunk/auto/auto_headers.sh | 50 +-- trunk/auto/codecov.sh | 4 +- trunk/auto/depends.sh | 538 ++++++++++++--------------- trunk/auto/modules.sh | 21 +- trunk/auto/options.sh | 131 ++++--- trunk/auto/setup_variables.sh | 24 +- trunk/auto/summary.sh | 38 +- trunk/auto/utest.sh | 21 +- trunk/configure | 244 ++++++------ trunk/doc/CHANGELOG.md | 1 + trunk/src/core/srs_core_version5.hpp | 2 +- 13 files changed, 536 insertions(+), 556 deletions(-) diff --git a/.gitignore b/.gitignore index 02e8ffa57..066cff572 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ .idea .DS_Store +*.heap cmake-build-debug /trunk/ide/srs_clion/CMakeCache.txt diff --git a/trunk/auto/apps.sh b/trunk/auto/apps.sh index 55c2e4b26..eedb8d931 100755 --- a/trunk/auto/apps.sh +++ b/trunk/auto/apps.sh @@ -2,8 +2,7 @@ # # params: # $SRS_OBJS the objs directory to store the Makefile. ie. ./objs -# $SRS_OBJS_DIR the objs directory for Makefile. ie. objs -# $SRS_MAKEFILE the makefile name. ie. Makefile +# $SRS_OBJS the objs directory for Makefile. ie. objs # # $MAIN_ENTRANCES array, disable all except the $APP_MAIN itself. ie. ["srs_main_server"] # $APP_MAIN the object file that contains main function. ie. srs_main_server @@ -13,9 +12,9 @@ # $ModuleLibFiles array, the 3rdpart library file to link with. ie. [objs/st-1.9/obj/libst.a objs/libx264/obj/libx264.a] # $LINK_OPTIONS the linker options. ie. -ldl -FILE=${SRS_OBJS}/${SRS_MAKEFILE} +FILE=${SRS_OBJS}/Makefile -APP_TARGET="${SRS_OBJS_DIR}/${APP_NAME}" +APP_TARGET="${SRS_OBJS}/${APP_NAME}" echo "Generating app ${APP_NAME} depends."; @@ -40,15 +39,16 @@ for item in ${MODULE_OBJS[*]}; do fi done - if [ ! -f ${item} ]; then + if [ ! -f ${SRS_WORKDIR}/${item} ]; then ignored=1 fi if [ ${ignored} == 1 ]; then + echo "Ignore file ${FILE_NAME}" continue; fi - OBJ_FILE=${SRS_OBJS_DIR}/$item + OBJ_FILE=${SRS_OBJS}/$item OBJ_FILE="${OBJ_FILE%.*}.o" echo -n "${OBJ_FILE} " >> ${FILE} done @@ -71,15 +71,16 @@ for item in ${MODULE_OBJS[*]}; do fi done - if [ ! -f ${item} ]; then + if [ ! -f ${SRS_WORKDIR}/${item} ]; then ignored=1 fi if [ ${ignored} == 1 ]; then + echo "Ignore file ${FILE_NAME}" continue; fi - OBJ_FILE=${SRS_OBJS_DIR}/$item + OBJ_FILE=${SRS_OBJS}/$item OBJ_FILE="${OBJ_FILE%.*}.o" echo -n "${OBJ_FILE} " >> ${FILE} done diff --git a/trunk/auto/auto_headers.sh b/trunk/auto/auto_headers.sh index 41863deb4..53650def1 100755 --- a/trunk/auto/auto_headers.sh +++ b/trunk/auto/auto_headers.sh @@ -44,67 +44,67 @@ function srs_undefine_macro() # generate auto headers file, depends on the finished of options.sh ##################################################################################### # auto headers in depends. -if [ $SRS_HDS = YES ]; then +if [[ $SRS_HDS == YES ]]; then srs_define_macro "SRS_HDS" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_HDS" $SRS_AUTO_HEADERS_H fi -if [ $SRS_SRT = YES ]; then +if [[ $SRS_SRT == YES ]]; then srs_define_macro "SRS_SRT" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_SRT" $SRS_AUTO_HEADERS_H fi -if [ $SRS_CXX11 = YES ]; then +if [[ $SRS_CXX11 == YES ]]; then srs_define_macro "SRS_CXX11" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_CXX11" $SRS_AUTO_HEADERS_H fi -if [ $SRS_CXX14 = YES ]; then +if [[ $SRS_CXX14 == YES ]]; then srs_define_macro "SRS_CXX14" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_CXX14" $SRS_AUTO_HEADERS_H fi -if [ $SRS_BACKTRACE = YES ]; then +if [[ $SRS_BACKTRACE == YES ]]; then srs_define_macro "SRS_BACKTRACE" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_BACKTRACE" $SRS_AUTO_HEADERS_H fi -if [ $SRS_RTC = YES ]; then +if [[ $SRS_RTC == YES ]]; then srs_define_macro "SRS_RTC" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_RTC" $SRS_AUTO_HEADERS_H fi -if [ $SRS_FFMPEG_FIT = YES ]; then +if [[ $SRS_FFMPEG_FIT == YES ]]; then srs_define_macro "SRS_FFMPEG_FIT" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_FFMPEG_FIT" $SRS_AUTO_HEADERS_H fi -if [ $SRS_SIMULATOR = YES ]; then +if [[ $SRS_SIMULATOR == YES ]]; then srs_define_macro "SRS_SIMULATOR" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_SIMULATOR" $SRS_AUTO_HEADERS_H fi -if [ $SRS_HTTPS = YES ]; then +if [[ $SRS_HTTPS == YES ]]; then srs_define_macro "SRS_HTTPS" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_HTTPS" $SRS_AUTO_HEADERS_H fi -if [ $SRS_GB28181 = YES ]; then +if [[ $SRS_GB28181 == YES ]]; then srs_define_macro "SRS_GB28181" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_GB28181" $SRS_AUTO_HEADERS_H fi -if [ $SRS_UTEST = YES ]; then +if [[ $SRS_UTEST == YES ]]; then srs_define_macro "SRS_UTEST" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_UTEST" $SRS_AUTO_HEADERS_H @@ -112,33 +112,33 @@ fi # whatever the FFMPEG tools, if transcode and ingest specified, # srs always compile the FFMPEG tool stub which used to start the FFMPEG process. -if [ $SRS_FFMPEG_STUB = YES ]; then +if [[ $SRS_FFMPEG_STUB == YES ]]; then srs_define_macro "SRS_FFMPEG_STUB" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_FFMPEG_STUB" $SRS_AUTO_HEADERS_H fi -if [ $SRS_GPERF = YES ]; then +if [[ $SRS_GPERF == YES ]]; then srs_define_macro "SRS_GPERF" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_GPERF" $SRS_AUTO_HEADERS_H fi -if [ $SRS_GPERF_MC = YES ]; then +if [[ $SRS_GPERF_MC == YES ]]; then srs_define_macro "SRS_GPERF_MC" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_GPERF_MC" $SRS_AUTO_HEADERS_H fi -if [ $SRS_GPERF_MD = YES ]; then +if [[ $SRS_GPERF_MD == YES ]]; then srs_define_macro "SRS_GPERF_MD" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_GPERF_MD" $SRS_AUTO_HEADERS_H fi -if [ $SRS_GPERF_MP = YES ]; then +if [[ $SRS_GPERF_MP == YES ]]; then srs_define_macro "SRS_GPERF_MP" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_GPERF_MP" $SRS_AUTO_HEADERS_H fi -if [ $SRS_GPERF_CP = YES ]; then +if [[ $SRS_GPERF_CP == YES ]]; then srs_define_macro "SRS_GPERF_CP" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_GPERF_CP" $SRS_AUTO_HEADERS_H @@ -148,44 +148,44 @@ fi # for embeded. ##################################################################################### # for log level compile settings -if [ $SRS_LOG_VERBOSE = YES ]; then +if [[ $SRS_LOG_VERBOSE == YES ]]; then srs_define_macro "SRS_VERBOSE" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_VERBOSE" $SRS_AUTO_HEADERS_H fi -if [ $SRS_LOG_INFO = YES ]; then +if [[ $SRS_LOG_INFO == YES ]]; then srs_define_macro "SRS_INFO" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_INFO" $SRS_AUTO_HEADERS_H fi -if [ $SRS_LOG_TRACE = YES ]; then +if [[ $SRS_LOG_TRACE == YES ]]; then srs_define_macro "SRS_TRACE" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_TRACE" $SRS_AUTO_HEADERS_H fi -if [ $SRS_LOG_LEVEL_V2 = YES ]; then +if [[ $SRS_LOG_LEVEL_V2 == YES ]]; then srs_define_macro "SRS_LOG_LEVEL_V2" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_LOG_LEVEL_V2" $SRS_AUTO_HEADERS_H fi -if [ $SRS_CROSS_BUILD = YES ]; then +if [[ $SRS_CROSS_BUILD == YES ]]; then srs_define_macro "SRS_CROSSBUILD" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_CROSSBUILD" $SRS_AUTO_HEADERS_H fi -if [ $SRS_OSX = YES ]; then +if [[ $SRS_OSX == YES ]]; then srs_define_macro "SRS_OSX" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_OSX" $SRS_AUTO_HEADERS_H fi -if [ $SRS_DEBUG = YES ]; then +if [[ $SRS_DEBUG == YES ]]; then srs_define_macro "SRS_DEBUG" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_DEBUG" $SRS_AUTO_HEADERS_H fi -if [ $SRS_DEBUG_STATS = YES ]; then +if [[ $SRS_DEBUG_STATS == YES ]]; then srs_define_macro "SRS_DEBUG_STATS" $SRS_AUTO_HEADERS_H else srs_undefine_macro "SRS_DEBUG_STATS" $SRS_AUTO_HEADERS_H diff --git a/trunk/auto/codecov.sh b/trunk/auto/codecov.sh index 7bdcbc73e..c6b9a61d5 100755 --- a/trunk/auto/codecov.sh +++ b/trunk/auto/codecov.sh @@ -1,12 +1,12 @@ #!/bin/bash # In .circleci/config.yml, generate *.gcno with -# ./configure --gcov --without-research --without-librtmp && make utest +# ./configure --gcov && make utest # and generate *.gcda by # ./objs/srs_utest # Workdir is objs/cover. -workdir=`pwd`/objs/cover +workdir=$(cd `dirname $0`/.. && pwd)/objs/cover # Create trunk under workdir. mkdir -p $workdir && cd $workdir diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index b1d0857ea..d6996d193 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -14,8 +14,7 @@ ##################################################################################### # utilities ##################################################################################### -function require_sudoer() -{ +function require_sudoer() { sudo echo "" >/dev/null 2>&1 ret=$?; if [[ 0 -ne $ret ]]; then @@ -24,18 +23,10 @@ function require_sudoer() fi } -# TODO: check gcc/g++ -echo "Checking gcc/g++/gdb/make." -echo "Required tools are ok." ##################################################################################### # for Ubuntu, auto install tools by apt-get ##################################################################################### -OS_IS_UBUNTU=NO -function Ubuntu_prepare() -{ - # For Debian, we think it's ubuntu also. - # For example, the wheezy/sid which is debian armv7 linux, can not identified by uname -v. - OS_IS_UBUNTU=$(apt-get --version >/dev/null 2>&1 && echo YES) +function Ubuntu_prepare() { if [[ $OS_IS_UBUNTU != YES ]]; then return 0; fi echo "Installing tools for Ubuntu." @@ -125,10 +116,7 @@ Ubuntu_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for ubuntu ##################################################################################### # for Centos, auto install tools by yum ##################################################################################### -OS_IS_CENTOS=NO -function Centos_prepare() -{ - OS_IS_CENTOS=$(yum --version >/dev/null 2>&1 && echo YES) +function Centos_prepare() { if [[ $OS_IS_CENTOS != YES ]]; then return 0; fi echo "Installing tools for Centos." @@ -215,31 +203,22 @@ Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for CentOS ##################################################################################### # For OSX, auto install tools by brew ##################################################################################### -OS_IS_OSX=NO -function OSX_prepare() -{ - uname -s|grep Darwin >/dev/null 2>&1 - ret=$?; if [[ 0 -ne $ret ]]; then - if [ $SRS_OSX = YES ]; then - echo "OSX check failed, actual is `uname -s`" - exit 1; - fi - return 0; +function OSX_prepare() { + if [[ $OS_IS_OSX != YES ]]; then + if [[ $SRS_OSX == YES ]]; then echo "OSX check failed, actual is `uname -s`"; exit 1; fi + return 0 fi # cross build for arm, install the cross build tool chain. - if [ $SRS_CROSS_BUILD = YES ]; then + if [[ $SRS_CROSS_BUILD == YES ]]; then echo "The embeded(arm/mips) is invalid for OSX" return 1 fi - OS_IS_OSX=YES - # requires the osx when os - if [ $OS_IS_OSX = YES ]; then - if [ $SRS_OSX = NO ]; then - echo "OSX detected, please use: ./configure --osx" - exit 1 - fi + # Requires the osx when darwin detected + if [[ $OS_IS_OSX == YES && $SRS_OSX != YES ]]; then + echo "OSX detected, please use: ./configure --osx" + exit 1 fi echo "OSX detected, install tools if needed" @@ -312,68 +291,34 @@ function OSX_prepare() OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$ret"; exit $ret; fi ##################################################################################### -# Detect CPU archs. -##################################################################################### -OS_IS_LOONGARCH64=$(g++ -dM -E - /dev/null|head -n 1) if [[ -d $SOURCE_DIR ]]; then @@ -423,27 +368,22 @@ fi _ST_MAKE_ARGS="${_ST_MAKE} STATIC_ONLY=${_ST_STATIC_ONLY}" _ST_MAKE_ARGS="${_ST_MAKE_ARGS} CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB}" # Patched ST from https://github.com/ossrs/state-threads/tree/srs -if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/libst.a ]]; then - echo "The state-threads is ok."; +if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st/libst.a ]]; then + rm -rf ${SRS_OBJS}/st && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st ${SRS_OBJS}/ && + echo "The state-threads is ok." else - echo "Building state-threads."; - ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && - # Create a hidden directory .src - cd ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && ln -sf ../../../3rdparty/st-srs .src && - # Link source files under .src - _srs_link_file .src/ ./ ./ && - # Build source code. - env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make ${_ST_MAKE_ARGS} && - cd .. && rm -rf st && ln -sf st-srs/${_ST_OBJ} st - ) + echo "Building state-threads." && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st ${SRS_OBJS}/st && + cp -rf ${SRS_WORKDIR}/3rdparty/st-srs ${SRS_OBJS}/${SRS_PLATFORM}/ && + env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${_ST_MAKE_ARGS} && + mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st && + cp -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/st.h ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st/ && + cp -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/libst.a ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st/ && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st ${SRS_OBJS}/ && + echo "The state-threads is ok." fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build state-threads failed, ret=$ret"; exit $ret; fi -# Always update the links. -(cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf st && ln -sf st-srs/${_ST_OBJ} st) -(cd ${SRS_OBJS} && rm -rf st && ln -sf ${SRS_PLATFORM}/st-srs/${_ST_OBJ} st) -if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "Build state-threads static lib failed."; exit -1; fi ##################################################################################### # nginx for HLS, nginx-1.5.0 @@ -462,43 +402,48 @@ mkdir -p ${SRS_OBJS}/nginx # the demo dir. # create forward dir mkdir -p ${SRS_OBJS}/nginx/html/live && -html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5 +html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5 && # copy players to nginx html dir. rm -rf ${SRS_OBJS}/nginx/html/players && -ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players +cp -rf $SRS_WORKDIR/research/players ${SRS_OBJS}/nginx/html/ && # for favicon.ico rm -rf ${SRS_OBJS}/nginx/html/favicon.ico && -ln -sf `pwd`/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico +cp -f $SRS_WORKDIR/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico && # For srs-console. rm -rf ${SRS_OBJS}/nginx/html/console && -ln -sf `pwd`/research/console ${SRS_OBJS}/nginx/html/console +cp -rf $SRS_WORKDIR/research/console ${SRS_OBJS}/nginx/html/ && # For SRS signaling. rm -rf ${SRS_OBJS}/nginx/html/demos && -ln -sf `pwd`/3rdparty/signaling/www/demos ${SRS_OBJS}/nginx/html/demos +cp -rf $SRS_WORKDIR/3rdparty/signaling/www/demos ${SRS_OBJS}/nginx/html/ && # For home page index.html rm -rf ${SRS_OBJS}/nginx/html/index.html && -ln -sf `pwd`/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html +cp -f $SRS_WORKDIR/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html && # nginx.html to detect whether nginx is alive echo "Nginx is ok." > ${SRS_OBJS}/nginx/html/nginx.html +# check status +ret=$?; if [[ $ret -ne 0 ]]; then echo "Build web pages failed, ret=$ret"; exit $ret; fi + ##################################################################################### # Generate default self-sign certificate for HTTPS server, test only. ##################################################################################### -if [[ ! -f conf/server.key || ! -f conf/server.crt ]]; then - openssl genrsa -out conf/server.key 2048 - openssl req -new -x509 -key conf/server.key -out conf/server.crt -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net" +if [[ ! -f $SRS_WORKDIR/conf/server.key || ! -f $SRS_WORKDIR/conf/server.crt ]]; then + openssl genrsa -out $SRS_WORKDIR/conf/server.key 2048 && + openssl req -new -x509 -key $SRS_WORKDIR/conf/server.key -out $SRS_WORKDIR/conf/server.crt -days 3650 \ + -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net" && echo "Generate test-only self-sign certificate files" fi ##################################################################################### # cherrypy for http hooks callback, CherryPy-3.2.4 ##################################################################################### +# TODO: FIXME: Replace by Go. if [[ $SRS_CHERRYPY == YES ]]; then # Detect python or python2 python --version >/dev/null 2>&1 && SYS_PYTHON=python; @@ -520,13 +465,13 @@ if [[ $SRS_CHERRYPY == YES ]]; then echo "Link players to cherrypy static-dir" rm -rf research/api-server/static-dir/players && - ln -sf `pwd`/research/players research/api-server/static-dir/players && + ln -sf $SRS_WORKDIR/research/players research/api-server/static-dir/players && rm -rf research/api-server/static-dir/live && - mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live && - ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live && + mkdir -p $SRS_WORKDIR/${SRS_OBJS}/nginx/html/live && + ln -sf $SRS_WORKDIR/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live && rm -rf research/api-server/static-dir/forward && - mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward && - ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward + mkdir -p $SRS_WORKDIR/${SRS_OBJS}/nginx/html/forward && + ln -sf $SRS_WORKDIR/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward ret=$?; if [[ $ret -ne 0 ]]; then echo "Warning: Ignore error to link players to cherrypy static-dir."; fi fi @@ -548,14 +493,14 @@ if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then if [[ $SRS_CROSS_BUILD_ARCH == "arm" ]]; then OPENSSL_CONFIG="./Configure linux-armv4"; fi if [[ $SRS_CROSS_BUILD_ARCH == "aarch64" ]]; then OPENSSL_CONFIG="./Configure linux-aarch64"; fi if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" ]]; then OPENSSL_CONFIG="./Configure linux-mips32"; fi - elif [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/libssl.a ]]; then + elif [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl/lib/libssl.a ]]; then # Try to use exists libraries. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == NO ]]; then - (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && - ln -sf /usr/local/ssl/lib/libssl.a && ln -sf /usr/local/ssl/lib/libcrypto.a && - mkdir -p /usr/local/ssl/lib/pkgconfig && ln -sf /usr/local/ssl/lib/pkgconfig) - (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && - ln -sf /usr/local/ssl/include/openssl) + (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl/lib && + cp /usr/local/ssl/lib/libssl.a . && cp /usr/local/ssl/lib/libcrypto.a . && + mkdir -p /usr/local/ssl/lib/pkgconfig && cp -rf /usr/local/ssl/lib/pkgconfig .) + (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl/include && + cp -rf /usr/local/ssl/include/openssl .) fi # Warning if not use the system ssl. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == YES ]]; then @@ -579,10 +524,12 @@ if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then # Use 1.0 if required. if [[ $SRS_SSL_1_0 == YES ]]; then OPENSSL_AR="$SRS_TOOL_AR -r" # For openssl 1.0, MUST specifies the args for ar or build faild. - OPENSSL_CANDIDATE="openssl-OpenSSL_1_0_2u" && OPENSSL_UNZIP="tar xf ../../3rdparty/$OPENSSL_CANDIDATE.tar.gz" + OPENSSL_CANDIDATE="openssl-OpenSSL_1_0_2u" && + OPENSSL_UNZIP="tar xf ${SRS_WORKDIR}/3rdparty/$OPENSSL_CANDIDATE.tar.gz -C ${SRS_OBJS}/${SRS_PLATFORM}" else OPENSSL_AR="$SRS_TOOL_AR" - OPENSSL_CANDIDATE="openssl-1.1-fit" && OPENSSL_UNZIP="cp -R ../../3rdparty/$OPENSSL_CANDIDATE ." + OPENSSL_CANDIDATE="openssl-1.1-fit" && + OPENSSL_UNZIP="cp -R ${SRS_WORKDIR}/3rdparty/$OPENSSL_CANDIDATE ${SRS_OBJS}/${SRS_PLATFORM}/" fi # # https://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options @@ -593,28 +540,26 @@ if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then #OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-ssl2 -no-comp -no-idea -no-hw -no-engine -no-dso -no-err -no-nextprotoneg -no-psk -no-srp -no-ec2m -no-weak-ssl-ciphers" # # cross build not specified, if exists flag, need to rebuild for no-arm platform. - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/$OPENSSL_CANDIDATE/_release/lib/libssl.a ]]; then - echo "The $OPENSSL_CANDIDATE is ok."; + if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl/lib/libssl.a ]]; then + rm -rf ${SRS_OBJS}/openssl && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl ${SRS_OBJS}/ && + echo "The $OPENSSL_CANDIDATE is ok." else - echo "Building $OPENSSL_CANDIDATE."; + echo "Building $OPENSSL_CANDIDATE." && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl \ + ${SRS_OBJS}/openssl && + ${OPENSSL_UNZIP} && ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} && cd ${SRS_OBJS}/${SRS_PLATFORM} && - ${OPENSSL_UNZIP} && cd $OPENSSL_CANDIDATE && ${OPENSSL_CONFIG} --prefix=`pwd`/_release $OPENSSL_OPTIONS && - make CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && make install_sw && - cd .. && rm -rf openssl && ln -sf $OPENSSL_CANDIDATE/_release openssl - ) - fi - # Which lib we use. - OPENSSL_LIB="$OPENSSL_CANDIDATE/_release" - if [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_LIB}/lib/libssl.a ]]; then - OPENSSL_LIB="openssl" + cd ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} && + ${OPENSSL_CONFIG} --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdpatry/openssl $OPENSSL_OPTIONS + ) && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" \ + LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} install_sw && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl ${SRS_OBJS}/ && + echo "The $OPENSSL_CANDIDATE is ok." fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build $OPENSSL_CANDIDATE failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf openssl && ln -sf $OPENSSL_CANDIDATE/_release openssl) - (cd ${SRS_OBJS} && rm -rf openssl && ln -sf ${SRS_PLATFORM}/${OPENSSL_LIB} openssl) - if [ ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]; then echo "Build $OPENSSL_CANDIDATE failed."; exit -1; fi fi ##################################################################################### @@ -631,68 +576,69 @@ if [[ $SRS_RTC == YES ]]; then # If use ASM for SRTP, we enable openssl(with ASM). if [[ $SRS_SRTP_ASM == YES ]]; then SRTP_OPTIONS="--enable-openssl" - SRTP_CONFIGURE="env PKG_CONFIG_PATH=$(cd ${SRS_OBJS}/${SRS_PLATFORM} && pwd)/openssl/lib/pkgconfig ./configure" + SRTP_CONFIGURE="env PKG_CONFIG_PATH=${SRS_DEPENDS_LIBS}/openssl/lib/pkgconfig ./configure" else + SRTP_OPTIONS="--disable-openssl" SRTP_CONFIGURE="./configure" fi if [[ $SRS_CROSS_BUILD == YES ]]; then SRTP_OPTIONS="$SRTP_OPTIONS --host=$SRS_CROSS_BUILD_HOST" fi - if [[ $OS_IS_LOONGARCH64 = YES ]]; then + if [[ $OS_IS_LOONGARCH64 == YES ]]; then SRTP_OPTIONS="$SRTP_OPTIONS --build=loongarch64-unknown-linux-gnu" fi - # Patched ST from https://github.com/ossrs/state-threads/tree/srs - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/_release/lib/libsrtp2.a ]]; then - echo "The libsrtp-2-fit is ok."; + # Copy and patch source files, then build and install libsrtp. + if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srtp2/lib/libsrtp2.a ]]; then + rm -rf ${SRS_OBJS}/srtp2 && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srtp2 ${SRS_OBJS} && + echo "The libsrtp-2-fit is ok." else - echo "Building libsrtp-2-fit."; + echo "Building libsrtp-2-fit." + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srtp2 \ + ${SRS_OBJS}/srtp2 && + cp -rf ${SRS_WORKDIR}/3rdparty/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/ && + patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c ${SRS_WORKDIR}/3rdparty/patches/srtp/gcc10-01.patch && + patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/config.guess ${SRS_WORKDIR}/3rdparty/patches/srtp/config.guess-02.patch && ( - rm -rf ${SRS_OBJS}/srtp2 && cd ${SRS_OBJS}/${SRS_PLATFORM} && - rm -rf libsrtp-2-fit && cp -R ../../3rdparty/libsrtp-2-fit . && cd libsrtp-2-fit && - patch -p0 crypto/math/datatypes.c ../../../3rdparty/patches/srtp/gcc10-01.patch && - patch -p0 config.guess ../../../3rdparty/patches/srtp/config.guess-02.patch && - $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=`pwd`/_release && - make ${SRS_JOBS} && make install && - cd .. && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2 - ) - fi - # check status - ret=$?; if [[ $ret -ne 0 ]]; then echo "Build libsrtp-2-fit failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2) - (cd ${SRS_OBJS} && rm -rf srtp2 && ln -sf ${SRS_PLATFORM}/libsrtp-2-fit/_release srtp2) - if [ ! -f ${SRS_OBJS}/srtp2/lib/libsrtp2.a ]; then echo "Build libsrtp-2-fit static lib failed."; exit -1; fi + cd ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit && + $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdpatry/srtp2 + ) && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit ${SRS_JOBS} && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit install && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srtp2 ${SRS_OBJS}/ && + echo "The libsrtp-2-fit is ok." + fi + ret=$?; if [[ $ret -ne 0 ]]; then echo "Build libsrtp failed, ret=$ret"; exit $ret; fi fi ##################################################################################### # libopus, for WebRTC to transcode AAC with Opus. ##################################################################################### # For cross build, we use opus of FFmpeg, so we don't build the libopus. -if [[ $SRS_RTC == YES && $SRS_CROSS_BUILD == NO ]]; then +if [[ $SRS_RTC == YES && $SRS_CROSS_BUILD != YES ]]; then # Only build static libraries if no shared FFmpeg. if [[ $SRS_SHARED_FFMPEG == NO ]]; then OPUS_OPTIONS="--disable-shared --disable-doc" fi - if [[ $OS_IS_LOONGARCH64 = YES ]]; then + if [[ $OS_IS_LOONGARCH64 == YES ]]; then OPUS_OPTIONS="$OPUS_OPTIONS --build=loongarch64-unknown-linux-gnu" fi - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1/_release/lib/libopus.a ]]; then - echo "The opus-1.3.1 is ok."; + if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/opus/lib/libopus.a ]]; then + rm -rf ${SRS_OBJS}/opus && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/opus ${SRS_OBJS}/ && + echo "The opus-1.3.1 is ok." else - echo "Building opus-1.3.1."; + echo "Building opus-1.3.1." && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/opus ${SRS_OBJS}/opus && + tar xf ${SRS_WORKDIR}/3rdparty/opus-1.3.1.tar.gz -C ${SRS_OBJS}/${SRS_PLATFORM} && ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && cd ${SRS_OBJS}/${SRS_PLATFORM} && - tar xf ../../3rdparty/opus-1.3.1.tar.gz && cd opus-1.3.1 && - ./configure --prefix=`pwd`/_release --enable-static $OPUS_OPTIONS && - make ${SRS_JOBS} && make install && - cd .. && rm -rf opus && ln -sf opus-1.3.1/_release opus - ) + cd ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && + ./configure --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdpatry/opus --enable-static $OPUS_OPTIONS + ) && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 ${SRS_JOBS} && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 install && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/opus ${SRS_OBJS}/ && + echo "The opus-1.3.1 is ok." fi - # check status - ret=$?; if [[ $ret -ne 0 ]]; then echo "Build opus-1.3.1 failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf opus && ln -sf opus-1.3.1/_release opus) - (cd ${SRS_OBJS} && rm -rf opus && ln -sf ${SRS_PLATFORM}/opus-1.3.1/_release opus) if [ ! -f ${SRS_OBJS}/opus/lib/libopus.a ]; then echo "Build opus-1.3.1 failed."; exit -1; fi fi @@ -704,7 +650,7 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then if [[ $SRS_CROSS_BUILD == YES ]]; then FFMPEG_CONFIGURE=./configure else - FFMPEG_CONFIGURE="env PKG_CONFIG_PATH=$(cd ${SRS_OBJS}/${SRS_PLATFORM} && pwd)/opus/lib/pkgconfig ./configure" + FFMPEG_CONFIGURE="env PKG_CONFIG_PATH=${SRS_DEPENDS_LIBS}/opus/lib/pkgconfig ./configure" fi # Disable all asm for FFmpeg, to compatible with ARM CPU. @@ -731,17 +677,18 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=libopus --enable-encoder=libopus --enable-libopus" fi - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/_release/lib/libavcodec.a ]]; then - echo "The ffmpeg-4-fit is ok."; + if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/ffmpeg/lib/libavcodec.a ]]; then + rm -rf ${SRS_OBJS}/ffmpeg && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/ffmpeg ${SRS_OBJS}/ && + echo "The ffmpeg-4-fit is ok." else - echo "Building ffmpeg-4-fit."; + echo "Building ffmpeg-4-fit." && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/ffmpeg \ + ${SRS_OBJS}/ffmpeg && + cp -rf ${SRS_WORKDIR}/3rdparty/ffmpeg-4-fit ${SRS_OBJS}/${SRS_PLATFORM}/ && ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && - # Create a hidden directory .src - cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && cp -R ../../../3rdparty/ffmpeg-4-fit/* . && - # Build source code. + cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && $FFMPEG_CONFIGURE \ - --prefix=`pwd`/_release --pkg-config=pkg-config \ + --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdpatry/ffmpeg --pkg-config=pkg-config \ --pkg-config-flags="--static" --extra-libs="-lpthread" --extra-libs="-lm" \ --disable-everything ${FFMPEG_OPTIONS} \ --disable-programs --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages \ @@ -751,56 +698,54 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then --disable-d3d11va --disable-dxva2 --disable-ffnvcodec --disable-nvdec --disable-nvenc --disable-v4l2-m2m --disable-vaapi \ --disable-vdpau --disable-appkit --disable-coreimage --disable-avfoundation --disable-securetransport --disable-iconv \ --disable-lzma --disable-sdl2 --enable-decoder=aac --enable-decoder=aac_fixed --enable-decoder=aac_latm \ - --enable-encoder=aac && - # See https://www.laoyuyu.me/2019/05/23/android/clang_compile_ffmpeg/ - if [[ $SRS_CROSS_BUILD == YES ]]; then - sed -i -e 's/#define getenv(x) NULL/\/\*#define getenv(x) NULL\*\//g' config.h && - sed -i -e 's/#define HAVE_GMTIME_R 0/#define HAVE_GMTIME_R 1/g' config.h && - sed -i -e 's/#define HAVE_LOCALTIME_R 0/#define HAVE_LOCALTIME_R 1/g' config.h && - # For MIPS, which fail with: - # ./libavutil/libm.h:54:32: error: static declaration of 'cbrt' follows non-static declaration - # /root/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.4.0_musl/include/math.h:163:13: note: previous declaration of 'cbrt' was here - if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" || $SRS_CROSS_BUILD_ARCH == "arm" ]]; then - sed -i -e 's/#define HAVE_CBRT 0/#define HAVE_CBRT 1/g' config.h && - sed -i -e 's/#define HAVE_CBRTF 0/#define HAVE_CBRTF 1/g' config.h && - sed -i -e 's/#define HAVE_COPYSIGN 0/#define HAVE_COPYSIGN 1/g' config.h && - sed -i -e 's/#define HAVE_ERF 0/#define HAVE_ERF 1/g' config.h && - sed -i -e 's/#define HAVE_HYPOT 0/#define HAVE_HYPOT 1/g' config.h && - sed -i -e 's/#define HAVE_RINT 0/#define HAVE_RINT 1/g' config.h && - sed -i -e 's/#define HAVE_LRINT 0/#define HAVE_LRINT 1/g' config.h && - sed -i -e 's/#define HAVE_LRINTF 0/#define HAVE_LRINTF 1/g' config.h && - sed -i -e 's/#define HAVE_ROUND 0/#define HAVE_ROUND 1/g' config.h && - sed -i -e 's/#define HAVE_ROUNDF 0/#define HAVE_ROUNDF 1/g' config.h && - sed -i -e 's/#define HAVE_TRUNC 0/#define HAVE_TRUNC 1/g' config.h && - sed -i -e 's/#define HAVE_TRUNCF 0/#define HAVE_TRUNCF 1/g' config.h - fi - fi && - make ${SRS_JOBS} && make install && - cd .. && rm -rf ffmpeg && ln -sf ffmpeg-4-fit/_release ffmpeg - ) + --enable-encoder=aac + ) && + # See https://www.laoyuyu.me/2019/05/23/android/clang_compile_ffmpeg/ + if [[ $SRS_CROSS_BUILD == YES ]]; then + sed -i -e 's/#define getenv(x) NULL/\/\*#define getenv(x) NULL\*\//g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_GMTIME_R 0/#define HAVE_GMTIME_R 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_LOCALTIME_R 0/#define HAVE_LOCALTIME_R 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + # For MIPS, which fail with: + # ./libavutil/libm.h:54:32: error: static declaration of 'cbrt' follows non-static declaration + # /root/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.4.0_musl/include/math.h:163:13: note: previous declaration of 'cbrt' was here + if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" || $SRS_CROSS_BUILD_ARCH == "arm" ]]; then + sed -i -e 's/#define HAVE_CBRT 0/#define HAVE_CBRT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_CBRTF 0/#define HAVE_CBRTF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_COPYSIGN 0/#define HAVE_COPYSIGN 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_ERF 0/#define HAVE_ERF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_HYPOT 0/#define HAVE_HYPOT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_RINT 0/#define HAVE_RINT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_LRINT 0/#define HAVE_LRINT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_LRINTF 0/#define HAVE_LRINTF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_ROUND 0/#define HAVE_ROUND 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_ROUNDF 0/#define HAVE_ROUNDF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_TRUNC 0/#define HAVE_TRUNC 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + sed -i -e 's/#define HAVE_TRUNCF 0/#define HAVE_TRUNCF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && + echo "FFmpeg sed ok" + fi + fi && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit ${SRS_JOBS} && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit install && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/ffmpeg ${SRS_OBJS}/ && + echo "The ffmpeg-4-fit is ok." fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build ffmpeg-4-fit failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf ffmpeg && ln -sf ffmpeg-4-fit/_release ffmpeg) - (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg-4-fit/_release ffmpeg) - if [ ! -f ${SRS_OBJS}/ffmpeg/lib/libavcodec.a ]; then echo "Build ffmpeg-4-fit failed."; exit -1; fi fi ##################################################################################### # live transcoding, ffmpeg-4.1, x264-core157, lame-3.99.5, libaacplus-2.0.2. ##################################################################################### -# Guess whether the ffmpeg is. -SYSTEMP_FFMPEG_BIN=/usr/local/bin/ffmpeg -if [[ ! -f $SYSTEMP_FFMPEG_BIN ]]; then SYSTEMP_FFMPEG_BIN=/usr/local/ffmpeg/bin/ffmpeg; fi +# Guess where is the ffmpeg. +SYSTEMP_FFMPEG_BIN=`which ffmpeg` # Always link the ffmpeg tools if exists. -if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then - mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin && - ln -sf $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg && - (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg) +if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then + mkdir -p ${SRS_OBJS}/ffmpeg/bin && + cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/ fi -if [ $SRS_FFMPEG_TOOL = YES ]; then - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg ]]; then +if [[ $SRS_FFMPEG_TOOL == YES ]]; then + if [[ -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then + cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/ && echo "ffmpeg-4.1 is ok."; else echo -e "${RED}Error: No FFmpeg found at /usr/local/bin/ffmpeg${BLACK}" @@ -809,98 +754,99 @@ if [ $SRS_FFMPEG_TOOL = YES ]; then echo -e "${RED} or disable it by --without-ffmpeg${BLACK}" exit -1; fi - # Always update the links. - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then - (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg) - fi fi ##################################################################################### # SRT module, https://github.com/ossrs/srs/issues/1147#issuecomment-577469119 ##################################################################################### if [[ $SRS_SRT == YES ]]; then - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/srt/lib/libsrt.a ]]; then - echo "libsrt-1-fit is ok."; + # Always disable c++11 for libsrt, because only the srt-app requres it. + LIBSRT_OPTIONS="--enable-apps=0 --enable-static=1 --enable-c++11=0" + if [[ $SRS_SHARED_SRT == YES ]]; then + LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=1" else - echo "Build srt-1-fit" - ( - if [[ ! -d ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/pkgconfig ]]; then - echo "OpenSSL pkgconfig no found, build srt-1-fit failed."; - exit -1; - fi - # Always disable c++11 for libsrt, because only the srt-app requres it. - LIBSRT_OPTIONS="--enable-apps=0 --enable-static=1 --enable-c++11=0" - if [[ $SRS_SHARED_SRT == YES ]]; then - LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=1" - else - LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0" - fi - # For cross-build. - if [[ $SRS_CROSS_BUILD == YES ]]; then - TOOL_GCC_REALPATH=$(realpath $(which $SRS_TOOL_CC)) - SRT_COMPILER_PREFIX=$(echo $TOOL_GCC_REALPATH |sed 's/-gcc.*$/-/') - LIBSRT_OPTIONS="$LIBSRT_OPTIONS --with-compiler-prefix=$SRT_COMPILER_PREFIX" - fi - # Start build libsrt. - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit && cd ${SRS_OBJS}/${SRS_PLATFORM} && - cp -R ../../3rdparty/srt-1-fit srt-1-fit && cd srt-1-fit && - PKG_CONFIG_PATH=../openssl/lib/pkgconfig ./configure --prefix=`pwd`/_release $LIBSRT_OPTIONS && - make ${SRS_JOBS} && make install && - cd .. && rm -rf srt && ln -sf srt-1-fit/_release srt && - # If exists lib64 of libsrt, link it to lib - if [[ -d srt/lib64 ]]; then - cd srt && ln -sf lib64 lib - fi - ) - ret=$?; if [[ $ret -ne 0 ]]; then echo "Build srt-1-fit failed, ret=$ret"; exit $ret; fi + LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0" + fi + # For cross-build. + if [[ $SRS_CROSS_BUILD == YES ]]; then + TOOL_GCC_REALPATH=$(realpath $(which $SRS_TOOL_CC)) + SRT_COMPILER_PREFIX=$(echo $TOOL_GCC_REALPATH |sed 's/-gcc.*$/-/') + LIBSRT_OPTIONS="$LIBSRT_OPTIONS --with-compiler-prefix=$SRT_COMPILER_PREFIX" + fi + # For windows build, over cygwin + if [[ $SRS_CYGWIN64 == YES ]]; then + LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix" fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf srt && ln -sf srt-1-fit/_release srt) - (cd ${SRS_OBJS} && rm -rf srt && ln -sf ${SRS_PLATFORM}/srt-1-fit/_release srt) - if [ ! -f ${SRS_OBJS}/srt/lib/libsrt.a ]; then echo "Build srt-1-fit failed."; exit -1; fi + + if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt/lib/libsrt.a ]]; then + rm -rf ${SRS_OBJS}/srt && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt ${SRS_OBJS}/ && + echo "libsrt-1-fit is ok." + else + if [[ ! -d ${SRS_OBJS}/openssl/lib/pkgconfig ]]; then + echo "OpenSSL pkgconfig no found, build srt-1-fit failed." + exit -1 + fi + echo "Build srt-1-fit" && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt ${SRS_OBJS}/srt && + cp -rf ${SRS_WORKDIR}/3rdparty/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM}/ && + ( + cd ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit && + env PKG_CONFIG_PATH=${SRS_DEPENDS_LIBS}/openssl/lib/pkgconfig \ + ./configure --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdpatry/srt $LIBSRT_OPTIONS + ) && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit ${SRS_JOBS} && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit install && + # If exists lib64 of libsrt, copy it to lib + if [[ -d ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt/lib64 ]]; then + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt/lib64 ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt/lib + fi && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt ${SRS_OBJS}/ && + echo "libsrt-1-fit is ok." + fi + ret=$?; if [[ $ret -ne 0 ]]; then echo "Build srt-1-fit failed, ret=$ret"; exit $ret; fi fi ##################################################################################### # build utest code ##################################################################################### -if [ $SRS_UTEST = YES ]; then - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gtest-fit/googletest/include/gtest/gtest.h ]]; then - echo "The gtest-fit is ok."; +if [[ $SRS_UTEST == YES ]]; then + if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gtest/googletest/include/gtest/gtest.h ]]; then + rm -rf ${SRS_OBJS}/gtest && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gtest ${SRS_OBJS}/ && + echo "The gtest-fit is ok." else - echo "Build gtest-fit"; - ( - cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf gtest-fit && cp -R ../../3rdparty/gtest-fit gtest-fit - rm -rf gtest && ln -sf gtest-fit/googletest gtest - ) + echo "Build gtest-fit" && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}gtest-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gtest ${SRS_OBJS}/gtest && + cp -rf ${SRS_WORKDIR}/3rdparty/gtest-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gtest && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gtest ${SRS_OBJS}/ && + echo "The gtest-fit is ok." fi # check status - ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gtest-fit failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf gtest && ln -sf gtest-fit/googletest gtest) - (cd ${SRS_OBJS} && rm -rf gtest && ln -sf ${SRS_PLATFORM}/gtest-fit/googletest gtest) - if [ ! -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]; then echo "Build gtest-fit failed."; exit -1; fi + ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gtest-1.6.0 failed, ret=$ret"; exit $ret; fi fi ##################################################################################### # build gperf code ##################################################################################### -if [ $SRS_GPERF = YES ]; then - if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gperf/bin/pprof ]]; then - echo "The gperftools-2-fit is ok."; +if [[ $SRS_GPERF == YES ]]; then + if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gperf/bin/pprof ]]; then + rm -rf ${SRS_OBJS}/gperf && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gperf ${SRS_OBJS}/ && + cp -f ${SRS_OBJS}/gperf/bin/pprof ${SRS_OBJS}/ && + echo "The gperftools-2-fit is ok." else - echo "Build gperftools-2-fit"; + echo "Build gperftools-2-fit" && + rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gperf \ + ${SRS_OBJS}/gperf ${SRS_OBJS}/pprof && + cp -rf ${SRS_WORKDIR}/3rdparty/gperftools-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/ && ( - rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit && cd ${SRS_OBJS}/${SRS_PLATFORM} && - cp -R ../../3rdparty/gperftools-2-fit . && cd gperftools-2-fit && - ./configure --prefix=`pwd`/_release --enable-frame-pointers && make ${SRS_JOBS} && make install && - cd .. && rm -rf gperf && ln -sf gperftools-2-fit/_release gperf && - rm -rf pprof && ln -sf gperf/bin/pprof pprof - ) + cd ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit && + ./configure --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdpatry/gperf --enable-frame-pointers + ) && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit ${SRS_JOBS} && + make -C ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit install && + cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gperf ${SRS_OBJS}/ && + cp -f ${SRS_OBJS}/gperf/bin/pprof ${SRS_OBJS}/ && + echo "The gperftools-2-fit is ok." fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gperftools-2-fit failed, ret=$ret"; exit $ret; fi - # Always update the links. - (cd ${SRS_OBJS} && rm -rf pprof && ln -sf ${SRS_PLATFORM}/gperf/bin/pprof pprof) - (cd ${SRS_OBJS} && rm -rf gperf && ln -sf ${SRS_PLATFORM}/gperftools-2-fit/_release gperf) - if [ ! -f ${SRS_OBJS}/pprof ]; then echo "Build gperftools-2-fit failed."; exit -1; fi fi diff --git a/trunk/auto/modules.sh b/trunk/auto/modules.sh index cffc0d9ba..51a36d84c 100755 --- a/trunk/auto/modules.sh +++ b/trunk/auto/modules.sh @@ -3,8 +3,7 @@ # # params: # $SRS_OBJS the objs directory to store the Makefile. ie. ./objs -# $SRS_OBJS_DIR the objs directory for Makefile. ie. objs -# $SRS_MAKEFILE the makefile name. ie. Makefile +# $SRS_OBJS the objs directory for Makefile. ie. objs # # $MODULE_DIR the module dir. ie. src/os/linux # $MODULE_ID the id of module. ie. CORE @@ -16,7 +15,7 @@ # returns: # $MODULE_OBJS array, the objects of the modules, used for link the binary -FILE=${SRS_OBJS}/${SRS_MAKEFILE} +FILE=${SRS_OBJS}/Makefile echo "#####################################################################################" >> ${FILE} echo "# The module ${MODULE_ID}." >> ${FILE} echo "#####################################################################################" >> ${FILE} @@ -27,7 +26,7 @@ echo "# INCS for ${MODULE_ID}, headers of module and its depends to compile" >> # # the public include files, for example: # CORE_MODULE_INCS = -Isrc/core -echo "${MODULE_ID}_MODULE_INCS = -I${MODULE_DIR} " >> ${FILE} +echo "${MODULE_ID}_MODULE_INCS = -I${SRS_WORKDIR}/${MODULE_DIR} " >> ${FILE} # # the private include files, for example: # CORE_INCS = -Isrc/core -Iobjs @@ -36,7 +35,7 @@ echo "${MODULE_ID}_MODULE_INCS = -I${MODULE_DIR} " >> ${FILE} INCS_NAME="${MODULE_ID}_INCS" # # current module header files -echo -n "${INCS_NAME} = -I${MODULE_DIR} " >> ${FILE} +echo -n "${INCS_NAME} = -I${SRS_WORKDIR}/${MODULE_DIR} " >> ${FILE} # # depends module header files for item in ${MODULE_DEPENDS[*]}; do @@ -60,8 +59,7 @@ echo "# DEPS for ${MODULE_ID}, the depends of make schema" >> ${FILE} DEPS_NAME="${MODULE_ID}_DEPS" echo -n "${DEPS_NAME} = " >> ${FILE} for item in ${MODULE_FILES[*]}; do - HEADER_FILE="${MODULE_DIR}/${item}.hpp" - if [[ ! -f ${HEADER_FILE} ]]; then HEADER_FILE="${MODULE_DIR}/${item}.h"; fi + HEADER_FILE="${SRS_WORKDIR}/${MODULE_DIR}/${item}.hpp" if [ -f ${HEADER_FILE} ]; then echo -n " ${HEADER_FILE}" >> ${FILE} fi @@ -78,10 +76,9 @@ echo "" >> ${FILE}; echo "" >> ${FILE} echo "# OBJ for ${MODULE_ID}, each object file" >> ${FILE} MODULE_OBJS=() for item in ${MODULE_FILES[*]}; do - CPP_FILE="${MODULE_DIR}/${item}.cpp" - if [[ ! -f ${CPP_FILE} ]]; then CPP_FILE="${MODULE_DIR}/${item}.cc"; fi - OBJ_FILE="${SRS_OBJS_DIR}/${MODULE_DIR}/${item}.o" - MODULE_OBJS="${MODULE_OBJS[@]} ${CPP_FILE}" + CPP_FILE="${SRS_WORKDIR}/${MODULE_DIR}/${item}.cpp" + OBJ_FILE="${SRS_OBJS}/${MODULE_DIR}/${item}.o" + MODULE_OBJS="${MODULE_OBJS[@]} ${MODULE_DIR}/${item}.cpp" if [ -f ${CPP_FILE} ]; then echo "${OBJ_FILE}: \$(${DEPS_NAME}) ${CPP_FILE} " >> ${FILE} echo " \$(CXX) -c \$(CXXFLAGS) ${DEFINES}\\" >> ${FILE} @@ -94,6 +91,6 @@ done echo "" >> ${FILE} # parent Makefile, to create module output dir before compile it. -echo " @mkdir -p ${SRS_OBJS_DIR}/${MODULE_DIR}" >> ${SRS_WORKDIR}/${SRS_MAKEFILE} +echo " @mkdir -p ${SRS_OBJS}/${MODULE_DIR}" >> ${SRS_MAKEFILE} echo -n "Generate modules ${MODULE_ID} ok"; echo '!'; diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 4e2aca549..7ddbe8e93 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -82,9 +82,8 @@ SRS_GPROF=NO # Performance test: gprof # ################################################################ # Preset options -SRS_X86_X64=NO # For x86_64 servers -SRS_OSX=NO #For osx/macOS PC. -SRS_CROSS_BUILD=NO #For cross build, for example, on Ubuntu. +SRS_OSX= #For OSX/macOS/Darwin PC. +SRS_CROSS_BUILD= #For cross build, for example, on Ubuntu. # For cross build, the cpu, for example(FFmpeg), --cpu=24kc SRS_CROSS_BUILD_CPU= # For cross build, the arch, for example(FFmpeg), --arch=aarch64 @@ -117,7 +116,6 @@ function show_help() { cat << END Presets: - --x86-64, --x86-x64 For x86/x64 cpu, common pc and servers. Default: $(value2switch $SRS_X86_X64) --cross-build Enable cross-build, please set bellow Toolchain also. Default: $(value2switch $SRS_CROSS_BUILD) --osx Enable build for OSX/Darwin AppleOS. Default: $(value2switch $SRS_OSX) @@ -252,8 +250,6 @@ function parse_user_option() { --extra-flags) SRS_EXTRA_FLAGS=${value} ;; --build-tag) SRS_BUILD_TAG=${value} ;; - --x86-x64) SRS_X86_X64=YES ;; - --x86-64) SRS_X86_X64=YES ;; --osx) SRS_OSX=YES ;; --without-srtp-nasm) SRS_SRTP_ASM=NO ;; @@ -365,6 +361,8 @@ function parse_user_option() { --enable-cross-compile) SRS_CROSS_BUILD=YES ;; # Deprecated, might be removed in future. + --x86-x64) SRS_X86_X64=YES ;; + --x86-64) SRS_X86_X64=YES ;; --with-nginx) SRS_NGINX=YES ;; --without-nginx) SRS_NGINX=NO ;; --nginx) SRS_NGINX=$(switch2value $value) ;; @@ -410,6 +408,32 @@ function switch2value() { fi } +##################################################################################### +function apply_system_options() { + OS_IS_OSX=$(uname -s |grep -q Darwin && echo YES) + OS_IS_LINUX=$(uname -s |grep -q Linux && echo YES) + OS_IS_CYGWIN=$(uname -s |grep -q CYGWIN && echo YES) + + OS_IS_CENTOS=$(yum --version >/dev/null 2>&1 && echo YES) + # For Debian, we think it's ubuntu also. + # For example, the wheezy/sid which is debian armv7 linux, can not identified by uname -v. + OS_IS_UBUNTU=$(apt-get --version >/dev/null 2>&1 && echo YES) + OS_IS_LOONGSON=$(uname -r |grep -q loongson && echo YES) + + # Use gcc to detect the CPU arch. + gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Please install gcc"; exit 1; fi + OS_IS_LOONGARCH64=$(gcc -dM -E - /dev/null || echo 1); fi + if [[ $OS_IS_LINUX == YES || $OS_IS_CYGWIN == YES ]]; then + SRS_JOBS=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || echo 1) + fi +} +apply_system_options + ##################################################################################### # parse preset options ##################################################################################### @@ -423,11 +447,6 @@ do done function apply_auto_options() { - # set default preset if not specifies - if [[ $SRS_X86_X64 == NO && $SRS_OSX == NO && $SRS_CROSS_BUILD == NO ]]; then - SRS_X86_X64=YES; opt="--x86-x64 $opt"; - fi - if [[ $SRS_CROSS_BUILD == YES ]]; then if [[ $SRS_CROSS_BUILD_PREFIX != "" && $SRS_CROSS_BUILD_HOST == "" ]]; then SRS_CROSS_BUILD_HOST=$(echo $SRS_CROSS_BUILD_PREFIX| sed 's/-$//g') @@ -460,10 +479,16 @@ function apply_auto_options() { SRS_FFMPEG_FIT=YES fi + # If enable gperf, disable sanitizer. + if [[ $SRS_GPERF == YES && $SRS_SANITIZER == YES ]]; then + echo "Disable sanitizer for gperf" + SRS_SANITIZER=NO + fi + # if transcode/ingest specified, requires the ffmpeg stub classes. SRS_FFMPEG_STUB=NO - if [ $SRS_TRANSCODE = YES ]; then SRS_FFMPEG_STUB=YES; fi - if [ $SRS_INGEST = YES ]; then SRS_FFMPEG_STUB=YES; fi + if [[ $SRS_TRANSCODE == YES ]]; then SRS_FFMPEG_STUB=YES; fi + if [[ $SRS_INGEST == YES ]]; then SRS_FFMPEG_STUB=YES; fi if [[ $SRS_SRTP_ASM == YES && $SRS_RTC == NO ]]; then echo "Disable SRTP-ASM, because RTC is disabled." @@ -474,9 +499,14 @@ function apply_auto_options() { echo "Disable SRTP-ASM, because NASM is disabled." SRS_SRTP_ASM=NO fi + + # parse the jobs for make + if [[ ! -z SRS_JOBS ]]; then + export SRS_JOBS="--jobs=${SRS_JOBS}" + fi } -if [ $help = yes ]; then +if [[ $help == YES ]]; then apply_auto_options show_help exit 0 @@ -488,24 +518,17 @@ fi function apply_detail_options() { # Always enable HTTP utilies. - if [ $SRS_HTTP_CORE = NO ]; then SRS_HTTP_CORE=YES; echo -e "${YELLOW}[WARN] Always enable HTTP utilies.${BLACK}"; fi - if [ $SRS_STREAM_CASTER = NO ]; then SRS_STREAM_CASTER=YES; echo -e "${YELLOW}[WARN] Always enable StreamConverter.${BLACK}"; fi - if [ $SRS_INGEST = NO ]; then SRS_INGEST=YES; echo -e "${YELLOW}[WARN] Always enable Ingest.${BLACK}"; fi - if [ $SRS_SSL = NO ]; then SRS_SSL=YES; echo -e "${YELLOW}[WARN] Always enable SSL.${BLACK}"; fi - if [ $SRS_STAT = NO ]; then SRS_STAT=YES; echo -e "${YELLOW}[WARN] Always enable Statistic.${BLACK}"; fi - if [ $SRS_TRANSCODE = NO ]; then SRS_TRANSCODE=YES; echo -e "${YELLOW}[WARN] Always enable Transcode.${BLACK}"; fi - if [ $SRS_HTTP_CALLBACK = NO ]; then SRS_HTTP_CALLBACK=YES; echo -e "${YELLOW}[WARN] Always enable HTTP callback.${BLACK}"; fi - if [ $SRS_HTTP_SERVER = NO ]; then SRS_HTTP_SERVER=YES; echo -e "${YELLOW}[WARN] Always enable HTTP server.${BLACK}"; fi - if [ $SRS_HTTP_API = NO ]; then SRS_HTTP_API=YES; echo -e "${YELLOW}[WARN] Always enable HTTP API.${BLACK}"; fi - if [ $SRS_HLS = NO ]; then SRS_HLS=YES; echo -e "${YELLOW}[WARN] Always enable HLS.${BLACK}"; fi - if [ $SRS_DVR = NO ]; then SRS_DVR=YES; echo -e "${YELLOW}[WARN] Always enable DVR.${BLACK}"; fi - - # parse the jobs for make - if [[ "" -eq SRS_JOBS ]]; then - export SRS_JOBS="--jobs=1" - else - export SRS_JOBS="--jobs=${SRS_JOBS}" - fi + if [[ $SRS_HTTP_CORE == NO ]]; then SRS_HTTP_CORE=YES; echo -e "${YELLOW}[WARN] Always enable HTTP utilies.${BLACK}"; fi + if [[ $SRS_STREAM_CASTER == NO ]]; then SRS_STREAM_CASTER=YES; echo -e "${YELLOW}[WARN] Always enable StreamConverter.${BLACK}"; fi + if [[ $SRS_INGEST == NO ]]; then SRS_INGEST=YES; echo -e "${YELLOW}[WARN] Always enable Ingest.${BLACK}"; fi + if [[ $SRS_SSL == NO ]]; then SRS_SSL=YES; echo -e "${YELLOW}[WARN] Always enable SSL.${BLACK}"; fi + if [[ $SRS_STAT == NO ]]; then SRS_STAT=YES; echo -e "${YELLOW}[WARN] Always enable Statistic.${BLACK}"; fi + if [[ $SRS_TRANSCODE == NO ]]; then SRS_TRANSCODE=YES; echo -e "${YELLOW}[WARN] Always enable Transcode.${BLACK}"; fi + if [[ $SRS_HTTP_CALLBACK == NO ]]; then SRS_HTTP_CALLBACK=YES; echo -e "${YELLOW}[WARN] Always enable HTTP callback.${BLACK}"; fi + if [[ $SRS_HTTP_SERVER == NO ]]; then SRS_HTTP_SERVER=YES; echo -e "${YELLOW}[WARN] Always enable HTTP server.${BLACK}"; fi + if [[ $SRS_HTTP_API == NO ]]; then SRS_HTTP_API=YES; echo -e "${YELLOW}[WARN] Always enable HTTP API.${BLACK}"; fi + if [[ $SRS_HLS == NO ]]; then SRS_HLS=YES; echo -e "${YELLOW}[WARN] Always enable HLS.${BLACK}"; fi + if [[ $SRS_DVR == NO ]]; then SRS_DVR=YES; echo -e "${YELLOW}[WARN] Always enable DVR.${BLACK}"; fi } apply_auto_options apply_detail_options @@ -600,13 +623,13 @@ function check_option_conflicts() { __check_ok=YES # check conflict - if [ $SRS_GPERF = NO ]; then - if [ $SRS_GPERF_MC = YES ]; then echo "gperf-mc depends on gperf, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_GPERF_MD = YES ]; then echo "gperf-md depends on gperf, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_GPERF_MP = YES ]; then echo "gperf-mp depends on gperf, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_GPERF_CP = YES ]; then echo "gperf-cp depends on gperf, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPERF == NO ]]; then + if [[ $SRS_GPERF_MC == YES ]]; then echo "gperf-mc depends on gperf, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPERF_MD == YES ]]; then echo "gperf-md depends on gperf, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPERF_MP == YES ]]; then echo "gperf-mp depends on gperf, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPERF_CP == YES ]]; then echo "gperf-cp depends on gperf, see: ./configure --help"; __check_ok=NO; fi fi - if [[ $SRS_GPERF_MC = YES && $SRS_GPERF_MP = YES ]]; then + if [[ $SRS_GPERF_MC == YES && $SRS_GPERF_MP == YES ]]; then echo "gperf-mc not compatible with gperf-mp, see: ./configure --help"; echo "@see: https://gperftools.github.io/gperftools/heap_checker.html"; echo "Note that since the heap-checker uses the heap-profiling framework internally, it is not possible to run both the heap-checker and heap profiler at the same time"; @@ -614,27 +637,27 @@ function check_option_conflicts() { fi # generate the group option: SRS_GPERF __gperf_slow=NO - if [ $SRS_GPERF_MC = YES ]; then SRS_GPERF=YES; __gperf_slow=YES; fi - if [ $SRS_GPERF_MD = YES ]; then SRS_GPERF=YES; __gperf_slow=YES; fi - if [ $SRS_GPERF_MP = YES ]; then SRS_GPERF=YES; __gperf_slow=YES; fi - if [ $SRS_GPERF_CP = YES ]; then SRS_GPERF=YES; __gperf_slow=YES; fi - if [ $__gperf_slow = YES ]; then if [ $SRS_GPROF = YES ]; then + if [[ $SRS_GPERF_MC == YES ]]; then SRS_GPERF=YES; __gperf_slow=YES; fi + if [[ $SRS_GPERF_MD == YES ]]; then SRS_GPERF=YES; __gperf_slow=YES; fi + if [[ $SRS_GPERF_MP == YES ]]; then SRS_GPERF=YES; __gperf_slow=YES; fi + if [[ $SRS_GPERF_CP == YES ]]; then SRS_GPERF=YES; __gperf_slow=YES; fi + if [[ $__gperf_slow == YES ]]; then if [[ $SRS_GPROF == YES ]]; then echo "gmc/gmp/gcp not compatible with gprof, see: ./configure --help"; __check_ok=NO; fi fi # check variable neccessary - if [ $SRS_HDS = RESERVED ]; then echo "you must specifies the hds, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_SSL = RESERVED ]; then echo "you must specifies the ssl, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_STREAM_CASTER = RESERVED ]; then echo "you must specifies the stream-converter, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_UTEST = RESERVED ]; then echo "you must specifies the utest, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_GPERF = RESERVED ]; then echo "you must specifies the gperf, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_GPERF_MC = RESERVED ]; then echo "you must specifies the gperf-mc, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_GPERF_MD = RESERVED ]; then echo "you must specifies the gperf-md, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_GPERF_MP = RESERVED ]; then echo "you must specifies the gperf-mp, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_GPERF_CP = RESERVED ]; then echo "you must specifies the gperf-cp, see: ./configure --help"; __check_ok=NO; fi - if [ $SRS_GPROF = RESERVED ]; then echo "you must specifies the gprof, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_HDS == RESERVED ]]; then echo "you must specifies the hds, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_SSL == RESERVED ]]; then echo "you must specifies the ssl, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_STREAM_CASTER == RESERVED ]]; then echo "you must specifies the stream-converter, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_UTEST == RESERVED ]]; then echo "you must specifies the utest, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPERF == RESERVED ]]; then echo "you must specifies the gperf, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPERF_MC == RESERVED ]]; then echo "you must specifies the gperf-mc, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPERF_MD == RESERVED ]]; then echo "you must specifies the gperf-md, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPERF_MP == RESERVED ]]; then echo "you must specifies the gperf-mp, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPERF_CP == RESERVED ]]; then echo "you must specifies the gperf-cp, see: ./configure --help"; __check_ok=NO; fi + if [[ $SRS_GPROF == RESERVED ]]; then echo "you must specifies the gprof, see: ./configure --help"; __check_ok=NO; fi if [[ -z $SRS_PREFIX ]]; then echo "you must specifies the prefix, see: ./configure --prefix"; __check_ok=NO; fi - if [ $__check_ok = NO ]; then + if [[ $__check_ok == NO ]]; then exit 1; fi } diff --git a/trunk/auto/setup_variables.sh b/trunk/auto/setup_variables.sh index e141148e5..def350086 100755 --- a/trunk/auto/setup_variables.sh +++ b/trunk/auto/setup_variables.sh @@ -24,22 +24,30 @@ if [[ $SRS_CROSS_BUILD == YES ]]; then SRS_PLATFORM="${SRS_PLATFORM}-crossbuild-$(echo $SRS_TOOL_CC_NAME|awk -F - '{print $1"-"$2}')" fi -echo "SRS_WORKDIR: ${SRS_WORKDIR}, SRS_OBJS_DIR: ${SRS_OBJS_DIR}, SRS_OBJS: ${SRS_OBJS}, SRS_PLATFORM: ${SRS_PLATFORM}" +echo "SRS_WORKDIR: ${SRS_WORKDIR}, SRS_OBJS: ${SRS_OBJS}, SRS_PLATFORM: ${SRS_PLATFORM}" +echo "All outputs to: ${SRS_OBJS}/${SRS_PLATFORM}" # For src object files on each platform. ( - mkdir -p ${SRS_OBJS_DIR} && cd ${SRS_OBJS_DIR} && - rm -rf src utest srs srs_utest research include lib srs_hls_ingester srs_mp4_parser && - mkdir -p ${SRS_PLATFORM}/src && ln -sf ${SRS_PLATFORM}/src && - mkdir -p ${SRS_PLATFORM}/utest && ln -sf ${SRS_PLATFORM}/utest && - mkdir -p ${SRS_PLATFORM}/research && ln -sf ${SRS_PLATFORM}/research && - mkdir -p ${SRS_PLATFORM}/include && ln -sf ${SRS_PLATFORM}/include && - mkdir -p ${SRS_PLATFORM}/lib && ln -sf ${SRS_PLATFORM}/lib + mkdir -p ${SRS_OBJS} && + (cd ${SRS_OBJS} && rm -rf src utest srs srs_utest research include lib srs_hls_ingester srs_mp4_parser) && + mkdir -p ${SRS_OBJS}/src ${SRS_OBJS}/research ${SRS_OBJS}/utest && + + mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry && + (cd ${SRS_OBJS} && rm -rf st ffmpeg opus srtp2 openssl srt) && + mkdir -p ${SRS_OBJS}/st ${SRS_OBJS}/ffmpeg ${SRS_OBJS}/opus ${SRS_OBJS}/srtp2 ${SRS_OBJS}/openssl \ + ${SRS_OBJS}/srt && + mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/ffmpeg \ + ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/opus ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srtp2 \ + ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt ) +ret=$?; if [[ $ret -ne 0 ]]; then echo "Create build directory failed, ret=$ret"; exit $ret; fi + if [[ $SRS_CLEAN == NO ]]; then echo "Fast cleanup, if need to do full cleanup, please use: make clean" fi +# TODO: FIXME: Remove python, use Go for api server demo. # Python or python2, for CentOS8. python2 --version >/dev/null 2>&1 && alias python=python2 && echo "Alias python2 as python" diff --git a/trunk/auto/summary.sh b/trunk/auto/summary.sh index 51b057c4d..6a27fb18b 100755 --- a/trunk/auto/summary.sh +++ b/trunk/auto/summary.sh @@ -1,25 +1,25 @@ #!/bin/bash # colorful summary -SrsHlsSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_HLS = YES ]; then SrsHlsSummaryColor="\${GREEN}"; fi -SrsDvrSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_DVR = YES ]; then SrsDvrSummaryColor="\${GREEN}"; fi -SrsNginxSummaryColor="\${GREEN}(Disabled) "; if [ $SRS_NGINX = YES ]; then SrsNginxSummaryColor="\${GREEN}"; fi -SrsSslSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_SSL = YES ]; then SrsSslSummaryColor="\${GREEN}"; fi -SrsFfmpegSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_FFMPEG_TOOL = YES ]; then SrsFfmpegSummaryColor="\${GREEN}"; fi -SrsTranscodeSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_TRANSCODE = YES ]; then SrsTranscodeSummaryColor="\${GREEN}"; fi -SrsIngestSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_INGEST = YES ]; then SrsIngestSummaryColor="\${GREEN}"; fi -SrsHttpCallbackSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_HTTP_CALLBACK = YES ]; then SrsHttpCallbackSummaryColor="\${GREEN}"; fi -SrsHttpServerSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_HTTP_SERVER = YES ]; then SrsHttpServerSummaryColor="\${GREEN}"; fi -SrsHttpApiSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_HTTP_API = YES ]; then SrsHttpApiSummaryColor="\${GREEN}"; fi -SrsStreamConverterSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_STREAM_CASTER = YES ]; then SrsStreamConverterSummaryColor="\${GREEN}"; fi -SrsUtestSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_UTEST = YES ]; then SrsUtestSummaryColor="\${GREEN}"; fi -SrsGperfSummaryColor="\${GREEN}(Disabled) "; if [ $SRS_GPERF = YES ]; then SrsGperfSummaryColor="\${GREEN}"; fi -SrsGperfMCSummaryColor="\${GREEN}(Disabled) "; if [ $SRS_GPERF_MC = YES ]; then SrsGperfMCSummaryColor="\${YELLOW}"; fi -SrsGperfMDSummaryColor="\${GREEN}(Disabled) "; if [ $SRS_GPERF_MD = YES ]; then SrsGperfMDSummaryColor="\${YELLOW}"; fi -SrsGperfMPSummaryColor="\${GREEN}(Disabled) "; if [ $SRS_GPERF_MP = YES ]; then SrsGperfMPSummaryColor="\${YELLOW}"; fi -SrsGperfCPSummaryColor="\${GREEN}(Disabled) "; if [ $SRS_GPERF_CP = YES ]; then SrsGperfCPSummaryColor="\${YELLOW}"; fi -SrsGprofSummaryColor="\${GREEN}(Disabled) "; if [ $SRS_GPROF = YES ]; then SrsGprofSummaryColor="\${YELLOW}"; fi -SrsValgrindSummaryColor="\${YELLOW}(Disabled) "; if [ $SRS_VALGRIND = YES ]; then SrsValgrindSummaryColor="\${GREEN}"; fi +SrsHlsSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_HLS == YES ]]; then SrsHlsSummaryColor="\${GREEN}"; fi +SrsDvrSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_DVR == YES ]]; then SrsDvrSummaryColor="\${GREEN}"; fi +SrsNginxSummaryColor="\${GREEN}(Disabled) "; if [[ $SRS_NGINX == YES ]]; then SrsNginxSummaryColor="\${GREEN}"; fi +SrsSslSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_SSL == YES ]]; then SrsSslSummaryColor="\${GREEN}"; fi +SrsFfmpegSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_FFMPEG_TOOL == YES ]]; then SrsFfmpegSummaryColor="\${GREEN}"; fi +SrsTranscodeSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_TRANSCODE == YES ]]; then SrsTranscodeSummaryColor="\${GREEN}"; fi +SrsIngestSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_INGEST == YES ]]; then SrsIngestSummaryColor="\${GREEN}"; fi +SrsHttpCallbackSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_HTTP_CALLBACK == YES ]]; then SrsHttpCallbackSummaryColor="\${GREEN}"; fi +SrsHttpServerSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_HTTP_SERVER == YES ]]; then SrsHttpServerSummaryColor="\${GREEN}"; fi +SrsHttpApiSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_HTTP_API == YES ]]; then SrsHttpApiSummaryColor="\${GREEN}"; fi +SrsStreamConverterSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_STREAM_CASTER == YES ]]; then SrsStreamConverterSummaryColor="\${GREEN}"; fi +SrsUtestSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_UTEST == YES ]]; then SrsUtestSummaryColor="\${GREEN}"; fi +SrsGperfSummaryColor="\${GREEN}(Disabled) "; if [[ $SRS_GPERF == YES ]]; then SrsGperfSummaryColor="\${GREEN}"; fi +SrsGperfMCSummaryColor="\${GREEN}(Disabled) "; if [[ $SRS_GPERF_MC == YES ]]; then SrsGperfMCSummaryColor="\${YELLOW}"; fi +SrsGperfMDSummaryColor="\${GREEN}(Disabled) "; if [[ $SRS_GPERF_MD == YES ]]; then SrsGperfMDSummaryColor="\${YELLOW}"; fi +SrsGperfMPSummaryColor="\${GREEN}(Disabled) "; if [[ $SRS_GPERF_MP == YES ]]; then SrsGperfMPSummaryColor="\${YELLOW}"; fi +SrsGperfCPSummaryColor="\${GREEN}(Disabled) "; if [[ $SRS_GPERF_CP == YES ]]; then SrsGperfCPSummaryColor="\${YELLOW}"; fi +SrsGprofSummaryColor="\${GREEN}(Disabled) "; if [[ $SRS_GPROF == YES ]]; then SrsGprofSummaryColor="\${YELLOW}"; fi +SrsValgrindSummaryColor="\${YELLOW}(Disabled) "; if [[ $SRS_VALGRIND == YES ]]; then SrsValgrindSummaryColor="\${GREEN}"; fi cat < ${SRS_OBJS}/${SRS_BUILD_SUMMARY} #!/bin/bash diff --git a/trunk/auto/utest.sh b/trunk/auto/utest.sh index c4a6d4565..dbd4cd15a 100755 --- a/trunk/auto/utest.sh +++ b/trunk/auto/utest.sh @@ -2,26 +2,25 @@ # # params: # $SRS_OBJS the objs directory to store the Makefile. ie. ./objs -# $SRS_OBJS_DIR the objs directory for Makefile. ie. objs -# $SRS_MAKEFILE the makefile name. ie. Makefile +# $SRS_OBJS the objs directory for Makefile. ie. objs # # $APP_NAME the app name to output. ie. srs_utest # $MODULE_DIR the src dir of utest code. ie. src/utest # $LINK_OPTIONS the link options for utest. ie. -lpthread -ldl -FILE=${SRS_OBJS}/utest/${SRS_MAKEFILE} +FILE=${SRS_OBJS}/${SRS_PLATFORM}/utest/Makefile # create dir for Makefile -mkdir -p ${SRS_OBJS}/utest +mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/utest # the prefix to generate the objs/utest/Makefile # dirs relative to current dir(objs/utest), it's trunk/objs/utest # trunk of srs, which contains the src dir, relative to objs/utest, it's trunk SRS_TRUNK_PREFIX=../../.. -# gest dir, relative to objs/utest, it's trunk/objs/gtest -GTEST_DIR=${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/gtest +# gest dir, relative to objs/utest, it's trunk/objs/{Platform}/gtest +GTEST_DIR=${SRS_TRUNK_PREFIX}/${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gtest/googletest cat << END > ${FILE} -# user must run make the ${SRS_OBJS_DIR}/utest dir +# user must run make the ${SRS_OBJS}/utest dir # at the same dir of Makefile. # A sample Makefile for building Google Test and using it in user @@ -58,7 +57,7 @@ CXXFLAGS += -std=c++11 # All tests produced by this Makefile. Remember to add new tests you # created to the list. -TESTS = ${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${APP_NAME} +TESTS = ${SRS_TRUNK_PREFIX}/${SRS_OBJS}/${APP_NAME} # All Google Test headers. Usually you shouldn't change this # definition. @@ -139,7 +138,7 @@ echo "# Depends, the depends objects" >> ${FILE} echo -n "SRS_UTEST_DEPS = " >> ${FILE} for item in ${MODULE_OBJS[*]}; do FILE_NAME=${item%.*} - echo -n "${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${FILE_NAME}.o " >> ${FILE} + echo -n "${SRS_TRUNK_PREFIX}/${SRS_OBJS}/${FILE_NAME}.o " >> ${FILE} done echo "" >> ${FILE}; echo "" >> ${FILE} # @@ -183,12 +182,12 @@ echo "" >> ${FILE}; echo "" >> ${FILE} # echo "# generate the utest binary" >> ${FILE} cat << END >> ${FILE} -${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${APP_NAME} : \$(SRS_UTEST_DEPS) ${MODULE_OBJS} gtest.a +${SRS_TRUNK_PREFIX}/${SRS_OBJS}/${APP_NAME} : \$(SRS_UTEST_DEPS) ${MODULE_OBJS} gtest.a \$(CXX) -o \$@ \$(CPPFLAGS) \$(CXXFLAGS) \$^ \$(DEPS_LIBRARIES_FILES) ${LINK_OPTIONS} END ##################################################################################### # parent Makefile, to create module output dir before compile it. -echo " @mkdir -p ${SRS_OBJS_DIR}/utest" >> ${SRS_WORKDIR}/${SRS_MAKEFILE} +echo " @mkdir -p ${SRS_OBJS}/utest" >> ${SRS_MAKEFILE} echo -n "Generate utest ok"; echo '!'; diff --git a/trunk/configure b/trunk/configure index ee6f28d44..8c5c63826 100755 --- a/trunk/configure +++ b/trunk/configure @@ -3,11 +3,16 @@ ##################################################################################### # the main output dir, all configure and make output are in this dir. ##################################################################################### -# create the main objs -SRS_WORKDIR="." -SRS_OBJS_DIR="objs" -SRS_OBJS="${SRS_WORKDIR}/${SRS_OBJS_DIR}" -SRS_MAKEFILE="Makefile" +# Configure SRS from other directory, for example: +# env SRS_WORKDIR=~/git/srs/trunk ./configure +if [[ -z $SRS_WORKDIR ]]; then SRS_WORKDIR="."; fi +# Set the objs to other directory, for example: +# env SRS_OUTPUT=$(pwd) ./configure +if [[ -z $SRS_OUTPUT ]]; then + SRS_OBJS="${SRS_WORKDIR}/objs" && SRS_MAKEFILE=${SRS_WORKDIR}/Makefile +else + SRS_OBJS="${SRS_OUTPUT}/objs" && SRS_MAKEFILE=${SRS_OUTPUT}/Makefile +fi # linux shell color support. RED="\\033[31m" @@ -21,13 +26,13 @@ BLACK="\\033[0m" # build options: SRS_JOBS ##################################################################################### # parse options, exit with error when parse options invalid. -. auto/options.sh +. $SRS_WORKDIR/auto/options.sh # setup variables when options parsed. -. auto/setup_variables.sh +. $SRS_WORKDIR/auto/setup_variables.sh # We don't need to cleanup the exists files. -rm -f ${SRS_WORKDIR}/${SRS_MAKEFILE} +rm -f ${SRS_MAKEFILE} # Create objs and platform directories. mkdir -p ${SRS_OBJS}/${SRS_PLATFORM} @@ -35,10 +40,10 @@ mkdir -p ${SRS_OBJS}/${SRS_PLATFORM} if [[ $SRS_GENERATE_OBJS == YES ]]; then exit 0; fi # apply user options. -. auto/depends.sh +. $SRS_WORKDIR/auto/depends.sh # the auto generated variables. -. auto/auto_headers.sh +. $SRS_WORKDIR/auto/auto_headers.sh ##################################################################################### # generate Makefile. @@ -48,13 +53,13 @@ SRS_BUILD_SUMMARY="_srs_build_summary.sh" # utest make entry, (cd utest; make) SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\"" -if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd ${SRS_OBJS_DIR}/${SRS_PLATFORM}/utest && \$(MAKE))"; fi +if [[ $SRS_UTEST == YES ]]; then SrsUtestMakeEntry="\$(MAKE)\$(JOBS) -C ${SRS_OBJS}/${SRS_PLATFORM}/utest"; fi ##################################################################################### # finger out modules to install. # where srs module is a dir which contains a config file. SRS_MODULES=() -__mfiles=`find modules -name "config"` && for __mfile in $__mfiles; do +__mfiles=$(find $SRS_WORKDIR/modules -name "config") && for __mfile in $__mfiles; do SRS_MODULES+=("`dirname $__mfile`") done @@ -63,7 +68,7 @@ __mphonys="" && __mdefaults="" && __mcleanups="" # add each modules for application for SRS_MODULE in ${SRS_MODULES[*]}; do echo "install module at: $SRS_MODULE" - . auto/reset_module.sh && . $SRS_MODULE/config + . $SRS_WORKDIR/auto/reset_module.sh && . $SRS_MODULE/config if [[ 0 -ne ${#SRS_MODULE_MAIN[@]} ]]; then __mphonys="$__mphonys $SRS_MODULE_NAME" __mdefaults="$__mdefaults $SRS_MODULE_NAME" @@ -72,7 +77,7 @@ for SRS_MODULE in ${SRS_MODULES[*]}; do done # generate extra phony for each modules. -cat << END > ${SRS_OBJS}/${SRS_MAKEFILE} +cat << END > ${SRS_OBJS}/Makefile .PHONY: $__mphonys @@ -93,12 +98,12 @@ if [[ $SRS_CXX14 == YES ]]; then CppStd="-std=c++14" fi # performance of gprof -SrsGprof=""; SrsGprofLink=""; if [ $SRS_GPROF = YES ]; then SrsGprof=" -pg -lc_p"; SrsGprofLink=" -pg"; fi +SrsGprof=""; SrsGprofLink=""; if [[ $SRS_GPROF == YES ]]; then SrsGprof=" -pg -lc_p"; SrsGprofLink=" -pg"; fi # performance of gperf -SrsGperf=""; SrsGperfLink=""; if [ $SRS_GPERF = YES ]; then SrsGperfLink=" -lpthread"; fi +SrsGperf=""; SrsGperfLink=""; if [[ $SRS_GPERF == YES ]]; then SrsGperfLink=" -lpthread"; fi # the cxx flag generated. CXXFLAGS="${CXXFLAGS} ${CppStd}${WarnLevel}${GDBDebug}${LibraryCompile}${SrsGprof}" -if [ $SRS_GPERF = YES ]; then +if [[ $SRS_GPERF == YES ]]; then CXXFLAGS="${CXXFLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free"; fi # For coverage. @@ -123,7 +128,7 @@ if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES ]]; then fi # Start to generate the Makefile. -cat << END >> ${SRS_OBJS}/${SRS_MAKEFILE} +cat << END >> ${SRS_OBJS}/Makefile GCC = ${SRS_TOOL_CC} CXX = ${SRS_TOOL_CXX} AR = ${SRS_TOOL_AR} @@ -142,42 +147,42 @@ END # library(.a): add to ModuleLibFiles if binary need the specifeid library. for example, LibSTfile # # st(state-threads) the basic network library for SRS. -LibSTRoot="${SRS_OBJS_DIR}/st"; LibSTfile="${LibSTRoot}/libst.a" +LibSTRoot="${SRS_OBJS}/st"; LibSTfile="${LibSTRoot}/libst.a" if [[ $SRS_SHARED_ST == YES ]]; then LibSTfile="-L${LibSTRoot} -lst"; fi # srtp if [[ $SRS_RTC == YES ]]; then - LibSrtpRoot="${SRS_OBJS_DIR}/srtp2/include"; LibSrtpFile="${SRS_OBJS_DIR}/srtp2/lib/libsrtp2.a" + LibSrtpRoot="${SRS_OBJS}/srtp2/include"; LibSrtpFile="${SRS_OBJS}/srtp2/lib/libsrtp2.a" fi # FFMPEG for WebRTC transcoding, such as aac to opus. if [[ $SRS_FFMPEG_FIT == YES ]]; then - LibFfmpegRoot="${SRS_OBJS_DIR}/ffmpeg/include"; LibFfmpegFile="${SRS_OBJS_DIR}/ffmpeg/lib/libavcodec.a ${SRS_OBJS_DIR}/ffmpeg/lib/libswresample.a ${SRS_OBJS_DIR}/ffmpeg/lib/libavutil.a" - if [[ $SRS_CROSS_BUILD == NO ]]; then - LibFfmpegFile="${LibFfmpegFile} ${SRS_OBJS_DIR}/opus/lib/libopus.a" + LibFfmpegRoot="${SRS_OBJS}/ffmpeg/include"; LibFfmpegFile="${SRS_OBJS}/ffmpeg/lib/libavcodec.a ${SRS_OBJS}/ffmpeg/lib/libswresample.a ${SRS_OBJS}/ffmpeg/lib/libavutil.a" + if [[ $SRS_CROSS_BUILD != YES ]]; then + LibFfmpegFile="${LibFfmpegFile} ${SRS_OBJS}/opus/lib/libopus.a" fi - if [[ $SRS_SHARED_FFMPEG == YES ]]; then LibFfmpegFile="-L${SRS_OBJS_DIR}/ffmpeg/lib -lavcodec -lswresample -lavutil -L${SRS_OBJS_DIR}/opus/lib -lopus"; fi + if [[ $SRS_SHARED_FFMPEG == YES ]]; then LibFfmpegFile="-L${SRS_OBJS}/ffmpeg/lib -lavcodec -lswresample -lavutil -L${SRS_OBJS}/opus/lib -lopus"; fi fi # openssl-1.1.0e, for the RTMP complex handshake. LibSSLRoot="";LibSSLfile="" if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == NO ]]; then - LibSSLRoot="${SRS_OBJS_DIR}/openssl/include"; LibSSLfile="${SRS_OBJS_DIR}/openssl/lib/libssl.a ${SRS_OBJS_DIR}/openssl/lib/libcrypto.a"; + LibSSLRoot="${SRS_OBJS}/openssl/include"; LibSSLfile="${SRS_OBJS}/openssl/lib/libssl.a ${SRS_OBJS}/openssl/lib/libcrypto.a"; fi # gperftools-2.1, for mem check and mem/cpu profile LibGperfRoot=""; LibGperfFile="" -if [ $SRS_GPERF = YES ]; then - LibGperfRoot="${SRS_OBJS_DIR}/gperf/include"; LibGperfFile="${SRS_OBJS_DIR}/gperf/lib/libtcmalloc_and_profiler.a"; +if [[ $SRS_GPERF == YES ]]; then + LibGperfRoot="${SRS_OBJS}/gperf/include"; LibGperfFile="${SRS_OBJS}/gperf/lib/libtcmalloc_and_profiler.a"; fi -if [ $SRS_GPERF_MD = YES ]; then - LibGperfFile="${SRS_OBJS_DIR}/gperf/lib/libtcmalloc_debug.a"; +if [[ $SRS_GPERF_MD == YES ]]; then + LibGperfFile="${SRS_OBJS}/gperf/lib/libtcmalloc_debug.a"; fi # srt code path if [[ $SRS_SRT == YES ]]; then - LibSRTRoot="${SRS_OBJS_DIR}/srt/include"; LibSRTfile="${SRS_OBJS_DIR}/srt/lib/libsrt.a" - if [[ $SRS_SHARED_SRT == YES ]]; then LibSRTfile="-L${SRS_OBJS_DIR}/srt/lib -lsrt"; fi + LibSRTRoot="${SRS_OBJS}/srt/include"; LibSRTfile="${SRS_OBJS}/srt/lib/libsrt.a" + if [[ $SRS_SHARED_SRT == YES ]]; then LibSRTfile="-L${SRS_OBJS}/srt/lib -lsrt"; fi fi # the link options, always use static link @@ -189,7 +194,7 @@ fi # Static link the c++ libraries, for user who build SRS by a new version of gcc, # so we need to link the c++ libraries staticly but not all. # @see https://stackoverflow.com/a/26107550 -if [ $SRS_STATIC = YES ]; then +if [[ $SRS_STATIC == YES ]]; then SrsLinkOptions="${SrsLinkOptions} -static-libstdc++"; fi @@ -223,16 +228,16 @@ fi #Core, depends only on system apis. MODULE_ID="CORE" MODULE_DEPENDS=() -ModuleLibIncs=(${SRS_OBJS_DIR}) +ModuleLibIncs=(${SRS_OBJS}) MODULE_FILES=("srs_core" "srs_core_version5" "srs_core_autofree" "srs_core_performance" "srs_core_time" "srs_core_platform") -CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh +CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . $SRS_WORKDIR/auto/modules.sh CORE_OBJS="${MODULE_OBJS[@]}" # #Kernel, depends on core, provides error/log/config, nothing about stream information. MODULE_ID="KERNEL" MODULE_DEPENDS=("CORE") -ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot}) +ModuleLibIncs=(${SRS_OBJS} ${LibSSLRoot}) MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_buffer" "srs_kernel_utility" "srs_kernel_flv" "srs_kernel_codec" "srs_kernel_io" "srs_kernel_consts" "srs_kernel_aac" "srs_kernel_mp3" "srs_kernel_ts" "srs_kernel_ps" @@ -241,13 +246,13 @@ MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_buffer" if [[ $SRS_RTC == YES ]]; then MODULE_FILES+=("srs_kernel_rtc_rtp" "srs_kernel_rtc_rtcp") fi -KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh +KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . $SRS_WORKDIR/auto/modules.sh KERNEL_OBJS="${MODULE_OBJS[@]}" # #RTMP/HTTP/Raw Protocol, depends on core/kernel, provides rtmp/htttp protocol features. MODULE_ID="PROTOCOL" MODULE_DEPENDS=("CORE" "KERNEL") -ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot}) +ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot} ${LibSSLRoot}) MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_protocol_conn" "srs_protocol_rtmp_handshake" "srs_protocol_rtmp_stack" "srs_protocol_utility" "srs_protocol_rtmp_msg_array" "srs_protocol_stream" "srs_protocol_raw_avc" "srs_protocol_http_stack" "srs_protocol_kbps" "srs_protocol_json" @@ -260,15 +265,15 @@ fi if [[ $SRS_RTC == YES ]]; then MODULE_FILES+=("srs_protocol_rtc_stun") fi -PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . auto/modules.sh +PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . $SRS_WORKDIR/auto/modules.sh PROTOCOL_OBJS="${MODULE_OBJS[@]}" # #App Module, for SRS server only. MODULE_ID="APP" MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL") -ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot}) -if [ $SRS_GPERF = YES ]; then +ModuleLibIncs=(${SRS_OBJS} ${LibSSLRoot}) +if [[ $SRS_GPERF == YES ]]; then ModuleLibIncs+=(${LibGperfRoot}) fi if [[ $SRS_RTC == YES ]]; then @@ -305,17 +310,17 @@ fi DEFINES="" # add each modules for app for SRS_MODULE in ${SRS_MODULES[*]}; do - . auto/reset_module.sh && . $SRS_MODULE/config + . $SRS_WORKDIR/auto/reset_module.sh && . $SRS_MODULE/config MODULE_FILES+=("${SRS_MODULE_APP[*]}") DEFINES="${DEFINES} ${SRS_MODULE_DEFINES}" done -APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh +APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . $SRS_WORKDIR/auto/modules.sh APP_OBJS="${MODULE_OBJS[@]}" # #Server Module, for SRS only. MODULE_ID="SERVER" MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP") -ModuleLibIncs=(${SRS_OBJS_DIR} ${LibGperfRoot} ${LibSSLRoot}) +ModuleLibIncs=(${SRS_OBJS} ${LibGperfRoot} ${LibSSLRoot}) if [[ $SRS_RTC == YES ]]; then ModuleLibIncs+=(${LibSrtpRoot}) fi @@ -323,13 +328,13 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then ModuleLibIncs+=("${LibFfmpegRoot[*]}") fi MODULE_FILES=("srs_main_server") -SERVER_INCS="src/main"; MODULE_DIR=${SERVER_INCS} . auto/modules.sh +SERVER_INCS="src/main"; MODULE_DIR=${SERVER_INCS} . $SRS_WORKDIR/auto/modules.sh SERVER_OBJS="${MODULE_OBJS[@]}" # #Main Module, for app from modules. MODULE_ID="MAIN" MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP") -ModuleLibIncs=(${SRS_OBJS_DIR} ${LibGperfRoot} ${LibSSLRoot}) +ModuleLibIncs=(${SRS_OBJS} ${LibGperfRoot} ${LibSSLRoot}) if [[ $SRS_RTC == YES ]]; then ModuleLibIncs+=(${LibSrtpRoot}) fi @@ -340,11 +345,11 @@ MODULE_FILES=() DEFINES="" # add each modules for main for SRS_MODULE in ${SRS_MODULES[*]}; do - . auto/reset_module.sh && . $SRS_MODULE/config + . $SRS_WORKDIR/auto/reset_module.sh && . $SRS_MODULE/config MODULE_FILES+=("${SRS_MODULE_MAIN[*]}") DEFINES="${DEFINES} ${SRS_MODULE_DEFINES}" done -MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh +MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . $SRS_WORKDIR/auto/modules.sh MAIN_OBJS="${MODULE_OBJS[@]}" ##################################################################################### @@ -354,7 +359,7 @@ MAIN_OBJS="${MODULE_OBJS[@]}" # all main entrances MAIN_ENTRANCES=("srs_main_server") for SRS_MODULE in ${SRS_MODULES[*]}; do - . auto/reset_module.sh && . $SRS_MODULE/config + . $SRS_WORKDIR/auto/reset_module.sh && . $SRS_MODULE/config MAIN_ENTRANCES+=("${SRS_MODULE_MAIN[*]}") done # @@ -371,7 +376,7 @@ if [[ $SRS_SRT == YES ]]; then fi # all depends objects MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${APP_OBJS[@]} ${SERVER_OBJS[@]}" -ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibGperfRoot} ${LibSSLRoot}) +ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot} ${LibGperfRoot} ${LibSSLRoot}) if [[ $SRS_RTC == YES ]]; then ModuleLibIncs+=(${LibSrtpRoot}) fi @@ -385,7 +390,7 @@ fi LINK_OPTIONS="${SrsLinkOptions}${SrsGprofLink}${SrsGperfLink}" # # srs: srs(simple rtmp server) over st(state-threads) -BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh +BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . $SRS_WORKDIR/auto/apps.sh # # For modules, with the app module. MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${APP_OBJS[@]} ${MAIN_OBJS[@]}" @@ -401,10 +406,10 @@ if [[ $SRS_SRT == YES ]]; then fi # for SRS_MODULE in ${SRS_MODULES[*]}; do - . auto/reset_module.sh && . $SRS_MODULE/config + . $SRS_WORKDIR/auto/reset_module.sh && . $SRS_MODULE/config # no SRS_MODULE_MAIN if [[ 0 -eq ${#SRS_MODULE_MAIN[@]} ]]; then continue; fi - BUILD_KEY="$SRS_MODULE_NAME" APP_MAIN="${SRS_MODULE_MAIN[0]}" APP_NAME="$SRS_MODULE_NAME" . auto/apps.sh + BUILD_KEY="$SRS_MODULE_NAME" APP_MAIN="${SRS_MODULE_MAIN[0]}" APP_NAME="$SRS_MODULE_NAME" . $SRS_WORKDIR/auto/apps.sh done # For utest on mac. # @see https://github.com/protocolbuffers/protobuf/issues/51#issuecomment-111044468 @@ -413,7 +418,7 @@ if [[ $SRS_OSX == YES ]]; then fi # # utest, the unit-test cases of srs, base on gtest1.6 -if [ $SRS_UTEST = YES ]; then +if [[ $SRS_UTEST == YES ]]; then MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_kernel" "srs_utest_core" "srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload" "srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc" @@ -424,7 +429,7 @@ if [ $SRS_UTEST = YES ]; then if [[ $SRS_GB28181 == YES ]]; then MODULE_FILES+=("srs_utest_gb28181") fi - ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot}) + ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot} ${LibSSLRoot}) if [[ $SRS_RTC == YES ]]; then ModuleLibIncs+=(${LibSrtpRoot}) fi @@ -446,23 +451,23 @@ if [ $SRS_UTEST = YES ]; then fi MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP") MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${APP_OBJS[@]} ${SRT_OBJS[@]}" - LINK_OPTIONS="-lpthread ${SrsLinkOptions}" MODULE_DIR="src/utest" APP_NAME="srs_utest" . auto/utest.sh + LINK_OPTIONS="-lpthread ${SrsLinkOptions}" MODULE_DIR="src/utest" APP_NAME="srs_utest" . $SRS_WORKDIR/auto/utest.sh fi ##################################################################################### # generate colorful summary script -. auto/summary.sh +. $SRS_WORKDIR/auto/summary.sh ##################################################################################### # makefile echo "Generate Makefile" # backup old makefile. -rm -f ${SRS_WORKDIR}/${SRS_MAKEFILE}.bk && -mv ${SRS_WORKDIR}/${SRS_MAKEFILE} ${SRS_WORKDIR}/${SRS_MAKEFILE}.bk +rm -f ${SRS_MAKEFILE}.bk && +mv ${SRS_MAKEFILE} ${SRS_MAKEFILE}.bk # generate phony header -cat << END > ${SRS_WORKDIR}/${SRS_MAKEFILE} +cat << END > ${SRS_MAKEFILE} .PHONY: default all _default install help clean destroy server srs_ingest_hls utest _prepare_dir $__mphonys .PHONY: clean_srs clean_modules clean_openssl clean_srtp2 clean_opus clean_ffmpeg clean_st .PHONY: st ffmpeg @@ -479,6 +484,7 @@ SRS_PREFIX=${SRS_PREFIX} SRS_DEFAULT_CONFIG=${SRS_DEFAULT_CONFIG} __REAL_INSTALL=\$(DESTDIR)\$(SRS_PREFIX) +JOBS=\$(shell echo \$(MAKEFLAGS)| grep -qE '\-j[0-9]+' || echo " ${SRS_JOBS}") default: server all: _default @@ -486,20 +492,20 @@ all: _default END # the real entry for all platform: -cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE} +cat << END >> ${SRS_MAKEFILE} _default: server srs_ingest_hls utest $__mdefaults help: @echo "Usage: make ||||||" @echo " help Display this help menu" @echo " clean Cleanup project and all depends" - @echo " destroy Cleanup all files for this platform in ${SRS_OBJS_DIR}/${SRS_PLATFORM}" + @echo " destroy Cleanup all files for this platform in ${SRS_OBJS}/${SRS_PLATFORM}" @echo " server Build the srs and other modules in main" @echo " utest Build the utest for srs" @echo " install Install srs to the prefix path" @echo " uninstall Uninstall srs from prefix path" @echo "To rebuild special module:" - @echo " st Rebuild st-srs in ${SRS_OBJS_DIR}/${SRS_PLATFORM}/st-srs" + @echo " st Rebuild st-srs in ${SRS_OBJS}/${SRS_PLATFORM}/st-srs" @echo " ffmpeg Rebuild ffmpeg in ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4.2-fit" @echo "To reconfigure special depends:" @echo " clean_openssl Remove the openssl cache." @@ -512,77 +518,75 @@ help: @echo " make help" doclean: - (cd ${SRS_OBJS_DIR} && rm -rf srs srs_utest $__mcleanups) - (cd ${SRS_OBJS_DIR} && rm -rf src/* include lib) - (mkdir -p ${SRS_OBJS_DIR}/utest && cd ${SRS_OBJS_DIR}/utest && rm -rf *.o *.a) + (cd ${SRS_OBJS} && rm -rf srs srs_utest $__mcleanups) + (cd ${SRS_OBJS} && rm -rf src/* include lib) + (mkdir -p ${SRS_OBJS}/utest && cd ${SRS_OBJS}/utest && rm -rf *.o *.a) clean: clean_srs clean_modules destroy: - (cd ${SRS_OBJS_DIR} && rm -rf ${SRS_PLATFORM}) + (cd ${SRS_OBJS} && rm -rf ${SRS_PLATFORM}) clean_srs: - @(cd ${SRS_OBJS_DIR} && rm -rf srs srs_utest) - @(cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf include/* lib/*) - @(cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && find src -name "*.o" -delete) - @(cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && find utest -name "*.o" -delete) + @(cd ${SRS_OBJS} && rm -rf srs srs_utest src/* utest/*) clean_modules: - @(cd ${SRS_OBJS_DIR} && rm -rf $__mdefaults) + @(cd ${SRS_OBJS} && rm -rf $__mdefaults) clean_openssl: - (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf openssl*) + @rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/openssl @echo "Please rebuild openssl by: ./configure" clean_srtp2: - (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf libsrtp-2.0.0) + @rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srtp2 @echo "Please rebuild libsrtp2 by: ./configure" clean_opus: - (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf opus-1.3.1) + @rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/opus @echo "Please rebuild opus by: ./configure" clean_ffmpeg: - (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf ffmpeg-4.2-fit) + @rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/ffmpeg @echo "Please rebuild FFmpeg by: ./configure" clean_st: - (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf st-srs) + @rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/st @echo "Please rebuild ST by: ./configure" st: - (cd ${SRS_OBJS_DIR} && rm -f srs srs_utest) - (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM}/st-srs && \$(MAKE) clean) - (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM}/st-srs && env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" \$(MAKE) ${_ST_MAKE_ARGS} CC=\$(GCC) AR=\$(AR) LD=\$(LINK) RANDLIB=\$(RANDLIB)) - @echo "Please rebuild srs by: rm -f objs/srs && make" + @rm -f ${SRS_OBJS}/srs srs_utest + @\$(MAKE)\$(JOBS) -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs clean) + @env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" \$(MAKE)\$(JOBS) -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${_ST_MAKE_ARGS} CC=\$(GCC) AR=\$(AR) LD=\$(LINK) RANDLIB=\$(RANDLIB)) + @echo "Please rebuild srs by: make" ffmpeg: - (cd ${SRS_OBJS_DIR} && rm -f srs srs_utest) - (cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4.2-fit && \$(MAKE) && \$(MAKE) install-libs) - @echo "Please rebuild srs by: rm -f objs/srs && make" + @rm -f ${SRS_OBJS}/srs srs_utest + \$(MAKE)\$(JOBS) -C ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4.2-fit + \$(MAKE)\$(JOBS) -C ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4.2-fit install-libs + @echo "Please rebuild srs by: make" END -cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE} +cat << END >> ${SRS_MAKEFILE} server: _prepare_dir @echo "Build the SRS server" - \$(MAKE) -f ${SRS_OBJS_DIR}/${SRS_MAKEFILE} srs + \$(MAKE)\$(JOBS) -f ${SRS_OBJS}/Makefile srs @bash objs/_srs_build_summary.sh END # generate all modules entry for SRS_MODULE in ${SRS_MODULES[*]}; do - . auto/reset_module.sh && . $SRS_MODULE/config - cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE} + . $SRS_WORKDIR/auto/reset_module.sh && . $SRS_MODULE/config + cat << END >> ${SRS_MAKEFILE} $SRS_MODULE_NAME: _prepare_dir server @echo "Build the $SRS_MODULE_NAME over SRS" - \$(MAKE) -f ${SRS_OBJS_DIR}/${SRS_MAKEFILE} $SRS_MODULE_NAME + \$(MAKE)\$(JOBS) -f ${SRS_OBJS}/Makefile $SRS_MODULE_NAME END done # install entry -cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE} +cat << END >> ${SRS_MAKEFILE} uninstall: @echo "rmdir \$(SRS_PREFIX)" @rm -rf \$(SRS_PREFIX) @@ -618,8 +622,8 @@ install: END -if [ $SRS_UTEST = YES ]; then - cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE} +if [[ $SRS_UTEST == YES ]]; then + cat << END >> ${SRS_MAKEFILE} utest: server @echo "Building the utest for srs" ${SrsUtestMakeEntry} @@ -627,22 +631,22 @@ utest: server END else - cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE} + cat << END >> ${SRS_MAKEFILE} utest: server @echo "Ignore utest for it's disabled." END fi -cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE} +cat << END >> ${SRS_MAKEFILE} # the ./configure will generate it. _prepare_dir: - @mkdir -p ${SRS_OBJS_DIR} + @mkdir -p ${SRS_OBJS} END # generate makefile ok, append the tails. -cat ${SRS_WORKDIR}/${SRS_MAKEFILE}.bk >> ${SRS_WORKDIR}/${SRS_MAKEFILE} && -rm -f ${SRS_WORKDIR}/${SRS_MAKEFILE}.bk +cat ${SRS_MAKEFILE}.bk >> ${SRS_MAKEFILE} && +rm -f ${SRS_MAKEFILE}.bk echo 'Configure ok! ' @@ -660,47 +664,47 @@ echo "" echo "Configure summary:" echo " ${SRS_AUTO_USER_CONFIGURE}" echo " ${SRS_AUTO_CONFIGURE}" -if [ $SRS_HLS = YES ]; then +if [[ $SRS_HLS == YES ]]; then echo -e "${GREEN}HLS is enabled.${BLACK}" else echo -e "${YELLOW}Warning: HLS is disabled.${BLACK}" fi -if [ $SRS_STREAM_CASTER = YES ]; then +if [[ $SRS_STREAM_CASTER == YES ]]; then echo -e "${YELLOW}Experiment: StreamConverter is enabled.${BLACK}" else echo -e "${GREEN}Note: StreamConverter is disabled.${BLACK}" fi -if [ $SRS_HDS = YES ]; then +if [[ $SRS_HDS == YES ]]; then echo -e "${YELLOW}Experiment: HDS is enabled.${BLACK}" else echo -e "${GREEN}Warning: HDS is disabled.${BLACK}" fi -if [ $SRS_GB28181 = YES ]; then +if [[ $SRS_GB28181 == YES ]]; then echo -e "${YELLOW}Experiment: GB28181 is enabled. https://github.com/ossrs/srs/issues/3176${BLACK}" else echo -e "${GREEN}Warning: GB28181 is disabled.${BLACK}" fi -if [ $SRS_SRT = YES ]; then +if [[ $SRS_SRT == YES ]]; then echo -e "${YELLOW}Experiment: SRT is enabled. https://github.com/ossrs/srs/issues/1147${BLACK}" else echo -e "${GREEN}Warning: SRT is disabled.${BLACK}" fi -if [ $SRS_RTC = YES ]; then +if [[ $SRS_RTC == YES ]]; then echo -e "${YELLOW}Experiment: RTC is enabled. https://github.com/ossrs/srs/issues/307${BLACK}" else echo -e "${GREEN}Warning: RTC is disabled.${BLACK}" fi -if [ $SRS_HTTPS = YES ]; then +if [[ $SRS_HTTPS == YES ]]; then echo -e "${YELLOW}Experiment: HTTPS is enabled. https://github.com/ossrs/srs/issues/1657${BLACK}" else echo -e "${GREEN}Warning: HTTPS is disabled.${BLACK}" fi -if [ $SRS_DVR = YES ]; then +if [[ $SRS_DVR == YES ]]; then echo -e "${GREEN}DVR is enabled.${BLACK}" else echo -e "${YELLOW}Warning: DVR is disabled.${BLACK}" fi -if [ $SRS_SSL = YES ]; then +if [[ $SRS_SSL == YES ]]; then echo -e "${GREEN}RTMP complex handshake is enabled${BLACK}" else echo -e "${YELLOW}Warning: RTMP complex handshake is disabled, flash cann't play h264/aac.${BLACK}" @@ -715,72 +719,72 @@ if [[ $SRS_SRTP_ASM == YES ]]; then else echo -e "${YELLOW}Warning: SRTP-NASM for WebRTC(openssl) is disabled${BLACK}" fi -if [ $SRS_TRANSCODE = YES ]; then +if [[ $SRS_TRANSCODE == YES ]]; then echo -e "${GREEN}The transcoding is enabled${BLACK}" else echo -e "${YELLOW}Warning: The transcoding is disabled.${BLACK}" fi -if [ $SRS_INGEST = YES ]; then +if [[ $SRS_INGEST == YES ]]; then echo -e "${GREEN}The ingesting is enabled.${BLACK}" else echo -e "${YELLOW}Warning: The ingesting is disabled.${BLACK}" fi -if [ $SRS_HTTP_CALLBACK = YES ]; then +if [[ $SRS_HTTP_CALLBACK == YES ]]; then echo -e "${GREEN}The http-callback is enabled${BLACK}" else echo -e "${YELLOW}Warning: The http-callback is disabled.${BLACK}" fi -if [ $SRS_HTTP_SERVER = YES ]; then +if [[ $SRS_HTTP_SERVER == YES ]]; then echo -e "${GREEN}Embeded HTTP server for HTTP-FLV/HLS is enabled.${BLACK}" else echo -e "${YELLOW}Warning: Embeded HTTP server is disabled, HTTP-FLV is disabled, please use nginx to delivery HLS.${BLACK}" fi -if [ $SRS_HTTP_API = YES ]; then +if [[ $SRS_HTTP_API == YES ]]; then echo -e "${GREEN}The HTTP API is enabled${BLACK}" else echo -e "${YELLOW}Warning: The HTTP API is disabled.${BLACK}" fi -if [ $SRS_UTEST = YES ]; then +if [[ $SRS_UTEST == YES ]]; then echo -e "${GREEN}The utests are enabled.${BLACK}" else echo -e "${YELLOW}Note: The utests are disabled.${BLACK}" fi -if [ $SRS_GPERF = YES ]; then +if [[ $SRS_GPERF == YES ]]; then echo -e "${GREEN}The gperf(tcmalloc) is enabled.${BLACK}" else echo -e "${GREEN}Note: The gperf(tcmalloc) is disabled.${BLACK}" fi -if [ $SRS_GPERF_MC = YES ]; then +if [[ $SRS_GPERF_MC == YES ]]; then echo -e "${YELLOW}The gmc(gperf memory check) is enabled, performance may suffer.${BLACK}" else echo -e "${GREEN}Note: The gmc(gperf memory check) is disabled.${BLACK}" fi -if [ $SRS_GPERF_MD = YES ]; then +if [[ $SRS_GPERF_MD == YES ]]; then echo -e "${YELLOW}The gmd(gperf memory defense) is enabled, performance may suffer.${BLACK}" else echo -e "${GREEN}Note: The gmd(gperf memory defense) is disabled.${BLACK}" fi -if [ $SRS_GPERF_MP = YES ]; then +if [[ $SRS_GPERF_MP == YES ]]; then echo -e "${YELLOW}The gmp(gperf memory profile) is enabled, performance may suffer.${BLACK}" else echo -e "${GREEN}Note: The gmp(gperf memory profile) is disabled.${BLACK}" fi -if [ $SRS_GPERF_CP = YES ]; then +if [[ $SRS_GPERF_CP == YES ]]; then echo -e "${YELLOW}The gcp(gperf cpu profile) is enabled, performance may suffer.${BLACK}" else echo -e "${GREEN}Note: The gcp(gperf cpu profile) is disabled.${BLACK}" fi -if [ $SRS_GPROF = YES ]; then +if [[ $SRS_GPROF == YES ]]; then echo -e "${YELLOW}The gprof(GNU profile tool) is enabled, performance may suffer.${BLACK}" else echo -e "${GREEN}Note: The gprof(GNU profile tool) is disabled.${BLACK}" fi -if [ $SRS_CROSS_BUILD = YES ]; then +if [[ $SRS_CROSS_BUILD == YES ]]; then echo -e "${YELLOW}The cross-build is enabled.${BLACK}" else echo -e "${GREEN}Note: The cross-build is disabled.${BLACK}" fi -if [ $SRS_VALGRIND = YES ]; then +if [[ $SRS_VALGRIND == YES ]]; then echo -e "${GREEN}The valgrind is enabled.${BLACK}" else echo -e "${GREEN}Note: The valgrind is disabled.${BLACK}" @@ -804,7 +808,7 @@ fi if [[ $SRS_CHERRYPY == YES ]]; then echo "" echo "You can run 3rdparty applications:" - if [ $SRS_HTTP_CALLBACK = YES ]; then + if [[ $SRS_HTTP_CALLBACK == YES ]]; then echo -e "\" python ./research/api-server/server.py 8085 \" to start the api-server" fi fi diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 421343e2a..61c687884 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for SRS. ## SRS 5.0 Changelog +* v5.0, 2022-11-18, For [#2532](https://github.com/ossrs/srs/issues/2532): Windows: Replace ln by cp for windows. v5.0.87 * v5.0, 2022-10-31, For [#2899](https://github.com/ossrs/srs/issues/2899): Exporter: Add metrics cpu, memory and uname. v5.0.86 * v5.0, 2022-10-30, Config: Support startting with environment variable only. v5.0.85 * v5.0, 2022-10-26, Fix [#3218](https://github.com/ossrs/srs/issues/3218): Log: Follow Java/log4j log level specs. v5.0.83 diff --git a/trunk/src/core/srs_core_version5.hpp b/trunk/src/core/srs_core_version5.hpp index 7fd6e0185..d3b9e2788 100644 --- a/trunk/src/core/srs_core_version5.hpp +++ b/trunk/src/core/srs_core_version5.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 5 #define VERSION_MINOR 0 -#define VERSION_REVISION 86 +#define VERSION_REVISION 87 #endif From 07b31910209a51fc3656a3e913ff1be9f44941a2 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 18 Nov 2022 21:27:33 +0800 Subject: [PATCH 3/4] Fix #3215: Callback: Fix bug for response string 0. v5.0.88 --- trunk/doc/CHANGELOG.md | 1 + trunk/src/app/srs_app_http_hooks.cpp | 3 ++- trunk/src/core/srs_core_version5.hpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 61c687884..cf0cbd1de 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for SRS. ## SRS 5.0 Changelog +* v5.0, 2022-11-18, Fix [#3215](https://github.com/ossrs/srs/issues/3215): Callback: Fix bug for response string 0. v5.0.88 * v5.0, 2022-11-18, For [#2532](https://github.com/ossrs/srs/issues/2532): Windows: Replace ln by cp for windows. v5.0.87 * v5.0, 2022-10-31, For [#2899](https://github.com/ossrs/srs/issues/2899): Exporter: Add metrics cpu, memory and uname. v5.0.86 * v5.0, 2022-10-30, Config: Support startting with environment variable only. v5.0.85 diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index ccbcb9184..b76f1f369 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -23,7 +23,8 @@ using namespace std; #include #include -#define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS) +// The HTTP response body should be "0", see https://github.com/ossrs/srs/issues/3215#issuecomment-1319991512 +#define SRS_HTTP_RESPONSE_OK SRS_XSTR(0) #define SRS_HTTP_HEADER_BUFFER 1024 #define SRS_HTTP_READ_BUFFER 4096 diff --git a/trunk/src/core/srs_core_version5.hpp b/trunk/src/core/srs_core_version5.hpp index d3b9e2788..578e57b69 100644 --- a/trunk/src/core/srs_core_version5.hpp +++ b/trunk/src/core/srs_core_version5.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 5 #define VERSION_MINOR 0 -#define VERSION_REVISION 87 +#define VERSION_REVISION 88 #endif From 60ba0cfdb6fcc10c9165ab15602ae835c6847115 Mon Sep 17 00:00:00 2001 From: Winlin Date: Fri, 18 Nov 2022 22:02:24 +0800 Subject: [PATCH 4/4] UTest: Enable sanitizer for utest. (#3247) 1. Enable sanitizer for utest. 2. Allow auto detect jobs for make. 3. Show more information about build cache. --- .github/workflows/codeql-analysis.yml | 4 ++-- .github/workflows/test.yml | 2 +- trunk/Dockerfile | 5 ++-- trunk/Dockerfile.builds | 34 +++++++++++++-------------- trunk/Dockerfile.cov | 4 ++-- trunk/Dockerfile.pkg | 2 +- trunk/Dockerfile.test | 4 ++-- trunk/auto/depends.sh | 1 + trunk/src/app/srs_app_gb28181.cpp | 2 +- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 38c3146a3..a8335efcf 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -27,8 +27,8 @@ jobs: run: | echo "pwd: $(pwd), who: $(whoami)" docker run --rm -v $(pwd):$(pwd) -w $(pwd)/trunk ossrs/srs:ubuntu20-cache \ - bash -c "./configure --jobs=2 && chmod 777 -R objs" - cd trunk && ./configure --jobs=2 && make -j2 + bash -c "./configure && chmod 777 -R objs" + cd trunk && ./configure && make - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b34cff63a..182d72726 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -134,7 +134,7 @@ jobs: run: docker run --rm srs:test bash -c 'make utest && ./objs/srs_utest' # For regression-test - name: Run SRS regression-test - run: docker run --rm srs:test bash -c 'make && ./objs/srs -c conf/regression-test.conf && cd 3rdparty/srs-bench && make && ./objs/srs_test -test.v' + run: docker run --rm srs:test bash -c 'make && (./objs/srs -c conf/regression-test.conf; ./etc/init.d/srs status) && cd 3rdparty/srs-bench && make && ./objs/srs_test -test.v' coverage: name: coverage diff --git a/trunk/Dockerfile b/trunk/Dockerfile index 84f7aa267..e2e3a8e52 100644 --- a/trunk/Dockerfile +++ b/trunk/Dockerfile @@ -4,9 +4,8 @@ FROM ${ARCH}${IMAGE} AS build ARG BUILDPLATFORM ARG TARGETPLATFORM -ARG JOBS=2 ARG SRS_AUTO_PACKAGER -RUN echo "BUILDPLATFORM: $BUILDPLATFORM, TARGETPLATFORM: $TARGETPLATFORM, JOBS: $JOBS, PACKAGER: ${#SRS_AUTO_PACKAGER}" +RUN echo "BUILDPLATFORM: $BUILDPLATFORM, TARGETPLATFORM: $TARGETPLATFORM, PACKAGER: ${#SRS_AUTO_PACKAGER}" # https://serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image ENV DEBIAN_FRONTEND noninteractive @@ -24,7 +23,7 @@ WORKDIR /srs/trunk # Build and install SRS. # Note that SRT is enabled by default, so we configure without --srt=on. -RUN ./configure --jobs=${JOBS} --gb28181=on --sanitizer-static=on && make -j${JOBS} && make install +RUN ./configure --gb28181=on --sanitizer-static=on && make && make install # All config files for SRS. RUN cp -R conf /usr/local/srs/conf && \ diff --git a/trunk/Dockerfile.builds b/trunk/Dockerfile.builds index 71d4c803b..d67210220 100644 --- a/trunk/Dockerfile.builds +++ b/trunk/Dockerfile.builds @@ -1,74 +1,74 @@ ######################################################## FROM ossrs/srs:dev-cache AS centos7-baseline COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off && make -j2 +RUN cd /srs/trunk && ./configure --srt=off --gb28181=off && make FROM ossrs/srs:dev-cache AS centos7-no-webrtc COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off --rtc=off && make -j2 +RUN cd /srs/trunk && ./configure --srt=off --gb28181=off --rtc=off && make FROM ossrs/srs:dev-cache AS centos7-no-asm COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off --nasm=off --srtp-nasm=off && make -j2 +RUN cd /srs/trunk && ./configure --srt=off --gb28181=off --nasm=off --srtp-nasm=off && make FROM ossrs/srs:dev-cache AS centos7-all COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=on --gb28181=on && make -j2 +RUN cd /srs/trunk && ./configure --srt=on --gb28181=on && make FROM ossrs/srs:dev-cache AS centos7-ansi-no-ffmpeg COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off --cxx11=off --cxx14=off --ffmpeg-fit=off && make -j2 +RUN cd /srs/trunk && ./configure --srt=off --gb28181=off --cxx11=off --cxx14=off --ffmpeg-fit=off && make ######################################################## FROM ossrs/srs:dev6-cache AS centos6-baseline COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off --cxx11=off --cxx14=off --sanitizer=off && make -j2 +RUN cd /srs/trunk && ./configure --srt=off --gb28181=off --cxx11=off --cxx14=off --sanitizer=off && make FROM ossrs/srs:dev6-cache AS centos6-all COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=on --gb28181=on --cxx11=off --cxx14=off --sanitizer=off && make -j2 +RUN cd /srs/trunk && ./configure --srt=on --gb28181=on --cxx11=off --cxx14=off --sanitizer=off && make ######################################################## FROM ossrs/srs:ubuntu16-cache AS ubuntu16-baseline COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off && make -j2 +RUN cd /srs/trunk && ./configure --srt=off --gb28181=off && make FROM ossrs/srs:ubuntu16-cache AS ubuntu16-all COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=on --gb28181=on && make -j2 +RUN cd /srs/trunk && ./configure --srt=on --gb28181=on && make ######################################################## FROM ossrs/srs:ubuntu18-cache AS ubuntu18-baseline COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off && make -j2 +RUN cd /srs/trunk && ./configure --srt=off --gb28181=off && make FROM ossrs/srs:ubuntu18-cache AS ubuntu18-all COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=on --gb28181=on && make -j2 +RUN cd /srs/trunk && ./configure --srt=on --gb28181=on && make ######################################################## FROM ossrs/srs:ubuntu20-cache AS ubuntu20-baseline COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --gb28181=off && make -j2 +RUN cd /srs/trunk && ./configure --srt=off --gb28181=off && make FROM ossrs/srs:ubuntu20-cache AS ubuntu20-all COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --srt=on --gb28181=on && make -j2 +RUN cd /srs/trunk && ./configure --srt=on --gb28181=on && make ######################################################## FROM ossrs/srs:ubuntu16-cross-arm AS ubuntu16-cross-armv7 COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --cross-build --cross-prefix=arm-linux-gnueabihf- && make -j2 +RUN cd /srs/trunk && ./configure --cross-build --cross-prefix=arm-linux-gnueabihf- && make FROM ossrs/srs:ubuntu16-cross-aarch64 AS ubuntu16-cross-aarch64 COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --cross-build --cross-prefix=aarch64-linux-gnu- && make -j2 +RUN cd /srs/trunk && ./configure --cross-build --cross-prefix=aarch64-linux-gnu- && make ######################################################## FROM ossrs/srs:ubuntu20-cross-arm AS ubuntu20-cross-armv7 COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --cross-build --cross-prefix=arm-linux-gnueabihf- && make -j2 +RUN cd /srs/trunk && ./configure --cross-build --cross-prefix=arm-linux-gnueabihf- && make FROM ossrs/srs:ubuntu20-cross-aarch64 AS ubuntu20-cross-aarch64 COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --cross-build --cross-prefix=aarch64-linux-gnu- && make -j2 +RUN cd /srs/trunk && ./configure --cross-build --cross-prefix=aarch64-linux-gnu- && make diff --git a/trunk/Dockerfile.cov b/trunk/Dockerfile.cov index c26a946db..ca1dd4f8f 100644 --- a/trunk/Dockerfile.cov +++ b/trunk/Dockerfile.cov @@ -8,5 +8,5 @@ COPY . /srs WORKDIR /srs/trunk # Note that we must enable the gcc7 or link failed. -RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on --gcov=on --sanitizer=off --jobs=2 -RUN scl enable devtoolset-7 -- make -j2 utest +RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on --gcov=on --sanitizer=off +RUN scl enable devtoolset-7 -- make utest diff --git a/trunk/Dockerfile.pkg b/trunk/Dockerfile.pkg index 1fb3d600a..b05263189 100644 --- a/trunk/Dockerfile.pkg +++ b/trunk/Dockerfile.pkg @@ -10,5 +10,5 @@ RUN yum install -y zip # Build and install SRS. ADD srs-server-${version}.tar.gz /srs WORKDIR /srs/srs-server-${version}/trunk -RUN ./scripts/package.sh --x86-x64 --jobs=2 --tag=${version} +RUN ./scripts/package.sh --x86-x64 --tag=${version} diff --git a/trunk/Dockerfile.test b/trunk/Dockerfile.test index 1cecb3dbb..b4e37dabd 100644 --- a/trunk/Dockerfile.test +++ b/trunk/Dockerfile.test @@ -6,8 +6,8 @@ COPY . /srs WORKDIR /srs/trunk # Note that we must enable the gcc7 or link failed. -RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on --sanitizer=off --jobs=2 -RUN scl enable devtoolset-7 -- make -j2 utest +RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --utest=on +RUN scl enable devtoolset-7 -- make utest # Build benchmark tool. RUN cd 3rdparty/srs-bench && make diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh index d6996d193..86023513b 100755 --- a/trunk/auto/depends.sh +++ b/trunk/auto/depends.sh @@ -326,6 +326,7 @@ if [[ -d /usr/local/srs-cache/srs/trunk/objs && $(pwd) != "/usr/local/srs-cache/ echo "Build from cache, source=$SOURCE_DIR, target=$TARGET_DIR" && rm -rf $TARGET_DIR && mkdir -p ${SRS_OBJS} && cp -R $SOURCE_DIR $TARGET_DIR && du -sh /usr/local/srs-cache/srs/trunk/objs/Platform-* && + du -sh /usr/local/srs-cache/srs/trunk/objs/Platform-*/* && du -sh objs/Platform-* && ls -lh objs fi diff --git a/trunk/src/app/srs_app_gb28181.cpp b/trunk/src/app/srs_app_gb28181.cpp index 8b46d0c81..042cc71b0 100644 --- a/trunk/src/app/srs_app_gb28181.cpp +++ b/trunk/src/app/srs_app_gb28181.cpp @@ -2333,7 +2333,7 @@ srs_error_t SrsRecoverablePsContext::decode_rtp(SrsBuffer* stream, int reserved, SrsRtpPacket rtp; int pos = stream->pos(); if ((err = rtp.decode(stream)) != srs_success) { - return enter_recover_mode(stream, handler, pos, err = srs_error_new(ERROR_GB_PS_HEADER, "decode rtp")); + return enter_recover_mode(stream, handler, pos, srs_error_wrap(err, "decode rtp")); } SrsRtpRawPayload* rtp_raw = dynamic_cast(rtp.payload());