diff --git a/vendor/rkh/rkh_patch/applications/applications_sample_camera_media.patch b/vendor/rkh/rkh_patch/applications/applications_sample_camera_media.patch index e070aea45f1ad950d16ee88f03d0e89a33db861f..64c99078db12131bdcc68624c8dee87e1096d6e5 100644 --- a/vendor/rkh/rkh_patch/applications/applications_sample_camera_media.patch +++ b/vendor/rkh/rkh_patch/applications/applications_sample_camera_media.patch @@ -1,8 +1,11 @@ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/applications/sample/camera/media/audio_capture_sample.cpp ../../../../../3403_project/ohos/applications/sample/camera/media/audio_capture_sample.cpp ---- ohos/applications/sample/camera/media/audio_capture_sample.cpp 2025-05-03 17:54:14.000000000 +0800 -+++ ../../../../../3403_project/ohos/applications/sample/camera/media/audio_capture_sample.cpp 2025-11-03 15:42:58.772842905 +0800 -@@ -284,6 +284,11 @@ int main(int argc, char *argv[]) +diff -uparN '--exclude=.git' ohos/applications/sample/camera/media/audio_capture_sample.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/applications/sample/camera/media/audio_capture_sample.cpp +--- ohos/applications/sample/camera/media/audio_capture_sample.cpp 2025-12-08 14:54:54.152390172 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/applications/sample/camera/media/audio_capture_sample.cpp 2025-11-29 09:51:40.834800085 +0800 +@@ -282,9 +282,13 @@ int main(int argc, char *argv[]) + AudioCapturer audioCap; + AudioCapturerInfo info; +- info.deviceId = "0"; info.inputSource = AUDIO_MIC; info.bitWidth = BIT_WIDTH_16; + // hihopeos add, deviceId = "0", fix ipc deserialization parsing on the audio caputure server side @@ -13,7 +16,7 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/applic AudioCodecFormat audioFormat = GetAudioFormat(); if (audioFormat == FORMAT_BUTT) { return -1; -@@ -305,7 +310,8 @@ int main(int argc, char *argv[]) +@@ -306,7 +310,8 @@ int main(int argc, char *argv[]) } frameCount = audioCap.GetFrameCount(); std::cout << "GetFrameCount " << frameCount << std::endl; @@ -23,9 +26,9 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/applic g_audioSourceProcessInput.buffer = new uint8_t[g_audioSourceProcessInput.framesize]; RumCmd(audioCap); -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/applications/sample/camera/media/BUILD.gn ../../../../../3403_project/ohos/applications/sample/camera/media/BUILD.gn ---- ohos/applications/sample/camera/media/BUILD.gn 2025-05-03 17:54:14.000000000 +0800 -+++ ../../../../../3403_project/ohos/applications/sample/camera/media/BUILD.gn 2025-11-03 15:42:58.772842905 +0800 +diff -uparN '--exclude=.git' ohos/applications/sample/camera/media/BUILD.gn /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/applications/sample/camera/media/BUILD.gn +--- ohos/applications/sample/camera/media/BUILD.gn 2025-12-08 14:54:54.152390172 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/applications/sample/camera/media/BUILD.gn 2025-11-29 09:51:40.834800085 +0800 @@ -27,7 +27,7 @@ executable("camera_sample") { "//foundation/multimedia/camera_lite/frameworks:camera_lite", "//foundation/multimedia/media_lite/frameworks/recorder_lite:recorder_lite", @@ -53,9 +56,9 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/applic } lite_component("media_sample") { -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/applications/sample/camera/media/camera_sample.cpp ../../../../../3403_project/ohos/applications/sample/camera/media/camera_sample.cpp ---- ohos/applications/sample/camera/media/camera_sample.cpp 2025-11-07 16:00:36.377514947 +0800 -+++ ../../../../../3403_project/ohos/applications/sample/camera/media/camera_sample.cpp 2025-11-03 15:42:58.772842905 +0800 +diff -uparN '--exclude=.git' ohos/applications/sample/camera/media/camera_sample.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/applications/sample/camera/media/camera_sample.cpp +--- ohos/applications/sample/camera/media/camera_sample.cpp 2025-12-08 14:54:54.152390172 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/applications/sample/camera/media/camera_sample.cpp 2025-11-29 09:51:40.834800085 +0800 @@ -78,7 +78,7 @@ Recorder *SampleCreateRecorder() int32_t channelCount = 1; AudioCodecFormat audioFormat = AAC_LC; @@ -113,9 +116,9 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/applic }; class SampleCameraDeviceCallback : public CameraDeviceCallback { -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/applications/sample/camera/media/player_sample.cpp ../../../../../3403_project/ohos/applications/sample/camera/media/player_sample.cpp ---- ohos/applications/sample/camera/media/player_sample.cpp 2025-05-03 17:54:14.000000000 +0800 -+++ ../../../../../3403_project/ohos/applications/sample/camera/media/player_sample.cpp 2025-11-03 15:42:58.772842905 +0800 +diff -uparN '--exclude=.git' ohos/applications/sample/camera/media/player_sample.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/applications/sample/camera/media/player_sample.cpp +--- ohos/applications/sample/camera/media/player_sample.cpp 2025-12-08 14:54:54.152390172 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/applications/sample/camera/media/player_sample.cpp 2025-11-29 09:51:40.834800085 +0800 @@ -360,8 +360,8 @@ static int SetSurface(TestSample &sample } sample.surface->SetUserData("region_position_x", "0"); diff --git a/vendor/rkh/rkh_patch/device/device_soc_hisilicon.patch b/vendor/rkh/rkh_patch/device/device_soc_hisilicon.patch index dee89a3d7e73e98496683384ff16d000d1f8e144..07f1d0c912a3c7fd91f82d8a9c43b71157ab5e7f 100644 --- a/vendor/rkh/rkh_patch/device/device_soc_hisilicon.patch +++ b/vendor/rkh/rkh_patch/device/device_soc_hisilicon.patch @@ -1,16 +1,134 @@ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/display/ss928/include/display_overlay_layer.h ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/display/ss928/include/display_overlay_layer.h ---- ohos/device/soc/hisilicon/common/hal/display/ss928/include/display_overlay_layer.h 2025-11-07 16:00:38.065503433 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/display/ss928/include/display_overlay_layer.h 2025-11-07 14:44:54.869657226 +0800 -@@ -26,4 +26,5 @@ int32_t InvokeOverlayLayerCmd(uint32_t d - int32_t CloseOverlayLayer(uint32_t devId, uint32_t layerId); - int32_t OverlayLayerFlush(uint32_t devId, uint32_t layerId, LayerBuffer *buffer); - int32_t GetOverlayLayerDeviceId(uint32_t devId, uint32_t layerId, uint32_t *deviceId); -+int32_t SetOverlayLayerPriority(uint32_t priority); - #endif // DISPLAY_OVERLAY_LAYER_H -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_layer.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_layer.c ---- ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_layer.c 2025-11-07 16:00:38.065503433 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_layer.c 2025-11-07 14:44:54.873657233 +0800 +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/display/ss928/src/bt1120.c ohos1/device/soc/hisilicon/common/hal/display/ss928/src/bt1120.c +--- ohos/device/soc/hisilicon/common/hal/display/ss928/src/bt1120.c 2025-12-18 15:30:15.802678161 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/display/ss928/src/bt1120.c 2025-12-18 15:44:30.886238365 +0800 +@@ -1,62 +1,62 @@ +-/* +- * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. +- * +- * 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. +- */ +- +-#include "display_layer_internal.h" +-#ifdef __BT1120_SUPPORT__ +-#include "ss_mpi_vb.h" +-#include "ss_mpi_audio.h" +- +-#ifdef __cplusplus +-#if __cplusplus +-extern "C" { +-#endif +-#endif /* End of #ifdef __cplusplus */ +-int32_t EnableVOWithBT1120(ot_vo_dev voDev) +-{ +- ss_mpi_vo_disable(voDev); +- +- ot_vo_pub_attr pubAttr = { 0 }; +- int32_t ret = ss_mpi_vo_get_pub_attr(voDev, &pubAttr); +- +- pubAttr.intf_type = OT_VO_INTF_BT1120; +- pubAttr.intf_sync = OT_VO_OUT_1080P60; +- pubAttr.bg_color = COLOR_RGB_BLUE; +- ret = ss_mpi_vo_set_pub_attr(voDev, &pubAttr); +- if (ret != DISPLAY_SUCCESS) { +- HDF_LOGE("set vo atter failed with %#x!\n", ret); +- return DISPLAY_FAILURE; +- } +- +- ret = ss_mpi_vo_enable(voDev); +- if (ret != DISPLAY_SUCCESS) { +- HDF_LOGE("vo enable failed with %#x!\n", ret); +- return DISPLAY_FAILURE; +- } +- return DISPLAY_SUCCESS; +-} +- +-int32_t DisableVOWithBT1120(ot_vo_dev voDev) +-{ +- ss_mpi_vo_disable(voDev); +- return DISPLAY_SUCCESS; +-} +- +-#ifdef __cplusplus +-#if __cplusplus +-} +-#endif +-#endif /* End of #ifdef __cplusplus */ +-#endif // __BT1120_SUPPORT__ ++/* ++ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. ++ * ++ * 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. ++ */ ++ ++#include "display_layer_internal.h" ++#ifdef __BT1120_SUPPORT__ ++#include "ss_mpi_vb.h" ++#include "ss_mpi_audio.h" ++ ++#ifdef __cplusplus ++#if __cplusplus ++extern "C" { ++#endif ++#endif /* End of #ifdef __cplusplus */ ++int32_t EnableVOWithBT1120(ot_vo_dev voDev) ++{ ++ ss_mpi_vo_disable(voDev); ++ ++ ot_vo_pub_attr pubAttr = { 0 }; ++ int32_t ret = ss_mpi_vo_get_pub_attr(voDev, &pubAttr); ++ ++ pubAttr.intf_type = OT_VO_INTF_BT1120; ++ pubAttr.intf_sync = OT_VO_OUT_1080P60; ++ pubAttr.bg_color = COLOR_RGB_BLUE; ++ ret = ss_mpi_vo_set_pub_attr(voDev, &pubAttr); ++ if (ret != DISPLAY_SUCCESS) { ++ HDF_LOGE("set vo atter failed with %#x!\n", ret); ++ return DISPLAY_FAILURE; ++ } ++ ++ ret = ss_mpi_vo_enable(voDev); ++ if (ret != DISPLAY_SUCCESS) { ++ HDF_LOGE("vo enable failed with %#x!\n", ret); ++ return DISPLAY_FAILURE; ++ } ++ return DISPLAY_SUCCESS; ++} ++ ++int32_t DisableVOWithBT1120(ot_vo_dev voDev) ++{ ++ ss_mpi_vo_disable(voDev); ++ return DISPLAY_SUCCESS; ++} ++ ++#ifdef __cplusplus ++#if __cplusplus ++} ++#endif ++#endif /* End of #ifdef __cplusplus */ ++#endif // __BT1120_SUPPORT__ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_layer.c ohos1/device/soc/hisilicon/common/hal/display/ss928/src/display_layer.c +--- ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_layer.c 2025-12-18 15:41:53.763785014 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/display/ss928/src/display_layer.c 2025-12-18 15:44:30.886238365 +0800 @@ -964,6 +964,11 @@ static int32_t SetLayerSize(uint32_t dev return DISPLAY_SUCCESS; } @@ -31,562 +149,1610 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device *funcs = lFuncs; HDF_LOGI("%s: layer initialize success", __func__); return DISPLAY_SUCCESS; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_overlay_layer.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_overlay_layer.c ---- ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_overlay_layer.c 2025-11-07 16:00:38.065503433 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_overlay_layer.c 2025-11-07 14:44:54.873657233 +0800 -@@ -693,3 +693,11 @@ int32_t GetOverlayLayerDeviceId(uint32_t - HDF_LOGI("GetOverlayLayerDeviceId (%u)", *deviceId); - return DISPLAY_SUCCESS; - } +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_overlay_layer.c ohos1/device/soc/hisilicon/common/hal/display/ss928/src/display_overlay_layer.c +--- ohos/device/soc/hisilicon/common/hal/display/ss928/src/display_overlay_layer.c 2025-12-18 15:30:15.802678161 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/display/ss928/src/display_overlay_layer.c 2025-12-18 15:44:30.886238365 +0800 +@@ -1,695 +1,703 @@ +-/* +- * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. +- * +- * 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. +- */ +- +-#include "display_overlay_layer.h" +-#include "display_adapt_video.h" +-#include "display_adapt_vo.h" +-#include "display_adapt_sys.h" +- +-#if defined(ENABLE_H8) || defined(ENABLE_H9) +-#include "ot_math.h" +-#define ALIGN_DOWN OT_ALIGN_DOWN +-#else +-#include "hi_math.h" +-#endif +-#include +-#include +-#include +-#include "vpss_resmng.h" +- +-#define ALIGN_DOWN_NUM 2 +-#define DISPLAY_LAYER_INVALID_ID (-1) +-#define VO_BUFF_LEN 3 +-#define LAYER_IDX_OFFSET 24 +-#define VO_DEV_OFFSET 16 +-#define VO_LAYER_OFFSET 8 +-#define INVALID_ID (-1U) +-#define UNUSED_ATTR __attribute__((unused)) +-#define DISPLAY_LAYER_MAX_NUM 64 +- +-#ifdef ENABLE_MULTI_DISP_CHN +-#define DISPLAY_CNT 2 // Two CHNs need to be initialized for dual-camera display +-#else +-#define DISPLAY_CNT 1 +-#endif +- +-/* default layer width */ +-#define DEFAULT_WIDTH_FOR_HDMI 1920 +-#define DEFAULT_WIDTH_FOR_LCD 480 +-/* default layer height */ +-#define DEFAULT_HEIGHT_FOR_HDMI 1080 +-#define DEFAULT_HEIGHT_FOR_LCD 960 +-#define DEFAULT_DISPLAY_FPS 60 +-#define DEFAULT_SET_FPS 30 +-#define OVERLAY_LAYER_NUM ((OV_LAYER_MAX) - (GRA_LAYER_MAX)) +-#define OFFSET_8 8 +- +-#if ENABLE_VO_TIME_TASK +-#define CNT 1000 +-static pthread_t g_voThread = 0; +-static bool g_voRunning = false; +-#endif +- +-#if ENABLE_VO_BUSYDROP +-static pthread_t g_voDropThread = 0; +-static bool g_voDropRunning = false; +-#endif +- +-typedef struct { +- VO_CHN voChn; +- VPSS_GRP vpssGrp; +- VPSS_CHN vpssChn; +- bool vpssIsInternalEnable; +-} OverlayLayerPrivate; +- +-static bool CheckTypeIsOverlayLayer(uint32_t layerId) +-{ +- return (layerId & LAYER_ID_VO_LAYER_TYPE_MARK) != 0; +-} +- +-static uint8_t GetVoChn(uint32_t layerId) +-{ +- return (uint8_t)layerId & LAYER_ID_VO_CHN_MASK; +-} +- +-static uint8_t GetVoLayer(uint32_t layerId) +-{ +- return (uint8_t)((layerId & LAYER_ID_VO_LAYER_ID_MASK) >> VO_LAYER_OFFSET); +-} +- +-static OverlayLayerPrivate *GetLayerInstance(uint32_t devId, uint8_t index) +-{ +- static OverlayLayerPrivate layerPriv[DEV_ID_NUM][OVERLAY_LAYER_NUM] = {{ +- { +- .voChn = -1, +- .vpssGrp = -1, +- .vpssChn = -1, +- }, { +- .voChn = -1, +- .vpssGrp = -1, +- .vpssChn = -1, +- }, { +- .voChn = -1, +- .vpssGrp = -1, +- .vpssChn = -1, +- }, { +- .voChn = -1, +- .vpssGrp = -1, +- .vpssChn = -1, +- } +- }}; +- return &layerPriv[devId][index]; +-} +- +-static int32_t BindVoVpss(VPSS_GRP vpssGrp, VPSS_CHN vpssChn, VO_LAYER voLayer, VO_CHN voChn) +-{ +- MPP_CHN_S stSrcChn; +- MPP_CHN_S stDestChn; +- stSrcChn.mod_id = HI_ID_VPSS; +- stSrcChn.dev_id = vpssGrp; +- stSrcChn.chn_id = vpssChn; +- +- stDestChn.mod_id = HI_ID_VO; +- stDestChn.dev_id = voLayer; +- stDestChn.chn_id = voChn; +- int32_t ret = ss_mpi_sys_bind(&stSrcChn, &stDestChn); +- CHECK_CALL_MPI_RET(ret, ss_mpi_sys_bind); +- HDF_LOGI("bind vo & vpss success, vpssGrp=%d vpssChn=%d voLayer=%d voChn=%d", vpssGrp, vpssChn, voLayer, voChn); +- return DISPLAY_SUCCESS; +-} +- +-static int32_t UnBindVoVpss(VPSS_GRP vpssGrp, VPSS_CHN vpssChn, VO_LAYER voLayer, VO_CHN voChn) +-{ +- MPP_CHN_S stSrcChn; +- stSrcChn.mod_id = HI_ID_VPSS; +- stSrcChn.dev_id = vpssGrp; +- stSrcChn.chn_id = vpssChn; +- +- MPP_CHN_S stDestChn; +- stDestChn.mod_id = HI_ID_VO; +- stDestChn.dev_id = voLayer; +- stDestChn.chn_id = voChn; +- int32_t ret = ss_mpi_sys_unbind(&stSrcChn, &stDestChn); +- HDF_LOGI("unbind vo & vpss success, vpssGrp=%d vpssChn=%d voLayer=%d voChn=%d", vpssGrp, vpssChn, voLayer, voChn); +- CHECK_CALL_MPI_RET(ret, ss_mpi_sys_unbind); +- +- return DISPLAY_SUCCESS; +-} +- +-#if ENABLE_VO_BUSYDROP +-static int32_t sample_comm_vdec_clear_vo_busybuf(td_void) +-{ +- for (int32_t index = 0; index < OVERLAY_LAYER_NUM; index++) { +- int32_t ret; +- ot_vo_layer layer = 0; +- ot_vo_chn_status status; +- td_bool is_clear_all = TD_FALSE; +- ret = ss_mpi_vo_query_chn_status(layer, index, &status); +- if (ret != TD_SUCCESS) { +- return TD_FAILURE; +- } +- if (status.chn_busy_num >= 2) { // 2:busy_num +- ret = ss_mpi_vo_clear_chn_buf(layer, index, is_clear_all); +- if (ret != TD_SUCCESS) { +- HDF_LOGE("Clear channel %d buf failed with errno %#x!\n", index, ret); +- return TD_FAILURE; +- } +- } +- } +- +- return TD_SUCCESS; +-} +- +-static void *VoDropTask(void *args) +-{ +- (void)args; +- while (g_voDropThread && g_voDropRunning) { +- sample_comm_vdec_clear_vo_busybuf(); +- struct timespec ts; +- ts.tv_sec = 0; +- ts.tv_nsec = 1 * 1000 * 1000; // 1000: ns to ms +- nanosleep(&ts, TD_NULL); +- } +- HDF_LOGI(" VoDropTask exit\n"); +- return NULL; +-} +- +-static void VoDropTaskBegin() +-{ +- if (g_voDropThread == 0) { +- g_voDropRunning = true; +- int32_t ret = pthread_create(&g_voDropThread, NULL, VoDropTask, NULL); +- if (ret != 0) { +- g_voDropRunning = false; +- g_voDropThread = 0; +- HDF_LOGI("creat vo drop thread failed %d \n", ret); +- return; +- } +- HDF_LOGI("creat vo drop thread = %d \n", ret); +- } +-} +- +-static void VoDropTaskEnd() +-{ +- if (g_voDropThread != 0) { +- g_voDropRunning = false; +- pthread_join(g_voDropThread, NULL); +- g_voDropThread = 0; +- } +-} +-#endif +- +-#if ENABLE_VO_TIME_TASK +-static void *VoTimeTask(void *args) +-{ +- (void)args; +- VIDEO_FRAME_INFO_S videoFrame = {0}; +- td_u64 curPTS = 0; +- td_u64 dl[CNT] = {0}; +- td_u64 lastPts = 0; +- HDF_LOGI(" VoTimeTask enter\n"); +- int32_t i = 0; +- while (i < CNT && g_voRunning) { +- int32_t ret = ss_mpi_vo_get_screen_frame(0, &videoFrame, 0x3E8); /* 1000ms */ +- if (ret != TD_SUCCESS) { +- continue; +- } +- ret = ss_mpi_sys_get_cur_pts(&curPTS); +- if (ret == TD_SUCCESS) { +- dl[i] = curPTS - videoFrame.video_frame.pts; +- if (lastPts != videoFrame.video_frame.pts) { +- lastPts = videoFrame.video_frame.pts; +- i++; +- } +- } +- ss_mpi_vo_release_screen_frame(0, &videoFrame); +- if (memset_s(&videoFrame, sizeof(videoFrame), 0, sizeof(videoFrame)) != EOK) { +- HDF_LOGI("memset_s videoFrame failed\n"); +- } +- struct timespec ts; +- ts.tv_sec = 0; +- ts.tv_nsec = 1 * 1000 * 1000; // 1000: ns to ms +- nanosleep(&ts, TD_NULL); +- } +- HDF_LOGI(" VoTimeTask exit\n"); +- if (i < CNT) { +- return NULL; +- } +- td_u64 total = 0; +- for (i = 0; i < CNT; i++) { +- if (i % 0x32 == 0) { /* 50 */ +- HDF_LOGI(" vo screen = %llu \n", dl[i]); +- } +- total += dl[i]; +- } +- HDF_LOGI(" vo screen avg = %llu\n", total / CNT); +- return NULL; +-} +- +-static void VoTimeTaskBegin(void) +-{ +- if (g_voThread == 0) { +- g_voRunning = true; +- int32_t ret = pthread_create(&g_voThread, NULL, VoTimeTask, NULL); +- if (ret != 0) { +- g_voRunning = false; +- g_voThread = 0; +- HDF_LOGI("creat vo thread failed %d \n", ret); +- return; +- } +- HDF_LOGI("creat vo thread = %d \n", ret); +- } +-} +- +-static void VoTimeTaskEnd(void) +-{ +- if (g_voThread != 0) { +- g_voRunning = false; +- pthread_join(g_voThread, NULL); +- g_voThread = 0; +- } +-} +-#endif +- +-static int32_t SetVoLayerParam(uint32_t devId, VO_VIDEO_LAYER_ATTR_S *attr) +-{ +- VO_PUB_ATTR_S stPubAttr = {0}; +- int32_t ret = ss_mpi_vo_get_pub_attr(devId > INT32_MAX ? INT32_MAX : devId, &stPubAttr); +- CHECK_CALL_MPI_RET(ret, ss_mpi_vo_get_pub_attr); +- attr->display_rect.x = 0; +- attr->display_rect.y = 0; +- attr->display_rect.width = DEFAULT_WIDTH_FOR_HDMI; +- attr->display_rect.height = DEFAULT_HEIGHT_FOR_HDMI; +- attr->display_frame_rate = DEFAULT_DISPLAY_FPS; +- attr->cluster_mode_en = TD_FALSE; +- attr->double_frame_en = TD_FALSE; +- attr->pixel_format = PIXEL_FORMAT_YVU_SEMIPLANAR_420; +- attr->img_size.width = attr->display_rect.width; +- attr->img_size.height = attr->display_rect.height; +- attr->dst_dynamic_range = DYNAMIC_RANGE_SDR8; +- attr->display_buf_len = VIDEO_LAYER_BUFF_LEN; +- return 0; +-} +- +-static int32_t EnabelVoChannel(VO_LAYER voLayer, VO_CHN voChn, uint32_t width, uint32_t height) +-{ +- if (voChn >= OT_VO_MAX_CHN_NUM) { +- return DISPLAY_FAILURE; +- } +- VO_CHN_ATTR_S chnAttr; +- int32_t ret = ss_mpi_vo_get_chn_attr(voLayer, voChn, &chnAttr); +- if (ret != TD_SUCCESS) { +- HDF_LOGE("ss_mpi_vo_get_chn_attr failure, ret = 0x%x", ret); +- return ret; +- } +- +- chnAttr.rect.x = ALIGN_DOWN(0, BYTE_ALIGN_NUM); +- chnAttr.rect.y = ALIGN_DOWN(0, BYTE_ALIGN_NUM); +- chnAttr.rect.width = ALIGN_DOWN(width, BYTE_ALIGN_NUM); +- chnAttr.rect.height = ALIGN_DOWN(height, BYTE_ALIGN_NUM); +- chnAttr.deflicker_en = TD_FALSE; +- chnAttr.priority = 0; +- ret = ss_mpi_vo_set_chn_attr(voLayer, voChn, &chnAttr); +- if (ret != TD_SUCCESS) { +- HDF_LOGE("ss_mpi_vo_set_chn_attr failure, ret = 0x%x", ret); +- return ret; +- } +- ret = ss_mpi_vo_enable_chn(voLayer, voChn); +- if (ret != TD_SUCCESS) { +- HDF_LOGE("ss_mpi_vo_enable_chn failure, ret = 0x%x", ret); +- return ret; +- } +- +- return DISPLAY_SUCCESS; +-} +- +-static int32_t DisabelVoChannel(VO_LAYER voLayer, VO_CHN voChn) +-{ +- int32_t ret = ss_mpi_vo_disable_chn(voLayer, voChn); +- if (ret != TD_SUCCESS) { +- HDF_LOGE("Camera video output disable channel failed.(ret=0x%x)\n", ret); +- return DISPLAY_FAILURE; +- } +- return DISPLAY_SUCCESS; +-} +- +-int32_t OverlayLayerFlush(uint32_t devId, uint32_t layerId, LayerBuffer *buffer) +-{ +- CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); +- int32_t ret = DISPLAY_FAILURE; +- if (!CheckTypeIsOverlayLayer(layerId)) { +- HDF_LOGE("%s: layerId type is not overlay Layer", __func__); +- return ret; +- } +- +- uint8_t vochn = GetVoChn(layerId); +- if (vochn >= OVERLAY_LAYER_NUM) { +- HDF_LOGE("%s: layerId is out of range", __func__); +- return ret; +- } +- +- OverlayLayerPrivate *priv = GetLayerInstance(devId, vochn); +- if (buffer != NULL && buffer->data.virAddr != NULL) { +-#if defined(ENABLE_H8) +- ret = ss_mpi_vpss_send_frame(priv->vpssGrp, (ot_video_frame_info *)buffer->data.virAddr, 0); +-#else +- ret = ss_mpi_vpss_send_frame_ex(priv->vpssGrp, priv->vpssChn, (ot_video_frame_info *)buffer->data.virAddr, 0); +-#endif +- if (ret != TD_SUCCESS) { +- HDF_LOGE("Flush ret =0x%x\n", ret); +- } +- return ret; +- } +- return ret; +-} +- +-int32_t EnabelVideoLayer(uint32_t devId) +-{ +- CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); +- +- const VO_LAYER voLayer = OT_VO_LAYER_V0; +- VO_VIDEO_LAYER_ATTR_S layerAttr = {0}; +- int32_t ret = ss_mpi_vo_get_video_layer_attr(voLayer, &layerAttr); +- if (ret != 0) { +- HDF_LOGI("Camera video output get layer failed.(ret=0x%x)\n", ret); +- } +- +- // If the configuration is initialized first +- if (layerAttr.display_rect.width > 0 && layerAttr.display_rect.height > 0) { +- DisableVideoLayer(devId); +- } +- +- SetVoLayerParam(devId, &layerAttr); +- ret = ss_mpi_vo_set_video_layer_attr(voLayer, &layerAttr); +- if (ret != TD_SUCCESS) { +- HDF_LOGI("ss_mpi_vo_set_video_layer_attr failure, ret = 0x%x", ret); +- return DISPLAY_FAILURE; +- } +- +- ret = ss_mpi_vo_enable_video_layer(voLayer); +- if (ret != TD_SUCCESS) { +- HDF_LOGI("ss_mpi_vo_enable_video_layer failure, ret = 0x%x", ret); +- return DISPLAY_FAILURE; +- } +- +- VO_CSC_S stVideoCSC = {0}; +- ret = ss_mpi_vo_get_layer_csc(voLayer, &stVideoCSC); +- if (ret != TD_SUCCESS) { +- HDF_LOGI("ss_mpi_vo_get_layer_csc.(ret=0x%x)\n", ret); +- return DISPLAY_FAILURE; +- } +- +- stVideoCSC.csc_matrix = VO_CSC_MATRIX_IDENTITY; +- ret = ss_mpi_vo_set_layer_csc(voLayer, &stVideoCSC); +- if (ret != TD_SUCCESS) { +- HDF_LOGI("ss_mpi_vo_set_layer_csc.(ret=0x%x)\n", ret); +- return DISPLAY_FAILURE; +- } +- return DISPLAY_SUCCESS; +-} +- +-int32_t DisableVideoLayer(uint32_t devId) +-{ +- CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); +- +- int32_t ret = ss_mpi_vo_disable_video_layer((VO_LAYER)OT_VO_LAYER_V0); +- if (ret != TD_SUCCESS) { +- HDF_LOGI("%s: ss_mpi_vo_disable_video_layer failure, ret 0x%x", __func__, ret); +- } +- return DISPLAY_SUCCESS; +-} +- +-int32_t CreateOverlayLayer(uint32_t devId, const LayerInfo *layerInfo, uint32_t *layerId) +-{ +- CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); +- CHECK_NULLPOINTER_RETURN_VALUE(layerInfo, DISPLAY_NULL_PTR); +- CHECK_NULLPOINTER_RETURN_VALUE(layerId, DISPLAY_NULL_PTR); +- +- const VO_LAYER voLayer = OT_VO_LAYER_V0; +- for (int32_t index = 0; index < OVERLAY_LAYER_NUM; index++) { +- OverlayLayerPrivate *priv = GetLayerInstance(devId, index > UINT8_MAX ? UINT8_MAX : index); +- if (priv->voChn != -1) { +- continue; +- } +- +- VO_CHN voChn = index; +- int32_t ret = EnabelVoChannel(voLayer, voChn, layerInfo->width < 0 ? 0 : layerInfo->width, +- layerInfo->height < 0 ? 0 : layerInfo->height); +- if (ret != DISPLAY_SUCCESS) { +- HDF_LOGE("ss_mpi_vo_set_chn_attr failure, ret = 0x%x", ret); +- } +- +- if (layerInfo != NULL) { +- ret = OpenVpssRes(layerInfo, &priv->vpssGrp, &priv->vpssChn); +- if (ret == DISPLAY_SUCCESS) { +- BindVoVpss(priv->vpssGrp, priv->vpssChn, voLayer, voChn); +- priv->vpssIsInternalEnable = true; +- } +- } +-#if ENABLE_VO_TIME_TASK +- VoTimeTaskBegin(); +-#endif +- +-#if ENABLE_VO_BUSYDROP +- VoDropTaskBegin(); +-#endif +- priv->voChn = voChn; +- uint32_t voLayerUint32 = voLayer < 0 ? 0 : (uint32_t)voLayer; +- uint32_t voChnUint32 = voChn < 0 ? 0 : (uint32_t)voChn; +- *layerId = LAYER_ID_VO_LAYER_TYPE_MARK | (voLayerUint32 << VO_LAYER_OFFSET) | voChnUint32; +- return DISPLAY_SUCCESS; +- } +- HDF_LOGE("%s: no layer to open", __func__); +- return DISPLAY_FAILURE; +-} +- +-int32_t CloseOverlayLayer(uint32_t devId, uint32_t layerId) +-{ +- CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); +- if (!CheckTypeIsOverlayLayer(layerId)) { +- HDF_LOGE("%s: layerId type is not overlay Layer", __func__); +- return DISPLAY_FAILURE; +- } +- uint8_t vochn = GetVoChn(layerId); +- if (vochn >= OVERLAY_LAYER_NUM) { +- HDF_LOGE("%s: layerId is out of range", __func__); +- return DISPLAY_FAILURE; +- } +- +-#if ENABLE_VO_BUSYDROP +- VoDropTaskEnd(); +-#endif +- +-#if ENABLE_VO_TIME_TASK +- VoTimeTaskEnd(); +-#endif +- +- OverlayLayerPrivate *priv = GetLayerInstance(devId, vochn); +- if (priv->voChn == -1) { +- HDF_LOGE("%s: layerId error, layerId not create", __func__); +- return DISPLAY_FAILURE; +- } +- +- const VO_LAYER voLayer = OT_VO_LAYER_V0; +- if (priv->vpssGrp != -1 || priv->vpssChn != -1) { +- UnBindVoVpss(priv->vpssGrp, priv->vpssChn, voLayer, priv->voChn); +- if (priv->vpssIsInternalEnable) { +- CloseVpssRes(priv->vpssGrp, priv->vpssChn); +- priv->vpssGrp = -1; +- priv->vpssChn = -1; +- } +- } +- +- DisabelVoChannel(OT_VO_LAYER_V0, priv->voChn); +- priv->voChn = -1; +- return DISPLAY_SUCCESS; +-} +- +-int32_t SetOverlayLayerSize(uint32_t devId, uint32_t layerId, const IRect *rect) +-{ +- CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); +- CHECK_NULLPOINTER_RETURN_VALUE(rect, DISPLAY_NULL_PTR); +- if (!CheckTypeIsOverlayLayer(layerId)) { +- HDF_LOGE("%s: layerId type is not overlay Layer", __func__); +- return DISPLAY_FAILURE; +- } +- uint8_t vochn = GetVoChn(layerId); +- if (vochn >= OVERLAY_LAYER_NUM) { +- HDF_LOGE("%s: layerId is out of range", __func__); +- return DISPLAY_FAILURE; +- } +- const VO_LAYER voLayer = GetVoLayer(layerId); +- +- VO_CHN_ATTR_S chnAttr = {0}; +- int32_t ret = ss_mpi_vo_get_chn_attr(voLayer, vochn, &chnAttr); +- CHECK_CALL_MPI_RET(ret, ss_mpi_vo_get_chn_attr); +- +- IRect displayRect = {0}; +- displayRect.x = ALIGN_DOWN(rect->x, ALIGN_DOWN_NUM); +- displayRect.y = ALIGN_DOWN(rect->y, ALIGN_DOWN_NUM); +- displayRect.w = ALIGN_DOWN(rect->w, ALIGN_DOWN_NUM); +- displayRect.h = ALIGN_DOWN(rect->h, ALIGN_DOWN_NUM); +- if (displayRect.x != chnAttr.rect.x || displayRect.y != chnAttr.rect.y || +- displayRect.w != (int32_t)chnAttr.rect.width || displayRect.h != (int32_t)chnAttr.rect.height) { +- chnAttr.rect.x = displayRect.x; +- chnAttr.rect.y = displayRect.y; +- chnAttr.rect.width = displayRect.w < 0 ? 0 : (td_u32)displayRect.w; +- chnAttr.rect.height = displayRect.h < 0 ? 0 : (td_u32)displayRect.h; +- HDF_LOGI("set display rect (%d, %d, %u, %u)", chnAttr.rect.x, chnAttr.rect.y, chnAttr.rect.width, +- chnAttr.rect.height); +- ret = ss_mpi_vo_set_chn_attr(voLayer, vochn, &chnAttr); +- CHECK_CALL_MPI_RET(ret, ss_mpi_vo_set_chn_attr); +- } +- +- return DISPLAY_SUCCESS; +-} +- +-static int32_t OverlayLayerCmdVoBindVpss(uint32_t devId, uint8_t index, VPSS_GRP vpssGrp, VPSS_CHN vpssChn) +-{ +- OverlayLayerPrivate *priv = GetLayerInstance(devId, index); +- const VO_LAYER voLayer = OT_VO_LAYER_V0; +- if (priv->vpssGrp != -1 && priv->vpssChn != -1) { +- UnBindVoVpss(priv->vpssGrp, priv->vpssChn, voLayer, priv->voChn); +- if (priv->vpssIsInternalEnable) { +- CloseVpssRes(priv->vpssGrp, priv->vpssChn); +- priv->vpssIsInternalEnable = false; +- priv->vpssGrp = -1; +- priv->vpssChn = -1; +- } +- } +- BindVoVpss(vpssGrp, vpssChn, voLayer, index); +- return DISPLAY_SUCCESS; +-} +- +-static int32_t OverlayLayerCmdVoUnBindVpss(uint32_t devId, uint8_t index, VPSS_GRP vpssGrp, VPSS_CHN vpssChn) +-{ +- OverlayLayerPrivate *priv = GetLayerInstance(devId, index); +- const VO_LAYER voLayer = OT_VO_LAYER_V0; +- if (priv->vpssGrp == vpssGrp && priv->vpssChn == vpssChn) { +- UnBindVoVpss(priv->vpssGrp, priv->vpssChn, voLayer, priv->voChn); +- if (priv->vpssIsInternalEnable) { +- CloseVpssRes(priv->vpssGrp, priv->vpssChn); +- priv->vpssIsInternalEnable = false; +- } +- priv->vpssGrp = -1; +- priv->vpssChn = -1; +- } else { +- UnBindVoVpss(vpssGrp, vpssChn, voLayer, priv->voChn); +- } +- return DISPLAY_SUCCESS; +-} +- +-static int32_t OverlayLayerCmdVdecVpss(uint32_t devId, uint8_t index, ot_vdec_chn vdecChn, bool isBind) +-{ +- OverlayLayerPrivate *priv = GetLayerInstance(devId, index); +- ot_mpp_chn srcChn; +- ot_mpp_chn destChn; +- +- srcChn.mod_id = OT_ID_VDEC; +- srcChn.dev_id = 0; +- srcChn.chn_id = vdecChn; +- +- destChn.mod_id = OT_ID_VPSS; +- destChn.dev_id = priv->vpssGrp; +- destChn.chn_id = priv->vpssChn; +- +- int32_t ret = DISPLAY_FAILURE; +- if (isBind) { +- ret = ss_mpi_sys_bind(&srcChn, &destChn); +- CHECK_CALL_MPI_RET(ret, ss_mpi_sys_bind); +- HDF_LOGI("bind vdec&vpss success, vpssGrp=%d vpssChn=%d vdecChn=%d", priv->vpssGrp, priv->vpssChn, vdecChn); +- } else { +- ret = ss_mpi_sys_unbind(&srcChn, &destChn); +- CHECK_CALL_MPI_RET(ret, ss_mpi_sys_unbind); +- HDF_LOGI("unbind vdec&vpss success, vpssGrp=%d vpssChn=%d vdecChn=%d", priv->vpssGrp, priv->vpssChn, vdecChn); +- } +- return ret; +-} +- +-int32_t InvokeOverlayLayerCmd(uint32_t devId, uint32_t layerId, uint32_t cmd, ...) +-{ +- CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); +- if (cmd > OVERLAYER_CMD_MAX) { +- HDF_LOGE("%s: not support cmd 0x%x\n", __func__, cmd); +- return DISPLAY_FAILURE; +- } +- if (!CheckTypeIsOverlayLayer(layerId)) { +- HDF_LOGE("%s: layerId type is not overlay Layer", __func__); +- return DISPLAY_FAILURE; +- } +- uint8_t vochn = GetVoChn(layerId); +- if (vochn >= OVERLAY_LAYER_NUM) { +- HDF_LOGE("%s: layerId is out of range", __func__); +- return DISPLAY_FAILURE; +- } +- +- va_list vl; +- va_start(vl, cmd); +- int32_t ret = DISPLAY_FAILURE; +- VPSS_CHN vpssChn; +- VPSS_GRP vpssGroup; +- ot_vdec_chn vdecChn; +- switch (cmd) { +- case OVERLAYER_CMD_VO_BIND_VPSS: +- vpssChn = va_arg(vl, int32_t); +- vpssGroup = va_arg(vl, int32_t); +- ret = OverlayLayerCmdVoBindVpss(devId, vochn, vpssGroup, vpssChn); +- break; +- case OVERLAYER_CMD_VO_UNBIND_VPSS: +- vpssChn = va_arg(vl, int32_t); +- vpssGroup = va_arg(vl, int32_t); +- ret = OverlayLayerCmdVoUnBindVpss(devId, vochn, vpssGroup, vpssChn); +- break; +- case OVERLAYER_CMD_VPSS_BING_VDEC: +- vdecChn = va_arg(vl, int32_t); +- ret = OverlayLayerCmdVdecVpss(devId, vochn, vdecChn, true); +- break; +- case OVERLAYER_CMD_VPSS_UNBING_VDEC: +- vdecChn = va_arg(vl, int32_t); +- ret = OverlayLayerCmdVdecVpss(devId, vochn, vdecChn, false); +- break; +- default: +- break; +- } +- va_end(vl); +- return ret; +-} +- +-int32_t GetOverlayLayerDeviceId(uint32_t devId, uint32_t layerId, uint32_t *deviceId) +-{ +- if (deviceId == NULL) { +- return DISPLAY_FAILURE; +- } +- CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); +- if (!CheckTypeIsOverlayLayer(layerId)) { +- HDF_LOGE("%s: layerId type is not overlay Layer", __func__); +- return DISPLAY_FAILURE; +- } +- +- uint8_t vochn = GetVoChn(layerId); +- if (vochn >= OVERLAY_LAYER_NUM) { +- HDF_LOGE("%s: layerId is out of range", __func__); +- return DISPLAY_FAILURE; +- } +- +- OverlayLayerPrivate *priv = GetLayerInstance(devId, vochn); +- uint32_t vpssGrpUint32 = priv->vpssGrp < 0 ? 0 : (uint32_t)priv->vpssGrp; +- uint32_t vpssChnUint32 = priv->vpssChn < 0 ? 0 : (uint32_t)priv->vpssChn; +- *deviceId = (((OT_ID_VPSS << 0x10) & 0xff0000) + ((vpssGrpUint32 << OFFSET_8) & 0xff00) + +- (vpssChnUint32 & 0xff)); // 8: offset +- HDF_LOGI("GetOverlayLayerDeviceId (%u)", *deviceId); +- return DISPLAY_SUCCESS; +-} ++/* ++ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. ++ * ++ * 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. ++ */ + -+int32_t SetOverlayLayerPriority(uint32_t priority) ++#include "display_overlay_layer.h" ++#include "display_adapt_video.h" ++#include "display_adapt_vo.h" ++#include "display_adapt_sys.h" ++ ++#if defined(ENABLE_H8) || defined(ENABLE_H9) ++#include "ot_math.h" ++#define ALIGN_DOWN OT_ALIGN_DOWN ++#else ++#include "hi_math.h" ++#endif ++#include ++#include ++#include ++#include "vpss_resmng.h" ++ ++#define ALIGN_DOWN_NUM 2 ++#define DISPLAY_LAYER_INVALID_ID (-1) ++#define VO_BUFF_LEN 3 ++#define LAYER_IDX_OFFSET 24 ++#define VO_DEV_OFFSET 16 ++#define VO_LAYER_OFFSET 8 ++#define INVALID_ID (-1U) ++#define UNUSED_ATTR __attribute__((unused)) ++#define DISPLAY_LAYER_MAX_NUM 64 ++ ++#ifdef ENABLE_MULTI_DISP_CHN ++#define DISPLAY_CNT 2 // Two CHNs need to be initialized for dual-camera display ++#else ++#define DISPLAY_CNT 1 ++#endif ++ ++/* default layer width */ ++#define DEFAULT_WIDTH_FOR_HDMI 1920 ++#define DEFAULT_WIDTH_FOR_LCD 480 ++/* default layer height */ ++#define DEFAULT_HEIGHT_FOR_HDMI 1080 ++#define DEFAULT_HEIGHT_FOR_LCD 960 ++#define DEFAULT_DISPLAY_FPS 60 ++#define DEFAULT_SET_FPS 30 ++#define OVERLAY_LAYER_NUM ((OV_LAYER_MAX) - (GRA_LAYER_MAX)) ++#define OFFSET_8 8 ++ ++#if ENABLE_VO_TIME_TASK ++#define CNT 1000 ++static pthread_t g_voThread = 0; ++static bool g_voRunning = false; ++#endif ++ ++#if ENABLE_VO_BUSYDROP ++static pthread_t g_voDropThread = 0; ++static bool g_voDropRunning = false; ++#endif ++ ++typedef struct { ++ VO_CHN voChn; ++ VPSS_GRP vpssGrp; ++ VPSS_CHN vpssChn; ++ bool vpssIsInternalEnable; ++} OverlayLayerPrivate; ++ ++static bool CheckTypeIsOverlayLayer(uint32_t layerId) +{ -+ const VO_LAYER voLayer = OT_VO_LAYER_V0; -+ HDF_LOGI("SetOverlayLayerPriority priority = %d", priority); -+ ss_mpi_vo_set_layer_priority(voLayer, priority); ++ return (layerId & LAYER_ID_VO_LAYER_TYPE_MARK) != 0; ++} ++ ++static uint8_t GetVoChn(uint32_t layerId) ++{ ++ return (uint8_t)layerId & LAYER_ID_VO_CHN_MASK; ++} ++ ++static uint8_t GetVoLayer(uint32_t layerId) ++{ ++ return (uint8_t)((layerId & LAYER_ID_VO_LAYER_ID_MASK) >> VO_LAYER_OFFSET); ++} ++ ++static OverlayLayerPrivate *GetLayerInstance(uint32_t devId, uint8_t index) ++{ ++ static OverlayLayerPrivate layerPriv[DEV_ID_NUM][OVERLAY_LAYER_NUM] = {{ ++ { ++ .voChn = -1, ++ .vpssGrp = -1, ++ .vpssChn = -1, ++ }, { ++ .voChn = -1, ++ .vpssGrp = -1, ++ .vpssChn = -1, ++ }, { ++ .voChn = -1, ++ .vpssGrp = -1, ++ .vpssChn = -1, ++ }, { ++ .voChn = -1, ++ .vpssGrp = -1, ++ .vpssChn = -1, ++ } ++ }}; ++ return &layerPriv[devId][index]; ++} ++ ++static int32_t BindVoVpss(VPSS_GRP vpssGrp, VPSS_CHN vpssChn, VO_LAYER voLayer, VO_CHN voChn) ++{ ++ MPP_CHN_S stSrcChn; ++ MPP_CHN_S stDestChn; ++ stSrcChn.mod_id = HI_ID_VPSS; ++ stSrcChn.dev_id = vpssGrp; ++ stSrcChn.chn_id = vpssChn; ++ ++ stDestChn.mod_id = HI_ID_VO; ++ stDestChn.dev_id = voLayer; ++ stDestChn.chn_id = voChn; ++ int32_t ret = ss_mpi_sys_bind(&stSrcChn, &stDestChn); ++ CHECK_CALL_MPI_RET(ret, ss_mpi_sys_bind); ++ HDF_LOGI("bind vo & vpss success, vpssGrp=%d vpssChn=%d voLayer=%d voChn=%d", vpssGrp, vpssChn, voLayer, voChn); + return DISPLAY_SUCCESS; +} -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/display/ss928/src/hdmi.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/display/ss928/src/hdmi.c ---- ohos/device/soc/hisilicon/common/hal/display/ss928/src/hdmi.c 2025-11-07 16:00:38.069503405 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/display/ss928/src/hdmi.c 2025-11-07 14:44:54.873657233 +0800 -@@ -33,7 +33,8 @@ static void SetHdmiParam(HI_HDMI_ATTR_S - attr->hdmi_en = TD_TRUE; - attr->video_format = HI_HDMI_VIDEO_FMT_1080P_60; - attr->deep_color_mode = HI_HDMI_DEEP_COLOR_24BIT; -- attr->audio_en = TD_FALSE; -+ attr->audio_en = TD_TRUE; -+ attr->sample_rate = OT_HDMI_SAMPLE_RATE_48K; - attr->bit_depth = HI_HDMI_BIT_DEPTH_16; - #ifndef ENABLE_H8 - attr->bEnableVideo = TD_TRUE; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_effect_manager/audio_effect_manager.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_effect_manager/audio_effect_manager.c ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_effect_manager/audio_effect_manager.c 2025-11-07 16:00:38.073503378 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_effect_manager/audio_effect_manager.c 2025-11-07 14:44:54.873657233 +0800 -@@ -129,9 +129,6 @@ static int32_t SetDeviceAndChannelId(Aud - - struct InvokeAttr paramAttr = {}; - paramAttr.request = (void *)keyValuePair; -- if (trackHandle == NULL || trackHandle->Invoke == NULL) { -- return MEDIA_HAL_ERR; -- } - ret = trackHandle->Invoke(trackHandle, INVOKE_ID_SET_EXTRA_PARAMS, ¶mAttr); - if (ret != MEDIA_HAL_OK) { - MEDIA_HAL_LOGE(MODULE_NAME, "audio input port set extra param failed: 0x%x", ret); -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.c ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.c 2025-11-07 16:00:38.073503378 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.c 2025-11-07 14:44:54.873657233 +0800 -@@ -104,7 +104,7 @@ static int32_t PrimaryPortOpen(AudioHand - static bool AudioPluginIsValidPin(enum AudioPortPin pin, const char *pluginName) - { - if (strcmp("primary", pluginName) == 0) { -- if (pin == PIN_IN_MIC || pin == PIN_OUT_SPEAKER) { -+ if (pin == PIN_IN_MIC || pin == PIN_OUT_SPEAKER || pin == PIN_OUT_HDMI) { - return true; - } - } -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.h ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.h ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.h 2025-11-07 16:00:38.073503378 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.h 2025-11-07 14:44:54.873657233 +0800 -@@ -19,4 +19,6 @@ - #ifndef PRIMARY_PORT_PLUGIN_H - #define PRIMARY_PORT_PLUGIN_H - -+#include "audio_port_plugin.h" + - #endif -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin_common/src/audio_port_plugin_common.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin_common/src/audio_port_plugin_common.c ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin_common/src/audio_port_plugin_common.c 2025-11-07 16:00:38.073503378 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin_common/src/audio_port_plugin_common.c 2025-11-07 14:44:54.873657233 +0800 -@@ -126,7 +126,9 @@ int32_t AudioAcodecInit(ot_audio_sample_ - AUDIO_OSAL_CLOSE(fdAcodec); - return MEDIA_HAL_ERR; - } -- ot_acodec_mixer inputMode = OT_ACODEC_MIXER_IN1; -+ // select acodec input_mode to IN_D , stereo mode -+ // ot_acodec_mixer inputMode = OT_ACODEC_MIXER_IN1; -+ ot_acodec_mixer inputMode = OT_ACODEC_MIXER_IN_D; - if (AUDIO_OSAL_IOCTL(fdAcodec, OT_ACODEC_SET_MIXER_MIC, &inputMode)) { - MEDIA_HAL_LOGE(MODULE_NAME, "select acodec input_mode failed"); - AUDIO_OSAL_CLOSE(fdAcodec); -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_in/audio_primary_sub_port_in.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_in/audio_primary_sub_port_in.c ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_in/audio_primary_sub_port_in.c 2025-11-07 16:00:38.073503378 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_in/audio_primary_sub_port_in.c 2025-11-07 14:44:54.873657233 +0800 -@@ -454,14 +454,23 @@ static int32_t AudioPrimarySubPortInSetE - return MEDIA_HAL_OK; - } - --static int32_t DualMono2Stereo(const int16_t *leftChnData, const int16_t *rightChnData, -- int16_t sampleNumPerChn, int16_t *stereoData) -+int32_t DualMono2Stereo(char *audioData, char *audioLeft, -+ char *audioRight, uint32_t audioLen) - { -- for (int32_t i = 0; i < sampleNumPerChn; i++) { -- /* Mono to Stereo */ -- stereoData[AUDIO_STEREO_SOUND_MODE_CHN_CNT * i] = leftChnData[i]; -- stereoData[(AUDIO_STEREO_SOUND_MODE_CHN_CNT * i) + 1] = rightChnData[i]; -+ if (audioData == NULL || audioLeft == NULL || audioRight == NULL) { -+ return -1; - } -+ uint32_t i, j; -+ uint32_t framesize = 2; -+ uint32_t signleDataLen = audioLen / 2; ++static int32_t UnBindVoVpss(VPSS_GRP vpssGrp, VPSS_CHN vpssChn, VO_LAYER voLayer, VO_CHN voChn) ++{ ++ MPP_CHN_S stSrcChn; ++ stSrcChn.mod_id = HI_ID_VPSS; ++ stSrcChn.dev_id = vpssGrp; ++ stSrcChn.chn_id = vpssChn; ++ ++ MPP_CHN_S stDestChn; ++ stDestChn.mod_id = HI_ID_VO; ++ stDestChn.dev_id = voLayer; ++ stDestChn.chn_id = voChn; ++ int32_t ret = ss_mpi_sys_unbind(&stSrcChn, &stDestChn); ++ HDF_LOGI("unbind vo & vpss success, vpssGrp=%d vpssChn=%d voLayer=%d voChn=%d", vpssGrp, vpssChn, voLayer, voChn); ++ CHECK_CALL_MPI_RET(ret, ss_mpi_sys_unbind); + -+ for (i = 0; i < signleDataLen; i += framesize) { -+ for (j = 0; j < framesize; j++) { -+ audioData[2 * i + j] = audioLeft[i + j]; -+ audioData[2 * i + framesize + j] = audioRight[i + j]; ++ return DISPLAY_SUCCESS; ++} ++ ++#if ENABLE_VO_BUSYDROP ++static int32_t sample_comm_vdec_clear_vo_busybuf(td_void) ++{ ++ for (int32_t index = 0; index < OVERLAY_LAYER_NUM; index++) { ++ int32_t ret; ++ ot_vo_layer layer = 0; ++ ot_vo_chn_status status; ++ td_bool is_clear_all = TD_FALSE; ++ ret = ss_mpi_vo_query_chn_status(layer, index, &status); ++ if (ret != TD_SUCCESS) { ++ return TD_FAILURE; ++ } ++ if (status.chn_busy_num >= 2) { // 2:busy_num ++ ret = ss_mpi_vo_clear_chn_buf(layer, index, is_clear_all); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGE("Clear channel %d buf failed with errno %#x!\n", index, ret); ++ return TD_FAILURE; ++ } + } + } + - return MEDIA_HAL_OK; - } - -@@ -849,10 +858,10 @@ int32_t AudioPrimarySubPortInAcquireFram - MEDIA_HAL_LOGE(MODULE_NAME, "audio capture input buffer too small"); - return MEDIA_HAL_INVALID_PARAM; - } -- uint32_t sampleNum = stAudioFrm.len / (portTrackInCtx->aiAttr.bit_width + 1); - if (portTrackInCtx->aiAttr.snd_mode == OT_AUDIO_SOUND_MODE_STEREO) { -- DualMono2Stereo((int16_t *)stAudioFrm.virt_addr[0], (int16_t *)stAudioFrm.virt_addr[1], sampleNum, -- (int16_t *)buffer); -+ // The hardware does not support dual channels, so the mono data is copied to dual channels. -+ DualMono2Stereo(buffer, (char *)stAudioFrm.virt_addr[0], -+ (char *)stAudioFrm.virt_addr[1], *replyBytes); - } else if (portTrackInCtx->aiAttr.snd_mode == OT_AUDIO_SOUND_MODE_MONO) { - if (memcpy_s(buffer, requestBytes, stAudioFrm.virt_addr[0], stAudioFrm.len) != EOK) { - MEDIA_HAL_LOGE(MODULE_NAME, "memcpy_s ot_audio_frame failed"); -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_out/audio_primary_sub_port_out.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_out/audio_primary_sub_port_out.c ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_out/audio_primary_sub_port_out.c 2025-11-07 16:00:38.073503378 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_out/audio_primary_sub_port_out.c 2025-11-07 14:44:54.873657233 +0800 -@@ -77,6 +77,7 @@ struct AudioSubPortOut { - bool mute; - ot_aio_attr aoSourceAttr; - ot_audio_dev aoDeviceId; -+ ot_audio_dev aoHDMIDeviceId; - bool aoEnabled; - struct AudioSubPortOutTrack *hwOutputPortTrack[MAX_OUTPUT_PORT_TRACK_CNT]; - pthread_mutex_t mutex; -@@ -131,6 +132,8 @@ static int32_t AudioOutputPortMngGetFree - return MEDIA_HAL_ERR; - } - for (int32_t i = 0; i < MAX_OUTPUT_PORT_CNT; i++) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "MAX_OUTPUT_PORT_CNT %d, g_audioHwOutputPorts[i].used = %d, chnID = %d", -+ MAX_OUTPUT_PORT_CNT, g_audioHwOutputPorts[i].used, g_audioHwOutputPorts[i].chnID); - if (!g_audioHwOutputPorts[i].used) { - g_audioHwOutputPorts[i].used = true; - int32_t chnID = g_audioHwOutputPorts[i].chnID; -@@ -238,7 +241,7 @@ AO_DISABLE: - return ret; - } - --static int32_t AoSourceAttrConfig(struct PortPluginAttr *portAttr, ot_aio_attr *aoSourceAttr) -+static int32_t AoSourceAttrConfig(struct PortPluginAttr *portAttr, ot_aio_attr *aoSourceAttr, enum AudioPortPin audioPortPin) - { - if (memset_s(aoSourceAttr, sizeof(ot_aio_attr), 0x0, sizeof(ot_aio_attr)) != EOK) { - MEDIA_HAL_LOGE(MODULE_NAME, "memset_s: hwOutputPort aoAttr failed"); -@@ -259,20 +262,28 @@ static int32_t AoSourceAttrConfig(struct - aoSourceAttr->frame_num = AUDIO_FRAME_NUM_OUT_BUF; - aoSourceAttr->point_num_per_frame = AUDIO_OUT_PTNUMPERFRM; - aoSourceAttr->clk_share = 0; -- aoSourceAttr->i2s_type = OT_AIO_I2STYPE_INNERCODEC; -+ if(audioPortPin == PIN_OUT_HDMI) { -+ aoSourceAttr->i2s_type = OT_AIO_I2STYPE_INNERHDMI; -+ } else if(audioPortPin == PIN_OUT_SPEAKER){ -+ aoSourceAttr->i2s_type = OT_AIO_I2STYPE_INNERCODEC; ++ return TD_SUCCESS; ++} ++ ++static void *VoDropTask(void *args) ++{ ++ (void)args; ++ while (g_voDropThread && g_voDropRunning) { ++ sample_comm_vdec_clear_vo_busybuf(); ++ struct timespec ts; ++ ts.tv_sec = 0; ++ ts.tv_nsec = 1 * 1000 * 1000; // 1000: ns to ms ++ nanosleep(&ts, TD_NULL); + } - return MEDIA_HAL_OK; - } - --static int32_t ConfigAndEnableAO(AudioHandle portHandle, struct PortPluginAttr *portAttr) -+static int32_t ConfigAndEnableAO(AudioHandle portHandle, struct PortPluginAttr *portAttr, enum AudioPortPin audioPortPin) - { - struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; -- int32_t ret = AoSourceAttrConfig(portAttr, &hwPortCtx->aoSourceAttr); -+ int32_t ret = AoSourceAttrConfig(portAttr, &hwPortCtx->aoSourceAttr, audioPortPin); - if (ret != MEDIA_HAL_OK) { - MEDIA_HAL_LOGE(MODULE_NAME, "ConfigAoSourceAttr failed"); - return ret; - } - ot_aio_attr aoAttr = hwPortCtx->aoSourceAttr; -- ret = AoInit(hwPortCtx->aoDeviceId, &aoAttr); -+ if(audioPortPin == PIN_OUT_HDMI) { -+ ret = AoInit(hwPortCtx->aoHDMIDeviceId, &aoAttr); -+ } else if(audioPortPin == PIN_OUT_SPEAKER){ -+ ret = AoInit(hwPortCtx->aoDeviceId, &aoAttr); ++ HDF_LOGI(" VoDropTask exit\n"); ++ return NULL; ++} ++ ++static void VoDropTaskBegin() ++{ ++ if (g_voDropThread == 0) { ++ g_voDropRunning = true; ++ int32_t ret = pthread_create(&g_voDropThread, NULL, VoDropTask, NULL); ++ if (ret != 0) { ++ g_voDropRunning = false; ++ g_voDropThread = 0; ++ HDF_LOGI("creat vo drop thread failed %d \n", ret); ++ return; ++ } ++ HDF_LOGI("creat vo drop thread = %d \n", ret); + } - if (ret != MEDIA_HAL_OK) { - MEDIA_HAL_LOGE(MODULE_NAME, "AoInit failed %#x", ret); - return ret; -@@ -301,7 +312,14 @@ int32_t AudioPrimarySubPortOutOpen(Audio - if (memset_s(hwOutputPort, sizeof(struct AudioSubPortOut), 0, sizeof(struct AudioSubPortOut)) != EOK) { - MEDIA_HAL_LOGE(MODULE_NAME, "memset_s AudioSubPortOut failed"); - } -- hwOutputPort->aoDeviceId = portIndex; -+ hwOutputPort->aoDeviceId = portIndex;// 0:speaker, 1:hdmi ++} + -+ portIndex = AudioOutputPortMngGetFreeChn(); -+ if (portIndex == -1) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "can not found free Output Port"); -+ return MEDIA_HAL_INVALID_PARAM; ++static void VoDropTaskEnd() ++{ ++ if (g_voDropThread != 0) { ++ g_voDropRunning = false; ++ pthread_join(g_voDropThread, NULL); ++ g_voDropThread = 0; + } -+ hwOutputPort->aoHDMIDeviceId = portIndex;// 1:hdmi - pthread_mutex_init(&hwOutputPort->mutex, NULL); - hwOutputPort->opened = true; - *portHandle = hwOutputPort; -@@ -318,7 +336,11 @@ int32_t AudioPrimarySubPortOutClose(Audi - if (hwPortCtx->aoEnabled) { - ret = ss_mpi_ao_disable(hwPortCtx->aoDeviceId); - if (ret != MEDIA_HAL_OK) { -- MEDIA_HAL_LOGE(MODULE_NAME, "ss_mpi_ao_disable fail,ret:0x%x", ret); -+ MEDIA_HAL_LOGE(MODULE_NAME, "aoDeviceId ss_mpi_ao_disable fail,ret:0x%x", ret); ++} ++#endif ++ ++#if ENABLE_VO_TIME_TASK ++static void *VoTimeTask(void *args) ++{ ++ (void)args; ++ VIDEO_FRAME_INFO_S videoFrame = {0}; ++ td_u64 curPTS = 0; ++ td_u64 dl[CNT] = {0}; ++ td_u64 lastPts = 0; ++ HDF_LOGI(" VoTimeTask enter\n"); ++ int32_t i = 0; ++ while (i < CNT && g_voRunning) { ++ int32_t ret = ss_mpi_vo_get_screen_frame(0, &videoFrame, 0x3E8); /* 1000ms */ ++ if (ret != TD_SUCCESS) { ++ continue; + } -+ ret = ss_mpi_ao_disable(hwPortCtx->aoHDMIDeviceId); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "aoHDMIDeviceId ss_mpi_ao_disable fail,ret:0x%x", ret); - } - hwPortCtx->aoEnabled = false; - } -@@ -326,6 +348,10 @@ int32_t AudioPrimarySubPortOutClose(Audi - if (ret != MEDIA_HAL_OK) { - MEDIA_HAL_LOGE(MODULE_NAME, "AudioOutputPortMngFreeChn failed"); - } -+ ret = AudioOutputPortMngFreeChn(hwPortCtx->aoHDMIDeviceId); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AudioOutputPortMngFreeChn failed"); ++ ret = ss_mpi_sys_get_cur_pts(&curPTS); ++ if (ret == TD_SUCCESS) { ++ dl[i] = curPTS - videoFrame.video_frame.pts; ++ if (lastPts != videoFrame.video_frame.pts) { ++ lastPts = videoFrame.video_frame.pts; ++ i++; ++ } ++ } ++ ss_mpi_vo_release_screen_frame(0, &videoFrame); ++ if (memset_s(&videoFrame, sizeof(videoFrame), 0, sizeof(videoFrame)) != EOK) { ++ HDF_LOGI("memset_s videoFrame failed\n"); ++ } ++ struct timespec ts; ++ ts.tv_sec = 0; ++ ts.tv_nsec = 1 * 1000 * 1000; // 1000: ns to ms ++ nanosleep(&ts, TD_NULL); + } - AudioAcodecDeInit(); - pthread_mutex_destroy(&hwPortCtx->mutex); - hwPortCtx->opened = false; -@@ -793,7 +819,7 @@ int32_t AudioPrimarySubPortOutCreateTrac - return MEDIA_HAL_INVALID_PARAM; - } - -- if (!hwPortCtx->aoEnabled && (ConfigAndEnableAO(portHandle, portAttr) != MEDIA_HAL_OK)) { -+ if (!hwPortCtx->aoEnabled && (ConfigAndEnableAO(portHandle, portAttr, audioPortPin) != MEDIA_HAL_OK)) { - MEDIA_HAL_LOGE(MODULE_NAME, "config and anable AO failed"); - return MEDIA_HAL_INIT_FAIL; - } -@@ -808,7 +834,11 @@ int32_t AudioPrimarySubPortOutCreateTrac - } - hwOutputPortTrack->aoSourceAttr = hwPortCtx->aoSourceAttr; - SubPortTrackOutLoadImpl(hwOutputPortTrack, portAttr, audioPortPin); -- hwOutputPortTrack->aoDeviceId = hwPortCtx->aoDeviceId; -+ if (audioPortPin == PIN_OUT_HDMI) { -+ hwOutputPortTrack->aoDeviceId = hwPortCtx->aoHDMIDeviceId; -+ } else if (audioPortPin == PIN_OUT_SPEAKER) { -+ hwOutputPortTrack->aoDeviceId = hwPortCtx->aoDeviceId; ++ HDF_LOGI(" VoTimeTask exit\n"); ++ if (i < CNT) { ++ return NULL; + } - hwOutputPortTrack->aoChn = trackIndex; - hwOutputPortTrack->vqeScene = VQE_SCENE_NONE; - hwOutputPortTrack->inited = true; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/Makefile ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/Makefile ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/Makefile 2025-11-07 16:00:38.073503378 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/Makefile 2025-11-03 15:43:47.971951415 +0800 -@@ -6,6 +6,7 @@ MODNAME := - ifeq ($(strip $(CFG_CHIP_TYPE)),$(filter $(CFG_CHIP_TYPE),hi3518ev300 hi3516dv300 hispark_ss927v100 hispark_ss928v100)) - # $(warning "the value of CFG_CHIP_TYPE is $(CFG_CHIP_TYPE)") - MODNAME += $(shell test -d hi35xx && echo hi35xx) -+MODNAME += $(shell test -d ss928_usb && echo ss928_usb) - else ifeq ($(strip $(CFG_CHIP_TYPE)),$(filter $(CFG_CHIP_TYPE),hi3862v100)) - MODNAME += $(shell test -d iot/audio_input_port_plugin && echo iot/audio_input_port_plugin) - MODNAME += $(shell test -d iot/audio_output_port_plugin && echo iot/audio_output_port_plugin) -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/plugin_include/audio_port_plugin.h ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/plugin_include/audio_port_plugin.h ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/plugin_include/audio_port_plugin.h 2025-11-07 16:00:38.073503378 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/plugin_include/audio_port_plugin.h 2025-11-07 14:44:54.873657233 +0800 -@@ -94,7 +94,9 @@ struct PortPluginAttr { - */ - typedef enum { - AUDIO_PLUGIN_PRIMARY = 0x1u, /* Primary plugin */ -- AUDIO_PLUGIN_BLUETOOTH = 0x2u, /* Bluetooth plugin */ -+ AUDIO_PLUGIN_HDMI = 0x2u, /* HDMI plugin */ -+ AUDIO_PLUGIN_USB = 0x3u, /* USB plugin */ -+ AUDIO_PLUGIN_BLUETOOTH = 0x10u, /* Bluetooth plugin */ - AUDIO_PLUGIN_NONE, - } AudioPluginType; - -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.c ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.c 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.c 2025-11-07 14:44:54.873657233 +0800 -@@ -0,0 +1,272 @@ -+ /* -+ * Copyright (c) 2024 RKH Corp. -+ * 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. -+ */ -+ -+#include "audio_usb_port_plugin.h" -+ -+#include -+#include "securec.h" -+#include -+#include "audio_usb_sub_port_in.h" -+#include "audio_usb_sub_port_out.h" ++ td_u64 total = 0; ++ for (i = 0; i < CNT; i++) { ++ if (i % 0x32 == 0) { /* 50 */ ++ HDF_LOGI(" vo screen = %llu \n", dl[i]); ++ } ++ total += dl[i]; ++ } ++ HDF_LOGI(" vo screen avg = %llu\n", total / CNT); ++ return NULL; ++} + -+#include "media_hal_common.h" -+#include "audio_port_plugin_common.h" ++static void VoTimeTaskBegin(void) ++{ ++ if (g_voThread == 0) { ++ g_voRunning = true; ++ int32_t ret = pthread_create(&g_voThread, NULL, VoTimeTask, NULL); ++ if (ret != 0) { ++ g_voRunning = false; ++ g_voThread = 0; ++ HDF_LOGI("creat vo thread failed %d \n", ret); ++ return; ++ } ++ HDF_LOGI("creat vo thread = %d \n", ret); ++ } ++} + -+#ifdef __cplusplus -+#if __cplusplus -+extern "C" { ++static void VoTimeTaskEnd(void) ++{ ++ if (g_voThread != 0) { ++ g_voRunning = false; ++ pthread_join(g_voThread, NULL); ++ g_voThread = 0; ++ } ++} +#endif -+#endif /* __cplusplus */ -+ -+#define MODULE_NAME "AudioUsbPortPlugin" -+ -+typedef struct { -+ /* sub port track context */ -+ AudioHandle subPortTrackHandle; -+} UsbPortTrackContext; + -+typedef struct { -+ /* port context */ -+ bool isOpened; -+ int card_usb_num; -+ /* sub port context */ -+ AudioHandle subPortInHandle; -+ AudioHandle subPortOutHandle; -+} UsbPortContext; ++static int32_t SetVoLayerParam(uint32_t devId, VO_VIDEO_LAYER_ATTR_S *attr) ++{ ++ VO_PUB_ATTR_S stPubAttr = {0}; ++ int32_t ret = ss_mpi_vo_get_pub_attr(devId > INT32_MAX ? INT32_MAX : devId, &stPubAttr); ++ CHECK_CALL_MPI_RET(ret, ss_mpi_vo_get_pub_attr); ++ attr->display_rect.x = 0; ++ attr->display_rect.y = 0; ++ attr->display_rect.width = DEFAULT_WIDTH_FOR_HDMI; ++ attr->display_rect.height = DEFAULT_HEIGHT_FOR_HDMI; ++ attr->display_frame_rate = DEFAULT_DISPLAY_FPS; ++ attr->cluster_mode_en = TD_FALSE; ++ attr->double_frame_en = TD_FALSE; ++ attr->pixel_format = PIXEL_FORMAT_YVU_SEMIPLANAR_420; ++ attr->img_size.width = attr->display_rect.width; ++ attr->img_size.height = attr->display_rect.height; ++ attr->dst_dynamic_range = DYNAMIC_RANGE_SDR8; ++ attr->display_buf_len = VIDEO_LAYER_BUFF_LEN; ++ return 0; ++} + -+static int32_t UsbPortGetPortPluginCapability(const struct AudioPort *port, -+ struct AudioPortCapability *capability) ++static int32_t EnabelVoChannel(VO_LAYER voLayer, VO_CHN voChn, uint32_t width, uint32_t height) +{ -+ CHK_NULL_RETURN(port, MEDIA_HAL_INVALID_PARAM, "Input param port is null"); -+ CHK_NULL_RETURN(capability, MEDIA_HAL_INVALID_PARAM, "Input param capability is null"); ++ if (voChn >= OT_VO_MAX_CHN_NUM) { ++ return DISPLAY_FAILURE; ++ } ++ VO_CHN_ATTR_S chnAttr; ++ int32_t ret = ss_mpi_vo_get_chn_attr(voLayer, voChn, &chnAttr); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGE("ss_mpi_vo_get_chn_attr failure, ret = 0x%x", ret); ++ return ret; ++ } + -+ int32_t ret; -+ if (port->dir == PORT_IN) { -+ ret = AudioUsbSubPortInGetCapability(port, capability); -+ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortInGetCapability failed"); -+ } else if (port->dir == PORT_OUT) { -+ ret = AudioUsbSubPortOutGetCapability(port, capability); -+ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortOutGetCapability failed"); -+ } else { -+ MEDIA_HAL_LOGE(MODULE_NAME, "port direction: 0x%x is invalid", port->dir); -+ return MEDIA_HAL_INVALID_PARAM; ++ chnAttr.rect.x = ALIGN_DOWN(0, BYTE_ALIGN_NUM); ++ chnAttr.rect.y = ALIGN_DOWN(0, BYTE_ALIGN_NUM); ++ chnAttr.rect.width = ALIGN_DOWN(width, BYTE_ALIGN_NUM); ++ chnAttr.rect.height = ALIGN_DOWN(height, BYTE_ALIGN_NUM); ++ chnAttr.deflicker_en = TD_FALSE; ++ chnAttr.priority = 0; ++ ret = ss_mpi_vo_set_chn_attr(voLayer, voChn, &chnAttr); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGE("ss_mpi_vo_set_chn_attr failure, ret = 0x%x", ret); ++ return ret; ++ } ++ ret = ss_mpi_vo_enable_chn(voLayer, voChn); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGE("ss_mpi_vo_enable_chn failure, ret = 0x%x", ret); ++ return ret; + } + -+ MEDIA_HAL_LOGD(MODULE_NAME, "%s get capability success", port->portName); -+ return MEDIA_HAL_OK; ++ return DISPLAY_SUCCESS; +} -+// check is or not exist usb audio devices -+int is_usb_audio_device(const char *card_dir) { -+ char usbbus_path[256]; -+ FILE *usbbus_file; + -+ snprintf(usbbus_path, sizeof(usbbus_path), "%s/usbbus", card_dir); -+ -+ usbbus_file = fopen(usbbus_path, "r"); -+ if (usbbus_file) { -+ fclose(usbbus_file); -+ return 1; ++static int32_t DisabelVoChannel(VO_LAYER voLayer, VO_CHN voChn) ++{ ++ int32_t ret = ss_mpi_vo_disable_chn(voLayer, voChn); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGE("Camera video output disable channel failed.(ret=0x%x)\n", ret); ++ return DISPLAY_FAILURE; + } -+ -+ return 0; ++ return DISPLAY_SUCCESS; +} + -+int list_usb_audio_devices(int *card_num, const char *device_str) { -+ DIR *dir; -+ struct dirent *entry; -+ char card_dir[256]; -+ FILE *pcm_file; -+ int card = -2; -+ int usbcard_invaild = 0; -+ dir = opendir("/proc/asound"); -+ if (dir == NULL) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "Failed to open /proc/asound"); -+ return -1; ++int32_t OverlayLayerFlush(uint32_t devId, uint32_t layerId, LayerBuffer *buffer) ++{ ++ CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); ++ int32_t ret = DISPLAY_FAILURE; ++ if (!CheckTypeIsOverlayLayer(layerId)) { ++ HDF_LOGE("%s: layerId type is not overlay Layer", __func__); ++ return ret; + } + -+ while ((entry = readdir(dir)) != NULL) { -+ if (entry->d_type == DT_DIR && strncmp(entry->d_name, "card", 4) == 0) { -+ snprintf(card_dir, sizeof(card_dir), "/proc/asound/%s", entry->d_name); -+ -+ // check is or not exist usb audio devices -+ if (is_usb_audio_device(card_dir)) { -+ card = atoi(entry->d_name + 4); -+ MEDIA_HAL_LOGE(MODULE_NAME, "list_usb_audio_devices card_num = %d",*card_num); -+ // check device is or not exist -+ snprintf(card_dir, sizeof(card_dir), "/proc/asound/card%d/%s/sub0", card, device_str); -+ pcm_file = fopen(card_dir, "r"); -+ if (pcm_file) { -+ *card_num = card; -+ MEDIA_HAL_LOGE(MODULE_NAME, "Card: %d, Device: 0 (Playback supported)\n", *card_num); -+ fclose(pcm_file); -+ usbcard_invaild = 1; -+ } ++ uint8_t vochn = GetVoChn(layerId); ++ if (vochn >= OVERLAY_LAYER_NUM) { ++ HDF_LOGE("%s: layerId is out of range", __func__); ++ return ret; ++ } + -+ } ++ OverlayLayerPrivate *priv = GetLayerInstance(devId, vochn); ++ if (buffer != NULL && buffer->data.virAddr != NULL) { ++#if defined(ENABLE_H8) ++ ret = ss_mpi_vpss_send_frame(priv->vpssGrp, (ot_video_frame_info *)buffer->data.virAddr, 0); ++#else ++ ret = ss_mpi_vpss_send_frame_ex(priv->vpssGrp, priv->vpssChn, (ot_video_frame_info *)buffer->data.virAddr, 0); ++#endif ++ if (ret != TD_SUCCESS) { ++ HDF_LOGE("Flush ret =0x%x\n", ret); + } ++ return ret; + } -+ if (usbcard_invaild) { -+ return 0; -+ } -+ closedir(dir); -+ return -1; ++ return ret; +} -+static int32_t UsbPortOpen(AudioHandle *portHandle) ++ ++int32_t EnabelVideoLayer(uint32_t devId) +{ -+ int32_t card_usb = -1; -+ int32_t ret = 0; -+ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "Input param portHandle is null"); ++ CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); + -+ UsbPortContext *priPortCtx = (UsbPortContext *)malloc(sizeof(UsbPortContext)); -+ if (priPortCtx == NULL) { -+ MEDIA_HAL_LOGI(MODULE_NAME, "malloc UsbPortContext failed"); -+ return MEDIA_HAL_NO_MEM; ++ const VO_LAYER voLayer = OT_VO_LAYER_V0; ++ VO_VIDEO_LAYER_ATTR_S layerAttr = {0}; ++ int32_t ret = ss_mpi_vo_get_video_layer_attr(voLayer, &layerAttr); ++ if (ret != 0) { ++ HDF_LOGI("Camera video output get layer failed.(ret=0x%x)\n", ret); + } -+ if (memset_s(priPortCtx, sizeof(UsbPortContext), 0, sizeof(UsbPortContext)) != EOK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s UsbPortContext failed"); -+ free(priPortCtx); -+ return MEDIA_HAL_ERR; ++ ++ // If the configuration is initialized first ++ if (layerAttr.display_rect.width > 0 && layerAttr.display_rect.height > 0) { ++ DisableVideoLayer(devId); + } + -+ if(!list_usb_audio_devices(&card_usb, "pcm0c")) { -+ priPortCtx->card_usb_num = card_usb; -+ ret = AudioUsbSubPortInOpen(&priPortCtx->subPortInHandle, card_usb); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortInOpen failed ret 0x%x", ret); -+ free(priPortCtx); -+ return ret; -+ } ++ SetVoLayerParam(devId, &layerAttr); ++ ret = ss_mpi_vo_set_video_layer_attr(voLayer, &layerAttr); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGI("ss_mpi_vo_set_video_layer_attr failure, ret = 0x%x", ret); ++ return DISPLAY_FAILURE; + } -+ if(!list_usb_audio_devices(&card_usb, "pcm0p")) { -+ priPortCtx->card_usb_num = card_usb; -+ int ret = AudioUsbSubPortOutOpen(&priPortCtx->subPortOutHandle, card_usb); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortOutOpen failed ret 0x%x", ret); -+ free(priPortCtx); -+ return ret; -+ } ++ ++ ret = ss_mpi_vo_enable_video_layer(voLayer); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGI("ss_mpi_vo_enable_video_layer failure, ret = 0x%x", ret); ++ return DISPLAY_FAILURE; + } -+ priPortCtx->isOpened = true; -+ *portHandle = priPortCtx; -+ MEDIA_HAL_LOGD(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++ ++ VO_CSC_S stVideoCSC = {0}; ++ ret = ss_mpi_vo_get_layer_csc(voLayer, &stVideoCSC); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGI("ss_mpi_vo_get_layer_csc.(ret=0x%x)\n", ret); ++ return DISPLAY_FAILURE; ++ } ++ ++ stVideoCSC.csc_matrix = VO_CSC_MATRIX_IDENTITY; ++ ret = ss_mpi_vo_set_layer_csc(voLayer, &stVideoCSC); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGI("ss_mpi_vo_set_layer_csc.(ret=0x%x)\n", ret); ++ return DISPLAY_FAILURE; ++ } ++ return DISPLAY_SUCCESS; +} + -+static bool AudioPluginIsValidPin(enum AudioPortPin pin, const char *pluginName) ++int32_t DisableVideoLayer(uint32_t devId) +{ -+ if (strcmp("Usb", pluginName) == 0) { -+ if (pin == PIN_IN_USB_EXT || pin == PIN_OUT_USB_EXT || pin == PIN_OUT_USB) { -+ return true; -+ } ++ CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); ++ ++ int32_t ret = ss_mpi_vo_disable_video_layer((VO_LAYER)OT_VO_LAYER_V0); ++ if (ret != TD_SUCCESS) { ++ HDF_LOGI("%s: ss_mpi_vo_disable_video_layer failure, ret 0x%x", __func__, ret); + } -+ return false; ++ return DISPLAY_SUCCESS; +} + -+static int32_t UsbPortCreateTrack(AudioHandle portHandle, enum AudioPortPin audioPortPin, -+ struct PortPluginAttr *portAttr, AudioHandle *trackHandle) ++int32_t CreateOverlayLayer(uint32_t devId, const LayerInfo *layerInfo, uint32_t *layerId) +{ -+ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "Input param portHandle is null"); -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "Input param trackHandle is null"); -+ CHK_NULL_RETURN(portAttr, MEDIA_HAL_INVALID_PARAM, "Input param portAttr is null"); ++ CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); ++ CHECK_NULLPOINTER_RETURN_VALUE(layerInfo, DISPLAY_NULL_PTR); ++ CHECK_NULLPOINTER_RETURN_VALUE(layerId, DISPLAY_NULL_PTR); + -+ if (!AudioPluginIsValidPin(audioPortPin, "Usb")) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "pin 0x%x is invalid", audioPortPin); -+ return MEDIA_HAL_INVALID_PARAM; ++ const VO_LAYER voLayer = OT_VO_LAYER_V0; ++ for (int32_t index = 0; index < OVERLAY_LAYER_NUM; index++) { ++ OverlayLayerPrivate *priv = GetLayerInstance(devId, index > UINT8_MAX ? UINT8_MAX : index); ++ if (priv->voChn != -1) { ++ continue; ++ } ++ ++ VO_CHN voChn = index; ++ int32_t ret = EnabelVoChannel(voLayer, voChn, layerInfo->width < 0 ? 0 : layerInfo->width, ++ layerInfo->height < 0 ? 0 : layerInfo->height); ++ if (ret != DISPLAY_SUCCESS) { ++ HDF_LOGE("ss_mpi_vo_set_chn_attr failure, ret = 0x%x", ret); ++ } ++ ++ if (layerInfo != NULL) { ++ ret = OpenVpssRes(layerInfo, &priv->vpssGrp, &priv->vpssChn); ++ if (ret == DISPLAY_SUCCESS) { ++ BindVoVpss(priv->vpssGrp, priv->vpssChn, voLayer, voChn); ++ priv->vpssIsInternalEnable = true; ++ } ++ } ++#if ENABLE_VO_TIME_TASK ++ VoTimeTaskBegin(); ++#endif ++ ++#if ENABLE_VO_BUSYDROP ++ VoDropTaskBegin(); ++#endif ++ priv->voChn = voChn; ++ uint32_t voLayerUint32 = voLayer < 0 ? 0 : (uint32_t)voLayer; ++ uint32_t voChnUint32 = voChn < 0 ? 0 : (uint32_t)voChn; ++ *layerId = LAYER_ID_VO_LAYER_TYPE_MARK | (voLayerUint32 << VO_LAYER_OFFSET) | voChnUint32; ++ return DISPLAY_SUCCESS; + } ++ HDF_LOGE("%s: no layer to open", __func__); ++ return DISPLAY_FAILURE; ++} + -+ UsbPortContext *priPortCtx = (UsbPortContext *)portHandle; -+ CHK_FAILED_RETURN(priPortCtx->isOpened, true, MEDIA_HAL_ERR, "port not open"); ++int32_t CloseOverlayLayer(uint32_t devId, uint32_t layerId) ++{ ++ CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); ++ if (!CheckTypeIsOverlayLayer(layerId)) { ++ HDF_LOGE("%s: layerId type is not overlay Layer", __func__); ++ return DISPLAY_FAILURE; ++ } ++ uint8_t vochn = GetVoChn(layerId); ++ if (vochn >= OVERLAY_LAYER_NUM) { ++ HDF_LOGE("%s: layerId is out of range", __func__); ++ return DISPLAY_FAILURE; ++ } + -+ int32_t ret; -+ MEDIA_HAL_LOGI(MODULE_NAME, "audioPortPin=%d", audioPortPin); -+ if (audioPortPin == PIN_IN_USB_EXT) { -+ ret = AudioUsbSubPortInCreateTrack(priPortCtx->subPortInHandle, -+ trackHandle, portAttr, audioPortPin); -+ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortInCreateTrack failed"); -+ } else { -+ ret = AudioUsbSubPortOutCreateTrack(priPortCtx->subPortOutHandle, -+ trackHandle, portAttr, audioPortPin); -+ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortOutCreateTrack failed"); ++#if ENABLE_VO_BUSYDROP ++ VoDropTaskEnd(); ++#endif ++ ++#if ENABLE_VO_TIME_TASK ++ VoTimeTaskEnd(); ++#endif ++ ++ OverlayLayerPrivate *priv = GetLayerInstance(devId, vochn); ++ if (priv->voChn == -1) { ++ HDF_LOGE("%s: layerId error, layerId not create", __func__); ++ return DISPLAY_FAILURE; + } + -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++ const VO_LAYER voLayer = OT_VO_LAYER_V0; ++ if (priv->vpssGrp != -1 || priv->vpssChn != -1) { ++ UnBindVoVpss(priv->vpssGrp, priv->vpssChn, voLayer, priv->voChn); ++ if (priv->vpssIsInternalEnable) { ++ CloseVpssRes(priv->vpssGrp, priv->vpssChn); ++ priv->vpssGrp = -1; ++ priv->vpssChn = -1; ++ } ++ } ++ ++ DisabelVoChannel(OT_VO_LAYER_V0, priv->voChn); ++ priv->voChn = -1; ++ return DISPLAY_SUCCESS; +} + -+static int32_t UsbPortDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle) ++int32_t SetOverlayLayerSize(uint32_t devId, uint32_t layerId, const IRect *rect) +{ -+ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "Input param portHandle is null"); -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "Input param trackHandle is null"); ++ CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); ++ CHECK_NULLPOINTER_RETURN_VALUE(rect, DISPLAY_NULL_PTR); ++ if (!CheckTypeIsOverlayLayer(layerId)) { ++ HDF_LOGE("%s: layerId type is not overlay Layer", __func__); ++ return DISPLAY_FAILURE; ++ } ++ uint8_t vochn = GetVoChn(layerId); ++ if (vochn >= OVERLAY_LAYER_NUM) { ++ HDF_LOGE("%s: layerId is out of range", __func__); ++ return DISPLAY_FAILURE; ++ } ++ const VO_LAYER voLayer = GetVoLayer(layerId); ++ ++ VO_CHN_ATTR_S chnAttr = {0}; ++ int32_t ret = ss_mpi_vo_get_chn_attr(voLayer, vochn, &chnAttr); ++ CHECK_CALL_MPI_RET(ret, ss_mpi_vo_get_chn_attr); ++ ++ IRect displayRect = {0}; ++ displayRect.x = ALIGN_DOWN(rect->x, ALIGN_DOWN_NUM); ++ displayRect.y = ALIGN_DOWN(rect->y, ALIGN_DOWN_NUM); ++ displayRect.w = ALIGN_DOWN(rect->w, ALIGN_DOWN_NUM); ++ displayRect.h = ALIGN_DOWN(rect->h, ALIGN_DOWN_NUM); ++ if (displayRect.x != chnAttr.rect.x || displayRect.y != chnAttr.rect.y || ++ displayRect.w != (int32_t)chnAttr.rect.width || displayRect.h != (int32_t)chnAttr.rect.height) { ++ chnAttr.rect.x = displayRect.x; ++ chnAttr.rect.y = displayRect.y; ++ chnAttr.rect.width = displayRect.w < 0 ? 0 : (td_u32)displayRect.w; ++ chnAttr.rect.height = displayRect.h < 0 ? 0 : (td_u32)displayRect.h; ++ HDF_LOGI("set display rect (%d, %d, %u, %u)", chnAttr.rect.x, chnAttr.rect.y, chnAttr.rect.width, ++ chnAttr.rect.height); ++ ret = ss_mpi_vo_set_chn_attr(voLayer, vochn, &chnAttr); ++ CHECK_CALL_MPI_RET(ret, ss_mpi_vo_set_chn_attr); ++ } + -+ UsbPortContext *priPortCtx = (UsbPortContext *)portHandle; -+ CHK_FAILED_RETURN(priPortCtx->isOpened, true, MEDIA_HAL_ERR, "port not open"); ++ return DISPLAY_SUCCESS; ++} + -+ int32_t ret; -+ AudioPortTrack *track = (AudioPortTrack *)trackHandle; -+ if (track->audioPin == PIN_IN_USB_EXT) { -+ ret = AudioUsbSubPortInDestroyTrack(priPortCtx->subPortInHandle, trackHandle); -+ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortInDestroyTrack failed"); ++static int32_t OverlayLayerCmdVoBindVpss(uint32_t devId, uint8_t index, VPSS_GRP vpssGrp, VPSS_CHN vpssChn) ++{ ++ OverlayLayerPrivate *priv = GetLayerInstance(devId, index); ++ const VO_LAYER voLayer = OT_VO_LAYER_V0; ++ if (priv->vpssGrp != -1 && priv->vpssChn != -1) { ++ UnBindVoVpss(priv->vpssGrp, priv->vpssChn, voLayer, priv->voChn); ++ if (priv->vpssIsInternalEnable) { ++ CloseVpssRes(priv->vpssGrp, priv->vpssChn); ++ priv->vpssIsInternalEnable = false; ++ priv->vpssGrp = -1; ++ priv->vpssChn = -1; ++ } ++ } ++ BindVoVpss(vpssGrp, vpssChn, voLayer, index); ++ return DISPLAY_SUCCESS; ++} ++ ++static int32_t OverlayLayerCmdVoUnBindVpss(uint32_t devId, uint8_t index, VPSS_GRP vpssGrp, VPSS_CHN vpssChn) ++{ ++ OverlayLayerPrivate *priv = GetLayerInstance(devId, index); ++ const VO_LAYER voLayer = OT_VO_LAYER_V0; ++ if (priv->vpssGrp == vpssGrp && priv->vpssChn == vpssChn) { ++ UnBindVoVpss(priv->vpssGrp, priv->vpssChn, voLayer, priv->voChn); ++ if (priv->vpssIsInternalEnable) { ++ CloseVpssRes(priv->vpssGrp, priv->vpssChn); ++ priv->vpssIsInternalEnable = false; ++ } ++ priv->vpssGrp = -1; ++ priv->vpssChn = -1; + } else { -+ ret = AudioUsbSubPortOutDestroyTrack(priPortCtx->subPortOutHandle, trackHandle); -+ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortOutDestroyTrack failed"); ++ UnBindVoVpss(vpssGrp, vpssChn, voLayer, priv->voChn); + } -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++ return DISPLAY_SUCCESS; +} + -+static int32_t UsbPortClose(AudioHandle portHandle) ++static int32_t OverlayLayerCmdVdecVpss(uint32_t devId, uint8_t index, ot_vdec_chn vdecChn, bool isBind) +{ -+ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "Input param portHandle is null"); -+ UsbPortContext *priPortCtx = (UsbPortContext *)portHandle; -+ CHK_FAILED_RETURN(priPortCtx->isOpened, true, MEDIA_HAL_ERR, "port not open"); ++ OverlayLayerPrivate *priv = GetLayerInstance(devId, index); ++ ot_mpp_chn srcChn; ++ ot_mpp_chn destChn; ++ ++ srcChn.mod_id = OT_ID_VDEC; ++ srcChn.dev_id = 0; ++ srcChn.chn_id = vdecChn; ++ ++ destChn.mod_id = OT_ID_VPSS; ++ destChn.dev_id = priv->vpssGrp; ++ destChn.chn_id = priv->vpssChn; ++ ++ int32_t ret = DISPLAY_FAILURE; ++ if (isBind) { ++ ret = ss_mpi_sys_bind(&srcChn, &destChn); ++ CHECK_CALL_MPI_RET(ret, ss_mpi_sys_bind); ++ HDF_LOGI("bind vdec&vpss success, vpssGrp=%d vpssChn=%d vdecChn=%d", priv->vpssGrp, priv->vpssChn, vdecChn); ++ } else { ++ ret = ss_mpi_sys_unbind(&srcChn, &destChn); ++ CHECK_CALL_MPI_RET(ret, ss_mpi_sys_unbind); ++ HDF_LOGI("unbind vdec&vpss success, vpssGrp=%d vpssChn=%d vdecChn=%d", priv->vpssGrp, priv->vpssChn, vdecChn); ++ } ++ return ret; ++} + -+ int32_t ret = AudioUsbSubPortInClose(priPortCtx->subPortInHandle); -+ CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "AudioUsbSubPortInClose failed"); -+ ret = AudioUsbSubPortOutClose(priPortCtx->subPortOutHandle); -+ CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "AudioUsbSubPortOutClose failed"); ++int32_t InvokeOverlayLayerCmd(uint32_t devId, uint32_t layerId, uint32_t cmd, ...) ++{ ++ CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); ++ if (cmd > OVERLAYER_CMD_MAX) { ++ HDF_LOGE("%s: not support cmd 0x%x\n", __func__, cmd); ++ return DISPLAY_FAILURE; ++ } ++ if (!CheckTypeIsOverlayLayer(layerId)) { ++ HDF_LOGE("%s: layerId type is not overlay Layer", __func__); ++ return DISPLAY_FAILURE; ++ } ++ uint8_t vochn = GetVoChn(layerId); ++ if (vochn >= OVERLAY_LAYER_NUM) { ++ HDF_LOGE("%s: layerId is out of range", __func__); ++ return DISPLAY_FAILURE; ++ } + -+ priPortCtx->isOpened = false; -+ free(priPortCtx); -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++ va_list vl; ++ va_start(vl, cmd); ++ int32_t ret = DISPLAY_FAILURE; ++ VPSS_CHN vpssChn; ++ VPSS_GRP vpssGroup; ++ ot_vdec_chn vdecChn; ++ switch (cmd) { ++ case OVERLAYER_CMD_VO_BIND_VPSS: ++ vpssChn = va_arg(vl, int32_t); ++ vpssGroup = va_arg(vl, int32_t); ++ ret = OverlayLayerCmdVoBindVpss(devId, vochn, vpssGroup, vpssChn); ++ break; ++ case OVERLAYER_CMD_VO_UNBIND_VPSS: ++ vpssChn = va_arg(vl, int32_t); ++ vpssGroup = va_arg(vl, int32_t); ++ ret = OverlayLayerCmdVoUnBindVpss(devId, vochn, vpssGroup, vpssChn); ++ break; ++ case OVERLAYER_CMD_VPSS_BING_VDEC: ++ vdecChn = va_arg(vl, int32_t); ++ ret = OverlayLayerCmdVdecVpss(devId, vochn, vdecChn, true); ++ break; ++ case OVERLAYER_CMD_VPSS_UNBING_VDEC: ++ vdecChn = va_arg(vl, int32_t); ++ ret = OverlayLayerCmdVdecVpss(devId, vochn, vdecChn, false); ++ break; ++ default: ++ break; ++ } ++ va_end(vl); ++ return ret; +} + -+static AudioPortPlugin g_usbPortPlugin = { -+ .audioPortDir = PORT_OUT_IN, -+ .audioPortPins = PIN_IN_USB_EXT | PIN_OUT_USB_EXT | PIN_OUT_USB, -+ .GetPortPluginCapability = UsbPortGetPortPluginCapability, -+ .Open = UsbPortOpen, -+ .CreateTrack = UsbPortCreateTrack, -+ .DestroyTrack = UsbPortDestroyTrack, -+ .Close = UsbPortClose, -+ .SetMute = NULL, -+ .GetMute = NULL, -+ .SetVolume = NULL, -+ .GetVolume = NULL, -+}; -+ -+const AudioPortPlugin *GetPortPluginFuncs(AudioPluginType pluginType) ++int32_t GetOverlayLayerDeviceId(uint32_t devId, uint32_t layerId, uint32_t *deviceId) +{ -+ if (pluginType == AUDIO_PLUGIN_BLUETOOTH) { -+ return NULL; ++ if (deviceId == NULL) { ++ return DISPLAY_FAILURE; + } -+ return &g_usbPortPlugin; ++ CHECK_DEVID_VALID(devId, DISPLAY_FAILURE); ++ if (!CheckTypeIsOverlayLayer(layerId)) { ++ HDF_LOGE("%s: layerId type is not overlay Layer", __func__); ++ return DISPLAY_FAILURE; ++ } ++ ++ uint8_t vochn = GetVoChn(layerId); ++ if (vochn >= OVERLAY_LAYER_NUM) { ++ HDF_LOGE("%s: layerId is out of range", __func__); ++ return DISPLAY_FAILURE; ++ } ++ ++ OverlayLayerPrivate *priv = GetLayerInstance(devId, vochn); ++ uint32_t vpssGrpUint32 = priv->vpssGrp < 0 ? 0 : (uint32_t)priv->vpssGrp; ++ uint32_t vpssChnUint32 = priv->vpssChn < 0 ? 0 : (uint32_t)priv->vpssChn; ++ *deviceId = (((OT_ID_VPSS << 0x10) & 0xff0000) + ((vpssGrpUint32 << OFFSET_8) & 0xff00) + ++ (vpssChnUint32 & 0xff)); // 8: offset ++ HDF_LOGI("GetOverlayLayerDeviceId (%u)", *deviceId); ++ return DISPLAY_SUCCESS; +} + -+#ifdef __cplusplus -+#if __cplusplus ++int32_t SetOverlayLayerPriority(uint32_t priority) ++{ ++ const VO_LAYER voLayer = OT_VO_LAYER_V0; ++ HDF_LOGI("SetOverlayLayerPriority priority = %d", priority); ++ ss_mpi_vo_set_layer_priority(voLayer, priority); ++ return DISPLAY_SUCCESS; +} -+#endif -+#endif /* __cplusplus */ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.h ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.h ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.h 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.h 2025-11-07 14:44:54.873657233 +0800 -@@ -0,0 +1,21 @@ -+ /* -+ * Copyright (c) 2024 RKH Corp. +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/display/ss928/src/hdmi.c ohos1/device/soc/hisilicon/common/hal/display/ss928/src/hdmi.c +--- ohos/device/soc/hisilicon/common/hal/display/ss928/src/hdmi.c 2025-12-18 15:41:53.763785014 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/display/ss928/src/hdmi.c 2025-12-18 15:44:30.886238365 +0800 +@@ -33,7 +33,8 @@ static void SetHdmiParam(HI_HDMI_ATTR_S + attr->hdmi_en = TD_TRUE; + attr->video_format = HI_HDMI_VIDEO_FMT_1080P_60; + attr->deep_color_mode = HI_HDMI_DEEP_COLOR_24BIT; +- attr->audio_en = TD_FALSE; ++ attr->audio_en = TD_TRUE; ++ attr->sample_rate = OT_HDMI_SAMPLE_RATE_48K; + attr->bit_depth = HI_HDMI_BIT_DEPTH_16; + #ifndef ENABLE_H8 + attr->bEnableVideo = TD_TRUE; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/display/ss928/src/layer_test.c ohos1/device/soc/hisilicon/common/hal/display/ss928/src/layer_test.c +--- ohos/device/soc/hisilicon/common/hal/display/ss928/src/layer_test.c 2025-12-18 15:30:15.802678161 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/display/ss928/src/layer_test.c 2025-12-18 15:44:30.886238365 +0800 +@@ -1,182 +1,182 @@ +-/* +- * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. +- * +- * 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. +- */ +- +-#include +-#include +-#include "display_layer.h" +-#include "display_gfx.h" +- +-static LayerFuncs* g_layerFunc = NULL; +-static GfxFuncs* g_gfxFunc = NULL; +- +-static LayerInfo g_layerInfo = {}; +-static uint32_t g_layerId = 0; +-static LayerBuffer g_fbBuf = {}; +- +-const static uint8_t DISPALY_DEV_ID = 0; +-const static uint8_t OPA_OPAQUE = 255; +-const static uint16_t DEFAULT_WIDTH = 720; +-const static uint16_t DEFAULT_HEIGHT = 480; +-const static uint8_t DEFAULT_BPP = 32; +- +-static void FillArea(void) +-{ +- ISurface surface = {}; +- surface.phyAddr = g_fbBuf.data.phyAddr; +- surface.height = g_fbBuf.height; +- surface.width = g_fbBuf.width; +- surface.stride = g_fbBuf.pitch; +- surface.enColorFmt = g_fbBuf.pixFormat; +- surface.clutPhyAddr = 0; +- surface.bYCbCrClut = false; +- surface.bAlphaMax255 = true; +- surface.bAlphaExt1555 = false; +- surface.alpha0 = 0; +- surface.alpha1 = OPA_OPAQUE; +- +- IRect rect = {0, 0, g_layerInfo.width, g_layerInfo.height}; // 2 half of width and height +- +- GfxOpt opt = {}; +- opt.enGlobalAlpha = true; +- opt.globalAlpha = OPA_OPAQUE; +- +- if (g_gfxFunc->FillRect(&surface, &rect, 0xFFFFFF00, &opt) == DISPLAY_FAILURE) { +- printf("fill rect failed!\n"); +- return; +- } +-} +- +-static void CloseLayer(void) +-{ +- if (g_layerFunc->CloseLayer != NULL) { +- g_layerFunc->CloseLayer(DISPALY_DEV_ID, g_layerId); +- } +-} +- +-static bool OpenLayer(void) +-{ +- g_layerInfo.width = DEFAULT_WIDTH; +- g_layerInfo.height = DEFAULT_HEIGHT; +- g_layerInfo.bpp = DEFAULT_BPP; +- g_layerInfo.pixFormat = PIXEL_FMT_RGBA_8888; +- g_layerInfo.type = LAYER_TYPE_GRAPHIC; +- +- int32_t ret = -1; +- if (g_layerFunc->CreateLayer != NULL) { +- ret = g_layerFunc->CreateLayer(DISPALY_DEV_ID, &g_layerInfo, &g_layerId); +- if (ret != DISPLAY_SUCCESS) { +- printf("CreateLayer fail\n"); +- return false; +- } +- } +- +- if (g_layerFunc->SetLayerVisible != NULL) { +- ret = g_layerFunc->SetLayerVisible(DISPALY_DEV_ID, g_layerId, true); +- if (ret != DISPLAY_SUCCESS) { +- printf("CreateLayer fail\n"); +- return false; +- } +- } +- +- if (g_layerFunc->SetLayerDirtyRegion != NULL) { +- IRect rect = {0, 0, g_layerInfo.width, g_layerInfo.height}; +- ret = g_layerFunc->SetLayerDirtyRegion(DISPALY_DEV_ID, g_layerId, &rect); +- if (ret != DISPLAY_SUCCESS) { +- printf("setLayerDirtyRegion fail\n"); +- return false; +- } +- } +- return true; +-} +- +-static void Deinit(void) +-{ +- if (g_gfxFunc->DeinitGfx != NULL) { +- g_gfxFunc->DeinitGfx(); +- } +- +- if (g_layerFunc->DeinitDisplay != NULL) { +- g_layerFunc->DeinitDisplay(DISPALY_DEV_ID); +- } +- +- if (g_gfxFunc != NULL) { +- GfxUninitialize(g_gfxFunc); +- } +- +- if (g_layerFunc != NULL) { +- LayerUninitialize(g_layerFunc); +- } +-} +- +-static bool Init() +-{ +- int32_t ret = LayerInitialize(&g_layerFunc); +- if (ret != DISPLAY_SUCCESS) { +- return false; +- } +- if (g_layerFunc->InitDisplay != NULL) { +- ret = g_layerFunc->InitDisplay(DISPALY_DEV_ID); +- if (ret != DISPLAY_SUCCESS) { +- printf("InitDisplay fail\n"); +- return false; +- } +- } +- +- ret = GfxInitialize(&g_gfxFunc); +- if (ret != DISPLAY_SUCCESS) { +- return false; +- } +- +- if (g_gfxFunc->InitGfx != NULL) { +- g_gfxFunc->InitGfx(); +- } +- return true; +-} +- +- +-int main(int argc, char* argv[]) +-{ +- Init(); +- OpenLayer(); +- if (g_layerFunc->GetLayerBuffer == NULL) { +- goto ERROR; +- } +- if (g_layerFunc->GetLayerBuffer(DISPALY_DEV_ID, g_layerId, &g_fbBuf) != DISPLAY_SUCCESS) { +- goto ERROR; +- } +- +- FillArea(); +- if (g_layerFunc->Flush != NULL) { +- g_layerFunc->Flush(DISPALY_DEV_ID, g_layerId, &g_fbBuf); +- } +- +- char cmd[32]; // 32 is the length of buffer +- while (fgets(cmd, 10, stdin) != NULL) { // 10: max get input char +- cmd[10] = '\0'; // 10 is the max length of cmd buffer +- if (strncmp(cmd, "quit", 4) == 0) { // 4 is the length of cmd string +- break; +- } else if (strncmp(cmd, "q", 1) == 0) { +- break; +- } else { +- printf("Input CMD: 'quit' or 'q' for quit the program!\n"); +- } +- } +- +-ERROR: +- CloseLayer(); +- Deinit(); +- return 0; +-} ++/* ++ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. ++ * + * 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 @@ -600,28 +1766,721 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device + * limitations under the License. + */ + -+#ifndef PRIMARY_PORT_PLUGIN_H -+#define PRIMARY_PORT_PLUGIN_H ++#include ++#include ++#include "display_layer.h" ++#include "display_gfx.h" ++ ++static LayerFuncs* g_layerFunc = NULL; ++static GfxFuncs* g_gfxFunc = NULL; ++ ++static LayerInfo g_layerInfo = {}; ++static uint32_t g_layerId = 0; ++static LayerBuffer g_fbBuf = {}; ++ ++const static uint8_t DISPALY_DEV_ID = 0; ++const static uint8_t OPA_OPAQUE = 255; ++const static uint16_t DEFAULT_WIDTH = 720; ++const static uint16_t DEFAULT_HEIGHT = 480; ++const static uint8_t DEFAULT_BPP = 32; ++ ++static void FillArea(void) ++{ ++ ISurface surface = {}; ++ surface.phyAddr = g_fbBuf.data.phyAddr; ++ surface.height = g_fbBuf.height; ++ surface.width = g_fbBuf.width; ++ surface.stride = g_fbBuf.pitch; ++ surface.enColorFmt = g_fbBuf.pixFormat; ++ surface.clutPhyAddr = 0; ++ surface.bYCbCrClut = false; ++ surface.bAlphaMax255 = true; ++ surface.bAlphaExt1555 = false; ++ surface.alpha0 = 0; ++ surface.alpha1 = OPA_OPAQUE; ++ ++ IRect rect = {0, 0, g_layerInfo.width, g_layerInfo.height}; // 2 half of width and height ++ ++ GfxOpt opt = {}; ++ opt.enGlobalAlpha = true; ++ opt.globalAlpha = OPA_OPAQUE; ++ ++ if (g_gfxFunc->FillRect(&surface, &rect, 0xFFFFFF00, &opt) == DISPLAY_FAILURE) { ++ printf("fill rect failed!\n"); ++ return; ++ } ++} ++ ++static void CloseLayer(void) ++{ ++ if (g_layerFunc->CloseLayer != NULL) { ++ g_layerFunc->CloseLayer(DISPALY_DEV_ID, g_layerId); ++ } ++} ++ ++static bool OpenLayer(void) ++{ ++ g_layerInfo.width = DEFAULT_WIDTH; ++ g_layerInfo.height = DEFAULT_HEIGHT; ++ g_layerInfo.bpp = DEFAULT_BPP; ++ g_layerInfo.pixFormat = PIXEL_FMT_RGBA_8888; ++ g_layerInfo.type = LAYER_TYPE_GRAPHIC; ++ ++ int32_t ret = -1; ++ if (g_layerFunc->CreateLayer != NULL) { ++ ret = g_layerFunc->CreateLayer(DISPALY_DEV_ID, &g_layerInfo, &g_layerId); ++ if (ret != DISPLAY_SUCCESS) { ++ printf("CreateLayer fail\n"); ++ return false; ++ } ++ } ++ ++ if (g_layerFunc->SetLayerVisible != NULL) { ++ ret = g_layerFunc->SetLayerVisible(DISPALY_DEV_ID, g_layerId, true); ++ if (ret != DISPLAY_SUCCESS) { ++ printf("CreateLayer fail\n"); ++ return false; ++ } ++ } ++ ++ if (g_layerFunc->SetLayerDirtyRegion != NULL) { ++ IRect rect = {0, 0, g_layerInfo.width, g_layerInfo.height}; ++ ret = g_layerFunc->SetLayerDirtyRegion(DISPALY_DEV_ID, g_layerId, &rect); ++ if (ret != DISPLAY_SUCCESS) { ++ printf("setLayerDirtyRegion fail\n"); ++ return false; ++ } ++ } ++ return true; ++} ++ ++static void Deinit(void) ++{ ++ if (g_gfxFunc->DeinitGfx != NULL) { ++ g_gfxFunc->DeinitGfx(); ++ } ++ ++ if (g_layerFunc->DeinitDisplay != NULL) { ++ g_layerFunc->DeinitDisplay(DISPALY_DEV_ID); ++ } ++ ++ if (g_gfxFunc != NULL) { ++ GfxUninitialize(g_gfxFunc); ++ } ++ ++ if (g_layerFunc != NULL) { ++ LayerUninitialize(g_layerFunc); ++ } ++} ++ ++static bool Init() ++{ ++ int32_t ret = LayerInitialize(&g_layerFunc); ++ if (ret != DISPLAY_SUCCESS) { ++ return false; ++ } ++ if (g_layerFunc->InitDisplay != NULL) { ++ ret = g_layerFunc->InitDisplay(DISPALY_DEV_ID); ++ if (ret != DISPLAY_SUCCESS) { ++ printf("InitDisplay fail\n"); ++ return false; ++ } ++ } ++ ++ ret = GfxInitialize(&g_gfxFunc); ++ if (ret != DISPLAY_SUCCESS) { ++ return false; ++ } ++ ++ if (g_gfxFunc->InitGfx != NULL) { ++ g_gfxFunc->InitGfx(); ++ } ++ return true; ++} ++ ++ ++int main(int argc, char* argv[]) ++{ ++ Init(); ++ OpenLayer(); ++ if (g_layerFunc->GetLayerBuffer == NULL) { ++ goto ERROR; ++ } ++ if (g_layerFunc->GetLayerBuffer(DISPALY_DEV_ID, g_layerId, &g_fbBuf) != DISPLAY_SUCCESS) { ++ goto ERROR; ++ } + ++ FillArea(); ++ if (g_layerFunc->Flush != NULL) { ++ g_layerFunc->Flush(DISPALY_DEV_ID, g_layerId, &g_fbBuf); ++ } ++ ++ char cmd[32]; // 32 is the length of buffer ++ while (fgets(cmd, 10, stdin) != NULL) { // 10: max get input char ++ cmd[10] = '\0'; // 10 is the max length of cmd buffer ++ if (strncmp(cmd, "quit", 4) == 0) { // 4 is the length of cmd string ++ break; ++ } else if (strncmp(cmd, "q", 1) == 0) { ++ break; ++ } else { ++ printf("Input CMD: 'quit' or 'q' for quit the program!\n"); ++ } ++ } ++ ++ERROR: ++ CloseLayer(); ++ Deinit(); ++ return 0; ++} +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_effect_manager/audio_effect_manager.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_effect_manager/audio_effect_manager.c +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_effect_manager/audio_effect_manager.c 2025-12-18 15:41:53.763785014 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_effect_manager/audio_effect_manager.c 2025-12-18 15:44:30.874238483 +0800 +@@ -129,9 +129,6 @@ static int32_t SetDeviceAndChannelId(Aud + + struct InvokeAttr paramAttr = {}; + paramAttr.request = (void *)keyValuePair; +- if (trackHandle == NULL || trackHandle->Invoke == NULL) { +- return MEDIA_HAL_ERR; +- } + ret = trackHandle->Invoke(trackHandle, INVOKE_ID_SET_EXTRA_PARAMS, ¶mAttr); + if (ret != MEDIA_HAL_OK) { + MEDIA_HAL_LOGE(MODULE_NAME, "audio input port set extra param failed: 0x%x", ret); +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.c +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.c 2025-12-18 15:41:53.763785014 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.c 2025-12-18 15:44:30.874238483 +0800 +@@ -104,7 +104,7 @@ static int32_t PrimaryPortOpen(AudioHand + static bool AudioPluginIsValidPin(enum AudioPortPin pin, const char *pluginName) + { + if (strcmp("primary", pluginName) == 0) { +- if (pin == PIN_IN_MIC || pin == PIN_OUT_SPEAKER) { ++ if (pin == PIN_IN_MIC || pin == PIN_OUT_SPEAKER || pin == PIN_OUT_HDMI) { + return true; + } + } +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.h ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.h +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.h 2025-12-18 15:41:53.763785014 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_port_plugin/audio_primary_port_plugin.h 2025-12-18 15:44:30.874238483 +0800 +@@ -19,4 +19,6 @@ + #ifndef PRIMARY_PORT_PLUGIN_H + #define PRIMARY_PORT_PLUGIN_H + +#include "audio_port_plugin.h" + -+#endif -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/include/audio_port_plugin_common.h ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/include/audio_port_plugin_common.h ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/include/audio_port_plugin_common.h 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/include/audio_port_plugin_common.h 2025-11-07 14:44:54.873657233 +0800 -@@ -0,0 +1,66 @@ -+ /* -+ * Copyright (c) 2024 RKH Corp. -+ * 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 + #endif +\ No newline at end of file +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_in/audio_primary_sub_port_in.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_in/audio_primary_sub_port_in.c +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_in/audio_primary_sub_port_in.c 2025-12-18 15:41:53.763785014 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_in/audio_primary_sub_port_in.c 2025-12-18 15:44:30.874238483 +0800 +@@ -454,14 +454,23 @@ static int32_t AudioPrimarySubPortInSetE + return MEDIA_HAL_OK; + } + +-static int32_t DualMono2Stereo(const int16_t *leftChnData, const int16_t *rightChnData, +- int16_t sampleNumPerChn, int16_t *stereoData) ++int32_t DualMono2Stereo(char *audioData, char *audioLeft, ++ char *audioRight, uint32_t audioLen) + { +- for (int32_t i = 0; i < sampleNumPerChn; i++) { +- /* Mono to Stereo */ +- stereoData[AUDIO_STEREO_SOUND_MODE_CHN_CNT * i] = leftChnData[i]; +- stereoData[(AUDIO_STEREO_SOUND_MODE_CHN_CNT * i) + 1] = rightChnData[i]; ++ if (audioData == NULL || audioLeft == NULL || audioRight == NULL) { ++ return -1; + } ++ uint32_t i, j; ++ uint32_t framesize = 2; ++ uint32_t signleDataLen = audioLen / 2; ++ ++ for (i = 0; i < signleDataLen; i += framesize) { ++ for (j = 0; j < framesize; j++) { ++ audioData[2 * i + j] = audioLeft[i + j]; ++ audioData[2 * i + framesize + j] = audioRight[i + j]; ++ } ++ } ++ + return MEDIA_HAL_OK; + } + +@@ -849,10 +858,10 @@ int32_t AudioPrimarySubPortInAcquireFram + MEDIA_HAL_LOGE(MODULE_NAME, "audio capture input buffer too small"); + return MEDIA_HAL_INVALID_PARAM; + } +- uint32_t sampleNum = stAudioFrm.len / (portTrackInCtx->aiAttr.bit_width + 1); + if (portTrackInCtx->aiAttr.snd_mode == OT_AUDIO_SOUND_MODE_STEREO) { +- DualMono2Stereo((int16_t *)stAudioFrm.virt_addr[0], (int16_t *)stAudioFrm.virt_addr[1], sampleNum, +- (int16_t *)buffer); ++ // The hardware does not support dual channels, so the mono data is copied to dual channels. ++ DualMono2Stereo(buffer, (char *)stAudioFrm.virt_addr[0], ++ (char *)stAudioFrm.virt_addr[1], *replyBytes); + } else if (portTrackInCtx->aiAttr.snd_mode == OT_AUDIO_SOUND_MODE_MONO) { + if (memcpy_s(buffer, requestBytes, stAudioFrm.virt_addr[0], stAudioFrm.len) != EOK) { + MEDIA_HAL_LOGE(MODULE_NAME, "memcpy_s ot_audio_frame failed"); +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_out/audio_primary_sub_port_out.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_out/audio_primary_sub_port_out.c +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_out/audio_primary_sub_port_out.c 2025-12-18 15:41:53.763785014 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/hi35xx/audio_primary_sub_port_out/audio_primary_sub_port_out.c 2025-12-18 15:44:30.874238483 +0800 +@@ -77,6 +77,7 @@ struct AudioSubPortOut { + bool mute; + ot_aio_attr aoSourceAttr; + ot_audio_dev aoDeviceId; ++ ot_audio_dev aoHDMIDeviceId; + bool aoEnabled; + struct AudioSubPortOutTrack *hwOutputPortTrack[MAX_OUTPUT_PORT_TRACK_CNT]; + pthread_mutex_t mutex; +@@ -131,6 +132,8 @@ static int32_t AudioOutputPortMngGetFree + return MEDIA_HAL_ERR; + } + for (int32_t i = 0; i < MAX_OUTPUT_PORT_CNT; i++) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "MAX_OUTPUT_PORT_CNT %d, g_audioHwOutputPorts[i].used = %d, chnID = %d", ++ MAX_OUTPUT_PORT_CNT, g_audioHwOutputPorts[i].used, g_audioHwOutputPorts[i].chnID); + if (!g_audioHwOutputPorts[i].used) { + g_audioHwOutputPorts[i].used = true; + int32_t chnID = g_audioHwOutputPorts[i].chnID; +@@ -238,7 +241,7 @@ AO_DISABLE: + return ret; + } + +-static int32_t AoSourceAttrConfig(struct PortPluginAttr *portAttr, ot_aio_attr *aoSourceAttr) ++static int32_t AoSourceAttrConfig(struct PortPluginAttr *portAttr, ot_aio_attr *aoSourceAttr, enum AudioPortPin audioPortPin) + { + if (memset_s(aoSourceAttr, sizeof(ot_aio_attr), 0x0, sizeof(ot_aio_attr)) != EOK) { + MEDIA_HAL_LOGE(MODULE_NAME, "memset_s: hwOutputPort aoAttr failed"); +@@ -259,20 +262,28 @@ static int32_t AoSourceAttrConfig(struct + aoSourceAttr->frame_num = AUDIO_FRAME_NUM_OUT_BUF; + aoSourceAttr->point_num_per_frame = AUDIO_OUT_PTNUMPERFRM; + aoSourceAttr->clk_share = 0; +- aoSourceAttr->i2s_type = OT_AIO_I2STYPE_INNERCODEC; ++ if(audioPortPin == PIN_OUT_HDMI) { ++ aoSourceAttr->i2s_type = OT_AIO_I2STYPE_INNERHDMI; ++ } else if(audioPortPin == PIN_OUT_SPEAKER){ ++ aoSourceAttr->i2s_type = OT_AIO_I2STYPE_INNERCODEC; ++ } + return MEDIA_HAL_OK; + } + +-static int32_t ConfigAndEnableAO(AudioHandle portHandle, struct PortPluginAttr *portAttr) ++static int32_t ConfigAndEnableAO(AudioHandle portHandle, struct PortPluginAttr *portAttr, enum AudioPortPin audioPortPin) + { + struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; +- int32_t ret = AoSourceAttrConfig(portAttr, &hwPortCtx->aoSourceAttr); ++ int32_t ret = AoSourceAttrConfig(portAttr, &hwPortCtx->aoSourceAttr, audioPortPin); + if (ret != MEDIA_HAL_OK) { + MEDIA_HAL_LOGE(MODULE_NAME, "ConfigAoSourceAttr failed"); + return ret; + } + ot_aio_attr aoAttr = hwPortCtx->aoSourceAttr; +- ret = AoInit(hwPortCtx->aoDeviceId, &aoAttr); ++ if(audioPortPin == PIN_OUT_HDMI) { ++ ret = AoInit(hwPortCtx->aoHDMIDeviceId, &aoAttr); ++ } else if(audioPortPin == PIN_OUT_SPEAKER){ ++ ret = AoInit(hwPortCtx->aoDeviceId, &aoAttr); ++ } + if (ret != MEDIA_HAL_OK) { + MEDIA_HAL_LOGE(MODULE_NAME, "AoInit failed %#x", ret); + return ret; +@@ -301,7 +312,14 @@ int32_t AudioPrimarySubPortOutOpen(Audio + if (memset_s(hwOutputPort, sizeof(struct AudioSubPortOut), 0, sizeof(struct AudioSubPortOut)) != EOK) { + MEDIA_HAL_LOGE(MODULE_NAME, "memset_s AudioSubPortOut failed"); + } +- hwOutputPort->aoDeviceId = portIndex; ++ hwOutputPort->aoDeviceId = portIndex;// 0:speaker, 1:hdmi ++ ++ portIndex = AudioOutputPortMngGetFreeChn(); ++ if (portIndex == -1) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "can not found free Output Port"); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ hwOutputPort->aoHDMIDeviceId = portIndex;// 1:hdmi + pthread_mutex_init(&hwOutputPort->mutex, NULL); + hwOutputPort->opened = true; + *portHandle = hwOutputPort; +@@ -318,7 +336,11 @@ int32_t AudioPrimarySubPortOutClose(Audi + if (hwPortCtx->aoEnabled) { + ret = ss_mpi_ao_disable(hwPortCtx->aoDeviceId); + if (ret != MEDIA_HAL_OK) { +- MEDIA_HAL_LOGE(MODULE_NAME, "ss_mpi_ao_disable fail,ret:0x%x", ret); ++ MEDIA_HAL_LOGE(MODULE_NAME, "aoDeviceId ss_mpi_ao_disable fail,ret:0x%x", ret); ++ } ++ ret = ss_mpi_ao_disable(hwPortCtx->aoHDMIDeviceId); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "aoHDMIDeviceId ss_mpi_ao_disable fail,ret:0x%x", ret); + } + hwPortCtx->aoEnabled = false; + } +@@ -326,6 +348,10 @@ int32_t AudioPrimarySubPortOutClose(Audi + if (ret != MEDIA_HAL_OK) { + MEDIA_HAL_LOGE(MODULE_NAME, "AudioOutputPortMngFreeChn failed"); + } ++ ret = AudioOutputPortMngFreeChn(hwPortCtx->aoHDMIDeviceId); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AudioOutputPortMngFreeChn failed"); ++ } + AudioAcodecDeInit(); + pthread_mutex_destroy(&hwPortCtx->mutex); + hwPortCtx->opened = false; +@@ -793,7 +819,7 @@ int32_t AudioPrimarySubPortOutCreateTrac + return MEDIA_HAL_INVALID_PARAM; + } + +- if (!hwPortCtx->aoEnabled && (ConfigAndEnableAO(portHandle, portAttr) != MEDIA_HAL_OK)) { ++ if (!hwPortCtx->aoEnabled && (ConfigAndEnableAO(portHandle, portAttr, audioPortPin) != MEDIA_HAL_OK)) { + MEDIA_HAL_LOGE(MODULE_NAME, "config and anable AO failed"); + return MEDIA_HAL_INIT_FAIL; + } +@@ -808,7 +834,11 @@ int32_t AudioPrimarySubPortOutCreateTrac + } + hwOutputPortTrack->aoSourceAttr = hwPortCtx->aoSourceAttr; + SubPortTrackOutLoadImpl(hwOutputPortTrack, portAttr, audioPortPin); +- hwOutputPortTrack->aoDeviceId = hwPortCtx->aoDeviceId; ++ if (audioPortPin == PIN_OUT_HDMI) { ++ hwOutputPortTrack->aoDeviceId = hwPortCtx->aoHDMIDeviceId; ++ } else if (audioPortPin == PIN_OUT_SPEAKER) { ++ hwOutputPortTrack->aoDeviceId = hwPortCtx->aoDeviceId; ++ } + hwOutputPortTrack->aoChn = trackIndex; + hwOutputPortTrack->vqeScene = VQE_SCENE_NONE; + hwOutputPortTrack->inited = true; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/Makefile ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/Makefile +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/Makefile 2025-12-18 15:41:53.763785014 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/Makefile 2025-12-18 15:44:30.874238483 +0800 +@@ -6,6 +6,7 @@ MODNAME := + ifeq ($(strip $(CFG_CHIP_TYPE)),$(filter $(CFG_CHIP_TYPE),hi3518ev300 hi3516dv300 hispark_ss927v100 hispark_ss928v100)) + # $(warning "the value of CFG_CHIP_TYPE is $(CFG_CHIP_TYPE)") + MODNAME += $(shell test -d hi35xx && echo hi35xx) ++MODNAME += $(shell test -d ss928_usb && echo ss928_usb) + else ifeq ($(strip $(CFG_CHIP_TYPE)),$(filter $(CFG_CHIP_TYPE),hi3862v100)) + MODNAME += $(shell test -d iot/audio_input_port_plugin && echo iot/audio_input_port_plugin) + MODNAME += $(shell test -d iot/audio_output_port_plugin && echo iot/audio_output_port_plugin) +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/plugin_include/audio_port_plugin.h ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/plugin_include/audio_port_plugin.h +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/plugin_include/audio_port_plugin.h 2025-12-18 15:41:53.763785014 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/plugin_include/audio_port_plugin.h 2025-12-18 15:44:30.874238483 +0800 +@@ -94,7 +94,9 @@ struct PortPluginAttr { + */ + typedef enum { + AUDIO_PLUGIN_PRIMARY = 0x1u, /* Primary plugin */ +- AUDIO_PLUGIN_BLUETOOTH = 0x2u, /* Bluetooth plugin */ ++ AUDIO_PLUGIN_HDMI = 0x2u, /* HDMI plugin */ ++ AUDIO_PLUGIN_USB = 0x3u, /* USB plugin */ ++ AUDIO_PLUGIN_BLUETOOTH = 0x10u, /* Bluetooth plugin */ + AUDIO_PLUGIN_NONE, + } AudioPluginType; + +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.c +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.c 1970-01-01 08:00:00.000000000 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.c 2025-12-18 15:44:30.874238483 +0800 +@@ -0,0 +1,272 @@ ++ /* ++ * Copyright (c) 2024 RKH Corp. ++ * 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. ++ */ ++ ++#include "audio_usb_port_plugin.h" ++ ++#include ++#include "securec.h" ++#include ++#include "audio_usb_sub_port_in.h" ++#include "audio_usb_sub_port_out.h" ++ ++#include "media_hal_common.h" ++#include "audio_port_plugin_common.h" ++ ++#ifdef __cplusplus ++#if __cplusplus ++extern "C" { ++#endif ++#endif /* __cplusplus */ ++ ++#define MODULE_NAME "AudioUsbPortPlugin" ++ ++typedef struct { ++ /* sub port track context */ ++ AudioHandle subPortTrackHandle; ++} UsbPortTrackContext; ++ ++typedef struct { ++ /* port context */ ++ bool isOpened; ++ int card_usb_num; ++ /* sub port context */ ++ AudioHandle subPortInHandle; ++ AudioHandle subPortOutHandle; ++} UsbPortContext; ++ ++static int32_t UsbPortGetPortPluginCapability(const struct AudioPort *port, ++ struct AudioPortCapability *capability) ++{ ++ CHK_NULL_RETURN(port, MEDIA_HAL_INVALID_PARAM, "Input param port is null"); ++ CHK_NULL_RETURN(capability, MEDIA_HAL_INVALID_PARAM, "Input param capability is null"); ++ ++ int32_t ret; ++ if (port->dir == PORT_IN) { ++ ret = AudioUsbSubPortInGetCapability(port, capability); ++ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortInGetCapability failed"); ++ } else if (port->dir == PORT_OUT) { ++ ret = AudioUsbSubPortOutGetCapability(port, capability); ++ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortOutGetCapability failed"); ++ } else { ++ MEDIA_HAL_LOGE(MODULE_NAME, "port direction: 0x%x is invalid", port->dir); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ ++ MEDIA_HAL_LOGD(MODULE_NAME, "%s get capability success", port->portName); ++ return MEDIA_HAL_OK; ++} ++// check is or not exist usb audio devices ++int is_usb_audio_device(const char *card_dir) { ++ char usbbus_path[256]; ++ FILE *usbbus_file; ++ ++ snprintf(usbbus_path, sizeof(usbbus_path), "%s/usbbus", card_dir); ++ ++ usbbus_file = fopen(usbbus_path, "r"); ++ if (usbbus_file) { ++ fclose(usbbus_file); ++ return 1; ++ } ++ ++ return 0; ++} ++ ++int list_usb_audio_devices(int *card_num, const char *device_str) { ++ DIR *dir; ++ struct dirent *entry; ++ char card_dir[256]; ++ FILE *pcm_file; ++ int card = -2; ++ int usbcard_invaild = 0; ++ dir = opendir("/proc/asound"); ++ if (dir == NULL) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "Failed to open /proc/asound"); ++ return -1; ++ } ++ ++ while ((entry = readdir(dir)) != NULL) { ++ if (entry->d_type == DT_DIR && strncmp(entry->d_name, "card", 4) == 0) { ++ snprintf(card_dir, sizeof(card_dir), "/proc/asound/%s", entry->d_name); ++ ++ // check is or not exist usb audio devices ++ if (is_usb_audio_device(card_dir)) { ++ card = atoi(entry->d_name + 4); ++ MEDIA_HAL_LOGE(MODULE_NAME, "list_usb_audio_devices card_num = %d",*card_num); ++ // check device is or not exist ++ snprintf(card_dir, sizeof(card_dir), "/proc/asound/card%d/%s/sub0", card, device_str); ++ pcm_file = fopen(card_dir, "r"); ++ if (pcm_file) { ++ *card_num = card; ++ MEDIA_HAL_LOGE(MODULE_NAME, "Card: %d, Device: 0 (Playback supported)\n", *card_num); ++ fclose(pcm_file); ++ usbcard_invaild = 1; ++ } ++ ++ } ++ } ++ } ++ if (usbcard_invaild) { ++ return 0; ++ } ++ closedir(dir); ++ return -1; ++} ++static int32_t UsbPortOpen(AudioHandle *portHandle) ++{ ++ int32_t card_usb = -1; ++ int32_t ret = 0; ++ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "Input param portHandle is null"); ++ ++ UsbPortContext *priPortCtx = (UsbPortContext *)malloc(sizeof(UsbPortContext)); ++ if (priPortCtx == NULL) { ++ MEDIA_HAL_LOGI(MODULE_NAME, "malloc UsbPortContext failed"); ++ return MEDIA_HAL_NO_MEM; ++ } ++ if (memset_s(priPortCtx, sizeof(UsbPortContext), 0, sizeof(UsbPortContext)) != EOK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s UsbPortContext failed"); ++ free(priPortCtx); ++ return MEDIA_HAL_ERR; ++ } ++ ++ if(!list_usb_audio_devices(&card_usb, "pcm0c")) { ++ priPortCtx->card_usb_num = card_usb; ++ ret = AudioUsbSubPortInOpen(&priPortCtx->subPortInHandle, card_usb); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortInOpen failed ret 0x%x", ret); ++ free(priPortCtx); ++ return ret; ++ } ++ } ++ if(!list_usb_audio_devices(&card_usb, "pcm0p")) { ++ priPortCtx->card_usb_num = card_usb; ++ int ret = AudioUsbSubPortOutOpen(&priPortCtx->subPortOutHandle, card_usb); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortOutOpen failed ret 0x%x", ret); ++ free(priPortCtx); ++ return ret; ++ } ++ } ++ priPortCtx->isOpened = true; ++ *portHandle = priPortCtx; ++ MEDIA_HAL_LOGD(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++} ++ ++static bool AudioPluginIsValidPin(enum AudioPortPin pin, const char *pluginName) ++{ ++ if (strcmp("Usb", pluginName) == 0) { ++ if (pin == PIN_IN_USB_EXT || pin == PIN_OUT_USB_EXT || pin == PIN_OUT_USB) { ++ return true; ++ } ++ } ++ return false; ++} ++ ++static int32_t UsbPortCreateTrack(AudioHandle portHandle, enum AudioPortPin audioPortPin, ++ struct PortPluginAttr *portAttr, AudioHandle *trackHandle) ++{ ++ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "Input param portHandle is null"); ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "Input param trackHandle is null"); ++ CHK_NULL_RETURN(portAttr, MEDIA_HAL_INVALID_PARAM, "Input param portAttr is null"); ++ ++ if (!AudioPluginIsValidPin(audioPortPin, "Usb")) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "pin 0x%x is invalid", audioPortPin); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ ++ UsbPortContext *priPortCtx = (UsbPortContext *)portHandle; ++ CHK_FAILED_RETURN(priPortCtx->isOpened, true, MEDIA_HAL_ERR, "port not open"); ++ ++ int32_t ret; ++ MEDIA_HAL_LOGI(MODULE_NAME, "audioPortPin=%d", audioPortPin); ++ if (audioPortPin == PIN_IN_USB_EXT) { ++ ret = AudioUsbSubPortInCreateTrack(priPortCtx->subPortInHandle, ++ trackHandle, portAttr, audioPortPin); ++ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortInCreateTrack failed"); ++ } else { ++ ret = AudioUsbSubPortOutCreateTrack(priPortCtx->subPortOutHandle, ++ trackHandle, portAttr, audioPortPin); ++ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortOutCreateTrack failed"); ++ } ++ ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t UsbPortDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle) ++{ ++ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "Input param portHandle is null"); ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "Input param trackHandle is null"); ++ ++ UsbPortContext *priPortCtx = (UsbPortContext *)portHandle; ++ CHK_FAILED_RETURN(priPortCtx->isOpened, true, MEDIA_HAL_ERR, "port not open"); ++ ++ int32_t ret; ++ AudioPortTrack *track = (AudioPortTrack *)trackHandle; ++ if (track->audioPin == PIN_IN_USB_EXT) { ++ ret = AudioUsbSubPortInDestroyTrack(priPortCtx->subPortInHandle, trackHandle); ++ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortInDestroyTrack failed"); ++ } else { ++ ret = AudioUsbSubPortOutDestroyTrack(priPortCtx->subPortOutHandle, trackHandle); ++ CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "AudioUsbSubPortOutDestroyTrack failed"); ++ } ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t UsbPortClose(AudioHandle portHandle) ++{ ++ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "Input param portHandle is null"); ++ UsbPortContext *priPortCtx = (UsbPortContext *)portHandle; ++ CHK_FAILED_RETURN(priPortCtx->isOpened, true, MEDIA_HAL_ERR, "port not open"); ++ ++ int32_t ret = AudioUsbSubPortInClose(priPortCtx->subPortInHandle); ++ CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "AudioUsbSubPortInClose failed"); ++ ret = AudioUsbSubPortOutClose(priPortCtx->subPortOutHandle); ++ CHK_FAILED_NO_RETURN(ret, MEDIA_HAL_OK, "AudioUsbSubPortOutClose failed"); ++ ++ priPortCtx->isOpened = false; ++ free(priPortCtx); ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++} ++ ++static AudioPortPlugin g_usbPortPlugin = { ++ .audioPortDir = PORT_OUT_IN, ++ .audioPortPins = PIN_IN_USB_EXT | PIN_OUT_USB_EXT | PIN_OUT_USB, ++ .GetPortPluginCapability = UsbPortGetPortPluginCapability, ++ .Open = UsbPortOpen, ++ .CreateTrack = UsbPortCreateTrack, ++ .DestroyTrack = UsbPortDestroyTrack, ++ .Close = UsbPortClose, ++ .SetMute = NULL, ++ .GetMute = NULL, ++ .SetVolume = NULL, ++ .GetVolume = NULL, ++}; ++ ++const AudioPortPlugin *GetPortPluginFuncs(AudioPluginType pluginType) ++{ ++ if (pluginType == AUDIO_PLUGIN_BLUETOOTH) { ++ return NULL; ++ } ++ return &g_usbPortPlugin; ++} ++ ++#ifdef __cplusplus ++#if __cplusplus ++} ++#endif ++#endif /* __cplusplus */ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.h ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.h +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.h 1970-01-01 08:00:00.000000000 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin/audio_usb_port_plugin.h 2025-12-18 15:44:30.874238483 +0800 +@@ -0,0 +1,21 @@ ++ /* ++ * Copyright (c) 2024 RKH Corp. ++ * 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. ++ */ ++ ++#ifndef PRIMARY_PORT_PLUGIN_H ++#define PRIMARY_PORT_PLUGIN_H ++ ++#include "audio_port_plugin.h" ++ ++#endif +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/include/audio_port_plugin_common.h ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/include/audio_port_plugin_common.h +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/include/audio_port_plugin_common.h 1970-01-01 08:00:00.000000000 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/include/audio_port_plugin_common.h 2025-12-18 15:44:30.874238483 +0800 +@@ -0,0 +1,66 @@ ++ /* ++ * Copyright (c) 2024 RKH Corp. ++ * 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. + */ + @@ -676,9 +2535,9 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device +#endif +#endif /* __cplusplus */ +#endif -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/src/audio_port_plugin_common.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/src/audio_port_plugin_common.c +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/src/audio_port_plugin_common.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/src/audio_port_plugin_common.c --- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/src/audio_port_plugin_common.c 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/src/audio_port_plugin_common.c 2025-11-07 14:44:54.873657233 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_port_plugin_common/src/audio_port_plugin_common.c 2025-12-18 15:44:30.874238483 +0800 @@ -0,0 +1,273 @@ + /* + * Copyright (c) 2024 RKH Corp. @@ -953,9 +2812,9 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device +} +#endif +#endif /* __cplusplus */ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.c +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.c --- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.c 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.c 2025-11-07 14:44:54.873657233 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.c 2025-12-18 15:44:30.874238483 +0800 @@ -0,0 +1,725 @@ + /* + * Copyright (c) 2024 RKH Corp. @@ -972,789 +2831,6447 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device + * limitations under the License. + */ + -+#include "audio_usb_sub_port_in.h" -+#include -+#ifndef __HuaweiLite__ -+#include -+#endif -+#include "securec.h" -+/* SDK include */ -+#include "ss_mpi_audio.h" -+#include "ot_common_aio.h" -+#include "ot_common_aenc.h" -+#include "audio_aac_adp.h" -+#include "media_hal_common.h" -+#include "audio_port_plugin_common.h" -+#include -+// #include "audio_effect_manager.h" ++#include "audio_usb_sub_port_in.h" ++#include ++#ifndef __HuaweiLite__ ++#include ++#endif ++#include "securec.h" ++/* SDK include */ ++#include "ss_mpi_audio.h" ++#include "ot_common_aio.h" ++#include "ot_common_aenc.h" ++#include "audio_aac_adp.h" ++#include "media_hal_common.h" ++#include "audio_port_plugin_common.h" ++#include ++// #include "audio_effect_manager.h" ++ ++#ifdef __cplusplus ++#if __cplusplus ++extern "C" { ++#endif ++#endif /* __cplusplus */ ++#define MODULE_NAME "AudioPrimarySubPortIn" ++ ++#define MAX_INPUT_PORT_CNT OT_AI_DEV_MAX_NUM ++#define MAX_INPUT_PORT_TRACK_CNT OT_AI_MAX_CHN_NUM ++ ++#define MAX_KEY_STR_LEN 10 ++ ++#define PORT_ID(module, device, channel) \ ++ ((unsigned int)(((module) << 16) | ((device) << 8) | (channel))) ++ ++/* count of audio frame in Buffer */ ++#define AUDIO_FRAME_NUM_IN_BUF 30 ++ ++/* sample per frame for all encoder(aacplus:2048) */ ++#define AUDIO_AUDIO_POINT_NUM 1024 ++ ++#define AUDIO_FRAME_CACHED_DEPTH 5 ++ ++#define AUDIO_INPUT_VOL 30 ++ ++#define AUDIO_HAL_FRAME_COUNT 1024 ++ ++#define AUDIO_AO_INNER_DEV_ID 0 /** ao inner acodec dev id */ ++ ++#define AUDIO_VQE_ANR_NOISE_DB_THR 45 ++#define AUDIO_VQE_ANR_NR_INTENSITY 15 ++static const float VOLUME_PERCENT_MIN_IN = 0.0f; ++static const float VOLUME_PERCENT_MAX_IN = 100.0f; ++ ++const unsigned long long TIME_CONVERSION_US_S = 1000000ULL; /* us to s */ ++const unsigned long long TIME_CONVERSION_NS_US = 1000ULL; /* ns to us */ ++ ++static enum AudioFormat g_audioInFormats[] = { AUDIO_FORMAT_TYPE_PCM_16_BIT }; ++ ++typedef struct { ++ /* track impl */ ++ AudioPortTrack common; ++ bool mute; ++ float volume; ++ float gain; ++ uint32_t currentChannelId; ++ uint64_t frames; ++ struct PortPluginAttr inputAttr; ++ struct AudioTimeStamp aiTimeStamp; ++ /* MPP LIB */ ++ ot_audio_dev aiDeviceId; ++ snd_pcm_t *ai_pcm_handle; ++ snd_mixer_t *ai_mixer_handle; ++ snd_mixer_elem_t *ai_elem_vol; ++ long ai_min_vol, ai_max_vol; ++ ot_aio_attr aiAttr; ++ ot_ai_chn aiChn; ++ ot_mpp_chn stSrcChn; ++ ot_mpp_chn stDestChn; ++ /* talk vqe ao info */ ++ ot_audio_dev refAoDevId; ++ ot_ai_chn refAoChnId; ++ enum VqeScene vqeScene; ++} SubPortTrackInContext; ++ ++typedef struct { ++ bool opened; ++ ot_audio_dev aiDeviceId; ++ snd_pcm_t *ai_pcm_handle; ++ snd_mixer_t *ai_mixer_handle; ++ snd_mixer_elem_t *ai_elem_vol; ++ long ai_min_vol, ai_max_vol; ++ SubPortTrackInContext *portTrackInCtx[MAX_INPUT_PORT_TRACK_CNT]; ++ pthread_mutex_t mutex; ++} SubPortInContext; ++ ++typedef struct { ++ bool used; ++ int32_t chnID; ++ SubPortInContext *portInCtx; ++} SubPortInMng; ++ ++static SubPortInMng g_subPortIn[MAX_INPUT_PORT_CNT]; ++static bool g_subPortInMngInited = false; ++static pthread_mutex_t g_subPortInMngLock = PTHREAD_MUTEX_INITIALIZER; ++ ++static void AudioSubPortInMngInit(void) ++{ ++ MEDIA_HAL_LOCK(g_subPortInMngLock); ++ if (!g_subPortInMngInited) { ++ for (int32_t i = 0; i < MAX_INPUT_PORT_CNT; i++) { ++ g_subPortIn[i].used = false; ++ g_subPortIn[i].chnID = i; ++ } ++ g_subPortInMngInited = true; ++ } ++ MEDIA_HAL_UNLOCK(g_subPortInMngLock); ++ int32_t ret = MediaSystemInit(); ++ if (ret != 0) { ++ MEDIA_HAL_LOGW(MODULE_NAME, "MediaSystemInit failed ret%d", ret); ++ } ++} ++ ++static int32_t AudioSubPortInMngGetFreeChn(void) ++{ ++ MEDIA_HAL_LOCK(g_subPortInMngLock); ++ if (!g_subPortInMngInited) { ++ MEDIA_HAL_UNLOCK(g_subPortInMngLock); ++ return MEDIA_HAL_ERR; ++ } ++ for (int32_t i = 0; i < MAX_INPUT_PORT_CNT; i++) { ++ if (!g_subPortIn[i].used) { ++ g_subPortIn[i].used = true; ++ int32_t chnID = g_subPortIn[i].chnID; ++ MEDIA_HAL_UNLOCK(g_subPortInMngLock); ++ return chnID; ++ } ++ } ++ MEDIA_HAL_UNLOCK(g_subPortInMngLock); ++ MEDIA_HAL_LOGE(MODULE_NAME, "could get free audio Input channel"); ++ return MEDIA_HAL_ERR; ++} ++ ++static int32_t AudioUsbSubPortInGetFreeTrack(SubPortInContext *portInCtx) ++{ ++ MEDIA_HAL_LOCK(portInCtx->mutex); ++ for (int32_t i = 0; i < MAX_INPUT_PORT_TRACK_CNT; i++) { ++ if (portInCtx->portTrackInCtx[i] == NULL) { ++ MEDIA_HAL_UNLOCK(portInCtx->mutex); ++ return i; ++ } ++ } ++ MEDIA_HAL_UNLOCK(portInCtx->mutex); ++ MEDIA_HAL_LOGE(MODULE_NAME, "could get free audio Input track"); ++ return MEDIA_HAL_ERR; ++} ++ ++static int32_t AudioUsbSubPortInFreeTrack(SubPortInContext *portInCtx, ++ SubPortTrackInContext *portTrackInCtx) ++{ ++ MEDIA_HAL_LOCK(portInCtx->mutex); ++ for (int32_t i = 0; i < MAX_INPUT_PORT_TRACK_CNT; i++) { ++ if (portInCtx->portTrackInCtx[i] == portTrackInCtx) { ++ portInCtx->portTrackInCtx[i] = NULL; ++ MEDIA_HAL_UNLOCK(portInCtx->mutex); ++ return MEDIA_HAL_OK; ++ } ++ } ++ MEDIA_HAL_UNLOCK(portInCtx->mutex); ++ MEDIA_HAL_LOGE(MODULE_NAME, "could not found audio Input track"); ++ return MEDIA_HAL_ERR; ++} ++ ++static int32_t AudioUsbSubPortInMngFreeChn(int32_t chnID) ++{ ++ MEDIA_HAL_LOCK(g_subPortInMngLock); ++ if (!g_subPortInMngInited) { ++ MEDIA_HAL_UNLOCK(g_subPortInMngLock); ++ return MEDIA_HAL_ERR; ++ } ++ for (int32_t i = 0; i < MAX_INPUT_PORT_CNT; i++) { ++ if (g_subPortIn[i].chnID == chnID) { ++ g_subPortIn[i].used = false; ++ MEDIA_HAL_UNLOCK(g_subPortInMngLock); ++ return MEDIA_HAL_OK; ++ } ++ } ++ MEDIA_HAL_UNLOCK(g_subPortInMngLock); ++ MEDIA_HAL_LOGE(MODULE_NAME, "freehandle input audio Input handle invalid : %d", chnID); ++ return MEDIA_HAL_ERR; ++} ++ ++static int32_t AudioPrimarySubPortInSetExtraParam(SubPortTrackInContext *portTrackInCtx, ++ const struct InvokeAttr *invokeAttr) ++{ ++ char aoDeviceIdKey[MAX_KEY_STR_LEN] = { 0 }; ++ char aoChanneIdKey[MAX_KEY_STR_LEN] = { 0 }; ++ int32_t aoDeviceId = -1; ++ int32_t aoChannelId = -1; ++ ++ int32_t ret = sscanf_s((const char *)invokeAttr->request, "%s = %d %s = %d", aoDeviceIdKey, MAX_KEY_STR_LEN, ++ &aoDeviceId, aoChanneIdKey, MAX_KEY_STR_LEN, &aoChannelId); ++ if (ret == MEDIA_HAL_ERR) { ++ MEDIA_HAL_LOGI(MODULE_NAME, "sscanf_s failed"); ++ return ret; ++ } ++ ++ portTrackInCtx->refAoDevId = aoDeviceId; ++ portTrackInCtx->refAoChnId = aoChannelId; ++ ++ MEDIA_HAL_LOGI(MODULE_NAME, "%s = %d, %s = %d", aoDeviceIdKey, aoDeviceId, aoChanneIdKey, aoChannelId); ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t DualMono2Stereo(char *audioData, char *audioLeft, ++ char *audioRight, uint32_t audioLen) ++{ ++ if (audioData == NULL || audioLeft == NULL || audioRight == NULL) { ++ return -1; ++ } ++ uint32_t i, j; ++ uint32_t framesize = 2; ++ uint32_t signleDataLen = audioLen / 2; ++ ++ for (i = 0; i < signleDataLen; i += framesize) { ++ for (j = 0; j < framesize; j++) { ++ audioData[2 * i + j] = audioLeft[i + j]; ++ audioData[2 * i + framesize + j] = audioLeft[i + j]; ++ } ++ } ++ ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInGetCapability(const struct AudioPort *port, struct AudioPortCapability *capability) ++{ ++ MEDIA_HAL_UNUSED(port); ++ capability->sampleRateMasks = 0; ++ capability->sampleRateMasks |= AUDIO_SAMPLE_RATE_MASK_48000; ++ capability->sampleRateMasks |= AUDIO_SAMPLE_RATE_MASK_96000; ++ capability->hardwareMode = true; ++ capability->formats = g_audioInFormats; ++ capability->subPortsNum = 0; ++ capability->subPorts = NULL; ++ ++ capability->channelCount = AUDIO_STEREO_SOUND_MODE_CHN_CNT; ++ MEDIA_HAL_LOGD(MODULE_NAME, "usb support stereo"); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInGetFrameCount(AudioHandle trackHandle, uint64_t *count) ++{ ++ MEDIA_HAL_UNUSED(trackHandle); ++ ++ *count = AUDIO_HAL_FRAME_COUNT; ++ MEDIA_HAL_LOGI(MODULE_NAME, "FrameCount :%llu", *count); ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t AiInit(SubPortInContext *portInCtx, ot_aio_attr aiAttr) ++{ ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++} ++ ++static bool AudioConvertAudioFormatToHAL(enum AudioFormat format, uint32_t *ptNumPerFrm) ++{ ++ if (ptNumPerFrm == NULL) { ++ return false; ++ } ++ switch (format) { ++ case AUDIO_FORMAT_TYPE_PCM_16_BIT: ++ case AUDIO_FORMAT_TYPE_AAC_LC: ++ case AUDIO_FORMAT_TYPE_AAC_LD: ++ case AUDIO_FORMAT_TYPE_AAC_ELD: ++ case AUDIO_FORMAT_TYPE_AAC_HE_V1: ++ case AUDIO_FORMAT_TYPE_AAC_HE_V2: ++ *ptNumPerFrm = AUDIO_AAC_PCM_PTNUMPERFRM; ++ break; ++ case AUDIO_FORMAT_TYPE_G711A: ++ case AUDIO_FORMAT_TYPE_G711U: ++ case AUDIO_FORMAT_TYPE_G726: ++ *ptNumPerFrm = AUDIO_G711_G726_PTNUMPERFRM; ++ break; ++ default: ++ MEDIA_HAL_LOGW(MODULE_NAME, "Invalid audio format: %d", format); ++ return false; ++ } ++ return true; ++} ++ ++static int32_t AiAttrConfig(const struct PortPluginAttr *inputAttr, ot_aio_attr *aiAttr) ++{ ++ if (memset_s(aiAttr, sizeof(ot_aio_attr), 0x0, sizeof(ot_aio_attr)) != EOK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s: portInCtx aiAttr failed"); ++ return MEDIA_HAL_ERR; ++ } ++ if (!AudioConvertSampleRateToHAL(inputAttr->sampleRate, &(aiAttr->sample_rate))) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertSampleRateToHAL sample_rate: %d failed", inputAttr->sampleRate); ++ return MEDIA_HAL_ERR; ++ } ++ aiAttr->bit_width = OT_AUDIO_BIT_WIDTH_16; ++ aiAttr->work_mode = OT_AIO_MODE_I2S_MASTER; ++ if (!AudioConvertChannelToHAL(inputAttr->channelCount, &(aiAttr->snd_mode))) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertChannelToHAL channelCount: %u failed ", inputAttr->channelCount); ++ return MEDIA_HAL_ERR; ++ } ++ aiAttr->expand_flag = 0; ++ aiAttr->frame_num = AUDIO_FRAME_NUM_IN_BUF; ++ if (!AudioConvertAudioFormatToHAL(inputAttr->audioFormat, &(aiAttr->point_num_per_frame))) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertCodecFormatToHAL codecFormat: %d failed ", inputAttr->audioFormat); ++ return MEDIA_HAL_ERR; ++ } ++ aiAttr->chn_cnt = inputAttr->channelCount; ++ aiAttr->clk_share = 1; ++ aiAttr->i2s_type = OT_AIO_I2STYPE_INNERCODEC; ++ return MEDIA_HAL_OK; ++} ++ ++static void SubPortTrackInInit(SubPortTrackInContext *portTrackInCtx, const struct PortPluginAttr *inputAttr, ++ enum AudioPortPin audioPortPin) ++{ ++ portTrackInCtx->inputAttr = *inputAttr; ++ ++ portTrackInCtx->common.audioPin = audioPortPin; ++ portTrackInCtx->common.GetFrameCount = AudioUsbSubPortInGetFrameCount; ++ portTrackInCtx->common.GetLatency = NULL; ++ portTrackInCtx->common.EnableTrack = AudioUsbSubPortInEnableTrack; ++ portTrackInCtx->common.PauseTrack = NULL; ++ portTrackInCtx->common.ResumeTrack = NULL; ++ portTrackInCtx->common.FlushTrack = NULL; ++ portTrackInCtx->common.DisableTrack = AudioUsbSubPortInDisableTrack; ++ portTrackInCtx->common.AcquireFrame = AudioUsbSubPortInAcquireFrame; ++ portTrackInCtx->common.SendFrame = NULL; ++ portTrackInCtx->common.GetPosition = AudioUsbSubPortInGetPosition; ++ portTrackInCtx->common.SetMute = AudioUsbSubPortInSetMute; ++ portTrackInCtx->common.GetMute = AudioUsbSubPortInGetMute; ++ portTrackInCtx->common.SetVolume = AudioUsbSubPortInSetVolume; ++ portTrackInCtx->common.GetVolume = AudioUsbSubPortInGetVolume; ++ portTrackInCtx->common.Invoke = AudioUsbSubPortInInvoke; ++ ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++} ++ ++int32_t AudioUsbSubPortInSetMute(AudioHandle trackHandle, bool mute) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ ++ if(mute) { // mute set input volume to 0 ++ snd_mixer_selem_set_capture_volume_all(portTrackInCtx->ai_elem_vol, 0); ++ } else { // unmute set input volume to last volume ++ long vol = portTrackInCtx->ai_min_vol + (portTrackInCtx->ai_max_vol - portTrackInCtx->ai_min_vol) * portTrackInCtx->volume / 100; ++ snd_mixer_selem_set_capture_volume_all(portTrackInCtx->ai_elem_vol, vol); ++ } ++ portTrackInCtx->mute = mute; ++ MEDIA_HAL_LOGI(MODULE_NAME, "set mute %d", mute); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInGetMute(AudioHandle trackHandle, bool *mute) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ ++ *mute = portTrackInCtx->mute; ++ MEDIA_HAL_LOGE(MODULE_NAME, "get mute %d", *mute); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInSetVolume(AudioHandle trackHandle, float volume) ++{ ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ int32_t ret; ++ if (volume < VOLUME_PERCENT_MIN_IN || volume > VOLUME_PERCENT_MAX_IN) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortInSetVolume, volume:%f err, it should [%f,%f]", volume, ++ VOLUME_PERCENT_MIN_IN, VOLUME_PERCENT_MAX_IN); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ const float EPSINON = 0.00001; ++ if ((volume >= -EPSINON) && (volume <= EPSINON)) { ++ ot_audio_fade fade = {}; ++ portTrackInCtx->volume = volume; ++ snd_mixer_selem_set_capture_volume_all(portTrackInCtx->ai_elem_vol, 0); ++ return MEDIA_HAL_OK; ++ } ++ ++ long vol = portTrackInCtx->ai_min_vol + (portTrackInCtx->ai_max_vol - portTrackInCtx->ai_min_vol) * volume / 100; ++ ret = snd_mixer_selem_set_capture_volume_all(portTrackInCtx->ai_elem_vol, vol); ++ if (ret < 0) { ++ MEDIA_HAL_LOGI(MODULE_NAME, "SetVolume failed: %s\n", snd_strerror(ret)); ++ return ret; ++ } ++ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortInSetVolume SetVolume: %d (raw=%ld)\n", volume, vol); ++ portTrackInCtx->volume = volume; ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInGetVolume(AudioHandle trackHandle, float *volume) ++{ ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ ++ *volume = (float)portTrackInCtx->volume; ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInOpen(AudioHandle *portHandle, int card_usb) ++{ ++ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); ++ int32_t ret; ++ if (!g_subPortInMngInited) { ++ AudioSubPortInMngInit(); ++ } ++ ++ int32_t portId = AudioSubPortInMngGetFreeChn(); ++ CHK_COND_RETURN(portId == MEDIA_HAL_INVALID_CHN_ID, MEDIA_HAL_ERR, "no free AI device"); ++ ++ SubPortInContext *portInCtx = (SubPortInContext *)malloc(sizeof(SubPortInContext)); ++ if (portInCtx == NULL) { ++ MEDIA_HAL_LOGI(MODULE_NAME, "malloc failed"); ++ ret = MEDIA_HAL_NO_MEM; ++ goto FREE_CHN; ++ } ++ ++ if (memset_s(portInCtx, sizeof(SubPortInContext), 0, sizeof(SubPortInContext)) != EOK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s failed"); ++ ret = MEDIA_HAL_ERR; ++ goto FREE; ++ } ++ ++ portInCtx->aiDeviceId = portId; ++ // todo zhp ++ char PCM_DEVICE[32]; ++ snprintf(PCM_DEVICE, sizeof(PCM_DEVICE), "hw:%d,0", card_usb); ++ int pcm = snd_pcm_open(&(portInCtx->ai_pcm_handle), PCM_DEVICE, SND_PCM_STREAM_CAPTURE, 0); ++ if (pcm < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_open failed"); ++ ret = MEDIA_HAL_ERR; ++ goto FREE; ++ } ++ ++ ret = snd_mixer_open(&(portInCtx->ai_mixer_handle), 0); ++ if (ret < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_open failed: %s\n", snd_strerror(ret)); ++ return ret; ++ } ++ char CTL_DEVICE[32]; ++ snprintf(CTL_DEVICE, sizeof(CTL_DEVICE), "hw:%d", card_usb); ++ ret = snd_mixer_attach(portInCtx->ai_mixer_handle, CTL_DEVICE); ++ if (ret < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_attach failed: %s\n", snd_strerror(ret)); ++ snd_mixer_close(portInCtx->ai_mixer_handle); ++ return ret; ++ } ++ ++ snd_mixer_selem_register(portInCtx->ai_mixer_handle, NULL, NULL); ++ snd_mixer_load(portInCtx->ai_mixer_handle); ++ ++ // get element "Master" or "PCM" with volume control ++ snd_mixer_elem_t *elem = NULL; ++ for (elem = snd_mixer_first_elem(portInCtx->ai_mixer_handle); elem; elem = snd_mixer_elem_next(elem)) { ++ if (snd_mixer_selem_is_active(elem)) { ++ const char *name = snd_mixer_selem_get_name(elem); ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_selem_get_name name=%s\n", name); ++ if ((strcmp(name, "Mic") == 0) && snd_mixer_selem_has_capture_volume(elem)) { ++ portInCtx->ai_elem_vol = elem; ++ break; ++ } ++ } ++ } ++ ++ if (!(portInCtx->ai_elem_vol)) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "Cannot find suitable mixer element (Master/PCM)\n"); ++ snd_mixer_close(portInCtx->ai_mixer_handle); ++ // maybe some device not support volume control ++ // return -1; ++ } ++ ++ // get volume range ++ snd_mixer_selem_get_capture_volume_range(portInCtx->ai_elem_vol, &portInCtx->ai_min_vol, &portInCtx->ai_max_vol); ++ MEDIA_HAL_LOGE(MODULE_NAME, "Volume range: [%ld, %ld]\n", portInCtx->ai_min_vol, portInCtx->ai_max_vol); ++ ++ pthread_mutex_init(&portInCtx->mutex, NULL); ++ portInCtx->opened = true; ++ ++ *portHandle = portInCtx; ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++ ++FREE: ++ free(portInCtx); ++FREE_CHN: ++ (void)AudioUsbSubPortInMngFreeChn(portId); ++ return ret; ++} ++ ++int32_t AudioUsbSubPortInClose(AudioHandle portHandle) ++{ ++ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); ++ SubPortInContext *portInCtx = (SubPortInContext *)portHandle; ++ ++ (void)AudioUsbSubPortInMngFreeChn(portInCtx->aiDeviceId); ++ snd_mixer_close(portInCtx->ai_mixer_handle); ++ snd_pcm_drain(portInCtx->ai_pcm_handle); ++ snd_pcm_close(portInCtx->ai_pcm_handle); ++ free(portInCtx); ++ ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInCreateTrack(AudioHandle portHandle, AudioHandle *trackHandle, ++ struct PortPluginAttr *inputAttr, enum AudioPortPin audioPortPin) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); ++ SubPortInContext *portInCtx = (SubPortInContext *)portHandle; ++ ++ int32_t trackIndex = AudioUsbSubPortInGetFreeTrack(portInCtx); ++ if (trackIndex == -1) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "can not found free Input Port track"); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)malloc(sizeof(SubPortTrackInContext)); ++ if (portTrackInCtx == NULL) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "malloc SubPortTrackInContext failed"); ++ return MEDIA_HAL_NO_MEM; ++ } ++ if (memset_s(portTrackInCtx, sizeof(SubPortTrackInContext), 0, ++ sizeof(SubPortTrackInContext)) != 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s SubPortTrackInContext failed"); ++ } ++ // todo zhp ++ SubPortTrackInInit(portTrackInCtx, inputAttr, audioPortPin); ++ ++ int32_t ret = AiAttrConfig(inputAttr, &(portTrackInCtx->aiAttr)); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AiAttrConfig %#x", ret); ++ goto FREE_TRACK_IN; ++ } ++ MEDIA_HAL_LOGE(MODULE_NAME, "aiAttr.bit_width: %d, snd_mode: %d, sample_rate: %d, chn_cnt: %d", portTrackInCtx->aiAttr.bit_width, portTrackInCtx->aiAttr.snd_mode, ++ portTrackInCtx->aiAttr.sample_rate, portTrackInCtx->aiAttr.chn_cnt); ++ snd_pcm_hw_params_t *params; ++ snd_pcm_uframes_t frames = 4096; ++ snd_pcm_hw_params_malloc(¶ms); ++ snd_pcm_hw_params_any(portInCtx->ai_pcm_handle, params); ++ snd_pcm_hw_params_set_access(portInCtx->ai_pcm_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); ++ // todo zhp ++ // snd_pcm_format_t format ++ //AudioConvertFormatToAlsa(aoAttr.bit_width, &format); ++ snd_pcm_hw_params_set_format(portInCtx->ai_pcm_handle, params, SND_PCM_FORMAT_S16_LE); ++ snd_pcm_hw_params_set_channels(portInCtx->ai_pcm_handle, params, portTrackInCtx->aiAttr.chn_cnt); ++ snd_pcm_hw_params_set_rate_near(portInCtx->ai_pcm_handle, params, &(portTrackInCtx->aiAttr.sample_rate), 0); ++ snd_pcm_hw_params_set_period_size_near(portInCtx->ai_pcm_handle, params, &frames, 0); ++ snd_pcm_hw_params(portInCtx->ai_pcm_handle, params); ++ snd_pcm_hw_params_free(params); ++ ++ // do nothing ++ ret = AiInit(portInCtx, portTrackInCtx->aiAttr); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AiInit failed %#x", ret); ++ goto FREE_TRACK_IN; ++ } ++ ++ portTrackInCtx->aiDeviceId = portInCtx->aiDeviceId; ++ portTrackInCtx->aiChn = trackIndex; ++ portTrackInCtx->ai_pcm_handle = portInCtx->ai_pcm_handle; ++ portTrackInCtx->ai_mixer_handle = portInCtx->ai_mixer_handle; ++ portTrackInCtx->ai_elem_vol = portInCtx->ai_elem_vol; ++ portTrackInCtx->ai_min_vol = portInCtx->ai_min_vol; ++ portTrackInCtx->ai_max_vol = portInCtx->ai_max_vol; ++ portTrackInCtx->refAoDevId = -1; ++ portTrackInCtx->refAoChnId = -1; ++ portTrackInCtx->vqeScene = VQE_SCENE_NONE; ++ portTrackInCtx->currentChannelId = PORT_ID(OT_ID_AI, 0, (uint32_t)portTrackInCtx->aiChn); ++ portInCtx->portTrackInCtx[trackIndex] = portTrackInCtx; ++ *trackHandle = &portTrackInCtx->common; ++ ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++ ++FREE_TRACK_IN: ++ free(portTrackInCtx); ++ return ret; ++} ++ ++int32_t AudioUsbSubPortInEnableTrack(AudioHandle trackHandle) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ int32_t ret; ++ ot_ai_chn_param stAiChnParam; ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ MEDIA_HAL_LOGI(MODULE_NAME, "AudioUsbSubPortInEnableTrack in"); ++ ++ ret = snd_pcm_prepare(portTrackInCtx->ai_pcm_handle); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_prepare ret=0x%x", ret); ++ return ret; ++ } ++ ++ MEDIA_HAL_LOGI(MODULE_NAME, "AudioUsbSubPortInEnableTrack out"); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInAcquireFrame(AudioHandle trackHandle, uint8_t *buffer, uint64_t requestBytes, ++ uint64_t *replyBytes) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ int32_t ret; ++ long frames; ++ int bytes_per_sample = (portTrackInCtx->aiAttr.bit_width + 1); // 0:8bit, 1:16bit ++ int channels = (portTrackInCtx->aiAttr.snd_mode == OT_AUDIO_SOUND_MODE_STEREO) ? 2 : 1; ++ int bytes_per_frame = bytes_per_sample * channels; ++ ++ uint64_t remaining_bytes = requestBytes; ++ *replyBytes = 0; ++ ++ while (remaining_bytes > 0) { ++ frames = snd_pcm_readi(portTrackInCtx->ai_pcm_handle, buffer, remaining_bytes / bytes_per_frame); ++ if (frames > 0) { ++ size_t bytes_read = frames * bytes_per_frame; ++ remaining_bytes -= bytes_read; ++ buffer += bytes_read; ++ *replyBytes += bytes_read; ++ } else if (frames == -EAGAIN) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "capture PCM readi -EAGAIN"); ++ snd_pcm_wait(portTrackInCtx->ai_pcm_handle, 100); ++ } else if (frames == -EBADFD) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "capture PCM bad state, preparing..."); ++ snd_pcm_prepare(portTrackInCtx->ai_pcm_handle); ++ return MEDIA_HAL_ERR; ++ } else { ++ MEDIA_HAL_LOGE(MODULE_NAME, "capture err: %s", snd_strerror(frames)); ++ ret = snd_pcm_recover(portTrackInCtx->ai_pcm_handle, frames, 0); ++ if (ret < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "capture recover failed: %s", snd_strerror(ret)); ++ return MEDIA_HAL_ERR; ++ } ++ } ++ } ++ *replyBytes = requestBytes; ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInGetPosition(AudioHandle trackHandle, ++ uint64_t *frames, struct AudioTimeStamp *time) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ ++ time->tvSec = portTrackInCtx->aiTimeStamp.tvSec; ++ time->tvNSec = portTrackInCtx->aiTimeStamp.tvNSec; ++ *frames = portTrackInCtx->frames; ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInDisableTrack(AudioHandle trackHandle) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ ++ ++ snd_pcm_drain(portTrackInCtx->ai_pcm_handle); ++ portTrackInCtx->refAoDevId = -1; ++ portTrackInCtx->refAoChnId = -1; ++ portTrackInCtx->vqeScene = VQE_SCENE_NONE; ++ ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); ++ SubPortInContext *portInCtx = (SubPortInContext *)portHandle; ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ ++ ++ int32_t ret = AudioUsbSubPortInFreeTrack(portInCtx, portTrackInCtx); ++ if (ret == -1) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "invalid trackHandle"); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ ++ ++ free(portTrackInCtx); ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortInInvoke(AudioHandle trackHandle, enum InvokeID invokeID, struct InvokeAttr *invokeAttr) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ int32_t ret = MEDIA_HAL_OK; ++ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ ++ switch (invokeID) { ++ ++ default: ++ MEDIA_HAL_LOGW(MODULE_NAME, "Invalid invokeID: %d", invokeID); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ return MEDIA_HAL_OK; ++} ++ ++#ifdef __cplusplus ++#if __cplusplus ++} ++#endif ++#endif /* __cplusplus */ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.h ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.h +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.h 1970-01-01 08:00:00.000000000 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.h 2025-12-18 15:44:30.874238483 +0800 +@@ -0,0 +1,63 @@ ++ /* ++ * Copyright (c) 2024 RKH Corp. ++ * 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. ++ */ ++ ++#ifndef AUDIO_PRIMARY_SUB_PORT_IN_H ++#define AUDIO_PRIMARY_SUB_PORT_IN_H ++ ++#include "audio_port_plugin.h" ++ ++#ifdef __cplusplus ++#if __cplusplus ++extern "C" { ++#endif ++#endif /* End of __cplusplus */ ++ ++/* sub port in track api */ ++int32_t AudioUsbSubPortInGetFrameCount(AudioHandle trackHandle, uint64_t *count); ++ ++int32_t AudioUsbSubPortInEnableTrack(AudioHandle trackHandle); ++int32_t AudioUsbSubPortInDisableTrack(AudioHandle trackHandle); ++ ++int32_t AudioUsbSubPortInAcquireFrame(AudioHandle trackHandle, uint8_t *buffer, ++ uint64_t requestBytes, uint64_t *replyBytes); ++ ++int32_t AudioUsbSubPortInGetPosition(AudioHandle trackHandle, ++ uint64_t *frames, struct AudioTimeStamp *time); ++ ++int32_t AudioUsbSubPortInSetMute(AudioHandle trackHandle, bool mute); ++int32_t AudioUsbSubPortInGetMute(AudioHandle trackHandle, bool *mute); ++ ++int32_t AudioUsbSubPortInSetVolume(AudioHandle trackHandle, float volume); ++int32_t AudioUsbSubPortInGetVolume(AudioHandle trackHandle, float *volume); ++ ++int32_t AudioUsbSubPortInInvoke(AudioHandle trackHandle, enum InvokeID invokeID, struct InvokeAttr *invokeAttr); ++ ++/* sub port in api */ ++int32_t AudioUsbSubPortInOpen(AudioHandle *portHandle, int card_usb); ++int32_t AudioUsbSubPortInClose(AudioHandle portHandle); ++ ++int32_t AudioUsbSubPortInGetCapability(const struct AudioPort *port, struct AudioPortCapability *capability); ++ ++int32_t AudioUsbSubPortInCreateTrack(AudioHandle portHandle, AudioHandle *trackHandle, ++ struct PortPluginAttr *inputAttr, enum AudioPortPin audioPortPin); ++int32_t AudioUsbSubPortInDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle); ++ ++#ifdef __cplusplus ++#if __cplusplus ++} ++#endif ++#endif /* __cplusplus */ ++ ++#endif /* AUDIO_INPUT_PORT_PLUGIN_IMPL_H */ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.c +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.c 1970-01-01 08:00:00.000000000 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.c 2025-12-18 15:44:30.874238483 +0800 +@@ -0,0 +1,816 @@ ++ /* ++ * Copyright (c) 2024 RKH Corp. ++ * 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. ++ */ ++ ++#include ++#include ++#ifndef __HuaweiLite__ ++#include ++#endif ++#include "securec.h" ++/* SDK include */ ++#include "ss_mpi_audio.h" ++#include "ot_common_aio.h" ++ ++#include "media_hal_common.h" ++#include "audio_port_plugin_common.h" ++#include ++ ++#include "audio_usb_sub_port_out.h" ++ ++#ifdef __cplusplus ++#if __cplusplus ++extern "C" { ++#endif ++#endif /* __cplusplus */ ++#define MODULE_NAME "AudioSubPortOut" ++ ++#define MAX_OUTPUT_PORT_CNT OT_AO_DEV_MAX_NUM ++#define MAX_OUTPUT_PORT_TRACK_CNT OT_AO_MAX_CHN_NUM ++ ++/* count of audio frame in Buffer */ ++#define AUDIO_FRAME_NUM_OUT_BUF 4 ++#define AUDIO_OUT_PTNUMPERFRM 1024 ++#define TIME_S_TO_US_SCALE 1000000 ++#define TIME_US_TO_NS_SCALE 1000 ++#define NO_WAIT 0 ++#define PCM_WAIT_TIMEOUT_MS 100 ++ ++struct AudioSubPortOutTrack { ++ /* track impl */ ++ AudioPortTrack common; ++ bool inited; ++ bool started; ++ bool paused; ++ bool mute; ++ float volume; ++ uint64_t frames; ++ int64_t firstFramePts; ++ int64_t currentPts; ++ struct PortPluginAttr inputAttr; ++ /* MPP LIB */ ++ ot_aio_attr aoSourceAttr; ++ ot_ao_chn aoChn; ++ ++ ot_audio_dev aoDeviceId; ++ snd_pcm_t *ao_pcm_handle; ++ snd_mixer_t *ao_mixer_handle; ++ snd_mixer_elem_t *ao_elem_vol; ++ long ao_min_vol, ao_max_vol; ++ enum VqeScene vqeScene; ++}; ++ ++struct AudioSubPortOut { ++ bool opened; ++ bool mute; ++ ot_aio_attr aoSourceAttr; ++ ot_audio_dev aoDeviceId; ++ snd_pcm_t *ao_pcm_handle; ++ snd_mixer_t *ao_mixer_handle; ++ snd_mixer_elem_t *ao_elem_vol; ++ long ao_min_vol, ao_max_vol; ++ bool aoEnabled; ++ struct AudioSubPortOutTrack *hwOutputPortTrack[MAX_OUTPUT_PORT_TRACK_CNT]; ++ pthread_mutex_t mutex; ++}; ++ ++struct AudioSubPortOutMng { ++ bool used; ++ int32_t chnID; ++ struct AudioSubPortOut *hwOutputPort; ++}; ++ ++static struct AudioSubPortOutMng g_audioHwOutputPorts[MAX_OUTPUT_PORT_CNT]; ++static bool g_audioOutputMngInited = false; ++static pthread_mutex_t g_audioOutputMngLock = PTHREAD_MUTEX_INITIALIZER; ++ ++const int32_t VOLUME_DB_MIN = -121; ++const int32_t VOLUME_DB_MAX = 6; ++static const float VOLUME_PERCENT_MIN = 0.0f; ++static const float VOLUME_PERCENT_MAX = 100.0f; ++const int32_t VOLUME_PERCENT_BASE = 100; ++const int32_t PERCENT_TO_GAIN_LOG_FACTOR = 10; ++ ++static void AudioRenderVolumePercentToDb(float volume, int32_t *db) ++{ ++ double tmpDb = PERCENT_TO_GAIN_LOG_FACTOR * log((double)volume / VOLUME_PERCENT_BASE); ++ if (tmpDb < VOLUME_DB_MIN) { ++ tmpDb = VOLUME_DB_MIN; ++ } else if (tmpDb > VOLUME_DB_MAX) { ++ tmpDb = VOLUME_DB_MAX; ++ } ++ *db = (int32_t)tmpDb; ++} ++ ++static void AudioOutputPortMngInit(void) ++{ ++ MEDIA_HAL_LOCK(g_audioOutputMngLock); ++ if (!g_audioOutputMngInited) { ++ for (int32_t i = 0; i < MAX_OUTPUT_PORT_CNT; i++) { ++ g_audioHwOutputPorts[i].used = false; ++ g_audioHwOutputPorts[i].chnID = i; ++ } ++ g_audioOutputMngInited = true; ++ } ++ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); ++} ++ ++static int32_t AudioOutputPortMngGetFreeChn() ++{ ++ MEDIA_HAL_LOCK(g_audioOutputMngLock); ++ if (!g_audioOutputMngInited) { ++ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); ++ return MEDIA_HAL_ERR; ++ } ++ for (int32_t i = 0; i < MAX_OUTPUT_PORT_CNT; i++) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "MAX_OUTPUT_PORT_CNT %d, g_audioHwOutputPorts[i].used = %d, chnID = %d", ++ MAX_OUTPUT_PORT_CNT, g_audioHwOutputPorts[i].used, g_audioHwOutputPorts[i].chnID); ++ if (!g_audioHwOutputPorts[i].used) { ++ g_audioHwOutputPorts[i].used = true; ++ int32_t chnID = g_audioHwOutputPorts[i].chnID; ++ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); ++ return chnID; ++ } ++ } ++ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); ++ MEDIA_HAL_LOGE(MODULE_NAME, "could get free audio Output channel"); ++ return MEDIA_HAL_ERR; ++} ++ ++static int32_t AudioOutputPortGetFreeTrack(struct AudioSubPortOut *hwAudioOutputPort) ++{ ++ MEDIA_HAL_LOCK(hwAudioOutputPort->mutex); ++ for (int32_t i = 0; i < MAX_OUTPUT_PORT_TRACK_CNT; i++) { ++ if (hwAudioOutputPort->hwOutputPortTrack[i] == NULL) { ++ MEDIA_HAL_UNLOCK(hwAudioOutputPort->mutex); ++ return i; ++ } ++ } ++ MEDIA_HAL_UNLOCK(hwAudioOutputPort->mutex); ++ MEDIA_HAL_LOGE(MODULE_NAME, "could get free audio Output track"); ++ return MEDIA_HAL_ERR; ++} ++ ++static int32_t AudioOutputPortFreeTrack(struct AudioSubPortOut *hwAudioOutputPort, ++ struct AudioSubPortOutTrack *hwOutputPortTrack) ++{ ++ MEDIA_HAL_LOCK(hwAudioOutputPort->mutex); ++ for (int32_t i = 0; i < MAX_OUTPUT_PORT_TRACK_CNT; i++) { ++ if (hwAudioOutputPort->hwOutputPortTrack[i] == hwOutputPortTrack) { ++ hwAudioOutputPort->hwOutputPortTrack[i] = NULL; ++ MEDIA_HAL_UNLOCK(hwAudioOutputPort->mutex); ++ return MEDIA_HAL_OK; ++ } ++ } ++ MEDIA_HAL_UNLOCK(hwAudioOutputPort->mutex); ++ MEDIA_HAL_LOGE(MODULE_NAME, "could not found audio Output track"); ++ return MEDIA_HAL_ERR; ++} ++ ++static int32_t AudioOutputPortMngFreeChn(int32_t chnID) ++{ ++ MEDIA_HAL_LOCK(g_audioOutputMngLock); ++ if (!g_audioOutputMngInited) { ++ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); ++ return MEDIA_HAL_ERR; ++ } ++ for (int32_t i = 0; i < MAX_OUTPUT_PORT_CNT; i++) { ++ if (g_audioHwOutputPorts[i].chnID == chnID) { ++ g_audioHwOutputPorts[i].used = false; ++ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); ++ return MEDIA_HAL_OK; ++ } ++ } ++ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); ++ MEDIA_HAL_LOGE(MODULE_NAME, "freehandle input audio Output handle invalid : %d", chnID); ++ return MEDIA_HAL_ERR; ++} ++ ++int32_t AudioUsbSubPortOutGetCapability(const struct AudioPort *port, ++ struct AudioPortCapability *capability) ++{ ++ MEDIA_HAL_UNUSED(port); ++ CHK_NULL_RETURN(capability, MEDIA_HAL_INVALID_PARAM, "param capability null"); ++ ++ capability->channelCount = AUDIO_STEREO_SOUND_MODE_CHN_CNT; ++ MEDIA_HAL_LOGD(MODULE_NAME, "usb support stereo."); ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t AoInit(ot_audio_dev aoDeviceId, ot_aio_attr *aoAttr) ++{ ++ // todo zhp ++ MEDIA_HAL_LOGE(MODULE_NAME, "AoInit success"); ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t AoSourceAttrConfig(struct PortPluginAttr *portAttr, ot_aio_attr *aoSourceAttr, enum AudioPortPin audioPortPin) ++{ ++ if (memset_s(aoSourceAttr, sizeof(ot_aio_attr), 0x0, sizeof(ot_aio_attr)) != EOK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s: hwOutputPort aoAttr failed"); ++ return MEDIA_HAL_ERR; ++ } ++ if (!AudioConvertSampleRateToHAL(portAttr->sampleRate, &aoSourceAttr->sample_rate)) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertSampleRateToHAL sample_rate: %d failed", portAttr->sampleRate); ++ return MEDIA_HAL_ERR; ++ } ++ aoSourceAttr->bit_width = OT_AUDIO_BIT_WIDTH_16; ++ aoSourceAttr->work_mode = OT_AIO_MODE_I2S_MASTER; ++ if (!AudioConvertChannelToHAL(portAttr->channelCount, &aoSourceAttr->snd_mode)) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertChannelToHAL channelCount: %u failed", portAttr->channelCount); ++ return MEDIA_HAL_ERR; ++ } ++ aoSourceAttr->chn_cnt = portAttr->channelCount; ++ aoSourceAttr->expand_flag = 0; ++ aoSourceAttr->frame_num = AUDIO_FRAME_NUM_OUT_BUF; ++ aoSourceAttr->point_num_per_frame = 4096; ++ aoSourceAttr->clk_share = 0; ++ ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t ConfigAndEnableAO(AudioHandle portHandle, struct PortPluginAttr *portAttr, enum AudioPortPin audioPortPin) ++{ ++ struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; ++ int32_t ret = AoSourceAttrConfig(portAttr, &hwPortCtx->aoSourceAttr, audioPortPin); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "ConfigAoSourceAttr failed"); ++ return ret; ++ } ++ ot_aio_attr aoAttr = hwPortCtx->aoSourceAttr; ++ ++ MEDIA_HAL_LOGE(MODULE_NAME, "aoAttr.bit_width: %d, snd_mode: %d, sample_rate: %d, chn_cnt: %d", aoAttr.bit_width, aoAttr.snd_mode, ++ aoAttr.sample_rate, aoAttr.chn_cnt); ++ snd_pcm_hw_params_t *params; ++ snd_pcm_uframes_t frames = 4096; ++ snd_pcm_hw_params_malloc(¶ms); ++ snd_pcm_hw_params_any(hwPortCtx->ao_pcm_handle, params); ++ snd_pcm_hw_params_set_access(hwPortCtx->ao_pcm_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); ++ // todo zhp ++ // snd_pcm_format_t format ++ //AudioConvertFormatToAlsa(aoAttr.bit_width, &format); ++ snd_pcm_hw_params_set_format(hwPortCtx->ao_pcm_handle, params, SND_PCM_FORMAT_S16_LE); ++ snd_pcm_hw_params_set_channels(hwPortCtx->ao_pcm_handle, params, aoAttr.chn_cnt); ++ snd_pcm_hw_params_set_rate_near(hwPortCtx->ao_pcm_handle, params, &(aoAttr.sample_rate), 0); ++ snd_pcm_hw_params_set_period_size_near(hwPortCtx->ao_pcm_handle, params, &frames, 0); ++ snd_pcm_hw_params(hwPortCtx->ao_pcm_handle, params); ++ snd_pcm_hw_params_free(params); ++ ++ MEDIA_HAL_LOGE(MODULE_NAME, "aoAttr.frame_num: %d, point_num_per_frame: %d, period_size: %d", aoAttr.frame_num, aoAttr.point_num_per_frame, frames); ++ ++ ++ ret = AoInit(hwPortCtx->aoDeviceId, &aoAttr); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AoInit failed %#x", ret); ++ return ret; ++ } ++ hwPortCtx->aoEnabled = true; ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutOpen(AudioHandle *portHandle, int card_usb) ++{ ++ struct AudioSubPortOut *hwOutputPort = NULL; ++ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); ++ if (!g_audioOutputMngInited) { ++ AudioOutputPortMngInit(); ++ } ++ int32_t portIndex = AudioOutputPortMngGetFreeChn(); ++ if (portIndex == -1) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "can not found free Output Port"); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ hwOutputPort = (struct AudioSubPortOut *)malloc(sizeof(struct AudioSubPortOut)); ++ if (hwOutputPort == NULL) { ++ (void)AudioOutputPortMngFreeChn(portIndex); ++ return MEDIA_HAL_NO_MEM; ++ } ++ if (memset_s(hwOutputPort, sizeof(struct AudioSubPortOut), 0, sizeof(struct AudioSubPortOut)) != EOK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s AudioSubPortOut failed"); ++ } ++ ++ hwOutputPort->aoDeviceId = portIndex; ++ char PCM_DEVICE[32]; ++ snprintf(PCM_DEVICE, sizeof(PCM_DEVICE), "hw:%d,0", card_usb); ++ int pcm = snd_pcm_open(&(hwOutputPort->ao_pcm_handle), PCM_DEVICE, SND_PCM_STREAM_PLAYBACK, 0); ++ if (pcm < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_open failed"); ++ return MEDIA_HAL_ERR; ++ } ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_open success"); ++ ++ int ret = snd_mixer_open(&(hwOutputPort->ao_mixer_handle), 0); ++ if (ret < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_open failed: %s\n", snd_strerror(ret)); ++ return ret; ++ } ++ char CTL_DEVICE[32]; ++ snprintf(CTL_DEVICE, sizeof(CTL_DEVICE), "hw:%d", card_usb); ++ ret = snd_mixer_attach(hwOutputPort->ao_mixer_handle, CTL_DEVICE); ++ if (ret < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_attach failed: %s\n", snd_strerror(ret)); ++ snd_mixer_close(hwOutputPort->ao_mixer_handle); ++ return ret; ++ } ++ ++ snd_mixer_selem_register(hwOutputPort->ao_mixer_handle, NULL, NULL); ++ snd_mixer_load(hwOutputPort->ao_mixer_handle); ++ ++ // get element "Master" or "PCM" with volume control ++ snd_mixer_elem_t *elem = NULL; ++ for (elem = snd_mixer_first_elem(hwOutputPort->ao_mixer_handle); elem; elem = snd_mixer_elem_next(elem)) { ++ if (snd_mixer_selem_is_active(elem)) { ++ const char *name = snd_mixer_selem_get_name(elem); ++ if (((strcmp(name, "PCM") == 0) || (strcmp(name, "Master") == 0)) && snd_mixer_selem_has_playback_volume(elem)) { ++ hwOutputPort->ao_elem_vol = elem; ++ break; ++ } ++ } ++ } ++ ++ if (!(hwOutputPort->ao_elem_vol)) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "Cannot find suitable mixer element (Master/PCM)\n"); ++ snd_mixer_close(hwOutputPort->ao_mixer_handle); ++ // maybe some device not support volume control ++ // return -1; ++ } ++ ++ // get volume range ++ snd_mixer_selem_get_playback_volume_range(hwOutputPort->ao_elem_vol, &hwOutputPort->ao_min_vol, &hwOutputPort->ao_max_vol); ++ MEDIA_HAL_LOGE(MODULE_NAME, "Volume range: [%ld, %ld]\n", hwOutputPort->ao_min_vol, hwOutputPort->ao_max_vol); ++ ++ pthread_mutex_init(&hwOutputPort->mutex, NULL); ++ hwOutputPort->opened = true; ++ *portHandle = hwOutputPort; ++ MEDIA_HAL_LOGE(MODULE_NAME, "hwOutputPort open SUCCESS"); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutClose(AudioHandle portHandle) ++{ ++ struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; ++ CHK_NULL_RETURN(hwPortCtx, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); ++ CHK_FAILED_RETURN(hwPortCtx->opened, true, MEDIA_HAL_ERR, "not inited"); ++ int32_t ret; ++ ++ ret = AudioOutputPortMngFreeChn(hwPortCtx->aoDeviceId); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AudioOutputPortMngFreeChn failed"); ++ } ++ snd_mixer_close(hwPortCtx->ao_mixer_handle); ++ snd_pcm_drain(hwPortCtx->ao_pcm_handle); ++ snd_pcm_close(hwPortCtx->ao_pcm_handle); ++ pthread_mutex_destroy(&hwPortCtx->mutex); ++ hwPortCtx->opened = false; ++ free(hwPortCtx); ++ hwPortCtx = NULL; ++ ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutGetLatency(AudioHandle trackHandle, uint32_t *latencyMs) ++{ ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_NULL_RETURN(latencyMs, MEDIA_HAL_INVALID_PARAM, "input param buffer null"); ++ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); ++ ++ *latencyMs = 20; ++ return MEDIA_HAL_OK; ++} ++ ++ ++ ++int32_t AudioUsbSubPortOutEnableTrack(AudioHandle trackHandle) ++{ ++ int32_t ret; ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_FAILED_RETURN(hwPortTrackCtx->started, false, MEDIA_HAL_OK, "started yet"); ++ ++ ret = snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); ++ if (ret != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_prepare left ret=0x%x", ret); ++ return ret; ++ } ++ ++ hwPortTrackCtx->started = true; ++ ++ MEDIA_HAL_LOGD(MODULE_NAME, "snd_pcm_prepare out"); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutPauseTrack(AudioHandle trackHandle) ++{ ++ int32_t ret; ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); ++ snd_pcm_state_t state = snd_pcm_state(hwPortTrackCtx->ao_pcm_handle); ++ MEDIA_HAL_LOGI(MODULE_NAME, "Current PCM state: %d", state); ++ ++ if (state == SND_PCM_STATE_RUNNING) { ++ int ret = snd_pcm_pause(hwPortTrackCtx->ao_pcm_handle, 1); ++ if (ret == 0) { ++ MEDIA_HAL_LOGI(MODULE_NAME, "USB Audio paused."); ++ return MEDIA_HAL_OK; ++ } ++ // zhp todo ++ // if pause failed, try drain and prepare ++ if (ret < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_pause(1) failed: %s", snd_strerror(ret)); ++ ret = snd_pcm_drain(hwPortTrackCtx->ao_pcm_handle); ++ if (ret < 0) { ++ snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, ret, 0); ++ snd_pcm_drop(hwPortTrackCtx->ao_pcm_handle); ++ } ++ snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); ++ return MEDIA_HAL_OK; ++ } ++ } else { ++ MEDIA_HAL_LOGW(MODULE_NAME, "PCM not in running state, ignore pause"); ++ } ++ ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutResumeTrack(AudioHandle trackHandle) ++{ ++ int32_t ret; ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ ++ // todo zhp ++ snd_pcm_state_t state = snd_pcm_state(hwPortTrackCtx->ao_pcm_handle); ++ MEDIA_HAL_LOGI(MODULE_NAME, "Current PCM state: %d", state); ++ ++ ret = snd_pcm_pause(hwPortTrackCtx->ao_pcm_handle, 0); ++ if (ret == 0) { ++ MEDIA_HAL_LOGI(MODULE_NAME, "USB Audio resumed."); ++ return 0; ++ } ++ if (ret < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_pause(0) failed: %s", snd_strerror(ret)); ++ MEDIA_HAL_LOGW(MODULE_NAME, "Pause not supported, trying recover..."); ++ ret = snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); ++ if (ret < 0) { ++ snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, ret, 0); ++ return MEDIA_HAL_ERR; ++ } ++ ++ return MEDIA_HAL_OK; ++ } ++ snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, ret, 0); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutFlushTrack(AudioHandle trackHandle) ++{ ++ int32_t ret; ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); ++ snd_pcm_state_t state = snd_pcm_state(hwPortTrackCtx->ao_pcm_handle); ++ if (state == SND_PCM_STATE_RUNNING) { ++ snd_pcm_drop(hwPortTrackCtx->ao_pcm_handle); ++ } ++ // setup pcm to prepare state ++ ret = snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); ++ if (ret < 0) { ++ snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, ret, 0); ++ } ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t AudioUsbSubPortOutTrackSetMute(AudioHandle trackHandle, bool mute) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ ++ struct AudioSubPortOutTrack *hwOutputPortTrack = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_FAILED_RETURN(hwOutputPortTrack->inited, true, MEDIA_HAL_ERR, "track not init"); ++ if(mute) { // mute set output volume to 0 ++ snd_mixer_selem_set_playback_volume_all(hwOutputPortTrack->ao_elem_vol, 0); ++ } else { // unmute set output volume to last volume ++ long vol = hwOutputPortTrack->ao_min_vol + (hwOutputPortTrack->ao_max_vol - hwOutputPortTrack->ao_min_vol) * hwOutputPortTrack->volume / 100; ++ snd_mixer_selem_set_playback_volume_all(hwOutputPortTrack->ao_elem_vol, vol); ++ } ++ hwOutputPortTrack->mute = mute; ++ MEDIA_HAL_LOGI(MODULE_NAME, "set mute:%d success", mute); ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t AudioUsbSubPortOutTrackGetMute(AudioHandle trackHandle, bool *mute) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ ++ struct AudioSubPortOutTrack *hwOutputPortTrack = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_FAILED_RETURN(hwOutputPortTrack->inited, true, MEDIA_HAL_ERR, "track not init"); ++ *mute = hwOutputPortTrack->mute; ++ MEDIA_HAL_LOGI(MODULE_NAME, "Get mute success, current state is %s", *mute == true ? "mute" : "unmute"); ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t AudioUsbSubPortOutTrackSetVolume(AudioHandle trackHandle, float volume) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ struct AudioSubPortOutTrack *hwOutputPortTrack = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_FAILED_RETURN(hwOutputPortTrack->inited, true, MEDIA_HAL_ERR, "track not init"); ++ ++ int32_t tmpValume; ++ int32_t ret; ++ if (volume < VOLUME_PERCENT_MIN || volume > VOLUME_PERCENT_MAX) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortOutTrackSetVolume, volume:%f err, it should [%f,%f]", volume, ++ VOLUME_PERCENT_MIN, VOLUME_PERCENT_MAX); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ const float EPSINON = 0.00001; ++ if ((volume >= -EPSINON) && (volume <= EPSINON)) { ++ ot_audio_fade fade = {}; ++ hwOutputPortTrack->volume = volume; ++ snd_mixer_selem_set_playback_volume_all(hwOutputPortTrack->ao_elem_vol, 0); ++ return MEDIA_HAL_OK; ++ } ++ ++ long vol = hwOutputPortTrack->ao_min_vol + (hwOutputPortTrack->ao_max_vol - hwOutputPortTrack->ao_min_vol) * volume / 100; ++ ret = snd_mixer_selem_set_playback_volume_all(hwOutputPortTrack->ao_elem_vol, vol); ++ if (ret < 0) { ++ MEDIA_HAL_LOGI(MODULE_NAME, "SetVolume failed: %s\n", snd_strerror(ret)); ++ return ret; ++ } ++ MEDIA_HAL_LOGI(MODULE_NAME, "SetVolume: %d (raw=%ld)\n", volume, vol); ++ ++ hwOutputPortTrack->volume = volume; ++ ++ return MEDIA_HAL_OK; ++} ++ ++static int32_t AudioUsbSubPortOutTrackGetVolume(AudioHandle trackHandle, float *volume) ++{ ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ ++ struct AudioSubPortOutTrack *hwOutputPortTrack = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_FAILED_RETURN(hwOutputPortTrack->inited, true, MEDIA_HAL_ERR, "track not init"); ++ *volume = hwOutputPortTrack->volume; ++ return MEDIA_HAL_OK; ++} ++ ++static void AudioRenderFillAudioFrame(const struct AudioSubPortOutTrack *hwPortTrack, const uint8_t *data, ++ uint64_t len, ot_audio_frame *audioFrame) ++{ ++ const uint32_t channels[OT_AUDIO_SOUND_MODE_BUTT] = {1, 2}; ++ audioFrame->bit_width = hwPortTrack->aoSourceAttr.bit_width; ++ audioFrame->snd_mode = hwPortTrack->aoSourceAttr.snd_mode; ++ audioFrame->time_stamp = 0; ++ audioFrame->seq = (uint32_t)hwPortTrack->frames; ++ audioFrame->phys_addr[0] = 0; ++ audioFrame->phys_addr[1] = 0; ++ audioFrame->pool_id[0] = 0; ++ audioFrame->pool_id[1] = 0; ++ if (audioFrame->snd_mode == OT_AUDIO_SOUND_MODE_MONO) { ++ audioFrame->virt_addr[0] = (uint8_t*)data; ++ audioFrame->virt_addr[1] = NULL; ++ audioFrame->len = (uint32_t)len; ++ } else if (audioFrame->snd_mode == OT_AUDIO_SOUND_MODE_STEREO) { ++ audioFrame->virt_addr[0] = (uint8_t*)data; ++ audioFrame->virt_addr[1] = (uint8_t*)data + len / channels[hwPortTrack->aoSourceAttr.snd_mode]; ++ audioFrame->len = (uint32_t)len / channels[hwPortTrack->aoSourceAttr.snd_mode]; ++ } ++} ++ ++ ++int32_t AudioUsbSubPortOutSendFrame(AudioHandle trackHandle, const uint8_t *buffer, ++ uint64_t requestBytes, uint64_t *replyBytes) ++{ ++ int32_t ret,offset; ++ int32_t tryNum = 3; ++ long frames; ++ ot_ao_chn_state chnStatus = {}; ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_NULL_RETURN(buffer, MEDIA_HAL_INVALID_PARAM, "input param buffer null"); ++ CHK_NULL_RETURN(replyBytes, MEDIA_HAL_INVALID_PARAM, "input param replyBytes null"); ++ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); ++ ++ int bytes_per_sample = (hwPortTrackCtx->aoSourceAttr.bit_width + 1); // bit_width =0 8bit; bit_width =1 16bit. ++ int channels = (hwPortTrackCtx->aoSourceAttr.snd_mode == OT_AUDIO_SOUND_MODE_STEREO) ? 2 : 1; ++ int bytes_per_frame = bytes_per_sample * channels; ++ uint8_t *interleaved_buf = NULL; ++ // 如果是立体声,需要转换为 interleaved 格式 ++ if (channels == 2) { ++ uint64_t frames_count = requestBytes / (bytes_per_sample * 2); // 每声道帧数 ++ interleaved_buf = malloc(requestBytes); ++ if (!interleaved_buf) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "malloc interleaved_buf failed"); ++ return MEDIA_HAL_NO_MEM; ++ } ++ ++ uint8_t *ch0 = (uint8_t *)buffer; ++ uint8_t *ch1 = (uint8_t *)buffer + frames_count * bytes_per_sample; ++ for (uint64_t i = 0; i < frames_count; i++) { ++ memcpy(interleaved_buf + i * bytes_per_frame, ch0 + i * bytes_per_sample, bytes_per_sample); ++ memcpy(interleaved_buf + i * bytes_per_frame + bytes_per_sample, ch1 + i * bytes_per_sample, bytes_per_sample); ++ } ++ buffer = interleaved_buf; ++ } ++#if DEBUG ++ static FILE *fp_debug = NULL; ++ if (fp_debug == NULL) { ++ fp_debug = fopen("/userdata/usb_out.pcm", "wb"); ++ } ++ if (fp_debug) { ++ fwrite(buffer, 1, requestBytes, fp_debug); ++ } ++#endif ++ uint64_t remaining_bytes = requestBytes; ++ while (remaining_bytes > 0) { ++ frames = snd_pcm_writei(hwPortTrackCtx->ao_pcm_handle, buffer, remaining_bytes / bytes_per_frame); ++#if DEBUG ++ snd_pcm_state_t state = snd_pcm_state(hwPortTrackCtx->ao_pcm_handle); ++ MEDIA_HAL_LOGE(MODULE_NAME, "PCM state = %d, bytes_per_frame = %d", state, bytes_per_frame); ++ MEDIA_HAL_LOGE(MODULE_NAME, "first 8 bytes: %02x %02x %02x %02x %02x %02x %02x %02x", ++ buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]); ++#endif ++ if (frames > 0) { ++ size_t bytes_written = frames * bytes_per_frame; ++ remaining_bytes -= bytes_written; ++ buffer += bytes_written; ++ } else if (frames == -EAGAIN) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "render PCM writei -EAGAIN"); ++ snd_pcm_wait(hwPortTrackCtx->ao_pcm_handle, PCM_WAIT_TIMEOUT_MS); ++ tryNum--; ++ if (tryNum == 0) { ++ return MEDIA_HAL_OK; ++ } ++ } else if (frames == -EBADFD) { ++ /* not #SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING */ ++ MEDIA_HAL_LOGE(MODULE_NAME, "render PCM is not in the right state : %s", snd_strerror(frames)); ++ snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); ++ return MEDIA_HAL_ERR; ++ } else { ++ /* -ESTRPIPE: a suspend event occurred, ++ * stream is suspended and waiting for an application recovery. ++ * -EPIPE: an underrun occurred. ++ */ ++ MEDIA_HAL_LOGE(MODULE_NAME, "err: %{public}s", snd_strerror(frames)); ++ ret = snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, frames, 0); // 0 for open render recover log. ++ if (ret < 0) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_writei failed: %{public}s", snd_strerror(ret)); ++ return MEDIA_HAL_ERR; ++ } ++ } ++ } ++ ++ *replyBytes = requestBytes; ++ hwPortTrackCtx->frames++; ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutTrackGetPosition(AudioHandle trackHandle, uint64_t *frames, ++ struct AudioTimeStamp *time) ++{ ++ // ot_ao_chn_state chnStatus = {}; ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_NULL_RETURN(frames, MEDIA_HAL_INVALID_PARAM, "input param frames null"); ++ CHK_NULL_RETURN(time, MEDIA_HAL_INVALID_PARAM, "input param time null"); ++ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); ++ ++ *frames = hwPortTrackCtx->frames - 0; ++ time->tvSec = hwPortTrackCtx->currentPts / TIME_S_TO_US_SCALE; ++ time->tvNSec = (hwPortTrackCtx->currentPts % TIME_S_TO_US_SCALE) / TIME_US_TO_NS_SCALE; ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutDisableTrack(AudioHandle trackHandle) ++{ ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); ++ ++ snd_pcm_drain(hwPortTrackCtx->ao_pcm_handle); ++ hwPortTrackCtx->vqeScene = VQE_SCENE_NONE; ++ hwPortTrackCtx->started = false; ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle) ++{ ++ struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; ++ CHK_NULL_RETURN(hwPortCtx, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ int32_t ret = AudioOutputPortFreeTrack(hwPortCtx, hwPortTrackCtx); ++ if (ret == MEDIA_HAL_ERR) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "invalid trackHandle"); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ ++ ++ free(hwPortTrackCtx); ++ return MEDIA_HAL_OK; ++} ++ ++int32_t AudioUsbSubPortOutInvoke(AudioHandle trackHandle, ++ enum InvokeID invokeID, struct InvokeAttr *invokeAttr) ++{ ++ int32_t ret = MEDIA_HAL_OK; ++ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; ++ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ CHK_NULL_RETURN(invokeAttr, MEDIA_HAL_INVALID_PARAM, "input param invokeAttr null"); ++ CHK_NULL_RETURN(invokeAttr->request, MEDIA_HAL_INVALID_PARAM, "input param request null"); ++ CHK_FAILED_RETURN(hwPortTrackCtx->inited, true, MEDIA_HAL_ERR, "not inited"); ++ switch (invokeID) { ++ default: ++ MEDIA_HAL_LOGW(MODULE_NAME, "Invalid invokeID: %d", invokeID); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ return MEDIA_HAL_OK; ++} ++ ++static void SubPortTrackOutLoadImpl(struct AudioSubPortOutTrack *portTrackOutCtx, ++ const struct PortPluginAttr *inputAttr, enum AudioPortPin audioPortPin) ++{ ++ portTrackOutCtx->inputAttr = *inputAttr; ++ ++ portTrackOutCtx->common.audioPin = audioPortPin; ++ portTrackOutCtx->common.GetFrameCount = NULL; ++ portTrackOutCtx->common.GetLatency = AudioUsbSubPortOutGetLatency; ++ portTrackOutCtx->common.EnableTrack = AudioUsbSubPortOutEnableTrack; ++ portTrackOutCtx->common.DisableTrack = AudioUsbSubPortOutDisableTrack; ++ portTrackOutCtx->common.PauseTrack = AudioUsbSubPortOutPauseTrack; ++ portTrackOutCtx->common.ResumeTrack = AudioUsbSubPortOutResumeTrack; ++ portTrackOutCtx->common.FlushTrack = AudioUsbSubPortOutFlushTrack; ++ portTrackOutCtx->common.AcquireFrame = NULL; ++ portTrackOutCtx->common.SendFrame = AudioUsbSubPortOutSendFrame; ++ portTrackOutCtx->common.GetPosition = AudioUsbSubPortOutTrackGetPosition; ++ portTrackOutCtx->common.SetMute = AudioUsbSubPortOutTrackSetMute; ++ portTrackOutCtx->common.GetMute = AudioUsbSubPortOutTrackGetMute; ++ portTrackOutCtx->common.SetVolume = AudioUsbSubPortOutTrackSetVolume; ++ portTrackOutCtx->common.GetVolume = AudioUsbSubPortOutTrackGetVolume; ++ portTrackOutCtx->common.Invoke = AudioUsbSubPortOutInvoke; ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return; ++} ++ ++int32_t AudioUsbSubPortOutCreateTrack(AudioHandle portHandle, AudioHandle *trackHandle, ++ struct PortPluginAttr *portAttr, enum AudioPortPin audioPortPin) ++{ ++ int32_t trackIndex; ++ struct AudioSubPortOutTrack *hwOutputPortTrack = NULL; ++ struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; ++ CHK_NULL_RETURN(hwPortCtx, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); ++ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ trackIndex = AudioOutputPortGetFreeTrack(hwPortCtx); ++ if (trackIndex == -1) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "can not found free Output Port track"); ++ return MEDIA_HAL_INVALID_PARAM; ++ } ++ ++ if (!hwPortCtx->aoEnabled && (ConfigAndEnableAO(portHandle, portAttr, audioPortPin) != MEDIA_HAL_OK)) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "config and anable AO failed"); ++ return MEDIA_HAL_INIT_FAIL; ++ } ++ ++ hwOutputPortTrack = (struct AudioSubPortOutTrack *)malloc(sizeof(struct AudioSubPortOutTrack)); ++ if (hwOutputPortTrack == NULL) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "malloc AudioSubPortOutTrack failed"); ++ return MEDIA_HAL_NO_MEM; ++ } ++ if (memset_s(hwOutputPortTrack, sizeof(struct AudioSubPortOutTrack), 0, ++ sizeof(struct AudioSubPortOutTrack)) != EOK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s AudioSubPortOutTrack failed"); ++ } ++ hwOutputPortTrack->aoSourceAttr = hwPortCtx->aoSourceAttr; ++ // todo zhp ++ SubPortTrackOutLoadImpl(hwOutputPortTrack, portAttr, audioPortPin); ++ hwOutputPortTrack->aoDeviceId = hwPortCtx->aoDeviceId; ++ hwOutputPortTrack->ao_pcm_handle = hwPortCtx->ao_pcm_handle; ++ hwOutputPortTrack->ao_mixer_handle = hwPortCtx->ao_mixer_handle; ++ hwOutputPortTrack->ao_elem_vol = hwPortCtx->ao_elem_vol; ++ hwOutputPortTrack->ao_min_vol = hwPortCtx->ao_min_vol; ++ hwOutputPortTrack->ao_max_vol = hwPortCtx->ao_max_vol; ++ hwOutputPortTrack->aoChn = trackIndex; ++ hwOutputPortTrack->vqeScene = VQE_SCENE_NONE; ++ hwOutputPortTrack->inited = true; ++ hwPortCtx->hwOutputPortTrack[trackIndex] = hwOutputPortTrack; ++ *trackHandle = &hwOutputPortTrack->common; ++ return MEDIA_HAL_OK; ++} ++ ++ ++#ifdef __cplusplus ++#if __cplusplus ++} ++#endif ++#endif /* __cplusplus */ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.h ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.h +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.h 1970-01-01 08:00:00.000000000 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.h 2025-12-18 15:44:30.874238483 +0800 +@@ -0,0 +1,37 @@ ++ /* ++ * Copyright (c) 2024 RKH Corp. ++ * 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. ++ */ ++ ++#ifndef AUDIO_PRIMARY_SUB_PORT_OUT_H ++#define AUDIO_PRIMARY_SUB_PORT_OUT_H ++ ++#include "audio_port_plugin.h" ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++/* sub port out api */ ++int32_t AudioUsbSubPortOutOpen(AudioHandle *portHandle, int card_usb); ++int32_t AudioUsbSubPortOutClose(AudioHandle portHandle); ++int32_t AudioUsbSubPortOutGetCapability(const struct AudioPort *port, struct AudioPortCapability *capability); ++int32_t AudioUsbSubPortOutCreateTrack(AudioHandle portHandle, AudioHandle *trackHandle, ++ struct PortPluginAttr *portAttr, enum AudioPortPin audioPortPin); ++int32_t AudioUsbSubPortOutDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle); ++ ++#ifdef __cplusplus ++} ++#endif ++ ++#endif +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/Makefile ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/Makefile +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/Makefile 1970-01-01 08:00:00.000000000 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/Makefile 2025-12-18 15:44:30.874238483 +0800 +@@ -0,0 +1,106 @@ ++LOCAL_DIR := $(shell pwd) ++MEDIA_BASE_DIR := $(LOCAL_DIR)/../../../.. ++include $(MEDIA_BASE_DIR)/build/base.mak ++ ++ ++#=============================================================================== ++# self deps ++#=============================================================================== ++AUDIO_PLUGIN_INC_PATH := $(LOCAL_DIR)/../plugin_include ++AUDIO_PORT_PLUGIN_COM_INC_PATH := $(LOCAL_DIR)/audio_usb_port_plugin_common/include ++AUDIO_SUB_PORT_IN_INC_PATH := $(LOCAL_DIR)/audio_usb_sub_port_in ++AUDIO_SUB_PORT_OUT_INC_PATH := $(LOCAL_DIR)/audio_usb_sub_port_out ++AUDIO_INTERFACE_PATH := $(MEDIA_BASE_DIR)/../../../../../../drivers/peripheral/audio/interfaces/include ++ ++OTCONFACCESS_INC_PATH := $(MEDIA_BASE_DIR)/../middleware/source/component/otconfaccess/include/ ++MW_COMMON_INC_PATH := $(MEDIA_BASE_DIR)/../middleware/source/common/include/ ++ ++SRC_DEPS_INC_PATH := -I$(AUDIO_HAL_INC_PATH) ++SRC_DEPS_INC_PATH += -I$(AUDIO_DRIVERS_INC_PATH)\ ++ -I$(MPP_INC_PATH)\ ++ -I$(AUDIO_PORT_PLUGIN_COM_INC_PATH)\ ++ -I$(MEDIA_HAL_COMMN_INC_PATH) \ ++ -I$(AUDIO_INTERFACE_PATH) \ ++ -I$(AUDIO_PLUGIN_INC_PATH) \ ++ -I$(AUDIO_SUB_PORT_IN_INC_PATH) \ ++ -I$(AUDIO_SUB_PORT_OUT_INC_PATH) \ ++ -I$(OTCONFACCESS_INC_PATH) \ ++ -I$(MW_COMMON_INC_PATH) \ ++ -I$(SECUREC_INC_PATH) ++ ++ALSA_INC_PATH := \ ++ -I$(MEDIA_BASE_DIR)/../../../../../../third_party/alsa-lib/include ++ ++SRC_DEPS_INC_PATH += $(ALSA_INC_PATH) ++#mod dir ++MOD_ROOT := $(LOCAL_DIR)/../.. ++SRC_ROOT := $(LOCAL_DIR) ++OBJ_ROOT := $(SRC_ROOT)/obj ++TRAGET_ROOT := $(MOD_ROOT)/$(TARGET_DIR) ++$(shell if [ ! -e $(TRAGET_ROOT) ]; then mkdir -p $(TRAGET_ROOT); fi) ++SRCS := $(LOCAL_DIR)/audio_usb_port_plugin/audio_usb_port_plugin.c ++SRCS += $(LOCAL_DIR)/audio_usb_sub_port_in/audio_usb_sub_port_in.c ++SRCS += $(LOCAL_DIR)/audio_usb_sub_port_out/audio_usb_sub_port_out.c ++SRCS += $(LOCAL_DIR)/audio_usb_port_plugin_common/src/audio_port_plugin_common.c ++SRCS := $(sort $(SRCS)) ++ ++ ++OBJS := $(SRCS:%.c=%.o) ++OBJS := $(sort $(OBJS)) ++SRC_DEPS := $(OBJS:%.o=%.d) ++ ++CFLAGS_CUR := $(CFLAGS) -fdata-sections -fno-omit-frame-pointer ++ ++LDFLAGS_SO := $(LDFLAGS) ++ ++ifeq ($(filter $(CFG_CHIP_TYPE),hispark_ss927v100 hispark_ss928v100),$(CFG_CHIP_TYPE)) ++CFLAGS_CUR += -D__SS626V100__ -D__LINUX__ ++SRC_DEPS_LIB += -lmedia_hal_common -lss_mpi -lsecurec -lpthread -ldl -lm -lmwlog -lotconfaccess -laac_sbr_enc -laac_sbr_dec -lvqe_record -lvqe_res -lss_otp ++else ++SRC_DEPS_LIB += -lmedia_hal_common -lss_mpi_audio -lsecurec -lpthread -ldl -lm -lmwlog -lotconfaccess -lss_mpi_audio_adp -lopus -laac_sbr_enc -laac_sbr_dec -lmp3_dec -lmp3_enc -lvqe_record -lvqe_res -lss_otp ++endif ++USB_ALSA_LIB_PATH := $(MEDIA_BASE_DIR)/../../../../../../third_party/alsa-lib/lib ++SRC_DEPS_LIB += -lasound ++SRC_DEPS_LIB_PATH += -L$(MPP_LIB_PATH)\ ++ -L$(SECUREC_LIB_PATH) \ ++ -L$(MEDIA_HAL_COMMN_LIB_PATH) \ ++ -L$(USB_ALSA_LIB_PATH) ++ ++ifeq ($(filter $(CFG_CHIP_TYPE),hispark_ss927v100 hispark_ss928v100),$(CFG_CHIP_TYPE)) ++SRC_DEPS_LIB_PATH += -L$(MEDIA_BASE_DIR)/../middleware/source/component/otconfaccess/lib/ss928v100/clang_musl \ ++ -L$(MEDIA_BASE_DIR)/../middleware/source/common/log/lib/ss928v100/clang_musl ++else ++SRC_DEPS_LIB_PATH += -L$(MEDIA_BASE_DIR)/../middleware/source/component/otconfaccess/lib/hi3516dv500/gcc_musl \ ++ -L$(MEDIA_BASE_DIR)/../middleware/source/common/log/lib/hi3516dv500/gcc_musl ++endif ++ ++ifeq ($(CFG_OS_TYPE),OHOS) ++SRC_DEPS_LIB_PATH += -L$(OUT_DIR)/$(CFG_CHIP_TYPE)/ipcamera_$(CFG_CHIP_TYPE)_liteos \ ++ -L$(OUT_DIR)/$(CFG_CHIP_TYPE)/ipcamera_$(CFG_CHIP_TYPE)_liteos/usr/lib ++else ++SRC_DEPS_LIB_PATH += -L$(OUT_DIR)/$(CFG_CHIP_TYPE)/ipcamera_$(CFG_CHIP_TYPE)_linux \ ++ -L$(OUT_DIR)/$(CFG_CHIP_TYPE)/ipcamera_$(CFG_CHIP_TYPE)_linux/usr/lib ++endif ++ ++LIB_SO := $(TRAGET_ROOT)/libaudio_usb_port.so ++LIB_A := $(TRAGET_ROOT)/libaudio_usb_port.a ++ ++.PHONY : clean all ++ ++all: $(LIB_SO) $(LIB_A) ++ @-rm -f $(OBJS) ++ ++$(LIB_A): $(OBJS) ++ $(AR) -rcv $@ $^ ++ ++ ++$(LIB_SO): $(OBJS) ++ $(CC) $(LDFLAGS_SO) $(CFLAGS_CUR) $(LFLAGS) -fPIC -shared -o $@ $^ $(SRC_DEPS_LIB_PATH) $(SRC_DEPS_LIB) ++ $(STRIP) $(LIB_SO) ++ ++ ++$(OBJS): %.o : %.c ++ $(CC) $(CFLAGS_CUR) $(LFLAGS) $(SRC_DEPS_INC_PATH) -c $< -o $@ ++ ++clean: ++ @-rm -f $(OBJS) $(LIB_SO) $(LIB_A) +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_manager.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/src/audio_manager.c +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_manager.c 2025-12-18 15:14:06.900482931 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/src/audio_manager.c 2025-12-18 15:44:30.878238444 +0800 +@@ -40,12 +40,22 @@ static struct AudioPort g_audioPrimaryPo + { PORT_OUT, 1, "PrimaryPortOut" } + }; + ++static struct AudioPort g_audioUsbPort[] = { ++ { PORT_IN, 0, "UsbPortIn"}, ++ { PORT_OUT, 1, "UsbPortOut" } ++}; ++ + static struct AudioAdapterDescriptor g_audioAdapterDescs[] = { + { + .adapterName = NULL, + .portNum = 0, + .ports = NULL, + }, ++ { ++ .adapterName = NULL, ++ .portNum = 0, ++ .ports = NULL, ++ }, + }; + + static struct AudioHwAdapterInternal g_audioAdapters[] = { +@@ -55,6 +65,12 @@ static struct AudioHwAdapterInternal g_a + .hwAdapter = {}, + .adapterLock = PTHREAD_MUTEX_INITIALIZER, + }, ++ { ++ .count = 0, ++ .loaded = false, ++ .hwAdapter = {}, ++ .adapterLock = PTHREAD_MUTEX_INITIALIZER, ++ }, + }; + + static bool g_allAdapterLoaded = false; +@@ -118,6 +134,21 @@ static int32_t AudioManagerGetAllAdapter + MEDIA_HAL_LOGE(MODULE_NAME, "AudioPluginManagerGetPlugin(Primary) failed"); + } + ++ const AudioPortPlugin *usbPlugin = AudioPluginManagerGetPlugin(AUDIO_PLUGIN_USB); ++ if (usbPlugin != NULL) { ++ g_audioAdapters[adapterIndex].hwAdapter.portPlugin = usbPlugin; ++ g_audioAdapters[adapterIndex].hwAdapter.portDirection = usbPlugin->audioPortDir; ++ g_audioAdapterDescs[adapterIndex].adapterName = "USB"; ++ MEDIA_HAL_LOGE(MODULE_NAME, "AudioPluginManagerGetPlugin(USB) success, adapterIndex = %d, adapterName = %s", ++ adapterIndex, g_audioAdapterDescs[adapterIndex].adapterName); ++ g_audioAdapterDescs[adapterIndex].portNum = (size_t)ARRAY_SIZE(g_audioUsbPort); ++ g_audioAdapterDescs[adapterIndex].ports = g_audioUsbPort; ++ ++ adapterIndex++; ++ } else { ++ MEDIA_HAL_LOGE(MODULE_NAME, "AudioPluginManagerGetPlugin(USB) failed"); ++ } ++ + if (adapterIndex == 0) { + MEDIA_HAL_UNLOCK(g_adapterMutex); + return MEDIA_HAL_ERR; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_plugins_manager/src/audio_plugins_manager.c ohos1/device/soc/hisilicon/common/hal/media/audio/source/src/audio_plugins_manager/src/audio_plugins_manager.c +--- ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_plugins_manager/src/audio_plugins_manager.c 2025-12-18 15:14:06.900482931 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/audio/source/src/audio_plugins_manager/src/audio_plugins_manager.c 2025-12-18 15:44:30.878238444 +0800 +@@ -39,6 +39,12 @@ extern "C" { + #define PRIMARY_PORT_PLUGIN_LIB_PATH "/lib/libaudio_primary_port.so" + #define PRIMARY_PORT_PLUGIN_USR_LIB_PATH "/usr/lib/libaudio_primary_port.so" + ++#define HDMI_PORT_PLUGIN_LIB_PATH "/lib/libaudio_hdmi_port.so" ++#define HDMI_PORT_PLUGIN_USR_LIB_PATH "/usr/lib/libaudio_hdmi_port.so" ++ ++#define USB_PORT_PLUGIN_LIB_PATH "/lib/libaudio_usb_port.so" ++#define USB_PORT_PLUGIN_USR_LIB_PATH "/usr/lib/libaudio_usb_port.so" ++ + #define BLUETOOTH_PORT_PLUGIN_LIB_PATH "/lib/libaudio_bluetooth_port.so" + #define BLUETOOTH_PORT_PLUGIN_USR_LIB_PATH "/usr/lib/libaudio_bluetooth_port.so" + #endif +@@ -119,6 +125,53 @@ static int32_t ScanAndLoadPrimaryPortPlu + return MEDIA_HAL_OK; + } + ++ ++static int32_t ScanAndLoadUSBPortPlugin(AudioPluginsManager *manager) ++{ ++ AudioPlugin usbPlugin = {}; ++ usbPlugin.audioPluginType = AUDIO_PLUGIN_USB; ++ const AudioPortPlugin *usbPluginImpl = NULL; ++#ifdef ENABLE_DL_AUDIO_PLUGIN ++ usbPlugin.pluginDlHandle = MediaHalDLOpen(USB_PORT_PLUGIN_USR_LIB_PATH); ++ if (usbPlugin.pluginDlHandle == NULL) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "not found usb port plugin in path: %s", USB_PORT_PLUGIN_USR_LIB_PATH); ++ usbPlugin.pluginDlHandle = MediaHalDLOpen(USB_PORT_PLUGIN_LIB_PATH); ++ if (usbPlugin.pluginDlHandle == NULL) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "not found usb port plugin in path: %s", USB_PORT_PLUGIN_LIB_PATH); ++ return MEDIA_HAL_ERR; ++ } ++ } ++ GetPortPlugin getPluginFuns = (GetPortPlugin)MediaHalDLSym(usbPlugin.pluginDlHandle, AUDIO_PORT_PLUGIN_FUNCS); ++ if (getPluginFuns == NULL) { ++ MediaHalDLClose(usbPlugin.pluginDlHandle); ++ MEDIA_HAL_LOGE(MODULE_NAME, "not found symbol: %s", AUDIO_PORT_PLUGIN_FUNCS); ++ return MEDIA_HAL_ERR; ++ } ++ usbPluginImpl = getPluginFuns(AUDIO_PLUGIN_NONE); ++ if (usbPluginImpl == NULL || ++ CheckPortPlugin(usbPluginImpl) != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "not found valid hdmi port plugin"); ++ MediaHalDLClose(usbPlugin.pluginDlHandle); ++ return MEDIA_HAL_ERR; ++ } ++#else ++ usbPluginImpl = GetPortPluginFuncs(AUDIO_PLUGIN_USB); ++ if (usbPluginImpl == NULL || ++ CheckPortPlugin(usbPluginImpl) != MEDIA_HAL_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "not found valid hdmi port plugin"); ++ return MEDIA_HAL_ERR; ++ } ++#endif ++ usbPlugin.pluginHandle = (uintptr_t)usbPluginImpl; ++ if (ListPushFront(&manager->plugins, (uintptr_t)&usbPlugin) != LIST_OK) { ++ MEDIA_HAL_LOGE(MODULE_NAME, "hdmi port plugin cannot be pushed into the list"); ++ return MEDIA_HAL_ERR; ++ } ++ ++ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ return MEDIA_HAL_OK; ++} ++ + static uintptr_t DupPlugin(const AudioPlugin *audioPlugin) + { + CHK_NULL_RETURN(audioPlugin, MEDIA_HAL_INVALID_PARAM, "input param audioPlugin null"); +@@ -196,6 +249,9 @@ void AudioPluginManagerInit(void) + if (ScanAndLoadPrimaryPortPlugin(manager) != MEDIA_HAL_OK) { + goto LOAD_FAILED; + } ++ if (ScanAndLoadUSBPortPlugin(manager) != MEDIA_HAL_OK) { ++ goto LOAD_FAILED; ++ } + + manager->inited = true; + MEDIA_HAL_UNLOCK(manager->mutex); +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/build/build_media_source_L1.sh ohos1/device/soc/hisilicon/common/hal/media/build/build_media_source_L1.sh +--- ohos/device/soc/hisilicon/common/hal/media/build/build_media_source_L1.sh 2025-12-18 15:14:06.900482931 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/build/build_media_source_L1.sh 2025-12-18 15:44:30.870238524 +0800 +@@ -85,8 +85,9 @@ fi + cp $ROOT_DIR/../middleware/source/common/uproc/lib/$CHIP_TYPE/$COMPILE_TYPE/libuproc.so $OUT_DIR/ + cp $ROOT_DIR/../middleware/source/common/log/lib/$CHIP_TYPE/$COMPILE_TYPE/libmwlog.so $OUT_DIR/ + # cp $ROOT_DIR/../middleware/source/common/securec/lib/$CHIP_TYPE/$COMPILE_TYPE/libsecurec.so $OUT_DIR/ +- ++ + cp $ROOT_DIR/audio/libs/$BOARD_NAME/$TOOLCHAIN_BUILD_COMPILER/$KERNEL_OS_TYPE/libs/libaudio_hw.so $OUT_DIR/ ++ cp $ROOT_DIR/audio/libs/$BOARD_NAME/$TOOLCHAIN_BUILD_COMPILER/$KERNEL_OS_TYPE/libs/libaudio_usb_port.so $OUT_DIR/ + if [ -f "$ROOT_DIR/audio/libs/$BOARD_NAME/$TOOLCHAIN_BUILD_COMPILER/$KERNEL_OS_TYPE/libs/libaudio_primary_port.so" ]; then + cp $ROOT_DIR/audio/libs/$BOARD_NAME/$TOOLCHAIN_BUILD_COMPILER/$KERNEL_OS_TYPE/libs/libaudio_primary_port.so $OUT_DIR/ + fi +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/build.sh ohos1/device/soc/hisilicon/common/hal/media/build.sh +--- ohos/device/soc/hisilicon/common/hal/media/build.sh 2025-12-18 15:14:06.900482931 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/build.sh 2025-12-18 15:44:30.870238524 +0800 +@@ -21,6 +21,7 @@ function main(){ + #cp -rf $CUR_DIR/audio/$BOARD_NAME/$OS_TYPE/libs/libaudio_input_port.so $OUT_DIR/ + #cp -rf $CUR_DIR/audio/$BOARD_NAME/$OS_TYPE/libs/libaudio_output_port.so $OUT_DIR/ + cp -rf $CUR_DIR/audio/$BOARD_NAME/$OS_TYPE/libs/libaudio_primary_port.so $OUT_DIR/ ++ cp -rf $CUR_DIR/audio/$BOARD_NAME/$OS_TYPE/libs/libaudio_usb_port.so $OUT_DIR/ + + cp -rf $CUR_DIR/codec/$BOARD_NAME/$OS_TYPE/libs/libcodec.so $OUT_DIR/ + cp -rf $CUR_DIR/codec/$BOARD_NAME/$OS_TYPE/libs/libhiaacdec.so $OUT_DIR/ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/camera/source/src/hal_camera.c ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/hal_camera.c +--- ohos/device/soc/hisilicon/common/hal/media/camera/source/src/hal_camera.c 2025-12-18 15:14:06.900482931 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/hal_camera.c 2025-12-18 15:44:30.870238524 +0800 +@@ -1,2104 +1,2104 @@ +-/* +- * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. +- * +- * 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. +- */ +- +-#include "hal_camera.h" +-#include +-#include "hi_camera_vi.h" +- +-#include "display_layer.h" +-#include "media_hal_common.h" +-#include "ot_common_isp.h" +-#include "ss_mpi_isp.h" +-#include "ot_common_awb.h" +-#include "ss_mpi_awb.h" +- +-#ifdef KERNEL_USER_MODE +-#include "sdk.h" +-#endif +- +- +-#define STREAM_ABILITY_NUM 3 +-#define JPEG_VPSS_CHN 0 +-#define PREEV_VPSS_CHN 1 +-#define VIDEO_VPSS_CHN 2 +-#define CALLBACK_VPSS_CHN 2 +-#define CALLBACK_EXT_CHN 6 +-#define VIDEO_EXT_MIN_CHN (OT_VPSS_MAX_PHYS_CHN_NUM + 1) +-#define VIDEO_EXT_MAX_CHN (OT_VPSS_MAX_PHYS_CHN_NUM + 2) +-#define HI_ALIGN_DOWN_NUM 2 +-#define HI_ALIGN_UP_NUM 2 +-#define MAX_FPS 60 +-#define MIN_FPS 1 +-#define FRAME_TIME_OUT 1000 +-#define SUPPORT_MAX_CAMERA_NUM 2 +-#define CAEMRA_MAX_STREAM_NUM 10 +- +-#define CAMERA_TOF "CAMERA_TOF" +-#define CAMERA_RGB "CAMERA_RGB" +-#define KEY_EXPOSURE_MODE "exposuremode" +-#define KEY_SATURATION_MODE "saturationmode" +-#define KEY_SHARPEN_MODE "sharpenmode" +-#define KEY_DRC_MODE "drcmode" +-#define KEY_WB_MODE "wbmode" +- +-#define CAMERA_INIT_PARAM_PATH "/storage/data/cameradev.ini" +-#define MODE_NAME_MAX_LEN 64 +-#define MODE_NAME_MAX_NUM 16 +-#define CAMERA_INIT_DOC_PATH "/storage/data/" +-#define ENLARGE_VALUE 2 +-#define DISPLAY_DEVID 0 +- +-/* default layer width */ +-#define DEFAULT_WIDTH_FOR_HDMI 1920 +-#define DEFAULT_WIDTH_FOR_LCD 480 +-/* default layer height */ +-#define DEFAULT_HEIGHT_FOR_HDMI 1080 +-#define DEFAULT_HEIGHT_FOR_LCD 960 +-#define DEFAULT_DISPLAY_FPS 60 +-#define MIN_WIDTH 16 +-#define MIN_HEIGHT 16 +-#define RESOLUTION_2592X1944_W 2592 +-#define RESOLUTION_2592X1944_H 1944 +-#define RESOLUTION_1080P_W 1920 +-#define RESOLUTION_1080P_H 1080 +-#define RESOLUTION_720P_W 1280 +-#define RESOLUTION_720P_H 720 +-#define RESOLUTION_D1_NTSC_W 720 +-#define RESOLUTION_D1_NTSC_H 480 +-#define RESOLUTION_360P_W 640 +-#define RESOLUTION_360P_H 360 +-#define FPS_60 60 +-#define MAX_KEY_STR_SIZE 30 +-#define MAX_KEY_VALUE_SIZE 512 +-#define BLACK_DELAY_FRAME 10 +-#define ANTIFLIKER_FREQUENCY 50 +-#define EXP_TIME_RANGE_MAX 4000 +-#define EXP_TIME_RANGE_MIN 10 +-#define NUMBER_BASE_10 10 +- +-/* Maximum number of display devices supported */ +-#define DEV_ID_NUM 1 +-/* Byte align number */ +-#define BYTE_ALIGN_NUM 2 +-/* Video layer buffer len */ +-#define VIDEO_LAYER_BUFF_LEN 3 +-/* Vo device number */ +-#define VO_LAYER_ID 0 +- +-/* Rotate enable */ +-#define VO_ROTATE_ENABLE 1 +- +-LayerFuncs *g_layerInterface = NULL; +- +-typedef struct { +- bool isMirror; +- bool isFlip; +- ot_rotation_attr rotation; +- uint32_t fps; +- uint32_t width; +- uint32_t height; +- ot_vpss_crop_info cropInfo; +- uint32_t maxW; +- uint32_t maxH; +- int32_t vpssGrp; +-} ControlInfo; +- +-typedef enum { +- HAL_CENTER_MIRROR = 0, /**< Central mirroring */ +- HAL_HORIZONTAL_MIRROR = 1, /**< Horizontal mirroring */ +- HAL_VETICALLY_MIRROR = 2, /**< Vertical mirroring */ +- HAL_ROTATION_90 = 3, /**< 90-degree rotation */ +- HAL_ROTATION_180 = 4, /**< 180-degree rotation */ +- HAL_ROTATION_BUTT, +-} CameraHalInvertMode; +- +-typedef struct { +- int32_t vpssChn; +- PosInfo pos; +- bool isUsed; +- bool isSetDepth; +- ot_video_frame_info videoFrame; +-} InternalStreamInfo; +- +-typedef struct { +- BufferAvailable bufferCallBack; +- CameraResultCb resultCb; +- StreamAttr streamAttr[CAEMRA_MAX_STREAM_NUM]; +- InternalStreamInfo internalStreamInfo[CAEMRA_MAX_STREAM_NUM]; +- bool isOpen; +- CameraType type; +- int32_t vpssGrp; +- uint32_t layerId; +-} CameraInfo; +- +-typedef struct { +- uint8_t modeNum; +- uint8_t index; +- char modeNameList[MODE_NAME_MAX_NUM][MODE_NAME_MAX_LEN]; +-} ModeInfo; +-static ModeInfo g_modeInfo = { 0 }; +- +-static CameraInfo g_cameraInfo[SUPPORT_MAX_CAMERA_NUM] = { 0 }; +-static InitParam g_initParam[SUPPORT_MAX_CAMERA_NUM] = { 0 }; +-static CameraDetectCb g_cameraDetect = NULL; +-static uint8_t g_cameraNum = 2; +-static bool g_isInit = false; +- +-static td_void AUDIO_init(void) +-{ +- td_s32 ret; +- +- ret = ot_aiao_mod_init(); +- if (ret != 0) { +- HAL_LOGE("aiao init error.\n"); +- } +- +- ret = ot_ai_mod_init(); +- if (ret != 0) { +- HAL_LOGE("ai init error.\n"); +- } +- +- ret = ot_ao_mod_init(); +- if (ret != 0) { +- HAL_LOGE("ao init error.\n"); +- } +- +- ret = ot_aenc_mod_init(); +- if (ret != 0) { +- HAL_LOGE("aenc init error.\n"); +- } +- +- ret = ot_adec_mod_init(); +- if (ret != 0) { +- HAL_LOGE("adec init error.\n"); +- } +- +- ret = ot_acodec_mod_init(); +- if (ret != 0) { +- HAL_LOGE("acodec init error.\n"); +- } +-} +- +-static td_s32 basic_mod_init() +-{ +- td_s32 ret; +- ret = osal_init(); +- if (ret != 0) { +- HAL_LOGE("osal_init init error.\n"); +- } +- +- ret = ot_base_mod_init(); +- if (ret != 0) { +- HAL_LOGE("base init error.\n"); +- } +- +- ret = ot_sys_mod_init(); +- if (ret != 0) { +- HAL_LOGE("sys init error.\n"); +- } +- +- ret = ot_chnl_mod_init(); +- if (ret != 0) { +- HAL_LOGE("chnl init error.\n"); +- } +- return ret; +-} +- +-static td_s32 common_mod_init() +-{ +- td_s32 ret; +- ret = ot_rgn_mod_init(); +- if (ret != 0) { +- HAL_LOGE("rgn init error.\n"); +- } +- struct { +- td_u32 u32_max_gdc_job; +- td_u32 u32_max_gdc_task; +- td_u32 u32_max_gdc_node; +- td_u32 au32_gdc_en[1]; +- } gdcModuleParam; +- gdcModuleParam.u32_max_gdc_job = 32; /* 32 -- max job num */ +- gdcModuleParam.u32_max_gdc_task = 64; /* 64 -- max task num */ +- gdcModuleParam.u32_max_gdc_node = 64; /* 64 -- max node num */ +- gdcModuleParam.au32_gdc_en[0] = 1; +- ret = ot_gdc_mod_init(&gdcModuleParam); +- if (ret != 0) { +- HAL_LOGE("gdc init error.\n"); +- } +- +- struct { +- td_u32 max_vgs_job; +- td_u32 max_vgs_task; +- td_u32 max_vgs_node; +- } vgsModuleParam; +- vgsModuleParam.max_vgs_job = 64; /* 64 -- max job num */ +- vgsModuleParam.max_vgs_task = 200; /* 200 -- max task num */ +- vgsModuleParam.max_vgs_node = 200; /* 200 -- max node num */ +- ret = ot_vgs_mod_init(&vgsModuleParam); +- if (ret != 0) { +- HAL_LOGE("vgs init error.\n"); +- } +- +- ret = ot_dis_mod_init(); +- if (ret != 0) { +- HAL_LOGE("dis init error.\n"); +- } +- +- ret = ot_vpp_mod_init(); +- if (ret != 0) { +- HAL_LOGE("vpp init error.\n"); +- } +- return ret; +-} +- +-static td_s32 business_mod_init() +-{ +- td_s32 ret; +- ret = ot_vi_mod_init(); +- if (ret != 0) { +- HAL_LOGE("vi init error.\n"); +- } +- +- ret = ot_isp_mod_init(); +- if (ret != 0) { +- HAL_LOGE("isp init error.\n"); +- } +- +- ret = ot_vpss_mod_init(NULL); +- if (ret != 0) { +- HAL_LOGE("vpss init error.\n"); +- } +- +- ret = ot_vo_mod_init(); +- if (ret != 0) { +- HAL_LOGE("vo init error.\n"); +- } +- +- ret = ot_vedu_mod_init(); +- if (ret != 0) { +- HAL_LOGE("vedu init error.\n"); +- } +- +- ret = ot_rc_mod_init(); +- if (ret != 0) { +- HAL_LOGE("rc init error.\n"); +- } +- +- td_u32 max_chn = 64; +- ret = ot_venc_mod_init(max_chn); +- if (ret != 0) { +- HAL_LOGE("venc init error.\n"); +- } +- +- ret = ot_h264e_mod_init(); +- if (ret != 0) { +- HAL_LOGE("H264e init error.\n"); +- } +- +- ret = ot_h265e_mod_init(NULL); +- if (ret != 0) { +- HAL_LOGE("H265e init error.\n"); +- } +- +- ret = ot_jpege_mod_init(); +- if (ret != 0) { +- HAL_LOGE("jpege init error.\n"); +- } +- return ret; +-} +- +-static td_s32 business_mod_init1() +-{ +- td_s32 ret; +- +- ret = ot_jpegd_mod_init(); +- if (ret != 0) { +- HAL_LOGE("jpegd init error.\n"); +- } +- +- ret = ot_vfmw_mod_init(32); /* 32 */ +- if (ret != 0) { +- HAL_LOGE("vfmw init error.\n"); +- } +- +- ret = ot_vdec_mod_init(); +- if (ret != 0) { +- HAL_LOGE("vdec init error.\n"); +- } +- +- AUDIO_init(); +- +- return ret; +-} +- +-td_void SDK_init(void) +-{ +- td_s32 ret; +- ret = basic_mod_init(); +- if (ret != 0) { +- HAL_LOGE("basic_mod_init error.\n"); +- return; +- } +- +- ret = common_mod_init(); +- if (ret != 0) { +- HAL_LOGE("common_mod_init error.\n"); +- return; +- } +- +- ret = business_mod_init(); +- if (ret != 0) { +- HAL_LOGE("business_mod_init error.\n"); +- return; +- } +- +- ret = business_mod_init1(); +- if (ret != 0) { +- HAL_LOGE("basic_mod_init error.\n"); +- return; +- } +- +- ot_dev_init(); +- +- HAL_LOGI("SDK init ok...\n"); +-} +- +-static td_void AUDIO_exit(void) +-{ +- ot_acodec_mod_exit(); +- ot_adec_mod_exit(); +- ot_aenc_mod_exit(); +- ot_ao_mod_exit(); +- ot_ai_mod_exit(); +- ot_aiao_mod_exit(); +-} +- +-td_void SDK_exit(void) +-{ +- ot_dev_exit(); +- AUDIO_exit(); +- ot_vdec_mod_exit(); +- ot_vfmw_mod_exit(); +- ot_jpegd_mod_exit(); +- ot_jpege_mod_exit(); +- ot_h265e_mod_exit(); +- ot_h264e_mod_exit(); +- ot_venc_mod_exit(); +- ot_rc_mod_exit(); +- ot_vedu_mod_exit(); +- ot_vo_mod_exit(); +- ot_vpss_mod_exit(); +- ot_isp_mod_exit(); +- ot_vi_mod_exit(); +- ot_vpp_mod_exit(); +- ot_dis_mod_exit(); +- ot_vgs_mod_exit(); +- ot_gdc_mod_exit(); +- ot_rgn_mod_exit(); +- ot_chnl_mod_exit(); +- ot_sys_mod_exit(); +- ot_base_mod_exit(); +- osal_exit(); +- HAL_LOGI("SDK exit ok...\n"); +-} +- +-static int Cmp(const void *a, const void *b) +-{ +- return strcmp((char *)a, (char *)b); +-} +- +-static void InitModeInfo(void) +-{ +- DIR *dir = opendir(CAMERA_INIT_DOC_PATH); +- struct dirent *ptr = NULL; +- if (dir == NULL) { +- HAL_LOGE("Open dir error...\n"); +- return; +- } +- +- uint8_t i = 0; +- while (i < MODE_NAME_MAX_NUM) { +- ptr = readdir(dir); +- if (ptr == NULL) { +- HAL_LOGI("break\n"); +- break; +- } +- if (strncmp(ptr->d_name, "camera", 0x6) == 0) { +- HAL_LOGI("file name:%s\n", ptr->d_name); +- HAL_LOG_DOFUNC(strncpy_s(&g_modeInfo.modeNameList[i][0], MODE_NAME_MAX_LEN - 1, +- ptr->d_name, ptr->d_reclen)); +- i++; +- } +- } +- +- g_modeInfo.modeNum = i; +- HAL_LOGI("mode num =%u\n", g_modeInfo.modeNum); +- qsort(g_modeInfo.modeNameList, i, MODE_NAME_MAX_LEN, Cmp); +- closedir(dir); +-} +- +-static uint8_t GetCurrentMode(void) +-{ +- ot_vb_cfg gotConfig = { 0 }; +- uint8_t index = 0; +- +- int32_t ret = ss_mpi_vb_get_cfg(&gotConfig); +- if (ret == TD_SUCCESS && gotConfig.max_pool_cnt != 0) { +- index = (uint8_t)((gotConfig.common_pool[0].blk_size - ENLARGE_VALUE) / ENLARGE_VALUE); +- } +- if (index >= g_modeInfo.modeNum) { +- HI_PRINTF("curr mode is wrong %u\n", index); +- index = 0; +- } +- HI_PRINTF("CurrentMode is %u\n", index); +- return index; +-} +- +-static void CameraSaveModeIndexWithVb(ot_vb_cfg *vbConfig) +-{ +- vbConfig->max_pool_cnt = 1; +- vbConfig->common_pool[0].blk_size = g_modeInfo.index * ENLARGE_VALUE + ENLARGE_VALUE; +- vbConfig->common_pool[0].blk_cnt = 1; +-} +- +-static void CameraSysConfigVb(ot_vb_cfg *pstVbConfig, const VB_PARAM_CONFIG_S *pstInitParam) +-{ +- uint32_t blkSize; +- pstVbConfig->max_pool_cnt += pstInitParam->stMaxPoolCnt; +- // The modeIndex of camera is save the NO.0, So starting with the 1st +- for (uint32_t i = 1; i < pstVbConfig->max_pool_cnt; i++) { +- uint32_t paramIndex = i - 1; // initParam starting with index 0 +- if (pstInitParam->stPixFormat[paramIndex] == OT_PIXEL_FORMAT_RGB_BAYER_12BPP) { +- ot_pic_buf_attr buf_attr = {0}; +- buf_attr.width = pstInitParam->stImageSize[paramIndex].width; +- buf_attr.height = pstInitParam->stImageSize[paramIndex].height; +- buf_attr.pixel_format = pstInitParam->stPixFormat[paramIndex]; +- buf_attr.bit_width = pstInitParam->stDataBitWidth[paramIndex]; +- buf_attr.compress_mode = pstInitParam->stCompressMode[paramIndex]; +- buf_attr.align = pstInitParam->stDefaultAlign[paramIndex]; +- blkSize = ot_common_get_pic_buf_size(&buf_attr); +- } else if (pstInitParam->stPixFormat[paramIndex] == OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420) { +- ot_pic_buf_attr buf_attr = {0}; +- buf_attr.width = pstInitParam->stImageSize[paramIndex].width; +- buf_attr.height = pstInitParam->stImageSize[paramIndex].height; +- buf_attr.pixel_format = pstInitParam->stPixFormat[paramIndex]; +- buf_attr.bit_width = pstInitParam->stDataBitWidth[paramIndex]; +- buf_attr.compress_mode = pstInitParam->stCompressMode[paramIndex]; +- buf_attr.align = pstInitParam->stDefaultAlign[paramIndex]; +- blkSize = ot_common_get_pic_buf_size(&buf_attr); +- pstVbConfig->common_pool[i].blk_size = blkSize; +- pstVbConfig->common_pool[i].blk_cnt = pstInitParam->stBlkCount[paramIndex]; +- } else { +- HI_PRINTF("other vb:%u,%u\n", paramIndex, pstInitParam->stPixFormat[paramIndex]); +- } +- } +-} +- +-static int32_t CameraVbInit(ot_vb_cfg *pstVbConfig) +-{ +- int32_t ret = ss_mpi_vb_set_cfg(pstVbConfig); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vb_set_cfg failed 0x%x!\n", ret); +- return TD_FAILURE; +- } +- ot_vb_supplement_cfg stSupplementConf = { 0 }; +- stSupplementConf.supplement_cfg = TD_TRUE; +- ret = ss_mpi_vb_set_supplement_cfg(&stSupplementConf); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vb_set_supplement_cfg failed!\n"); +- return TD_FAILURE; +- } +- ret = ss_mpi_vb_init(); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vb_init failed!\n"); +- return TD_FAILURE; +- } +- HAL_LOGI(" vb config success \n"); +- return TD_SUCCESS; +-} +- +-static int32_t CameraCreateVbPool(void) +-{ +- ot_vb_cfg vbConfig = { 0 }; +- ot_vb_cfg gotConfig = { 0 }; +- CameraSaveModeIndexWithVb(&vbConfig); +- CameraSysConfigVb(&vbConfig, &g_initParam[0].stVbAttr); +- td_s32 ret = ss_mpi_vb_get_cfg(&gotConfig); +- if (ret != TD_SUCCESS || gotConfig.max_pool_cnt == 0) { +- ret = CameraVbInit(&vbConfig); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("system init failed with %d!\n", ret); +- return TD_FAILURE; +- } +- } +- ret = MediaSystemInit(); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("MediaSystemInit failed.s32Ret:0x%x !\n", ret); +- } +- return TD_SUCCESS; +-} +- +-static void CameraDestoryVbPool(void) +-{ +- int32_t ret = MediaSystemDeinit(); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("MediaSystemDeinit failed 0x%x!\n", ret); +- return; +- } +- ret = ss_mpi_vb_exit(); +- if (ret != TD_SUCCESS) { +- ret = ss_mpi_vb_exit(); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vb_exit 1failed 0x%x!\n", ret); +- } +- } +-} +-static void CameraGetVpssGrpConfig(ot_vpss_grp_attr *pstVpssGrpAttr, const InitParam *initParam) +-{ +- if (memset_s(pstVpssGrpAttr, sizeof(ot_vpss_grp_attr), 0, sizeof(ot_vpss_grp_attr)) != EOK) { +- HI_PRINTF("memset_s pstVpssGrpAttr failed!"); +- } +- pstVpssGrpAttr->frame_rate.src_frame_rate = FPS_60; +- pstVpssGrpAttr->frame_rate.dst_frame_rate = FPS_60; +- pstVpssGrpAttr->dynamic_range = OT_DYNAMIC_RANGE_SDR8; +- pstVpssGrpAttr->pixel_format = initParam->stViAttr.stChnAttr[0][0].pixel_format; +- pstVpssGrpAttr->max_width = initParam->stViAttr.stChnAttr[0][0].size.width; +- pstVpssGrpAttr->max_height = initParam->stViAttr.stChnAttr[0][0].size.height; +-} +- +-static void CameraGetVpssChnConfig(ot_vpss_chn_attr pstVpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM], +- bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM], const InitParam *initParam) +-{ +- for (uint32_t i = 0; i < OT_VPSS_MAX_PHYS_CHN_NUM; i++) { +- pstVpssChnAttr[i].width = initParam->stViAttr.stChnAttr[0][0].size.width; +- pstVpssChnAttr[i].height = initParam->stViAttr.stChnAttr[0][0].size.height; +- pstVpssChnAttr[i].chn_mode = OT_VPSS_CHN_MODE_USER; +- pstVpssChnAttr[i].compress_mode = OT_COMPRESS_MODE_NONE; +- pstVpssChnAttr[i].dynamic_range = OT_DYNAMIC_RANGE_SDR8; +- pstVpssChnAttr[i].video_format = OT_VIDEO_FORMAT_LINEAR; +- pstVpssChnAttr[i].pixel_format = initParam->stViAttr.stChnAttr[0][0].pixel_format; +- pstVpssChnAttr[i].frame_rate.src_frame_rate = FPS_60; +- pstVpssChnAttr[i].frame_rate.dst_frame_rate = FPS_60; +- pstVpssChnAttr[i].depth = 0; +- pstVpssChnAttr[i].mirror_en = 0; +- pstVpssChnAttr[i].flip_en = 0; +- pstVpssChnAttr[i].border_en = 0; +- pstVpssChnAttr[i].aspect_ratio.mode = OT_ASPECT_RATIO_NONE; +- } +- chnEnable[0] = true; +-} +- +-static int32_t CameraVideoProcStart(ot_vpss_grp VpssGrp, bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM], +- ot_vpss_grp_attr *pstVpssGrpAttr, ot_vpss_chn_attr astVpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM]) +-{ +- int32_t ret = ss_mpi_vpss_create_grp(VpssGrp, pstVpssGrpAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_create_grp(grp:%d) failed with %#x!\n", VpssGrp, ret); +- return TD_FAILURE; +- } +- HI_PRINTF("ss_mpi_vpss_create_grp(grp:%d) success\n", VpssGrp); +- for (int32_t j = 0; j < OT_VPSS_MAX_PHYS_CHN_NUM; j++) { +- if (chnEnable[j]) { +- ot_vpss_chn VpssChn = j; +- ret = ss_mpi_vpss_set_chn_attr(VpssGrp, VpssChn, &astVpssChnAttr[VpssChn]); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_set_chn_attr failed with %#x\n", ret); +- return TD_FAILURE; +- } +- ret = ss_mpi_vpss_enable_chn(VpssGrp, VpssChn); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_enable_chn failed with %#x\n", ret); +- return TD_FAILURE; +- } +- +-#if defined(ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY) && (ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY != 0) +- ot_low_delay_info vpssLdyInfo; +- ret = ss_mpi_vpss_get_chn_low_delay(VpssGrp, VpssChn, &vpssLdyInfo); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_get_chn_low_delay failed with %#x\n", ret); +- return TD_FAILURE; +- } +- vpssLdyInfo.enable = TD_TRUE; +- vpssLdyInfo.line_cnt = 16; /* 16:VDEC_LOW_DELAY_MIN_LINE */ +- ret = ss_mpi_vpss_set_chn_low_delay(VpssGrp, VpssChn, &vpssLdyInfo); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_set_chn_low_delay failed with %#x\n", ret); +- return TD_FAILURE; +- } +-#endif +- } +- } +- ret = ss_mpi_vpss_start_grp(VpssGrp); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_start_grp failed with %#x\n", ret); +- return TD_FAILURE; +- } +- HI_PRINTF("CameraVideoProcStart success\n"); +- return TD_SUCCESS; +-} +- +-int32_t CameraVpssEnableLowDelay(void) +-{ +-#if defined(ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY) && (ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY != 0) +- ot_low_delay_info vpssLdyInfo; +- int32_t ret = ss_mpi_vpss_get_chn_low_delay(0, 0, &vpssLdyInfo); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_get_chn_low_delay failed with %#x\n", ret); +- return TD_FAILURE; +- } +- +- vpssLdyInfo.enable = TD_TRUE; +- vpssLdyInfo.line_cnt = 16; /* 16:VDEC_LOW_DELAY_MIN_LINE */ +- ret = ss_mpi_vpss_set_chn_low_delay(0, 0, &vpssLdyInfo); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_set_chn_low_delay failed with %#x\n", ret); +- return TD_FAILURE; +- } +-#endif +- return TD_SUCCESS; +-} +- +-static int32_t CameraViBindVproc(ot_vi_pipe ViPipe, ot_vi_chn ViChn, ot_vpss_grp VpssGrp) +-{ +- ot_mpp_chn stSrcChn; +- ot_mpp_chn stDestChn; +- stSrcChn.mod_id = OT_ID_VI; +- stSrcChn.dev_id = ViPipe; +- stSrcChn.chn_id = ViChn; +- stDestChn.mod_id = OT_ID_VPSS; +- stDestChn.dev_id = VpssGrp; +- stDestChn.chn_id = 0; +- CHECK_RET(ss_mpi_sys_bind(&stSrcChn, &stDestChn), "ss_mpi_sys_bind(VI-VPSS)"); +- return TD_SUCCESS; +-} +- +-static int32_t CameraVideoProcStop(ot_vpss_grp VpssGrp, bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM]) +-{ +- int32_t ret; +- for (int32_t j = 0; j < OT_VPSS_MAX_PHYS_CHN_NUM; j++) { +- if (chnEnable[j]) { +- ot_vpss_chn VpssChn = j; +- ret = ss_mpi_vpss_disable_chn(VpssGrp, VpssChn); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- } +- } +- ret = ss_mpi_vpss_stop_grp(VpssGrp); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- ret = ss_mpi_vpss_destroy_grp(VpssGrp); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- HI_PRINTF("CameraVideoProcStop success"); +- return TD_SUCCESS; +-} +- +-static int32_t CameraViUnBindVproc(ot_vi_pipe viPipe, ot_vi_chn viChn, ot_vpss_grp vpssGrp) +-{ +- ot_mpp_chn stSrcChn; +- ot_mpp_chn stDestChn; +- stSrcChn.mod_id = OT_ID_VI; +- stSrcChn.dev_id = viPipe; +- stSrcChn.chn_id = viChn; +- stDestChn.mod_id = OT_ID_VPSS; +- stDestChn.dev_id = vpssGrp; +- stDestChn.chn_id = 0; +- CHECK_RET(ss_mpi_sys_unbind(&stSrcChn, &stDestChn), "ss_mpi_sys_unbind(VI-VPSS)"); +- +- return TD_SUCCESS; +-} +- +-static void CameraInitParam(uint32_t mode) +-{ +- char path[PATH_MAX_LEN] = { 0 }; +- +- if (snprintf_s(path, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s%s", CAMERA_INIT_DOC_PATH, +- g_modeInfo.modeNameList[mode]) < 0) { +- HI_PRINTF("snprintf_s failed\n"); +- return; +- } +- +- HI_PRINTF("path = %s\n", path); +- if (memset_s(&g_initParam, sizeof(g_initParam), 0, sizeof(g_initParam)) != EOK) { +- HI_PRINTF("memset_s g_initParam failed\n"); +- } +- uint8_t ret = GetParamCamera(path, g_initParam, SUPPORT_MAX_CAMERA_NUM); +- if (ret < SUPPORT_MAX_CAMERA_NUM) { +- g_cameraNum = ret; +- } else { +- g_cameraNum = SUPPORT_MAX_CAMERA_NUM - 1; +- } +- HI_PRINTF("lib_:%s, obj_:%s\n", g_initParam[g_cameraNum].stViAttr.sensorLib, +- g_initParam[g_cameraNum].stViAttr.sensorObj); +-} +- +-static void ReadRangCap(uint32_t cameraId, StreamCap* streamCap, uint32_t streamNum) +-{ +- InitParam *initParam = &g_initParam[cameraId]; +- for (uint32_t i = 0; i < streamNum; i++) { +- streamCap[i].format = FORMAT_YVU420; +- streamCap[i].u.range.maxFps = initParam->stViAttr.stChnAttr[0][0].frame_rate_ctrl.dst_frame_rate; +- streamCap[i].u.range.minFps = MIN_FPS; +- streamCap[i].u.range.maxHeight = initParam->stViAttr.stChnAttr[0][0].size.height; +- streamCap[i].u.range.minHeight = MIN_HEIGHT; +- streamCap[i].u.range.maxWidth = initParam->stViAttr.stChnAttr[0][0].size.width; +- streamCap[i].u.range.minWidth = MIN_WIDTH; +- } +-} +- +-static void ReadEnumCap(uint32_t cameraId, StreamCap* streamCap, uint32_t streamNum) +-{ +- InitParam *initParam = &g_initParam[cameraId]; +- for (uint32_t i = 0; i < streamNum; i++) { +- streamCap[i].format = FORMAT_YVU420; +- streamCap[i].u.formatEnum.frame_rate[0] = \ +- initParam->stViAttr.stChnAttr[0][0].frame_rate_ctrl.dst_frame_rate; +- streamCap[i].u.formatEnum.frame_rate_num = 1; +- if (i == 0) { +- streamCap[i].u.formatEnum.width = RESOLUTION_2592X1944_W; +- streamCap[i].u.formatEnum.height = RESOLUTION_2592X1944_H; +- } else if (i == 1) { +- streamCap[i].u.formatEnum.width = RESOLUTION_1080P_W; +- streamCap[i].u.formatEnum.height = RESOLUTION_1080P_H; +- } else if (i == 0x2) { +- streamCap[i].u.formatEnum.width = RESOLUTION_720P_W; +- streamCap[i].u.formatEnum.height = RESOLUTION_720P_H; +- } else if (i == 0x3) { +- streamCap[i].u.formatEnum.width = RESOLUTION_D1_NTSC_W; +- streamCap[i].u.formatEnum.height = RESOLUTION_D1_NTSC_H; +- } else if (i == 0x4) { +- streamCap[i].u.formatEnum.width = RESOLUTION_360P_W; +- streamCap[i].u.formatEnum.height = RESOLUTION_360P_H; +- } else { +- streamCap[i].u.formatEnum.width = RESOLUTION_1080P_W; +- streamCap[i].u.formatEnum.height = RESOLUTION_1080P_H; +- } +- } +-} +- +-static void DisableVpssExtChn(ot_vpss_grp vpssGrp) +-{ +- for (ot_vpss_chn chn = OT_VPSS_MAX_PHYS_CHN_NUM; chn <= CALLBACK_EXT_CHN; chn++) { +- ss_mpi_vpss_disable_chn(vpssGrp, chn); +- } +-} +- +-static int32_t ParamCheck(const StreamAttr *stream, const ControlInfo *config) +-{ +- if (stream->invertMode >= HAL_ROTATION_BUTT) { +- HI_PRINTF("rotation param invalid\n"); +- return TD_FAILURE; +- } +- if (stream->fps > MAX_FPS || stream->fps == 0) { +- HI_PRINTF("fps param invalid\n"); +- return TD_FAILURE; +- } +- if (stream->width <= 0 || stream->width > MAX_FRAME_WIDTH || +- stream->height <= 0 || stream->height > MAX_FRAME_WIDTH) { +- HI_PRINTF("width height param invalid\n"); +- return TD_FAILURE; +- } +- if (stream->crop.x == 0 && stream->crop.y == 0 && +- stream->crop.w == 0 && stream->crop.h == 0) { +- return TD_SUCCESS; +- } +- if (stream->crop.x + stream->crop.w > config->maxW || +- stream->crop.y + stream->crop.h > config->maxH) { +- HI_PRINTF("crop param invalid\n"); +- return TD_FAILURE; +- } +- if (stream->invertMode == HAL_ROTATION_90) { +- if (stream->crop.w < stream->height || stream->crop.h < stream->width) { +- HI_PRINTF("crop param invalid\n"); +- return TD_FAILURE; +- } +- } else if (stream->crop.h < stream->height || stream->crop.w < stream->width) { +- HI_PRINTF("crop param invalid\n"); +- return TD_FAILURE; +- } +- return TD_SUCCESS; +-} +- +-#ifdef USE_EXT_CHN +-static void GetVpss(const StreamAttr *stream, const CameraInfo *cameraInfo, +- ot_vpss_chn *vpssChn, ot_vpss_chn *vpssPhyChn) +-{ +- *vpssChn = -1; +- static ot_vpss_chn videoChn = VIDEO_EXT_MIN_CHN; +- if (stream->type == STREAM_VIDEO) { +- if (videoChn > VIDEO_EXT_MAX_CHN) { +- videoChn = VIDEO_EXT_MIN_CHN; +- } +- *vpssChn = videoChn++; +- *vpssPhyChn = VIDEO_VPSS_CHN; +- } else if (stream->type == STREAM_PREVIEW) { +- *vpssChn = PREEV_VPSS_CHN; +- *vpssPhyChn = PREEV_VPSS_CHN; +- } else if (stream->type == STREAM_CAPTURE) { +- *vpssChn = OT_VPSS_MAX_PHYS_CHN_NUM; +- *vpssPhyChn = JPEG_VPSS_CHN; +- } else { +- *vpssChn = CALLBACK_EXT_CHN; +- *vpssPhyChn = CALLBACK_VPSS_CHN; +- } +-} +-#else +-static void GetVpss(const StreamAttr *stream, const CameraInfo *cameraInfo, +- ot_vpss_chn *vpssChn, ot_vpss_chn *vpssPhyChn) +-{ +- (void)stream; +- *vpssChn = -1; +- *vpssPhyChn = -1; +- for (td_u8 i = 0; i < CAEMRA_MAX_STREAM_NUM; i++) { +- if (cameraInfo->internalStreamInfo[i].isUsed == true || +- cameraInfo->internalStreamInfo[i].vpssChn >= OT_VPSS_MAX_PHYS_CHN_NUM) { +- continue; +- } +- *vpssChn = i; +- *vpssPhyChn = i; +- HI_PRINTF("GetVpss chnn :%u\n", i); +- return; +- } +-} +-#endif +- +-static uint32_t GetDeviceId(uint32_t chn) +-{ +- return (((OT_ID_VPSS << 0x10) & 0xff0000) + (chn & 0xff)); // 16 +-} +- +-static bool IsValidChnn(ot_vpss_chn vpssChn) +-{ +- if (vpssChn >= 0 && vpssChn < OT_VPSS_MAX_CHN_NUM) { +- return true; +- } +- return false; +-} +- +-static void ConvertCrop(ot_vpss_chn vpssChn, const StreamAttr *stream, ControlInfo *config) +-{ +- if (stream->crop.w == 0 || stream->crop.h == 0) { +- config->cropInfo.enable = TD_FALSE; +- config->cropInfo.crop_mode = OT_COORD_ABS; +- config->cropInfo.crop_rect.x = 0; +- config->cropInfo.crop_rect.y = 0; +- config->cropInfo.crop_rect.width = config->maxW; +- config->cropInfo.crop_rect.height = config->maxH; +- return; +- } +- config->cropInfo.enable = TD_TRUE; +- config->cropInfo.crop_mode = OT_COORD_ABS; +- if (vpssChn < OT_VPSS_MAX_PHYS_CHN_NUM) { +- if (config->rotation.rotation_fixed == OT_ROTATION_90) { +- config->cropInfo.crop_rect.width = ALIGN_DOWN(stream->height, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.height = ALIGN_DOWN(stream->width, HI_ALIGN_DOWN_NUM); +- td_u32 x = stream->crop.x * stream->height / stream->crop.w; +- td_u32 y = stream->crop.y * stream->width / stream->crop.h; +- config->cropInfo.crop_rect.x = ALIGN_DOWN(x, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.y = ALIGN_DOWN(y, HI_ALIGN_DOWN_NUM); +- } else { +- config->cropInfo.crop_rect.width = ALIGN_DOWN(stream->width, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.height = ALIGN_DOWN(stream->height, HI_ALIGN_DOWN_NUM); +- td_u32 x = stream->crop.x * stream->width / stream->crop.w; +- td_u32 y = stream->crop.y * stream->height / stream->crop.h; +- config->cropInfo.crop_rect.x = ALIGN_DOWN(x, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.y = ALIGN_DOWN(y, HI_ALIGN_DOWN_NUM); +- } +- } else { +- if (config->rotation.rotation_fixed == OT_ROTATION_90) { +- config->cropInfo.crop_rect.x = ALIGN_DOWN(stream->crop.y, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.y = ALIGN_DOWN(stream->crop.x, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.width = ALIGN_DOWN(stream->crop.h, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.height = ALIGN_DOWN(stream->crop.w, HI_ALIGN_DOWN_NUM); +- } else { +- config->cropInfo.crop_rect.x = ALIGN_DOWN(stream->crop.x, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.y = ALIGN_DOWN(stream->crop.y, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.width = ALIGN_DOWN(stream->crop.w, HI_ALIGN_DOWN_NUM); +- config->cropInfo.crop_rect.height = ALIGN_DOWN(stream->crop.h, HI_ALIGN_DOWN_NUM); +- } +- } +-} +- +-static void ConvetToControlInfo(ot_vpss_chn vpssChn, const StreamAttr *stream, ControlInfo *config) +-{ +- if (IsValidChnn(vpssChn) == false) { +- return; +- } +- config->fps = stream->fps; +- config->width = stream->width; +- config->height = stream->height; +- config->rotation.enable = TD_TRUE; +- config->rotation.rotation_type = OT_ROTATION_ANG_FIXED; +- if (stream->invertMode == HAL_HORIZONTAL_MIRROR) { +- config->isFlip = TD_TRUE; +- } else if (stream->invertMode == HAL_VETICALLY_MIRROR) { +- config->isMirror = TD_TRUE; +- } else if (stream->invertMode == HAL_ROTATION_90) { +- config->rotation.rotation_fixed = OT_ROTATION_90; +- } else if (stream->invertMode == HAL_ROTATION_180) { +- config->rotation.rotation_fixed = OT_ROTATION_180; +- } else { +- config->isFlip = TD_FALSE; +- config->isMirror = TD_FALSE; +- config->rotation.rotation_fixed = OT_ROTATION_0; +- } +- +- ConvertCrop(vpssChn, stream, config); +- HAL_LOGI("flip = %d rota = %d crop w = %u enable = %d\n", config->isFlip, config->rotation.rotation_fixed, +- config->cropInfo.crop_rect.width, config->cropInfo.enable); +-} +- +-static void GetVpssExtChnConfig(ot_vpss_ext_chn_attr *extChnAttr, const ControlInfo *config, +- ot_vpss_chn_attr *vpssChnAttr, ot_vpss_chn vpssPhyChn) +-{ +- extChnAttr->bind_chn = vpssPhyChn; +- extChnAttr->pixel_format = OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420; +- extChnAttr->frame_rate.src_frame_rate = vpssChnAttr->frame_rate.dst_frame_rate; +- extChnAttr->frame_rate.dst_frame_rate = config->fps; +- extChnAttr->width = config->width; +- extChnAttr->height = config->height; +-} +- +-static int32_t GetFreeStreamIndex(const CameraInfo *cameraInfo, uint32_t *streamIndex) +-{ +- for (int32_t i = 0; i < CAEMRA_MAX_STREAM_NUM; i++) { +- if (!cameraInfo->internalStreamInfo[i].isUsed) { +- *streamIndex = i; +- return TD_SUCCESS; +- } +- } +- HAL_LOGE("get free stream index failed\n"); +- return TD_FAILURE; +-} +- +-static void AddStream(CameraInfo *cameraInfo, uint32_t streamIndex, ot_vpss_chn vpssChn, const StreamAttr *stream) +-{ +- LOG_CHK_RETURN(streamIndex >= CAEMRA_MAX_STREAM_NUM); +- cameraInfo->streamAttr[streamIndex] = *stream; +- cameraInfo->internalStreamInfo[streamIndex].isUsed = true; +- cameraInfo->internalStreamInfo[streamIndex].vpssChn = vpssChn; +- HAL_LOGI("stream %u vpss = %d\n", streamIndex, vpssChn); +-} +- +-static void DeleteStream(CameraInfo *cameraInfo, uint32_t streamIndex) +-{ +- ot_vpss_grp vpssGrp = 0; +- ot_vpss_chn vpssChn = cameraInfo->internalStreamInfo[streamIndex].vpssChn; +- HAL_LOG_DOFUNC(memset_s(&cameraInfo->streamAttr[streamIndex], sizeof(StreamAttr), 0, sizeof(StreamAttr))); +- HAL_LOG_DOFUNC(memset_s(&cameraInfo->internalStreamInfo[streamIndex], sizeof(InternalStreamInfo), +- 0, sizeof(InternalStreamInfo))); +- for (uint8_t i = 0; i < CAEMRA_MAX_STREAM_NUM; i++) { +- if (cameraInfo->internalStreamInfo[i].isUsed && cameraInfo->internalStreamInfo[i].vpssChn == vpssChn) { +- return; +- } +- } +- if (vpssChn >= OT_VPSS_MAX_PHYS_CHN_NUM) { +- ss_mpi_vpss_disable_chn(vpssGrp, vpssChn); +- } +-} +- +-static int32_t EnablePreview(ot_vpss_chn vpssChn, uint32_t cameraId, PosInfo *pos, const StreamAttr *streamAttr) +-{ +- IRect displayRect; +- displayRect.x = pos->x; +- displayRect.y = pos->y; +- displayRect.w = streamAttr->width; +- displayRect.h = streamAttr->height; +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- int32_t vpssGrp = cameraInfo->vpssGrp; +- LayerInfo layerInfo = {0}; +- layerInfo.width = streamAttr->width; +- layerInfo.height = streamAttr->height; +- layerInfo.type = LAYER_TYPE_OVERLAY; +- layerInfo.bpp = 8; // 8: Number of bits occupied by each pixel +- layerInfo.pixFormat = PIXEL_FMT_YCRCB_420_SP; +- layerInfo.fps = streamAttr->fps; +- LOG_CHK_RETURN_ERR(g_layerInterface == NULL, TD_FAILURE); +- HAL_LOG_DOFUNC_RETURN(g_layerInterface->CreateLayer(DISPLAY_DEVID, &layerInfo, &cameraInfo->layerId)); +- HAL_LOG_DOFUNC_RETURN(g_layerInterface->SetLayerSize(DISPLAY_DEVID, cameraInfo->layerId, &displayRect)); +- HAL_LOG_DOFUNC_RETURN(g_layerInterface->InvokeLayerCmd(DISPLAY_DEVID, cameraInfo->layerId, +- OVERLAYER_CMD_VO_BIND_VPSS, vpssChn, vpssGrp)); +- return TD_SUCCESS; +-} +- +-static void DisablePreview(ot_vpss_chn vpssChn, uint32_t cameraId) +-{ +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- int32_t vpssGrp = cameraInfo->vpssGrp; +- LOG_CHK_RETURN(g_layerInterface == NULL); +- g_layerInterface->InvokeLayerCmd(DISPLAY_DEVID, cameraInfo->layerId, +- OVERLAYER_CMD_VO_UNBIND_VPSS, vpssChn, vpssGrp); +- g_layerInterface->CloseLayer(DISPLAY_DEVID, cameraInfo->layerId); +- cameraInfo->layerId = -1; +-} +- +-static int32_t CovertToBuffer(const ot_video_frame_info *videoFrame, HalBuffer *halBuffer) +-{ +- if (halBuffer->format == FORMAT_PRIVATE) { +- HalBuffer getBuf; +- getBuf.stride0 = (int32_t)videoFrame->video_frame.stride[0]; +- getBuf.stride1 = (int32_t)videoFrame->video_frame.stride[1]; +- getBuf.height = (int32_t)videoFrame->video_frame.height; +- getBuf.width = (int32_t)videoFrame->video_frame.width; +- getBuf.timeStamp = (int64_t)videoFrame->video_frame.pts; +- int32_t size = getBuf.height * getBuf.width * 0x3 / 0x2; // YUV size +- if (halBuffer->size <= size) { +- HAL_LOGE("%d <= %d\n", halBuffer->size, size); +- return TD_FAILURE; +- } +- getBuf.size = size; +- getBuf.format = FORMAT_YVU420; +- getBuf.phyAddr = videoFrame->video_frame.phys_addr[0]; +- HAL_LOG_DOFUNC_RETURN(memcpy_s(halBuffer->virAddr, halBuffer->size, &getBuf, sizeof(HalBuffer))); +- return TD_SUCCESS; +- } else if (videoFrame->video_frame.pixel_format == OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420) { +- halBuffer->format = FORMAT_YVU420; +- } else if (videoFrame->video_frame.pixel_format == OT_PIXEL_FORMAT_RGB_BAYER_12BPP) { +- halBuffer->format = FORMAT_RGB_BAYER_12BPP; +- } else { +- } +- halBuffer->stride0 = (int32_t)videoFrame->video_frame.stride[0]; +- halBuffer->stride1 = (int32_t)videoFrame->video_frame.stride[1]; +- halBuffer->height = (int32_t)videoFrame->video_frame.height; +- halBuffer->width = (int32_t)videoFrame->video_frame.width; +- halBuffer->timeStamp = (int64_t)videoFrame->video_frame.pts; +- halBuffer->size = halBuffer->height * halBuffer->width * 0x3 / 0x2; // YUV size +- halBuffer->virAddr = (void *) ss_mpi_sys_mmap(videoFrame->video_frame.phys_addr[0], halBuffer->size); +- return TD_SUCCESS; +-} +- +- +-static void CameraGetViConfig(CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- for (uint32_t i = 0; i < cameraCnt; i++) { +- pstViConfig[i].stSnsInfo.s32SnsId = g_initParam[i].stViAttr.stMipiAttr.devno; +- HI_PRINTF("sns id = %u\n", g_initParam[i].stViAttr.stMipiAttr.devno); +- pstViConfig[i].stSnsInfo.s32BusId = g_initParam[i].stViAttr.busId; +- pstViConfig[i].stSnsInfo.MipiDev = g_initParam[i].stViAttr.stMipiAttr.devno; +- pstViConfig[i].stDevInfo.ViDev = g_initParam[i].stViAttr.stMipiAttr.devno; +- HAL_LOG_DOFUNC(memset_s(&pstViConfig[i].stSnapInfo, sizeof(HISI_SNAP_INFO_S), 0, sizeof(HISI_SNAP_INFO_S))); +- pstViConfig[i].stPipeInfo.bMultiPipe = TD_FALSE; +- pstViConfig[i].stPipeInfo.bVcNumCfged = TD_FALSE; +- pstViConfig[i].stPipeInfo.enMastPipeMode = g_initParam[i].stViAttr.pipeMode[0]; +- pstViConfig[i].stPipeInfo.aPipe[0] = g_initParam[i].stViAttr.stMipiAttr.devno; +- pstViConfig[i].stPipeInfo.aPipe[0] = 0; +- for (int32_t j = 0x1; j < OT_VI_MAX_PIPE_NUM; j++) { +- pstViConfig[i].stPipeInfo.aPipe[j] = -1; +- } +- if (cameraCnt == 1 && g_cameraNum == SUPPORT_MAX_CAMERA_NUM) { // 1 sensor(2 pipe) analog 2 sensors +- pstViConfig[0].stPipeInfo.aPipe[1] = pstViConfig[0].stPipeInfo.aPipe[0] + 1; +- } +- +- pstViConfig[i].stPipeInfo.frameInterruptType = g_initParam[i].stViAttr.frameInterruptType[0]; +- pstViConfig[i].stPipeInfo.earlyLine = g_initParam[i].stViAttr.earlyLine[0]; +- pstViConfig[i].stChnInfo.ViChn = 0; +- pstViConfig[i].stChnInfo.enPixFormat = g_initParam[i].stViAttr.stChnAttr[0][0].pixel_format; +- pstViConfig[i].stChnInfo.dynamicRange = g_initParam[i].stViAttr.stChnAttr[0][0].dynamic_range; +- pstViConfig[i].stChnInfo.videoFormat = g_initParam[i].stViAttr.stChnAttr[0][0].video_format; +- pstViConfig[i].stChnInfo.compressMode = g_initParam[i].stViAttr.stChnAttr[0][0].compress_mode; +- pstViConfig[i].mipiAttr = &g_initParam[i].stViAttr.stMipiAttr; +- pstViConfig[i].devAttr = &g_initParam[i].stViAttr.stDevAttr; +- pstViConfig[i].pipeAttr = &(g_initParam[i].stViAttr.stPipeAttr[0]); +- pstViConfig[i].chnAttr = &(g_initParam[i].stViAttr.stChnAttr[0][0]); +- pstViConfig[i].ispPubAttr = &g_initParam[i].stViAttr.stPubAttr; +- pstViConfig[i].sensorLib = g_initParam[i].stViAttr.sensorLib; +- pstViConfig[i].sensorObj = g_initParam[i].stViAttr.sensorObj; +- pstViConfig[i].len = SENSOR_DESC_MAX_LEN; +- } +-} +- +-static void SetChnDepth(InternalStreamInfo *internalInfo, ImageFormat format) +-{ +- if (internalInfo->isSetDepth == true) { +- return; +- } +- if (format == FORMAT_YVU420 || format == FORMAT_PRIVATE) { +- if (internalInfo->vpssChn < OT_VPSS_MAX_PHYS_CHN_NUM) { +- ot_vpss_chn_attr chnAttr = { 0 }; +- ss_mpi_vpss_get_chn_attr(0, internalInfo->vpssChn, &chnAttr); +- chnAttr.depth = 1; +- HAL_LOG_DOFUNC(ss_mpi_vpss_set_chn_attr(0, internalInfo->vpssChn, &chnAttr)); +- } else { +- ot_vpss_ext_chn_attr extChnAttr = { 0 }; +- ss_mpi_vpss_get_ext_chn_attr(0, internalInfo->vpssChn, &extChnAttr); +- extChnAttr.depth = 1; +- HAL_LOG_DOFUNC(ss_mpi_vpss_set_ext_chn_attr(0, internalInfo->vpssChn, &extChnAttr)); +- } +- } else if (format == FORMAT_RGB_BAYER_12BPP) { +- HAL_LOGI("set vi dump attr\n"); +- ot_vi_frame_dump_attr attr = {true, 1}; +- HAL_LOG_DOFUNC(ss_mpi_vi_set_pipe_frame_dump_attr(0, &attr)); +- } else { +- HAL_LOGI("not support format\n"); +- return; +- } +- internalInfo->isSetDepth = true; +-} +- +-static void UpdateVpssAttr(ot_vpss_chn vpssChn, const StreamAttr *stream, const ControlInfo *config, +- ot_vpss_chn_attr *vpssChnAttr) +-{ +- vpssChnAttr->flip_en = config->isFlip; +- vpssChnAttr->mirror_en = config->isMirror; +- if (vpssChn < OT_VPSS_MAX_PHYS_CHN_NUM) { +- if (config->cropInfo.crop_rect.width <= stream->crop.w && +- config->cropInfo.crop_rect.height <= stream->crop.h && +- stream->crop.w != 0 && stream->crop.h != 0) { +- vpssChnAttr->width = config->maxW * config->cropInfo.crop_rect.width / stream->crop.w; +- vpssChnAttr->height = config->maxH * config->cropInfo.crop_rect.height / stream->crop.h; +- vpssChnAttr->width = ALIGN_UP(vpssChnAttr->width, HI_ALIGN_UP_NUM); +- vpssChnAttr->height = ALIGN_UP(vpssChnAttr->height, HI_ALIGN_UP_NUM); +- } else if (config->rotation.rotation_fixed == OT_ROTATION_90) { +- vpssChnAttr->width = ALIGN_DOWN(stream->height, HI_ALIGN_DOWN_NUM); +- vpssChnAttr->height = ALIGN_DOWN(stream->width, HI_ALIGN_DOWN_NUM); +- } else { +- vpssChnAttr->width = ALIGN_DOWN(stream->width, HI_ALIGN_DOWN_NUM); +- vpssChnAttr->height = ALIGN_DOWN(stream->height, HI_ALIGN_DOWN_NUM); +- } +- vpssChnAttr->frame_rate.src_frame_rate = FPS_60; +- vpssChnAttr->frame_rate.dst_frame_rate = FPS_60; +- vpssChnAttr->pixel_format = OT_PIXEL_FORMAT_YUV_SEMIPLANAR_420; +- HI_PRINTF("chnn attr: chnn = %d w = %u h = %u\n", vpssChn, vpssChnAttr->width, vpssChnAttr->height); +- } +- vpssChnAttr->chn_mode = OT_VPSS_CHN_MODE_USER; +-} +- +-static td_s32 CreateStream(ot_vpss_chn vpssChn, ot_vpss_chn vpssPhyChn, +- const StreamAttr *stream, const ControlInfo *config) +-{ +- HI_PRINTF("CreateImage w h %d %d chan %d vpGroup %d\n", stream->width, stream->height, vpssChn, config->vpssGrp); +- const ot_vpss_grp vpssGrp = config->vpssGrp; +- ot_vpss_chn_attr vpssChnAttr = { 0 }; +- if (IsValidChnn(vpssChn) == false) { +- return TD_FAILURE; +- } +- td_u32 ret = (td_u32)ss_mpi_vpss_get_chn_attr(vpssGrp, vpssPhyChn, &vpssChnAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF(" get attr failed %#x!, vpssGrp=%d, vpssPhyChn=%d\n", ret, vpssGrp, vpssPhyChn); +- } +- +- UpdateVpssAttr(vpssChn, stream, config, &vpssChnAttr); +- HI_PRINTF("vpssPhyChn = %d rotation.enable = %d\n", vpssPhyChn, config->rotation.enable); +- ret |= (td_u32)ss_mpi_vpss_set_chn_attr(vpssGrp, vpssPhyChn, &vpssChnAttr); +- if (config->rotation.enable == TD_TRUE) { +- ret |= (td_u32)ss_mpi_vpss_set_chn_rotation(vpssGrp, vpssPhyChn, &(config->rotation)); +- } +- if (vpssChn < OT_VPSS_MAX_PHYS_CHN_NUM && config->cropInfo.enable == TD_TRUE) { +- ret |= (td_u32)ss_mpi_vpss_set_chn_crop(vpssGrp, vpssChn, &(config->cropInfo)); +- } +- ret |= (td_u32)ss_mpi_vpss_enable_chn(vpssGrp, vpssPhyChn); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_set_chn_attr failed with %#x\n", ret); +- return TD_FAILURE; +- } +- if (vpssChn >= OT_VPSS_MAX_PHYS_CHN_NUM) { +- HI_PRINTF("ext vpssChn = %d\n", vpssChn); +- ot_vpss_ext_chn_attr extChnAttr = { 0 }; +- GetVpssExtChnConfig(&extChnAttr, config, &vpssChnAttr, vpssPhyChn); +- ret = (td_u32)ss_mpi_vpss_set_ext_chn_attr(vpssGrp, vpssChn, &extChnAttr); +- ret |= (td_u32)ss_mpi_vpss_set_chn_crop(vpssGrp, vpssChn, &(config->cropInfo)); +- ret |= (td_u32)ss_mpi_vpss_enable_chn(vpssGrp, vpssChn); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vpss_set_ext_chn_attr failed with %#x\n", ret); +- return TD_FAILURE; +- } +- } +- return TD_SUCCESS; +-} +- +-static int32_t CheckSameChn(const CameraInfo *cameraInfo, const StreamAttr *stream, ot_vpss_chn *sameChn) +-{ +- *sameChn = -1; +- for (td_u8 i = 0; i < CAEMRA_MAX_STREAM_NUM; i++) { +- if (cameraInfo->internalStreamInfo[i].isUsed) { +- if (cameraInfo->streamAttr[i].width == stream->width && +- cameraInfo->streamAttr[i].height == stream->height && +- cameraInfo->streamAttr[i].fps == stream->fps && +- cameraInfo->streamAttr[i].crop.w == stream->crop.w && +- cameraInfo->streamAttr[i].crop.h == stream->crop.h && +- cameraInfo->streamAttr[i].crop.x == stream->crop.x && +- cameraInfo->streamAttr[i].crop.y == stream->crop.y && +- cameraInfo->streamAttr[i].invertMode == stream->invertMode) { +- *sameChn = cameraInfo->internalStreamInfo[i].vpssChn; +- return TD_SUCCESS; +- } +- } +- } +- return TD_FAILURE; +-} +- +-int32_t HalCameraInit(void) +-{ +- HAL_ENTER(); +- LOG_CHK_RETURN_ERR(g_isInit == true, TD_SUCCESS); +-#ifdef KERNEL_USER_MODE +- sdk_init(); +-#endif +- SDK_init(); +- InitModeInfo(); +- CameraInitParam(GetCurrentMode()); +- HAL_LOG_DOFUNC_RETURN(CameraCreateVbPool()); +- HAL_LOG_DOFUNC(LayerInitialize(&g_layerInterface)); +- if (g_layerInterface != NULL && g_layerInterface->InitDisplay != NULL) { +- HAL_LOG_DOFUNC(g_layerInterface->InitDisplay(1)); +- } +- g_isInit = true; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraDeinit(void) +-{ +- HAL_ENTER(); +- LOG_CHK_RETURN_ERR(g_isInit == false, TD_SUCCESS); +- if (g_layerInterface != NULL && g_layerInterface->DeinitDisplay != NULL) { +- HAL_LOG_DOFUNC(g_layerInterface->DeinitDisplay(0)); +- } +- HAL_LOG_DOFUNC(LayerUninitialize(g_layerInterface)); +-#ifdef KERNEL_USER_MODE +- sdk_exit(); +-#endif +- SDK_exit(); +- g_isInit = false; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraGetModeNum(uint8_t *num) +-{ +- HAL_ENTER(); +- LOG_CHK_RETURN_ERR(num == NULL, TD_FAILURE); +- *num = g_modeInfo.modeNum; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraSetMode(uint8_t index) +-{ +- HAL_ENTER(); +- LOG_CHK_RETURN_ERR(g_isInit == false || index >= g_modeInfo.modeNum, TD_FAILURE); +- for (int8_t i = 0; i < SUPPORT_MAX_CAMERA_NUM; i++) { +- if (g_cameraInfo[i].isOpen) { +- HAL_LOGE("camera is opened: %d\n", i); +- return TD_FAILURE; +- } +- } +- CameraDestoryVbPool(); +- g_isInit = false; +- CameraInitParam(index); +- g_modeInfo.index = index; +- HAL_LOG_DOFUNC_RETURN(CameraCreateVbPool()); +- LOG_CHK_RETURN_ERR(g_layerInterface == NULL, TD_FAILURE); +- g_isInit = true; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraSetDeviceDetectCb(const CameraDetectCb cb) +-{ +- HAL_ENTER(); +- LOG_CHK_RETURN_ERR(cb == NULL || g_cameraDetect != NULL, TD_FAILURE); +- g_cameraDetect = cb; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraGetDeviceNum(uint8_t *num) +-{ +- HAL_ENTER(); +- LOG_CHK_RETURN_ERR(num == NULL, TD_FAILURE); +- *num = g_cameraNum; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraGetDeviceList(char cameraList[][CAMERA_NAME_MAX_LEN], uint8_t listNum) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(cameraList); +- +- for (uint8_t i = 0; i < g_cameraNum && i < listNum; i++) { +- if (snprintf_s(cameraList[i], CAMERA_NAME_MAX_LEN, CAMERA_NAME_MAX_LEN - 1, "%u", i) < 0) { +- HAL_LOGE("snprintf_s failed\n"); +- return TD_FAILURE; +- } +- } +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraGetStreamCapNum(const char *camera, uint32_t *num) +-{ +- HI_CHECK_NULL_PTR(num); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum, TD_FAILURE); +- *num = CAEMRA_MAX_STREAM_NUM; +- return TD_SUCCESS; +-} +- +-int32_t HalCameraGetStreamCap(const char *camera, StreamCap *streamCap, uint32_t streamNum) +-{ +- HAL_ENTER(); +- LOG_CHK_RETURN_ERR(streamCap == NULL || camera == NULL, TD_FAILURE); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum, TD_FAILURE); +- uint32_t num; +- HAL_LOG_DOFUNC_RETURN(HalCameraGetStreamCapNum(camera, &num)); +- LOG_CHK_RETURN_ERR(streamNum < num, TD_FAILURE); +- if (streamCap->type == CAP_DESC_RANGE) { +- ReadRangCap(cameraId, streamCap, num); +- } else if (streamCap->type == CAP_DESC_ENUM) { +- ReadEnumCap(cameraId, streamCap, num); +- } +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-static uint32_t GetCameraCnt(void) +-{ +- if (g_cameraNum == SUPPORT_MAX_CAMERA_NUM && +- g_initParam[0].stViAttr.stMipiAttr.devno == g_initParam[1].stViAttr.stMipiAttr.devno) { +- return 1; +- } else { +- return g_cameraNum; +- } +-} +- +-static bool CheckViStart(uint32_t cameraId) +-{ +- for (uint32_t i = 0; i < g_cameraNum; i++) { +- if (i == cameraId) { +- continue; +- } +- if (g_cameraInfo[i].isOpen) { +- return true; +- } +- } +- +- return false; +-} +- +-static int32_t CameraStartVpss(const CAMERA_VI_CONFIG_S *viConfig, uint32_t cameraId, ot_vpss_grp vpssGrp) +-{ +- CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; +- InitParam *initParam = &g_initParam[cameraId]; +- uint32_t cameraCnt = GetCameraCnt(); +- bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM] = { 0 }; +- ot_vpss_grp_attr vpssGrpAttr; +- /* config vpss group */ +- CameraGetVpssGrpConfig(&vpssGrpAttr, initParam); +- /* config vpss chn */ +- ot_vpss_chn_attr vpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM]; +- CameraGetVpssChnConfig(vpssChnAttr, chnEnable, initParam); +- /* start vpss */ +- int32_t ret = CameraVideoProcStart(vpssGrp, chnEnable, &vpssGrpAttr, vpssChnAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("start vpss group failed. ret: 0x%x !\n", ret); +- return ret; +- } +- /* vi bind vpss */ +- ot_vi_chn viChn = 0; +- ot_vi_pipe viPipe; +- if (g_cameraNum == SUPPORT_MAX_CAMERA_NUM && cameraCnt == 1) { +- viPipe = viConfig[0].stPipeInfo.aPipe[0]; +- } else { +- viPipe = viConfig[cameraId].stPipeInfo.aPipe[0]; +- } +- ret = CameraViBindVproc(viPipe, viChn, vpssGrp); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("vi bind vpss failed. ret: 0x%x !\n", ret); +- CameraVideoProcStop(vpssGrp, chnEnable); +- return ret; +- } +- cameraInfo->vpssGrp = vpssGrp; +- return ret; +-} +- +-static void CameraStopVpss(const CAMERA_VI_CONFIG_S *viConfig, uint32_t cameraId) +-{ +- CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; +- InitParam *initParam = &g_initParam[cameraId]; +- uint32_t cameraCnt = GetCameraCnt(); +- ot_vi_pipe viPipe; +- if (g_cameraNum == SUPPORT_MAX_CAMERA_NUM && cameraCnt == 1) { +- viPipe = viConfig[0].stPipeInfo.aPipe[0]; +- } else { +- viPipe = viConfig[cameraId].stPipeInfo.aPipe[0]; +- } +- ot_vi_chn viChn = 0; +- ot_vpss_grp vpssGrp = cameraInfo->vpssGrp; +- CameraViUnBindVproc(viPipe, viChn, vpssGrp); +- bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM] = { 0 }; +- ot_vpss_chn_attr astVpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM]; +- CameraGetVpssChnConfig(astVpssChnAttr, chnEnable, initParam); +- DisableVpssExtChn(vpssGrp); +- CameraVideoProcStop(vpssGrp, chnEnable); +- cameraInfo->vpssGrp = -1; +-} +- +-int32_t HalCameraDeviceOpen(const char *camera) +-{ +- HAL_ENTER(); +- HI_PRINTF(" open camera = %s\n", camera); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum, TD_FAILURE); +- /* get vi config */ +- int32_t ret; +- CAMERA_VI_CONFIG_S viConfig[SUPPORT_MAX_CAMERA_NUM] = { 0 }; +- CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; +- InitParam *initParam = &g_initParam[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->isOpen == true, TD_SUCCESS); +- cameraInfo->type = initParam->stViAttr.sensorType; +- +- uint32_t cameraCnt = GetCameraCnt(); +- CameraGetViConfig(viConfig, cameraCnt); +- HI_PRINTF("lib0:%s, obj0:%s, len0:%u\n", initParam->stViAttr.sensorLib, +- initParam->stViAttr.sensorObj, viConfig[0].len); +- ot_vpss_grp vpssGrp = 0; +- if (CheckViStart(cameraId)) { +- HI_PRINTF("Vi is Started. Next, bind the vpssGrp.\n"); +- vpssGrp = 1; +- } else { +- /* start vi */ +- ret = CameraStartVi(viConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("start vi failed.ret:0x%x !\n", ret); +- goto EXIT; +- } +- } +- +- if (cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { +- ret = CameraStartVpss(viConfig, cameraId, vpssGrp); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("CameraStartVpss failed. ret:0x%x !\n", ret); +- goto EXIT1; +- } +- } +- +- cameraInfo->isOpen = true; +- HAL_EXIT(); +- return TD_SUCCESS; +- +-EXIT1: +- if (!CheckViStart(cameraId)) { +- CameraStopVi(viConfig, cameraCnt); +- } +-EXIT: +- return ret; +-} +- +-int32_t HalCameraDeviceClose(const char *camera) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- HI_PRINTF("cameraId=%u\n", cameraId); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum, TD_FAILURE); +- CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->isOpen == false, TD_SUCCESS); +- CAMERA_VI_CONFIG_S viConfig[SUPPORT_MAX_CAMERA_NUM] = {}; +- uint32_t cameraCnt = GetCameraCnt(); +- CameraGetViConfig(viConfig, cameraCnt); +- +- if (cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { +- CameraStopVpss(viConfig, cameraId); +- } +- if (!CheckViStart(cameraId)) { +- CameraStopVi(&viConfig, cameraCnt); +- } +- cameraInfo->isOpen = false; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraStreamCreate(const char *camera, const StreamAttr *stream, uint32_t *streamId) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(stream == NULL || streamId == NULL || cameraId >= g_cameraNum, TD_FAILURE); +- ControlInfo config = { 0 }; +- config.maxW = g_initParam[cameraId].stViAttr.stChnAttr[0][0].size.width; +- config.maxH = g_initParam[cameraId].stViAttr.stChnAttr[0][0].size.height; +- if (config.maxW > MAX_FRAME_WIDTH || config.maxH > MAX_FRAME_WIDTH) { +- HI_PRINTF("maxW maxH param invalid\n"); +- return TD_FAILURE; +- } +- HAL_LOG_DOFUNC_RETURN(ParamCheck(stream, &config)); +- +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- config.vpssGrp = cameraInfo->vpssGrp; +- uint32_t streamIndex = 0; +- ot_vpss_chn vpssChn = -1; +- ot_vpss_chn vpssPhyChn = -1; +- ot_vpss_chn sameChn = -1; +- HAL_LOG_DOFUNC_RETURN(GetFreeStreamIndex(cameraInfo, &streamIndex)); +- +- if (CheckSameChn(cameraInfo, stream, &sameChn) == TD_SUCCESS) { +- vpssChn = sameChn; +- } else if (cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { +- GetVpss(stream, cameraInfo, &vpssChn, &vpssPhyChn); +- if (vpssChn == -1 && vpssPhyChn == -1) { +- HI_PRINTF(" GetVpss failed, vpssChn=%d\n", vpssChn); +- return TD_FAILURE; +- } +- ConvetToControlInfo(vpssChn, stream, &config); +- td_s32 ret = CreateStream(vpssChn, vpssPhyChn, stream, &config); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("CreateStream failed ret:%d\n", ret); +- return TD_FAILURE; +- } +- } +- AddStream(cameraInfo, streamIndex, vpssChn, stream); +- *streamId = streamIndex; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraGetDeviceId(const char *camera, uint32_t streamId, uint32_t *deviceId) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || deviceId == NULL, TD_FAILURE); +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); +- *deviceId = GetDeviceId((uint32_t)cameraInfo->internalStreamInfo[streamId].vpssChn); +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraStreamDestroy(const char *camera, uint32_t streamId) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM, TD_FAILURE); +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); +- DeleteStream(cameraInfo, streamId); +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraStreamOn(const char *camera, uint32_t streamId) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM, TD_FAILURE); +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); +- if (cameraInfo->streamAttr[streamId].type == STREAM_PREVIEW && cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { +- HAL_LOG_DOFUNC_RETURN(EnablePreview(cameraInfo->internalStreamInfo[streamId].vpssChn, +- cameraId, +- &cameraInfo->internalStreamInfo[streamId].pos, +- &cameraInfo->streamAttr[streamId])); +- } +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraStreamOff(const char *camera, uint32_t streamId) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM, TD_FAILURE); +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); +- if (cameraInfo->streamAttr[streamId].type == STREAM_PREVIEW && cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { +- DisablePreview(cameraInfo->internalStreamInfo[streamId].vpssChn, cameraId); +- } +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraDequeueBuf(const char *camera, uint32_t streamId, HalBuffer *buffer) +-{ +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || buffer == NULL, TD_FAILURE); +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); +- ot_vpss_grp vpssGrp = 0; +- if (buffer->format == FORMAT_PRIVATE) { +- SetChnDepth(&(cameraInfo->internalStreamInfo[streamId]), buffer->format); +- HAL_LOG_DOFUNC_RETURN(ss_mpi_vpss_get_chn_frame(vpssGrp, cameraInfo->internalStreamInfo[streamId].vpssChn, +- &cameraInfo->internalStreamInfo[streamId].videoFrame, FRAME_TIME_OUT)); +- } else { +- buffer->format = cameraInfo->streamAttr[streamId].format; +- SetChnDepth(&(cameraInfo->internalStreamInfo[streamId]), buffer->format); +- if (buffer->format == FORMAT_YVU420) { +- HAL_LOG_DOFUNC_RETURN(ss_mpi_vpss_get_chn_frame(vpssGrp, cameraInfo->internalStreamInfo[streamId].vpssChn, +- &cameraInfo->internalStreamInfo[streamId].videoFrame, FRAME_TIME_OUT)); +- } else if (buffer->format == FORMAT_RGB_BAYER_12BPP) { +- HAL_LOG_DOFUNC_RETURN(ss_mpi_vi_get_pipe_frame(0, &cameraInfo->internalStreamInfo[streamId].videoFrame, +- FRAME_TIME_OUT)); +- } else { +- HAL_LOGI("not support format\n"); +- return TD_FAILURE; +- } +- } +- CovertToBuffer(&cameraInfo->internalStreamInfo[streamId].videoFrame, buffer); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraQueueBuf(const char *camera, uint32_t streamId, const HalBuffer *buffer) +-{ +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || buffer == NULL, TD_FAILURE); +- ot_vpss_grp vpssGrp = 0; +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); +- if (buffer->format == FORMAT_PRIVATE) { +- HAL_LOG_DOFUNC_RETURN(ss_mpi_vpss_release_chn_frame(vpssGrp, cameraInfo->internalStreamInfo[streamId].vpssChn, +- &cameraInfo->internalStreamInfo[streamId].videoFrame)); +- return TD_SUCCESS; +- } +- HAL_LOG_DOFUNC(ss_mpi_sys_munmap(buffer->virAddr, buffer->size)); +- if (buffer->format == FORMAT_YVU420) { +- HAL_LOG_DOFUNC_RETURN(ss_mpi_vpss_release_chn_frame(vpssGrp, cameraInfo->internalStreamInfo[streamId].vpssChn, +- &cameraInfo->internalStreamInfo[streamId].videoFrame)); +- } else if (buffer->format == FORMAT_RGB_BAYER_12BPP) { +- HAL_LOG_DOFUNC_RETURN(ss_mpi_vi_release_pipe_frame(0, &cameraInfo->internalStreamInfo[streamId].videoFrame)); +- } else { +- HAL_LOGI("not support format\n"); +- return TD_FAILURE; +- } +- return TD_SUCCESS; +-} +- +-int32_t HalCameraSetBufferCallback(const char *camera, const BufferAvailable callback) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || callback == NULL, TD_FAILURE); +- CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->bufferCallBack != NULL, TD_FAILURE); +- cameraInfo->bufferCallBack = callback; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraStreamSetInfo(const char *camera, uint32_t streamId, const StreamInfo *info) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || info == NULL, TD_FAILURE); +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); +- if (info->type == STREAM_INFO_POS) { +- cameraInfo->internalStreamInfo[streamId].pos.x = info->u.pos.x; +- cameraInfo->internalStreamInfo[streamId].pos.y = info->u.pos.y; +- } else { +- HAL_LOGI("not support now\n"); +- } +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraStreamGetInfo(const char *camera, uint32_t streamId, StreamInfo *info) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || info == NULL, TD_FAILURE); +- CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); +- if (info->type == STREAM_INFO_POS) { +- info->u.pos.x = cameraInfo->internalStreamInfo[streamId].pos.x; +- info->u.pos.y = cameraInfo->internalStreamInfo[streamId].pos.y; +- } else { +- HAL_LOGI("not support now\n"); +- } +- HAL_LOGI("not support now\n"); +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraDeviceSetInfo(const char *camera, const DeviceInfo *info) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || info == NULL, TD_FAILURE); +- HAL_LOGI("not support now\n"); +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraDeviceGetInfo(const char *camera, DeviceInfo *info) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || info == NULL, TD_FAILURE); +- HAL_LOGI("not support now\n"); +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraGetAbility(const char *camera, AbilityInfo *ability) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || ability == NULL, TD_FAILURE); +- HAL_LOG_DOFUNC(memset_s(ability, sizeof(AbilityInfo), 0, sizeof(AbilityInfo))); +- if (cameraId == 0) { +- HAL_LOG_DOFUNC(strncpy_s(ability->cameraDesc, DESC_MAX_LEN - 1, CAMERA_RGB, sizeof(CAMERA_RGB))); +- ability->type = CAM_TYPE_WIDE_ANGLE; +- } else { +- HAL_LOG_DOFUNC(strncpy_s(ability->cameraDesc, DESC_MAX_LEN - 1, CAMERA_TOF, sizeof(CAMERA_TOF))); +- ability->type = CAM_TYPE_TRUE_DEAPTH; +- } +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraSetResultCb(const char *camera, CameraResultCb cb) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- char *endPtr = NULL; +- uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); +- LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); +- LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || cb == NULL, TD_FAILURE); +- CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; +- LOG_CHK_RETURN_ERR(cameraInfo->resultCb != NULL, TD_FAILURE); +- cameraInfo->resultCb = cb; +- HAL_EXIT(); +- return TD_SUCCESS; +-} +- +-int32_t HalCameraUpdateSaturationMode(const char *value, uint32_t len) +-{ +- int32_t saturationMode; +- int32_t saturationValue; +- int32_t ret = sscanf_s(value, "%d#%d", &saturationMode, &saturationValue); +- if (ret == -1 || ret == 0 || ret == 1) { +- HAL_LOGE("saturation mode sscanf_s failed!"); +- return ret; +- } +- ot_vi_pipe viPipe = 0; +- ot_isp_saturation_attr satAttr; +- ss_mpi_isp_get_saturation_attr(viPipe, &satAttr); +- if (saturationMode == CAMERA_ATTR_OP_MODE_MANUAL) { +- satAttr.op_type = OT_OP_MODE_MANUAL; +- satAttr.manual_attr.saturation = saturationValue; +- ret = ss_mpi_isp_set_saturation_attr(viPipe, &satAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set exposure attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateSaturationMode: set saturation mode MANUAL success!"); +- } else if (saturationMode == CAMERA_ATTR_OP_MODE_AUTO) { +- satAttr.op_type = OT_OP_MODE_AUTO; +- ret = ss_mpi_isp_set_saturation_attr(viPipe, &satAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set auto exposure attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateSaturationMode: set saturation mode AUTO success!"); +- } else { +- HAL_LOGE("not support saturation mode = %d", saturationMode); +- ret = TD_FAILURE; +- } +- return ret; +-} +- +-int32_t HalCameraUpdateSharpenMode(const char *value, uint32_t len) +-{ +- int32_t sharpenMode; +- int32_t sharpenValue; +- int32_t ret = sscanf_s(value, "%d#%d", &sharpenMode, &sharpenValue); +- if (ret == -1 || ret == 0 || ret == 1) { +- HAL_LOGE("sharpen mode sscanf_s failed!"); +- return ret; +- } +- ot_vi_pipe viPipe = 0; +- ot_isp_sharpen_attr shpAttr; +- ss_mpi_isp_get_sharpen_attr(viPipe, &shpAttr); +- if (sharpenMode == CAMERA_ATTR_OP_MODE_MANUAL) { +- shpAttr.op_type = OT_OP_MODE_MANUAL; +- shpAttr.manual_attr.max_sharp_gain = sharpenValue; +- ret = ss_mpi_isp_set_sharpen_attr(viPipe, &shpAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set sharpen attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateSharpenMode: set sharpen mode MANUAL success!\n"); +- } else if (sharpenMode == CAMERA_ATTR_OP_MODE_AUTO) { +- shpAttr.op_type = OT_OP_MODE_AUTO; +- ret = ss_mpi_isp_set_sharpen_attr(viPipe, &shpAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set auto sharpen attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateSharpenMode: set sharpen mode AUTO success!"); +- } else { +- HAL_LOGE("not support sharpen mode = %d", sharpenMode); +- ret = TD_FAILURE; +- } +- return ret; +-} +- +-int32_t HalCameraUpdateDrcMode(const char *value, uint32_t len) +-{ +- int32_t drcMode; +- int32_t drcValue; +- int32_t ret = sscanf_s(value, "%d#%d", &drcMode, &drcValue); +- if (ret == -1 || ret == 0 || ret == 1) { +- HAL_LOGE("drc mode sscanf_s failed!"); +- return ret; +- } +- ot_vi_pipe viPipe = 0; +- ot_isp_drc_attr drcAttr; +- ss_mpi_isp_get_drc_attr(viPipe, &drcAttr); +- if (drcMode == CAMERA_ATTR_OP_MODE_MANUAL) { +- drcAttr.enable = true; +- drcAttr.op_type = OT_OP_MODE_MANUAL; +- drcAttr.manual_attr.strength = drcValue; +- ret = ss_mpi_isp_set_drc_attr(viPipe, &drcAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set drc attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateDrcMode: set drc mode MANUAL success!"); +- } else if (drcMode == CAMERA_ATTR_OP_MODE_AUTO) { +- drcAttr.enable = false; +- drcAttr.op_type = OT_OP_MODE_AUTO; +- ret = ss_mpi_isp_set_drc_attr(viPipe, &drcAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set auto drc attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateDrcMode: set drc mode AUTO success!"); +- } else { +- HAL_LOGE("not support drc mode = %d", drcMode); +- ret = TD_FAILURE; +- } +- return ret; +-} +- +-int32_t HalCameraUpdateWbMode(const char *value, uint32_t len) +-{ +- int32_t wbMode; +- int32_t wbValue; +- int32_t ret = sscanf_s(value, "%d#%d", &wbMode, &wbValue); +- if (ret == -1 || ret == 0 || ret == 1) { +- HAL_LOGE("wb mode sscanf_s failed!"); +- return ret; +- } +- ot_vi_pipe viPipe = 0; +- ot_isp_wb_attr wbAttr; +- ss_mpi_isp_get_wb_attr(viPipe, &wbAttr); +- if (wbMode == CAMERA_ATTR_OP_MODE_MANUAL) { +- wbAttr.op_type = OT_OP_MODE_MANUAL; +- wbAttr.manual_attr.r_gain = wbValue; +- ret = ss_mpi_isp_set_wb_attr(viPipe, &wbAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set wb attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateWbMode: set wb mode MANUAL success!"); +- } else if (wbMode == CAMERA_ATTR_OP_MODE_AUTO) { +- wbAttr.op_type = OT_OP_MODE_AUTO; +- ret = ss_mpi_isp_set_wb_attr(viPipe, &wbAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set auto sharpen attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateWbMode: set wb mode AUTO success!"); +- } else { +- HAL_LOGE("not support wb mode = %d", wbMode); +- ret = TD_FAILURE; +- } +- return ret; +-} +- +-int32_t HalCameraUpdateExposureMode(const char *value, uint32_t len) +-{ +- int32_t exposureMode; +- int32_t exposureValue; +- int32_t ret = sscanf_s(value, "%d#%d", &exposureMode, &exposureValue); +- if (ret == -1 || ret == 0 || ret == 1) { +- HAL_LOGE("exposure mode sscanf_s failed!"); +- return ret; +- } +- ot_vi_pipe viPipe = 0; +- ot_isp_exposure_attr expAttr; +- ss_mpi_isp_get_exposure_attr(viPipe, &expAttr); +- if (exposureMode == CAMERA_ATTR_OP_MODE_MANUAL) { +- expAttr.bypass = TD_FALSE; +- expAttr.op_type = OT_OP_MODE_MANUAL; +- expAttr.manual_attr.a_gain_op_type = OT_OP_MODE_MANUAL; +- expAttr.manual_attr.d_gain_op_type = OT_OP_MODE_MANUAL; +- expAttr.manual_attr.ispd_gain_op_type = OT_OP_MODE_MANUAL; +- expAttr.manual_attr.exp_time_op_type = OT_OP_MODE_MANUAL; +- expAttr.manual_attr.isp_d_gain = exposureValue; +- ret = ss_mpi_isp_set_exposure_attr(viPipe, &expAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set exposure attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateExposureMode: set exposure mode MANUAL success!"); +- } else if (exposureMode == CAMERA_ATTR_OP_MODE_AUTO) { +- expAttr.bypass = TD_FALSE; +- expAttr.op_type = OT_OP_MODE_AUTO; +- ret = ss_mpi_isp_set_exposure_attr(viPipe, &expAttr); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("set auto exposure attr failed ret = %d", ret); +- return TD_FAILURE; +- } +- HAL_LOGI("HalCameraUpdateExposureMode: set exposure mode AUTO success!"); +- } else { +- HAL_LOGE("not support exposure mode = %d", exposureMode); +- ret = TD_FAILURE; +- } +- return ret; +-} +- +-int32_t HalCameraUpdateSettings(const char *camera, const char *value, uint32_t len) +-{ +- HAL_ENTER(); +- HI_CHECK_NULL_PTR(camera); +- HI_CHECK_NULL_PTR(value); +- char keyFlag[MAX_KEY_STR_SIZE] = { 0 }; +- char valueFlag[MAX_KEY_VALUE_SIZE] = { 0 }; +- int32_t ret = sscanf_s(value, "%s = %s", keyFlag, MAX_KEY_STR_SIZE, +- valueFlag, MAX_KEY_VALUE_SIZE); +- if (ret == -1) { +- HAL_LOGE("sscanf_s failed, ret = % d", ret); +- return ret; +- } +- if (strcmp(keyFlag, KEY_EXPOSURE_MODE) == 0) { +- ret = HalCameraUpdateExposureMode(valueFlag, MAX_KEY_VALUE_SIZE); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("Update exposure mode failed!"); +- return ret; +- } +- } else if (strcmp(keyFlag, KEY_SATURATION_MODE) == 0) { +- ret = HalCameraUpdateSaturationMode(valueFlag, MAX_KEY_VALUE_SIZE); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("Update saturation mode failed!"); +- return ret; +- } +- } else if (strcmp(keyFlag, KEY_SHARPEN_MODE) == 0) { +- ret = HalCameraUpdateSharpenMode(valueFlag, MAX_KEY_VALUE_SIZE); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("Update sharpen mode failed!"); +- return ret; +- } +- } else if (strcmp(keyFlag, KEY_DRC_MODE) == 0) { +- ret = HalCameraUpdateDrcMode(valueFlag, MAX_KEY_VALUE_SIZE); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("Update drc mode failed!"); +- return ret; +- } +- } else if (strcmp(keyFlag, KEY_WB_MODE) == 0) { +- ret = HalCameraUpdateWbMode(valueFlag, MAX_KEY_VALUE_SIZE); +- if (ret != TD_SUCCESS) { +- HAL_LOGE("Update wb mode failed!"); +- return ret; +- } +- } else { +- HAL_LOGE("Unsupported Parameter Settings!"); +- } +- return TD_SUCCESS; +-} +- +-static HalCameraManager g_localHalCameraManager = { +- .HalCameraInit = HalCameraInit, +- .HalCameraDeinit = HalCameraDeinit, +- .HalCameraGetModeNum = HalCameraGetModeNum, +- .HalCameraSetMode = HalCameraSetMode, +- .HalCameraSetDeviceDetectCb = HalCameraSetDeviceDetectCb, +- .HalCameraGetDeviceNum = HalCameraGetDeviceNum, +- .HalCameraGetDeviceList = HalCameraGetDeviceList, +- .HalCameraGetStreamCapNum = HalCameraGetStreamCapNum, +- .HalCameraGetStreamCap = HalCameraGetStreamCap, +- .HalCameraDeviceOpen = HalCameraDeviceOpen, +- .HalCameraDeviceClose = HalCameraDeviceClose, +- .HalCameraStreamCreate = HalCameraStreamCreate, +- .HalCameraStreamDestroy = HalCameraStreamDestroy, +- .HalCameraGetDeviceId = HalCameraGetDeviceId, +- .HalCameraStreamOn = HalCameraStreamOn, +- .HalCameraStreamOff = HalCameraStreamOff, +- .HalCameraDequeueBuf = HalCameraDequeueBuf, +- .HalCameraQueueBuf = HalCameraQueueBuf, +- .HalCameraSetBufferCallback = HalCameraSetBufferCallback, +- .HalCameraStreamSetInfo = HalCameraStreamSetInfo, +- .HalCameraStreamGetInfo = HalCameraStreamGetInfo, +- .HalCameraDeviceSetInfo = HalCameraDeviceSetInfo, +- .HalCameraDeviceGetInfo = HalCameraDeviceGetInfo, +- .HalCameraGetAbility = HalCameraGetAbility, +- .HalCameraSetResultCb = HalCameraSetResultCb, +- .HalCameraUpdateSettings = HalCameraUpdateSettings, +-}; +- +-HalCameraManager *GetHalCameraFuncs(void) +-{ +- return &g_localHalCameraManager; +-} ++/* ++ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. ++ * ++ * 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. ++ */ ++ ++#include "hal_camera.h" ++#include ++#include "hi_camera_vi.h" ++ ++#include "display_layer.h" ++#include "media_hal_common.h" ++#include "ot_common_isp.h" ++#include "ss_mpi_isp.h" ++#include "ot_common_awb.h" ++#include "ss_mpi_awb.h" ++ ++#ifdef KERNEL_USER_MODE ++#include "sdk.h" ++#endif ++ ++ ++#define STREAM_ABILITY_NUM 3 ++#define JPEG_VPSS_CHN 0 ++#define PREEV_VPSS_CHN 1 ++#define VIDEO_VPSS_CHN 2 ++#define CALLBACK_VPSS_CHN 2 ++#define CALLBACK_EXT_CHN 6 ++#define VIDEO_EXT_MIN_CHN (OT_VPSS_MAX_PHYS_CHN_NUM + 1) ++#define VIDEO_EXT_MAX_CHN (OT_VPSS_MAX_PHYS_CHN_NUM + 2) ++#define HI_ALIGN_DOWN_NUM 2 ++#define HI_ALIGN_UP_NUM 2 ++#define MAX_FPS 60 ++#define MIN_FPS 1 ++#define FRAME_TIME_OUT 1000 ++#define SUPPORT_MAX_CAMERA_NUM 2 ++#define CAEMRA_MAX_STREAM_NUM 10 ++ ++#define CAMERA_TOF "CAMERA_TOF" ++#define CAMERA_RGB "CAMERA_RGB" ++#define KEY_EXPOSURE_MODE "exposuremode" ++#define KEY_SATURATION_MODE "saturationmode" ++#define KEY_SHARPEN_MODE "sharpenmode" ++#define KEY_DRC_MODE "drcmode" ++#define KEY_WB_MODE "wbmode" ++ ++#define CAMERA_INIT_PARAM_PATH "/storage/data/cameradev.ini" ++#define MODE_NAME_MAX_LEN 64 ++#define MODE_NAME_MAX_NUM 16 ++#define CAMERA_INIT_DOC_PATH "/storage/data/" ++#define ENLARGE_VALUE 2 ++#define DISPLAY_DEVID 0 ++ ++/* default layer width */ ++#define DEFAULT_WIDTH_FOR_HDMI 1920 ++#define DEFAULT_WIDTH_FOR_LCD 480 ++/* default layer height */ ++#define DEFAULT_HEIGHT_FOR_HDMI 1080 ++#define DEFAULT_HEIGHT_FOR_LCD 960 ++#define DEFAULT_DISPLAY_FPS 60 ++#define MIN_WIDTH 16 ++#define MIN_HEIGHT 16 ++#define RESOLUTION_2592X1944_W 2592 ++#define RESOLUTION_2592X1944_H 1944 ++#define RESOLUTION_1080P_W 1920 ++#define RESOLUTION_1080P_H 1080 ++#define RESOLUTION_720P_W 1280 ++#define RESOLUTION_720P_H 720 ++#define RESOLUTION_D1_NTSC_W 720 ++#define RESOLUTION_D1_NTSC_H 480 ++#define RESOLUTION_360P_W 640 ++#define RESOLUTION_360P_H 360 ++#define FPS_60 60 ++#define MAX_KEY_STR_SIZE 30 ++#define MAX_KEY_VALUE_SIZE 512 ++#define BLACK_DELAY_FRAME 10 ++#define ANTIFLIKER_FREQUENCY 50 ++#define EXP_TIME_RANGE_MAX 4000 ++#define EXP_TIME_RANGE_MIN 10 ++#define NUMBER_BASE_10 10 ++ ++/* Maximum number of display devices supported */ ++#define DEV_ID_NUM 1 ++/* Byte align number */ ++#define BYTE_ALIGN_NUM 2 ++/* Video layer buffer len */ ++#define VIDEO_LAYER_BUFF_LEN 3 ++/* Vo device number */ ++#define VO_LAYER_ID 0 ++ ++/* Rotate enable */ ++#define VO_ROTATE_ENABLE 1 ++ ++LayerFuncs *g_layerInterface = NULL; ++ ++typedef struct { ++ bool isMirror; ++ bool isFlip; ++ ot_rotation_attr rotation; ++ uint32_t fps; ++ uint32_t width; ++ uint32_t height; ++ ot_vpss_crop_info cropInfo; ++ uint32_t maxW; ++ uint32_t maxH; ++ int32_t vpssGrp; ++} ControlInfo; ++ ++typedef enum { ++ HAL_CENTER_MIRROR = 0, /**< Central mirroring */ ++ HAL_HORIZONTAL_MIRROR = 1, /**< Horizontal mirroring */ ++ HAL_VETICALLY_MIRROR = 2, /**< Vertical mirroring */ ++ HAL_ROTATION_90 = 3, /**< 90-degree rotation */ ++ HAL_ROTATION_180 = 4, /**< 180-degree rotation */ ++ HAL_ROTATION_BUTT, ++} CameraHalInvertMode; ++ ++typedef struct { ++ int32_t vpssChn; ++ PosInfo pos; ++ bool isUsed; ++ bool isSetDepth; ++ ot_video_frame_info videoFrame; ++} InternalStreamInfo; ++ ++typedef struct { ++ BufferAvailable bufferCallBack; ++ CameraResultCb resultCb; ++ StreamAttr streamAttr[CAEMRA_MAX_STREAM_NUM]; ++ InternalStreamInfo internalStreamInfo[CAEMRA_MAX_STREAM_NUM]; ++ bool isOpen; ++ CameraType type; ++ int32_t vpssGrp; ++ uint32_t layerId; ++} CameraInfo; ++ ++typedef struct { ++ uint8_t modeNum; ++ uint8_t index; ++ char modeNameList[MODE_NAME_MAX_NUM][MODE_NAME_MAX_LEN]; ++} ModeInfo; ++static ModeInfo g_modeInfo = { 0 }; ++ ++static CameraInfo g_cameraInfo[SUPPORT_MAX_CAMERA_NUM] = { 0 }; ++static InitParam g_initParam[SUPPORT_MAX_CAMERA_NUM] = { 0 }; ++static CameraDetectCb g_cameraDetect = NULL; ++static uint8_t g_cameraNum = 2; ++static bool g_isInit = false; ++ ++static td_void AUDIO_init(void) ++{ ++ td_s32 ret; ++ ++ ret = ot_aiao_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("aiao init error.\n"); ++ } ++ ++ ret = ot_ai_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("ai init error.\n"); ++ } ++ ++ ret = ot_ao_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("ao init error.\n"); ++ } ++ ++ ret = ot_aenc_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("aenc init error.\n"); ++ } ++ ++ ret = ot_adec_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("adec init error.\n"); ++ } ++ ++ ret = ot_acodec_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("acodec init error.\n"); ++ } ++} ++ ++static td_s32 basic_mod_init() ++{ ++ td_s32 ret; ++ ret = osal_init(); ++ if (ret != 0) { ++ HAL_LOGE("osal_init init error.\n"); ++ } ++ ++ ret = ot_base_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("base init error.\n"); ++ } ++ ++ ret = ot_sys_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("sys init error.\n"); ++ } + -+#ifdef __cplusplus -+#if __cplusplus -+extern "C" { -+#endif -+#endif /* __cplusplus */ -+#define MODULE_NAME "AudioPrimarySubPortIn" ++ ret = ot_chnl_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("chnl init error.\n"); ++ } ++ return ret; ++} + -+#define MAX_INPUT_PORT_CNT OT_AI_DEV_MAX_NUM -+#define MAX_INPUT_PORT_TRACK_CNT OT_AI_MAX_CHN_NUM ++static td_s32 common_mod_init() ++{ ++ td_s32 ret; ++ ret = ot_rgn_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("rgn init error.\n"); ++ } ++ struct { ++ td_u32 u32_max_gdc_job; ++ td_u32 u32_max_gdc_task; ++ td_u32 u32_max_gdc_node; ++ td_u32 au32_gdc_en[1]; ++ } gdcModuleParam; ++ gdcModuleParam.u32_max_gdc_job = 32; /* 32 -- max job num */ ++ gdcModuleParam.u32_max_gdc_task = 64; /* 64 -- max task num */ ++ gdcModuleParam.u32_max_gdc_node = 64; /* 64 -- max node num */ ++ gdcModuleParam.au32_gdc_en[0] = 1; ++ ret = ot_gdc_mod_init(&gdcModuleParam); ++ if (ret != 0) { ++ HAL_LOGE("gdc init error.\n"); ++ } + -+#define MAX_KEY_STR_LEN 10 ++ struct { ++ td_u32 max_vgs_job; ++ td_u32 max_vgs_task; ++ td_u32 max_vgs_node; ++ } vgsModuleParam; ++ vgsModuleParam.max_vgs_job = 64; /* 64 -- max job num */ ++ vgsModuleParam.max_vgs_task = 200; /* 200 -- max task num */ ++ vgsModuleParam.max_vgs_node = 200; /* 200 -- max node num */ ++ ret = ot_vgs_mod_init(&vgsModuleParam); ++ if (ret != 0) { ++ HAL_LOGE("vgs init error.\n"); ++ } + -+#define PORT_ID(module, device, channel) \ -+ ((unsigned int)(((module) << 16) | ((device) << 8) | (channel))) ++ ret = ot_dis_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("dis init error.\n"); ++ } + -+/* count of audio frame in Buffer */ -+#define AUDIO_FRAME_NUM_IN_BUF 30 ++ ret = ot_vpp_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("vpp init error.\n"); ++ } ++ return ret; ++} + -+/* sample per frame for all encoder(aacplus:2048) */ -+#define AUDIO_AUDIO_POINT_NUM 1024 ++static td_s32 business_mod_init() ++{ ++ td_s32 ret; ++ ret = ot_vi_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("vi init error.\n"); ++ } + -+#define AUDIO_FRAME_CACHED_DEPTH 5 ++ ret = ot_isp_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("isp init error.\n"); ++ } + -+#define AUDIO_INPUT_VOL 30 ++ ret = ot_vpss_mod_init(NULL); ++ if (ret != 0) { ++ HAL_LOGE("vpss init error.\n"); ++ } + -+#define AUDIO_HAL_FRAME_COUNT 1024 ++ ret = ot_vo_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("vo init error.\n"); ++ } + -+#define AUDIO_AO_INNER_DEV_ID 0 /** ao inner acodec dev id */ ++ ret = ot_vedu_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("vedu init error.\n"); ++ } + -+#define AUDIO_VQE_ANR_NOISE_DB_THR 45 -+#define AUDIO_VQE_ANR_NR_INTENSITY 15 -+static const float VOLUME_PERCENT_MIN_IN = 0.0f; -+static const float VOLUME_PERCENT_MAX_IN = 100.0f; ++ ret = ot_rc_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("rc init error.\n"); ++ } + -+const unsigned long long TIME_CONVERSION_US_S = 1000000ULL; /* us to s */ -+const unsigned long long TIME_CONVERSION_NS_US = 1000ULL; /* ns to us */ ++ td_u32 max_chn = 64; ++ ret = ot_venc_mod_init(max_chn); ++ if (ret != 0) { ++ HAL_LOGE("venc init error.\n"); ++ } + -+static enum AudioFormat g_audioInFormats[] = { AUDIO_FORMAT_TYPE_PCM_16_BIT }; ++ ret = ot_h264e_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("H264e init error.\n"); ++ } + -+typedef struct { -+ /* track impl */ -+ AudioPortTrack common; -+ bool mute; -+ float volume; -+ float gain; -+ uint32_t currentChannelId; -+ uint64_t frames; -+ struct PortPluginAttr inputAttr; -+ struct AudioTimeStamp aiTimeStamp; -+ /* MPP LIB */ -+ ot_audio_dev aiDeviceId; -+ snd_pcm_t *ai_pcm_handle; -+ snd_mixer_t *ai_mixer_handle; -+ snd_mixer_elem_t *ai_elem_vol; -+ long ai_min_vol, ai_max_vol; -+ ot_aio_attr aiAttr; -+ ot_ai_chn aiChn; -+ ot_mpp_chn stSrcChn; -+ ot_mpp_chn stDestChn; -+ /* talk vqe ao info */ -+ ot_audio_dev refAoDevId; -+ ot_ai_chn refAoChnId; -+ enum VqeScene vqeScene; -+} SubPortTrackInContext; ++ ret = ot_h265e_mod_init(NULL); ++ if (ret != 0) { ++ HAL_LOGE("H265e init error.\n"); ++ } + -+typedef struct { -+ bool opened; -+ ot_audio_dev aiDeviceId; -+ snd_pcm_t *ai_pcm_handle; -+ snd_mixer_t *ai_mixer_handle; -+ snd_mixer_elem_t *ai_elem_vol; -+ long ai_min_vol, ai_max_vol; -+ SubPortTrackInContext *portTrackInCtx[MAX_INPUT_PORT_TRACK_CNT]; -+ pthread_mutex_t mutex; -+} SubPortInContext; ++ ret = ot_jpege_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("jpege init error.\n"); ++ } ++ return ret; ++} + -+typedef struct { -+ bool used; -+ int32_t chnID; -+ SubPortInContext *portInCtx; -+} SubPortInMng; ++static td_s32 business_mod_init1() ++{ ++ td_s32 ret; + -+static SubPortInMng g_subPortIn[MAX_INPUT_PORT_CNT]; -+static bool g_subPortInMngInited = false; -+static pthread_mutex_t g_subPortInMngLock = PTHREAD_MUTEX_INITIALIZER; ++ ret = ot_jpegd_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("jpegd init error.\n"); ++ } + -+static void AudioSubPortInMngInit(void) ++ ret = ot_vfmw_mod_init(32); /* 32 */ ++ if (ret != 0) { ++ HAL_LOGE("vfmw init error.\n"); ++ } ++ ++ ret = ot_vdec_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("vdec init error.\n"); ++ } ++ ++ AUDIO_init(); ++ ++ return ret; ++} ++ ++td_void SDK_init(void) +{ -+ MEDIA_HAL_LOCK(g_subPortInMngLock); -+ if (!g_subPortInMngInited) { -+ for (int32_t i = 0; i < MAX_INPUT_PORT_CNT; i++) { -+ g_subPortIn[i].used = false; -+ g_subPortIn[i].chnID = i; -+ } -+ g_subPortInMngInited = true; ++ td_s32 ret; ++ ret = basic_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("basic_mod_init error.\n"); ++ return; + } -+ MEDIA_HAL_UNLOCK(g_subPortInMngLock); -+ int32_t ret = MediaSystemInit(); ++ ++ ret = common_mod_init(); + if (ret != 0) { -+ MEDIA_HAL_LOGW(MODULE_NAME, "MediaSystemInit failed ret%d", ret); ++ HAL_LOGE("common_mod_init error.\n"); ++ return; + } ++ ++ ret = business_mod_init(); ++ if (ret != 0) { ++ HAL_LOGE("business_mod_init error.\n"); ++ return; ++ } ++ ++ ret = business_mod_init1(); ++ if (ret != 0) { ++ HAL_LOGE("basic_mod_init error.\n"); ++ return; ++ } ++ ++ ot_dev_init(); ++ ++ HAL_LOGI("SDK init ok...\n"); +} + -+static int32_t AudioSubPortInMngGetFreeChn(void) ++static td_void AUDIO_exit(void) +{ -+ MEDIA_HAL_LOCK(g_subPortInMngLock); -+ if (!g_subPortInMngInited) { -+ MEDIA_HAL_UNLOCK(g_subPortInMngLock); -+ return MEDIA_HAL_ERR; ++ ot_acodec_mod_exit(); ++ ot_adec_mod_exit(); ++ ot_aenc_mod_exit(); ++ ot_ao_mod_exit(); ++ ot_ai_mod_exit(); ++ ot_aiao_mod_exit(); ++} ++ ++td_void SDK_exit(void) ++{ ++ ot_dev_exit(); ++ AUDIO_exit(); ++ ot_vdec_mod_exit(); ++ ot_vfmw_mod_exit(); ++ ot_jpegd_mod_exit(); ++ ot_jpege_mod_exit(); ++ ot_h265e_mod_exit(); ++ ot_h264e_mod_exit(); ++ ot_venc_mod_exit(); ++ ot_rc_mod_exit(); ++ ot_vedu_mod_exit(); ++ ot_vo_mod_exit(); ++ ot_vpss_mod_exit(); ++ ot_isp_mod_exit(); ++ ot_vi_mod_exit(); ++ ot_vpp_mod_exit(); ++ ot_dis_mod_exit(); ++ ot_vgs_mod_exit(); ++ ot_gdc_mod_exit(); ++ ot_rgn_mod_exit(); ++ ot_chnl_mod_exit(); ++ ot_sys_mod_exit(); ++ ot_base_mod_exit(); ++ osal_exit(); ++ HAL_LOGI("SDK exit ok...\n"); ++} ++ ++static int Cmp(const void *a, const void *b) ++{ ++ return strcmp((char *)a, (char *)b); ++} ++ ++static void InitModeInfo(void) ++{ ++ DIR *dir = opendir(CAMERA_INIT_DOC_PATH); ++ struct dirent *ptr = NULL; ++ if (dir == NULL) { ++ HAL_LOGE("Open dir error...\n"); ++ return; + } -+ for (int32_t i = 0; i < MAX_INPUT_PORT_CNT; i++) { -+ if (!g_subPortIn[i].used) { -+ g_subPortIn[i].used = true; -+ int32_t chnID = g_subPortIn[i].chnID; -+ MEDIA_HAL_UNLOCK(g_subPortInMngLock); -+ return chnID; ++ ++ uint8_t i = 0; ++ while (i < MODE_NAME_MAX_NUM) { ++ ptr = readdir(dir); ++ if (ptr == NULL) { ++ HAL_LOGI("break\n"); ++ break; ++ } ++ if (strncmp(ptr->d_name, "camera", 0x6) == 0) { ++ HAL_LOGI("file name:%s\n", ptr->d_name); ++ HAL_LOG_DOFUNC(strncpy_s(&g_modeInfo.modeNameList[i][0], MODE_NAME_MAX_LEN - 1, ++ ptr->d_name, ptr->d_reclen)); ++ i++; + } + } -+ MEDIA_HAL_UNLOCK(g_subPortInMngLock); -+ MEDIA_HAL_LOGE(MODULE_NAME, "could get free audio Input channel"); -+ return MEDIA_HAL_ERR; ++ ++ g_modeInfo.modeNum = i; ++ HAL_LOGI("mode num =%u\n", g_modeInfo.modeNum); ++ qsort(g_modeInfo.modeNameList, i, MODE_NAME_MAX_LEN, Cmp); ++ closedir(dir); ++} ++ ++static uint8_t GetCurrentMode(void) ++{ ++ ot_vb_cfg gotConfig = { 0 }; ++ uint8_t index = 0; ++ ++ int32_t ret = ss_mpi_vb_get_cfg(&gotConfig); ++ if (ret == TD_SUCCESS && gotConfig.max_pool_cnt != 0) { ++ index = (uint8_t)((gotConfig.common_pool[0].blk_size - ENLARGE_VALUE) / ENLARGE_VALUE); ++ } ++ if (index >= g_modeInfo.modeNum) { ++ HI_PRINTF("curr mode is wrong %u\n", index); ++ index = 0; ++ } ++ HI_PRINTF("CurrentMode is %u\n", index); ++ return index; ++} ++ ++static void CameraSaveModeIndexWithVb(ot_vb_cfg *vbConfig) ++{ ++ vbConfig->max_pool_cnt = 1; ++ vbConfig->common_pool[0].blk_size = g_modeInfo.index * ENLARGE_VALUE + ENLARGE_VALUE; ++ vbConfig->common_pool[0].blk_cnt = 1; ++} ++ ++static void CameraSysConfigVb(ot_vb_cfg *pstVbConfig, const VB_PARAM_CONFIG_S *pstInitParam) ++{ ++ uint32_t blkSize; ++ pstVbConfig->max_pool_cnt += pstInitParam->stMaxPoolCnt; ++ // The modeIndex of camera is save the NO.0, So starting with the 1st ++ for (uint32_t i = 1; i < pstVbConfig->max_pool_cnt; i++) { ++ uint32_t paramIndex = i - 1; // initParam starting with index 0 ++ if (pstInitParam->stPixFormat[paramIndex] == OT_PIXEL_FORMAT_RGB_BAYER_12BPP) { ++ ot_pic_buf_attr buf_attr = {0}; ++ buf_attr.width = pstInitParam->stImageSize[paramIndex].width; ++ buf_attr.height = pstInitParam->stImageSize[paramIndex].height; ++ buf_attr.pixel_format = pstInitParam->stPixFormat[paramIndex]; ++ buf_attr.bit_width = pstInitParam->stDataBitWidth[paramIndex]; ++ buf_attr.compress_mode = pstInitParam->stCompressMode[paramIndex]; ++ buf_attr.align = pstInitParam->stDefaultAlign[paramIndex]; ++ blkSize = ot_common_get_pic_buf_size(&buf_attr); ++ } else if (pstInitParam->stPixFormat[paramIndex] == OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420) { ++ ot_pic_buf_attr buf_attr = {0}; ++ buf_attr.width = pstInitParam->stImageSize[paramIndex].width; ++ buf_attr.height = pstInitParam->stImageSize[paramIndex].height; ++ buf_attr.pixel_format = pstInitParam->stPixFormat[paramIndex]; ++ buf_attr.bit_width = pstInitParam->stDataBitWidth[paramIndex]; ++ buf_attr.compress_mode = pstInitParam->stCompressMode[paramIndex]; ++ buf_attr.align = pstInitParam->stDefaultAlign[paramIndex]; ++ blkSize = ot_common_get_pic_buf_size(&buf_attr); ++ pstVbConfig->common_pool[i].blk_size = blkSize; ++ pstVbConfig->common_pool[i].blk_cnt = pstInitParam->stBlkCount[paramIndex]; ++ } else { ++ HI_PRINTF("other vb:%u,%u\n", paramIndex, pstInitParam->stPixFormat[paramIndex]); ++ } ++ } ++} ++ ++static int32_t CameraVbInit(ot_vb_cfg *pstVbConfig) ++{ ++ int32_t ret = ss_mpi_vb_set_cfg(pstVbConfig); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vb_set_cfg failed 0x%x!\n", ret); ++ return TD_FAILURE; ++ } ++ ot_vb_supplement_cfg stSupplementConf = { 0 }; ++ stSupplementConf.supplement_cfg = TD_TRUE; ++ ret = ss_mpi_vb_set_supplement_cfg(&stSupplementConf); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vb_set_supplement_cfg failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = ss_mpi_vb_init(); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vb_init failed!\n"); ++ return TD_FAILURE; ++ } ++ HAL_LOGI(" vb config success \n"); ++ return TD_SUCCESS; ++} ++ ++static int32_t CameraCreateVbPool(void) ++{ ++ ot_vb_cfg vbConfig = { 0 }; ++ ot_vb_cfg gotConfig = { 0 }; ++ CameraSaveModeIndexWithVb(&vbConfig); ++ CameraSysConfigVb(&vbConfig, &g_initParam[0].stVbAttr); ++ td_s32 ret = ss_mpi_vb_get_cfg(&gotConfig); ++ if (ret != TD_SUCCESS || gotConfig.max_pool_cnt == 0) { ++ ret = CameraVbInit(&vbConfig); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("system init failed with %d!\n", ret); ++ return TD_FAILURE; ++ } ++ } ++ ret = MediaSystemInit(); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("MediaSystemInit failed.s32Ret:0x%x !\n", ret); ++ } ++ return TD_SUCCESS; ++} ++ ++static void CameraDestoryVbPool(void) ++{ ++ int32_t ret = MediaSystemDeinit(); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("MediaSystemDeinit failed 0x%x!\n", ret); ++ return; ++ } ++ ret = ss_mpi_vb_exit(); ++ if (ret != TD_SUCCESS) { ++ ret = ss_mpi_vb_exit(); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vb_exit 1failed 0x%x!\n", ret); ++ } ++ } ++} ++static void CameraGetVpssGrpConfig(ot_vpss_grp_attr *pstVpssGrpAttr, const InitParam *initParam) ++{ ++ if (memset_s(pstVpssGrpAttr, sizeof(ot_vpss_grp_attr), 0, sizeof(ot_vpss_grp_attr)) != EOK) { ++ HI_PRINTF("memset_s pstVpssGrpAttr failed!"); ++ } ++ pstVpssGrpAttr->frame_rate.src_frame_rate = FPS_60; ++ pstVpssGrpAttr->frame_rate.dst_frame_rate = FPS_60; ++ pstVpssGrpAttr->dynamic_range = OT_DYNAMIC_RANGE_SDR8; ++ pstVpssGrpAttr->pixel_format = initParam->stViAttr.stChnAttr[0][0].pixel_format; ++ pstVpssGrpAttr->max_width = initParam->stViAttr.stChnAttr[0][0].size.width; ++ pstVpssGrpAttr->max_height = initParam->stViAttr.stChnAttr[0][0].size.height; ++} ++ ++static void CameraGetVpssChnConfig(ot_vpss_chn_attr pstVpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM], ++ bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM], const InitParam *initParam) ++{ ++ for (uint32_t i = 0; i < OT_VPSS_MAX_PHYS_CHN_NUM; i++) { ++ pstVpssChnAttr[i].width = initParam->stViAttr.stChnAttr[0][0].size.width; ++ pstVpssChnAttr[i].height = initParam->stViAttr.stChnAttr[0][0].size.height; ++ pstVpssChnAttr[i].chn_mode = OT_VPSS_CHN_MODE_USER; ++ pstVpssChnAttr[i].compress_mode = OT_COMPRESS_MODE_NONE; ++ pstVpssChnAttr[i].dynamic_range = OT_DYNAMIC_RANGE_SDR8; ++ pstVpssChnAttr[i].video_format = OT_VIDEO_FORMAT_LINEAR; ++ pstVpssChnAttr[i].pixel_format = initParam->stViAttr.stChnAttr[0][0].pixel_format; ++ pstVpssChnAttr[i].frame_rate.src_frame_rate = FPS_60; ++ pstVpssChnAttr[i].frame_rate.dst_frame_rate = FPS_60; ++ pstVpssChnAttr[i].depth = 0; ++ pstVpssChnAttr[i].mirror_en = 0; ++ pstVpssChnAttr[i].flip_en = 0; ++ pstVpssChnAttr[i].border_en = 0; ++ pstVpssChnAttr[i].aspect_ratio.mode = OT_ASPECT_RATIO_NONE; ++ } ++ chnEnable[0] = true; ++} ++ ++static int32_t CameraVideoProcStart(ot_vpss_grp VpssGrp, bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM], ++ ot_vpss_grp_attr *pstVpssGrpAttr, ot_vpss_chn_attr astVpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM]) ++{ ++ int32_t ret = ss_mpi_vpss_create_grp(VpssGrp, pstVpssGrpAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_create_grp(grp:%d) failed with %#x!\n", VpssGrp, ret); ++ return TD_FAILURE; ++ } ++ HI_PRINTF("ss_mpi_vpss_create_grp(grp:%d) success\n", VpssGrp); ++ for (int32_t j = 0; j < OT_VPSS_MAX_PHYS_CHN_NUM; j++) { ++ if (chnEnable[j]) { ++ ot_vpss_chn VpssChn = j; ++ ret = ss_mpi_vpss_set_chn_attr(VpssGrp, VpssChn, &astVpssChnAttr[VpssChn]); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_set_chn_attr failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++ ret = ss_mpi_vpss_enable_chn(VpssGrp, VpssChn); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_enable_chn failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++ ++#if defined(ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY) && (ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY != 0) ++ ot_low_delay_info vpssLdyInfo; ++ ret = ss_mpi_vpss_get_chn_low_delay(VpssGrp, VpssChn, &vpssLdyInfo); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_get_chn_low_delay failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++ vpssLdyInfo.enable = TD_TRUE; ++ vpssLdyInfo.line_cnt = 16; /* 16:VDEC_LOW_DELAY_MIN_LINE */ ++ ret = ss_mpi_vpss_set_chn_low_delay(VpssGrp, VpssChn, &vpssLdyInfo); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_set_chn_low_delay failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++#endif ++ } ++ } ++ ret = ss_mpi_vpss_start_grp(VpssGrp); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_start_grp failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++ HI_PRINTF("CameraVideoProcStart success\n"); ++ return TD_SUCCESS; ++} ++ ++int32_t CameraVpssEnableLowDelay(void) ++{ ++#if defined(ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY) && (ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY != 0) ++ ot_low_delay_info vpssLdyInfo; ++ int32_t ret = ss_mpi_vpss_get_chn_low_delay(0, 0, &vpssLdyInfo); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_get_chn_low_delay failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++ ++ vpssLdyInfo.enable = TD_TRUE; ++ vpssLdyInfo.line_cnt = 16; /* 16:VDEC_LOW_DELAY_MIN_LINE */ ++ ret = ss_mpi_vpss_set_chn_low_delay(0, 0, &vpssLdyInfo); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_set_chn_low_delay failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++#endif ++ return TD_SUCCESS; +} + -+static int32_t AudioUsbSubPortInGetFreeTrack(SubPortInContext *portInCtx) ++static int32_t CameraViBindVproc(ot_vi_pipe ViPipe, ot_vi_chn ViChn, ot_vpss_grp VpssGrp) +{ -+ MEDIA_HAL_LOCK(portInCtx->mutex); -+ for (int32_t i = 0; i < MAX_INPUT_PORT_TRACK_CNT; i++) { -+ if (portInCtx->portTrackInCtx[i] == NULL) { -+ MEDIA_HAL_UNLOCK(portInCtx->mutex); -+ return i; -+ } -+ } -+ MEDIA_HAL_UNLOCK(portInCtx->mutex); -+ MEDIA_HAL_LOGE(MODULE_NAME, "could get free audio Input track"); -+ return MEDIA_HAL_ERR; ++ ot_mpp_chn stSrcChn; ++ ot_mpp_chn stDestChn; ++ stSrcChn.mod_id = OT_ID_VI; ++ stSrcChn.dev_id = ViPipe; ++ stSrcChn.chn_id = ViChn; ++ stDestChn.mod_id = OT_ID_VPSS; ++ stDestChn.dev_id = VpssGrp; ++ stDestChn.chn_id = 0; ++ CHECK_RET(ss_mpi_sys_bind(&stSrcChn, &stDestChn), "ss_mpi_sys_bind(VI-VPSS)"); ++ return TD_SUCCESS; +} + -+static int32_t AudioUsbSubPortInFreeTrack(SubPortInContext *portInCtx, -+ SubPortTrackInContext *portTrackInCtx) ++static int32_t CameraVideoProcStop(ot_vpss_grp VpssGrp, bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM]) +{ -+ MEDIA_HAL_LOCK(portInCtx->mutex); -+ for (int32_t i = 0; i < MAX_INPUT_PORT_TRACK_CNT; i++) { -+ if (portInCtx->portTrackInCtx[i] == portTrackInCtx) { -+ portInCtx->portTrackInCtx[i] = NULL; -+ MEDIA_HAL_UNLOCK(portInCtx->mutex); -+ return MEDIA_HAL_OK; ++ int32_t ret; ++ for (int32_t j = 0; j < OT_VPSS_MAX_PHYS_CHN_NUM; j++) { ++ if (chnEnable[j]) { ++ ot_vpss_chn VpssChn = j; ++ ret = ss_mpi_vpss_disable_chn(VpssGrp, VpssChn); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } + } + } -+ MEDIA_HAL_UNLOCK(portInCtx->mutex); -+ MEDIA_HAL_LOGE(MODULE_NAME, "could not found audio Input track"); -+ return MEDIA_HAL_ERR; ++ ret = ss_mpi_vpss_stop_grp(VpssGrp); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ ret = ss_mpi_vpss_destroy_grp(VpssGrp); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ HI_PRINTF("CameraVideoProcStop success"); ++ return TD_SUCCESS; +} + -+static int32_t AudioUsbSubPortInMngFreeChn(int32_t chnID) ++static int32_t CameraViUnBindVproc(ot_vi_pipe viPipe, ot_vi_chn viChn, ot_vpss_grp vpssGrp) +{ -+ MEDIA_HAL_LOCK(g_subPortInMngLock); -+ if (!g_subPortInMngInited) { -+ MEDIA_HAL_UNLOCK(g_subPortInMngLock); -+ return MEDIA_HAL_ERR; -+ } -+ for (int32_t i = 0; i < MAX_INPUT_PORT_CNT; i++) { -+ if (g_subPortIn[i].chnID == chnID) { -+ g_subPortIn[i].used = false; -+ MEDIA_HAL_UNLOCK(g_subPortInMngLock); -+ return MEDIA_HAL_OK; -+ } -+ } -+ MEDIA_HAL_UNLOCK(g_subPortInMngLock); -+ MEDIA_HAL_LOGE(MODULE_NAME, "freehandle input audio Input handle invalid : %d", chnID); -+ return MEDIA_HAL_ERR; ++ ot_mpp_chn stSrcChn; ++ ot_mpp_chn stDestChn; ++ stSrcChn.mod_id = OT_ID_VI; ++ stSrcChn.dev_id = viPipe; ++ stSrcChn.chn_id = viChn; ++ stDestChn.mod_id = OT_ID_VPSS; ++ stDestChn.dev_id = vpssGrp; ++ stDestChn.chn_id = 0; ++ CHECK_RET(ss_mpi_sys_unbind(&stSrcChn, &stDestChn), "ss_mpi_sys_unbind(VI-VPSS)"); ++ ++ return TD_SUCCESS; +} + -+static int32_t AudioPrimarySubPortInSetExtraParam(SubPortTrackInContext *portTrackInCtx, -+ const struct InvokeAttr *invokeAttr) ++static void CameraInitParam(uint32_t mode) +{ -+ char aoDeviceIdKey[MAX_KEY_STR_LEN] = { 0 }; -+ char aoChanneIdKey[MAX_KEY_STR_LEN] = { 0 }; -+ int32_t aoDeviceId = -1; -+ int32_t aoChannelId = -1; ++ char path[PATH_MAX_LEN] = { 0 }; + -+ int32_t ret = sscanf_s((const char *)invokeAttr->request, "%s = %d %s = %d", aoDeviceIdKey, MAX_KEY_STR_LEN, -+ &aoDeviceId, aoChanneIdKey, MAX_KEY_STR_LEN, &aoChannelId); -+ if (ret == MEDIA_HAL_ERR) { -+ MEDIA_HAL_LOGI(MODULE_NAME, "sscanf_s failed"); -+ return ret; ++ if (snprintf_s(path, PATH_MAX_LEN, PATH_MAX_LEN - 1, "%s%s", CAMERA_INIT_DOC_PATH, ++ g_modeInfo.modeNameList[mode]) < 0) { ++ HI_PRINTF("snprintf_s failed\n"); ++ return; + } + -+ portTrackInCtx->refAoDevId = aoDeviceId; -+ portTrackInCtx->refAoChnId = aoChannelId; -+ -+ MEDIA_HAL_LOGI(MODULE_NAME, "%s = %d, %s = %d", aoDeviceIdKey, aoDeviceId, aoChanneIdKey, aoChannelId); -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++ HI_PRINTF("path = %s\n", path); ++ if (memset_s(&g_initParam, sizeof(g_initParam), 0, sizeof(g_initParam)) != EOK) { ++ HI_PRINTF("memset_s g_initParam failed\n"); ++ } ++ uint8_t ret = GetParamCamera(path, g_initParam, SUPPORT_MAX_CAMERA_NUM); ++ if (ret < SUPPORT_MAX_CAMERA_NUM) { ++ g_cameraNum = ret; ++ } else { ++ g_cameraNum = SUPPORT_MAX_CAMERA_NUM - 1; ++ } ++ HI_PRINTF("lib_:%s, obj_:%s\n", g_initParam[g_cameraNum].stViAttr.sensorLib, ++ g_initParam[g_cameraNum].stViAttr.sensorObj); +} + -+int32_t DualMono2Stereo(char *audioData, char *audioLeft, -+ char *audioRight, uint32_t audioLen) ++static void ReadRangCap(uint32_t cameraId, StreamCap* streamCap, uint32_t streamNum) +{ -+ if (audioData == NULL || audioLeft == NULL || audioRight == NULL) { -+ return -1; ++ InitParam *initParam = &g_initParam[cameraId]; ++ for (uint32_t i = 0; i < streamNum; i++) { ++ streamCap[i].format = FORMAT_YVU420; ++ streamCap[i].u.range.maxFps = initParam->stViAttr.stChnAttr[0][0].frame_rate_ctrl.dst_frame_rate; ++ streamCap[i].u.range.minFps = MIN_FPS; ++ streamCap[i].u.range.maxHeight = initParam->stViAttr.stChnAttr[0][0].size.height; ++ streamCap[i].u.range.minHeight = MIN_HEIGHT; ++ streamCap[i].u.range.maxWidth = initParam->stViAttr.stChnAttr[0][0].size.width; ++ streamCap[i].u.range.minWidth = MIN_WIDTH; + } -+ uint32_t i, j; -+ uint32_t framesize = 2; -+ uint32_t signleDataLen = audioLen / 2; ++} + -+ for (i = 0; i < signleDataLen; i += framesize) { -+ for (j = 0; j < framesize; j++) { -+ audioData[2 * i + j] = audioLeft[i + j]; -+ audioData[2 * i + framesize + j] = audioLeft[i + j]; ++static void ReadEnumCap(uint32_t cameraId, StreamCap* streamCap, uint32_t streamNum) ++{ ++ InitParam *initParam = &g_initParam[cameraId]; ++ for (uint32_t i = 0; i < streamNum; i++) { ++ streamCap[i].format = FORMAT_YVU420; ++ streamCap[i].u.formatEnum.frame_rate[0] = \ ++ initParam->stViAttr.stChnAttr[0][0].frame_rate_ctrl.dst_frame_rate; ++ streamCap[i].u.formatEnum.frame_rate_num = 1; ++ if (i == 0) { ++ streamCap[i].u.formatEnum.width = RESOLUTION_2592X1944_W; ++ streamCap[i].u.formatEnum.height = RESOLUTION_2592X1944_H; ++ } else if (i == 1) { ++ streamCap[i].u.formatEnum.width = RESOLUTION_1080P_W; ++ streamCap[i].u.formatEnum.height = RESOLUTION_1080P_H; ++ } else if (i == 0x2) { ++ streamCap[i].u.formatEnum.width = RESOLUTION_720P_W; ++ streamCap[i].u.formatEnum.height = RESOLUTION_720P_H; ++ } else if (i == 0x3) { ++ streamCap[i].u.formatEnum.width = RESOLUTION_D1_NTSC_W; ++ streamCap[i].u.formatEnum.height = RESOLUTION_D1_NTSC_H; ++ } else if (i == 0x4) { ++ streamCap[i].u.formatEnum.width = RESOLUTION_360P_W; ++ streamCap[i].u.formatEnum.height = RESOLUTION_360P_H; ++ } else { ++ streamCap[i].u.formatEnum.width = RESOLUTION_1080P_W; ++ streamCap[i].u.formatEnum.height = RESOLUTION_1080P_H; + } + } -+ -+ return MEDIA_HAL_OK; +} + -+int32_t AudioUsbSubPortInGetCapability(const struct AudioPort *port, struct AudioPortCapability *capability) ++static void DisableVpssExtChn(ot_vpss_grp vpssGrp) +{ -+ MEDIA_HAL_UNUSED(port); -+ capability->sampleRateMasks = 0; -+ capability->sampleRateMasks |= AUDIO_SAMPLE_RATE_MASK_48000; -+ capability->sampleRateMasks |= AUDIO_SAMPLE_RATE_MASK_96000; -+ capability->hardwareMode = true; -+ capability->formats = g_audioInFormats; -+ capability->subPortsNum = 0; -+ capability->subPorts = NULL; -+ -+ capability->channelCount = AUDIO_STEREO_SOUND_MODE_CHN_CNT; -+ MEDIA_HAL_LOGD(MODULE_NAME, "usb support stereo"); -+ return MEDIA_HAL_OK; ++ for (ot_vpss_chn chn = OT_VPSS_MAX_PHYS_CHN_NUM; chn <= CALLBACK_EXT_CHN; chn++) { ++ ss_mpi_vpss_disable_chn(vpssGrp, chn); ++ } +} + -+int32_t AudioUsbSubPortInGetFrameCount(AudioHandle trackHandle, uint64_t *count) ++static int32_t ParamCheck(const StreamAttr *stream, const ControlInfo *config) +{ -+ MEDIA_HAL_UNUSED(trackHandle); ++ if (stream->invertMode >= HAL_ROTATION_BUTT) { ++ HI_PRINTF("rotation param invalid\n"); ++ return TD_FAILURE; ++ } ++ if (stream->fps > MAX_FPS || stream->fps == 0) { ++ HI_PRINTF("fps param invalid\n"); ++ return TD_FAILURE; ++ } ++ if (stream->width <= 0 || stream->width > MAX_FRAME_WIDTH || ++ stream->height <= 0 || stream->height > MAX_FRAME_WIDTH) { ++ HI_PRINTF("width height param invalid\n"); ++ return TD_FAILURE; ++ } ++ if (stream->crop.x == 0 && stream->crop.y == 0 && ++ stream->crop.w == 0 && stream->crop.h == 0) { ++ return TD_SUCCESS; ++ } ++ if (stream->crop.x + stream->crop.w > config->maxW || ++ stream->crop.y + stream->crop.h > config->maxH) { ++ HI_PRINTF("crop param invalid\n"); ++ return TD_FAILURE; ++ } ++ if (stream->invertMode == HAL_ROTATION_90) { ++ if (stream->crop.w < stream->height || stream->crop.h < stream->width) { ++ HI_PRINTF("crop param invalid\n"); ++ return TD_FAILURE; ++ } ++ } else if (stream->crop.h < stream->height || stream->crop.w < stream->width) { ++ HI_PRINTF("crop param invalid\n"); ++ return TD_FAILURE; ++ } ++ return TD_SUCCESS; ++} + -+ *count = AUDIO_HAL_FRAME_COUNT; -+ MEDIA_HAL_LOGI(MODULE_NAME, "FrameCount :%llu", *count); -+ return MEDIA_HAL_OK; ++#ifdef USE_EXT_CHN ++static void GetVpss(const StreamAttr *stream, const CameraInfo *cameraInfo, ++ ot_vpss_chn *vpssChn, ot_vpss_chn *vpssPhyChn) ++{ ++ *vpssChn = -1; ++ static ot_vpss_chn videoChn = VIDEO_EXT_MIN_CHN; ++ if (stream->type == STREAM_VIDEO) { ++ if (videoChn > VIDEO_EXT_MAX_CHN) { ++ videoChn = VIDEO_EXT_MIN_CHN; ++ } ++ *vpssChn = videoChn++; ++ *vpssPhyChn = VIDEO_VPSS_CHN; ++ } else if (stream->type == STREAM_PREVIEW) { ++ *vpssChn = PREEV_VPSS_CHN; ++ *vpssPhyChn = PREEV_VPSS_CHN; ++ } else if (stream->type == STREAM_CAPTURE) { ++ *vpssChn = OT_VPSS_MAX_PHYS_CHN_NUM; ++ *vpssPhyChn = JPEG_VPSS_CHN; ++ } else { ++ *vpssChn = CALLBACK_EXT_CHN; ++ *vpssPhyChn = CALLBACK_VPSS_CHN; ++ } ++} ++#else ++static void GetVpss(const StreamAttr *stream, const CameraInfo *cameraInfo, ++ ot_vpss_chn *vpssChn, ot_vpss_chn *vpssPhyChn) ++{ ++ (void)stream; ++ *vpssChn = -1; ++ *vpssPhyChn = -1; ++ for (td_u8 i = 0; i < CAEMRA_MAX_STREAM_NUM; i++) { ++ if (cameraInfo->internalStreamInfo[i].isUsed == true || ++ cameraInfo->internalStreamInfo[i].vpssChn >= OT_VPSS_MAX_PHYS_CHN_NUM) { ++ continue; ++ } ++ *vpssChn = i; ++ *vpssPhyChn = i; ++ HI_PRINTF("GetVpss chnn :%u\n", i); ++ return; ++ } +} ++#endif + -+static int32_t AiInit(SubPortInContext *portInCtx, ot_aio_attr aiAttr) ++static uint32_t GetDeviceId(uint32_t chn) +{ -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++ return (((OT_ID_VPSS << 0x10) & 0xff0000) + (chn & 0xff)); // 16 +} + -+static bool AudioConvertAudioFormatToHAL(enum AudioFormat format, uint32_t *ptNumPerFrm) ++static bool IsValidChnn(ot_vpss_chn vpssChn) +{ -+ if (ptNumPerFrm == NULL) { -+ return false; -+ } -+ switch (format) { -+ case AUDIO_FORMAT_TYPE_PCM_16_BIT: -+ case AUDIO_FORMAT_TYPE_AAC_LC: -+ case AUDIO_FORMAT_TYPE_AAC_LD: -+ case AUDIO_FORMAT_TYPE_AAC_ELD: -+ case AUDIO_FORMAT_TYPE_AAC_HE_V1: -+ case AUDIO_FORMAT_TYPE_AAC_HE_V2: -+ *ptNumPerFrm = AUDIO_AAC_PCM_PTNUMPERFRM; -+ break; -+ case AUDIO_FORMAT_TYPE_G711A: -+ case AUDIO_FORMAT_TYPE_G711U: -+ case AUDIO_FORMAT_TYPE_G726: -+ *ptNumPerFrm = AUDIO_G711_G726_PTNUMPERFRM; -+ break; -+ default: -+ MEDIA_HAL_LOGW(MODULE_NAME, "Invalid audio format: %d", format); -+ return false; ++ if (vpssChn >= 0 && vpssChn < OT_VPSS_MAX_CHN_NUM) { ++ return true; + } -+ return true; ++ return false; +} + -+static int32_t AiAttrConfig(const struct PortPluginAttr *inputAttr, ot_aio_attr *aiAttr) ++static void ConvertCrop(ot_vpss_chn vpssChn, const StreamAttr *stream, ControlInfo *config) +{ -+ if (memset_s(aiAttr, sizeof(ot_aio_attr), 0x0, sizeof(ot_aio_attr)) != EOK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s: portInCtx aiAttr failed"); -+ return MEDIA_HAL_ERR; -+ } -+ if (!AudioConvertSampleRateToHAL(inputAttr->sampleRate, &(aiAttr->sample_rate))) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertSampleRateToHAL sample_rate: %d failed", inputAttr->sampleRate); -+ return MEDIA_HAL_ERR; -+ } -+ aiAttr->bit_width = OT_AUDIO_BIT_WIDTH_16; -+ aiAttr->work_mode = OT_AIO_MODE_I2S_MASTER; -+ if (!AudioConvertChannelToHAL(inputAttr->channelCount, &(aiAttr->snd_mode))) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertChannelToHAL channelCount: %u failed ", inputAttr->channelCount); -+ return MEDIA_HAL_ERR; ++ if (stream->crop.w == 0 || stream->crop.h == 0) { ++ config->cropInfo.enable = TD_FALSE; ++ config->cropInfo.crop_mode = OT_COORD_ABS; ++ config->cropInfo.crop_rect.x = 0; ++ config->cropInfo.crop_rect.y = 0; ++ config->cropInfo.crop_rect.width = config->maxW; ++ config->cropInfo.crop_rect.height = config->maxH; ++ return; + } -+ aiAttr->expand_flag = 0; -+ aiAttr->frame_num = AUDIO_FRAME_NUM_IN_BUF; -+ if (!AudioConvertAudioFormatToHAL(inputAttr->audioFormat, &(aiAttr->point_num_per_frame))) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertCodecFormatToHAL codecFormat: %d failed ", inputAttr->audioFormat); -+ return MEDIA_HAL_ERR; ++ config->cropInfo.enable = TD_TRUE; ++ config->cropInfo.crop_mode = OT_COORD_ABS; ++ if (vpssChn < OT_VPSS_MAX_PHYS_CHN_NUM) { ++ if (config->rotation.rotation_fixed == OT_ROTATION_90) { ++ config->cropInfo.crop_rect.width = ALIGN_DOWN(stream->height, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.height = ALIGN_DOWN(stream->width, HI_ALIGN_DOWN_NUM); ++ td_u32 x = stream->crop.x * stream->height / stream->crop.w; ++ td_u32 y = stream->crop.y * stream->width / stream->crop.h; ++ config->cropInfo.crop_rect.x = ALIGN_DOWN(x, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.y = ALIGN_DOWN(y, HI_ALIGN_DOWN_NUM); ++ } else { ++ config->cropInfo.crop_rect.width = ALIGN_DOWN(stream->width, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.height = ALIGN_DOWN(stream->height, HI_ALIGN_DOWN_NUM); ++ td_u32 x = stream->crop.x * stream->width / stream->crop.w; ++ td_u32 y = stream->crop.y * stream->height / stream->crop.h; ++ config->cropInfo.crop_rect.x = ALIGN_DOWN(x, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.y = ALIGN_DOWN(y, HI_ALIGN_DOWN_NUM); ++ } ++ } else { ++ if (config->rotation.rotation_fixed == OT_ROTATION_90) { ++ config->cropInfo.crop_rect.x = ALIGN_DOWN(stream->crop.y, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.y = ALIGN_DOWN(stream->crop.x, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.width = ALIGN_DOWN(stream->crop.h, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.height = ALIGN_DOWN(stream->crop.w, HI_ALIGN_DOWN_NUM); ++ } else { ++ config->cropInfo.crop_rect.x = ALIGN_DOWN(stream->crop.x, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.y = ALIGN_DOWN(stream->crop.y, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.width = ALIGN_DOWN(stream->crop.w, HI_ALIGN_DOWN_NUM); ++ config->cropInfo.crop_rect.height = ALIGN_DOWN(stream->crop.h, HI_ALIGN_DOWN_NUM); ++ } + } -+ aiAttr->chn_cnt = inputAttr->channelCount; -+ aiAttr->clk_share = 1; -+ aiAttr->i2s_type = OT_AIO_I2STYPE_INNERCODEC; -+ return MEDIA_HAL_OK; +} + -+static void SubPortTrackInInit(SubPortTrackInContext *portTrackInCtx, const struct PortPluginAttr *inputAttr, -+ enum AudioPortPin audioPortPin) ++static void ConvetToControlInfo(ot_vpss_chn vpssChn, const StreamAttr *stream, ControlInfo *config) +{ -+ portTrackInCtx->inputAttr = *inputAttr; -+ -+ portTrackInCtx->common.audioPin = audioPortPin; -+ portTrackInCtx->common.GetFrameCount = AudioUsbSubPortInGetFrameCount; -+ portTrackInCtx->common.GetLatency = NULL; -+ portTrackInCtx->common.EnableTrack = AudioUsbSubPortInEnableTrack; -+ portTrackInCtx->common.PauseTrack = NULL; -+ portTrackInCtx->common.ResumeTrack = NULL; -+ portTrackInCtx->common.FlushTrack = NULL; -+ portTrackInCtx->common.DisableTrack = AudioUsbSubPortInDisableTrack; -+ portTrackInCtx->common.AcquireFrame = AudioUsbSubPortInAcquireFrame; -+ portTrackInCtx->common.SendFrame = NULL; -+ portTrackInCtx->common.GetPosition = AudioUsbSubPortInGetPosition; -+ portTrackInCtx->common.SetMute = AudioUsbSubPortInSetMute; -+ portTrackInCtx->common.GetMute = AudioUsbSubPortInGetMute; -+ portTrackInCtx->common.SetVolume = AudioUsbSubPortInSetVolume; -+ portTrackInCtx->common.GetVolume = AudioUsbSubPortInGetVolume; -+ portTrackInCtx->common.Invoke = AudioUsbSubPortInInvoke; ++ if (IsValidChnn(vpssChn) == false) { ++ return; ++ } ++ config->fps = stream->fps; ++ config->width = stream->width; ++ config->height = stream->height; ++ config->rotation.enable = TD_TRUE; ++ config->rotation.rotation_type = OT_ROTATION_ANG_FIXED; ++ if (stream->invertMode == HAL_HORIZONTAL_MIRROR) { ++ config->isFlip = TD_TRUE; ++ } else if (stream->invertMode == HAL_VETICALLY_MIRROR) { ++ config->isMirror = TD_TRUE; ++ } else if (stream->invertMode == HAL_ROTATION_90) { ++ config->rotation.rotation_fixed = OT_ROTATION_90; ++ } else if (stream->invertMode == HAL_ROTATION_180) { ++ config->rotation.rotation_fixed = OT_ROTATION_180; ++ } else { ++ config->isFlip = TD_FALSE; ++ config->isMirror = TD_FALSE; ++ config->rotation.rotation_fixed = OT_ROTATION_0; ++ } + -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); ++ ConvertCrop(vpssChn, stream, config); ++ HAL_LOGI("flip = %d rota = %d crop w = %u enable = %d\n", config->isFlip, config->rotation.rotation_fixed, ++ config->cropInfo.crop_rect.width, config->cropInfo.enable); +} + -+int32_t AudioUsbSubPortInSetMute(AudioHandle trackHandle, bool mute) ++static void GetVpssExtChnConfig(ot_vpss_ext_chn_attr *extChnAttr, const ControlInfo *config, ++ ot_vpss_chn_attr *vpssChnAttr, ot_vpss_chn vpssPhyChn) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ extChnAttr->bind_chn = vpssPhyChn; ++ extChnAttr->pixel_format = OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420; ++ extChnAttr->frame_rate.src_frame_rate = vpssChnAttr->frame_rate.dst_frame_rate; ++ extChnAttr->frame_rate.dst_frame_rate = config->fps; ++ extChnAttr->width = config->width; ++ extChnAttr->height = config->height; ++} + -+ if(mute) { // mute set input volume to 0 -+ snd_mixer_selem_set_capture_volume_all(portTrackInCtx->ai_elem_vol, 0); -+ } else { // unmute set input volume to last volume -+ long vol = portTrackInCtx->ai_min_vol + (portTrackInCtx->ai_max_vol - portTrackInCtx->ai_min_vol) * portTrackInCtx->volume / 100; -+ snd_mixer_selem_set_capture_volume_all(portTrackInCtx->ai_elem_vol, vol); ++static int32_t GetFreeStreamIndex(const CameraInfo *cameraInfo, uint32_t *streamIndex) ++{ ++ for (int32_t i = 0; i < CAEMRA_MAX_STREAM_NUM; i++) { ++ if (!cameraInfo->internalStreamInfo[i].isUsed) { ++ *streamIndex = i; ++ return TD_SUCCESS; ++ } + } -+ portTrackInCtx->mute = mute; -+ MEDIA_HAL_LOGI(MODULE_NAME, "set mute %d", mute); -+ return MEDIA_HAL_OK; ++ HAL_LOGE("get free stream index failed\n"); ++ return TD_FAILURE; +} + -+int32_t AudioUsbSubPortInGetMute(AudioHandle trackHandle, bool *mute) ++static void AddStream(CameraInfo *cameraInfo, uint32_t streamIndex, ot_vpss_chn vpssChn, const StreamAttr *stream) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; -+ -+ *mute = portTrackInCtx->mute; -+ MEDIA_HAL_LOGE(MODULE_NAME, "get mute %d", *mute); -+ return MEDIA_HAL_OK; ++ LOG_CHK_RETURN(streamIndex >= CAEMRA_MAX_STREAM_NUM); ++ cameraInfo->streamAttr[streamIndex] = *stream; ++ cameraInfo->internalStreamInfo[streamIndex].isUsed = true; ++ cameraInfo->internalStreamInfo[streamIndex].vpssChn = vpssChn; ++ HAL_LOGI("stream %u vpss = %d\n", streamIndex, vpssChn); +} + -+int32_t AudioUsbSubPortInSetVolume(AudioHandle trackHandle, float volume) ++static void DeleteStream(CameraInfo *cameraInfo, uint32_t streamIndex) +{ -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; -+ int32_t ret; -+ if (volume < VOLUME_PERCENT_MIN_IN || volume > VOLUME_PERCENT_MAX_IN) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortInSetVolume, volume:%f err, it should [%f,%f]", volume, -+ VOLUME_PERCENT_MIN_IN, VOLUME_PERCENT_MAX_IN); -+ return MEDIA_HAL_INVALID_PARAM; ++ ot_vpss_grp vpssGrp = 0; ++ ot_vpss_chn vpssChn = cameraInfo->internalStreamInfo[streamIndex].vpssChn; ++ HAL_LOG_DOFUNC(memset_s(&cameraInfo->streamAttr[streamIndex], sizeof(StreamAttr), 0, sizeof(StreamAttr))); ++ HAL_LOG_DOFUNC(memset_s(&cameraInfo->internalStreamInfo[streamIndex], sizeof(InternalStreamInfo), ++ 0, sizeof(InternalStreamInfo))); ++ for (uint8_t i = 0; i < CAEMRA_MAX_STREAM_NUM; i++) { ++ if (cameraInfo->internalStreamInfo[i].isUsed && cameraInfo->internalStreamInfo[i].vpssChn == vpssChn) { ++ return; ++ } + } -+ const float EPSINON = 0.00001; -+ if ((volume >= -EPSINON) && (volume <= EPSINON)) { -+ ot_audio_fade fade = {}; -+ portTrackInCtx->volume = volume; -+ snd_mixer_selem_set_capture_volume_all(portTrackInCtx->ai_elem_vol, 0); -+ return MEDIA_HAL_OK; ++ if (vpssChn >= OT_VPSS_MAX_PHYS_CHN_NUM) { ++ ss_mpi_vpss_disable_chn(vpssGrp, vpssChn); + } ++} + -+ long vol = portTrackInCtx->ai_min_vol + (portTrackInCtx->ai_max_vol - portTrackInCtx->ai_min_vol) * volume / 100; -+ ret = snd_mixer_selem_set_capture_volume_all(portTrackInCtx->ai_elem_vol, vol); -+ if (ret < 0) { -+ MEDIA_HAL_LOGI(MODULE_NAME, "SetVolume failed: %s\n", snd_strerror(ret)); -+ return ret; ++static int32_t EnablePreview(ot_vpss_chn vpssChn, uint32_t cameraId, PosInfo *pos, const StreamAttr *streamAttr) ++{ ++ IRect displayRect; ++ displayRect.x = pos->x; ++ displayRect.y = pos->y; ++ displayRect.w = streamAttr->width; ++ displayRect.h = streamAttr->height; ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ int32_t vpssGrp = cameraInfo->vpssGrp; ++ LayerInfo layerInfo = {0}; ++ layerInfo.width = streamAttr->width; ++ layerInfo.height = streamAttr->height; ++ layerInfo.type = LAYER_TYPE_OVERLAY; ++ layerInfo.bpp = 8; // 8: Number of bits occupied by each pixel ++ layerInfo.pixFormat = PIXEL_FMT_YCRCB_420_SP; ++ layerInfo.fps = streamAttr->fps; ++ LOG_CHK_RETURN_ERR(g_layerInterface == NULL, TD_FAILURE); ++ HAL_LOG_DOFUNC_RETURN(g_layerInterface->CreateLayer(DISPLAY_DEVID, &layerInfo, &cameraInfo->layerId)); ++ HAL_LOG_DOFUNC_RETURN(g_layerInterface->SetLayerSize(DISPLAY_DEVID, cameraInfo->layerId, &displayRect)); ++ HAL_LOG_DOFUNC_RETURN(g_layerInterface->InvokeLayerCmd(DISPLAY_DEVID, cameraInfo->layerId, ++ OVERLAYER_CMD_VO_BIND_VPSS, vpssChn, vpssGrp)); ++ return TD_SUCCESS; ++} ++ ++static void DisablePreview(ot_vpss_chn vpssChn, uint32_t cameraId) ++{ ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ int32_t vpssGrp = cameraInfo->vpssGrp; ++ LOG_CHK_RETURN(g_layerInterface == NULL); ++ g_layerInterface->InvokeLayerCmd(DISPLAY_DEVID, cameraInfo->layerId, ++ OVERLAYER_CMD_VO_UNBIND_VPSS, vpssChn, vpssGrp); ++ g_layerInterface->CloseLayer(DISPLAY_DEVID, cameraInfo->layerId); ++ cameraInfo->layerId = -1; ++} ++ ++static int32_t CovertToBuffer(const ot_video_frame_info *videoFrame, HalBuffer *halBuffer) ++{ ++ if (halBuffer->format == FORMAT_PRIVATE) { ++ HalBuffer getBuf; ++ getBuf.stride0 = (int32_t)videoFrame->video_frame.stride[0]; ++ getBuf.stride1 = (int32_t)videoFrame->video_frame.stride[1]; ++ getBuf.height = (int32_t)videoFrame->video_frame.height; ++ getBuf.width = (int32_t)videoFrame->video_frame.width; ++ getBuf.timeStamp = (int64_t)videoFrame->video_frame.pts; ++ int32_t size = getBuf.height * getBuf.width * 0x3 / 0x2; // YUV size ++ if (halBuffer->size <= size) { ++ HAL_LOGE("%d <= %d\n", halBuffer->size, size); ++ return TD_FAILURE; ++ } ++ getBuf.size = size; ++ getBuf.format = FORMAT_YVU420; ++ getBuf.phyAddr = videoFrame->video_frame.phys_addr[0]; ++ HAL_LOG_DOFUNC_RETURN(memcpy_s(halBuffer->virAddr, halBuffer->size, &getBuf, sizeof(HalBuffer))); ++ return TD_SUCCESS; ++ } else if (videoFrame->video_frame.pixel_format == OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420) { ++ halBuffer->format = FORMAT_YVU420; ++ } else if (videoFrame->video_frame.pixel_format == OT_PIXEL_FORMAT_RGB_BAYER_12BPP) { ++ halBuffer->format = FORMAT_RGB_BAYER_12BPP; ++ } else { + } -+ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortInSetVolume SetVolume: %d (raw=%ld)\n", volume, vol); -+ portTrackInCtx->volume = volume; -+ return MEDIA_HAL_OK; ++ halBuffer->stride0 = (int32_t)videoFrame->video_frame.stride[0]; ++ halBuffer->stride1 = (int32_t)videoFrame->video_frame.stride[1]; ++ halBuffer->height = (int32_t)videoFrame->video_frame.height; ++ halBuffer->width = (int32_t)videoFrame->video_frame.width; ++ halBuffer->timeStamp = (int64_t)videoFrame->video_frame.pts; ++ halBuffer->size = halBuffer->height * halBuffer->width * 0x3 / 0x2; // YUV size ++ halBuffer->virAddr = (void *) ss_mpi_sys_mmap(videoFrame->video_frame.phys_addr[0], halBuffer->size); ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortInGetVolume(AudioHandle trackHandle, float *volume) ++ ++static void CameraGetViConfig(CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +{ -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ pstViConfig[i].stSnsInfo.s32SnsId = g_initParam[i].stViAttr.stMipiAttr.devno; ++ HI_PRINTF("sns id = %u\n", g_initParam[i].stViAttr.stMipiAttr.devno); ++ pstViConfig[i].stSnsInfo.s32BusId = g_initParam[i].stViAttr.busId; ++ pstViConfig[i].stSnsInfo.MipiDev = g_initParam[i].stViAttr.stMipiAttr.devno; ++ pstViConfig[i].stDevInfo.ViDev = g_initParam[i].stViAttr.stMipiAttr.devno; ++ HAL_LOG_DOFUNC(memset_s(&pstViConfig[i].stSnapInfo, sizeof(HISI_SNAP_INFO_S), 0, sizeof(HISI_SNAP_INFO_S))); ++ pstViConfig[i].stPipeInfo.bMultiPipe = TD_FALSE; ++ pstViConfig[i].stPipeInfo.bVcNumCfged = TD_FALSE; ++ pstViConfig[i].stPipeInfo.enMastPipeMode = g_initParam[i].stViAttr.pipeMode[0]; ++ pstViConfig[i].stPipeInfo.aPipe[0] = g_initParam[i].stViAttr.stMipiAttr.devno; ++ pstViConfig[i].stPipeInfo.aPipe[0] = 0; ++ for (int32_t j = 0x1; j < OT_VI_MAX_PIPE_NUM; j++) { ++ pstViConfig[i].stPipeInfo.aPipe[j] = -1; ++ } ++ if (cameraCnt == 1 && g_cameraNum == SUPPORT_MAX_CAMERA_NUM) { // 1 sensor(2 pipe) analog 2 sensors ++ pstViConfig[0].stPipeInfo.aPipe[1] = pstViConfig[0].stPipeInfo.aPipe[0] + 1; ++ } + -+ *volume = (float)portTrackInCtx->volume; -+ return MEDIA_HAL_OK; ++ pstViConfig[i].stPipeInfo.frameInterruptType = g_initParam[i].stViAttr.frameInterruptType[0]; ++ pstViConfig[i].stPipeInfo.earlyLine = g_initParam[i].stViAttr.earlyLine[0]; ++ pstViConfig[i].stChnInfo.ViChn = 0; ++ pstViConfig[i].stChnInfo.enPixFormat = g_initParam[i].stViAttr.stChnAttr[0][0].pixel_format; ++ pstViConfig[i].stChnInfo.dynamicRange = g_initParam[i].stViAttr.stChnAttr[0][0].dynamic_range; ++ pstViConfig[i].stChnInfo.videoFormat = g_initParam[i].stViAttr.stChnAttr[0][0].video_format; ++ pstViConfig[i].stChnInfo.compressMode = g_initParam[i].stViAttr.stChnAttr[0][0].compress_mode; ++ pstViConfig[i].mipiAttr = &g_initParam[i].stViAttr.stMipiAttr; ++ pstViConfig[i].devAttr = &g_initParam[i].stViAttr.stDevAttr; ++ pstViConfig[i].pipeAttr = &(g_initParam[i].stViAttr.stPipeAttr[0]); ++ pstViConfig[i].chnAttr = &(g_initParam[i].stViAttr.stChnAttr[0][0]); ++ pstViConfig[i].ispPubAttr = &g_initParam[i].stViAttr.stPubAttr; ++ pstViConfig[i].sensorLib = g_initParam[i].stViAttr.sensorLib; ++ pstViConfig[i].sensorObj = g_initParam[i].stViAttr.sensorObj; ++ pstViConfig[i].len = SENSOR_DESC_MAX_LEN; ++ } +} + -+int32_t AudioUsbSubPortInOpen(AudioHandle *portHandle, int card_usb) ++static void SetChnDepth(InternalStreamInfo *internalInfo, ImageFormat format) +{ -+ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); -+ int32_t ret; -+ if (!g_subPortInMngInited) { -+ AudioSubPortInMngInit(); ++ if (internalInfo->isSetDepth == true) { ++ return; + } -+ -+ int32_t portId = AudioSubPortInMngGetFreeChn(); -+ CHK_COND_RETURN(portId == MEDIA_HAL_INVALID_CHN_ID, MEDIA_HAL_ERR, "no free AI device"); -+ -+ SubPortInContext *portInCtx = (SubPortInContext *)malloc(sizeof(SubPortInContext)); -+ if (portInCtx == NULL) { -+ MEDIA_HAL_LOGI(MODULE_NAME, "malloc failed"); -+ ret = MEDIA_HAL_NO_MEM; -+ goto FREE_CHN; ++ if (format == FORMAT_YVU420 || format == FORMAT_PRIVATE) { ++ if (internalInfo->vpssChn < OT_VPSS_MAX_PHYS_CHN_NUM) { ++ ot_vpss_chn_attr chnAttr = { 0 }; ++ ss_mpi_vpss_get_chn_attr(0, internalInfo->vpssChn, &chnAttr); ++ chnAttr.depth = 1; ++ HAL_LOG_DOFUNC(ss_mpi_vpss_set_chn_attr(0, internalInfo->vpssChn, &chnAttr)); ++ } else { ++ ot_vpss_ext_chn_attr extChnAttr = { 0 }; ++ ss_mpi_vpss_get_ext_chn_attr(0, internalInfo->vpssChn, &extChnAttr); ++ extChnAttr.depth = 1; ++ HAL_LOG_DOFUNC(ss_mpi_vpss_set_ext_chn_attr(0, internalInfo->vpssChn, &extChnAttr)); ++ } ++ } else if (format == FORMAT_RGB_BAYER_12BPP) { ++ HAL_LOGI("set vi dump attr\n"); ++ ot_vi_frame_dump_attr attr = {true, 1}; ++ HAL_LOG_DOFUNC(ss_mpi_vi_set_pipe_frame_dump_attr(0, &attr)); ++ } else { ++ HAL_LOGI("not support format\n"); ++ return; + } ++ internalInfo->isSetDepth = true; ++} + -+ if (memset_s(portInCtx, sizeof(SubPortInContext), 0, sizeof(SubPortInContext)) != EOK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s failed"); -+ ret = MEDIA_HAL_ERR; -+ goto FREE; ++static void UpdateVpssAttr(ot_vpss_chn vpssChn, const StreamAttr *stream, const ControlInfo *config, ++ ot_vpss_chn_attr *vpssChnAttr) ++{ ++ vpssChnAttr->flip_en = config->isFlip; ++ vpssChnAttr->mirror_en = config->isMirror; ++ if (vpssChn < OT_VPSS_MAX_PHYS_CHN_NUM) { ++ if (config->cropInfo.crop_rect.width <= stream->crop.w && ++ config->cropInfo.crop_rect.height <= stream->crop.h && ++ stream->crop.w != 0 && stream->crop.h != 0) { ++ vpssChnAttr->width = config->maxW * config->cropInfo.crop_rect.width / stream->crop.w; ++ vpssChnAttr->height = config->maxH * config->cropInfo.crop_rect.height / stream->crop.h; ++ vpssChnAttr->width = ALIGN_UP(vpssChnAttr->width, HI_ALIGN_UP_NUM); ++ vpssChnAttr->height = ALIGN_UP(vpssChnAttr->height, HI_ALIGN_UP_NUM); ++ } else if (config->rotation.rotation_fixed == OT_ROTATION_90) { ++ vpssChnAttr->width = ALIGN_DOWN(stream->height, HI_ALIGN_DOWN_NUM); ++ vpssChnAttr->height = ALIGN_DOWN(stream->width, HI_ALIGN_DOWN_NUM); ++ } else { ++ vpssChnAttr->width = ALIGN_DOWN(stream->width, HI_ALIGN_DOWN_NUM); ++ vpssChnAttr->height = ALIGN_DOWN(stream->height, HI_ALIGN_DOWN_NUM); ++ } ++ vpssChnAttr->frame_rate.src_frame_rate = FPS_60; ++ vpssChnAttr->frame_rate.dst_frame_rate = FPS_60; ++ vpssChnAttr->pixel_format = OT_PIXEL_FORMAT_YUV_SEMIPLANAR_420; ++ HI_PRINTF("chnn attr: chnn = %d w = %u h = %u\n", vpssChn, vpssChnAttr->width, vpssChnAttr->height); + } ++ vpssChnAttr->chn_mode = OT_VPSS_CHN_MODE_USER; ++} + -+ portInCtx->aiDeviceId = portId; -+ // todo zhp -+ char PCM_DEVICE[32]; -+ snprintf(PCM_DEVICE, sizeof(PCM_DEVICE), "hw:%d,0", card_usb); -+ int pcm = snd_pcm_open(&(portInCtx->ai_pcm_handle), PCM_DEVICE, SND_PCM_STREAM_CAPTURE, 0); -+ if (pcm < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_open failed"); -+ ret = MEDIA_HAL_ERR; -+ goto FREE; ++static td_s32 CreateStream(ot_vpss_chn vpssChn, ot_vpss_chn vpssPhyChn, ++ const StreamAttr *stream, const ControlInfo *config) ++{ ++ HI_PRINTF("CreateImage w h %d %d chan %d vpGroup %d\n", stream->width, stream->height, vpssChn, config->vpssGrp); ++ const ot_vpss_grp vpssGrp = config->vpssGrp; ++ ot_vpss_chn_attr vpssChnAttr = { 0 }; ++ if (IsValidChnn(vpssChn) == false) { ++ return TD_FAILURE; ++ } ++ td_u32 ret = (td_u32)ss_mpi_vpss_get_chn_attr(vpssGrp, vpssPhyChn, &vpssChnAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF(" get attr failed %#x!, vpssGrp=%d, vpssPhyChn=%d\n", ret, vpssGrp, vpssPhyChn); + } + -+ ret = snd_mixer_open(&(portInCtx->ai_mixer_handle), 0); -+ if (ret < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_open failed: %s\n", snd_strerror(ret)); -+ return ret; ++ UpdateVpssAttr(vpssChn, stream, config, &vpssChnAttr); ++ HI_PRINTF("vpssPhyChn = %d rotation.enable = %d\n", vpssPhyChn, config->rotation.enable); ++ ret |= (td_u32)ss_mpi_vpss_set_chn_attr(vpssGrp, vpssPhyChn, &vpssChnAttr); ++ if (config->rotation.enable == TD_TRUE) { ++ ret |= (td_u32)ss_mpi_vpss_set_chn_rotation(vpssGrp, vpssPhyChn, &(config->rotation)); + } -+ char CTL_DEVICE[32]; -+ snprintf(CTL_DEVICE, sizeof(CTL_DEVICE), "hw:%d", card_usb); -+ ret = snd_mixer_attach(portInCtx->ai_mixer_handle, CTL_DEVICE); -+ if (ret < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_attach failed: %s\n", snd_strerror(ret)); -+ snd_mixer_close(portInCtx->ai_mixer_handle); -+ return ret; ++ if (vpssChn < OT_VPSS_MAX_PHYS_CHN_NUM && config->cropInfo.enable == TD_TRUE) { ++ ret |= (td_u32)ss_mpi_vpss_set_chn_crop(vpssGrp, vpssChn, &(config->cropInfo)); + } ++ ret |= (td_u32)ss_mpi_vpss_enable_chn(vpssGrp, vpssPhyChn); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_set_chn_attr failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++ if (vpssChn >= OT_VPSS_MAX_PHYS_CHN_NUM) { ++ HI_PRINTF("ext vpssChn = %d\n", vpssChn); ++ ot_vpss_ext_chn_attr extChnAttr = { 0 }; ++ GetVpssExtChnConfig(&extChnAttr, config, &vpssChnAttr, vpssPhyChn); ++ ret = (td_u32)ss_mpi_vpss_set_ext_chn_attr(vpssGrp, vpssChn, &extChnAttr); ++ ret |= (td_u32)ss_mpi_vpss_set_chn_crop(vpssGrp, vpssChn, &(config->cropInfo)); ++ ret |= (td_u32)ss_mpi_vpss_enable_chn(vpssGrp, vpssChn); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vpss_set_ext_chn_attr failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++ } ++ return TD_SUCCESS; ++} + -+ snd_mixer_selem_register(portInCtx->ai_mixer_handle, NULL, NULL); -+ snd_mixer_load(portInCtx->ai_mixer_handle); -+ -+ // get element "Master" or "PCM" with volume control -+ snd_mixer_elem_t *elem = NULL; -+ for (elem = snd_mixer_first_elem(portInCtx->ai_mixer_handle); elem; elem = snd_mixer_elem_next(elem)) { -+ if (snd_mixer_selem_is_active(elem)) { -+ const char *name = snd_mixer_selem_get_name(elem); -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_selem_get_name name=%s\n", name); -+ if ((strcmp(name, "Mic") == 0) && snd_mixer_selem_has_capture_volume(elem)) { -+ portInCtx->ai_elem_vol = elem; -+ break; ++static int32_t CheckSameChn(const CameraInfo *cameraInfo, const StreamAttr *stream, ot_vpss_chn *sameChn) ++{ ++ *sameChn = -1; ++ for (td_u8 i = 0; i < CAEMRA_MAX_STREAM_NUM; i++) { ++ if (cameraInfo->internalStreamInfo[i].isUsed) { ++ if (cameraInfo->streamAttr[i].width == stream->width && ++ cameraInfo->streamAttr[i].height == stream->height && ++ cameraInfo->streamAttr[i].fps == stream->fps && ++ cameraInfo->streamAttr[i].crop.w == stream->crop.w && ++ cameraInfo->streamAttr[i].crop.h == stream->crop.h && ++ cameraInfo->streamAttr[i].crop.x == stream->crop.x && ++ cameraInfo->streamAttr[i].crop.y == stream->crop.y && ++ cameraInfo->streamAttr[i].invertMode == stream->invertMode) { ++ *sameChn = cameraInfo->internalStreamInfo[i].vpssChn; ++ return TD_SUCCESS; + } + } + } ++ return TD_FAILURE; ++} + -+ if (!(portInCtx->ai_elem_vol)) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "Cannot find suitable mixer element (Master/PCM)\n"); -+ snd_mixer_close(portInCtx->ai_mixer_handle); -+ // maybe some device not support volume control -+ // return -1; ++int32_t HalCameraInit(void) ++{ ++ HAL_ENTER(); ++ LOG_CHK_RETURN_ERR(g_isInit == true, TD_SUCCESS); ++#ifdef KERNEL_USER_MODE ++ sdk_init(); ++#endif ++ SDK_init(); ++ InitModeInfo(); ++ CameraInitParam(GetCurrentMode()); ++ HAL_LOG_DOFUNC_RETURN(CameraCreateVbPool()); ++ HAL_LOG_DOFUNC(LayerInitialize(&g_layerInterface)); ++ if (g_layerInterface != NULL && g_layerInterface->InitDisplay != NULL) { ++ HAL_LOG_DOFUNC(g_layerInterface->InitDisplay(1)); + } ++ g_isInit = true; ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+ // get volume range -+ snd_mixer_selem_get_capture_volume_range(portInCtx->ai_elem_vol, &portInCtx->ai_min_vol, &portInCtx->ai_max_vol); -+ MEDIA_HAL_LOGE(MODULE_NAME, "Volume range: [%ld, %ld]\n", portInCtx->ai_min_vol, portInCtx->ai_max_vol); -+ -+ pthread_mutex_init(&portInCtx->mutex, NULL); -+ portInCtx->opened = true; -+ -+ *portHandle = portInCtx; -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++int32_t HalCameraDeinit(void) ++{ ++ HAL_ENTER(); ++ LOG_CHK_RETURN_ERR(g_isInit == false, TD_SUCCESS); ++ if (g_layerInterface != NULL && g_layerInterface->DeinitDisplay != NULL) { ++ HAL_LOG_DOFUNC(g_layerInterface->DeinitDisplay(0)); ++ } ++ HAL_LOG_DOFUNC(LayerUninitialize(g_layerInterface)); ++#ifdef KERNEL_USER_MODE ++ sdk_exit(); ++#endif ++ SDK_exit(); ++ g_isInit = false; ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+FREE: -+ free(portInCtx); -+FREE_CHN: -+ (void)AudioUsbSubPortInMngFreeChn(portId); -+ return ret; ++int32_t HalCameraGetModeNum(uint8_t *num) ++{ ++ HAL_ENTER(); ++ LOG_CHK_RETURN_ERR(num == NULL, TD_FAILURE); ++ *num = g_modeInfo.modeNum; ++ HAL_EXIT(); ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortInClose(AudioHandle portHandle) ++int32_t HalCameraSetMode(uint8_t index) +{ -+ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); -+ SubPortInContext *portInCtx = (SubPortInContext *)portHandle; ++ HAL_ENTER(); ++ LOG_CHK_RETURN_ERR(g_isInit == false || index >= g_modeInfo.modeNum, TD_FAILURE); ++ for (int8_t i = 0; i < SUPPORT_MAX_CAMERA_NUM; i++) { ++ if (g_cameraInfo[i].isOpen) { ++ HAL_LOGE("camera is opened: %d\n", i); ++ return TD_FAILURE; ++ } ++ } ++ CameraDestoryVbPool(); ++ g_isInit = false; ++ CameraInitParam(index); ++ g_modeInfo.index = index; ++ HAL_LOG_DOFUNC_RETURN(CameraCreateVbPool()); ++ LOG_CHK_RETURN_ERR(g_layerInterface == NULL, TD_FAILURE); ++ g_isInit = true; ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+ (void)AudioUsbSubPortInMngFreeChn(portInCtx->aiDeviceId); -+ snd_mixer_close(portInCtx->ai_mixer_handle); -+ snd_pcm_drain(portInCtx->ai_pcm_handle); -+ snd_pcm_close(portInCtx->ai_pcm_handle); -+ free(portInCtx); ++int32_t HalCameraSetDeviceDetectCb(const CameraDetectCb cb) ++{ ++ HAL_ENTER(); ++ LOG_CHK_RETURN_ERR(cb == NULL || g_cameraDetect != NULL, TD_FAILURE); ++ g_cameraDetect = cb; ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++int32_t HalCameraGetDeviceNum(uint8_t *num) ++{ ++ HAL_ENTER(); ++ LOG_CHK_RETURN_ERR(num == NULL, TD_FAILURE); ++ *num = g_cameraNum; ++ HAL_EXIT(); ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortInCreateTrack(AudioHandle portHandle, AudioHandle *trackHandle, -+ struct PortPluginAttr *inputAttr, enum AudioPortPin audioPortPin) ++int32_t HalCameraGetDeviceList(char cameraList[][CAMERA_NAME_MAX_LEN], uint8_t listNum) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); -+ SubPortInContext *portInCtx = (SubPortInContext *)portHandle; ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(cameraList); + -+ int32_t trackIndex = AudioUsbSubPortInGetFreeTrack(portInCtx); -+ if (trackIndex == -1) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "can not found free Input Port track"); -+ return MEDIA_HAL_INVALID_PARAM; ++ for (uint8_t i = 0; i < g_cameraNum && i < listNum; i++) { ++ if (snprintf_s(cameraList[i], CAMERA_NAME_MAX_LEN, CAMERA_NAME_MAX_LEN - 1, "%u", i) < 0) { ++ HAL_LOGE("snprintf_s failed\n"); ++ return TD_FAILURE; ++ } + } ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)malloc(sizeof(SubPortTrackInContext)); -+ if (portTrackInCtx == NULL) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "malloc SubPortTrackInContext failed"); -+ return MEDIA_HAL_NO_MEM; -+ } -+ if (memset_s(portTrackInCtx, sizeof(SubPortTrackInContext), 0, -+ sizeof(SubPortTrackInContext)) != 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s SubPortTrackInContext failed"); -+ } -+ // todo zhp -+ SubPortTrackInInit(portTrackInCtx, inputAttr, audioPortPin); ++int32_t HalCameraGetStreamCapNum(const char *camera, uint32_t *num) ++{ ++ HI_CHECK_NULL_PTR(num); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum, TD_FAILURE); ++ *num = CAEMRA_MAX_STREAM_NUM; ++ return TD_SUCCESS; ++} + -+ int32_t ret = AiAttrConfig(inputAttr, &(portTrackInCtx->aiAttr)); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AiAttrConfig %#x", ret); -+ goto FREE_TRACK_IN; ++int32_t HalCameraGetStreamCap(const char *camera, StreamCap *streamCap, uint32_t streamNum) ++{ ++ HAL_ENTER(); ++ LOG_CHK_RETURN_ERR(streamCap == NULL || camera == NULL, TD_FAILURE); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum, TD_FAILURE); ++ uint32_t num; ++ HAL_LOG_DOFUNC_RETURN(HalCameraGetStreamCapNum(camera, &num)); ++ LOG_CHK_RETURN_ERR(streamNum < num, TD_FAILURE); ++ if (streamCap->type == CAP_DESC_RANGE) { ++ ReadRangCap(cameraId, streamCap, num); ++ } else if (streamCap->type == CAP_DESC_ENUM) { ++ ReadEnumCap(cameraId, streamCap, num); + } -+ MEDIA_HAL_LOGE(MODULE_NAME, "aiAttr.bit_width: %d, snd_mode: %d, sample_rate: %d, chn_cnt: %d", portTrackInCtx->aiAttr.bit_width, portTrackInCtx->aiAttr.snd_mode, -+ portTrackInCtx->aiAttr.sample_rate, portTrackInCtx->aiAttr.chn_cnt); -+ snd_pcm_hw_params_t *params; -+ snd_pcm_uframes_t frames = 4096; -+ snd_pcm_hw_params_malloc(¶ms); -+ snd_pcm_hw_params_any(portInCtx->ai_pcm_handle, params); -+ snd_pcm_hw_params_set_access(portInCtx->ai_pcm_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); -+ // todo zhp -+ // snd_pcm_format_t format -+ //AudioConvertFormatToAlsa(aoAttr.bit_width, &format); -+ snd_pcm_hw_params_set_format(portInCtx->ai_pcm_handle, params, SND_PCM_FORMAT_S16_LE); -+ snd_pcm_hw_params_set_channels(portInCtx->ai_pcm_handle, params, portTrackInCtx->aiAttr.chn_cnt); -+ snd_pcm_hw_params_set_rate_near(portInCtx->ai_pcm_handle, params, &(portTrackInCtx->aiAttr.sample_rate), 0); -+ snd_pcm_hw_params_set_period_size_near(portInCtx->ai_pcm_handle, params, &frames, 0); -+ snd_pcm_hw_params(portInCtx->ai_pcm_handle, params); -+ snd_pcm_hw_params_free(params); ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+ // do nothing -+ ret = AiInit(portInCtx, portTrackInCtx->aiAttr); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AiInit failed %#x", ret); -+ goto FREE_TRACK_IN; ++static uint32_t GetCameraCnt(void) ++{ ++ if (g_cameraNum == SUPPORT_MAX_CAMERA_NUM && ++ g_initParam[0].stViAttr.stMipiAttr.devno == g_initParam[1].stViAttr.stMipiAttr.devno) { ++ return 1; ++ } else { ++ return g_cameraNum; + } -+ -+ portTrackInCtx->aiDeviceId = portInCtx->aiDeviceId; -+ portTrackInCtx->aiChn = trackIndex; -+ portTrackInCtx->ai_pcm_handle = portInCtx->ai_pcm_handle; -+ portTrackInCtx->ai_mixer_handle = portInCtx->ai_mixer_handle; -+ portTrackInCtx->ai_elem_vol = portInCtx->ai_elem_vol; -+ portTrackInCtx->ai_min_vol = portInCtx->ai_min_vol; -+ portTrackInCtx->ai_max_vol = portInCtx->ai_max_vol; -+ portTrackInCtx->refAoDevId = -1; -+ portTrackInCtx->refAoChnId = -1; -+ portTrackInCtx->vqeScene = VQE_SCENE_NONE; -+ portTrackInCtx->currentChannelId = PORT_ID(OT_ID_AI, 0, (uint32_t)portTrackInCtx->aiChn); -+ portInCtx->portTrackInCtx[trackIndex] = portTrackInCtx; -+ *trackHandle = &portTrackInCtx->common; -+ -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; -+ -+FREE_TRACK_IN: -+ free(portTrackInCtx); -+ return ret; +} + -+int32_t AudioUsbSubPortInEnableTrack(AudioHandle trackHandle) ++static bool CheckViStart(uint32_t cameraId) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ int32_t ret; -+ ot_ai_chn_param stAiChnParam; -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; -+ MEDIA_HAL_LOGI(MODULE_NAME, "AudioUsbSubPortInEnableTrack in"); -+ -+ ret = snd_pcm_prepare(portTrackInCtx->ai_pcm_handle); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_prepare ret=0x%x", ret); -+ return ret; ++ for (uint32_t i = 0; i < g_cameraNum; i++) { ++ if (i == cameraId) { ++ continue; ++ } ++ if (g_cameraInfo[i].isOpen) { ++ return true; ++ } + } + -+ MEDIA_HAL_LOGI(MODULE_NAME, "AudioUsbSubPortInEnableTrack out"); -+ return MEDIA_HAL_OK; ++ return false; +} + -+int32_t AudioUsbSubPortInAcquireFrame(AudioHandle trackHandle, uint8_t *buffer, uint64_t requestBytes, -+ uint64_t *replyBytes) ++static int32_t CameraStartVpss(const CAMERA_VI_CONFIG_S *viConfig, uint32_t cameraId, ot_vpss_grp vpssGrp) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; -+ int32_t ret; -+ long frames; -+ int bytes_per_sample = (portTrackInCtx->aiAttr.bit_width + 1); // 0:8bit, 1:16bit -+ int channels = (portTrackInCtx->aiAttr.snd_mode == OT_AUDIO_SOUND_MODE_STEREO) ? 2 : 1; -+ int bytes_per_frame = bytes_per_sample * channels; -+ -+ uint64_t remaining_bytes = requestBytes; -+ *replyBytes = 0; -+ -+ while (remaining_bytes > 0) { -+ frames = snd_pcm_readi(portTrackInCtx->ai_pcm_handle, buffer, remaining_bytes / bytes_per_frame); -+ if (frames > 0) { -+ size_t bytes_read = frames * bytes_per_frame; -+ remaining_bytes -= bytes_read; -+ buffer += bytes_read; -+ *replyBytes += bytes_read; -+ } else if (frames == -EAGAIN) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "capture PCM readi -EAGAIN"); -+ snd_pcm_wait(portTrackInCtx->ai_pcm_handle, 100); -+ } else if (frames == -EBADFD) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "capture PCM bad state, preparing..."); -+ snd_pcm_prepare(portTrackInCtx->ai_pcm_handle); -+ return MEDIA_HAL_ERR; -+ } else { -+ MEDIA_HAL_LOGE(MODULE_NAME, "capture err: %s", snd_strerror(frames)); -+ ret = snd_pcm_recover(portTrackInCtx->ai_pcm_handle, frames, 0); -+ if (ret < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "capture recover failed: %s", snd_strerror(ret)); -+ return MEDIA_HAL_ERR; -+ } -+ } ++ CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; ++ InitParam *initParam = &g_initParam[cameraId]; ++ uint32_t cameraCnt = GetCameraCnt(); ++ bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM] = { 0 }; ++ ot_vpss_grp_attr vpssGrpAttr; ++ /* config vpss group */ ++ CameraGetVpssGrpConfig(&vpssGrpAttr, initParam); ++ /* config vpss chn */ ++ ot_vpss_chn_attr vpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM]; ++ CameraGetVpssChnConfig(vpssChnAttr, chnEnable, initParam); ++ /* start vpss */ ++ int32_t ret = CameraVideoProcStart(vpssGrp, chnEnable, &vpssGrpAttr, vpssChnAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("start vpss group failed. ret: 0x%x !\n", ret); ++ return ret; + } -+ *replyBytes = requestBytes; -+ return MEDIA_HAL_OK; ++ /* vi bind vpss */ ++ ot_vi_chn viChn = 0; ++ ot_vi_pipe viPipe; ++ if (g_cameraNum == SUPPORT_MAX_CAMERA_NUM && cameraCnt == 1) { ++ viPipe = viConfig[0].stPipeInfo.aPipe[0]; ++ } else { ++ viPipe = viConfig[cameraId].stPipeInfo.aPipe[0]; ++ } ++ ret = CameraViBindVproc(viPipe, viChn, vpssGrp); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("vi bind vpss failed. ret: 0x%x !\n", ret); ++ CameraVideoProcStop(vpssGrp, chnEnable); ++ return ret; ++ } ++ cameraInfo->vpssGrp = vpssGrp; ++ return ret; +} + -+int32_t AudioUsbSubPortInGetPosition(AudioHandle trackHandle, -+ uint64_t *frames, struct AudioTimeStamp *time) ++static void CameraStopVpss(const CAMERA_VI_CONFIG_S *viConfig, uint32_t cameraId) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; -+ -+ time->tvSec = portTrackInCtx->aiTimeStamp.tvSec; -+ time->tvNSec = portTrackInCtx->aiTimeStamp.tvNSec; -+ *frames = portTrackInCtx->frames; -+ return MEDIA_HAL_OK; ++ CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; ++ InitParam *initParam = &g_initParam[cameraId]; ++ uint32_t cameraCnt = GetCameraCnt(); ++ ot_vi_pipe viPipe; ++ if (g_cameraNum == SUPPORT_MAX_CAMERA_NUM && cameraCnt == 1) { ++ viPipe = viConfig[0].stPipeInfo.aPipe[0]; ++ } else { ++ viPipe = viConfig[cameraId].stPipeInfo.aPipe[0]; ++ } ++ ot_vi_chn viChn = 0; ++ ot_vpss_grp vpssGrp = cameraInfo->vpssGrp; ++ CameraViUnBindVproc(viPipe, viChn, vpssGrp); ++ bool chnEnable[OT_VPSS_MAX_PHYS_CHN_NUM] = { 0 }; ++ ot_vpss_chn_attr astVpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM]; ++ CameraGetVpssChnConfig(astVpssChnAttr, chnEnable, initParam); ++ DisableVpssExtChn(vpssGrp); ++ CameraVideoProcStop(vpssGrp, chnEnable); ++ cameraInfo->vpssGrp = -1; +} + -+int32_t AudioUsbSubPortInDisableTrack(AudioHandle trackHandle) ++int32_t HalCameraDeviceOpen(const char *camera) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ HAL_ENTER(); ++ HI_PRINTF(" open camera = %s\n", camera); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum, TD_FAILURE); ++ /* get vi config */ ++ int32_t ret; ++ CAMERA_VI_CONFIG_S viConfig[SUPPORT_MAX_CAMERA_NUM] = { 0 }; ++ CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; ++ InitParam *initParam = &g_initParam[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->isOpen == true, TD_SUCCESS); ++ cameraInfo->type = initParam->stViAttr.sensorType; ++ ++ uint32_t cameraCnt = GetCameraCnt(); ++ CameraGetViConfig(viConfig, cameraCnt); ++ HI_PRINTF("lib0:%s, obj0:%s, len0:%u\n", initParam->stViAttr.sensorLib, ++ initParam->stViAttr.sensorObj, viConfig[0].len); ++ ot_vpss_grp vpssGrp = 0; ++ if (CheckViStart(cameraId)) { ++ HI_PRINTF("Vi is Started. Next, bind the vpssGrp.\n"); ++ vpssGrp = 1; ++ } else { ++ /* start vi */ ++ ret = CameraStartVi(viConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("start vi failed.ret:0x%x !\n", ret); ++ goto EXIT; ++ } ++ } + ++ if (cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { ++ ret = CameraStartVpss(viConfig, cameraId, vpssGrp); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("CameraStartVpss failed. ret:0x%x !\n", ret); ++ goto EXIT1; ++ } ++ } + -+ snd_pcm_drain(portTrackInCtx->ai_pcm_handle); -+ portTrackInCtx->refAoDevId = -1; -+ portTrackInCtx->refAoChnId = -1; -+ portTrackInCtx->vqeScene = VQE_SCENE_NONE; ++ cameraInfo->isOpen = true; ++ HAL_EXIT(); ++ return TD_SUCCESS; + -+ return MEDIA_HAL_OK; ++EXIT1: ++ if (!CheckViStart(cameraId)) { ++ CameraStopVi(viConfig, cameraCnt); ++ } ++EXIT: ++ return ret; +} + -+int32_t AudioUsbSubPortInDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle) ++int32_t HalCameraDeviceClose(const char *camera) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); -+ SubPortInContext *portInCtx = (SubPortInContext *)portHandle; -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; -+ -+ -+ int32_t ret = AudioUsbSubPortInFreeTrack(portInCtx, portTrackInCtx); -+ if (ret == -1) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "invalid trackHandle"); -+ return MEDIA_HAL_INVALID_PARAM; ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ HI_PRINTF("cameraId=%u\n", cameraId); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum, TD_FAILURE); ++ CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->isOpen == false, TD_SUCCESS); ++ CAMERA_VI_CONFIG_S viConfig[SUPPORT_MAX_CAMERA_NUM] = {}; ++ uint32_t cameraCnt = GetCameraCnt(); ++ CameraGetViConfig(viConfig, cameraCnt); ++ ++ if (cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { ++ CameraStopVpss(viConfig, cameraId); ++ } ++ if (!CheckViStart(cameraId)) { ++ CameraStopVi(&viConfig, cameraCnt); + } ++ cameraInfo->isOpen = false; ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + ++int32_t HalCameraStreamCreate(const char *camera, const StreamAttr *stream, uint32_t *streamId) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(stream == NULL || streamId == NULL || cameraId >= g_cameraNum, TD_FAILURE); ++ ControlInfo config = { 0 }; ++ config.maxW = g_initParam[cameraId].stViAttr.stChnAttr[0][0].size.width; ++ config.maxH = g_initParam[cameraId].stViAttr.stChnAttr[0][0].size.height; ++ if (config.maxW > MAX_FRAME_WIDTH || config.maxH > MAX_FRAME_WIDTH) { ++ HI_PRINTF("maxW maxH param invalid\n"); ++ return TD_FAILURE; ++ } ++ HAL_LOG_DOFUNC_RETURN(ParamCheck(stream, &config)); ++ ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ config.vpssGrp = cameraInfo->vpssGrp; ++ uint32_t streamIndex = 0; ++ ot_vpss_chn vpssChn = -1; ++ ot_vpss_chn vpssPhyChn = -1; ++ ot_vpss_chn sameChn = -1; ++ HAL_LOG_DOFUNC_RETURN(GetFreeStreamIndex(cameraInfo, &streamIndex)); ++ ++ if (CheckSameChn(cameraInfo, stream, &sameChn) == TD_SUCCESS) { ++ vpssChn = sameChn; ++ } else if (cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { ++ GetVpss(stream, cameraInfo, &vpssChn, &vpssPhyChn); ++ if (vpssChn == -1 && vpssPhyChn == -1) { ++ HI_PRINTF(" GetVpss failed, vpssChn=%d\n", vpssChn); ++ return TD_FAILURE; ++ } ++ ConvetToControlInfo(vpssChn, stream, &config); ++ td_s32 ret = CreateStream(vpssChn, vpssPhyChn, stream, &config); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("CreateStream failed ret:%d\n", ret); ++ return TD_FAILURE; ++ } ++ } ++ AddStream(cameraInfo, streamIndex, vpssChn, stream); ++ *streamId = streamIndex; ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+ free(portTrackInCtx); -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++int32_t HalCameraGetDeviceId(const char *camera, uint32_t streamId, uint32_t *deviceId) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || deviceId == NULL, TD_FAILURE); ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); ++ *deviceId = GetDeviceId((uint32_t)cameraInfo->internalStreamInfo[streamId].vpssChn); ++ HAL_EXIT(); ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortInInvoke(AudioHandle trackHandle, enum InvokeID invokeID, struct InvokeAttr *invokeAttr) ++int32_t HalCameraStreamDestroy(const char *camera, uint32_t streamId) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ int32_t ret = MEDIA_HAL_OK; -+ SubPortTrackInContext *portTrackInCtx = (SubPortTrackInContext *)trackHandle; ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM, TD_FAILURE); ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); ++ DeleteStream(cameraInfo, streamId); ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+ switch (invokeID) { ++int32_t HalCameraStreamOn(const char *camera, uint32_t streamId) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM, TD_FAILURE); ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); ++ if (cameraInfo->streamAttr[streamId].type == STREAM_PREVIEW && cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { ++ HAL_LOG_DOFUNC_RETURN(EnablePreview(cameraInfo->internalStreamInfo[streamId].vpssChn, ++ cameraId, ++ &cameraInfo->internalStreamInfo[streamId].pos, ++ &cameraInfo->streamAttr[streamId])); ++ } ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+ default: -+ MEDIA_HAL_LOGW(MODULE_NAME, "Invalid invokeID: %d", invokeID); -+ return MEDIA_HAL_INVALID_PARAM; ++int32_t HalCameraStreamOff(const char *camera, uint32_t streamId) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM, TD_FAILURE); ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); ++ if (cameraInfo->streamAttr[streamId].type == STREAM_PREVIEW && cameraInfo->type != CAM_TYPE_TRUE_DEAPTH) { ++ DisablePreview(cameraInfo->internalStreamInfo[streamId].vpssChn, cameraId); + } -+ return MEDIA_HAL_OK; ++ HAL_EXIT(); ++ return TD_SUCCESS; +} + -+#ifdef __cplusplus -+#if __cplusplus ++int32_t HalCameraDequeueBuf(const char *camera, uint32_t streamId, HalBuffer *buffer) ++{ ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || buffer == NULL, TD_FAILURE); ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); ++ ot_vpss_grp vpssGrp = 0; ++ if (buffer->format == FORMAT_PRIVATE) { ++ SetChnDepth(&(cameraInfo->internalStreamInfo[streamId]), buffer->format); ++ HAL_LOG_DOFUNC_RETURN(ss_mpi_vpss_get_chn_frame(vpssGrp, cameraInfo->internalStreamInfo[streamId].vpssChn, ++ &cameraInfo->internalStreamInfo[streamId].videoFrame, FRAME_TIME_OUT)); ++ } else { ++ buffer->format = cameraInfo->streamAttr[streamId].format; ++ SetChnDepth(&(cameraInfo->internalStreamInfo[streamId]), buffer->format); ++ if (buffer->format == FORMAT_YVU420) { ++ HAL_LOG_DOFUNC_RETURN(ss_mpi_vpss_get_chn_frame(vpssGrp, cameraInfo->internalStreamInfo[streamId].vpssChn, ++ &cameraInfo->internalStreamInfo[streamId].videoFrame, FRAME_TIME_OUT)); ++ } else if (buffer->format == FORMAT_RGB_BAYER_12BPP) { ++ HAL_LOG_DOFUNC_RETURN(ss_mpi_vi_get_pipe_frame(0, &cameraInfo->internalStreamInfo[streamId].videoFrame, ++ FRAME_TIME_OUT)); ++ } else { ++ HAL_LOGI("not support format\n"); ++ return TD_FAILURE; ++ } ++ } ++ CovertToBuffer(&cameraInfo->internalStreamInfo[streamId].videoFrame, buffer); ++ return TD_SUCCESS; +} -+#endif -+#endif /* __cplusplus */ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.h ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.h ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.h 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_in/audio_usb_sub_port_in.h 2025-11-07 14:44:54.877657238 +0800 -@@ -0,0 +1,63 @@ -+ /* -+ * Copyright (c) 2024 RKH Corp. -+ * 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. -+ */ + -+#ifndef AUDIO_PRIMARY_SUB_PORT_IN_H -+#define AUDIO_PRIMARY_SUB_PORT_IN_H ++int32_t HalCameraQueueBuf(const char *camera, uint32_t streamId, const HalBuffer *buffer) ++{ ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || buffer == NULL, TD_FAILURE); ++ ot_vpss_grp vpssGrp = 0; ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); ++ if (buffer->format == FORMAT_PRIVATE) { ++ HAL_LOG_DOFUNC_RETURN(ss_mpi_vpss_release_chn_frame(vpssGrp, cameraInfo->internalStreamInfo[streamId].vpssChn, ++ &cameraInfo->internalStreamInfo[streamId].videoFrame)); ++ return TD_SUCCESS; ++ } ++ HAL_LOG_DOFUNC(ss_mpi_sys_munmap(buffer->virAddr, buffer->size)); ++ if (buffer->format == FORMAT_YVU420) { ++ HAL_LOG_DOFUNC_RETURN(ss_mpi_vpss_release_chn_frame(vpssGrp, cameraInfo->internalStreamInfo[streamId].vpssChn, ++ &cameraInfo->internalStreamInfo[streamId].videoFrame)); ++ } else if (buffer->format == FORMAT_RGB_BAYER_12BPP) { ++ HAL_LOG_DOFUNC_RETURN(ss_mpi_vi_release_pipe_frame(0, &cameraInfo->internalStreamInfo[streamId].videoFrame)); ++ } else { ++ HAL_LOGI("not support format\n"); ++ return TD_FAILURE; ++ } ++ return TD_SUCCESS; ++} + -+#include "audio_port_plugin.h" ++int32_t HalCameraSetBufferCallback(const char *camera, const BufferAvailable callback) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || callback == NULL, TD_FAILURE); ++ CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->bufferCallBack != NULL, TD_FAILURE); ++ cameraInfo->bufferCallBack = callback; ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+#ifdef __cplusplus -+#if __cplusplus -+extern "C" { -+#endif -+#endif /* End of __cplusplus */ ++int32_t HalCameraStreamSetInfo(const char *camera, uint32_t streamId, const StreamInfo *info) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || info == NULL, TD_FAILURE); ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); ++ if (info->type == STREAM_INFO_POS) { ++ cameraInfo->internalStreamInfo[streamId].pos.x = info->u.pos.x; ++ cameraInfo->internalStreamInfo[streamId].pos.y = info->u.pos.y; ++ } else { ++ HAL_LOGI("not support now\n"); ++ } ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+/* sub port in track api */ -+int32_t AudioUsbSubPortInGetFrameCount(AudioHandle trackHandle, uint64_t *count); ++int32_t HalCameraStreamGetInfo(const char *camera, uint32_t streamId, StreamInfo *info) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || streamId >= CAEMRA_MAX_STREAM_NUM || info == NULL, TD_FAILURE); ++ CameraInfo* cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->internalStreamInfo[streamId].isUsed == false, TD_FAILURE); ++ if (info->type == STREAM_INFO_POS) { ++ info->u.pos.x = cameraInfo->internalStreamInfo[streamId].pos.x; ++ info->u.pos.y = cameraInfo->internalStreamInfo[streamId].pos.y; ++ } else { ++ HAL_LOGI("not support now\n"); ++ } ++ HAL_LOGI("not support now\n"); ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+int32_t AudioUsbSubPortInEnableTrack(AudioHandle trackHandle); -+int32_t AudioUsbSubPortInDisableTrack(AudioHandle trackHandle); ++int32_t HalCameraDeviceSetInfo(const char *camera, const DeviceInfo *info) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || info == NULL, TD_FAILURE); ++ HAL_LOGI("not support now\n"); ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+int32_t AudioUsbSubPortInAcquireFrame(AudioHandle trackHandle, uint8_t *buffer, -+ uint64_t requestBytes, uint64_t *replyBytes); ++int32_t HalCameraDeviceGetInfo(const char *camera, DeviceInfo *info) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || info == NULL, TD_FAILURE); ++ HAL_LOGI("not support now\n"); ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+int32_t AudioUsbSubPortInGetPosition(AudioHandle trackHandle, -+ uint64_t *frames, struct AudioTimeStamp *time); ++int32_t HalCameraGetAbility(const char *camera, AbilityInfo *ability) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || ability == NULL, TD_FAILURE); ++ HAL_LOG_DOFUNC(memset_s(ability, sizeof(AbilityInfo), 0, sizeof(AbilityInfo))); ++ if (cameraId == 0) { ++ HAL_LOG_DOFUNC(strncpy_s(ability->cameraDesc, DESC_MAX_LEN - 1, CAMERA_RGB, sizeof(CAMERA_RGB))); ++ ability->type = CAM_TYPE_WIDE_ANGLE; ++ } else { ++ HAL_LOG_DOFUNC(strncpy_s(ability->cameraDesc, DESC_MAX_LEN - 1, CAMERA_TOF, sizeof(CAMERA_TOF))); ++ ability->type = CAM_TYPE_TRUE_DEAPTH; ++ } ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+int32_t AudioUsbSubPortInSetMute(AudioHandle trackHandle, bool mute); -+int32_t AudioUsbSubPortInGetMute(AudioHandle trackHandle, bool *mute); ++int32_t HalCameraSetResultCb(const char *camera, CameraResultCb cb) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ char *endPtr = NULL; ++ uint32_t cameraId = (uint32_t)strtol(camera, &endPtr, NUMBER_BASE_10); ++ LOG_CHK_RETURN_ERR(endPtr == camera || *endPtr != '\0', TD_FAILURE); ++ LOG_CHK_RETURN_ERR(cameraId >= g_cameraNum || cb == NULL, TD_FAILURE); ++ CameraInfo *cameraInfo = &g_cameraInfo[cameraId]; ++ LOG_CHK_RETURN_ERR(cameraInfo->resultCb != NULL, TD_FAILURE); ++ cameraInfo->resultCb = cb; ++ HAL_EXIT(); ++ return TD_SUCCESS; ++} + -+int32_t AudioUsbSubPortInSetVolume(AudioHandle trackHandle, float volume); -+int32_t AudioUsbSubPortInGetVolume(AudioHandle trackHandle, float *volume); ++int32_t HalCameraUpdateSaturationMode(const char *value, uint32_t len) ++{ ++ int32_t saturationMode; ++ int32_t saturationValue; ++ int32_t ret = sscanf_s(value, "%d#%d", &saturationMode, &saturationValue); ++ if (ret == -1 || ret == 0 || ret == 1) { ++ HAL_LOGE("saturation mode sscanf_s failed!"); ++ return ret; ++ } ++ ot_vi_pipe viPipe = 0; ++ ot_isp_saturation_attr satAttr; ++ ss_mpi_isp_get_saturation_attr(viPipe, &satAttr); ++ if (saturationMode == CAMERA_ATTR_OP_MODE_MANUAL) { ++ satAttr.op_type = OT_OP_MODE_MANUAL; ++ satAttr.manual_attr.saturation = saturationValue; ++ ret = ss_mpi_isp_set_saturation_attr(viPipe, &satAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set exposure attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateSaturationMode: set saturation mode MANUAL success!"); ++ } else if (saturationMode == CAMERA_ATTR_OP_MODE_AUTO) { ++ satAttr.op_type = OT_OP_MODE_AUTO; ++ ret = ss_mpi_isp_set_saturation_attr(viPipe, &satAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set auto exposure attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateSaturationMode: set saturation mode AUTO success!"); ++ } else { ++ HAL_LOGE("not support saturation mode = %d", saturationMode); ++ ret = TD_FAILURE; ++ } ++ return ret; ++} + -+int32_t AudioUsbSubPortInInvoke(AudioHandle trackHandle, enum InvokeID invokeID, struct InvokeAttr *invokeAttr); ++int32_t HalCameraUpdateSharpenMode(const char *value, uint32_t len) ++{ ++ int32_t sharpenMode; ++ int32_t sharpenValue; ++ int32_t ret = sscanf_s(value, "%d#%d", &sharpenMode, &sharpenValue); ++ if (ret == -1 || ret == 0 || ret == 1) { ++ HAL_LOGE("sharpen mode sscanf_s failed!"); ++ return ret; ++ } ++ ot_vi_pipe viPipe = 0; ++ ot_isp_sharpen_attr shpAttr; ++ ss_mpi_isp_get_sharpen_attr(viPipe, &shpAttr); ++ if (sharpenMode == CAMERA_ATTR_OP_MODE_MANUAL) { ++ shpAttr.op_type = OT_OP_MODE_MANUAL; ++ shpAttr.manual_attr.max_sharp_gain = sharpenValue; ++ ret = ss_mpi_isp_set_sharpen_attr(viPipe, &shpAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set sharpen attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateSharpenMode: set sharpen mode MANUAL success!\n"); ++ } else if (sharpenMode == CAMERA_ATTR_OP_MODE_AUTO) { ++ shpAttr.op_type = OT_OP_MODE_AUTO; ++ ret = ss_mpi_isp_set_sharpen_attr(viPipe, &shpAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set auto sharpen attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateSharpenMode: set sharpen mode AUTO success!"); ++ } else { ++ HAL_LOGE("not support sharpen mode = %d", sharpenMode); ++ ret = TD_FAILURE; ++ } ++ return ret; ++} + -+/* sub port in api */ -+int32_t AudioUsbSubPortInOpen(AudioHandle *portHandle, int card_usb); -+int32_t AudioUsbSubPortInClose(AudioHandle portHandle); ++int32_t HalCameraUpdateDrcMode(const char *value, uint32_t len) ++{ ++ int32_t drcMode; ++ int32_t drcValue; ++ int32_t ret = sscanf_s(value, "%d#%d", &drcMode, &drcValue); ++ if (ret == -1 || ret == 0 || ret == 1) { ++ HAL_LOGE("drc mode sscanf_s failed!"); ++ return ret; ++ } ++ ot_vi_pipe viPipe = 0; ++ ot_isp_drc_attr drcAttr; ++ ss_mpi_isp_get_drc_attr(viPipe, &drcAttr); ++ if (drcMode == CAMERA_ATTR_OP_MODE_MANUAL) { ++ drcAttr.enable = true; ++ drcAttr.op_type = OT_OP_MODE_MANUAL; ++ drcAttr.manual_attr.strength = drcValue; ++ ret = ss_mpi_isp_set_drc_attr(viPipe, &drcAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set drc attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateDrcMode: set drc mode MANUAL success!"); ++ } else if (drcMode == CAMERA_ATTR_OP_MODE_AUTO) { ++ drcAttr.enable = false; ++ drcAttr.op_type = OT_OP_MODE_AUTO; ++ ret = ss_mpi_isp_set_drc_attr(viPipe, &drcAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set auto drc attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateDrcMode: set drc mode AUTO success!"); ++ } else { ++ HAL_LOGE("not support drc mode = %d", drcMode); ++ ret = TD_FAILURE; ++ } ++ return ret; ++} + -+int32_t AudioUsbSubPortInGetCapability(const struct AudioPort *port, struct AudioPortCapability *capability); ++int32_t HalCameraUpdateWbMode(const char *value, uint32_t len) ++{ ++ int32_t wbMode; ++ int32_t wbValue; ++ int32_t ret = sscanf_s(value, "%d#%d", &wbMode, &wbValue); ++ if (ret == -1 || ret == 0 || ret == 1) { ++ HAL_LOGE("wb mode sscanf_s failed!"); ++ return ret; ++ } ++ ot_vi_pipe viPipe = 0; ++ ot_isp_wb_attr wbAttr; ++ ss_mpi_isp_get_wb_attr(viPipe, &wbAttr); ++ if (wbMode == CAMERA_ATTR_OP_MODE_MANUAL) { ++ wbAttr.op_type = OT_OP_MODE_MANUAL; ++ wbAttr.manual_attr.r_gain = wbValue; ++ ret = ss_mpi_isp_set_wb_attr(viPipe, &wbAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set wb attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateWbMode: set wb mode MANUAL success!"); ++ } else if (wbMode == CAMERA_ATTR_OP_MODE_AUTO) { ++ wbAttr.op_type = OT_OP_MODE_AUTO; ++ ret = ss_mpi_isp_set_wb_attr(viPipe, &wbAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set auto sharpen attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateWbMode: set wb mode AUTO success!"); ++ } else { ++ HAL_LOGE("not support wb mode = %d", wbMode); ++ ret = TD_FAILURE; ++ } ++ return ret; ++} + -+int32_t AudioUsbSubPortInCreateTrack(AudioHandle portHandle, AudioHandle *trackHandle, -+ struct PortPluginAttr *inputAttr, enum AudioPortPin audioPortPin); -+int32_t AudioUsbSubPortInDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle); ++int32_t HalCameraUpdateExposureMode(const char *value, uint32_t len) ++{ ++ int32_t exposureMode; ++ int32_t exposureValue; ++ int32_t ret = sscanf_s(value, "%d#%d", &exposureMode, &exposureValue); ++ if (ret == -1 || ret == 0 || ret == 1) { ++ HAL_LOGE("exposure mode sscanf_s failed!"); ++ return ret; ++ } ++ ot_vi_pipe viPipe = 0; ++ ot_isp_exposure_attr expAttr; ++ ss_mpi_isp_get_exposure_attr(viPipe, &expAttr); ++ if (exposureMode == CAMERA_ATTR_OP_MODE_MANUAL) { ++ expAttr.bypass = TD_FALSE; ++ expAttr.op_type = OT_OP_MODE_MANUAL; ++ expAttr.manual_attr.a_gain_op_type = OT_OP_MODE_MANUAL; ++ expAttr.manual_attr.d_gain_op_type = OT_OP_MODE_MANUAL; ++ expAttr.manual_attr.ispd_gain_op_type = OT_OP_MODE_MANUAL; ++ expAttr.manual_attr.exp_time_op_type = OT_OP_MODE_MANUAL; ++ expAttr.manual_attr.isp_d_gain = exposureValue; ++ ret = ss_mpi_isp_set_exposure_attr(viPipe, &expAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set exposure attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateExposureMode: set exposure mode MANUAL success!"); ++ } else if (exposureMode == CAMERA_ATTR_OP_MODE_AUTO) { ++ expAttr.bypass = TD_FALSE; ++ expAttr.op_type = OT_OP_MODE_AUTO; ++ ret = ss_mpi_isp_set_exposure_attr(viPipe, &expAttr); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("set auto exposure attr failed ret = %d", ret); ++ return TD_FAILURE; ++ } ++ HAL_LOGI("HalCameraUpdateExposureMode: set exposure mode AUTO success!"); ++ } else { ++ HAL_LOGE("not support exposure mode = %d", exposureMode); ++ ret = TD_FAILURE; ++ } ++ return ret; ++} + -+#ifdef __cplusplus -+#if __cplusplus ++int32_t HalCameraUpdateSettings(const char *camera, const char *value, uint32_t len) ++{ ++ HAL_ENTER(); ++ HI_CHECK_NULL_PTR(camera); ++ HI_CHECK_NULL_PTR(value); ++ char keyFlag[MAX_KEY_STR_SIZE] = { 0 }; ++ char valueFlag[MAX_KEY_VALUE_SIZE] = { 0 }; ++ int32_t ret = sscanf_s(value, "%s = %s", keyFlag, MAX_KEY_STR_SIZE, ++ valueFlag, MAX_KEY_VALUE_SIZE); ++ if (ret == -1) { ++ HAL_LOGE("sscanf_s failed, ret = % d", ret); ++ return ret; ++ } ++ if (strcmp(keyFlag, KEY_EXPOSURE_MODE) == 0) { ++ ret = HalCameraUpdateExposureMode(valueFlag, MAX_KEY_VALUE_SIZE); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("Update exposure mode failed!"); ++ return ret; ++ } ++ } else if (strcmp(keyFlag, KEY_SATURATION_MODE) == 0) { ++ ret = HalCameraUpdateSaturationMode(valueFlag, MAX_KEY_VALUE_SIZE); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("Update saturation mode failed!"); ++ return ret; ++ } ++ } else if (strcmp(keyFlag, KEY_SHARPEN_MODE) == 0) { ++ ret = HalCameraUpdateSharpenMode(valueFlag, MAX_KEY_VALUE_SIZE); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("Update sharpen mode failed!"); ++ return ret; ++ } ++ } else if (strcmp(keyFlag, KEY_DRC_MODE) == 0) { ++ ret = HalCameraUpdateDrcMode(valueFlag, MAX_KEY_VALUE_SIZE); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("Update drc mode failed!"); ++ return ret; ++ } ++ } else if (strcmp(keyFlag, KEY_WB_MODE) == 0) { ++ ret = HalCameraUpdateWbMode(valueFlag, MAX_KEY_VALUE_SIZE); ++ if (ret != TD_SUCCESS) { ++ HAL_LOGE("Update wb mode failed!"); ++ return ret; ++ } ++ } else { ++ HAL_LOGE("Unsupported Parameter Settings!"); ++ } ++ return TD_SUCCESS; +} -+#endif -+#endif /* __cplusplus */ + -+#endif /* AUDIO_INPUT_PORT_PLUGIN_IMPL_H */ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.c ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.c 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.c 2025-11-07 14:44:54.877657238 +0800 -@@ -0,0 +1,816 @@ -+ /* -+ * Copyright (c) 2024 RKH Corp. ++static HalCameraManager g_localHalCameraManager = { ++ .HalCameraInit = HalCameraInit, ++ .HalCameraDeinit = HalCameraDeinit, ++ .HalCameraGetModeNum = HalCameraGetModeNum, ++ .HalCameraSetMode = HalCameraSetMode, ++ .HalCameraSetDeviceDetectCb = HalCameraSetDeviceDetectCb, ++ .HalCameraGetDeviceNum = HalCameraGetDeviceNum, ++ .HalCameraGetDeviceList = HalCameraGetDeviceList, ++ .HalCameraGetStreamCapNum = HalCameraGetStreamCapNum, ++ .HalCameraGetStreamCap = HalCameraGetStreamCap, ++ .HalCameraDeviceOpen = HalCameraDeviceOpen, ++ .HalCameraDeviceClose = HalCameraDeviceClose, ++ .HalCameraStreamCreate = HalCameraStreamCreate, ++ .HalCameraStreamDestroy = HalCameraStreamDestroy, ++ .HalCameraGetDeviceId = HalCameraGetDeviceId, ++ .HalCameraStreamOn = HalCameraStreamOn, ++ .HalCameraStreamOff = HalCameraStreamOff, ++ .HalCameraDequeueBuf = HalCameraDequeueBuf, ++ .HalCameraQueueBuf = HalCameraQueueBuf, ++ .HalCameraSetBufferCallback = HalCameraSetBufferCallback, ++ .HalCameraStreamSetInfo = HalCameraStreamSetInfo, ++ .HalCameraStreamGetInfo = HalCameraStreamGetInfo, ++ .HalCameraDeviceSetInfo = HalCameraDeviceSetInfo, ++ .HalCameraDeviceGetInfo = HalCameraDeviceGetInfo, ++ .HalCameraGetAbility = HalCameraGetAbility, ++ .HalCameraSetResultCb = HalCameraSetResultCb, ++ .HalCameraUpdateSettings = HalCameraUpdateSettings, ++}; ++ ++HalCameraManager *GetHalCameraFuncs(void) ++{ ++ return &g_localHalCameraManager; ++} +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_comm.h ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_comm.h +--- ohos/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_comm.h 2025-12-18 15:14:06.900482931 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_comm.h 2025-12-18 15:44:30.870238524 +0800 +@@ -1,308 +1,308 @@ +-/* +- * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. +- * +- * 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. +- */ +- +-#ifndef OHOS_CAMERA_COMM_H +-#define OHOS_CAMERA_COMM_H +- +- +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +- +-#include "ot_type.h" +-#include "ot_buffer.h" +-#include "ot_common_adec.h" +-#include "ot_common_aenc.h" +-#include "ot_common_aio.h" +-#include "ot_common_isp.h" +-#include "ot_common_region.h" +-#include "ot_common_sys.h" +-#include "ot_common_vb.h" +-#include "ot_common_venc.h" +-#include "ot_common_vgs.h" +-#include "ot_common_vi.h" +-#include "ot_common_vo.h" +-#include "ot_common_vpss.h" +-#include "ot_common.h" +-#include "ot_defines.h" +-#include "ot_math.h" +-#include "ot_mipi_rx.h" +-#include "ot_sns_ctrl.h" +-#include "ss_mpi_ae.h" +-#include "ss_mpi_audio.h" +-#include "ss_mpi_awb.h" +-#include "ss_mpi_isp.h" +-#include "ss_mpi_region.h" +-#include "ss_mpi_sys.h" +-#if !defined (__SS928V100__) +-#include "ss_mpi_sys_bind.h" +-#include "ss_mpi_sys_mem.h" +-#endif +-#include "ss_mpi_vb.h" +-#include "ss_mpi_venc.h" +-#include "ss_mpi_vgs.h" +-#include "ss_mpi_vi.h" +-#include "ss_mpi_vo.h" +-#include "ss_mpi_vpss.h" +- +-#ifdef HAVE_DISPLAY +-#include "ot_mipi_tx.h" +-#endif +- +-#ifdef __cplusplus +-#if __cplusplus +-extern "C" { +-#endif +-#endif /* End of #ifdef __cplusplus */ +- +-/* ****************************************************** +- macro define +-****************************************************** */ +-#define FILE_NAME_LEN 128 +- +-#define CHECK_CHN_RET(express, Chn, name) \ +- do { \ +- int32_t Ret; \ +- Ret = express; \ +- if (TD_SUCCESS != Ret) { \ +- printf("\033[0;31m%s chn %d failed at %s: LINE: %d with %#x!\033[0;39m\n", name, Chn, __FUNCTION__, \ +- __LINE__, Ret); \ +- fflush(stdout); \ +- return Ret; \ +- } \ +- } while (0) +- +-#define CHECK_RET(express, name) \ +- do { \ +- int32_t Ret; \ +- Ret = express; \ +- if (TD_SUCCESS != Ret) { \ +- printf("\033[0;31m%s failed at %s: LINE: %d with %#x!\033[0;39m\n", name, __FUNCTION__, __LINE__, Ret); \ +- return Ret; \ +- } \ +- } while (0) +-#define HISI_PIXEL_FORMAT OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420 +-#define SENSOR_DESC_MAX_LEN 64 +-#define WDR_MAX_PIPE_NUM 4 +-#define MAX_CHN_NUM_PER_PIPE 2 +-#define MAX_FRAME_WIDTH 8192 +- +-#ifndef __HuaweiLite__ +-#define VI_DATA_PATH "." +-#else +-#define VI_DATA_PATH "/sharefs" +-#endif +- +-#define SUCCESS 0 +-#define FAILURE (-1) +- +-#define DEBUG_LOG_SWITCH 1 +-#define INFO_LOG_SWITCH 1 +-#define ERROR_LOG_SWITCH 1 +-#define TAG "CamHal" +-#ifdef ERROR_LOG_SWITCH +-#define HAL_LOGE(fmt, args...) do { \ +- printf("E: %s %s-%d: " fmt, TAG, __func__, __LINE__, ##args); \ +- } while (0) +- +-#define HAL_LOGI(fmt, args...) do { \ +- printf("I: %s %s-%d: " fmt, TAG, __func__, __LINE__, ##args); \ +- } while (0) +- +-#define HAL_LOGD(fmt, args...) do { \ +- printf("D: %s %s-%d: " fmt, TAG, __func__, __LINE__, ##args); \ +- } while (0) +-#else +-#define HAL_LOGE(...) +-#define HAL_LOGI(...) +-#define HAL_LOGD(...) +-#endif +- +-#define HAL_ENTER() HAL_LOGI("enter\n") +-#define HAL_EXIT() HAL_LOGI("exit\n") +-#define LOG_CHK_RETURN(val) \ +- do { \ +- if ((val)) { \ +- HAL_LOGE("\n"); \ +- return; \ +- }; \ +- } while (0) +- +-#define LOG_CHK_RETURN_ERR(val, ret) \ +- do { \ +- if ((val)) { \ +- HAL_LOGE("\n"); \ +- return ret; \ +- } \ +- } while (0) +- +-#define HI_PRINTF(fmt...) do { \ +- printf("[%s]-%d: ", __FUNCTION__, __LINE__); \ +- printf(fmt); \ +- } while (0) +- +-#define HAL_LOG_DOFUNC(func) \ +- do { \ +- int32_t ret = func; \ +- if (ret != 0) { \ +- printf("[%s]-%d: error = 0x%x", __FUNCTION__, __LINE__, ret); \ +- } \ +- } while (0) +- +-#define HAL_LOG_DOFUNC_RETURN(func) \ +- do { \ +- int32_t ret = func; \ +- if (ret != 0) { \ +- printf("[%s]-%d: error = 0x%x", __FUNCTION__, __LINE__, ret); \ +- return ret; \ +- } \ +- } while (0) +- +-#define HI_CHECK_NULL_PTR(ptr) do { \ +- if ((ptr) == NULL) { \ +- printf("func:%s,line:%d, NULL pointer\n", __FUNCTION__, __LINE__); \ +- return TD_FAILURE; \ +- } \ +- } while (0) +- +-#define CHECK_SNPRINTF_PROC(ret) do { \ +- if ((ret) < 0) { \ +- printf("[%s:%d], snprintf_s failed\n", __FUNCTION__, __LINE__); \ +- } \ +-} while (0) +- +-/* ****************************************************** +- structure define +-****************************************************** */ +-typedef struct INI_VB_PARAM_CONFIG_S { +- uint32_t stMaxPoolCnt; +- ot_size stImageSize[OT_VB_MAX_COMMON_POOLS]; +- uint32_t stPixFormat[OT_VB_MAX_COMMON_POOLS]; +- uint32_t stDataBitWidth[OT_VB_MAX_COMMON_POOLS]; +- uint32_t stCompressMode[OT_VB_MAX_COMMON_POOLS]; +- uint32_t stDefaultAlign[OT_VB_MAX_COMMON_POOLS]; +- uint32_t stBlkCount[OT_VB_MAX_COMMON_POOLS]; +-} VB_PARAM_CONFIG_S; +- +-typedef struct { +- int32_t s32SnsId; +- int32_t s32BusId; +- combo_dev_t MipiDev; +-} HISI_SENSOR_INFO_S; +- +-typedef struct { +- td_bool bSnap; +- td_bool bDoublePipe; +- ot_vi_pipe VideoPipe; +- ot_vi_pipe SnapPipe; +- ot_vi_vpss_mode_type enVideoPipeMode; +- ot_vi_vpss_mode_type enSnapPipeMode; +-} HISI_SNAP_INFO_S; +- +-typedef struct { +- ot_vi_dev ViDev; +- ot_wdr_mode wdrMode; +-} HISI_DEV_INFO_S; +- +-typedef struct { +- ot_vi_pipe aPipe[OT_VI_MAX_PIPE_NUM]; +- ot_vi_vpss_mode_type enMastPipeMode; +- td_bool bMultiPipe; +- td_bool bVcNumCfged; +- td_bool ispBypass; +- ot_pixel_format pixelFormat; +- uint32_t u32VCNum[OT_VI_MAX_PIPE_NUM]; +- td_u32 frameInterruptType; +- td_u32 earlyLine; +-} HISI_PIPE_INFO_S; +- +-typedef struct { +- ot_vi_chn ViChn; +- ot_pixel_format enPixFormat; +- ot_dynamic_range dynamicRange; +- ot_video_format videoFormat; +- ot_compress_mode compressMode; +-} HISI_CHN_INFO_S; +- +-typedef struct { +- HISI_SENSOR_INFO_S stSnsInfo; +- HISI_DEV_INFO_S stDevInfo; +- HISI_PIPE_INFO_S stPipeInfo; +- HISI_CHN_INFO_S stChnInfo; +- HISI_SNAP_INFO_S stSnapInfo; +- combo_dev_attr_t *mipiAttr; +- ot_vi_dev_attr *devAttr; +- ot_vi_pipe_attr *pipeAttr; +- ot_vi_chn_attr *chnAttr; +- ot_isp_pub_attr *ispPubAttr; +- char *sensorLib; +- char *sensorObj; +- uint16_t len; +-} CAMERA_VI_CONFIG_S; +- +-typedef struct INI_VI_PARAM_CONFIG_S { +- ot_vi_vpss_mode_type pipeMode[OT_VI_MAX_PIPE_NUM]; +- char sensorLib[SENSOR_DESC_MAX_LEN]; +- char sensorObj[SENSOR_DESC_MAX_LEN]; +- ot_vi_dev_attr stDevAttr; +- combo_dev_attr_t stMipiAttr; +- ot_vi_pipe_attr stPipeAttr[OT_VI_MAX_PIPE_NUM]; +- ot_isp_pub_attr stPubAttr; +- ot_vi_chn_attr stChnAttr[OT_VI_MAX_PIPE_NUM][MAX_CHN_NUM_PER_PIPE]; +- td_u32 frameInterruptType[OT_VI_MAX_PIPE_NUM]; +- td_u32 earlyLine[OT_VI_MAX_PIPE_NUM]; +- int8_t busId; +- uint32_t sensorType; +-} VI_PARAM_CONFIG_S; +- +-typedef struct INI_VPSS_CHN_ATTR_CONFIG_S { +- uint32_t stMaxPortCnt; +- ot_vpss_chn_attr stVpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM]; +- ot_vpss_chn_attr stVpssExtChnAttr; +-} VPSS_CHN_ATTR_CONFIG_S; +- +-typedef struct { +- VB_PARAM_CONFIG_S stVbAttr; +- VI_PARAM_CONFIG_S stViAttr; +-} InitParam; +- +- +-enum CameraAttrOperatorMode { +- CAMERA_ATTR_OP_MODE_MANUAL, +- CAMERA_ATTR_OP_MODE_AUTO, +-}; +- +-#ifdef __cplusplus +-#if __cplusplus +-} +-#endif +-#endif /* End of #ifdef __cplusplus */ +- +-#endif /* End of #ifndef OHOS_CAMERA_COMM_H */ ++/* ++ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. ++ * + * 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 @@ -1768,1128 +9285,3792 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device + * limitations under the License. + */ + ++#ifndef OHOS_CAMERA_COMM_H ++#define OHOS_CAMERA_COMM_H ++ ++ ++#include ++#include +#include ++#include +#include -+#ifndef __HuaweiLite__ -+#include -+#endif -+#include "securec.h" -+/* SDK include */ -+#include "ss_mpi_audio.h" ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "ot_type.h" ++#include "ot_buffer.h" ++#include "ot_common_adec.h" ++#include "ot_common_aenc.h" +#include "ot_common_aio.h" -+ -+#include "media_hal_common.h" -+#include "audio_port_plugin_common.h" -+#include -+ -+#include "audio_usb_sub_port_out.h" ++#include "ot_common_isp.h" ++#include "ot_common_region.h" ++#include "ot_common_sys.h" ++#include "ot_common_vb.h" ++#include "ot_common_venc.h" ++#include "ot_common_vgs.h" ++#include "ot_common_vi.h" ++#include "ot_common_vo.h" ++#include "ot_common_vpss.h" ++#include "ot_common.h" ++#include "ot_defines.h" ++#include "ot_math.h" ++#include "ot_mipi_rx.h" ++#include "ot_sns_ctrl.h" ++#include "ss_mpi_ae.h" ++#include "ss_mpi_audio.h" ++#include "ss_mpi_awb.h" ++#include "ss_mpi_isp.h" ++#include "ss_mpi_region.h" ++#include "ss_mpi_sys.h" ++#if !defined (__SS928V100__) ++#include "ss_mpi_sys_bind.h" ++#include "ss_mpi_sys_mem.h" ++#endif ++#include "ss_mpi_vb.h" ++#include "ss_mpi_venc.h" ++#include "ss_mpi_vgs.h" ++#include "ss_mpi_vi.h" ++#include "ss_mpi_vo.h" ++#include "ss_mpi_vpss.h" ++ ++#ifdef HAVE_DISPLAY ++#include "ot_mipi_tx.h" ++#endif + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif -+#endif /* __cplusplus */ -+#define MODULE_NAME "AudioSubPortOut" ++#endif /* End of #ifdef __cplusplus */ ++ ++/* ****************************************************** ++ macro define ++****************************************************** */ ++#define FILE_NAME_LEN 128 ++ ++#define CHECK_CHN_RET(express, Chn, name) \ ++ do { \ ++ int32_t Ret; \ ++ Ret = express; \ ++ if (TD_SUCCESS != Ret) { \ ++ printf("\033[0;31m%s chn %d failed at %s: LINE: %d with %#x!\033[0;39m\n", name, Chn, __FUNCTION__, \ ++ __LINE__, Ret); \ ++ fflush(stdout); \ ++ return Ret; \ ++ } \ ++ } while (0) ++ ++#define CHECK_RET(express, name) \ ++ do { \ ++ int32_t Ret; \ ++ Ret = express; \ ++ if (TD_SUCCESS != Ret) { \ ++ printf("\033[0;31m%s failed at %s: LINE: %d with %#x!\033[0;39m\n", name, __FUNCTION__, __LINE__, Ret); \ ++ return Ret; \ ++ } \ ++ } while (0) ++#define HISI_PIXEL_FORMAT OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420 ++#define SENSOR_DESC_MAX_LEN 64 ++#define WDR_MAX_PIPE_NUM 4 ++#define MAX_CHN_NUM_PER_PIPE 2 ++#define MAX_FRAME_WIDTH 8192 + -+#define MAX_OUTPUT_PORT_CNT OT_AO_DEV_MAX_NUM -+#define MAX_OUTPUT_PORT_TRACK_CNT OT_AO_MAX_CHN_NUM ++#ifndef __HuaweiLite__ ++#define VI_DATA_PATH "." ++#else ++#define VI_DATA_PATH "/sharefs" ++#endif ++ ++#define SUCCESS 0 ++#define FAILURE (-1) ++ ++#define DEBUG_LOG_SWITCH 1 ++#define INFO_LOG_SWITCH 1 ++#define ERROR_LOG_SWITCH 1 ++#define TAG "CamHal" ++#ifdef ERROR_LOG_SWITCH ++#define HAL_LOGE(fmt, args...) do { \ ++ printf("E: %s %s-%d: " fmt, TAG, __func__, __LINE__, ##args); \ ++ } while (0) ++ ++#define HAL_LOGI(fmt, args...) do { \ ++ printf("I: %s %s-%d: " fmt, TAG, __func__, __LINE__, ##args); \ ++ } while (0) ++ ++#define HAL_LOGD(fmt, args...) do { \ ++ printf("D: %s %s-%d: " fmt, TAG, __func__, __LINE__, ##args); \ ++ } while (0) ++#else ++#define HAL_LOGE(...) ++#define HAL_LOGI(...) ++#define HAL_LOGD(...) ++#endif ++ ++#define HAL_ENTER() HAL_LOGI("enter\n") ++#define HAL_EXIT() HAL_LOGI("exit\n") ++#define LOG_CHK_RETURN(val) \ ++ do { \ ++ if ((val)) { \ ++ HAL_LOGE("\n"); \ ++ return; \ ++ }; \ ++ } while (0) ++ ++#define LOG_CHK_RETURN_ERR(val, ret) \ ++ do { \ ++ if ((val)) { \ ++ HAL_LOGE("\n"); \ ++ return ret; \ ++ } \ ++ } while (0) ++ ++#define HI_PRINTF(fmt...) do { \ ++ printf("[%s]-%d: ", __FUNCTION__, __LINE__); \ ++ printf(fmt); \ ++ } while (0) ++ ++#define HAL_LOG_DOFUNC(func) \ ++ do { \ ++ int32_t ret = func; \ ++ if (ret != 0) { \ ++ printf("[%s]-%d: error = 0x%x", __FUNCTION__, __LINE__, ret); \ ++ } \ ++ } while (0) ++ ++#define HAL_LOG_DOFUNC_RETURN(func) \ ++ do { \ ++ int32_t ret = func; \ ++ if (ret != 0) { \ ++ printf("[%s]-%d: error = 0x%x", __FUNCTION__, __LINE__, ret); \ ++ return ret; \ ++ } \ ++ } while (0) ++ ++#define HI_CHECK_NULL_PTR(ptr) do { \ ++ if ((ptr) == NULL) { \ ++ printf("func:%s,line:%d, NULL pointer\n", __FUNCTION__, __LINE__); \ ++ return TD_FAILURE; \ ++ } \ ++ } while (0) ++ ++#define CHECK_SNPRINTF_PROC(ret) do { \ ++ if ((ret) < 0) { \ ++ printf("[%s:%d], snprintf_s failed\n", __FUNCTION__, __LINE__); \ ++ } \ ++} while (0) ++ ++/* ****************************************************** ++ structure define ++****************************************************** */ ++typedef struct INI_VB_PARAM_CONFIG_S { ++ uint32_t stMaxPoolCnt; ++ ot_size stImageSize[OT_VB_MAX_COMMON_POOLS]; ++ uint32_t stPixFormat[OT_VB_MAX_COMMON_POOLS]; ++ uint32_t stDataBitWidth[OT_VB_MAX_COMMON_POOLS]; ++ uint32_t stCompressMode[OT_VB_MAX_COMMON_POOLS]; ++ uint32_t stDefaultAlign[OT_VB_MAX_COMMON_POOLS]; ++ uint32_t stBlkCount[OT_VB_MAX_COMMON_POOLS]; ++} VB_PARAM_CONFIG_S; ++ ++typedef struct { ++ int32_t s32SnsId; ++ int32_t s32BusId; ++ combo_dev_t MipiDev; ++} HISI_SENSOR_INFO_S; ++ ++typedef struct { ++ td_bool bSnap; ++ td_bool bDoublePipe; ++ ot_vi_pipe VideoPipe; ++ ot_vi_pipe SnapPipe; ++ ot_vi_vpss_mode_type enVideoPipeMode; ++ ot_vi_vpss_mode_type enSnapPipeMode; ++} HISI_SNAP_INFO_S; ++ ++typedef struct { ++ ot_vi_dev ViDev; ++ ot_wdr_mode wdrMode; ++} HISI_DEV_INFO_S; ++ ++typedef struct { ++ ot_vi_pipe aPipe[OT_VI_MAX_PIPE_NUM]; ++ ot_vi_vpss_mode_type enMastPipeMode; ++ td_bool bMultiPipe; ++ td_bool bVcNumCfged; ++ td_bool ispBypass; ++ ot_pixel_format pixelFormat; ++ uint32_t u32VCNum[OT_VI_MAX_PIPE_NUM]; ++ td_u32 frameInterruptType; ++ td_u32 earlyLine; ++} HISI_PIPE_INFO_S; + -+/* count of audio frame in Buffer */ -+#define AUDIO_FRAME_NUM_OUT_BUF 4 -+#define AUDIO_OUT_PTNUMPERFRM 1024 -+#define TIME_S_TO_US_SCALE 1000000 -+#define TIME_US_TO_NS_SCALE 1000 -+#define NO_WAIT 0 -+#define PCM_WAIT_TIMEOUT_MS 100 ++typedef struct { ++ ot_vi_chn ViChn; ++ ot_pixel_format enPixFormat; ++ ot_dynamic_range dynamicRange; ++ ot_video_format videoFormat; ++ ot_compress_mode compressMode; ++} HISI_CHN_INFO_S; + -+struct AudioSubPortOutTrack { -+ /* track impl */ -+ AudioPortTrack common; -+ bool inited; -+ bool started; -+ bool paused; -+ bool mute; -+ float volume; -+ uint64_t frames; -+ int64_t firstFramePts; -+ int64_t currentPts; -+ struct PortPluginAttr inputAttr; -+ /* MPP LIB */ -+ ot_aio_attr aoSourceAttr; -+ ot_ao_chn aoChn; ++typedef struct { ++ HISI_SENSOR_INFO_S stSnsInfo; ++ HISI_DEV_INFO_S stDevInfo; ++ HISI_PIPE_INFO_S stPipeInfo; ++ HISI_CHN_INFO_S stChnInfo; ++ HISI_SNAP_INFO_S stSnapInfo; ++ combo_dev_attr_t *mipiAttr; ++ ot_vi_dev_attr *devAttr; ++ ot_vi_pipe_attr *pipeAttr; ++ ot_vi_chn_attr *chnAttr; ++ ot_isp_pub_attr *ispPubAttr; ++ char *sensorLib; ++ char *sensorObj; ++ uint16_t len; ++} CAMERA_VI_CONFIG_S; ++ ++typedef struct INI_VI_PARAM_CONFIG_S { ++ ot_vi_vpss_mode_type pipeMode[OT_VI_MAX_PIPE_NUM]; ++ char sensorLib[SENSOR_DESC_MAX_LEN]; ++ char sensorObj[SENSOR_DESC_MAX_LEN]; ++ ot_vi_dev_attr stDevAttr; ++ combo_dev_attr_t stMipiAttr; ++ ot_vi_pipe_attr stPipeAttr[OT_VI_MAX_PIPE_NUM]; ++ ot_isp_pub_attr stPubAttr; ++ ot_vi_chn_attr stChnAttr[OT_VI_MAX_PIPE_NUM][MAX_CHN_NUM_PER_PIPE]; ++ td_u32 frameInterruptType[OT_VI_MAX_PIPE_NUM]; ++ td_u32 earlyLine[OT_VI_MAX_PIPE_NUM]; ++ int8_t busId; ++ uint32_t sensorType; ++} VI_PARAM_CONFIG_S; ++ ++typedef struct INI_VPSS_CHN_ATTR_CONFIG_S { ++ uint32_t stMaxPortCnt; ++ ot_vpss_chn_attr stVpssChnAttr[OT_VPSS_MAX_PHYS_CHN_NUM]; ++ ot_vpss_chn_attr stVpssExtChnAttr; ++} VPSS_CHN_ATTR_CONFIG_S; + -+ ot_audio_dev aoDeviceId; -+ snd_pcm_t *ao_pcm_handle; -+ snd_mixer_t *ao_mixer_handle; -+ snd_mixer_elem_t *ao_elem_vol; -+ long ao_min_vol, ao_max_vol; -+ enum VqeScene vqeScene; -+}; ++typedef struct { ++ VB_PARAM_CONFIG_S stVbAttr; ++ VI_PARAM_CONFIG_S stViAttr; ++} InitParam; + -+struct AudioSubPortOut { -+ bool opened; -+ bool mute; -+ ot_aio_attr aoSourceAttr; -+ ot_audio_dev aoDeviceId; -+ snd_pcm_t *ao_pcm_handle; -+ snd_mixer_t *ao_mixer_handle; -+ snd_mixer_elem_t *ao_elem_vol; -+ long ao_min_vol, ao_max_vol; -+ bool aoEnabled; -+ struct AudioSubPortOutTrack *hwOutputPortTrack[MAX_OUTPUT_PORT_TRACK_CNT]; -+ pthread_mutex_t mutex; -+}; + -+struct AudioSubPortOutMng { -+ bool used; -+ int32_t chnID; -+ struct AudioSubPortOut *hwOutputPort; ++enum CameraAttrOperatorMode { ++ CAMERA_ATTR_OP_MODE_MANUAL, ++ CAMERA_ATTR_OP_MODE_AUTO, +}; + -+static struct AudioSubPortOutMng g_audioHwOutputPorts[MAX_OUTPUT_PORT_CNT]; -+static bool g_audioOutputMngInited = false; -+static pthread_mutex_t g_audioOutputMngLock = PTHREAD_MUTEX_INITIALIZER; ++#ifdef __cplusplus ++#if __cplusplus ++} ++#endif ++#endif /* End of #ifdef __cplusplus */ ++ ++#endif /* End of #ifndef OHOS_CAMERA_COMM_H */ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_vi.c ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_vi.c +--- ohos/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_vi.c 2025-12-18 15:14:06.900482931 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_vi.c 2025-12-18 15:44:30.870238524 +0800 +@@ -1,1630 +1,1630 @@ +-/* +- * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. +- * +- * 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. +- */ +- +-#include "hi_camera_vi.h" +-#include +-#include "ss_confaccess.h" +-#ifdef __cplusplus +-#if __cplusplus +-extern "C" { +-#endif +-#endif /* End of #ifdef __cplusplus */ +- +-#define MIPI_DEV_NODE "/dev/ot_mipi_rx" +-#define MAX_SENSOR_NUM 2 +-#define ISP_MAX_DEV_NUM 4 +-#define THREAD_NAME_SIZE 20 +-#define INIT_PARAM_KEY_MAX_LEN 128 +- +-/* product ini identification */ +-#define PDT_INIPARAM "productini" +-#define PDT_INIPARAM_PATH "/storage/data/media_config.ini" +-#define CAMERA_DEV_MODULE "camera_dev" +-static pthread_t g_ispPid[ISP_MAX_DEV_NUM] = { 0 }; +-static uint32_t g_au32IspSnsId[ISP_MAX_DEV_NUM] = { 0, 1 }; +-static void *g_snsLibHandle[MAX_SENSOR_NUM] = {NULL}; +-static ot_isp_sns_obj *g_snsObj[MAX_SENSOR_NUM] = {NULL}; +-static int32_t g_sensorDev[MAX_SENSOR_NUM] = { -1, -1 }; +-static uint32_t g_sensorCnt = 0; +-/* * +-Vi dev attr +-*/ +-static ot_vi_dev_attr g_devAttrDefaultBase = { +- OT_VI_INTF_MODE_MIPI, +- OT_VI_WORK_MODE_MULTIPLEX_1, +- { 0xFFF00000, 0x0 }, +- OT_VI_SCAN_PROGRESSIVE, +- { -1, -1, -1, -1 }, +- OT_VI_DATA_SEQ_YUYV, +- /* port_vsync port_vsync_neg port_hsync port_hsync_neg */ +- { +- OT_VI_VSYNC_PULSE, +- OT_VI_VSYNC_NEG_LOW, +- OT_VI_HSYNC_VALID_SIG, +- OT_VI_HSYNC_NEG_HIGH, +- OT_VI_VSYNC_VALID_SIG, +- OT_VI_VSYNC_VALID_NEG_HIGH, +- +- /* hsync_hfb hsync_act hsync_hhb */ +- { 0, 1280, 0, +- /* vsync0_vhb vsync0_act vsync0_hhb */ +- 0, 720, 0, +- /* vsync1_vhb vsync1_act vsync1_hhb */ +- 0, 0, 0 } +- }, +- OT_VI_DATA_TYPE_RAW, +- TD_FALSE, +- { 1920, 1080 }, +- OT_DATA_RATE_X1 +-}; +- +-static int32_t GetVbPoolParam(VB_PARAM_CONFIG_S *vbAttr) +-{ +- char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; +- td_s32 poolcnt = 0; +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, "vb:max_poolcnt", 0, &poolcnt); +- if (poolcnt > OT_VB_MAX_COMMON_POOLS) { +- HI_PRINTF("poolcnt:%d error, max:%d\n", poolcnt, OT_VB_MAX_COMMON_POOLS); +- return TD_FAILURE; +- } +- +- vbAttr->stMaxPoolCnt = (td_u32)poolcnt; +- +- for (uint32_t i = 0; i < vbAttr->stMaxPoolCnt; i++) { +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vb.pool.%u:image_width", i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stImageSize[i].width); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vb.pool.%u:image_height", i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stImageSize[i].height); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vb.pool.%u:pix_format", i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stPixFormat[i]); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vb.pool.%u:data_bitwidth", i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stDataBitWidth[i]); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vb.pool.%u:compress_mode", i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stCompressMode[i]); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vb.pool.%u:default_align", i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stDefaultAlign[i]); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vb.pool.%u:blk_count", i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stBlkCount[i]); +- HI_PRINTF("vb pool %u image width=%u height=%u\n", i, +- vbAttr->stImageSize[i].width, vbAttr->stImageSize[i].height); +- } +- return TD_SUCCESS; +-} +- +-static void GetViDevParam(ot_vi_dev_attr *viDevAttr, uint8_t index) +-{ +- /* init dev attr */ +- char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; +- +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.dev:sensor_width", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viDevAttr->in_size.width); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.dev:sensor_height", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viDevAttr->in_size.height); +-} +- +-static int32_t GetViMipiParam(combo_dev_attr_t *viMipiAttr, uint8_t index) +-{ +- /* mipi attr */ +- char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; +- +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:combo_dev_t", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->devno); +- HI_PRINTF("index %u devno %u\n", index, viMipiAttr->devno); +- g_sensorDev[index] = viMipiAttr->devno; +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:input_mode_t", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->input_mode); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:mipi_data_rate_t", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->data_rate); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:img_rect_x", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->img_rect.x); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:img_rect_y", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->img_rect.y); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:img_rect_w", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->img_rect.width); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:img_rect_h", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->img_rect.height); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:data_type_t", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->mipi_attr.input_data_type); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:mipi_wdr_mode_t", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->mipi_attr.wdr_mode); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:lane_id_num", index)); +- td_u32 laneIdNum = 0; +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &laneIdNum); +- if (laneIdNum > MIPI_LANE_NUM) { +- HI_PRINTF("lane_id_num:%u error, max:%d\n", laneIdNum, MIPI_LANE_NUM); +- return TD_FAILURE; +- } +- +- for (uint32_t i = 0; i < laneIdNum; i++) { +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.mipi:lane_id_%u", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->mipi_attr.lane_id[i]); +- } +- for (uint32_t i = laneIdNum; i < MIPI_LANE_NUM; i++) { +- viMipiAttr->mipi_attr.lane_id[i] = -1; +- } +- +- return TD_SUCCESS; +-} +- +-static void GetViIspPubParam(ot_isp_pub_attr *ispPubAttr, uint8_t index) +-{ +- /* isp_pub attr */ +- char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; +- +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:stWndRect_x", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wnd_rect.x); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:stWndRect_y", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wnd_rect.y); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:stWndRect_w", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wnd_rect.width); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:stWndRect_h", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wnd_rect.height); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:outImageSize_x", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->sns_size.width); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:outImageSize_y", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->sns_size.height); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:frameRate", index)); +- td_double frameRate = 0; +- SS_CONFACCESS_GetDouble(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &frameRate); +- ispPubAttr->frame_rate = (td_float)frameRate; +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:bayer_format", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->bayer_format); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:wdrMode", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wdr_mode); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:snsMode", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->sns_mode); +-} +- +-static int32_t GetViPipeChnParam(uint32_t pipeId, VI_PARAM_CONFIG_S *viAttr, uint8_t index) +-{ +- char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; +- +- /* chn attr */ +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:chncnt", index, pipeId)); +- uint32_t chnCnt = 0; +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnCnt); +- if (chnCnt > MAX_CHN_NUM_PER_PIPE) { +- HI_PRINTF("chncnt:%u error, max:%d\n", chnCnt, MAX_CHN_NUM_PER_PIPE); +- return TD_FAILURE; +- } +- +- for (uint32_t j = 0; j < chnCnt; j++) { +- ot_vi_chn_attr *chnAttr = &viAttr->stChnAttr[pipeId][j]; +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:out_width", index, pipeId, j)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->size.width); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:out_height", index, pipeId, j)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->size.height); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:pixel_format", index, pipeId, j)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->pixel_format); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:dynamic_range", index, pipeId, j)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->dynamic_range); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:video_format", index, pipeId, j)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->video_format); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:compress_mode", index, pipeId, j)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->compress_mode); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:mirror_en", index, pipeId, j)); +- int32_t isMirrorEnable = 0; +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &isMirrorEnable); +- chnAttr->mirror_en = (isMirrorEnable != 0) ? TD_TRUE : TD_FALSE; +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:flip_en", index, pipeId, j)); +- int32_t isFlipEnable = 0; +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &isFlipEnable); +- chnAttr->flip_en = (isFlipEnable != 0) ? TD_TRUE : TD_FALSE; +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:depth", index, pipeId, j)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->depth); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:src_framerate", index, pipeId, j)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, +- &chnAttr->frame_rate_ctrl.src_frame_rate); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u.chl.%u:dst_framerate", index, pipeId, j)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, +- &chnAttr->frame_rate_ctrl.dst_frame_rate); +- } +- return TD_SUCCESS; +-} +- +-static int32_t GetViPipeParam(VI_PARAM_CONFIG_S *viAttr, uint8_t index) +-{ +- char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; +- /* pipe attr */ +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.dev:pipecnt", index)); +- uint32_t pipeCnt = 0; +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeCnt); +- if (pipeCnt > OT_VI_MAX_PIPE_NUM) { +- HI_PRINTF("pipecnt:%u error, max:%d\n", pipeCnt, OT_VI_MAX_PIPE_NUM); +- return TD_FAILURE; +- } +- +- for (uint32_t i = 0; i < pipeCnt; i++) { +- ot_vi_pipe_attr *pipeAttr = &viAttr->stPipeAttr[i]; +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "common.vcap%u.pipe.%u:vivpssmode", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viAttr->pipeMode[i]); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:pipe_bypass_mode", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->pipe_bypass_mode); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:isp_bypass", index, i)); +- int32_t isIspBypass = 0; +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &isIspBypass); +- pipeAttr->isp_bypass = (isIspBypass != 0) ? TD_TRUE : TD_FALSE; +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:width", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->size.width); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:height", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->size.height); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:pixel_format", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->pixel_format); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:compress_mode", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->compress_mode); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:src_framerate", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, +- &pipeAttr->frame_rate_ctrl.src_frame_rate); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:dst_framerate", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, +- &pipeAttr->frame_rate_ctrl.dst_frame_rate); +- +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:interrupt_type", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0x5, +- &viAttr->frameInterruptType[i]); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.pipe.%u:earlyLine", index, i)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viAttr->earlyLine[i]); +- /* chn attr */ +- if (GetViPipeChnParam(i, viAttr, index) != TD_SUCCESS) { +- HI_PRINTF("GetViPipe[%u]ChnParam failed \n", i); +- return TD_FAILURE; +- } +- } +- +- return TD_SUCCESS; +-} +- +-static int32_t GetViParam(VI_PARAM_CONFIG_S *viAttr, uint8_t index) +-{ +- /* init dev attr */ +- GetViDevParam(&viAttr->stDevAttr, index); +- char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; +- +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.dev:sensor_lib", index)); +- const char *tmpValue = NULL; +- SS_CONFACCESS_GetString(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, "/usr/lib/libsns_imx415.so", &tmpValue); +- if (tmpValue != NULL) { +- HAL_LOG_DOFUNC(strncpy_s(viAttr->sensorLib, SENSOR_DESC_MAX_LEN, tmpValue, SENSOR_DESC_MAX_LEN - 1)); +- } +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.dev:sensor_obj", index)); +- SS_CONFACCESS_GetString(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, "g_sns_imx415_obj", &tmpValue); +- if (tmpValue != NULL) { +- HAL_LOG_DOFUNC(strncpy_s(viAttr->sensorObj, SENSOR_DESC_MAX_LEN, tmpValue, SENSOR_DESC_MAX_LEN - 1)); +- } +- +- /* mipi attr */ +- if (GetViMipiParam(&viAttr->stMipiAttr, index) != TD_SUCCESS) { +- HI_PRINTF("GetViMipiParam failed \n"); +- return TD_FAILURE; +- } +- +- /* isp_pub attr */ +- GetViIspPubParam(&viAttr->stPubAttr, index); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.isp_pub:busId", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viAttr->busId); +- HI_PRINTF(" busid = %d\n", viAttr->busId); +- CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, +- "vcap%u.dev:sensor_type", index)); +- SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viAttr->sensorType); +- HI_PRINTF(" sensor type = %u\n", viAttr->sensorType); +- /* pipe attr */ +- if (GetViPipeParam(viAttr, index) != TD_SUCCESS) { +- HI_PRINTF("GetViPipeParam failed \n"); +- return TD_FAILURE; +- } +- +- return TD_SUCCESS; +-} +- +-uint8_t GetParamCamera(const char path[PATH_MAX_LEN], InitParam *initParam, uint8_t cameraId) +-{ +- int32_t ret = SS_CONFACCESS_Init(PDT_INIPARAM, PDT_INIPARAM_PATH); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("SS_CONFACCESS_Init failed\n"); +- return cameraId + 1; +- } +- g_sensorCnt = 0; +- g_sensorDev[0] = -1; +- g_sensorDev[1] = -1; +- +- int32_t sensorCnt = 0; +- ret = SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, "common:sensorcnt", 0, &sensorCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("SS_CONFACCESS_GetInt failed\n"); +- } +- // init vb +- HI_PRINTF("sens count = %d\n", sensorCnt); +- if (GetVbPoolParam(&initParam->stVbAttr) != TD_SUCCESS) { +- HI_PRINTF("GetVbPoolParam failed\n"); +- ret = SS_CONFACCESS_Deinit(PDT_INIPARAM); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("SS_CONFACCESS_Deinit failed\n"); +- } +- return cameraId + 1; +- } +- uint8_t i = 0; +- for (; i < cameraId && i < sensorCnt; i++) { +- if (GetViParam(&initParam[i].stViAttr, i) != TD_SUCCESS) { +- HI_PRINTF("GetViPipeParam failed\n"); +- ret = SS_CONFACCESS_Deinit(PDT_INIPARAM); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("SS_CONFACCESS_Deinit failed\n"); +- } +- return cameraId + 1; +- } +- } +- ret = SS_CONFACCESS_Deinit(PDT_INIPARAM); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("SS_CONFACCESS_Deinit failed\n"); +- } +- g_sensorCnt = i; +- return i; +-} +- +-static int32_t ViSetMipiHsMode(void) +-{ +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return -1; +- } +- lane_divide_mode_t enHsMode; +- if (g_sensorCnt == MAX_SENSOR_NUM && g_sensorDev[0] != g_sensorDev[1]) { +- enHsMode = LANE_DIVIDE_MODE_1; // 2+2 +- } else { +- enHsMode = LANE_DIVIDE_MODE_0; // 4 +- } +- int32_t ret = ioctl(fd, OT_MIPI_SET_HS_MODE, &enHsMode); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("OT_MIPI_SET_HS_MODE failed\n"); +- } +- close(fd); +- return ret; +-} +- +-static int32_t ViEnableMipiClock(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- int32_t ret = TD_SUCCESS; +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return TD_FAILURE; +- } +- for (uint32_t i = 0; i < cameraCnt; i++) { +- combo_dev_t devno = pstViConfig[i].stSnsInfo.MipiDev; +- ret = ioctl(fd, OT_MIPI_ENABLE_MIPI_CLOCK, &devno); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("MIPI_ENABLE_CLOCK %u failed\n", devno); +- break; +- } +- } +- close(fd); +- return ret; +-} +- +-static int32_t ViDisableMipiClock(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return TD_FAILURE; +- } +- int32_t ret = TD_SUCCESS; +- for (uint32_t i = 0; i < cameraCnt; i++) { +- combo_dev_t devno = pstViConfig->stSnsInfo.MipiDev; +- ret = ioctl(fd, OT_MIPI_DISABLE_MIPI_CLOCK, &devno); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("MIPI_DISABLE_CLOCK %u failed\n", devno); +- break; +- } +- } +- close(fd); +- return ret; +-} +- +-static int32_t ViResetMipi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- int32_t ret = TD_SUCCESS; +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return TD_FAILURE; +- } +- for (uint32_t i = 0; i < cameraCnt; i++) { +- combo_dev_t devno = pstViConfig[i].stSnsInfo.MipiDev; +- ret = ioctl(fd, OT_MIPI_RESET_MIPI, &devno); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("RESET_MIPI %u failed\n", devno); +- break; +- } +- } +- close(fd); +- return ret; +-} +- +-static int32_t ViEnableSensorClock(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- int32_t ret = TD_SUCCESS; +- sns_clk_source_t snsDev; +- +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return TD_FAILURE; +- } +- for (uint32_t i = 0; i < cameraCnt; i++) { +- snsDev = g_sensorDev[i]; +- ret = ioctl(fd, OT_MIPI_ENABLE_SENSOR_CLOCK, &snsDev); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("OT_MIPI_ENABLE_SENSOR_CLOCK failed\n"); +- break; +- } +- } +- close(fd); +- return ret; +-} +- +-static int32_t ViResetSensor(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- (void)pstViConfig; +- int32_t ret = TD_SUCCESS; +- sns_clk_source_t snsDev; +- +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return TD_FAILURE; +- } +- for (uint32_t i = 0; i < cameraCnt; i++) { +- snsDev = g_sensorDev[i]; +- ret = ioctl(fd, OT_MIPI_RESET_SENSOR, &snsDev); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("OT_MIPI_RESET_SENSOR failed\n"); +- break; +- } +- } +- close(fd); +- return ret; +-} +- +-static int32_t ViUnresetSensor(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- int32_t ret = TD_SUCCESS; +- sns_clk_source_t snsDev; +- +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return TD_FAILURE; +- } +- for (uint32_t i = 0; i < cameraCnt; i++) { +- snsDev = g_sensorDev[i]; +- ret = ioctl(fd, OT_MIPI_UNRESET_SENSOR, &snsDev); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("OT_MIPI_UNRESET_SENSOR failed\n"); +- break; +- } +- } +- close(fd); +- return ret; +-} +- +-static int32_t ViUnresetMipi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return TD_FAILURE; +- } +- for (uint32_t i = 0; i < cameraCnt; i++) { +- combo_dev_t devno = pstViConfig[i].stSnsInfo.MipiDev; +- int32_t ret = ioctl(fd, OT_MIPI_UNRESET_MIPI, &devno); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("UNRESET_MIPI %u failed\n", devno); +- break; +- } +- } +- close(fd); +- return TD_SUCCESS; +-} +- +-static int32_t ViSetMipiAttr(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- combo_dev_attr_t stcomboDevAttr; +- +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return TD_FAILURE; +- } +- +- for (uint32_t i = 0; i < cameraCnt; i++) { +- HAL_LOG_DOFUNC(memcpy_s(&stcomboDevAttr, sizeof(combo_dev_attr_t), +- pstViConfig[i].mipiAttr, sizeof(combo_dev_attr_t))); +- +- stcomboDevAttr.devno = pstViConfig[i].stSnsInfo.MipiDev; +- int32_t ret = ioctl(fd, OT_MIPI_SET_DEV_ATTR, &stcomboDevAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("OT_MIPI_SET_DEV_ATTR failed:ret= 0x%x dev:%u\n", ret, stcomboDevAttr.devno); +- break; +- } +- } +- close(fd); +- return TD_SUCCESS; +-} +- +-static int32_t CameraDisableSensorClock(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- int32_t ret = TD_SUCCESS; +- +- int32_t fd = open(MIPI_DEV_NODE, O_RDWR); +- if (fd < 0) { +- HI_PRINTF("open hi_mipi dev failed\n"); +- return TD_FAILURE; +- } +- for (uint32_t i = 0; i < cameraCnt; i++) { +- sns_clk_source_t snsDev = pstViConfig[i].stDevInfo.ViDev; +- ret = ioctl(fd, OT_MIPI_DISABLE_SENSOR_CLOCK, &snsDev); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("OT_MIPI_DISABLE_SENSOR_CLOCK failed\n"); +- break; +- } +- } +- close(fd); +- return ret; +-} +- +-/* **************************************************************************** +- * function : init mipi +- * *************************************************************************** */ +-static int32_t CameraStartMIPI(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- if (pstViConfig == NULL) { +- HI_PRINTF("%s: null ptr\n", __FUNCTION__); +- return TD_FAILURE; +- } +- +- int32_t ret = ViSetMipiHsMode(); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_SetMipiHsMode failed!\n"); +- return TD_FAILURE; +- } +- ret = ViEnableMipiClock(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_EnableMipiClock failed!\n"); +- return TD_FAILURE; +- } +- ret = ViResetMipi(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_ResetMipi failed!\n"); +- return TD_FAILURE; +- } +- ret = ViEnableSensorClock(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_EnableSensorClock failed!\n"); +- return TD_FAILURE; +- } +- +- ret = ViResetSensor(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_ResetSensor failed!\n"); +- return TD_FAILURE; +- } +- ret = ViSetMipiAttr(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_SetMipiAttr failed!\n"); +- return TD_FAILURE; +- } +- ret = ViUnresetMipi(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_UnresetMipi failed!\n"); +- return TD_FAILURE; +- } +- ret = ViUnresetSensor(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_UnresetSensor failed!\n"); +- return TD_FAILURE; +- } +- return TD_SUCCESS; +-} +- +-static int32_t CameraStopMIPI(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- if (pstViConfig == NULL) { +- HI_PRINTF("%s: null ptr\n", __FUNCTION__); +- return TD_FAILURE; +- } +- int32_t ret = ViResetSensor(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_ResetSensor failed!\n"); +- return TD_FAILURE; +- } +- ret = CameraDisableSensorClock(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_DisableSensorClock failed!\n"); +- return TD_FAILURE; +- } +- ret = ViResetMipi(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_ResetMipi failed!\n"); +- return TD_FAILURE; +- } +- ret = ViDisableMipiClock(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_DisableMipiClock failed!\n"); +- return TD_FAILURE; +- } +- return TD_SUCCESS; +-} +- +-int32_t HpCameraSetFps(td_float pf32Framerate) +-{ +- ot_isp_pub_attr stIspPubAttr; +- ot_vi_pipe ViPipe = 0; +- HAL_LOG_DOFUNC(memset_s(&stIspPubAttr, sizeof(ot_isp_pub_attr), 0, sizeof(ot_isp_pub_attr))); +- int32_t ret = ss_mpi_isp_get_pub_attr(ViPipe, &stIspPubAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_isp_get_pub_attr failed %x\n", ret); +- return TD_FAILURE; +- } +- /* 1.set mater isp pub attr */ +- stIspPubAttr.frame_rate = pf32Framerate; +- ret = ss_mpi_isp_set_pub_attr(ViPipe, &stIspPubAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_isp_set_pub_attr failed %x\n", ret); +- return TD_FAILURE; +- } +- return TD_SUCCESS; +-} +- +-int32_t HpCameraGetFps(void) +-{ +- ot_isp_pub_attr stIspPubAttr; +- ot_vi_pipe ViPipe = 0; +- HAL_LOG_DOFUNC(memset_s(&stIspPubAttr, sizeof(ot_isp_pub_attr), 0, sizeof(ot_isp_pub_attr))); +- int32_t ret = ss_mpi_isp_get_pub_attr(ViPipe, &stIspPubAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_isp_get_pub_attr failed %x\n", ret); +- return TD_FAILURE; +- } +- /* 1.set mater isp pub attr */ +- return (int32_t)stIspPubAttr.frame_rate; +-} +- +-static int32_t ConfigVIVPSSMode(const CAMERA_VI_CONFIG_S *viConfig, ot_vi_vpss_mode *viVpssMode) +-{ +- ot_vi_pipe viPipe = viConfig->stPipeInfo.aPipe[0]; +- HI_PRINTF("viPipe = %d\n", viPipe); +- if (viPipe < 0 || viPipe >= OT_VI_MAX_PIPE_NUM) { +- HI_PRINTF("viPipe is illgal %d!\n", viPipe); +- return TD_FAILURE; +- } +- +- viVpssMode->mode[viPipe] = OT_VI_ONLINE_VPSS_OFFLINE; +- return TD_SUCCESS; +-} +- +-static int32_t CameraSetParam(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- ot_vi_vpss_mode stVIVPSSMode = { 0 }; +- +- int32_t ret = ss_mpi_sys_get_vi_vpss_mode(&stVIVPSSMode); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("Get VI-VPSS mode Param failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- for (uint32_t i = 0; i < cameraCnt; i++) { +- ret = ConfigVIVPSSMode(&pstViConfig[i], &stVIVPSSMode); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ConfigVIVPSSMode failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- } +- ret = ss_mpi_sys_set_vi_vpss_mode(&stVIVPSSMode); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("Set VI-VPSS mode Param failed with %#x!\n", ret); +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViGetDevAttr(ot_vi_dev_attr *pstViDevAttr, const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- int ret = memcpy_s(pstViDevAttr, sizeof(ot_vi_dev_attr), &g_devAttrDefaultBase, sizeof(ot_vi_dev_attr)); +- if (ret != EOK) { +- HI_PRINTF("memcpy_s pstViDevAttr err\n"); +- } +- pstViDevAttr->in_size.width = pstViConfig->devAttr->in_size.width; +- pstViDevAttr->in_size.height = pstViConfig->devAttr->in_size.height; +- +- return TD_SUCCESS; +-} +- +-static int32_t ViStartDev(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- ot_vi_dev_attr stViDevAttr = { 0 }; +- +- ot_vi_dev ViDev = pstViConfig->stDevInfo.ViDev; +- ViGetDevAttr(&stViDevAttr, pstViConfig); +- if (pstViConfig->stPipeInfo.enMastPipeMode == OT_VI_PARALLEL_VPSS_OFFLINE || +- pstViConfig->stPipeInfo.enMastPipeMode == OT_VI_PARALLEL_VPSS_PARALLEL) { +- stViDevAttr.data_rate = OT_DATA_RATE_X2; +- } +- +- int32_t ret = ss_mpi_vi_set_dev_attr(ViDev, &stViDevAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_set_dev_attr failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- +- ret = ss_mpi_vi_enable_dev(ViDev); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_enable_dev failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- +- return TD_SUCCESS; +-} +- +-static int32_t ViBindPipeDev(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- int32_t pipeCnt = 0; +- int32_t ret = 0; +- ot_vi_bind_pipe devBindPipe = { 0 }; +- +- for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { +- ot_vi_pipe aPipe = pstViConfig->stPipeInfo.aPipe[i]; +- if (aPipe >= 0 && aPipe < OT_VI_MAX_PIPE_NUM) { +- devBindPipe.pipe_id[pipeCnt] = aPipe; +- pipeCnt++; +- devBindPipe.pipe_num = pipeCnt; +- ret = ss_mpi_vi_bind(pstViConfig->stDevInfo.ViDev, aPipe); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_bind failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- } +- } +- +- return ret; +-} +- +-static int32_t ViStopSingleViPipe(ot_vi_pipe ViPipe) +-{ +- int32_t ret = ss_mpi_vi_stop_pipe(ViPipe); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_stop_pipe failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- +- ret = ss_mpi_vi_destroy_pipe(ViPipe); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_destroy_pipe failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- +- return ret; +-} +- +-static int32_t ViCreatePipe(const CAMERA_VI_CONFIG_S *pstViConfig, ot_vi_pipe ViPipe, +- ot_vi_pipe_attr *stPipeAttr, int32_t i) +-{ +- ot_frame_interrupt_attr frameIntAttr = { 0 }; +- +- int32_t ret = ss_mpi_vi_create_pipe(ViPipe, stPipeAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_create_pipe failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- if (pstViConfig->stPipeInfo.bVcNumCfged == TD_TRUE) { +- ret = ss_mpi_vi_set_pipe_vc_number(ViPipe, pstViConfig->stPipeInfo.u32VCNum[i]); +- if (ret != TD_SUCCESS) { +- ss_mpi_vi_destroy_pipe(ViPipe); +- HI_PRINTF("ss_mpi_vi_set_pipe_vc_number failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- } +- if (pstViConfig->stPipeInfo.frameInterruptType < OT_FRAME_INTERRUPT_BUTT && +- pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { +- frameIntAttr.interrupt_type = pstViConfig->stPipeInfo.frameInterruptType; +- frameIntAttr.early_line = pstViConfig->stPipeInfo.earlyLine; +- ret = ss_mpi_vi_set_pipe_frame_interrupt_attr(ViPipe, &frameIntAttr); +- HI_PRINTF(" ss_mpi_vi_set_pipe_frame_interrupt_attr type %d %u ret = %d\n", frameIntAttr.interrupt_type, +- frameIntAttr.early_line, ret); +- } +- ret = ss_mpi_vi_start_pipe(ViPipe); +- if (ret != TD_SUCCESS) { +- ss_mpi_vi_destroy_pipe(ViPipe); +- HI_PRINTF("ss_mpi_vi_start_pipe failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViDoCreatePipe(const CAMERA_VI_CONFIG_S *pstViConfig, ot_vi_pipe ViPipe, +- ot_vi_pipe_attr *stPipeAttr, int32_t index) +-{ +- int32_t ret; +- if ((pstViConfig->stSnapInfo.bSnap) && (pstViConfig->stSnapInfo.bDoublePipe) && +- (ViPipe == pstViConfig->stSnapInfo.SnapPipe)) { +- ret = ss_mpi_vi_create_pipe(ViPipe, stPipeAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_create_pipe failed with %#x!\n", ret); +- for (int32_t j = 0; j < index; j++) { +- ot_vi_pipe stopViPipe = j; +- (void)ViStopSingleViPipe(stopViPipe); +- } +- return ret; +- } +- } else { +- ret = ViCreatePipe(pstViConfig, ViPipe, stPipeAttr, index); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_create_pipe failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViStartViPipe(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { +- ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; +- if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { +- ot_vi_pipe_attr stPipeAttr; +- HAL_LOG_DOFUNC(memcpy_s(&stPipeAttr, sizeof(ot_vi_pipe_attr), +- pstViConfig->pipeAttr, sizeof(ot_vi_pipe_attr))); +- if (pstViConfig->stPipeInfo.ispBypass == TD_TRUE) { +- stPipeAttr.isp_bypass = TD_TRUE; +- stPipeAttr.pixel_format = pstViConfig->stPipeInfo.pixelFormat; +- } +- if ((viPipe == 0x2) || (viPipe == 0x3)) { +- stPipeAttr.compress_mode = OT_COMPRESS_MODE_NONE; +- } +- int32_t ret = ViDoCreatePipe(pstViConfig, viPipe, &stPipeAttr, i); +- if (ret != TD_SUCCESS) { +- return ret; +- } +- } +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViEnableChn(ot_vi_pipe ViPipe, ot_vi_chn ViChn, ot_vi_chn_attr stChnAttr, td_bool bNeedChn, +- const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- if (bNeedChn) { +- int32_t ret = ss_mpi_vi_set_chn_attr(ViPipe, ViChn, &stChnAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_set_chn_attr failed with %#x!\n", ret); +- return ret; +- } +- ot_vi_vpss_mode_type enMastPipeMode = pstViConfig->stPipeInfo.enMastPipeMode; +- if (enMastPipeMode == OT_VI_OFFLINE_VPSS_OFFLINE || enMastPipeMode == OT_VI_ONLINE_VPSS_OFFLINE || +- enMastPipeMode == OT_VI_PARALLEL_VPSS_OFFLINE) { +- ret = ss_mpi_vi_enable_chn(ViPipe, ViChn); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_enable_chn failed with %#x!\n", ret); +- return ret; +- } +- } +- +-#if defined(ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY) && (ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY != 0) +- ot_low_delay_info viLdyInfo; +- ret = ss_mpi_vi_get_chn_low_delay(ViPipe, ViChn, &viLdyInfo); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_get_chn_low_delay failed with %#x\n", ret); +- return TD_FAILURE; +- } +- viLdyInfo.enable = TD_TRUE; +- viLdyInfo.line_cnt = 16; /* 16:VDEC_LOW_DELAY_MIN_LINE */ +- ret = ss_mpi_vi_set_chn_low_delay(ViPipe, ViChn, &viLdyInfo); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_set_chn_low_delay failed with %#x\n", ret); +- return TD_FAILURE; +- } +-#endif +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViStartViChn(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { +- ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; +- if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { +- ot_vi_chn ViChn = pstViConfig->stChnInfo.ViChn; +- ot_vi_chn_attr stChnAttr; +- HAL_LOG_DOFUNC(memcpy_s(&stChnAttr, sizeof(ot_vi_chn_attr), +- pstViConfig->chnAttr, sizeof(ot_vi_chn_attr))); +- td_bool bNeedChn = TD_FALSE; +- if (pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { +- bNeedChn = TD_TRUE; +- } else { +- bNeedChn = (i > 0) ? TD_FALSE : TD_TRUE; +- } +- int32_t ret = ViEnableChn(viPipe, ViChn, stChnAttr, bNeedChn, pstViConfig); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ViEnableChn failed with %#x!\n", ret); +- return ret; +- } +- } +- } +- +- return TD_SUCCESS; +-} +-static int32_t ViStopViPipe(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { +- ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; +- if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { +- (void)ViStopSingleViPipe(viPipe); +- } +- } +- return TD_SUCCESS; +-} +-static int32_t ViStopDev(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- ot_vi_dev viDev = pstViConfig->stDevInfo.ViDev; +- ot_vi_bind_pipe bindPipe = {0}; +- int32_t ret = ss_mpi_vi_get_bind_by_dev(viDev, &bindPipe); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_get_bind_by_dev failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- for (int32_t i = 1; i <= bindPipe.pipe_num; i++) { +- ret = ss_mpi_vi_unbind(viDev, bindPipe.pipe_id[i]); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_unbind failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- } +- ret = ss_mpi_vi_disable_dev(viDev); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_disable_dev failed with %#x!\n", ret); +- return TD_FAILURE; +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViCreateSingleVi(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- int32_t ret = ViStartDev(pstViConfig); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_StartDev failed !\n"); +- return TD_FAILURE; +- } +- ret = ViBindPipeDev(pstViConfig); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_BindPipeDev failed !\n"); +- goto EXIT1; +- } +- ret = ViStartViPipe(pstViConfig); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_StartViPipe failed !\n"); +- goto EXIT1; +- } +- ret = ViStartViChn(pstViConfig); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_StartViChn failed !\n"); +- goto EXIT2; +- } +- return TD_SUCCESS; +-EXIT2: +- (void)ViStopViPipe(pstViConfig); +-EXIT1: +- (void)ViStopDev(pstViConfig); +- return ret; +-} +- +-static int32_t ViDisableChn(const CAMERA_VI_CONFIG_S *pstViConfig, ot_vi_pipe ViPipe, +- ot_vi_chn ViChn, td_bool bNeedChn) +-{ +- if (bNeedChn) { +- ot_vi_vpss_mode_type enMastPipeMode = pstViConfig->stPipeInfo.enMastPipeMode; +- if (enMastPipeMode == OT_VI_OFFLINE_VPSS_OFFLINE || enMastPipeMode == OT_VI_ONLINE_VPSS_OFFLINE || +- enMastPipeMode == OT_VI_PARALLEL_VPSS_OFFLINE) { +- int32_t ret = ss_mpi_vi_disable_chn(ViPipe, ViChn); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_disable_chn failed with %#x!\n", ret); +- return ret; +- } +- } +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViStopViChn(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { +- ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; +- if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { +- ot_vi_chn viChn = pstViConfig->stChnInfo.ViChn; +- td_bool bNeedChn = TD_FALSE; +- if (pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { +- bNeedChn = TD_TRUE; +- } else { +- bNeedChn = (i > 0) ? TD_FALSE : TD_TRUE; +- } +- int32_t ret = ViDisableChn(pstViConfig, viPipe, viChn, bNeedChn); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_vi_disable_chn failed with %#x!\n", ret); +- return ret; +- } +- } +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViDestroySingleVi(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- (void)ViStopViChn(pstViConfig); +- (void)ViStopViPipe(pstViConfig); +- (void)ViStopDev(pstViConfig); +- return TD_SUCCESS; +-} +-static int32_t CameraCreateVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- for (uint32_t i = 0; i < cameraCnt; i++) { +- int32_t ret = ViCreateSingleVi(&(pstViConfig[i])); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_CreateSingleVi failed !\n"); +- (void)ViDestroySingleVi(&pstViConfig[0]); +- } +- } +- return TD_SUCCESS; +-} +- +-static td_bool IsValidPath(const char *path, int size) +-{ +- if ((path == NULL) || (size == 0) || (size > SENSOR_DESC_MAX_LEN)) { +- return TD_FALSE; +- } +- if (strpbrk(path, "\"*+,:;<=>\?[]|\x7F")) { +- return TD_FALSE; +- } +- return TD_TRUE; +-} +- +-static void ViGetSnsObj(char *sensorLib, char *sensorObj, uint16_t cameraCnt, uint32_t snsId) +-{ +- char *pcdlsymError = NULL; +- if (!IsValidPath(sensorLib, cameraCnt)) { +- HI_PRINTF("sensor lib Path is valid Path:%s\n!", sensorLib); +- return; +- } +- if (snsId >= MAX_SENSOR_NUM) { +- HI_PRINTF("sns id error\n"); +- return; +- } +- g_snsLibHandle[snsId] = dlopen(sensorLib, RTLD_NOW); +- if (g_snsLibHandle[snsId] == NULL) { +- pcdlsymError = dlerror(); +- HI_PRINTF("dlopen sns lib error! %s\n", pcdlsymError); +- return; +- } +- (void)dlerror(); +- g_snsObj[snsId] = (ot_isp_sns_obj *)dlsym(g_snsLibHandle[snsId], sensorObj); +- if (g_snsObj[snsId] == NULL) { +- (void)dlclose(g_snsLibHandle[snsId]); +- g_snsLibHandle[snsId] = NULL; +- return; +- } +- pcdlsymError = dlerror(); +- if (pcdlsymError != NULL) { +- (void)dlclose(g_snsLibHandle[snsId]); +- g_snsLibHandle[snsId] = NULL; +- return; +- } +-} +- +-static const ot_isp_sns_obj *GetSnsObjById(uint32_t snsId) +-{ +- if (snsId >= MAX_SENSOR_NUM) { +- HI_PRINTF("invalid sensor id: %u\n", snsId); +- return NULL; +- } +- const ot_isp_sns_obj *snsObj = g_snsObj[snsId]; +- return snsObj; +-} +- +-static int32_t ViSensorRegiterCallback(ot_isp_dev IspDev, uint32_t u32SnsId, const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- if (IspDev >= ISP_MAX_DEV_NUM) { +- return TD_FAILURE; +- } +- const ot_isp_sns_obj *snsObj = GetSnsObjById(u32SnsId); +- if (snsObj == NULL) { +- HI_PRINTF("sensor %u not exist!\n", u32SnsId); +- return TD_FAILURE; +- } +- ot_isp_3a_alg_lib stAeLib; +- ot_isp_3a_alg_lib stAwbLib; +- stAeLib.id = IspDev; +- stAwbLib.id = IspDev; +- if (strncpy_s(stAeLib.lib_name, sizeof(stAeLib.lib_name), OT_AE_LIB_NAME, sizeof(OT_AE_LIB_NAME)) != EOK) { +- HI_PRINTF("strncpy_s stAeLib.lib_name failed"); +- return TD_FAILURE; +- } +- if (strncpy_s(stAwbLib.lib_name, sizeof(stAwbLib.lib_name), OT_AWB_LIB_NAME, sizeof(OT_AWB_LIB_NAME)) != EOK) { +- HI_PRINTF("strncpy_s stAwbLib.lib_name failed"); +- return TD_FAILURE; +- } +- if (snsObj->pfn_register_callback != NULL) { +- int32_t ret = snsObj->pfn_register_callback(IspDev, &stAeLib, &stAwbLib); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("sensor_register_callback failed with %#x!\n", ret); +- return ret; +- } +- } else { +- HI_PRINTF("sensor_register_callback failed with TD_NULL!\n"); +- } +- g_au32IspSnsId[IspDev] = u32SnsId; +- return TD_SUCCESS; +-} +- +-static int32_t ViIspBindSns(ot_isp_dev IspDev, uint32_t u32SnsId, td_s8 s8SnsDev) +-{ +- const ot_isp_sns_obj *snsObj = GetSnsObjById(u32SnsId); +- if (snsObj == NULL) { +- HI_PRINTF("sensor %u not exist!\n", u32SnsId); +- return TD_FAILURE; +- } +- ot_isp_sns_commbus uSnsBusInfo = { 0 }; +- uSnsBusInfo.i2c_dev = s8SnsDev; +- if (snsObj->pfn_set_bus_info != NULL) { +- int32_t ret = snsObj->pfn_set_bus_info(IspDev, uSnsBusInfo); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("set sensor bus info failed with %#x!\n", ret); +- return ret; +- } +- } else { +- HI_PRINTF("not support set sensor bus info!\n"); +- return TD_FAILURE; +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViIspAwblibUnCallback(ot_isp_dev IspDev) +-{ +- ot_isp_3a_alg_lib stAwbLib; +- stAwbLib.id = IspDev; +- HAL_LOG_DOFUNC(strncpy_s(stAwbLib.lib_name, sizeof(stAwbLib.lib_name), OT_AWB_LIB_NAME, sizeof(OT_AWB_LIB_NAME))); +- CHECK_RET(ss_mpi_awb_unregister(IspDev, &stAwbLib), "awblib unregister call back"); +- return TD_SUCCESS; +-} +-static int32_t ViIspAelibUnCallback(ot_isp_dev IspDev) +-{ +- ot_isp_3a_alg_lib stAeLib; +- stAeLib.id = IspDev; +- HAL_LOG_DOFUNC(strncpy_s(stAeLib.lib_name, sizeof(stAeLib.lib_name), OT_AE_LIB_NAME, sizeof(OT_AE_LIB_NAME))); +- CHECK_RET(ss_mpi_ae_unregister(IspDev, &stAeLib), "aelib unregister call back"); +- return TD_SUCCESS; +-} +- +-static int32_t ViIspSensorUnRegiterCallback(ot_isp_dev IspDev) +-{ +- ot_isp_3a_alg_lib stAeLib; +- ot_isp_3a_alg_lib stAwbLib; +- uint32_t snsId = g_au32IspSnsId[IspDev]; +- if (snsId >= MAX_SENSOR_NUM) { +- HI_PRINTF("%s: invalid sensor id: %u\n", __FUNCTION__, snsId); +- return TD_FAILURE; +- } +- const ot_isp_sns_obj *snsObj = g_snsObj[snsId]; +- if (snsObj == NULL) { +- return TD_FAILURE; +- } +- stAeLib.id = IspDev; +- stAwbLib.id = IspDev; +- HAL_LOG_DOFUNC(strncpy_s(stAeLib.lib_name, sizeof(stAeLib.lib_name), OT_AE_LIB_NAME, sizeof(OT_AE_LIB_NAME))); +- HAL_LOG_DOFUNC(strncpy_s(stAwbLib.lib_name, sizeof(stAwbLib.lib_name), OT_AWB_LIB_NAME, sizeof(OT_AWB_LIB_NAME))); +- if (snsObj->pfn_un_register_callback != NULL) { +- int32_t ret = snsObj->pfn_un_register_callback(IspDev, &stAeLib, &stAwbLib); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("sensor_unregister_callback failed with %#x!\n", ret); +- return ret; +- } +- } else { +- HI_PRINTF("sensor_unregister_callback failed with TD_NULL!\n"); +- } +- return TD_SUCCESS; +-} +- +-static void ViIspStop(ot_isp_dev IspDev) +-{ +- if (IspDev >= ISP_MAX_DEV_NUM) { +- return; +- } +- if (g_ispPid[IspDev] != 0) { +- ss_mpi_isp_exit(IspDev); +- pthread_join(g_ispPid[IspDev], NULL); +- ViIspAwblibUnCallback(IspDev); +- ViIspAelibUnCallback(IspDev); +- ViIspSensorUnRegiterCallback(IspDev); +- g_ispPid[IspDev] = 0; +- } +- return; +-} +- +-static int32_t ViIspAelibCallback(ot_isp_dev IspDev) +-{ +- ot_isp_3a_alg_lib stAeLib; +- stAeLib.id = IspDev; +- HAL_LOG_DOFUNC(strncpy_s(stAeLib.lib_name, sizeof(stAeLib.lib_name), OT_AE_LIB_NAME, sizeof(OT_AE_LIB_NAME))); +- CHECK_RET(ss_mpi_ae_register(IspDev, &stAeLib), "aelib register call back"); +- return TD_SUCCESS; +-} +- +-static int32_t ViIspAwblibCallback(ot_isp_dev IspDev) +-{ +- ot_isp_3a_alg_lib stAwbLib; +- stAwbLib.id = IspDev; +- HAL_LOG_DOFUNC(strncpy_s(stAwbLib.lib_name, sizeof(stAwbLib.lib_name), OT_AWB_LIB_NAME, sizeof(OT_AWB_LIB_NAME))); +- CHECK_RET(ss_mpi_awb_register(IspDev, &stAwbLib), "awblib register call back"); +- return TD_SUCCESS; +-} +- +-static void *ViIspThread(void *param) +-{ +- char szThreadName[THREAD_NAME_SIZE]; +- ot_isp_dev IspDev = (ot_isp_dev)param; +- if (snprintf_s(szThreadName, THREAD_NAME_SIZE, THREAD_NAME_SIZE - 1, "ISP%d_RUN", IspDev) >= 0) { +- prctl(PR_SET_NAME, szThreadName, 0, 0, 0); +- } +- +- HI_PRINTF("ISP Dev %d running !\n", IspDev); +- int32_t ret = ss_mpi_isp_run(IspDev); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ss_mpi_isp_run failed with %#x!\n", ret); +- } +- return NULL; +-} +- +-/* ***************************************************************************** +- * funciton : ISP Run +- * **************************************************************************** */ +-static int32_t ViIspRun(ot_isp_dev IspDev) +-{ +- pthread_attr_t *pstAttr = NULL; +- int32_t ret = pthread_create(&g_ispPid[IspDev], pstAttr, ViIspThread, (void *)IspDev); +- if (ret != 0) { +- HI_PRINTF("create isp running thread failed!, error: %d\n", ret); +- goto out; +- } +-out: +- if (pstAttr != NULL) { +- pthread_attr_destroy(pstAttr); +- } +- return ret; +-} +- +-static int32_t ViIspPrepare(const CAMERA_VI_CONFIG_S *pstViConfig, ot_vi_pipe ViPipe, uint32_t u32SnsId, int32_t index) +-{ +- int32_t ret = ViSensorRegiterCallback(ViPipe, u32SnsId, pstViConfig); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("register sensor %u to ISP %d failed\n", u32SnsId, ViPipe); +- ViIspStop(ViPipe); +- return TD_FAILURE; +- } +- if (((pstViConfig->stSnapInfo.bDoublePipe) && (pstViConfig->stSnapInfo.SnapPipe == ViPipe)) || +- (pstViConfig->stPipeInfo.bMultiPipe && index > 0)) { +- ret = ViIspBindSns(ViPipe, u32SnsId, -1); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("register sensor %u bus id %d failed\n", u32SnsId, pstViConfig->stSnsInfo.s32BusId); +- ViIspStop(ViPipe); +- return TD_FAILURE; +- } +- } else { +- ret = ViIspBindSns(ViPipe, u32SnsId, pstViConfig->stSnsInfo.s32BusId); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("register sensor %u bus id %d failed\n", u32SnsId, pstViConfig->stSnsInfo.s32BusId); +- ViIspStop(ViPipe); +- return TD_FAILURE; +- } +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViRunIsp(ot_vi_pipe ViPipe, ot_isp_pub_attr stPubAttr) +-{ +- int32_t ret = ViIspAelibCallback(ViPipe); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_ISP_Aelib_Callback failed\n"); +- ViIspStop(ViPipe); +- return TD_FAILURE; +- } +- +- ret = ViIspAwblibCallback(ViPipe); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_ISP_Awblib_Callback failed\n"); +- ViIspStop(ViPipe); +- return TD_FAILURE; +- } +- +- ret = ss_mpi_isp_mem_init(ViPipe); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("Init Ext memory failed with %#x!\n", ret); +- ViIspStop(ViPipe); +- return TD_FAILURE; +- } +- +- ret = ss_mpi_isp_set_pub_attr(ViPipe, &stPubAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("SetPubAttr failed with %#x!\n", ret); +- ViIspStop(ViPipe); +- return TD_FAILURE; +- } +- +- ret = ss_mpi_isp_init(ViPipe); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ISP Init failed with %#x!\n", ret); +- ViIspStop(ViPipe); +- return TD_FAILURE; +- } +- +- ret = ViIspRun(ViPipe); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ISP Run failed with %#x!\n", ret); +- ViIspStop(ViPipe); +- return TD_FAILURE; +- } +- return TD_SUCCESS; +-} +- +-static int32_t ViStartIsp(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- if (pstViConfig->pipeAttr->pipe_bypass_mode == OT_VI_PIPE_BYPASS_BE) { +- return TD_SUCCESS; +- } +- for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { +- ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; +- if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { +- uint32_t u32SnsId = pstViConfig->stSnsInfo.s32SnsId; +- ot_isp_pub_attr stPubAttr; +- HAL_LOG_DOFUNC(memcpy_s(&stPubAttr, sizeof(ot_isp_pub_attr), +- pstViConfig->ispPubAttr, sizeof(ot_isp_pub_attr))); +- td_bool bNeedPipe = TD_FALSE; +- if (pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { +- bNeedPipe = TD_TRUE; +- } else { +- bNeedPipe = (i > 0) ? TD_FALSE : TD_TRUE; +- } +- if (bNeedPipe != TD_TRUE) { +- continue; +- } +- int32_t ret = ViIspPrepare(pstViConfig, viPipe, u32SnsId, i); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ViIspPrepare failed with %#x!\n", ret); +- ViIspStop(viPipe); +- return TD_FAILURE; +- } +- ret = ViRunIsp(viPipe, stPubAttr); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("ISP Run failed with %#x!\n", ret); +- ViIspStop(viPipe); +- return TD_FAILURE; +- } +- } +- } +- +- return TD_SUCCESS; +-} +- +-static int32_t CameraCreateIsp(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- int32_t ret = TD_SUCCESS; +- for (uint32_t i = 0; i < cameraCnt; i++) { +- ret = ViStartIsp(&pstViConfig[i]); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_StartIsp failed !\n"); +- break; +- } +- } +- return ret; +-} +- +-static int32_t CameraDestroyVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- for (uint32_t i = 0; i < cameraCnt; i++) { +- (void)ViDestroySingleVi(&pstViConfig[i]); +- } +- return TD_SUCCESS; +-} +- +-int32_t CameraStartVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- if (pstViConfig == NULL) { +- HI_PRINTF("%s: null ptr\n", __FUNCTION__); +- return TD_FAILURE; +- } +- if (cameraCnt > MAX_SENSOR_NUM) { +- HI_PRINTF("ptr cameraCnt %u error\n", cameraCnt); +- return TD_FAILURE; +- } +- HI_PRINTF("lib:%s, obj:%s, len:%u\n", pstViConfig[0].sensorLib, pstViConfig[0].sensorObj, pstViConfig[0].len); +- uint32_t snsId = pstViConfig[0].stSnsInfo.s32SnsId; +- if (snsId >= MAX_SENSOR_NUM) { +- HI_PRINTF("sns id error\n"); +- return TD_FAILURE; +- } +- ViGetSnsObj(pstViConfig[0].sensorLib, pstViConfig[0].sensorObj, pstViConfig[0].len, snsId); +- if (cameraCnt == MAX_SENSOR_NUM) { +- uint32_t snsId1 = pstViConfig[1].stSnsInfo.s32SnsId; +- ViGetSnsObj(pstViConfig[1].sensorLib, pstViConfig[1].sensorObj, pstViConfig[1].len, snsId1); +- } +- int32_t ret = CameraStartMIPI(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("CameraStartMIPI failed!\n"); +- return TD_FAILURE; +- } +- ret = CameraSetParam(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("CameraSetParam failed!\n"); +- return TD_FAILURE; +- } +- +- ret = CameraCreateVi(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("CameraCreateVi failed!\n"); +- return TD_FAILURE; +- } +- +- ret = CameraCreateIsp(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- CameraDestroyVi(pstViConfig, cameraCnt); +- HI_PRINTF("CameraCreateIsp failed!\n"); +- return TD_FAILURE; +- } +- +- return ret; +-} +- +-static int32_t ViStopIsp(const CAMERA_VI_CONFIG_S *pstViConfig) +-{ +- for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { +- ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; +- if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { +- td_bool bNeedPipe = TD_FALSE; +- if (pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { +- bNeedPipe = TD_TRUE; +- } else { +- bNeedPipe = (i > 0) ? TD_FALSE : TD_TRUE; +- } +- if (bNeedPipe != TD_TRUE) { +- continue; +- } +- ViIspStop(viPipe); +- } +- } +- return TD_SUCCESS; +-} +- +-static int32_t CameraDestroyIsp(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- int32_t ret = TD_SUCCESS; +- for (uint32_t i = 0; i < cameraCnt; i++) { +- ret = ViStopIsp(&pstViConfig[i]); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("HISI_VI_StopIsp failed !\n"); +- } +- } +- return ret; +-} +- +-int32_t CameraStopVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +-{ +- if (pstViConfig == NULL) { +- HI_PRINTF("%s: null ptr\n", __FUNCTION__); +- return TD_FAILURE; +- } +- if (cameraCnt > MAX_SENSOR_NUM) { +- HI_PRINTF("ptr len %u error\n", cameraCnt); +- return TD_FAILURE; +- } +- int32_t ret = CameraDestroyIsp(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("CameraDestroyIsp failed !\n"); +- return TD_FAILURE; +- } +- ret = CameraDestroyVi(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("CameraDestroyVi failed !\n"); +- return TD_FAILURE; +- } +- +- ret = CameraStopMIPI(pstViConfig, cameraCnt); +- if (ret != TD_SUCCESS) { +- HI_PRINTF("CameraStopMIPI failed !\n"); +- return TD_FAILURE; +- } +- uint32_t snsId = pstViConfig->stSnsInfo.s32SnsId; +- if (snsId >= MAX_SENSOR_NUM) { +- HI_PRINTF("sns id error\n"); +- return TD_FAILURE; +- } +- if (g_snsLibHandle[snsId] != NULL) { +- (void)dlclose(g_snsLibHandle[snsId]); +- g_snsLibHandle[snsId] = NULL; +- g_snsObj[snsId] = NULL; +- HI_PRINTF("delete sensor lib snsid %u\n", snsId); +- } +- return ret; +-} +- +- +-#ifdef __cplusplus +-#if __cplusplus +-} +-#endif +-#endif /* End of #ifdef __cplusplus */ +- ++/* ++ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. ++ * ++ * 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. ++ */ + -+const int32_t VOLUME_DB_MIN = -121; -+const int32_t VOLUME_DB_MAX = 6; -+static const float VOLUME_PERCENT_MIN = 0.0f; -+static const float VOLUME_PERCENT_MAX = 100.0f; -+const int32_t VOLUME_PERCENT_BASE = 100; -+const int32_t PERCENT_TO_GAIN_LOG_FACTOR = 10; ++#include "hi_camera_vi.h" ++#include ++#include "ss_confaccess.h" ++#ifdef __cplusplus ++#if __cplusplus ++extern "C" { ++#endif ++#endif /* End of #ifdef __cplusplus */ ++ ++#define MIPI_DEV_NODE "/dev/ot_mipi_rx" ++#define MAX_SENSOR_NUM 2 ++#define ISP_MAX_DEV_NUM 4 ++#define THREAD_NAME_SIZE 20 ++#define INIT_PARAM_KEY_MAX_LEN 128 ++ ++/* product ini identification */ ++#define PDT_INIPARAM "productini" ++#define PDT_INIPARAM_PATH "/storage/data/media_config.ini" ++#define CAMERA_DEV_MODULE "camera_dev" ++static pthread_t g_ispPid[ISP_MAX_DEV_NUM] = { 0 }; ++static uint32_t g_au32IspSnsId[ISP_MAX_DEV_NUM] = { 0, 1 }; ++static void *g_snsLibHandle[MAX_SENSOR_NUM] = {NULL}; ++static ot_isp_sns_obj *g_snsObj[MAX_SENSOR_NUM] = {NULL}; ++static int32_t g_sensorDev[MAX_SENSOR_NUM] = { -1, -1 }; ++static uint32_t g_sensorCnt = 0; ++/* * ++Vi dev attr ++*/ ++static ot_vi_dev_attr g_devAttrDefaultBase = { ++ OT_VI_INTF_MODE_MIPI, ++ OT_VI_WORK_MODE_MULTIPLEX_1, ++ { 0xFFF00000, 0x0 }, ++ OT_VI_SCAN_PROGRESSIVE, ++ { -1, -1, -1, -1 }, ++ OT_VI_DATA_SEQ_YUYV, ++ /* port_vsync port_vsync_neg port_hsync port_hsync_neg */ ++ { ++ OT_VI_VSYNC_PULSE, ++ OT_VI_VSYNC_NEG_LOW, ++ OT_VI_HSYNC_VALID_SIG, ++ OT_VI_HSYNC_NEG_HIGH, ++ OT_VI_VSYNC_VALID_SIG, ++ OT_VI_VSYNC_VALID_NEG_HIGH, ++ ++ /* hsync_hfb hsync_act hsync_hhb */ ++ { 0, 1280, 0, ++ /* vsync0_vhb vsync0_act vsync0_hhb */ ++ 0, 720, 0, ++ /* vsync1_vhb vsync1_act vsync1_hhb */ ++ 0, 0, 0 } ++ }, ++ OT_VI_DATA_TYPE_RAW, ++ TD_FALSE, ++ { 1920, 1080 }, ++ OT_DATA_RATE_X1 ++}; + -+static void AudioRenderVolumePercentToDb(float volume, int32_t *db) ++static int32_t GetVbPoolParam(VB_PARAM_CONFIG_S *vbAttr) +{ -+ double tmpDb = PERCENT_TO_GAIN_LOG_FACTOR * log((double)volume / VOLUME_PERCENT_BASE); -+ if (tmpDb < VOLUME_DB_MIN) { -+ tmpDb = VOLUME_DB_MIN; -+ } else if (tmpDb > VOLUME_DB_MAX) { -+ tmpDb = VOLUME_DB_MAX; ++ char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; ++ td_s32 poolcnt = 0; ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, "vb:max_poolcnt", 0, &poolcnt); ++ if (poolcnt > OT_VB_MAX_COMMON_POOLS) { ++ HI_PRINTF("poolcnt:%d error, max:%d\n", poolcnt, OT_VB_MAX_COMMON_POOLS); ++ return TD_FAILURE; + } -+ *db = (int32_t)tmpDb; -+} + -+static void AudioOutputPortMngInit(void) -+{ -+ MEDIA_HAL_LOCK(g_audioOutputMngLock); -+ if (!g_audioOutputMngInited) { -+ for (int32_t i = 0; i < MAX_OUTPUT_PORT_CNT; i++) { -+ g_audioHwOutputPorts[i].used = false; -+ g_audioHwOutputPorts[i].chnID = i; -+ } -+ g_audioOutputMngInited = true; ++ vbAttr->stMaxPoolCnt = (td_u32)poolcnt; ++ ++ for (uint32_t i = 0; i < vbAttr->stMaxPoolCnt; i++) { ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vb.pool.%u:image_width", i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stImageSize[i].width); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vb.pool.%u:image_height", i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stImageSize[i].height); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vb.pool.%u:pix_format", i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stPixFormat[i]); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vb.pool.%u:data_bitwidth", i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stDataBitWidth[i]); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vb.pool.%u:compress_mode", i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stCompressMode[i]); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vb.pool.%u:default_align", i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stDefaultAlign[i]); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vb.pool.%u:blk_count", i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &vbAttr->stBlkCount[i]); ++ HI_PRINTF("vb pool %u image width=%u height=%u\n", i, ++ vbAttr->stImageSize[i].width, vbAttr->stImageSize[i].height); + } -+ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); ++ return TD_SUCCESS; +} + -+static int32_t AudioOutputPortMngGetFreeChn() ++static void GetViDevParam(ot_vi_dev_attr *viDevAttr, uint8_t index) +{ -+ MEDIA_HAL_LOCK(g_audioOutputMngLock); -+ if (!g_audioOutputMngInited) { -+ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); -+ return MEDIA_HAL_ERR; -+ } -+ for (int32_t i = 0; i < MAX_OUTPUT_PORT_CNT; i++) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "MAX_OUTPUT_PORT_CNT %d, g_audioHwOutputPorts[i].used = %d, chnID = %d", -+ MAX_OUTPUT_PORT_CNT, g_audioHwOutputPorts[i].used, g_audioHwOutputPorts[i].chnID); -+ if (!g_audioHwOutputPorts[i].used) { -+ g_audioHwOutputPorts[i].used = true; -+ int32_t chnID = g_audioHwOutputPorts[i].chnID; -+ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); -+ return chnID; -+ } -+ } -+ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); -+ MEDIA_HAL_LOGE(MODULE_NAME, "could get free audio Output channel"); -+ return MEDIA_HAL_ERR; ++ /* init dev attr */ ++ char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; ++ ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.dev:sensor_width", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viDevAttr->in_size.width); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.dev:sensor_height", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viDevAttr->in_size.height); +} + -+static int32_t AudioOutputPortGetFreeTrack(struct AudioSubPortOut *hwAudioOutputPort) ++static int32_t GetViMipiParam(combo_dev_attr_t *viMipiAttr, uint8_t index) +{ -+ MEDIA_HAL_LOCK(hwAudioOutputPort->mutex); -+ for (int32_t i = 0; i < MAX_OUTPUT_PORT_TRACK_CNT; i++) { -+ if (hwAudioOutputPort->hwOutputPortTrack[i] == NULL) { -+ MEDIA_HAL_UNLOCK(hwAudioOutputPort->mutex); -+ return i; -+ } ++ /* mipi attr */ ++ char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; ++ ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:combo_dev_t", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->devno); ++ HI_PRINTF("index %u devno %u\n", index, viMipiAttr->devno); ++ g_sensorDev[index] = viMipiAttr->devno; ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:input_mode_t", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->input_mode); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:mipi_data_rate_t", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->data_rate); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:img_rect_x", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->img_rect.x); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:img_rect_y", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->img_rect.y); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:img_rect_w", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->img_rect.width); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:img_rect_h", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->img_rect.height); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:data_type_t", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->mipi_attr.input_data_type); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:mipi_wdr_mode_t", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->mipi_attr.wdr_mode); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:lane_id_num", index)); ++ td_u32 laneIdNum = 0; ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &laneIdNum); ++ if (laneIdNum > MIPI_LANE_NUM) { ++ HI_PRINTF("lane_id_num:%u error, max:%d\n", laneIdNum, MIPI_LANE_NUM); ++ return TD_FAILURE; + } -+ MEDIA_HAL_UNLOCK(hwAudioOutputPort->mutex); -+ MEDIA_HAL_LOGE(MODULE_NAME, "could get free audio Output track"); -+ return MEDIA_HAL_ERR; ++ ++ for (uint32_t i = 0; i < laneIdNum; i++) { ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.mipi:lane_id_%u", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viMipiAttr->mipi_attr.lane_id[i]); ++ } ++ for (uint32_t i = laneIdNum; i < MIPI_LANE_NUM; i++) { ++ viMipiAttr->mipi_attr.lane_id[i] = -1; ++ } ++ ++ return TD_SUCCESS; +} + -+static int32_t AudioOutputPortFreeTrack(struct AudioSubPortOut *hwAudioOutputPort, -+ struct AudioSubPortOutTrack *hwOutputPortTrack) ++static void GetViIspPubParam(ot_isp_pub_attr *ispPubAttr, uint8_t index) +{ -+ MEDIA_HAL_LOCK(hwAudioOutputPort->mutex); -+ for (int32_t i = 0; i < MAX_OUTPUT_PORT_TRACK_CNT; i++) { -+ if (hwAudioOutputPort->hwOutputPortTrack[i] == hwOutputPortTrack) { -+ hwAudioOutputPort->hwOutputPortTrack[i] = NULL; -+ MEDIA_HAL_UNLOCK(hwAudioOutputPort->mutex); -+ return MEDIA_HAL_OK; -+ } -+ } -+ MEDIA_HAL_UNLOCK(hwAudioOutputPort->mutex); -+ MEDIA_HAL_LOGE(MODULE_NAME, "could not found audio Output track"); -+ return MEDIA_HAL_ERR; ++ /* isp_pub attr */ ++ char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; ++ ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:stWndRect_x", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wnd_rect.x); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:stWndRect_y", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wnd_rect.y); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:stWndRect_w", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wnd_rect.width); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:stWndRect_h", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wnd_rect.height); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:outImageSize_x", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->sns_size.width); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:outImageSize_y", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->sns_size.height); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:frameRate", index)); ++ td_double frameRate = 0; ++ SS_CONFACCESS_GetDouble(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &frameRate); ++ ispPubAttr->frame_rate = (td_float)frameRate; ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:bayer_format", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->bayer_format); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:wdrMode", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->wdr_mode); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:snsMode", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &ispPubAttr->sns_mode); +} + -+static int32_t AudioOutputPortMngFreeChn(int32_t chnID) ++static int32_t GetViPipeChnParam(uint32_t pipeId, VI_PARAM_CONFIG_S *viAttr, uint8_t index) +{ -+ MEDIA_HAL_LOCK(g_audioOutputMngLock); -+ if (!g_audioOutputMngInited) { -+ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); -+ return MEDIA_HAL_ERR; ++ char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; ++ ++ /* chn attr */ ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:chncnt", index, pipeId)); ++ uint32_t chnCnt = 0; ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnCnt); ++ if (chnCnt > MAX_CHN_NUM_PER_PIPE) { ++ HI_PRINTF("chncnt:%u error, max:%d\n", chnCnt, MAX_CHN_NUM_PER_PIPE); ++ return TD_FAILURE; + } -+ for (int32_t i = 0; i < MAX_OUTPUT_PORT_CNT; i++) { -+ if (g_audioHwOutputPorts[i].chnID == chnID) { -+ g_audioHwOutputPorts[i].used = false; -+ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); -+ return MEDIA_HAL_OK; -+ } ++ ++ for (uint32_t j = 0; j < chnCnt; j++) { ++ ot_vi_chn_attr *chnAttr = &viAttr->stChnAttr[pipeId][j]; ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:out_width", index, pipeId, j)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->size.width); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:out_height", index, pipeId, j)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->size.height); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:pixel_format", index, pipeId, j)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->pixel_format); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:dynamic_range", index, pipeId, j)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->dynamic_range); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:video_format", index, pipeId, j)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->video_format); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:compress_mode", index, pipeId, j)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->compress_mode); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:mirror_en", index, pipeId, j)); ++ int32_t isMirrorEnable = 0; ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &isMirrorEnable); ++ chnAttr->mirror_en = (isMirrorEnable != 0) ? TD_TRUE : TD_FALSE; ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:flip_en", index, pipeId, j)); ++ int32_t isFlipEnable = 0; ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &isFlipEnable); ++ chnAttr->flip_en = (isFlipEnable != 0) ? TD_TRUE : TD_FALSE; ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:depth", index, pipeId, j)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &chnAttr->depth); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:src_framerate", index, pipeId, j)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, ++ &chnAttr->frame_rate_ctrl.src_frame_rate); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u.chl.%u:dst_framerate", index, pipeId, j)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, ++ &chnAttr->frame_rate_ctrl.dst_frame_rate); + } -+ MEDIA_HAL_UNLOCK(g_audioOutputMngLock); -+ MEDIA_HAL_LOGE(MODULE_NAME, "freehandle input audio Output handle invalid : %d", chnID); -+ return MEDIA_HAL_ERR; ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortOutGetCapability(const struct AudioPort *port, -+ struct AudioPortCapability *capability) ++static int32_t GetViPipeParam(VI_PARAM_CONFIG_S *viAttr, uint8_t index) +{ -+ MEDIA_HAL_UNUSED(port); -+ CHK_NULL_RETURN(capability, MEDIA_HAL_INVALID_PARAM, "param capability null"); ++ char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; ++ /* pipe attr */ ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.dev:pipecnt", index)); ++ uint32_t pipeCnt = 0; ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeCnt); ++ if (pipeCnt > OT_VI_MAX_PIPE_NUM) { ++ HI_PRINTF("pipecnt:%u error, max:%d\n", pipeCnt, OT_VI_MAX_PIPE_NUM); ++ return TD_FAILURE; ++ } + -+ capability->channelCount = AUDIO_STEREO_SOUND_MODE_CHN_CNT; -+ MEDIA_HAL_LOGD(MODULE_NAME, "usb support stereo."); -+ return MEDIA_HAL_OK; -+} ++ for (uint32_t i = 0; i < pipeCnt; i++) { ++ ot_vi_pipe_attr *pipeAttr = &viAttr->stPipeAttr[i]; ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "common.vcap%u.pipe.%u:vivpssmode", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viAttr->pipeMode[i]); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:pipe_bypass_mode", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->pipe_bypass_mode); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:isp_bypass", index, i)); ++ int32_t isIspBypass = 0; ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &isIspBypass); ++ pipeAttr->isp_bypass = (isIspBypass != 0) ? TD_TRUE : TD_FALSE; ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:width", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->size.width); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:height", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->size.height); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:pixel_format", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->pixel_format); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:compress_mode", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &pipeAttr->compress_mode); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:src_framerate", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, ++ &pipeAttr->frame_rate_ctrl.src_frame_rate); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:dst_framerate", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, ++ &pipeAttr->frame_rate_ctrl.dst_frame_rate); ++ ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:interrupt_type", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0x5, ++ &viAttr->frameInterruptType[i]); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.pipe.%u:earlyLine", index, i)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viAttr->earlyLine[i]); ++ /* chn attr */ ++ if (GetViPipeChnParam(i, viAttr, index) != TD_SUCCESS) { ++ HI_PRINTF("GetViPipe[%u]ChnParam failed \n", i); ++ return TD_FAILURE; ++ } ++ } + -+static int32_t AoInit(ot_audio_dev aoDeviceId, ot_aio_attr *aoAttr) -+{ -+ // todo zhp -+ MEDIA_HAL_LOGE(MODULE_NAME, "AoInit success"); -+ return MEDIA_HAL_OK; ++ return TD_SUCCESS; +} + -+static int32_t AoSourceAttrConfig(struct PortPluginAttr *portAttr, ot_aio_attr *aoSourceAttr, enum AudioPortPin audioPortPin) ++static int32_t GetViParam(VI_PARAM_CONFIG_S *viAttr, uint8_t index) +{ -+ if (memset_s(aoSourceAttr, sizeof(ot_aio_attr), 0x0, sizeof(ot_aio_attr)) != EOK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s: hwOutputPort aoAttr failed"); -+ return MEDIA_HAL_ERR; ++ /* init dev attr */ ++ GetViDevParam(&viAttr->stDevAttr, index); ++ char szModuleNodeKey[INIT_PARAM_KEY_MAX_LEN] = { 0 }; ++ ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.dev:sensor_lib", index)); ++ const char *tmpValue = NULL; ++ SS_CONFACCESS_GetString(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, "/usr/lib/libsns_imx415.so", &tmpValue); ++ if (tmpValue != NULL) { ++ HAL_LOG_DOFUNC(strncpy_s(viAttr->sensorLib, SENSOR_DESC_MAX_LEN, tmpValue, SENSOR_DESC_MAX_LEN - 1)); + } -+ if (!AudioConvertSampleRateToHAL(portAttr->sampleRate, &aoSourceAttr->sample_rate)) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertSampleRateToHAL sample_rate: %d failed", portAttr->sampleRate); -+ return MEDIA_HAL_ERR; ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.dev:sensor_obj", index)); ++ SS_CONFACCESS_GetString(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, "g_sns_imx415_obj", &tmpValue); ++ if (tmpValue != NULL) { ++ HAL_LOG_DOFUNC(strncpy_s(viAttr->sensorObj, SENSOR_DESC_MAX_LEN, tmpValue, SENSOR_DESC_MAX_LEN - 1)); + } -+ aoSourceAttr->bit_width = OT_AUDIO_BIT_WIDTH_16; -+ aoSourceAttr->work_mode = OT_AIO_MODE_I2S_MASTER; -+ if (!AudioConvertChannelToHAL(portAttr->channelCount, &aoSourceAttr->snd_mode)) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "ConvertChannelToHAL channelCount: %u failed", portAttr->channelCount); -+ return MEDIA_HAL_ERR; ++ ++ /* mipi attr */ ++ if (GetViMipiParam(&viAttr->stMipiAttr, index) != TD_SUCCESS) { ++ HI_PRINTF("GetViMipiParam failed \n"); ++ return TD_FAILURE; + } -+ aoSourceAttr->chn_cnt = portAttr->channelCount; -+ aoSourceAttr->expand_flag = 0; -+ aoSourceAttr->frame_num = AUDIO_FRAME_NUM_OUT_BUF; -+ aoSourceAttr->point_num_per_frame = 4096; -+ aoSourceAttr->clk_share = 0; + -+ return MEDIA_HAL_OK; ++ /* isp_pub attr */ ++ GetViIspPubParam(&viAttr->stPubAttr, index); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.isp_pub:busId", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viAttr->busId); ++ HI_PRINTF(" busid = %d\n", viAttr->busId); ++ CHECK_SNPRINTF_PROC(snprintf_s(szModuleNodeKey, INIT_PARAM_KEY_MAX_LEN, INIT_PARAM_KEY_MAX_LEN - 1, ++ "vcap%u.dev:sensor_type", index)); ++ SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, szModuleNodeKey, 0, &viAttr->sensorType); ++ HI_PRINTF(" sensor type = %u\n", viAttr->sensorType); ++ /* pipe attr */ ++ if (GetViPipeParam(viAttr, index) != TD_SUCCESS) { ++ HI_PRINTF("GetViPipeParam failed \n"); ++ return TD_FAILURE; ++ } ++ ++ return TD_SUCCESS; +} + -+static int32_t ConfigAndEnableAO(AudioHandle portHandle, struct PortPluginAttr *portAttr, enum AudioPortPin audioPortPin) ++uint8_t GetParamCamera(const char path[PATH_MAX_LEN], InitParam *initParam, uint8_t cameraId) +{ -+ struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; -+ int32_t ret = AoSourceAttrConfig(portAttr, &hwPortCtx->aoSourceAttr, audioPortPin); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "ConfigAoSourceAttr failed"); -+ return ret; ++ int32_t ret = SS_CONFACCESS_Init(PDT_INIPARAM, PDT_INIPARAM_PATH); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("SS_CONFACCESS_Init failed\n"); ++ return cameraId + 1; + } -+ ot_aio_attr aoAttr = hwPortCtx->aoSourceAttr; -+ -+ MEDIA_HAL_LOGE(MODULE_NAME, "aoAttr.bit_width: %d, snd_mode: %d, sample_rate: %d, chn_cnt: %d", aoAttr.bit_width, aoAttr.snd_mode, -+ aoAttr.sample_rate, aoAttr.chn_cnt); -+ snd_pcm_hw_params_t *params; -+ snd_pcm_uframes_t frames = 4096; -+ snd_pcm_hw_params_malloc(¶ms); -+ snd_pcm_hw_params_any(hwPortCtx->ao_pcm_handle, params); -+ snd_pcm_hw_params_set_access(hwPortCtx->ao_pcm_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); -+ // todo zhp -+ // snd_pcm_format_t format -+ //AudioConvertFormatToAlsa(aoAttr.bit_width, &format); -+ snd_pcm_hw_params_set_format(hwPortCtx->ao_pcm_handle, params, SND_PCM_FORMAT_S16_LE); -+ snd_pcm_hw_params_set_channels(hwPortCtx->ao_pcm_handle, params, aoAttr.chn_cnt); -+ snd_pcm_hw_params_set_rate_near(hwPortCtx->ao_pcm_handle, params, &(aoAttr.sample_rate), 0); -+ snd_pcm_hw_params_set_period_size_near(hwPortCtx->ao_pcm_handle, params, &frames, 0); -+ snd_pcm_hw_params(hwPortCtx->ao_pcm_handle, params); -+ snd_pcm_hw_params_free(params); -+ -+ MEDIA_HAL_LOGE(MODULE_NAME, "aoAttr.frame_num: %d, point_num_per_frame: %d, period_size: %d", aoAttr.frame_num, aoAttr.point_num_per_frame, frames); -+ ++ g_sensorCnt = 0; ++ g_sensorDev[0] = -1; ++ g_sensorDev[1] = -1; + -+ ret = AoInit(hwPortCtx->aoDeviceId, &aoAttr); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AoInit failed %#x", ret); -+ return ret; ++ int32_t sensorCnt = 0; ++ ret = SS_CONFACCESS_GetInt(PDT_INIPARAM, CAMERA_DEV_MODULE, "common:sensorcnt", 0, &sensorCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("SS_CONFACCESS_GetInt failed\n"); + } -+ hwPortCtx->aoEnabled = true; -+ return MEDIA_HAL_OK; ++ // init vb ++ HI_PRINTF("sens count = %d\n", sensorCnt); ++ if (GetVbPoolParam(&initParam->stVbAttr) != TD_SUCCESS) { ++ HI_PRINTF("GetVbPoolParam failed\n"); ++ ret = SS_CONFACCESS_Deinit(PDT_INIPARAM); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("SS_CONFACCESS_Deinit failed\n"); ++ } ++ return cameraId + 1; ++ } ++ uint8_t i = 0; ++ for (; i < cameraId && i < sensorCnt; i++) { ++ if (GetViParam(&initParam[i].stViAttr, i) != TD_SUCCESS) { ++ HI_PRINTF("GetViPipeParam failed\n"); ++ ret = SS_CONFACCESS_Deinit(PDT_INIPARAM); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("SS_CONFACCESS_Deinit failed\n"); ++ } ++ return cameraId + 1; ++ } ++ } ++ ret = SS_CONFACCESS_Deinit(PDT_INIPARAM); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("SS_CONFACCESS_Deinit failed\n"); ++ } ++ g_sensorCnt = i; ++ return i; +} + -+int32_t AudioUsbSubPortOutOpen(AudioHandle *portHandle, int card_usb) ++static int32_t ViSetMipiHsMode(void) +{ -+ struct AudioSubPortOut *hwOutputPort = NULL; -+ CHK_NULL_RETURN(portHandle, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); -+ if (!g_audioOutputMngInited) { -+ AudioOutputPortMngInit(); -+ } -+ int32_t portIndex = AudioOutputPortMngGetFreeChn(); -+ if (portIndex == -1) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "can not found free Output Port"); -+ return MEDIA_HAL_INVALID_PARAM; -+ } -+ hwOutputPort = (struct AudioSubPortOut *)malloc(sizeof(struct AudioSubPortOut)); -+ if (hwOutputPort == NULL) { -+ (void)AudioOutputPortMngFreeChn(portIndex); -+ return MEDIA_HAL_NO_MEM; ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return -1; + } -+ if (memset_s(hwOutputPort, sizeof(struct AudioSubPortOut), 0, sizeof(struct AudioSubPortOut)) != EOK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s AudioSubPortOut failed"); ++ lane_divide_mode_t enHsMode; ++ if (g_sensorCnt == MAX_SENSOR_NUM && g_sensorDev[0] != g_sensorDev[1]) { ++ enHsMode = LANE_DIVIDE_MODE_1; // 2+2 ++ } else { ++ enHsMode = LANE_DIVIDE_MODE_0; // 4 + } -+ -+ hwOutputPort->aoDeviceId = portIndex; -+ char PCM_DEVICE[32]; -+ snprintf(PCM_DEVICE, sizeof(PCM_DEVICE), "hw:%d,0", card_usb); -+ int pcm = snd_pcm_open(&(hwOutputPort->ao_pcm_handle), PCM_DEVICE, SND_PCM_STREAM_PLAYBACK, 0); -+ if (pcm < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_open failed"); -+ return MEDIA_HAL_ERR; ++ int32_t ret = ioctl(fd, OT_MIPI_SET_HS_MODE, &enHsMode); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("OT_MIPI_SET_HS_MODE failed\n"); + } -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_open success"); ++ close(fd); ++ return ret; ++} + -+ int ret = snd_mixer_open(&(hwOutputPort->ao_mixer_handle), 0); -+ if (ret < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_open failed: %s\n", snd_strerror(ret)); -+ return ret; ++static int32_t ViEnableMipiClock(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ int32_t ret = TD_SUCCESS; ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return TD_FAILURE; + } -+ char CTL_DEVICE[32]; -+ snprintf(CTL_DEVICE, sizeof(CTL_DEVICE), "hw:%d", card_usb); -+ ret = snd_mixer_attach(hwOutputPort->ao_mixer_handle, CTL_DEVICE); -+ if (ret < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_mixer_attach failed: %s\n", snd_strerror(ret)); -+ snd_mixer_close(hwOutputPort->ao_mixer_handle); -+ return ret; ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ combo_dev_t devno = pstViConfig[i].stSnsInfo.MipiDev; ++ ret = ioctl(fd, OT_MIPI_ENABLE_MIPI_CLOCK, &devno); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("MIPI_ENABLE_CLOCK %u failed\n", devno); ++ break; ++ } + } ++ close(fd); ++ return ret; ++} + -+ snd_mixer_selem_register(hwOutputPort->ao_mixer_handle, NULL, NULL); -+ snd_mixer_load(hwOutputPort->ao_mixer_handle); -+ -+ // get element "Master" or "PCM" with volume control -+ snd_mixer_elem_t *elem = NULL; -+ for (elem = snd_mixer_first_elem(hwOutputPort->ao_mixer_handle); elem; elem = snd_mixer_elem_next(elem)) { -+ if (snd_mixer_selem_is_active(elem)) { -+ const char *name = snd_mixer_selem_get_name(elem); -+ if (((strcmp(name, "PCM") == 0) || (strcmp(name, "Master") == 0)) && snd_mixer_selem_has_playback_volume(elem)) { -+ hwOutputPort->ao_elem_vol = elem; -+ break; -+ } ++static int32_t ViDisableMipiClock(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return TD_FAILURE; ++ } ++ int32_t ret = TD_SUCCESS; ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ combo_dev_t devno = pstViConfig->stSnsInfo.MipiDev; ++ ret = ioctl(fd, OT_MIPI_DISABLE_MIPI_CLOCK, &devno); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("MIPI_DISABLE_CLOCK %u failed\n", devno); ++ break; + } + } ++ close(fd); ++ return ret; ++} + -+ if (!(hwOutputPort->ao_elem_vol)) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "Cannot find suitable mixer element (Master/PCM)\n"); -+ snd_mixer_close(hwOutputPort->ao_mixer_handle); -+ // maybe some device not support volume control -+ // return -1; ++static int32_t ViResetMipi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ int32_t ret = TD_SUCCESS; ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return TD_FAILURE; + } -+ -+ // get volume range -+ snd_mixer_selem_get_playback_volume_range(hwOutputPort->ao_elem_vol, &hwOutputPort->ao_min_vol, &hwOutputPort->ao_max_vol); -+ MEDIA_HAL_LOGE(MODULE_NAME, "Volume range: [%ld, %ld]\n", hwOutputPort->ao_min_vol, hwOutputPort->ao_max_vol); -+ -+ pthread_mutex_init(&hwOutputPort->mutex, NULL); -+ hwOutputPort->opened = true; -+ *portHandle = hwOutputPort; -+ MEDIA_HAL_LOGE(MODULE_NAME, "hwOutputPort open SUCCESS"); -+ return MEDIA_HAL_OK; ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ combo_dev_t devno = pstViConfig[i].stSnsInfo.MipiDev; ++ ret = ioctl(fd, OT_MIPI_RESET_MIPI, &devno); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("RESET_MIPI %u failed\n", devno); ++ break; ++ } ++ } ++ close(fd); ++ return ret; +} + -+int32_t AudioUsbSubPortOutClose(AudioHandle portHandle) ++static int32_t ViEnableSensorClock(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +{ -+ struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; -+ CHK_NULL_RETURN(hwPortCtx, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); -+ CHK_FAILED_RETURN(hwPortCtx->opened, true, MEDIA_HAL_ERR, "not inited"); -+ int32_t ret; ++ int32_t ret = TD_SUCCESS; ++ sns_clk_source_t snsDev; + -+ ret = AudioOutputPortMngFreeChn(hwPortCtx->aoDeviceId); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AudioOutputPortMngFreeChn failed"); ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return TD_FAILURE; + } -+ snd_mixer_close(hwPortCtx->ao_mixer_handle); -+ snd_pcm_drain(hwPortCtx->ao_pcm_handle); -+ snd_pcm_close(hwPortCtx->ao_pcm_handle); -+ pthread_mutex_destroy(&hwPortCtx->mutex); -+ hwPortCtx->opened = false; -+ free(hwPortCtx); -+ hwPortCtx = NULL; ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ snsDev = g_sensorDev[i]; ++ ret = ioctl(fd, OT_MIPI_ENABLE_SENSOR_CLOCK, &snsDev); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("OT_MIPI_ENABLE_SENSOR_CLOCK failed\n"); ++ break; ++ } ++ } ++ close(fd); ++ return ret; ++} + -+ return MEDIA_HAL_OK; ++static int32_t ViResetSensor(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ (void)pstViConfig; ++ int32_t ret = TD_SUCCESS; ++ sns_clk_source_t snsDev; ++ ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return TD_FAILURE; ++ } ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ snsDev = g_sensorDev[i]; ++ ret = ioctl(fd, OT_MIPI_RESET_SENSOR, &snsDev); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("OT_MIPI_RESET_SENSOR failed\n"); ++ break; ++ } ++ } ++ close(fd); ++ return ret; +} + -+int32_t AudioUsbSubPortOutGetLatency(AudioHandle trackHandle, uint32_t *latencyMs) ++static int32_t ViUnresetSensor(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +{ -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_NULL_RETURN(latencyMs, MEDIA_HAL_INVALID_PARAM, "input param buffer null"); -+ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); ++ int32_t ret = TD_SUCCESS; ++ sns_clk_source_t snsDev; + -+ *latencyMs = 20; -+ return MEDIA_HAL_OK; ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return TD_FAILURE; ++ } ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ snsDev = g_sensorDev[i]; ++ ret = ioctl(fd, OT_MIPI_UNRESET_SENSOR, &snsDev); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("OT_MIPI_UNRESET_SENSOR failed\n"); ++ break; ++ } ++ } ++ close(fd); ++ return ret; +} + ++static int32_t ViUnresetMipi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return TD_FAILURE; ++ } ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ combo_dev_t devno = pstViConfig[i].stSnsInfo.MipiDev; ++ int32_t ret = ioctl(fd, OT_MIPI_UNRESET_MIPI, &devno); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("UNRESET_MIPI %u failed\n", devno); ++ break; ++ } ++ } ++ close(fd); ++ return TD_SUCCESS; ++} + -+ -+int32_t AudioUsbSubPortOutEnableTrack(AudioHandle trackHandle) ++static int32_t ViSetMipiAttr(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +{ -+ int32_t ret; -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_FAILED_RETURN(hwPortTrackCtx->started, false, MEDIA_HAL_OK, "started yet"); ++ combo_dev_attr_t stcomboDevAttr; + -+ ret = snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); -+ if (ret != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_prepare left ret=0x%x", ret); -+ return ret; ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return TD_FAILURE; + } + -+ hwPortTrackCtx->started = true; ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ HAL_LOG_DOFUNC(memcpy_s(&stcomboDevAttr, sizeof(combo_dev_attr_t), ++ pstViConfig[i].mipiAttr, sizeof(combo_dev_attr_t))); + -+ MEDIA_HAL_LOGD(MODULE_NAME, "snd_pcm_prepare out"); -+ return MEDIA_HAL_OK; ++ stcomboDevAttr.devno = pstViConfig[i].stSnsInfo.MipiDev; ++ int32_t ret = ioctl(fd, OT_MIPI_SET_DEV_ATTR, &stcomboDevAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("OT_MIPI_SET_DEV_ATTR failed:ret= 0x%x dev:%u\n", ret, stcomboDevAttr.devno); ++ break; ++ } ++ } ++ close(fd); ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortOutPauseTrack(AudioHandle trackHandle) ++static int32_t CameraDisableSensorClock(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +{ -+ int32_t ret; -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); -+ snd_pcm_state_t state = snd_pcm_state(hwPortTrackCtx->ao_pcm_handle); -+ MEDIA_HAL_LOGI(MODULE_NAME, "Current PCM state: %d", state); ++ int32_t ret = TD_SUCCESS; + -+ if (state == SND_PCM_STATE_RUNNING) { -+ int ret = snd_pcm_pause(hwPortTrackCtx->ao_pcm_handle, 1); -+ if (ret == 0) { -+ MEDIA_HAL_LOGI(MODULE_NAME, "USB Audio paused."); -+ return MEDIA_HAL_OK; -+ } -+ // zhp todo -+ // if pause failed, try drain and prepare -+ if (ret < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_pause(1) failed: %s", snd_strerror(ret)); -+ ret = snd_pcm_drain(hwPortTrackCtx->ao_pcm_handle); -+ if (ret < 0) { -+ snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, ret, 0); -+ snd_pcm_drop(hwPortTrackCtx->ao_pcm_handle); -+ } -+ snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); -+ return MEDIA_HAL_OK; ++ int32_t fd = open(MIPI_DEV_NODE, O_RDWR); ++ if (fd < 0) { ++ HI_PRINTF("open hi_mipi dev failed\n"); ++ return TD_FAILURE; ++ } ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ sns_clk_source_t snsDev = pstViConfig[i].stDevInfo.ViDev; ++ ret = ioctl(fd, OT_MIPI_DISABLE_SENSOR_CLOCK, &snsDev); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("OT_MIPI_DISABLE_SENSOR_CLOCK failed\n"); ++ break; + } -+ } else { -+ MEDIA_HAL_LOGW(MODULE_NAME, "PCM not in running state, ignore pause"); + } -+ -+ return MEDIA_HAL_OK; ++ close(fd); ++ return ret; +} + -+int32_t AudioUsbSubPortOutResumeTrack(AudioHandle trackHandle) ++/* **************************************************************************** ++ * function : init mipi ++ * *************************************************************************** */ ++static int32_t CameraStartMIPI(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +{ -+ int32_t ret; -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ if (pstViConfig == NULL) { ++ HI_PRINTF("%s: null ptr\n", __FUNCTION__); ++ return TD_FAILURE; ++ } + -+ // todo zhp -+ snd_pcm_state_t state = snd_pcm_state(hwPortTrackCtx->ao_pcm_handle); -+ MEDIA_HAL_LOGI(MODULE_NAME, "Current PCM state: %d", state); ++ int32_t ret = ViSetMipiHsMode(); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_SetMipiHsMode failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = ViEnableMipiClock(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_EnableMipiClock failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = ViResetMipi(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_ResetMipi failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = ViEnableSensorClock(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_EnableSensorClock failed!\n"); ++ return TD_FAILURE; ++ } + -+ ret = snd_pcm_pause(hwPortTrackCtx->ao_pcm_handle, 0); -+ if (ret == 0) { -+ MEDIA_HAL_LOGI(MODULE_NAME, "USB Audio resumed."); -+ return 0; ++ ret = ViResetSensor(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_ResetSensor failed!\n"); ++ return TD_FAILURE; + } -+ if (ret < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_pause(0) failed: %s", snd_strerror(ret)); -+ MEDIA_HAL_LOGW(MODULE_NAME, "Pause not supported, trying recover..."); -+ ret = snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); -+ if (ret < 0) { -+ snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, ret, 0); -+ return MEDIA_HAL_ERR; -+ } ++ ret = ViSetMipiAttr(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_SetMipiAttr failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = ViUnresetMipi(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_UnresetMipi failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = ViUnresetSensor(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_UnresetSensor failed!\n"); ++ return TD_FAILURE; ++ } ++ return TD_SUCCESS; ++} + -+ return MEDIA_HAL_OK; ++static int32_t CameraStopMIPI(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ if (pstViConfig == NULL) { ++ HI_PRINTF("%s: null ptr\n", __FUNCTION__); ++ return TD_FAILURE; + } -+ snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, ret, 0); -+ return MEDIA_HAL_OK; ++ int32_t ret = ViResetSensor(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_ResetSensor failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = CameraDisableSensorClock(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_DisableSensorClock failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = ViResetMipi(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_ResetMipi failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = ViDisableMipiClock(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_DisableMipiClock failed!\n"); ++ return TD_FAILURE; ++ } ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortOutFlushTrack(AudioHandle trackHandle) ++int32_t HpCameraSetFps(td_float pf32Framerate) +{ -+ int32_t ret; -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); -+ snd_pcm_state_t state = snd_pcm_state(hwPortTrackCtx->ao_pcm_handle); -+ if (state == SND_PCM_STATE_RUNNING) { -+ snd_pcm_drop(hwPortTrackCtx->ao_pcm_handle); ++ ot_isp_pub_attr stIspPubAttr; ++ ot_vi_pipe ViPipe = 0; ++ HAL_LOG_DOFUNC(memset_s(&stIspPubAttr, sizeof(ot_isp_pub_attr), 0, sizeof(ot_isp_pub_attr))); ++ int32_t ret = ss_mpi_isp_get_pub_attr(ViPipe, &stIspPubAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_isp_get_pub_attr failed %x\n", ret); ++ return TD_FAILURE; + } -+ // setup pcm to prepare state -+ ret = snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); -+ if (ret < 0) { -+ snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, ret, 0); ++ /* 1.set mater isp pub attr */ ++ stIspPubAttr.frame_rate = pf32Framerate; ++ ret = ss_mpi_isp_set_pub_attr(ViPipe, &stIspPubAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_isp_set_pub_attr failed %x\n", ret); ++ return TD_FAILURE; + } -+ return MEDIA_HAL_OK; ++ return TD_SUCCESS; +} + -+static int32_t AudioUsbSubPortOutTrackSetMute(AudioHandle trackHandle, bool mute) ++int32_t HpCameraGetFps(void) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ ot_isp_pub_attr stIspPubAttr; ++ ot_vi_pipe ViPipe = 0; ++ HAL_LOG_DOFUNC(memset_s(&stIspPubAttr, sizeof(ot_isp_pub_attr), 0, sizeof(ot_isp_pub_attr))); ++ int32_t ret = ss_mpi_isp_get_pub_attr(ViPipe, &stIspPubAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_isp_get_pub_attr failed %x\n", ret); ++ return TD_FAILURE; ++ } ++ /* 1.set mater isp pub attr */ ++ return (int32_t)stIspPubAttr.frame_rate; ++} + -+ struct AudioSubPortOutTrack *hwOutputPortTrack = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_FAILED_RETURN(hwOutputPortTrack->inited, true, MEDIA_HAL_ERR, "track not init"); -+ if(mute) { // mute set output volume to 0 -+ snd_mixer_selem_set_playback_volume_all(hwOutputPortTrack->ao_elem_vol, 0); -+ } else { // unmute set output volume to last volume -+ long vol = hwOutputPortTrack->ao_min_vol + (hwOutputPortTrack->ao_max_vol - hwOutputPortTrack->ao_min_vol) * hwOutputPortTrack->volume / 100; -+ snd_mixer_selem_set_playback_volume_all(hwOutputPortTrack->ao_elem_vol, vol); ++static int32_t ConfigVIVPSSMode(const CAMERA_VI_CONFIG_S *viConfig, ot_vi_vpss_mode *viVpssMode) ++{ ++ ot_vi_pipe viPipe = viConfig->stPipeInfo.aPipe[0]; ++ HI_PRINTF("viPipe = %d\n", viPipe); ++ if (viPipe < 0 || viPipe >= OT_VI_MAX_PIPE_NUM) { ++ HI_PRINTF("viPipe is illgal %d!\n", viPipe); ++ return TD_FAILURE; + } -+ hwOutputPortTrack->mute = mute; -+ MEDIA_HAL_LOGI(MODULE_NAME, "set mute:%d success", mute); -+ return MEDIA_HAL_OK; ++ ++ viVpssMode->mode[viPipe] = OT_VI_ONLINE_VPSS_OFFLINE; ++ return TD_SUCCESS; +} + -+static int32_t AudioUsbSubPortOutTrackGetMute(AudioHandle trackHandle, bool *mute) ++static int32_t CameraSetParam(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ ot_vi_vpss_mode stVIVPSSMode = { 0 }; + -+ struct AudioSubPortOutTrack *hwOutputPortTrack = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_FAILED_RETURN(hwOutputPortTrack->inited, true, MEDIA_HAL_ERR, "track not init"); -+ *mute = hwOutputPortTrack->mute; -+ MEDIA_HAL_LOGI(MODULE_NAME, "Get mute success, current state is %s", *mute == true ? "mute" : "unmute"); -+ return MEDIA_HAL_OK; ++ int32_t ret = ss_mpi_sys_get_vi_vpss_mode(&stVIVPSSMode); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("Get VI-VPSS mode Param failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ ret = ConfigVIVPSSMode(&pstViConfig[i], &stVIVPSSMode); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ConfigVIVPSSMode failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ } ++ ret = ss_mpi_sys_set_vi_vpss_mode(&stVIVPSSMode); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("Set VI-VPSS mode Param failed with %#x!\n", ret); ++ } ++ return TD_SUCCESS; ++} ++ ++static int32_t ViGetDevAttr(ot_vi_dev_attr *pstViDevAttr, const CAMERA_VI_CONFIG_S *pstViConfig) ++{ ++ int ret = memcpy_s(pstViDevAttr, sizeof(ot_vi_dev_attr), &g_devAttrDefaultBase, sizeof(ot_vi_dev_attr)); ++ if (ret != EOK) { ++ HI_PRINTF("memcpy_s pstViDevAttr err\n"); ++ } ++ pstViDevAttr->in_size.width = pstViConfig->devAttr->in_size.width; ++ pstViDevAttr->in_size.height = pstViConfig->devAttr->in_size.height; ++ ++ return TD_SUCCESS; +} + -+static int32_t AudioUsbSubPortOutTrackSetVolume(AudioHandle trackHandle, float volume) ++static int32_t ViStartDev(const CAMERA_VI_CONFIG_S *pstViConfig) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ struct AudioSubPortOutTrack *hwOutputPortTrack = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_FAILED_RETURN(hwOutputPortTrack->inited, true, MEDIA_HAL_ERR, "track not init"); ++ ot_vi_dev_attr stViDevAttr = { 0 }; + -+ int32_t tmpValume; -+ int32_t ret; -+ if (volume < VOLUME_PERCENT_MIN || volume > VOLUME_PERCENT_MAX) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AudioUsbSubPortOutTrackSetVolume, volume:%f err, it should [%f,%f]", volume, -+ VOLUME_PERCENT_MIN, VOLUME_PERCENT_MAX); -+ return MEDIA_HAL_INVALID_PARAM; -+ } -+ const float EPSINON = 0.00001; -+ if ((volume >= -EPSINON) && (volume <= EPSINON)) { -+ ot_audio_fade fade = {}; -+ hwOutputPortTrack->volume = volume; -+ snd_mixer_selem_set_playback_volume_all(hwOutputPortTrack->ao_elem_vol, 0); -+ return MEDIA_HAL_OK; ++ ot_vi_dev ViDev = pstViConfig->stDevInfo.ViDev; ++ ViGetDevAttr(&stViDevAttr, pstViConfig); ++ if (pstViConfig->stPipeInfo.enMastPipeMode == OT_VI_PARALLEL_VPSS_OFFLINE || ++ pstViConfig->stPipeInfo.enMastPipeMode == OT_VI_PARALLEL_VPSS_PARALLEL) { ++ stViDevAttr.data_rate = OT_DATA_RATE_X2; + } + -+ long vol = hwOutputPortTrack->ao_min_vol + (hwOutputPortTrack->ao_max_vol - hwOutputPortTrack->ao_min_vol) * volume / 100; -+ ret = snd_mixer_selem_set_playback_volume_all(hwOutputPortTrack->ao_elem_vol, vol); -+ if (ret < 0) { -+ MEDIA_HAL_LOGI(MODULE_NAME, "SetVolume failed: %s\n", snd_strerror(ret)); -+ return ret; ++ int32_t ret = ss_mpi_vi_set_dev_attr(ViDev, &stViDevAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_set_dev_attr failed with %#x!\n", ret); ++ return TD_FAILURE; + } -+ MEDIA_HAL_LOGI(MODULE_NAME, "SetVolume: %d (raw=%ld)\n", volume, vol); + -+ hwOutputPortTrack->volume = volume; ++ ret = ss_mpi_vi_enable_dev(ViDev); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_enable_dev failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } + -+ return MEDIA_HAL_OK; ++ return TD_SUCCESS; +} + -+static int32_t AudioUsbSubPortOutTrackGetVolume(AudioHandle trackHandle, float *volume) ++static int32_t ViBindPipeDev(const CAMERA_VI_CONFIG_S *pstViConfig) +{ -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); ++ int32_t pipeCnt = 0; ++ int32_t ret = 0; ++ ot_vi_bind_pipe devBindPipe = { 0 }; ++ ++ for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { ++ ot_vi_pipe aPipe = pstViConfig->stPipeInfo.aPipe[i]; ++ if (aPipe >= 0 && aPipe < OT_VI_MAX_PIPE_NUM) { ++ devBindPipe.pipe_id[pipeCnt] = aPipe; ++ pipeCnt++; ++ devBindPipe.pipe_num = pipeCnt; ++ ret = ss_mpi_vi_bind(pstViConfig->stDevInfo.ViDev, aPipe); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_bind failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ } ++ } + -+ struct AudioSubPortOutTrack *hwOutputPortTrack = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_FAILED_RETURN(hwOutputPortTrack->inited, true, MEDIA_HAL_ERR, "track not init"); -+ *volume = hwOutputPortTrack->volume; -+ return MEDIA_HAL_OK; ++ return ret; +} + -+static void AudioRenderFillAudioFrame(const struct AudioSubPortOutTrack *hwPortTrack, const uint8_t *data, -+ uint64_t len, ot_audio_frame *audioFrame) ++static int32_t ViStopSingleViPipe(ot_vi_pipe ViPipe) +{ -+ const uint32_t channels[OT_AUDIO_SOUND_MODE_BUTT] = {1, 2}; -+ audioFrame->bit_width = hwPortTrack->aoSourceAttr.bit_width; -+ audioFrame->snd_mode = hwPortTrack->aoSourceAttr.snd_mode; -+ audioFrame->time_stamp = 0; -+ audioFrame->seq = (uint32_t)hwPortTrack->frames; -+ audioFrame->phys_addr[0] = 0; -+ audioFrame->phys_addr[1] = 0; -+ audioFrame->pool_id[0] = 0; -+ audioFrame->pool_id[1] = 0; -+ if (audioFrame->snd_mode == OT_AUDIO_SOUND_MODE_MONO) { -+ audioFrame->virt_addr[0] = (uint8_t*)data; -+ audioFrame->virt_addr[1] = NULL; -+ audioFrame->len = (uint32_t)len; -+ } else if (audioFrame->snd_mode == OT_AUDIO_SOUND_MODE_STEREO) { -+ audioFrame->virt_addr[0] = (uint8_t*)data; -+ audioFrame->virt_addr[1] = (uint8_t*)data + len / channels[hwPortTrack->aoSourceAttr.snd_mode]; -+ audioFrame->len = (uint32_t)len / channels[hwPortTrack->aoSourceAttr.snd_mode]; ++ int32_t ret = ss_mpi_vi_stop_pipe(ViPipe); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_stop_pipe failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ ++ ret = ss_mpi_vi_destroy_pipe(ViPipe); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_destroy_pipe failed with %#x!\n", ret); ++ return TD_FAILURE; + } -+} + ++ return ret; ++} + -+int32_t AudioUsbSubPortOutSendFrame(AudioHandle trackHandle, const uint8_t *buffer, -+ uint64_t requestBytes, uint64_t *replyBytes) ++static int32_t ViCreatePipe(const CAMERA_VI_CONFIG_S *pstViConfig, ot_vi_pipe ViPipe, ++ ot_vi_pipe_attr *stPipeAttr, int32_t i) +{ -+ int32_t ret,offset; -+ int32_t tryNum = 3; -+ long frames; -+ ot_ao_chn_state chnStatus = {}; -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_NULL_RETURN(buffer, MEDIA_HAL_INVALID_PARAM, "input param buffer null"); -+ CHK_NULL_RETURN(replyBytes, MEDIA_HAL_INVALID_PARAM, "input param replyBytes null"); -+ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); -+ -+ int bytes_per_sample = (hwPortTrackCtx->aoSourceAttr.bit_width + 1); // bit_width =0 8bit; bit_width =1 16bit. -+ int channels = (hwPortTrackCtx->aoSourceAttr.snd_mode == OT_AUDIO_SOUND_MODE_STEREO) ? 2 : 1; -+ int bytes_per_frame = bytes_per_sample * channels; -+ uint8_t *interleaved_buf = NULL; -+ // 如果是立体声,需要转换为 interleaved 格式 -+ if (channels == 2) { -+ uint64_t frames_count = requestBytes / (bytes_per_sample * 2); // 每声道帧数 -+ interleaved_buf = malloc(requestBytes); -+ if (!interleaved_buf) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "malloc interleaved_buf failed"); -+ return MEDIA_HAL_NO_MEM; -+ } ++ ot_frame_interrupt_attr frameIntAttr = { 0 }; + -+ uint8_t *ch0 = (uint8_t *)buffer; -+ uint8_t *ch1 = (uint8_t *)buffer + frames_count * bytes_per_sample; -+ for (uint64_t i = 0; i < frames_count; i++) { -+ memcpy(interleaved_buf + i * bytes_per_frame, ch0 + i * bytes_per_sample, bytes_per_sample); -+ memcpy(interleaved_buf + i * bytes_per_frame + bytes_per_sample, ch1 + i * bytes_per_sample, bytes_per_sample); ++ int32_t ret = ss_mpi_vi_create_pipe(ViPipe, stPipeAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_create_pipe failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ if (pstViConfig->stPipeInfo.bVcNumCfged == TD_TRUE) { ++ ret = ss_mpi_vi_set_pipe_vc_number(ViPipe, pstViConfig->stPipeInfo.u32VCNum[i]); ++ if (ret != TD_SUCCESS) { ++ ss_mpi_vi_destroy_pipe(ViPipe); ++ HI_PRINTF("ss_mpi_vi_set_pipe_vc_number failed with %#x!\n", ret); ++ return TD_FAILURE; + } -+ buffer = interleaved_buf; + } -+#if DEBUG -+ static FILE *fp_debug = NULL; -+ if (fp_debug == NULL) { -+ fp_debug = fopen("/userdata/usb_out.pcm", "wb"); ++ if (pstViConfig->stPipeInfo.frameInterruptType < OT_FRAME_INTERRUPT_BUTT && ++ pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { ++ frameIntAttr.interrupt_type = pstViConfig->stPipeInfo.frameInterruptType; ++ frameIntAttr.early_line = pstViConfig->stPipeInfo.earlyLine; ++ ret = ss_mpi_vi_set_pipe_frame_interrupt_attr(ViPipe, &frameIntAttr); ++ HI_PRINTF(" ss_mpi_vi_set_pipe_frame_interrupt_attr type %d %u ret = %d\n", frameIntAttr.interrupt_type, ++ frameIntAttr.early_line, ret); + } -+ if (fp_debug) { -+ fwrite(buffer, 1, requestBytes, fp_debug); ++ ret = ss_mpi_vi_start_pipe(ViPipe); ++ if (ret != TD_SUCCESS) { ++ ss_mpi_vi_destroy_pipe(ViPipe); ++ HI_PRINTF("ss_mpi_vi_start_pipe failed with %#x!\n", ret); ++ return TD_FAILURE; + } -+#endif -+ uint64_t remaining_bytes = requestBytes; -+ while (remaining_bytes > 0) { -+ frames = snd_pcm_writei(hwPortTrackCtx->ao_pcm_handle, buffer, remaining_bytes / bytes_per_frame); -+#if DEBUG -+ snd_pcm_state_t state = snd_pcm_state(hwPortTrackCtx->ao_pcm_handle); -+ MEDIA_HAL_LOGE(MODULE_NAME, "PCM state = %d, bytes_per_frame = %d", state, bytes_per_frame); -+ MEDIA_HAL_LOGE(MODULE_NAME, "first 8 bytes: %02x %02x %02x %02x %02x %02x %02x %02x", -+ buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]); -+#endif -+ if (frames > 0) { -+ size_t bytes_written = frames * bytes_per_frame; -+ remaining_bytes -= bytes_written; -+ buffer += bytes_written; -+ } else if (frames == -EAGAIN) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "render PCM writei -EAGAIN"); -+ snd_pcm_wait(hwPortTrackCtx->ao_pcm_handle, PCM_WAIT_TIMEOUT_MS); -+ tryNum--; -+ if (tryNum == 0) { -+ return MEDIA_HAL_OK; -+ } -+ } else if (frames == -EBADFD) { -+ /* not #SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING */ -+ MEDIA_HAL_LOGE(MODULE_NAME, "render PCM is not in the right state : %s", snd_strerror(frames)); -+ snd_pcm_prepare(hwPortTrackCtx->ao_pcm_handle); -+ return MEDIA_HAL_ERR; -+ } else { -+ /* -ESTRPIPE: a suspend event occurred, -+ * stream is suspended and waiting for an application recovery. -+ * -EPIPE: an underrun occurred. -+ */ -+ MEDIA_HAL_LOGE(MODULE_NAME, "err: %{public}s", snd_strerror(frames)); -+ ret = snd_pcm_recover(hwPortTrackCtx->ao_pcm_handle, frames, 0); // 0 for open render recover log. -+ if (ret < 0) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "snd_pcm_writei failed: %{public}s", snd_strerror(ret)); -+ return MEDIA_HAL_ERR; ++ return TD_SUCCESS; ++} ++ ++static int32_t ViDoCreatePipe(const CAMERA_VI_CONFIG_S *pstViConfig, ot_vi_pipe ViPipe, ++ ot_vi_pipe_attr *stPipeAttr, int32_t index) ++{ ++ int32_t ret; ++ if ((pstViConfig->stSnapInfo.bSnap) && (pstViConfig->stSnapInfo.bDoublePipe) && ++ (ViPipe == pstViConfig->stSnapInfo.SnapPipe)) { ++ ret = ss_mpi_vi_create_pipe(ViPipe, stPipeAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_create_pipe failed with %#x!\n", ret); ++ for (int32_t j = 0; j < index; j++) { ++ ot_vi_pipe stopViPipe = j; ++ (void)ViStopSingleViPipe(stopViPipe); + } ++ return ret; ++ } ++ } else { ++ ret = ViCreatePipe(pstViConfig, ViPipe, stPipeAttr, index); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_create_pipe failed with %#x!\n", ret); ++ return TD_FAILURE; + } + } -+ -+ *replyBytes = requestBytes; -+ hwPortTrackCtx->frames++; -+ return MEDIA_HAL_OK; ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortOutTrackGetPosition(AudioHandle trackHandle, uint64_t *frames, -+ struct AudioTimeStamp *time) ++static int32_t ViStartViPipe(const CAMERA_VI_CONFIG_S *pstViConfig) +{ -+ // ot_ao_chn_state chnStatus = {}; -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_NULL_RETURN(frames, MEDIA_HAL_INVALID_PARAM, "input param frames null"); -+ CHK_NULL_RETURN(time, MEDIA_HAL_INVALID_PARAM, "input param time null"); -+ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); -+ -+ *frames = hwPortTrackCtx->frames - 0; -+ time->tvSec = hwPortTrackCtx->currentPts / TIME_S_TO_US_SCALE; -+ time->tvNSec = (hwPortTrackCtx->currentPts % TIME_S_TO_US_SCALE) / TIME_US_TO_NS_SCALE; -+ return MEDIA_HAL_OK; ++ for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { ++ ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; ++ if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { ++ ot_vi_pipe_attr stPipeAttr; ++ HAL_LOG_DOFUNC(memcpy_s(&stPipeAttr, sizeof(ot_vi_pipe_attr), ++ pstViConfig->pipeAttr, sizeof(ot_vi_pipe_attr))); ++ if (pstViConfig->stPipeInfo.ispBypass == TD_TRUE) { ++ stPipeAttr.isp_bypass = TD_TRUE; ++ stPipeAttr.pixel_format = pstViConfig->stPipeInfo.pixelFormat; ++ } ++ if ((viPipe == 0x2) || (viPipe == 0x3)) { ++ stPipeAttr.compress_mode = OT_COMPRESS_MODE_NONE; ++ } ++ int32_t ret = ViDoCreatePipe(pstViConfig, viPipe, &stPipeAttr, i); ++ if (ret != TD_SUCCESS) { ++ return ret; ++ } ++ } ++ } ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortOutDisableTrack(AudioHandle trackHandle) ++static int32_t ViEnableChn(ot_vi_pipe ViPipe, ot_vi_chn ViChn, ot_vi_chn_attr stChnAttr, td_bool bNeedChn, ++ const CAMERA_VI_CONFIG_S *pstViConfig) +{ -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_FAILED_RETURN(hwPortTrackCtx->started, true, MEDIA_HAL_ERR, "not started yet"); ++ if (bNeedChn) { ++ int32_t ret = ss_mpi_vi_set_chn_attr(ViPipe, ViChn, &stChnAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_set_chn_attr failed with %#x!\n", ret); ++ return ret; ++ } ++ ot_vi_vpss_mode_type enMastPipeMode = pstViConfig->stPipeInfo.enMastPipeMode; ++ if (enMastPipeMode == OT_VI_OFFLINE_VPSS_OFFLINE || enMastPipeMode == OT_VI_ONLINE_VPSS_OFFLINE || ++ enMastPipeMode == OT_VI_PARALLEL_VPSS_OFFLINE) { ++ ret = ss_mpi_vi_enable_chn(ViPipe, ViChn); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_enable_chn failed with %#x!\n", ret); ++ return ret; ++ } ++ } + -+ snd_pcm_drain(hwPortTrackCtx->ao_pcm_handle); -+ hwPortTrackCtx->vqeScene = VQE_SCENE_NONE; -+ hwPortTrackCtx->started = false; -+ return MEDIA_HAL_OK; ++#if defined(ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY) && (ENABLE_DISTRIBUTED_CAMERA_LOW_DELAY != 0) ++ ot_low_delay_info viLdyInfo; ++ ret = ss_mpi_vi_get_chn_low_delay(ViPipe, ViChn, &viLdyInfo); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_get_chn_low_delay failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++ viLdyInfo.enable = TD_TRUE; ++ viLdyInfo.line_cnt = 16; /* 16:VDEC_LOW_DELAY_MIN_LINE */ ++ ret = ss_mpi_vi_set_chn_low_delay(ViPipe, ViChn, &viLdyInfo); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_set_chn_low_delay failed with %#x\n", ret); ++ return TD_FAILURE; ++ } ++#endif ++ } ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortOutDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle) ++static int32_t ViStartViChn(const CAMERA_VI_CONFIG_S *pstViConfig) +{ -+ struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; -+ CHK_NULL_RETURN(hwPortCtx, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ int32_t ret = AudioOutputPortFreeTrack(hwPortCtx, hwPortTrackCtx); -+ if (ret == MEDIA_HAL_ERR) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "invalid trackHandle"); -+ return MEDIA_HAL_INVALID_PARAM; ++ for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { ++ ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; ++ if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { ++ ot_vi_chn ViChn = pstViConfig->stChnInfo.ViChn; ++ ot_vi_chn_attr stChnAttr; ++ HAL_LOG_DOFUNC(memcpy_s(&stChnAttr, sizeof(ot_vi_chn_attr), ++ pstViConfig->chnAttr, sizeof(ot_vi_chn_attr))); ++ td_bool bNeedChn = TD_FALSE; ++ if (pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { ++ bNeedChn = TD_TRUE; ++ } else { ++ bNeedChn = (i > 0) ? TD_FALSE : TD_TRUE; ++ } ++ int32_t ret = ViEnableChn(viPipe, ViChn, stChnAttr, bNeedChn, pstViConfig); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ViEnableChn failed with %#x!\n", ret); ++ return ret; ++ } ++ } + } + -+ -+ free(hwPortTrackCtx); -+ return MEDIA_HAL_OK; ++ return TD_SUCCESS; +} -+ -+int32_t AudioUsbSubPortOutInvoke(AudioHandle trackHandle, -+ enum InvokeID invokeID, struct InvokeAttr *invokeAttr) ++static int32_t ViStopViPipe(const CAMERA_VI_CONFIG_S *pstViConfig) +{ -+ int32_t ret = MEDIA_HAL_OK; -+ struct AudioSubPortOutTrack *hwPortTrackCtx = (struct AudioSubPortOutTrack *)trackHandle; -+ CHK_NULL_RETURN(hwPortTrackCtx, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ CHK_NULL_RETURN(invokeAttr, MEDIA_HAL_INVALID_PARAM, "input param invokeAttr null"); -+ CHK_NULL_RETURN(invokeAttr->request, MEDIA_HAL_INVALID_PARAM, "input param request null"); -+ CHK_FAILED_RETURN(hwPortTrackCtx->inited, true, MEDIA_HAL_ERR, "not inited"); -+ switch (invokeID) { -+ default: -+ MEDIA_HAL_LOGW(MODULE_NAME, "Invalid invokeID: %d", invokeID); -+ return MEDIA_HAL_INVALID_PARAM; ++ for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { ++ ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; ++ if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { ++ (void)ViStopSingleViPipe(viPipe); ++ } + } -+ return MEDIA_HAL_OK; ++ return TD_SUCCESS; ++} ++static int32_t ViStopDev(const CAMERA_VI_CONFIG_S *pstViConfig) ++{ ++ ot_vi_dev viDev = pstViConfig->stDevInfo.ViDev; ++ ot_vi_bind_pipe bindPipe = {0}; ++ int32_t ret = ss_mpi_vi_get_bind_by_dev(viDev, &bindPipe); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_get_bind_by_dev failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ for (int32_t i = 1; i <= bindPipe.pipe_num; i++) { ++ ret = ss_mpi_vi_unbind(viDev, bindPipe.pipe_id[i]); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_unbind failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ } ++ ret = ss_mpi_vi_disable_dev(viDev); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_disable_dev failed with %#x!\n", ret); ++ return TD_FAILURE; ++ } ++ return TD_SUCCESS; +} + -+static void SubPortTrackOutLoadImpl(struct AudioSubPortOutTrack *portTrackOutCtx, -+ const struct PortPluginAttr *inputAttr, enum AudioPortPin audioPortPin) ++static int32_t ViCreateSingleVi(const CAMERA_VI_CONFIG_S *pstViConfig) +{ -+ portTrackOutCtx->inputAttr = *inputAttr; ++ int32_t ret = ViStartDev(pstViConfig); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_StartDev failed !\n"); ++ return TD_FAILURE; ++ } ++ ret = ViBindPipeDev(pstViConfig); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_BindPipeDev failed !\n"); ++ goto EXIT1; ++ } ++ ret = ViStartViPipe(pstViConfig); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_StartViPipe failed !\n"); ++ goto EXIT1; ++ } ++ ret = ViStartViChn(pstViConfig); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_StartViChn failed !\n"); ++ goto EXIT2; ++ } ++ return TD_SUCCESS; ++EXIT2: ++ (void)ViStopViPipe(pstViConfig); ++EXIT1: ++ (void)ViStopDev(pstViConfig); ++ return ret; ++} + -+ portTrackOutCtx->common.audioPin = audioPortPin; -+ portTrackOutCtx->common.GetFrameCount = NULL; -+ portTrackOutCtx->common.GetLatency = AudioUsbSubPortOutGetLatency; -+ portTrackOutCtx->common.EnableTrack = AudioUsbSubPortOutEnableTrack; -+ portTrackOutCtx->common.DisableTrack = AudioUsbSubPortOutDisableTrack; -+ portTrackOutCtx->common.PauseTrack = AudioUsbSubPortOutPauseTrack; -+ portTrackOutCtx->common.ResumeTrack = AudioUsbSubPortOutResumeTrack; -+ portTrackOutCtx->common.FlushTrack = AudioUsbSubPortOutFlushTrack; -+ portTrackOutCtx->common.AcquireFrame = NULL; -+ portTrackOutCtx->common.SendFrame = AudioUsbSubPortOutSendFrame; -+ portTrackOutCtx->common.GetPosition = AudioUsbSubPortOutTrackGetPosition; -+ portTrackOutCtx->common.SetMute = AudioUsbSubPortOutTrackSetMute; -+ portTrackOutCtx->common.GetMute = AudioUsbSubPortOutTrackGetMute; -+ portTrackOutCtx->common.SetVolume = AudioUsbSubPortOutTrackSetVolume; -+ portTrackOutCtx->common.GetVolume = AudioUsbSubPortOutTrackGetVolume; -+ portTrackOutCtx->common.Invoke = AudioUsbSubPortOutInvoke; -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return; ++static int32_t ViDisableChn(const CAMERA_VI_CONFIG_S *pstViConfig, ot_vi_pipe ViPipe, ++ ot_vi_chn ViChn, td_bool bNeedChn) ++{ ++ if (bNeedChn) { ++ ot_vi_vpss_mode_type enMastPipeMode = pstViConfig->stPipeInfo.enMastPipeMode; ++ if (enMastPipeMode == OT_VI_OFFLINE_VPSS_OFFLINE || enMastPipeMode == OT_VI_ONLINE_VPSS_OFFLINE || ++ enMastPipeMode == OT_VI_PARALLEL_VPSS_OFFLINE) { ++ int32_t ret = ss_mpi_vi_disable_chn(ViPipe, ViChn); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_disable_chn failed with %#x!\n", ret); ++ return ret; ++ } ++ } ++ } ++ return TD_SUCCESS; +} + -+int32_t AudioUsbSubPortOutCreateTrack(AudioHandle portHandle, AudioHandle *trackHandle, -+ struct PortPluginAttr *portAttr, enum AudioPortPin audioPortPin) ++static int32_t ViStopViChn(const CAMERA_VI_CONFIG_S *pstViConfig) +{ -+ int32_t trackIndex; -+ struct AudioSubPortOutTrack *hwOutputPortTrack = NULL; -+ struct AudioSubPortOut *hwPortCtx = (struct AudioSubPortOut *)portHandle; -+ CHK_NULL_RETURN(hwPortCtx, MEDIA_HAL_INVALID_PARAM, "input param portHandle null"); -+ CHK_NULL_RETURN(trackHandle, MEDIA_HAL_INVALID_PARAM, "input param trackHandle null"); -+ trackIndex = AudioOutputPortGetFreeTrack(hwPortCtx); -+ if (trackIndex == -1) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "can not found free Output Port track"); -+ return MEDIA_HAL_INVALID_PARAM; ++ for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { ++ ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; ++ if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { ++ ot_vi_chn viChn = pstViConfig->stChnInfo.ViChn; ++ td_bool bNeedChn = TD_FALSE; ++ if (pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { ++ bNeedChn = TD_TRUE; ++ } else { ++ bNeedChn = (i > 0) ? TD_FALSE : TD_TRUE; ++ } ++ int32_t ret = ViDisableChn(pstViConfig, viPipe, viChn, bNeedChn); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_vi_disable_chn failed with %#x!\n", ret); ++ return ret; ++ } ++ } + } ++ return TD_SUCCESS; ++} + -+ if (!hwPortCtx->aoEnabled && (ConfigAndEnableAO(portHandle, portAttr, audioPortPin) != MEDIA_HAL_OK)) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "config and anable AO failed"); -+ return MEDIA_HAL_INIT_FAIL; ++static int32_t ViDestroySingleVi(const CAMERA_VI_CONFIG_S *pstViConfig) ++{ ++ (void)ViStopViChn(pstViConfig); ++ (void)ViStopViPipe(pstViConfig); ++ (void)ViStopDev(pstViConfig); ++ return TD_SUCCESS; ++} ++static int32_t CameraCreateVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ int32_t ret = ViCreateSingleVi(&(pstViConfig[i])); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_CreateSingleVi failed !\n"); ++ (void)ViDestroySingleVi(&pstViConfig[0]); ++ } + } ++ return TD_SUCCESS; ++} + -+ hwOutputPortTrack = (struct AudioSubPortOutTrack *)malloc(sizeof(struct AudioSubPortOutTrack)); -+ if (hwOutputPortTrack == NULL) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "malloc AudioSubPortOutTrack failed"); -+ return MEDIA_HAL_NO_MEM; ++static td_bool IsValidPath(const char *path, int size) ++{ ++ if ((path == NULL) || (size == 0) || (size > SENSOR_DESC_MAX_LEN)) { ++ return TD_FALSE; + } -+ if (memset_s(hwOutputPortTrack, sizeof(struct AudioSubPortOutTrack), 0, -+ sizeof(struct AudioSubPortOutTrack)) != EOK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "memset_s AudioSubPortOutTrack failed"); ++ if (strpbrk(path, "\"*+,:;<=>\?[]|\x7F")) { ++ return TD_FALSE; + } -+ hwOutputPortTrack->aoSourceAttr = hwPortCtx->aoSourceAttr; -+ // todo zhp -+ SubPortTrackOutLoadImpl(hwOutputPortTrack, portAttr, audioPortPin); -+ hwOutputPortTrack->aoDeviceId = hwPortCtx->aoDeviceId; -+ hwOutputPortTrack->ao_pcm_handle = hwPortCtx->ao_pcm_handle; -+ hwOutputPortTrack->ao_mixer_handle = hwPortCtx->ao_mixer_handle; -+ hwOutputPortTrack->ao_elem_vol = hwPortCtx->ao_elem_vol; -+ hwOutputPortTrack->ao_min_vol = hwPortCtx->ao_min_vol; -+ hwOutputPortTrack->ao_max_vol = hwPortCtx->ao_max_vol; -+ hwOutputPortTrack->aoChn = trackIndex; -+ hwOutputPortTrack->vqeScene = VQE_SCENE_NONE; -+ hwOutputPortTrack->inited = true; -+ hwPortCtx->hwOutputPortTrack[trackIndex] = hwOutputPortTrack; -+ *trackHandle = &hwOutputPortTrack->common; -+ return MEDIA_HAL_OK; ++ return TD_TRUE; +} + -+ -+#ifdef __cplusplus -+#if __cplusplus ++static void ViGetSnsObj(char *sensorLib, char *sensorObj, uint16_t cameraCnt, uint32_t snsId) ++{ ++ char *pcdlsymError = NULL; ++ if (!IsValidPath(sensorLib, cameraCnt)) { ++ HI_PRINTF("sensor lib Path is valid Path:%s\n!", sensorLib); ++ return; ++ } ++ if (snsId >= MAX_SENSOR_NUM) { ++ HI_PRINTF("sns id error\n"); ++ return; ++ } ++ g_snsLibHandle[snsId] = dlopen(sensorLib, RTLD_NOW); ++ if (g_snsLibHandle[snsId] == NULL) { ++ pcdlsymError = dlerror(); ++ HI_PRINTF("dlopen sns lib error! %s\n", pcdlsymError); ++ return; ++ } ++ (void)dlerror(); ++ g_snsObj[snsId] = (ot_isp_sns_obj *)dlsym(g_snsLibHandle[snsId], sensorObj); ++ if (g_snsObj[snsId] == NULL) { ++ (void)dlclose(g_snsLibHandle[snsId]); ++ g_snsLibHandle[snsId] = NULL; ++ return; ++ } ++ pcdlsymError = dlerror(); ++ if (pcdlsymError != NULL) { ++ (void)dlclose(g_snsLibHandle[snsId]); ++ g_snsLibHandle[snsId] = NULL; ++ return; ++ } +} -+#endif -+#endif /* __cplusplus */ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.h ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.h ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.h 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/audio_usb_sub_port_out/audio_usb_sub_port_out.h 2025-11-07 14:44:54.877657238 +0800 -@@ -0,0 +1,37 @@ -+ /* -+ * Copyright (c) 2024 RKH Corp. -+ * 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. -+ */ -+ -+#ifndef AUDIO_PRIMARY_SUB_PORT_OUT_H -+#define AUDIO_PRIMARY_SUB_PORT_OUT_H + -+#include "audio_port_plugin.h" -+ -+#ifdef __cplusplus -+extern "C" { -+#endif -+ -+/* sub port out api */ -+int32_t AudioUsbSubPortOutOpen(AudioHandle *portHandle, int card_usb); -+int32_t AudioUsbSubPortOutClose(AudioHandle portHandle); -+int32_t AudioUsbSubPortOutGetCapability(const struct AudioPort *port, struct AudioPortCapability *capability); -+int32_t AudioUsbSubPortOutCreateTrack(AudioHandle portHandle, AudioHandle *trackHandle, -+ struct PortPluginAttr *portAttr, enum AudioPortPin audioPortPin); -+int32_t AudioUsbSubPortOutDestroyTrack(AudioHandle portHandle, AudioHandle trackHandle); -+ -+#ifdef __cplusplus ++static const ot_isp_sns_obj *GetSnsObjById(uint32_t snsId) ++{ ++ if (snsId >= MAX_SENSOR_NUM) { ++ HI_PRINTF("invalid sensor id: %u\n", snsId); ++ return NULL; ++ } ++ const ot_isp_sns_obj *snsObj = g_snsObj[snsId]; ++ return snsObj; +} -+#endif -+ -+#endif -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/Makefile ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/Makefile ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/Makefile 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/plugins/ss928_usb/Makefile 2025-11-03 15:43:47.971951415 +0800 -@@ -0,0 +1,106 @@ -+LOCAL_DIR := $(shell pwd) -+MEDIA_BASE_DIR := $(LOCAL_DIR)/../../../.. -+include $(MEDIA_BASE_DIR)/build/base.mak + ++static int32_t ViSensorRegiterCallback(ot_isp_dev IspDev, uint32_t u32SnsId, const CAMERA_VI_CONFIG_S *pstViConfig) ++{ ++ if (IspDev >= ISP_MAX_DEV_NUM) { ++ return TD_FAILURE; ++ } ++ const ot_isp_sns_obj *snsObj = GetSnsObjById(u32SnsId); ++ if (snsObj == NULL) { ++ HI_PRINTF("sensor %u not exist!\n", u32SnsId); ++ return TD_FAILURE; ++ } ++ ot_isp_3a_alg_lib stAeLib; ++ ot_isp_3a_alg_lib stAwbLib; ++ stAeLib.id = IspDev; ++ stAwbLib.id = IspDev; ++ if (strncpy_s(stAeLib.lib_name, sizeof(stAeLib.lib_name), OT_AE_LIB_NAME, sizeof(OT_AE_LIB_NAME)) != EOK) { ++ HI_PRINTF("strncpy_s stAeLib.lib_name failed"); ++ return TD_FAILURE; ++ } ++ if (strncpy_s(stAwbLib.lib_name, sizeof(stAwbLib.lib_name), OT_AWB_LIB_NAME, sizeof(OT_AWB_LIB_NAME)) != EOK) { ++ HI_PRINTF("strncpy_s stAwbLib.lib_name failed"); ++ return TD_FAILURE; ++ } ++ if (snsObj->pfn_register_callback != NULL) { ++ int32_t ret = snsObj->pfn_register_callback(IspDev, &stAeLib, &stAwbLib); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("sensor_register_callback failed with %#x!\n", ret); ++ return ret; ++ } ++ } else { ++ HI_PRINTF("sensor_register_callback failed with TD_NULL!\n"); ++ } ++ g_au32IspSnsId[IspDev] = u32SnsId; ++ return TD_SUCCESS; ++} + -+#=============================================================================== -+# self deps -+#=============================================================================== -+AUDIO_PLUGIN_INC_PATH := $(LOCAL_DIR)/../plugin_include -+AUDIO_PORT_PLUGIN_COM_INC_PATH := $(LOCAL_DIR)/audio_usb_port_plugin_common/include -+AUDIO_SUB_PORT_IN_INC_PATH := $(LOCAL_DIR)/audio_usb_sub_port_in -+AUDIO_SUB_PORT_OUT_INC_PATH := $(LOCAL_DIR)/audio_usb_sub_port_out -+AUDIO_INTERFACE_PATH := $(MEDIA_BASE_DIR)/../../../../../../drivers/peripheral/audio/interfaces/include -+ -+OTCONFACCESS_INC_PATH := $(MEDIA_BASE_DIR)/../middleware/source/component/otconfaccess/include/ -+MW_COMMON_INC_PATH := $(MEDIA_BASE_DIR)/../middleware/source/common/include/ ++static int32_t ViIspBindSns(ot_isp_dev IspDev, uint32_t u32SnsId, td_s8 s8SnsDev) ++{ ++ const ot_isp_sns_obj *snsObj = GetSnsObjById(u32SnsId); ++ if (snsObj == NULL) { ++ HI_PRINTF("sensor %u not exist!\n", u32SnsId); ++ return TD_FAILURE; ++ } ++ ot_isp_sns_commbus uSnsBusInfo = { 0 }; ++ uSnsBusInfo.i2c_dev = s8SnsDev; ++ if (snsObj->pfn_set_bus_info != NULL) { ++ int32_t ret = snsObj->pfn_set_bus_info(IspDev, uSnsBusInfo); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("set sensor bus info failed with %#x!\n", ret); ++ return ret; ++ } ++ } else { ++ HI_PRINTF("not support set sensor bus info!\n"); ++ return TD_FAILURE; ++ } ++ return TD_SUCCESS; ++} + -+SRC_DEPS_INC_PATH := -I$(AUDIO_HAL_INC_PATH) -+SRC_DEPS_INC_PATH += -I$(AUDIO_DRIVERS_INC_PATH)\ -+ -I$(MPP_INC_PATH)\ -+ -I$(AUDIO_PORT_PLUGIN_COM_INC_PATH)\ -+ -I$(MEDIA_HAL_COMMN_INC_PATH) \ -+ -I$(AUDIO_INTERFACE_PATH) \ -+ -I$(AUDIO_PLUGIN_INC_PATH) \ -+ -I$(AUDIO_SUB_PORT_IN_INC_PATH) \ -+ -I$(AUDIO_SUB_PORT_OUT_INC_PATH) \ -+ -I$(OTCONFACCESS_INC_PATH) \ -+ -I$(MW_COMMON_INC_PATH) \ -+ -I$(SECUREC_INC_PATH) ++static int32_t ViIspAwblibUnCallback(ot_isp_dev IspDev) ++{ ++ ot_isp_3a_alg_lib stAwbLib; ++ stAwbLib.id = IspDev; ++ HAL_LOG_DOFUNC(strncpy_s(stAwbLib.lib_name, sizeof(stAwbLib.lib_name), OT_AWB_LIB_NAME, sizeof(OT_AWB_LIB_NAME))); ++ CHECK_RET(ss_mpi_awb_unregister(IspDev, &stAwbLib), "awblib unregister call back"); ++ return TD_SUCCESS; ++} ++static int32_t ViIspAelibUnCallback(ot_isp_dev IspDev) ++{ ++ ot_isp_3a_alg_lib stAeLib; ++ stAeLib.id = IspDev; ++ HAL_LOG_DOFUNC(strncpy_s(stAeLib.lib_name, sizeof(stAeLib.lib_name), OT_AE_LIB_NAME, sizeof(OT_AE_LIB_NAME))); ++ CHECK_RET(ss_mpi_ae_unregister(IspDev, &stAeLib), "aelib unregister call back"); ++ return TD_SUCCESS; ++} + -+ALSA_INC_PATH := \ -+ -I$(MEDIA_BASE_DIR)/../../../../../../third_party/alsa-lib/include ++static int32_t ViIspSensorUnRegiterCallback(ot_isp_dev IspDev) ++{ ++ ot_isp_3a_alg_lib stAeLib; ++ ot_isp_3a_alg_lib stAwbLib; ++ uint32_t snsId = g_au32IspSnsId[IspDev]; ++ if (snsId >= MAX_SENSOR_NUM) { ++ HI_PRINTF("%s: invalid sensor id: %u\n", __FUNCTION__, snsId); ++ return TD_FAILURE; ++ } ++ const ot_isp_sns_obj *snsObj = g_snsObj[snsId]; ++ if (snsObj == NULL) { ++ return TD_FAILURE; ++ } ++ stAeLib.id = IspDev; ++ stAwbLib.id = IspDev; ++ HAL_LOG_DOFUNC(strncpy_s(stAeLib.lib_name, sizeof(stAeLib.lib_name), OT_AE_LIB_NAME, sizeof(OT_AE_LIB_NAME))); ++ HAL_LOG_DOFUNC(strncpy_s(stAwbLib.lib_name, sizeof(stAwbLib.lib_name), OT_AWB_LIB_NAME, sizeof(OT_AWB_LIB_NAME))); ++ if (snsObj->pfn_un_register_callback != NULL) { ++ int32_t ret = snsObj->pfn_un_register_callback(IspDev, &stAeLib, &stAwbLib); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("sensor_unregister_callback failed with %#x!\n", ret); ++ return ret; ++ } ++ } else { ++ HI_PRINTF("sensor_unregister_callback failed with TD_NULL!\n"); ++ } ++ return TD_SUCCESS; ++} + -+SRC_DEPS_INC_PATH += $(ALSA_INC_PATH) -+#mod dir -+MOD_ROOT := $(LOCAL_DIR)/../.. -+SRC_ROOT := $(LOCAL_DIR) -+OBJ_ROOT := $(SRC_ROOT)/obj -+TRAGET_ROOT := $(MOD_ROOT)/$(TARGET_DIR) -+$(shell if [ ! -e $(TRAGET_ROOT) ]; then mkdir -p $(TRAGET_ROOT); fi) -+SRCS := $(LOCAL_DIR)/audio_usb_port_plugin/audio_usb_port_plugin.c -+SRCS += $(LOCAL_DIR)/audio_usb_sub_port_in/audio_usb_sub_port_in.c -+SRCS += $(LOCAL_DIR)/audio_usb_sub_port_out/audio_usb_sub_port_out.c -+SRCS += $(LOCAL_DIR)/audio_usb_port_plugin_common/src/audio_port_plugin_common.c -+SRCS := $(sort $(SRCS)) ++static void ViIspStop(ot_isp_dev IspDev) ++{ ++ if (IspDev >= ISP_MAX_DEV_NUM) { ++ return; ++ } ++ if (g_ispPid[IspDev] != 0) { ++ ss_mpi_isp_exit(IspDev); ++ pthread_join(g_ispPid[IspDev], NULL); ++ ViIspAwblibUnCallback(IspDev); ++ ViIspAelibUnCallback(IspDev); ++ ViIspSensorUnRegiterCallback(IspDev); ++ g_ispPid[IspDev] = 0; ++ } ++ return; ++} + ++static int32_t ViIspAelibCallback(ot_isp_dev IspDev) ++{ ++ ot_isp_3a_alg_lib stAeLib; ++ stAeLib.id = IspDev; ++ HAL_LOG_DOFUNC(strncpy_s(stAeLib.lib_name, sizeof(stAeLib.lib_name), OT_AE_LIB_NAME, sizeof(OT_AE_LIB_NAME))); ++ CHECK_RET(ss_mpi_ae_register(IspDev, &stAeLib), "aelib register call back"); ++ return TD_SUCCESS; ++} + -+OBJS := $(SRCS:%.c=%.o) -+OBJS := $(sort $(OBJS)) -+SRC_DEPS := $(OBJS:%.o=%.d) ++static int32_t ViIspAwblibCallback(ot_isp_dev IspDev) ++{ ++ ot_isp_3a_alg_lib stAwbLib; ++ stAwbLib.id = IspDev; ++ HAL_LOG_DOFUNC(strncpy_s(stAwbLib.lib_name, sizeof(stAwbLib.lib_name), OT_AWB_LIB_NAME, sizeof(OT_AWB_LIB_NAME))); ++ CHECK_RET(ss_mpi_awb_register(IspDev, &stAwbLib), "awblib register call back"); ++ return TD_SUCCESS; ++} + -+CFLAGS_CUR := $(CFLAGS) -fdata-sections -fno-omit-frame-pointer ++static void *ViIspThread(void *param) ++{ ++ char szThreadName[THREAD_NAME_SIZE]; ++ ot_isp_dev IspDev = (ot_isp_dev)param; ++ if (snprintf_s(szThreadName, THREAD_NAME_SIZE, THREAD_NAME_SIZE - 1, "ISP%d_RUN", IspDev) >= 0) { ++ prctl(PR_SET_NAME, szThreadName, 0, 0, 0); ++ } + -+LDFLAGS_SO := $(LDFLAGS) ++ HI_PRINTF("ISP Dev %d running !\n", IspDev); ++ int32_t ret = ss_mpi_isp_run(IspDev); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ss_mpi_isp_run failed with %#x!\n", ret); ++ } ++ return NULL; ++} + -+ifeq ($(filter $(CFG_CHIP_TYPE),hispark_ss927v100 hispark_ss928v100),$(CFG_CHIP_TYPE)) -+CFLAGS_CUR += -D__SS626V100__ -D__LINUX__ -+SRC_DEPS_LIB += -lmedia_hal_common -lss_mpi -lsecurec -lpthread -ldl -lm -lmwlog -lotconfaccess -laac_sbr_enc -laac_sbr_dec -lvqe_record -lvqe_res -lss_otp -+else -+SRC_DEPS_LIB += -lmedia_hal_common -lss_mpi_audio -lsecurec -lpthread -ldl -lm -lmwlog -lotconfaccess -lss_mpi_audio_adp -lopus -laac_sbr_enc -laac_sbr_dec -lmp3_dec -lmp3_enc -lvqe_record -lvqe_res -lss_otp -+endif -+USB_ALSA_LIB_PATH := $(MEDIA_BASE_DIR)/../../../../../../third_party/alsa-lib/lib -+SRC_DEPS_LIB += -lasound -+SRC_DEPS_LIB_PATH += -L$(MPP_LIB_PATH)\ -+ -L$(SECUREC_LIB_PATH) \ -+ -L$(MEDIA_HAL_COMMN_LIB_PATH) \ -+ -L$(USB_ALSA_LIB_PATH) ++/* ***************************************************************************** ++ * funciton : ISP Run ++ * **************************************************************************** */ ++static int32_t ViIspRun(ot_isp_dev IspDev) ++{ ++ pthread_attr_t *pstAttr = NULL; ++ int32_t ret = pthread_create(&g_ispPid[IspDev], pstAttr, ViIspThread, (void *)IspDev); ++ if (ret != 0) { ++ HI_PRINTF("create isp running thread failed!, error: %d\n", ret); ++ goto out; ++ } ++out: ++ if (pstAttr != NULL) { ++ pthread_attr_destroy(pstAttr); ++ } ++ return ret; ++} + -+ifeq ($(filter $(CFG_CHIP_TYPE),hispark_ss927v100 hispark_ss928v100),$(CFG_CHIP_TYPE)) -+SRC_DEPS_LIB_PATH += -L$(MEDIA_BASE_DIR)/../middleware/source/component/otconfaccess/lib/ss928v100/clang_musl \ -+ -L$(MEDIA_BASE_DIR)/../middleware/source/common/log/lib/ss928v100/clang_musl -+else -+SRC_DEPS_LIB_PATH += -L$(MEDIA_BASE_DIR)/../middleware/source/component/otconfaccess/lib/hi3516dv500/gcc_musl \ -+ -L$(MEDIA_BASE_DIR)/../middleware/source/common/log/lib/hi3516dv500/gcc_musl -+endif ++static int32_t ViIspPrepare(const CAMERA_VI_CONFIG_S *pstViConfig, ot_vi_pipe ViPipe, uint32_t u32SnsId, int32_t index) ++{ ++ int32_t ret = ViSensorRegiterCallback(ViPipe, u32SnsId, pstViConfig); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("register sensor %u to ISP %d failed\n", u32SnsId, ViPipe); ++ ViIspStop(ViPipe); ++ return TD_FAILURE; ++ } ++ if (((pstViConfig->stSnapInfo.bDoublePipe) && (pstViConfig->stSnapInfo.SnapPipe == ViPipe)) || ++ (pstViConfig->stPipeInfo.bMultiPipe && index > 0)) { ++ ret = ViIspBindSns(ViPipe, u32SnsId, -1); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("register sensor %u bus id %d failed\n", u32SnsId, pstViConfig->stSnsInfo.s32BusId); ++ ViIspStop(ViPipe); ++ return TD_FAILURE; ++ } ++ } else { ++ ret = ViIspBindSns(ViPipe, u32SnsId, pstViConfig->stSnsInfo.s32BusId); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("register sensor %u bus id %d failed\n", u32SnsId, pstViConfig->stSnsInfo.s32BusId); ++ ViIspStop(ViPipe); ++ return TD_FAILURE; ++ } ++ } ++ return TD_SUCCESS; ++} + -+ifeq ($(CFG_OS_TYPE),OHOS) -+SRC_DEPS_LIB_PATH += -L$(OUT_DIR)/$(CFG_CHIP_TYPE)/ipcamera_$(CFG_CHIP_TYPE)_liteos \ -+ -L$(OUT_DIR)/$(CFG_CHIP_TYPE)/ipcamera_$(CFG_CHIP_TYPE)_liteos/usr/lib -+else -+SRC_DEPS_LIB_PATH += -L$(OUT_DIR)/$(CFG_CHIP_TYPE)/ipcamera_$(CFG_CHIP_TYPE)_linux \ -+ -L$(OUT_DIR)/$(CFG_CHIP_TYPE)/ipcamera_$(CFG_CHIP_TYPE)_linux/usr/lib -+endif ++static int32_t ViRunIsp(ot_vi_pipe ViPipe, ot_isp_pub_attr stPubAttr) ++{ ++ int32_t ret = ViIspAelibCallback(ViPipe); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_ISP_Aelib_Callback failed\n"); ++ ViIspStop(ViPipe); ++ return TD_FAILURE; ++ } + -+LIB_SO := $(TRAGET_ROOT)/libaudio_usb_port.so -+LIB_A := $(TRAGET_ROOT)/libaudio_usb_port.a ++ ret = ViIspAwblibCallback(ViPipe); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_ISP_Awblib_Callback failed\n"); ++ ViIspStop(ViPipe); ++ return TD_FAILURE; ++ } + -+.PHONY : clean all ++ ret = ss_mpi_isp_mem_init(ViPipe); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("Init Ext memory failed with %#x!\n", ret); ++ ViIspStop(ViPipe); ++ return TD_FAILURE; ++ } + -+all: $(LIB_SO) $(LIB_A) -+ @-rm -f $(OBJS) ++ ret = ss_mpi_isp_set_pub_attr(ViPipe, &stPubAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("SetPubAttr failed with %#x!\n", ret); ++ ViIspStop(ViPipe); ++ return TD_FAILURE; ++ } + -+$(LIB_A): $(OBJS) -+ $(AR) -rcv $@ $^ ++ ret = ss_mpi_isp_init(ViPipe); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ISP Init failed with %#x!\n", ret); ++ ViIspStop(ViPipe); ++ return TD_FAILURE; ++ } + ++ ret = ViIspRun(ViPipe); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ISP Run failed with %#x!\n", ret); ++ ViIspStop(ViPipe); ++ return TD_FAILURE; ++ } ++ return TD_SUCCESS; ++} + -+$(LIB_SO): $(OBJS) -+ $(CC) $(LDFLAGS_SO) $(CFLAGS_CUR) $(LFLAGS) -fPIC -shared -o $@ $^ $(SRC_DEPS_LIB_PATH) $(SRC_DEPS_LIB) -+ $(STRIP) $(LIB_SO) ++static int32_t ViStartIsp(const CAMERA_VI_CONFIG_S *pstViConfig) ++{ ++ if (pstViConfig->pipeAttr->pipe_bypass_mode == OT_VI_PIPE_BYPASS_BE) { ++ return TD_SUCCESS; ++ } ++ for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { ++ ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; ++ if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { ++ uint32_t u32SnsId = pstViConfig->stSnsInfo.s32SnsId; ++ ot_isp_pub_attr stPubAttr; ++ HAL_LOG_DOFUNC(memcpy_s(&stPubAttr, sizeof(ot_isp_pub_attr), ++ pstViConfig->ispPubAttr, sizeof(ot_isp_pub_attr))); ++ td_bool bNeedPipe = TD_FALSE; ++ if (pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { ++ bNeedPipe = TD_TRUE; ++ } else { ++ bNeedPipe = (i > 0) ? TD_FALSE : TD_TRUE; ++ } ++ if (bNeedPipe != TD_TRUE) { ++ continue; ++ } ++ int32_t ret = ViIspPrepare(pstViConfig, viPipe, u32SnsId, i); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ViIspPrepare failed with %#x!\n", ret); ++ ViIspStop(viPipe); ++ return TD_FAILURE; ++ } ++ ret = ViRunIsp(viPipe, stPubAttr); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("ISP Run failed with %#x!\n", ret); ++ ViIspStop(viPipe); ++ return TD_FAILURE; ++ } ++ } ++ } + ++ return TD_SUCCESS; ++} + -+$(OBJS): %.o : %.c -+ $(CC) $(CFLAGS_CUR) $(LFLAGS) $(SRC_DEPS_INC_PATH) -c $< -o $@ ++static int32_t CameraCreateIsp(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ int32_t ret = TD_SUCCESS; ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ ret = ViStartIsp(&pstViConfig[i]); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_StartIsp failed !\n"); ++ break; ++ } ++ } ++ return ret; ++} + -+clean: -+ @-rm -f $(OBJS) $(LIB_SO) $(LIB_A) -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_manager.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_manager.c ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_manager.c 2025-11-07 16:00:38.077503351 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_manager.c 2025-11-03 15:43:47.975951343 +0800 -@@ -40,12 +40,22 @@ static struct AudioPort g_audioPrimaryPo - { PORT_OUT, 1, "PrimaryPortOut" } - }; - -+static struct AudioPort g_audioUsbPort[] = { -+ { PORT_IN, 0, "UsbPortIn"}, -+ { PORT_OUT, 1, "UsbPortOut" } -+}; ++static int32_t CameraDestroyVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ (void)ViDestroySingleVi(&pstViConfig[i]); ++ } ++ return TD_SUCCESS; ++} + - static struct AudioAdapterDescriptor g_audioAdapterDescs[] = { - { - .adapterName = NULL, - .portNum = 0, - .ports = NULL, - }, -+ { -+ .adapterName = NULL, -+ .portNum = 0, -+ .ports = NULL, -+ }, - }; - - static struct AudioHwAdapterInternal g_audioAdapters[] = { -@@ -55,6 +65,12 @@ static struct AudioHwAdapterInternal g_a - .hwAdapter = {}, - .adapterLock = PTHREAD_MUTEX_INITIALIZER, - }, -+ { -+ .count = 0, -+ .loaded = false, -+ .hwAdapter = {}, -+ .adapterLock = PTHREAD_MUTEX_INITIALIZER, -+ }, - }; - - static bool g_allAdapterLoaded = false; -@@ -118,6 +134,21 @@ static int32_t AudioManagerGetAllAdapter - MEDIA_HAL_LOGE(MODULE_NAME, "AudioPluginManagerGetPlugin(Primary) failed"); - } - -+ const AudioPortPlugin *usbPlugin = AudioPluginManagerGetPlugin(AUDIO_PLUGIN_USB); -+ if (usbPlugin != NULL) { -+ g_audioAdapters[adapterIndex].hwAdapter.portPlugin = usbPlugin; -+ g_audioAdapters[adapterIndex].hwAdapter.portDirection = usbPlugin->audioPortDir; -+ g_audioAdapterDescs[adapterIndex].adapterName = "USB"; -+ MEDIA_HAL_LOGE(MODULE_NAME, "AudioPluginManagerGetPlugin(USB) success, adapterIndex = %d, adapterName = %s", -+ adapterIndex, g_audioAdapterDescs[adapterIndex].adapterName); -+ g_audioAdapterDescs[adapterIndex].portNum = (size_t)ARRAY_SIZE(g_audioUsbPort); -+ g_audioAdapterDescs[adapterIndex].ports = g_audioUsbPort; ++int32_t CameraStartVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ if (pstViConfig == NULL) { ++ HI_PRINTF("%s: null ptr\n", __FUNCTION__); ++ return TD_FAILURE; ++ } ++ if (cameraCnt > MAX_SENSOR_NUM) { ++ HI_PRINTF("ptr cameraCnt %u error\n", cameraCnt); ++ return TD_FAILURE; ++ } ++ HI_PRINTF("lib:%s, obj:%s, len:%u\n", pstViConfig[0].sensorLib, pstViConfig[0].sensorObj, pstViConfig[0].len); ++ uint32_t snsId = pstViConfig[0].stSnsInfo.s32SnsId; ++ if (snsId >= MAX_SENSOR_NUM) { ++ HI_PRINTF("sns id error\n"); ++ return TD_FAILURE; ++ } ++ ViGetSnsObj(pstViConfig[0].sensorLib, pstViConfig[0].sensorObj, pstViConfig[0].len, snsId); ++ if (cameraCnt == MAX_SENSOR_NUM) { ++ uint32_t snsId1 = pstViConfig[1].stSnsInfo.s32SnsId; ++ ViGetSnsObj(pstViConfig[1].sensorLib, pstViConfig[1].sensorObj, pstViConfig[1].len, snsId1); ++ } ++ int32_t ret = CameraStartMIPI(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("CameraStartMIPI failed!\n"); ++ return TD_FAILURE; ++ } ++ ret = CameraSetParam(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("CameraSetParam failed!\n"); ++ return TD_FAILURE; ++ } + -+ adapterIndex++; -+ } else { -+ MEDIA_HAL_LOGE(MODULE_NAME, "AudioPluginManagerGetPlugin(USB) failed"); ++ ret = CameraCreateVi(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("CameraCreateVi failed!\n"); ++ return TD_FAILURE; + } + - if (adapterIndex == 0) { - MEDIA_HAL_UNLOCK(g_adapterMutex); - return MEDIA_HAL_ERR; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_plugins_manager/src/audio_plugins_manager.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_plugins_manager/src/audio_plugins_manager.c ---- ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_plugins_manager/src/audio_plugins_manager.c 2025-11-07 16:00:38.077503351 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/audio/source/src/audio_plugins_manager/src/audio_plugins_manager.c 2025-11-03 15:43:47.975951343 +0800 -@@ -39,6 +39,12 @@ extern "C" { - #define PRIMARY_PORT_PLUGIN_LIB_PATH "/lib/libaudio_primary_port.so" - #define PRIMARY_PORT_PLUGIN_USR_LIB_PATH "/usr/lib/libaudio_primary_port.so" - -+#define HDMI_PORT_PLUGIN_LIB_PATH "/lib/libaudio_hdmi_port.so" -+#define HDMI_PORT_PLUGIN_USR_LIB_PATH "/usr/lib/libaudio_hdmi_port.so" ++ ret = CameraCreateIsp(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ CameraDestroyVi(pstViConfig, cameraCnt); ++ HI_PRINTF("CameraCreateIsp failed!\n"); ++ return TD_FAILURE; ++ } + -+#define USB_PORT_PLUGIN_LIB_PATH "/lib/libaudio_usb_port.so" -+#define USB_PORT_PLUGIN_USR_LIB_PATH "/usr/lib/libaudio_usb_port.so" ++ return ret; ++} + - #define BLUETOOTH_PORT_PLUGIN_LIB_PATH "/lib/libaudio_bluetooth_port.so" - #define BLUETOOTH_PORT_PLUGIN_USR_LIB_PATH "/usr/lib/libaudio_bluetooth_port.so" - #endif -@@ -119,6 +125,53 @@ static int32_t ScanAndLoadPrimaryPortPlu - return MEDIA_HAL_OK; - } - ++static int32_t ViStopIsp(const CAMERA_VI_CONFIG_S *pstViConfig) ++{ ++ for (int32_t i = 0; i < OT_VI_MAX_PIPE_NUM; i++) { ++ ot_vi_pipe viPipe = pstViConfig->stPipeInfo.aPipe[i]; ++ if (viPipe >= 0 && viPipe < OT_VI_MAX_PIPE_NUM) { ++ td_bool bNeedPipe = TD_FALSE; ++ if (pstViConfig->stDevInfo.wdrMode == OT_WDR_MODE_NONE) { ++ bNeedPipe = TD_TRUE; ++ } else { ++ bNeedPipe = (i > 0) ? TD_FALSE : TD_TRUE; ++ } ++ if (bNeedPipe != TD_TRUE) { ++ continue; ++ } ++ ViIspStop(viPipe); ++ } ++ } ++ return TD_SUCCESS; ++} + -+static int32_t ScanAndLoadUSBPortPlugin(AudioPluginsManager *manager) ++static int32_t CameraDestroyIsp(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) +{ -+ AudioPlugin usbPlugin = {}; -+ usbPlugin.audioPluginType = AUDIO_PLUGIN_USB; -+ const AudioPortPlugin *usbPluginImpl = NULL; -+#ifdef ENABLE_DL_AUDIO_PLUGIN -+ usbPlugin.pluginDlHandle = MediaHalDLOpen(USB_PORT_PLUGIN_USR_LIB_PATH); -+ if (usbPlugin.pluginDlHandle == NULL) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "not found usb port plugin in path: %s", USB_PORT_PLUGIN_USR_LIB_PATH); -+ usbPlugin.pluginDlHandle = MediaHalDLOpen(USB_PORT_PLUGIN_LIB_PATH); -+ if (usbPlugin.pluginDlHandle == NULL) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "not found usb port plugin in path: %s", USB_PORT_PLUGIN_LIB_PATH); -+ return MEDIA_HAL_ERR; ++ int32_t ret = TD_SUCCESS; ++ for (uint32_t i = 0; i < cameraCnt; i++) { ++ ret = ViStopIsp(&pstViConfig[i]); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("HISI_VI_StopIsp failed !\n"); + } + } -+ GetPortPlugin getPluginFuns = (GetPortPlugin)MediaHalDLSym(usbPlugin.pluginDlHandle, AUDIO_PORT_PLUGIN_FUNCS); -+ if (getPluginFuns == NULL) { -+ MediaHalDLClose(usbPlugin.pluginDlHandle); -+ MEDIA_HAL_LOGE(MODULE_NAME, "not found symbol: %s", AUDIO_PORT_PLUGIN_FUNCS); -+ return MEDIA_HAL_ERR; ++ return ret; ++} ++ ++int32_t CameraStopVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt) ++{ ++ if (pstViConfig == NULL) { ++ HI_PRINTF("%s: null ptr\n", __FUNCTION__); ++ return TD_FAILURE; + } -+ usbPluginImpl = getPluginFuns(AUDIO_PLUGIN_NONE); -+ if (usbPluginImpl == NULL || -+ CheckPortPlugin(usbPluginImpl) != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "not found valid hdmi port plugin"); -+ MediaHalDLClose(usbPlugin.pluginDlHandle); -+ return MEDIA_HAL_ERR; ++ if (cameraCnt > MAX_SENSOR_NUM) { ++ HI_PRINTF("ptr len %u error\n", cameraCnt); ++ return TD_FAILURE; + } -+#else -+ usbPluginImpl = GetPortPluginFuncs(AUDIO_PLUGIN_USB); -+ if (usbPluginImpl == NULL || -+ CheckPortPlugin(usbPluginImpl) != MEDIA_HAL_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "not found valid hdmi port plugin"); -+ return MEDIA_HAL_ERR; ++ int32_t ret = CameraDestroyIsp(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("CameraDestroyIsp failed !\n"); ++ return TD_FAILURE; + } -+#endif -+ usbPlugin.pluginHandle = (uintptr_t)usbPluginImpl; -+ if (ListPushFront(&manager->plugins, (uintptr_t)&usbPlugin) != LIST_OK) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "hdmi port plugin cannot be pushed into the list"); -+ return MEDIA_HAL_ERR; ++ ret = CameraDestroyVi(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("CameraDestroyVi failed !\n"); ++ return TD_FAILURE; + } + -+ MEDIA_HAL_LOGI(MODULE_NAME, "success"); -+ return MEDIA_HAL_OK; ++ ret = CameraStopMIPI(pstViConfig, cameraCnt); ++ if (ret != TD_SUCCESS) { ++ HI_PRINTF("CameraStopMIPI failed !\n"); ++ return TD_FAILURE; ++ } ++ uint32_t snsId = pstViConfig->stSnsInfo.s32SnsId; ++ if (snsId >= MAX_SENSOR_NUM) { ++ HI_PRINTF("sns id error\n"); ++ return TD_FAILURE; ++ } ++ if (g_snsLibHandle[snsId] != NULL) { ++ (void)dlclose(g_snsLibHandle[snsId]); ++ g_snsLibHandle[snsId] = NULL; ++ g_snsObj[snsId] = NULL; ++ HI_PRINTF("delete sensor lib snsid %u\n", snsId); ++ } ++ return ret; +} + - static uintptr_t DupPlugin(const AudioPlugin *audioPlugin) - { - CHK_NULL_RETURN(audioPlugin, MEDIA_HAL_INVALID_PARAM, "input param audioPlugin null"); -@@ -196,6 +249,9 @@ void AudioPluginManagerInit(void) - if (ScanAndLoadPrimaryPortPlugin(manager) != MEDIA_HAL_OK) { - goto LOAD_FAILED; - } -+ if (ScanAndLoadUSBPortPlugin(manager) != MEDIA_HAL_OK) { -+ goto LOAD_FAILED; -+ } - - manager->inited = true; - MEDIA_HAL_UNLOCK(manager->mutex); -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/build/build_media_source_L1.sh ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/build/build_media_source_L1.sh ---- ohos/device/soc/hisilicon/common/hal/media/build/build_media_source_L1.sh 2025-11-07 16:00:38.077503351 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/build/build_media_source_L1.sh 2025-11-07 15:44:19.951100763 +0800 -@@ -85,8 +85,9 @@ fi - cp $ROOT_DIR/../middleware/source/common/uproc/lib/$CHIP_TYPE/$COMPILE_TYPE/libuproc.so $OUT_DIR/ - cp $ROOT_DIR/../middleware/source/common/log/lib/$CHIP_TYPE/$COMPILE_TYPE/libmwlog.so $OUT_DIR/ - # cp $ROOT_DIR/../middleware/source/common/securec/lib/$CHIP_TYPE/$COMPILE_TYPE/libsecurec.so $OUT_DIR/ -- + - cp $ROOT_DIR/audio/libs/$BOARD_NAME/$TOOLCHAIN_BUILD_COMPILER/$KERNEL_OS_TYPE/libs/libaudio_hw.so $OUT_DIR/ -+ cp $ROOT_DIR/audio/libs/$BOARD_NAME/$TOOLCHAIN_BUILD_COMPILER/$KERNEL_OS_TYPE/libs/libaudio_usb_port.so $OUT_DIR/ - if [ -f "$ROOT_DIR/audio/libs/$BOARD_NAME/$TOOLCHAIN_BUILD_COMPILER/$KERNEL_OS_TYPE/libs/libaudio_primary_port.so" ]; then - cp $ROOT_DIR/audio/libs/$BOARD_NAME/$TOOLCHAIN_BUILD_COMPILER/$KERNEL_OS_TYPE/libs/libaudio_primary_port.so $OUT_DIR/ - fi -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/build.sh ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/build.sh ---- ohos/device/soc/hisilicon/common/hal/media/build.sh 2025-05-03 17:54:46.000000000 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/build.sh 2025-11-03 15:43:47.975951343 +0800 -@@ -21,6 +21,7 @@ function main(){ - #cp -rf $CUR_DIR/audio/$BOARD_NAME/$OS_TYPE/libs/libaudio_input_port.so $OUT_DIR/ - #cp -rf $CUR_DIR/audio/$BOARD_NAME/$OS_TYPE/libs/libaudio_output_port.so $OUT_DIR/ - cp -rf $CUR_DIR/audio/$BOARD_NAME/$OS_TYPE/libs/libaudio_primary_port.so $OUT_DIR/ -+ cp -rf $CUR_DIR/audio/$BOARD_NAME/$OS_TYPE/libs/libaudio_usb_port.so $OUT_DIR/ - - cp -rf $CUR_DIR/codec/$BOARD_NAME/$OS_TYPE/libs/libcodec.so $OUT_DIR/ - cp -rf $CUR_DIR/codec/$BOARD_NAME/$OS_TYPE/libs/libhiaacdec.so $OUT_DIR/ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/codec/source/plugins/audio_encoder/hi35xx/native_aenc.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/codec/source/plugins/audio_encoder/hi35xx/native_aenc.c ---- ohos/device/soc/hisilicon/common/hal/media/codec/source/plugins/audio_encoder/hi35xx/native_aenc.c 2025-11-07 16:00:38.089503269 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/codec/source/plugins/audio_encoder/hi35xx/native_aenc.c 2025-11-07 14:44:54.881657245 +0800 -@@ -45,13 +45,13 @@ ++#ifdef __cplusplus ++#if __cplusplus ++} ++#endif ++#endif /* End of #ifdef __cplusplus */ ++ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_vi.h ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_vi.h +--- ohos/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_vi.h 2025-12-18 15:14:06.900482931 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/hi_camera_vi.h 2025-12-18 15:44:30.870238524 +0800 +@@ -1,42 +1,42 @@ +-/* +- * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. +- * +- * 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. +- */ +- +-#ifndef OHOS_CAMERA_VI_H +-#define OHOS_CAMERA_VI_H +- +-#include "hi_camera_comm.h" +- +-#ifdef __cplusplus +-#if __cplusplus +-extern "C" { +-#endif +-#endif /* End of #ifdef __cplusplus */ +- +-#define PATH_MAX_LEN 128 +-int32_t HpCameraSetFps(td_float pf32Framerate); +-int32_t CameraStartVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt); +-void HpCameraAllIspStop(void); +-int32_t CameraStopVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt); +-int32_t HpCameraGetFps(void); +-uint8_t GetParamCamera(const char path[PATH_MAX_LEN], InitParam *initParam, uint8_t cameraId); +- +-#ifdef __cplusplus +-#if __cplusplus +-} +-#endif +-#endif /* End of #ifdef __cplusplus */ +- +-#endif /* End of #ifndef OHOS_CAMERA_VI_H */ ++/* ++ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. ++ * ++ * 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. ++ */ ++ ++#ifndef OHOS_CAMERA_VI_H ++#define OHOS_CAMERA_VI_H ++ ++#include "hi_camera_comm.h" ++ ++#ifdef __cplusplus ++#if __cplusplus ++extern "C" { ++#endif ++#endif /* End of #ifdef __cplusplus */ ++ ++#define PATH_MAX_LEN 128 ++int32_t HpCameraSetFps(td_float pf32Framerate); ++int32_t CameraStartVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt); ++void HpCameraAllIspStop(void); ++int32_t CameraStopVi(const CAMERA_VI_CONFIG_S *pstViConfig, uint32_t cameraCnt); ++int32_t HpCameraGetFps(void); ++uint8_t GetParamCamera(const char path[PATH_MAX_LEN], InitParam *initParam, uint8_t cameraId); ++ ++#ifdef __cplusplus ++#if __cplusplus ++} ++#endif ++#endif /* End of #ifdef __cplusplus */ ++ ++#endif /* End of #ifndef OHOS_CAMERA_VI_H */ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/camera/source/src/sample_camera.c ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/sample_camera.c +--- ohos/device/soc/hisilicon/common/hal/media/camera/source/src/sample_camera.c 2025-12-18 15:14:06.900482931 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/camera/source/src/sample_camera.c 2025-12-18 15:44:30.870238524 +0800 +@@ -1,67 +1,67 @@ +-/* +- * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. +- * +- * 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. +- */ +- +-#include +-#include "hal_camera.h" +- +-#define DEFAULT_WIDTH 480 +-#define DEFAULT_HEIGHT 480 +-#define DEFAULT_SET_FPS 60 +-#define DELAY_5S (5000 * 1000) +- +-int main(void) +-{ +- /* init para */ +- HalCameraInit(); +- uint8_t camUse = 0x1; +- uint32_t cameraList[0x2] = { 0 }; +- uint8_t camNum = 0; +- uint32_t streamId = 0; +- HalCameraGetDeviceNum(&camNum); +- printf("num = %d\n", camNum); +- HalCameraGetDeviceList(cameraList, 0x2); +- +- for (uint8_t i = 0; i < camNum; i++) { +- camUse = i; +- StreamAttr streamAttr; +- streamAttr.crop.x = 0; +- streamAttr.crop.y = 0; +- streamAttr.crop.h = 0; +- streamAttr.crop.w = 0; +- streamAttr.fps = DEFAULT_SET_FPS; +- streamAttr.width = DEFAULT_WIDTH; +- streamAttr.height = DEFAULT_HEIGHT; +- streamAttr.type = STREAM_PREVIEW; +- streamAttr.format = FORMAT_YVU420; +- streamAttr.invertMode = 0; +- +- HalCameraDeviceOpen(cameraList[camUse]); +- HalCameraStreamCreate(cameraList[camUse], &streamAttr, &streamId); +- uint32_t deviceId = 0; +- HalCameraGetDeviceId(cameraList[camUse], streamId, &deviceId); +- StreamInfo info; +- info.type = STREAM_INFO_POS; +- info.u.pos.x = 0; +- info.u.pos.y = 0; +- HalCameraStreamSetInfo(cameraList[camUse], streamId, &info); +- printf(" device id = 0x%x\n", deviceId); +- HalCameraStreamOn(cameraList[camUse], streamId); +- HalBuffer buffer = { 0 }; +- usleep(DELAY_5S); +- } +- while (true) { } +- return 0; +-} ++/* ++ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. ++ * ++ * 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. ++ */ ++ ++#include ++#include "hal_camera.h" ++ ++#define DEFAULT_WIDTH 480 ++#define DEFAULT_HEIGHT 480 ++#define DEFAULT_SET_FPS 60 ++#define DELAY_5S (5000 * 1000) ++ ++int main(void) ++{ ++ /* init para */ ++ HalCameraInit(); ++ uint8_t camUse = 0x1; ++ uint32_t cameraList[0x2] = { 0 }; ++ uint8_t camNum = 0; ++ uint32_t streamId = 0; ++ HalCameraGetDeviceNum(&camNum); ++ printf("num = %d\n", camNum); ++ HalCameraGetDeviceList(cameraList, 0x2); ++ ++ for (uint8_t i = 0; i < camNum; i++) { ++ camUse = i; ++ StreamAttr streamAttr; ++ streamAttr.crop.x = 0; ++ streamAttr.crop.y = 0; ++ streamAttr.crop.h = 0; ++ streamAttr.crop.w = 0; ++ streamAttr.fps = DEFAULT_SET_FPS; ++ streamAttr.width = DEFAULT_WIDTH; ++ streamAttr.height = DEFAULT_HEIGHT; ++ streamAttr.type = STREAM_PREVIEW; ++ streamAttr.format = FORMAT_YVU420; ++ streamAttr.invertMode = 0; ++ ++ HalCameraDeviceOpen(cameraList[camUse]); ++ HalCameraStreamCreate(cameraList[camUse], &streamAttr, &streamId); ++ uint32_t deviceId = 0; ++ HalCameraGetDeviceId(cameraList[camUse], streamId, &deviceId); ++ StreamInfo info; ++ info.type = STREAM_INFO_POS; ++ info.u.pos.x = 0; ++ info.u.pos.y = 0; ++ HalCameraStreamSetInfo(cameraList[camUse], streamId, &info); ++ printf(" device id = 0x%x\n", deviceId); ++ HalCameraStreamOn(cameraList[camUse], streamId); ++ HalBuffer buffer = { 0 }; ++ usleep(DELAY_5S); ++ } ++ while (true) { } ++ return 0; ++} +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/codec/source/plugins/audio_encoder/hi35xx/native_aenc.c ohos1/device/soc/hisilicon/common/hal/media/codec/source/plugins/audio_encoder/hi35xx/native_aenc.c +--- ohos/device/soc/hisilicon/common/hal/media/codec/source/plugins/audio_encoder/hi35xx/native_aenc.c 2025-12-18 15:14:06.904482889 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/codec/source/plugins/audio_encoder/hi35xx/native_aenc.c 2025-12-18 15:44:30.870238524 +0800 +@@ -46,13 +46,13 @@ #define AENC_GET_FRAME_BLOCK_TIMEOUT_MS 1000 #define MOD_ID(deviceid) \ @@ -2906,92 +13087,14 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device typedef struct { ot_audio_stream nativeBuf; -@@ -876,42 +876,16 @@ static td_s32 NATIVE_AENC_GetStream(void - NativeAencContext *nativeAencCtx = (NativeAencContext*)aencHdl; - - td_s32 ret; -- fd_set readFds; -- td_s32 aencFd = ss_mpi_aenc_get_fd(nativeAencCtx->aencChn); -- if (aencFd < 0) { -- MEDIA_HAL_LOGE(MODULE_NAME, "ss_mpi_aenc_get_fd failed ret %#x", aencFd); -- return AENC_ERR_AENC_ERR; -- } -- - ot_audio_stream *audioStream = GetFreeAencNativeOutbuffer(nativeAencCtx); - if (audioStream == NULL) { - MEDIA_HAL_LOGE(MODULE_NAME, "no free native out buffer for aenc"); - return OT_ERR_AAC_UNKNOWN; - } -- -- FD_ZERO(&readFds); -- FD_SET(aencFd, &readFds); -- struct timeval timeoutVal; -- timeoutVal.tv_sec = block ? 30 : 1; /* 30: time */ -- timeoutVal.tv_usec = 0; -- ret = select(aencFd + 1, &readFds, NULL, NULL, &timeoutVal); -- if (ret < 0) { -- MEDIA_HAL_LOGE(MODULE_NAME, "select failed!"); -- ReleaseAencNativeOutbuffer(nativeAencCtx, audioStream); -- return OT_ERR_AAC_UNKNOWN; -- } else if (ret == 0) { -- MEDIA_HAL_LOGE(MODULE_NAME, "chn [%d] get aenc stream time out", nativeAencCtx->aencChn); -+ ret = ss_mpi_aenc_get_stream(nativeAencCtx->aencChn, audioStream, TD_FALSE); -+ if (ret != TD_SUCCESS) { -+ MEDIA_HAL_LOGE(MODULE_NAME, "ss_mpi_aenc_get_stream failed with %#x !", ret); - ReleaseAencNativeOutbuffer(nativeAencCtx, audioStream); -- return MEDIA_HAL_TIMEOUT; -- } else { -- if (FD_ISSET(aencFd, &readFds)) { -- ret = ss_mpi_aenc_get_stream(nativeAencCtx->aencChn, audioStream, TD_FALSE); -- if (ret != TD_SUCCESS) { -- MEDIA_HAL_LOGE(MODULE_NAME, "ss_mpi_aenc_get_stream failed with %#x !", ret); -- ReleaseAencNativeOutbuffer(nativeAencCtx, audioStream); -- return ret; -- } -- } -+ return ret; - } - - ret = FillAencOutputInfo(nativeAencCtx->encType, audioStream, outInfo); -@@ -1004,4 +978,3 @@ td_s32 AEncoderImplUnRegister() +@@ -1006,4 +1006,3 @@ td_s32 AEncoderImplUnRegister() AencMngDeinit(); return ret; } - -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/common/source/src/audio_dl_adp.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/common/source/src/audio_dl_adp.c ---- ohos/device/soc/hisilicon/common/hal/media/common/source/src/audio_dl_adp.c 2025-11-07 16:00:38.093503242 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/common/source/src/audio_dl_adp.c 2025-11-07 14:46:29.437127486 +0800 -@@ -44,22 +44,17 @@ td_s32 audio_dlopen(td_void **lib_handle - } - - *lib_handle = TD_NULL; -- char *realLibName = realpath(lib_name, NULL); -- if (realLibName == TD_NULL) { -- printf("Failed to get real path for %s\n", lib_name); -- return TD_FAILURE; -- } - #ifndef __LITEOS__ -- *lib_handle = dlopen(realLibName, RTLD_LAZY | RTLD_LOCAL); -+ *lib_handle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL); - #else -- *lib_handle = LOS_SoLoad(realLibName); -+ *lib_handle = LOS_SoLoad(lib_name); - #endif -+ - if (*lib_handle == TD_NULL) { -- printf("dlopen %s failed!\n", realLibName); -- free(realLibName); -+ printf("dlopen %s failed!\n", lib_name); - return TD_FAILURE; - } -- free(realLibName); -+ - return TD_SUCCESS; - } - -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/common/source/src/media_hal_common.c ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/common/source/src/media_hal_common.c ---- ohos/device/soc/hisilicon/common/hal/media/common/source/src/media_hal_common.c 2025-11-07 16:00:38.093503242 +0800 -+++ ../../../../../3403_project/ohos/device/soc/hisilicon/common/hal/media/common/source/src/media_hal_common.c 2025-11-07 15:44:25.811017209 +0800 +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/device/soc/hisilicon/common/hal/media/common/source/src/media_hal_common.c ohos1/device/soc/hisilicon/common/hal/media/common/source/src/media_hal_common.c +--- ohos/device/soc/hisilicon/common/hal/media/common/source/src/media_hal_common.c 2025-12-18 15:14:06.904482889 +0800 ++++ ohos1/device/soc/hisilicon/common/hal/media/common/source/src/media_hal_common.c 2025-12-18 15:44:30.874238483 +0800 @@ -165,13 +165,8 @@ void *MediaHalDLOpen(const char *file) if (file == NULL) { return NULL; diff --git a/vendor/rkh/rkh_patch/foundation/arkui_ui_lite.patch b/vendor/rkh/rkh_patch/foundation/arkui_ui_lite.patch deleted file mode 100644 index 2e2d1f3d7407c8f304c4898c35faaf125539d76d..0000000000000000000000000000000000000000 --- a/vendor/rkh/rkh_patch/foundation/arkui_ui_lite.patch +++ /dev/null @@ -1,1255 +0,0 @@ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/BUILD.gn ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/BUILD.gn ---- ohos/foundation/arkui/ui_lite/BUILD.gn 2025-05-03 17:56:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/BUILD.gn 2025-09-22 12:34:40.964729466 +0800 -@@ -185,7 +185,6 @@ if (os_level != "standard") { - "frameworks/draw/draw_triangle.cpp", - "frameworks/draw/draw_utils.cpp", - "frameworks/engines/gfx/gfx_engine_manager.cpp", -- "frameworks/engines/gfx/hi3516/hi3516_engine.cpp", - "frameworks/engines/gfx/soft_engine.cpp", - "frameworks/events/event.cpp", - "frameworks/font/base_font.cpp", -@@ -207,6 +206,8 @@ if (os_level != "standard") { - "frameworks/imgdecode/cache_manager.cpp", - "frameworks/imgdecode/file_img_decoder.cpp", - "frameworks/imgdecode/image_load.cpp", -+ "frameworks/imgdecode/png_img_decoder.cpp", -+ "frameworks/imgdecode/jpeg_img_decoder.cpp", - "frameworks/layout/flex_layout.cpp", - "frameworks/layout/grid_layout.cpp", - "frameworks/layout/list_layout.cpp", -@@ -219,6 +220,12 @@ if (os_level != "standard") { - "frameworks/window/window_impl.cpp", - ] - -+ if (board_name == "hispark_ss927v100" || board_name == "hispark_ss928v100") { -+ sources += ["frameworks/engines/gfx/hi3519/hi3519_engine.cpp"] -+ } else { -+ sources += ["frameworks/engines/gfx/hi3516/hi3516_engine.cpp"] -+ } -+ - if (ohos_kernel_type == "liteos_m") { - target_type = "static_library" - include_dirs = [ -@@ -260,7 +267,7 @@ if (os_level != "standard") { - - if (ui_lite_enable_video_component_config) { - defines += [ "ENABLE_VIDEO_COMPONENT=1" ] -- source += [ "frameworks/components/ui_video.cpp" ] -+ sources += [ "frameworks/components/ui_video.cpp" ] - - deps += [ "//foundation/multimedia/media_lite/frameworks/player_lite:player_lite" ] - } -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/common/graphic_startup.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/common/graphic_startup.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/common/graphic_startup.cpp 2025-05-03 17:56:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/common/graphic_startup.cpp 2025-09-22 12:34:40.964729466 +0800 -@@ -38,6 +38,7 @@ - #endif - #if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES - #include "hals/gfx_engines.h" -+#include "hals/gralloc_engines.h" - #endif - #include "securec.h" - -@@ -150,6 +151,7 @@ void GraphicStartUp::Init() - #endif - #if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES - GfxEngines::GetInstance()->InitDriver(); -+ GrallocEngines::GetInstance()->Init(); - #endif - } - } // namespace OHOS -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/common/image.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/common/image.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/common/image.cpp 2025-05-03 17:56:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/common/image.cpp 2025-09-22 12:34:40.964729466 +0800 -@@ -103,7 +103,7 @@ bool Image::SetStandardSrc(const char* s - return false; - } - --#if ENABLE_JPEG || ENABLE_PNG -+#if (ENABLE_JPEG || ENABLE_PNG) && (!CACHE_JPEG_AND_PNG) - ImageType imageType = CheckImgType(src); - #if ENABLE_PNG - if (imageType == IMG_PNG) { -@@ -250,7 +250,7 @@ bool Image::PreParse(const char *src) - } - path_ = path; - bool isSucess = true; --#if ENABLE_JPEG || ENABLE_PNG -+#if (ENABLE_JPEG || ENABLE_PNG) && (!CACHE_JPEG_AND_PNG) - ImageType imageType = CheckImgType(src); - if (imageType == IMG_PNG) { - #if ENABLE_PNG -@@ -285,7 +285,7 @@ void Image::DrawImage(BufferInfo& gfxDst - } - } - --#if ENABLE_PNG -+#if ENABLE_PNG && (!CACHE_JPEG_AND_PNG) - static inline void FreePngBytep(png_bytep** rowPointer, uint16_t size) - { - png_bytep* tmpRowPointer = *rowPointer; -@@ -409,7 +409,7 @@ bool Image::SetPNGSrc(const char* src) - } - #endif - --#if ENABLE_JPEG -+#if ENABLE_JPEG && (!CACHE_JPEG_AND_PNG) - bool Image::SetJPEGSrc(const char* src) - { - struct jpeg_decompress_struct cinfo; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/components/root_view.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/components/root_view.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/components/root_view.cpp 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/components/root_view.cpp 2025-09-22 12:34:40.968729460 +0800 -@@ -19,6 +19,9 @@ - #include "core/render_manager.h" - #include "draw/draw_utils.h" - #include "gfx_utils/graphic_log.h" -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+#include "hals/gralloc_engines.h" -+#endif - #if defined(ENABLE_WINDOW) && ENABLE_WINDOW - #include "window/window_impl.h" - #endif -@@ -576,7 +579,13 @@ void RootView::BlitMapBuffer(Rect& curVi - imageInfo.header.height = dc_.mapBufferInfo->height; - imageInfo.header.reserved = 0; - imageInfo.data = reinterpret_cast(dc_.mapBufferInfo->virAddr); -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ imageInfo.phyAddr = reinterpret_cast(dc_.mapBufferInfo->phyAddr); -+ TransformDataInfo imageTranDataInfo = {imageInfo.header, imageInfo.data, -+ imageInfo.phyAddr, pxSize, LEVEL0, BILINEAR}; -+#else - TransformDataInfo imageTranDataInfo = {imageInfo.header, imageInfo.data, pxSize, LEVEL0, BILINEAR}; -+#endif - BaseGfxEngine::GetInstance()->DrawTransform(*dc_.bufferInfo, invalidRect, {0, 0}, Color::Black(), OPA_OPAQUE, - transMap, imageTranDataInfo); - } -@@ -843,14 +852,34 @@ void RootView::InitMapBufferInfo(BufferI - BaseGfxEngine* baseGfxEngine = BaseGfxEngine::GetInstance(); - baseGfxEngine->AdjustLineStride(*dc_.mapBufferInfo); - uint32_t bufferSize = dc_.mapBufferInfo->stride * dc_.mapBufferInfo->height; -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ AllocInfo info; -+ info.expectedSize = bufferSize; -+ info.usage = HBM_USE_ASSIGN_SIZE | HBM_USE_MEM_MMZ; -+ -+ GrallocBuffer buffer; -+ if (!GrallocEngines::GetInstance()->AllocBuffer(info, buffer)) { -+ GRAPHIC_LOGE("AllocBuffer failed."); -+ delete dc_.mapBufferInfo; -+ dc_.mapBufferInfo = nullptr; -+ return; -+ } -+ dc_.mapBufferInfo->virAddr = buffer.virAddr; -+ dc_.mapBufferInfo->phyAddr = reinterpret_cast(buffer.phyAddr); -+#else - dc_.mapBufferInfo->virAddr = dc_.mapBufferInfo->phyAddr = - baseGfxEngine->AllocBuffer(bufferSize, BUFFER_MAP_SURFACE); -+#endif - } - - void RootView::DestroyMapBufferInfo() - { - if (dc_.mapBufferInfo != nullptr) { -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ GrallocEngines::GetInstance()->FreeBuffer(static_cast(dc_.mapBufferInfo->virAddr)); -+#else - BaseGfxEngine::GetInstance()->FreeBuffer(static_cast(dc_.mapBufferInfo->virAddr), BUFFER_MAP_SURFACE); -+#endif - dc_.mapBufferInfo->virAddr = dc_.mapBufferInfo->phyAddr = nullptr; - delete dc_.mapBufferInfo; - dc_.mapBufferInfo = nullptr; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/components/ui_analog_clock.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/components/ui_analog_clock.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/components/ui_analog_clock.cpp 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/components/ui_analog_clock.cpp 2025-09-22 12:34:40.968729460 +0800 -@@ -280,8 +280,13 @@ void UIAnalogClock::DrawHandImage(Buffer - return; - } - uint8_t pxSize = DrawUtils::GetPxSizeByColorMode(hand.imageInfo_.header.colorMode); -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ TransformDataInfo imageTranDataInfo = {hand.imageInfo_.header, hand.imageInfo_.data, hand.imageInfo_.phyAddr, -+ pxSize, BlurLevel::LEVEL0, TransformAlgorithm::BILINEAR}; -+#else - TransformDataInfo imageTranDataInfo = {hand.imageInfo_.header, hand.imageInfo_.data, pxSize, BlurLevel::LEVEL0, - TransformAlgorithm::BILINEAR}; -+#endif - BaseGfxEngine::GetInstance()->DrawTransform(gfxDstBuffer, invalidatedArea, {0, 0}, Color::Black(), opaScale_, - hand.trans_, imageTranDataInfo); - } -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/components/ui_canvas.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/components/ui_canvas.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/components/ui_canvas.cpp 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/components/ui_canvas.cpp 2025-09-22 12:34:40.968729460 +0800 -@@ -1472,8 +1472,14 @@ void UICanvas::BlitMapBuffer(BufferInfo - imageInfo.header.reserved = 0; - uint8_t* addr = reinterpret_cast(gfxMapBuffer.virAddr); - imageInfo.data = addr; -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ imageInfo.phyAddr = reinterpret_cast(gfxMapBuffer.phyAddr); -+ TransformDataInfo imageTranDataInfo = {imageInfo.header, imageInfo.data, imageInfo.phyAddr, pxSize, -+ BlurLevel::LEVEL0, TransformAlgorithm::BILINEAR}; -+#else - TransformDataInfo imageTranDataInfo = {imageInfo.header, imageInfo.data, pxSize, - BlurLevel::LEVEL0, TransformAlgorithm::BILINEAR}; -+#endif - BaseGfxEngine::GetInstance()->DrawTransform(gfxDstBuffer, invalidatedArea, {0, 0}, Color::Black(), - OPA_OPAQUE, transMap, imageTranDataInfo); - } -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/components/ui_image_view.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/components/ui_image_view.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/components/ui_image_view.cpp 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/components/ui_image_view.cpp 2025-09-22 12:34:40.968729460 +0800 -@@ -456,9 +456,15 @@ void UIImageView::OnDraw(BufferInfo& gfx - imgInfo = *(GetImageInfo()); - } - uint8_t pxSize = DrawUtils::GetPxSizeByColorMode(imgInfo.header.colorMode); -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ TransformDataInfo imageTranDataInfo = {imgInfo.header, imgInfo.data, imgInfo.phyAddr, pxSize, -+ static_cast(blurLevel_), -+ static_cast(algorithm_)}; -+#else - TransformDataInfo imageTranDataInfo = {imgInfo.header, imgInfo.data, pxSize, - static_cast(blurLevel_), - static_cast(algorithm_)}; -+#endif - OpacityType opaScale = DrawUtils::GetMixOpacity(opa, style_->imageOpa_); - Matrix4 scaleMatrix = drawTransMap_->GetScaleMatrix(); - int16_t paddingX = style_->paddingLeft_ * scaleMatrix[0][0]; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/draw/draw_image.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/draw/draw_image.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/draw/draw_image.cpp 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/draw/draw_image.cpp 2025-09-22 12:34:40.968729460 +0800 -@@ -28,8 +28,13 @@ void DrawImage::DrawCommon(BufferInfo& g - } - OpacityType opa = DrawUtils::GetMixOpacity(opaScale, style.imageOpa_); - uint8_t pxBitSize = DrawUtils::GetPxSizeByColorMode(img->header.colorMode); -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ DrawUtils::GetInstance()->DrawImage(gfxDstBuffer, coords, mask, img->data, opa, pxBitSize, -+ static_cast(img->header.colorMode), img->phyAddr); -+#else - DrawUtils::GetInstance()->DrawImage(gfxDstBuffer, coords, mask, img->data, opa, pxBitSize, - static_cast(img->header.colorMode)); -+#endif - } - - void DrawImage::DrawCommon(BufferInfo& gfxDstBuffer, const Rect& coords, const Rect& mask, -@@ -47,8 +52,14 @@ void DrawImage::DrawCommon(BufferInfo& g - - uint8_t pxBitSize = DrawUtils::GetPxSizeByColorMode(entry.GetImageInfo().header.colorMode); - if (entry.InCache()) { -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ DrawUtils::GetInstance()->DrawImage(gfxDstBuffer, coords, mask, entry.GetImgData(), opa, pxBitSize, -+ static_cast(entry.GetImageInfo().header.colorMode), -+ entry.GetImageInfo().phyAddr); -+#else - DrawUtils::GetInstance()->DrawImage(gfxDstBuffer, coords, mask, entry.GetImgData(), opa, pxBitSize, - static_cast(entry.GetImageInfo().header.colorMode)); -+#endif - } else { - Rect valid = coords; - if (!valid.Intersect(valid, mask)) { -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/draw/draw_label.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/draw/draw_label.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/draw/draw_label.cpp 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/draw/draw_label.cpp 2025-09-22 12:34:40.968729460 +0800 -@@ -287,10 +287,13 @@ void DrawLabel::DrawLetterWithRotate(Buf - // Avoiding errors caused by rounding calculations - transMap.Translate(Vector2(posX + node.left, posY + offset - node.top)); - transMap.Rotate(letterInfo.rotateAngle, Vector2(posX, posY)); -- -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ TransformDataInfo letterTranDataInfo = {ImageHeader{colorMode, 0, 0, 0, node.cols, node.rows}, fontMap, nullptr, -+ fontWeight, BlurLevel::LEVEL0, TransformAlgorithm::BILINEAR}; -+#else - TransformDataInfo letterTranDataInfo = {ImageHeader{colorMode, 0, 0, 0, node.cols, node.rows}, fontMap, fontWeight, - BlurLevel::LEVEL0, TransformAlgorithm::BILINEAR}; -- -+#endif - uint8_t* buffer = nullptr; - if (letterInfo.hasAnimator) { - bool inRange = DrawLabel::CalculatedTransformDataInfo(&buffer, letterTranDataInfo, letterInfo); -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/draw/draw_utils.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/draw/draw_utils.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/draw/draw_utils.cpp 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/draw/draw_utils.cpp 2025-09-22 12:34:40.972729454 +0800 -@@ -381,7 +381,8 @@ void DrawUtils::DrawImage(BufferInfo& gf - const uint8_t* image, - OpacityType opa, - uint8_t pxBitSize, -- ColorMode colorMode) const -+ ColorMode colorMode, -+ const uint8_t* imgPhyAddr) const - { - if (image == nullptr) { - return; -@@ -404,6 +405,11 @@ void DrawUtils::DrawImage(BufferInfo& gf - - src.virAddr = static_cast(const_cast(image)); - src.stride = imageWidthInByte; -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ src.width = area.GetWidth(); -+ src.height = area.GetHeight(); -+ src.phyAddr = static_cast(const_cast(imgPhyAddr)); -+#endif - src.mode = colorMode; - src.color = 0; - -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/draw/draw_utils.h ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/draw/draw_utils.h ---- ohos/foundation/arkui/ui_lite/frameworks/draw/draw_utils.h 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/draw/draw_utils.h 2025-09-22 12:34:40.972729454 +0800 -@@ -230,7 +230,8 @@ public: - const OpacityType opa) const; - - void DrawImage(BufferInfo& gfxDstBuffer, const Rect& area, const Rect& mask, -- const uint8_t* image, OpacityType opa, uint8_t pxBitSize, ColorMode colorMode) const; -+ const uint8_t* image, OpacityType opa, uint8_t pxBitSize, ColorMode colorMode, -+ const uint8_t* imgPhyAddr = nullptr) const; - - static void - GetXAxisErrForJunctionLine(bool ignoreJunctionPoint, bool isRightPart, int16_t& xMinErr, int16_t& xMaxErr); -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/engines/gfx/hi3519/hi3519_engine.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/engines/gfx/hi3519/hi3519_engine.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/engines/gfx/hi3519/hi3519_engine.cpp 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/engines/gfx/hi3519/hi3519_engine.cpp 2025-09-22 12:34:40.972729454 +0800 -@@ -0,0 +1,169 @@ -+/* -+ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. -+ * 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. -+ */ -+ -+#include "engines/gfx/hi3519/hi3519_engine.h" -+#include "draw/draw_utils.h" -+#include "hals/gfx_engines.h" -+#include "lite_wm_type.h" -+ -+namespace OHOS { -+const int16_t HARDWARE_ACC_SIZE_LIMIT = 50 * 50; // 50: Minimum supported pixel width and height -+ -+#define ALIGN_BYTE(byte, align) (((byte) + (align) - 1) & (~((align) -1))) -+ -+__attribute__((constructor)) void RegisterHi3519GfxEngine() -+{ -+ BaseGfxEngine::InitGfxEngine(new Hi3519GfxEngine()); -+} -+ -+ImagePixelFormat Hi3519GfxEngine::GetPixelFormatByColorMode(ColorMode colorMode) -+{ -+ ImagePixelFormat format = IMAGE_PIXEL_FORMAT_NONE; -+ switch (colorMode) { -+ case ARGB8888: -+ format = IMAGE_PIXEL_FORMAT_ARGB8888; -+ break; -+ case RGB888: -+ format = IMAGE_PIXEL_FORMAT_RGB888; -+ break; -+ case RGB565: -+ format = IMAGE_PIXEL_FORMAT_RGB565; -+ break; -+ case ARGB1555: -+ format = IMAGE_PIXEL_FORMAT_ARGB1555; -+ break; -+ default: -+ GRAPHIC_LOGE("current color mode not support!"); -+ break; -+ } -+ return format; -+} -+ -+uint8_t GetByteSizeByColorMode(uint8_t colorMode) -+{ -+ switch (colorMode) { -+ case ARGB8888: -+ return 4; // 4: 4 Byte -+ case RGB888: -+ return 3; // 3: 3 Byte -+ case RGB565: -+ case ARGB1555: -+ case ARGB4444: -+ return 2; // 2: 2 Byte -+ default: -+ return 0; -+ } -+} -+ -+void Hi3519GfxEngine::Blit(BufferInfo& dst, const Point& dstPos, const BufferInfo& src, -+ const Rect& subRect, const BlendOption& blendOption) -+{ -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ LiteSurfaceData srcData; -+ srcData.phyAddr = (uint8_t *)src.phyAddr; -+ srcData.width = src.width; -+ srcData.height = src.height; -+ srcData.stride = src.stride; -+ srcData.pixelFormat = GetPixelFormatByColorMode(src.mode); -+ -+ LiteSurfaceData dstData; -+ dstData.phyAddr = (uint8_t *)dst.phyAddr; -+ dstData.width = dst.width; -+ dstData.height = dst.height; -+ dstData.stride = dst.stride; -+ dstData.pixelFormat = GetPixelFormatByColorMode(dst.mode); -+ Rect dstRect; -+ dstRect.SetX(subRect.GetX()); -+ dstRect.SetY(subRect.GetY()); -+ dstRect.SetWidth(src.rect.GetWidth()); -+ dstRect.SetHeight(src.rect.GetHeight()); -+ if (GfxEngines::GetInstance()->GfxBlitWithOpt(srcData, src.rect, dstData, dstRect, blendOption.opacity)) { -+ return; -+ } -+#endif -+ SoftEngine::Blit(dst, dstPos, src, subRect, blendOption); -+} -+ -+void Hi3519GfxEngine::Fill(BufferInfo& dst, -+ const Rect& fillArea, -+ const ColorType color, -+ const OpacityType opacity) -+{ -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ if (fillArea.GetSize() >= HARDWARE_ACC_SIZE_LIMIT) { -+ LiteSurfaceData data; -+ data.phyAddr = static_cast(dst.phyAddr); -+ data.width = dst.width; -+ data.height = dst.height; -+ data.stride = dst.stride; -+ data.pixelFormat = IMAGE_PIXEL_FORMAT_ARGB8888; -+ if (GfxEngines::GetInstance()->GfxFillArea(data, fillArea, color, opacity)) { -+ return; -+ } -+ } -+#endif -+ SoftEngine::Fill(dst, fillArea, color, opacity); -+} -+ -+void Hi3519GfxEngine::DrawTransform(BufferInfo& dst, const Rect& mask, const Point& position, ColorType color, -+ OpacityType opacity, const TransformMap& transMap, const TransformDataInfo& dataInfo) -+{ -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ if ((transMap.GetRotateAngle() == 0) && (dataInfo.phyAddr != nullptr) && -+ (dataInfo.header.width != 0) && (dataInfo.header.height != 0)) { -+ LiteSurfaceData srcData; -+ srcData.phyAddr = const_cast(dataInfo.phyAddr); -+ srcData.width = dataInfo.header.width; -+ srcData.height = dataInfo.header.height; -+ uint32_t rowSize = srcData.width * GetByteSizeByColorMode(dataInfo.header.colorMode); -+ srcData.stride = ALIGN_BYTE(rowSize, 4); // 4:Align Byte -+ srcData.pixelFormat = GetPixelFormatByColorMode(static_cast(dataInfo.header.colorMode)); -+ -+ LiteSurfaceData dstData; -+ dstData.phyAddr = (uint8_t *)dst.phyAddr; -+ dstData.width = dst.width; -+ dstData.height = dst.height; -+ dstData.stride = dst.stride; -+ dstData.pixelFormat = GetPixelFormatByColorMode(dst.mode); -+ -+ Rect trans = transMap.GetBoxRect(); -+ if ((trans.GetWidth() == 0) || (trans.GetHeight() == 0)) { -+ GRAPHIC_LOGE("transMap rect error, size %u %u\n", trans.GetWidth(), trans.GetHeight()); -+ return; -+ } -+ double xScale = 1.0f * trans.GetWidth() / dataInfo.header.width; -+ double yScale = 1.0f * trans.GetHeight() / dataInfo.header.height; -+ trans.SetX(trans.GetX() + position.x); -+ trans.SetY(trans.GetY() + position.y); -+ Rect dstRect; -+ if (!dstRect.Intersect(trans, mask)) { -+ return; -+ } -+ -+ Rect srcRect; -+ int32_t leftOffset = dstRect.GetLeft() - trans.GetLeft(); -+ int32_t topOffset = dstRect.GetTop() - trans.GetTop(); -+ srcRect.SetLeft(leftOffset / xScale); -+ srcRect.SetTop(topOffset / yScale); -+ srcRect.SetWidth(dstRect.GetWidth() / xScale); -+ srcRect.SetHeight(dstRect.GetHeight() / yScale); -+ if (GfxEngines::GetInstance()->GfxBlitWithOpt(srcData, srcRect, dstData, dstRect, opacity)) { -+ return; -+ } -+ } -+#endif -+ SoftEngine::DrawTransform(dst, mask, position, color, opacity, transMap, dataInfo); -+} -+} -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/engines/gfx/hi3519/hi3519_engine.h ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/engines/gfx/hi3519/hi3519_engine.h ---- ohos/foundation/arkui/ui_lite/frameworks/engines/gfx/hi3519/hi3519_engine.h 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/engines/gfx/hi3519/hi3519_engine.h 2025-09-22 12:34:40.972729454 +0800 -@@ -0,0 +1,47 @@ -+/* -+ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. -+ * 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. -+ */ -+ -+#ifndef GRAPHIC_LITE_HI3519_ENGINE_H -+#define GRAPHIC_LITE_HI3519_ENGINE_H -+ -+#include "engines/gfx/soft_engine.h" -+#include "gfx_utils/pixel_format_utils.h" -+ -+namespace OHOS { -+class Hi3519GfxEngine : public SoftEngine { -+public: -+ void Blit(BufferInfo& dst, -+ const Point& dstPos, -+ const BufferInfo& src, -+ const Rect& subRect, -+ const BlendOption& blendOption) override; -+ -+ void Fill(BufferInfo& dst, -+ const Rect& fillArea, -+ const ColorType color, -+ const OpacityType opacity) override; -+ -+ void DrawTransform(BufferInfo& dst, -+ const Rect& mask, -+ const Point& position, -+ ColorType color, -+ OpacityType opacity, -+ const TransformMap& transMap, -+ const TransformDataInfo& dataInfo) override; -+private: -+ ImagePixelFormat GetPixelFormatByColorMode(ColorMode colorMode); -+}; -+} -+#endif // GRAPHIC_LITE_HI3519_ENGINE_H -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/imgdecode/cache_manager.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/cache_manager.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/imgdecode/cache_manager.cpp 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/cache_manager.cpp 2025-09-22 12:34:40.972729454 +0800 -@@ -18,6 +18,10 @@ - #include "hal_tick.h" - #include "securec.h" - -+#include "common/image.h" -+#include "jpeg_img_decoder.h" -+#include "png_img_decoder.h" -+ - namespace OHOS { - const uint8_t* CacheEntry::GetImgData() const - { -@@ -126,7 +130,6 @@ RetCode CacheManager::Open(const char* p - uint16_t indexHitted = 0; - RetCode ret = GetIndex(path, indexHitted); - if (ret == RetCode::OK) { -- ReadToCache(entryArr_[indexHitted]); - entry = entryArr_[indexHitted]; - return RetCode::OK; - } -@@ -139,11 +142,21 @@ RetCode CacheManager::Open(const char* p - uint32_t startTime = HALTick::GetInstance().GetTime(); - entryArr_[indexHitted].life_ = 0; - -- ret = TryDecode(path, style, entryArr_[indexHitted]); -+ char realPath[PATH_MAX + 1] = {0}; -+ if (strlen(path) > PATH_MAX || realpath(path, realPath) == nullptr) { -+ return RetCode::FAIL; -+ } -+ -+ ret = TryDecode(realPath, style, entryArr_[indexHitted]); -+ if (ret != RetCode::OK) { -+ GRAPHIC_LOGE("CacheManager TryDecode %s faild\n", path); -+ return ret; -+ } -+ ret = ReadToCache(entryArr_[indexHitted]); - if (ret != RetCode::OK) { -+ Clear(entryArr_[indexHitted]); - return ret; - } -- ReadToCache(entryArr_[indexHitted]); - entryArr_[indexHitted].life_ = HALTick::GetInstance().GetElapseTime(startTime); - entry = entryArr_[indexHitted]; - return RetCode::OK; -@@ -268,27 +281,34 @@ RetCode CacheManager::SelectEntryToRepla - - RetCode CacheManager::TryDecode(const char* path, const Style& style, CacheEntry& entry) - { -- FileImgDecoder* decoder = &(FileImgDecoder::GetInstance()); -- if (decoder == nullptr) { -- Clear(entry); -- return RetCode::FAIL; -- } -- - entry.dsc_.srcType = IMG_SRC_FILE; - RetCode ret = entry.SetSrc(path); - if (ret != RetCode::OK) { - Clear(entry); - return ret; - } -+ FileImgDecoder* decoder = &(FileImgDecoder::GetInstance()); -+ -+ Image::ImageType type = Image::CheckImgType(path); -+ if (type == Image::IMG_PNG) { -+ decoder = &(PngImgDecoder::GetInstance()); -+ } else if (type == Image::IMG_JPEG) { -+ decoder = &(JpegImgDecoder::GetInstance()); -+ } -+ -+ if (decoder == nullptr) { -+ Clear(entry); -+ return RetCode::FAIL; -+ } - entry.dsc_.decoder = decoder; - -- ret = entry.dsc_.decoder->GetHeader(entry.dsc_); -+ ret = entry.dsc_.decoder->Open(entry.dsc_); - if (ret != RetCode::OK) { - Clear(entry); - return ret; - } - -- ret = entry.dsc_.decoder->Open(entry.dsc_); -+ ret = entry.dsc_.decoder->GetHeader(entry.dsc_); - if (ret != RetCode::OK) { - Clear(entry); - return ret; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/imgdecode/file_img_decoder.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/file_img_decoder.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/imgdecode/file_img_decoder.cpp 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/file_img_decoder.cpp 2025-09-22 12:34:40.972729454 +0800 -@@ -17,6 +17,7 @@ - #include "gfx_utils/mem_api.h" - #include "imgdecode/file_img_decoder.h" - #include "imgdecode/image_load.h" -+#include "securec.h" - - namespace OHOS { - FileImgDecoder& FileImgDecoder::GetInstance() -@@ -39,12 +40,7 @@ RetCode FileImgDecoder::Open(ImgResDsc& - - dsc.imgInfo.data = nullptr; - dsc.inCache_ = false; -- uint8_t colorMode = dsc.imgInfo.header.colorMode; -- if (IsImgValidMode(colorMode)) { -- return RetCode::OK; -- } else { -- return RetCode::FAIL; -- } -+ return RetCode::OK; - } - - RetCode FileImgDecoder::Close(ImgResDsc& dsc) -@@ -57,33 +53,26 @@ RetCode FileImgDecoder::Close(ImgResDsc& - close(dsc.fd); - dsc.fd = -1; - } -- -+ dsc.inCache_ = false; - return RetCode::OK; - } - - RetCode FileImgDecoder::GetHeader(ImgResDsc& dsc) - { -- int32_t fd; -- int32_t readCount; --#ifdef _WIN32 -- fd = open(dsc.path, O_BINARY); --#else -- fd = open(dsc.path, O_RDONLY); --#endif -- if (fd == -1) { -+ if (dsc.fd == -1) { - return RetCode::FAIL; - } -- -- readCount = read(fd, &dsc.imgInfo.header, sizeof(ImageHeader)); -- close(fd); -- dsc.fd = -1; -+ int32_t readCount = read(dsc.fd, &dsc.imgInfo.header, sizeof(ImageHeader)); - if (readCount != sizeof(ImageHeader)) { - dsc.imgInfo.header.width = 0; - dsc.imgInfo.header.height = 0; - dsc.imgInfo.header.colorMode = UNKNOWN; - return RetCode::FAIL; - } -- -+ uint8_t colorMode = dsc.imgInfo.header.colorMode; -+ if (!IsImgValidMode(colorMode)) { -+ return RetCode::FAIL; -+ } - return RetCode::OK; - } - -@@ -116,16 +105,32 @@ RetCode FileImgDecoder::ReadToCache(ImgR - } - - bool readSuccess = false; -- if (dsc.imgInfo.header.compressMode != COMPRESS_MODE_NONE) { -+ if (dsc.imgInfo.header.compressMode != COMPRESS_MODE_NONE) { - readSuccess = ImageLoad::GetImageInfo(dsc.fd, pxCount, dsc.imgInfo); - } else { -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ int rowSize = dsc.imgInfo.header.width * DrawUtils::GetByteSizeByColorMode(dsc.imgInfo.header.colorMode); -+ /* tde requires 4-byte alignment of stride */ -+ dsc.imgInfo.dataSize = rowSize * dsc.imgInfo.header.height; -+#else - dsc.imgInfo.dataSize = pxCount; -+#endif - dsc.imgInfo.data = reinterpret_cast(ImageCacheMalloc(dsc.imgInfo)); - if (dsc.imgInfo.data == nullptr) { - return RetCode::OK; - } - uint8_t* tmp = const_cast(dsc.imgInfo.data); -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ int32_t readTotalSize = 0; -+ memset_s(reinterpret_cast(tmp), dsc.imgInfo.dataSize, 0, dsc.imgInfo.dataSize); -+ for (int i = 0; i < dsc.imgInfo.header.height; i++) { -+ readTotalSize += read(dsc.fd, reinterpret_cast(tmp), rowSize); -+ tmp += rowSize; -+ } -+ readSuccess = (readTotalSize == rowSize * dsc.imgInfo.header.height); -+#else - readSuccess = (static_cast(pxCount) == read(dsc.fd, reinterpret_cast(tmp), pxCount)); -+#endif - } - if (!readSuccess) { - ImageCacheFree(dsc.imgInfo); -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/imgdecode/file_img_decoder.h ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/file_img_decoder.h ---- ohos/foundation/arkui/ui_lite/frameworks/imgdecode/file_img_decoder.h 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/file_img_decoder.h 2025-09-22 12:34:40.976729447 +0800 -@@ -45,20 +45,21 @@ public: - bool inCache_; - }; - -- RetCode Open(ImgResDsc& dsc); -+ virtual RetCode Open(ImgResDsc& dsc); - -- RetCode Close(ImgResDsc& dsc); -+ virtual RetCode Close(ImgResDsc& dsc); - -- RetCode GetHeader(ImgResDsc& dsc); -+ virtual RetCode GetHeader(ImgResDsc& dsc); - -- RetCode ReadLine(ImgResDsc& dsc, const Point& start, int16_t len, uint8_t* buf); -+ virtual RetCode ReadLine(ImgResDsc& dsc, const Point& start, int16_t len, uint8_t* buf); - -- RetCode ReadToCache(ImgResDsc& dsc); -+ virtual RetCode ReadToCache(ImgResDsc& dsc); - --private: -+protected: - FileImgDecoder() {} -- ~FileImgDecoder() {} -+ virtual ~FileImgDecoder() {} - -+private: - bool IsImgValidMode(uint8_t colorMode) - { - if ((colorMode == RGB565) || (colorMode == RGB888) || (colorMode == ARGB8888)) { -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/imgdecode/jpeg_img_decoder.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/jpeg_img_decoder.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/imgdecode/jpeg_img_decoder.cpp 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/jpeg_img_decoder.cpp 2025-09-22 12:34:40.976729447 +0800 -@@ -0,0 +1,128 @@ -+/* -+ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. -+ * 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. -+ */ -+ -+#include "imgdecode/jpeg_img_decoder.h" -+#include "gfx_utils/file.h" -+#include "gfx_utils/graphic_log.h" -+#include "gfx_utils/mem_api.h" -+#include "securec.h" -+ -+namespace OHOS { -+RetCode JpegImgDecoder::Open(ImgResDsc& dsc) -+{ -+ fp_ = fopen(dsc.path, "rb"); -+ if (fp_ == nullptr) { -+ GRAPHIC_LOGE("open file:%s failed\n", dsc.path); -+ return RetCode::FAIL; -+ } -+ -+ dsc.imgInfo.data = nullptr; -+ dsc.inCache_ = false; -+ -+ return RetCode::OK; -+} -+ -+RetCode JpegImgDecoder::Close(ImgResDsc& dsc) -+{ -+ if (dsc.imgInfo.data != nullptr) { -+ ImageCacheFree(dsc.imgInfo); -+ dsc.imgInfo.data = nullptr; -+ } -+ -+ if (fp_ != nullptr) { -+ fclose(fp_); -+ fp_ = nullptr; -+ } -+ -+ dsc.inCache_ = false; -+ return RetCode::OK; -+} -+ -+RetCode JpegImgDecoder::CreateDecoder(void) -+{ -+ if (fp_ == nullptr) { -+ GRAPHIC_LOGE("File is not opened, call Open first\n"); -+ return RetCode::FAIL; -+ } -+ -+ cinfo_.err = jpeg_std_error(&jerr_); -+ jpeg_create_decompress(&cinfo_); -+ jpeg_stdio_src(&cinfo_, fp_); -+ jpeg_read_header(&cinfo_, TRUE); -+ jpeg_start_decompress(&cinfo_); -+ -+ return RetCode::OK; -+} -+ -+void JpegImgDecoder::DestroyDecoder(void) -+{ -+ if (fp_ != nullptr) { -+ fclose(fp_); -+ fp_ = nullptr; -+ } -+ -+ jpeg_finish_decompress(&cinfo_); -+ jpeg_destroy_decompress(&cinfo_); -+} -+ -+RetCode JpegImgDecoder::GetHeader(ImgResDsc& dsc) -+{ -+ if (CreateDecoder() != RetCode::OK) { -+ GRAPHIC_LOGE("Decoder is created failed\n"); -+ return RetCode::FAIL; -+ } -+ -+ dsc.imgInfo.header.width = cinfo_.output_width; -+ dsc.imgInfo.header.height = cinfo_.output_height; -+ dsc.imgInfo.header.colorMode = ARGB8888; -+ -+ return RetCode::OK; -+} -+ -+RetCode JpegImgDecoder::ReadToCache(ImgResDsc& dsc) -+{ -+ JSAMPARRAY buffer; -+ uint8_t pixelByteSize = DrawUtils::GetPxSizeByColorMode(ARGB8888) >> 3; // 3: Shift right 3 bits -+ uint16_t width = cinfo_.output_width; -+ uint16_t height = cinfo_.output_height; -+ uint32_t dataSize = width * height * pixelByteSize; -+ uint16_t rowStride = cinfo_.output_width * pixelByteSize; -+ buffer = (*cinfo_.mem->alloc_sarray)(reinterpret_cast(&cinfo_), -+ JPOOL_IMAGE, rowStride, 1); // 1: one-row-high array -+ -+ dsc.imgInfo.dataSize = dataSize; -+ uint8_t* srcData = static_cast(ImageCacheMalloc(dsc.imgInfo)); -+ dsc.imgInfo.data = srcData; -+ if (srcData == nullptr) { -+ DestroyDecoder(); -+ return RetCode::FAIL; -+ } -+ -+ uint32_t n = 0; -+ while (cinfo_.output_scanline < cinfo_.output_height) { -+ jpeg_read_scanlines(&cinfo_, buffer, 1); // 1: read one line each time -+ for (uint16_t x = 0; x < width * 3; x += 3) { // 3: color components per pixel -+ srcData[n++] = buffer[0][x + 2]; // 2: B channel -+ srcData[n++] = buffer[0][x + 1]; // 1: G channel -+ srcData[n++] = buffer[0][x + 0]; // 0: R channel -+ srcData[n++] = 255; // 255: set alpha channel -+ } -+ } -+ DestroyDecoder(); -+ dsc.inCache_ = true; -+ -+ return RetCode::OK; -+} -+} // namespace OHOS -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/imgdecode/jpeg_img_decoder.h ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/jpeg_img_decoder.h ---- ohos/foundation/arkui/ui_lite/frameworks/imgdecode/jpeg_img_decoder.h 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/jpeg_img_decoder.h 2025-09-22 12:34:40.976729447 +0800 -@@ -0,0 +1,63 @@ -+/* -+ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. -+ * 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. -+ */ -+ -+#ifndef GRAPHIC_LITE_JPEG_IMG_DECODER_H -+#define GRAPHIC_LITE_JPEG_IMG_DECODER_H -+ -+#include "file_img_decoder.h" -+#include "draw/draw_image.h" -+#include "draw/draw_utils.h" -+#include "jpeglib.h" -+ -+namespace OHOS { -+class JpegImgDecoder : public FileImgDecoder { -+public: -+ static JpegImgDecoder& GetInstance() -+ { -+ static JpegImgDecoder instance; -+ return instance; -+ } -+ -+ RetCode Open(ImgResDsc& dsc) override; -+ -+ RetCode Close(ImgResDsc& dsc) override; -+ -+ RetCode GetHeader(ImgResDsc& dsc) override; -+ -+ RetCode ReadToCache(ImgResDsc& dsc) override; -+ -+ RetCode ReadLine(ImgResDsc& dsc, const Point& start, int16_t len, uint8_t* buf) override -+ { -+ return RetCode::FAIL; -+ } -+ -+private: -+ FILE* fp_ {nullptr}; -+ struct jpeg_decompress_struct cinfo_ {0}; -+ struct jpeg_error_mgr jerr_ {0}; -+ JpegImgDecoder() {}; -+ virtual ~JpegImgDecoder() {}; -+ -+ RetCode CreateDecoder(void); -+ -+ void DestroyDecoder(void); -+ -+ JpegImgDecoder(const JpegImgDecoder&) = delete; -+ JpegImgDecoder& operator=(const JpegImgDecoder&) = delete; -+ JpegImgDecoder(JpegImgDecoder&&) = delete; -+ JpegImgDecoder& operator=(JpegImgDecoder&&) = delete; -+}; -+} -+#endif -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/imgdecode/png_img_decoder.cpp ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/png_img_decoder.cpp ---- ohos/foundation/arkui/ui_lite/frameworks/imgdecode/png_img_decoder.cpp 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/png_img_decoder.cpp 2025-09-22 12:34:40.976729447 +0800 -@@ -0,0 +1,194 @@ -+/* -+ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. -+ * 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. -+ */ -+ -+#include "imgdecode/png_img_decoder.h" -+#include "gfx_utils/mem_api.h" -+#include "gfx_utils/file.h" -+#include "gfx_utils/graphic_log.h" -+ -+namespace OHOS { -+ -+#define FREE_RES(ptr) \ -+ do { \ -+ UIFree(ptr); \ -+ ptr = nullptr; \ -+ } while (0) -+ -+RetCode PngImgDecoder::Open(ImgResDsc& dsc) -+{ -+ fp_ = fopen(dsc.path, "rb"); -+ if (fp_ == nullptr) { -+ GRAPHIC_LOGE("open file:%s failed\n", dsc.path); -+ return RetCode::FAIL; -+ } -+ -+ dsc.imgInfo.data = nullptr; -+ dsc.inCache_ = false; -+ dsc.fd = -1; // don't use fd here -+ -+ return RetCode::OK; -+} -+ -+RetCode PngImgDecoder::Close(ImgResDsc& dsc) -+{ -+ if (dsc.imgInfo.data != nullptr) { -+ ImageCacheFree(dsc.imgInfo); -+ dsc.imgInfo.data = nullptr; -+ } -+ -+ if (fp_ != nullptr) { -+ fclose(fp_); -+ fp_ = nullptr; -+ } -+ -+ dsc.inCache_ = false; -+ -+ return RetCode::OK; -+} -+ -+RetCode PngImgDecoder::CreateDecoder(void) -+{ -+ if (fp_ == nullptr) { -+ GRAPHIC_LOGE("File is not opened, call Open first\n"); -+ return RetCode::FAIL; -+ } -+ -+ png_ = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); -+ if (png_ == nullptr) { -+ return RetCode::FAIL; -+ } -+ -+ info_ = png_create_info_struct(png_); -+ if (info_ == nullptr) { -+ png_destroy_read_struct(&png_, nullptr, nullptr); -+ return RetCode::FAIL; -+ } -+ -+ png_init_io(png_, fp_); -+ png_read_info(png_, info_); -+ -+ return RetCode::OK; -+} -+ -+void PngImgDecoder::DestroyDecoder(void) -+{ -+ if (fp_ != nullptr) { -+ fclose(fp_); -+ fp_ = nullptr; -+ } -+ -+ if (png_ != nullptr && info_ != nullptr) { -+ png_destroy_read_struct(&png_, &info_, nullptr); -+ } else if (png_ != nullptr && info_ == nullptr) { -+ png_destroy_read_struct(&png_, nullptr, nullptr); -+ } -+} -+ -+RetCode PngImgDecoder::GetHeader(ImgResDsc& dsc) -+{ -+ if (CreateDecoder() != RetCode::OK) { -+ GRAPHIC_LOGE("Decoder is created failed\n"); -+ return RetCode::FAIL; -+ } -+ -+ dsc.imgInfo.header.width = png_get_image_width(png_, info_); -+ dsc.imgInfo.header.height = png_get_image_height(png_, info_); -+ dsc.imgInfo.header.colorMode = ARGB8888; -+ -+ return RetCode::OK; -+} -+ -+void PngImgDecoder::UpdateInfo(void) -+{ -+ uint8_t colorType = png_get_color_type(png_, info_); -+ uint8_t bitDepth = png_get_bit_depth(png_, info_); -+ if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) { // 8: Expand grayscale images to the full 8 bits -+ png_set_expand_gray_1_2_4_to_8(png_); -+ } -+ if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA) { -+ png_set_gray_to_rgb(png_); -+ } -+ if (colorType == PNG_COLOR_TYPE_PALETTE) { -+ png_set_palette_to_rgb(png_); -+ } -+ if (bitDepth == 16) { // 16: Chop 16-bit depth images to 8-bit depth -+ png_set_strip_16(png_); -+ } -+ -+ if (png_get_valid(png_, info_, PNG_INFO_tRNS)) { -+ png_set_tRNS_to_alpha(png_); -+ } -+ if (!(colorType & PNG_COLOR_MASK_ALPHA)) { -+ png_set_add_alpha(png_, 0xFF, PNG_FILLER_AFTER); -+ } -+ png_set_interlace_handling(png_); -+ png_read_update_info(png_, info_); -+} -+ -+RetCode PngImgDecoder::ReadToCache(ImgResDsc& dsc) -+{ -+ uint8_t pixelByteSize = DrawUtils::GetPxSizeByColorMode(ARGB8888) >> 3; // 3: Shift right 3 bits -+ uint16_t width = dsc.imgInfo.header.width; -+ uint16_t height = dsc.imgInfo.header.height; -+ uint32_t dataSize = height * width * pixelByteSize; -+ -+ UpdateInfo(); -+ png_bytep* rowPointer = static_cast(UIMalloc(sizeof(png_bytep) * height)); -+ if (rowPointer == nullptr) { -+ DestroyDecoder(); -+ return RetCode::FAIL; -+ } -+ for (uint16_t y = 0; y < height; y++) { -+ rowPointer[y] = static_cast(UIMalloc(png_get_rowbytes(png_, info_))); -+ if (rowPointer[y] == nullptr) { -+ for (uint16_t i = 0; i < y; i++) { -+ FREE_RES(rowPointer[i]); -+ } -+ FREE_RES(rowPointer); -+ DestroyDecoder(); -+ return RetCode::FAIL; -+ } -+ } -+ png_read_image(png_, rowPointer); -+ -+ dsc.imgInfo.dataSize = dataSize; -+ uint8_t* srcData = static_cast(ImageCacheMalloc(dsc.imgInfo)); -+ dsc.imgInfo.data = srcData; -+ if (srcData == nullptr) { -+ for (uint16_t i = 0; i < height; i++) { -+ FREE_RES(rowPointer[i]); -+ } -+ FREE_RES(rowPointer); -+ DestroyDecoder(); -+ return RetCode::FAIL; -+ } -+ uint32_t n = 0; -+ for (uint16_t y = 0; y < height; y++) { -+ png_bytep row = rowPointer[y]; -+ for (uint16_t x = 0; x < width * pixelByteSize; x += pixelByteSize) { -+ srcData[n++] = row[x + 2]; // 2: B channel -+ srcData[n++] = row[x + 1]; // 1: G channel -+ srcData[n++] = row[x + 0]; // 0: R channel -+ srcData[n++] = row[x + 3]; // 3: Alpha channel -+ } -+ FREE_RES(row); -+ } -+ FREE_RES(rowPointer); -+ -+ DestroyDecoder(); -+ dsc.inCache_ = true; -+ return RetCode::OK; -+} -+} // namespace OHOS -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/frameworks/imgdecode/png_img_decoder.h ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/png_img_decoder.h ---- ohos/foundation/arkui/ui_lite/frameworks/imgdecode/png_img_decoder.h 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/frameworks/imgdecode/png_img_decoder.h 2025-09-22 12:34:40.976729447 +0800 -@@ -0,0 +1,64 @@ -+/* -+ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. -+ * 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. -+ */ -+ -+#ifndef GRAPHIC_LITE_PNG_IMG_DECODER_H -+#define GRAPHIC_LITE_PNG_IMG_DECODER_H -+ -+#include "file_img_decoder.h" -+#include "draw/draw_image.h" -+#include "draw/draw_utils.h" -+#include "png.h" -+ -+namespace OHOS { -+class PngImgDecoder : public FileImgDecoder { -+public: -+ static PngImgDecoder& GetInstance() -+ { -+ static PngImgDecoder instance; -+ return instance; -+ } -+ -+ RetCode Open(ImgResDsc& dsc) override; -+ -+ RetCode Close(ImgResDsc& dsc) override; -+ -+ RetCode GetHeader(ImgResDsc& dsc) override; -+ -+ RetCode ReadToCache(ImgResDsc& dsc) override; -+ -+ RetCode ReadLine(ImgResDsc& dsc, const Point& start, int16_t len, uint8_t* buf) override -+ { -+ return RetCode::FAIL; -+ } -+ -+private: -+ FILE* fp_; -+ png_structp png_; -+ png_infop info_; -+ -+ PngImgDecoder() : fp_(nullptr), png_(nullptr), info_(nullptr) {}; -+ virtual ~PngImgDecoder() {}; -+ -+ RetCode CreateDecoder(void); -+ void DestroyDecoder(void); -+ -+ PngImgDecoder(const PngImgDecoder&) = delete; -+ PngImgDecoder& operator=(const PngImgDecoder&) = delete; -+ PngImgDecoder(PngImgDecoder&&) = delete; -+ PngImgDecoder& operator=(PngImgDecoder&&) = delete; -+ void UpdateInfo(void); -+}; -+} -+#endif -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/interfaces/innerkits/engines/gfx/gfx_engine_manager.h ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/interfaces/innerkits/engines/gfx/gfx_engine_manager.h ---- ohos/foundation/arkui/ui_lite/interfaces/innerkits/engines/gfx/gfx_engine_manager.h 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/interfaces/innerkits/engines/gfx/gfx_engine_manager.h 2025-09-22 12:34:40.976729447 +0800 -@@ -69,6 +69,9 @@ struct ArcInfo { - struct TransformDataInfo { - ImageHeader header; - const uint8_t* data; -+#if defined(ENABLE_GFX_ENGINES) && ENABLE_GFX_ENGINES -+ const uint8_t* phyAddr; -+#endif - uint8_t pxSize; - BlurLevel blurLevel; - TransformAlgorithm algorithm; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/arkui/ui_lite/interfaces/kits/common/image.h ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/interfaces/kits/common/image.h ---- ohos/foundation/arkui/ui_lite/interfaces/kits/common/image.h 2025-05-03 17:56:01.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/arkui/ui_lite/interfaces/kits/common/image.h 2025-09-22 12:34:40.976729447 +0800 -@@ -167,14 +167,15 @@ private: - bool mallocFlag_; - bool SetLiteSrc(const char* src); - bool SetStandardSrc(const char* src); --#if ENABLE_JPEG -+#if ENABLE_JPEG && (!CACHE_JPEG_AND_PNG) - bool SetJPEGSrc(const char* src); - #endif --#if ENABLE_PNG -+#if ENABLE_PNG && (!CACHE_JPEG_AND_PNG) - bool SetPNGSrc(const char* src); - #endif - #if ENABLE_JPEG || ENABLE_PNG -- ImageType CheckImgType(const char* src); -+ friend class CacheManager; -+ static ImageType CheckImgType(const char* src); - #endif - bool IsImgValid(const char* suffix) - { diff --git a/vendor/rkh/rkh_patch/foundation/graphic_graphic_utils_lite.patch b/vendor/rkh/rkh_patch/foundation/graphic_graphic_utils_lite.patch index 4c4d146e55be94535434a65fdc8f4fe5b54200bc..7644ed9267e7c32ec161a4d50af2ca94a3912e11 100644 --- a/vendor/rkh/rkh_patch/foundation/graphic_graphic_utils_lite.patch +++ b/vendor/rkh/rkh_patch/foundation/graphic_graphic_utils_lite.patch @@ -1,299 +1,7 @@ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/BUILD.gn ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/BUILD.gn ---- ohos/foundation/graphic/graphic_utils_lite/BUILD.gn 2025-05-03 17:56:19.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/BUILD.gn 2025-09-22 12:35:38.848604401 +0800 -@@ -74,6 +74,7 @@ lite_library("graphic_utils_lite") { - "frameworks/hal_cpu.cpp", - "frameworks/hal_tick.cpp", - "frameworks/mem_api.cpp", -+ "frameworks/mem_custom.cpp", - "frameworks/pixel_format_utils.cpp", - "frameworks/style.cpp", - "frameworks/trans_affine.cpp", -@@ -86,7 +87,10 @@ lite_library("graphic_utils_lite") { - public_deps = - [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static" ] - } else { -- deps = [ "//third_party/bounds_checking_function:libsec_shared" ] -+ deps = [ -+ ":graphic_hals", -+ "//third_party/bounds_checking_function:libsec_shared" -+ ] - public_deps = - [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared" ] - } -@@ -97,6 +101,8 @@ config("graphic_utils_public_config") { - "interfaces/innerkits", - "interfaces/kits", - "$product_path/graphic_config", -+ "//drivers/peripheral/base", -+ "//drivers/peripheral/display/interfaces/include", - ] - - defines += [ -@@ -132,12 +138,13 @@ if (ohos_kernel_type != "liteos_m") { - sources = [ - "frameworks/hals/gfx_engines.cpp", - "frameworks/hals/hi_fbdev.cpp", -+ "frameworks/hals/gralloc_engines.cpp" - ] - include_dirs = - [ "//foundation/window/window_manager_lite/interfaces/innerkits" ] - deps = [ -- ":utils_lite", - "//drivers/peripheral/display/hal:hdi_display", -+ "//third_party/bounds_checking_function:libsec_shared" - ] - public_configs = [ ":graphic_hals_public_config" ] - ldflags = [ -@@ -150,6 +157,7 @@ if (ohos_kernel_type != "liteos_m") { - - config("graphic_hals_public_config") { - include_dirs = [ -+ "interfaces/kits", - "interfaces/innerkits", - "//drivers/peripheral/base", - "//drivers/peripheral/display/interfaces/include", -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/frameworks/hals/gfx_engines.cpp ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/frameworks/hals/gfx_engines.cpp ---- ohos/foundation/graphic/graphic_utils_lite/frameworks/hals/gfx_engines.cpp 2025-05-03 17:56:19.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/frameworks/hals/gfx_engines.cpp 2025-09-22 12:35:38.848604401 +0800 -@@ -16,6 +16,7 @@ - #include "hals/gfx_engines.h" - - #include "gfx_utils/graphic_log.h" -+#include "securec.h" - - namespace OHOS { - struct { -@@ -161,4 +162,43 @@ bool GfxEngines::GfxBlit(const LiteSurfa - } - return true; - } -+ -+bool GfxEngines::GfxBlitWithOpt(const LiteSurfaceData& srcSurfaceData, -+ const Rect& srcRect, -+ const LiteSurfaceData& dstSurfaceData, -+ const Rect& dstRect, -+ uint8_t opa) -+{ -+ if (gfxFuncs_ == nullptr || srcSurfaceData.phyAddr == nullptr || dstSurfaceData.phyAddr == nullptr) { -+ return false; -+ } -+ ISurface srcSurface = {}; -+ ISurface dstSurface = {}; -+ if (Convert2ISurface(srcSurfaceData, srcSurface) == false) { -+ return false; -+ } -+ if (Convert2ISurface(dstSurfaceData, dstSurface) == false) { -+ return false; -+ } -+ IRect srcIRect = {}; -+ IRect dstIRect = {}; -+ Convert2IRect(srcRect, srcIRect); -+ Convert2IRect(dstRect, dstIRect); -+ GfxOpt opt; -+ if (memset_s(&opt, sizeof(GfxOpt), 0, sizeof(GfxOpt)) != EOK) { -+ return false; -+ } -+ opt.enPixelAlpha = true; -+ opt.blendType = BLEND_SRCOVER; -+ opt.enableScale = true; -+ opt.enGlobalAlpha = true; -+ opt.globalAlpha = opa; -+ -+ if (gfxFuncs_->Blit(&srcSurface, &srcIRect, &dstSurface, &dstIRect, &opt) == DISPLAY_FAILURE) { -+ GRAPHIC_LOGW("HW blit failed, and retry SW blit."); -+ return false; -+ } -+ return true; -+} -+ - } // namespace OHOS -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/frameworks/hals/gralloc_engines.cpp ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/frameworks/hals/gralloc_engines.cpp ---- ohos/foundation/graphic/graphic_utils_lite/frameworks/hals/gralloc_engines.cpp 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/frameworks/hals/gralloc_engines.cpp 2025-09-22 12:35:38.848604401 +0800 -@@ -0,0 +1,81 @@ -+/* -+ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. -+ * 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. -+ */ -+ -+#include "hals/gralloc_engines.h" -+#include -+#include "display_type.h" -+#include "gfx_utils/graphic_log.h" -+#include "securec.h" -+namespace OHOS { -+static std::map buffers; -+ -+GrallocEngines* GrallocEngines::GetInstance() -+{ -+ static GrallocEngines instance; -+ return &instance; -+} -+ -+bool GrallocEngines::Init() -+{ -+ if (grallocFuncs_ != nullptr) { -+ GRAPHIC_LOGI("GrallocEngines has init succeed."); -+ return true; -+ } -+#ifdef ENABLE_GFX_ENGINES -+ if (GrallocInitialize(&grallocFuncs_) != DISPLAY_SUCCESS) { -+ return false; -+ } -+#endif -+ return true; -+} -+ -+bool GrallocEngines::AllocBuffer(const AllocInfo& info, GrallocBuffer& buffer) -+{ -+ if (grallocFuncs_ == nullptr) { -+ GRAPHIC_LOGE("GrallocEngines not init!"); -+ return false; -+ } -+ BufferHandle* bufferHandle = nullptr; -+ if (grallocFuncs_->AllocMem(&info, &bufferHandle) != DISPLAY_SUCCESS) { -+ return false; -+ } -+ buffers.insert(std::make_pair(reinterpret_cast(bufferHandle->virAddr), bufferHandle)); -+ buffer.phyAddr = bufferHandle->phyAddr; -+ buffer.virAddr = bufferHandle->virAddr; -+ return true; -+} -+ -+void GrallocEngines::FreeBuffer(const uint8_t* virAddr) -+{ -+ if (grallocFuncs_ == nullptr) { -+ GRAPHIC_LOGE("GrallocEngines not init!"); -+ return; -+ } -+ -+ if (virAddr == nullptr) { -+ return; -+ } -+ -+ uint64_t addr = reinterpret_cast(virAddr); -+ auto iter = buffers.find(addr); -+ if (iter != buffers.end()) { -+ BufferHandle* handle = iter->second; -+ if (handle != nullptr) { -+ buffers.erase(iter); -+ grallocFuncs_->FreeMem(handle); -+ } -+ } -+} -+} // namespace OHOS -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/frameworks/mem_api.cpp ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/frameworks/mem_api.cpp ---- ohos/foundation/graphic/graphic_utils_lite/frameworks/mem_api.cpp 2025-05-03 17:56:19.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/frameworks/mem_api.cpp 2025-09-22 12:35:38.848604401 +0800 -@@ -17,6 +17,7 @@ - #include "gfx_utils/common_macros.h" - - namespace OHOS { -+#ifndef IMG_CACHE_MEMORY_CUSTOM - UI_WEAK_SYMBOL void* ImageCacheMalloc(const ImageInfo& info) - { - return malloc(info.dataSize); -@@ -29,6 +30,7 @@ UI_WEAK_SYMBOL void ImageCacheFree(Image - info.data = nullptr; - return; - } -+#endif - - UI_WEAK_SYMBOL void* UIMalloc(uint32_t size) - { -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/frameworks/mem_custom.cpp ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/frameworks/mem_custom.cpp ---- ohos/foundation/graphic/graphic_utils_lite/frameworks/mem_custom.cpp 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/frameworks/mem_custom.cpp 2025-09-22 12:35:38.848604401 +0800 -@@ -0,0 +1,51 @@ -+/* -+ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. -+ * 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. -+ */ -+ -+#include "gfx_utils/mem_api.h" -+#include "gfx_utils/common_macros.h" -+#ifdef IMG_CACHE_MEMORY_CUSTOM -+#include "hals/gralloc_engines.h" -+#include "gfx_utils/graphic_log.h" -+ -+namespace OHOS { -+UI_WEAK_SYMBOL void* ImageCacheMalloc(const ImageInfo& info) -+{ -+ AllocInfo allocInfo; -+ allocInfo.expectedSize = info.dataSize; -+ allocInfo.usage = HBM_USE_ASSIGN_SIZE | HBM_USE_MEM_MMZ; -+ GrallocBuffer buffer; -+ if (!GrallocEngines::GetInstance()->AllocBuffer(allocInfo, buffer)) { -+ GRAPHIC_LOGE("AllocBuffer failed."); -+ return nullptr; -+ } -+ uint8_t** buf = const_cast(&info.phyAddr); -+ *buf = reinterpret_cast(buffer.phyAddr); -+ buf = const_cast(&info.data); -+ *buf = reinterpret_cast(buffer.virAddr); -+ return buffer.virAddr; -+} -+ -+UI_WEAK_SYMBOL void ImageCacheFree(ImageInfo& info) -+{ -+ if (info.data == nullptr) { -+ return; -+ } -+ GrallocEngines::GetInstance()->FreeBuffer(info.data); -+ info.phyAddr = nullptr; -+ info.data = nullptr; -+ return; -+} -+} -+#endif -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_config.h ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_config.h ---- ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_config.h 2025-05-03 17:56:19.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_config.h 2025-09-22 12:35:38.848604401 +0800 -@@ -257,12 +257,28 @@ namespace OHOS { - #ifndef ENABLE_PNG - #define ENABLE_PNG 1 - #endif -+ -+/** -+ * @brief Customize the memory area when loading image resources -+ */ -+#ifndef IMG_CACHE_MEMORY_CUSTOM -+#define IMG_CACHE_MEMORY_CUSTOM 1 -+#endif -+ -+/** -+ * @brief Cache the decoded content for Jpeg and Png image -+ */ -+#ifndef CACHE_JPEG_AND_PNG -+#define CACHE_JPEG_AND_PNG 1 -+#endif -+ - /** - * @brief ARM NEON ability, which is enabled by default on other platforms. - */ +diff -uparN '--exclude=.git' ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_config.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_config.h +--- ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_config.h 2025-12-08 09:52:44.415991015 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_config.h 2025-11-27 16:18:09.109957386 +0800 +@@ -278,6 +278,7 @@ namespace OHOS { #ifndef ENABLE_ARM_NEON #define ENABLE_ARM_NEON 1 #endif @@ -301,7 +9,7 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda /** * @brief Graphics rendering hardware acceleration, which is disabled by default on other platforms. */ -@@ -480,12 +496,12 @@ static constexpr uint8_t MAX_FONT_SEARCH +@@ -495,12 +496,12 @@ static constexpr uint8_t MAX_FONT_SEARCH /* Resolution width of a graphics display screen. The default value is 960. */ #ifndef HORIZONTAL_RESOLUTION @@ -316,9 +24,9 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda #endif #endif -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_neon_utils.h ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_neon_utils.h +diff -uparN '--exclude=.git' ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_neon_utils.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_neon_utils.h --- ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_neon_utils.h 2025-05-03 17:56:19.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_neon_utils.h 2025-09-22 11:12:05.265990858 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1127/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/graphic_neon_utils.h 2025-11-27 16:18:09.113957343 +0800 @@ -105,6 +105,18 @@ static void NeonMemcpy(void* dst, int32_ src = (uint8_t*)src + mod; } @@ -346,98 +54,3 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda } static inline void NeonBlendRGBA(uint8x8_t& r1, uint8x8_t& g1, uint8x8_t& b1, uint8x8_t& a1, -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/hals/gfx_engines.h ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/hals/gfx_engines.h ---- ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/hals/gfx_engines.h 2025-05-03 17:56:19.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/hals/gfx_engines.h 2025-09-22 12:35:38.848604401 +0800 -@@ -40,6 +40,12 @@ public: - const LiteSurfaceData& dstSurfaceData, - int16_t x, - int16_t y); -+ -+ bool GfxBlitWithOpt(const LiteSurfaceData& srcSurfaceData, -+ const Rect& srcRect, -+ const LiteSurfaceData& dstSurfaceData, -+ const Rect& dstRect, -+ uint8_t opa); - private: - GfxEngines() : gfxFuncs_(nullptr) {} - virtual ~GfxEngines() {} -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/hals/gralloc_engines.h ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/hals/gralloc_engines.h ---- ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/hals/gralloc_engines.h 1970-01-01 08:00:00.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/innerkits/hals/gralloc_engines.h 2025-09-22 12:35:38.848604401 +0800 -@@ -0,0 +1,44 @@ -+/* -+ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. -+ * 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. -+ */ -+ -+#ifndef GRAPHIC_LITE_GRALLOC_ENGINES_H -+#define GRAPHIC_LITE_GRALLOC_ENGINES_H -+#include "display_gralloc.h" -+#include "display_type.h" -+#ifndef __LITEOS_M__ -+#include "buffer_handle.h" -+#endif -+ -+namespace OHOS { -+typedef struct { -+ void* virAddr; -+ uint64_t phyAddr; -+} GrallocBuffer; -+ -+class GrallocEngines { -+public: -+ static GrallocEngines* GetInstance(); -+ bool Init(); -+ -+ bool AllocBuffer(const AllocInfo& info, GrallocBuffer& buffer); -+ void FreeBuffer(const uint8_t* virAddr); -+ -+private: -+ GrallocEngines() : grallocFuncs_(nullptr) {} -+ ~GrallocEngines() {} -+ GrallocFuncs* grallocFuncs_; -+}; -+} // end namespace -+#endif // GRAPHIC_LITE_GRALLOC_ENGINES_H -\ No newline at end of file -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/interfaces/kits/gfx_utils/image_info.h ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/kits/gfx_utils/image_info.h ---- ohos/foundation/graphic/graphic_utils_lite/interfaces/kits/gfx_utils/image_info.h 2025-05-03 17:56:19.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/interfaces/kits/gfx_utils/image_info.h 2025-09-22 12:35:38.848604401 +0800 -@@ -36,6 +36,7 @@ - #define GRAPHIC_LITE_IMAGE_INFO_H - - #include -+#include "graphic_config.h" - - namespace OHOS { - /** -@@ -63,6 +64,9 @@ struct ImageInfo { - uint32_t dataSize; - /** Pixel color data of pixelmap images */ - const uint8_t* data; -+#if IMG_CACHE_MEMORY_CUSTOM -+ const uint8_t* phyAddr; -+#endif - /** User-defined data */ - void* userData; - }; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/graphic/graphic_utils_lite/utils.gni ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/utils.gni ---- ohos/foundation/graphic/graphic_utils_lite/utils.gni 2025-05-03 17:56:19.000000000 +0800 -+++ ../../../../../hi3403_l1_0922/ohos/foundation/graphic/graphic_utils_lite/utils.gni 2025-09-22 12:35:38.852604391 +0800 -@@ -51,4 +51,5 @@ graphic_hals_include_dirs = [ - graphic_hals_sources = [ - "$GRAPHIC_GRAPHIC_UTILS_LITE_PATH/frameworks/hals/gfx_engines.cpp", - "$GRAPHIC_GRAPHIC_UTILS_LITE_PATH/frameworks/hals/hi_fbdev.cpp", -+ "$GRAPHIC_GRAPHIC_UTILS_LITE_PATH/frameworks/hals/gralloc_engines.cpp", - ] diff --git a/vendor/rkh/rkh_patch/foundation/multimedia_audio_lite.patch b/vendor/rkh/rkh_patch/foundation/multimedia_audio_lite.patch index 0eb5131ae911ef3a48d08b6c77feb8797d814e57..33daa5d989f1d8bffcf4107559b0f1e9b2f9e252 100644 --- a/vendor/rkh/rkh_patch/foundation/multimedia_audio_lite.patch +++ b/vendor/rkh/rkh_patch/foundation/multimedia_audio_lite.patch @@ -1,6 +1,6 @@ -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/bundle.json ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/bundle.json ---- ohos/foundation/multimedia/audio_lite/bundle.json 2025-05-03 17:56:21.000000000 +0800 -+++ ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/bundle.json 2025-11-03 15:44:54.170805293 +0800 +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/bundle.json /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/bundle.json +--- ohos/foundation/multimedia/audio_lite/bundle.json 2025-12-18 16:10:31.785162109 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/bundle.json 2025-12-18 09:10:45.135652986 +0800 @@ -34,4 +34,4 @@ "test": [] } @@ -8,21 +8,57 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda -} \ No newline at end of file +} -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.cpp ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.cpp ---- ohos/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.cpp 2025-11-06 16:22:22.623568756 +0800 -+++ ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.cpp 2025-11-06 17:02:00.179098532 +0800 -@@ -34,7 +34,9 @@ using namespace std; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.cpp +--- ohos/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.cpp 2025-12-18 16:10:31.785162109 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.cpp 2025-12-18 09:10:45.135652986 +0800 +@@ -34,7 +34,10 @@ using namespace std; namespace OHOS { namespace Audio { constexpr int32_t SURFACE_QUEUE_SIZE = 5; -constexpr int32_t SURFACE_SIZE = 4096; -+// add record buffer use surface buffer ++// hihopeos add record buffer use surface buffer +// when channel = 2, ai output buffer 2048*2 + 12 > 4096, surface size must be 8192 ++// constexpr int32_t SURFACE_SIZE = 4096; +constexpr int32_t SURFACE_SIZE = 8192; constexpr int32_t SURFACE_HEIGHT = 1; constexpr int32_t SURFACE_WIDTH = 8192; constexpr int32_t WAIT_SURFACE_BUFFER_US = 10; -@@ -359,12 +361,12 @@ bool AudioCapturer::AudioCapturerClient: +@@ -101,12 +104,13 @@ static int32_t ProxyCallbackFunc(void *o + case AUD_CAP_FUNC_GET_INFO: { + uint32_t size = 0; + ReadUint32(reply, &size); +- const char *bufferAdd = reinterpret_cast(ReadBuffer(reply, size_t(size))); +- if (bufferAdd == nullptr || size == 0) { ++ void *bufferAdd = (void*)ReadBuffer(reply, (size_t)size); ++ if (bufferAdd == nullptr || !size) { + MEDIA_INFO_LOG("Readbuffer info failed"); + return -1; + } +- DeserializeCaptureInfo(bufferAdd, static_cast(para->data)); ++ DeserializeCaptureInfo(static_cast(bufferAdd), ++ static_cast(para->data)); + break; + } + case AUD_CAP_FUNC_GET_MIN_FRAME_COUNT: +@@ -293,7 +297,7 @@ bool AudioCapturer::AudioCapturerClient: + return true; + } + +-std::string AudioCapturer::AudioCapturerClient::SerializeCaptureInfo(const AudioCapturerInfo &info) const ++std::string AudioCapturer::AudioCapturerClient::SerializeCaptureInfo(const AudioCapturerInfo &info) + { + std::stringstream ss; + ss << static_cast(info.inputSource) << ' ' +@@ -305,7 +309,7 @@ std::string AudioCapturer::AudioCapturer + << static_cast(info.streamType) << ' ' + << static_cast(info.bitWidth) << ' ' + << static_cast(info.deviceType); +- MEDIA_INFO_LOG("info.streamType = %d, info.bitWidth = %d, info.deviceType = %d", ++ MEDIA_ERR_LOG("info.streamType = %d, info.bitWidth = %d, info.deviceType = %d", + info.streamType, info.bitWidth, info.deviceType); + return ss.str(); + } +@@ -359,12 +363,12 @@ bool AudioCapturer::AudioCapturerClient: uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); CallBackPara para = {.funcId = AUD_CAP_FUNC_START, .ret = MEDIA_IPC_FAILED}; @@ -37,7 +73,7 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda int32_t ret = proxy_->Invoke(proxy_, AUD_CAP_FUNC_START, &io, ¶, ProxyCallbackFunc); if (ret) { MEDIA_ERR_LOG("Start failed, ret=%d", ret); -@@ -380,7 +382,7 @@ bool AudioCapturer::AudioCapturerClient: +@@ -380,7 +384,7 @@ bool AudioCapturer::AudioCapturerClient: uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); CallBackPara para = {.funcId = AUD_CAP_FUNC_STOP, .ret = MEDIA_IPC_FAILED}; @@ -46,7 +82,7 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda if (proxy_ == nullptr) { MEDIA_ERR_LOG("Stop failed, proxy_ value is nullptr"); return false; -@@ -401,7 +403,7 @@ bool AudioCapturer::AudioCapturerClient: +@@ -401,7 +405,7 @@ bool AudioCapturer::AudioCapturerClient: uint8_t tmpData[DEFAULT_IPC_SIZE]; IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); CallBackPara para = {.funcId = AUD_CAP_FUNC_RELEASE, .ret = MEDIA_IPC_FAILED}; @@ -55,9 +91,80 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda if (proxy_ == nullptr) { MEDIA_ERR_LOG("Release failed, proxy_ value is nullptr"); return false; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/frameworks/BUILD.gn ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/frameworks/BUILD.gn ---- ohos/foundation/multimedia/audio_lite/frameworks/BUILD.gn 2025-11-06 16:22:22.623568756 +0800 -+++ ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/frameworks/BUILD.gn 2025-11-03 15:44:54.174805226 +0800 +@@ -470,7 +474,6 @@ IClientProxy *AudioCapturer::AudioCaptur + int32_t AudioCapturer::AudioCapturerClient::AudioCapturerCallback(uint32_t code, IpcIo *data, + IpcIo *reply, MessageOption option) + { +- (void)reply; + auto playerCallback = static_cast(option.args); + if (playerCallback == nullptr) { + MEDIA_ERR_LOG("call back error, playerCallback is null"); +@@ -483,8 +486,8 @@ int32_t AudioCapturer::AudioCapturerClie + ReadUint32(data, &dhId); + uint32_t size = 0; + ReadUint32(data, &size); +- const char *bufferAdd = reinterpret_cast(ReadBuffer(data, size_t(size))); +- if (bufferAdd == nullptr || size == 0) { ++ void *bufferAdd = (void *)ReadBuffer(data, (size_t)size); ++ if (bufferAdd == nullptr || !size) { + MEDIA_INFO_LOG("Readbuffer info failed"); + return -1; + } +@@ -494,9 +497,9 @@ int32_t AudioCapturer::AudioCapturerClie + ReadInt32(data, &connectStatus); + AudioDeviceInfo info; + info.dhId = dhId; +- info.deviceName = std::string(bufferAdd); +- info.deviceType = AudioSystemDeviceType(deviceType); +- info.connectStatus = DeviceConnectStatus(connectStatus); ++ info.deviceName = std::string((char *)bufferAdd); ++ info.deviceType = (AudioSystemDeviceType)deviceType; ++ info.connectStatus = (DeviceConnectStatus)connectStatus; + playerCallback->OnDeviceChange(info); + MEDIA_INFO_LOG("AudioCapturerClient AudioCapturerCallback, ON_DEVICE_CHANGED success\n"); + break; +@@ -514,15 +517,14 @@ int32_t AudioCapturer::AudioCapturerClie + return 0; + } + +-void AudioCapturer::AudioCapturerClient::SetDeviceChangeCallback( +- const std::shared_ptr &callback) ++void AudioCapturer::AudioCapturerClient::SetDeviceChangeCallback(const std::shared_ptr &callback) + { + if (sid_ == nullptr) { + sid_ = new SvcIdentity(); + } + callback_ = callback; + objectStub_.func = AudioCapturerCallback; +- objectStub_.args = callback_.get(); ++ objectStub_.args = (void *)callback_.get(); + objectStub_.isRemote = false; + sid_->handle = IPC_INVALID_HANDLE; + sid_->token = SERVICE_TYPE_ANONYMOUS; +@@ -536,7 +538,7 @@ void AudioCapturer::AudioCapturerClient: + } + CallBackPara para = {}; + para.funcId = AUD_CAP_FUNC_SET_DEVICE_CHANGE_CALLBACK; +- int32_t ans = proxy_->Invoke(proxy_, AUD_CAP_FUNC_SET_DEVICE_CHANGE_CALLBACK, &io, ¶, ProxyCallbackFunc); ++ uint32_t ans = proxy_->Invoke(proxy_, AUD_CAP_FUNC_SET_DEVICE_CHANGE_CALLBACK, &io, ¶, ProxyCallbackFunc); + if (ans != 0) { + MEDIA_ERR_LOG("SetDeviceChangeCallback : Invoke failed, ret=%u\n", ans); + } +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.h +--- ohos/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.h 2025-12-18 09:10:10.567998265 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/frameworks/binder/audio_capturer_client.h 2025-12-18 09:10:45.135652986 +0800 +@@ -56,7 +56,7 @@ private: + int32_t InitSurface(void); + int32_t DeleteSurface(void); + void ReleaseAllBuffer(); +- std::string SerializeCaptureInfo(const AudioCapturerInfo &info) const; ++ std::string SerializeCaptureInfo(const AudioCapturerInfo &info); + SvcIdentity *sid_ = nullptr; + IpcObjectStub objectStub_; + IClientProxy *proxy_ = nullptr; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/frameworks/BUILD.gn /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/frameworks/BUILD.gn +--- ohos/foundation/multimedia/audio_lite/frameworks/BUILD.gn 2025-12-18 16:10:31.785162109 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/frameworks/BUILD.gn 2025-12-18 09:10:45.135652986 +0800 @@ -54,6 +54,8 @@ shared_library("audio_capturer_lite") { public_deps = [ "//foundation/multimedia/media_utils_lite:media_common", @@ -67,20 +174,425 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda ] } -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_encoder/audio_encoder.cpp ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/services/impl/audio_encoder/audio_encoder.cpp ---- ohos/foundation/multimedia/audio_lite/services/impl/audio_encoder/audio_encoder.cpp 2025-11-06 16:22:22.627568718 +0800 -+++ ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/services/impl/audio_encoder/audio_encoder.cpp 2025-11-06 17:02:00.179098532 +0800 -@@ -203,6 +203,7 @@ int32_t AudioEncoder::BindSource(uint32_ +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/frameworks/passthrough/audio_capturer_client.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/frameworks/passthrough/audio_capturer_client.cpp +--- ohos/foundation/multimedia/audio_lite/frameworks/passthrough/audio_capturer_client.cpp 2025-12-18 09:10:10.567998265 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/frameworks/passthrough/audio_capturer_client.cpp 2025-12-18 09:10:45.135652986 +0800 +@@ -66,9 +66,9 @@ bool AudioCapturer::AudioCapturerClient: + return impl_->GetTimestamp(timestamp, base); + } + +-void AudioCapturer::AudioCapturerClient::SetDeviceChangeCallback( +- const std::shared_ptr &callback) ++void AudioCapturer::AudioCapturerClient::SetDeviceChangeCallback(const std::shared_ptr &callback) + { ++ + } + + int32_t AudioCapturer::AudioCapturerClient::SetCapturerInfo(const AudioCapturerInfo &info) +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/interfaces/kits/audio_capturer.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/interfaces/kits/audio_capturer.h +--- ohos/foundation/multimedia/audio_lite/interfaces/kits/audio_capturer.h 2025-12-18 09:10:10.567998265 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/interfaces/kits/audio_capturer.h 2025-12-18 09:10:45.135652986 +0800 +@@ -44,7 +44,7 @@ + + #include "media_errors.h" + #include "media_info.h" +-#include "audio_manager_device_change_callback.h" ++#include "audio_manager_callback.h" + + namespace OHOS { + namespace Audio { +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/interfaces/kits/audio_device_manager.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/interfaces/kits/audio_device_manager.h +--- ohos/foundation/multimedia/audio_lite/interfaces/kits/audio_device_manager.h 2025-12-18 09:10:10.567998265 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/interfaces/kits/audio_device_manager.h 2025-12-18 09:10:45.135652986 +0800 +@@ -15,6 +15,7 @@ + #ifndef AUDIO_SYSTEM_MANAGER_H + #define AUDIO_SYSTEM_MANAGER_H + ++#include + #include + #include + #include +@@ -29,8 +30,8 @@ namespace OHOS { + ~AudioDeviceManager(); + static AudioDeviceManager *GetInstance(); + std::vector GetAllConnectDevices(); +- int32_t AddDevice(const AudioDeviceInfo &deviceInfo); +- int32_t RemoveDevice(const AudioDeviceInfo &deviceInfo); ++ int32_t AddDevice(const AudioDeviceInfo &deviceinfo); ++ int32_t RemoveDevice(const AudioDeviceInfo &deviceinfo); + private: + AudioDeviceManager(); + std::vector allDevices_; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/interfaces/kits/audio_manager_callback.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/interfaces/kits/audio_manager_callback.h +--- ohos/foundation/multimedia/audio_lite/interfaces/kits/audio_manager_callback.h 1970-01-01 08:00:00.000000000 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/interfaces/kits/audio_manager_callback.h 2025-12-18 09:10:45.135652986 +0800 +@@ -0,0 +1,43 @@ ++/* ++ * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. ++ * 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. ++ */ ++ ++#ifndef AUDIO_MANAGER_CALL_BACK_H ++#define AUDIO_MANAGER_CALL_BACK_H ++ ++#include "media_info.h" ++namespace OHOS { ++ namespace Audio { ++ class AudioManagerDeviceChangeCallback { ++ public: ++ virtual ~AudioManagerDeviceChangeCallback() = default; ++ /** ++ * Called when an interrupt is received. ++ * ++ * @param deviceChangeAction Indicates the DeviceChangeAction information needed by client. ++ * For details, refer DeviceChangeAction struct ++ * @since 8 ++ */ ++ virtual void OnDeviceChange(const AudioDeviceInfo &deviceInfo) = 0; ++ virtual void OnReadDataFailed() = 0; ++ }; ++ ++ typedef enum { ++ ON_DEVICE_CHANGED, ++ ON_READ_DATA_FAILED, ++ } AudioCapturerClientCall; ++ } ++} ++ ++#endif +\ No newline at end of file +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/interfaces/kits/audio_manager_device_change_callback.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/interfaces/kits/audio_manager_device_change_callback.h +--- ohos/foundation/multimedia/audio_lite/interfaces/kits/audio_manager_device_change_callback.h 2025-12-18 09:10:10.567998265 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/interfaces/kits/audio_manager_device_change_callback.h 1970-01-01 08:00:00.000000000 +0800 +@@ -1,42 +0,0 @@ +-/* +- * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd. +- * 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. +- */ +- +-#ifndef AUDIO_MANAGER_CALL_BACK_H +-#define AUDIO_MANAGER_CALL_BACK_H +- +-#include "media_info.h" +-namespace OHOS { +- namespace Audio { +- class AudioManagerDeviceChangeCallback { +- public: +- virtual ~AudioManagerDeviceChangeCallback() = default; +- /** +- * Called when an interrupt is received. +- * +- * @param deviceChangeAction Indicates the DeviceChangeAction information needed by client. +- * For details, refer DeviceChangeAction struct +- * @since 8 +- */ +- virtual void OnDeviceChange(const AudioDeviceInfo &deviceInfo) = 0; +- virtual void OnReadDataFailed() = 0; +- }; +- enum AudioCapturerClientCall { +- ON_DEVICE_CHANGED, +- ON_READ_DATA_FAILED, +- }; +- } +-} +- +-#endif +\ No newline at end of file +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_capturer_impl.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_capturer_impl.cpp +--- ohos/foundation/multimedia/audio_lite/services/impl/audio_capturer_impl.cpp 2025-12-18 09:10:10.567998265 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_capturer_impl.cpp 2025-12-18 09:10:45.139652947 +0800 +@@ -247,7 +247,8 @@ int32_t AudioCapturerImpl::Read(uint8_t + readLen = audioSource->ReadFrame(frame, isBlockingRead); + if (readLen == 0) { + return ERR_INVALID_READ; +- } else if (readLen == ERR_INVALID_READ) { ++ } ++ else if (readLen == ERR_INVALID_READ) { + MEDIA_ERR_LOG("audioSource_ ReadFrame fail,ret:0x%x", readLen); + return ERR_INVALID_READ; + } +@@ -302,6 +303,7 @@ std::shared_ptr AudioCaptur + { + if (info_.deviceType == AUDIO_DEVICE_MIC_LOCAL) { + return audioSourceLocal_; ++ + } + if (info_.deviceType == AUDIO_DEVICE_MIC_VIRTUAL) { + return audioSourceVirtual_; +@@ -356,10 +358,8 @@ bool AudioCapturerImpl::Release() + } + void AudioCapturerImpl::SetDeviceChangeCallback(std::shared_ptr callback) + { +- std::shared_ptr callbackImp = +- std::make_shared(callback); +- OHOS::HDI::DistributedAudio::Audio::V1_0::AudioManagerInterfaceImpl::GetAudioManager()-> +- SetDeviceChangeCallback(callbackImp); ++ std::shared_ptr callbackImp = std::make_shared(callback); ++ OHOS::HDI::DistributedAudio::Audio::V1_0::AudioManagerInterfaceImpl::GetAudioManager()->SetDeviceChangeCallback(callbackImp); + MEDIA_INFO_LOG("set AudioSourceVirtual callback success!"); + } + } // namespace Audio +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_capturer_impl.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_capturer_impl.h +--- ohos/foundation/multimedia/audio_lite/services/impl/audio_capturer_impl.h 2025-12-18 09:10:10.571998225 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_capturer_impl.h 2025-12-18 09:10:45.139652947 +0800 +@@ -20,6 +20,7 @@ + #include + #include "audio_capturer.h" + #include "media_info.h" ++ + namespace OHOS { + namespace Audio { + enum AudioChannel { +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_encoder/audio_encoder.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_encoder/audio_encoder.cpp +--- ohos/foundation/multimedia/audio_lite/services/impl/audio_encoder/audio_encoder.cpp 2025-12-18 16:10:31.785162109 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_encoder/audio_encoder.cpp 2025-12-18 09:10:45.139652947 +0800 +@@ -119,7 +119,7 @@ static AudioSoundMode ConvertSoundMode(u + } + } + +-void AudioEncoder::SetEncAttrValue(const AudioEncodeConfig &config) ++void AudioEncoder::setEncAttrValue(const AudioEncodeConfig &config) + { + uint32_t paramIndex = 0; + domainKind_ = AUDIO_ENCODER; +@@ -173,7 +173,7 @@ int32_t AudioEncoder::InitAudioEncoderAt + MEDIA_ERR_LOG("audioFormat:%d is not support sampleRate:%d", config.audioFormat, config.sampleRate); + return ERR_INVALID_PARAM; + } +- SetEncAttrValue(config); ++ setEncAttrValue(config); + + return SUCCESS; + } +@@ -187,6 +187,14 @@ int32_t AudioEncoder::Initialize(const A + } + const char *audioEncName = "codec.aac.hardware.encoder"; + ret = CodecCreate(audioEncName, encAttr_, AUDIO_ENC_PARAM_NUM, &encHandle_); ++ // callstack info start ++ // static td_s32 CreateHandler(const Param *attr, int len, CodecType type, CodecCtx *ctx) ++ // int32_t CodecChannelCreate(void **channelCtx, CodecType type, const Param *attr, int len) ++ // chanCtx->pluginCommon->pfnCreate(&chanCtx->pluginHandle, attr, len); ++ // static td_s32 NATIVE_AENC_Create(void **aencHdl, const Param *attr, int len) ++ // static td_s32 FillAencAttribute(const Param *attrSrc, int lenSrc, AvAenAttr *attrDst) ++ // static td_s32 AencCreateChn(const AvAenAttr *aenAttr, const void *priv, ot_aenc_chn aencChn) ++ // callstack info end + if (ret != SUCCESS) { + MEDIA_ERR_LOG("CodecCreate failed:0x%x", ret); + return ret; +@@ -203,6 +211,15 @@ int32_t AudioEncoder::BindSource(uint32_ params[0].val = reinterpret_cast(&deviceId); params[0].size = sizeof(uint32_t); int32_t ret = CodecSetParameter(encHandle_, params, sizeof(params) / sizeof(params[0])); ++ // for ai bind to aenc ++ // int32_t SetDevice(CodecBufferChannel *channelCtx, CodecType type, DirectionType dirType, ++ // const Param *params); ++ ++ // MEDIA_HAL_UNUSED(dirType); ++ // MEDIA_HAL_UNUSED(type); + ++ // static td_s32 NATIVE_AENC_SetParameter(void *aencHdl, const Param *param) ++ // callstack info end.. if (ret != SUCCESS) { MEDIA_ERR_LOG("CodecSetDevice:0x%x", ret); return ret; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/local/audio_source_local.cpp ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/local/audio_source_local.cpp ---- ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/local/audio_source_local.cpp 2025-11-06 16:22:22.627568718 +0800 -+++ ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/local/audio_source_local.cpp 2025-11-06 17:02:00.179098532 +0800 +@@ -269,7 +286,7 @@ int32_t AudioEncoder::ReadStream(AudioSt + MEDIA_ERR_LOG("memcpy_s failed, timeStamp:%lld, retCopy:0x%x", outInfo.timeStamp, retCopy); + return ERR_INVALID_OPERATION; + } else { +- readLen = int(outInfo.buffers[0].length); ++ readLen = outInfo.buffers[0].length; + } + stream.timeStamp = outInfo.timeStamp; + (void)CodecQueueOutput(encHandle_, &outInfo, timeoutMs, -1); +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_encoder/include/audio_encoder.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_encoder/include/audio_encoder.h +--- ohos/foundation/multimedia/audio_lite/services/impl/audio_encoder/include/audio_encoder.h 2025-12-18 09:10:10.571998225 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_encoder/include/audio_encoder.h 2025-12-18 09:10:45.139652947 +0800 +@@ -117,7 +117,7 @@ public: + + private: + int32_t InitAudioEncoderAttr(const AudioEncodeConfig &config); +- void SetEncAttrValue(const AudioEncodeConfig &config); ++ void setEncAttrValue(const AudioEncodeConfig &config); + + private: + bool initialized_; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_source/include/local/audio_source_local.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/include/local/audio_source_local.h +--- ohos/foundation/multimedia/audio_lite/services/impl/audio_source/include/local/audio_source_local.h 2025-12-18 09:10:10.571998225 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/include/local/audio_source_local.h 2025-12-18 09:10:45.139652947 +0800 +@@ -97,7 +97,7 @@ public: + int32_t Release() override; + + private: +- int32_t InitCheck() const; ++ int32_t InitCheck(); + + private: + bool initialized_; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_source/include/virtual/audio_source_virtual.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/include/virtual/audio_source_virtual.h +--- ohos/foundation/multimedia/audio_lite/services/impl/audio_source/include/virtual/audio_source_virtual.h 2025-12-18 09:10:10.571998225 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/include/virtual/audio_source_virtual.h 2025-12-18 09:10:45.139652947 +0800 +@@ -16,16 +16,17 @@ + #ifndef FRAMEWORKS_AUDIO_SOURCE_INCLUDE_AUDIO_VIRTUAL_H_ + #define FRAMEWORKS_AUDIO_SOURCE_INCLUDE_AUDIO_VIRTUAL_H_ + ++#include + #include + #include +-#include ++#include + #include + + #include "audio_source.h" + #include "iaudio_capture.h" + #include "iaudio_adapter.h" + #include "iaudio_manager.h" +-#include "audio_manager_device_change_callback.h" ++#include "audio_manager_callback.h" + #include "iaudio_device_callback.h" + + namespace OHOS { +@@ -33,13 +34,9 @@ namespace Audio { + using namespace OHOS::HDI::DistributedAudio::Audio::V1_0; + class AudioManagerDeviceChangeCallbackImpl : public IAudioManagerDeviceChangeCallback { + public: +- explicit AudioManagerDeviceChangeCallbackImpl(std::shared_ptr callback) +- { +- callback_ = callback; +- } ++ AudioManagerDeviceChangeCallbackImpl(std::shared_ptr callback) { callback_ = callback; } + ~AudioManagerDeviceChangeCallbackImpl() override {} +- void OnDeviceChange(const AudioDeviceInfo &deviceInfo) override +- { ++ void OnDeviceChange(const AudioDeviceInfo &deviceInfo) override { + if (callback_ != nullptr) { + callback_->OnDeviceChange(deviceInfo); + } +@@ -50,8 +47,8 @@ private: + + class AudioSourceVirtual : public AudioSource { + public: +- explicit AudioSourceVirtual(std::string deviceId); +- ~AudioSourceVirtual() override; ++ AudioSourceVirtual(std::string deviceId); ++ ~AudioSourceVirtual(); + + /** + * Enumerates currently supported devices by audio source type. +@@ -60,14 +57,14 @@ public: + * @param devices holds an array of satisfied audio device description, including name and identity. + * @return Returns SUCCESS if success, other values otherwise. + */ +- int32_t EnumDeviceBySourceType(AudioSourceType inputSource, std::vector &devices) override; ++ int32_t EnumDeviceBySourceType(AudioSourceType inputSource, std::vector &devices); + + /** + * Obtains the frame count (in BytesPerSample) required in the current conditions. + * + * @return Returns the frame count (in BytesPerSample); returns {@code -1} if an exception occurs. + */ +- uint64_t GetFrameCount() override; ++ uint64_t GetFrameCount(); + + /** + * Initializes the audio source according to a specific configuration. +@@ -75,7 +72,7 @@ public: + * @param config a configuration of audio source. + * @return Returns SUCCESS if success, other values otherwise. + */ +- int32_t Initialize(const AudioSourceConfig &config) override; ++ int32_t Initialize(const AudioSourceConfig &config); + + /** + * Sets input device's identity when switching device. +@@ -83,7 +80,7 @@ public: + * @param deviceId identity to set. + * @return Returns SUCCESS if set successfully, other values otherwise. + */ +- int32_t SetInputDevice(uint32_t deviceId) override; ++ int32_t SetInputDevice(uint32_t deviceId); + + /** + * Gets current device's identity. +@@ -91,14 +88,14 @@ public: + * @param deviceId holds the identity of current device, if success. + * @return Returns SUCCESS if success, other values otherwise. + */ +- int32_t GetCurrentDeviceId(uint32_t &deviceId) override; ++ int32_t GetCurrentDeviceId(uint32_t &deviceId); + + /** + * Starts audio source. + * + * @return Returns SUCCESS if success, other values otherwise. + */ +- int32_t Start() override; ++ int32_t Start(); + + /** + * +@@ -108,24 +105,24 @@ public: + * @param isBlockingRead reading mode. + * @return Returns size of data actually read. + */ +- int32_t ReadFrame(AudioFrame &frame, bool isBlockingRead) override; ++ int32_t ReadFrame(AudioFrame &frame, bool isBlockingRead); + + /** + * Stops audio source. + * + * @return Returns SUCCESS if success, other values otherwise. + */ +- int32_t Stop() override; ++ int32_t Stop(); + + /** + * release. + */ +- int32_t Release() override; ++ int32_t Release(); + + void SetDeviceChangeCallback(const std::shared_ptr &callback); + + private: +- int32_t InitCheck() const; ++ int32_t InitCheck(); + private: + IAudioManager *audioManager_ = nullptr; + bool initialized_; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/audio_source.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/src/audio_source.cpp +--- ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/audio_source.cpp 2025-12-18 09:10:10.571998225 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/src/audio_source.cpp 2025-12-18 09:10:45.139652947 +0800 +@@ -22,6 +22,7 @@ namespace Audio { + + AudioSource::AudioSource() + { ++ + } + + AudioSource::~AudioSource() +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/local/audio_source_local.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/src/local/audio_source_local.cpp +--- ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/local/audio_source_local.cpp 2025-12-18 16:10:31.785162109 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/src/local/audio_source_local.cpp 2025-12-18 09:10:45.139652947 +0800 @@ -34,7 +34,6 @@ static AudioManager *g_audioManager = nu AudioSourceLocal::AudioSourceLocal() : initialized_(false), @@ -100,7 +612,7 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda - if (memcpy_s(&capturePort_, sizeof(struct AudioPort), - &desc->ports[port], sizeof(struct AudioPort)) != 0) { - MEDIA_WARNING_LOG("memcpy_s capturePort_ failed"); -+ if(strcmp(desc->adapterName, "Primary") == 0) { // if use USB audio, "Primary"->"USB" ++ if(strcmp(desc->adapterName, "Primary") == 0) { // USB + for (int port = 0; (desc != nullptr && port < static_cast(desc->portNum)); port++) { + if (desc->ports[port].dir == PORT_IN && + !(g_audioManager->LoadAdapter(g_audioManager, desc, &audioAdapter_))) { @@ -115,15 +627,36 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda } } } -@@ -169,6 +170,7 @@ int32_t AudioSourceLocal::Initialize(con - AUDIO_RETURN_VAL_IF_NULL(audioAdapter_); +@@ -66,6 +67,11 @@ AudioSourceLocal::AudioSourceLocal() + + AudioSourceLocal::~AudioSourceLocal() + { ++ MEDIA_DEBUG_LOG("in"); ++ if (initialized_) { ++ Release(); ++ } ++ + if (audioAdapter_ != nullptr) { + MEDIA_INFO_LOG("UnloadModule audioAdapter_"); + if (g_audioManager == nullptr) { +@@ -78,7 +84,7 @@ AudioSourceLocal::~AudioSourceLocal() + } + } + +-int32_t AudioSourceLocal::InitCheck() const ++int32_t AudioSourceLocal::InitCheck() + { + if (!initialized_) { + MEDIA_ERR_LOG("not initialized"); +@@ -170,6 +176,7 @@ int32_t AudioSourceLocal::Initialize(con MEDIA_INFO_LOG("deviceId:0x%x config.sampleRate:%d", config.deviceId, config.sampleRate); AudioDeviceDescriptor desc; -+ // if use USB audio, "PIN_IN_MIC"->"PIN_IN_MIC" desc.pins = PIN_IN_MIC; ++ // desc.pins = PIN_IN_USB_EXT; desc.desc = NULL; AudioSampleAttributes attrs; -@@ -186,6 +188,7 @@ int32_t AudioSourceLocal::Initialize(con + deviceId_ = config.deviceId; +@@ -186,6 +193,7 @@ int32_t AudioSourceLocal::Initialize(con MEDIA_ERR_LOG("not support audioFormat:%d", config.audioFormat); return ERR_INVALID_PARAM; } @@ -131,21 +664,235 @@ diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/founda attrs.sampleRate = config.sampleRate; attrs.channelCount = config.channelCount; attrs.interleaved = config.interleaved; -diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/server/src/audio_capturer_samgr.cpp ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/services/server/src/audio_capturer_samgr.cpp ---- ohos/foundation/multimedia/audio_lite/services/server/src/audio_capturer_samgr.cpp 2025-05-03 17:56:21.000000000 +0800 -+++ ../../../../../3403_project/ohos/foundation/multimedia/audio_lite/services/server/src/audio_capturer_samgr.cpp 2025-11-06 17:02:00.183098490 +0800 -@@ -75,11 +75,13 @@ static TaskConfig GetTaskConfig(Service +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/virtual/audio_source_virtural.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/src/virtual/audio_source_virtural.cpp +--- ohos/foundation/multimedia/audio_lite/services/impl/audio_source/src/virtual/audio_source_virtural.cpp 2025-12-18 09:10:10.571998225 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/impl/audio_source/src/virtual/audio_source_virtural.cpp 2025-12-18 09:10:45.139652947 +0800 +@@ -55,7 +55,7 @@ AudioSourceVirtual::AudioSourceVirtual(s + OHOS::HDI::DistributedAudio::Audio::V1_0::AudioAdapterDescriptor desc = vecDescs[index]; + for (uint32_t port = 0; port < desc.ports.size(); port++) { + if (desc.ports[port].dir == PORT_OUT_IN && +- (audioManager_->LoadAdapter(desc, audioAdapter_) == SUCCESS)) { ++ !(audioManager_->LoadAdapter(desc, audioAdapter_))) { + (void)audioAdapter_->InitAllPorts(); + if (deviceId_ == desc.adapterName || deviceId_ == "") { + adapterName_ = desc.adapterName; +@@ -75,6 +75,11 @@ AudioSourceVirtual::AudioSourceVirtual(s + + AudioSourceVirtual::~AudioSourceVirtual() + { ++ MEDIA_DEBUG_LOG("in"); ++ if (initialized_) { ++ Release(); ++ } ++ + if (audioAdapter_ != nullptr) { + MEDIA_INFO_LOG("UnloadModule audioAdapter_"); + if (audioManager_ == nullptr) { +@@ -87,7 +92,7 @@ AudioSourceVirtual::~AudioSourceVirtual( + } + } + +-int32_t AudioSourceVirtual::InitCheck() const ++int32_t AudioSourceVirtual::InitCheck() + { + if (!initialized_) { + MEDIA_ERR_LOG("not initialized"); +@@ -274,10 +279,7 @@ int32_t AudioSourceVirtual::ReadFrame(Au + frame.time.tvNSec = timeStamp.tvNSec; + readlen = vecframe.size(); + if (readlen > 0) { +- errno_t err = memcpy_s(frame.buffer, frame.bufferLen, vecframe.data(), readlen); +- if (err != EOK) { +- MEDIA_ERR_LOG("memcpy_s failed."); +- } ++ (void)memcpy_s(frame.buffer, frame.bufferLen, vecframe.data(), readlen); + } + return readlen; + } +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/server/include/audio_capturer_server.h /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/server/include/audio_capturer_server.h +--- ohos/foundation/multimedia/audio_lite/services/server/include/audio_capturer_server.h 2025-12-18 09:10:10.575998185 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/server/include/audio_capturer_server.h 2025-12-18 09:10:45.139652947 +0800 +@@ -59,7 +59,7 @@ public: + SvcIdentity GetSvcIdentity(); + void SetCanCallback(bool isCallback); + private: +- SvcIdentity sid_ {0, 0, 0}; ++ SvcIdentity sid_; + std::atomic isCallback_ {false}; + }; + +@@ -77,11 +77,10 @@ public: + void Dispatch(int32_t funcId, pid_t pid, IpcIo *req, IpcIo *reply); + static void *ReadAudioDataProcess(void *serverStr); + void OnAllDeviceChange(); +- void AddDeviceInfo(AudioDeviceInfo deviceInfo); ++ void addDeviceInfo(AudioDeviceInfo deviceInfo); + int32_t SendDeviceInfo(const AudioDeviceInfo &deviceInfo); + void SendReadDataFailInfo(void); + private: +- bool HandleTimestamp(SurfaceBuffer *surfaceBuf, int32_t readLen); + void GetMinFrameCount(IpcIo *req, IpcIo *reply); + int32_t SetSurfaceProcess(Surface *surface); + void SetInfo(AudioCapturerImpl *capturer, IpcIo *req, IpcIo *reply); +@@ -95,9 +94,9 @@ private: + SurfaceBuffer *GetCacheBuffer(void); + void CancelBuffer(SurfaceBuffer *buffer); + void FreeCacheBuffer(void); +- void SetAudioCapturerServerCallback(const AudioCapturerImpl *capturer, IpcIo *req); +- AudioCapturerInfo DeserializeCaptureInfo(const char *str) const; +- std::string SerializeCaptureInfo(const AudioCapturerInfo &info) const; ++ void SetAudioCapturerServerCallback(AudioCapturerImpl *capturer, IpcIo *req); ++ AudioCapturerInfo DeserializeCaptureInfo(const char *str); ++ std::string SerializeCaptureInfo(const AudioCapturerInfo &info); + pid_t clientPid_ = -1; + AudioCapturerImpl *capturer_ = nullptr; + Surface *surface_ = nullptr; +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/server/src/audio_capturer_samgr.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/server/src/audio_capturer_samgr.cpp +--- ohos/foundation/multimedia/audio_lite/services/server/src/audio_capturer_samgr.cpp 2025-12-18 09:10:10.575998185 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/server/src/audio_capturer_samgr.cpp 2025-12-18 09:10:45.139652947 +0800 +@@ -75,6 +75,13 @@ static TaskConfig GetTaskConfig(Service static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply) { -+ // if check will crash when origin is nullptr ++ // hihopeos add ,if check will crash when origin is nullptr +#if 0 - if (origin == nullptr) { - MEDIA_ERR_LOG("Invoke: origin is nullptr"); - return FALSE; - } -- ++ if (origin == nullptr) { ++ MEDIA_ERR_LOG("Invoke: origin is nullptr"); ++ return FALSE; ++ } +#endif pid_t pid = GetCallingPid(); AudioCapturerServer *mng = AudioCapturerServer::GetInstance(); if (mng == nullptr) { +diff -uparN '--exclude=prebuilts' '--exclude=.git' '--exclude=.repo' ohos/foundation/multimedia/audio_lite/services/server/src/audio_capturer_server.cpp /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/server/src/audio_capturer_server.cpp +--- ohos/foundation/multimedia/audio_lite/services/server/src/audio_capturer_server.cpp 2025-12-18 09:10:10.575998185 +0800 ++++ /ssd3/yin_yong/code/HiHopeOS-5.1-dev-L1-v1.1-1218/ohos1/foundation/multimedia/audio_lite/services/server/src/audio_capturer_server.cpp 2025-12-18 09:10:45.139652947 +0800 +@@ -114,9 +114,8 @@ void AudioCapturerServer::FreeCacheBuffe + bufCache_ = nullptr; + } + +-void AudioCapturerServer::SetAudioCapturerServerCallback(const AudioCapturerImpl *capturer, IpcIo *req) ++void AudioCapturerServer::SetAudioCapturerServerCallback(AudioCapturerImpl *capturer, IpcIo *req) + { +- (void)capturer; + SvcIdentity sid; + if (ReadRemoteObject(req, &sid)) { + if (callback_ != nullptr) { +@@ -145,7 +144,7 @@ SvcIdentity AudioCapturerServerCallback: + void AudioCapturerServerCallback::OnDeviceChange(const AudioDeviceInfo &deviceInfo) + { + MEDIA_INFO_LOG("revice Device changed,device dhid = %d", deviceInfo.dhId); +- AudioCapturerServer::GetInstance()->AddDeviceInfo(deviceInfo); ++ AudioCapturerServer::GetInstance()->addDeviceInfo(deviceInfo); + if (isCallback_.load()) { + AudioCapturerServer::GetInstance()->SendDeviceInfo(deviceInfo); + } +@@ -164,11 +163,11 @@ int32_t AudioCapturerServer::SendDeviceI + IpcIo io; + uint8_t tmpData[DEFAULT_IPC_SIZE]; + IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); +- WriteUint32(&io, deviceInfo.dhId); ++ WriteUint32(&io, (int32_t)deviceInfo.dhId); + WriteUint32(&io, deviceInfo.deviceName.size()); + WriteBuffer(&io, deviceInfo.deviceName.c_str(), deviceInfo.deviceName.size()); +- WriteInt32(&io, deviceInfo.deviceType); +- WriteInt32(&io, deviceInfo.connectStatus); ++ WriteInt32(&io, (int32_t)deviceInfo.deviceType); ++ WriteInt32(&io, (int32_t)deviceInfo.connectStatus); + MessageOption option; + MessageOptionInit(&option); + option.flags = TF_OP_ASYNC; +@@ -188,18 +187,17 @@ void AudioCapturerServer::SendReadDataFa + } + IpcIo io; + uint8_t tmpData[DEFAULT_IPC_SIZE]; +- IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0); ++ IpcIoInit(&io, tmpData, DEFAULT_IPC_SIZE, 0);; + MessageOption option; + MessageOptionInit(&option); + option.flags = TF_OP_ASYNC; +- int32_t ret = SendRequest(callback_->GetSvcIdentity(), AudioCapturerClientCall::ON_READ_DATA_FAILED, +- &io, nullptr, option, nullptr); ++ int32_t ret = SendRequest(callback_->GetSvcIdentity(), ON_READ_DATA_FAILED, &io, nullptr, option, nullptr); + if (ret != MEDIA_OK) { + MEDIA_ERR_LOG("AudioCapturerServerCallback::ON_READ_DATA_FAILED failed"); + } + } + +-void AudioCapturerServer::AddDeviceInfo(AudioDeviceInfo deviceInfo) ++void AudioCapturerServer::addDeviceInfo(AudioDeviceInfo deviceInfo) + { + std::lock_guard lck(callbackLock_); + std::vector::iterator it = deviceInfoList_.begin(); +@@ -229,26 +227,6 @@ void AudioCapturerServer::OnAllDeviceCha + } + } + +-bool AudioCapturerServer::HandleTimestamp(SurfaceBuffer *surfaceBuf, int32_t readLen) +-{ +- Timestamp timestamp; +- Timestamp::Timebase base = {}; +- bool ret = capturer_->GetTimestamp(timestamp, base); +- if (!ret) { +- MEDIA_ERR_LOG("No readtime get."); +- return false; +- } +- +- errno_t retCopy = memcpy_s((uint8_t *)surfaceBuf->GetVirAddr(), sizeof(Timestamp), ×tamp, sizeof(Timestamp)); +- if (retCopy != EOK) { +- MEDIA_ERR_LOG("retCopy = %x", retCopy); +- return false; +- } +- +- surfaceBuf->SetSize(sizeof(Timestamp) + readLen); +- return true; +-} +- + void *AudioCapturerServer::ReadAudioDataProcess(void *serverStr) + { + AudioCapturerServer *serverStore = (AudioCapturerServer *)serverStr; +@@ -284,14 +262,25 @@ void *AudioCapturerServer::ReadAudioData + break; + } + +- if (!serverStore->HandleTimestamp(surfaceBuf, readLen)) { ++ Timestamp timestamp; ++ Timestamp::Timebase base = {}; ++ bool ret = serverStore->capturer_->GetTimestamp(timestamp, base); ++ if (!ret) { ++ MEDIA_ERR_LOG("No readtime get."); ++ continue; ++ } ++ errno_t retCopy = memcpy_s((uint8_t *)buf, sizeof(Timestamp), ×tamp, sizeof(Timestamp)); ++ if (retCopy != EOK) { ++ MEDIA_ERR_LOG("retCopy = %x", retCopy); + continue; + } ++ surfaceBuf->SetSize(sizeof(Timestamp) + readLen); + + // flush buffer + if (serverStore->surface_->FlushBuffer(surfaceBuf) != 0) { + MEDIA_ERR_LOG("Flush surface buffer failed."); + serverStore->CancelBuffer(surfaceBuf); ++ ret = MEDIA_ERR; + continue; + } + serverStore->FreeCacheBuffer(); +@@ -326,7 +315,7 @@ void AudioCapturerServer::GetMinFrameCou + WriteUint32(reply, frameCount); + } + +-std::string AudioCapturerServer::SerializeCaptureInfo(const AudioCapturerInfo &info) const ++std::string AudioCapturerServer::SerializeCaptureInfo(const AudioCapturerInfo &info) + { + std::stringstream ss; + ss << static_cast(info.inputSource) << ' ' +@@ -341,7 +330,7 @@ std::string AudioCapturerServer::Seriali + return ss.str(); + } + +-AudioCapturerInfo AudioCapturerServer::DeserializeCaptureInfo(const char *str) const ++AudioCapturerInfo AudioCapturerServer::DeserializeCaptureInfo(const char *str) + { + AudioCapturerInfo info = {}; + std::stringstream ss(str); diff --git a/vendor/rkh/rkh_patch_build.sh b/vendor/rkh/rkh_patch_build.sh index 5c5258aa7b4a621e8e4ecacbba4c36eb8a36ea62..cdaa95aa8675089e40ee69dd93aa38d3cc9bad64 100644 --- a/vendor/rkh/rkh_patch_build.sh +++ b/vendor/rkh/rkh_patch_build.sh @@ -20,9 +20,7 @@ function patch_build() patch -p0 < ${SOURCE_ROOT_DIR}/rkh_patch/foundation/arkui_ace_engine_lite.patch patch -p0 < ${SOURCE_ROOT_DIR}/rkh_patch/foundation/bundlemanager_bundle_framework_lite.patch patch -p0 < ${SOURCE_ROOT_DIR}/rkh_patch/foundation/systemabilitymgr_samgr_lite.patch - patch -p0 < ${SOURCE_ROOT_DIR}/rkh_patch/foundation/arkui_ui_lite.patch patch -p0 < ${SOURCE_ROOT_DIR}/rkh_patch/foundation/graphic_graphic_utils_lite.patch - patch -p0 < ${SOURCE_ROOT_DIR}/rkh_patch/foundation/window_window_manager_lite.patch patch -p0 < ${SOURCE_ROOT_DIR}/rkh_patch/applications/applications_sample_camera.patch patch -p0 < ${SOURCE_ROOT_DIR}/rkh_patch/applications/applications_sample_camera_gallery.patch