-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQCameraHWI.cpp
2787 lines (2502 loc) · 89 KB
/
QCameraHWI.cpp
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) 2011-2012 The Linux Foundation. All rights reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
/*#error uncomment this for compiler test!*/
#define ALOG_NIDEBUG 0
#define LOG_TAG "QCameraHWI"
#include <utils/Log.h>
#include <utils/threads.h>
#include <cutils/properties.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "QCameraHAL.h"
#include "QCameraHWI.h"
/* QCameraHardwareInterface class implementation goes here*/
/* following code implement the contol logic of this class*/
namespace android {
static void HAL_event_cb(mm_camera_event_t *evt, void *user_data)
{
QCameraHardwareInterface *obj = (QCameraHardwareInterface *)user_data;
if (obj) {
obj->processEvent(evt);
} else {
ALOGE("%s: NULL user_data", __func__);
}
}
int32_t QCameraHardwareInterface::createRecord()
{
int32_t ret = MM_CAMERA_OK;
ALOGV("%s : BEGIN",__func__);
/*
* Creating Instance of record stream.
*/
ALOGE("Mymode Record = %d",myMode);
mStreamRecord = QCameraStream_record::createInstance(mCameraId,
myMode);
if (!mStreamRecord) {
ALOGE("%s: error - can't creat record stream!", __func__);
return BAD_VALUE;
}
/* Store HAL object in record stream Object */
mStreamRecord->setHALCameraControl(this);
/*Init Channel */
ret = mStreamRecord->init();
if (MM_CAMERA_OK != ret){
ALOGE("%s: error - can't init Record channel!", __func__);
return BAD_VALUE;
}
ALOGV("%s : END",__func__);
return ret;
}
int32_t QCameraHardwareInterface::createSnapshot()
{
int32_t ret = MM_CAMERA_OK;
ALOGV("%s : BEGIN",__func__);
/*
* Creating Instance of Snapshot stream.
*/
ALOGE("Mymode Snap = %d",myMode);
mStreamSnap = QCameraStream_Snapshot::createInstance(mCameraId,
myMode);
if (!mStreamSnap) {
ALOGE("%s: error - can't creat snapshot stream!", __func__);
return BAD_VALUE;
}
/* Store HAL object in Snapshot stream Object */
mStreamSnap->setHALCameraControl(this);
/*Init Channel */
ret = mStreamSnap->init();
if (MM_CAMERA_OK != ret){
ALOGE("%s: error - can't init Snapshot channel!", __func__);
return BAD_VALUE;
}
ALOGV("%s : END",__func__);
return ret;
}
int32_t QCameraHardwareInterface::createPreview()
{
int32_t ret = MM_CAMERA_OK;
ALOGV("%s : BEGIN",__func__);
ALOGE("Mymode Preview = %d",myMode);
mStreamDisplay = QCameraStream_preview::createInstance(mCameraId,
myMode);
if (!mStreamDisplay) {
ALOGE("%s: error - can't creat preview stream!", __func__);
return BAD_VALUE;
}
mStreamDisplay->setHALCameraControl(this);
/*now init all the buffers and send to steam object*/
ret = mStreamDisplay->init();
if (MM_CAMERA_OK != ret){
ALOGE("%s: error - can't init Preview channel!", __func__);
return BAD_VALUE;
}
ALOGV("%s : END",__func__);
return ret;
}
/* constructor */
QCameraHardwareInterface::
QCameraHardwareInterface(int cameraId, int mode)
: mCameraId(cameraId),
mParameters(),
mMsgEnabled(0),
mNotifyCb(0),
mDataCb(0),
mDataCbTimestamp(0),
mCallbackCookie(0),
//mPreviewHeap(0),
mStreamDisplay (NULL), mStreamRecord(NULL), mStreamSnap(NULL),
mStreamLiveSnap(NULL),
mPreviewFormat(CAMERA_YUV_420_NV21),
mFps(0),
mDebugFps(0),
mBrightness(0),
mContrast(0),
mBestShotMode(0),
mEffects(0),
mSkinToneEnhancement(0),
mDenoiseValue(0),
mHJR(0),
mRotation(0),
mMaxZoom(0),
mCurrentZoom(0),
mSupportedPictureSizesCount(15),
mFaceDetectOn(0),
mDumpFrmCnt(0), mDumpSkipCnt(0),
mFocusMode(AF_MODE_MAX),
mPictureSizeCount(15),
mPreviewSizeCount(13),
mVideoSizeCount(0),
mAutoFocusRunning(false),
mPrepareSnapshot(false),
mNeedToUnlockCaf(false),
mHasAutoFocusSupport(false),
mInitialized(false),
mDisEnabled(0),
mIs3DModeOn(0),
mSmoothZoomRunning(false),
mParamStringInitialized(false),
mZoomSupported(false),
mFullLiveshotEnabled(true),
mRecordingHint(false),
mAppRecordingHint(false),
mStartRecording(0),
mReleasedRecordingFrame(false),
mHdrMode(HDR_BRACKETING_OFF),
mSnapshotFormat(0),
mZslInterval(1),
mRestartPreview(false),
mStatsOn(0), mCurrentHisto(-1), mSendData(false), mStatHeap(NULL),
mZslLookBackMode(0),
mZslLookBackValue(0),
mZslEmptyQueueFlag(FALSE),
mPictureSizes(NULL),
mVideoSizes(NULL),
mCameraState(CAMERA_STATE_UNINITED),
mPostPreviewHeap(NULL),
mExifTableNumEntries(0),
mNoDisplayMode(0),
mSupportedFpsRanges(NULL),
mSupportedFpsRangesCount(0),
mPowerModule(0),
mSnapshotFlip(FLIP_NONE)
{
ALOGI("QCameraHardwareInterface: E");
int32_t result = MM_CAMERA_E_GENERAL;
mMobiCatEnabled = false;
char value[PROPERTY_VALUE_MAX];
pthread_mutex_init(&mAsyncCmdMutex, NULL);
pthread_cond_init(&mAsyncCmdWait, NULL);
property_get("persist.debug.sf.showfps", value, "0");
mDebugFps = atoi(value);
mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED;
mPreviewWindow = NULL;
property_get("camera.hal.fps", value, "0");
mFps = atoi(value);
ALOGI("Init mPreviewState = %d", mPreviewState);
property_get("persist.camera.hal.multitouchaf", value, "0");
mMultiTouch = atoi(value);
property_get("persist.camera.full.liveshot", value, "1");
mFullLiveshotEnabled = atoi(value);
property_get("persist.camera.hal.dis", value, "0");
mDisEnabled = atoi(value);
/* Open camera stack! */
result=cam_ops_open(mCameraId, MM_CAMERA_OP_MODE_NOTUSED);
if (result == MM_CAMERA_OK) {
int i;
mm_camera_event_type_t evt;
for (i = 0; i < MM_CAMERA_EVT_TYPE_MAX; i++) {
evt = (mm_camera_event_type_t) i;
if (cam_evt_is_event_supported(mCameraId, evt)){
cam_evt_register_event_notify(mCameraId,
HAL_event_cb, (void *)this, evt);
}
}
}
ALOGV("Cam open returned %d",result);
if(MM_CAMERA_OK != result) {
ALOGE("startCamera: cam_ops_open failed: id = %d", mCameraId);
return;
}
loadTables();
/* Setup Picture Size and Preview size tables */
setPictureSizeTable();
ALOGD("%s: Picture table size: %d", __func__, mPictureSizeCount);
ALOGD("%s: Picture table: ", __func__);
for(unsigned int i=0; i < mPictureSizeCount;i++) {
ALOGD(" %d %d", mPictureSizes[i].width, mPictureSizes[i].height);
}
setPreviewSizeTable();
ALOGD("%s: Preview table size: %d", __func__, mPreviewSizeCount);
ALOGD("%s: Preview table: ", __func__);
for(unsigned int i=0; i < mPreviewSizeCount;i++) {
ALOGD(" %d %d", mPreviewSizes[i].width, mPreviewSizes[i].height);
}
setVideoSizeTable();
ALOGD("%s: Video table size: %d", __func__, mVideoSizeCount);
ALOGD("%s: Video table: ", __func__);
for(unsigned int i=0; i < mVideoSizeCount;i++) {
ALOGD(" %d %d", mVideoSizes[i].width, mVideoSizes[i].height);
}
/* set my mode - update myMode member variable due to difference in
enum definition between upper and lower layer*/
setMyMode(mode);
initDefaultParameters();
//Create Stream Objects
//Preview
result = createPreview();
if(result != MM_CAMERA_OK) {
ALOGE("%s X: Failed to create Preview Object",__func__);
return;
}
//Record
result = createRecord();
if(result != MM_CAMERA_OK) {
ALOGE("%s X: Failed to create Record Object",__func__);
return;
}
//Snapshot
result = createSnapshot();
if(result != MM_CAMERA_OK) {
ALOGE("%s X: Failed to create Record Object",__func__);
return;
}
mCameraState = CAMERA_STATE_READY;
if (hw_get_module(POWER_HARDWARE_MODULE_ID,
(const hw_module_t **)&mPowerModule)) {
ALOGE("%s module not found", POWER_HARDWARE_MODULE_ID);
}
ALOGI("QCameraHardwareInterface: X");
}
QCameraHardwareInterface::~QCameraHardwareInterface()
{
ALOGI("~QCameraHardwareInterface: E");
int result;
switch(mPreviewState) {
case QCAMERA_HAL_PREVIEW_STOPPED:
break;
case QCAMERA_HAL_PREVIEW_START:
break;
case QCAMERA_HAL_PREVIEW_STARTED:
stopPreview();
break;
case QCAMERA_HAL_RECORDING_STARTED:
stopRecordingInternal();
stopPreview();
break;
case QCAMERA_HAL_TAKE_PICTURE:
cancelPictureInternal();
break;
default:
break;
}
mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED;
if(mSupportedFpsRanges != NULL)
delete mSupportedFpsRanges;
freePictureTable();
freeVideoSizeTable();
if(mStatHeap != NULL) {
mStatHeap.clear( );
mStatHeap = NULL;
}
/* Join the threads, complete operations and then delete
the instances. */
cam_ops_close(mCameraId);
if(mStreamDisplay){
QCameraStream_preview::deleteInstance (mStreamDisplay);
mStreamDisplay = NULL;
}
if(mStreamRecord) {
QCameraStream_record::deleteInstance (mStreamRecord);
mStreamRecord = NULL;
}
if(mStreamSnap) {
QCameraStream_Snapshot::deleteInstance (mStreamSnap);
mStreamSnap = NULL;
}
if (mStreamLiveSnap){
QCameraStream_Snapshot::deleteInstance (mStreamLiveSnap);
mStreamLiveSnap = NULL;
}
pthread_mutex_destroy(&mAsyncCmdMutex);
pthread_cond_destroy(&mAsyncCmdWait);
ALOGI("~QCameraHardwareInterface: X");
}
bool QCameraHardwareInterface::isCameraReady()
{
ALOGE("isCameraReady mCameraState %d", mCameraState);
return (mCameraState == CAMERA_STATE_READY);
}
void QCameraHardwareInterface::release()
{
ALOGI("release: E");
Mutex::Autolock l(&mLock);
switch(mPreviewState) {
case QCAMERA_HAL_PREVIEW_STOPPED:
break;
case QCAMERA_HAL_PREVIEW_START:
break;
case QCAMERA_HAL_PREVIEW_STARTED:
stopPreviewInternal();
break;
case QCAMERA_HAL_RECORDING_STARTED:
stopRecordingInternal();
stopPreviewInternal();
break;
case QCAMERA_HAL_TAKE_PICTURE:
cancelPictureInternal();
break;
default:
break;
}
#if 0
if (isRecordingRunning()) {
stopRecordingInternal();
ALOGI("release: stopRecordingInternal done.");
}
if (isPreviewRunning()) {
stopPreview(); //stopPreviewInternal();
ALOGI("release: stopPreviewInternal done.");
}
if (isSnapshotRunning()) {
cancelPictureInternal();
ALOGI("release: cancelPictureInternal done.");
}
if (mCameraState == CAMERA_STATE_ERROR) {
//TBD: If Error occurs then tear down
ALOGI("release: Tear down.");
}
#endif
mPreviewState = QCAMERA_HAL_PREVIEW_STOPPED;
ALOGI("release: X");
}
void QCameraHardwareInterface::setCallbacks(
camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void *user)
{
ALOGE("setCallbacks: E");
Mutex::Autolock lock(mLock);
mNotifyCb = notify_cb;
mDataCb = data_cb;
mDataCbTimestamp = data_cb_timestamp;
mGetMemory = get_memory;
mCallbackCookie = user;
ALOGI("setCallbacks: X");
}
void QCameraHardwareInterface::enableMsgType(int32_t msgType)
{
ALOGI("enableMsgType: E, msgType =0x%x", msgType);
Mutex::Autolock lock(mLock);
mMsgEnabled |= msgType;
ALOGI("enableMsgType: X, msgType =0x%x, mMsgEnabled=0x%x", msgType, mMsgEnabled);
}
void QCameraHardwareInterface::disableMsgType(int32_t msgType)
{
ALOGI("disableMsgType: E");
Mutex::Autolock lock(mLock);
mMsgEnabled &= ~msgType;
ALOGI("disableMsgType: X, msgType =0x%x, mMsgEnabled=0x%x", msgType, mMsgEnabled);
}
int QCameraHardwareInterface::msgTypeEnabled(int32_t msgType)
{
ALOGI("msgTypeEnabled: E");
Mutex::Autolock lock(mLock);
return (mMsgEnabled & msgType);
ALOGI("msgTypeEnabled: X");
}
#if 0
status_t QCameraHardwareInterface::dump(int fd, const Vector<String16>& args) const
{
ALOGI("dump: E");
const size_t SIZE = 256;
char buffer[SIZE];
String8 result;
AutoMutex lock(&mLock);
write(fd, result.string(), result.size());
ALOGI("dump: E");
return NO_ERROR;
}
#endif
int QCameraHardwareInterface::dump(int fd)
{
ALOGE("%s: not supported yet", __func__);
return -1;
}
status_t QCameraHardwareInterface::sendCommand(int32_t command, int32_t arg1,
int32_t arg2)
{
ALOGI("sendCommand: E");
status_t rc = NO_ERROR;
Mutex::Autolock l(&mLock);
switch (command) {
#ifdef QCOM_BSP
case CAMERA_CMD_HISTOGRAM_ON:
ALOGE("histogram set to on");
rc = setHistogram(1);
break;
case CAMERA_CMD_HISTOGRAM_OFF:
ALOGE("histogram set to off");
rc = setHistogram(0);
break;
case CAMERA_CMD_HISTOGRAM_SEND_DATA:
ALOGE("histogram send data");
mSendData = true;
rc = NO_ERROR;
break;
#endif
case CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG :
{
bool enable = bool(arg1);
if (enable) {
mMsgEnabled |= CAMERA_MSG_FOCUS_MOVE;
} else {
mMsgEnabled &= ~CAMERA_MSG_FOCUS_MOVE;
}
}
break;
case CAMERA_CMD_START_FACE_DETECTION:
if(supportsFaceDetection() == false){
ALOGE("Face detection support is not available");
return NO_ERROR;
}
setFaceDetection("on");
return runFaceDetection();
case CAMERA_CMD_STOP_FACE_DETECTION:
if(supportsFaceDetection() == false){
ALOGE("Face detection support is not available");
return NO_ERROR;
}
setFaceDetection("off");
return runFaceDetection();
#if 0
case CAMERA_CMD_SEND_META_DATA:
mMetaDataWaitLock.lock();
if(mFaceDetectOn == true) {
mSendMetaData = true;
}
mMetaDataWaitLock.unlock();
return NO_ERROR;
#endif
#if 0 /* To Do: will enable it later */
case CAMERA_CMD_START_SMOOTH_ZOOM :
ALOGV("HAL sendcmd start smooth zoom %d %d", arg1 , arg2);
/*TO DO: get MaxZoom from parameter*/
int MaxZoom = 100;
switch(mCameraState ) {
case CAMERA_STATE_PREVIEW:
case CAMERA_STATE_RECORD_CMD_SENT:
case CAMERA_STATE_RECORD:
mTargetSmoothZoom = arg1;
mCurrentZoom = mParameters.getInt("zoom");
mSmoothZoomStep = (mCurrentZoom > mTargetSmoothZoom)? -1: 1;
if(mCurrentZoom == mTargetSmoothZoom) {
ALOGV("Smoothzoom target zoom value is same as "
"current zoom value, return...");
mNotifyCallback(CAMERA_MSG_ZOOM,
mCurrentZoom, 1, mCallbackCookie);
} else if(mCurrentZoom < 0 || mCurrentZoom > MaxZoom ||
mTargetSmoothZoom < 0 || mTargetSmoothZoom > MaxZoom) {
ALOGE(" ERROR : beyond supported zoom values, break..");
mNotifyCallback(CAMERA_MSG_ZOOM,
mCurrentZoom, 0, mCallbackCookie);
} else {
mSmoothZoomRunning = true;
mCurrentZoom += mSmoothZoomStep;
if ((mSmoothZoomStep < 0 && mCurrentZoom < mTargetSmoothZoom)||
(mSmoothZoomStep > 0 && mCurrentZoom > mTargetSmoothZoom )) {
mCurrentZoom = mTargetSmoothZoom;
}
mParameters.set("zoom", mCurrentZoom);
setZoom(mParameters);
}
break;
default:
ALOGV(" No preview, no smoothzoom ");
break;
}
rc = NO_ERROR;
break;
case CAMERA_CMD_STOP_SMOOTH_ZOOM:
if(mSmoothZoomRunning) {
mSmoothZoomRunning = false;
/*To Do: send cmd to stop zooming*/
}
ALOGV("HAL sendcmd stop smooth zoom");
rc = NO_ERROR;
break;
#endif
default:
break;
}
ALOGI("sendCommand: X");
return rc;
}
void QCameraHardwareInterface::setMyMode(int mode)
{
ALOGI("setMyMode: E");
if (mode & CAMERA_SUPPORT_MODE_3D) {
myMode = CAMERA_MODE_3D;
}else {
/* default mode is 2D */
myMode = CAMERA_MODE_2D;
}
if (mode & CAMERA_SUPPORT_MODE_ZSL) {
myMode = (camera_mode_t)(myMode |CAMERA_ZSL_MODE);
}else {
myMode = (camera_mode_t) (myMode | CAMERA_NONZSL_MODE);
}
ALOGI("setMyMode: Set mode to %d (passed mode: %d)", myMode, mode);
ALOGI("setMyMode: X");
}
/* static factory function */
QCameraHardwareInterface *QCameraHardwareInterface::createInstance(int cameraId, int mode)
{
ALOGI("createInstance: E");
QCameraHardwareInterface *cam = new QCameraHardwareInterface(cameraId, mode);
if (cam ) {
if (cam->mCameraState != CAMERA_STATE_READY) {
ALOGE("createInstance: Failed");
delete cam;
cam = NULL;
}
}
if (cam) {
//sp<CameraHardwareInterface> hardware(cam);
ALOGI("createInstance: X");
return cam;
} else {
return NULL;
}
}
/* external plug in function */
extern "C" void *
QCameraHAL_openCameraHardware(int cameraId, int mode)
{
ALOGI("QCameraHAL_openCameraHardware: E");
return (void *) QCameraHardwareInterface::createInstance(cameraId, mode);
}
#if 0
bool QCameraHardwareInterface::useOverlay(void)
{
ALOGI("useOverlay: E");
mUseOverlay = TRUE;
ALOGI("useOverlay: X");
return mUseOverlay;
}
#endif
bool QCameraHardwareInterface::isPreviewRunning() {
ALOGI("isPreviewRunning: E");
bool ret = false;
ALOGI("isPreviewRunning: camera state:%d", mCameraState);
if((mCameraState == CAMERA_STATE_PREVIEW) ||
(mCameraState == CAMERA_STATE_PREVIEW_START_CMD_SENT) ||
(mCameraState == CAMERA_STATE_RECORD) ||
(mCameraState == CAMERA_STATE_RECORD_START_CMD_SENT) ||
(mCameraState == CAMERA_STATE_ZSL) ||
(mCameraState == CAMERA_STATE_ZSL_START_CMD_SENT)){
return true;
}
ALOGI("isPreviewRunning: X");
return ret;
}
bool QCameraHardwareInterface::isRecordingRunning() {
ALOGE("isRecordingRunning: E");
bool ret = false;
if(QCAMERA_HAL_RECORDING_STARTED == mPreviewState)
ret = true;
//if((mCameraState == CAMERA_STATE_RECORD) ||
// (mCameraState == CAMERA_STATE_RECORD_START_CMD_SENT)) {
// return true;
//}
ALOGE("isRecordingRunning: X");
return ret;
}
bool QCameraHardwareInterface::isSnapshotRunning() {
ALOGE("isSnapshotRunning: E");
bool ret = false;
//if((mCameraState == CAMERA_STATE_SNAP_CMD_ACKED) ||
// (mCameraState == CAMERA_STATE_SNAP_START_CMD_SENT)) {
// return true;
//}
switch(mPreviewState) {
case QCAMERA_HAL_PREVIEW_STOPPED:
case QCAMERA_HAL_PREVIEW_START:
case QCAMERA_HAL_PREVIEW_STARTED:
case QCAMERA_HAL_RECORDING_STARTED:
default:
break;
case QCAMERA_HAL_TAKE_PICTURE:
ret = true;
break;
}
ALOGI("isSnapshotRunning: X");
return ret;
}
bool QCameraHardwareInterface::isZSLMode() {
return (myMode & CAMERA_ZSL_MODE);
}
int QCameraHardwareInterface::getHDRMode() {
return mHdrMode;
}
void QCameraHardwareInterface::debugShowPreviewFPS() const
{
static int mFrameCount;
static int mLastFrameCount = 0;
static nsecs_t mLastFpsTime = 0;
static float mFps = 0;
mFrameCount++;
nsecs_t now = systemTime();
nsecs_t diff = now - mLastFpsTime;
if (diff > ms2ns(250)) {
mFps = ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff;
ALOGE("Preview Frames Per Second: %.4f", mFps);
mLastFpsTime = now;
mLastFrameCount = mFrameCount;
}
}
void QCameraHardwareInterface::
processPreviewChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *app_cb) {
ALOGI("processPreviewChannelEvent: E");
switch(channelEvent) {
case MM_CAMERA_CH_EVT_STREAMING_ON:
mCameraState =
isZSLMode() ? CAMERA_STATE_ZSL : CAMERA_STATE_PREVIEW;
break;
case MM_CAMERA_CH_EVT_STREAMING_OFF:
mCameraState = CAMERA_STATE_READY;
break;
case MM_CAMERA_CH_EVT_DATA_DELIVERY_DONE:
break;
default:
break;
}
ALOGI("processPreviewChannelEvent: X");
return;
}
void QCameraHardwareInterface::processRecordChannelEvent(
mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *app_cb) {
ALOGI("processRecordChannelEvent: E");
switch(channelEvent) {
case MM_CAMERA_CH_EVT_STREAMING_ON:
mCameraState = CAMERA_STATE_RECORD;
break;
case MM_CAMERA_CH_EVT_STREAMING_OFF:
mCameraState = CAMERA_STATE_PREVIEW;
break;
case MM_CAMERA_CH_EVT_DATA_DELIVERY_DONE:
break;
default:
break;
}
ALOGI("processRecordChannelEvent: X");
return;
}
void QCameraHardwareInterface::
processSnapshotChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *app_cb) {
ALOGI("processSnapshotChannelEvent: E evt=%d state=%d", channelEvent,
mCameraState);
switch(channelEvent) {
case MM_CAMERA_CH_EVT_STREAMING_ON:
if (!mFullLiveshotEnabled) {
mCameraState =
isZSLMode() ? CAMERA_STATE_ZSL : CAMERA_STATE_SNAP_CMD_ACKED;
}
break;
case MM_CAMERA_CH_EVT_STREAMING_OFF:
if (!mFullLiveshotEnabled) {
mCameraState = CAMERA_STATE_READY;
}
break;
case MM_CAMERA_CH_EVT_DATA_DELIVERY_DONE:
break;
case MM_CAMERA_CH_EVT_DATA_REQUEST_MORE:
if (isZSLMode()) {
/* ZSL Mode: In ZSL Burst Mode, users may request for number of
snapshots larger than internal size of ZSL queue. So we'll need
process the remaining frames as they become available.
In such case, we'll get this event */
if(NULL != mStreamSnap)
mStreamSnap->takePictureZSL();
}
break;
default:
break;
}
ALOGI("processSnapshotChannelEvent: X");
return;
}
void QCameraHardwareInterface::processChannelEvent(
mm_camera_ch_event_t *event, app_notify_cb_t *app_cb)
{
ALOGI("processChannelEvent: E");
Mutex::Autolock lock(mLock);
switch(event->ch) {
case MM_CAMERA_CH_PREVIEW:
processPreviewChannelEvent(event->evt, app_cb);
break;
case MM_CAMERA_CH_VIDEO:
processRecordChannelEvent(event->evt, app_cb);
break;
case MM_CAMERA_CH_SNAPSHOT:
processSnapshotChannelEvent(event->evt, app_cb);
break;
default:
break;
}
ALOGI("processChannelEvent: X");
return;
}
void QCameraHardwareInterface::processCtrlEvent(mm_camera_ctrl_event_t *event, app_notify_cb_t *app_cb)
{
ALOGI("processCtrlEvent: %d, E",event->evt);
Mutex::Autolock lock(mLock);
switch(event->evt)
{
case MM_CAMERA_CTRL_EVT_ZOOM_DONE:
zoomEvent(&event->status, app_cb);
break;
case MM_CAMERA_CTRL_EVT_AUTO_FOCUS_DONE:
autoFocusEvent(&event->status, app_cb);
break;
case MM_CAMERA_CTRL_EVT_PREP_SNAPSHOT:
break;
case MM_CAMERA_CTRL_EVT_AUTO_FOCUS_MOVE:
autoFocusMoveEvent(&event->status, app_cb);
break;
case MM_CAMERA_CTRL_EVT_WDN_DONE:
wdenoiseEvent(event->status, (void *)(event->cookie));
break;
case MM_CAMERA_CTRL_EVT_HDR_DONE:
hdrEvent(event->status, (void *)(event->cookie));
break;
case MM_CAMERA_CTRL_EVT_ERROR:
app_cb->notifyCb = mNotifyCb;
app_cb->argm_notify.msg_type = CAMERA_MSG_ERROR;
app_cb->argm_notify.ext1 = CAMERA_ERROR_UNKNOWN;
app_cb->argm_notify.cookie = mCallbackCookie;
break;
case MM_CAMERA_CTRL_EVT_SNAPSHOT_CONFIG_DONE:
ALOGV("%s: MM_CAMERA_CTRL_EVT_SNAPSHOT_CONFIG_DONE", __func__);
app_cb->notifyCb = mNotifyCb;
app_cb->argm_notify.msg_type = CAMERA_MSG_SHUTTER;
app_cb->argm_notify.ext1 = 0;
app_cb->argm_notify.ext2 = TRUE;
app_cb->argm_notify.cookie = mCallbackCookie;
mShutterSoundPlayed = TRUE;
break;
default:
break;
}
ALOGI("processCtrlEvent: X");
return;
}
void QCameraHardwareInterface::processStatsEvent(
mm_camera_stats_event_t *event, app_notify_cb_t *app_cb)
{
ALOGI("processStatsEvent: E");
if (!isPreviewRunning( )) {
ALOGE("preview is not running");
return;
}
switch (event->event_id) {
#ifdef QCOM_BSP
case MM_CAMERA_STATS_EVT_HISTO:
{
ALOGE("HAL process Histo: mMsgEnabled=0x%x, mStatsOn=%d, mSendData=%d, mDataCb=%p ",
(mMsgEnabled & CAMERA_MSG_STATS_DATA), mStatsOn, mSendData, mDataCb);
int msgEnabled = mMsgEnabled;
/*get stats buffer based on index*/
camera_preview_histogram_info* hist_info =
(camera_preview_histogram_info*) mHistServer.camera_memory[event->e.stats_histo.index]->data;
if(mStatsOn == QCAMERA_PARM_ENABLE && mSendData &&
mDataCb && (msgEnabled & CAMERA_MSG_STATS_DATA) ) {
uint32_t *dest;
mSendData = false;
mCurrentHisto = (mCurrentHisto + 1) % 3;
// The first element of the array will contain the maximum hist value provided by driver.
*(uint32_t *)((unsigned int)(mStatsMapped[mCurrentHisto]->data)) = hist_info->max_value;
memcpy((uint32_t *)((unsigned int)mStatsMapped[mCurrentHisto]->data + sizeof(int32_t)),
(uint32_t *)hist_info->buffer,(sizeof(int32_t) * 256));
app_cb->dataCb = mDataCb;
app_cb->argm_data_cb.msg_type = CAMERA_MSG_STATS_DATA;
app_cb->argm_data_cb.data = mStatsMapped[mCurrentHisto];
app_cb->argm_data_cb.index = 0;
app_cb->argm_data_cb.metadata = NULL;
app_cb->argm_data_cb.cookie = mCallbackCookie;
}
break;
}
#endif
default: // Drop stats event.
break;
}
ALOGV("receiveCameraStats X");
}
void QCameraHardwareInterface::processInfoEvent(
mm_camera_info_event_t *event, app_notify_cb_t *app_cb) {
ALOGI("processInfoEvent: %d, E",event->event_id);
//Mutex::Autolock lock(eventLock);
switch(event->event_id)
{
case MM_CAMERA_INFO_EVT_ROI:
roiEvent(event->e.roi, app_cb);
break;
case MM_CAMERA_INFO_FLASH_FRAME_IDX:
zslFlashEvent(event->e.zsl_flash_info, app_cb);
break;
default:
break;
}
ALOGI("processInfoEvent: X");
return;
}
void QCameraHardwareInterface::processEvent(mm_camera_event_t *event)
{
app_notify_cb_t app_cb;
ALOGE("processEvent: type :%d E",event->event_type);
if(mPreviewState == QCAMERA_HAL_PREVIEW_STOPPED){
ALOGE("Stop recording issued. Return from process Event");
return;
}
memset(&app_cb, 0, sizeof(app_notify_cb_t));
switch(event->event_type)
{
case MM_CAMERA_EVT_TYPE_CH:
processChannelEvent(&event->e.ch, &app_cb);
break;
case MM_CAMERA_EVT_TYPE_CTRL:
processCtrlEvent(&event->e.ctrl, &app_cb);
break;
case MM_CAMERA_EVT_TYPE_STATS:
processStatsEvent(&event->e.stats, &app_cb);
break;
case MM_CAMERA_EVT_TYPE_INFO:
processInfoEvent(&event->e.info, &app_cb);
break;
default:
break;
}
ALOGE(" App_cb Notify %p, datacb=%p", app_cb.notifyCb, app_cb.dataCb);
if (app_cb.notifyCb) {
app_cb.notifyCb(app_cb.argm_notify.msg_type,
app_cb.argm_notify.ext1, app_cb.argm_notify.ext2,
app_cb.argm_notify.cookie);
}
if (app_cb.dataCb) {
app_cb.dataCb(app_cb.argm_data_cb.msg_type,
app_cb.argm_data_cb.data, app_cb.argm_data_cb.index,
app_cb.argm_data_cb.metadata, app_cb.argm_data_cb.cookie);
}
ALOGI("processEvent: X");
return;
}
void QCameraHardwareInterface::zslFlashEvent(struct zsl_flash_t evt, app_notify_cb_t *) {
ALOGE("%s: E", __func__);
ALOGE("flashEvent: numFrames = %d, frameId[0] = %d", evt.valid_entires, evt.frame_idx[0]);
status_t ret = mStreamSnap->takePictureZSL();
if (ret != MM_CAMERA_OK) {
ALOGE("%s: Error taking ZSL snapshot!", __func__);
}
ALOGE("%s: X", __func__);
}
bool QCameraHardwareInterface::preview_parm_config (cam_ctrl_dimension_t* dim,
QCameraParameters& parm)
{
ALOGI("preview_parm_config: E");
bool matching = true;
int display_width = 0; /* width of display */
int display_height = 0; /* height of display */
uint16_t video_width = 0; /* width of the video */
uint16_t video_height = 0; /* height of the video */
/* First check if the preview resolution is the same, if not, change it*/
parm.getPreviewSize(&display_width, &display_height);
if (display_width && display_height) {
matching = (display_width == dim->display_width) &&
(display_height == dim->display_height);
if (!matching) {
dim->display_width = display_width;
dim->display_height = display_height;
}
}
else
matching = false;