Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
87afd616
Commit
87afd616
authored
Apr 04, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
可以自定义选择编译某特性
parent
8169e57d
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
63 行增加
和
178 行删除
+63
-178
CMakeLists.txt
+34
-24
cmake/FindMYSQL.cmake
+0
-2
src/MediaFile/MediaRecorder.cpp
+14
-6
src/MediaFile/MediaRecorder.h
+6
-7
src/MediaFile/TsMuxer.cpp
+6
-3
src/MediaFile/TsMuxer.h
+0
-132
tests/CMakeLists.txt
+3
-4
没有找到文件。
CMakeLists.txt
查看文件 @
87afd616
...
...
@@ -12,7 +12,6 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
#设置工程源码根目录
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
)
#设置头文件目录
...
...
@@ -31,40 +30,54 @@ else()
add_definitions
(
-DWIN32_LEAN_AND_MEAN -DMP4V2_NO_STDINT_DEFS
)
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是否安装
find_package
(
OpenSSL QUIET
)
if
(
OPENSSL_FOUND
)
message
(
STATUS
"found
openssl library
\"
${
OPENSSL_INCLUDE_DIR
}
\"
,ENABLE_OPENSSL enabl
ed"
)
if
(
OPENSSL_FOUND
AND ENABLE_OPENSSL
)
message
(
STATUS
"found
library:
${
OPENSSL_LIBRARIES
}
,ENABLE_OPENSSL defin
ed"
)
include_directories
(
${
OPENSSL_INCLUDE_DIR
}
)
add_definitions
(
-DENABLE_OPENSSL
)
list
(
APPEND LINK_LIB_LIST
${
OPENSSL_LIBRARIES
}
)
endif
(
OPENSSL_FOUND
)
endif
()
#查找mysql是否安装
find_package
(
MYSQL QUIET
)
if
(
MYSQL_FOUND
)
message
(
STATUS
"found
mysqlclient library
\"
${
MYSQL_INCLUDE_DIR
}
\"
,ENABLE_MYSQL enabl
ed"
)
if
(
MYSQL_FOUND
AND ENABLE_MYSQL
)
message
(
STATUS
"found
library:
${
MYSQL_LIBRARIES
}
,ENABLE_MYSQL defin
ed"
)
include_directories
(
${
MYSQL_INCLUDE_DIR
}
)
add_definitions
(
-DENABLE_MYSQL
)
list
(
APPEND LINK_LIB_LIST
${
MYSQL_LIBRARIES
}
)
endif
(
MYSQL_FOUND
)
endif
()
#查找MP4V2是否安装
find_package
(
MP4V2 QUIET
)
if
(
MP4V2_FOUND
)
if
(
MP4V2_FOUND
AND ENABLE_MP4V2
)
include_directories
(
${
MP4V2_INCLUDE_DIR
}
)
list
(
APPEND LINK_LIB_LIST
${
MP4V2_LIBRARY
}
)
add_definitions
(
-DENABLE_MP4V2
)
message
(
STATUS
"found
MP4V2:
${
MP4V2_INCLUDE_DIR
}
,
${
MP4V2_LIBRARY
}
"
)
endif
(
MP4V2_FOUND
)
message
(
STATUS
"found
library:
${
MP4V2_LIBRARY
}
,ENABLE_MP4V2 defined
"
)
endif
()
#查找x264是否安装
find_package
(
X264 QUIET
)
if
(
X264_FOUND
)
message
(
STATUS
"found
x264 library
\"
${
X264_INCLUDE_DIRS
}
\"
,ENABLE_X264 enabl
ed"
)
if
(
X264_FOUND
AND ENABLE_X264
)
message
(
STATUS
"found
library:
${
X264_LIBRARIES
}
,ENABLE_X264 defin
ed"
)
include_directories
(
${
X264_INCLUDE_DIRS
}
)
add_definitions
(
-DENABLE_X264
)
list
(
APPEND LINK_LIB_LIST
${
X264_LIBRARIES
}
)
...
...
@@ -72,25 +85,24 @@ endif ()
#查找faac是否安装
find_package
(
FAAC QUIET
)
if
(
FAAC_FOUND
)
message
(
STATUS
"found
faac library
\"
${
FAAC_INCLUDE_DIR
}
\"
,ENABLE_FAAC enabl
ed"
)
if
(
FAAC_FOUND
AND ENABLE_FAAC
)
message
(
STATUS
"found
library:
${
FAAC_LIBRARIES
}
,ENABLE_FAAC defin
ed"
)
include_directories
(
${
FAAC_INCLUDE_DIR
}
)
add_definitions
(
-DENABLE_FAAC
)
list
(
APPEND LINK_LIB_LIST
${
FAAC_LIBRARIES
}
)
endif
()
#使能GOP缓存
add_definitions
(
-DENABLE_RING_USEBUF
)
#添加库
add_library
(
zltoolkit STATIC
${
ToolKit_src_list
}
)
add_library
(
zlmediakit STATIC
${
MediaKit_src_list
}
)
#libmpeg
aux_source_directory
(
${
MediaServer_Root
}
/libmpeg/include src_mpeg
)
aux_source_directory
(
${
MediaServer_Root
}
/libmpeg/source src_mpeg
)
include_directories
(
${
MediaServer_Root
}
/libmpeg/include
)
add_library
(
mpeg STATIC
${
src_mpeg
}
)
if
(
ENABLE_HLS
)
aux_source_directory
(
${
MediaServer_Root
}
/libmpeg/include src_mpeg
)
aux_source_directory
(
${
MediaServer_Root
}
/libmpeg/source src_mpeg
)
include_directories
(
${
MediaServer_Root
}
/libmpeg/include
)
add_library
(
mpeg STATIC
${
src_mpeg
}
)
endif
()
if
(
WIN32
)
list
(
APPEND LINK_LIB_LIST WS2_32 Iphlpapi shlwapi
)
...
...
@@ -98,8 +110,6 @@ elseif(NOT ANDROID OR IOS)
list
(
APPEND LINK_LIB_LIST pthread
)
endif
()
message
(
STATUS
"linked libraries:
${
LINK_LIB_LIST
}
"
)
#测试程序
add_subdirectory
(
tests
)
...
...
cmake/FindMYSQL.cmake
查看文件 @
87afd616
...
...
@@ -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
)
set
(
MYSQL_FOUND TRUE
)
message
(
STATUS
"Found MySQL:
${
MYSQL_INCLUDE_DIR
}
,
${
MYSQL_LIBRARIES
}
"
)
else
(
MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES
)
set
(
MYSQL_FOUND FALSE
)
message
(
STATUS
"MySQL not found."
)
...
...
@@ -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
}
"
)
else
(
MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION
)
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
)
mark_as_advanced
(
MYSQL_INCLUDE_DIR MYSQL_LIBRARIES MYSQL_EMBEDDED_LIBRARIES
)
src/MediaFile/MediaRecorder.cpp
查看文件 @
87afd616
...
...
@@ -52,12 +52,14 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
strVhost
=
DEFAULT_VHOST
;
}
#if defined(ENABLE_HLS)
if
(
enableHls
)
{
auto
m3u8FilePath
=
hlsPath
+
"/"
+
strVhost
+
"/"
+
strApp
+
"/"
+
strId
+
"/hls.m3u8"
;
_hlsMaker
.
reset
(
new
HlsRecorder
(
m3u8FilePath
,
string
(
VHOST_KEY
)
+
"="
+
strVhost
,
hlsBufSize
,
hlsDuration
,
hlsNum
));
}
#endif //defined(ENABLE_HLS)
#if
def ENABLE_MP4V2
#if
defined(ENABLE_MP4V2)
GET_CONFIG_AND_REGISTER
(
string
,
recordPath
,
Record
::
kFilePath
);
GET_CONFIG_AND_REGISTER
(
string
,
recordAppName
,
Record
::
kAppName
);
...
...
@@ -65,32 +67,38 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
auto
mp4FilePath
=
recordPath
+
"/"
+
strVhost
+
"/"
+
recordAppName
+
"/"
+
strApp
+
"/"
+
strId
+
"/"
;
_mp4Maker
.
reset
(
new
Mp4Maker
(
mp4FilePath
,
strVhost
,
strApp
,
strId
));
}
#endif //
ENABLE_MP4V2
#endif //
defined(ENABLE_MP4V2)
}
MediaRecorder
::~
MediaRecorder
()
{
}
void
MediaRecorder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
)
{
#if defined(ENABLE_HLS)
if
(
_hlsMaker
)
{
_hlsMaker
->
inputFrame
(
frame
);
}
#ifdef ENABLE_MP4V2
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4V2)
if
(
_mp4Maker
)
{
_mp4Maker
->
inputFrame
(
frame
);
}
#endif //
ENABLE_MP4V2
#endif //
defined(ENABLE_MP4V2)
}
void
MediaRecorder
::
addTrack
(
const
Track
::
Ptr
&
track
)
{
#if defined(ENABLE_HLS)
if
(
_hlsMaker
)
{
_hlsMaker
->
addTrack
(
track
);
}
#ifdef ENABLE_MP4V2
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4V2)
if
(
_mp4Maker
)
{
_mp4Maker
->
addTrack
(
track
);
}
#endif //
ENABLE_MP4V2
#endif //
defined(ENABLE_MP4V2)
}
}
/* namespace mediakit */
src/MediaFile/MediaRecorder.h
查看文件 @
87afd616
...
...
@@ -30,12 +30,9 @@
#include <memory>
#include "Player/PlayerBase.h"
#include "Common/MediaSink.h"
#ifdef ENABLE_MP4V2
#include "Mp4Maker.h"
#endif //ENABLE_MP4V2
#include "HlsRecorder.h"
using
namespace
toolkit
;
namespace
mediakit
{
...
...
@@ -63,11 +60,13 @@ public:
*/
void
addTrack
(
const
Track
::
Ptr
&
track
)
override
;
private
:
#if defined(ENABLE_HLS)
std
::
shared_ptr
<
HlsRecorder
>
_hlsMaker
;
#ifdef ENABLE_MP4V2
std
::
shared_ptr
<
Mp4Maker
>
_mp4Maker
;
#endif //ENABLE_MP4V2
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4V2)
std
::
shared_ptr
<
Mp4Maker
>
_mp4Maker
;
#endif //defined(ENABLE_MP4V2)
};
}
/* namespace mediakit */
...
...
src/MediaFile/TsMuxer.cpp
查看文件 @
87afd616
...
...
@@ -25,8 +25,9 @@
*/
#include "TsMuxer.h"
#i
nclude <assert.h>
#i
f defined(ENABLE_HLS)
#include "mpeg-ts-proto.h"
#include "mpeg-ts.h"
namespace
mediakit
{
...
...
@@ -121,4 +122,6 @@ void TsMuxer::uninit() {
_codecid_to_stream_id
.
clear
();
}
}
//
namespace
mediakit
\ No newline at end of file
}
//namespace mediakit
#endif// defined(ENABLE_HLS)
\ No newline at end of file
src/MediaFile/TsMuxer.h
查看文件 @
87afd616
...
...
@@ -28,7 +28,6 @@
#define TSMUXER_H
#include <unordered_map>
#include "mpeg-ts.h"
#include "Extension/Frame.h"
#include "Extension/Track.h"
#include "Util/File.h"
...
...
@@ -56,136 +55,5 @@ private:
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
#endif //TSMUXER_H
tests/CMakeLists.txt
查看文件 @
87afd616
...
...
@@ -5,7 +5,7 @@ find_package(SDL2 QUIET)
if
(
SDL2_FOUND
)
include_directories
(
${
SDL2_INCLUDE_DIR
}
)
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
)
#查找ffmpeg/libutil是否安装
...
...
@@ -13,7 +13,7 @@ find_package(AVUTIL QUIET)
if
(
AVUTIL_FOUND
)
include_directories
(
${
AVUTIL_INCLUDE_DIR
}
)
list
(
APPEND LINK_LIB_LIST
${
AVUTIL_LIBRARIES
}
)
message
(
STATUS
"found
libutil
${
AVUTIL_LIBRARIES
}
"
)
message
(
STATUS
"found
library:
${
AVUTIL_LIBRARIES
}
"
)
endif
()
#查找ffmpeg/libavcodec是否安装
...
...
@@ -21,13 +21,12 @@ find_package(AVCODEC QUIET)
if
(
AVCODEC_FOUND
)
include_directories
(
${
AVCODEC_INCLUDE_DIR
}
)
list
(
APPEND LINK_LIB_LIST
${
AVCODEC_LIBRARIES
}
)
message
(
STATUS
"found
libavcodec
${
AVCODEC_LIBRARIES
}
"
)
message
(
STATUS
"found
library:
${
AVCODEC_LIBRARIES
}
"
)
endif
()
aux_source_directory
(
. TEST_SRC_LIST
)
#如果ffmpeg/libavcodec ffmpeg/libavcodec SDL 都安装了则编译 test_player
if
(
SDL2_FOUND AND AVCODEC_FOUND AND AVUTIL_FOUND
)
message
(
STATUS
"test_player will be compiled"
)
else
()
message
(
STATUS
"test_player ingored, please install sdl2 ffmpeg/libavcodec ffmpeg/libavutil"
)
list
(
REMOVE_ITEM TEST_SRC_LIST ./test_player.cpp
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论