Commit 87afd616 by xiongziliang

可以自定义选择编译某特性

parent 8169e57d
...@@ -12,7 +12,6 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) ...@@ -12,7 +12,6 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
#设置工程源码根目录 #设置工程源码根目录
set(ToolKit_Root ${CMAKE_SOURCE_DIR}/3rdpart/ZLToolKit/src) set(ToolKit_Root ${CMAKE_SOURCE_DIR}/3rdpart/ZLToolKit/src)
set(MediaServer_Root ${CMAKE_SOURCE_DIR}/3rdpart/media-server)
set(MediaKit_Root ${CMAKE_SOURCE_DIR}/src) set(MediaKit_Root ${CMAKE_SOURCE_DIR}/src)
#设置头文件目录 #设置头文件目录
...@@ -31,40 +30,54 @@ else() ...@@ -31,40 +30,54 @@ else()
add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS) add_definitions(-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS)
endif () endif ()
set(ENABLE_HLS true)
set(ENABLE_OPENSSL true)
set(ENABLE_MYSQL true)
set(ENABLE_MP4V2 true)
set(ENABLE_FAAC true)
set(ENABLE_X264 true)
#添加两个静态库 #添加两个静态库
set(LINK_LIB_LIST zlmediakit zltoolkit mpeg) if(ENABLE_HLS)
set(LINK_LIB_LIST zlmediakit zltoolkit mpeg)
set(MediaServer_Root ${CMAKE_SOURCE_DIR}/3rdpart/media-server)
add_definitions(-DENABLE_HLS)
message(STATUS "ENABLE_HLS defined")
else()
set(LINK_LIB_LIST zlmediakit zltoolkit)
endif()
#查找openssl是否安装 #查找openssl是否安装
find_package(OpenSSL QUIET) find_package(OpenSSL QUIET)
if (OPENSSL_FOUND) if (OPENSSL_FOUND AND ENABLE_OPENSSL)
message(STATUS "found openssl library\"${OPENSSL_INCLUDE_DIR}\",ENABLE_OPENSSL enabled") message(STATUS "found library:${OPENSSL_LIBRARIES},ENABLE_OPENSSL defined")
include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DENABLE_OPENSSL) add_definitions(-DENABLE_OPENSSL)
list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES}) list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES})
endif (OPENSSL_FOUND) endif ()
#查找mysql是否安装 #查找mysql是否安装
find_package(MYSQL QUIET) find_package(MYSQL QUIET)
if (MYSQL_FOUND) if (MYSQL_FOUND AND ENABLE_MYSQL)
message(STATUS "found mysqlclient library\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL enabled") message(STATUS "found library:${MYSQL_LIBRARIES},ENABLE_MYSQL defined")
include_directories(${MYSQL_INCLUDE_DIR}) include_directories(${MYSQL_INCLUDE_DIR})
add_definitions(-DENABLE_MYSQL) add_definitions(-DENABLE_MYSQL)
list(APPEND LINK_LIB_LIST ${MYSQL_LIBRARIES}) list(APPEND LINK_LIB_LIST ${MYSQL_LIBRARIES})
endif (MYSQL_FOUND) endif ()
#查找MP4V2是否安装 #查找MP4V2是否安装
find_package(MP4V2 QUIET) find_package(MP4V2 QUIET)
if (MP4V2_FOUND) if (MP4V2_FOUND AND ENABLE_MP4V2)
include_directories(${MP4V2_INCLUDE_DIR}) include_directories(${MP4V2_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${MP4V2_LIBRARY}) list(APPEND LINK_LIB_LIST ${MP4V2_LIBRARY})
add_definitions(-DENABLE_MP4V2) add_definitions(-DENABLE_MP4V2)
message(STATUS "found MP4V2:${MP4V2_INCLUDE_DIR},${MP4V2_LIBRARY}") message(STATUS "found library:${MP4V2_LIBRARY},ENABLE_MP4V2 defined")
endif (MP4V2_FOUND) endif ()
#查找x264是否安装 #查找x264是否安装
find_package(X264 QUIET) find_package(X264 QUIET)
if (X264_FOUND) if (X264_FOUND AND ENABLE_X264)
message(STATUS "found x264 library\"${X264_INCLUDE_DIRS}\",ENABLE_X264 enabled") message(STATUS "found library:${X264_LIBRARIES},ENABLE_X264 defined")
include_directories(${X264_INCLUDE_DIRS}) include_directories(${X264_INCLUDE_DIRS})
add_definitions(-DENABLE_X264) add_definitions(-DENABLE_X264)
list(APPEND LINK_LIB_LIST ${X264_LIBRARIES}) list(APPEND LINK_LIB_LIST ${X264_LIBRARIES})
...@@ -72,25 +85,24 @@ endif () ...@@ -72,25 +85,24 @@ endif ()
#查找faac是否安装 #查找faac是否安装
find_package(FAAC QUIET) find_package(FAAC QUIET)
if (FAAC_FOUND) if (FAAC_FOUND AND ENABLE_FAAC)
message(STATUS "found faac library\"${FAAC_INCLUDE_DIR}\",ENABLE_FAAC enabled") message(STATUS "found library:${FAAC_LIBRARIES},ENABLE_FAAC defined")
include_directories(${FAAC_INCLUDE_DIR}) include_directories(${FAAC_INCLUDE_DIR})
add_definitions(-DENABLE_FAAC) add_definitions(-DENABLE_FAAC)
list(APPEND LINK_LIB_LIST ${FAAC_LIBRARIES}) list(APPEND LINK_LIB_LIST ${FAAC_LIBRARIES})
endif () endif ()
#使能GOP缓存
add_definitions(-DENABLE_RING_USEBUF)
#添加库 #添加库
add_library(zltoolkit STATIC ${ToolKit_src_list}) add_library(zltoolkit STATIC ${ToolKit_src_list})
add_library(zlmediakit STATIC ${MediaKit_src_list}) add_library(zlmediakit STATIC ${MediaKit_src_list})
#libmpeg #libmpeg
aux_source_directory(${MediaServer_Root}/libmpeg/include src_mpeg) if(ENABLE_HLS)
aux_source_directory(${MediaServer_Root}/libmpeg/source src_mpeg) aux_source_directory(${MediaServer_Root}/libmpeg/include src_mpeg)
include_directories(${MediaServer_Root}/libmpeg/include) aux_source_directory(${MediaServer_Root}/libmpeg/source src_mpeg)
add_library(mpeg STATIC ${src_mpeg}) include_directories(${MediaServer_Root}/libmpeg/include)
add_library(mpeg STATIC ${src_mpeg})
endif()
if (WIN32) if (WIN32)
list(APPEND LINK_LIB_LIST WS2_32 Iphlpapi shlwapi) list(APPEND LINK_LIB_LIST WS2_32 Iphlpapi shlwapi)
...@@ -98,8 +110,6 @@ elseif(NOT ANDROID OR IOS) ...@@ -98,8 +110,6 @@ elseif(NOT ANDROID OR IOS)
list(APPEND LINK_LIB_LIST pthread) list(APPEND LINK_LIB_LIST pthread)
endif () endif ()
message(STATUS "linked libraries:${LINK_LIB_LIST}")
#测试程序 #测试程序
add_subdirectory(tests) add_subdirectory(tests)
......
...@@ -113,7 +113,6 @@ check_cxx_source_compiles( "#include <mysql.h>\nint main() { int i = MYSQL_OPT_U ...@@ -113,7 +113,6 @@ check_cxx_source_compiles( "#include <mysql.h>\nint main() { int i = MYSQL_OPT_U
if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES) if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
set(MYSQL_FOUND TRUE) set(MYSQL_FOUND TRUE)
message(STATUS "Found MySQL: ${MYSQL_INCLUDE_DIR}, ${MYSQL_LIBRARIES}")
else(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES) else(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
set(MYSQL_FOUND FALSE) set(MYSQL_FOUND FALSE)
message(STATUS "MySQL not found.") message(STATUS "MySQL not found.")
...@@ -124,7 +123,6 @@ if(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CO ...@@ -124,7 +123,6 @@ if(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CO
message(STATUS "Found MySQL Embedded: ${MYSQL_INCLUDE_DIR}, ${MYSQL_EMBEDDED_LIBRARIES}") message(STATUS "Found MySQL Embedded: ${MYSQL_INCLUDE_DIR}, ${MYSQL_EMBEDDED_LIBRARIES}")
else(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION) else(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
set(MYSQL_EMBEDDED_FOUND FALSE) set(MYSQL_EMBEDDED_FOUND FALSE)
message(STATUS "MySQL Embedded not found.")
endif(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION) endif(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
mark_as_advanced(MYSQL_INCLUDE_DIR MYSQL_LIBRARIES MYSQL_EMBEDDED_LIBRARIES) mark_as_advanced(MYSQL_INCLUDE_DIR MYSQL_LIBRARIES MYSQL_EMBEDDED_LIBRARIES)
...@@ -52,12 +52,14 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, ...@@ -52,12 +52,14 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
strVhost = DEFAULT_VHOST; strVhost = DEFAULT_VHOST;
} }
#if defined(ENABLE_HLS)
if(enableHls) { if(enableHls) {
auto m3u8FilePath = hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8"; auto m3u8FilePath = hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8";
_hlsMaker.reset(new HlsRecorder(m3u8FilePath,string(VHOST_KEY) + "=" + strVhost ,hlsBufSize, hlsDuration, hlsNum)); _hlsMaker.reset(new HlsRecorder(m3u8FilePath,string(VHOST_KEY) + "=" + strVhost ,hlsBufSize, hlsDuration, hlsNum));
} }
#endif //defined(ENABLE_HLS)
#ifdef ENABLE_MP4V2 #if defined(ENABLE_MP4V2)
GET_CONFIG_AND_REGISTER(string,recordPath,Record::kFilePath); GET_CONFIG_AND_REGISTER(string,recordPath,Record::kFilePath);
GET_CONFIG_AND_REGISTER(string,recordAppName,Record::kAppName); GET_CONFIG_AND_REGISTER(string,recordAppName,Record::kAppName);
...@@ -65,32 +67,38 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, ...@@ -65,32 +67,38 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
auto mp4FilePath = recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/"; auto mp4FilePath = recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/";
_mp4Maker.reset(new Mp4Maker(mp4FilePath,strVhost,strApp,strId)); _mp4Maker.reset(new Mp4Maker(mp4FilePath,strVhost,strApp,strId));
} }
#endif //ENABLE_MP4V2 #endif //defined(ENABLE_MP4V2)
} }
MediaRecorder::~MediaRecorder() { MediaRecorder::~MediaRecorder() {
} }
void MediaRecorder::inputFrame(const Frame::Ptr &frame) { void MediaRecorder::inputFrame(const Frame::Ptr &frame) {
#if defined(ENABLE_HLS)
if (_hlsMaker) { if (_hlsMaker) {
_hlsMaker->inputFrame(frame); _hlsMaker->inputFrame(frame);
} }
#ifdef ENABLE_MP4V2 #endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4V2)
if (_mp4Maker) { if (_mp4Maker) {
_mp4Maker->inputFrame(frame); _mp4Maker->inputFrame(frame);
} }
#endif //ENABLE_MP4V2 #endif //defined(ENABLE_MP4V2)
} }
void MediaRecorder::addTrack(const Track::Ptr &track) { void MediaRecorder::addTrack(const Track::Ptr &track) {
#if defined(ENABLE_HLS)
if (_hlsMaker) { if (_hlsMaker) {
_hlsMaker->addTrack(track); _hlsMaker->addTrack(track);
} }
#ifdef ENABLE_MP4V2 #endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4V2)
if (_mp4Maker) { if (_mp4Maker) {
_mp4Maker->addTrack(track); _mp4Maker->addTrack(track);
} }
#endif //ENABLE_MP4V2 #endif //defined(ENABLE_MP4V2)
} }
} /* namespace mediakit */ } /* namespace mediakit */
...@@ -30,12 +30,9 @@ ...@@ -30,12 +30,9 @@
#include <memory> #include <memory>
#include "Player/PlayerBase.h" #include "Player/PlayerBase.h"
#include "Common/MediaSink.h" #include "Common/MediaSink.h"
#ifdef ENABLE_MP4V2
#include "Mp4Maker.h" #include "Mp4Maker.h"
#endif //ENABLE_MP4V2
#include "HlsRecorder.h" #include "HlsRecorder.h"
using namespace toolkit; using namespace toolkit;
namespace mediakit { namespace mediakit {
...@@ -63,11 +60,13 @@ public: ...@@ -63,11 +60,13 @@ public:
*/ */
void addTrack(const Track::Ptr & track) override; void addTrack(const Track::Ptr & track) override;
private: private:
#if defined(ENABLE_HLS)
std::shared_ptr<HlsRecorder> _hlsMaker; std::shared_ptr<HlsRecorder> _hlsMaker;
#ifdef ENABLE_MP4V2 #endif //defined(ENABLE_HLS)
std::shared_ptr<Mp4Maker> _mp4Maker;
#endif //ENABLE_MP4V2
#if defined(ENABLE_MP4V2)
std::shared_ptr<Mp4Maker> _mp4Maker;
#endif //defined(ENABLE_MP4V2)
}; };
} /* namespace mediakit */ } /* namespace mediakit */
......
...@@ -25,8 +25,9 @@ ...@@ -25,8 +25,9 @@
*/ */
#include "TsMuxer.h" #include "TsMuxer.h"
#include <assert.h> #if defined(ENABLE_HLS)
#include "mpeg-ts-proto.h" #include "mpeg-ts-proto.h"
#include "mpeg-ts.h"
namespace mediakit { namespace mediakit {
...@@ -121,4 +122,6 @@ void TsMuxer::uninit() { ...@@ -121,4 +122,6 @@ void TsMuxer::uninit() {
_codecid_to_stream_id.clear(); _codecid_to_stream_id.clear();
} }
}//namespace mediakit }//namespace mediakit
\ No newline at end of file
#endif// defined(ENABLE_HLS)
\ No newline at end of file
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#define TSMUXER_H #define TSMUXER_H
#include <unordered_map> #include <unordered_map>
#include "mpeg-ts.h"
#include "Extension/Frame.h" #include "Extension/Frame.h"
#include "Extension/Track.h" #include "Extension/Track.h"
#include "Util/File.h" #include "Util/File.h"
...@@ -56,136 +55,5 @@ private: ...@@ -56,136 +55,5 @@ private:
List<Frame::Ptr> _frameCached; List<Frame::Ptr> _frameCached;
}; };
class TsMuxer2{
public:
typedef function<void(const void *packet, int bytes)> onTsCallback;
TsMuxer2(){
init();
}
~TsMuxer2(){
uninit();
}
bool addTrack(int track,int codec_id){
lock_guard<recursive_mutex> lck(_mtx);
auto it = _allTrackMap.find(track);
if(it != _allTrackMap.end()){
// WarnL << "Track:" << track << "已经存在!";
return false;
}
_allTrackMap[track] = codec_id;
resetAllTracks();
return true;
}
bool removeTrack(int track){
lock_guard<recursive_mutex> lck(_mtx);
auto it = _allTrackMap.find(track);
if(it == _allTrackMap.end()){
// WarnL << "Track:" << track << "不存在!";
return false;
}
DebugL << "删除Track:" << track;
_allTrackMap.erase(it);
resetAllTracks();
return true;
}
bool inputTrackData(int track, const char *data, int length, int64_t pts, int64_t dts, int flags){
lock_guard<recursive_mutex> lck(_mtx);
auto it = _track_id_to_stream_id.find(track);
if(it == _track_id_to_stream_id.end()){
WarnL << "Track:" << track << "不存在!";
return false;
}
mpeg_ts_write(_context,it->second,flags,pts,dts,data,length);
return true;
}
void setOnTsCallback(const onTsCallback &cb) {
lock_guard<recursive_mutex> lck(_mtx);
_onts = cb;
}
bool saveToFile(const string &file){
lock_guard<recursive_mutex> lck(_mtx);
FILE *fp = File::createfile_file(file.data(),"ab");
if(!fp){
WarnL << "打开文件失败:" << file << " " << get_uv_errmsg();
return false;
}
setvbuf(fp, _file_buf, _IOFBF, sizeof(_file_buf));
_file.reset(fp,[](FILE *fp){
fclose(fp);
});
return true;
}
private:
void init() {
lock_guard<recursive_mutex> lck(_mtx);
static mpeg_ts_func_t s_func= {
[](void* param, size_t bytes){
TsMuxer2 *muxer = (TsMuxer2 *)param;
assert(sizeof(TsMuxer2::_tsbuf) >= bytes);
return (void *)muxer->_tsbuf;
},
[](void* param, void* packet){
//do nothing
},
[](void* param, const void* packet, size_t bytes){
TsMuxer2 *muxer = (TsMuxer2 *)param;
muxer->onTs(packet, bytes);
}
};
if(_context == nullptr){
_context = mpeg_ts_create(&s_func,this);
}
}
void uninit() {
lock_guard<recursive_mutex> lck(_mtx);
if(_context){
mpeg_ts_destroy(_context);
_context = nullptr;
}
_track_id_to_stream_id.clear();
}
void resetAllTracks(){
lock_guard<recursive_mutex> lck(_mtx);
uninit();
init();
//添加Track
for (auto &pr : _allTrackMap){
InfoL << "添加Track:" << pr.first << " " << pr.second;
_track_id_to_stream_id[pr.first] = mpeg_ts_add_stream(_context,pr.second, nullptr,0);
}
}
void onTs(const void *packet, int bytes) {
lock_guard<recursive_mutex> lck(_mtx);
if(_onts){
_onts(packet,bytes);
}
if(_file){
fwrite(packet,bytes,1,_file.get());
}
}
private:
void *_context = nullptr;
char *_tsbuf[188];
unordered_map<int,int > _track_id_to_stream_id;
unordered_map<int,int > _allTrackMap;
recursive_mutex _mtx;
onTsCallback _onts;
char _file_buf[64 * 1024];
std::shared_ptr<FILE> _file;
};
}//namespace mediakit }//namespace mediakit
#endif //TSMUXER_H #endif //TSMUXER_H
...@@ -5,7 +5,7 @@ find_package(SDL2 QUIET) ...@@ -5,7 +5,7 @@ find_package(SDL2 QUIET)
if (SDL2_FOUND) if (SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIR}) include_directories(${SDL2_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${SDL2_LIBRARY}) list(APPEND LINK_LIB_LIST ${SDL2_LIBRARY})
message(STATUS "found SDL2:${SDL2_INCLUDE_DIR},${SDL2_LIBRARY}") message(STATUS "found library:${SDL2_LIBRARY}")
endif (SDL2_FOUND) endif (SDL2_FOUND)
#查找ffmpeg/libutil是否安装 #查找ffmpeg/libutil是否安装
...@@ -13,7 +13,7 @@ find_package(AVUTIL QUIET) ...@@ -13,7 +13,7 @@ find_package(AVUTIL QUIET)
if(AVUTIL_FOUND) if(AVUTIL_FOUND)
include_directories(${AVUTIL_INCLUDE_DIR}) include_directories(${AVUTIL_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${AVUTIL_LIBRARIES}) list(APPEND LINK_LIB_LIST ${AVUTIL_LIBRARIES})
message(STATUS "found libutil ${AVUTIL_LIBRARIES}") message(STATUS "found library:${AVUTIL_LIBRARIES}")
endif() endif()
#查找ffmpeg/libavcodec是否安装 #查找ffmpeg/libavcodec是否安装
...@@ -21,13 +21,12 @@ find_package(AVCODEC QUIET) ...@@ -21,13 +21,12 @@ find_package(AVCODEC QUIET)
if(AVCODEC_FOUND) if(AVCODEC_FOUND)
include_directories(${AVCODEC_INCLUDE_DIR}) include_directories(${AVCODEC_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${AVCODEC_LIBRARIES}) list(APPEND LINK_LIB_LIST ${AVCODEC_LIBRARIES})
message(STATUS "found libavcodec ${AVCODEC_LIBRARIES}") message(STATUS "found library:${AVCODEC_LIBRARIES}")
endif() endif()
aux_source_directory(. TEST_SRC_LIST) aux_source_directory(. TEST_SRC_LIST)
#如果ffmpeg/libavcodec ffmpeg/libavcodec SDL 都安装了则编译 test_player #如果ffmpeg/libavcodec ffmpeg/libavcodec SDL 都安装了则编译 test_player
if(SDL2_FOUND AND AVCODEC_FOUND AND AVUTIL_FOUND) if(SDL2_FOUND AND AVCODEC_FOUND AND AVUTIL_FOUND)
message(STATUS "test_player will be compiled")
else() else()
message(STATUS "test_player ingored, please install sdl2 ffmpeg/libavcodec ffmpeg/libavutil") message(STATUS "test_player ingored, please install sdl2 ffmpeg/libavcodec ffmpeg/libavutil")
list(REMOVE_ITEM TEST_SRC_LIST ./test_player.cpp) list(REMOVE_ITEM TEST_SRC_LIST ./test_player.cpp)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论