liyujie
2025-08-28 d9927380ed7c8366f762049be9f3fee225860833
android/hardware/aw/camera/3_4/v4l2_stream.cpp
....@@ -55,6 +55,7 @@
5555 static int eb_yuv_count = 0;
5656 static int eb_jpeg_count = 0;
5757 static int dq_yuv_count = 0;
58
+static int cb_yuv_count = 0;
5859 const int output_counts = 10;
5960 #endif
6061
....@@ -64,12 +65,16 @@
6465 V4L2Stream* V4L2Stream::NewV4L2Stream(
6566 const int id,
6667 const std::string device_path,
67
- std::shared_ptr<CCameraConfig> pCameraCfg) {
68
- return new V4L2Stream(id, device_path, pCameraCfg);
68
+ std::shared_ptr<CCameraConfig> pCameraCfg,
69
+ int merge_status
70
+ ) {
71
+ return new V4L2Stream(id, device_path, pCameraCfg, merge_status);
6972 }
7073
7174 V4L2Stream::V4L2Stream(const int id, const std::string device_path,
72
- std::shared_ptr<CCameraConfig> pCameraCfg)
75
+ std::shared_ptr<CCameraConfig> pCameraCfg,
76
+ int merge_status
77
+ )
7378 : mCameraConfig(pCameraCfg),
7479 device_path_(std::move(device_path)),
7580 device_fd_(-1),
....@@ -87,7 +92,14 @@
8792 HAL_LOG_ENTER();
8893 int pipefd[2];
8994 int ret = -1;
90
- if (device_path_.compare(MAIN_STREAM_PATH) == 0) {
95
+ if (merge_status) {
96
+ if (device_path_.compare(MAIN_MERGE_STREAM_PATH) == 0) {
97
+ device_ss_ = MAIN_STREAM;
98
+ } else if (device_path_.compare(SUB_0_MERGE_STREAM_PATH) == 0) {
99
+ device_ss_ = SUB_0_STREAM;
100
+ }
101
+ } else {
102
+ if (device_path_.compare(MAIN_STREAM_PATH) == 0) {
91103 device_ss_ = MAIN_STREAM;
92104 } else if (device_path_.compare(SUB_0_STREAM_PATH) == 0) {
93105 device_ss_ = SUB_0_STREAM;
....@@ -95,9 +107,15 @@
95107 device_ss_ = MAIN_STREAM;
96108 } else if (device_path_.compare(SUB_0_FRONT_STREAM_PATH) == 0) {
97109 device_ss_ = SUB_0_STREAM;
110
+ }
98111 }
99112
100113 memset(&jpeg_crop_rect, 0, sizeof(cam_crop_rect_t));
114
+ reduce_call_num = 0;
115
+ reducecallnum_dst_width = 0;
116
+ reducecallnum_dst_height = 0;
117
+ reducecallnum_src_width = 0;
118
+ reducecallnum_src_height = 0;
101119 ret = pipe(pipefd);
102120 if (ret == -1) {
103121 ALOGE("V4L2Stream create pipe failed");
....@@ -116,7 +134,7 @@
116134 close(write_fd_);
117135 }
118136
119
-int V4L2Stream::Connect() {
137
+int V4L2Stream::Connect(int merge_status) {
120138 HAL_LOG_ENTER();
121139 std::lock_guard<std::mutex> lock(connection_lock_);
122140
....@@ -146,6 +164,25 @@
146164
147165 device_fd_ = fd;
148166 ++connection_count_;
167
+
168
+ struct dma_merge picture_merge;
169
+ HAL_LOGE("bill merge_status = %d", merge_status);
170
+ if(device_id_ == 0 && merge_status) {
171
+ picture_merge.en = 1;
172
+ } else if(device_id_ == 0 && !merge_status) {
173
+ picture_merge.en = 2;
174
+ } else {
175
+ picture_merge.en = 0;
176
+ }
177
+
178
+ HAL_LOGD("device_id_:%d picture_merge.en:%d", device_id_, picture_merge.en);
179
+
180
+ if (TEMP_FAILURE_RETRY(
181
+ ioctl(fd, VIDIOC_SET_DMA_MERGE, &picture_merge)) != 0) {
182
+ HAL_LOGE("VIDIOC_SET_DMA_MERGE on %d error: %s.",
183
+ picture_merge.en,
184
+ strerror(errno));
185
+ }
149186
150187 HAL_LOGV("Detect camera stream %s, stream serial:%d.",
151188 device_path_.c_str(), device_ss_);
....@@ -268,12 +305,55 @@
268305 if (getSingleCameraId() < 0) {
269306 mIspId = mAWIspApi->awIspGetIspId(mDevice_id);
270307 }
271
- if (mIspId >= 0) {
272
- mAWIspApi->awIspStart(mIspId);
273
- HAL_LOGD("ISP turned on.");
308
+ //if (mIspId >= 0) {
309
+ // mAWIspApi->awIspStart(mIspId);
310
+ // HAL_LOGD("ISP turned on.");
311
+ //} else {
312
+ // HAL_LOGE("ISP turned on failed!");
313
+ //}
314
+
315
+ if(device_id_ == 0 &&
316
+ device_path_.compare(MAIN_MERGE_STREAM_PATH) == 0) {
317
+ mDevice_id = 0;
318
+ mIspId = mAWIspApi->awIspGetIspId(mDevice_id);
319
+ if (mIspId >= 0) {
320
+ mAWIspApi->awIspStart(mIspId);
321
+ HAL_LOGD("ISP turned on. mDevice_id = %d", mDevice_id);
322
+ } else {
323
+ HAL_LOGE("ISP turned on failed!");
324
+ }
325
+
326
+ } else if(device_id_ == 0 &&
327
+ device_path_.compare(SUB_0_MERGE_STREAM_PATH) == 0) {
328
+ mDevice_id = 1;
329
+ mIspId = mAWIspApi->awIspGetIspId(mDevice_id);
330
+ if (mIspId >= 0) {
331
+ mAWIspApi->awIspStart(mIspId);
332
+ HAL_LOGD("ISP turned on. mDevice_id = %d", mDevice_id);
333
+ } else {
334
+ HAL_LOGE("ISP turned on failed!");
335
+ }
336
+
337
+ } else if(device_id_ == 1 && format_->GetMergeStreamFlag()) {
338
+ mDevice_id = 0;
339
+ mIspId = mAWIspApi->awIspGetIspId(mDevice_id);
340
+ if (mIspId >= 0) {
341
+ mAWIspApi->awIspStart(mIspId);
342
+ HAL_LOGD("ISP turned on. mDevice_id = %d", mDevice_id);
343
+ } else {
344
+ HAL_LOGE("ISP turned on failed!");
345
+ }
346
+
274347 } else {
275
- HAL_LOGE("ISP turned on failed!");
276
- }
348
+ mIspId = mAWIspApi->awIspGetIspId(mDevice_id);
349
+ if (mIspId >= 0) {
350
+ mAWIspApi->awIspStart(mIspId);
351
+ HAL_LOGD("ISP turned on. mDevice_id = %d", mDevice_id);
352
+ } else {
353
+ HAL_LOGE("ISP turned on failed!");
354
+ }
355
+ }
356
+
277357 #endif
278358
279359 return 0;
....@@ -614,13 +694,17 @@
614694 s.r.width = cam_crop_rect.width;
615695 s.r.height = cam_crop_rect.height;
616696
617
- ret = IoctlLocked(VIDIOC_S_SELECTION, &s);
618
- HAL_LOGV("ret:%d device_fd_:%d left:%d top:%d width:%d height:%d",
619
- ret, device_fd_, s.r.left, s.r.top, s.r.width, s.r.height);
620
- if (ret < 0) {
621
- HAL_LOGE("failed, %s", strerror(errno));
622
- } else {
623
- HAL_LOGV("ok, %s", strerror(errno));
697
+ if (mCameraConfig->supportReducecallnumSize()) {
698
+ HAL_LOGV("####SetCropRect supportReducecallnumSize!~");
699
+ }else {
700
+ ret = IoctlLocked(VIDIOC_S_SELECTION, &s);
701
+ HAL_LOGV("ret:%d device_fd_:%d left:%d top:%d width:%d height:%d",
702
+ ret, device_fd_, s.r.left, s.r.top, s.r.width, s.r.height);
703
+ if (ret < 0) {
704
+ HAL_LOGE("failed, %s", strerror(errno));
705
+ } else {
706
+ HAL_LOGV("ok, %s", strerror(errno));
707
+ }
624708 }
625709 return ret;
626710 }
....@@ -669,17 +753,39 @@
669753 return 0;
670754 }
671755
672
-int V4L2Stream::SetParm(int mCapturemode) {
756
+int V4L2Stream::SetParm(int mCapturemode, uint32_t width, uint32_t height) {
673757 HAL_LOG_ENTER();
674758
675759 struct v4l2_streamparm params;
676760 memset(&params, 0, sizeof(params));
677761
678762 params.parm.capture.timeperframe.numerator = 1;
679
- params.parm.capture.timeperframe.denominator = 30;
763
+
764
+
680765 params.parm.capture.reserved[0] = 0;
681766 params.type = V4L2_CAPTURE_TYPE;
682767 params.parm.capture.capturemode = mCapturemode;
768
+
769
+ if (width * height > 2112*1568) {
770
+ HAL_LOGV("SetParm %dx%d",width,height);
771
+ params.parm.capture.timeperframe.denominator = 25;
772
+ } else {
773
+ params.parm.capture.timeperframe.denominator = 30;
774
+ }
775
+ if (width * height > 4000*3000) {
776
+ params.parm.capture.timeperframe.denominator = 24;
777
+ params.parm.capture.reserved[2] = 3;
778
+ } else {
779
+ if (device_id_ == 0 &&
780
+ device_path_.compare(SUB_0_MERGE_STREAM_PATH) == 0) {
781
+ params.parm.capture.timeperframe.denominator = 24;
782
+ params.parm.capture.reserved[2] = 3;
783
+ } else {
784
+ params.parm.capture.reserved[2] = 0;
785
+ }
786
+ }
787
+ HAL_LOGI("params.parm.capture.timeperframe.denominator:%d reserved:%d",
788
+ params.parm.capture.timeperframe.denominator, params.parm.capture.reserved[2]);
683789
684790 if (IoctlLocked(VIDIOC_S_PARM, &params) < 0) {
685791 HAL_LOGE("S_PARM fails: %s", strerror(errno));
....@@ -800,7 +906,8 @@
800906 }
801907
802908 int V4L2Stream::SetFormat(const StreamFormat& desired_format,
803
- uint32_t* result_max_buffers) {
909
+ uint32_t* result_max_buffers,
910
+ bool merge_stream_flag) {
804911 HAL_LOG_ENTER();
805912
806913 if (format_ && desired_format == *format_) {
....@@ -856,7 +963,31 @@
856963 new_format.fmt.pix_mp.width = interpolation_src_width;
857964 new_format.fmt.pix_mp.height = interpolation_src_height;
858965 setFormatFlag = 1;
859
- }
966
+ }
967
+
968
+ }
969
+
970
+ if(mCameraConfig->supportReducecallnumSize())
971
+ {
972
+ char * value;
973
+ value = mCameraConfig->supportReducecallnumSizeValue();
974
+ parse_pair(value, &reducecallnum_src_width, &reducecallnum_src_height, 'x');
975
+
976
+ char *reduce_call_num_char;
977
+ reduce_call_num_char = mCameraConfig->ReduceCallNumValue();
978
+ reduce_call_num = atoi(reduce_call_num_char);
979
+
980
+ new_format.fmt.pix_mp.width = reducecallnum_src_width;
981
+ new_format.fmt.pix_mp.height = reducecallnum_src_height;
982
+
983
+ struct buf_merge buf_merge;
984
+ buf_merge.en = 1;
985
+ buf_merge.buffer_num = reduce_call_num;
986
+
987
+ if (IoctlLocked(VIDIOC_SET_BUFFER_MERGE, &buf_merge) < 0) {
988
+ HAL_LOGE("VIDIOC_SET_BUFFER_MERGE failed: %s", strerror(errno));
989
+ return -ENODEV;
990
+ }
860991 }
861992
862993 // TODO(b/29334616): When async, this will need to check if the stream
....@@ -871,8 +1002,18 @@
8711002 return -ENODEV;
8721003 }
8731004
1005
+ if(mCameraConfig->supportReducecallnumSize())
1006
+ {
1007
+ char * value1;
1008
+ value1 = mCameraConfig->defaultReducecallnumSizeValue();
1009
+ parse_pair(value1, &reducecallnum_dst_width, &reducecallnum_dst_height, 'x');
1010
+
1011
+ new_format.fmt.pix_mp.width = reducecallnum_dst_width;
1012
+ new_format.fmt.pix_mp.height = reducecallnum_dst_height;
1013
+ }
1014
+
8741015 // Check that the driver actually set to the requested values.
875
- if (desired_format != StreamFormat(new_format)) {
1016
+ if (desired_format != StreamFormat(new_format, merge_stream_flag)) {
8761017 HAL_LOGE("Device doesn't support desired stream configuration.");
8771018 }
8781019
....@@ -881,7 +1022,7 @@
8811022 new_format.fmt.pix_mp.height = cur_height;
8821023 }
8831024 // Keep track of our new format.
884
- format_.reset(new StreamFormat(new_format));
1025
+ format_.reset(new StreamFormat(new_format, merge_stream_flag));
8851026
8861027 // Format changed, request new buffers.
8871028 int res = RequestBuffers(*result_max_buffers);
....@@ -1169,7 +1310,10 @@
11691310 #if DBG_SAVE_OUTPUT
11701311 char yuv_path[100];
11711312 dq_yuv_count = dq_yuv_count % output_counts;
1172
- sprintf(yuv_path, "/data/camera/dq_yuv_%d.bin", dq_yuv_count++);
1313
+ sprintf(yuv_path, "/data/camera/dq_yuv_%dx%d_%d.bin",
1314
+ format_->width(),
1315
+ format_->height(),
1316
+ dq_yuv_count++);
11731317 int copy_size = ALIGN_16B(format_->width())*ALIGN_16B(format_->height())*3/2;
11741318 saveBuffers(yuv_path, *src_addr_, copy_size, true);
11751319 #endif
....@@ -1264,9 +1408,43 @@
12641408 }
12651409 }
12661410
1267
- memcpy(dst_addr_ycbcr->y, src_addr, width*height);
1268
- memcpy(dst_addr_ycbcr->cr,
1269
- reinterpret_cast<char*>(src_addr) + width*height, width*height/2);
1411
+ if(mCameraConfig->supportReducecallnumSize())
1412
+ {
1413
+ int i,cur_width,cur_height;
1414
+ cur_width = reducecallnum_src_width;
1415
+ cur_height = reducecallnum_src_height;
1416
+
1417
+ for(i = 0 ;i < reduce_call_num; i++)
1418
+ {
1419
+ memcpy((char *)dst_addr_ycbcr->y + i*(cur_width * cur_height),
1420
+ (char *)src_addr + i*(cur_width * cur_height * 3 / 2),
1421
+ cur_width*cur_height);
1422
+ /*memcpy((char *)dst_addr_ycbcr->cr + i*(cur_width * cur_height / 2),
1423
+ (char *)src_addr + (i + 1)*(cur_width * cur_height) + i * (cur_width*cur_height / 2),
1424
+ cur_width*cur_height / 2);*/
1425
+ }
1426
+ memcpy(dst_addr_ycbcr->cr, (char*)src_addr + width*height, width*height/2);
1427
+ }
1428
+ else {
1429
+ memcpy(dst_addr_ycbcr->y, src_addr, width*height);
1430
+ memcpy(dst_addr_ycbcr->cr, (char*)src_addr + width*height, width*height/2);
1431
+ }
1432
+
1433
+#if DBG_SAVE_OUTPUT
1434
+ char yuv_path[100];
1435
+ sprintf(yuv_path, "/data/camera/yuv_preview_%dx%d_%d.bin",
1436
+ width, height,
1437
+ (cb_yuv_count++) % 10);
1438
+ int y_size = width * height;
1439
+ int cr_size = width * height/2;
1440
+ saveBuffers(yuv_path,
1441
+ dst_addr_ycbcr->y,
1442
+ dst_addr_ycbcr->cr,
1443
+ y_size,
1444
+ cr_size,
1445
+ true);
1446
+#endif
1447
+
12701448 return 0;
12711449 }
12721450
....@@ -1372,7 +1550,11 @@
13721550 if (mCameraConfig->supportInterpolationSize()) {
13731551 jpeg_enc.quality = 100;
13741552 sjpegInfo.quality = 100;
1375
- } else {
1553
+ } else if (format_->width() * format_->height() > 3264 * 2448) {
1554
+ jpeg_enc.quality = 100;
1555
+ sjpegInfo.quality = 100;
1556
+ }
1557
+ else {
13761558 sjpegInfo.quality = jpeg_enc.quality;
13771559 }
13781560
....@@ -1509,44 +1691,49 @@
15091691 return false;
15101692 }
15111693
1694
+ int isp_3a_param_size = 0;
1695
+ int isp_debug_msg_size = 0;
1696
+
15121697 camera3_jpeg_3a_blob_t jpeg_3a_header;
15131698 jpeg_3a_header.jpeg_3a_header_id = CAMERA3_JPEG_3A_PARAM_BLOB_ID;
1514
- jpeg_3a_header.jpeg_3a_size = sizeof(camera3_jpeg_3a_blob_t) +
1515
- ISP_3A_PARAM_SIZE;
1516
- ALOGV("3a jpeg_3a_size = %d sizeof struct = %zu",
1517
- jpeg_3a_header.jpeg_3a_size, sizeof(camera3_jpeg_3a_blob_t));
15181699 strncpy(jpeg_3a_header.magic_str, ISP_DEBUG_MAGIC_STR, 8);
15191700
15201701 camera3_jpeg_isp_msg_blob_t jpeg_isp_msg_header;
15211702 jpeg_isp_msg_header.jpeg_isp_msg_header_id = CAMERA3_JPEG_ISP_MSG_BLOB_ID;
1522
- jpeg_isp_msg_header.jpeg_isp_msg_size =
1523
- sizeof(camera3_jpeg_isp_msg_blob_t) + ISP_DEBUG_MSG_SIZE;
1524
- ALOGV("isp jpeg_isp_size = %d sizeof struct = %zu",
1525
- jpeg_isp_msg_header.jpeg_isp_msg_size,
1526
- sizeof(camera3_jpeg_isp_msg_blob_t));
15271703 strncpy(jpeg_isp_msg_header.magic_str, ISP_DEBUG_MAGIC_STR, 8);
15281704
15291705 camera3_jpeg_blob_t jpegHeader;
15301706 jpegHeader.jpeg_blob_id = CAMERA3_JPEG_BLOB_ID;
1531
- jpegHeader.jpeg_size =
1532
- bufSize + jpeg_3a_header.jpeg_3a_size +
1533
- jpeg_isp_msg_header.jpeg_isp_msg_size;
15341707
15351708 unsigned long jpeg_eof_offset =
15361709 (unsigned long)(mJpegBufferSizes - (unsigned long)sizeof(jpegHeader));
15371710 char *jpeg_eof = reinterpret_cast<char *>(jpeg_buf) + jpeg_eof_offset;
1538
- memcpy(jpeg_eof, &jpegHeader, sizeof(jpegHeader));
15391711
15401712 char *jpeg_isp_3a_params = reinterpret_cast<char *>(jpeg_buf + bufSize);
1713
+ isp_3a_param_size =
1714
+ mAWIspApi->awIspGet3AParameters(reinterpret_cast<void*>(
1715
+ jpeg_isp_3a_params + sizeof(jpeg_3a_header)));
1716
+ jpeg_3a_header.jpeg_3a_size = sizeof(camera3_jpeg_3a_blob_t) +
1717
+ isp_3a_param_size;
15411718 memcpy(jpeg_isp_3a_params, &jpeg_3a_header, sizeof(jpeg_3a_header));
1542
- mAWIspApi->awIspGet3AParameters(reinterpret_cast<void*>(
1543
- jpeg_isp_3a_params + sizeof(jpeg_3a_header)));
15441719
15451720 char *jpeg_isp_debug_msg = reinterpret_cast<char *>(jpeg_buf + bufSize +
15461721 jpeg_3a_header.jpeg_3a_size);
1722
+ isp_debug_msg_size =
1723
+ mAWIspApi->awIspGetDebugMessage(reinterpret_cast<void*>(
1724
+ jpeg_isp_debug_msg + sizeof(jpeg_isp_msg_header)));
1725
+ jpeg_isp_msg_header.jpeg_isp_msg_size =
1726
+ sizeof(camera3_jpeg_isp_msg_blob_t) + isp_debug_msg_size;
15471727 memcpy(jpeg_isp_debug_msg, &jpeg_isp_msg_header, sizeof(jpeg_isp_msg_header));
1548
- mAWIspApi->awIspGetDebugMessage(reinterpret_cast<void*>(
1549
- jpeg_isp_debug_msg + sizeof(jpeg_isp_msg_header)));
1728
+
1729
+ jpegHeader.jpeg_size =
1730
+ bufSize + jpeg_3a_header.jpeg_3a_size +
1731
+ jpeg_isp_msg_header.jpeg_isp_msg_size;
1732
+ memcpy(jpeg_eof, &jpegHeader, sizeof(jpegHeader));
1733
+
1734
+ HAL_LOGV("####jpeg_size:%d jpeg_3a_size:%d jpeg_isp_msg_size:%d",
1735
+ jpegHeader.jpeg_size,jpeg_3a_header.jpeg_3a_size,
1736
+ jpeg_isp_msg_header.jpeg_isp_msg_size);
15501737
15511738 return 0;
15521739 }