This source file includes following definitions.
- filewrite_get_file_chunk
- filewrite_set_discard_file
- filewrite_main_hook
- filewrite_file_complete
- remotecap_fwt_chunks_done
- fwt_open
- fwt_write
- fwt_lseek
- fwt_close
- fwt_after_close
1 #include "stdlib.h"
2
3 #include "remotecap_core.h"
4 static int ignore_current_write=0;
5 #ifdef CAM_DRYOS
6 static long fwt_bytes_written = 0;
7 volatile int current_write_ignored=0;
8 #endif
9
10
11
12
13
14
15 static cam_ptp_data_chunk *file_chunks;
16 #ifdef CAM_FILEWRITETASK_MULTIPASS
17 static int file_curr_session_chunk;
18 #ifdef CAM_FILEWRITETASK_SEEKS
19 static int file_bytes_left;
20 static int fwt_file_offset;
21 static int file_full_size;
22 #else
23 static int file_last_session;
24 #endif
25 #endif
26
27
28
29
30 int filewrite_get_file_chunk(char **addr,int *size,unsigned n,int *pos) {
31 *pos=-1;
32 #if !defined(CAM_FILEWRITETASK_MULTIPASS)
33
34 if (n >= MAX_CHUNKS_FOR_FWT || file_chunks == NULL) {
35 *addr=(char *)0xFFFFFFFF;
36 *size=0;
37 return REMOTECAP_FWT_CHUNK_STATUS_LAST;
38 }
39 *addr=(char *)file_chunks[n].address;
40 *size=file_chunks[n].length;
41 if (n < MAX_CHUNKS_FOR_FWT-1) {
42 if (file_chunks[n+1].length==0) {
43 return REMOTECAP_FWT_CHUNK_STATUS_LAST;
44 }
45 return REMOTECAP_FWT_CHUNK_STATUS_MORE;
46 }
47 return REMOTECAP_FWT_CHUNK_STATUS_LAST;
48 #else
49 if ( file_chunks == NULL ) {
50 int m=50;
51 while (m>0) {
52 _SleepTask(10);
53 m--;
54 if ( file_chunks != NULL ) break;
55 }
56 if ( file_chunks == NULL ) {
57 *addr=(char *)0;
58 *size=0;
59 return REMOTECAP_FWT_CHUNK_STATUS_LAST;
60 }
61 }
62 *addr=(char *)file_chunks[file_curr_session_chunk].address;
63 *size=file_chunks[file_curr_session_chunk].length;
64 #ifdef CAM_FILEWRITETASK_SEEKS
65 if ( n == 0 ) {
66 file_bytes_left = file_full_size;
67 }
68 file_bytes_left -= *size;
69 if (file_curr_session_chunk == 0) {
70 *pos=fwt_file_offset;
71 }
72 #else
73 (void)n;
74 if ((file_curr_session_chunk==0) && (file_last_session)) {
75 *pos=0;
76 }
77 #endif
78 file_curr_session_chunk++;
79 #ifdef CAM_FILEWRITETASK_SEEKS
80 if (file_bytes_left>0) {
81 if ( file_curr_session_chunk < MAX_CHUNKS_FOR_FWT ) {
82 if (file_chunks[file_curr_session_chunk].length==0) {
83 return REMOTECAP_FWT_CHUNK_STATUS_SESS_LAST;
84 }
85 return REMOTECAP_FWT_CHUNK_STATUS_MORE;
86 }
87 else {
88 return REMOTECAP_FWT_CHUNK_STATUS_SESS_LAST;
89 }
90 }
91 #else
92 if ( file_curr_session_chunk < MAX_CHUNKS_FOR_FWT ) {
93 if (file_chunks[file_curr_session_chunk].length==0) {
94 if (file_last_session) {
95 return REMOTECAP_FWT_CHUNK_STATUS_LAST;
96 }
97 else {
98 return REMOTECAP_FWT_CHUNK_STATUS_SESS_LAST;
99 }
100 }
101 return REMOTECAP_FWT_CHUNK_STATUS_MORE;
102 }
103 else {
104 if (file_last_session) {
105 return REMOTECAP_FWT_CHUNK_STATUS_LAST;
106 }
107 else {
108 return REMOTECAP_FWT_CHUNK_STATUS_SESS_LAST;
109 }
110 }
111 #endif
112 return REMOTECAP_FWT_CHUNK_STATUS_LAST;
113 #endif
114 }
115
116 void filewrite_set_discard_file(int state) {
117 ignore_current_write = state;
118 }
119
120 void filewrite_main_hook(fwt_data_struct *fwt_data)
121 {
122 #ifdef CAM_FILEWRITETASK_MULTIPASS
123 file_curr_session_chunk = 0;
124 #ifdef CAM_FILEWRITETASK_SEEKS
125
126
127
128
129
130
131
132
133
134
135
136
137 if ( ((fwt_data->seek_flag & FWT_SEEKMASK) == FWT_MUSTSEEK) || (fwt_data->file_offset != 0) ) {
138 fwt_file_offset = fwt_data->file_offset;
139 }
140 else {
141 fwt_file_offset = -1;
142 }
143 file_full_size = fwt_data->full_size;
144 #else
145
146
147
148
149
150
151 if (fwt_data->oflags & OFLAG_NOFLUSH) {
152 file_last_session = 0;
153 }
154 else {
155 file_last_session = 1;
156 }
157 #endif
158 #endif
159
160 file_chunks = &(fwt_data->pdc[0]);
161 #ifdef CAM_HAS_CANON_RAW
162
163
164 if(strcmp(".CR2",&(fwt_data->name[24])) == 0) {
165 remotecap_fwt_craw_available();
166 } else {
167 remotecap_fwt_jpeg_available();
168 }
169 #else
170 remotecap_fwt_jpeg_available();
171 #endif
172 file_chunks=NULL;
173 }
174
175
176
177
178 int filewrite_file_complete(void) {
179 if(ignore_current_write) {
180 #ifdef CAM_DRYOS
181 #ifdef CAM_FILEWRITETASK_SEEKS
182 if (fwt_bytes_written < file_full_size) {
183 return 1;
184 }
185 #elif defined(CAM_FILEWRITETASK_MULTIPASS)
186 if (!file_last_session) {
187 return 1;
188 }
189 #endif
190 current_write_ignored=0;
191 fwt_bytes_written = 0;
192 #endif
193 remotecap_fwt_file_complete();
194 return 1;
195 }
196 return 0;
197 }
198
199 #ifdef CAM_FILEWRITETASK_MULTIPASS
200 void remotecap_fwt_chunks_done() {
201 file_chunks=NULL;
202 }
203 #endif
204
205
206 #ifdef CAM_DRYOS
207 int fwt_open(const char *name, int flags, int mode) {
208 if (!ignore_current_write) {
209 return _Open(name, flags, mode);
210 }
211 current_write_ignored=1;
212 return 255;
213 }
214
215 int fwt_write(int fd, const void *buffer, long nbytes) {
216 if (!current_write_ignored) {
217 return _Write(fd, buffer, nbytes);
218 }
219 fwt_bytes_written += nbytes;
220 return (int)nbytes;
221 }
222
223 #ifdef CAM_FILEWRITETASK_SEEKS
224 int fwt_lseek(int fd, long offset, int whence) {
225 if (!current_write_ignored) {
226 return _lseek(fd, offset, whence);
227 }
228 return (int)offset;
229 }
230 #endif
231
232 int fwt_close (int fd) {
233 if (!filewrite_file_complete()) {
234 int ret = _Close(fd);
235
236 fwt_bytes_written = 0;
237 return ret;
238 }
239 return 0;
240 }
241 #else
242
243
244
245
246 int fwt_after_close (int param) {
247
248 return param;
249 }
250 #endif