forked from mitya555/capture-encode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode.c
1206 lines (992 loc) · 41.7 KB
/
encode.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
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2012, Broadcom Europe Ltd
Copyright (c) 2012, Kalle Vahlman <zuh@iki>
Tuomas Kulve <[email protected]>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Video encode demo using OpenMAX IL though the ilcient helper library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "interface/vcos/vcos_assert.h"
#include <time.h>
#include <signal.h>
#include "bcm_host.h"
#include "ilclient.h"
#define NUMFRAMES 300
#define WIDTH 640
#define PITCH ((WIDTH+31)&~31)
#define HEIGHT ((WIDTH)*9/16)
#define HEIGHT16 ((HEIGHT+15)&~15)
#define SIZE ((WIDTH * HEIGHT16 * 3)/2)
// generate an animated test card in YUV format
static int
generate_test_card(void *buf, OMX_U32 * filledLen, int frame) {
int i, j;
char *y = buf, *u = y + PITCH * HEIGHT16, *v =
u + (PITCH >> 1) * (HEIGHT16 >> 1);
for (j = 0; j < HEIGHT / 2; j++) {
char *py = y + 2 * j * PITCH;
char *pu = u + j * (PITCH >> 1);
char *pv = v + j * (PITCH >> 1);
for (i = 0; i < WIDTH / 2; i++) {
int z = (((i + frame) >> 4) ^ ((j + frame) >> 4)) & 15;
py[0] = py[1] = py[PITCH] = py[PITCH + 1] = 0x80 + z * 0x8;
pu[0] = 0x00 + z * 0x10;
pv[0] = 0x80 + z * 0x30;
py += 2;
pu++;
pv++;
}
}
*filledLen = SIZE;
return 1;
}
static void
print_def_(OMX_PARAM_PORTDEFINITIONTYPE *def_ptr, FILE *out, int image) {
fprintf(out, "Port %u: %s %u/%u %u %u %s, %s, %s",
def_ptr->nPortIndex,
def_ptr->eDir == OMX_DirInput ? "in" : "out",
def_ptr->nBufferCountActual,
def_ptr->nBufferCountMin,
def_ptr->nBufferSize,
def_ptr->nBufferAlignment,
def_ptr->bEnabled ? "enabled" : "disabled",
def_ptr->bPopulated ? "populated" : "not populated",
def_ptr->bBuffersContiguous ? "contiguous" : "not contiguous");
if (image)
fprintf(out, " Image: %ux%u %ux%u fmt=%u %u\n",
def_ptr->format.image.nFrameWidth,
def_ptr->format.image.nFrameHeight,
def_ptr->format.image.nStride,
def_ptr->format.image.nSliceHeight,
def_ptr->format.image.eCompressionFormat,
def_ptr->format.image.eColorFormat);
else
fprintf(out, " Video: %ux%u %ux%u fmt=%u %u @%u\n",
def_ptr->format.video.nFrameWidth,
def_ptr->format.video.nFrameHeight,
def_ptr->format.video.nStride,
def_ptr->format.video.nSliceHeight,
def_ptr->format.video.eCompressionFormat,
def_ptr->format.video.eColorFormat,
def_ptr->format.video.xFramerate >> 16);
}
extern void
time_diff(struct timespec *start, struct timespec *end, struct timespec *result);
static void
get_time_diff(struct timespec *start, struct timespec *result) {
struct timespec cur_time;
clock_gettime(CLOCK_MONOTONIC, &cur_time);
time_diff(start, &cur_time, result);
}
static void
wait_timeout(__time_t sec, __suseconds_t usec) {
struct timeval timeout;
timeout.tv_sec = sec;
timeout.tv_usec = usec;
select(0, NULL, NULL, NULL, &timeout);
}
static void
print_def(OMX_PARAM_PORTDEFINITIONTYPE *def_ptr, FILE *out) {
print_def_(def_ptr, out, 0); // video by default
}
int
video_encode_test(char *outputfilename)
{
OMX_VIDEO_PARAM_PORTFORMATTYPE format;
OMX_PARAM_PORTDEFINITIONTYPE def;
COMPONENT_T *video_encode = NULL;
COMPONENT_T *list[5];
OMX_BUFFERHEADERTYPE *buf;
OMX_BUFFERHEADERTYPE *out;
OMX_ERRORTYPE r;
ILCLIENT_T *client;
int status = 0;
int framenumber = 0;
FILE *outf;
memset(list, 0, sizeof(list));
if ((client = ilclient_init()) == NULL) {
return -3;
}
if (OMX_Init() != OMX_ErrorNone) {
ilclient_destroy(client);
return -4;
}
// create video_encode
r = ilclient_create_component(client, &video_encode, "video_encode",
ILCLIENT_DISABLE_ALL_PORTS |
ILCLIENT_ENABLE_INPUT_BUFFERS |
ILCLIENT_ENABLE_OUTPUT_BUFFERS);
if (r != 0) {
printf
("ilclient_create_component() for video_encode failed with %x!\n",
r);
exit(1);
}
list[0] = video_encode;
// get current settings of video_encode component from port 200
memset(&def, 0, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
def.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
def.nVersion.nVersion = OMX_VERSION;
def.nPortIndex = 200;
if (OMX_GetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamPortDefinition,
&def) != OMX_ErrorNone) {
printf("%s:%d: OMX_GetParameter() for video_encode port 200 failed!\n",
__FUNCTION__, __LINE__);
exit(1);
}
print_def(&def, stdout);
// Port 200: in 1/1 115200 16 enabled,not pop.,not cont. 320x240 320x240 @1966080 20
def.format.video.nFrameWidth = WIDTH;
def.format.video.nFrameHeight = HEIGHT;
def.format.video.xFramerate = 30 << 16;
def.format.video.nSliceHeight = def.format.video.nFrameHeight;
def.format.video.nStride = def.format.video.nFrameWidth;
def.format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
print_def(&def, stdout);
r = OMX_SetParameter(ILC_GET_HANDLE(video_encode),
OMX_IndexParamPortDefinition, &def);
if (r != OMX_ErrorNone) {
printf("%s:%d: OMX_SetParameter() for video_encode port 200 failed with %x!\n",
__FUNCTION__, __LINE__, r);
exit(1);
}
memset(&format, 0, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
format.nSize = sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE);
format.nVersion.nVersion = OMX_VERSION;
format.nPortIndex = 201;
format.eCompressionFormat = OMX_VIDEO_CodingAVC; // OMX_VIDEO_CodingMPEG4 fails, see https://github.com/raspberrypi/firmware/issues/162
printf("OMX_SetParameter for video_encode:201...\n");
r = OMX_SetParameter(ILC_GET_HANDLE(video_encode),
OMX_IndexParamVideoPortFormat, &format);
if (r != OMX_ErrorNone) {
printf("%s:%d: OMX_SetParameter() for video_encode port 201 failed with %x!\n",
__FUNCTION__, __LINE__, r);
exit(1);
}
OMX_VIDEO_PARAM_BITRATETYPE bitrateType;
// set current bitrate to 1Mbit
memset(&bitrateType, 0, sizeof(OMX_VIDEO_PARAM_BITRATETYPE));
bitrateType.nSize = sizeof(OMX_VIDEO_PARAM_BITRATETYPE);
bitrateType.nVersion.nVersion = OMX_VERSION;
bitrateType.eControlRate = OMX_Video_ControlRateVariable;
bitrateType.nTargetBitrate = 1000000;
bitrateType.nPortIndex = 201;
r = OMX_SetParameter(ILC_GET_HANDLE(video_encode),
OMX_IndexParamVideoBitrate, &bitrateType);
if (r != OMX_ErrorNone) {
printf("%s:%d: OMX_SetParameter() for bitrate for video_encode port 201 failed with %x!\n",
__FUNCTION__, __LINE__, r);
exit(1);
}
// get current bitrate
memset(&bitrateType, 0, sizeof(OMX_VIDEO_PARAM_BITRATETYPE));
bitrateType.nSize = sizeof(OMX_VIDEO_PARAM_BITRATETYPE);
bitrateType.nVersion.nVersion = OMX_VERSION;
bitrateType.nPortIndex = 201;
if (OMX_GetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamVideoBitrate,
&bitrateType) != OMX_ErrorNone) {
printf("%s:%d: OMX_GetParameter() for video_encode for bitrate port 201 failed!\n",
__FUNCTION__, __LINE__);
exit(1);
}
printf("Current Bitrate=%u\n",bitrateType.nTargetBitrate);
printf("encode to idle...\n");
if (ilclient_change_component_state(video_encode, OMX_StateIdle) == -1) {
printf("%s:%d: ilclient_change_component_state(video_encode, OMX_StateIdle) failed",
__FUNCTION__, __LINE__);
}
printf("enabling port buffers for 200...\n");
if (ilclient_enable_port_buffers(video_encode, 200, NULL, NULL, NULL) != 0) {
printf("enabling port buffers for 200 failed!\n");
exit(1);
}
printf("enabling port buffers for 201...\n");
if (ilclient_enable_port_buffers(video_encode, 201, NULL, NULL, NULL) != 0) {
printf("enabling port buffers for 201 failed!\n");
exit(1);
}
printf("encode to executing...\n");
ilclient_change_component_state(video_encode, OMX_StateExecuting);
outf = fopen(outputfilename, "w");
if (outf == NULL) {
printf("Failed to open '%s' for writing video\n", outputfilename);
exit(1);
}
printf("looping for buffers...\n");
do {
buf = ilclient_get_input_buffer(video_encode, 200, 1);
if (buf == NULL) {
printf("Doh, no buffers for me!\n");
}
else {
/* fill it */
generate_test_card(buf->pBuffer, &buf->nFilledLen, framenumber++);
if (OMX_EmptyThisBuffer(ILC_GET_HANDLE(video_encode), buf) !=
OMX_ErrorNone) {
printf("Error emptying buffer!\n");
}
out = ilclient_get_output_buffer(video_encode, 201, 1);
r = OMX_FillThisBuffer(ILC_GET_HANDLE(video_encode), out);
if (r != OMX_ErrorNone) {
printf("Error filling buffer: %x\n", r);
}
if (out != NULL) {
if (out->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
int i;
for (i = 0; i < out->nFilledLen; i++)
printf("%x ", out->pBuffer[i]);
printf("\n");
}
r = fwrite(out->pBuffer, 1, out->nFilledLen, outf);
if (r != out->nFilledLen) {
printf("fwrite: Error emptying buffer: %d!\n", r);
}
else {
printf("Writing frame %d/%d\n", framenumber, NUMFRAMES);
}
out->nFilledLen = 0;
}
else {
printf("Not getting it :(\n");
}
}
}
while (framenumber < NUMFRAMES);
fclose(outf);
printf("Teardown.\n");
printf("disabling port buffers for 200 and 201...\n");
ilclient_disable_port_buffers(video_encode, 200, NULL, NULL, NULL);
ilclient_disable_port_buffers(video_encode, 201, NULL, NULL, NULL);
ilclient_state_transition(list, OMX_StateIdle);
ilclient_state_transition(list, OMX_StateLoaded);
ilclient_cleanup_components(list);
OMX_Deinit();
ilclient_destroy(client);
return status;
}
extern OMX_BUFFERHEADERTYPE *
capture_frame(OMX_BUFFERHEADERTYPE *buf_list);
#define OMX_ERR_EXIT(fmt_str) {\
fprintf(stderr, fmt_str, __FUNCTION__, __LINE__, r);\
exit(1);\
}
#define ILC_ERR_EXIT(fmt_str) {\
fprintf(stderr, fmt_str, __FUNCTION__, __LINE__, r_il);\
exit(1);\
}
#define INIT_OMX_TYPE_NO_PORT(var, type) memset(&(var), 0, sizeof(type));\
(var).nSize = sizeof(type);\
(var).nVersion.nVersion = OMX_VERSION;
#define INIT_OMX_TYPE(var, type, port) INIT_OMX_TYPE_NO_PORT(var, type)\
(var).nPortIndex = (port);
#define INIT_OMX_TYPE_PTR(var_ptr, type, port) memset((var_ptr), 0, sizeof(type));\
(var_ptr)->nSize = sizeof(type);\
(var_ptr)->nVersion.nVersion = OMX_VERSION;\
(var_ptr)->nPortIndex = (port);
int
capture_encode_loop(int frames, OMX_U32 frameWidth, OMX_U32 frameHeight, uint frameRate, OMX_COLOR_FORMATTYPE colorFormat, unsigned int bufsize) {
OMX_VIDEO_PARAM_PORTFORMATTYPE format;
OMX_PARAM_PORTDEFINITIONTYPE def;
COMPONENT_T *video_encode = NULL;
COMPONENT_T *list[5];
OMX_BUFFERHEADERTYPE *buf;
OMX_BUFFERHEADERTYPE *out;
OMX_ERRORTYPE r;
int r_il = 0;
ILCLIENT_T *client;
int status = 0;
int framenumber = 0;
memset(list, 0, sizeof(list));
if ((client = ilclient_init()) == NULL) {
fprintf(stderr, "ilclient_init() for video_encode failed!\n");
return -3;
}
if ((r = OMX_Init()) != OMX_ErrorNone) {
ilclient_destroy(client);
fprintf(stderr, "OMX_Init() for video_encode failed with %x!\n", r);
return -4;
}
// create video_encode
if ((r_il = ilclient_create_component(client, &video_encode, "video_encode",
ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS | ILCLIENT_ENABLE_OUTPUT_BUFFERS)) != 0)
ILC_ERR_EXIT("%s:%d: ilclient_create_component() for video_encode failed (%d)!\n")
list[0] = video_encode;
// get current settings of video_encode component from port 200
INIT_OMX_TYPE(def, OMX_PARAM_PORTDEFINITIONTYPE, 200)
if ((r = OMX_GetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamPortDefinition, &def)) != OMX_ErrorNone)
OMX_ERR_EXIT("%s:%d: OMX_GetParameter() for video_encode port 200 failed with %x!\n")
print_def(&def, stderr);
// Port 200: in 1/1 115200 16 enabled,not pop.,not cont. 320x240 320x240 @1966080 20
def.nBufferSize = bufsize;
def.format.video.nFrameWidth = frameWidth;
def.format.video.nFrameHeight = frameHeight;
def.format.video.xFramerate = frameRate << 16; // 30 << 16;
def.format.video.nSliceHeight = def.format.video.nFrameHeight;
def.format.video.nStride = def.format.video.nFrameWidth;
def.format.video.eColorFormat = colorFormat; // OMX_COLOR_FormatYUV420PackedPlanar;
print_def(&def, stderr);
if ((r = OMX_SetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamPortDefinition, &def)) != OMX_ErrorNone)
OMX_ERR_EXIT("%s:%d: OMX_SetParameter() for video_encode port 200 failed with %x!\n")
INIT_OMX_TYPE(format, OMX_VIDEO_PARAM_PORTFORMATTYPE, 201)
format.eCompressionFormat = OMX_VIDEO_CodingAVC; // OMX_VIDEO_CodingMPEG4 fails, see https://github.com/raspberrypi/firmware/issues/162
fprintf(stderr, "OMX_SetParameter for video_encode:201...\n");
if ((r = OMX_SetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamVideoPortFormat, &format)) != OMX_ErrorNone)
OMX_ERR_EXIT("%s:%d: OMX_SetParameter() for format for video_encode port 201 failed with %x!\n")
OMX_VIDEO_PARAM_BITRATETYPE bitrateType;
// set current bitrate to 1Mbit
INIT_OMX_TYPE(bitrateType, OMX_VIDEO_PARAM_BITRATETYPE, 201)
bitrateType.eControlRate = OMX_Video_ControlRateVariable;
bitrateType.nTargetBitrate = 1000000;
if ((r = OMX_SetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamVideoBitrate, &bitrateType)) != OMX_ErrorNone)
OMX_ERR_EXIT("%s:%d: OMX_SetParameter() for bitrate for video_encode port 201 failed with %x!\n")
// get current bitrate
INIT_OMX_TYPE(bitrateType, OMX_VIDEO_PARAM_BITRATETYPE, 201)
if ((r = OMX_GetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamVideoBitrate, &bitrateType)) != OMX_ErrorNone)
OMX_ERR_EXIT("%s:%d: OMX_GetParameter() for bitrate for video_encode port 201 failed with %x!\n")
fprintf(stderr, "Current Bitrate=%u\n",bitrateType.nTargetBitrate);
fprintf(stderr, "encode to idle...\n");
if (ilclient_change_component_state(video_encode, OMX_StateIdle) == -1)
fprintf(stderr, "%s:%d: ilclient_change_component_state(video_encode, OMX_StateIdle) failed", __FUNCTION__, __LINE__);
fprintf(stderr, "enabling port buffers for 200...\n");
if ((r_il = ilclient_enable_port_buffers(video_encode, 200, NULL, NULL, NULL)) != 0)
ILC_ERR_EXIT("%s:%d: enabling port buffers for 200 failed (%d)!\n")
fprintf(stderr, "enabling port buffers for 201...\n");
if ((r_il = ilclient_enable_port_buffers(video_encode, 201, NULL, NULL, NULL)) != 0)
ILC_ERR_EXIT("%s:%d: enabling port buffers for 201 failed (%d)!\n")
fprintf(stderr, "encode to executing...\n");
ilclient_change_component_state(video_encode, OMX_StateExecuting);
fprintf(stderr, "looping for buffers...\n");
do {
buf = ilclient_get_input_buffer(video_encode, 200, 1);
if (buf == NULL) {
fprintf(stderr, "Doh, no buffers for me!\n");
}
else {
/* fill it */
//generate_test_card(buf->pBuffer, &buf->nFilledLen, framenumber++);
capture_frame(buf);
framenumber++;
if ((r = OMX_EmptyThisBuffer(ILC_GET_HANDLE(video_encode), buf)) != OMX_ErrorNone)
fprintf(stderr, "Error emptying buffer: %x\n", r);
out = ilclient_get_output_buffer(video_encode, 201, 1);
if ((r = OMX_FillThisBuffer(ILC_GET_HANDLE(video_encode), out)) != OMX_ErrorNone)
fprintf(stderr, "Error filling buffer: %x\n", r);
if (out != NULL) {
if (out->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
int i;
for (i = 0; i < out->nFilledLen; i++)
fprintf(stderr, "%x ", out->pBuffer[i]);
fprintf(stderr, "\n");
}
size_t res = fwrite(out->pBuffer, 1, out->nFilledLen, stdout);
if (res != out->nFilledLen)
fprintf(stderr, "fwrite: Error emptying buffer: %d\n", res);
//else
// fprintf(stderr, "Writing frame %d/%d\n", framenumber, frames);
out->nFilledLen = 0;
}
else
fprintf(stderr, "Not getting it :(\n");
}
}
while (framenumber < frames);
fprintf(stderr, "Teardown.\n");
fprintf(stderr, "disabling port buffers for 200 and 201...\n");
ilclient_disable_port_buffers(video_encode, 200, NULL, NULL, NULL);
ilclient_disable_port_buffers(video_encode, 201, NULL, NULL, NULL);
ilclient_state_transition(list, OMX_StateIdle);
ilclient_state_transition(list, OMX_StateLoaded);
ilclient_cleanup_components(list);
OMX_Deinit();
ilclient_destroy(client);
return status;
}
static void
get_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portdef_ptr, COMPONENT_T *comp, OMX_U32 port, int image) {
INIT_OMX_TYPE_PTR(portdef_ptr, OMX_PARAM_PORTDEFINITIONTYPE, port)
OMX_GetParameter(ILC_GET_HANDLE(comp), OMX_IndexParamPortDefinition, portdef_ptr);
print_def_(portdef_ptr, stderr, image);
}
static void
set_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portdef_ptr, COMPONENT_T *comp, OMX_U32 port, int image) {
OMX_ERRORTYPE r = OMX_SetParameter(ILC_GET_HANDLE(comp), OMX_IndexParamPortDefinition, portdef_ptr);
vc_assert(r == OMX_ErrorNone);
get_portdef(portdef_ptr, comp, port, image);
}
static void
disable_port_buffers(COMPONENT_T *comp, OMX_U32 port) {
fprintf(stderr, "disabling port buffers for %d... ", port);
ilclient_disable_port_buffers(comp, port, NULL, NULL, NULL);
fprintf(stderr, "Done.\n");
}
//#define TUNNEL
//#define DEBUG
//#define INFO
#ifdef DEBUG
#define DEBUG_PRINT(x) fprintf(stderr, (x));
#define DEBUG_PRINT_1(x,y) fprintf(stderr, (x), (y));
#define DEBUG_PRINT_3(s,x,y,z) fprintf(stderr, (s), (x), (y), (z));
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINT_1(x,y)
#define DEBUG_PRINT_3(s,x,y,z)
#endif /* DEBUG */
#ifdef INFO
#define INFO_PRINT_2(x,y,z) fprintf(stderr, (x), (y), (z));
#else
#define INFO_PRINT_2(x,y,z)
#endif /* INFO */
static int
image_decode_init(COMPONENT_T *image_decode, uint bufsize) {
OMX_PARAM_PORTDEFINITIONTYPE portdef;
int r_il;
// get image_decode input port definition - port 320
get_portdef(&portdef, image_decode, 320, 1);
// set image_decode input buffer size and image format - port 320
if (portdef.nBufferSize < bufsize)
portdef.nBufferSize = bufsize;
//portdef.nBufferCountMin = portdef.nBufferCountActual = 1;
portdef.format.image.eCompressionFormat = OMX_IMAGE_CodingJPEG;
set_portdef(&portdef, image_decode, 320, 1);
int inputbuffernumber = portdef.nBufferCountActual;
// get image_decode output port definition - port 321
get_portdef(&portdef, image_decode, 321, 1);
// set image_decode output image format - port 321
portdef.format.image.eCompressionFormat = OMX_IMAGE_CodingAutoDetect;
set_portdef(&portdef, image_decode, 321, 1);
// create image_decode input buffers - port 320
if ((r_il = ilclient_enable_port_buffers(image_decode, 320, NULL, NULL, NULL)) != 0)
ILC_ERR_EXIT("%s:%d: enabling port buffers for 320 failed (%d)!\n")
// move image_decode to executing
fprintf(stderr, "move image_decode to executing\n");
ilclient_change_component_state(image_decode, OMX_StateExecuting);
return inputbuffernumber;
}
static void
video_encode_set_input_image_format(OMX_PARAM_PORTDEFINITIONTYPE *portdef_ptr, COMPONENT_T *video_encode, OMX_U32 frameWidth, OMX_U32 frameHeight, OMX_COLOR_FORMATTYPE colorFormat) {
// get current settings of video_encode component from port 200
get_portdef(portdef_ptr, video_encode, 200, VC_FALSE);
// set video_encode input image format - port 200
portdef_ptr->format.video.nFrameWidth = frameWidth;
portdef_ptr->format.video.nFrameHeight = frameHeight;
portdef_ptr->format.video.nSliceHeight = portdef_ptr->format.video.nFrameHeight;
portdef_ptr->format.video.nStride = portdef_ptr->format.video.nFrameWidth;
portdef_ptr->format.video.eColorFormat = colorFormat; // OMX_COLOR_FormatYUV420PackedPlanar;
set_portdef(portdef_ptr, video_encode, 200, VC_FALSE);
}
static void
write_media_set_input_video_format(OMX_PARAM_PORTDEFINITIONTYPE *portdef_ptr, COMPONENT_T *write_media, OMX_U32 frameWidth, OMX_U32 frameHeight, OMX_VIDEO_CODINGTYPE codingType) {
// get current settings of write_media component from port 171
get_portdef(portdef_ptr, write_media, 171, VC_FALSE);
// set write_media input video format - port 171
portdef_ptr->format.video.nFrameWidth = frameWidth;
portdef_ptr->format.video.nFrameHeight = frameHeight;
//portdef_ptr->format.video.nSliceHeight = portdef_ptr->format.video.nFrameHeight;
//portdef_ptr->format.video.nStride = portdef_ptr->format.video.nFrameWidth;
//portdef_ptr->format.video.eColorFormat = colorFormat; // OMX_COLOR_FormatYUV420PackedPlanar;
portdef_ptr->format.video.eCompressionFormat = codingType;
set_portdef(portdef_ptr, write_media, 171, VC_FALSE);
}
extern int
psips, bitrate, codec;
extern char *write_media_file;
static void
video_encode_init(COMPONENT_T *video_encode) {
OMX_VIDEO_PARAM_PORTFORMATTYPE format;
OMX_ERRORTYPE r;
//// get current settings of video_encode component from port 200
//get_portdef(&portdef, video_encode, 200, 0);
//// set video_encode input frame rate - port 200
//portdef.format.video.xFramerate = frameRate << 16; // 30 << 16;
//set_portdef(&portdef, video_encode, 200, 0);
// set video_encode codec to H.264
INIT_OMX_TYPE(format, OMX_VIDEO_PARAM_PORTFORMATTYPE, 201)
switch (codec) {
case 0: format.eCompressionFormat = OMX_VIDEO_CodingMPEG2; break; /**< AKA: H.262 */
case 1: format.eCompressionFormat = OMX_VIDEO_CodingH263; break; /**< H.263 */
case 2: format.eCompressionFormat = OMX_VIDEO_CodingMPEG4; break; /**< MPEG-4 */
case 3: format.eCompressionFormat = OMX_VIDEO_CodingWMV; break; /**< all versions of Windows Media Video */
case 4: format.eCompressionFormat = OMX_VIDEO_CodingRV; break; /**< all versions of Real Video */
case 5: format.eCompressionFormat = OMX_VIDEO_CodingAVC; break; /**< H.264/AVC */
case 6: format.eCompressionFormat = OMX_VIDEO_CodingMJPEG; break; /**< Motion JPEG */
case 7: format.eCompressionFormat = OMX_VIDEO_CodingVP6; break; /**< On2 VP6 */
case 8: format.eCompressionFormat = OMX_VIDEO_CodingVP7; break; /**< On2 VP7 */
case 9: format.eCompressionFormat = OMX_VIDEO_CodingVP8; break; /**< On2 VP8 */
case 10: format.eCompressionFormat = OMX_VIDEO_CodingYUV; break; /* raw YUV video */
case 11: format.eCompressionFormat = OMX_VIDEO_CodingSorenson; break; /**< Sorenson */
case 12: format.eCompressionFormat = OMX_VIDEO_CodingTheora; break; /**< Theora */
case 13: format.eCompressionFormat = OMX_VIDEO_CodingMVC; break; /**< H.264/MVC */
default: format.eCompressionFormat = OMX_VIDEO_CodingAVC; break; /**< H.264/AVC */
}
r = OMX_SetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamVideoPortFormat, &format);
vc_assert(r == OMX_ErrorNone);
OMX_VIDEO_PARAM_BITRATETYPE bitrateType;
if (bitrate) {
// set current bitrate to 1Mbit // 0 that means that the output will either use VBR, or no rate control at all
INIT_OMX_TYPE(bitrateType, OMX_VIDEO_PARAM_BITRATETYPE, 201)
bitrateType.eControlRate = OMX_Video_ControlRateVariable;
bitrateType.nTargetBitrate = bitrate; // 1000000; // 0;
r = OMX_SetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamVideoBitrate, &bitrateType);
vc_assert(r == OMX_ErrorNone);
}
// get current bitrate
INIT_OMX_TYPE(bitrateType, OMX_VIDEO_PARAM_BITRATETYPE, 201)
OMX_GetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamVideoBitrate, &bitrateType);
fprintf(stderr, "Current Bitrate=%u\n", bitrateType.nTargetBitrate);
// set psips
if (psips) {
OMX_CONFIG_PORTBOOLEANTYPE portBoolType;
INIT_OMX_TYPE(portBoolType, OMX_CONFIG_PORTBOOLEANTYPE, 201)
r = OMX_SetParameter(ILC_GET_HANDLE(video_encode), OMX_IndexParamBrcmVideoAVCInlineHeaderEnable, &portBoolType);
vc_assert(r == OMX_ErrorNone);
}
}
static COMPONENT_T *_comp[5];
static TUNNEL_T _tunnel[4];
static int _copybuffernumber;
static void
capture_encode_jpeg_error_callback(void *userdata, COMPONENT_T *comp, OMX_U32 error) {
INFO_PRINT_2("Error: 0x%X (%s)\n", error, comp == _tunnel->source ? "image_decode" : comp == _tunnel->sink ? "video_encode" : "write_media");
}
static void
capture_encode_jpeg_port_settings_callback(void *userdata, COMPONENT_T *comp, OMX_U32 port) {
DEBUG_PRINT_1("port settings changed event - port %d\n", port)
if (port == 321 && comp == /*image_decode*/_tunnel->source) {
int r_il;
OMX_PARAM_PORTDEFINITIONTYPE portdef;
// get image_decode output port definition - port 321
DEBUG_PRINT("get image_decode output port definition - port 321\n")
get_portdef(&portdef, comp, 321, VC_TRUE);
// set video_encode input image format - port 200
video_encode_set_input_image_format(&portdef, /*video_encode*/_tunnel->sink, portdef.format.image.nFrameWidth, portdef.format.image.nFrameHeight, portdef.format.image.eColorFormat);
video_encode_init(/*video_encode*/_tunnel->sink);
#ifdef TUNNEL
fprintf(stderr, "setup 321 -> 200 tunnel\n");
// setup tunnel
if ((r_il = ilclient_setup_tunnel(_tunnel, 0, 0)) != 0)
fprintf(stderr, "Error setting up tunnel: %d\n", r_il);
#else
// create image_decode output buffers - port 321
DEBUG_PRINT("create image_decode output buffers - port 321\n")
if ((r_il = ilclient_enable_port_buffers(comp, 321, NULL, NULL, NULL)) != 0)
ILC_ERR_EXIT("%s:%d: enabling port buffers for 321 failed (%d)!\n")
// create video_encode input buffers - port 200
DEBUG_PRINT("create video_encode input buffers - port 200\n")
if ((r_il = ilclient_enable_port_buffers(/*video_encode*/_tunnel->sink, 200, NULL, NULL, NULL)) != 0)
ILC_ERR_EXIT("%s:%d: enabling port buffers for 200 failed (%d)!\n")
// create video_encode output buffers - port 201
DEBUG_PRINT("create video_encode output buffers - port 201\n")
if ((r_il = ilclient_enable_port_buffers(/*video_encode*/_tunnel->sink, 201, NULL, NULL, NULL)) != 0)
ILC_ERR_EXIT("%s:%d: enabling port buffers for 201 failed (%d)!\n")
#endif /* TUNNEL */
if (write_media_file) {
get_portdef(&portdef, /*video_encode*/(_tunnel + 1)->source, 201, VC_FALSE);
write_media_set_input_video_format(&portdef, /*write_media*/(_tunnel + 1)->sink, portdef.format.video.nFrameWidth, portdef.format.video.nFrameHeight, portdef.format.video.eCompressionFormat);
OMX_ERRORTYPE r;
typedef struct _OMX_PARAM_CONTENTURITYPE
{
OMX_U32 nSize; /**< size of the structure in bytes, including actual URI name */
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U8 contentURI[500]; /**< The URI name */
} _OMX_PARAM_CONTENTURITYPE;
_OMX_PARAM_CONTENTURITYPE contentUri;
INIT_OMX_TYPE_NO_PORT(contentUri, _OMX_PARAM_CONTENTURITYPE)
strcpy((char *)contentUri.contentURI, write_media_file);
contentUri.nSize -= (500 - strlen(write_media_file));
if ((r = OMX_SetParameter(ILC_GET_HANDLE(/*write_media*/(_tunnel + 1)->sink), OMX_IndexParamContentURI, &contentUri)) != OMX_ErrorNone)
OMX_ERR_EXIT("%s:%d: OMX_SetParameter() for content URI for write_media failed with %x!\n")
#ifdef TUNNEL
fprintf(stderr, "setup 201 -> 171 tunnel\n");
// setup tunnel
if ((r_il = ilclient_setup_tunnel(_tunnel + 1, 0, 0)) != 0)
fprintf(stderr, "Error setting up tunnel: %d\n", r_il);
#else
// create write_media input buffers - port 171
DEBUG_PRINT("create write_media input buffers - port 171\n")
if ((r_il = ilclient_enable_port_buffers(/*write_media*/(_tunnel + 1)->sink, 171, NULL, NULL, NULL)) != 0)
ILC_ERR_EXIT("%s:%d: enabling port buffers for 171 failed (%d)!\n")
#endif /* TUNNEL */
}
// move all components except image_decode to executing
fprintf(stderr, "move video_encode %sto executing\n", write_media_file ? "and write_media " : "");
ilclient_state_transition(_comp + 1, OMX_StateExecuting);
}
}
static OMX_U8 *_swap;
static OMX_BUFFERHEADERTYPE *
tunnel_buffer(TUNNEL_T *tunnel, int *copybuffernumber, int block) {
#ifndef TUNNEL
OMX_ERRORTYPE r;
OMX_BUFFERHEADERTYPE *buf;
OMX_BUFFERHEADERTYPE *out;
DEBUG_PRINT_1("4. get %d out buffers from output component queue\n", tunnel->source_port)
while ((out = ilclient_get_output_buffer(tunnel->source, tunnel->source_port, block)) != NULL && out->nFilledLen == 0) {
DEBUG_PRINT_1("5. send empty %d out buffer to output component processor\n", tunnel->source_port)
if ((r = OMX_FillThisBuffer(ILC_GET_HANDLE(tunnel->source), out)) != OMX_ErrorNone)
fprintf(stderr, "Error filling %d out buffer: %x\n", tunnel->source_port, r);
}
if (out != NULL) {
DEBUG_PRINT_1("6. get %d in buffer from input component queue (blocking)\n", tunnel->sink_port)
buf = ilclient_get_input_buffer(tunnel->sink, tunnel->sink_port, VC_TRUE);
/* fill it */
//generate_test_card(buf->pBuffer, &buf->nFilledLen, framenumber++);
DEBUG_PRINT_3("7. copy buffer %d->%d (%d bytes)\n", tunnel->source_port, tunnel->sink_port, out->nFilledLen)
//memcpy(buf->pBuffer, out->pBuffer, out->nFilledLen);
_swap = buf->pBuffer;
buf->pBuffer = out->pBuffer;
out->pBuffer = _swap;
_swap = NULL;
buf->nFilledLen = out->nFilledLen;
out->nFilledLen = 0;
if (copybuffernumber) {
(*copybuffernumber)++;
INFO_PRINT_2("copied frame %d (%d bytes)\n", (*copybuffernumber), buf->nFilledLen)
}
DEBUG_PRINT_1("8. send emptied %d out buffer to output component processor\n", tunnel->source_port)
if ((r = OMX_FillThisBuffer(ILC_GET_HANDLE(tunnel->source), out)) != OMX_ErrorNone)
fprintf(stderr, "Error filling %d out buffer: %x\n", tunnel->source_port, r);
DEBUG_PRINT_1("9. send filled %d in buffer to input component processor\n", tunnel->sink_port)
if ((r = OMX_EmptyThisBuffer(ILC_GET_HANDLE(tunnel->sink), buf)) != OMX_ErrorNone)
fprintf(stderr, "Error emptying %d in buffer: %x!\n", tunnel->sink_port, r);
}
return out;
#else
OMX_ERRORTYPE r;
OMX_BUFFERHEADERTYPE *buf;
OMX_BUFFERHEADERTYPE *out;
DEBUG_PRINT_1("4. get %d out buffers from output component queue\n", tunnel->source_port)
while ((out = ilclient_get_output_buffer(, tunnel->source, , tunnel->source_port, block)) != NULL) {
DEBUG_PRINT_1("5. send %d out buffer to output component processor\n", tunnel->source_port)
if ((r = OMX_FillThisBuffer(ILC_GET_HANDLE(tunnel->source), out)) != OMX_ErrorNone)
fprintf(stderr, "Error filling %d out buffer: %x\n", tunnel->source_port, r);
}
DEBUG_PRINT_1("6. get %d in buffers from input component queue\n", tunnel->sink_port)
while ((buf = ilclient_get_input_buffer(tunnel->sink, tunnel->sink_port, block)) != NULL) {
DEBUG_PRINT_1("7. send %d in buffer to input component processor\n", tunnel->sink_port)
if ((r = OMX_EmptyThisBuffer(ILC_GET_HANDLE(tunnel->sink), buf)) != OMX_ErrorNone)
fprintf(stderr, "Error emptying %d in buffer: %x!\n", tunnel->sink_port, r);
}
return NULL;
#endif /* TUNNEL */
}
static void
wait_tunnel_buffer(TUNNEL_T *tunnel, int *copybuffernumber) {
while (tunnel_buffer(tunnel, copybuffernumber, VC_FALSE) != NULL)
wait_timeout(0, 5);
}
static void
capture_encode_jpeg_fill_buffer_done_callback(void *data, COMPONENT_T *comp) {
if (comp == /*image_decode*/_tunnel->source)
tunnel_buffer(_tunnel, &_copybuffernumber, VC_FALSE);
else if (write_media_file && comp == /*video_encode*/(_tunnel + 1)->source)
tunnel_buffer(_tunnel + 1, NULL, VC_FALSE);
}
static uint
buffer_list_count(OMX_BUFFERHEADERTYPE *list)
{
uint cnt = 0;
while (list) {
cnt++;
list = list->pAppPrivate;
}
return cnt;
}
static OMX_BUFFERHEADERTYPE *
buffer_list_get_buf_remove(OMX_BUFFERHEADERTYPE **list, OMX_BUFFERHEADERTYPE *buf) {
/* take the buf buffer out of the list */
if (list != NULL && *list != NULL) {
if (buf == *list) {
*list = buf->pAppPrivate;
buf->pAppPrivate = NULL;
return buf;
}
else {
OMX_BUFFERHEADERTYPE *ptr = *list;
while (ptr != NULL && ptr->pAppPrivate != buf)
ptr = ptr->pAppPrivate;
if (ptr != NULL) {
ptr->pAppPrivate = buf->pAppPrivate;
buf->pAppPrivate = NULL;
return buf;
}
}
}
return NULL;
}
static int
get_input_buffers(COMPONENT_T *image_decode, OMX_U32 port, int block, int buffernumber, OMX_BUFFERHEADERTYPE **list) {
OMX_BUFFERHEADERTYPE *buf;
int cnt = buffer_list_count(*list);
while (cnt < buffernumber && (buf = ilclient_get_input_buffer(image_decode, port, block)) != NULL) {
buf->pAppPrivate = *list;
*list = buf;
cnt++;
}
return cnt;
}
static void
wait_for_StateExecuting(COMPONENT_T *comp) {
// check component is in the right state to accept buffers
OMX_STATETYPE state;
while (OMX_GetState(ILC_GET_HANDLE(comp), &state) != OMX_ErrorNone || state != OMX_StateExecuting)
wait_timeout(0, 5);
}
extern void
close_device(void),
open_device(void),
uninit_device(int external_buffers),
init_buffers(unsigned int buffer_size, OMX_BUFFERHEADERTYPE *external_buffers),
stop_capturing(void),
start_capturing(void);
extern unsigned int
init_device(void);
static ILCLIENT_T *_client;
static OMX_U32 _port[5][2][3];
static OMX_BUFFERHEADERTYPE *_inputbufferlist;
static int _framenumber, _outframenumber;
static int _torndown;
static void
release_input_buffers(void) {
OMX_BUFFERHEADERTYPE *buf;
OMX_ERRORTYPE r;
// release empty port 320 input buffers back to image_decode processor
DEBUG_PRINT("release empty port 320 input buffers back to image_decode processor\n")
while (_inputbufferlist) {
/* take a buffer out of inputbufferlist */
buf = buffer_list_get_buf_remove(&_inputbufferlist, _inputbufferlist);
DEBUG_PRINT_1("buffer 0x%x ", (unsigned int)buf)
/* release it */
if ((r = OMX_EmptyThisBuffer(ILC_GET_HANDLE(_comp[0]), buf)) != OMX_ErrorNone)
fprintf(stderr, "Error emptying buffer: %x\n", r);
DEBUG_PRINT("released\n")
}
}
static void
capture_encode_jpeg_teardown(void) {
if (_torndown) {
fprintf(stderr, "Torn down.\n");
return;
}
stop_capturing();
uninit_device(1);
close_device();
fprintf(stderr, "\r \ninput frames: %d\ncopied frames: %d\noutput frames: %d\n\n", _framenumber, _copybuffernumber, _outframenumber);
fprintf(stderr, "Teardown.\n");
// remove callback functions
ilclient_set_fill_buffer_done_callback(_client, NULL, NULL);
ilclient_set_port_settings_callback(_client, NULL, NULL);
ilclient_set_error_callback(_client, NULL, NULL);
// release empty port 320 input buffers back to image_decode processor
release_input_buffers();
for (int i_comp = 0; i_comp < 5 && _comp[i_comp]; i_comp++)
for (int i_port_inout = 0; i_port_inout < 2; i_port_inout++)
for (int i_port = 0; i_port < 3 && _port[i_comp][i_port_inout][i_port]; i_port++)
disable_port_buffers(_comp[i_comp], _port[i_comp][i_port_inout][i_port]);
#ifdef TUNNEL
ilclient_disable_tunnel(_tunnel);
ilclient_teardown_tunnels(_tunnel);
#endif /* TUNNEL */
ilclient_state_transition(_comp, OMX_StateIdle);
ilclient_state_transition(_comp, OMX_StateLoaded);
ilclient_cleanup_components(_comp);
if (_swap)
free(_swap);
OMX_Deinit();
ilclient_destroy(_client);
bcm_host_deinit();
_torndown = 1;
}
static void
intHandler(int dummy) { exit(0); }
int
capture_encode_jpeg_loop(int frames/*, OMX_U32 frameWidth, OMX_U32 frameHeight, uint frameRate, OMX_COLOR_FORMATTYPE colorFormat, uint bufsize*/) {
COMPONENT_T *video_encode = NULL, *image_decode = NULL;