-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcamera1.backup-20181013-1357.pas
614 lines (450 loc) · 19.3 KB
/
camera1.backup-20181013-1357.pas
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
unit camera1;
// Based on camera_tunnel_non.c by SonienTaegi
// Copyright: GPLv2
interface
uses
classes,sysutils,uIL_Client, uOMX, VC4, threads,
retromalina, mwindows, blitter, retro;
type TCameraThread=class (TThread)
private
protected
procedure Execute; override;
public
Constructor Create(CreateSuspended : boolean);
end;
const COMPONENT_CAMERA='OMX.broadcom.camera';
const COMPONENT_RENDER='OMX.broadcom.video_render';
type PContext=^context;
context=record
pcamera:OMX_HANDLETYPE;
prender:OMX_HANDLETYPE;
iscameraready:OMX_BOOL;
nwidth,nheight,nframerate:cardinal;
pBufferCameraOut:^OMX_BUFFERHEADERTYPE;
pSrcY,pSrcU,pSrcV:^OMX_U8;
nSizeY, nSizeU, nSizeV:cardinal;
pBufferPool:array[0..15] of ^OMX_BUFFERHEADERTYPE; // OMX_BUFFERHEADERTYPE**
nBufferPoolSize,nBufferPoolIndex:cardinal;
isFilled:OMX_BOOL;
end;
var camerathread:TCameraThread;
cmw:pointer=nil;
camerawindow:TWindow=nil;
rendertestwindow:TWindow=nil;
mContext:context;
t1,t2,t3,t4:int64;
procedure camera;
implementation
var camerabufferfilled:boolean;
procedure print_log(s:string);
begin
camerawindow.println(s);
end;
constructor TCameraThread.create(CreateSuspended : boolean);
begin
FreeOnTerminate := True;
inherited Create(CreateSuspended);
end;
procedure TCameraThread.execute;
label p999;
begin
ThreadSetpriority(ThreadGetCurrent,6);
sleep(1);
setpallette(grayscalepallette,0);
if camerawindow=nil then
begin
camerawindow:=TWindow.create(480,800,'Camera log');
camerawindow.decoration.hscroll:=true;
camerawindow.decoration.vscroll:=true;
camerawindow.resizable:=true;
camerawindow.cls(0);
camerawindow.tc:=252;
camerawindow.move(1200,64,480,1100,0,0);
cmw:=camerawindow;
end
else goto p999;
if rendertestwindow=nil then
begin
rendertestwindow:=TWindow.create(1280,720,'Camera render');
rendertestwindow.decoration.hscroll:=false;
rendertestwindow.decoration.vscroll:=false;
rendertestwindow.resizable:=true;
rendertestwindow.cls(0);
rendertestwindow.tc:=15;
rendertestwindow.move(800,400,1280,720,0,0);
end;
camera;
repeat sleep(100) until camerawindow.needclose;
camerawindow.destroy;
camerawindow:=nil;
rendertestwindow.destroy;
rendertestwindow:=nil;
cmw:=nil;
p999:
setpallette(ataripallette,0);
end;
//------------------------------------------------------------------------------
//
// You need to define these 3 callbacks to use OMX
//
//------------------------------------------------------------------------------
// Callback: OMX Event occured
function onOMXevent(hComponent: OMX_HANDLETYPE;
pAppData:OMX_PTR;
eEvent: OMX_EVENTTYPE;
nData1: OMX_U32;
nData2: OMX_U32;
pEventData: OMX_PTR): OMX_ERRORTYPE; cdecl;
begin
result:= OMX_ErrorNone;
end;
// Callback: Camera buffer filled
function onFillCameraOut(hComponent:OMX_HANDLETYPE; pAppData: OMX_PTR;pBuffer:POMX_BUFFERHEADERTYPE): OMX_ERRORTYPE; cdecl;
begin
camerabufferfilled:=true;
result:=OMX_ErrorNone;
end;
// Callback: Render buffer empty
function onEmptyRenderIn(hComponent:OMX_HANDLETYPE; pAppData:OMX_PTR; PBuffer:POMX_BUFFERHEADERTYPE): OMX_ERRORTYPE; cdecl;
begin
result:= OMX_ErrorNone;
end;
function isState(hcomponent:POMX_HANDLETYPE; state:OMX_STATETYPE): OMX_BOOL;
var currentState: OMX_STATETYPE;
begin
if (hComponent=nil) then result:=OMX_FALSE;
OMX_GetState(hComponent,@currentState);
if currentState=state then result:=OMX_TRUE else result:=OMX_FALSE;
end;
function wait_for_state_change(state_tobe: OMX_STATETYPE; handle:OMX_HANDLETYPE): OMX_BOOL;
var isValid:OMX_BOOL=OMX_TRUE;
timeout_counter:cardinal=0;
state_current:OMX_STATETYPE;
begin
camerawindow.println('Waiting for '+inttohex(cardinal(handle),8));
isValid := OMX_FALSE;
while (timeout_counter < 5000) and (isValid=OMX_FALSE) do
begin
timeout_counter:=0;
OMX_GetState(handle, @state_current);
if (state_current <> state_tobe) then begin threadsleep(1); inc(timeout_counter); end else IsValid:=OMX_TRUE;
end;
result:=IsValid;
end;
procedure terminate;
var state:OMX_STATETYPE;
bWaitForCamera, bWaitForRender: OMX_BOOL;
begin
camerawindow.println('On terminating...');
bWaitForCamera := OMX_FALSE;
bWaitForRender := OMX_FALSE;
if(isState(mContext.pCamera, OMX_StateExecuting))=OMX_TRUE then
begin
OMX_SendCommand(mContext.pCamera, OMX_CommandStateSet, OMX_StateIdle, nil);
bWaitForCamera := OMX_TRUE;
end;
if(isState(mContext.pRender, OMX_StateExecuting))=OMX_TRUE then
begin
OMX_SendCommand(mContext.pRender, OMX_CommandStateSet, OMX_StateIdle, nil);
bWaitForRender := OMX_TRUE;
end;
if(bWaitForCamera=OMX_TRUE) then wait_for_state_change(OMX_StateIdle, mContext.pCamera);
if(bWaitForRender=OMX_TRUE) then wait_for_state_change(OMX_StateIdle, mContext.pRender);
// Idle -> Loaded
bWaitForCamera := OMX_FALSE;
bWaitForRender := OMX_FALSE;
if(isState(mContext.pCamera, OMX_StateIdle)) =OMX_TRUE then
begin
OMX_SendCommand(mContext.pCamera, OMX_CommandStateSet, OMX_StateLoaded, nil);
bWaitForCamera := OMX_TRUE;
end;
if(isState(mContext.pRender, OMX_StateIdle)) then
begin
OMX_SendCommand(mContext.pRender, OMX_CommandStateSet, OMX_StateLoaded, nil);
bWaitForRender := OMX_TRUE;
end;
//if(bWaitForCamera=OMX_TRUE) then wait_for_state_change(OMX_StateLoaded, mContext.pCamera);
//if(bWaitForRender=OMX_TRUE) then wait_for_state_change(OMX_StateLoaded, mContext.pRender);
// Loaded -> Free
if(isState(mContext.pCamera, OMX_StateLoaded))=OMX_TRUE then OMX_FreeHandle(mContext.pCamera);
if(isState(mContext.pRender, OMX_StateLoaded))=OMX_TRUE then OMX_FreeHandle(mContext.pRender);
OMX_Deinit();
print_log('Terminated. You can now close the window');
end;
procedure componentPrepare;
var err:OMX_ERRORTYPE;
portDef:OMX_PARAM_PORTDEFINITIONTYPE;
i:cardinal;
begin
// Request state of components to be IDLE.
// The command will turn the component into waiting mode.
// After allocating buffer to all enabled ports than the component will be IDLE.
// Allocate buffer to camera
//for i:=0 to 16 do removeramlimits(cardinal(mContext.pSrcY)+i*4096);
// Wait up for component being idle.
print_log('STATE : IDLE OK!');
end;
procedure camera;
label p999;
var err:OMX_ERRORTYPE;
portdef:OMX_PARAM_PORTDEFINITIONTYPE;
callbackOMX:OMX_CALLBACKTYPE;
portCapturing:OMX_CONFIG_PORTBOOLEANTYPE;
deviceNumber:OMX_PARAM_U32TYPE;
formatVideo:POMX_VIDEO_PORTDEFINITIONTYPE;
displayRegion:OMX_CONFIG_DISPLAYREGIONTYPE;
y,u,v,y2,u2,v2:cardinal;
py:POMX_U8=nil;
pu:POMX_U8=nil;
pv:POMX_U8=nil;
py2:POMX_U8=nil;
pu2:POMX_U8=nil;
pv2:POMX_U8=nil;
nOffsetU, nOffsetV, nFrameMax, nFrames:cardinal;
PBuffer: POMX_BUFFERHEADERTYPE;
i:integer;
qqq:int64;
begin
// Initialize variables
FillChar (mContext, SizeOf(mContext), 0);
mContext.nWidth := 1280;
mContext.nHeight := 720;
mContext.nFramerate := 90;
// initialize VC4.
bcmhostinit;
print_log('VC4 initialized');
// initialize OMX
OMX_Init;
print_log('OMX initialized');
// Set 3 callbacks needed by OMX components
callbackOMX.EventHandler := @onOMXevent;
callbackOMX.EmptyBufferDone := @onEmptyRenderIn;
callbackOMX.FillBufferDone := @onFillCameraOut;
print_log('Callbacks set');
// Load the camera and the renderer
err := OMX_GetHandle(@(mContext.pCamera), COMPONENT_CAMERA, @mContext, @CallbackOMX);
if (err <> OMX_ErrorNone ) then print_log('error loading camera'+inttostr(err));
print_log('Camera loaded: '+inttohex(cardinal(mContext.pCamera),8));
err := OMX_GetHandle(@(mContext.pRender), COMPONENT_RENDER, @mContext, @CallbackOMX);
if (err <> OMX_ErrorNone ) then print_log('error loading renderer'+inttostr(err));
print_log('Renderer loaded: '+inttohex(cardinal(mContext.pRender),8));
// Disable unused camera ports - we will use #71
OMX_SendCommand(mContext.pCamera, OMX_CommandPortDisable, 70, nil);
OMX_SendCommand(mContext.pCamera, OMX_CommandPortDisable, 72, nil);
OMX_SendCommand(mContext.pCamera, OMX_CommandPortDisable, 73, nil);
print_log('Camera ports 70,72,73 disabled');
// Set camera device number
FillChar (deviceNumber, SizeOf(deviceNumber), 0);
deviceNumber.nSize := sizeof(deviceNumber);
deviceNumber.nVersion.nVersion := OMX_VERSION;
deviceNumber.nVersion.nVersionMajor := OMX_VERSION_MAJOR;
deviceNumber.nVersion.nVersionMinor := OMX_VERSION_MINOR;
deviceNumber.nVersion.nRevision := OMX_VERSION_REVISION;
deviceNumber.nVersion.nStep := OMX_VERSION_STEP;
deviceNumber.nPortIndex := OMX_ALL;
deviceNumber.nU32 := 0;
err := OMX_SetParameter(mContext.pCamera, OMX_IndexParamCameraDeviceNumber, @deviceNumber);
if err<>OMX_ErrorNone then print_log(inttostr(err)+ 'camera set number FAIL');
print_log('Camera device number set to 0');
// Set video format of #71 port and compute the camera buffer size.
//Step 1 - get default parameters
FillChar (portDef, SizeOf(portDef), 0);
portDef.nSize := sizeof(portDef);
portDef.nVersion.nVersion := OMX_VERSION;
portDef.nVersion.nVersionMajor := OMX_VERSION_MAJOR;
portDef.nVersion.nVersionMinor := OMX_VERSION_MINOR;
portDef.nVersion.nRevision := OMX_VERSION_REVISION;
portDef.nVersion.nStep := OMX_VERSION_STEP;
portDef.nPortIndex := 71;
OMX_GetParameter(mContext.pCamera, OMX_IndexParamPortDefinition, @portDef);
//Step 2 - set needed video format
formatVideo := @portDef.format.video;
formatVideo^.eColorFormat := OMX_COLOR_FormatYUV420PackedPlanar;
formatVideo^.nFrameWidth := mContext.nWidth;
formatVideo^.nFrameHeight := mContext.nHeight;
formatVideo^.xFramerate := mContext.nFramerate shl 16; // Fixed point. 1
formatVideo^.nStride := formatVideo^.nFrameWidth; // Stride 0 -> Raise segment fault.
formatVideo^.nSliceHeight := mContext.nHeight;
err := OMX_SetParameter(mContext.pCamera, OMX_IndexParamPortDefinition, @portDef);
if err<>OMX_ErrorNone then print_log(inttostr(err)+ 'camera set format FAIL');
print_log('Camera video format set to '+inttostr(mContext.nWidth)+'x'+inttostr(mContext.nHeight));
//Step 3 - retrieve new parameters from the camera after setting and compute the buffers size
OMX_GetParameter(mContext.pCamera, OMX_IndexParamPortDefinition, @portDef);
formatVideo := @portDef.format.video;
mContext.nSizeY := formatVideo^.nFrameWidth * formatVideo^.nSliceHeight;
mContext.nSizeU := mContext.nSizeY div 4;
mContext.nSizeV := mContext.nSizeY div 4;
print_log('Camera buffer size Y: '+inttostr(mContext.nSizeY)+'; U: '+inttostr(mContext.nSizeU)+'; V: '+inttostr(mContext.nSizeV));
// ------------- End of video format setting -----------------------------------
// Set video format of renderer port #90
FillChar (portDef, SizeOf(portDef), 0);
portDef.nSize := sizeof(portDef);
portDef.nVersion.nVersion := OMX_VERSION;
portDef.nVersion.nVersionMajor := OMX_VERSION_MAJOR;
portDef.nVersion.nVersionMinor := OMX_VERSION_MINOR;
portDef.nVersion.nRevision := OMX_VERSION_REVISION;
portDef.nVersion.nStep := OMX_VERSION_STEP;
portDef.nPortIndex := 90;
OMX_GetParameter(mContext.pRender, OMX_IndexParamPortDefinition, @portDef);
formatVideo := @portDef.format.video;
formatVideo^.eColorFormat := OMX_COLOR_FormatYUV420PackedPlanar;
formatVideo^.eCompressionFormat := OMX_VIDEO_CodingUnused;
formatVideo^.nFrameWidth := mContext.nWidth;
formatVideo^.nFrameHeight := mContext.nHeight;
formatVideo^.nStride := mContext.nWidth;
formatVideo^.nSliceHeight := mContext.nHeight;
formatVideo^.xFramerate := mContext.nFramerate shl 16;
err := OMX_SetParameter(mContext.pRender, OMX_IndexParamPortDefinition, @portDef);
if err<>OMX_ErrorNone then print_log(inttostr(err)+ 'renderer set format failed');
print_log('Renderer video format set to '+inttostr(mContext.nWidth)+'x'+inttostr(mContext.nHeight));
// Configure rendering region
FillChar (displayRegion, SizeOf(displayRegion), 0);
displayRegion.nSize := sizeof(displayRegion);
displayRegion.nVersion.nVersion := OMX_VERSION;
displayRegion.nVersion.nVersionMajor := OMX_VERSION_MAJOR;
displayRegion.nVersion.nVersionMinor := OMX_VERSION_MINOR;
displayRegion.nVersion.nRevision := OMX_VERSION_REVISION;
displayRegion.nVersion.nStep := OMX_VERSION_STEP;
displayRegion.nPortIndex := 90;
displayRegion.dest_rect.width := mContext.nWidth div 2;
displayRegion.dest_rect.height := mContext.nHeight div 2;
displayRegion.dest_rect.x_offset := 30;
displayRegion.dest_rect.y_offset := 30;
displayRegion.set_ := OMX_DISPLAY_SET_NUM or OMX_DISPLAY_SET_FULLSCREEN or OMX_DISPLAY_SET_MODE or OMX_DISPLAY_SET_DEST_RECT;
displayRegion.mode := OMX_DISPLAY_MODE_FILL;
displayRegion.fullscreen := OMX_FALSE;
displayRegion.num := 0;
err := OMX_SetConfig(mContext.pRender, OMX_IndexConfigDisplayRegion, @displayRegion);
if err<>OMX_ErrorNone then print_log(inttostr(err)+ 'renderer set region FAIL');
print_log('Renderer display region set to '+inttostr(displayRegion.dest_rect.width)+'x'+inttostr(displayRegion.dest_rect.height ));
//------ End of renderer format setting ----------------------------------------
//------ Change the components state from loaded to idle------------------------
err := OMX_SendCommand(mContext.pCamera, OMX_CommandStateSet, OMX_StateIdle, nil);
if err<>OMX_ErrorNone then print_log(inttostr(err)+ 'camera idle request FAIL');
print_log('Camera state set to idle');
err := OMX_SendCommand(mContext.pRender, OMX_CommandStateSet, OMX_StateIdle, nil);
if err<>OMX_ErrorNone then print_log(inttostr(err)+ 'renderer idle request FAIL');
print_log('Renderer state set to idle');
//----- Allocate buffers to render
FillChar (portDef, SizeOf(portDef), 0);
portDef.nSize := sizeof(portDef);
portDef.nVersion.nVersion := OMX_VERSION;
portDef.nVersion.nVersionMajor := OMX_VERSION_MAJOR;
portDef.nVersion.nVersionMinor := OMX_VERSION_MINOR;
portDef.nVersion.nRevision := OMX_VERSION_REVISION;
portDef.nVersion.nStep := OMX_VERSION_STEP;
portDef.nPortIndex := 90;
OMX_GetParameter(mContext.pRender, OMX_IndexParamPortDefinition, @portDef);
mContext.nBufferPoolSize := portDef.nBufferCountActual;
mContext.nBufferPoolIndex := 0;
for i:=0 to mContext.nBufferPoolSize-1 do
begin
mContext.pBufferPool[i] := nil;
err := OMX_AllocateBuffer(mContext.pRender, @(mContext.pBufferPool[i]), 90, @mContext, portDef.nBufferSize);
if err<>OMX_ErrorNone then print_log(inttostr(err)+ 'allocate render buffer FAIL');
end;
print_log('Allocated '+inttostr(portDef.nBufferCountActual)+' render buffers size '+inttostr(portDef.nBufferSize));
//----- Allocate buffers to camera
FillChar (portDef, SizeOf(portDef), 0);
portDef.nSize := sizeof(portDef);
portDef.nVersion.nVersion := OMX_VERSION;
portDef.nVersion.nVersionMajor := OMX_VERSION_MAJOR;
portDef.nVersion.nVersionMinor := OMX_VERSION_MINOR;
portDef.nVersion.nRevision := OMX_VERSION_REVISION;
portDef.nVersion.nStep := OMX_VERSION_STEP;
portDef.nPortIndex := 71;
OMX_GetParameter(mContext.pCamera, OMX_IndexParamPortDefinition, @portDef);
OMX_AllocateBuffer(mContext.pCamera, @mContext.pBufferCameraOut, 71, @mContext, portDef.nBufferSize);
if err<>OMX_ErrorNone then print_log(inttostr(err)+ 'allocate camera buffer FAIL');
print_log('Allocated '+inttostr(portDef.nBufferCountActual)+' camera buffers size '+inttostr(portDef.nBufferSize));
//--- set working variables
mContext.pSrcY := mContext.pBufferCameraOut^.pBuffer;
mContext.pSrcU := pointer(cardinal(mContext.pSrcY) + mContext.nSizeY);
mContext.pSrcV := pointer(cardinal(mContext.pSrcU) + mContext.nSizeU);
print_log('Y buffer at '+inttohex(cardinal(mContext.pSrcY),8));
//------- wait until components state is idle
if wait_for_state_change(OMX_StateIdle, mContext.pRender)=OMX_FALSE then print_log('*** Failed waiting for renderer idle state')
else print_log('Renderer state is now idle');
if wait_for_state_change(OMX_StateIdle, mContext.pCamera)=OMX_FALSE then print_log('*** Failed waiting for camera idle state')
else print_log('Camera state is now idle');
//------ Change the components state from loaded to idle------------------------
err := OMX_SendCommand(mContext.pCamera, OMX_CommandStateSet, OMX_StateExecuting, nil);
if err<>OMX_ErrorNone then print_log(inttostr(err)+' Camera executing FAIL');
err := OMX_SendCommand(mContext.pRender, OMX_CommandStateSet, OMX_StateExecuting, nil);
if err<>OMX_ErrorNone then print_log(inttostr(err)+' Renderer executing FAIL');
if wait_for_state_change(OMX_StateExecuting, mContext.pRender)=OMX_FALSE then print_log('*** Failed waiting for renderer executing state')
else print_log('Renderer state is now executing');
if wait_for_state_change(OMX_StateExecuting, mContext.pCamera)=OMX_FALSE then print_log('*** Failed waiting for renderer executing state')
else print_log('Camera state is now executing');
//----------- Start capturing at port 71 --------------------------------------
while keypressed do readkey;
print_log('Capture start. Press any key to stop');
FillChar (portCapturing, SizeOf(portCapturing), 0);
portCapturing.nSize := sizeof(portCapturing);
portCapturing.nVersion.nVersion := OMX_VERSION;
portCapturing.nVersion.nVersionMajor := OMX_VERSION_MAJOR;
portCapturing.nVersion.nVersionMinor := OMX_VERSION_MINOR;
portCapturing.nVersion.nRevision := OMX_VERSION_REVISION;
portCapturing.nVersion.nStep := OMX_VERSION_STEP;
portCapturing.nPortIndex := 71;
portCapturing.bEnabled := OMX_TRUE;
OMX_SetConfig(mContext.pCamera, OMX_IndexConfigPortCapturing, @portCapturing);
pY := nil;
pU := nil;
pV := nil;
nOffsetU := mContext.nWidth * mContext.nHeight;
nOffsetV := (nOffsetU * 5) div 4;
nFrameMax:= mContext.nFramerate * 600;
nFrames := 0;
print_log('Capture will stop itself after '+inttostr(nFramemax div mContext.nFramerate)+' seconds');
// ---- Fill initial camera buffer
OMX_FillThisBuffer(mContext.pCamera, mContext.pBufferCameraOut);
// ---- Prepare addresses for fastmove
y2:=cardinal(mContext.pSrcY);
u2:=cardinal(mContext.pSrcU);
v2:=cardinal(mContext.pSrcV);
// ----- MAIN CAPTURE LOOP -----------------------------------------------------
while keypressed do readkey;
while(nFrames < nFrameMax) and (not keypressed) do
begin
if camerabufferfilled then
begin
t1:=gettime;
// pBuffer := mContext.pBufferPool[mContext.nBufferPoolIndex];
// if(pBuffer^.nFilledLen = 0) then
// begin
// y:= cardinal(pBuffer^.pBuffer);
// u:=y+nOffsetU;
// v:=y+nOffsetV;
// end;
// fastmove(y2,y,mContext.nSizeY); y += mContext.nSizeY;
// fastmove(u2,u,mContext.nSizeU); u += mContext.nSizeU;
// fastmove(v2,v,mContext.nSizeV); v += mContext.nSizeV;
// retromachine blit test
blit8(y2,0,0,cardinal(rendertestwindow.canvas),0,0,1280,720,1280,1280);
t1:=gettime-t1;
rendertestwindow.outtextxyz(4,4,inttostr(t1),15,2,2);
rendertestwindow.outtextxyz(4,44,inttostr(t2),15,2,2);
rendertestwindow.outtextxyz(4,84,inttostr(nframes),15,2,2);
// pBuffer^.nFilledLen += mContext.pBufferCameraOut^.nFilledLen;
// if (mContext.pBufferCameraOut^.nFlags and OMX_BUFFERFLAG_ENDOFFRAME)<>0 then
// begin
// OMX_EmptyThisBuffer(mContext.pRender, pBuffer);
// mContext.nBufferPoolIndex+=1;
// if(mContext.nBufferPoolIndex = mContext.nBufferPoolSize) then mContext.nBufferPoolIndex := 0;
// nFrames+=1;
// end;
camerabufferfilled:=false;
t2:=gettime;
OMX_FillThisBuffer(mContext.pCamera, mContext.pBufferCameraOut);
t2:=gettime-t2;
end;
threadsleep(1);
end;
portCapturing.bEnabled := OMX_FALSE;
OMX_SetConfig(mContext.pCamera, OMX_IndexConfigPortCapturing, @portCapturing);
print_log('Capture stop.');
p999:
terminate;
end;
end.