liyujie
2025-08-28 d9927380ed7c8366f762049be9f3fee225860833
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "CameraDebug.h"
 
#define LOG_TAG "CameraDebug"
#include <cutils/log.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/time.h>
 
#ifdef USE_SUNXI_CAMERA_H
#include <sunxi_camera.h>
#else
//#include <videodev2_34.h>
#endif
#ifdef USE_CSI_VIN_DRIVER
#include <sunxi_camera_v2.h>
#endif
#define PATH "/data/camera/"
 
bool saveframe(char *str,void *p, unsigned int length,bool is_oneframe)
{
    int fd;
    LOGD("Debug to save a frame!");
    if(access(str,0) != -1) {
        LOGW("File %s is exists!!!\n",str);
        return true;
    }
    if(is_oneframe)
        fd = open(str,O_CREAT|O_RDWR|O_TRUNC,0777);        //save one frame data
    else
        fd = open(str,O_CREAT|O_RDWR|O_APPEND,0777);       //save more frames
    if(!fd) {
        LOGE("Open file error");
        return false;
    }
    if(write(fd,p,length)){
        //LOGD("Write file successfully");
        close(fd);
        return true;
    }
    else {
        LOGE("Write file fail");
        close(fd);
        return false;
    }
}
 
bool saveSize(int width, int height)
{
    int fd;
    char buf[128];
    fd = open("/data/camera/size.txt",O_CREAT|O_RDWR|O_APPEND,0777);
    if(!fd) {
        LOGE("Open file error");
        return false;
    }
    sprintf(buf,"width:%d height:%d",width,height);
    if(write(fd,(void*)buf,sizeof(buf))) {
        close(fd);
        return true;
    }
    else {
        LOGE("Write file fail");
        close(fd);
        return false;
    }
}