!119 feat: add distributed camera idl deps

Merge pull request !119 from hobbycao/master
This commit is contained in:
openharmony_ci
2022-06-14 13:06:16 +00:00
committed by Gitee
91 changed files with 597 additions and 4480 deletions
-2
View File
@@ -62,8 +62,6 @@
"//foundation/distributedhardware/distributed_camera/sa_profile:dcamera.cfg",
"//foundation/distributedhardware/distributed_camera/services/channel:distributed_camera_channel",
"//foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/hdi_ipc/config/host:distributed_camera_host_config",
"//foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/hdi_ipc/config/provider:distributed_camera_provider_config",
"//foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/hdi_ipc/client:distributed_camera_hdf_client",
"//foundation/distributedhardware/distributed_camera/camera_hdf/hdi_impl:distributed_camera_hdf"
],
"inner_kits":[
+4 -4
View File
@@ -23,12 +23,10 @@ ohos_shared_library("distributed_camera_hdf") {
"include/dcamera_provider",
"include/dstream_operator",
"include/utils",
"../interfaces/include",
"../interfaces/hdi_ipc",
"../interfaces/hdi_ipc/server/device",
"../interfaces/hdi_ipc/server/host",
"../interfaces/hdi_ipc/server/operator",
"../interfaces/hdi_ipc/server/provider",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"${display_hdf_path}/interfaces/include",
@@ -53,8 +51,6 @@ ohos_shared_library("distributed_camera_hdf") {
"../interfaces/hdi_ipc/server/operator/doffline_stream_operator_stub.cpp",
"../interfaces/hdi_ipc/server/operator/dstream_operator_callback_proxy.cpp",
"../interfaces/hdi_ipc/server/operator/dstream_operator_stub.cpp",
"../interfaces/hdi_ipc/server/provider/dcamera_provider_callback_proxy.cpp",
"../interfaces/hdi_ipc/server/provider/dcamera_provider_stub.cpp",
"src/dcamera_device/dcamera_device.cpp",
"src/dcamera_device/dmetadata_processor.cpp",
"src/dcamera_host/dcamera_host.cpp",
@@ -69,6 +65,8 @@ ohos_shared_library("distributed_camera_hdf") {
"src/utils/dh_log.cpp",
]
public_deps = [ "//drivers/interface/distributed_camera/v1_0:libdistributed_camera_provider_stub_1.0" ]
deps = [
"//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter",
"//drivers/peripheral/camera/interfaces/metadata:metadata",
@@ -83,10 +81,12 @@ ohos_shared_library("distributed_camera_hdf") {
]
external_deps = [
"device_driver_framework:libhdf_utils",
"graphic_chipsetsdk:buffer_handle",
"graphic_chipsetsdk:surface",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
"utils_base:utils",
]
subsystem_name = "distributedhardware"
@@ -22,14 +22,14 @@
#include "dmetadata_processor.h"
#include "dstream_operator.h"
#include "icamera_device_callback.h"
#include "idistributed_camera_provider_callback.h"
#include "types.h"
#include "v1_0/id_camera_provider_callback.h"
namespace OHOS {
namespace DistributedHardware {
class DCameraDevice : public DCameraDeviceStub {
public:
DCameraDevice(const std::shared_ptr<DHBase> &dhBase, const std::string &abilityInfo);
DCameraDevice(const DHBase &dhBase, const std::string &abilityInfo);
DCameraDevice() = default;
virtual ~DCameraDevice() = default;
DCameraDevice(const DCameraDevice &other) = delete;
@@ -49,8 +49,8 @@ public:
CamRetCode OpenDCamera(const OHOS::sptr<ICameraDeviceCallback> &callback);
CamRetCode GetDCameraAbility(std::shared_ptr<CameraAbility> &ability);
DCamRetCode AcquireBuffer(int streamId, std::shared_ptr<DCameraBuffer> &buffer);
DCamRetCode ShutterBuffer(int streamId, const std::shared_ptr<DCameraBuffer> &buffer);
DCamRetCode AcquireBuffer(int streamId, DCameraBuffer &buffer);
DCamRetCode ShutterBuffer(int streamId, const DCameraBuffer &buffer);
DCamRetCode OnSettingsResult(const std::shared_ptr<DCameraSettings> &result);
DCamRetCode Notify(const std::shared_ptr<DCameraHDFEvent> &event);
void SetProviderCallback(const OHOS::sptr<IDCameraProviderCallback> &callback);
@@ -61,13 +61,13 @@ public:
private:
void Init(const std::string &abilityInfo);
DCamRetCode CreateDStreamOperator();
std::string GenerateCameraId(const std::shared_ptr<DHBase> &dhBase);
std::string GenerateCameraId(const DHBase &dhBase);
void NotifyStartCaptureError();
void NotifyCameraError(const std::shared_ptr<DCameraHDFEvent> &event);
private:
bool isOpened_;
std::string dCameraId_;
std::shared_ptr<DHBase> dhBase_;
DHBase dhBase_;
std::string dCameraAbilityInfo_;
OHOS::sptr<ICameraDeviceCallback> dCameraDeviceCallback_;
OHOS::sptr<IDCameraProviderCallback> dCameraProviderCallback_;
@@ -21,13 +21,14 @@
#include <vector>
#include "constants.h"
#include "dcamera.h"
#include "v1_0/dcamera_types.h"
#include <foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/include/types.h>
#include <drivers/peripheral/camera/interfaces/include/types.h>
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DMetadataProcessor {
public:
DMetadataProcessor() = default;
@@ -17,16 +17,18 @@
#define DISTRIBUTED_CAMERA_HOST_H
#include "dcamera.h"
#include "dcamera_base.h"
#include "dcamera_device.h"
#include "icamera_device.h"
#include "icamera_host_callback.h"
#include "icamera_device_callback.h"
#include "v1_0/dcamera_types.h"
#include <foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/include/types.h>
#include <drivers/peripheral/camera/interfaces/include/types.h>
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraHost {
public:
DCameraHost() = default;
@@ -45,15 +47,15 @@ public:
OHOS::sptr<ICameraDevice> &pDevice);
CamRetCode SetFlashlight(const std::string &cameraId, bool &isEnable);
DCamRetCode AddDCameraDevice(const std::shared_ptr<DHBase> &dhBase, const std::string &abilityInfo,
const sptr<IDCameraProviderCallback> &callback);
DCamRetCode RemoveDCameraDevice(const std::shared_ptr<DHBase> &dhBase);
OHOS::sptr<DCameraDevice> GetDCameraDeviceByDHBase(const std::shared_ptr<DHBase> &dhBase);
void NotifyDCameraStatus(const std::shared_ptr<DHBase> &dhBase, int32_t result);
DCamRetCode AddDCameraDevice(const DHBase &dhBase, const std::string &abilityInfo,
const sptr<IDCameraProviderCallback> &callback);
DCamRetCode RemoveDCameraDevice(const DHBase &dhBase);
OHOS::sptr<DCameraDevice> GetDCameraDeviceByDHBase(const DHBase &dhBase);
void NotifyDCameraStatus(const DHBase &dhBase, int32_t result);
private:
bool IsCameraIdInvalid(const std::string &cameraId);
std::string GetCameraIdByDHBase(const std::shared_ptr<DHBase> &dhBase);
std::string GetCameraIdByDHBase(const DHBase &dhBase);
private:
class AutoRelease {
@@ -70,7 +72,7 @@ private:
static std::shared_ptr<DCameraHost> instance_;
OHOS::sptr<ICameraHostCallback> dCameraHostCallback_;
std::map<DHBase, std::string> dhBaseHashDCamIdMap_;
std::map<DCameraBase, std::string> dhBaseHashDCamIdMap_;
std::map<std::string, OHOS::sptr<DCameraDevice>> dCameraDeviceMap_;
};
} // namespace DistributedHardware
@@ -16,14 +16,14 @@
#ifndef DISTRIBUTED_CAMERA_PROVIDER_H
#define DISTRIBUTED_CAMERA_PROVIDER_H
#include "dcamera.h"
#include "idistributed_camera_provider_callback.h"
#include "v1_0/id_camera_provider.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraHost;
class DCameraDevice;
class DCameraProvider {
class DCameraProvider : public IDCameraProvider {
public:
DCameraProvider() = default;
virtual ~DCameraProvider() = default;
@@ -33,32 +33,27 @@ public:
DCameraProvider& operator=(DCameraProvider &&other) = delete;
public:
static std::shared_ptr<DCameraProvider> GetInstance();
DCamRetCode EnableDCameraDevice(const std::shared_ptr<DHBase> &dhBase, const std::string &abilitySet,
const sptr<IDCameraProviderCallback> &callback);
DCamRetCode DisableDCameraDevice(const std::shared_ptr<DHBase> &dhBase);
DCamRetCode AcquireBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
std::shared_ptr<DCameraBuffer> &buffer);
DCamRetCode ShutterBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
const std::shared_ptr<DCameraBuffer> &buffer);
DCamRetCode OnSettingsResult(const std::shared_ptr<DHBase> &dhBase, const std::shared_ptr<DCameraSettings> &result);
DCamRetCode Notify(const std::shared_ptr<DHBase> &dhBase, const std::shared_ptr<DCameraHDFEvent> &event);
static OHOS::sptr<DCameraProvider> GetInstance();
int32_t EnableDCameraDevice(const DHBase& dhBase, const std::string& abilityInfo,
const sptr<IDCameraProviderCallback>& callbackObj) override;
int32_t DisableDCameraDevice(const DHBase& dhBase) override;
int32_t AcquireBuffer(const DHBase& dhBase, int32_t streamId, DCameraBuffer& buffer) override;
int32_t ShutterBuffer(const DHBase& dhBase, int32_t streamId, const DCameraBuffer& buffer) override;
int32_t OnSettingsResult(const DHBase& dhBase, const DCameraSettings& result) override;
int32_t Notify(const DHBase& dhBase, const DCameraHDFEvent& event) override;
DCamRetCode OpenSession(const std::shared_ptr<DHBase> &dhBase);
DCamRetCode CloseSession(const std::shared_ptr<DHBase> &dhBase);
DCamRetCode ConfigureStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCStreamInfo>> &streamInfos);
DCamRetCode ReleaseStreams(const std::shared_ptr<DHBase> &dhBase, const std::vector<int> &streamIds);
DCamRetCode StartCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCCaptureInfo>> &captureInfos);
DCamRetCode StopCapture(const std::shared_ptr<DHBase> &dhBase, const std::vector<int> &streamIds);
DCamRetCode UpdateSettings(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCameraSettings>> &settings);
int32_t OpenSession(const DHBase &dhBase);
int32_t CloseSession(const DHBase &dhBase);
int32_t ConfigureStreams(const DHBase &dhBase, const std::vector<DCStreamInfo> &streamInfos);
int32_t ReleaseStreams(const DHBase &dhBase, const std::vector<int> &streamIds);
int32_t StartCapture(const DHBase &dhBase, const std::vector<DCCaptureInfo> &captureInfos);
int32_t StopCapture(const DHBase &dhBase, const std::vector<int> &streamIds);
int32_t UpdateSettings(const DHBase &dhBase, const std::vector<DCameraSettings> &settings);
private:
bool IsDhBaseInfoInvalid(const std::shared_ptr<DHBase> &dhBase);
sptr<IDCameraProviderCallback> GetCallbackBydhBase(const std::shared_ptr<DHBase> &dhBase);
OHOS::sptr<DCameraDevice> GetDCameraDevice(const std::shared_ptr<DHBase> &dhBase);
bool IsDhBaseInfoInvalid(const DHBase &dhBase);
sptr<IDCameraProviderCallback> GetCallbackBydhBase(const DHBase &dhBase);
OHOS::sptr<DCameraDevice> GetDCameraDevice(const DHBase &dhBase);
private:
class AutoRelease {
@@ -72,7 +67,7 @@ private:
}
};
static AutoRelease autoRelease_;
static std::shared_ptr<DCameraProvider> instance_;
static OHOS::sptr<DCameraProvider> instance_;
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -24,8 +24,11 @@
#include "dimage_buffer.h"
#include "surface.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DBufferManager {
public:
DBufferManager() = default;
@@ -41,9 +44,9 @@ public:
RetCode RemoveBuffer(std::shared_ptr<DImageBuffer>& buffer);
void NotifyStop(bool state);
static RetCode SurfaceBufferToDImageBuffer(const OHOS::sptr<OHOS::SurfaceBuffer> &surfaceBuffer,
const std::shared_ptr<DImageBuffer> &buffer);
const std::shared_ptr<DImageBuffer> &buffer);
static RetCode DImageBufferToDCameraBuffer(const std::shared_ptr<DImageBuffer> &imageBuffer,
std::shared_ptr<DCameraBuffer> &buffer);
DCameraBuffer &buffer);
static uint64_t CameraUsageToGrallocUsage(const uint64_t cameraUsage);
static uint32_t PixelFormatToDCameraFormat(const PixelFormat format);
@@ -19,14 +19,15 @@
#include "surface.h"
#include "dimage_buffer.h"
#include "dbuffer_manager.h"
#include "v1_0/dcamera_types.h"
#include <foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/include/types.h>
#include <drivers/peripheral/camera/interfaces/include/types.h>
namespace OHOS {
namespace DistributedHardware {
using namespace std;
using namespace OHOS::Camera;
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraStream {
public:
DCameraStream() = default;
@@ -42,8 +43,8 @@ public:
DCamRetCode SetDCameraBufferQueue(const OHOS::sptr<OHOS::IBufferProducer> producer);
DCamRetCode ReleaseDCameraBufferQueue();
DCamRetCode GetDCameraStreamAttribute(shared_ptr<StreamAttribute> &attribute);
DCamRetCode GetDCameraBuffer(shared_ptr<DCameraBuffer> &buffer);
DCamRetCode ReturnDCameraBuffer(const shared_ptr<DCameraBuffer> &buffer);
DCamRetCode GetDCameraBuffer(DCameraBuffer &buffer);
DCamRetCode ReturnDCameraBuffer(const DCameraBuffer &buffer);
DCamRetCode FlushDCameraBuffer();
DCamRetCode FinishCommitStream();
bool HasBufferQueue();
@@ -27,6 +27,8 @@
#include "constants.h"
#include "dcamera_steam.h"
#include "json/json.h"
namespace OHOS {
namespace DistributedHardware {
using namespace std;
@@ -58,9 +60,9 @@ public:
CamRetCode ChangeToOfflineStream(const std::vector<int>& streamIds, OHOS::sptr<IStreamOperatorCallback>& callback,
OHOS::sptr<IOfflineStreamOperator>& offlineOperator) override;
DCamRetCode InitOutputConfigurations(const std::shared_ptr<DHBase> &dhBase, const std::string &abilityInfo);
DCamRetCode AcquireBuffer(int streamId, std::shared_ptr<DCameraBuffer> &buffer);
DCamRetCode ShutterBuffer(int streamId, const std::shared_ptr<DCameraBuffer> &buffer);
DCamRetCode InitOutputConfigurations(const DHBase &dhBase, const std::string &abilityInfo);
DCamRetCode AcquireBuffer(int streamId, DCameraBuffer &buffer);
DCamRetCode ShutterBuffer(int streamId, const DCameraBuffer &buffer);
DCamRetCode SetCallBack(OHOS::sptr<IStreamOperatorCallback> const &callback);
DCamRetCode SetDeviceCallback(function<void(ErrorType, int)> &errorCbk,
function<void(uint64_t, std::shared_ptr<Camera::CameraMetadata>)> &resultCbk);
@@ -85,6 +87,9 @@ private:
std::vector<std::shared_ptr<DCStreamInfo>> &srcStreamInfo);
void SnapShotStreamOnCaptureEnded(int32_t captureId, int streamId);
bool HasContinuousCaptureInfo(int captureId);
void ExtractStreamInfo(DCStreamInfo &dstStreamInfo, const std::shared_ptr<DCStreamInfo> &srcStreamInfo);
void ExtractCaptureInfo(std::vector<DCCaptureInfo> &captureInfos);
void ExtractCameraAttr(Json::Value &rootValue, std::set<int> &allFormats, std::vector<int> &photoFormats);
private:
std::shared_ptr<DMetadataProcessor> dMetadataProcessor_;
@@ -92,7 +97,7 @@ private:
function<void(ErrorType, int)> errorCallback_;
function<void(uint64_t, std::shared_ptr<Camera::CameraMetadata>)> resultCallback_;
std::shared_ptr<DHBase> dhBase_;
DHBase dhBase_;
std::vector<DCEncodeType> dcSupportedCodecType_;
std::map<DCSceneType, std::vector<int>> dcSupportedFormatMap_;
std::map<int, std::vector<DCResolution>> dcSupportedResolutionMap_;
+2 -1
View File
@@ -16,12 +16,13 @@
#ifndef DISTRIBUTED_CAMERA_H
#define DISTRIBUTED_CAMERA_H
#include <foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/include/types.h>
#include <drivers/peripheral/camera/interfaces/include/types.h>
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
using namespace OHOS::HDI::DistributedCamera::V1_0;
using RetCode = uint32_t;
using MetaType = int32_t;
const std::string BASE_64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -12,24 +12,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_DCAMERA_BASE_H
#define OHOS_DCAMERA_BASE_H
#ifndef DISTRIBUTED_CAMERA_DEVICE_CALLBACK_H
#define DISTRIBUTED_CAMERA_DEVICE_CALLBACK_H
#include "dcamera_device_callback_stub.h"
#include <string>
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DCameraDeviceCallback : public DCameraDeviceCallbackStub {
class DCameraBase {
public:
DCameraDeviceCallback() = default;
virtual ~DCameraDeviceCallback() = default;
DCameraBase() = default;
explicit DCameraBase(std::string deviceId, std::string dhId) : deviceId_(deviceId), dhId_(dhId) {}
~DCameraBase() = default;
public:
virtual void OnError(ErrorType type, int32_t errorMsg) override;
virtual void OnResult(uint64_t timestamp, const std::shared_ptr<Camera::CameraMetadata> &result) override;
bool operator == (const DCameraBase& index) const
{
return this->deviceId_ == index.deviceId_ && this->dhId_ == index.dhId_;
}
bool operator < (const DCameraBase& index) const
{
return (this->deviceId_ + this->dhId_) < (index.deviceId_ + index.dhId_);
}
std::string deviceId_;
std::string dhId_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_DEVICE_CALLBACK_H
#endif // OHOS_DCAMERA_BASE_H
@@ -17,6 +17,7 @@
#include <iostream>
#include <iterator>
#include <sstream>
#include "anonymous_string.h"
#include "constants.h"
#include "dcamera.h"
@@ -29,7 +30,7 @@ namespace OHOS {
namespace DistributedHardware {
using ErrorCallback = std::function<void (ErrorType, int32_t)>;
using ResultCallback = std::function<void (uint64_t, std::shared_ptr<Camera::CameraMetadata>)>;
DCameraDevice::DCameraDevice(const std::shared_ptr<DHBase> &dhBase, const std::string &abilityInfo)
DCameraDevice::DCameraDevice(const DHBase &dhBase, const std::string &abilityInfo)
: isOpened_(false),
dCameraId_(GenerateCameraId(dhBase)),
dhBase_(dhBase),
@@ -118,23 +119,23 @@ CamRetCode DCameraDevice::UpdateSettings(const std::shared_ptr<CameraSetting> &s
return CamRetCode::CAMERA_CLOSED;
}
std::shared_ptr<DCameraSettings> dcSetting = std::make_shared<DCameraSettings>();
DCameraSettings dcSetting;
dcSetting->type_ = DCSettingsType::UPDATE_METADATA;
dcSetting.type_ = DCSettingsType::UPDATE_METADATA;
std::string abilityStr = Camera::MetadataUtils::EncodeToString(settings);
dcSetting->value_ = Base64Encode(reinterpret_cast<const unsigned char *>(abilityStr.c_str()), abilityStr.length());
dcSetting.value_ = Base64Encode(reinterpret_cast<const unsigned char *>(abilityStr.c_str()), abilityStr.length());
std::vector<std::shared_ptr<DCameraSettings>> dcSettings;
std::vector<DCameraSettings> dcSettings;
dcSettings.push_back(dcSetting);
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider == nullptr) {
DHLOGE("Distributed camera provider instance is null.");
return CamRetCode::DEVICE_ERROR;
}
DCamRetCode ret = provider->UpdateSettings(dhBase_, dcSettings);
int32_t ret = provider->UpdateSettings(dhBase_, dcSettings);
return MapToExternalRetCode(ret);
return MapToExternalRetCode(static_cast<DCamRetCode>(ret));
}
CamRetCode DCameraDevice::SetResultMode(const ResultCallbackMode &mode)
@@ -180,17 +181,19 @@ CamRetCode DCameraDevice::EnableResult(const std::vector<MetaType> &results)
stringstream sstream;
std::reverse_copy(results.begin(), results.end(), ostream_iterator<int32_t>(sstream, ""));
std::shared_ptr<DCameraSettings> dcSetting = std::make_shared<DCameraSettings>();
dcSetting->type_ = DCSettingsType::ENABLE_METADATA;
dcSetting->value_ = sstream.str();
DCameraSettings dcSetting;
dcSetting.type_ = DCSettingsType::ENABLE_METADATA;
dcSetting.value_ = sstream.str();
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider != nullptr) {
std::vector<std::shared_ptr<DCameraSettings>> dcSettings;
dcSettings.push_back(dcSetting);
ret = provider->UpdateSettings(dhBase_, dcSettings);
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider == nullptr) {
DHLOGE("Enable metadata failed, provider is nullptr.");
return CamRetCode::DEVICE_ERROR;
}
return MapToExternalRetCode(ret);
std::vector<DCameraSettings> dcSettings;
dcSettings.push_back(dcSetting);
int32_t retProv = provider->UpdateSettings(dhBase_, dcSettings);
return MapToExternalRetCode(static_cast<DCamRetCode>(retProv));
}
CamRetCode DCameraDevice::DisableResult(const std::vector<MetaType> &results)
@@ -208,24 +211,26 @@ CamRetCode DCameraDevice::DisableResult(const std::vector<MetaType> &results)
stringstream sstream;
std::reverse_copy(results.begin(), results.end(), ostream_iterator<int32_t>(sstream, ""));
std::shared_ptr<DCameraSettings> dcSetting = std::make_shared<DCameraSettings>();
dcSetting->type_ = DCSettingsType::DISABLE_METADATA;
dcSetting->value_ = sstream.str();
DCameraSettings dcSetting;
dcSetting.type_ = DCSettingsType::DISABLE_METADATA;
dcSetting.value_ = sstream.str();
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider != nullptr) {
std::vector<std::shared_ptr<DCameraSettings>> dcSettings;
dcSettings.push_back(dcSetting);
ret = provider->UpdateSettings(dhBase_, dcSettings);
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider == nullptr) {
DHLOGE("Metadata processor provider is nullptr.");
return CamRetCode::DEVICE_ERROR;
}
return MapToExternalRetCode(ret);
std::vector<DCameraSettings> dcSettings;
dcSettings.push_back(dcSetting);
int32_t retProv = provider->UpdateSettings(dhBase_, dcSettings);
return MapToExternalRetCode(static_cast<DCamRetCode>(retProv));
}
void DCameraDevice::Close()
{
DHLOGI("DCameraDevice::Close distributed camera: %s", GetAnonyString(dCameraId_).c_str());
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if ((provider != nullptr) && (dCameraStreamOperator_ != nullptr)) {
std::vector<int> streamIds = dCameraStreamOperator_->GetStreamIds();
provider->StopCapture(dhBase_, streamIds);
@@ -253,15 +258,15 @@ CamRetCode DCameraDevice::OpenDCamera(const OHOS::sptr<ICameraDeviceCallback> &c
}
dCameraDeviceCallback_ = callback;
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider == nullptr) {
DHLOGE("Get distributed camera provider instance is null.");
return CamRetCode::DEVICE_ERROR;
}
DCamRetCode ret = provider->OpenSession(dhBase_);
int32_t ret = provider->OpenSession(dhBase_);
if (ret != DCamRetCode::SUCCESS) {
DHLOGE("Open distributed camera control session failed, ret = %d.", ret);
return MapToExternalRetCode(ret);
return MapToExternalRetCode(static_cast<DCamRetCode>(ret));
}
unique_lock<mutex> lock(openSesslock_);
@@ -278,14 +283,14 @@ CamRetCode DCameraDevice::OpenDCamera(const OHOS::sptr<ICameraDeviceCallback> &c
}
}
ret = CreateDStreamOperator();
DCamRetCode retDCode = CreateDStreamOperator();
if (ret != SUCCESS) {
DHLOGE("Create distributed camera stream operator failed.");
return MapToExternalRetCode(ret);
return MapToExternalRetCode(retDCode);
}
isOpened_ = true;
return MapToExternalRetCode(ret);
return MapToExternalRetCode(retDCode);
}
CamRetCode DCameraDevice::GetDCameraAbility(std::shared_ptr<CameraAbility> &ability)
@@ -302,7 +307,7 @@ CamRetCode DCameraDevice::GetDCameraAbility(std::shared_ptr<CameraAbility> &abil
return MapToExternalRetCode(ret);
}
DCamRetCode DCameraDevice::AcquireBuffer(int streamId, std::shared_ptr<DCameraBuffer> &buffer)
DCamRetCode DCameraDevice::AcquireBuffer(int streamId, DCameraBuffer &buffer)
{
if (dCameraStreamOperator_ == nullptr) {
DHLOGE("Stream operator not init.");
@@ -316,7 +321,7 @@ DCamRetCode DCameraDevice::AcquireBuffer(int streamId, std::shared_ptr<DCameraBu
return ret;
}
DCamRetCode DCameraDevice::ShutterBuffer(int streamId, const std::shared_ptr<DCameraBuffer> &buffer)
DCamRetCode DCameraDevice::ShutterBuffer(int streamId, const DCameraBuffer &buffer)
{
if (dCameraStreamOperator_ == nullptr) {
DHLOGE("Stream operator not init.");
@@ -334,25 +339,25 @@ DCamRetCode DCameraDevice::OnSettingsResult(const std::shared_ptr<DCameraSetting
{
if (result == nullptr) {
DHLOGE("Input camera settings is null.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
if (dMetadataProcessor_ == nullptr) {
DHLOGE("Metadata processor not init.");
return DEVICE_NOT_INIT;
return DCamRetCode::DEVICE_NOT_INIT;
}
if (result->type_ != DCSettingsType::METADATA_RESULT) {
DHLOGE("Invalid camera setting type = %d.", result->type_);
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
if ((result->value_).empty()) {
DHLOGE("Camera settings result is empty.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
DCamRetCode ret = dMetadataProcessor_->SaveResultMetadata(result->value_);
if (ret != SUCCESS) {
if (ret != DCamRetCode::SUCCESS) {
DHLOGE("Save result metadata failed, ret = %d", ret);
}
return ret;
@@ -364,7 +369,7 @@ DCamRetCode DCameraDevice::Notify(const std::shared_ptr<DCameraHDFEvent> &event)
event->content_.c_str());
if ((event->type_ != DCameraEventType::DCAMERA_MESSAGE) && (event->type_ != DCameraEventType::DCAMERA_OPERATION)) {
DHLOGE("Invalid distributed camera event type = %d.", event->type_);
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
switch (event->result_) {
case DCameraEventResult::DCAMERA_EVENT_CHANNEL_CONNECTED: {
@@ -410,7 +415,7 @@ void DCameraDevice::NotifyStartCaptureError()
if (dCameraDeviceCallback_ != nullptr) {
dCameraDeviceCallback_->OnError(ErrorType::REQUEST_TIMEOUT, 0);
}
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if ((provider != nullptr) && (dCameraStreamOperator_ != nullptr)) {
std::vector<int> streamIds = dCameraStreamOperator_->GetStreamIds();
provider->StopCapture(dhBase_, streamIds);
@@ -442,9 +447,9 @@ OHOS::sptr<IDCameraProviderCallback> DCameraDevice::GetProviderCallback()
return dCameraProviderCallback_;
}
std::string DCameraDevice::GenerateCameraId(const std::shared_ptr<DHBase> &dhBase)
std::string DCameraDevice::GenerateCameraId(const DHBase &dhBase)
{
return dhBase->deviceId_ + "__" + dhBase->dhId_;
return dhBase.deviceId_ + "__" + dhBase.dhId_;
}
std::string DCameraDevice::GetDCameraId()
@@ -248,7 +248,7 @@ DCamRetCode DMetadataProcessor::AddAbilityEntry(uint32_t tag, const void *data,
{
if (dCameraAbility_ == nullptr) {
DHLOGE("Distributed camera abilily is null.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
camera_metadata_item_t item;
@@ -266,7 +266,7 @@ DCamRetCode DMetadataProcessor::UpdateAbilityEntry(uint32_t tag, const void *dat
{
if (dCameraAbility_ == nullptr) {
DHLOGE("Distributed camera abilily is null.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
camera_metadata_item_t item;
@@ -295,7 +295,7 @@ DCamRetCode DMetadataProcessor::SetMetadataResultMode(const ResultCallbackMode &
{
if (mode < ResultCallbackMode::PER_FRAME || mode > ResultCallbackMode::ON_CHANGED) {
DHLOGE("Invalid result callback mode.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
metaResultMode_ = mode;
return SUCCESS;
@@ -429,18 +429,18 @@ DCamRetCode DMetadataProcessor::SaveResultMetadata(std::string resultStr)
{
if (resultStr.empty()) {
DHLOGE("Input result string is null.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
latestProducerResultMetadata_ = Camera::MetadataUtils::DecodeFromString(resultStr)->get();
if (latestProducerResultMetadata_ == nullptr) {
DHLOGE("Failed to decode metadata setting from string.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
if (!Camera::GetCameraMetadataItemCount(latestProducerResultMetadata_)) {
DHLOGE("Input result metadata item is empty.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
return SUCCESS;
@@ -118,11 +118,11 @@ CamRetCode DCameraHost::SetFlashlight(const std::string &cameraId, bool &isEnab
return CamRetCode::METHOD_NOT_SUPPORTED;
}
DCamRetCode DCameraHost::AddDCameraDevice(const std::shared_ptr<DHBase> &dhBase, const std::string &abilityInfo,
DCamRetCode DCameraHost::AddDCameraDevice(const DHBase &dhBase, const std::string &abilityInfo,
const sptr<IDCameraProviderCallback> &callback)
{
DHLOGI("DCameraHost::AddDCameraDevice for {devId: %s, dhId: %s}",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
OHOS::sptr<DCameraDevice> dcameraDevice = new (std::nothrow) DCameraDevice(dhBase, abilityInfo);
if (dcameraDevice == nullptr) {
@@ -132,8 +132,8 @@ DCamRetCode DCameraHost::AddDCameraDevice(const std::shared_ptr<DHBase> &dhBase,
std::string dCameraId = dcameraDevice->GetDCameraId();
dCameraDeviceMap_[dCameraId] = dcameraDevice;
DHBase dhBaseKey(dhBase->deviceId_, dhBase->dhId_);
dhBaseHashDCamIdMap_.emplace(dhBaseKey, dCameraId);
DCameraBase dcameraBase(dhBase.deviceId_, dhBase.dhId_);
dhBaseHashDCamIdMap_.emplace(dcameraBase, dCameraId);
dcameraDevice->SetProviderCallback(callback);
if (dCameraHostCallback_ != nullptr) {
@@ -145,10 +145,10 @@ DCamRetCode DCameraHost::AddDCameraDevice(const std::shared_ptr<DHBase> &dhBase,
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraHost::RemoveDCameraDevice(const std::shared_ptr<DHBase> &dhBase)
DCamRetCode DCameraHost::RemoveDCameraDevice(const DHBase &dhBase)
{
DHLOGI("DCameraHost::RemoveDCameraDevice for {devId: %s, dhId: %s}",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
std::string dCameraId = GetCameraIdByDHBase(dhBase);
if (dCameraId.empty()) {
@@ -164,8 +164,8 @@ DCamRetCode DCameraHost::RemoveDCameraDevice(const std::shared_ptr<DHBase> &dhBa
dcameraDevice->SetProviderCallback(nullptr);
}
DHBase dhBaseKey(dhBase->deviceId_, dhBase->dhId_);
dhBaseHashDCamIdMap_.erase(dhBaseKey);
DCameraBase dcameraBase(dhBase.deviceId_, dhBase.dhId_);
dhBaseHashDCamIdMap_.erase(dcameraBase);
dCameraDeviceMap_.erase(dCameraId);
if (dCameraHostCallback_ != nullptr) {
@@ -193,17 +193,17 @@ bool DCameraHost::IsCameraIdInvalid(const std::string &cameraId)
return true;
}
std::string DCameraHost::GetCameraIdByDHBase(const std::shared_ptr<DHBase> &dhBase)
std::string DCameraHost::GetCameraIdByDHBase(const DHBase &dhBase)
{
DHBase dhBaseKey(dhBase->deviceId_, dhBase->dhId_);
auto iter = dhBaseHashDCamIdMap_.find(dhBaseKey);
DCameraBase dcameraBase(dhBase.deviceId_, dhBase.dhId_);
auto iter = dhBaseHashDCamIdMap_.find(dcameraBase);
if (iter == dhBaseHashDCamIdMap_.end()) {
return "";
}
return iter->second;
}
OHOS::sptr<DCameraDevice> DCameraHost::GetDCameraDeviceByDHBase(const std::shared_ptr<DHBase> &dhBase)
OHOS::sptr<DCameraDevice> DCameraHost::GetDCameraDeviceByDHBase(const DHBase &dhBase)
{
std::string dCameraId = GetCameraIdByDHBase(dhBase);
if (dCameraId.empty()) {
@@ -219,7 +219,7 @@ OHOS::sptr<DCameraDevice> DCameraHost::GetDCameraDeviceByDHBase(const std::share
return iter->second;
}
void DCameraHost::NotifyDCameraStatus(const std::shared_ptr<DHBase> &dhBase, int32_t result)
void DCameraHost::NotifyDCameraStatus(const DHBase &dhBase, int32_t result)
{
std::string dCameraId = GetCameraIdByDHBase(dhBase);
if (dCameraId.empty()) {
@@ -22,13 +22,18 @@
namespace OHOS {
namespace DistributedHardware {
std::shared_ptr<DCameraProvider> DCameraProvider::instance_ = nullptr;
OHOS::sptr<DCameraProvider> DCameraProvider::instance_ = nullptr;
DCameraProvider::AutoRelease DCameraProvider::autoRelease_;
std::shared_ptr<DCameraProvider> DCameraProvider::GetInstance()
extern "C" IDCameraProvider *HdiImplGetInstance(void)
{
return static_cast<IDCameraProvider *>(DCameraProvider::GetInstance().GetRefPtr());
}
OHOS::sptr<DCameraProvider> DCameraProvider::GetInstance()
{
if (instance_ == nullptr) {
instance_ = std::make_shared<DCameraProvider>();
instance_ = new DCameraProvider();
if (instance_ == nullptr) {
DHLOGE("Get distributed camera provider instance failed.");
return nullptr;
@@ -37,15 +42,11 @@ std::shared_ptr<DCameraProvider> DCameraProvider::GetInstance()
return instance_;
}
DCamRetCode DCameraProvider::EnableDCameraDevice(const std::shared_ptr<DHBase> &dhBase,
const std::string &abilityInfo, const sptr<IDCameraProviderCallback> &callback)
int32_t DCameraProvider::EnableDCameraDevice(const DHBase& dhBase, const std::string& abilityInfo,
const sptr<IDCameraProviderCallback>& callbackObj)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::EnableDCameraDevice, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::EnableDCameraDevice for {devId: %s, dhId: %s, abilityInfo length: %d}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str(), abilityInfo.length());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str(), abilityInfo.length());
if (IsDhBaseInfoInvalid(dhBase)) {
DHLOGE("DCameraProvider::EnableDCameraDevice, devId or dhId is invalid.");
@@ -55,8 +56,8 @@ DCamRetCode DCameraProvider::EnableDCameraDevice(const std::shared_ptr<DHBase> &
DHLOGE("DCameraProvider::EnableDCameraDevice, dcamera ability is empty.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (callback == nullptr) {
DHLOGE("DCameraProvider::EnableDCameraDevice, dcamera provider callback is null.");
if (callbackObj == nullptr) {
DHLOGE("DCameraProvider::EnableDCameraDevice, dcamera provider callbackObj is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
@@ -65,7 +66,7 @@ DCamRetCode DCameraProvider::EnableDCameraDevice(const std::shared_ptr<DHBase> &
DHLOGE("DCameraProvider::EnableDCameraDevice, dcamera host is null.");
return DCamRetCode::DEVICE_NOT_INIT;
}
DCamRetCode ret = dCameraHost->AddDCameraDevice(dhBase, abilityInfo, callback);
DCamRetCode ret = dCameraHost->AddDCameraDevice(dhBase, abilityInfo, callbackObj);
if (ret != DCamRetCode::SUCCESS) {
DHLOGE("DCameraProvider::EnableDCameraDevice failed, ret = %d.", ret);
}
@@ -73,14 +74,10 @@ DCamRetCode DCameraProvider::EnableDCameraDevice(const std::shared_ptr<DHBase> &
return ret;
}
DCamRetCode DCameraProvider::DisableDCameraDevice(const std::shared_ptr<DHBase> &dhBase)
int32_t DCameraProvider::DisableDCameraDevice(const DHBase& dhBase)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::DisableDCameraDevice, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::DisableDCameraDevice for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
if (IsDhBaseInfoInvalid(dhBase)) {
DHLOGE("DCameraProvider::DisableDCameraDevice, devId or dhId is invalid.");
@@ -101,15 +98,10 @@ DCamRetCode DCameraProvider::DisableDCameraDevice(const std::shared_ptr<DHBase>
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraProvider::AcquireBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
std::shared_ptr<DCameraBuffer> &buffer)
int32_t DCameraProvider::AcquireBuffer(const DHBase& dhBase, int32_t streamId, DCameraBuffer& buffer)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::AcquireBuffer, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::AcquireBuffer for {devId: %s, dhId: %s}, streamId: %d.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str(), streamId);
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str(), streamId);
OHOS::sptr<DCameraDevice> device = GetDCameraDevice(dhBase);
if (device == nullptr) {
@@ -117,41 +109,35 @@ DCamRetCode DCameraProvider::AcquireBuffer(const std::shared_ptr<DHBase> &dhBase
return DCamRetCode::INVALID_ARGUMENT;
}
return device->AcquireBuffer(streamId, buffer);
DCamRetCode ret = device->AcquireBuffer(streamId, buffer);
if (ret != DCamRetCode::SUCCESS) {
DHLOGE("DCameraProvider::AcquireBuffer failed, ret = %d.", ret);
return ret;
}
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraProvider::ShutterBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
const std::shared_ptr<DCameraBuffer> &buffer)
int32_t DCameraProvider::ShutterBuffer(const DHBase& dhBase, int32_t streamId, const DCameraBuffer& buffer)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::ShutterBuffer, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (buffer == nullptr) {
DHLOGE("DCameraProvider::ShutterBuffer, input distributed camera buffer is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::ShutterBuffer for {devId: %s, dhId: %s}, streamId = %d, buffer index = %d.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str(), streamId, buffer->index_);
DHLOGD("DCameraProvider::ShutterBuffer for {devId: %s, dhId: %s}, streamId = %d, buffer index = %d.",
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str(), streamId, buffer.index_);
/* ShutterBuffer don't need buffer handle */
if (buffer.bufferHandle_ != nullptr) {
FreeBufferHandle(buffer.bufferHandle_->GetBufferHandle());
}
OHOS::sptr<DCameraDevice> device = GetDCameraDevice(dhBase);
if (device == nullptr) {
DHLOGE("DCameraProvider::ShutterBuffer failed, dcamera device not found.");
return DCamRetCode::INVALID_ARGUMENT;
}
return device->ShutterBuffer(streamId, buffer);
}
DCamRetCode DCameraProvider::OnSettingsResult(const std::shared_ptr<DHBase> &dhBase,
const std::shared_ptr<DCameraSettings> &result)
int32_t DCameraProvider::OnSettingsResult(const DHBase& dhBase, const DCameraSettings& result)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::OnSettingsResult, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::OnSettingsResult for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
OHOS::sptr<DCameraDevice> device = GetDCameraDevice(dhBase);
if (device == nullptr) {
@@ -159,18 +145,16 @@ DCamRetCode DCameraProvider::OnSettingsResult(const std::shared_ptr<DHBase> &dhB
return DCamRetCode::INVALID_ARGUMENT;
}
return device->OnSettingsResult(result);
std::shared_ptr<DCameraSettings> dCameraResult = std::make_shared<DCameraSettings>();
dCameraResult->type_ = result.type_;
dCameraResult->value_ = result.value_;
return device->OnSettingsResult(dCameraResult);
}
DCamRetCode DCameraProvider::Notify(const std::shared_ptr<DHBase> &dhBase,
const std::shared_ptr<DCameraHDFEvent> &event)
int32_t DCameraProvider::Notify(const DHBase& dhBase, const DCameraHDFEvent& event)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::Notify, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::Notify for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
OHOS::sptr<DCameraDevice> device = GetDCameraDevice(dhBase);
if (device == nullptr) {
@@ -178,17 +162,17 @@ DCamRetCode DCameraProvider::Notify(const std::shared_ptr<DHBase> &dhBase,
return DCamRetCode::INVALID_ARGUMENT;
}
return device->Notify(event);
std::shared_ptr<DCameraHDFEvent> dCameraEvent = std::make_shared<DCameraHDFEvent>();
dCameraEvent->type_ = event.type_;
dCameraEvent->result_ = event.result_;
dCameraEvent->content_ = event.content_;
return device->Notify(dCameraEvent);
}
DCamRetCode DCameraProvider::OpenSession(const std::shared_ptr<DHBase> &dhBase)
int32_t DCameraProvider::OpenSession(const DHBase &dhBase)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::OpenSession, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::OpenSession for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
sptr<IDCameraProviderCallback> callback = GetCallbackBydhBase(dhBase);
if (callback == nullptr) {
@@ -199,14 +183,10 @@ DCamRetCode DCameraProvider::OpenSession(const std::shared_ptr<DHBase> &dhBase)
return callback->OpenSession(dhBase);
}
DCamRetCode DCameraProvider::CloseSession(const std::shared_ptr<DHBase> &dhBase)
int32_t DCameraProvider::CloseSession(const DHBase &dhBase)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::CloseSession, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::CloseSession for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
sptr<IDCameraProviderCallback> callback = GetCallbackBydhBase(dhBase);
if (callback == nullptr) {
@@ -217,15 +197,10 @@ DCamRetCode DCameraProvider::CloseSession(const std::shared_ptr<DHBase> &dhBase)
return callback->CloseSession(dhBase);
}
DCamRetCode DCameraProvider::ConfigureStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCStreamInfo>> &streamInfos)
int32_t DCameraProvider::ConfigureStreams(const DHBase &dhBase, const std::vector<DCStreamInfo> &streamInfos)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::ConfigureStreams, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::ConfigureStreams for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
sptr<IDCameraProviderCallback> callback = GetCallbackBydhBase(dhBase);
if (callback == nullptr) {
@@ -233,22 +208,17 @@ DCamRetCode DCameraProvider::ConfigureStreams(const std::shared_ptr<DHBase> &dhB
return DCamRetCode::INVALID_ARGUMENT;
}
for (auto info : streamInfos) {
for (auto info = streamInfos.begin(); info != streamInfos.end(); info++) {
DHLOGI("ConfigureStreams: id=%d, width=%d, height=%d, format=%d, " +
"type=%d.", info->streamId_, info->width_, info->height_, info->format_, info->type_);
}
return callback->ConfigureStreams(dhBase, streamInfos);
}
DCamRetCode DCameraProvider::ReleaseStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds)
int32_t DCameraProvider::ReleaseStreams(const DHBase &dhBase, const std::vector<int> &streamIds)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::ReleaseStreams, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::ReleaseStreams for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
sptr<IDCameraProviderCallback> callback = GetCallbackBydhBase(dhBase);
if (callback == nullptr) {
@@ -264,15 +234,10 @@ DCamRetCode DCameraProvider::ReleaseStreams(const std::shared_ptr<DHBase> &dhBas
return callback->ReleaseStreams(dhBase, streamIds);
}
DCamRetCode DCameraProvider::StartCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCCaptureInfo>> &captureInfos)
int32_t DCameraProvider::StartCapture(const DHBase &dhBase, const std::vector<DCCaptureInfo> &captureInfos)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::StartCapture, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::StartCapture for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
sptr<IDCameraProviderCallback> callback = GetCallbackBydhBase(dhBase);
if (callback == nullptr) {
@@ -280,7 +245,7 @@ DCamRetCode DCameraProvider::StartCapture(const std::shared_ptr<DHBase> &dhBase,
return DCamRetCode::INVALID_ARGUMENT;
}
for (auto info : captureInfos) {
for (auto info = captureInfos.begin(); info != captureInfos.end(); info++) {
std::string idString = "";
for (int id : info->streamIds_) {
idString += (std::to_string(id) + ", ");
@@ -292,15 +257,10 @@ DCamRetCode DCameraProvider::StartCapture(const std::shared_ptr<DHBase> &dhBase,
return callback->StartCapture(dhBase, captureInfos);
}
DCamRetCode DCameraProvider::StopCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds)
int32_t DCameraProvider::StopCapture(const DHBase &dhBase, const std::vector<int> &streamIds)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::StopCapture, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::StopCapture for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
sptr<IDCameraProviderCallback> callback = GetCallbackBydhBase(dhBase);
if (callback == nullptr) {
@@ -317,15 +277,10 @@ DCamRetCode DCameraProvider::StopCapture(const std::shared_ptr<DHBase> &dhBase,
return callback->StopCapture(dhBase, streamIds);
}
DCamRetCode DCameraProvider::UpdateSettings(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCameraSettings>> &settings)
int32_t DCameraProvider::UpdateSettings(const DHBase &dhBase, const std::vector<DCameraSettings> &settings)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::UpdateSettings, dhBase is null.");
return DCamRetCode::INVALID_ARGUMENT;
}
DHLOGI("DCameraProvider::UpdateSettings for {devId: %s, dhId: %s}.",
GetAnonyString(dhBase->deviceId_).c_str(), GetAnonyString(dhBase->dhId_).c_str());
GetAnonyString(dhBase.deviceId_).c_str(), GetAnonyString(dhBase.dhId_).c_str());
sptr<IDCameraProviderCallback> callback = GetCallbackBydhBase(dhBase);
if (callback == nullptr) {
@@ -336,18 +291,14 @@ DCamRetCode DCameraProvider::UpdateSettings(const std::shared_ptr<DHBase> &dhBas
return callback->UpdateSettings(dhBase, settings);
}
bool DCameraProvider::IsDhBaseInfoInvalid(const std::shared_ptr<DHBase> &dhBase)
bool DCameraProvider::IsDhBaseInfoInvalid(const DHBase &dhBase)
{
return dhBase == nullptr || dhBase->deviceId_.empty() || (dhBase->deviceId_.size() > DEVID_MAX_LENGTH) ||
dhBase->dhId_.empty() || (dhBase->dhId_.size() > DHID_MAX_LENGTH);
return dhBase.deviceId_.empty() || (dhBase.deviceId_.size() > DEVID_MAX_LENGTH) ||
dhBase.dhId_.empty() || (dhBase.dhId_.size() > DHID_MAX_LENGTH);
}
sptr<IDCameraProviderCallback> DCameraProvider::GetCallbackBydhBase(const std::shared_ptr<DHBase> &dhBase)
sptr<IDCameraProviderCallback> DCameraProvider::GetCallbackBydhBase(const DHBase &dhBase)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::GetCallbackBydhBase, dhBase is null.");
return nullptr;
}
OHOS::sptr<DCameraDevice> device = GetDCameraDevice(dhBase);
if (device == nullptr) {
DHLOGE("DCameraProvider::GetCallbackBydhBase failed, dcamera device not found.");
@@ -356,12 +307,8 @@ sptr<IDCameraProviderCallback> DCameraProvider::GetCallbackBydhBase(const std::s
return device->GetProviderCallback();
}
OHOS::sptr<DCameraDevice> DCameraProvider::GetDCameraDevice(const std::shared_ptr<DHBase> &dhBase)
OHOS::sptr<DCameraDevice> DCameraProvider::GetDCameraDevice(const DHBase &dhBase)
{
if (dhBase == nullptr) {
DHLOGE("DCameraProvider::GetDCameraDevice, dhBase is null.");
return nullptr;
}
std::shared_ptr<DCameraHost> dCameraHost = DCameraHost::GetInstance();
if (dCameraHost == nullptr) {
DHLOGE("DCameraProvider::GetDCameraDevice, dcamera host is null.");
@@ -26,7 +26,7 @@ std::shared_ptr<DImageBuffer> DBufferManager::AcquireBuffer()
if (!idleList_.empty()) {
auto it = idleList_.begin();
busyList_.splice(busyList_.begin(), idleList_, it);
DHLOGI("Acquire buffer success, index = %d", (*it)->GetIndex());
DHLOGD("Acquire buffer success, index = %d", (*it)->GetIndex());
return *it;
}
return nullptr;
@@ -140,7 +140,7 @@ uint32_t DBufferManager::PixelFormatToDCameraFormat(const PixelFormat format)
}
RetCode DBufferManager::DImageBufferToDCameraBuffer(const std::shared_ptr<DImageBuffer> &imageBuffer,
std::shared_ptr<DCameraBuffer> &buffer)
DCameraBuffer &buffer)
{
BufferHandle *bufHandle = imageBuffer->GetBufferHandle();
if (bufHandle == nullptr) {
@@ -151,10 +151,9 @@ RetCode DBufferManager::DImageBufferToDCameraBuffer(const std::shared_ptr<DImage
DHLOGE("Convert image surface buffer failed, BufferHandle is invalid.");
return RC_ERROR;
}
buffer->index_ = imageBuffer->GetIndex();
buffer->size_ = imageBuffer->GetSize();
buffer->bufferHandle_ = bufHandle;
buffer.index_ = imageBuffer->GetIndex();
buffer.size_ = imageBuffer->GetSize();
buffer.bufferHandle_ = new BufferHandleSequenceable(bufHandle);
return RC_OK;
}
} // namespace DistributedHardware
@@ -210,7 +210,7 @@ DCamRetCode DCameraStream::GetNextRequest()
DHLOGE("Add buffer to buffer manager failed. [streamId = %d]", dcStreamInfo_->streamId_);
return DCamRetCode::EXCEED_MAX_NUMBER;
}
DHLOGI("Add new image buffer success: index = %d, fence = %d", imageBuffer->GetIndex(), fence);
DHLOGD("Add new image buffer success: index = %d, fence = %d", imageBuffer->GetIndex(), fence);
auto itr = bufferConfigMap_.find(imageBuffer);
if (itr == bufferConfigMap_.end()) {
@@ -221,7 +221,7 @@ DCamRetCode DCameraStream::GetNextRequest()
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraStream::GetDCameraBuffer(shared_ptr<DCameraBuffer> &buffer)
DCamRetCode DCameraStream::GetDCameraBuffer(DCameraBuffer &buffer)
{
DCamRetCode retCode = GetNextRequest();
if (retCode != DCamRetCode::SUCCESS && retCode != DCamRetCode::EXCEED_MAX_NUMBER) {
@@ -242,28 +242,23 @@ DCamRetCode DCameraStream::GetDCameraBuffer(shared_ptr<DCameraBuffer> &buffer)
}
captureBufferCount_++;
DHLOGI("Get buffer success. address = %p, index = %d, size = %d", buffer->bufferHandle_->virAddr,
buffer->index_, buffer->size_);
DHLOGD("Get buffer success. address = %p, index = %d, size = %d", buffer.bufferHandle_->GetBufferHandle()->virAddr,
buffer.index_, buffer.size_);
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraStream::ReturnDCameraBuffer(const shared_ptr<DCameraBuffer> &buffer)
DCamRetCode DCameraStream::ReturnDCameraBuffer(const DCameraBuffer &buffer)
{
if (buffer == nullptr) {
DHLOGE("result buffer is null. [streamId = %d]", dcStreamInfo_->streamId_);
return DCamRetCode::INVALID_ARGUMENT;
}
shared_ptr<DImageBuffer> imageBuffer = nullptr;
map<shared_ptr<DImageBuffer>, tuple<OHOS::sptr<OHOS::SurfaceBuffer>, int, int>>::iterator iter;
for (iter = bufferConfigMap_.begin(); iter != bufferConfigMap_.end(); ++iter) {
if (buffer->index_ == iter->first->GetIndex()) {
if (buffer.index_ == iter->first->GetIndex()) {
imageBuffer = iter->first;
break;
}
}
if (imageBuffer == nullptr) {
DHLOGE("Cannot found image buffer, buffer index = %d.", buffer->index_);
DHLOGE("Cannot found image buffer, buffer index = %d.", buffer.index_);
return DCamRetCode::INVALID_ARGUMENT;
}
@@ -275,7 +270,7 @@ DCamRetCode DCameraStream::ReturnDCameraBuffer(const shared_ptr<DCameraBuffer> &
auto bufCfg = bufferConfigMap_.find(imageBuffer);
if (bufCfg == bufferConfigMap_.end()) {
DHLOGE("Cannot get bufferConfig.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
auto surfaceBuffer = std::get<0>(bufCfg->second);
int32_t fence = std::get<1>(bufCfg->second);
@@ -18,7 +18,6 @@
#include "dcamera_provider.h"
#include "dcamera.h"
#include "distributed_hardware_log.h"
#include "json/json.h"
#include "metadata_utils.h"
namespace OHOS {
@@ -120,21 +119,34 @@ CamRetCode DStreamOperator::ReleaseStreams(const std::vector<int>& streamIds)
}
}
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider == nullptr) {
DHLOGE("Distributed camera provider not init.");
return CamRetCode::DEVICE_ERROR;
}
DCamRetCode ret = provider->ReleaseStreams(dhBase_, streamIds);
int32_t ret = provider->ReleaseStreams(dhBase_, streamIds);
if (ret != SUCCESS) {
DHLOGE("Release distributed camera streams failed.");
return MapToExternalRetCode(ret);
return MapToExternalRetCode(static_cast<DCamRetCode>(ret));
}
DHLOGI("DStreamOperator::Release distributed camera streams success.");
return CamRetCode::NO_ERROR;
}
void DStreamOperator::ExtractStreamInfo(DCStreamInfo &dstStreamInfo,
const std::shared_ptr<DCStreamInfo> &srcStreamInfo)
{
dstStreamInfo.streamId_ = srcStreamInfo->streamId_;
dstStreamInfo.width_ = srcStreamInfo->width_;
dstStreamInfo.height_ = srcStreamInfo->height_;
dstStreamInfo.stride_ = srcStreamInfo->stride_;
dstStreamInfo.format_ = srcStreamInfo->format_;
dstStreamInfo.dataspace_ = srcStreamInfo->dataspace_;
dstStreamInfo.encodeType_ = srcStreamInfo->encodeType_;
dstStreamInfo.type_ = srcStreamInfo->type_;
}
CamRetCode DStreamOperator::CommitStreams(OperationMode mode,
const std::shared_ptr<Camera::CameraMetadata>& modeSetting)
{
@@ -157,30 +169,32 @@ CamRetCode DStreamOperator::CommitStreams(OperationMode mode,
DHLOGE("No stream to commit.");
return CamRetCode::INVALID_ARGUMENT;
}
std::vector<std::shared_ptr<DCStreamInfo>> dCameraStreams;
std::vector<DCStreamInfo> dCameraStreams;
for (auto streamInfo : dcStreamInfoMap_) {
dCameraStreams.push_back(streamInfo.second);
DCStreamInfo stream;
ExtractStreamInfo(stream, streamInfo.second);
dCameraStreams.push_back(stream);
}
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider == nullptr) {
DHLOGE("Distributed camera provider not init.");
return CamRetCode::DEVICE_ERROR;
}
DCamRetCode ret = provider->ConfigureStreams(dhBase_, dCameraStreams);
int32_t ret = provider->ConfigureStreams(dhBase_, dCameraStreams);
if (ret != DCamRetCode::SUCCESS) {
DHLOGE("Commit distributed camera streams failed.");
return MapToExternalRetCode(ret);
return MapToExternalRetCode(static_cast<DCamRetCode>(ret));
}
for (size_t i = 0; i < dCameraStreams.size(); i++) {
auto streamInfo = dCameraStreams[i];
for (auto halStream : halStreamMap_) {
if (streamInfo->streamId_ == halStream.first) {
if (streamInfo.streamId_ == halStream.first) {
ret = halStream.second->FinishCommitStream();
if (ret != DCamRetCode::SUCCESS) {
DHLOGE("Stream %d cannot init.", streamInfo->streamId_);
return MapToExternalRetCode(ret);
DHLOGE("Stream %d cannot init.", streamInfo.streamId_);
return MapToExternalRetCode(static_cast<DCamRetCode>(ret));
}
}
}
@@ -245,6 +259,24 @@ CamRetCode DStreamOperator::DetachBufferQueue(int streamId)
}
}
void DStreamOperator::ExtractCaptureInfo(std::vector<DCCaptureInfo> &captureInfos)
{
for (auto &captureInfo : cachedDCaptureInfoList_) {
DCCaptureInfo capture;
capture.streamIds_.assign(captureInfo->streamIds_.begin(), captureInfo->streamIds_.end());
capture.width_ = captureInfo->width_;
capture.height_ = captureInfo->height_;
capture.stride_ = captureInfo->stride_;
capture.format_ = captureInfo->format_;
capture.dataspace_ = captureInfo->dataspace_;
capture.isCapture_ = captureInfo->isCapture_;
capture.encodeType_ = captureInfo->encodeType_;
capture.type_ = captureInfo->type_;
capture.captureSettings_.assign(captureInfo->captureSettings_.begin(), captureInfo->captureSettings_.end());
captureInfos.emplace_back(capture);
}
}
CamRetCode DStreamOperator::Capture(int captureId, const std::shared_ptr<CaptureInfo>& captureInfo, bool isStreaming)
{
if (captureId < 0 || halCaptureInfoMap_.find(captureId) != halCaptureInfoMap_.end()) {
@@ -277,15 +309,17 @@ CamRetCode DStreamOperator::Capture(int captureId, const std::shared_ptr<Capture
return MapToExternalRetCode(ret);
}
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider == nullptr) {
DHLOGE("Distributed camera provider not init.");
return CamRetCode::DEVICE_ERROR;
}
ret = provider->StartCapture(dhBase_, cachedDCaptureInfoList_);
if (ret != SUCCESS) {
std::vector<DCCaptureInfo> captureInfos;
ExtractCaptureInfo(captureInfos);
int32_t retProv = provider->StartCapture(dhBase_, captureInfos);
if (retProv != SUCCESS) {
DHLOGE("Start distributed camera capture failed.");
return MapToExternalRetCode(ret);
return MapToExternalRetCode(static_cast<DCamRetCode>(retProv));
}
halCaptureInfoMap_[captureId] = captureInfo;
@@ -308,17 +342,17 @@ CamRetCode DStreamOperator::CancelCapture(int captureId)
return CamRetCode::INVALID_ARGUMENT;
}
std::shared_ptr<DCameraProvider> provider = DCameraProvider::GetInstance();
OHOS::sptr<DCameraProvider> provider = DCameraProvider::GetInstance();
if (provider == nullptr) {
DHLOGE("Distributed camera provider not init.");
return CamRetCode::DEVICE_ERROR;
}
std::vector<int> streamIds = halCaptureInfoMap_[captureId]->streamIds_;
DCamRetCode ret = provider->StopCapture(dhBase_, streamIds);
int32_t ret = provider->StopCapture(dhBase_, streamIds);
if (ret != SUCCESS) {
DHLOGE("Cancel distributed camera capture failed.");
return MapToExternalRetCode(ret);
return MapToExternalRetCode(static_cast<DCamRetCode>(ret));
}
std::vector<std::shared_ptr<CaptureEndedInfo>> info;
@@ -378,22 +412,9 @@ CamRetCode DStreamOperator::ChangeToOfflineStream(const std::vector<int>& stream
return CamRetCode::METHOD_NOT_SUPPORTED;
}
DCamRetCode DStreamOperator::InitOutputConfigurations(const std::shared_ptr<DHBase> &dhBase,
const std::string &abilityInfo)
void DStreamOperator::ExtractCameraAttr(Json::Value &rootValue, std::set<int> &allFormats,
std::vector<int> &photoFormats)
{
dhBase_ = dhBase;
JSONCPP_STRING errs;
Json::CharReaderBuilder readerBuilder;
Json::Value rootValue;
std::unique_ptr<Json::CharReader> const jsonReader(readerBuilder.newCharReader());
if (!jsonReader->parse(abilityInfo.c_str(), abilityInfo.c_str() + abilityInfo.length(), &rootValue, &errs) ||
!rootValue.isObject()) {
DHLOGE("Input ablity info is not json object.");
return INVALID_ARGUMENT;
}
if (rootValue["CodecType"].isArray()) {
uint32_t size = rootValue["CodecType"].size();
for (uint32_t i = 0; i < size; i++) {
@@ -402,7 +423,6 @@ DCamRetCode DStreamOperator::InitOutputConfigurations(const std::shared_ptr<DHBa
}
}
std::set<int> allFormats;
if (rootValue["OutputFormat"]["Preview"].isArray() && (rootValue["OutputFormat"]["Preview"].size() > 0)) {
std::vector<int> previewFormats;
uint32_t size = rootValue["OutputFormat"]["Preview"].size();
@@ -423,7 +443,6 @@ DCamRetCode DStreamOperator::InitOutputConfigurations(const std::shared_ptr<DHBa
dcSupportedFormatMap_[DCSceneType::VIDEO] = videoFormats;
}
std::vector<int> photoFormats;
if (rootValue["OutputFormat"]["Photo"].isArray() && (rootValue["OutputFormat"]["Photo"].size() > 0)) {
uint32_t size = rootValue["OutputFormat"]["Photo"].size();
for (uint32_t i = 0; i < size; i++) {
@@ -432,6 +451,26 @@ DCamRetCode DStreamOperator::InitOutputConfigurations(const std::shared_ptr<DHBa
}
dcSupportedFormatMap_[DCSceneType::PHOTO] = photoFormats;
}
}
DCamRetCode DStreamOperator::InitOutputConfigurations(const DHBase &dhBase, const std::string &abilityInfo)
{
dhBase_ = dhBase;
JSONCPP_STRING errs;
Json::CharReaderBuilder readerBuilder;
Json::Value rootValue;
std::unique_ptr<Json::CharReader> const jsonReader(readerBuilder.newCharReader());
if (!jsonReader->parse(abilityInfo.c_str(), abilityInfo.c_str() + abilityInfo.length(), &rootValue, &errs) ||
!rootValue.isObject()) {
DHLOGE("Input ablity info is not json object.");
return DCamRetCode::INVALID_ARGUMENT;
}
std::set<int> allFormats;
std::vector<int> photoFormats;
ExtractCameraAttr(rootValue, allFormats, photoFormats);
for (const auto &format : allFormats) {
bool isPhotoFormat = count(photoFormats.begin(), photoFormats.end(), format);
@@ -471,7 +510,7 @@ DCamRetCode DStreamOperator::InitOutputConfigurations(const std::shared_ptr<DHBa
return SUCCESS;
}
DCamRetCode DStreamOperator::AcquireBuffer(int streamId, std::shared_ptr<DCameraBuffer> &buffer)
DCamRetCode DStreamOperator::AcquireBuffer(int streamId, DCameraBuffer &buffer)
{
std::unique_lock<std::mutex> lock(requestLock_);
if (!IsCapturing()) {
@@ -494,9 +533,9 @@ DCamRetCode DStreamOperator::AcquireBuffer(int streamId, std::shared_ptr<DCamera
return ret;
}
DCamRetCode DStreamOperator::ShutterBuffer(int streamId, const std::shared_ptr<DCameraBuffer> &buffer)
DCamRetCode DStreamOperator::ShutterBuffer(int streamId, const DCameraBuffer &buffer)
{
DHLOGI("DStreamOperator::ShutterBuffer begin shutter buffer for streamId = %d", streamId);
DHLOGD("DStreamOperator::ShutterBuffer begin shutter buffer for streamId = %d", streamId);
int32_t captureId = -1;
for (auto iter = halCaptureInfoMap_.begin(); iter != halCaptureInfoMap_.end(); iter++) {
@@ -644,9 +683,9 @@ void DStreamOperator::ConvertStreamInfo(std::shared_ptr<StreamInfo> &srcInfo, st
if ((srcInfo->intent_ == STILL_CAPTURE) || (srcInfo->intent_ == POST_VIEW)) {
dstInfo->type_ = DCStreamType::SNAPSHOT_FRAME;
if (dstInfo->encodeType_ == ENCODE_TYPE_JPEG) {
if (dstInfo->encodeType_ == DCEncodeType::ENCODE_TYPE_JPEG) {
dstInfo->format_ = OHOS_CAMERA_FORMAT_JPEG;
} else if (dstInfo->encodeType_ == ENCODE_TYPE_NULL) {
} else if (dstInfo->encodeType_ == DCEncodeType::ENCODE_TYPE_NULL) {
dstInfo->format_ = OHOS_CAMERA_FORMAT_YCRCB_420_SP;
}
} else {
@@ -668,7 +707,7 @@ DCamRetCode DStreamOperator::NegotiateSuitableCaptureInfo(const std::shared_ptr<
}
if (srcStreamInfo.empty()) {
DHLOGE("Input source stream info vector is empty.");
return INVALID_ARGUMENT;
return DCamRetCode::INVALID_ARGUMENT;
}
std::shared_ptr<DCCaptureInfo> inputCaptureInfo = BuildSuitableCaptureInfo(srcCaptureInfo, srcStreamInfo);
@@ -722,10 +761,10 @@ std::shared_ptr<DCCaptureInfo> DStreamOperator::BuildSuitableCaptureInfo(const s
ChooseSuitableDataSpace(srcStreamInfo, captureInfo);
ChooseSuitableEncodeType(srcStreamInfo, captureInfo);
std::shared_ptr<DCameraSettings> dcSetting = std::make_shared<DCameraSettings>();
dcSetting->type_ = DCSettingsType::UPDATE_METADATA;
DCameraSettings dcSetting;
dcSetting.type_ = DCSettingsType::UPDATE_METADATA;
std::string settingStr = Camera::MetadataUtils::EncodeToString(srcCaptureInfo->captureSetting_);
dcSetting->value_ = Base64Encode(reinterpret_cast<const unsigned char *>(settingStr.c_str()), settingStr.length());
dcSetting.value_ = Base64Encode(reinterpret_cast<const unsigned char *>(settingStr.c_str()), settingStr.length());
captureInfo->captureSettings_.push_back(dcSetting);
+1 -4
View File
@@ -24,15 +24,12 @@ ohos_executable("dcamera_hdi_sample") {
]
include_dirs = [
"${distributedcamera_hdf_path}/interfaces/include",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/client/device",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/client/host",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/client/operator",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/client/provider",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/device",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/host",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/operator",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/provider",
"${distributedcamera_hdf_path}/hdi_impl/include/dcamera_device",
"${distributedcamera_hdf_path}/hdi_impl/include/dcamera_host",
"${distributedcamera_hdf_path}/hdi_impl/include/dcamera_provider",
@@ -62,7 +59,6 @@ ohos_executable("dcamera_hdi_sample") {
]
deps = [
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/client:distributed_camera_hdf_client",
"${fwk_utils_path}:distributedhardwareutils",
"${fwk_utils_path}:distributedhardwareutils",
"${hdf_uhdf_path}/hdi:libhdi",
@@ -72,6 +68,7 @@ ohos_executable("dcamera_hdi_sample") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
"samgr_standard:samgr_proxy",
+2 -1
View File
@@ -34,7 +34,6 @@
#include "display_type.h"
#include "distributed_hardware_log.h"
#include "drivers/peripheral/camera/interfaces/include/types.h"
#include "foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/include/types.h"
#include "icamera_device.h"
#include "icamera_host.h"
#include "idistributed_hardware_source.h"
@@ -51,9 +50,11 @@
#include "dcamera_host_callback.h"
#include "dcamera_host_proxy.h"
#include "dstream_operator_callback.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class Test {
public:
void Init();
@@ -1,83 +0,0 @@
# Copyright (c) 2021-2022 Huawei Device 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.
import("//build/ohos.gni")
import("//drivers/adapter/uhdf2/uhdf.gni")
import(
"//foundation/distributedhardware/distributed_camera/distributedcamera.gni")
ohos_shared_library("distributed_camera_hdf_client") {
include_dirs = [
"../",
"../../include",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"${camera_hdf_path}/camera/interfaces/include",
"${camera_hdf_path}/camera/interfaces/hdi_ipc",
"${distributedcamera_hdf_path}/hdi_impl/include/utils",
"${hdf_framework_path}/include/utils",
"${hdf_uhdf_path}/include/hdi",
"${hdf_uhdf_path}/osal/include",
"//drivers/peripheral/base",
"//drivers/peripheral/camera/interfaces/metadata/include",
]
cflags = [
"-fPIC",
"-Wall",
]
if ("${product_name}" == "m40") {
cflags += [ "-DPRODUCT_M40" ]
}
sources = [
"device/dcamera_device_callback.cpp",
"device/dcamera_device_callback_stub.cpp",
"device/dcamera_device_proxy.cpp",
"host/dcamera_host_callback.cpp",
"host/dcamera_host_callback_stub.cpp",
"host/dcamera_host_proxy.cpp",
"operator/doffline_stream_operator_proxy.cpp",
"operator/dstream_operator_callback.cpp",
"operator/dstream_operator_callback_stub.cpp",
"operator/dstream_operator_proxy.cpp",
"provider/dcamera_provider_callback.cpp",
"provider/dcamera_provider_callback_stub.cpp",
"provider/dcamera_provider_proxy.cpp",
]
deps = [
"${distributedcamera_hdf_path}/hdi_impl:distributed_camera_hdf",
"${hdf_uhdf_path}/hdi:libhdi",
"//drivers/peripheral/camera/interfaces/metadata:metadata",
"//utils/native/base:utils",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"distributedcamerahdf\"",
"LOG_DOMAIN=0xD004100",
]
external_deps = [
"graphic_chipsetsdk:buffer_handle",
"graphic_chipsetsdk:surface",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
]
cflags_cc = cflags
subsystem_name = "distributedhardware"
part_name = "distributed_camera"
}
@@ -1,64 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_device_callback_stub.h"
#include <hdf_base.h>
#include "cmd_common.h"
#include "dcamera_device_callback.h"
#include "distributed_hardware_log.h"
#include "ipc_data_utils.h"
#include "metadata_utils.h"
namespace OHOS {
namespace DistributedHardware {
int32_t DCameraDeviceCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
switch (code) {
case CMD_CAMERA_DEVICE_CALLBACK_ON_ERROR: {
if (data.ReadInterfaceToken() != DCameraDeviceCallbackStub::GetDescriptor()) {
DHLOGI("DCameraDeviceCallbackStub::OnError token failed.");
return HDF_FAILURE;
}
ErrorType type = static_cast<ErrorType>(data.ReadUint32());
int32_t errorMsg = data.ReadInt32();
DHLOGI("DCameraDeviceCallbackStub::OnError entry.");
OnError(type, errorMsg);
break;
}
case CMD_CAMERA_DEVICE_CALLBACK_ON_RESULT: {
if (data.ReadInterfaceToken() != DCameraDeviceCallbackStub::GetDescriptor()) {
DHLOGI("DCameraDeviceCallbackStub::OnResult token failed.");
return HDF_FAILURE;
}
uint64_t timestamp = data.ReadUint64();
std::shared_ptr<Camera::CameraMetadata> result = nullptr;
Camera::MetadataUtils::DecodeCameraMetadata(data, result);
DHLOGI("DCameraDeviceCallbackStub::OnResult entry.");
OnResult(timestamp, result);
break;
}
default: {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
return 0;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,36 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_DEVICE_CALLBACK_CLIENT_STUB_H
#define DISTRIBUTED_CAMERA_DEVICE_CALLBACK_CLIENT_STUB_H
#include "icamera_device_callback.h"
#include "iremote_stub.h"
#include "message_parcel.h"
#include "parcel.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DCameraDeviceCallbackStub : public IRemoteStub<ICameraDeviceCallback> {
public:
virtual ~DCameraDeviceCallbackStub() = default;
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option) override;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_DEVICE_CALLBACK_CLIENT_STUB_H
@@ -1,208 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_device_proxy.h"
#include <hdf_base.h>
#include <message_parcel.h>
#include "cmd_common.h"
#include "distributed_hardware_log.h"
#include "ipc_data_utils.h"
#include "istream_operator.h"
#include "istream_operator_callback.h"
#include "metadata_utils.h"
namespace OHOS {
namespace DistributedHardware {
CamRetCode DCameraDeviceProxy::GetStreamOperator(
const OHOS::sptr<IStreamOperatorCallback> &callback,
OHOS::sptr<IStreamOperator> &streamOperator)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraDeviceProxy::GetDescriptor())) {
DHLOGE("Write stream operator descriptor failed.");
return CamRetCode::INVALID_ARGUMENT;
}
bool nullFlag = (callback != nullptr);
if (!data.WriteBool(nullFlag)) {
DHLOGE("Write stream operator callback flag failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (nullFlag && !data.WriteRemoteObject(callback->AsObject())) {
DHLOGE("Write stream operator object failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_DEVICE_REMOTE_GET_STREAM_OPERATOR, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
CamRetCode retCode = static_cast<CamRetCode>(reply.ReadInt32());
bool flag = reply.ReadBool();
if (flag) {
sptr<IRemoteObject> remoteStreamOperator = reply.ReadRemoteObject();
streamOperator = OHOS::iface_cast<IStreamOperator>(remoteStreamOperator);
}
return retCode;
}
CamRetCode DCameraDeviceProxy::UpdateSettings(const std::shared_ptr<CameraSetting> &settings)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraDeviceProxy::GetDescriptor())) {
DHLOGE("Write stream operator descriptor failed.");
return CamRetCode::INVALID_ARGUMENT;
}
bool bRet = Camera::MetadataUtils::EncodeCameraMetadata(settings, data);
if (!bRet) {
DHLOGE("Write update settings metadata failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_DEVICE_UPDATE_SETTINGS, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DCameraDeviceProxy::SetResultMode(const ResultCallbackMode &mode)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraDeviceProxy::GetDescriptor())) {
DHLOGE("Write stream operator descriptor failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32(static_cast<int32_t>(mode))) {
DHLOGE("Write result callback mode failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_DEVICE_REMOTE_SET_RESULT_MODE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DCameraDeviceProxy::GetEnabledResults(std::vector<MetaType> &results)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraDeviceProxy::GetDescriptor())) {
DHLOGE("Write stream operator descriptor failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_DEVICE_REMOTE_GET_ENABLED_RESULTS, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
CamRetCode retCode = static_cast<CamRetCode>(reply.ReadInt32());
if (!reply.ReadInt32Vector(&results)) {
DHLOGE("Read results failed.");
return CamRetCode::INVALID_ARGUMENT;
}
return retCode;
}
CamRetCode DCameraDeviceProxy::EnableResult(const std::vector<MetaType> &results)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraDeviceProxy::GetDescriptor())) {
DHLOGE("Write stream operator descriptor failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32Vector(results)) {
DHLOGE("Write results failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_DEVICE_REMOTE_ENABLE_RESULT, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DCameraDeviceProxy::DisableResult(const std::vector<MetaType> &results)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraDeviceProxy::GetDescriptor())) {
DHLOGE("Write stream operator descriptor failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32Vector(results)) {
DHLOGE("Write results failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_DEVICE_REMOTE_DISABLE_RESULT, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
void DCameraDeviceProxy::Close()
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraDeviceProxy::GetDescriptor())) {
DHLOGE("Write stream operator descriptor failed.");
return;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_DEVICE_REMOTE_CLOSE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
}
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,53 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_DEVICE_CLIENT_PROXY_H
#define DISTRIBUTED_CAMERA_DEVICE_CLIENT_PROXY_H
#include "iremote_proxy.h"
#include "icamera_device.h"
#include "istream_operator_callback.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DCameraDeviceProxy : public IRemoteProxy<ICameraDevice> {
public:
explicit DCameraDeviceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<ICameraDevice>(impl) {}
virtual ~DCameraDeviceProxy() = default;
virtual CamRetCode GetStreamOperator(const OHOS::sptr<IStreamOperatorCallback> &callback,
OHOS::sptr<IStreamOperator> &streamOperator) override;
virtual CamRetCode UpdateSettings(const std::shared_ptr<CameraSetting> &settings) override;
virtual CamRetCode SetResultMode(const ResultCallbackMode &mode) override;
virtual CamRetCode GetEnabledResults(std::vector<MetaType> &results) override;
virtual CamRetCode EnableResult(const std::vector<MetaType> &results) override;
virtual CamRetCode DisableResult(const std::vector<MetaType> &results) override;
virtual void Close() override;
private:
static constexpr int CMD_CAMERA_DEVICE_REMOTE_GET_STREAM_OPERATOR = 0;
static constexpr int CMD_CAMERA_DEVICE_REMOTE_UPDATE_SERTTINGS = 1;
static constexpr int CMD_CAMERA_DEVICE_REMOTE_SET_RESULT_MODE = 2;
static constexpr int CMD_CAMERA_DEVICE_REMOTE_GET_ENABLED_RESULTS = 3;
static constexpr int CMD_CAMERA_DEVICE_REMOTE_ENABLE_RESULT = 4;
static constexpr int CMD_CAMERA_DEVICE_REMOTE_DISABLE_RESULT = 5;
static constexpr int CMD_CAMERA_DEVICE_REMOTE_CLOSE = 6;
static inline BrokerDelegator<DCameraDeviceProxy> delegator_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_DEVICE_CLIENT_PROXY_H
@@ -1,36 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_host_callback.h"
#include "distributed_hardware_log.h"
namespace OHOS {
namespace DistributedHardware {
void DCameraHostCallback::OnCameraStatus(const std::string &cameraId, CameraStatus status)
{
DHLOGW("DCameraHostCallback::OnCameraStatus enter.");
}
void DCameraHostCallback::OnFlashlightStatus(const std::string &cameraId, FlashlightStatus status)
{
DHLOGW("DCameraHostCallback::OnFlashlightStatus enter.");
}
void DCameraHostCallback::OnCameraEvent(const std::string &cameraId, CameraEvent event)
{
DHLOGW("DCameraHostCallback::OnCameraEvent enter.");
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,36 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_HOST_CALLBACK_H
#define DISTRIBUTED_CAMERA_HOST_CALLBACK_H
#include "dcamera_host_callback_stub.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DCameraHostCallback : public DCameraHostCallbackStub {
public:
DCameraHostCallback() = default;
virtual ~DCameraHostCallback() = default;
public:
virtual void OnCameraStatus(const std::string &cameraId, CameraStatus status) override;
virtual void OnFlashlightStatus(const std::string &cameraId, FlashlightStatus status) override;
virtual void OnCameraEvent(const std::string &cameraId, CameraEvent event) override;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_HOST_CALLBACK_H
@@ -1,73 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_host_callback_stub.h"
#include <hdf_base.h>
#include "cmd_common.h"
#include "dcamera_host_callback.h"
#include "distributed_hardware_log.h"
namespace OHOS {
namespace DistributedHardware {
int32_t DCameraHostCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
switch (code) {
case CMD_CAMERA_HOST_CALLBACK_ON_STATUS: {
DHLOGI("DCameraHostCallbackStub::OnCameraStatus entry.");
if (data.ReadInterfaceToken() != DCameraHostCallbackStub::GetDescriptor()) {
DHLOGI("DCameraDeviceCallbackStub::OnCameraStatus token failed.");
return HDF_FAILURE;
}
std::string cameraId = data.ReadString();
CameraStatus status = static_cast<CameraStatus>(data.ReadInt32());
OnCameraStatus(cameraId, status);
break;
}
case CMD_CAMERA_HOST_CALLBACK_ON_FLASHLIGHT_STATUS: {
DHLOGI("DCameraHostCallbackStub::OnFlashlightStatus entry.");
if (data.ReadInterfaceToken() != DCameraHostCallbackStub::GetDescriptor()) {
DHLOGI("DCameraDeviceCallbackStub::OnFlashlightStatus token failed.");
return HDF_FAILURE;
}
std::string cameraId = data.ReadString();
FlashlightStatus status = static_cast<FlashlightStatus>(data.ReadInt32());
OnFlashlightStatus(cameraId, status);
break;
}
case CMD_CAMERA_HOST_CALLBACK_ON_CAMERA_EVENT: {
DHLOGI("DCameraHostCallbackStub::OnCameraEvent entry.");
if (data.ReadInterfaceToken() != DCameraHostCallbackStub::GetDescriptor()) {
DHLOGI("DCameraDeviceCallbackStub::OnCameraEvent token failed.");
return HDF_FAILURE;
}
std::string cameraId = data.ReadString();
CameraEvent event = static_cast<CameraEvent>(data.ReadInt32());
OnCameraEvent(cameraId, event);
break;
}
default: {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
return 0;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,36 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_HOST_CALLBACK_CLIENT_STUB_H
#define DISTRIBUTED_CAMERA_HOST_CALLBACK_CLIENT_STUB_H
#include "icamera_host_callback.h"
#include "iremote_stub.h"
#include "message_parcel.h"
#include "parcel.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DCameraHostCallbackStub : public IRemoteStub<ICameraHostCallback> {
public:
virtual ~DCameraHostCallbackStub() = default;
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option) override;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_HOST_CALLBACK_CLIENT_STUB_H
@@ -1,210 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_host_proxy.h"
#include <hdf_base.h>
#include <hdf_log.h>
#include <message_parcel.h>
#include "cmd_common.h"
#include "distributed_hardware_log.h"
#include "icamera_device.h"
#include "icamera_device_callback.h"
#include "icamera_host_callback.h"
#include "ipc_data_utils.h"
#include "metadata_utils.h"
OHOS::sptr<OHOS::Camera::ICameraHost> OHOS::Camera::ICameraHost::Get(const char *serviceName)
{
using namespace OHOS::HDI::ServiceManager::V1_0;
OHOS::sptr<IServiceManager> serviceMgr = IServiceManager::Get();
if (serviceMgr == nullptr) {
HDF_LOGE("%{public}s: IServiceManager failed!", __func__);
return nullptr;
}
OHOS::sptr<IRemoteObject> remote = serviceMgr->GetService(serviceName);
if (remote == nullptr) {
HDF_LOGE("%{public}s: get %{public}s failed!", __func__, serviceName);
return nullptr;
}
return iface_cast<OHOS::DistributedHardware::DCameraHostProxy>(remote);
}
namespace OHOS {
namespace DistributedHardware {
CamRetCode DCameraHostProxy::SetCallback(const OHOS::sptr<ICameraHostCallback> &callback)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraHostProxy::GetDescriptor())) {
DHLOGE("Write remote token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
bool callbackFlag = (callback != nullptr);
if (!data.WriteBool(callbackFlag)) {
DHLOGE("Set callback flag failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (callbackFlag && !data.WriteRemoteObject(callback->AsObject())) {
DHLOGE("Write remote callback object failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_HOST_REMOTE_SET_CALLBACK, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DCameraHostProxy::GetCameraIds(std::vector<std::string> &cameraIds)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraHostProxy::GetDescriptor())) {
DHLOGE("Write remote token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_HOST_REMOTE_GET_CAMERAID, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
CamRetCode retCode = static_cast<CamRetCode>(reply.ReadInt32());
if (retCode == CamRetCode::NO_ERROR && !reply.ReadStringVector(&cameraIds)) {
DHLOGE("Read camera ids failed.");
return CamRetCode::INVALID_ARGUMENT;
}
return retCode;
}
CamRetCode DCameraHostProxy::GetCameraAbility(const std::string &cameraId,
std::shared_ptr<CameraAbility> &ability)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraHostProxy::GetDescriptor())) {
DHLOGE("Write remote token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(cameraId)) {
DHLOGE("Write cameraId failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_HOST_REMOTE_GET_CAMERA_ABILITY, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
CamRetCode retCode = static_cast<CamRetCode>(reply.ReadInt32());
if (retCode == CamRetCode::NO_ERROR) {
Camera::MetadataUtils::DecodeCameraMetadata(reply, ability);
}
return retCode;
}
CamRetCode DCameraHostProxy::OpenCamera(const std::string &cameraId,
const OHOS::sptr<ICameraDeviceCallback> &callback, OHOS::sptr<ICameraDevice> &pDevice)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraHostProxy::GetDescriptor())) {
DHLOGE("Write remote token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(cameraId)) {
DHLOGE("Write cameraId failed.");
return CamRetCode::INVALID_ARGUMENT;
}
bool callbackFlag = (callback != nullptr);
if (!data.WriteBool(callbackFlag)) {
DHLOGE("Write camera callback flag failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (callbackFlag && !data.WriteRemoteObject(callback->AsObject())) {
DHLOGE("Write camera device callback failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_HOST_REMOTE_OPEN_CAMERA, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
CamRetCode retCode = static_cast<CamRetCode>(reply.ReadInt32());
bool flag = reply.ReadBool();
if (flag) {
sptr<IRemoteObject> remoteCameraDevice = reply.ReadRemoteObject();
if (remoteCameraDevice == nullptr) {
DHLOGE("Read remote camera device is null.");
}
pDevice = OHOS::iface_cast<ICameraDevice>(remoteCameraDevice);
}
return retCode;
}
CamRetCode DCameraHostProxy::SetFlashlight(const std::string &cameraId, bool &isEnable)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraHostProxy::GetDescriptor())) {
DHLOGE("Write remote token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(cameraId)) {
DHLOGE("Write cameraId failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteBool(isEnable)) {
DHLOGE("Write isEnable failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_CAMERA_HOST_REMOTE_SET_FLASH_LIGHT, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,50 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_HOST_CLIENT_PROXY_H
#define DISTRIBUTED_CAMERA_HOST_CLIENT_PROXY_H
#include "iremote_proxy.h"
#include "icamera_host.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DCameraHostProxy : public IRemoteProxy<ICameraHost> {
public:
explicit DCameraHostProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<ICameraHost>(impl) {}
virtual ~DCameraHostProxy() {}
virtual CamRetCode SetCallback(const OHOS::sptr<ICameraHostCallback> &callback) override;
virtual CamRetCode GetCameraIds(std::vector<std::string> &cameraIds) override;
virtual CamRetCode GetCameraAbility(const std::string &cameraId,
std::shared_ptr<CameraAbility> &ability) override;
virtual CamRetCode OpenCamera(const std::string &cameraId,
const OHOS::sptr<ICameraDeviceCallback> &callback,
OHOS::sptr<ICameraDevice> &pDevice) override;
virtual CamRetCode SetFlashlight(const std::string &cameraId, bool &isEnable) override;
private:
static constexpr int CMD_CAMERA_HOST_REMOTE_SET_CALLBACK = 0;
static constexpr int CMD_CAMERA_HOST_REMOTE_GET_CAMERAID = 1;
static constexpr int CMD_CAMERA_HOST_REMOTE_GET_CAMERA_ABILITY = 2;
static constexpr int CMD_CAMERA_HOST_REMOTE_OPEN_CAMERA = 3;
static constexpr int CMD_CAMERA_HOST_REMOTE_SET_FLASH_LIGHT = 4;
static inline BrokerDelegator<DCameraHostProxy> delegator_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_HOST_CLIENT_PROXY_H
@@ -1,91 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "doffline_stream_operator_proxy.h"
#include <hdf_base.h>
#include <message_parcel.h>
#include "distributed_hardware_log.h"
namespace OHOS {
namespace DistributedHardware {
CamRetCode DOfflineStreamOperatorProxy::CancelCapture(int captureId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DOfflineStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32(static_cast<int32_t>(captureId))) {
DHLOGE("Write captureId object failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_OFFLINE_STREAM_OPERATOR_CANCEL_CAPTURE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DOfflineStreamOperatorProxy::ReleaseStreams(const std::vector<int> &streamIds)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DOfflineStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
std::vector<int32_t> pxyStreamIds = streamIds;
if (!data.WriteInt32Vector(pxyStreamIds)) {
DHLOGE("Write streamIds object failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_OFFLINE_STREAM_OPERATOR_RELEASE_STREAMS, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DOfflineStreamOperatorProxy::Release()
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DOfflineStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_OFFLINE_STREAM_OPERATOR_RELEASE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,44 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_OFFLINE_STREAM_OPERATOR_CLIENT_PROXY_H
#define DISTRIBUTED_OFFLINE_STREAM_OPERATOR_CLIENT_PROXY_H
#include "iremote_proxy.h"
#include "ioffline_stream_operator.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DOfflineStreamOperatorProxy : public IRemoteProxy<IOfflineStreamOperator> {
public:
explicit DOfflineStreamOperatorProxy(const sptr<IRemoteObject>& impl)
: IRemoteProxy<IOfflineStreamOperator>(impl) {}
virtual ~DOfflineStreamOperatorProxy() {}
virtual CamRetCode CancelCapture(int captureId) override;
virtual CamRetCode ReleaseStreams(const std::vector<int>& streamIds) override;
virtual CamRetCode Release() override;
private:
static constexpr int CMD_OFFLINE_STREAM_OPERATOR_CANCEL_CAPTURE = 0;
static constexpr int CMD_OFFLINE_STREAM_OPERATOR_RELEASE_STREAMS = 1;
static constexpr int CMD_OFFLINE_STREAM_OPERATOR_RELEASE = 2;
static inline BrokerDelegator<DOfflineStreamOperatorProxy> delegator_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_OFFLINE_STREAM_OPERATOR_CLIENT_PROXY_H
@@ -1,44 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dstream_operator_callback.h"
#include "distributed_hardware_log.h"
namespace OHOS {
namespace DistributedHardware {
void DStreamOperatorCallback::OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId)
{
DHLOGW("DStreamOperatorCallback::OnCaptureStarted enter.");
}
void DStreamOperatorCallback::OnCaptureEnded(int32_t captureId,
const std::vector<std::shared_ptr<CaptureEndedInfo>> &info)
{
DHLOGW("DStreamOperatorCallback::OnCaptureEnded enter.");
}
void DStreamOperatorCallback::OnCaptureError(int32_t captureId,
const std::vector<std::shared_ptr<CaptureErrorInfo>> &info)
{
DHLOGW("DStreamOperatorCallback::OnCaptureError enter.");
}
void DStreamOperatorCallback::OnFrameShutter(int32_t captureId, const std::vector<int32_t> &streamId,
uint64_t timestamp)
{
DHLOGW("DStreamOperatorCallback::OnFrameShutter enter.");
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,40 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_STREAM_OPERATOR_CALLBACK_H
#define DISTRIBUTED_STREAM_OPERATOR_CALLBACK_H
#include "dstream_operator_callback_stub.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DStreamOperatorCallback : public DStreamOperatorCallbackStub {
public:
DStreamOperatorCallback() = default;
virtual ~DStreamOperatorCallback() = default;
public:
virtual void OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId) override;
virtual void OnCaptureEnded(int32_t captureId,
const std::vector<std::shared_ptr<CaptureEndedInfo>> &info) override;
virtual void OnCaptureError(int32_t captureId,
const std::vector<std::shared_ptr<CaptureErrorInfo>> &info) override;
virtual void OnFrameShutter(int32_t captureId,
const std::vector<int32_t> &streamId, uint64_t timestamp) override;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_STREAM_OPERATOR_CALLBACK_H
@@ -1,151 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dstream_operator_callback_stub.h"
#include <hdf_base.h>
#include <message_parcel.h>
#include "cmd_common.h"
#include "distributed_hardware_log.h"
#include "dstream_operator_callback.h"
namespace OHOS {
namespace DistributedHardware {
int32_t DStreamOperatorCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
int32_t ret = HDF_SUCCESS;
switch (code) {
case CMD_STREAM_OPERATOR_CALLBACK_ON_CAPTURE_STARTED: {
ret = OnCaptureStartedStub(data, reply, option);
break;
}
case CMD_STREAM_OPERATOR_CALLBACK_ON_CAPTURE_ENDED: {
ret = OnCaptureEndedStub(data, reply, option);
break;
}
case CMD_STREAM_OPERATOR_CALLBACK_ON_CAPTURE_ERROR: {
ret = OnCaptureErrorStub(data, reply, option);
break;
}
case CMD_STREAM_OPERATOR_CALLBACK_ON_FRAME_SHUTTER: {
ret = OnFrameShutterStub(data, reply, option);
break;
}
default: {
ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
return ret;
}
int32_t DStreamOperatorCallbackStub::OnCaptureStartedStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DHLOGI("DStreamOperatorCallbackStub::OnCaptureStartedStub entry.");
if (data.ReadInterfaceToken() != DStreamOperatorCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
int32_t captureId = data.ReadInt32();
std::vector<int32_t> streamIds;
if (!data.ReadInt32Vector(&streamIds)) {
DHLOGE("OnCaptureStarted read streamIds failed.");
return HDF_FAILURE;
}
OnCaptureStarted(captureId, streamIds);
return HDF_SUCCESS;
}
int32_t DStreamOperatorCallbackStub::OnCaptureEndedStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DHLOGI("DStreamOperatorCallbackStub::OnCaptureEndedStub entry.");
if (data.ReadInterfaceToken() != DStreamOperatorCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
int32_t captureId = data.ReadInt32();
int32_t count = data.ReadInt32();
std::vector<std::shared_ptr<CaptureEndedInfo>> info;
for (int32_t i = 0; i < count; i++) {
const CaptureEndedInfo *pInfo = reinterpret_cast<const CaptureEndedInfo *>(
data.ReadBuffer(sizeof(CaptureEndedInfo)));
if (pInfo == nullptr) {
DHLOGE("Read ended info failed.");
return HDF_FAILURE;
}
std::shared_ptr<CaptureEndedInfo> captureEndedInfo = std::make_shared<CaptureEndedInfo>();
captureEndedInfo->streamId_ = pInfo->streamId_;
captureEndedInfo->frameCount_ = pInfo->frameCount_;
info.push_back(captureEndedInfo);
}
OnCaptureEnded(captureId, info);
return HDF_SUCCESS;
}
int32_t DStreamOperatorCallbackStub::OnCaptureErrorStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DHLOGI("DStreamOperatorCallbackStub::OnCaptureErrorStub entry.");
if (data.ReadInterfaceToken() != DStreamOperatorCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
int32_t captureId = data.ReadInt32();
int32_t count = data.ReadInt32();
std::vector<std::shared_ptr<CaptureErrorInfo>> info;
for (int32_t i = 0; i < count; i++) {
const CaptureErrorInfo *pInfo = reinterpret_cast<const CaptureErrorInfo *>(
data.ReadBuffer(sizeof(CaptureErrorInfo)));
if (pInfo == nullptr) {
DHLOGE("Read error info failed.");
return HDF_FAILURE;
}
std::shared_ptr<CaptureErrorInfo> captureErrorInfo = std::make_shared<CaptureErrorInfo>();
captureErrorInfo->streamId_ = pInfo->streamId_;
captureErrorInfo->error_ = pInfo->error_;
info.push_back(captureErrorInfo);
}
OnCaptureError(captureId, info);
return HDF_SUCCESS;
}
int32_t DStreamOperatorCallbackStub::OnFrameShutterStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DHLOGI("DStreamOperatorCallbackStub::OnFrameShutterStub entry.");
if (data.ReadInterfaceToken() != DStreamOperatorCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
int32_t captureId = data.ReadInt32();
std::vector<int32_t> streamIds;
if (!data.ReadInt32Vector(&streamIds)) {
DHLOGE("Read streamIds failed.");
return HDF_FAILURE;
}
uint64_t timestamp = data.ReadUint64();
OnFrameShutter(captureId, streamIds, timestamp);
return HDF_SUCCESS;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,41 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_STREAM_OPERATOR_CALLBACK_CLIENT_STUB_H
#define DISTRIBUTED_STREAM_OPERATOR_CALLBACK_CLIENT_STUB_H
#include "iremote_stub.h"
#include "istream_operator_callback.h"
#include "message_parcel.h"
#include "parcel.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DStreamOperatorCallbackStub : public IRemoteStub<IStreamOperatorCallback> {
public:
virtual ~DStreamOperatorCallbackStub() = default;
private:
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option) override;
int32_t OnCaptureStartedStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t OnCaptureEndedStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t OnCaptureErrorStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t OnFrameShutterStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_STREAM_OPERATOR_CALLBACK_CLIENT_STUB_H
@@ -1,387 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dstream_operator_proxy.h"
#include <hdf_base.h>
#include <hdf_log.h>
#include <message_parcel.h>
#include "cmd_common.h"
#include "distributed_hardware_log.h"
#include "ioffline_stream_operator.h"
#include "ipc_data_utils.h"
#include "istream_operator_callback.h"
#include "metadata_utils.h"
namespace OHOS {
namespace DistributedHardware {
CamRetCode DStreamOperatorProxy::IsStreamsSupported(OperationMode mode,
const std::shared_ptr<Camera::CameraMetadata> &modeSetting,
const std::vector<std::shared_ptr<StreamInfo>> &info,
StreamSupportType &type)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32(mode)) {
DHLOGE("Write operation mode failed.");
return CamRetCode::INVALID_ARGUMENT;
}
bool nullFlag = (modeSetting != nullptr);
if (!data.WriteBool(nullFlag)) {
DHLOGE("Write mode null flag failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (nullFlag && !Camera::MetadataUtils::EncodeCameraMetadata(modeSetting, data)) {
DHLOGE("Write metadata failed.");
return CamRetCode::INVALID_ARGUMENT;
}
nullFlag = info.size();
if (!data.WriteBool(nullFlag)) {
DHLOGE("Write streaminfo null flag failed.");
return CamRetCode::INVALID_ARGUMENT;
}
size_t count = info.size();
if (!data.WriteInt32(static_cast<int32_t>(count))) {
HDF_LOGE("%s: write info count failed", __func__);
return CamRetCode::INVALID_ARGUMENT;
}
for (size_t i = 0; i < count; i++) {
std::shared_ptr<StreamInfo> streamInfo = info.at(i);
bool ret = IpcDataUtils::EncodeStreamInfo(streamInfo, data);
if (!ret) {
HDF_LOGE("%s: write streamInfo failed. index = %zu", __func__, i);
return CamRetCode::INVALID_ARGUMENT;
}
}
int32_t ret = Remote()->SendRequest(CMD_STREAM_OPERATOR_IS_STREAMS_SUPPORTED, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d", ret);
return CamRetCode::INVALID_ARGUMENT;
}
CamRetCode retCode = static_cast<CamRetCode>(reply.ReadInt32());
type = static_cast<StreamSupportType>(reply.ReadInt32());
return retCode;
}
CamRetCode DStreamOperatorProxy::CreateStreams(const std::vector<std::shared_ptr<StreamInfo>> &streamInfos)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
size_t count = streamInfos.size();
if (!data.WriteInt32(static_cast<int32_t>(count))) {
DHLOGE("Write streamInfos count failed.");
return CamRetCode::INVALID_ARGUMENT;
}
for (size_t i = 0; i < count; i++) {
std::shared_ptr<StreamInfo> streamInfo = streamInfos.at(i);
bool bRet = IpcDataUtils::EncodeStreamInfo(streamInfo, data);
if (!bRet) {
DHLOGE("Write streamInfo failed. index = %zu", i);
return CamRetCode::INVALID_ARGUMENT;
}
}
int32_t ret = Remote()->SendRequest(CMD_STREAM_OPERATOR_CREATE_STREAMS, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DStreamOperatorProxy::ReleaseStreams(const std::vector<int> &streamIds)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
std::vector<int32_t> pxyStreamIds = streamIds;
if (!data.WriteInt32Vector(pxyStreamIds)) {
DHLOGE("Write streamIds failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_STREAM_OPERATOR_RELEASE_STREAMS, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DStreamOperatorProxy::CommitStreams(OperationMode mode,
const std::shared_ptr<Camera::CameraMetadata> &modeSetting)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32(mode)) {
DHLOGE("Write operation mode failed.");
return CamRetCode::INVALID_ARGUMENT;
}
bool bRet = Camera::MetadataUtils::EncodeCameraMetadata(modeSetting, data);
if (!bRet) {
DHLOGE("Write metadata failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_STREAM_OPERATOR_COMMIT_STREAMS, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DStreamOperatorProxy::GetStreamAttributes(std::vector<std::shared_ptr<StreamAttribute>> &attributes)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_STREAM_OPERATOR_GET_STREAM_ATTRIBUTES, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
int32_t retCode = reply.ReadInt32();
int32_t count = reply.ReadInt32();
for (int i = 0; i < count; i++) {
const uint8_t *buffer = data.ReadBuffer(sizeof(StreamAttribute));
std::shared_ptr<StreamAttribute> attribute = std::shared_ptr<StreamAttribute>(
reinterpret_cast<StreamAttribute *>(
const_cast<uint8_t *>(buffer)));
attributes.push_back(attribute);
}
return static_cast<CamRetCode>(retCode);
}
CamRetCode DStreamOperatorProxy::AttachBufferQueue(int streamId, const OHOS::sptr<OHOS::IBufferProducer> &producer)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (producer == nullptr) {
DHLOGE("Input producer is NULL.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32(static_cast<int32_t>(streamId))) {
DHLOGE("Write streamId failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteRemoteObject(producer->AsObject())) {
DHLOGE("Write buffer producer failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_STREAM_OPERATOR_ATTACH_BUFFER_QUEUE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DStreamOperatorProxy::DetachBufferQueue(int streamId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32(static_cast<int32_t>(streamId))) {
DHLOGE("Write streamId failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_STREAM_OPERATOR_DETACH_BUFFER_QUEUE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DStreamOperatorProxy::Capture(int captureId,
const std::shared_ptr<CaptureInfo> &info, bool isStreaming)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (info == nullptr) {
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32(static_cast<int32_t>(captureId))) {
DHLOGE("Write captureId failed.");
return CamRetCode::INVALID_ARGUMENT;
}
std::vector<int32_t> pxyStreamIds = info->streamIds_;
if (!data.WriteInt32Vector(pxyStreamIds)) {
DHLOGE("Write streamIds failed.");
return CamRetCode::INVALID_ARGUMENT;
}
bool bRet = Camera::MetadataUtils::EncodeCameraMetadata(info->captureSetting_, data);
if (!bRet) {
DHLOGE("Write metadata failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteBool(info->enableShutterCallback_)) {
DHLOGE("Write enableShutterCallback_ failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteBool(isStreaming)) {
DHLOGE("Write isStreaming failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_STREAM_OPERATOR_CAPTURE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DStreamOperatorProxy::CancelCapture(int captureId)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32(static_cast<int32_t>(captureId))) {
DHLOGE("Write captureId failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(
CMD_STREAM_OPERATOR_CANCEL_CAPTURE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
return static_cast<CamRetCode>(reply.ReadInt32());
}
CamRetCode DStreamOperatorProxy::ChangeToOfflineStream(
const std::vector<int> &streamIds,
OHOS::sptr<IStreamOperatorCallback> &callback,
OHOS::sptr<IOfflineStreamOperator> &offlineOperator)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DStreamOperatorProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (callback == nullptr) {
return CamRetCode::INVALID_ARGUMENT;
}
std::vector<int32_t> pxyStreamIds = streamIds;
if (!data.WriteInt32Vector(pxyStreamIds)) {
DHLOGE("Write streamIds failed.");
return CamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteRemoteObject(callback->AsObject())) {
DHLOGE("Write offline stream operator callback failed.");
return CamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_STREAM_OPERATOR_CHANGE_TO_OFFLINE_STREAM, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code = %d.", ret);
return CamRetCode::INVALID_ARGUMENT;
}
CamRetCode retCode = static_cast<CamRetCode>(reply.ReadInt32());
sptr<IRemoteObject> remoteObj = reply.ReadRemoteObject();
offlineOperator = OHOS::iface_cast<IOfflineStreamOperator>(remoteObj);
return retCode;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,65 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_STREAM_OPERATOR_CLIENT_PROXY_H
#define DISTRIBUTED_STREAM_OPERATOR_CLIENT_PROXY_H
#include "iremote_proxy.h"
#include "istream_operator.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::Camera;
class DStreamOperatorProxy : public IRemoteProxy<IStreamOperator> {
public:
explicit DStreamOperatorProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IStreamOperator>(impl) {}
virtual ~DStreamOperatorProxy() = default;
virtual CamRetCode IsStreamsSupported(OperationMode mode,
const std::shared_ptr<Camera::CameraMetadata> &modeSetting,
const std::vector<std::shared_ptr<StreamInfo>> &info,
StreamSupportType &type) override;
virtual CamRetCode CreateStreams(const std::vector<std::shared_ptr<StreamInfo>> &streamInfos) override;
virtual CamRetCode ReleaseStreams(const std::vector<int> &streamIds) override;
virtual CamRetCode CommitStreams(OperationMode mode,
const std::shared_ptr<Camera::CameraMetadata> &modeSetting) override;
virtual CamRetCode GetStreamAttributes(std::vector<std::shared_ptr<StreamAttribute>> &attributes) override;
virtual CamRetCode AttachBufferQueue(int streamId,
const OHOS::sptr<OHOS::IBufferProducer> &producer) override;
virtual CamRetCode DetachBufferQueue(int streamId) override;
virtual CamRetCode Capture(int captureId,
const std::shared_ptr<CaptureInfo> &info, bool isStreaming) override;
virtual CamRetCode CancelCapture(int captureId) override;
virtual CamRetCode ChangeToOfflineStream(const std::vector<int> &streamIds,
OHOS::sptr<IStreamOperatorCallback> &callback,
OHOS::sptr<IOfflineStreamOperator> &offlineOperator) override;
private:
static constexpr int CMD_STREAM_OPERATOR_IS_STREAMS_SUPPORTED = 0;
static constexpr int CMD_STREAM_OPERATOR_CREATE_STREAMS = 1;
static constexpr int CMD_STREAM_OPERATOR_RELEASE_STREAMS = 2;
static constexpr int CMD_STREAM_OPERATOR_COMMIT_STREAMS = 3;
static constexpr int CMD_STREAM_OPERATOR_GET_STREAM_ATTRIBUTES = 4;
static constexpr int CMD_STREAM_OPERATOR_ATTACH_BUFFER_QUEUE = 5;
static constexpr int CMD_STREAM_OPERATOR_DETACH_BUFFER_QUEUE = 6;
static constexpr int CMD_STREAM_OPERATOR_CAPTURE = 7;
static constexpr int CMD_STREAM_OPERATOR_CANCEL_CAPTURE = 8;
static constexpr int CMD_STREAM_OPERATOR_CHANGE_TO_OFFLINE_STREAM = 9;
static inline BrokerDelegator<DStreamOperatorProxy> delegator_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_STREAM_OPERATOR_CLIENT_PROXY_H
@@ -1,68 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_provider_callback.h"
#include "distributed_hardware_log.h"
namespace OHOS {
namespace DistributedHardware {
DCamRetCode DCameraProviderCallback::OpenSession(const std::shared_ptr<DHBase> &dhBase)
{
DHLOGW("DCameraProviderCallback::OpenSession enter.");
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraProviderCallback::CloseSession(const std::shared_ptr<DHBase> &dhBase)
{
DHLOGW("DCameraProviderCallback::CloseSession enter.");
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraProviderCallback::ConfigureStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCStreamInfo>> &streamInfos)
{
DHLOGW("DCameraProviderCallback::ConfigureStreams enter.");
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraProviderCallback::ReleaseStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds)
{
DHLOGW("DCameraProviderCallback::ReleaseStreams enter.");
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraProviderCallback::StartCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCCaptureInfo>> &captureInfos)
{
DHLOGW("DCameraProviderCallback::StartCapture enter.");
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraProviderCallback::StopCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds)
{
DHLOGW("DCameraProviderCallback::StopCapture enter.");
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraProviderCallback::UpdateSettings(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCameraSettings>> &settings)
{
DHLOGW("DCameraProviderCallback::UpdateSettings enter.");
return DCamRetCode::SUCCESS;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,44 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_H
#define DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_H
#include "dcamera_provider_callback_stub.h"
namespace OHOS {
namespace DistributedHardware {
class DCameraProviderCallback : public DCameraProviderCallbackStub {
public:
DCameraProviderCallback() = default;
virtual ~DCameraProviderCallback() = default;
public:
virtual DCamRetCode OpenSession(const std::shared_ptr<DHBase> &dhBase) override;
virtual DCamRetCode CloseSession(const std::shared_ptr<DHBase> &dhBase) override;
virtual DCamRetCode ConfigureStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCStreamInfo>> &streamInfos) override;
virtual DCamRetCode ReleaseStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds) override;
virtual DCamRetCode StartCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCCaptureInfo>> &captureInfos) override;
virtual DCamRetCode StopCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds) override;
virtual DCamRetCode UpdateSettings(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCameraSettings>> &settings) override;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_H
@@ -1,261 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_provider_callback_stub.h"
#include <hdf_base.h>
#include "dcamera_provider_callback.h"
#include "distributed_hardware_log.h"
#include "ipc_data_utils.h"
namespace OHOS {
namespace DistributedHardware {
int32_t DCameraProviderCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
int32_t ret = HDF_SUCCESS;
switch (code) {
case CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_OPEN_SESSION: {
ret = DCProviderOpenSessionStub(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_CLOSE_SESSION: {
ret = DCProviderCloseSessionStub(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_CONFIGURE_STREAMS: {
ret = DCProviderConfigureStreamsStub(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_RELEASE_STREAMS: {
ret = DCProviderReleaseStreamsStub(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_START_CAPTURE: {
ret = DCProviderStartCaptureStub(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_STOP_CAPTURE: {
ret = DCProviderStopCaptureStub(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_UPDATE_SETTINGS: {
ret = DCProviderUpdateSettingsStub(data, reply, option);
break;
}
default: {
ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
return ret;
}
int32_t DCameraProviderCallbackStub::DCProviderOpenSessionStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
if (data.ReadInterfaceToken() != DCameraProviderCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
DCamRetCode ret = OpenSession(dhBase);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderCallbackStub::DCProviderCloseSessionStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
if (data.ReadInterfaceToken() != DCameraProviderCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
DCamRetCode ret = CloseSession(dhBase);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderCallbackStub::DCProviderConfigureStreamsStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
if (data.ReadInterfaceToken() != DCameraProviderCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
int32_t count = data.ReadInt32();
std::vector<std::shared_ptr<DCStreamInfo>> streamInfos;
for (int32_t i = 0; i < count; i++) {
const DCStreamInfo *pInfo = reinterpret_cast<const DCStreamInfo *>(
data.ReadBuffer(sizeof(DCStreamInfo)));
if (pInfo == nullptr) {
DHLOGE("Read distributed camera stream info failed.");
return HDF_FAILURE;
}
std::shared_ptr<DCStreamInfo> streamInfo = std::make_shared<DCStreamInfo>();
streamInfo->streamId_ = pInfo->streamId_;
streamInfo->width_ = pInfo->width_;
streamInfo->height_ = pInfo->height_;
streamInfo->stride_ = pInfo->stride_;
streamInfo->format_ = pInfo->format_;
streamInfo->dataspace_ = pInfo->dataspace_;
streamInfo->encodeType_ = pInfo->encodeType_;
streamInfo->type_ = pInfo->type_;
streamInfos.push_back(streamInfo);
}
DCamRetCode ret = ConfigureStreams(dhBase, streamInfos);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderCallbackStub::DCProviderReleaseStreamsStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
if (data.ReadInterfaceToken() != DCameraProviderCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
std::vector<int> streamIds;
if (!data.ReadInt32Vector(&streamIds)) {
DHLOGE("Read streamIds failed.");
return HDF_FAILURE;
}
DCamRetCode ret = ReleaseStreams(dhBase, streamIds);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderCallbackStub::DCProviderStartCaptureStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
if (data.ReadInterfaceToken() != DCameraProviderCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
int32_t count = data.ReadInt32();
std::vector<std::shared_ptr<DCCaptureInfo>> captureInfos;
for (int32_t i = 0; i < count; i++) {
std::shared_ptr<DCCaptureInfo> captureInfo = std::make_shared<DCCaptureInfo>();
std::vector<int32_t> streamIds;
if (!data.ReadInt32Vector(&streamIds)) {
DHLOGE("Read streamIds failed.");
return HDF_FAILURE;
}
captureInfo->streamIds_ = streamIds;
captureInfo->width_ = static_cast<int>(data.ReadInt32());
captureInfo->height_ = static_cast<int>(data.ReadInt32());
captureInfo->stride_ = static_cast<int>(data.ReadInt32());
captureInfo->format_ = static_cast<int>(data.ReadInt32());
captureInfo->dataspace_ = static_cast<int>(data.ReadInt32());
captureInfo->isCapture_ = data.ReadBool();
captureInfo->encodeType_ = static_cast<DCEncodeType>(data.ReadInt32());
captureInfo->type_ = static_cast<DCStreamType>(data.ReadInt32());
int32_t settingsSize = data.ReadInt32();
std::vector<std::shared_ptr<DCameraSettings>> capSettings;
for (int32_t k = 0; k < settingsSize; k++) {
std::shared_ptr<DCameraSettings> metadata = std::make_shared<DCameraSettings>();
IpcDataUtils::DecodeDCameraSettings(data, metadata);
capSettings.push_back(metadata);
}
captureInfo->captureSettings_ = capSettings;
captureInfos.push_back(captureInfo);
}
DCamRetCode ret = StartCapture(dhBase, captureInfos);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderCallbackStub::DCProviderStopCaptureStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
if (data.ReadInterfaceToken() != DCameraProviderCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
std::vector<int> streamIds;
if (!data.ReadInt32Vector(&streamIds)) {
DHLOGE("Read streamIds failed.");
return HDF_FAILURE;
}
DCamRetCode ret = StopCapture(dhBase, streamIds);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderCallbackStub::DCProviderUpdateSettingsStub(MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
if (data.ReadInterfaceToken() != DCameraProviderCallbackStub::GetDescriptor()) {
DHLOGE("OnCaptureStarted invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
int32_t count = data.ReadInt32();
std::vector<std::shared_ptr<DCameraSettings>> settings;
for (int32_t i = 0; i < count; i++) {
std::shared_ptr<DCameraSettings> metadata = std::make_shared<DCameraSettings>();
IpcDataUtils::DecodeDCameraSettings(data, metadata);
settings.push_back(metadata);
}
DCamRetCode ret = UpdateSettings(dhBase, settings);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,44 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_CLIENT_STUB_H
#define DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_CLIENT_STUB_H
#include "idistributed_camera_provider_callback.h"
#include "iremote_stub.h"
#include "message_parcel.h"
#include "parcel.h"
namespace OHOS {
namespace DistributedHardware {
class DCameraProviderCallbackStub : public IRemoteStub<IDCameraProviderCallback> {
public:
virtual ~DCameraProviderCallbackStub() = default;
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option) override;
private:
int32_t DCProviderOpenSessionStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t DCProviderCloseSessionStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t DCProviderConfigureStreamsStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t DCProviderReleaseStreamsStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t DCProviderStartCaptureStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t DCProviderStopCaptureStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
int32_t DCProviderUpdateSettingsStub(MessageParcel &data, MessageParcel &reply, MessageOption &option);
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_CLIENT_STUB_H
@@ -1,332 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_provider_proxy.h"
#include <buffer_handle_parcel.h>
#include <buffer_handle_utils.h>
#include <hdf_base.h>
#include <message_parcel.h>
#include <sys/mman.h>
#include "distributed_hardware_log.h"
#include "ipc_data_utils.h"
#include "iservmgr_hdi.h"
namespace OHOS {
namespace DistributedHardware {
const std::string DC_PROVIDER_HDI_SERVER_NAME = "distributed_camera_provider_service";
sptr<IDCameraProvider> IDCameraProvider::Get()
{
using namespace OHOS::HDI::ServiceManager::V1_0;
OHOS::sptr<IServiceManager> serviceMgr = IServiceManager::Get();
if (serviceMgr == nullptr) {
DHLOGE("Get IServiceManager failed.");
return nullptr;
}
OHOS::sptr<IRemoteObject> remote = serviceMgr->GetService(DC_PROVIDER_HDI_SERVER_NAME.c_str());
if (remote == nullptr) {
DHLOGE("GetService failed! serviceName = %s", DC_PROVIDER_HDI_SERVER_NAME.c_str());
return nullptr;
}
return iface_cast<DCameraProviderProxy>(remote);
}
DCamRetCode DCameraProviderProxy::EnableDCameraDevice(const std::shared_ptr<DHBase> &dhBase,
const std::string &abilityInfo, const sptr<IDCameraProviderCallback> &callback)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_) || !data.WriteString(abilityInfo)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
bool nullFlag = (callback != nullptr);
if (!data.WriteBool(nullFlag)) {
DHLOGE("Write distributed camera provider callback null flag failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (nullFlag && !data.WriteRemoteObject(callback->AsObject())) {
DHLOGE("Set callback write remote obj failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_ENABLE_DEVICE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d", ret);
return DCamRetCode::INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderProxy::DisableDCameraDevice(const std::shared_ptr<DHBase> &dhBase)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_DISABLE_DEVICE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
return DCamRetCode::INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderProxy::AcquireBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
std::shared_ptr<DCameraBuffer> &buffer)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteInt32(static_cast<int32_t>(streamId))) {
DHLOGE("Write streamId failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_ACQUIRE_BUFFER, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
return DCamRetCode::INVALID_ARGUMENT;
}
int32_t retCode = reply.ReadInt32();
if (retCode != DCamRetCode::SUCCESS) {
DHLOGE("Acquire available buffer from stub failed.");
return static_cast<DCamRetCode>(retCode);
}
buffer = std::make_shared<DCameraBuffer>();
buffer->index_ = reply.ReadInt32();
buffer->size_ = reply.ReadInt32();
BufferHandle* retHandle = ReadBufferHandle(reply);
if (retHandle == nullptr) {
DHLOGE("Read return buffer handle failed.");
FreeBufferHandle(buffer->bufferHandle_);
return DCamRetCode::INVALID_ARGUMENT;
}
retHandle->virAddr = DCameraMemoryMap(retHandle);
buffer->bufferHandle_ = retHandle;
return DCamRetCode::SUCCESS;
}
DCamRetCode DCameraProviderProxy::ShutterBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
const std::shared_ptr<DCameraBuffer> &buffer)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
DCamRetCode ret = DCamRetCode::SUCCESS;
do {
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
ret = DCamRetCode::INVALID_ARGUMENT;
break;
}
if (!data.WriteInt32(static_cast<int32_t>(streamId))) {
DHLOGE("Write streamId failed.");
ret = DCamRetCode::INVALID_ARGUMENT;
break;
}
bool nullFlag = (buffer != nullptr);
if (!data.WriteBool(nullFlag)) {
DHLOGE("Write distributed camera buffer null flag failed.");
ret = DCamRetCode::INVALID_ARGUMENT;
break;
}
if (!data.WriteInt32(buffer->index_) || !data.WriteInt32(buffer->size_)) {
DHLOGE("write buffer index and size parameter failed.");
ret = DCamRetCode::INVALID_ARGUMENT;
break;
}
int32_t retCode = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_SHUTTER_BUFFER, data, reply, option);
if (retCode != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", retCode);
ret = DCamRetCode::FAILED;
}
} while (0);
DCameraMemoryUnmap(buffer->bufferHandle_);
if (ret != DCamRetCode::SUCCESS) {
return ret;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderProxy::OnSettingsResult(const std::shared_ptr<DHBase> &dhBase,
const std::shared_ptr<DCameraSettings> &result)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
bool nullFlag = (result != nullptr);
if (!data.WriteBool(nullFlag)) {
DHLOGE("Write distributed camera settings null flag failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (nullFlag && !IpcDataUtils::EncodeDCameraSettings(result, data)) {
DHLOGE("Write distributed camera settings failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_ON_SETTINGS_RESULT, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
return DCamRetCode::INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderProxy::Notify(const std::shared_ptr<DHBase> &dhBase,
const std::shared_ptr<DCameraHDFEvent> &event)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
bool nullFlag = (event != nullptr);
if (!data.WriteBool(nullFlag)) {
DHLOGE("Write distributed camera hdf event null flag failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (nullFlag && !IpcDataUtils::EncodeDCameraHDFEvent(event, data)) {
DHLOGE("Write distributed camera hdf event failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_NOTIFY, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
return DCamRetCode::INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
#ifdef PRODUCT_M40
void* DCameraProviderProxy::DCameraMemoryMap(const BufferHandle *buffer)
{
if (buffer == nullptr) {
DHLOGE("mmap the buffer handle is NULL");
return nullptr;
}
if (buffer->reserveFds <= 0) {
DHLOGE("invalid file descriptor num : %d", buffer->reserveFds);
return nullptr;
}
void* virAddr = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, buffer->reserve[0], 0);
if (virAddr == MAP_FAILED) {
DHLOGE("mmap failed errno %s, fd : %d", strerror(errno), buffer->fd);
return nullptr;
}
return virAddr;
}
#else
void* DCameraProviderProxy::DCameraMemoryMap(const BufferHandle *buffer)
{
if (buffer == nullptr) {
DHLOGE("mmap the buffer handle is NULL");
return nullptr;
}
void* virAddr = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, buffer->fd, 0);
if (virAddr == MAP_FAILED) {
DHLOGE("mmap failed errno %s, fd : %d", strerror(errno), buffer->fd);
return nullptr;
}
return virAddr;
}
#endif
void DCameraProviderProxy::DCameraMemoryUnmap(BufferHandle *buffer)
{
if (buffer == nullptr) {
DHLOGE("unmmap the buffer handle is NULL");
return;
}
if (buffer->virAddr == nullptr) {
DHLOGE("virAddr is NULL , has not map the buffer");
return;
}
int ret = munmap(buffer->virAddr, buffer->size);
if (ret != 0) {
DHLOGE("munmap failed err: %s", strerror(errno));
}
buffer->virAddr = nullptr;
FreeBufferHandle(buffer);
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,59 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_PROVIDER_CLIENT_PROXY_H
#define DISTRIBUTED_CAMERA_PROVIDER_CLIENT_PROXY_H
#include "iremote_proxy.h"
#include "buffer_handle.h"
#include "idistributed_camera_provider.h"
namespace OHOS {
namespace DistributedHardware {
class DCameraProviderProxy : public IRemoteProxy<IDCameraProvider> {
public:
explicit DCameraProviderProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDCameraProvider>(impl) {}
virtual ~DCameraProviderProxy() = default;
virtual DCamRetCode EnableDCameraDevice(const std::shared_ptr<DHBase> &dhBase,
const std::string &abilityInfo,
const sptr<IDCameraProviderCallback> &callback) override;
virtual DCamRetCode DisableDCameraDevice(const std::shared_ptr<DHBase> &dhBase) override;
virtual DCamRetCode AcquireBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
std::shared_ptr<DCameraBuffer> &buffer) override;
virtual DCamRetCode ShutterBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
const std::shared_ptr<DCameraBuffer> &buffer) override;
virtual DCamRetCode OnSettingsResult(const std::shared_ptr<DHBase> &dhBase,
const std::shared_ptr<DCameraSettings> &result) override;
virtual DCamRetCode Notify(const std::shared_ptr<DHBase> &dhBase,
const std::shared_ptr<DCameraHDFEvent> &event) override;
private:
static void* DCameraMemoryMap(const BufferHandle *buffer);
static void DCameraMemoryUnmap(BufferHandle *buffer);
private:
static constexpr int CMD_DISTRIBUTED_CAMERA_PROVIDER_ENABLE_DEVICE = 0;
static constexpr int CMD_DISTRIBUTED_CAMERA_PROVIDER_DISABLE_DEVICE = 1;
static constexpr int CMD_DISTRIBUTED_CAMERA_PROVIDER_ACQUIRE_BUFFER = 2;
static constexpr int CMD_DISTRIBUTED_CAMERA_PROVIDER_SHUTTER_BUFFER = 3;
static constexpr int CMD_DISTRIBUTED_CAMERA_PROVIDER_ON_SETTINGS_RESULT = 4;
static constexpr int CMD_DISTRIBUTED_CAMERA_PROVIDER_NOTIFY = 5;
static inline BrokerDelegator<DCameraProviderProxy> delegator_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_PROVIDER_CLIENT_PROXY_H
@@ -18,7 +18,6 @@ import(
ohos_shared_library("distributed_camera_host_config") {
include_dirs = [
"${distributedcamera_hdf_path}/interfaces/include",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/host",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/device",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/operator",
@@ -39,6 +38,7 @@ ohos_shared_library("distributed_camera_host_config") {
"${hdf_uhdf_path}/ipc/include",
"${hdf_uhdf_path}/include/host",
"//drivers/peripheral/camera/interfaces/metadata/include",
"//third_party/jsoncpp/include",
]
sources = [ "dcamera_host_config.cpp" ]
@@ -48,6 +48,8 @@ ohos_shared_library("distributed_camera_host_config") {
"//utils/native/base:utils",
]
public_deps = [ "//drivers/interface/distributed_camera/v1_0:libdistributed_camera_provider_stub_1.0" ]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"distributedcamerahdf\"",
@@ -1,64 +0,0 @@
# Copyright (c) 2021 Huawei Device 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.
import("//build/ohos.gni")
import("//drivers/adapter/uhdf2/uhdf.gni")
import(
"//foundation/distributedhardware/distributed_camera/distributedcamera.gni")
ohos_shared_library("distributed_camera_provider_config") {
include_dirs = [
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/provider",
"${distributedcamera_hdf_path}/interfaces/include",
"${distributedcamera_hdf_path}/hdi_impl/include/dcamera_provider",
"${distributedcamera_hdf_path}/hdi_impl/include/utils",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"${camera_hdf_path}/camera/interfaces/include",
"${camera_hdf_path}/camera/interfaces/hdi_ipc",
"${hdf_framework_path}/include/utils",
"${hdf_framework_path}/include/core",
"${hdf_framework_path}/include/osal",
"${hdf_uhdf_path}/include/hdi",
"${hdf_uhdf_path}/osal/include",
"${hdf_uhdf_path}/ipc/include",
"${hdf_uhdf_path}/include/host",
"//drivers/peripheral/camera/interfaces/metadata/include",
]
sources = [ "dcamera_provider_config.cpp" ]
deps = [
"${distributedcamera_hdf_path}/hdi_impl:distributed_camera_hdf",
"//utils/native/base:utils",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"distributedcamerahdf\"",
"LOG_DOMAIN=0xD004100",
]
external_deps = [
"device_driver_framework:libhdf_host",
"graphic_chipsetsdk:buffer_handle",
"graphic_chipsetsdk:surface",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
]
install_images = [ chipset_base_dir ]
subsystem_name = "distributedhardware"
part_name = "distributed_camera"
}
@@ -1,102 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_provider_stub.h"
#include <hdf_base.h>
#include <hdf_device_desc.h>
#include <hdf_log.h>
#include <osal_mem.h>
struct HdfDCameraProviderService {
struct IDeviceIoService ioservice;
void *instance;
};
static int32_t DCameraProviderServiceDispatch(struct HdfDeviceIoClient *client, int cmdId,
struct HdfSBuf *data, struct HdfSBuf *reply)
{
HdfDCameraProviderService *service = CONTAINER_OF(client->device->service, HdfDCameraProviderService, ioservice);
return DCProviderServiceOnRemoteRequest(service->instance, cmdId, data, reply);
}
int HdfDCameraProviderConfigInit(struct HdfDeviceObject *deviceObject)
{
if (deviceObject == nullptr) {
HDF_LOGE("HdfDCameraProviderConfigInit: HdfDeviceObject is NULL !");
return HDF_FAILURE;
}
if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_CAMERA)) {
HDF_LOGE("HdfDCameraProviderConfigInit set camera class failed");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int HdfDCameraProviderConfigBind(HdfDeviceObject *deviceObject)
{
HDF_LOGI("HdfDCameraProviderConfigBind enter!");
if (deviceObject == nullptr) {
HDF_LOGE("HdfDCameraProviderConfigBind: HdfDeviceObject is NULL !");
return HDF_FAILURE;
}
HdfDCameraProviderService *service =
reinterpret_cast<HdfDCameraProviderService *>(malloc(sizeof(HdfDCameraProviderService)));
if (service == nullptr) {
HDF_LOGE("HdfDCameraProviderConfigBind malloc HdfDCameraProviderService failed!");
return HDF_FAILURE;
}
service->ioservice.Dispatch = DCameraProviderServiceDispatch;
service->ioservice.Open = nullptr;
service->ioservice.Release = nullptr;
service->instance = DCameraProviderStubInstance();
deviceObject->service = &service->ioservice;
return HDF_SUCCESS;
}
void HdfDCameraProviderConfigRelease(HdfDeviceObject *deviceObject)
{
if (deviceObject == nullptr || deviceObject->service == nullptr) {
HDF_LOGE("HdfDCameraProviderConfigRelease: deviceObject or deviceObject->service is NULL!");
return;
}
HdfDCameraProviderService *service = CONTAINER_OF(deviceObject->service, HdfDCameraProviderService, ioservice);
if (service == nullptr) {
HDF_LOGE("HdfDCameraProviderConfigRelease: service is NULL!");
return;
}
free(service);
}
struct HdfDriverEntry g_dCameraProviderConfigEntry = {
.moduleVersion = 1,
.moduleName = "distributed_camera_provider_service",
.Bind = HdfDCameraProviderConfigBind,
.Init = HdfDCameraProviderConfigInit,
.Release = HdfDCameraProviderConfigRelease,
};
#ifndef __cplusplus
extern "C" {
#endif // __cplusplus
HDF_INIT(g_dCameraProviderConfigEntry);
#ifndef __cplusplus
}
#endif // __cplusplus
@@ -23,12 +23,13 @@
#include <iostream>
#include <iservmgr_hdi.h>
#include "camera_metadata_info.h"
#include "v1_0/dcamera_types.h"
#include <foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/include/types.h>
#include <drivers/peripheral/camera/interfaces/include/types.h>
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class IpcDataUtils {
static const uint32_t RATIONAL_TYPE_STEP = 2;
public:
@@ -97,7 +97,7 @@ int32_t DCameraDeviceStub::DCDeviceStubGetStreamOperator(MessageParcel& data, Me
bool nullFlag = (streamOperator != nullptr);
if (!reply.WriteBool(nullFlag)) {
DHLOGE("Write stream operator flag failed.");
return INVALID_ARGUMENT;
return HDF_FAILURE;
}
if (nullFlag && !reply.WriteRemoteObject(streamOperator->AsObject())) {
@@ -1,274 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_provider_callback_proxy.h"
#include <hdf_base.h>
#include <message_parcel.h>
#include "distributed_hardware_log.h"
#include "ipc_data_utils.h"
namespace OHOS {
namespace DistributedHardware {
DCamRetCode DCameraProviderCallbackProxy::OpenSession(const std::shared_ptr<DHBase> &dhBase)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderCallbackProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_OPEN_SESSION, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
return INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderCallbackProxy::CloseSession(const std::shared_ptr<DHBase> &dhBase)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderCallbackProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_CLOSE_SESSION, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
return INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderCallbackProxy::ConfigureStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCStreamInfo>> &streamInfos)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderCallbackProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
size_t size = streamInfos.size();
if (!data.WriteInt32(static_cast<int32_t>(size))) {
DHLOGE("Write stream info size failed.");
return INVALID_ARGUMENT;
}
for (size_t i = 0; i < size; i++) {
auto streamInfo = streamInfos.at(i);
bool bRet = data.WriteBuffer((void *)streamInfo.get(), sizeof(DCStreamInfo));
if (!bRet) {
DHLOGE("Write stream info index = %d failed.", i);
return INVALID_ARGUMENT;
}
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_CONFIGURE_STREAMS,
data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
return INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderCallbackProxy::ReleaseStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderCallbackProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
std::vector<int32_t> pxyStreamIds = streamIds;
if (!data.WriteInt32Vector(pxyStreamIds)) {
DHLOGE("Write streamId failed.");
return INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_RELEASE_STREAMS,
data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d", ret);
return INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderCallbackProxy::StartCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCCaptureInfo>> &captureInfos)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderCallbackProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
size_t size = captureInfos.size();
if (!data.WriteInt32(static_cast<int32_t>(size))) {
DHLOGE("Write distributed camera capture info size failed.");
return INVALID_ARGUMENT;
}
for (size_t i = 0; i < size; i++) {
auto captureInfo = captureInfos.at(i);
if (!data.WriteInt32Vector(captureInfo->streamIds_)) {
DHLOGE("Write streamIds vector failed.");
return INVALID_ARGUMENT;
}
data.WriteInt32(static_cast<int32_t>(captureInfo->width_));
data.WriteInt32(static_cast<int32_t>(captureInfo->height_));
data.WriteInt32(static_cast<int32_t>(captureInfo->stride_));
data.WriteInt32(static_cast<int32_t>(captureInfo->format_));
data.WriteInt32(static_cast<int32_t>(captureInfo->dataspace_));
data.WriteBool(static_cast<int32_t>(captureInfo->isCapture_));
data.WriteInt32(static_cast<int32_t>(captureInfo->encodeType_));
data.WriteInt32(static_cast<int32_t>(captureInfo->type_));
std::vector<std::shared_ptr<DCameraSettings>> capSettings = captureInfo->captureSettings_;
size_t settingsSize = capSettings.size();
if (!data.WriteInt32(static_cast<int32_t>(settingsSize))) {
DHLOGE("Write distributed camera capture settings size failed.");
return INVALID_ARGUMENT;
}
for (size_t k = 0; k < settingsSize; k++) {
bool bRet = IpcDataUtils::EncodeDCameraSettings(capSettings.at(k), data);
if (!bRet) {
DHLOGE("Write distributed camera capture settings failed.");
return INVALID_ARGUMENT;
}
}
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_START_CAPTURE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d", ret);
return INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderCallbackProxy::StopCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderCallbackProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
std::vector<int32_t> pxyStreamIds = streamIds;
if (!data.WriteInt32Vector(pxyStreamIds)) {
DHLOGE("Write streamId failed.");
return INVALID_ARGUMENT;
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_STOP_CAPTURE, data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
return INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
DCamRetCode DCameraProviderCallbackProxy::UpdateSettings(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCameraSettings>> &settings)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(DCameraProviderCallbackProxy::GetDescriptor())) {
DHLOGE("Write token failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
if (!data.WriteString(dhBase->deviceId_) || !data.WriteString(dhBase->dhId_)) {
DHLOGE("Write distributed camera base info or ability info failed.");
return DCamRetCode::INVALID_ARGUMENT;
}
size_t size = settings.size();
if (!data.WriteInt32(static_cast<int32_t>(size))) {
DHLOGE("Write distributed camera settings size failed.");
return INVALID_ARGUMENT;
}
for (size_t i = 0; i < size; i++) {
bool bRet = IpcDataUtils::EncodeDCameraSettings(settings.at(i), data);
if (!bRet) {
DHLOGE("Write distributed camera settings index = %zu failed.", i);
return INVALID_ARGUMENT;
}
}
int32_t ret = Remote()->SendRequest(CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_UPDATE_SETTINGS,
data, reply, option);
if (ret != HDF_SUCCESS) {
DHLOGE("SendRequest failed, error code is %d.", ret);
return INVALID_ARGUMENT;
}
return static_cast<DCamRetCode>(reply.ReadInt32());
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,49 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_PROXY_H
#define DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_PROXY_H
#include "iremote_proxy.h"
#include "idistributed_camera_provider_callback.h"
namespace OHOS {
namespace DistributedHardware {
class DCameraProviderCallbackProxy : public IRemoteProxy<IDCameraProviderCallback> {
public:
explicit DCameraProviderCallbackProxy(const sptr<IRemoteObject> &impl)
: IRemoteProxy<IDCameraProviderCallback>(impl) {}
virtual ~DCameraProviderCallbackProxy() = default;
virtual DCamRetCode OpenSession(const std::shared_ptr<DHBase> &dhBase);
virtual DCamRetCode CloseSession(const std::shared_ptr<DHBase> &dhBase);
virtual DCamRetCode ConfigureStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCStreamInfo>> &streamInfos);
virtual DCamRetCode ReleaseStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds);
virtual DCamRetCode StartCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCCaptureInfo>> &captureInfos);
virtual DCamRetCode StopCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<int> &streamIds);
virtual DCamRetCode UpdateSettings(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCameraSettings>> &settings);
private:
static inline BrokerDelegator<DCameraProviderCallbackProxy> delegator_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_PROXY_H
@@ -1,297 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 "dcamera_provider_stub.h"
#include <buffer_handle_parcel.h>
#include <hdf_base.h>
#include <hdf_log.h>
#include <hdf_sbuf_ipc.h>
#include "distributed_hardware_log.h"
#include "idistributed_camera_provider.h"
#include "ipc_data_utils.h"
namespace OHOS {
namespace DistributedHardware {
DCameraProviderStub::DCameraProviderStub()
{
}
int32_t DCameraProviderStub::Init()
{
dcameraProvider_ = DCameraProvider::GetInstance();
if (dcameraProvider_ == nullptr) {
DHLOGE("Get distributed camera provider instance failed.");
return HDF_FAILURE;
}
DHLOGI("Get distributed camera provider instance success.");
return HDF_SUCCESS;
}
int32_t DCameraProviderStub::DCProviderStubEnableDCameraDevice(MessageParcel& data, MessageParcel& reply,
MessageOption& option)
{
if (data.ReadInterfaceToken() != DCameraProviderStub::GetDescriptor()) {
DHLOGE("invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
const std::string abilitySet = data.ReadString();
if (abilitySet.empty()) {
DHLOGE("Read input param is empty.");
return HDF_ERR_INVALID_PARAM;
}
sptr<IDCameraProviderCallback> dcProviderCallback = nullptr;
bool flag = data.ReadBool();
if (flag) {
sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
if (remoteObj == nullptr) {
DHLOGE("Read distributed camera provider callback failed.");
return HDF_FAILURE;
}
dcProviderCallback = OHOS::iface_cast<IDCameraProviderCallback>(remoteObj);
}
DCamRetCode ret = dcameraProvider_->EnableDCameraDevice(dhBase, abilitySet, dcProviderCallback);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderStub::DCProviderStubDisableDCameraDevice(MessageParcel& data, MessageParcel& reply,
MessageOption& option)
{
if (data.ReadInterfaceToken() != DCameraProviderStub::GetDescriptor()) {
DHLOGE("invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
DCamRetCode ret = dcameraProvider_->DisableDCameraDevice(dhBase);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderStub::DCProviderStubAcquireBuffer(MessageParcel& data, MessageParcel& reply,
MessageOption& option)
{
if (data.ReadInterfaceToken() != DCameraProviderStub::GetDescriptor()) {
DHLOGE("invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
int32_t streamId = data.ReadInt32();
std::shared_ptr<DCameraBuffer> dCamerabuffer = std::make_shared<DCameraBuffer>();
DCamRetCode ret = dcameraProvider_->AcquireBuffer(dhBase, streamId, dCamerabuffer);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
if (ret != DCamRetCode::SUCCESS) {
DHLOGE("Acquire available buffer failed.");
return HDF_SUCCESS;
}
if (!reply.WriteInt32(dCamerabuffer->index_) || !reply.WriteInt32(dCamerabuffer->size_)) {
DHLOGE("write buffer index and size parameter failed.");
return HDF_FAILURE;
}
BufferHandle* bufferHandle = dCamerabuffer->bufferHandle_;
if (!WriteBufferHandle(reply, *bufferHandle)) {
DHLOGE("Write buffer handle failed.");
FreeBufferHandle(bufferHandle);
return HDF_ERR_INVALID_PARAM;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderStub::DCProviderStubShutterBuffer(MessageParcel& data, MessageParcel& reply,
MessageOption& option)
{
if (data.ReadInterfaceToken() != DCameraProviderStub::GetDescriptor()) {
DHLOGE("invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
int32_t streamId = data.ReadInt32();
std::shared_ptr<DCameraBuffer> buffer = nullptr;
bool flag = data.ReadBool();
if (flag) {
buffer = std::make_shared<DCameraBuffer>();
buffer->index_ = data.ReadInt32();
buffer->size_ = data.ReadInt32();
buffer->bufferHandle_ = nullptr;
}
DCamRetCode ret = dcameraProvider_->ShutterBuffer(dhBase, streamId, buffer);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderStub::DCProviderStubOnSettingsResult(MessageParcel& data, MessageParcel& reply,
MessageOption& option)
{
if (data.ReadInterfaceToken() != DCameraProviderStub::GetDescriptor()) {
DHLOGE("invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
std::shared_ptr<DCameraSettings> dCameraSettings = std::make_shared<DCameraSettings>();
bool flag = data.ReadBool();
if (flag) {
if (dCameraSettings == nullptr) {
DHLOGE("Read distributed camera settings failed, dCameraSettings is null.");
return HDF_FAILURE;
}
IpcDataUtils::DecodeDCameraSettings(data, dCameraSettings);
}
DCamRetCode ret = dcameraProvider_->OnSettingsResult(dhBase, dCameraSettings);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderStub::DCProviderStubNotify(MessageParcel& data, MessageParcel& reply, MessageOption& option)
{
if (data.ReadInterfaceToken() != DCameraProviderStub::GetDescriptor()) {
DHLOGE("invalid token.");
return HDF_FAILURE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>(data.ReadString(), data.ReadString());
std::shared_ptr<DCameraHDFEvent> dCameraEvent = std::make_shared<DCameraHDFEvent>();
bool flag = data.ReadBool();
if (flag) {
if (dCameraEvent == nullptr) {
DHLOGE("Read distributed camera hdf event failed, dCameraEvent is null.");
return HDF_FAILURE;
}
IpcDataUtils::DecodeDCameraHDFEvent(data, dCameraEvent);
}
DCamRetCode ret = dcameraProvider_->Notify(dhBase, dCameraEvent);
if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
DHLOGE("Write retcode failed.");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t DCameraProviderStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
MessageOption& option)
{
int32_t ret = HDF_SUCCESS;
switch (code) {
case CMD_DISTRIBUTED_CAMERA_PROVIDER_ENABLE_DEVICE: {
ret = DCProviderStubEnableDCameraDevice(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_DISABLE_DEVICE: {
ret = DCProviderStubDisableDCameraDevice(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_ACQUIRE_BUFFER: {
ret = DCProviderStubAcquireBuffer(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_SHUTTER_BUFFER: {
ret = DCProviderStubShutterBuffer(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_ON_SETTINGS_RESULT: {
ret = DCProviderStubOnSettingsResult(data, reply, option);
break;
}
case CMD_DISTRIBUTED_CAMERA_PROVIDER_NOTIFY: {
ret = DCProviderStubNotify(data, reply, option);
break;
}
default: {
DHLOGE("Unknown remote request code=%d.", code);
}
}
return ret;
}
} // namespace DistributedHardware
} // namespace OHOS
void *DCameraProviderStubInstance()
{
OHOS::DistributedHardware::DCameraProviderStub *stub =
new (std::nothrow) OHOS::DistributedHardware::DCameraProviderStub();
if (stub == nullptr) {
HDF_LOGE("%{public}s: camera provider stub create failed.", __func__);
return nullptr;
}
int32_t ret = stub->Init();
if (ret != HDF_SUCCESS) {
delete stub;
stub = nullptr;
return nullptr;
}
return reinterpret_cast<void *>(stub);
}
void DestroyDCameraProviderStub(void *stubObj)
{
delete reinterpret_cast<OHOS::DistributedHardware::DCameraProviderStub *>(stubObj);
}
int32_t DCProviderServiceOnRemoteRequest(void *stub, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
{
if (stub == nullptr) {
HDF_LOGE("%{public}s:stub is null", __func__);
return HDF_FAILURE;
}
OHOS::DistributedHardware::DCameraProviderStub *providerStub =
reinterpret_cast<OHOS::DistributedHardware::DCameraProviderStub *>(stub);
OHOS::MessageParcel *dataParcel = nullptr;
OHOS::MessageParcel *replyParcel = nullptr;
if (SbufToParcel(reply, &replyParcel) != HDF_SUCCESS) {
HDF_LOGE("%{public}s:invalid reply sbuf object to dispatch", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) {
HDF_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__);
return HDF_ERR_INVALID_PARAM;
}
OHOS::MessageOption option;
return providerStub->OnRemoteRequest(cmdId, *dataParcel, *replyParcel, option);
}
@@ -1,60 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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 DISTRIBUTED_CAMERA_PROVIDER_SERVER_STUB_H
#define DISTRIBUTED_CAMERA_PROVIDER_SERVER_STUB_H
#include <message_option.h>
#include <message_parcel.h>
#include <refbase.h>
#include "dcamera_provider.h"
#include "iremote_stub.h"
namespace OHOS {
namespace DistributedHardware {
class DCameraProviderStub {
public:
DCameraProviderStub();
virtual ~DCameraProviderStub() {}
int32_t Init();
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
MessageOption& option);
private:
int32_t DCProviderStubEnableDCameraDevice(MessageParcel& data, MessageParcel& reply, MessageOption& option);
int32_t DCProviderStubDisableDCameraDevice(MessageParcel& data, MessageParcel& reply, MessageOption& option);
int32_t DCProviderStubAcquireBuffer(MessageParcel& data, MessageParcel& reply, MessageOption& option);
int32_t DCProviderStubShutterBuffer(MessageParcel& data, MessageParcel& reply, MessageOption& option);
int32_t DCProviderStubOnSettingsResult(MessageParcel& data, MessageParcel& reply, MessageOption& option);
int32_t DCProviderStubNotify(MessageParcel& data, MessageParcel& reply, MessageOption& option);
static inline const std::u16string metaDescriptor_ = u"HDI.DCamera.V1_0.Provider";
static inline const std::u16string &GetDescriptor()
{
return metaDescriptor_;
}
private:
std::shared_ptr<DCameraProvider> dcameraProvider_ = nullptr;
};
} // namespace DistributedHardware
} // namespace OHOS
void* DCameraProviderStubInstance();
void DestroyDCameraProviderStub(void* stubObj);
int32_t DCProviderServiceOnRemoteRequest(void* stub, int cmdId, struct HdfSBuf* data, struct HdfSBuf* reply);
#endif // DISTRIBUTED_CAMERA_PROVIDER_SERVER_STUB_H
@@ -1,163 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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.
*/
/**
* @file idistributed_camera_provider.h
*
* @brief Transfer interfaces call between distributed camera SA service and distributed camera HDF service,
* and provide Hardware Driver Interfaces (HDIs) for the upper layer.
*
* @since 1.0
* @version 1.0
*/
#ifndef HDI_DISTRIBUTED_CAMERA_PROVIDER_H
#define HDI_DISTRIBUTED_CAMERA_PROVIDER_H
#include "idistributed_camera_provider_callback.h"
namespace OHOS {
namespace DistributedHardware {
enum {
CMD_DISTRIBUTED_CAMERA_PROVIDER_ENABLE_DEVICE = 0,
CMD_DISTRIBUTED_CAMERA_PROVIDER_DISABLE_DEVICE,
CMD_DISTRIBUTED_CAMERA_PROVIDER_ACQUIRE_BUFFER,
CMD_DISTRIBUTED_CAMERA_PROVIDER_SHUTTER_BUFFER,
CMD_DISTRIBUTED_CAMERA_PROVIDER_ON_SETTINGS_RESULT,
CMD_DISTRIBUTED_CAMERA_PROVIDER_NOTIFY,
};
class IDCameraProvider : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"HDI.DCamera.V1_0.Provider");
virtual ~IDCameraProvider() {}
public:
/**
* @brief Obtains an <b>IDCameraProvider</b> instance.
* This function provides the entry to the distributed camera SA service.
* You must use this function to obtain an <b>IDCameraProvider</b> instance before performing other operations.
*
* @return Returns the <b>IDCameraProvider</b> instance if the operation is successful,
* returns <b>nullptr</b> otherwise.
*
* @since 1.0
* @version 1.0
*/
static sptr<IDCameraProvider> Get();
/**
* @brief Enable distributed camera device and set callback. For details about the callbacks,
* see {@link IDCameraProviderCallback}.
*
* @param dhBase [in] Distributed hardware device base info.
*
* @param abilityInfo [in] The static capability info of the distributed camera device to be enabled.
*
* @param callback [in] Indicates the callbacks to set.
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode EnableDCameraDevice(const std::shared_ptr<DHBase> &dhBase,
const std::string &abilityInfo, const sptr<IDCameraProviderCallback> &callback) = 0;
/**
* @brief Disable distributed camera device.
*
* @param dhBase [in] Distributed hardware device base info
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode DisableDCameraDevice(const std::shared_ptr<DHBase> &dhBase) = 0;
/**
* @brief Acquire a frame buffer from the procedure handle which attached to the streamId.
*
* @param dhBase [in] Distributed hardware device base info
*
* @param streamId [in] Indicates the ID of the stream to which the procedure handle is to be attached.
*
* @param buffer [out] A frame buffer
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode AcquireBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
std::shared_ptr<DCameraBuffer> &buffer) = 0;
/**
* @brief Notify distributed camera HDF service when a frame buffer has been filled.
*
* @param dhBase [in] Distributed hardware device base info
*
* @param streamId [in] Indicates the ID of the stream to which the frame buffer is to be attached.
*
* @param buffer [out] output frame buffer
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode ShutterBuffer(const std::shared_ptr<DHBase> &dhBase, int streamId,
const std::shared_ptr<DCameraBuffer> &buffer) = 0;
/**
* @brief Called to report metadata related to the distributed camera device.
*
* @param dhBase [in] Distributed hardware device base info
*
* @param result Indicates the metadata reported.
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode OnSettingsResult(const std::shared_ptr<DHBase> &dhBase,
const std::shared_ptr<DCameraSettings> &result) = 0;
/**
* @brief Called to notify some events from distributed camera SA service to distributed camera HDF service.
*
* @param dhBase [in] Distributed hardware device base info
*
* @param event [in] Detail event contents
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode Notify(const std::shared_ptr<DHBase> &dhBase,
const std::shared_ptr<DCameraHDFEvent> &event) = 0;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // HDI_DISTRIBUTED_CAMERA_PROVIDER_H
@@ -1,160 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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.
*/
/**
* @file idistributed_camera_provider_callback.h
*
* @brief Declares callbacks for distributed camera SA service. The caller needs to implement the callbacks.
*
* @since 1.0
* @version 1.0
*/
#ifndef HDI_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_H
#define HDI_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_H
#include <vector>
#include <iremote_broker.h>
#include "types.h"
namespace OHOS {
namespace DistributedHardware {
enum {
CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_OPEN_SESSION = 0,
CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_CLOSE_SESSION,
CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_CONFIGURE_STREAMS,
CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_RELEASE_STREAMS,
CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_START_CAPTURE,
CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_STOP_CAPTURE,
CMD_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_UPDATE_SETTINGS,
};
class IDCameraProviderCallback : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"HDI.DCamera.V1_0.ProviderCallback");
virtual ~IDCameraProviderCallback() {}
public:
/**
* @brief Create the transmission channel between the source device and the sink device.
* Open and initialize the distributed camera session.
*
* @param dhBase [in] Distributed hardware device base info
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode OpenSession(const std::shared_ptr<DHBase> &dhBase) = 0;
/**
* @brief Close the distributed camera session, and destroy the transmission channel between
* the source device and the sink device.
*
* @param dhBase [in] Distributed hardware device base info
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode CloseSession(const std::shared_ptr<DHBase> &dhBase) = 0;
/**
* @brief Configures streams.
*
* @param dhBase [in] Distributed hardware device base info
*
* @param streamInfos [in] Indicates the list of stream information, which is defined by {@link DCStreamInfo}.
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode ConfigureStreams(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCStreamInfo>> &streamInfos) = 0;
/**
* @brief Releases streams.
*
* @param dhBase [in] Distributed hardware device base info
*
* @param streamIds [IN] Indicates the IDs of the streams to release.
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode ReleaseStreams(const std::shared_ptr<DHBase> &dhBase, const std::vector<int> &streamIds) = 0;
/**
* @brief Start capture images.
* This function must be called after {@link ConfigStreams}.
* There are two image capture modes: continuous capture and single capture.
*
* @param dhBase [in] Distributed hardware device base info
*
* @param captureInfos [in] Indicates the capture request configuration information.
* For details, see {@link DCCaptureInfo}.
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode StartCapture(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCCaptureInfo>> &captureInfos) = 0;
/**
* @brief Stop capture images.
*
* @param dhBase [in] Distributed hardware device base info
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode StopCapture(const std::shared_ptr<DHBase> &dhBase, const std::vector<int> &streamIds) = 0;
/**
* @brief Updates distributed camera device control parameters.
*
* @param dhBase [in] Distributed hardware device base info
*
* @param settings [in] Indicates the camera parameters, including the sensor frame rate and 3A parameters.
* For details about the settings, see {@link DCameraSettings}.
*
* @return Returns <b>NO_ERROR</b> if the operation is successful,
* returns an error code defined in {@link DCamRetCode} otherwise.
*
* @since 1.0
* @version 1.0
*/
virtual DCamRetCode UpdateSettings(const std::shared_ptr<DHBase> &dhBase,
const std::vector<std::shared_ptr<DCameraSettings>> &settings) = 0;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // HDI_DISTRIBUTED_CAMERA_PROVIDER_CALLBACK_H
-306
View File
@@ -1,306 +0,0 @@
/*
* Copyright (c) 2021 Huawei Device 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.
*/
/**
* @file types.h
*
* @brief Declares data types used by the Hardware Driver Interfaces (HDIs) of this module.
*
* @since 1.0
* @version 1.0
*/
#ifndef DISTRIBUTED_CAMERA_PROVIDER_TYPES_H
#define DISTRIBUTED_CAMERA_PROVIDER_TYPES_H
#include <string>
#include <vector>
#include "buffer_handle.h"
namespace OHOS {
namespace DistributedHardware {
/**
* @brief Enumerates distributed camera metadata updating types.
*/
using DCSettingsType = enum _DCSettingsType : int32_t {
/**
* Set the whole package metadata.
*/
UPDATE_METADATA = 0,
/**
* Enable metadata.
*/
ENABLE_METADATA = 1,
/**
* Disable metadata.
*/
DISABLE_METADATA = 2,
/**
* Metadata result.
*/
METADATA_RESULT = 3,
/**
* Set flash light.
*/
SET_FLASH_LIGHT = 4,
/**
* Set fps range.
*/
FPS_RANGE = 5
};
/**
* @brief Enumerates return values of the HDIs.
*/
using DCamRetCode = enum _DCamRetCode : int32_t {
/**
* Successful call.
*/
SUCCESS = 0,
/**
* The camera device is busy.
*/
CAMERA_BUSY = 1,
/**
* Invalid parameters.
*/
INVALID_ARGUMENT = 2,
/**
* Unsupported function.
*/
METHOD_NOT_SUPPORTED = 3,
/**
* The camera device is offlined.
*/
CAMERA_OFFLINE = 4,
/**
* The number of distributed camera devices enabled exceeds the limit.
*/
EXCEED_MAX_NUMBER = 5,
/**
* The device is not initialized.
*/
DEVICE_NOT_INIT = 6,
/**
* Failed call.
*/
FAILED = -1,
};
/**
* @brief Enumerates encoding types of stream data.
*/
using DCEncodeType = enum _DCEncodeType : int32_t {
/**
* Unspecified
*/
ENCODE_TYPE_NULL = 0,
/**
* H.264
*/
ENCODE_TYPE_H264 = 1,
/**
* H.265
*/
ENCODE_TYPE_H265 = 2,
/**
* JPEG
*/
ENCODE_TYPE_JPEG = 3,
};
/**
* @brief Enumerates distributed camera inner stream types.
*/
using DCStreamType = enum _DCStreamType : int32_t {
/**
* Continuous capture stream. For example preview streams, video streams.
*/
CONTINUOUS_FRAME = 0,
/**
* Single capture stream. For example photographing streams.
*/
SNAPSHOT_FRAME = 1
};
/**
* @brief Distributed hardware device base info.
*/
using DHBase = struct _DHBase {
/**
* The device id.
*/
std::string deviceId_;
/**
* The distributed hardware id.
*/
std::string dhId_;
_DHBase() : deviceId_(""), dhId_("") {}
_DHBase(const std::string &deviceId, const std::string &dhId) : deviceId_(deviceId), dhId_(dhId) {}
bool operator ==(const _DHBase& others) const
{
return this->deviceId_ == others.deviceId_ && this->dhId_ == others.dhId_;
}
bool operator < (const _DHBase& others) const
{
return (this->deviceId_ + this->dhId_) < (others.deviceId_ + others.dhId_);
}
};
/**
* @brief The control settings of the distributed camera device.
*/
using DCameraSettings = struct _DCameraSettings {
/**
* Settings type.
*/
DCSettingsType type_;
/**
* Settings value. Serialized from bool, array, structure, etc.
*/
std::string value_;
};
/**
* @brief Defines the inner stream information of the distributed camera,
* which is used to pass configuration parameters during stream creation.
*/
using DCStreamInfo = struct _DCStreamInfo {
/**
* Stream ID, which uniquely identifies a stream on a camera device.
*/
int streamId_;
/**
* Image width.
*/
int width_;
/**
* Image height.
*/
int height_;
/**
* Image stride.
*/
int stride_;
/**
* Image format.
*/
int format_;
/**
* Image color space.
*/
int dataspace_;
/**
* Encoding type.
*/
DCEncodeType encodeType_;
/**
* Stream type.
*/
DCStreamType type_;
};
/**
* @brief Defines the information about a inner capture request of the distributed camera.
*/
using DCCaptureInfo = struct _DCCaptureInfo {
/**
* IDs of captured streams.
*/
std::vector<int> streamIds_;
/**
* Image width.
*/
int width_;
/**
* Image height.
*/
int height_;
/**
* Image stride.
*/
int stride_;
/**
* Image format.
*/
int format_;
/**
* Image color space.
*/
int dataspace_;
/**
* Capture Info
*/
bool isCapture_;
/**
* Encoding type.
*/
DCEncodeType encodeType_;
/**
* Stream type.
*/
DCStreamType type_;
/**
* Stream settings.
*/
std::vector<std::shared_ptr<DCameraSettings>> captureSettings_;
};
/**
* @brief Defines the inner buffer of the distributed camera,
* which is used to acquire buffer during processing capture requests.
*/
using DCameraBuffer = struct _DCameraBuffer {
/**
* Buffer index.
*/
int32_t index_;
/**
* Buffer size.
*/
uint32_t size_;
/**
* Buffer handle.
*/
BufferHandle* bufferHandle_;
};
/**
* @brief Notification event of the distributed camera.
*/
using DCameraHDFEvent = struct _DCameraHDFEvent {
/**
* Event type.
*/
int32_t type_;
/**
* Event result.
*/
int32_t result_;
/**
* Extended content (optional).
*/
std::string content_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISTRIBUTED_CAMERA_PROVIDER_TYPES_H
+13
View File
@@ -30,8 +30,18 @@ ohos_shared_library("distributed_camera_utils") {
"include/utils",
]
cflags = [
"-fPIC",
"-Wall",
]
if ("${product_name}" == "m40") {
cflags += [ "-DPRODUCT_M40" ]
}
sources = [
"src/utils/data_buffer.cpp",
"src/utils/dcamera_buffer_handle.cpp",
"src/utils/dcamera_hisysevent_adapter.cpp",
"src/utils/dcamera_sa_process_state.cpp",
"src/utils/dcamera_utils_tools.cpp",
@@ -50,10 +60,13 @@ ohos_shared_library("distributed_camera_utils") {
external_deps = [
"dsoftbus_standard:softbus_client",
"graphic_chipsetsdk:buffer_handle",
"hisysevent_native:libhisysevent",
"hiviewdfx_hilog_native:libhilog",
]
cflags_cc = cflags
subsystem_name = "distributedhardware"
part_name = "distributed_camera"
@@ -94,6 +94,7 @@ const std::string CAMERA_FORMAT_VIDEO = "Video";
const std::string CAMERA_FORMAT_PHOTO = "Photo";
const std::string CAMERA_RESOLUTION_KEY = "Resolution";
const std::string CAMERA_SURFACE_FORMAT = "CAMERA_SURFACE_FORMAT";
const std::string HDF_DCAMERA_EXT_SERVICE = "distributed_camera_provider_service";
const int32_t RESOLUTION_MAX_WIDTH_SNAPSHOT = 4096;
const int32_t RESOLUTION_MAX_HEIGHT_SNAPSHOT = 3072;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device 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
@@ -13,19 +13,15 @@
* limitations under the License.
*/
#include "dcamera_device_callback.h"
#include "distributed_hardware_log.h"
#ifndef OHOS_DCAMERA_BUFFER_HANDLE_H
#define OHOS_DCAMERA_BUFFER_HANDLE_H
#include "buffer_handle.h"
namespace OHOS {
namespace DistributedHardware {
void DCameraDeviceCallback::OnError(ErrorType type, int32_t errorMsg)
{
DHLOGW("DCameraDeviceCallback::OnError enter.");
}
void DCameraDeviceCallback::OnResult(uint64_t timestamp, const std::shared_ptr<Camera::CameraMetadata> &result)
{
DHLOGW("DCameraDeviceCallback::OnResult enter.");
}
void* DCameraMemoryMap(const BufferHandle *buffer);
void DCameraMemoryUnmap(BufferHandle *buffer);
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DCAMERA_BUFFER_HANDLE_H
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2022 Huawei Device 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 "dcamera_buffer_handle.h"
#include <cerrno>
#include <sys/mman.h>
#include "buffer_handle_utils.h"
#include "distributed_hardware_log.h"
namespace OHOS {
namespace DistributedHardware {
#ifdef PRODUCT_M40
void* DCameraMemoryMap(const BufferHandle *buffer)
{
if (buffer == nullptr) {
DHLOGE("mmap the buffer handle is NULL");
return nullptr;
}
if (buffer->reserveFds <= 0) {
DHLOGE("invalid file descriptor num : %d", buffer->reserveFds);
return nullptr;
}
void* virAddr = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, buffer->reserve[0], 0);
if (virAddr == MAP_FAILED) {
DHLOGE("mmap failed errno %s, fd : %d", strerror(errno), buffer->fd);
return nullptr;
}
return virAddr;
}
#else
void* DCameraMemoryMap(const BufferHandle *buffer)
{
if (buffer == nullptr) {
DHLOGE("mmap the buffer handle is NULL");
return nullptr;
}
void* virAddr = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, buffer->fd, 0);
if (virAddr == MAP_FAILED) {
DHLOGE("mmap failed errno %s, fd : %d", strerror(errno), buffer->fd);
return nullptr;
}
return virAddr;
}
#endif
void DCameraMemoryUnmap(BufferHandle *buffer)
{
if (buffer == nullptr) {
DHLOGE("unmmap the buffer handle is NULL");
return;
}
if (buffer->virAddr != nullptr) {
int ret = munmap(buffer->virAddr, buffer->size);
if (ret != 0) {
DHLOGE("munmap failed err: %s", strerror(errno));
}
}
buffer->virAddr = nullptr;
FreeBufferHandle(buffer);
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -18,10 +18,11 @@
#include "distributed_camera_constants.h"
#include "json/json.h"
#include "types.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraCaptureInfo {
public:
int32_t width_;
@@ -20,10 +20,11 @@
#include <string>
#include <vector>
#include "types.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraChannelDetail {
public:
DCameraChannelDetail() = default;
@@ -16,10 +16,11 @@
#ifndef OHOS_DCAMERA_METADATA_SETTING_H
#define OHOS_DCAMERA_METADATA_SETTING_H
#include "types.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraMetadataSettingCmd {
public:
std::string type_;
@@ -36,7 +36,6 @@ config("module_private_config") {
"${services_path}/cameraservice/base/include",
"${common_path}/include/constants",
"${common_path}/include/utils",
"${distributedcamera_hdf_path}/interfaces/include",
]
}
@@ -57,6 +56,7 @@ ohos_unittest("DCameraProtocolTest") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
@@ -42,7 +42,6 @@ ohos_shared_library("distributed_camera_client") {
"include/listener",
"${common_path}/include/constants",
"${common_path}/include/utils",
"${distributedcamera_hdf_path}/interfaces/include",
"${services_path}/cameraservice/base/include",
"//third_party/jsoncpp/include",
]
@@ -87,6 +86,7 @@ ohos_shared_library("distributed_camera_client") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"hiviewdfx_hilog_native:libhilog",
"multimedia_media_standard:media_client",
]
@@ -24,10 +24,11 @@
#include "data_buffer.h"
#include "dcamera_capture_info_cmd.h"
#include "dcamera_event_cmd.h"
#include "types.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class StateCallback {
public:
StateCallback() = default;
@@ -40,7 +40,6 @@ config("module_private_config") {
]
include_dirs += [
"${distributedcamera_hdf_path}/interfaces/include",
"${common_path}/include/constants",
"${common_path}/include/utils",
"${services_path}/cameraservice/base/include",
@@ -73,6 +72,7 @@ ohos_unittest("DCameraClientTest") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
@@ -42,7 +42,6 @@ ohos_shared_library("distributed_camera_handler") {
"include",
"${common_path}/include/constants",
"${common_path}/include/utils",
"${distributedcamera_hdf_path}/interfaces/include",
"${services_path}/cameraservice/cameraoperator/client/include/callback",
]
@@ -71,6 +70,7 @@ ohos_shared_library("distributed_camera_handler") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"hiviewdfx_hilog_native:libhilog",
"multimedia_media_standard:media_client",
]
@@ -25,10 +25,11 @@
#include "camera_manager.h"
#include "json/json.h"
#include "single_instance.h"
#include "types.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
struct ConfigInfo {
DCStreamType type;
std::string formatKey;
@@ -39,7 +39,6 @@ config("module_private_config") {
]
include_dirs += [
"${distributedcamera_hdf_path}/interfaces/include",
"${common_path}/include/constants",
"${common_path}/include/utils",
"${services_path}/cameraservice/base/include",
@@ -68,6 +67,7 @@ ohos_unittest("DCameraHandlerTest") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
+1 -1
View File
@@ -50,7 +50,6 @@ ohos_shared_library("distributed_camera_sink") {
"${innerkits_path}/native_cpp/camera_sink/include",
"${innerkits_path}/native_cpp/camera_source/include",
"${innerkits_path}/native_cpp/camera_source/include/callback",
"${distributedcamera_hdf_path}/interfaces/include",
"${services_path}/cameraservice/base/include",
"${services_path}/cameraservice/cameraoperator/client/include",
"${services_path}/cameraservice/cameraoperator/client/include/callback",
@@ -118,6 +117,7 @@ ohos_shared_library("distributed_camera_sink") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
@@ -42,7 +42,6 @@ config("module_private_config") {
include_dirs += [
"${common_path}/include/constants",
"${common_path}/include/utils",
"${distributedcamera_hdf_path}/interfaces/include",
"${innerkits_path}/native_cpp/camera_sink/include",
"${services_path}/cameraservice/base/include",
"${services_path}/cameraservice/cameraoperator/handler/include",
@@ -70,6 +69,7 @@ ohos_unittest("DistributedCameraSinkServiceTest") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
@@ -44,7 +44,6 @@ config("module_private_config") {
"${services_path}/data_process/include/utils",
"${common_path}/include/constants",
"${common_path}/include/utils",
"${distributedcamera_hdf_path}/interfaces/include",
"${innerkits_path}/native_cpp/camera_source/include",
"${innerkits_path}/native_cpp/camera_source/include/callback",
@@ -86,6 +85,7 @@ ohos_unittest("DCameraSinkMgrTest") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"multimedia_media_standard:media_client",
@@ -42,8 +42,6 @@ ohos_shared_library("distributed_camera_source") {
"${innerkits_path}/native_cpp/camera_source/include",
"${innerkits_path}/native_cpp/camera_sink/include",
"${innerkits_path}/native_cpp/camera_source/include/callback",
"${distributedcamera_hdf_path}/interfaces/include",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/client/provider",
"${services_path}/cameraservice/base/include",
"${services_path}/channel/include",
"${services_path}/data_process/include/eventbus",
@@ -89,7 +87,6 @@ ohos_shared_library("distributed_camera_source") {
deps = [
"${common_path}:distributed_camera_utils",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/client:distributed_camera_hdf_client",
"${fwk_utils_path}:distributedhardwareutils",
"${services_path}/channel:distributed_camera_channel",
"${services_path}/data_process:distributed_camera_data_process",
@@ -106,6 +103,7 @@ ohos_shared_library("distributed_camera_source") {
external_deps = [
"device_driver_framework:libhdf_utils",
"device_driver_framework:libhdi",
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
@@ -24,8 +24,8 @@
#include "icamera_state_listener.h"
#include "icamera_input.h"
#include "idistributed_camera_provider_callback.h"
#include "idistributed_camera_provider.h"
#include "v1_0/id_camera_provider_callback.h"
#include "v1_0/id_camera_provider.h"
namespace OHOS {
namespace DistributedHardware {
@@ -19,13 +19,14 @@
#include <variant>
#include "event.h"
#include "types.h"
#include "v1_0/dcamera_types.h"
#include "dcamera_event_cmd.h"
#include "dcamera_index.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
typedef enum {
DCAMERA_EVENT_REGIST = 0,
DCAMERA_EVENT_UNREGIST = 1,
@@ -24,7 +24,7 @@
#include "event_bus.h"
#include "icamera_channel.h"
#include "idistributed_camera_provider.h"
#include "v1_0/id_camera_provider.h"
namespace OHOS {
namespace DistributedHardware {
@@ -23,10 +23,11 @@
#include "dcamera_stream_data_process.h"
#include "icamera_source_data_process.h"
#include "types.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraSourceDataProcess : public ICameraSourceDataProcess {
public:
DCameraSourceDataProcess(std::string devId, std::string dhId, DCStreamType streamType);
@@ -19,10 +19,11 @@
#include <memory>
#include "icamera_channel_listener.h"
#include "types.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraSourceInput;
class DCameraSourceInputChannelListener : public ICameraChannelListener {
public:
@@ -23,12 +23,13 @@
#include "icamera_source_data_process.h"
#include "idata_process_pipeline.h"
#include "image_common_type.h"
#include "types.h"
#include "v1_0/dcamera_types.h"
#include "dcamera_stream_data_process_producer.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraStreamDataProcess : public std::enable_shared_from_this<DCameraStreamDataProcess> {
public:
DCameraStreamDataProcess(std::string devId, std::string dhId, DCStreamType streamType);
@@ -23,10 +23,11 @@
#include "data_buffer.h"
#include "event_handler.h"
#include "idistributed_camera_provider.h"
#include "v1_0/id_camera_provider.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraStreamDataProcessProducer {
public:
typedef enum {
@@ -45,7 +46,8 @@ private:
void StartEvent();
void LooperContinue();
void LooperSnapShot();
int32_t FeedStreamToDriver(const std::shared_ptr<DHBase>& dhBase, const std::shared_ptr<DataBuffer>& buffer);
int32_t FeedStreamToDriver(const DHBase& dhBase, const std::shared_ptr<DataBuffer>& buffer);
int32_t CheckSharedMemory(const DCameraBuffer& sharedMemory, const std::shared_ptr<DataBuffer>& buffer);
const uint32_t DCAMERA_PRODUCER_MAX_BUFFER_SIZE = 30;
const uint32_t DCAMERA_PRODUCER_RETRY_SLEEP_MS = 500;
@@ -16,26 +16,24 @@
#ifndef OHOS_DCAMERA_PROVIDER_CALLBACK_IMPL_H
#define OHOS_DCAMERA_PROVIDER_CALLBACK_IMPL_H
#include "dcamera_provider_callback.h"
#include "v1_0/id_camera_provider_callback.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraSourceDev;
class DCameraProviderCallbackImpl : public DCameraProviderCallback {
class DCameraProviderCallbackImpl : public IDCameraProviderCallback {
public:
DCameraProviderCallbackImpl(std::string devId, std::string dhId, std::shared_ptr<DCameraSourceDev>& sourceDev);
~DCameraProviderCallbackImpl();
DCamRetCode OpenSession(const std::shared_ptr<DHBase>& dhBase) override;
DCamRetCode CloseSession(const std::shared_ptr<DHBase>& dhBase) override;
DCamRetCode ConfigureStreams(const std::shared_ptr<DHBase>& dhBase,
const std::vector<std::shared_ptr<DCStreamInfo>>& streamInfos) override;
DCamRetCode ReleaseStreams(const std::shared_ptr<DHBase>& dhBase, const std::vector<int>& streamIds) override;
DCamRetCode StartCapture(const std::shared_ptr<DHBase>& dhBase,
const std::vector<std::shared_ptr<DCCaptureInfo>>& captureInfos) override;
DCamRetCode StopCapture(const std::shared_ptr<DHBase>& dhBase, const std::vector<int>& streamIds) override;
DCamRetCode UpdateSettings(const std::shared_ptr<DHBase>& dhBase,
const std::vector<std::shared_ptr<DCameraSettings>>& settings) override;
int32_t OpenSession(const DHBase& dhBase) override;
int32_t CloseSession(const DHBase& dhBase) override;
int32_t ConfigureStreams(const DHBase& dhBase, const std::vector<DCStreamInfo>& streamInfos) override;
int32_t ReleaseStreams(const DHBase& dhBase, const std::vector<int>& streamIds) override;
int32_t StartCapture(const DHBase& dhBase, const std::vector<DCCaptureInfo>& captureInfos) override;
int32_t StopCapture(const DHBase& dhBase, const std::vector<int>& streamIds) override;
int32_t UpdateSettings(const DHBase& dhBase, const std::vector<DCameraSettings>& settings) override;
private:
std::string devId_;
@@ -16,10 +16,11 @@
#ifndef OHOS_ICAMERA_INPUT_H
#define OHOS_ICAMERA_INPUT_H
#include "types.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class ICameraInput {
public:
virtual ~ICameraInput() = default;
@@ -19,10 +19,11 @@
#include <vector>
#include "data_buffer.h"
#include "types.h"
#include "v1_0/dcamera_types.h"
namespace OHOS {
namespace DistributedHardware {
using namespace OHOS::HDI::DistributedCamera::V1_0;
class DCameraStreamConfig {
public:
DCameraStreamConfig(int32_t width, int32_t height, int32_t format, int32_t dataspace,
@@ -235,7 +235,7 @@ int32_t DCameraSourceDev::ExecuteRegister(std::shared_ptr<DCameraRegistParam>& p
return ret;
}
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get();
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get(HDF_DCAMERA_EXT_SERVICE);
if (camHdiProvider == nullptr) {
DHLOGI("ExecuteRegister camHdiProvider is nullptr devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
@@ -243,10 +243,10 @@ int32_t DCameraSourceDev::ExecuteRegister(std::shared_ptr<DCameraRegistParam>& p
input_->UnInit();
return DCAMERA_BAD_OPERATE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>();
dhBase->deviceId_ = param->devId_;
dhBase->dhId_ = param->dhId_;
DCamRetCode retHdi = camHdiProvider->EnableDCameraDevice(dhBase, param->param_, hdiCallback_);
DHBase dhBase;
dhBase.deviceId_ = param->devId_;
dhBase.dhId_ = param->dhId_;
int32_t retHdi = camHdiProvider->EnableDCameraDevice(dhBase, param->param_, hdiCallback_);
DHLOGI("DCameraSourceDev Execute Register register hal, ret: %d, devId: %s dhId: %s", retHdi,
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
if (retHdi != SUCCESS) {
@@ -275,17 +275,17 @@ int32_t DCameraSourceDev::ExecuteUnRegister(std::shared_ptr<DCameraRegistParam>&
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
}
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get();
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get(HDF_DCAMERA_EXT_SERVICE);
if (camHdiProvider == nullptr) {
DHLOGI("ExecuteUnRegister camHdiProvider is nullptr devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
return DCAMERA_BAD_OPERATE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>();
dhBase->deviceId_ = param->devId_;
dhBase->dhId_ = param->dhId_;
DCamRetCode retHdi = camHdiProvider->DisableDCameraDevice(dhBase);
DHBase dhBase;
dhBase.deviceId_ = param->devId_;
dhBase.dhId_ = param->dhId_;
int32_t retHdi = camHdiProvider->DisableDCameraDevice(dhBase);
DHLOGI("DCameraSourceDev Execute UnRegister unregister hal, ret: %d, devId: %s dhId: %s", retHdi,
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
if (retHdi != SUCCESS) {
@@ -437,8 +437,8 @@ int32_t DCameraSourceDev::ExecuteStartCapture(std::vector<std::shared_ptr<DCCapt
for (auto settingIter = (*iter)->captureSettings_.begin(); settingIter != (*iter)->captureSettings_.end();
settingIter++) {
std::shared_ptr<DCameraSettings> setting = std::make_shared<DCameraSettings>();
setting->type_ = (*settingIter)->type_;
setting->value_ = (*settingIter)->value_;
setting->type_ = settingIter->type_;
setting->value_ = settingIter->value_;
capture->captureSettings_.push_back(setting);
}
captures.push_back(capture);
@@ -165,20 +165,20 @@ int32_t DCameraSourceController::ChannelNeg(std::shared_ptr<DCameraChannelInfo>&
int32_t DCameraSourceController::DCameraNotify(std::shared_ptr<DCameraEvent>& events)
{
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get();
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get(HDF_DCAMERA_EXT_SERVICE);
if (camHdiProvider == nullptr) {
DHLOGI("DCameraNotify camHdiProvider is nullptr devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
return DCAMERA_BAD_OPERATE;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>();
dhBase->deviceId_ = devId_;
dhBase->dhId_ = dhId_;
std::shared_ptr<DCameraHDFEvent> hdiEvent = std::make_shared<DCameraHDFEvent>();
hdiEvent->type_ = events->eventType_;
hdiEvent->result_ = events->eventResult_;
hdiEvent->content_ = events->eventContent_;
DCamRetCode retHdi = camHdiProvider->Notify(dhBase, hdiEvent);
DHBase dhBase;
dhBase.deviceId_ = devId_;
dhBase.dhId_ = dhId_;
DCameraHDFEvent hdiEvent;
hdiEvent.type_ = events->eventType_;
hdiEvent.result_ = events->eventResult_;
hdiEvent.content_ = events->eventContent_;
int32_t retHdi = camHdiProvider->Notify(dhBase, hdiEvent);
DHLOGI("Nofify hal, ret: %d, devId: %s dhId: %s, type: %d, result: %d, content: %s", retHdi,
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), events->eventType_, events->eventResult_,
events->eventContent_.c_str());
@@ -446,7 +446,7 @@ void DCameraSourceController::OnDataReceived(std::vector<std::shared_ptr<DataBuf
void DCameraSourceController::HandleMetaDataResult(std::string& jsonStr)
{
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get();
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get(HDF_DCAMERA_EXT_SERVICE);
if (camHdiProvider == nullptr) {
DHLOGI("DCameraSourceController HandleMetaDataResult camHdiProvider is null, devId: %s, dhId: %s",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
@@ -459,11 +459,14 @@ void DCameraSourceController::HandleMetaDataResult(std::string& jsonStr)
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
return;
}
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>();
dhBase->deviceId_ = devId_;
dhBase->dhId_ = dhId_;
DHBase dhBase;
dhBase.deviceId_ = devId_;
dhBase.dhId_ = dhId_;
for (auto iter = cmd.value_.begin(); iter != cmd.value_.end(); iter++) {
DCamRetCode retHdi = camHdiProvider->OnSettingsResult(dhBase, (*iter));
DCameraSettings setting;
setting.type_ = (*iter)->type_;
setting.value_ = (*iter)->value_;
int32_t retHdi = camHdiProvider->OnSettingsResult(dhBase, setting);
DHLOGI("OnSettingsResult hal, ret: %d, devId: %s dhId: %s, type: %d, result: %d, content: %s", retHdi,
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
}
@@ -19,6 +19,7 @@
#include <securec.h>
#include "anonymous_string.h"
#include "dcamera_buffer_handle.h"
#include "distributed_camera_constants.h"
#include "distributed_camera_errno.h"
#include "distributed_hardware_log.h"
@@ -111,9 +112,9 @@ void DCameraStreamDataProcessProducer::LooperContinue()
{
DHLOGI("LooperContinue producer devId: %s dhId: %s streamType: %d streamId: %d state: %d",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId_, state_);
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>();
dhBase->deviceId_ = devId_;
dhBase->dhId_ = dhId_;
DHBase dhBase;
dhBase.deviceId_ = devId_;
dhBase.dhId_ = dhId_;
while (state_ == DCAMERA_PRODUCER_STATE_START) {
std::shared_ptr<DataBuffer> buffer = nullptr;
@@ -154,9 +155,9 @@ void DCameraStreamDataProcessProducer::LooperSnapShot()
{
DHLOGI("LooperSnapShot producer devId: %s dhId: %s streamType: %d streamId: %d state: %d",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId_, state_);
std::shared_ptr<DHBase> dhBase = std::make_shared<DHBase>();
dhBase->deviceId_ = devId_;
dhBase->dhId_ = dhId_;
DHBase dhBase;
dhBase.deviceId_ = devId_;
dhBase.dhId_ = dhId_;
while (state_ == DCAMERA_PRODUCER_STATE_START) {
std::shared_ptr<DataBuffer> buffer = nullptr;
@@ -195,61 +196,79 @@ void DCameraStreamDataProcessProducer::LooperSnapShot()
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId_, state_);
}
int32_t DCameraStreamDataProcessProducer::FeedStreamToDriver(const std::shared_ptr<DHBase>& dhBase,
int32_t DCameraStreamDataProcessProducer::FeedStreamToDriver(const DHBase& dhBase,
const std::shared_ptr<DataBuffer>& buffer)
{
DHLOGD("LooperFeed devId %s dhId %s streamSize: %d streamType: %d, streamId: %d", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str(), buffer->Size(), streamType_, streamId_);
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get();
sptr<IDCameraProvider> camHdiProvider = IDCameraProvider::Get(HDF_DCAMERA_EXT_SERVICE);
if (camHdiProvider == nullptr) {
DHLOGI("camHdiProvider is nullptr");
return DCAMERA_BAD_VALUE;
}
std::shared_ptr<DCameraBuffer> sharedMemory;
DCamRetCode retHdi = camHdiProvider->AcquireBuffer(dhBase, streamId_, sharedMemory);
if (retHdi != SUCCESS) {
DCameraBuffer sharedMemory;
int32_t ret = camHdiProvider->AcquireBuffer(dhBase, streamId_, sharedMemory);
if (ret != SUCCESS) {
DHLOGE("AcquireBuffer devId: %s dhId: %s streamId: %d ret: %d",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_, retHdi);
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_, ret);
return DCAMERA_BAD_OPERATE;
}
int32_t ret = DCAMERA_OK;
do {
if (sharedMemory == nullptr) {
DHLOGE("sharedMemory devId: %s dhId: %s streamId: %d, sharedMemory is null",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_);
ret = CheckSharedMemory(sharedMemory, buffer);
if (ret != DCAMERA_OK) {
DHLOGE("CheckSharedMemory failed devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
break;
}
sharedMemory.bufferHandle_->GetBufferHandle()->virAddr =
DCameraMemoryMap(sharedMemory.bufferHandle_->GetBufferHandle());
if (sharedMemory.bufferHandle_->GetBufferHandle()->virAddr == nullptr) {
DHLOGE("mmap failed devId: %s dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
ret = DCAMERA_MEMORY_OPT_ERROR;
break;
}
if (buffer->Size() > sharedMemory->size_) {
DHLOGE("sharedMemory devId: %s dhId: %s streamId: %d bufSize: %d, addressSize: %d",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_, buffer->Size(),
sharedMemory->size_);
ret = DCAMERA_MEMORY_OPT_ERROR;
break;
}
ret = memcpy_s(sharedMemory->bufferHandle_->virAddr, sharedMemory->size_, buffer->Data(),
ret = memcpy_s(sharedMemory.bufferHandle_->GetBufferHandle()->virAddr, sharedMemory.size_, buffer->Data(),
buffer->Size());
if (ret != EOK) {
DHLOGE("memcpy_s devId: %s dhId: %s streamId: %d bufSize: %d, addressSize: %d",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_, buffer->Size(),
sharedMemory->size_);
sharedMemory.size_);
ret = DCAMERA_MEMORY_OPT_ERROR;
break;
}
sharedMemory->size_ = buffer->Size();
sharedMemory.size_ = buffer->Size();
} while (0);
retHdi = camHdiProvider->ShutterBuffer(dhBase, streamId_, sharedMemory);
if (retHdi != SUCCESS) {
ret = camHdiProvider->ShutterBuffer(dhBase, streamId_, sharedMemory);
DCameraMemoryUnmap(sharedMemory.bufferHandle_->GetBufferHandle());
if (ret != SUCCESS) {
DHLOGE("ShutterBuffer devId: %s dhId: %s streamId: %d ret: %d",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_, retHdi);
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_, ret);
return DCAMERA_BAD_OPERATE;
}
DHLOGD("LooperFeed end devId %s dhId %s streamSize: %d streamType: %d, streamId: %d",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), buffer->Size(), streamType_, streamId_);
return ret;
}
int32_t DCameraStreamDataProcessProducer::CheckSharedMemory(const DCameraBuffer& sharedMemory,
const std::shared_ptr<DataBuffer>& buffer)
{
if (sharedMemory.bufferHandle_ == nullptr || sharedMemory.bufferHandle_->GetBufferHandle() == nullptr) {
DHLOGE("bufferHandle read failed devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
return DCAMERA_MEMORY_OPT_ERROR;
}
if (buffer->Size() > sharedMemory.size_) {
DHLOGE("sharedMemory devId: %s dhId: %s streamId: %d bufSize: %d, addressSize: %d",
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamId_, buffer->Size(),
sharedMemory.size_);
return DCAMERA_MEMORY_OPT_ERROR;
}
return DCAMERA_OK;
}
} // namespace DistributedHardware
} // namespace OHOS
@@ -20,7 +20,6 @@
#include "anonymous_string.h"
#include "distributed_camera_errno.h"
#include "distributed_hardware_log.h"
#include "types.h"
namespace OHOS {
namespace DistributedHardware {
@@ -22,8 +22,6 @@
#include "distributed_camera_errno.h"
#include "distributed_hardware_log.h"
#include "types.h"
namespace OHOS {
namespace DistributedHardware {
DCameraProviderCallbackImpl::DCameraProviderCallbackImpl(std::string devId, std::string dhId,
@@ -39,7 +37,7 @@ DCameraProviderCallbackImpl::~DCameraProviderCallbackImpl()
GetAnonyString(dhId_).c_str());
}
DCamRetCode DCameraProviderCallbackImpl::OpenSession(const std::shared_ptr<DHBase>& dhBase)
int32_t DCameraProviderCallbackImpl::OpenSession(const DHBase& dhBase)
{
DHLOGI("DCameraProviderCallbackImpl OpenSession devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
@@ -59,7 +57,7 @@ DCamRetCode DCameraProviderCallbackImpl::OpenSession(const std::shared_ptr<DHBas
return SUCCESS;
}
DCamRetCode DCameraProviderCallbackImpl::CloseSession(const std::shared_ptr<DHBase>& dhBase)
int32_t DCameraProviderCallbackImpl::CloseSession(const DHBase& dhBase)
{
DHLOGI("DCameraProviderCallbackImpl CloseSession devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
@@ -79,8 +77,8 @@ DCamRetCode DCameraProviderCallbackImpl::CloseSession(const std::shared_ptr<DHBa
return SUCCESS;
}
DCamRetCode DCameraProviderCallbackImpl::ConfigureStreams(const std::shared_ptr<DHBase>& dhBase,
const std::vector<std::shared_ptr<DCStreamInfo>>& streamInfos)
int32_t DCameraProviderCallbackImpl::ConfigureStreams(const DHBase& dhBase,
const std::vector<DCStreamInfo>& streamInfos)
{
DHLOGI("DCameraProviderCallbackImpl ConfigStreams devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
@@ -90,7 +88,20 @@ DCamRetCode DCameraProviderCallbackImpl::ConfigureStreams(const std::shared_ptr<
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
return FAILED;
}
int32_t ret = sourceDev->ConfigStreams(streamInfos);
std::vector<std::shared_ptr<DCStreamInfo>> streams;
for (auto iter = streamInfos.begin(); iter != streamInfos.end(); iter++) {
std::shared_ptr<DCStreamInfo> stream = std::make_shared<DCStreamInfo>();
stream->streamId_ = iter->streamId_;
stream->width_ = iter->width_;
stream->height_ = iter->height_;
stream->stride_ = iter->stride_;
stream->format_ = iter->format_;
stream->dataspace_ = iter->dataspace_;
stream->encodeType_ = iter->encodeType_;
stream->type_ = iter->type_;
streams.push_back(stream);
}
int32_t ret = sourceDev->ConfigStreams(streams);
if (ret != DCAMERA_OK) {
DHLOGE("DCameraProviderCallbackImpl CloseSession failed, ret: %d, devId: %s, dhId: %s", ret,
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
@@ -99,8 +110,7 @@ DCamRetCode DCameraProviderCallbackImpl::ConfigureStreams(const std::shared_ptr<
return SUCCESS;
}
DCamRetCode DCameraProviderCallbackImpl::ReleaseStreams(const std::shared_ptr<DHBase>& dhBase,
const std::vector<int>& streamIds)
int32_t DCameraProviderCallbackImpl::ReleaseStreams(const DHBase& dhBase, const std::vector<int>& streamIds)
{
DHLOGI("DCameraProviderCallbackImpl ReleaseStreams devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
@@ -119,8 +129,7 @@ DCamRetCode DCameraProviderCallbackImpl::ReleaseStreams(const std::shared_ptr<DH
return SUCCESS;
}
DCamRetCode DCameraProviderCallbackImpl::StartCapture(const std::shared_ptr<DHBase>& dhBase,
const std::vector<std::shared_ptr<DCCaptureInfo>>& captureInfos)
int32_t DCameraProviderCallbackImpl::StartCapture(const DHBase& dhBase, const std::vector<DCCaptureInfo>& captureInfos)
{
DHLOGI("DCameraProviderCallbackImpl StartCapture devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
@@ -130,7 +139,23 @@ DCamRetCode DCameraProviderCallbackImpl::StartCapture(const std::shared_ptr<DHBa
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
return FAILED;
}
int32_t ret = sourceDev->StartCapture(captureInfos);
std::vector<std::shared_ptr<DCCaptureInfo>> captures;
for (auto iter = captureInfos.begin(); iter != captureInfos.end(); iter++) {
std::shared_ptr<DCCaptureInfo> capture = std::make_shared<DCCaptureInfo>();
capture->streamIds_.assign(iter->streamIds_.begin(), iter->streamIds_.end());
capture->width_ = iter->width_;
capture->height_ = iter->height_;
capture->stride_ = iter->stride_;
capture->format_ = iter->format_;
capture->dataspace_ = iter->dataspace_;
capture->isCapture_ = iter->isCapture_;
capture->encodeType_ = iter->encodeType_;
capture->type_ = iter->type_;
capture->captureSettings_.assign(iter->captureSettings_.begin(), iter->captureSettings_.end());
captures.push_back(capture);
}
int32_t ret = sourceDev->StartCapture(captures);
if (ret != DCAMERA_OK) {
DHLOGE("DCameraProviderCallbackImpl StartCapture failed, ret: %d, devId: %s, dhId: %s", ret,
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
@@ -139,8 +164,7 @@ DCamRetCode DCameraProviderCallbackImpl::StartCapture(const std::shared_ptr<DHBa
return SUCCESS;
}
DCamRetCode DCameraProviderCallbackImpl::StopCapture(const std::shared_ptr<DHBase>& dhBase,
const std::vector<int>& streamIds)
int32_t DCameraProviderCallbackImpl::StopCapture(const DHBase& dhBase, const std::vector<int>& streamIds)
{
DHLOGI("DCameraProviderCallbackImpl StopCapture devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
@@ -159,8 +183,7 @@ DCamRetCode DCameraProviderCallbackImpl::StopCapture(const std::shared_ptr<DHBas
return SUCCESS;
}
DCamRetCode DCameraProviderCallbackImpl::UpdateSettings(const std::shared_ptr<DHBase>& dhBase,
const std::vector<std::shared_ptr<DCameraSettings>>& settings)
int32_t DCameraProviderCallbackImpl::UpdateSettings(const DHBase& dhBase, const std::vector<DCameraSettings>& settings)
{
DHLOGI("DCameraProviderCallbackImpl UpdateSettings devId: %s dhId: %s", GetAnonyString(devId_).c_str(),
GetAnonyString(dhId_).c_str());
@@ -170,7 +193,15 @@ DCamRetCode DCameraProviderCallbackImpl::UpdateSettings(const std::shared_ptr<DH
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
return FAILED;
}
int32_t ret = sourceDev->UpdateCameraSettings(settings);
std::vector<std::shared_ptr<DCameraSettings>> settingInfos;
for (auto iter = settings.begin(); iter != settings.end(); iter++) {
std::shared_ptr<DCameraSettings> settingInfo = std::make_shared<DCameraSettings>();
settingInfo->type_ = iter->type_;
settingInfo->value_ = iter->value_;
settingInfos.push_back(settingInfo);
}
int32_t ret = sourceDev->UpdateCameraSettings(settingInfos);
if (ret != DCAMERA_OK) {
DHLOGE("DCameraProviderCallbackImpl UpdateSettings failed, ret: %d, devId: %s, dhId: %s", ret,
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
@@ -46,7 +46,6 @@ config("module_private_config") {
"${fwk_utils_path}/include/eventbus",
"${fwk_common_path}/utils/include",
"${fwk_common_path}/log/include",
"${distributedcamera_hdf_path}/interfaces/include",
"${distributedcamera_hdf_path}/interfaces/hdi_ipc/client/provider",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
@@ -73,6 +72,7 @@ ohos_unittest("DCameraSourceMgrTest") {
]
external_deps = [
"distributed_camera_device_driver_interface:libdistributed_camera_provider_proxy_1.0",
"dsoftbus_standard:softbus_client",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",