mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Add CameraHal.
This commit is contained in:
parent
e821de5832
commit
7493f4c22f
|
@ -66,6 +66,7 @@ void VCameraHalMonitor::ReportEvent(const CameraReportEvent &event)
|
|||
}
|
||||
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 +77,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");
|
||||
|
|
|
@ -112,12 +112,16 @@ 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);
|
||||
using VideoStreamCallback = void (*)(const void *, const int);
|
||||
class VCameraHal
|
||||
{
|
||||
public:
|
||||
|
@ -125,6 +129,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
|
||||
{
|
||||
|
|
82
hal/src/CameraHal.cpp
Normal file
82
hal/src/CameraHal.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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), mMediaRecordingTimeMs(NO_MEDIA_RECORDING), mAudioStreamCallback(nullptr),
|
||||
mVideoStreamCallback(nullptr)
|
||||
{
|
||||
}
|
||||
void CameraHal::Init(void)
|
||||
{
|
||||
}
|
||||
void CameraHal::UnInit(void)
|
||||
{
|
||||
mTaskRuning = false;
|
||||
mCv.notify_one();
|
||||
}
|
||||
StatusCode CameraHal::StartSingleTask(const CameraTaskParam ¶m)
|
||||
{
|
||||
mMediaRecordingTimeMs = param.mVideoRecordingTimeMs;
|
||||
auto taskTimerThread = [=](std::shared_ptr<CameraHal> media) {
|
||||
LogInfo("StartSingleTask start.\n");
|
||||
media->TaskTimer();
|
||||
};
|
||||
std::shared_ptr<CameraHal> media = std::dynamic_pointer_cast<CameraHal>(shared_from_this());
|
||||
mTaskTimerThread = std::thread(taskTimerThread, media);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode CameraHal::StopTask(void)
|
||||
{
|
||||
mTaskRuning = false;
|
||||
mCv.notify_one();
|
||||
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)
|
||||
{
|
||||
if (mTaskRuning && nullptr != mAudioStreamCallback) {
|
||||
mAudioStreamCallback(stream, length);
|
||||
}
|
||||
}
|
||||
void CameraHal::GetVideoStream(const void *stream, const unsigned int &length)
|
||||
{
|
||||
if (mTaskRuning && nullptr != mVideoStreamCallback) {
|
||||
mVideoStreamCallback(stream, length);
|
||||
}
|
||||
}
|
||||
void CameraHal::TaskTimer(void)
|
||||
{
|
||||
mTaskRuning = true;
|
||||
while (mTaskRuning) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mCv.wait_for(lock, std::chrono::milliseconds(mMediaRecordingTimeMs), [&] {
|
||||
return !mTaskRuning;
|
||||
});
|
||||
/**
|
||||
* @brief If the recording time is over, you need to stop the recording timer here.
|
||||
*/
|
||||
mTaskRuning = false;
|
||||
}
|
||||
}
|
52
hal/src/CameraHal.h
Normal file
52
hal/src/CameraHal.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 <condition_variable>
|
||||
#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);
|
||||
void GetVideoStream(const void *stream, const unsigned int &length);
|
||||
|
||||
private:
|
||||
void TaskTimer(void);
|
||||
|
||||
private:
|
||||
std::mutex mMutex;
|
||||
std::condition_variable mCv;
|
||||
bool mTaskRuning;
|
||||
std::thread mTaskTimerThread;
|
||||
unsigned int mMediaRecordingTimeMs;
|
||||
AudioStreamCallback mAudioStreamCallback;
|
||||
VideoStreamCallback mVideoStreamCallback;
|
||||
};
|
||||
#endif
|
|
@ -57,7 +57,7 @@ StatusCode HalCpp::GetSdCardHal(std::shared_ptr<VSdCardHal> &sdCard)
|
|||
}
|
||||
StatusCode HalCpp::GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||
{
|
||||
LogInfo("GetAllLeds\n");
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user