mirror of
https://github.com/openharmony/multimedia_utils_lite.git
synced 2026-07-19 11:33:48 -04:00
!11 multimedia 服务化
Merge pull request !11 from harmony_zhangjian/master
This commit is contained in:
@@ -27,6 +27,7 @@ shared_library("media_common") {
|
||||
]
|
||||
public_deps = [
|
||||
"$ohos_vendor_adapter_dir:hardware_media_sdk",
|
||||
"//foundation/graphic/surface:lite_surface",
|
||||
"$ohos_vendor_adapter_dir/../modules/middleware:middleware_source_sdk",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
|
||||
Executable
+244
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 HI_CAMERA_H
|
||||
#define HI_CAMERA_H
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
|
||||
#define CAMERA_FPS_MAX_NUM 16
|
||||
#define CAMERA_DESC_MAX_LEN 32
|
||||
#define INFO_MAX_LEN 1024
|
||||
#define DESC_MAX_LEN 64
|
||||
#define AUTO_MODE_MAX_NUM 16
|
||||
#define PRIVATE_META_MAX_LEN 32
|
||||
|
||||
typedef struct {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t w;
|
||||
int32_t h;
|
||||
} RectInfo;
|
||||
|
||||
typedef enum {
|
||||
STREAM_INFO_ATTR = 0,
|
||||
STREAM_INFO_POS,
|
||||
STERAM_INFO_PRIVATE,
|
||||
STREAM_INFO_BUTT,
|
||||
} StreamInfoType;
|
||||
|
||||
typedef enum {
|
||||
CAMERA_CONTROL_3A_MODE = 0,
|
||||
CAMERA_CONTROL_PRIVATE,
|
||||
CAMERA_CONTROL_BUTT,
|
||||
} DeviceType;
|
||||
|
||||
typedef enum {
|
||||
FORMAT_YVU420 = 0,
|
||||
FORMAT_JPEG,
|
||||
FORMAT_AVC,
|
||||
FORMAT_HEVC,
|
||||
FORMAT_RGB_BAYER_12BPP,
|
||||
FORMAT_IMAGE_BUTT
|
||||
} ImageFormat;
|
||||
|
||||
typedef enum {
|
||||
STREAM_PREVIEW = 0,
|
||||
STREAM_VIDEO,
|
||||
STREAM_CAPTURE,
|
||||
STREAM_CALLBACK,
|
||||
STREAM_TYPE_BUTT
|
||||
} StreamType;
|
||||
|
||||
typedef struct {//动态能力 or 静态能力
|
||||
StreamType type;
|
||||
ImageFormat format;
|
||||
int32_t width; //静态
|
||||
int32_t height; //静态
|
||||
uint16_t fps; //动态
|
||||
RectInfo crop; //动态
|
||||
uint8_t invertMode;
|
||||
} StreamAttr;
|
||||
|
||||
typedef enum {
|
||||
CAP_DESC_RANGE,
|
||||
CAP_DESC_ENUM,
|
||||
CAP_DESC_MAX,
|
||||
} CapDescType;
|
||||
|
||||
typedef struct {
|
||||
ImageFormat format; /**< the format of memory */
|
||||
int32_t width; /**< the width of memory */
|
||||
int32_t height; /**< the heigh of memory */
|
||||
int32_t stride0; /**< the stride of memory */
|
||||
int32_t stride1; //添加的变量
|
||||
int32_t size; /* < size of memory */
|
||||
int32_t fd; /**< buffer fd, -1 if not supported */
|
||||
uint32_t flag; /**< flag */
|
||||
int64_t usage; /**< the usage of memory */
|
||||
uint64_t phyAddr; /**< Physical address */
|
||||
uint64_t pts; /**< pts */
|
||||
uint64_t timeStamp; //添加的变量
|
||||
void *virAddr; /**< Virtual address of memory */
|
||||
} HalBuffer;
|
||||
|
||||
typedef struct {
|
||||
int32_t maxWidth;
|
||||
int32_t minWidth;
|
||||
int32_t maxHeight;
|
||||
int32_t minHeight;
|
||||
int32_t maxFps;
|
||||
int32_t minFps;
|
||||
} FormatRange;
|
||||
|
||||
typedef struct Format {
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
uint8_t frame_rate_num;
|
||||
uint8_t frame_rate[CAMERA_FPS_MAX_NUM];
|
||||
} FormatEnum;
|
||||
|
||||
typedef struct {
|
||||
CapDescType type;
|
||||
char description[CAMERA_DESC_MAX_LEN]; /* like YUYV 4:2:2 (YUYV) */
|
||||
ImageFormat format; //只支持YUV
|
||||
union {
|
||||
FormatRange range;
|
||||
FormatEnum formatEnum;
|
||||
} u;
|
||||
} StreamCap;
|
||||
|
||||
typedef enum status {
|
||||
CAMERA_STATUS_NOT_PRESENT,
|
||||
CAMERA_STATUS_PRESENT,
|
||||
CAMERA_STATUS_BUTT,
|
||||
} CameraStatus;
|
||||
|
||||
typedef void (*BufferAvailable)(uint32_t streamId, HalBuffer *halBuffer, uint32_t bufferNum);
|
||||
typedef void (*CameraDetectCb)(uint32_t cameraId, CameraStatus status);
|
||||
|
||||
typedef struct {
|
||||
DeviceType type;
|
||||
union {
|
||||
uint8_t data[INFO_MAX_LEN];
|
||||
} u;
|
||||
} DeviceInfo;
|
||||
|
||||
typedef struct {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
} PosInfo;
|
||||
|
||||
typedef struct {
|
||||
StreamInfoType type;
|
||||
union {
|
||||
uint8_t data[INFO_MAX_LEN];
|
||||
StreamAttr attr;
|
||||
PosInfo pos;
|
||||
} u;
|
||||
} StreamInfo;
|
||||
|
||||
typedef enum {
|
||||
ORIENTATION_FRONT,
|
||||
ORIENTATION_REAR,
|
||||
ORIENTATION_OTHER,
|
||||
ORIENTATION_BUTT,
|
||||
} CameraOrientation;
|
||||
|
||||
typedef enum {
|
||||
AE_MODE_ON,
|
||||
AE_MODE_OFF,
|
||||
AE_BUTT,
|
||||
} CameraAEMode;
|
||||
|
||||
typedef enum {
|
||||
AF_MODE_AUTO,
|
||||
AF_MODE_OFF,
|
||||
AF_BUTT,
|
||||
} CameraAFMode;
|
||||
|
||||
typedef enum {
|
||||
AWB_MODE_AUTO,
|
||||
AWB_MODE_OFF,
|
||||
AWB_BUTT,
|
||||
} CameraAWBMode;
|
||||
|
||||
typedef enum {
|
||||
CAM_TYPE_WIDE_ANGLE,
|
||||
CAM_TYPE_FISH_EYE,
|
||||
CAM_TYPE_TRUE_DEAPTH,
|
||||
CAM_TYPE_BUTT,
|
||||
} CameraType;
|
||||
|
||||
typedef struct {
|
||||
CameraOrientation orientation;
|
||||
uint8_t aeModeNum;
|
||||
uint8_t afModeNum;
|
||||
uint8_t awbModeNum;
|
||||
CameraAEMode aeModes[AUTO_MODE_MAX_NUM];
|
||||
CameraAFMode afModes[AUTO_MODE_MAX_NUM];
|
||||
CameraAWBMode awbModes[AUTO_MODE_MAX_NUM];
|
||||
CameraType type;
|
||||
char cameraDesc[DESC_MAX_LEN];
|
||||
} AbilityInfo;
|
||||
|
||||
typedef struct {
|
||||
CameraAEMode aeMode;
|
||||
CameraAFMode afMode;
|
||||
CameraAWBMode awbMode;
|
||||
uint32_t privateData[PRIVATE_META_MAX_LEN];
|
||||
} CameraMetaResult;
|
||||
|
||||
typedef void (*CameraResultCb)(uint32_t cameraId, CameraMetaResult result);
|
||||
|
||||
int32_t HalCameraInit(void);
|
||||
int32_t HalCameraDeinit(void);
|
||||
int32_t HalCameraGetModeNum(uint8_t *num);
|
||||
int32_t HalCameraSetMode(uint8_t index);
|
||||
int32_t HalCameraSetDeviceDetectCb(const CameraDetectCb cb);
|
||||
int32_t HalCameraGetDeviceNum(uint8_t *num);
|
||||
int32_t HalCameraGetDeviceList(uint32_t *cameraList, uint8_t listNum);
|
||||
int32_t HalCameraGetStreamCapNum(uint32_t cameraId, uint32_t *num);
|
||||
int32_t HalCameraGetStreamCap(uint32_t cameraId, StreamCap *streamCap, uint32_t streamNum);
|
||||
int32_t HalCameraDeviceOpen(uint32_t cameraId);
|
||||
int32_t HalCameraDeviceClose(uint32_t cameraId);
|
||||
int32_t HalCameraStreamCreate(uint32_t cameraId, const StreamAttr *stream, uint32_t *streamId);
|
||||
int32_t HalCameraStreamDestroy(uint32_t cameraId, uint32_t streamId);
|
||||
int32_t HalCameraGetDeviceId(uint32_t cameraId, uint32_t streamId, uint32_t *deviceId);
|
||||
int32_t HalCameraStreamOn(uint32_t cameraId, uint32_t streamId);
|
||||
int32_t HalCameraStreamOff(uint32_t cameraId, uint32_t streamId);
|
||||
int32_t HalCameraDequeueBuf(uint32_t cameraId, uint32_t streamId, HalBuffer *buffer);
|
||||
int32_t HalCameraQueueBuf(uint32_t cameraId, uint32_t streamId, const HalBuffer *buffer);
|
||||
int32_t HalCameraSetBufferCallback(uint32_t cameraId, const BufferAvailable callback);
|
||||
int32_t HalCameraStreamSetInfo(uint32_t cameraId, uint32_t streamId, const StreamInfo *info);
|
||||
int32_t HalCameraStreamGetInfo(uint32_t cameraId, uint32_t streamId, StreamInfo *info);
|
||||
int32_t HalCameraDeviceSetInfo(uint32_t cameraId, const DeviceInfo *info);
|
||||
int32_t HalCameraDeviceGetInfo(uint32_t cameraId, DeviceInfo *info);
|
||||
int32_t HalCameraGetAbility(uint32_t cameraId, AbilityInfo *ability);
|
||||
int32_t HalCameraSetResultCb(uint32_t cameraId, CameraResultCb cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* End of #ifdef __cplusplus */
|
||||
|
||||
#endif
|
||||
Regular → Executable
-5
@@ -60,11 +60,6 @@ const int32_t COLOR_FORMAT_ARGB8888_32BIT = 16;
|
||||
/** Indicates the YUV420SP color format. */
|
||||
const int32_t COLOR_FORMAT_YUV420SP = 21;
|
||||
|
||||
/** Indicates that the current frame is an Instantaneous Decoder Refresh (IDR) frame. */
|
||||
const std::string KEY_IS_SYNC_FRAME = "is-sync-frame";
|
||||
|
||||
/** Indicates the frame timestamp. */
|
||||
const std::string KEY_TIME_US = "timeUs";
|
||||
|
||||
/**
|
||||
* @brief Enumerates audio source types.
|
||||
|
||||
Regular → Executable
+1
@@ -49,5 +49,6 @@
|
||||
#define MEDIA_INIT_FAIL (-2)
|
||||
#define MEDIA_ERR (-3)
|
||||
#define MEDIA_PERMISSION_DENIED (-4)
|
||||
#define MEDIA_IPC_FAILED (-5)
|
||||
|
||||
#endif // OHOS_MEDIA_LOG_H
|
||||
Regular → Executable
+41
-3
@@ -40,6 +40,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "format.h"
|
||||
#include "surface.h"
|
||||
|
||||
using std::shared_ptr;
|
||||
|
||||
@@ -137,7 +138,19 @@ struct StreamCallback {
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
struct StreamSource {
|
||||
class StreamSource {
|
||||
public:
|
||||
StreamSource(void);
|
||||
|
||||
virtual ~StreamSource(void);
|
||||
|
||||
void SetSurface(Surface* surface);
|
||||
|
||||
Surface* GetSurface(void);
|
||||
|
||||
uint8_t* GetSharedBuffer(size_t& size);
|
||||
|
||||
int QueueSharedBuffer(void* buffer, size_t size);
|
||||
/**
|
||||
* @brief Notifies your application of the information about the buffer memory block that can be filled with data.
|
||||
*
|
||||
@@ -147,7 +160,7 @@ struct StreamSource {
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
virtual void OnBufferAvailable(size_t index, size_t offset, size_t size) = 0;
|
||||
virtual void OnBufferAvailable(size_t index, size_t offset, size_t size) {}
|
||||
|
||||
/**
|
||||
* @brief Sets a callback function for your application.
|
||||
@@ -156,7 +169,12 @@ struct StreamSource {
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
virtual void SetStreamCallback(const std::shared_ptr<StreamCallback> &callback) = 0;
|
||||
virtual void SetStreamCallback(const std::shared_ptr<StreamCallback> &callback) {}
|
||||
|
||||
private:
|
||||
|
||||
Surface* surface_;
|
||||
SurfaceBuffer* curBuffer_;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -176,6 +194,17 @@ public:
|
||||
*/
|
||||
explicit Source(const std::string& uri);
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a {@link Source} instance based on a specified URI and header.
|
||||
*
|
||||
* If the HTTP URL header does not carry valid information for network playback, this function is equivalent to
|
||||
* {@link Source(const std::string& uri)}.
|
||||
*
|
||||
* @param uri Indicates the media source URI.
|
||||
* @param header Indicates the header.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
Source(const std::string &uri, const std::map<std::string, std::string> &header);
|
||||
|
||||
/**
|
||||
@@ -214,6 +243,15 @@ public:
|
||||
*/
|
||||
const std::string &GetSourceUri() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the HTTP header for the media source.
|
||||
*
|
||||
* This function is called only when the {@link SourceType} is {@link SOURCE_TYPE_URI}.
|
||||
*
|
||||
* @return Returns the media source header.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
const std::map<std::string, std::string> &GetSourceHeader() const;
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "source.h"
|
||||
#include "media_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@@ -58,5 +59,64 @@ const Format &Source::GetSourceStreamFormat() const
|
||||
{
|
||||
return format_;
|
||||
}
|
||||
|
||||
StreamSource::StreamSource()
|
||||
: surface_(nullptr),
|
||||
curBuffer_(nullptr)
|
||||
{}
|
||||
|
||||
StreamSource::~StreamSource()
|
||||
{
|
||||
MEDIA_ERR_LOG("[%s,%d] in", __func__, __LINE__);
|
||||
if (surface_ != nullptr) {
|
||||
delete surface_;
|
||||
}
|
||||
}
|
||||
|
||||
void StreamSource::SetSurface(Surface* surface)
|
||||
{
|
||||
surface_ = surface;
|
||||
}
|
||||
|
||||
Surface* StreamSource::GetSurface(void)
|
||||
{
|
||||
return surface_;
|
||||
}
|
||||
|
||||
|
||||
uint8_t* StreamSource::GetSharedBuffer(size_t& size)
|
||||
{
|
||||
if ((surface_ == nullptr) || (curBuffer_ != nullptr)){
|
||||
return nullptr;
|
||||
}
|
||||
SurfaceBuffer* surfaceBuffer = surface_->RequestBuffer();
|
||||
if (surfaceBuffer != nullptr) {
|
||||
curBuffer_ = surfaceBuffer;
|
||||
size = surface_->GetSize();
|
||||
return static_cast<uint8_t*>(surfaceBuffer->GetVirAddr());
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int StreamSource::QueueSharedBuffer(void* buffer, size_t size)
|
||||
{
|
||||
if ((surface_ == nullptr) || (buffer == nullptr) || (curBuffer_ == nullptr)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(buffer != curBuffer_->GetVirAddr()) {
|
||||
return -1;
|
||||
}
|
||||
curBuffer_->SetInt32(0, size);
|
||||
if (surface_->FlushBuffer(curBuffer_) != 0) {
|
||||
surface_->CancelBuffer(curBuffer_);
|
||||
curBuffer_ = nullptr;
|
||||
return -1;
|
||||
}
|
||||
curBuffer_ = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user