diff --git a/.travis.yml b/.travis.yml index 9a0a133ef..7e14b12b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ before_script: script: - mkdir build - cd build - - cmake -DCODE_COVERAGE=ON -DTRAVIS=ON -DCMAKE_BUILD_TYPE=Debug ../ + - cmake -DCODE_COVERAGE=ON -DTRAVIS=ON -DUSEASAN=ON -DCMAKE_BUILD_TYPE=Debug ../ - cmake --build . --config Debug -- -j8 after_success: diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f1e75752..4b06df4a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,12 @@ cmake_minimum_required(VERSION 3.15) project(CicadaMedia) + +#set(USEASAN ON) +#set(USETSAN ON) +#set(USEUBSAN ON) +if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + # set(USEMSAN ON) +endif () add_subdirectory(cmdline) diff --git a/cmdline/CMakeLists.txt b/cmdline/CMakeLists.txt index adb81ae2c..714e97eca 100644 --- a/cmdline/CMakeLists.txt +++ b/cmdline/CMakeLists.txt @@ -3,13 +3,6 @@ project(cicadaPlayer) set(CMAKE_CXX_STANDARD 11) -#set(USEASAN ON) -#set(USETSAN ON) -#set(USEUBSAN ON) -if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") -# set(USEMSAN ON) -endif () - if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") else () set(CMAKE_CXX_FLAGS "-fprofile-instr-generate -fcoverage-mapping") diff --git a/framework/cacheModule/CacheManager.cpp b/framework/cacheModule/CacheManager.cpp index cc5153f50..ee3f3c944 100644 --- a/framework/cacheModule/CacheManager.cpp +++ b/framework/cacheModule/CacheManager.cpp @@ -7,6 +7,7 @@ #include #include #include +#include CacheManager::CacheManager() { @@ -98,6 +99,9 @@ void CacheManager::sendMediaFrame(const unique_ptr &frame, StreamType if (metaRet == 0) { streamMetas.push_back(audioMeta); + } else { + releaseMeta(audioMeta); + free(audioMeta); } } mCacheModule.setStreamMeta(streamMetas); diff --git a/framework/cacheModule/CacheModule.cpp b/framework/cacheModule/CacheModule.cpp index 9c36a02d5..eaaebe5b8 100644 --- a/framework/cacheModule/CacheModule.cpp +++ b/framework/cacheModule/CacheModule.cpp @@ -258,6 +258,7 @@ void CacheModule::clearStreamMetas() if (!mStreamMetas.empty()) { for (auto &item : mStreamMetas) { releaseMeta(item); + free(item); } mStreamMetas.clear(); diff --git a/framework/tests/CMakeLists.txt b/framework/tests/CMakeLists.txt index 60ee3ca3f..9160a70be 100644 --- a/framework/tests/CMakeLists.txt +++ b/framework/tests/CMakeLists.txt @@ -5,6 +5,16 @@ if (!HAVE_COVERAGE_CONFIG) include(../code_coverage.cmake) endif () +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(TARGET_PLATFORM macOSX) +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(TARGET_PLATFORM Linux) +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(TARGET_PLATFORM windows) +endif () + +include(../${TARGET_PLATFORM}.cmake) + include(GoogleTest.cmake) add_subdirectory(dataSource) add_subdirectory(render) diff --git a/framework/tests/dataSource/CMakeLists.txt b/framework/tests/dataSource/CMakeLists.txt index 4b3fb43e3..bca6ffb5c 100644 --- a/framework/tests/dataSource/CMakeLists.txt +++ b/framework/tests/dataSource/CMakeLists.txt @@ -10,6 +10,8 @@ if (APPLE) include(../Apple.cmake) endif () +include(../../${TARGET_PLATFORM}.cmake) + cmake_policy(SET CMP0079 NEW) add_executable(dataSourceTest "") diff --git a/framework/tests/dataSource/dataSourceUnitTest.cpp b/framework/tests/dataSource/dataSourceUnitTest.cpp index 32497068e..165285a12 100644 --- a/framework/tests/dataSource/dataSourceUnitTest.cpp +++ b/framework/tests/dataSource/dataSourceUnitTest.cpp @@ -61,6 +61,7 @@ TEST(protocol, file) char *obuffer = static_cast(malloc(strlen(buffer) + 1)); source->Read(obuffer, strlen(buffer) + 1); ASSERT_EQ(memcmp(buffer, obuffer, strlen(buffer) + 1), 0); + free(obuffer); } TEST(dns, https) diff --git a/framework/tests/decoder/CMakeLists.txt b/framework/tests/decoder/CMakeLists.txt index 8ea3af5f9..81c3e7dc3 100644 --- a/framework/tests/decoder/CMakeLists.txt +++ b/framework/tests/decoder/CMakeLists.txt @@ -13,6 +13,7 @@ if (APPLE) include(../Apple.cmake) endif () +include(../../${TARGET_PLATFORM}.cmake) target_sources(decoderUnitTest PRIVATE decoderUnitTest.cpp diff --git a/framework/tests/demuxer/CMakeLists.txt b/framework/tests/demuxer/CMakeLists.txt index 726a79fc8..d70896431 100644 --- a/framework/tests/demuxer/CMakeLists.txt +++ b/framework/tests/demuxer/CMakeLists.txt @@ -13,6 +13,8 @@ if (APPLE) include(../Apple.cmake) endif () +include(../../${TARGET_PLATFORM}.cmake) + target_sources(demuxerUnitTest PRIVATE demuxerUnitTest.cpp diff --git a/framework/tests/render/CMakeLists.txt b/framework/tests/render/CMakeLists.txt index f622e51fe..51e6c7e17 100644 --- a/framework/tests/render/CMakeLists.txt +++ b/framework/tests/render/CMakeLists.txt @@ -13,6 +13,8 @@ if (APPLE) include(../Apple.cmake) endif () +include(../../${TARGET_PLATFORM}.cmake) + target_sources(renderTest PRIVATE diff --git a/mediaPlayer/tests/apiTest/CMakeLists.txt b/mediaPlayer/tests/apiTest/CMakeLists.txt index 5dfb50877..9107d473e 100644 --- a/mediaPlayer/tests/apiTest/CMakeLists.txt +++ b/mediaPlayer/tests/apiTest/CMakeLists.txt @@ -12,6 +12,7 @@ endif () if (APPLE) include(../../../framework/tests/Apple.cmake) endif () +include(../../../framework/${TARGET_PLATFORM}.cmake) add_executable(mediaPlayerApiTest "") diff --git a/mediaPlayer/tests/apiTest/mediaPlayerApiTest.cpp b/mediaPlayer/tests/apiTest/mediaPlayerApiTest.cpp index 3880f25cc..624efdac4 100644 --- a/mediaPlayer/tests/apiTest/mediaPlayerApiTest.cpp +++ b/mediaPlayer/tests/apiTest/mediaPlayerApiTest.cpp @@ -8,6 +8,7 @@ #include #include "tests/player_command.h" #include +#include using namespace std; @@ -204,6 +205,8 @@ static void getApiOnPrepared(void *arg) Stream_meta meta{}; apiPlayer->GetCurrentStreamMeta(&meta, ST_TYPE_VIDEO); + releaseMeta(&meta); + } TEST(coverag, getApi) diff --git a/mediaPlayer/tests/cache/CMakeLists.txt b/mediaPlayer/tests/cache/CMakeLists.txt index 9b4b639ce..bd00e1717 100644 --- a/mediaPlayer/tests/cache/CMakeLists.txt +++ b/mediaPlayer/tests/cache/CMakeLists.txt @@ -13,6 +13,8 @@ if (APPLE) include(../../../framework/tests/Apple.cmake) endif () +include(../../../framework/${TARGET_PLATFORM}.cmake) + add_executable(mediaPlayerCacheTest "") target_sources(mediaPlayerCacheTest diff --git a/mediaPlayer/tests/formatTest/CMakeLists.txt b/mediaPlayer/tests/formatTest/CMakeLists.txt index 25467ff82..62417abd5 100644 --- a/mediaPlayer/tests/formatTest/CMakeLists.txt +++ b/mediaPlayer/tests/formatTest/CMakeLists.txt @@ -13,6 +13,7 @@ if (APPLE) include(../../../framework/tests/Apple.cmake) endif () +include(../../../framework/${TARGET_PLATFORM}.cmake) add_executable(mediaPlayerFormatTest "") target_sources(mediaPlayerFormatTest diff --git a/mediaPlayer/tests/player_command.cpp b/mediaPlayer/tests/player_command.cpp index c8e50c736..a4dc25b7f 100644 --- a/mediaPlayer/tests/player_command.cpp +++ b/mediaPlayer/tests/player_command.cpp @@ -28,6 +28,7 @@ int command_loop(Cicada::MediaPlayer *player, void *arg) return -1; return 0; } + std::unique_lock lock(pCase->mMutex); player_command &cmd = pCase->mCommands.front(); if (cmd.timestamp < af_getsteady_ms()) { switch (cmd.mID) { diff --git a/mediaPlayer/tests/player_command.h b/mediaPlayer/tests/player_command.h index ea8fd9af8..ba8595a9d 100644 --- a/mediaPlayer/tests/player_command.h +++ b/mediaPlayer/tests/player_command.h @@ -8,6 +8,7 @@ #include #include +#include class player_command { public: @@ -44,6 +45,7 @@ class commandsCase { } std::vector &mCommands; + std::mutex mMutex; bool mExitOnEmpty{true}; }; diff --git a/mediaPlayer/tests/seekTest/CMakeLists.txt b/mediaPlayer/tests/seekTest/CMakeLists.txt index 7fb17b075..5fb3d8b6b 100644 --- a/mediaPlayer/tests/seekTest/CMakeLists.txt +++ b/mediaPlayer/tests/seekTest/CMakeLists.txt @@ -13,6 +13,8 @@ if (APPLE) include(../../../framework/tests/Apple.cmake) endif () +include(../../../framework/${TARGET_PLATFORM}.cmake) + add_executable(mediaPlayerSeekTest "") target_sources(mediaPlayerSeekTest diff --git a/mediaPlayer/tests/switch_stream/CMakeLists.txt b/mediaPlayer/tests/switch_stream/CMakeLists.txt index 6fb6e0554..6fda7b2da 100644 --- a/mediaPlayer/tests/switch_stream/CMakeLists.txt +++ b/mediaPlayer/tests/switch_stream/CMakeLists.txt @@ -13,6 +13,8 @@ if (APPLE) include(../../../framework/tests/Apple.cmake) endif () +include(../../../framework/${TARGET_PLATFORM}.cmake) + add_executable(mediaPlayerSwitchStreamTest "") target_sources(mediaPlayerSwitchStreamTest diff --git a/mediaPlayer/tests/switch_stream/mediaPlayerSwitchStream.cpp b/mediaPlayer/tests/switch_stream/mediaPlayerSwitchStream.cpp index 52c4aa1ab..294f73dde 100644 --- a/mediaPlayer/tests/switch_stream/mediaPlayerSwitchStream.cpp +++ b/mediaPlayer/tests/switch_stream/mediaPlayerSwitchStream.cpp @@ -52,6 +52,7 @@ static void createTestCase_switchVideo(commandsCase &testCase) testCase.mCommands.push_back(cmd); cmd.mID = player_command::selectStream; int64_t start_time = af_getsteady_ms(); + std::unique_lock lock(testCase.mMutex); for (int i = 0; i < count; i++) { cmd.timestamp = i * posDelta + start_time; cmd.arg0 = i; @@ -79,6 +80,7 @@ static void createTestCase_switchSubtitle(commandsCase &testCase) cmd.timestamp += 3 * posDelta; cmd.mID = player_command::setLoop; cmd.arg0 = 0; + std::unique_lock lock(testCase.mMutex); testCase.mCommands.push_back(cmd); } @@ -89,7 +91,10 @@ static void onPrepared_video(void *userData) player_command cmd; cmd.mID = player_command::start; cmd.timestamp = af_getsteady_ms(); - testCase->mCommands.push_back(cmd); + { + std::unique_lock lock(testCase->mMutex); + testCase->mCommands.push_back(cmd); + } createTestCase_switchVideo(*testCase); testCase->mExitOnEmpty = true; } @@ -102,7 +107,10 @@ static void onPrepared_subtitle(void *userData) player_command cmd; cmd.mID = player_command::start; cmd.timestamp = af_getsteady_ms(); - testCase->mCommands.push_back(cmd); + { + std::unique_lock lock(testCase->mMutex); + testCase->mCommands.push_back(cmd); + } createTestCase_switchSubtitle(*testCase); testCase->mExitOnEmpty = true; }