Add ffmpeg.
This commit is contained in:
commit
b9f67a16b2
32
README.md
32
README.md
|
@ -9,11 +9,33 @@
|
|||
* SDK工程所有开发文档均使用markdown语法编写,需要使用markdown语法解析器进行解析,方便阅读,如:Typora;开发工程师建议使用vscode安装markdownlint插件进行阅读;
|
||||
* SDK工程所有文档描述路径时,"//"双斜杠表示工程根目录;
|
||||
|
||||
## 1.2. 编译
|
||||
## 1.2. 开发环境准备
|
||||
|
||||
  工程的开发,需要预安装一些开发工具。例如:cmake的特定版本,llvm工具等。
|
||||
|
||||
### 1.2.1. cmake安装
|
||||
|
||||
  cmake是一个跨平台的安装(编译)工具,它是由Kitware公司开发的一个开源软件,可以用来配置、构建、编译一个工程。
|
||||
|
||||
```code
|
||||
# 项目根目录执行:
|
||||
$ make install-cmake
|
||||
```
|
||||
|
||||
### 1.2.2. llvm工具安装
|
||||
|
||||
  LLVM是一个编译器工具链,包含clang编译器、llvm核心库等。此处只用了clang-tidy和clang-format工具,一个负责编码规范,一个负责代码格式化。
|
||||
|
||||
```code
|
||||
# 项目根目录执行:
|
||||
$ make compile_llvm
|
||||
```
|
||||
|
||||
## 1.3. 编译
|
||||
|
||||
  架构设计上支持去平台编译和运行,本仓库源码可仿真运行在ubuntu系统。
|
||||
|
||||
### 1.2.1. Ubuntu系统
|
||||
### 1.3.1. Ubuntu系统
|
||||
|
||||
在项目根目录下执行命令:
|
||||
|
||||
|
@ -24,7 +46,7 @@ cd cmake-shell/ // 在中间文件目录进行编译,把所有中间文件
|
|||
make // 编译全部输出构建文件
|
||||
```
|
||||
|
||||
### 1.2.2. 交叉编译
|
||||
### 1.3.2. 交叉编译
|
||||
|
||||
参考:
|
||||
|
||||
|
@ -37,9 +59,9 @@ make // 编译全部输出构建文件
|
|||
|
||||
  交叉编译请参考基于IPC SDK作为子仓库的工程配置,此处忽略。
|
||||
|
||||
### 1.2.3. 小技巧
|
||||
### 1.3.3. 小技巧
|
||||
|
||||
#### 1.2.3.1. 代码阅读辅助工具(基于vscode)
|
||||
#### 1.3.3.1. 代码阅读辅助工具(基于vscode)
|
||||
|
||||
  为了方便代码跳转阅读,除了安装基本的c++插件外,结合cmake构建工具生成的compile_commands.json文件可实现代码之间的精准跳转。
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
#include "AppMonitor.h"
|
||||
#include "ILog.h"
|
||||
#include <vector>
|
||||
AppMonitor::AppMonitor() : mMicStatus(SwitchStatus::END)
|
||||
{
|
||||
}
|
||||
StatusCode AppMonitor::GetProductInfo(AppGetProductInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetProductInfo.\n");
|
||||
|
@ -65,7 +68,7 @@ StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
|||
}
|
||||
StatusCode AppMonitor::GetParamValue(AppParamValue ¶m)
|
||||
{
|
||||
param.mMicStatus = SwitchStatus::ON;
|
||||
param.mMicStatus = mMicStatus;
|
||||
param.mRec = SwitchStatus::OFF;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
|
@ -114,16 +117,18 @@ StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::v
|
|||
}
|
||||
StatusCode AppMonitor::SetDateTime(const AppSetDateTime ¶m)
|
||||
{
|
||||
//
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetTimeZone(const unsigned int &zone)
|
||||
{
|
||||
//
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::SetParamValue(const AppSetParamValue ¶m)
|
||||
{
|
||||
LogInfo("SetParamValue: param = %s.\n", param.mName.c_str());
|
||||
if (param.mName == "mic") {
|
||||
mMicStatus = static_cast<SwitchStatus>(param.mValue);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::EnterRecorder(void)
|
||||
|
@ -136,7 +141,6 @@ StatusCode AppMonitor::AppPlayback(const PlayBackEvent &event)
|
|||
}
|
||||
StatusCode AppMonitor::UploadFile(AppUploadFile ¶m)
|
||||
{
|
||||
//
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetThumbnail(AppGetThumbnail ¶m)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
class AppMonitor : public VAppMonitor
|
||||
{
|
||||
public:
|
||||
AppMonitor() = default;
|
||||
AppMonitor();
|
||||
virtual ~AppMonitor() = default;
|
||||
StatusCode GetProductInfo(AppGetProductInfo ¶m) override;
|
||||
StatusCode GetDeviceAttr(AppGetDeviceAttr ¶m) override;
|
||||
|
@ -41,5 +41,8 @@ public:
|
|||
|
||||
private:
|
||||
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
|
||||
|
||||
private:
|
||||
SwitchStatus mMicStatus; // TODO: improve delete.
|
||||
};
|
||||
#endif
|
239
doc/git_guide.md
Normal file
239
doc/git_guide.md
Normal file
|
@ -0,0 +1,239 @@
|
|||
# 1. git使用手册
|
||||
|
||||
## 1.1. 概述
|
||||
|
||||
  git是分布式版本控制系统,在多人开发中,git可以很好的管理代码的版本。
|
||||
|
||||
## 1.2. 源码托管服务器
|
||||
|
||||
  github和gitlab还有gitee(国产)都是开源的代码托管服务器,可以用来管理源码。
|
||||
|
||||
## 1.3. git安装
|
||||
|
||||
## 1.4. git分支管理
|
||||
|
||||
### 1.4.1. git创建本地分支
|
||||
|
||||
* 基于远端分支创建一个本地分支,同时新建一个对应的远端分支:
|
||||
|
||||
  当主干发生较大变化,例如:原厂更新sdk时,需要新建分支,划分界限。
|
||||
|
||||
```code
|
||||
$ git branch -a
|
||||
----------------
|
||||
* master
|
||||
remotes/origin/HEAD -> origin/master
|
||||
remotes/origin/app_test
|
||||
remotes/origin/master
|
||||
$ git checkout -b master-sdk-202405 origin/master
|
||||
-------------------------------------------------
|
||||
M ipc-sdk
|
||||
Branch 'master-sdk-202405' set up to track remote branch 'master' from 'origin'.
|
||||
Switched to a new branch 'master-sdk-202405'
|
||||
$ git branch -a
|
||||
----------------
|
||||
master
|
||||
* master-sdk-202405
|
||||
remotes/origin/HEAD -> origin/master
|
||||
remotes/origin/app_test
|
||||
remotes/origin/master
|
||||
$ git push origin master-sdk-202405:sdk-202405
|
||||
----------------------------------------------
|
||||
Enumerating objects: 3, done.
|
||||
Counting objects: 100% (3/3), done.
|
||||
Delta compression using up to 8 threads
|
||||
Compressing objects: 100% (2/2), done.
|
||||
Writing objects: 100% (2/2), 250 bytes | 250.00 KiB/s, done.
|
||||
Total 2 (delta 1), reused 0 (delta 0)
|
||||
remote: Powered by GITEE.COM [GNK-6.4]
|
||||
remote: Create a pull request for 'sdk-202405' on Gitee by visiting:
|
||||
remote: https://gitee.com/shenzhen-jiuyilian/ipc-rk1106/pull/new/shenzhen-jiuyilian:sdk-202405...shenzhen-jiuyilian:master
|
||||
To gitee.com:shenzhen-jiuyilian/ipc-rk1106.git
|
||||
* [new branch] master-sdk-202405 -> sdk-202405
|
||||
$ git branch -a
|
||||
---------------
|
||||
master
|
||||
* master-sdk-202405
|
||||
remotes/origin/HEAD -> origin/master
|
||||
remotes/origin/app_test
|
||||
remotes/origin/master
|
||||
remotes/origin/sdk-202405
|
||||
```
|
||||
|
||||
### 1.4.2. git获取远端分支
|
||||
|
||||
  当想知道远端是否新建了分支,可使用git fetch命令获取远端分支。
|
||||
|
||||
**git fetch示例:**
|
||||
|
||||
```code
|
||||
$ git fetch
|
||||
------------
|
||||
remote: Enumerating objects: 21, done.
|
||||
remote: Counting objects: 100% (21/21), done.
|
||||
remote: Compressing objects: 100% (11/11), done.
|
||||
remote: Total 14 (delta 8), reused 0 (delta 0), pack-reused 0
|
||||
Unpacking objects: 100% (14/14), 2.14 KiB | 156.00 KiB/s, done.
|
||||
From gitee.com:shenzhen-jiuyilian/ipc-rk1106
|
||||
bf71a01..2b9b803 master -> origin/master
|
||||
* [new branch] sdk-202402 -> origin/sdk-202402 // 此处发现远端新建了分支
|
||||
Fetching submodule ipc-sdk
|
||||
From gitee.com:shenzhen-jiuyilian/ipc
|
||||
7c261bd..eec9fb4 master-develop -> origin/master-develop
|
||||
```
|
||||
|
||||
**多个远端仓库git fetch示例:**
|
||||
|
||||
```code
|
||||
$ git remote -v
|
||||
----------------
|
||||
dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git (fetch)
|
||||
dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git (push)
|
||||
rk https://gerrit.rock-chips.com:8443/linux/linux/ipc/app/fastboot_server (fetch)
|
||||
rk https://gerrit.rock-chips.com:8443/linux/linux/ipc/app/fastboot_server (push)
|
||||
$ git fetch dgiot // git fetch + 远端仓库名称
|
||||
---------------------------------------------
|
||||
remote: Enumerating objects: 9, done.
|
||||
remote: Counting objects: 100% (9/9), done.
|
||||
remote: Compressing objects: 100% (7/7), done.
|
||||
remote: Total 9 (delta 3), reused 5 (delta 2), pack-reused 0
|
||||
Unpacking objects: 100% (9/9), 8.74 KiB | 746.00 KiB/s, done.
|
||||
From gitee.com:shenzhen-jiuyilian/fastbootserver
|
||||
* [new branch] sdk-202405 -> dgiot/sdk-202405
|
||||
```
|
||||
|
||||
### 1.4.3. git新增远端地址
|
||||
|
||||
  在一个git仓库中,可以同时管理多个远端地址,例如:在原厂的git仓库中,可以在仓库添加一个私人的git仓库,这样后续把修改提交到自己的仓库进行代码管理。
|
||||
|
||||
**git remote add示例:**
|
||||
|
||||
命令格式:
|
||||
|
||||
```code
|
||||
git remote add <remote-name> <remote-url>
|
||||
```
|
||||
|
||||
示例:
|
||||
|
||||
```code
|
||||
$ git remote add dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git
|
||||
---------------------------------------------------------------------------
|
||||
$ git remote -v
|
||||
----------------
|
||||
dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git (fetch)
|
||||
dgiot git@gitee.com:shenzhen-jiuyilian/fastbootserver.git (push)
|
||||
rk https://gerrit.rock-chips.com:8443/linux/linux/ipc/app/fastboot_server (fetch)
|
||||
rk https://gerrit.rock-chips.com:8443/linux/linux/ipc/app/fastboot_server (push)
|
||||
$ git fetch dgiot
|
||||
------------------
|
||||
remote: Enumerating objects: 107, done.
|
||||
remote: Counting objects: 100% (104/104), done.
|
||||
remote: Compressing objects: 100% (45/45), done.
|
||||
remote: Total 99 (delta 47), reused 89 (delta 42), pack-reused 0
|
||||
Unpacking objects: 100% (99/99), 29.55 KiB | 315.00 KiB/s, done.
|
||||
From gitee.com:shenzhen-jiuyilian/fastbootserver
|
||||
* [new branch] master -> dgiot/master
|
||||
* [new branch] sdk-202405 -> dgiot/sdk-202405
|
||||
$ git branch -a
|
||||
----------------
|
||||
* (HEAD detached at bf91101)
|
||||
remotes/dgiot/master
|
||||
remotes/dgiot/sdk-202405
|
||||
remotes/m/master
|
||||
remotes/rk/master
|
||||
$ git checkout -b sdk-202405 m/master
|
||||
--------------------------------------
|
||||
Switched to a new branch 'sdk-202405'
|
||||
$ git branch -a
|
||||
----------------
|
||||
* sdk-202405
|
||||
remotes/dgiot/master
|
||||
remotes/dgiot/sdk-202405
|
||||
remotes/m/master
|
||||
remotes/rk/master
|
||||
$ git pull dgiot sdk-202405
|
||||
---------------------------
|
||||
From gitee.com:shenzhen-jiuyilian/fastbootserver
|
||||
* branch sdk-202405 -> FETCH_HEAD
|
||||
Updating bf91101..dc76264
|
||||
Fast-forward
|
||||
.clang-format | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
.gitmodules | 3 +++
|
||||
README.md | 30 ++++++++++++++++++++++++++++++
|
||||
rv1106_ipc_sdk | 1 +
|
||||
4 files changed, 170 insertions(+)
|
||||
create mode 100644 .clang-format
|
||||
create mode 100644 .gitmodules
|
||||
create mode 100755 README.md
|
||||
create mode 160000 rv1106_ipc_sdk
|
||||
$ git submodule update --init
|
||||
-----------------------------
|
||||
Submodule 'rv1106_ipc_sdk' (git@gitee.com:shenzhen-jiuyilian/ipc-rk1106.git) registered for path 'rv1106_ipc_sdk'
|
||||
Cloning into '/home/xiaojiazhu/project/rkipc/ipc_20240517/project/app/component/fastboot_server/rv1106_ipc_sdk'...
|
||||
Submodule path 'rv1106_ipc_sdk': checked out 'ff8da760b201d365300aed78190de8564f0d2171'
|
||||
```
|
||||
|
||||
### 1.4.4. git删除远端地址
|
||||
|
||||
```code
|
||||
# git remote remove <remote-name>
|
||||
$ git remote -v
|
||||
---------------
|
||||
Germany payton@git.affgt.com:Germany/hunting.git (fetch)
|
||||
Germany payton@git.affgt.com:Germany/hunting.git (push)
|
||||
origin git@gitee.com:shenzhen-jiuyilian/ipc.git (fetch)
|
||||
origin git@gitee.com:shenzhen-jiuyilian/ipc.git (push)
|
||||
$ git remote remove Germany
|
||||
---------------------------
|
||||
$ git remote -v
|
||||
----------------
|
||||
origin git@gitee.com:shenzhen-jiuyilian/ipc.git (fetch)
|
||||
origin git@gitee.com:shenzhen-jiuyilian/ipc.git (push)
|
||||
```
|
||||
|
||||
### 1.4.5. git删除一个远端分支
|
||||
|
||||
```code
|
||||
# git push <remote-name> --delete <branch-name>
|
||||
$ git branch -r
|
||||
---------------
|
||||
origin/Branch_QT
|
||||
origin/HEAD -> origin/master
|
||||
origin/master
|
||||
origin/master-develop
|
||||
origin/without-testtools
|
||||
$ git push origin --delete Branch_QT
|
||||
-------------------------------------
|
||||
remote: Powered by GITEE.COM [GNK-6.4]
|
||||
To gitee.com:shenzhen-jiuyilian/ipc.git
|
||||
- [deleted] Branch_QT
|
||||
```
|
||||
|
||||
## 1.5. 多仓库管理
|
||||
|
||||
### 1.5.1. 合并两个无关联记录的仓库
|
||||
|
||||
  在一个仓库上合并另外一个无关联记录的仓库。
|
||||
|
||||
```code
|
||||
# 假设A仓库的代码合入到B仓库
|
||||
# 在需要合并的仓库A下面执行
|
||||
$ rm -rf .git # 如果不需要A仓库的修改记录,需要重新创建一个新的本地分支和记录;
|
||||
$ git init # 初始化一个空的仓库,并创建.git目录;
|
||||
$ git add . # 添加A仓库的代码;
|
||||
$ git commit -m "new log" # 保存代码,创建新的log;此时创建了一个本地的master分支;
|
||||
$ git remote add B <B仓库的地址> # 添加B仓库的地址;
|
||||
$ git fetch B # 拉取B仓库的信息;
|
||||
$ git checkout -b open B/master # 创建一个B仓库的本地分支,并切换到该分支;
|
||||
$ git merge master --allow-unrelated-histories # 合并A仓库的代码,并允许两个分支没有关联记录;
|
||||
$ git checkout --theirs . # 合并如果有冲突,选择A仓库的代码;
|
||||
$ git restore --source=master output_files/libs/ # 按需,恢复A仓库的某些代码;
|
||||
$ git add . # 添加需要合并的代码;
|
||||
$ git commit -m "merge log" # 合并后的代码,保存到本地仓库;
|
||||
$ git push B open:master # 推送到B仓库的master分支;
|
||||
```
|
||||
|
||||
## 1.6. 存疑
|
||||
|
||||
* 不同的分支之间如何同步某个文件?
|
2
external/ffmpeg/CMakeLists.txt
vendored
2
external/ffmpeg/CMakeLists.txt
vendored
|
@ -7,6 +7,7 @@ add_custom_target(
|
|||
# COMMAND cp ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/modify/http.c ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/src
|
||||
# COMMAND touch ${EXTERNAL_SOURCE_PATH}/goahead-5.2.0/GoAhead/src/http.c
|
||||
COMMAND test -f ${EXTERNAL_SOURCE_PATH}/ffmpeg/Makefile || tar -xf ffmpeg_6.1.1.orig.tar.xz
|
||||
COMMAND chmod 777 -R ffmpeg-6.1.1
|
||||
COMMAND cd ffmpeg-6.1.1 && ./configure --enable-cross-compile --target-os=linux --arch=arm64
|
||||
--cc=${CMAKE_C_COMPILER}
|
||||
--cxx=${CMAKE_CXX_COMPILER}
|
||||
|
@ -27,6 +28,7 @@ add_custom_target(
|
|||
--disable-outdevs --disable-ffprobe --disable-ffmpeg --disable-ffplay --disable-debug
|
||||
COMMAND cd ffmpeg-6.1.1 && make
|
||||
COMMAND cd ffmpeg-6.1.1 && make install
|
||||
COMMAND cd ffmpeg-6.1.1 && make clean
|
||||
WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/ffmpeg/
|
||||
)
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ include_directories(
|
|||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/LinuxApi/include
|
||||
${UTILS_SOURCE_PATH}/KeyControl/include
|
||||
${UTILS_SOURCE_PATH}/LedControl/include
|
||||
)
|
||||
#do not rely on any other library
|
||||
# link_directories(
|
||||
|
@ -24,7 +25,7 @@ aux_source_directory(./src IMPL_SRC_FILES)
|
|||
set(ABSTRACT_TARGET HalAbstract)
|
||||
set(IMPL_TARGET Hal)
|
||||
add_library(${ABSTRACT_TARGET} STATIC ${ABSTRACT_SRC_FILES})
|
||||
target_link_libraries(${ABSTRACT_TARGET} LinuxApi KeyControl StatusCode Log)
|
||||
target_link_libraries(${ABSTRACT_TARGET} LinuxApi KeyControl LedControl StatusCode Log)
|
||||
add_library(${IMPL_TARGET} STATIC ${IMPL_SRC_FILES})
|
||||
target_link_libraries(${IMPL_TARGET} ${ABSTRACT_TARGET})
|
||||
|
||||
|
|
|
@ -64,8 +64,14 @@ void VCameraHalMonitor::ReportEvent(const CameraReportEvent &event)
|
|||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
}
|
||||
StatusCode VCameraTaskContext::TaskFinished(void)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
camera_task_param::camera_task_param(const CameraTaskType &cameraTask) : mCameraTask(cameraTask)
|
||||
{
|
||||
mVideoRecordingTimeMs = DEFAULT_VIDEO_RECORDING_TIME_MS;
|
||||
}
|
||||
void VCameraHal::SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor)
|
||||
{
|
||||
|
@ -76,6 +82,21 @@ StatusCode VCameraHal::StartSingleTask(const CameraTaskParam ¶m)
|
|||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VCameraHal::StopTask(void)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VCameraHal::SetAudioStreamCallback(AudioStreamCallback callback)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode VCameraHal::SetVideoStreamCallback(VideoStreamCallback callback)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
void VSdCardHalMonitor::ReportEvent(const SdCardHalStatus &status)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#ifndef I_HAL_CPP_H
|
||||
#define I_HAL_CPP_H
|
||||
#include "StatusCode.h"
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
@ -70,7 +71,6 @@ public:
|
|||
virtual void CheckKeyStatus(void);
|
||||
virtual void GetHoldPressingTimeMs(long int &holdTimeMs, VirtualKeyEvent &event);
|
||||
virtual void SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor);
|
||||
// virtual std::string GetKeyHalName(void);
|
||||
};
|
||||
class VLedHal
|
||||
{
|
||||
|
@ -100,6 +100,7 @@ class VCameraTaskContext
|
|||
public:
|
||||
VCameraTaskContext() = default;
|
||||
virtual ~VCameraTaskContext() = default;
|
||||
virtual StatusCode TaskFinished(void);
|
||||
};
|
||||
template <typename T>
|
||||
class CameraTaskContext : public VCameraTaskContext
|
||||
|
@ -113,12 +114,18 @@ public:
|
|||
public:
|
||||
T mData;
|
||||
};
|
||||
constexpr int DEFAULT_VIDEO_RECORDING_TIME_MS = 10 * 1000;
|
||||
typedef struct camera_task_param
|
||||
{
|
||||
camera_task_param(const CameraTaskType &cameraTask);
|
||||
const CameraTaskType mCameraTask;
|
||||
unsigned int mVideoRecordingTimeMs;
|
||||
std::shared_ptr<VCameraTaskContext> mCtx;
|
||||
} CameraTaskParam;
|
||||
// using AudioStreamCallback = void (*)(const void *, const int, const unsigned long long);
|
||||
// using VideoStreamCallback = void (*)(const void *, const int, const unsigned long long);
|
||||
using AudioStreamCallback = std::function<void(const void *, const unsigned int &, const unsigned long long &)>;
|
||||
using VideoStreamCallback = std::function<void(const void *, const unsigned int &, const unsigned long long &)>;
|
||||
class VCameraHal
|
||||
{
|
||||
public:
|
||||
|
@ -126,6 +133,9 @@ public:
|
|||
virtual ~VCameraHal() = default;
|
||||
virtual void SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor);
|
||||
virtual StatusCode StartSingleTask(const CameraTaskParam ¶m);
|
||||
virtual StatusCode StopTask(void);
|
||||
virtual StatusCode SetAudioStreamCallback(AudioStreamCallback callback);
|
||||
virtual StatusCode SetVideoStreamCallback(VideoStreamCallback callback);
|
||||
};
|
||||
class VSdCardHalMonitor
|
||||
{
|
||||
|
|
57
hal/src/CameraHal.cpp
Normal file
57
hal/src/CameraHal.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "CameraHal.h"
|
||||
#include "ILog.h"
|
||||
CameraHal::CameraHal() : mTaskRuning(false), mAudioStreamCallback(nullptr), mVideoStreamCallback(nullptr)
|
||||
{
|
||||
}
|
||||
void CameraHal::Init(void)
|
||||
{
|
||||
}
|
||||
void CameraHal::UnInit(void)
|
||||
{
|
||||
}
|
||||
StatusCode CameraHal::StartSingleTask(const CameraTaskParam ¶m)
|
||||
{
|
||||
mTaskRuning = true;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode CameraHal::StopTask(void)
|
||||
{
|
||||
mTaskRuning = false;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode CameraHal::SetAudioStreamCallback(AudioStreamCallback callback)
|
||||
{
|
||||
mAudioStreamCallback = callback;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode CameraHal::SetVideoStreamCallback(VideoStreamCallback callback)
|
||||
{
|
||||
mVideoStreamCallback = callback;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void CameraHal::GetAudioStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
if (mTaskRuning && nullptr != mAudioStreamCallback) {
|
||||
mAudioStreamCallback(stream, length, timeStamp);
|
||||
}
|
||||
}
|
||||
void CameraHal::GetVideoStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
if (mTaskRuning && nullptr != mVideoStreamCallback) {
|
||||
mVideoStreamCallback(stream, length, timeStamp);
|
||||
}
|
||||
}
|
45
hal/src/CameraHal.h
Normal file
45
hal/src/CameraHal.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef CAMERA_HAL_H
|
||||
#define CAMERA_HAL_H
|
||||
#include "IHalCpp.h"
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
constexpr unsigned int NO_MEDIA_RECORDING = -1;
|
||||
class CameraHal : public VCameraHal, public std::enable_shared_from_this<CameraHal>
|
||||
{
|
||||
public:
|
||||
CameraHal();
|
||||
virtual ~CameraHal() = default;
|
||||
virtual void Init(void);
|
||||
virtual void UnInit(void);
|
||||
|
||||
protected:
|
||||
StatusCode StartSingleTask(const CameraTaskParam ¶m) override;
|
||||
StatusCode StopTask(void) override;
|
||||
StatusCode SetAudioStreamCallback(AudioStreamCallback callback) override;
|
||||
StatusCode SetVideoStreamCallback(VideoStreamCallback callback) override;
|
||||
|
||||
protected:
|
||||
void GetAudioStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp);
|
||||
void GetVideoStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp);
|
||||
|
||||
private:
|
||||
// std::mutex mMutex;
|
||||
bool mTaskRuning;
|
||||
AudioStreamCallback mAudioStreamCallback;
|
||||
VideoStreamCallback mVideoStreamCallback;
|
||||
};
|
||||
#endif
|
|
@ -30,12 +30,8 @@ StatusCode HalCpp::Init(void)
|
|||
if (nullptr != sdCardImpl) {
|
||||
sdCardImpl->Init();
|
||||
}
|
||||
HalMakePtr::GetInstance()->CreateAllKeyHal(mKeys);
|
||||
// auto checkPinValue = [](std::shared_ptr<HalCpp> impl) {
|
||||
// LogInfo("HalCpp::CheckAllPinVauleThread start\n");
|
||||
// impl->CheckAllPinVauleThread();
|
||||
// };
|
||||
// mCheckPinThread = std::thread(checkPinValue, shared_from_this());
|
||||
HalMakePtr::GetInstance()->CreateAllKeysHal(mKeys);
|
||||
HalMakePtr::GetInstance()->CreateAllLedsHal(mLeds);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode HalCpp::UnInit(void)
|
||||
|
@ -45,10 +41,6 @@ StatusCode HalCpp::UnInit(void)
|
|||
if (nullptr != sdCardImpl) {
|
||||
sdCardImpl->UnInit();
|
||||
}
|
||||
mThreadRuning = false;
|
||||
if (mCheckPinThread.joinable()) {
|
||||
mCheckPinThread.join();
|
||||
}
|
||||
mWifiHal.reset();
|
||||
mSdCardHal.reset();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
|
@ -63,6 +55,19 @@ StatusCode HalCpp::GetSdCardHal(std::shared_ptr<VSdCardHal> &sdCard)
|
|||
sdCard = mSdCardHal;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode HalCpp::GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||
{
|
||||
LogInfo("GetAllLeds, size = %d\n", mLeds.size());
|
||||
for (auto &led : mLeds) {
|
||||
std::shared_ptr<VLedHal> ledControl = std::dynamic_pointer_cast<VLedHal>(led);
|
||||
if (nullptr == ledControl) {
|
||||
LogError("ledControl is nullptr\n");
|
||||
continue;
|
||||
}
|
||||
allLeds.insert(std::make_pair(led->GetLedName(), ledControl));
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode HalCpp::GetAllKeys(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
||||
{
|
||||
LogInfo("GetAllKeys\n");
|
||||
|
@ -76,12 +81,3 @@ StatusCode HalCpp::GetAllKeys(std::map<std::string, std::shared_ptr<VKeyHal>> &a
|
|||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void HalCpp::CheckAllPinVauleThread(void)
|
||||
{
|
||||
// mThreadRuning = true;
|
||||
// while (mThreadRuning) {
|
||||
// for (auto &keyHalImpl : mKeys) {
|
||||
// }
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(PERIPHERAL_CHECK_PERIOD_MS));
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define HALCPP_H
|
||||
#include "IHalCpp.h"
|
||||
#include "KeyControl.h"
|
||||
#include "LedControl.h"
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
class HalCpp : public IHalCpp, public std::enable_shared_from_this<HalCpp>
|
||||
|
@ -27,17 +28,15 @@ public:
|
|||
StatusCode UnInit(void) override;
|
||||
StatusCode GetWifiHal(std::shared_ptr<VWifiHal> &wifi) override;
|
||||
StatusCode GetSdCardHal(std::shared_ptr<VSdCardHal> &sdCard) override;
|
||||
StatusCode GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds) override;
|
||||
StatusCode GetAllKeys(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys) override;
|
||||
|
||||
private:
|
||||
void CheckAllPinVauleThread(void);
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<VLedHal>> mLedHals;
|
||||
std::shared_ptr<VWifiHal> mWifiHal;
|
||||
std::shared_ptr<VSdCardHal> mSdCardHal;
|
||||
std::vector<std::shared_ptr<VKeyControl>> mKeys;
|
||||
bool mThreadRuning = false;
|
||||
std::thread mCheckPinThread;
|
||||
std::vector<std::shared_ptr<VLedControl>> mLeds;
|
||||
};
|
||||
#endif
|
|
@ -93,7 +93,12 @@ StatusCode HalMakePtr::CreateSdCardHal(std::shared_ptr<VSdCardHal> &impl)
|
|||
impl = std::make_shared<SdCardHal>();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode HalMakePtr::CreateAllKeyHal(std::vector<std::shared_ptr<VKeyControl>> &keys)
|
||||
StatusCode HalMakePtr::CreateAllKeysHal(std::vector<std::shared_ptr<VKeyControl>> &keys)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode HalMakePtr::CreateAllLedsHal(std::vector<std::shared_ptr<VLedControl>> &leds)
|
||||
{
|
||||
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "IHalCpp.h"
|
||||
#include "StatusCode.h"
|
||||
#include "KeyControl.h"
|
||||
#include "LedControl.h"
|
||||
#include <memory>
|
||||
class HalMakePtr
|
||||
{
|
||||
|
@ -38,6 +39,7 @@ public:
|
|||
virtual StatusCode CreateWifiHal(std::shared_ptr<VWifiHal> &impl);
|
||||
virtual StatusCode CreateCameraHal(std::shared_ptr<VCameraHal> &impl);
|
||||
virtual StatusCode CreateSdCardHal(std::shared_ptr<VSdCardHal> &impl);
|
||||
virtual StatusCode CreateAllKeyHal(std::vector<std::shared_ptr<VKeyControl>> &keys);
|
||||
virtual StatusCode CreateAllKeysHal(std::vector<std::shared_ptr<VKeyControl>> &keys);
|
||||
virtual StatusCode CreateAllLedsHal(std::vector<std::shared_ptr<VLedControl>> &leds);
|
||||
};
|
||||
#endif
|
|
@ -29,12 +29,22 @@ StatusCode WifiHal::OpenApMode(void)
|
|||
constexpr int SLEEP_TIME_MS = 5;
|
||||
constexpr int WAITING_TIME_MS = 1000 * 10;
|
||||
unsigned int sleepingTime_ms = 0;
|
||||
unsigned int resetWifiPowerCount = 0;
|
||||
mInitRunning = true;
|
||||
while (CheckWlan0IfExist() == false) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
sleepingTime_ms += SLEEP_TIME_MS;
|
||||
if (sleepingTime_ms > WAITING_TIME_MS) {
|
||||
LogError("wlan0 not found. \n");
|
||||
if (0 == resetWifiPowerCount) {
|
||||
LogWarning("wlan0 not found, try to reset. \n");
|
||||
PowerOff();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
PowerOn();
|
||||
sleepingTime_ms = 0;
|
||||
resetWifiPowerCount++;
|
||||
continue;
|
||||
}
|
||||
LogError("wlan0 not found, reset wifi power count: %d. \n", resetWifiPowerCount);
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
if (false == mInitRunning) {
|
||||
|
|
20
merge.sh
Executable file
20
merge.sh
Executable file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 获取所有由我们删除的文件列表
|
||||
deleted_files=$(git status --short | grep '^DU' | awk '{print $2}')
|
||||
|
||||
# 检查是否找到了任何文件
|
||||
if [[ -z "$deleted_files" ]]; then
|
||||
echo "没有找到由我们删除的文件。"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 遍历文件列表并忽略它们
|
||||
for file in $deleted_files; do
|
||||
echo "忽略文件: $file"
|
||||
git rm --cached "$file"
|
||||
done
|
||||
|
||||
# 提示用户提交更改
|
||||
echo "已忽略所有由我们删除的文件。"
|
||||
echo "你可以使用 'git commit' 来提交这些更改。"
|
|
@ -423,8 +423,8 @@ void SixFrameHandle::ResponseGetParamItems(cJSON *result, const AppGetCapability
|
|||
cJSON_AddItemToObject(mic, CJSON_INDEX_STRING, index);
|
||||
cJSON_AddItemToArray(items, cJSON_CreateString("on"));
|
||||
cJSON_AddItemToArray(items, cJSON_CreateString("off"));
|
||||
cJSON_AddItemToArray(index, cJSON_CreateNumber(0));
|
||||
cJSON_AddItemToArray(index, cJSON_CreateNumber(1));
|
||||
cJSON_AddItemToArray(index, cJSON_CreateNumber(0));
|
||||
}
|
||||
}
|
||||
// {
|
||||
|
@ -714,16 +714,10 @@ AppSetParamValue inline SixFrameHandle::RequestSetParamValueParse(const std::str
|
|||
auto parseFunc = [](const std::string &key, const std::string &value, std::shared_ptr<VParseUrl> &parse) {
|
||||
std::shared_ptr<ParseUrl<AppSetParamValue>> parseImpl =
|
||||
std::dynamic_pointer_cast<ParseUrl<AppSetParamValue>>(parse);
|
||||
if ("switchcam" == key) {
|
||||
parseImpl->mData.mName = "switchcam";
|
||||
parseImpl->mData.mValue = std::stoi(value);
|
||||
if ("param" == key) {
|
||||
parseImpl->mData.mName = value;
|
||||
}
|
||||
if ("rec" == key) {
|
||||
parseImpl->mData.mName = "rec";
|
||||
parseImpl->mData.mValue = std::stoi(value);
|
||||
}
|
||||
if ("mic" == key) {
|
||||
parseImpl->mData.mName = "mic";
|
||||
if ("value" == key) {
|
||||
parseImpl->mData.mValue = std::stoi(value);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -14,10 +14,38 @@
|
|||
*/
|
||||
#include "MediaHandle.h"
|
||||
#include "ILog.h"
|
||||
#include "SaveStream.h"
|
||||
MediaHandle::MediaHandle(const MediaChannel &mediaChannel, const std::shared_ptr<VCameraHal> &cameraHal)
|
||||
: mMediaChannel(mediaChannel), mCameraHal(cameraHal)
|
||||
: mMediaChannel(mediaChannel), mCameraHal(cameraHal), mTaskRuning(false)
|
||||
{
|
||||
}
|
||||
void MediaHandle::Init(void)
|
||||
{
|
||||
if (mCameraHal == nullptr) {
|
||||
LogError("CameraHal is null.\n");
|
||||
return;
|
||||
}
|
||||
auto audioFunc = std::bind(&MediaHandle::GetAudioStreamCallback, this, _1, _2, _3);
|
||||
mCameraHal->SetAudioStreamCallback(audioFunc);
|
||||
auto videoFunc = std::bind(&MediaHandle::GetVideoStreamCallback, this, _1, _2, _3);
|
||||
mCameraHal->SetVideoStreamCallback(videoFunc);
|
||||
}
|
||||
void MediaHandle::UnInit(void)
|
||||
{
|
||||
mTaskRuning = false;
|
||||
mCv.notify_one();
|
||||
if (mTaskTimerThread.joinable()) {
|
||||
mTaskTimerThread.join();
|
||||
}
|
||||
if (mCameraHal) {
|
||||
/**
|
||||
* @brief Before releasing the class instance, it is necessary to call the UnInit function to ensure that the
|
||||
* callback function is cleared elsewhere, otherwise it will crash.
|
||||
*/
|
||||
mCameraHal->SetAudioStreamCallback(nullptr);
|
||||
mCameraHal->SetVideoStreamCallback(nullptr);
|
||||
}
|
||||
}
|
||||
StatusCode MediaHandle::ExecuteTask(std::shared_ptr<VMediaTask> &task)
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(mMutex);
|
||||
|
@ -29,11 +57,18 @@ StatusCode MediaHandle::ExecuteTask(std::shared_ptr<VMediaTask> &task)
|
|||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
}
|
||||
mStreamHandle = std::make_shared<SaveStream>();
|
||||
if (nullptr == mStreamHandle) {
|
||||
LogError("Create stream handle failed.\n");
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
mStreamHandle->Init();
|
||||
CameraTaskType taskType = TaskTypeConvert(task->GetTaskType());
|
||||
CameraTaskParam data(taskType);
|
||||
auto code = mCameraHal->StartSingleTask(data);
|
||||
if (IsCodeOK(code)) {
|
||||
mCurrentTask = task;
|
||||
StartTaskTimer();
|
||||
}
|
||||
else {
|
||||
LogError("Execute task failed.\n");
|
||||
|
@ -48,7 +83,53 @@ StatusCode MediaHandle::ClearTask(void)
|
|||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MediaHandle::StartTaskTimer(void)
|
||||
{
|
||||
auto taskTimerThread = [=](std::shared_ptr<MediaHandle> media) {
|
||||
LogInfo("StartTaskTimer start.\n");
|
||||
media->TaskTimer();
|
||||
};
|
||||
std::shared_ptr<MediaHandle> media = shared_from_this();
|
||||
mTaskTimerThread = std::thread(taskTimerThread, media);
|
||||
}
|
||||
void MediaHandle::TaskTimer(void)
|
||||
{
|
||||
constexpr int TASK_TIMER = 1000 * 10;
|
||||
mTaskRuning = true;
|
||||
while (mTaskRuning) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mCv.wait_for(lock, std::chrono::milliseconds(TASK_TIMER), [&] {
|
||||
return !mTaskRuning;
|
||||
});
|
||||
/**
|
||||
* @brief If the recording time is over, you need to stop the recording timer here.
|
||||
*/
|
||||
mTaskRuning = false;
|
||||
}
|
||||
if (mCameraHal) {
|
||||
mCameraHal->StopTask();
|
||||
}
|
||||
mMutex.lock();
|
||||
auto runingTask = mCurrentTask.lock();
|
||||
if (mCurrentTask.expired()) {
|
||||
LogWarning("SdCardHal: monitor is expired.\n");
|
||||
return;
|
||||
}
|
||||
LogInfo("Task finished response to application.\n");
|
||||
std::vector<MediaTaskResponse> responses;
|
||||
runingTask->Response(responses);
|
||||
mCurrentTask.reset();
|
||||
mMutex.unlock();
|
||||
}
|
||||
CameraTaskType MediaHandle::TaskTypeConvert(const MediaTaskType &type)
|
||||
{
|
||||
return CameraTaskType::END;
|
||||
}
|
||||
void MediaHandle::GetVideoStreamCallback(const void *stream, const int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
mStreamHandle->GetVideoStream(stream, length, timeStamp);
|
||||
}
|
||||
void MediaHandle::GetAudioStreamCallback(const void *stream, const int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
mStreamHandle->GetAudioStream(stream, length, timeStamp);
|
||||
}
|
|
@ -16,23 +16,41 @@
|
|||
#define MEDI_AHANDLE_H
|
||||
#include "IHalCpp.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "VStreamHandle.h"
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
using std::placeholders::_1;
|
||||
using std::placeholders::_2;
|
||||
using std::placeholders::_3;
|
||||
class MediaHandle : public VMediaHandle, public std::enable_shared_from_this<MediaHandle>
|
||||
{
|
||||
public:
|
||||
MediaHandle(const MediaChannel &mediaChannel, const std::shared_ptr<VCameraHal> &cameraHal);
|
||||
virtual ~MediaHandle() = default;
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
|
||||
protected:
|
||||
StatusCode ExecuteTask(std::shared_ptr<VMediaTask> &task) override;
|
||||
StatusCode StopTask(void) override;
|
||||
StatusCode ClearTask(void) override;
|
||||
|
||||
private:
|
||||
void StartTaskTimer(void);
|
||||
void TaskTimer(void);
|
||||
CameraTaskType TaskTypeConvert(const MediaTaskType &type);
|
||||
void GetVideoStreamCallback(const void *stream, const int &length, const unsigned long long &timeStamp);
|
||||
void GetAudioStreamCallback(const void *stream, const int &length, const unsigned long long &timeStamp);
|
||||
|
||||
private:
|
||||
std::mutex mMutex;
|
||||
std::condition_variable mCv;
|
||||
const MediaChannel &mMediaChannel;
|
||||
std::shared_ptr<VCameraHal> mCameraHal;
|
||||
std::weak_ptr<VMediaTask> mCurrentTask;
|
||||
std::shared_ptr<VStreamHandle> mStreamHandle;
|
||||
bool mTaskRuning;
|
||||
std::thread mTaskTimerThread;
|
||||
};
|
||||
#endif
|
|
@ -23,6 +23,7 @@ StatusCode MediaManagerImpl::Init(void)
|
|||
}
|
||||
StatusCode MediaManagerImpl::UnInit(void)
|
||||
{
|
||||
UnInitMediaHandles();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MediaManagerImpl::GetMediaChannel(const MediaChannel &channel, std::shared_ptr<VMediaHandle> &handle)
|
||||
|
@ -76,8 +77,21 @@ void MediaManagerImpl::InitMediaHandles(std::map<CameraType, std::shared_ptr<VCa
|
|||
continue;
|
||||
}
|
||||
MediaChannel channel = static_cast<MediaChannel>(i);
|
||||
std::shared_ptr<VMediaHandle> media = std::make_shared<MediaHandle>(channel, camera->second);
|
||||
std::shared_ptr<MediaHandle> media = std::make_shared<MediaHandle>(channel, camera->second);
|
||||
media->Init();
|
||||
mAllMediaChannels[channel] = media;
|
||||
LogInfo("InitMediaHandles. channel = %d \n", static_cast<MediaChannel>(i));
|
||||
}
|
||||
}
|
||||
void MediaManagerImpl::UnInitMediaHandles(void)
|
||||
{
|
||||
for (auto &media : mAllMediaChannels) {
|
||||
LogInfo("UnInitMediaHandles. channel = %d \n", media.first);
|
||||
std::shared_ptr<MediaHandle> mediaImpl = std::dynamic_pointer_cast<MediaHandle>(media.second);
|
||||
if (nullptr == mediaImpl) {
|
||||
LogWarning("mediaImpl is null.\n");
|
||||
continue;
|
||||
}
|
||||
mediaImpl->UnInit();
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@ public:
|
|||
private:
|
||||
void SetCamerasMonitor(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras);
|
||||
void InitMediaHandles(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras);
|
||||
void UnInitMediaHandles(void);
|
||||
|
||||
private:
|
||||
std::map<CameraType, std::shared_ptr<VCameraHal>> mAllCameras;
|
||||
|
|
55
middleware/MediaManager/src/SaveStream.cpp
Normal file
55
middleware/MediaManager/src/SaveStream.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this mFileAudio except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "SaveStream.h"
|
||||
#include "ILog.h"
|
||||
SaveStream::SaveStream() : mFileAudio(nullptr), mFileVideo(nullptr)
|
||||
{
|
||||
}
|
||||
void SaveStream::Init(void)
|
||||
{
|
||||
mFileAudio = fopen("/tmp/audio.g711", "a+"); // TODO:
|
||||
mFileVideo = fopen("/tmp/video.h264", "a+"); // TODO:
|
||||
}
|
||||
void SaveStream::UnInit(void)
|
||||
{
|
||||
if (mFileAudio) {
|
||||
fclose(mFileAudio);
|
||||
mFileAudio = nullptr;
|
||||
}
|
||||
if (mFileVideo) {
|
||||
fclose(mFileVideo);
|
||||
mFileVideo = nullptr;
|
||||
}
|
||||
}
|
||||
void SaveStream::GetVideoStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
if (mFileVideo) {
|
||||
size_t writeLength = fwrite(stream, 1, length, mFileVideo);
|
||||
if (writeLength != length) {
|
||||
LogError("Write video stream failed.\n");
|
||||
}
|
||||
fflush(mFileVideo);
|
||||
}
|
||||
}
|
||||
void SaveStream::GetAudioStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
if (mFileAudio) {
|
||||
size_t writeLength = fwrite(stream, 1, length, mFileAudio);
|
||||
if (writeLength != length) {
|
||||
LogError("Write video stream failed.\n");
|
||||
}
|
||||
fflush(mFileAudio);
|
||||
}
|
||||
}
|
33
middleware/MediaManager/src/SaveStream.h
Normal file
33
middleware/MediaManager/src/SaveStream.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef SAVE_STREAM_H
|
||||
#define SAVE_STREAM_H
|
||||
#include "VStreamHandle.h"
|
||||
#include <cstdio>
|
||||
class SaveStream : public VStreamHandle
|
||||
{
|
||||
public:
|
||||
SaveStream();
|
||||
virtual ~SaveStream() = default;
|
||||
void Init(void) override;
|
||||
void UnInit(void) override;
|
||||
void GetVideoStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp) override;
|
||||
void GetAudioStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp) override;
|
||||
|
||||
private:
|
||||
FILE *mFileAudio;
|
||||
FILE *mFileVideo;
|
||||
};
|
||||
#endif
|
27
middleware/MediaManager/src/VStreamHandle.cpp
Normal file
27
middleware/MediaManager/src/VStreamHandle.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "VStreamHandle.h"
|
||||
void VStreamHandle::Init(void)
|
||||
{
|
||||
}
|
||||
void VStreamHandle::UnInit(void)
|
||||
{
|
||||
}
|
||||
void VStreamHandle::GetVideoStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
}
|
||||
void VStreamHandle::GetAudioStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
}
|
27
middleware/MediaManager/src/VStreamHandle.h
Normal file
27
middleware/MediaManager/src/VStreamHandle.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef V_STREAM_HANDLE_H
|
||||
#define V_STREAM_HANDLE_H
|
||||
class VStreamHandle
|
||||
{
|
||||
public:
|
||||
VStreamHandle() = default;
|
||||
virtual ~VStreamHandle() = default;
|
||||
virtual void Init(void);
|
||||
virtual void UnInit(void);
|
||||
virtual void GetVideoStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp);
|
||||
virtual void GetAudioStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp);
|
||||
};
|
||||
#endif
|
|
@ -178,7 +178,9 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_AUTO_SetParamValue)
|
|||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockSetParamValue();
|
||||
MockSetParamValue("mic", "1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetParamValue("mic");
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
// ../output_files/test/bin/HuntingCameraTest
|
||||
|
|
|
@ -32,7 +32,6 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaReprot)
|
|||
MockReportCameraEvent("/tmp/test.MP4", CameraType::MAIN_CAMERA);
|
||||
CreateUpgradeFile();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
// McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 4);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
@ -40,4 +39,17 @@ TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaReprot)
|
|||
MainThread::GetInstance()->Runing();
|
||||
RemoveUpgradeFile();
|
||||
}
|
||||
// ../output_files/test/bin/HuntingCameraTest
|
||||
// --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_EXAMPLE_MediaTask
|
||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaTask)
|
||||
{
|
||||
McuManagerTestTool::MockOtherSideIpcMissionReply(IpcMission::TEST);
|
||||
SetAllCamerasResult(mAllCamerasMock);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 15);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
HalTestTool::MockKeyClick("reset", 200); // Simulate pressing a button.
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
} // namespace MediaManager_Mock_Test
|
|
@ -269,7 +269,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_SetParamValue)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockSetParamValue();
|
||||
MockSetParamValue("mic", "1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ protected: // About http
|
|||
void MockGetLockVideoStatus(void);
|
||||
void MockGetStorageInfo(void);
|
||||
void MockGetStorageFileList(void);
|
||||
void MockSetParamValue(void);
|
||||
void MockSetParamValue(const std::string &item, const std::string &value);
|
||||
void MockEnterRecorder(void);
|
||||
void MockAppPlayback(void);
|
||||
void MockMonitorSetFileList(std::vector<AppGetFileList> &files);
|
||||
|
|
1
test/support_test/audio.g711a
Executable file
1
test/support_test/audio.g711a
Executable file
File diff suppressed because one or more lines are too long
BIN
test/support_test/video.h264
Executable file
BIN
test/support_test/video.h264
Executable file
Binary file not shown.
|
@ -12,7 +12,7 @@ add_subdirectory(McuProtocol)
|
|||
add_subdirectory(ModBusCRC16)
|
||||
add_subdirectory(LedControl)
|
||||
add_subdirectory(KeyControl)
|
||||
add_subdirectory(MediaAdapter)
|
||||
add_subdirectory(MediaBase)
|
||||
add_subdirectory(FxHttpServer)
|
||||
add_subdirectory(Servers)
|
||||
add_subdirectory(TcpModule)
|
||||
|
|
|
@ -58,17 +58,15 @@ endif()
|
|||
|
||||
# build libconfig before make libConfigBase.a
|
||||
add_custom_command(
|
||||
# OUTPUT ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs/libconfig.a
|
||||
OUTPUT ${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig.a
|
||||
COMMAND echo "Build libconfig-1.7.3. COMPILE_HOST = ${COMPILE_HOST}"
|
||||
# COMMAND tar zxvf libconfig-1.7.3.tar.gz
|
||||
COMMAND sh build_libconfig.sh ${TARGET_PLATFORM} ${COMPILE_HOST}
|
||||
COMMAND mv ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs/libconfig.a ${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig.a
|
||||
COMMAND cd libconfig-1.7.3; make clean;
|
||||
WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/libconfig/
|
||||
)
|
||||
add_custom_target(
|
||||
libconfig.a
|
||||
# DEPENDS ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs/libconfig.a
|
||||
DEPENDS ${EXTERNAL_LIBS_OUTPUT_PATH}/libconfig.a
|
||||
)
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@ include_directories(
|
|||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||
# )
|
||||
|
||||
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME MediaAdapter)
|
||||
|
|
68
utils/MediaBase/CMakeLists.txt
Normal file
68
utils/MediaBase/CMakeLists.txt
Normal file
|
@ -0,0 +1,68 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
include_directories(
|
||||
./src
|
||||
./include
|
||||
# ${UTILS_SOURCE_PATH}/LinuxApi/include
|
||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
${UTILS_SOURCE_PATH}/ModBusCRC16/include
|
||||
${UTILS_SOURCE_PATH}/Log/include
|
||||
)
|
||||
# link_directories(
|
||||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||
# )
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME MediaBase)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} StatusCode Log)
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
MediaBase_code_check
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
${SRC_FILES}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/MediaBase
|
||||
)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
add_custom_target(
|
||||
MediaBase_code_format
|
||||
COMMAND ${CLANG_FORMAT_EXE}
|
||||
-style=file
|
||||
-i ${SRC_FILES} ${HEADER_FILES}
|
||||
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/MediaBase
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make MediaBase_code_check
|
||||
COMMAND make MediaBase_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
# build ffmpeg before make libMediaBase.a
|
||||
add_custom_command(
|
||||
OUTPUT ${EXTERNAL_LIBS_OUTPUT_PATH}/ffmpeg/lib/libavcodec.a
|
||||
COMMAND echo "Did not found ffmpeg libs in output_files, now compile ffmpeg."
|
||||
COMMAND make ffmpeg
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
add_custom_target(
|
||||
compile_ffmpeg
|
||||
DEPENDS ${EXTERNAL_LIBS_OUTPUT_PATH}/ffmpeg/lib/libavcodec.a
|
||||
)
|
||||
add_dependencies(${TARGET_NAME} compile_ffmpeg)
|
||||
|
||||
define_file_name(${TARGET_NAME})
|
||||
|
||||
file(GLOB_RECURSE INSTALL_HEADER_FILES include/*.h)
|
||||
install(FILES ${INSTALL_HEADER_FILES} DESTINATION include)
|
31
utils/MediaBase/include/MediaBase.h
Normal file
31
utils/MediaBase/include/MediaBase.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MEDIA_BASE_H
|
||||
#define MEDIA_BASE_H
|
||||
#include "StatusCode.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
enum MediaHandleType
|
||||
{
|
||||
MEDIA_HANDLE_TYPE_READ_H264 = 0,
|
||||
MEDIA_HANDLE_TYPE_END
|
||||
};
|
||||
void *ICreateMediaBase(const MediaHandleType type);
|
||||
void IMediaBaseFree(void *object);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
32
utils/MediaBase/src/IMediaBase.cpp
Normal file
32
utils/MediaBase/src/IMediaBase.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "IMediaBase.h"
|
||||
#include "ILog.h"
|
||||
#include <string.h>
|
||||
static const char *MEDIA_BASE_NAME = "media_adapter";
|
||||
const char inline *GetMediaBaseModuleName(void)
|
||||
{
|
||||
return MEDIA_BASE_NAME;
|
||||
}
|
||||
std::shared_ptr<IMediaBase> *NewIMediaBase(const MediaHandleType &type)
|
||||
{
|
||||
LogInfo("Create the midia base object.\n");
|
||||
MeidaAdapter *impl = (MeidaAdapter *)malloc(sizeof(MeidaAdapter));
|
||||
MeidaAdapter tmp;
|
||||
memcpy((void *)impl, (void *)&tmp, sizeof(MeidaAdapter));
|
||||
impl->mHeader.mCheckName = MEDIA_BASE_NAME;
|
||||
impl->mIMediaBase = std::make_shared<IMediaBase>();
|
||||
return (std::shared_ptr<IMediaBase> *)(((char *)impl) + sizeof(MediaBaseHeader));
|
||||
}
|
36
utils/MediaBase/src/IMediaBase.h
Normal file
36
utils/MediaBase/src/IMediaBase.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef I_MEDIA_BASE_H
|
||||
#define I_MEDIA_BASE_H
|
||||
#include "MediaBase.h"
|
||||
#include <memory>
|
||||
class IMediaBase
|
||||
{
|
||||
public:
|
||||
IMediaBase() = default;
|
||||
virtual ~IMediaBase() = default;
|
||||
};
|
||||
typedef struct media_base_header
|
||||
{
|
||||
const char *mCheckName;
|
||||
} MediaBaseHeader;
|
||||
typedef struct media_adapter
|
||||
{
|
||||
MediaBaseHeader mHeader;
|
||||
std::shared_ptr<IMediaBase> mIMediaBase;
|
||||
} MeidaAdapter;
|
||||
const char *GetMediaBaseModuleName(void);
|
||||
std::shared_ptr<IMediaBase> *NewIMediaBase(const MediaHandleType &type);
|
||||
#endif
|
40
utils/MediaBase/src/MediaBase.cpp
Normal file
40
utils/MediaBase/src/MediaBase.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "MediaBase.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaBase.h"
|
||||
void *ICreateMediaBase(const MediaHandleType type)
|
||||
{
|
||||
return NewIMediaBase(type);
|
||||
}
|
||||
static bool ObjectCheck(void *object)
|
||||
{
|
||||
if (nullptr == object) {
|
||||
LogError("nullptr object!\n");
|
||||
return false;
|
||||
}
|
||||
if (*((const char **)(((char *)object) - sizeof(IMediaBase))) != GetMediaBaseModuleName()) {
|
||||
LogError("Illegal object!\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void IMediaBaseFree(void *object)
|
||||
{
|
||||
if (ObjectCheck(object) == true) {
|
||||
(*(std::shared_ptr<IMediaBase> *)object).reset();
|
||||
free(((char *)object) - sizeof(MediaBaseHeader));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user