提交 8c2a1bc9 编写于 作者: O openharmony_ci 提交者: Gitee

!39 解决linux录像文件打开错误的问题

Merge pull request !39 from harmony_zhangjian/master
...@@ -112,6 +112,8 @@ static int32_t SampleGetThmFromJpg(const char* jpegPath, uint32_t* dstSize) ...@@ -112,6 +112,8 @@ static int32_t SampleGetThmFromJpg(const char* jpegPath, uint32_t* dstSize)
fstat(fd, &stStat); fstat(fd, &stStat);
pszFile = (char*)malloc(stStat.st_size); pszFile = (char*)malloc(stStat.st_size);
if ((pszFile == nullptr) || (stStat.st_size < 6)) { /* 6 min size of thumb head */ if ((pszFile == nullptr) || (stStat.st_size < 6)) { /* 6 min size of thumb head */
fflush(fpJpg);
fsync(fileno(fpJpg));
fclose(fpJpg); fclose(fpJpg);
if (pszFile) { if (pszFile) {
free(pszFile); free(pszFile);
...@@ -122,6 +124,8 @@ static int32_t SampleGetThmFromJpg(const char* jpegPath, uint32_t* dstSize) ...@@ -122,6 +124,8 @@ static int32_t SampleGetThmFromJpg(const char* jpegPath, uint32_t* dstSize)
} }
if (fread(pszFile, stStat.st_size, 1, fpJpg) <= 0) { if (fread(pszFile, stStat.st_size, 1, fpJpg) <= 0) {
fflush(fpJpg);
fsync(fileno(fpJpg));
fclose(fpJpg); fclose(fpJpg);
free(pszFile); free(pszFile);
printf("fread jpeg src fail!\n"); printf("fread jpeg src fail!\n");
...@@ -173,6 +177,8 @@ int32_t SampleGetdcfinfo(const char* srcJpgPath, const char* dstThmPath) ...@@ -173,6 +177,8 @@ int32_t SampleGetdcfinfo(const char* srcJpgPath, const char* dstThmPath)
u32WritenSize += s32RtnVal; u32WritenSize += s32RtnVal;
} }
if (fpTHM != nullptr) { if (fpTHM != nullptr) {
fflush(fpTHM);
fsync(fileno(fpTHM));
fclose(fpTHM); fclose(fpTHM);
fpTHM = 0; fpTHM = 0;
} }
...@@ -197,6 +203,8 @@ static void SampleSaveCapture(const char* p, uint32_t size, int type, const char ...@@ -197,6 +203,8 @@ static void SampleSaveCapture(const char* p, uint32_t size, int type, const char
fp = fopen(tmpFile, "w+"); fp = fopen(tmpFile, "w+");
if (fp) { if (fp) {
fwrite(p, 1, size, fp); fwrite(p, 1, size, fp);
fflush(fp);
fsync(fileno(fp));
fclose(fp); fclose(fp);
} }
} }
...@@ -211,6 +219,8 @@ static void SampleSaveCapture(const char* p, uint32_t size, int type, const char ...@@ -211,6 +219,8 @@ static void SampleSaveCapture(const char* p, uint32_t size, int type, const char
return; return;
} }
fwrite(p, 1, size, fp); fwrite(p, 1, size, fp);
fflush(fp);
fsync(fileno(fp));
fclose(fp); fclose(fp);
if (type == 0) { if (type == 0) {
...@@ -397,8 +407,13 @@ SampleCameraStateMng::~SampleCameraStateMng() ...@@ -397,8 +407,13 @@ SampleCameraStateMng::~SampleCameraStateMng()
recorder_->Release(); recorder_->Release();
delete recorder_; delete recorder_;
} }
if (gRecFd_ >= 0) if (gRecFd_ >= 0) {
close (gRecFd_); FILE *fp = fdopen(gRecFd_, "w+");
fflush(fp);
fsync(gRecFd_);
fclose(fp);
close(gRecFd_);
}
if (fc_) { if (fc_) {
delete fc_; delete fc_;
fc_ = nullptr; fc_ = nullptr;
...@@ -431,6 +446,10 @@ void SampleCameraStateMng::StartRecord(Surface *mSurface) ...@@ -431,6 +446,10 @@ void SampleCameraStateMng::StartRecord(Surface *mSurface)
return; return;
} }
if (gRecFd_ > 0) { if (gRecFd_ > 0) {
FILE *fp = fdopen(gRecFd_, "w+");
fflush(fp);
fsync(gRecFd_);
fclose(fp);
close(gRecFd_); close(gRecFd_);
gRecFd_ = -1; gRecFd_ = -1;
} }
......
...@@ -196,6 +196,10 @@ public: ...@@ -196,6 +196,10 @@ public:
recorder_ = nullptr; recorder_ = nullptr;
} }
if (recordFd_ != -1) { if (recordFd_ != -1) {
FILE *fp = fdopen(recordFd_, "w+");
fflush(fp);
fsync(recordFd_);
fclose(fp);
close(recordFd_); close(recordFd_);
recordFd_ = -1; recordFd_ = -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册