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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
|
/* Copyright (c) 2012-2015, The Linux Foundataion. 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 Linux Foundation 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 "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
*
*/
#define LOG_TAG "QCameraChannel"
#include <utils/Errors.h>
#include "QCameraParameters.h"
#include "QCamera2HWI.h"
#include "QCameraChannel.h"
using namespace android;
namespace qcamera {
/*===========================================================================
* FUNCTION : QCameraChannel
*
* DESCRIPTION: constrcutor of QCameraChannel
*
* PARAMETERS :
* @cam_handle : camera handle
* @cam_ops : ptr to camera ops table
*
* RETURN : none
*==========================================================================*/
QCameraChannel::QCameraChannel(uint32_t cam_handle,
mm_camera_ops_t *cam_ops)
{
m_camHandle = cam_handle;
m_camOps = cam_ops;
m_bIsActive = false;
m_bAllowDynBufAlloc = false;
m_handle = 0;
}
/*===========================================================================
* FUNCTION : QCameraChannel
*
* DESCRIPTION: default constrcutor of QCameraChannel
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCameraChannel::QCameraChannel()
{
m_camHandle = 0;
m_camOps = NULL;
m_bIsActive = false;
m_handle = 0;
}
/*===========================================================================
* FUNCTION : ~QCameraChannel
*
* DESCRIPTION: destructor of QCameraChannel
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCameraChannel::~QCameraChannel()
{
if (m_bIsActive) {
stop();
}
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL) {
if (m_handle == mStreams[i]->getChannelHandle()) {
delete mStreams[i];
}
}
}
mStreams.clear();
m_camOps->delete_channel(m_camHandle, m_handle);
m_handle = 0;
}
/*===========================================================================
* FUNCTION : deleteChannel
*
* DESCRIPTION: deletes a camera channel
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
void QCameraChannel::deleteChannel()
{
if (m_bIsActive) {
stop();
}
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL) {
if (m_handle == mStreams[i]->getChannelHandle()) {
mStreams[i]->deleteStream();
}
}
}
m_camOps->delete_channel(m_camHandle, m_handle);
}
/*===========================================================================
* FUNCTION : init
*
* DESCRIPTION: initialization of channel
*
* PARAMETERS :
* @attr : channel bundle attribute setting
* @dataCB : data notify callback
* @userData: user data ptr
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraChannel::init(mm_camera_channel_attr_t *attr,
mm_camera_buf_notify_t dataCB,
void *userData)
{
m_handle = m_camOps->add_channel(m_camHandle,
attr,
dataCB,
userData);
if (m_handle == 0) {
ALOGE("%s: Add channel failed", __func__);
return UNKNOWN_ERROR;
}
return NO_ERROR;
}
/*===========================================================================
* FUNCTION : addStream
*
* DESCRIPTION: add a stream into channel
*
* PARAMETERS :
* @allocator : stream related buffer allocator
* @streamInfoBuf : ptr to buf that constains stream info
* @minStreamBufNum: number of stream buffers needed
* @paddingInfo : padding information
* @stream_cb : stream data notify callback
* @userdata : user data ptr
* @bDynAllocBuf : flag indicating if allow allocate buffers in 2 steps
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraChannel::addStream(QCameraAllocator &allocator,
QCameraHeapMemory *streamInfoBuf,
uint8_t minStreamBufNum,
cam_padding_info_t *paddingInfo,
stream_cb_routine stream_cb,
void *userdata,
bool bDynAllocBuf,
bool bDeffAlloc)
{
int32_t rc = NO_ERROR;
if (mStreams.size() >= MAX_STREAM_NUM_IN_BUNDLE) {
ALOGE("%s: stream number (%d) exceeds max limit (%d)",
__func__, mStreams.size(), MAX_STREAM_NUM_IN_BUNDLE);
return BAD_VALUE;
}
QCameraStream *pStream = new QCameraStream(allocator,
m_camHandle,
m_handle,
m_camOps,
paddingInfo,
bDeffAlloc);
if (pStream == NULL) {
ALOGE("%s: No mem for Stream", __func__);
return NO_MEMORY;
}
rc = pStream->init(streamInfoBuf, minStreamBufNum,
stream_cb, userdata, bDynAllocBuf);
if (rc == 0) {
mStreams.add(pStream);
} else {
delete pStream;
}
return rc;
}
/*===========================================================================
* FUNCTION : config
*
* DESCRIPTION: Configure any deffered channel streams
*
* PARAMETERS : None
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraChannel::config()
{
int32_t rc = NO_ERROR;
for (size_t i = 0; i < mStreams.size(); ++i) {
if ((mStreams[i] != NULL) &&
mStreams[i]->isDeffered() &&
(m_handle == mStreams[i]->getChannelHandle())) {
rc = mStreams[i]->configStream();
if (rc != NO_ERROR) {
break;
}
}
}
return rc;
}
/*===========================================================================
* FUNCTION : linkStream
*
* DESCRIPTION: link a stream into channel
*
* PARAMETERS :
* @ch : Channel which the stream belongs to
* @stream : Stream which needs to be linked
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraChannel::linkStream(QCameraChannel *ch, QCameraStream *stream)
{
int32_t rc = NO_ERROR;
if ((0 == m_handle) || (NULL == ch) || (NULL == stream)) {
return NO_INIT;
}
int32_t handle = m_camOps->link_stream(m_camHandle,
ch->getMyHandle(),
stream->getMyHandle(),
m_handle);
if (0 == handle) {
ALOGE("%s : Linking of stream failed", __func__);
rc = INVALID_OPERATION;
} else {
mStreams.add(stream);
}
return rc;
}
/*===========================================================================
* FUNCTION : start
*
* DESCRIPTION: start channel, which will start all streams belong to this channel
*
* PARAMETERS : None
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraChannel::start()
{
int32_t rc = NO_ERROR;
if (mStreams.size() > 1) {
// there is more than one stream in the channel
// we need to notify mctl that all streams in this channel need to be bundled
cam_bundle_config_t bundleInfo;
memset(&bundleInfo, 0, sizeof(bundleInfo));
rc = m_camOps->get_bundle_info(m_camHandle, m_handle, &bundleInfo);
if (rc != NO_ERROR) {
ALOGE("%s: get_bundle_info failed", __func__);
return rc;
}
if (bundleInfo.num_of_streams > 1) {
for (int i = 0; i < bundleInfo.num_of_streams; i++) {
QCameraStream *pStream = getStreamByServerID(bundleInfo.stream_ids[i]);
if (pStream != NULL) {
if (pStream->isTypeOf(CAM_STREAM_TYPE_METADATA)) {
// Skip metadata for reprocess now because PP module cannot handle meta data
// May need furthur discussion if Imaginglib need meta data
continue;
}
cam_stream_parm_buffer_t param;
memset(¶m, 0, sizeof(cam_stream_parm_buffer_t));
param.type = CAM_STREAM_PARAM_TYPE_SET_BUNDLE_INFO;
param.bundleInfo = bundleInfo;
rc = pStream->setParameter(param);
if (rc != NO_ERROR) {
ALOGE("%s: stream setParameter for set bundle failed", __func__);
return rc;
}
}
}
}
}
for (size_t i = 0; i < mStreams.size(); i++) {
if ((mStreams[i] != NULL) &&
(m_handle == mStreams[i]->getChannelHandle())) {
mStreams[i]->start();
}
}
rc = m_camOps->start_channel(m_camHandle, m_handle);
if (rc != NO_ERROR) {
for (size_t i = 0; i < mStreams.size(); i++) {
if ((mStreams[i] != NULL) &&
(m_handle == mStreams[i]->getChannelHandle())) {
mStreams[i]->stop();
}
}
} else {
m_bIsActive = true;
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL) {
mStreams[i]->cond_signal();
}
}
}
return rc;
}
/*===========================================================================
* FUNCTION : stop
*
* DESCRIPTION: stop a channel, which will stop all streams belong to this channel
*
* PARAMETERS : none
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraChannel::stop()
{
int32_t rc = NO_ERROR;
ssize_t linkedIdx = -1;
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL) {
if (m_handle == mStreams[i]->getChannelHandle()) {
mStreams[i]->stop();
} else {
// Remove linked stream from stream list
linkedIdx = (ssize_t)i;
}
}
}
if (linkedIdx > 0) {
mStreams.removeAt((size_t)linkedIdx);
}
rc = m_camOps->stop_channel(m_camHandle, m_handle);
m_bIsActive = false;
return rc;
}
/*===========================================================================
* FUNCTION : bufDone
*
* DESCRIPTION: return a stream buf back to kernel
*
* PARAMETERS :
* @recvd_frame : stream buf frame to be returned
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraChannel::bufDone(mm_camera_super_buf_t *recvd_frame)
{
int32_t rc = NO_ERROR;
for (uint32_t i = 0; i < recvd_frame->num_bufs; i++) {
if (recvd_frame->bufs[i] != NULL) {
for (size_t j = 0; j < mStreams.size(); j++) {
if (mStreams[j] != NULL &&
mStreams[j]->getMyHandle() == recvd_frame->bufs[i]->stream_id) {
rc = mStreams[j]->bufDone(recvd_frame->bufs[i]->buf_idx);
break; // break loop j
}
}
}
}
return rc;
}
/*===========================================================================
* FUNCTION : processZoomDone
*
* DESCRIPTION: process zoom done event
*
* PARAMETERS :
* @previewWindoe : ptr to preview window ops table, needed to set preview
* crop information
* @crop_info : crop info as a result of zoom operation
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraChannel::processZoomDone(preview_stream_ops_t *previewWindow,
cam_crop_data_t &crop_info)
{
int32_t rc = NO_ERROR;
for (size_t i = 0; i < mStreams.size(); i++) {
if ((mStreams[i] != NULL) &&
(m_handle == mStreams[i]->getChannelHandle())) {
rc = mStreams[i]->processZoomDone(previewWindow, crop_info);
}
}
return rc;
}
/*===========================================================================
* FUNCTION : getStreamByHandle
*
* DESCRIPTION: return stream object by stream handle
*
* PARAMETERS :
* @streamHandle : stream handle
*
* RETURN : stream object. NULL if not found
*==========================================================================*/
QCameraStream *QCameraChannel::getStreamByHandle(uint32_t streamHandle)
{
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL && mStreams[i]->getMyHandle() == streamHandle) {
return mStreams[i];
}
}
return NULL;
}
/*===========================================================================
* FUNCTION : getStreamByServerID
*
* DESCRIPTION: return stream object by stream server ID from daemon
*
* PARAMETERS :
* @serverID : stream server ID
*
* RETURN : stream object. NULL if not found
*==========================================================================*/
QCameraStream *QCameraChannel::getStreamByServerID(uint32_t serverID)
{
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL && mStreams[i]->getMyServerID() == serverID) {
return mStreams[i];
}
}
return NULL;
}
/*===========================================================================
* FUNCTION : getStreamByIndex
*
* DESCRIPTION: return stream object by index of streams in the channel
*
* PARAMETERS :
* @index : index of stream in the channel
*
* RETURN : stream object. NULL if not found
*==========================================================================*/
QCameraStream *QCameraChannel::getStreamByIndex(uint32_t index)
{
if (index >= MAX_STREAM_NUM_IN_BUNDLE) {
return NULL;
}
if (index < mStreams.size()) {
return mStreams[index];
}
return NULL;
}
/*===========================================================================
* FUNCTION : UpdateStreamBasedParameters
*
* DESCRIPTION: update any stream based settings from parameters
*
* PARAMETERS :
* @param : reference to parameters object
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraChannel::UpdateStreamBasedParameters(QCameraParameters ¶m)
{
int32_t rc = NO_ERROR;
if (param.isPreviewFlipChanged()) {
// try to find preview stream
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL &&
(m_handle == mStreams[i]->getChannelHandle()) &&
(mStreams[i]->isTypeOf(CAM_STREAM_TYPE_PREVIEW) ||
(mStreams[i]->isOrignalTypeOf(CAM_STREAM_TYPE_PREVIEW))) ) {
cam_stream_parm_buffer_t param_buf;
memset(¶m_buf, 0, sizeof(cam_stream_parm_buffer_t));
param_buf.type = CAM_STREAM_PARAM_TYPE_SET_FLIP;
param_buf.flipInfo.flip_mask =
(uint32_t)param.getFlipMode(CAM_STREAM_TYPE_PREVIEW);
rc = mStreams[i]->setParameter(param_buf);
if (rc != NO_ERROR) {
ALOGE("%s: set preview stream flip failed", __func__);
}
}
}
}
if (param.isVideoFlipChanged()) {
// try to find video stream
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL &&
(m_handle == mStreams[i]->getChannelHandle()) &&
(mStreams[i]->isTypeOf(CAM_STREAM_TYPE_VIDEO) ||
(mStreams[i]->isOrignalTypeOf(CAM_STREAM_TYPE_VIDEO))) ) {
cam_stream_parm_buffer_t param_buf;
memset(¶m_buf, 0, sizeof(cam_stream_parm_buffer_t));
param_buf.type = CAM_STREAM_PARAM_TYPE_SET_FLIP;
param_buf.flipInfo.flip_mask =
(uint32_t)param.getFlipMode(CAM_STREAM_TYPE_VIDEO);
rc = mStreams[i]->setParameter(param_buf);
if (rc != NO_ERROR) {
ALOGE("%s: set video stream flip failed", __func__);
}
}
}
}
if (param.isSnapshotFlipChanged()) {
// try to find snapshot/postview stream
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL &&
(m_handle == mStreams[i]->getChannelHandle()) &&
(mStreams[i]->isTypeOf(CAM_STREAM_TYPE_SNAPSHOT) ||
mStreams[i]->isOrignalTypeOf(CAM_STREAM_TYPE_SNAPSHOT) ||
mStreams[i]->isTypeOf(CAM_STREAM_TYPE_POSTVIEW) ||
mStreams[i]->isOrignalTypeOf(CAM_STREAM_TYPE_POSTVIEW) ) ) {
cam_stream_parm_buffer_t param_buf;
memset(¶m_buf, 0, sizeof(cam_stream_parm_buffer_t));
param_buf.type = CAM_STREAM_PARAM_TYPE_SET_FLIP;
param_buf.flipInfo.flip_mask =
(uint32_t)param.getFlipMode(CAM_STREAM_TYPE_SNAPSHOT);
rc = mStreams[i]->setParameter(param_buf);
if (rc != NO_ERROR) {
ALOGE("%s: set snapshot stream flip failed", __func__);
}
}
}
}
return rc;
}
/*===========================================================================
* FUNCTION : QCameraPicChannel
*
* DESCRIPTION: constructor of QCameraPicChannel
*
* PARAMETERS :
* @cam_handle : camera handle
* @cam_ops : ptr to camera ops table
*
* RETURN : none
*==========================================================================*/
QCameraPicChannel::QCameraPicChannel(uint32_t cam_handle,
mm_camera_ops_t *cam_ops) :
QCameraChannel(cam_handle, cam_ops)
{
m_bAllowDynBufAlloc = true;
}
/*===========================================================================
* FUNCTION : QCameraPicChannel
*
* DESCRIPTION: default constructor of QCameraPicChannel
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCameraPicChannel::QCameraPicChannel()
{
m_bAllowDynBufAlloc = true;
}
/*===========================================================================
* FUNCTION : ~QCameraPicChannel
*
* DESCRIPTION: destructor of QCameraPicChannel
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCameraPicChannel::~QCameraPicChannel()
{
}
/*===========================================================================
* FUNCTION : takePicture
*
* DESCRIPTION: send request for queued snapshot frames
*
* PARAMETERS :
* @num_of_snapshot : number of snapshot frames requested
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraPicChannel::takePicture(uint8_t num_of_snapshot)
{
int32_t rc = m_camOps->request_super_buf(m_camHandle,
m_handle,
num_of_snapshot);
return rc;
}
/*===========================================================================
* FUNCTION : cancelPicture
*
* DESCRIPTION: cancel request for queued snapshot frames
*
* PARAMETERS : none
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraPicChannel::cancelPicture()
{
int32_t rc = m_camOps->cancel_super_buf_request(m_camHandle, m_handle);
return rc;
}
/*===========================================================================
* FUNCTION : stopAdvancedCapture
*
* DESCRIPTION: stop advanced capture based on advanced capture type.
*
* PARAMETERS :
* @type : advanced capture type.
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraPicChannel::stopAdvancedCapture(mm_camera_advanced_capture_t type)
{
int32_t rc = m_camOps->process_advanced_capture(m_camHandle, type,
m_handle, 0);
return rc;
}
/*===========================================================================
* FUNCTION : startAdvancedCapture
*
* DESCRIPTION: start advanced capture based on advanced capture type.
*
* PARAMETERS :
* @type : advanced capture type.
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraPicChannel::startAdvancedCapture(mm_camera_advanced_capture_t type)
{
int32_t rc = m_camOps->process_advanced_capture(m_camHandle, type,
m_handle, 1);
return rc;
}
/*===========================================================================
* FUNCTION : flushSuperbuffer
*
* DESCRIPTION: flush the all superbuffer frames.
*
* PARAMETERS :
* @frame_idx : .
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraPicChannel::flushSuperbuffer(uint32_t frame_idx)
{
int32_t rc = m_camOps->flush_super_buf_queue(m_camHandle, m_handle, frame_idx);
return rc;
}
/*===========================================================================
* FUNCTION : QCameraVideoChannel
*
* DESCRIPTION: constructor of QCameraVideoChannel
*
* PARAMETERS :
* @cam_handle : camera handle
* @cam_ops : ptr to camera ops table
*
* RETURN : none
*==========================================================================*/
QCameraVideoChannel::QCameraVideoChannel(uint32_t cam_handle,
mm_camera_ops_t *cam_ops) :
QCameraChannel(cam_handle, cam_ops)
{
}
/*===========================================================================
* FUNCTION : QCameraVideoChannel
*
* DESCRIPTION: default constructor of QCameraVideoChannel
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCameraVideoChannel::QCameraVideoChannel()
{
}
/*===========================================================================
* FUNCTION : ~QCameraVideoChannel
*
* DESCRIPTION: destructor of QCameraVideoChannel
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCameraVideoChannel::~QCameraVideoChannel()
{
}
/*===========================================================================
* FUNCTION : takePicture
*
* DESCRIPTION: send request for queued snapshot frames
*
* PARAMETERS :
* @num_of_snapshot : number of snapshot frames requested
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraVideoChannel::takePicture(uint8_t num_of_snapshot)
{
int32_t rc = m_camOps->request_super_buf(m_camHandle,
m_handle,
num_of_snapshot);
return rc;
}
/*===========================================================================
* FUNCTION : cancelPicture
*
* DESCRIPTION: cancel request for queued snapshot frames
*
* PARAMETERS : none
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraVideoChannel::cancelPicture()
{
int32_t rc = m_camOps->cancel_super_buf_request(m_camHandle, m_handle);
return rc;
}
/*===========================================================================
* FUNCTION : releaseFrame
*
* DESCRIPTION: return video frame from app
*
* PARAMETERS :
* @opaque : ptr to video frame to be returned
* @isMetaData : if frame is a metadata or real frame
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraVideoChannel::releaseFrame(const void * opaque, bool isMetaData)
{
QCameraStream *pVideoStream = NULL;
for (size_t i = 0; i < mStreams.size(); i++) {
if (mStreams[i] != NULL && mStreams[i]->isTypeOf(CAM_STREAM_TYPE_VIDEO)) {
pVideoStream = mStreams[i];
break;
}
}
if (NULL == pVideoStream) {
ALOGE("%s: No video stream in the channel", __func__);
return BAD_VALUE;
}
int32_t rc = pVideoStream->bufDone(opaque, isMetaData);
return rc;
}
/*===========================================================================
* FUNCTION : QCameraReprocessChannel
*
* DESCRIPTION: constructor of QCameraReprocessChannel
*
* PARAMETERS :
* @cam_handle : camera handle
* @cam_ops : ptr to camera ops table
* @pp_mask : post-proccess feature mask
*
* RETURN : none
*==========================================================================*/
QCameraReprocessChannel::QCameraReprocessChannel(uint32_t cam_handle,
mm_camera_ops_t *cam_ops) :
QCameraChannel(cam_handle, cam_ops),
m_pSrcChannel(NULL)
{
memset(mSrcStreamHandles, 0, sizeof(mSrcStreamHandles));
}
/*===========================================================================
* FUNCTION : QCameraReprocessChannel
*
* DESCRIPTION: default constructor of QCameraReprocessChannel
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCameraReprocessChannel::QCameraReprocessChannel() :
m_pSrcChannel(NULL)
{
}
/*===========================================================================
* FUNCTION : ~QCameraReprocessChannel
*
* DESCRIPTION: destructor of QCameraReprocessChannel
*
* PARAMETERS : none
*
* RETURN : none
*==========================================================================*/
QCameraReprocessChannel::~QCameraReprocessChannel()
{
}
/*===========================================================================
* FUNCTION : addReprocStreamsFromSource
*
* DESCRIPTION: add reprocess streams from input source channel
*
* PARAMETERS :
* @allocator : stream related buffer allocator
* @config : pp feature configuration
* @pSrcChannel : ptr to input source channel that needs reprocess
* @minStreamBufNum: number of stream buffers needed
* @burstNum : number of burst captures needed
* @paddingInfo : padding information
* @param : reference to parameters
* @contStream : continous streaming mode or burst
* @offline : configure for offline reprocessing
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraReprocessChannel::addReprocStreamsFromSource(
QCameraAllocator& allocator, cam_pp_feature_config_t &config,
QCameraChannel *pSrcChannel, uint8_t minStreamBufNum, uint8_t burstNum,
cam_padding_info_t *paddingInfo, QCameraParameters ¶m, bool contStream,
bool offline)
{
int32_t rc = 0;
QCameraStream *pStream = NULL;
QCameraHeapMemory *pStreamInfoBuf = NULL;
cam_stream_info_t *streamInfo = NULL;
memset(mSrcStreamHandles, 0, sizeof(mSrcStreamHandles));
for (uint32_t i = 0; i < pSrcChannel->getNumOfStreams(); i++) {
pStream = pSrcChannel->getStreamByIndex(i);
if (pStream != NULL) {
if (pStream->isTypeOf(CAM_STREAM_TYPE_METADATA) ||
pStream->isTypeOf(CAM_STREAM_TYPE_RAW)) {
// Skip metadata&raw for reprocess now because PP module cannot handle
// meta data&raw. May need furthur discussion if Imaginglib need meta data
continue;
}
if (pStream->isTypeOf(CAM_STREAM_TYPE_PREVIEW) ||
pStream->isTypeOf(CAM_STREAM_TYPE_POSTVIEW) ||
pStream->isOrignalTypeOf(CAM_STREAM_TYPE_PREVIEW) ||
pStream->isOrignalTypeOf(CAM_STREAM_TYPE_POSTVIEW)) {
uint32_t feature_mask = config.feature_mask;
// skip thumbnail reprocessing if not needed
if (!param.needThumbnailReprocess(&feature_mask)) {
continue;
}
//Don't do WNR for thumbnail
feature_mask &= ~CAM_QCOM_FEATURE_DENOISE2D;
if (!feature_mask) {
// Skip thumbnail stream reprocessing since no other
//reprocessing is enabled.
continue;
}
}
pStreamInfoBuf = allocator.allocateStreamInfoBuf(CAM_STREAM_TYPE_OFFLINE_PROC);
if (pStreamInfoBuf == NULL) {
ALOGE("%s: no mem for stream info buf", __func__);
rc = NO_MEMORY;
break;
}
streamInfo = (cam_stream_info_t *)pStreamInfoBuf->getPtr(0);
memset(streamInfo, 0, sizeof(cam_stream_info_t));
streamInfo->stream_type = CAM_STREAM_TYPE_OFFLINE_PROC;
rc = pStream->getFormat(streamInfo->fmt);
if (pStream->isTypeOf(CAM_STREAM_TYPE_POSTVIEW) ||
pStream->isTypeOf(CAM_STREAM_TYPE_PREVIEW)) {
param.getThumbnailSize(&(streamInfo->dim.width), &(streamInfo->dim.height));
}
else {
rc = pStream->getFrameDimension(streamInfo->dim);
}
//FSSR generates 4x output
uint32_t feature_mask = config.feature_mask;
if (feature_mask & CAM_QCOM_FEATURE_FSSR) {
(streamInfo->dim).width *= 2;
(streamInfo->dim).height *= 2;
}
if ( contStream ) {
streamInfo->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
streamInfo->num_of_burst = 0;
} else {
streamInfo->streaming_mode = CAM_STREAMING_MODE_BURST;
streamInfo->num_of_burst = burstNum;
}
cam_stream_reproc_config_t rp_cfg;
memset(&rp_cfg, 0, sizeof(cam_stream_reproc_config_t));
if (offline) {
cam_frame_len_offset_t offset;
memset(&offset, 0, sizeof(cam_frame_len_offset_t));
rp_cfg.pp_type = CAM_OFFLINE_REPROCESS_TYPE;
pStream->getFormat(rp_cfg.offline.input_fmt);
pStream->getFrameDimension(rp_cfg.offline.input_dim);
pStream->getFrameOffset(offset);
rp_cfg.offline.input_buf_planes.plane_info = offset;
rp_cfg.offline.input_type = pStream->getMyType();
//For input metadata + input buffer
rp_cfg.offline.num_of_bufs = 2;
} else {
rp_cfg.pp_type = CAM_ONLINE_REPROCESS_TYPE;
rp_cfg.online.input_stream_id = pStream->getMyServerID();
if (CAM_STREAM_TYPE_OFFLINE_PROC ==
(rp_cfg.online.input_stream_type = pStream->getMyType())) {
rp_cfg.online.input_stream_type = pStream->getMyOriginalType();
}
}
streamInfo->reprocess_config = rp_cfg;
streamInfo->reprocess_config.pp_feature_config = config;
if (!(pStream->isTypeOf(CAM_STREAM_TYPE_SNAPSHOT) ||
pStream->isOrignalTypeOf(CAM_STREAM_TYPE_SNAPSHOT))) {
// CAC, SHARPNESS, FLIP and WNR would have been already applied -
// on preview/postview stream in realtime. Need not apply again.
streamInfo->reprocess_config.pp_feature_config.feature_mask &=
~CAM_QCOM_FEATURE_CAC;
streamInfo->reprocess_config.pp_feature_config.feature_mask &=
~CAM_QCOM_FEATURE_SHARPNESS;
streamInfo->reprocess_config.pp_feature_config.feature_mask &=
~CAM_QCOM_FEATURE_FLIP;
//Don't do WNR for thumbnail
streamInfo->reprocess_config.pp_feature_config.feature_mask &=
~CAM_QCOM_FEATURE_DENOISE2D;
if (param.isHDREnabled()
&& !param.isHDRThumbnailProcessNeeded()){
streamInfo->reprocess_config.pp_feature_config.feature_mask
&= ~CAM_QCOM_FEATURE_HDR;
}
}
uint32_t mask;
mask = streamInfo->reprocess_config.pp_feature_config.feature_mask;
if (mask & CAM_QCOM_FEATURE_ROTATION) {
if (streamInfo->reprocess_config.pp_feature_config.rotation == ROTATE_90 ||
streamInfo->reprocess_config.pp_feature_config.rotation == ROTATE_270) {
// rotated by 90 or 270, need to switch width and height
int32_t temp = streamInfo->dim.height;
streamInfo->dim.height = streamInfo->dim.width;
streamInfo->dim.width = temp;
}
}
cam_stream_type_t type = CAM_STREAM_TYPE_DEFAULT;
if (offline) {
type = streamInfo->reprocess_config.offline.input_type;
} else {
type = streamInfo->reprocess_config.online.input_stream_type;
}
if (type == CAM_STREAM_TYPE_SNAPSHOT) {
int flipMode = param.getFlipMode(type);
if (flipMode > 0) {
streamInfo->reprocess_config.pp_feature_config.feature_mask |= CAM_QCOM_FEATURE_FLIP;
streamInfo->reprocess_config.pp_feature_config.flip = (uint32_t)flipMode;
}
}
if (mask & CAM_QCOM_FEATURE_SCALE) {
//we only Scale Snapshot frame
if(pStream->isTypeOf(CAM_STREAM_TYPE_SNAPSHOT)){
//also check whether rotation is needed
if((mask & CAM_QCOM_FEATURE_ROTATION) &&
(streamInfo->reprocess_config.pp_feature_config.rotation == ROTATE_90 ||
streamInfo->reprocess_config.pp_feature_config.rotation == ROTATE_270)){
//need swap
streamInfo->dim.width = streamInfo->reprocess_config.pp_feature_config.scale_param.output_height;
streamInfo->dim.height = streamInfo->reprocess_config.pp_feature_config.scale_param.output_width;
}else{
streamInfo->dim.width = streamInfo->reprocess_config.pp_feature_config.scale_param.output_width;
streamInfo->dim.height = streamInfo->reprocess_config.pp_feature_config.scale_param.output_height;
}
}
CDBG_HIGH("%s: stream width=%d, height=%d.", __func__, streamInfo->dim.width,
streamInfo->dim.height);
}
// save source stream handler
mSrcStreamHandles[mStreams.size()] = pStream->getMyHandle();
// add reprocess stream
rc = addStream(allocator,
pStreamInfoBuf, minStreamBufNum,
paddingInfo,
NULL, NULL, false);
if (rc != NO_ERROR) {
ALOGE("%s: add reprocess stream failed, ret = %d", __func__, rc);
break;
}
}
}
if (rc == NO_ERROR) {
m_pSrcChannel = pSrcChannel;
}
return rc;
}
/*===========================================================================
* FUNCTION : getStreamBySrouceHandle
*
* DESCRIPTION: find reprocess stream by its source stream handle
*
* PARAMETERS :
* @srcHandle : source stream handle
*
* RETURN : ptr to reprocess stream if found. NULL if not found
*==========================================================================*/
QCameraStream * QCameraReprocessChannel::getStreamBySrouceHandle(uint32_t srcHandle)
{
QCameraStream *pStream = NULL;
for (size_t i = 0; i < mStreams.size(); i++) {
if (mSrcStreamHandles[i] == srcHandle) {
pStream = mStreams[i];
break;
}
}
return pStream;
}
/*===========================================================================
* FUNCTION : stop
*
* DESCRIPTION: Unmap offline buffers and stop channel
*
* PARAMETERS : none
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraReprocessChannel::stop()
{
if (!mOfflineBuffers.empty()) {
QCameraStream *stream = NULL;
List<OfflineBuffer>::iterator it = mOfflineBuffers.begin();
int error = NO_ERROR;
for( ; it != mOfflineBuffers.end(); it++) {
stream = (*it).stream;
if (NULL != stream) {
error = stream->unmapBuf((*it).type,
(*it).index,
-1);
if (NO_ERROR != error) {
ALOGE("%s: Error during offline buffer unmap %d",
__func__, error);
}
}
}
mOfflineBuffers.clear();
}
return QCameraChannel::stop();
}
/*===========================================================================
* FUNCTION : doReprocessOffline
*
* DESCRIPTION: request to do offline reprocess on the frame
*
* PARAMETERS :
* @frame : frame to be performed a reprocess
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraReprocessChannel::doReprocessOffline(
mm_camera_super_buf_t *frame)
{
int32_t rc = 0;
OfflineBuffer mappedBuffer;
if (mStreams.size() < 1) {
ALOGE("%s: No reprocess streams", __func__);
return -1;
}
if (m_pSrcChannel == NULL) {
ALOGE("%s: No source channel for reprocess", __func__);
return -1;
}
if (frame == NULL) {
ALOGE("%s: Invalid source frame", __func__);
return BAD_VALUE;
}
// find meta data stream and index of meta data frame in the superbuf
mm_camera_buf_def_t *meta_buf = NULL;
QCameraStream *pStream = NULL;
for (uint32_t i = 0; i < frame->num_bufs; i++) {
pStream = m_pSrcChannel->getStreamByHandle(frame->bufs[i]->stream_id);
if (pStream != NULL) {
if (pStream->isTypeOf(CAM_STREAM_TYPE_METADATA)) {
meta_buf = frame->bufs[i];
break;
}
}
}
for (uint32_t i = 0; i < frame->num_bufs; i++) {
pStream = getStreamBySrouceHandle(frame->bufs[i]->stream_id);
if ((pStream != NULL) &&
(m_handle == pStream->getChannelHandle())) {
if (pStream->isTypeOf(CAM_STREAM_TYPE_METADATA)) {
continue;
}
uint32_t meta_buf_index = 0;
if (NULL != meta_buf) {
rc = pStream->mapBuf(CAM_MAPPING_BUF_TYPE_OFFLINE_META_BUF,
meta_buf_index,
-1,
meta_buf->fd,
meta_buf->frame_len);
if (NO_ERROR != rc ) {
ALOGE("%s : Error during metadata buffer mapping",
__func__);
break;
}
}
mappedBuffer.index = meta_buf_index;
mappedBuffer.stream = pStream;
mappedBuffer.type = CAM_MAPPING_BUF_TYPE_OFFLINE_META_BUF;
mOfflineBuffers.push_back(mappedBuffer);
uint32_t buf_index = 1;
rc = pStream->mapBuf(CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF,
buf_index,
-1,
frame->bufs[i]->fd,
frame->bufs[i]->frame_len);
if (NO_ERROR != rc ) {
ALOGE("%s : Error during reprocess input buffer mapping",
__func__);
break;
}
mappedBuffer.index = buf_index;
mappedBuffer.stream = pStream;
mappedBuffer.type = CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF;
mOfflineBuffers.push_back(mappedBuffer);
cam_stream_parm_buffer_t param;
memset(¶m, 0, sizeof(cam_stream_parm_buffer_t));
param.type = CAM_STREAM_PARAM_TYPE_DO_REPROCESS;
param.reprocess.buf_index = buf_index;
param.reprocess.frame_idx = frame->bufs[i]->frame_idx;
param.reprocess.frame_pp_config.uv_upsample =
frame->bufs[i]->is_uv_subsampled;
if (NULL != meta_buf) {
// we have meta data sent together with reprocess frame
param.reprocess.meta_present = 1;
param.reprocess.meta_buf_index = meta_buf_index;
uint32_t stream_id = frame->bufs[i]->stream_id;
QCameraStream *srcStream =
m_pSrcChannel->getStreamByHandle(stream_id);
cam_metadata_info_t *meta =
(cam_metadata_info_t *)meta_buf->buffer;
if ((NULL != meta) && (NULL != srcStream)) {
for (int j = 0; j < MAX_NUM_STREAMS; j++) {
if (meta->crop_data.crop_info[j].stream_id ==
srcStream->getMyServerID()) {
param.reprocess.frame_pp_config.crop.crop_enabled = 1;
param.reprocess.frame_pp_config.crop.input_crop =
meta->crop_data.crop_info[j].crop;
break;
}
}
}
}
rc = pStream->setParameter(param);
if (rc != NO_ERROR) {
ALOGE("%s: stream setParameter for reprocess failed",
__func__);
break;
}
}
}
return rc;
}
/*===========================================================================
* FUNCTION : doReprocess
*
* DESCRIPTION: request to do a reprocess on the frame
*
* PARAMETERS :
* @frame : frame to be performed a reprocess
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraReprocessChannel::doReprocess(mm_camera_super_buf_t *frame)
{
int32_t rc = 0;
if (mStreams.size() < 1) {
ALOGE("%s: No reprocess streams", __func__);
return -1;
}
if (m_pSrcChannel == NULL) {
ALOGE("%s: No source channel for reprocess", __func__);
return -1;
}
// find meta data stream and index of meta data frame in the superbuf
QCameraStream *pMetaStream = NULL;
uint32_t meta_buf_index = 0;
for (uint32_t i = 0; i < frame->num_bufs; i++) {
QCameraStream *pStream = m_pSrcChannel->getStreamByHandle(frame->bufs[i]->stream_id);
if (pStream != NULL) {
if (pStream->isTypeOf(CAM_STREAM_TYPE_METADATA)) {
meta_buf_index = frame->bufs[i]->buf_idx;
pMetaStream = pStream;
break;
}
}
}
for (uint32_t i = 0; i < frame->num_bufs; i++) {
QCameraStream *pStream = getStreamBySrouceHandle(frame->bufs[i]->stream_id);
if ((pStream != NULL) &&
(m_handle == pStream->getChannelHandle())) {
if (pStream->isTypeOf(CAM_STREAM_TYPE_METADATA)) {
// Skip metadata for reprocess now because PP module cannot handle meta data
// May need furthur discussion if Imaginglib need meta data
continue;
}
cam_stream_parm_buffer_t param;
memset(¶m, 0, sizeof(cam_stream_parm_buffer_t));
param.type = CAM_STREAM_PARAM_TYPE_DO_REPROCESS;
param.reprocess.buf_index = frame->bufs[i]->buf_idx;
param.reprocess.frame_idx = frame->bufs[i]->frame_idx;
param.reprocess.frame_pp_config.uv_upsample = frame->bufs[i]->is_uv_subsampled;
if (pMetaStream != NULL) {
// we have meta data frame bundled, sent together with reprocess frame
param.reprocess.meta_present = 1;
param.reprocess.meta_stream_handle = pMetaStream->getMyServerID();
param.reprocess.meta_buf_index = meta_buf_index;
}
rc = pStream->setParameter(param);
if (rc != NO_ERROR) {
ALOGE("%s: stream setParameter for reprocess failed", __func__);
break;
}
}
}
return rc;
}
/*===========================================================================
* FUNCTION : doReprocess
*
* DESCRIPTION: request to do a reprocess on the frame
*
* PARAMETERS :
* @buf_fd : fd to the input buffer that needs reprocess
* @buf_lenght : length of the input buffer
* @ret_val : result of reprocess.
* Example: Could be faceID in case of register face image.
*
* RETURN : int32_t type of status
* NO_ERROR -- success
* none-zero failure code
*==========================================================================*/
int32_t QCameraReprocessChannel::doReprocess(int buf_fd,
size_t buf_length, int32_t &ret_val)
{
int32_t rc = 0;
if (mStreams.size() < 1) {
ALOGE("%s: No reprocess streams", __func__);
return -1;
}
uint32_t buf_idx = 0;
for (size_t i = 0; i < mStreams.size(); i++) {
if ((mStreams[i] != NULL) &&
(m_handle != mStreams[i]->getChannelHandle())) {
continue;
}
rc = mStreams[i]->mapBuf(CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF,
buf_idx, -1,
buf_fd, buf_length);
if (rc == NO_ERROR) {
cam_stream_parm_buffer_t param;
memset(¶m, 0, sizeof(cam_stream_parm_buffer_t));
param.type = CAM_STREAM_PARAM_TYPE_DO_REPROCESS;
param.reprocess.buf_index = buf_idx;
rc = mStreams[i]->setParameter(param);
if (rc == NO_ERROR) {
ret_val = param.reprocess.ret_val;
}
mStreams[i]->unmapBuf(CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF,
buf_idx, -1);
}
}
return rc;
}
}; // namespace qcamera
|