Record chip stream data.
This commit is contained in:
parent
5fccf8f991
commit
f5366a4bcf
|
@ -78,6 +78,7 @@ std::string MediaTask::GetThumbnailNameForSaving(const std::string &targetName)
|
|||
}
|
||||
int MediaTask::GetVideoDuration_ms(void)
|
||||
{
|
||||
return 1000 * 60;
|
||||
return DEFAULT_VIDEO_DURATION_MS;
|
||||
}
|
||||
void MediaTask::Response(const std::vector<MediaTaskResponse> &response)
|
||||
|
|
|
@ -15,8 +15,12 @@
|
|||
#include "CameraHal.h"
|
||||
#include "IHalCpp.h"
|
||||
#include "ILog.h"
|
||||
#include "LinuxApi.h"
|
||||
#include "StatusCode.h"
|
||||
CameraHal::CameraHal() : mTaskRuning(false), mAudioStreamCallback(nullptr), mVideoStreamCallback(nullptr)
|
||||
#include <stdio.h>
|
||||
CameraHal::CameraHal()
|
||||
: mTaskRuning(false), mAudioStreamCallback(nullptr), mVideoStreamCallback(nullptr), mVideoFile(nullptr),
|
||||
mAudioFile(nullptr)
|
||||
{
|
||||
}
|
||||
void CameraHal::Init(void)
|
||||
|
@ -29,11 +33,24 @@ StatusCode CameraHal::StartSingleTask(const CameraTaskParam ¶m)
|
|||
{
|
||||
LogInfo("StartSingleTask.\n");
|
||||
mTaskRuning = true;
|
||||
fx_system_v2("rm -f " SD_CARD_MOUNT_PATH "/chip.g711a");
|
||||
fx_system_v2("rm -f " SD_CARD_MOUNT_PATH "/chip.h264");
|
||||
mAudioFile = fopen(SD_CARD_MOUNT_PATH "/chip.g711a", "a+");
|
||||
mVideoFile = fopen(SD_CARD_MOUNT_PATH "/chip.h264", "a+");
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode CameraHal::StopTask(void)
|
||||
{
|
||||
mTaskRuning = false;
|
||||
if (mAudioFile) {
|
||||
fclose(mAudioFile);
|
||||
mAudioFile = nullptr;
|
||||
}
|
||||
if (mVideoFile) {
|
||||
fclose(mVideoFile);
|
||||
mVideoFile = nullptr;
|
||||
}
|
||||
fx_system_v2("sync");
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode CameraHal::SetAudioStreamCallback(AudioStreamCallback callback)
|
||||
|
@ -49,12 +66,23 @@ StatusCode CameraHal::SetVideoStreamCallback(VideoStreamCallback callback)
|
|||
void CameraHal::GetAudioStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
if (mTaskRuning && nullptr != mAudioStreamCallback) {
|
||||
SaveChipStream(ChipStreamType::AUDIO, stream, length);
|
||||
mAudioStreamCallback(stream, length, timeStamp);
|
||||
}
|
||||
}
|
||||
void CameraHal::GetVideoStream(const void *stream, const unsigned int &length, const unsigned long long &timeStamp)
|
||||
{
|
||||
if (mTaskRuning && nullptr != mVideoStreamCallback) {
|
||||
SaveChipStream(ChipStreamType::VIDEO, stream, length);
|
||||
mVideoStreamCallback(stream, length, timeStamp);
|
||||
}
|
||||
}
|
||||
void CameraHal::SaveChipStream(const ChipStreamType &streamType, const void *stream, const unsigned int &length)
|
||||
{
|
||||
FILE *file = nullptr;
|
||||
file = streamType == ChipStreamType::AUDIO ? mAudioFile : mVideoFile;
|
||||
if (file) {
|
||||
fwrite(stream, 1, length, file);
|
||||
fflush(file);
|
||||
}
|
||||
}
|
|
@ -18,6 +18,12 @@
|
|||
#include <mutex>
|
||||
#include <thread>
|
||||
constexpr unsigned int NO_MEDIA_RECORDING = -1;
|
||||
enum class ChipStreamType
|
||||
{
|
||||
VIDEO = 0,
|
||||
AUDIO,
|
||||
END
|
||||
};
|
||||
class CameraHal : public VCameraHal, public std::enable_shared_from_this<CameraHal>
|
||||
{
|
||||
public:
|
||||
|
@ -35,11 +41,17 @@ protected:
|
|||
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);
|
||||
void SaveChipStream(const ChipStreamType &streamType, const void *stream, const unsigned int &length);
|
||||
|
||||
private:
|
||||
// std::mutex mMutex;
|
||||
bool mTaskRuning;
|
||||
AudioStreamCallback mAudioStreamCallback;
|
||||
VideoStreamCallback mVideoStreamCallback;
|
||||
/**
|
||||
* @brief Each time a media task is executed, the original data stream of the chip is saved to the SD card.
|
||||
*/
|
||||
FILE *mVideoFile; ///< The original video stream data is saved.
|
||||
FILE *mAudioFile; ///< The original audio stream data is saved.
|
||||
};
|
||||
#endif
|
|
@ -126,7 +126,7 @@ void MediaHandle::StartTaskTimer(void)
|
|||
}
|
||||
void MediaHandle::TaskTimer(void)
|
||||
{
|
||||
constexpr int TASK_TIME_OUT = 1000 * 10;
|
||||
constexpr int TASK_TIME_OUT = 1000 * 60;
|
||||
mTaskRuning = true;
|
||||
while (mTaskRuning) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
|
|
Loading…
Reference in New Issue
Block a user