1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CAMERA_ROTATE_PLUGIN_H 17 #define CAMERA_ROTATE_PLUGIN_H 18 19 #include <string> 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <refbase.h> 23 #include "safe_map.h" 24 #include "camera_metadata_info.h" 25 #include "surface.h" 26 27 using ParameterMap = std::map<int32_t, std::string>; 28 using UpdateSettingsCallback = std::function<int32_t(ParameterMap& parameters)>; 29 namespace OHOS { 30 namespace CameraStandard { 31 enum PluginParameter { 32 PLUGIN_BUNDLE_NAME = 0, 33 PLUGIN_CAMERA_ID, 34 PLUGIN_CAMERA_POSITION, 35 PLUGIN_CAMERA_CONNECTION_TYPE, // 0:buildin, 1:usb, 2:remote 36 PLUGIN_SENSOR_ORIENTATION, // ability 37 PLUGIN_PREVIEW_FORMAT, // preview 38 PLUGIN_SURFACE_FRAME_GRAVITY, // preview 39 PLUGIN_SURFACE_FIXED_ROTATION, // preview 40 PLUGIN_CAMERA_HAL_ROTATE_ANGLE, // preview + video 不区分 统一下发给HAL的 41 PLUGIN_JPEG_ORIENTATION, // jpeg 42 PLUGIN_CAPTURE_MIRROR, // jpeg 43 PLUGIN_SURFACE_APP_FWK_TYPE, //video 44 PLUGIN_VIDEO_SURFACE_TRANSFORM, // video 45 PLUGIN_VIDEO_MIRROR, // video 46 PLUGIN_PREVIEW_TRANSFORM, // preview 47 }; 48 class HCaptureSession; 49 50 class CameraRotatePlugin : public RefBase { 51 public: 52 ~CameraRotatePlugin(); 53 static sptr<CameraRotatePlugin> &GetInstance(); 54 bool HookCameraAbility(const std::string& cameraId, std::shared_ptr<OHOS::Camera::CameraMetadata>& inability); 55 bool HookOpenDeviceForRotate(const std::string& bundleName, 56 std::shared_ptr<OHOS::Camera::CameraMetadata> inputCapability, const std::string& cameraId); 57 bool HookCloseDeviceForRotate(const std::string& bundleName, 58 std::shared_ptr<OHOS::Camera::CameraMetadata> inputCapability, const std::string& cameraId); 59 bool HookCreatePreviewFormat(const std::string& bundleName, int32_t& format); 60 bool HookPreviewStreamStart(ParameterMap basicInfoMap, const sptr<OHOS::IBufferProducer>& producer, 61 int32_t& rotateAngle); 62 bool HookPreviewTransform(ParameterMap basicInfoMap, const sptr<OHOS::IBufferProducer>& producer, 63 int32_t& sensorOrientation, int32_t& cameraPosition); 64 bool HookCreateVideoOutput(ParameterMap basicInfoMap, const sptr<OHOS::IBufferProducer>& producer); 65 bool HookVideoStreamStart(ParameterMap basicInfoMap, const sptr<OHOS::IBufferProducer>& producer, 66 bool& mirror); 67 bool HookCaptureStreamStart(ParameterMap basicInfoMap, int32_t& jpegOrientation, bool& mirror); 68 void SetCaptureSession(const std::string& bundleName, wptr<HCaptureSession> hcaptureSession); 69 private: 70 CameraRotatePlugin(); 71 bool Init(); 72 void InitParam(const std::string& bundleName, std::shared_ptr<OHOS::Camera::CameraMetadata> inputCapability, 73 const std::string& cameraId, ParameterMap& param); 74 bool GetCameraAbility(ParameterMap basicInfoMap, uint8_t& cameraPosition, int32_t& sensorOrientation); 75 bool SubscribeUpdateSettingCallback(ParameterMap basicInfoMap); 76 bool UnSubscribeUpdateSettingCallback(ParameterMap basicInfoMap); 77 bool CreatePreviewOutput(ParameterMap basicInfoMap, int32_t& format); 78 bool PreviewStreamStart(ParameterMap basicInfoMap, int32_t& frameGravity, int32_t& fixedRotation, 79 int32_t& rotateAngle); 80 bool PreviewTransform(ParameterMap basicInfoMap, int32_t& frameGravity, int32_t& fixedRotation, 81 int32_t& sensorOrientation, int32_t& cameraPosition); 82 bool CaptureStreamStart(ParameterMap basicInfoMap, int32_t& jpegOrientation, bool& mirror); 83 bool CreateVideoOutput(ParameterMap basicInfoMap, std::string& surfaceAppFwkType, uint32_t& transform); 84 bool VideoStreamStart(ParameterMap basicInfoMap, std::string& surfaceAppFwkType, uint32_t& transform, 85 bool& mirror); 86 void* GetFunction(const std::string& functionName); 87 bool GetParameterResult(ParameterMap basicInfoMap, const std::string& functionName, ParameterMap& parameterMap); 88 int32_t OnParameterChange(ParameterMap ParameterMap); 89 90 static std::mutex instanceMutex_; 91 SafeMap<std::string, void*> functionMap_; 92 static sptr<CameraRotatePlugin> cameraRotatePlugin_; 93 static bool initResult; 94 void *handle_ = nullptr; 95 // wptr<HCaptureSession> hcaptureSession_; 96 SafeMap<std::string, wptr<HCaptureSession>> captureSessionMap_; 97 }; 98 } 99 } 100 #endif /* CAMERA_ROTATE_PLUGIN_H */ 101