Backup.
This commit is contained in:
parent
281a1aa60f
commit
7cfcd56f87
|
@ -89,7 +89,7 @@ bool TestMissionState::HoldDownResetKey(const KeyEventData &data)
|
||||||
constexpr int CLOSE_WATCH_DOG_PRESSING_TIME_MS = 1000 * 3;
|
constexpr int CLOSE_WATCH_DOG_PRESSING_TIME_MS = 1000 * 3;
|
||||||
if (mFormatKeyHoldTime > data.mHoldTime && data.mHoldTime >= CLOSE_WATCH_DOG_PRESSING_TIME_MS &&
|
if (mFormatKeyHoldTime > data.mHoldTime && data.mHoldTime >= CLOSE_WATCH_DOG_PRESSING_TIME_MS &&
|
||||||
mResetKeyHoldTime == 0) {
|
mResetKeyHoldTime == 0) {
|
||||||
LogInfo("Close watch dog.\n");
|
LogWarning("Close watch dog.\n");
|
||||||
constexpr int KEEP_BLINKING_FAST_MS = 1000 * 3;
|
constexpr int KEEP_BLINKING_FAST_MS = 1000 * 3;
|
||||||
LedsHandle::ControlDeviceStatusLed(DeviceStatus::CLOSE_WATCHDOG, KEEP_BLINKING_FAST_MS, BLINKING_FAST_MS);
|
LedsHandle::ControlDeviceStatusLed(DeviceStatus::CLOSE_WATCHDOG, KEEP_BLINKING_FAST_MS, BLINKING_FAST_MS);
|
||||||
CloseWatchDog();
|
CloseWatchDog();
|
||||||
|
|
|
@ -155,12 +155,12 @@ bool FfmpegOutputStream::CheckStreamHeader(const void *data, const size_t &size)
|
||||||
if ((0x00 == pData[i]) && (0x00 == pData[i + 1]) && (0x00 == pData[i + 2]) && (0x01 == pData[i + 3]) &&
|
if ((0x00 == pData[i]) && (0x00 == pData[i + 1]) && (0x00 == pData[i + 2]) && (0x01 == pData[i + 3]) &&
|
||||||
(0x5 == (pData[i + 4] & 0x1F))) {
|
(0x5 == (pData[i + 4] & 0x1F))) {
|
||||||
uint8_t *extradata = (uint8_t *)av_mallocz(i + 1);
|
uint8_t *extradata = (uint8_t *)av_mallocz(i + 1);
|
||||||
if (!extradata) {
|
mH264Data2Jpeg = (char *)malloc(size + 1);
|
||||||
|
if (!extradata && !mH264Data2Jpeg) {
|
||||||
LogError("Could not allocate extradata\n");
|
LogError("Could not allocate extradata\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LogInfo("Found extradata\n");
|
LogInfo("Found extradata\n");
|
||||||
mH264Data2Jpeg = (char *)malloc(size + 1);
|
|
||||||
memcpy(mH264Data2Jpeg, data, size);
|
memcpy(mH264Data2Jpeg, data, size);
|
||||||
/**
|
/**
|
||||||
* @brief Find the first I-frame and decode it ->encode it into a JPEG image file.
|
* @brief Find the first I-frame and decode it ->encode it into a JPEG image file.
|
||||||
|
|
|
@ -58,7 +58,13 @@ void FfmpegThumbnail::Init(const ThumbnailInfo &thumbnailInfo)
|
||||||
mTargetWidth = thumbnailInfo.mTargetWidth;
|
mTargetWidth = thumbnailInfo.mTargetWidth;
|
||||||
mTargetHeight = thumbnailInfo.mTargetHeight;
|
mTargetHeight = thumbnailInfo.mTargetHeight;
|
||||||
mDecoder = std::make_shared<FfmpegDecoder>(mDecodecId, mSrouceWidth, mSrouceHeight);
|
mDecoder = std::make_shared<FfmpegDecoder>(mDecodecId, mSrouceWidth, mSrouceHeight);
|
||||||
|
if (!mDecoder) {
|
||||||
|
LogError("mDecoder = nullptr.\n");
|
||||||
|
}
|
||||||
mEncoder = std::make_shared<FfmpegEncoder>(mEncodecId, mTargetWidth, mTargetHeight);
|
mEncoder = std::make_shared<FfmpegEncoder>(mEncodecId, mTargetWidth, mTargetHeight);
|
||||||
|
if (!mEncoder) {
|
||||||
|
LogError("mEncoder = nullptr.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void FfmpegThumbnail::UnInit(void)
|
void FfmpegThumbnail::UnInit(void)
|
||||||
{
|
{
|
||||||
|
@ -130,6 +136,10 @@ void FfmpegThumbnail::GetDecodeDataCallback(AVFrame *frame)
|
||||||
{
|
{
|
||||||
LogInfo("Decode frame->width = %d, frame->height=%d\n", frame->width, frame->height);
|
LogInfo("Decode frame->width = %d, frame->height=%d\n", frame->width, frame->height);
|
||||||
AVFrame *thumbnailFrame = av_frame_alloc();
|
AVFrame *thumbnailFrame = av_frame_alloc();
|
||||||
|
if (!thumbnailFrame) {
|
||||||
|
LogError("thumbnailFrame = nullptr.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
thumbnailFrame->format = AV_PIX_FMT_YUV420P;
|
thumbnailFrame->format = AV_PIX_FMT_YUV420P;
|
||||||
thumbnailFrame->width = mTargetWidth;
|
thumbnailFrame->width = mTargetWidth;
|
||||||
thumbnailFrame->height = mTargetHeight;
|
thumbnailFrame->height = mTargetHeight;
|
||||||
|
@ -137,6 +147,10 @@ void FfmpegThumbnail::GetDecodeDataCallback(AVFrame *frame)
|
||||||
int jpegBufSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, mSrouceWidth, mSrouceHeight, 1);
|
int jpegBufSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, mSrouceWidth, mSrouceHeight, 1);
|
||||||
LogInfo("jpegBufSize: %d\n", jpegBufSize);
|
LogInfo("jpegBufSize: %d\n", jpegBufSize);
|
||||||
uint8_t *jpegBuf = (uint8_t *)av_malloc(jpegBufSize);
|
uint8_t *jpegBuf = (uint8_t *)av_malloc(jpegBufSize);
|
||||||
|
if (!jpegBuf) {
|
||||||
|
LogError("jpegBuf = nullptr.\n");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
av_image_fill_arrays(
|
av_image_fill_arrays(
|
||||||
thumbnailFrame->data, thumbnailFrame->linesize, jpegBuf, AV_PIX_FMT_YUV420P, frame->width, frame->height, 1);
|
thumbnailFrame->data, thumbnailFrame->linesize, jpegBuf, AV_PIX_FMT_YUV420P, frame->width, frame->height, 1);
|
||||||
|
|
||||||
|
@ -150,14 +164,25 @@ void FfmpegThumbnail::GetDecodeDataCallback(AVFrame *frame)
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
if (!mSwsCtx) {
|
||||||
|
LogError("mSwsCtx = nullptr.\n");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
system("echo 1 > /proc/sys/vm/drop_caches");
|
||||||
// Perform pixel format conversion.
|
// Perform pixel format conversion.
|
||||||
sws_scale(mSwsCtx, frame->data, frame->linesize, 0, frame->height, thumbnailFrame->data, thumbnailFrame->linesize);
|
sws_scale(mSwsCtx, frame->data, frame->linesize, 0, frame->height, thumbnailFrame->data, thumbnailFrame->linesize);
|
||||||
|
|
||||||
|
return;
|
||||||
if (mEncoder) {
|
if (mEncoder) {
|
||||||
mEncoder->EncodeData(thumbnailFrame, mStream, mEncodeCallback);
|
mEncoder->EncodeData(thumbnailFrame, mStream, mEncodeCallback);
|
||||||
}
|
}
|
||||||
av_frame_free(&thumbnailFrame);
|
END:
|
||||||
av_free(jpegBuf);
|
if (thumbnailFrame) {
|
||||||
|
av_frame_free(&thumbnailFrame);
|
||||||
|
}
|
||||||
|
if (jpegBuf) {
|
||||||
|
av_free(jpegBuf);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void FfmpegThumbnail::GetEncodeDataCallback(AVPacket *pkt, const std::string &fileName)
|
void FfmpegThumbnail::GetEncodeDataCallback(AVPacket *pkt, const std::string &fileName)
|
||||||
|
@ -167,21 +192,19 @@ void FfmpegThumbnail::GetEncodeDataCallback(AVPacket *pkt, const std::string &fi
|
||||||
bool FfmpegThumbnail::SaveThumbnailFile(const std::string &fileName, const void *data, const size_t &size)
|
bool FfmpegThumbnail::SaveThumbnailFile(const std::string &fileName, const void *data, const size_t &size)
|
||||||
{
|
{
|
||||||
FILE *file = nullptr;
|
FILE *file = nullptr;
|
||||||
LogInfo("SaveThumbnailFile:%s\n", fileName.c_str());
|
if (!data) {
|
||||||
file = fopen(fileName.c_str(), "a+");
|
LogError("SaveThumbnailFile:%s failed, data is nullptr.\n", fileName.c_str());
|
||||||
|
|
||||||
if (file) {
|
|
||||||
fwrite(data, 1, size, file);
|
|
||||||
fflush(file);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
LogInfo("SaveThumbnailFile:%s, size = %u\n", fileName.c_str(), size);
|
||||||
if (file) {
|
file = fopen(fileName.c_str(), "a+");
|
||||||
fclose(file);
|
if (!file) {
|
||||||
file = nullptr;
|
LogError("fopen failed.\n");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
fx_system_v2("sync");
|
fwrite(data, 1, size, file);
|
||||||
|
fflush(file);
|
||||||
|
fclose(file);
|
||||||
|
// system("sync");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user