Merge branch 'gitee'

This commit is contained in:
gozfree
2022-04-13 21:40:21 +08:00
60 changed files with 930 additions and 431 deletions

View File

@@ -1,31 +1,7 @@
cmake_minimum_required(VERSION 3.9)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
include_directories(include)
PROJECT(gear-lib)
set(darray_src src/libdarray.c src/libserializer.c)
set(hash_src src/libhash.c)
set(posix_src src/libposix.c)
set(base64_src src/libbase64.c)
set(log_src src/liblog.c)
set(file_src src/filewatcher.c src/fio.c src/io.c src/libfile.c)
set(ipc_src src/libipc.c src/msgq_posix.c src/msgq_sysv.c src/netlink.c src/shm.c src/unix_socket.c)
set(gevent_src src/epoll.c src/libgevent.c src/poll.c src/select.c)
set(dict_src src/libdict.c)
set(queue_src src/libqueue.c)
set(vector_src src/libvector.c)
set(media-io_src src/audio-def.c src/libmedia-io.c src/video-def.c)
add_library(posix SHARED ${posix_src})
add_library(hash SHARED ${hash_src})
add_library(media-io SHARED ${media-io_src})
add_library(darray SHARED ${darray_src})
add_library(gevent SHARED ${gevent_src})
add_library(dict SHARED ${dict_src})
add_library(ipc SHARED ${ipc_src})
target_link_libraries(ipc rt gevent dict)
add_library(log SHARED ${log_src})
add_library(file SHARED ${file_src})
add_library(queue SHARED ${queue_src})
add_library(vector SHARED ${vector_src})
INCLUDE(build/cmake_env.inc)
ADD_SUBDIRECTORY(gear-lib)

View File

@@ -10,7 +10,7 @@
* 全部用POSIX C实现目标是为了跨平台兼容linux, windows, android, ios.
* 适用于物联网,嵌入式,以及网络服务开发等场景
![struct](https://github.com/gozfree/gear-lib/blob/master/build/gear-lib.png)
![struct](./build/gear-lib.png)
## 数据结构
| | |

View File

@@ -10,7 +10,7 @@ This is a collection of basic libraries.
* All are written in POSIX C, aim to used compatibility on linux, windows, android, ios.
* Aim to reuse for IOT, embedded and network service development
![struct](https://github.com/gozfree/gear-lib/blob/master/build/gear-lib.png)
![struct](./build/gear-lib.png)
## Data Struct
| | |

24
build/cmake_env.inc Normal file
View File

@@ -0,0 +1,24 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20)
PROJECT(gear-lib)
#set output directory
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
SET(TD_TESTS_OUTPUT_DIR ${PROJECT_BINARY_DIR}/test)
MESSAGE(STATUS "============= Compile Env ============= ")
MESSAGE(STATUS " CPU Info: " ${CMAKE_SYSTEM_PROCESSOR})
MESSAGE(STATUS " OS Info: " ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION})
MESSAGE(STATUS "Host Info: " ${CMAKE_HOST_SYSTEM_NAME})
MESSAGE(STATUS "============= Compile Env ============= ")
MESSAGE(STATUS "Project source directory: " ${PROJECT_SOURCE_DIR})
MESSAGE(STATUS "Project binary files output path: " ${PROJECT_BINARY_DIR})
MESSAGE(STATUS "Project executable files output path: " ${EXECUTABLE_OUTPUT_PATH})
MESSAGE(STATUS "Project library files output path: " ${LIBRARY_OUTPUT_PATH})
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(OS_LINUX TRUE)
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
SET(OS_WINDOWS TRUE)
ENDIF ()

View File

@@ -80,8 +80,10 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "librtsp", "librtsp\librtsp.vcxproj", "{968FA321-4230-4DD4-A554-2619A7D5D080}"
ProjectSection(ProjectDependencies) = postProject
{2B438236-335D-4F87-8D3A-A10300C7F7DA} = {2B438236-335D-4F87-8D3A-A10300C7F7DA}
{BAF9105C-FF03-4D1C-96A0-DF2F8270936F} = {BAF9105C-FF03-4D1C-96A0-DF2F8270936F}
{8682FC88-8540-447B-87CF-4E2B3DAF50A9} = {8682FC88-8540-447B-87CF-4E2B3DAF50A9}
{88F2DE94-0375-40CF-92C0-70B98C56B508} = {88F2DE94-0375-40CF-92C0-70B98C56B508}
{67EEB99D-920D-4E28-BC28-477A8E334023} = {67EEB99D-920D-4E28-BC28-477A8E334023}
{C8C000B6-BF66-420C-A7B8-D566E955731A} = {C8C000B6-BF66-420C-A7B8-D566E955731A}
{2E965CCF-A6DE-4D7D-84A6-ED3F79659914} = {2E965CCF-A6DE-4D7D-84A6-ED3F79659914}
{819399D0-724E-4805-B513-480B317CE139} = {819399D0-724E-4805-B513-480B317CE139}
@@ -102,6 +104,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libhal", "libhal\libhal.vcx
{2E965CCF-A6DE-4D7D-84A6-ED3F79659914} = {2E965CCF-A6DE-4D7D-84A6-ED3F79659914}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libvector", "libvector\libvector.vcxproj", "{8CAD541B-A89A-48B0-B7EC-AF9E527EA8CE}"
ProjectSection(ProjectDependencies) = postProject
{2E965CCF-A6DE-4D7D-84A6-ED3F79659914} = {2E965CCF-A6DE-4D7D-84A6-ED3F79659914}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdict", "libdict\libdict.vcxproj", "{46503A91-6BD1-4B9A-8DE4-7EA7AA0091B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -176,6 +185,14 @@ Global
{496D075D-50CA-465D-9D0A-D9229257FC48}.Debug|Win32.Build.0 = Debug|Win32
{496D075D-50CA-465D-9D0A-D9229257FC48}.Release|Win32.ActiveCfg = Release|Win32
{496D075D-50CA-465D-9D0A-D9229257FC48}.Release|Win32.Build.0 = Release|Win32
{8CAD541B-A89A-48B0-B7EC-AF9E527EA8CE}.Debug|Win32.ActiveCfg = Debug|Win32
{8CAD541B-A89A-48B0-B7EC-AF9E527EA8CE}.Debug|Win32.Build.0 = Debug|Win32
{8CAD541B-A89A-48B0-B7EC-AF9E527EA8CE}.Release|Win32.ActiveCfg = Release|Win32
{8CAD541B-A89A-48B0-B7EC-AF9E527EA8CE}.Release|Win32.Build.0 = Release|Win32
{46503A91-6BD1-4B9A-8DE4-7EA7AA0091B7}.Debug|Win32.ActiveCfg = Debug|Win32
{46503A91-6BD1-4B9A-8DE4-7EA7AA0091B7}.Debug|Win32.Build.0 = Debug|Win32
{46503A91-6BD1-4B9A-8DE4-7EA7AA0091B7}.Release|Win32.ActiveCfg = Release|Win32
{46503A91-6BD1-4B9A-8DE4-7EA7AA0091B7}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{46503A91-6BD1-4B9A-8DE4-7EA7AA0091B7}</ProjectGuid>
<RootNamespace>libdict</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\gear-lib\libposix;..\..\..\..\gear-lib\libposix\MsvcLibX\include;..\..\..\..\gear-lib\libposix\pthreads4w;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>"/DUCRTINCLUDE=$(VCInstallDir)include" "/DMSVCINCLUDE=$(VCInstallDir)include" "/DWSDKINCLUDE=$(WindowsSdkDir)Include" %(AdditionalOptions)</AdditionalOptions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\gear-lib\libdict\libdict.c" />
<ClCompile Include="..\..\..\..\gear-lib\libdict\test_libdict.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\gear-lib\libdict\libdict.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\..\gear-lib\libdict\Makefile" />
<None Include="..\..\..\..\gear-lib\libdict\README.md" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\gear-lib\libdict\libdict.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\gear-lib\libdict\test_libdict.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\gear-lib\libdict\libdict.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\..\gear-lib\libdict\Makefile" />
<None Include="..\..\..\..\gear-lib\libdict\README.md" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

View File

@@ -69,6 +69,7 @@
<ClInclude Include="..\..\..\..\gear-lib\libgevent\wepoll.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\gear-lib\libgevent\epoll.c" />
<ClCompile Include="..\..\..\..\gear-lib\libgevent\libgevent.c" />
<ClCompile Include="..\..\..\..\gear-lib\libgevent\iocp.c" />
<ClCompile Include="..\..\..\..\gear-lib\libgevent\select.c" />

View File

@@ -16,7 +16,7 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
@@ -74,4 +74,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@@ -42,7 +42,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>..\..\..\..\gear-lib\libposix;..\..\..\..\gear-lib\libposix\MsvcLibX\include;..\..\..\..\gear-lib\libposix\pthreads4w;..\..\..\..\gear-lib\liblog;..\..\..\..\gear-lib\libsock;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\gear-lib\libposix;..\..\..\..\gear-lib\libposix\MsvcLibX\include;..\..\..\..\gear-lib\libposix\pthreads4w;..\..\..\..\gear-lib\liblog;..\..\..\..\gear-lib\libsock;..\..\..\..\gear-lib\libtime;..\..\..\..\gear-lib\libdict;..\..\..\..\gear-lib\libgevent;..\..\..\..\gear-lib\libdarray;..\..\..\..\gear-lib\libthread;..\..\..\..\gear-lib\libmedia-io;..\..\..\..\gear-lib\libfile;..\..\..\..\gear-lib\libuvc;..\..\..\..\gear-lib\libqueue;..\..\..\..\gear-lib\librtsp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>"/DUCRTINCLUDE=$(VCInstallDir)include" "/DMSVCINCLUDE=$(VCInstallDir)include" "/DWSDKINCLUDE=$(WindowsSdkDir)Include" %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
@@ -64,6 +64,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<None Include="..\..\..\..\gear-lib\librtsp\Android.mk" />
<None Include="..\..\..\..\gear-lib\librtsp\libx264.a" />
<None Include="..\..\..\..\gear-lib\librtsp\Makefile" />
<None Include="..\..\..\..\gear-lib\librtsp\README.md" />
<None Include="..\..\..\..\gear-lib\librtsp\sample.264" />
@@ -79,12 +80,12 @@
<ClInclude Include="..\..\..\..\gear-lib\librtsp\sdp.h" />
<ClInclude Include="..\..\..\..\gear-lib\librtsp\transport_session.h" />
<ClInclude Include="..\..\..\..\gear-lib\librtsp\uri_parse.h" />
<ClInclude Include="..\..\..\..\gear-lib\librtsp\x264.h" />
<ClInclude Include="..\..\..\..\gear-lib\librtsp\x264_config.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\gear-lib\librtsp\librtsp_server.c" />
<ClCompile Include="..\..\..\..\gear-lib\librtsp\media_source.c" />
<ClCompile Include="..\..\..\..\gear-lib\librtsp\media_source_h264.c" />
<ClCompile Include="..\..\..\..\gear-lib\librtsp\media_source_live.c" />
<ClCompile Include="..\..\..\..\gear-lib\librtsp\request_handle.c" />
<ClCompile Include="..\..\..\..\gear-lib\librtsp\rtp.c" />
<ClCompile Include="..\..\..\..\gear-lib\librtsp\rtp_h264.c" />

View File

@@ -20,6 +20,7 @@
<None Include="..\..\..\..\gear-lib\librtsp\README.md" />
<None Include="..\..\..\..\gear-lib\librtsp\sample.264" />
<None Include="..\..\..\..\gear-lib\librtsp\TODO" />
<None Include="..\..\..\..\gear-lib\librtsp\libx264.a" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\gear-lib\librtsp\librtsp.h">
@@ -49,6 +50,12 @@
<ClInclude Include="..\..\..\..\gear-lib\librtsp\uri_parse.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\gear-lib\librtsp\x264.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\gear-lib\librtsp\x264_config.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\gear-lib\librtsp\librtsp_server.c">
@@ -57,12 +64,6 @@
<ClCompile Include="..\..\..\..\gear-lib\librtsp\media_source.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\gear-lib\librtsp\media_source_h264.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\gear-lib\librtsp\media_source_live.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\gear-lib\librtsp\request_handle.c">
<Filter>Source Files</Filter>
</ClCompile>

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8CAD541B-A89A-48B0-B7EC-AF9E527EA8CE}</ProjectGuid>
<RootNamespace>libvector</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>..\..\..\..\gear-lib\libposix;..\..\..\..\gear-lib\libposix\MsvcLibX\include;..\..\..\..\gear-lib\libposix\pthreads4w;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>"/DUCRTINCLUDE=$(VCInstallDir)include" "/DMSVCINCLUDE=$(VCInstallDir)include" "/DWSDKINCLUDE=$(WindowsSdkDir)Include" %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\gear-lib\libvector\libvector.c" />
<ClCompile Include="..\..\..\..\gear-lib\libvector\test_libvector.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\gear-lib\libvector\libvector.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\..\gear-lib\libvector\Makefile" />
<None Include="..\..\..\..\gear-lib\libvector\Makefile.nmake" />
<None Include="..\..\..\..\gear-lib\libvector\README.md" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\gear-lib\libvector\libvector.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\gear-lib\libvector\test_libvector.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\gear-lib\libvector\libvector.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\..\gear-lib\libvector\Makefile" />
<None Include="..\..\..\..\gear-lib\libvector\Makefile.nmake" />
<None Include="..\..\..\..\gear-lib\libvector\README.md" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

32
gear-lib/CMakeLists.txt Normal file
View File

@@ -0,0 +1,32 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
SET(POSIX_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libposix/)
SET(DICT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libdict/)
SET(DARRAY_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libdarray/)
SET(THREAD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libthread/)
SET(GEVENT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libgevent/)
SET(MEDIA_IO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libmedia-io/)
SET(QUEUE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libqueue/)
SET(LOG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/liblog/)
SET(SOCK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libsock/)
SET(FILE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libfile/)
SET(UVC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libuvc/)
SET(TIME_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libtime/)
ADD_SUBDIRECTORY(libposix)
ADD_SUBDIRECTORY(libbase64)
ADD_SUBDIRECTORY(libbitmap)
ADD_SUBDIRECTORY(libdict)
ADD_SUBDIRECTORY(libdarray)
ADD_SUBDIRECTORY(libqueue)
ADD_SUBDIRECTORY(libthread)
ADD_SUBDIRECTORY(libgevent)
ADD_SUBDIRECTORY(libfile)
ADD_SUBDIRECTORY(libtime)
ADD_SUBDIRECTORY(libsock)
ADD_SUBDIRECTORY(liblog)
ADD_SUBDIRECTORY(libmedia-io)
ADD_SUBDIRECTORY(libuvc)
ADD_SUBDIRECTORY(librtmpc)
ADD_SUBDIRECTORY(librtsp)

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
ADD_LIBRARY(base64 ${SOURCE_FILES})

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
ADD_LIBRARY(bitmap ${SOURCE_FILES})

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${POSIX_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_FILES)
add_library(config ${SOURCE_FILES})

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
ADD_LIBRARY(darray ${SOURCE_FILES})

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
ADD_LIBRARY(dict ${SOURCE_FILES})

View File

@@ -19,6 +19,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
#include <libposix.h>
#include "libdict.h"
#include <stdio.h>
#include <stdlib.h>

View File

@@ -21,7 +21,6 @@
******************************************************************************/
#include "libdict.h"
#include <string.h>
#include <time.h>
#include <sys/time.h>
#define ALIGN "%15s: %6.4f sec\n"

View File

@@ -0,0 +1,13 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR} ${DICT_INCLUDE_DIR} ${GEVENT_INCLUDE_DIR} ${DARRAY_INCLUDE_DIR} ${THREAD_INCLUDE_DIR})
LIST(APPEND SOURCE_FILES libfile.c fio.c io.c)
IF (DEFINED OS_LINUX)
LIST(APPEND SOURCE_FILES filewatcher.c)
ENDIF ()
ADD_LIBRARY(file ${SOURCE_FILES})

View File

@@ -0,0 +1,14 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR} ${DARRAY_INCLUDE_DIR} ${THREAD_INCLUDE_DIR})
LIST(APPEND SOURCE_FILES libgevent.c)
IF (DEFINED OS_LINUX)
LIST(APPEND SOURCE_FILES epoll.c libgevent.c poll.c select.c)
ELSEIF (DEFINED OS_WINDOWS)
LIST(APPEND SOURCE_FILES wepoll.c iocp.c)
ENDIF ()
ADD_LIBRARY(gevent ${SOURCE_FILES})

View File

@@ -80,7 +80,7 @@ $(TGT_LIB_A): $(OBJS_LIB)
$(AR_V) rcs $@ $^
$(TGT_LIB_SO): $(OBJS_LIB)
$(CC_V) -o $@ $^ $(SHARED)
$(CC_V) -o $@ $^ $(SHARED) $(LDFLAGS)
@mv $(TGT_LIB_SO) $(TGT_LIB_SO_VER)
@ln -sf $(TGT_LIB_SO_VER) $(TGT_LIB_SO)

View File

@@ -20,18 +20,28 @@
* SOFTWARE.
******************************************************************************/
#include "libgevent.h"
#if defined (OS_LINUX)
#ifndef __CYGWIN__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#if defined (OS_LINUX)
#include <sys/epoll.h>
#elif defined (OS_WINDOWS)
#include "wepoll.h"
#endif
#if defined (OS_LINUX)
#define epoll_fd_t int
#define is_epoll_fd_invalid(fd) (fd == -1)
#elif defined (OS_WINDOWS)
#define epoll_fd_t HANDLE
#define is_epoll_fd_invalid(fd) (fd == NULL)
#endif
#ifdef __ANDROID__
#define EPOLLRDHUP (0x2000)
#define EPOLLRDHUP (1U << 13)
#endif
#define EPOLL_MAX_NEVENT (4096)
@@ -39,17 +49,17 @@
(((LONG_MAX) - 999) / 1000)
struct epoll_ctx {
int epfd;
epoll_fd_t epfd;
int nevents;
struct epoll_event *events;
};
static void *epoll_init(void)
{
int fd;
epoll_fd_t fd;
struct epoll_ctx *ec;
fd = epoll_create(1);
if (-1 == fd) {
if (is_epoll_fd_invalid(fd)) {
printf("epoll_create errno=%d %s\n", errno, strerror(errno));
return NULL;
}
@@ -93,7 +103,6 @@ static int epoll_add(struct gevent_base *eb, struct gevent *e)
epev.events |= EPOLLONESHOT;
else
epev.events &= ~EPOLLONESHOT;
epev.events |= EPOLLET;
epev.data.ptr = (void *)e;
@@ -129,7 +138,6 @@ static int epoll_mod(struct gevent_base *eb, struct gevent *e)
epev.events |= EPOLLONESHOT;
else
epev.events &= ~EPOLLONESHOT;
epev.events |= EPOLLET;
epev.data.ptr = (void *)e;
@@ -201,12 +209,28 @@ static int epoll_dispatch(struct gevent_base *eb, struct timeval *tv)
}
struct gevent_ops epollops = {
.init = epoll_init,
.deinit = epoll_deinit,
.add = epoll_add,
.del = epoll_del,
.mod = epoll_mod,
.dispatch = epoll_dispatch,
#if defined (OS_LINUX)
.init =
#endif
epoll_init,
#if defined (OS_LINUX)
.deinit =
#endif
epoll_deinit,
#if defined (OS_LINUX)
.add =
#endif
epoll_add,
#if defined (OS_LINUX)
.del =
#endif
epoll_del,
#if defined (OS_LINUX)
.mod =
#endif
epoll_mod,
#if defined (OS_LINUX)
.dispatch =
#endif
epoll_dispatch,
};
#endif
#endif

View File

@@ -22,20 +22,20 @@
#include "libgevent.h"
#include <stdio.h>
#include <stdlib.h>
#if defined (OS_LINUX) || defined (OS_APPLE)
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#if defined (OS_LINUX) || defined (OS_APPLE)
#ifndef __CYGWIN__
#include <sys/eventfd.h>
#endif
#endif
#include <errno.h>
#if defined (OS_LINUX) || defined (OS_RTTHREAD) || defined (OS_APPLE)
extern const struct gevent_ops selectops;
extern const struct gevent_ops pollops;
#endif
#if defined (OS_LINUX)
#if defined (OS_LINUX) || defined (OS_WINDOWS)
#ifndef __CYGWIN__
extern const struct gevent_ops epollops;
#endif
@@ -45,10 +45,16 @@ extern const struct gevent_ops iocpops;
#endif
enum gevent_backend_type {
#if defined (OS_LINUX) || defined (OS_RTTHREAD) || defined (OS_APPLE)
GEVENT_SELECT,
GEVENT_POLL,
#endif
#if defined (OS_LINUX) || defined (OS_WINDOWS)
GEVENT_EPOLL,
#endif
#if defined (OS_WINDOWS)
GEVENT_IOCP,
#endif
};
struct gevent_backend {
@@ -61,7 +67,7 @@ static struct gevent_backend gevent_backend_list[] = {
{GEVENT_SELECT, &selectops},
{GEVENT_POLL, &pollops},
#endif
#if defined (OS_LINUX)
#if defined (OS_LINUX) || defined (OS_WINDOWS)
#ifndef __CYGWIN__
{GEVENT_EPOLL, &epollops},
#endif
@@ -76,7 +82,8 @@ static struct gevent_backend gevent_backend_list[] = {
#elif defined (OS_APPLE)
#define GEVENT_BACKEND GEVENT_POLL
#elif defined (OS_WINDOWS)
#define GEVENT_BACKEND GEVENT_IOCP
//#define GEVENT_BACKEND GEVENT_IOCP
#define GEVENT_BACKEND GEVENT_EPOLL
#endif
static void event_in(int fd, void *arg)
@@ -201,7 +208,7 @@ void gevent_base_loop_break(struct gevent_base *eb)
void gevent_base_signal(struct gevent_base *eb)
{
uint64_t notify;
uint64_t notify = '1';
if (sizeof(uint64_t) != write(eb->inner_fd, &notify, sizeof(uint64_t))) {
perror("write error");
}

View File

@@ -47,7 +47,8 @@ enum EPOLL_EVENTS {
EPOLLWRBAND = (int) (1U << 9),
EPOLLMSG = (int) (1U << 10), /* Never reported. */
EPOLLRDHUP = (int) (1U << 13),
EPOLLONESHOT = (int) (1U << 31)
EPOLLONESHOT = (int) (1U << 30),
EPOLLET = (int) (1U << 31) /* Not used, just for compile compatible */
};
#define EPOLLIN (1U << 0)
@@ -61,7 +62,8 @@ enum EPOLL_EVENTS {
#define EPOLLWRBAND (1U << 9)
#define EPOLLMSG (1U << 10)
#define EPOLLRDHUP (1U << 13)
#define EPOLLONESHOT (1U << 31)
#define EPOLLONESHOT (1U << 30)
#define EPOLLET (1U << 31)
#define EPOLL_CTL_ADD 1
#define EPOLL_CTL_MOD 2

View File

@@ -50,7 +50,8 @@ enum EPOLL_EVENTS {
EPOLLWRBAND = (int) (1U << 9),
EPOLLMSG = (int) (1U << 10), /* Never reported. */
EPOLLRDHUP = (int) (1U << 13),
EPOLLONESHOT = (int) (1U << 31)
EPOLLONESHOT = (int) (1U << 30),
EPOLLET = (int) (1U << 31) /* Not used, just for compile compatible */
};
#define EPOLLIN (1U << 0)
@@ -64,7 +65,8 @@ enum EPOLL_EVENTS {
#define EPOLLWRBAND (1U << 9)
#define EPOLLMSG (1U << 10)
#define EPOLLRDHUP (1U << 13)
#define EPOLLONESHOT (1U << 31)
#define EPOLLONESHOT (1U << 30)
#define EPOLLET (1U << 31)
#define EPOLL_CTL_ADD 1
#define EPOLL_CTL_MOD 2

View File

@@ -61,7 +61,7 @@ EXTRA_CFLAGS += -I$(OUTPUT)/include/gear-lib
SHARED := -shared
EXTRA_LDFLAGS := $($(ARCH)_LDFLAGS)
EXTRA_LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -ldict -lgevent -ldarray -lthread
EXTRA_LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -lposix -ldict -lgevent -ldarray -lthread
EXTRA_LDFLAGS += -pthread -lrt

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
ADD_LIBRARY(log ${SOURCE_FILES})

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
ADD_LIBRARY(media-io ${SOURCE_FILES})

View File

@@ -0,0 +1,16 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(.)
LIST(APPEND SOURCE_FILES libposix.c)
IF (DEFINED OS_LINUX)
LIST(APPEND SOURCE_FILES libposix4nix.c)
ELSEIF (DEFINED OS_WINDOWS)
AUX_SOURCE_DIRECTORY(MsvcLibX MSVCLIBX_SRC)
AUX_SOURCE_DIRECTORY(pthreads4w PTHREADS4W_SRC)
LIST(APPEND SOURCE_FILES ${MSVCLIBX_SRC} ${PTHREADS4W_SRC})
ENDIF ()
ADD_LIBRARY(posix ${SOURCE_FILES})

View File

@@ -134,7 +134,10 @@ GEAR_API void usleep(unsigned long usec);
typedef int clockid_t;
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME ((clockid_t)1)
#define CLOCK_REALTIME ((clockid_t)0)
#endif
#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC ((clockid_t)1)
#endif
#ifndef CLOCK_PROCESS_CPUTIME_ID
#define CLOCK_PROCESS_CPUTIME_ID ((clockid_t)2)
@@ -142,9 +145,7 @@ typedef int clockid_t;
#ifndef CLOCK_THREAD_CPUTIME_ID
#define CLOCK_THREAD_CPUTIME_ID ((clockid_t)3)
#endif
#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC ((clockid_t)4)
#endif
/******************************************************************************

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
ADD_LIBRARY(queue ${SOURCE_FILES})

View File

@@ -0,0 +1,9 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR} ${DARRAY_INCLUDE_DIR} ${MEDIA_IO_INCLUDE_DIR} ${QUEUE_INCLUDE_DIR} ${THREAD_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_CRYPTO")
ADD_LIBRARY(rtmpc ${SOURCE_FILES})

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR} ${LOG_INCLUDE_DIR} ${DICT_INCLUDE_DIR} ${THREAD_INCLUDE_DIR} ${GEVENT_INCLUDE_DIR} ${DARRAY_INCLUDE_DIR} ${SOCK_INCLUDE_DIR} ${MEDIA_IO_INCLUDE_DIR} ${FILE_INCLUDE_DIR} ${QUEUE_INCLUDE_DIR} ${UVC_INCLUDE_DIR} ${TIME_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
ADD_LIBRARY(rtsp ${SOURCE_FILES})

View File

@@ -19,6 +19,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
#include <libposix.h>
#include <liblog.h>
#include <libdict.h>
#include "librtsp.h"
#include <libsock.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -26,10 +31,7 @@
#include <time.h>
#include <errno.h>
#include <sys/time.h>
#include <liblog.h>
#include <libdict.h>
#include "librtsp.h"
#include <libsock.h>
#include "media_source.h"
#include "transport_session.h"
#include "rtsp_parser.h"
@@ -98,8 +100,9 @@ static void rtsp_connect_create(struct rtsp_server *rtsp, int fd, uint32_t ip, u
static void rtsp_connect_destroy(struct rtsp_server *rtsp, int fd)
{
char key[9];
struct rtsp_request *req;
snprintf(key, sizeof(key), "%d", fd);
struct rtsp_request *req = (struct rtsp_request *)dict_get(rtsp->connect_pool, key, NULL);
req = (struct rtsp_request *)dict_get(rtsp->connect_pool, key, NULL);
logi("fd = %d, req=%p\n", fd, req);
dict_del(rtsp->connect_pool, key);
gevent_del(rtsp->evbase, &req->event);

View File

@@ -40,10 +40,10 @@ typedef struct media_source {
char sdp[SDP_LEN_MAX];
struct timeval tm_create;
int (*sdp_generate)(struct media_source *ms);
int (*open)(struct media_source *ms, const char *uri);
int (*read)(struct media_source *ms, void **data, size_t *len);
int (*write)(struct media_source *ms, void *data, size_t len);
void (*close)(struct media_source *ms);
int (*_open)(struct media_source *ms, const char *uri);
int (*_read)(struct media_source *ms, void **data, size_t *len);
int (*_write)(struct media_source *ms, void *data, size_t len);
void (*_close)(struct media_source *ms);
int (*get_frame)();
void *opaque;
bool is_active;

View File

@@ -40,12 +40,13 @@ struct h264_source_ctx {
static void *item_alloc_hook(void *data, size_t len, void *arg)
{
struct media_packet *new_pkt;
struct media_packet *pkt = (struct media_packet *)arg;
if (!pkt) {
loge("calloc packet failed!\n");
return NULL;
}
struct media_packet *new_pkt = media_packet_copy(pkt, MEDIA_MEM_SHALLOW);
new_pkt = media_packet_copy(pkt, MEDIA_MEM_SHALLOW);
logd("media_packet size=%d\n", media_packet_get_size(new_pkt));
return new_pkt;
}
@@ -71,26 +72,29 @@ static int h264_parser_frame(struct h264_source_ctx *c, const char *name)
{
int ret = 0;
size_t count = 0;
size_t bytes;
const uint8_t *start, *end, *nalu, *nalu2;
struct media_packet *pkt;
struct queue_item *it;
struct iovec *data = file_dump(name);
if (!data) {
loge("file_dump %s failed!\n", name);
return -1;
}
const uint8_t *start = data->iov_base;
const uint8_t *end = start + data->iov_len;
const uint8_t *nalu = h264_find_start_code(start, end);
start = data->iov_base;
end = start + data->iov_len;
nalu = h264_find_start_code(start, end);
while (nalu < end) {
const uint8_t *nalu2 = h264_find_start_code(nalu + 4, end);
size_t bytes = nalu2 - nalu;
struct media_packet *pkt = media_packet_create(MEDIA_TYPE_VIDEO, MEDIA_MEM_SHALLOW, (uint8_t *)nalu, bytes);
nalu2 = h264_find_start_code(nalu + 4, end);
bytes = nalu2 - nalu;
pkt = media_packet_create(MEDIA_TYPE_VIDEO, MEDIA_MEM_SHALLOW, (uint8_t *)nalu, bytes);
pkt->video->pts = 90000 * count++;
pkt->video->dts = 90000 * count++;
pkt->video->encoder.timebase.num = 30;
pkt->video->encoder.timebase.den = 1;
struct queue_item *it = queue_item_alloc(c->q, pkt->video->data, pkt->video->size, pkt);
it = queue_item_alloc(c->q, pkt->video->data, pkt->video->size, pkt);
if (!it) {
loge("item_alloc packet type %d failed!\n", pkt->type);
ret = -1;
@@ -199,8 +203,8 @@ static int sdp_generate(struct media_source *ms)
struct media_source media_source_h264 = {
.name = "H264",
.sdp_generate = sdp_generate,
.open = h264_file_open,
.read = h264_file_read_frame,
.write = h264_file_write,
.close = h264_file_close,
._open = h264_file_open,
._read = h264_file_read_frame,
._write = h264_file_write,
._close = h264_file_close,
};

View File

@@ -68,7 +68,7 @@ struct live_source_ctx {
void *priv;
};
static struct live_source_ctx g_live = {.uvc_opened = false};
static struct live_source_ctx g_live;
static int pixel_format_to_x264_csp(enum pixel_format fmt)
{
@@ -205,6 +205,7 @@ failed:
static int init_pic_data(struct x264_ctx *c, x264_picture_t *pic,
struct video_frame *frame)
{
int i;
x264_picture_init(pic);
pic->i_pts = frame->timestamp;
pic->img.i_csp = c->param.i_csp;
@@ -233,7 +234,7 @@ pic->img.i_plane, frame->planes);
return -1;
}
for (int i = 0; i < pic->img.i_plane; i++) {
for (i = 0; i < pic->img.i_plane; i++) {
pic->img.i_stride[i] = (int)frame->linesize[i];
pic->img.plane[i] = frame->data[i];
}
@@ -243,6 +244,7 @@ pic->img.i_plane, frame->planes);
static int fill_packet(struct x264_ctx *c, struct video_packet *pkt,
x264_nal_t *nals, int nal_cnt, x264_picture_t *pic_out)
{
int i;
if (!nal_cnt)
return -1;
@@ -253,7 +255,7 @@ static int fill_packet(struct x264_ctx *c, struct video_packet *pkt,
pkt->encoder.extra_size = c->encoder.extra_size;
c->append_extra = true;
}
for (int i = 0; i < nal_cnt; i++) {
for (i = 0; i < nal_cnt; i++) {
x264_nal_t *nal = nals + i;
da_push_back_array(c->packet_data, nal->p_payload, nal->i_payload);
}
@@ -341,6 +343,7 @@ static uint32_t get_random_number()
static int live_open(struct media_source *ms, const char *name)
{
struct live_source_ctx *c = &g_live;
g_live.uvc_opened = false;
if (c->uvc_opened) {
logi("uvc already opened!\n");
return 0;
@@ -350,7 +353,7 @@ static int live_open(struct media_source *ms, const char *name)
c->conf.fps.num = 30;
c->conf.fps.den = 1;
c->conf.format = PIXEL_FORMAT_YUY2,
c->uvc = uvc_open(UVC_TYPE_V4L2, "/dev/video0", &c->conf);
c->uvc = uvc_open("/dev/video0", &c->conf);
if (!c->uvc) {
loge("uvc open failed!\n");
return -1;
@@ -444,7 +447,7 @@ static int live_read(struct media_source *ms, void **data, size_t *len)
struct media_source media_source_uvc = {
.name = "uvc",
.sdp_generate = sdp_generate,
.open = live_open,
.read = live_read,
.close = live_close,
._open = live_open,
._read = live_read,
._close = live_close,
};

View File

@@ -91,13 +91,15 @@ int handle_rtsp_response(struct rtsp_request *req, int code, const char *msg)
static int on_teardown(struct rtsp_request *req, char *url)
{
struct rtsp_server *rc;
struct transport_session *ts;
//int len = sock_send(req->fd, resp, strlen(resp));
if (-1 == parse_range(&req->range, (char *)req->raw->iov_base, req->raw->iov_len)) {
loge("parse_range failed!\n");
return -1;
}
struct rtsp_server *rc = req->rtsp_server;
struct transport_session *ts = transport_session_lookup(rc->transport_session_pool, req->session.id);
rc = req->rtsp_server;
ts = transport_session_lookup(rc->transport_session_pool, req->session.id);
if (!ts) {
loge("transport_session is NULL\n");
return handle_rtsp_response(req, 454, NULL);
@@ -153,6 +155,7 @@ static int on_setup(struct rtsp_request *req, char *url)
{
char buf[RTSP_RESPONSE_LEN_MAX];
char transport[128];
struct transport_session *ts;
struct rtsp_server *rc = req->rtsp_server;
if (-1 == parse_transport(&req->transport, (char *)req->raw->iov_base, req->raw->iov_len)) {
@@ -171,7 +174,7 @@ static int on_setup(struct rtsp_request *req, char *url)
sock_addr_ntop(req->transport.destination, req->client.ip);
}
struct transport_session *ts = transport_session_lookup(rc->transport_session_pool, req->session.id);
ts = transport_session_lookup(rc->transport_session_pool, req->session.id);
if (!ts) {
ts = transport_session_create(rc->transport_session_pool, &req->transport);
if (!ts) {
@@ -210,18 +213,21 @@ static int on_play(struct rtsp_request *req, char *url)
{
int n = 0;
char buf[RTSP_RESPONSE_LEN_MAX];
struct rtsp_server *rc;
struct transport_session *ts;
struct media_source *ms;
if (-1 == parse_range(&req->range, (char *)req->raw->iov_base, req->raw->iov_len)) {
loge("parse_range failed!\n");
return -1;
}
struct rtsp_server *rc = req->rtsp_server;
struct transport_session *ts = transport_session_lookup(rc->transport_session_pool, req->session.id);
rc = req->rtsp_server;
ts = transport_session_lookup(rc->transport_session_pool, req->session.id);
if (!ts) {
handle_rtsp_response(req, 454, NULL);
return -1;
}
struct media_source *ms = rtsp_media_source_lookup(url);
ms = rtsp_media_source_lookup(url);
if (req->range.to > 0) {
n += snprintf(buf+n, sizeof(buf)-n, "Range: npt=%.3f-%.3f\r\n", (float)(req->range.from / 1000.0f), (float)(req->range.to / 1000.0f));

View File

@@ -301,11 +301,12 @@ int rtp_ssrc(void)
struct rtp_socket *rtp_socket_create(enum rtp_mode mode, int tcp_fd, const char* src_ip, const char *dst_ip)
{
unsigned short i;
struct rtp_socket *s = calloc(1, sizeof(struct rtp_socket));
if (!s) {
return NULL;
}
unsigned short i;
s->mode = mode;
switch (mode) {
case RTP_TCP:

View File

@@ -22,8 +22,11 @@
#ifndef LIBRTP_H
#define LIBRTP_H
#include <libposix.h>
#include <stdint.h>
#if defined (OS_LINUX)
#include <netinet/in.h>
#endif
#include <libmedia-io.h>
#ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@@ -19,11 +19,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
#include "sdp.h"
#include <libposix.h>
#include <liblog.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sdp.h"
#define SDP_TOOL_NAME ((const char *)"ipcam rtsp")
#define SDP_TOOL_VERSION ((const char *)"version 2016.05.22")
@@ -267,21 +268,6 @@ const char* SDP_LIVE_FMT =
int get_sdp(struct media_source *ms, char *sdp, size_t len)
{
int sdp_len = 0;
char sdp_filter[128];
char sdp_range[128];
const char *sdp_media = "m=video 0 RTP/AVP 33\r\nc=IN IP4 0.0.0.0\r\nb=AS:5000\r\na=control:track1";
float dur = duration();
if (dur == 0.0) {
snprintf(sdp_range, sizeof(sdp_range), "%s", "a=range:npt=0-\r\n");
} else if (dur > 0.0) {
snprintf(sdp_range, sizeof(sdp_range), "%s", "a=range:npt=0-%.3f\r\n");
} else { // subsessions have differing durations, so "a=range:" lines go there
snprintf(sdp_range, sizeof(sdp_range), "%s", "");
}
snprintf(sdp_filter, sizeof(sdp_filter), SDP_FILTER_FMT, RTSP_SERVER_IP);
char const* const sdp_prefix_fmt =
"v=0\r\n"
"o=- %ld%06ld %d IN IP4 %s\r\n"
@@ -296,6 +282,20 @@ int get_sdp(struct media_source *ms, char *sdp, size_t len)
"a=x-qt-text-nam:%s\r\n"
"a=x-qt-text-inf:%s\r\n"
"%s";
int sdp_len = 0;
char sdp_filter[128];
char sdp_range[128];
const char *sdp_media = "m=video 0 RTP/AVP 33\r\nc=IN IP4 0.0.0.0\r\nb=AS:5000\r\na=control:track1";
float dur = duration();
if (dur == 0.0) {
snprintf(sdp_range, sizeof(sdp_range), "%s", "a=range:npt=0-\r\n");
} else if (dur > 0.0) {
snprintf(sdp_range, sizeof(sdp_range), "%s", "a=range:npt=0-%.3f\r\n");
} else { // subsessions have differing durations, so "a=range:" lines go there
snprintf(sdp_range, sizeof(sdp_range), "%s", "");
}
snprintf(sdp_filter, sizeof(sdp_filter), SDP_FILTER_FMT, RTSP_SERVER_IP);
sdp_len = strlen(sdp_prefix_fmt)
+ 20 + 6 + 20 + strlen("127.0.0.1")

View File

@@ -19,10 +19,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
#include "librtsp.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "librtsp.h"
int main(int argc, char **argv)
{

View File

@@ -19,14 +19,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
#include "transport_session.h"
#include "media_source.h"
#include "rtp.h"
#include <libposix.h>
#include <liblog.h>
#include <libtime.h>
#include <libdict.h>
#include <libgevent.h>
#include <libmedia-io.h>
#include "transport_session.h"
#include "media_source.h"
#include "rtp.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -103,40 +105,45 @@ static void *send_thread(struct thread *t, void *ptr)
struct media_source *ms = ts->media_source;
void *data = NULL;
size_t len = 0;
unsigned int ssrc, seq;
uint64_t pts;
int ret;
if (-1 == ms->open(ms, "sample.264")) {
struct media_packet *mpkt;
struct video_packet *vpkt;
struct rtp_packet *rpkt;
if (-1 == ms->_open(ms, "sample.264")) {
loge("open failed!\n");
return NULL;
}
ms->is_active = true;
unsigned int ssrc = (unsigned int)rtp_ssrc();
uint64_t pts = time_now_msec();
unsigned int seq = ssrc;
ssrc = (unsigned int)rtp_ssrc();
pts = time_now_msec();
seq = ssrc;
logd("rtp send thread %s created\n", t->name);
while (t->run) {
if (-1 == ms->read(ms, &data, &len) || data == NULL) {
if (-1 == ms->_read(ms, &data, &len) || data == NULL) {
loge("read failed!\n");
sleep(1);
continue;
}
struct media_packet *pkt = data;
switch (pkt->type) {
mpkt = data;
switch (mpkt->type) {
case MEDIA_TYPE_AUDIO:
logd("MEDIA_TYPE_AUDIO\n");
break;
case MEDIA_TYPE_VIDEO: {
logd("MEDIA_TYPE_VIDEO\n");
struct video_packet *vpkt = pkt->video;
struct rtp_packet *pkt = rtp_packet_create(RTP_PT_H264, vpkt->size, seq, ssrc);
if (!pkt) {
vpkt = mpkt->video;
rpkt = rtp_packet_create(RTP_PT_H264, vpkt->size, seq, ssrc);
if (!rpkt) {
loge("rtp_packet_create failed!\n");
break;
}
pts = get_ms_time_v(vpkt, vpkt->dts);
logd("rtp_packet_create video size=%d, pts=%d\n", vpkt->size, pts);
ret = rtp_payload_h264_encode(ts->rtp->sock, pkt, vpkt->data, vpkt->size, pts);
seq = pkt->header.seq;
rtp_packet_destroy(pkt);
ret = rtp_payload_h264_encode(ts->rtp->sock, rpkt, vpkt->data, vpkt->size, pts);
seq = rpkt->header.seq;
rtp_packet_destroy(rpkt);
if (ret == -1) {
loge("rtp_payload_h264_encode failed!\n");
t->run = false;
@@ -148,15 +155,16 @@ static void *send_thread(struct thread *t, void *ptr)
}
}
ms->is_active = false;
ms->close(ms);
ms->_close(ms);
return NULL;
}
static void on_recv(int fd, void *arg)
{
int ret;
char buf[2048];
memset(buf, 0, sizeof(buf));
int ret = sock_recv(fd, buf, 2048);
ret = sock_recv(fd, buf, 2048);
if (ret > 0) {
rtcp_parse(buf, ret);
} else if (ret == 0) {

View File

@@ -0,0 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(gear-lib)
INCLUDE_DIRECTORIES(. ${POSIX_INCLUDE_DIR} ${GEVENT_INCLUDE_DIR} ${DARRAY_INCLUDE_DIR} ${THREAD_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(. SOURCE_FILES)
ADD_LIBRARY(sock ${SOURCE_FILES})

Some files were not shown because too many files have changed in this diff Show More