upload
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
TOPDIR := $(patsubst %,%,$(CURDIR))
|
||||
|
||||
ifndef DDK_PATH
|
||||
$(error "Can not find DDK_PATH env, please set it in environment!.")
|
||||
endif
|
||||
|
||||
LOCAL_MODULE_NAME := libatlasutil.so
|
||||
CC := aarch64-linux-gnu-g++
|
||||
|
||||
|
||||
LOCAL_DIR := .
|
||||
OUT_DIR = out
|
||||
OBJ_DIR = $(OUT_DIR)/obj
|
||||
DEPS_DIR = $(OUT_DIR)/deps
|
||||
LOCAL_LIBRARY=$(OUT_DIR)/$(LOCAL_MODULE_NAME)
|
||||
OUT_INC_DIR = $(OUT_DIR)/include
|
||||
|
||||
INC_DIR = \
|
||||
-I$(HOME)/Ascend/driver/ \
|
||||
-I$(DDK_PATH)/../arm64-linux_gcc7.3.0/acllib/include/
|
||||
|
||||
|
||||
CC_FLAGS := $(INC_DIR) -DENABLE_DVPP_INTERFACE -std=c++11 -fPIC -Wall -O2
|
||||
LNK_FLAGS := \
|
||||
-L$(NPU_HOST_LIB) \
|
||||
-L$(HOME)/Ascend/driver \
|
||||
-lmedia_mini \
|
||||
-lascendcl \
|
||||
-lacl_dvpp \
|
||||
-shared
|
||||
|
||||
SRCS := $(patsubst $(LOCAL_DIR)/%.cpp, %.cpp, $(shell find $(LOCAL_DIR) -name "*.cpp"))
|
||||
OBJS := $(addprefix $(OBJ_DIR)/, $(patsubst %.cpp, %.o,$(SRCS)))
|
||||
|
||||
ALL_OBJS := $(OBJS)
|
||||
|
||||
all: do_pre_build do_build
|
||||
|
||||
do_pre_build:
|
||||
$(Q)echo - do [$@]
|
||||
$(Q)mkdir -p $(OBJ_DIR)
|
||||
$(Q)mkdir -p $(OUT_INC_DIR)
|
||||
|
||||
do_build: $(LOCAL_LIBRARY) | do_pre_build
|
||||
$(Q)echo - do [$@]
|
||||
|
||||
$(LOCAL_LIBRARY): $(ALL_OBJS)
|
||||
$(Q)echo [LD] $@
|
||||
$(Q)$(CC) $(CC_FLAGS) -o $@ $^ -Wl,--whole-archive -Wl,--no-whole-archive -Wl,--start-group -Wl,--end-group -Wl,-rpath='/home/HwHiAiUser/HIAI_PROJECTS/ascend_lib' $(LNK_FLAGS)
|
||||
|
||||
|
||||
$(OBJS): $(OBJ_DIR)/%.o : %.cpp | do_pre_build
|
||||
$(Q)echo [CC] $@
|
||||
$(Q)mkdir -p $(dir $@)
|
||||
$(Q)$(CC) $(CC_FLAGS) $(INC_DIR) -c -fstack-protector-all $< -o $@
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf $(TOPDIR)/out
|
||||
@@ -0,0 +1,209 @@
|
||||
/**
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2018, Hisilicon Technologies Co., Ltd. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1 Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2 Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3 Neither the names of the copyright holders nor the names of the
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* ============================================================================
|
||||
*/
|
||||
#include <memory>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "acl/acl.h"
|
||||
#include "acl/ops/acl_dvpp.h"
|
||||
#include "atlas_utils_common.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" {
|
||||
|
||||
#if 0
|
||||
void* CopyDataHostToDvpp(void* data, int size) {
|
||||
void* buffer = nullptr;
|
||||
|
||||
auto aclRet = acldvppMalloc(&buffer, size);
|
||||
if (aclRet != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("acl malloc dvpp data failed, dataSize=%u, ret=%d",
|
||||
size, aclRet);
|
||||
return nullptr;
|
||||
}
|
||||
printf("malloc dvpp memory size %d ok", size);
|
||||
// copy input to device memory
|
||||
aclRet = aclrtMemcpy(buffer, size, data, size, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||
if (aclRet != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("acl memcpy data to dvpp failed, size %u, error %d", size, aclRet);
|
||||
acldvppFree(buffer);
|
||||
return nullptr;
|
||||
}
|
||||
printf("copy data to dvpp ok");
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void* CopyDataHostToDevice(void* data, int size) {
|
||||
void* buffer = nullptr;
|
||||
|
||||
auto aclRet = aclrtMalloc(&buffer, size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||
if (aclRet != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("acl malloc device memory failed, dataSize=%u, ret=%d",
|
||||
size, aclRet);
|
||||
return nullptr;
|
||||
}
|
||||
// copy input to device memory
|
||||
aclRet = aclrtMemcpy(buffer, size, data, size, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||
if (aclRet != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("acl memcpy data to dev failed, size %u, error %d", size, aclRet);
|
||||
aclrtFree(buffer);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void* CopyDataDeviceToDevice(void* data, int size) {
|
||||
void* buffer = nullptr;
|
||||
|
||||
auto aclRet = aclrtMalloc(&buffer, size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||
if (aclRet != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("acl malloc device memory failed, dataSize=%u, ret=%d",
|
||||
size, aclRet);
|
||||
return nullptr;
|
||||
}
|
||||
// copy input to device memory
|
||||
aclRet = aclrtMemcpy(buffer, size, data, size, ACL_MEMCPY_DEVICE_TO_DEVICE);
|
||||
if (aclRet != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("acl memcpy data to dev failed, size %u, error %d", size, aclRet);
|
||||
aclrtFree(buffer);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void* CopyDataDeviceToHost(void* deviceData, uint32_t dataLen) {
|
||||
void *outHostData = nullptr;
|
||||
|
||||
aclError ret = aclrtMallocHost(&outHostData, dataLen);
|
||||
if (ret != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("aclrtMallocHost failed, ret[%d]", ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ret = aclrtMemcpy(outHostData, dataLen, deviceData,
|
||||
dataLen, ACL_MEMCPY_DEVICE_TO_HOST);
|
||||
if (ret != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("aclrtMemcpy failed, ret[%d]", ret);
|
||||
aclrtFreeHost(outHostData);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return outHostData;
|
||||
}
|
||||
|
||||
void* CopyDataDeviceToNewBuf(void* deviceData, uint32_t dataLen) {
|
||||
uint8_t* outHostData = new uint8_t[dataLen];
|
||||
|
||||
/* aclError ret = aclrtMallocHost(&outHostData, dataLen);
|
||||
if (ret != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("aclrtMallocHost failed, ret[%d]", ret);
|
||||
return nullptr;
|
||||
}
|
||||
*/
|
||||
int ret = aclrtMemcpy(outHostData, dataLen, deviceData,
|
||||
dataLen, ACL_MEMCPY_DEVICE_TO_HOST);
|
||||
if (ret != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("aclrtMemcpy failed, ret[%d]", ret);
|
||||
aclrtFreeHost(outHostData);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return (void *)outHostData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SaveBinFile(const char* filename, void* data, uint32_t size) {
|
||||
FILE *outFileFp = fopen(filename, "wb+");
|
||||
if (outFileFp == nullptr) {
|
||||
ASC_LOG_ERROR("Save file %s failed for open error", filename);
|
||||
return;
|
||||
}
|
||||
fwrite(data, 1, size, outFileFp);
|
||||
|
||||
fflush(outFileFp);
|
||||
fclose(outFileFp);
|
||||
}
|
||||
|
||||
char* ReadBinFile(const std::string& fileName, uint32_t& fileSize)
|
||||
{
|
||||
std::ifstream binFile(fileName, std::ifstream::binary);
|
||||
if (binFile.is_open() == false) {
|
||||
ASC_LOG_ERROR("open file %s failed", fileName.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
binFile.seekg(0, binFile.end);
|
||||
uint32_t binFileBufferLen = binFile.tellg();
|
||||
if (binFileBufferLen == 0) {
|
||||
ASC_LOG_ERROR("binfile is empty, filename is %s", fileName.c_str());
|
||||
binFile.close();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
binFile.seekg(0, binFile.beg);
|
||||
|
||||
char* binFileBufferData = new(std::nothrow) char[binFileBufferLen];
|
||||
if (binFileBufferData == nullptr) {
|
||||
ASC_LOG_ERROR("malloc binFileBufferData failed");
|
||||
binFile.close();
|
||||
return nullptr;
|
||||
}
|
||||
binFile.read(binFileBufferData, binFileBufferLen);
|
||||
binFile.close();
|
||||
fileSize = binFileBufferLen;
|
||||
return binFileBufferData;
|
||||
}
|
||||
|
||||
int ReadImageFile(ImageData* image, const string& filename) {
|
||||
char* data;
|
||||
uint32_t size = 0;
|
||||
|
||||
data = ReadBinFile(filename, size);
|
||||
if (data == nullptr) {
|
||||
ASC_LOG_ERROR("Read image file %s failed", filename.c_str());
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
image->data = SHARED_PRT_U8_BUF(data);
|
||||
image->size = size;
|
||||
printf("read image ok, size %d", size);
|
||||
return STATUS_OK;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2018, Hisilicon Technologies Co., Ltd. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1 Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2 Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3 Neither the names of the copyright holders nor the names of the
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
#ifndef _ATLAS_UTILS_COMMON_H_
|
||||
#define _ATLAS_UTILS_COMMON_H_
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include "acl/acl_base.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define STATUS_ERROR -1
|
||||
#define STATUS_OK 0
|
||||
|
||||
#define ALIGN_UP(num, align) (((num) + (align) - 1) & ~((align) - 1))
|
||||
#define ALIGN_UP2(num) ALIGN_UP(num, 2)
|
||||
#define ALIGN_UP16(num) ALIGN_UP(num, 16)
|
||||
#define ALIGN_UP128(num) ALIGN_UP(num, 128)
|
||||
|
||||
#define YUV420SP_SIZE(width, height) ((width) * (height) * 3 / 2)
|
||||
//#define SHARED_PRT_DVPP_BUF(buf) (shared_ptr<uint8_t>((uint8_t *)(buf), [](uint8_t* p) { acldvppFree(p); }))
|
||||
//#define SHARED_PRT_U8_BUF(buf) (shared_ptr<uint8_t>((uint8_t *)(buf), [](uint8_t* p) { delete[](p); }))
|
||||
|
||||
|
||||
#define ASC_LOG_ERROR(fmt, ...) \
|
||||
do{aclAppLog(ACL_ERROR, __FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
printf(fmt"\n", ##__VA_ARGS__);}while(0)
|
||||
|
||||
#define ASC_LOG_INFO(fmt, ...) \
|
||||
do{aclAppLog(ACL_INFO, __FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
printf(fmt"\n", ##__VA_ARGS__);}while(0)
|
||||
|
||||
#define ASC_LOG_DEBUG(fmt, ...) \
|
||||
do{aclAppLog(ACL_DEBUG, __FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
printf(fmt"\n", ##__VA_ARGS__);}while(0)
|
||||
#if 0
|
||||
struct ImageData {
|
||||
bool isAligned = false;
|
||||
uint32_t format = 1; //PIXEL_FORMAT_YUV_SEMIPLANAR_420;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
uint32_t alignWidth = 0;
|
||||
uint32_t alignHeight = 0;
|
||||
uint32_t size = 0;
|
||||
std::shared_ptr<uint8_t> data;
|
||||
};
|
||||
|
||||
struct FrameData {
|
||||
bool isFinished = false;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
uint32_t frameId = 0;
|
||||
ImageData image;
|
||||
};
|
||||
|
||||
struct Resolution {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
};
|
||||
|
||||
struct BoxArea {
|
||||
uint32_t ltx;
|
||||
uint32_t lty;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
};
|
||||
|
||||
|
||||
struct DataBuffer {
|
||||
uint32_t size;
|
||||
std::shared_ptr<void> data;
|
||||
};
|
||||
|
||||
struct DetectionData {
|
||||
ImageData image;
|
||||
std::vector<DataBuffer> output;
|
||||
};
|
||||
|
||||
struct AtlasMessage {
|
||||
int dest;
|
||||
int msgId;
|
||||
std::shared_ptr<void> data;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
void* CopyDataDeviceToHost(void* deviceData, uint32_t dataLen);
|
||||
void* CopyDataHostToDvpp(void* data, int size);
|
||||
void* CopyDataHostToDevice(void* data, int size);
|
||||
void* CopyDataDeviceToDevice(void* data, int size);
|
||||
void* CopyDataDeviceToNewBuf(void* deviceData, uint32_t dataLen);
|
||||
|
||||
void SaveBinFile(const char* filename, void* data, uint32_t size);
|
||||
int ReadImageFile(ImageData* image, const string& filename);
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif /* HIAI_APP_IMAGE_POOL_H_ */
|
||||
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2018, Hisilicon Technologies Co., Ltd. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1 Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2 Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3 Neither the names of the copyright holders nor the names of the
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* ============================================================================
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include <memory>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "acl/acl.h"
|
||||
#include "acl/ops/acl_dvpp.h"
|
||||
#include "atlas_utils_common.h"
|
||||
#include "camera.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" {
|
||||
#include "peripheral_api.h"
|
||||
#include "camera.h"
|
||||
|
||||
CameraManager g_CameraMgr;
|
||||
|
||||
int CameraInit(int id, int fps, int width, int height) {
|
||||
if (!g_CameraMgr.hwInited) {
|
||||
MediaLibInit();
|
||||
g_CameraMgr.hwInited = 1;
|
||||
}
|
||||
|
||||
Camera& cap = CAMERA(id);
|
||||
cap.frameSize = YUV420SP_SIZE(width, height);
|
||||
cap.id = id;
|
||||
cap.fps = fps;
|
||||
cap.width = width;
|
||||
cap.height = height;
|
||||
cap.inited = true;
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
int ConfigCamera(int id, int fps, int width, int height) {
|
||||
int ret = SetCameraProperty(id, CAMERA_PROP_FPS, &fps);
|
||||
if (ret == LIBMEDIA_STATUS_FAILED) {
|
||||
ASC_LOG_ERROR("Set camera fps failed");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
CameraResolution resolution;
|
||||
resolution.width = width;
|
||||
resolution.height = height;
|
||||
ret = SetCameraProperty(id, CAMERA_PROP_RESOLUTION, &resolution);
|
||||
if (ret == LIBMEDIA_STATUS_FAILED) {
|
||||
ASC_LOG_ERROR("Set camera resolution failed");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
CameraCapMode mode = CAMERA_CAP_ACTIVE;
|
||||
ret = SetCameraProperty(id, CAMERA_PROP_CAP_MODE, &mode);
|
||||
if (ret == LIBMEDIA_STATUS_FAILED) {
|
||||
ASC_LOG_ERROR("Set camera mode:%d failed", mode);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
int OpenCameraEx(int id, int fps, int width, int height) {
|
||||
if ((id < 0) || (id >= CAMERA_NUM)) {
|
||||
ASC_LOG_ERROR("Open camera failed for invalid id %d", id);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
if (!CAMERA(id).inited) {
|
||||
CameraInit(id, fps, width, height);
|
||||
}
|
||||
|
||||
CameraStatus status = QueryCameraStatus(id);
|
||||
if (status == CAMERA_STATUS_CLOSED){
|
||||
// Open Camera
|
||||
if (LIBMEDIA_STATUS_FAILED == OpenCamera(id)) {
|
||||
ASC_LOG_ERROR("Camera%d closed, and open failed.", id);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
} else if (status != CAMERA_STATUS_OPEN) {
|
||||
ASC_LOG_ERROR("Invalid camera%d status %d", id, status);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
//Set camera property
|
||||
if (STATUS_OK != ConfigCamera(id, fps, width, height)) {
|
||||
CloseCamera(id);
|
||||
ASC_LOG_ERROR("Set camera%d property failed", id);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
ASC_LOG_INFO("Open camera %d success", id);
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
int ReadCameraFrame(int id, CameraOutput& frame) {
|
||||
int size = CAMERA(id).frameSize;
|
||||
void* data = nullptr;
|
||||
auto aclRet = acldvppMalloc(&data, size);
|
||||
if (aclRet != ACL_ERROR_NONE) {
|
||||
ASC_LOG_ERROR("acl malloc dvpp data failed, dataSize=%u, ret=%d",
|
||||
size, aclRet);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
int ret = ReadFrameFromCamera(id, (void*)data, (int *)&size);
|
||||
if ((ret == LIBMEDIA_STATUS_FAILED) ||
|
||||
(size != CAMERA(id).frameSize)) {
|
||||
acldvppFree(data);
|
||||
ASC_LOG_ERROR("Get image from camera %d failed, size %d", id, size);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
frame.size = size;
|
||||
frame.data = (uint8_t*)data;
|
||||
ASC_LOG_INFO("cpp image ptr 0x%x", data);
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
int CloseCameraEx(int cameraId) {
|
||||
if (LIBMEDIA_STATUS_FAILED == CloseCamera(cameraId)) {
|
||||
ASC_LOG_ERROR("Close camera %d failed", cameraId);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* ============================================================================
|
||||
*
|
||||
* Copyright (C) 2018, Hisilicon Technologies Co., Ltd. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1 Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2 Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3 Neither the names of the copyright holders nor the names of the
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* ============================================================================
|
||||
*/
|
||||
#ifndef _CAMERA_H
|
||||
#define _CAMERA_H
|
||||
|
||||
#define CAMERA_NUM (2)
|
||||
|
||||
#define CAMERA(i) (g_CameraMgr.cap[i])
|
||||
|
||||
struct CameraOutput {
|
||||
int size;
|
||||
uint8_t* data;
|
||||
};
|
||||
|
||||
struct Camera {
|
||||
bool inited = false;
|
||||
int id = 255;
|
||||
int fps = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int frameSize = 0;
|
||||
|
||||
};
|
||||
|
||||
struct CameraManager {
|
||||
bool hwInited = 0;
|
||||
Camera cap[CAMERA_NUM];
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user