-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
125 lines (99 loc) · 3.16 KB
/
main.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
#include "omx.h"
#include "logerr.h"
#include "omx_still.h"
uint8_t jpeg1[10000000];
uint8_t jpeg2[10000000];
size_t position1 = 0;
size_t position2 = 0;
void buffering1(const uint8_t * const buffer, size_t length)
{
LOG_MESSAGE("Buffer 1 Received %zd at position %zd", length, position1);
if(length > sizeof(jpeg1)-position1)
{
LOG_ERROR("Buffer1 overflow %zd %zd", position1, length);
length = sizeof(jpeg1)-position1;
}
memcpy(&jpeg1[position1], buffer, length);
position1 += length;
}
void buffering2(const uint8_t * const buffer, size_t length)
{
LOG_MESSAGE("Buffer 2 Received %zd at position %zd", length, position2);
if(length > sizeof(jpeg2)-position2)
{
LOG_ERROR("Buffer2 overflow %zd %zd", position2, length);
length = sizeof(jpeg2)-position2;
}
memcpy(&jpeg2[position2], buffer, length);
position2 += length;
}
void buffering(const uint32_t frame, const uint8_t * const buffer, size_t length)
{
switch(frame)
{
case 0: buffering1(buffer, length); break;
case 1: buffering2(buffer, length); break;
default: LOG_ERROR("Unexpected frame %d", frame); break;
}
}
WARN_UNUSED enum error_code write_file(const char * const filename, const uint8_t * const buffer, const size_t length)
{
//Open the file
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0666);
if(fd == -1)
{
LOG_ERRNO("open %s", filename);
return ERROR;
}
//Append the buffer into the file
if(write(fd, buffer, length) == -1)
{
LOG_ERRNO("write %s %zu", filename, length);
return ERROR;
}
//Close the file
if(close(fd))
{
LOG_ERRNO("close %s", filename);
return ERROR;
}
return OK;
}
int main()
{
enum error_code result;
struct camera_shot_configuration config = {
.shutterSpeed = 50000,
.iso = 100,
.redGain = 1000,
.blueGain = 1000,
.quality = 50,
.sharpness = 0,
.contrast = 0,
.brightness = 50,
.saturation = 0,
.drc = OMX_DynRangeExpOff,
.whiteBalance = OMX_WhiteBalControlOff
};
position1 = 0;
position2 = 0;
config.iso = 100;
result = omx_still_open(config); if(result!=OK) { return result; }
result = omx_still_shoot(1, buffering); if(result!=OK) { return result; }
result = omx_still_close(); if(result!=OK) { return result; }
result = write_file("/tmp/1.jpg", jpeg1, position1); if(result!=OK) { return result; }
position1 = 0;
position2 = 0;
config.iso = 200;
result = omx_still_open(config); if(result!=OK) { return result; }
result = omx_still_shoot(1, buffering); if(result!=OK) { return result; }
result = write_file("/tmp/2.jpg", jpeg1, position1); if(result!=OK) { return result; }
return OK;
}