Completed all functional ports.

This commit is contained in:
Tryanks
2024-03-17 19:49:02 +08:00
parent 397d4cf154
commit 083935ff32
7 changed files with 68 additions and 191 deletions

View File

@@ -120,6 +120,10 @@ typedef enum {
* ion : use ion device under Android/Linux, MppBuffer will encapsulte ion file handle
* ext_dma : the DMABUF(DMA buffers) come from the application
* drm : use the drm device interface for memory management
*
* MPP default allocator select priority for kernel above 5.10:
* MPP_BUFFER_TYPE_DMA_HEAP > MPP_BUFFER_TYPE_DRM > MPP_BUFFER_TYPE_ION
* MPP_BUFFER_TYPE_EXT_DMA is only used for general external dma_buf fd import.
*/
typedef enum {
MPP_BUFFER_TYPE_NORMAL,
@@ -137,9 +141,9 @@ typedef enum {
* 16 high bits of MppBufferType are used in flags
*
* eg:
* DRM CMA buffer : MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_CONTIG
* = 0x00010003
* DRM SECURE buffer: MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_SECURE
* DMA_HEAP CMA buffer : MPP_BUFFER_TYPE_DMA_HEAP | MPP_BUFFER_FLAGS_CONTIG
* = 0x00010004
* DRM SECURE buffer : MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_SECURE
* = 0x00080003
*
* The dma buffer source can also be set by format: flags | type.

View File

@@ -1,17 +1,6 @@
/* SPDX-License-Identifier: Apache-2.0 OR MIT */
/*
* Copyright 2015 Rockchip Electronics 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.
* Copyright (c) 2015 Rockchip Electronics Co., Ltd.
*/
#ifndef __MPP_FRAME_H__
@@ -56,6 +45,12 @@ typedef enum {
MPP_FRAME_RANGE_NB, ///< Not part of ABI
} MppFrameColorRange;
typedef enum {
MPP_FRAME_CHROMA_DOWN_SAMPLE_MODE_NONE,
MPP_FRAME_CHORMA_DOWN_SAMPLE_MODE_AVERAGE,
MPP_FRAME_CHORMA_DOWN_SAMPLE_MODE_DISCARD,
} MppFrameChromaDownSampleMode;
typedef enum {
MPP_FRAME_VIDEO_FMT_COMPONEMT = 0,
MPP_FRAME_VIDEO_FMT_PAL = 1,
@@ -163,6 +158,33 @@ typedef enum {
MPP_CHROMA_LOC_NB, ///< Not part of ABI
} MppFrameChromaLocation;
typedef enum {
MPP_CHROMA_UNSPECIFIED,
MPP_CHROMA_400,
MPP_CHROMA_410,
MPP_CHROMA_411,
MPP_CHROMA_420,
MPP_CHROMA_422,
MPP_CHROMA_440,
MPP_CHROMA_444,
} MppFrameChromaFormat;
/*
* MppFrameFormat bit flag:
*
* +-----------------------------------------------+
* | 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
* +-----------------------------------------------+
* bit 0 ~ 15: YUV / RGB format value
* bit 16 ~ 19: YUV / RGB flag 0 - YUV; 1 - RGB;
* bit 20 ~ 23: Frame Buffer Compression (FBC) flag, 0 - No FBC; 1 - FBCv1; 2 - FBCv2;
* bit 24 : Big / little end flag, 0 - big end; 1 - little end;
* bit 25 : Tile format flag, 0 - No tile; 1 - tile format;
* bit 26 ~ 27: High Dynamic Range (HDR) flag, 0 - Standard Dynamic Range (SDR); 1 - HDR;
*
* NOTE: FBC format and tile format can not exist at the same time.
*/
#define MPP_FRAME_FMT_MASK (0x000fffff)
#define MPP_FRAME_FMT_PROP_MASK (0x0ff00000)
@@ -177,6 +199,8 @@ typedef enum {
#define MPP_FRAME_HDR_NONE (0x00000000)
#define MPP_FRAME_HDR (0x04000000)
#define MPP_FRAME_TILE_FLAG (0x02000000)
/*
* AFBC_V1 is for ISP output.
* It has default payload offset to be calculated * from width and height:
@@ -209,6 +233,8 @@ typedef enum {
#define MPP_FRAME_FMT_IS_LE(fmt) ((fmt & MPP_FRAME_FMT_LE_MASK) == MPP_FRAME_FMT_LE_MASK)
#define MPP_FRAME_FMT_IS_BE(fmt) ((fmt & MPP_FRAME_FMT_LE_MASK) == 0)
#define MPP_FRAME_FMT_IS_TILE(fmt) (fmt & MPP_FRAME_TILE_FLAG)
/* mpp color format index definition */
typedef enum {
MPP_FMT_YUV420SP = (MPP_FRAME_FMT_YUV + 0), /* YYYY... UV... (NV12) */

View File

@@ -71,8 +71,8 @@ typedef enum GopMode_e {
* fps_in_num
* input frame rate numerator, if 0 then default 30
*
* fps_in_denorm
* input frame rate denorminator, if 0 then default 1
* fps_in_denom
* input frame rate denominator, if 0 then default 1
*
* fps_out_flex
* 0 - fix output frame rate
@@ -81,16 +81,16 @@ typedef enum GopMode_e {
* fps_out_num
* output frame rate numerator, if 0 then default 30
*
* fps_out_denorm
* output frame rate denorminator, if 0 then default 1
* fps_out_denom
* output frame rate denominator, if 0 then default 1
*/
typedef struct RcFpsCfg_t {
RK_S32 fps_in_flex;
RK_S32 fps_in_num;
RK_S32 fps_in_denorm;
RK_S32 fps_in_denom;
RK_S32 fps_out_flex;
RK_S32 fps_out_num;
RK_S32 fps_out_denorm;
RK_S32 fps_out_denom;
} RcFpsCfg;
typedef struct RcSuperframeCfg_t {

View File

@@ -213,8 +213,8 @@ typedef enum MppEncRcCfgChange_e {
MPP_ENC_RC_CFG_CHANGE_RC_MODE = (1 << 0),
MPP_ENC_RC_CFG_CHANGE_QUALITY = (1 << 1),
MPP_ENC_RC_CFG_CHANGE_BPS = (1 << 2), /* change on bps target / max / min */
MPP_ENC_RC_CFG_CHANGE_FPS_IN = (1 << 5), /* change on fps in flex / numerator / denorminator */
MPP_ENC_RC_CFG_CHANGE_FPS_OUT = (1 << 6), /* change on fps out flex / numerator / denorminator */
MPP_ENC_RC_CFG_CHANGE_FPS_IN = (1 << 5), /* change on fps in flex / numerator / denominator */
MPP_ENC_RC_CFG_CHANGE_FPS_OUT = (1 << 6), /* change on fps out flex / numerator / denominator */
MPP_ENC_RC_CFG_CHANGE_GOP = (1 << 7),
MPP_ENC_RC_CFG_CHANGE_SKIP_CNT = (1 << 8),
MPP_ENC_RC_CFG_CHANGE_MAX_REENC = (1 << 9),
@@ -312,8 +312,8 @@ typedef struct MppEncRcCfg_t {
* fps_in_num
* input frame rate numerator, if 0 then default 30
*
* fps_in_denorm
* input frame rate denorminator, if 0 then default 1
* fps_in_denom
* input frame rate denominator, if 0 then default 1
*
* fps_out_flex
* 0 - fix output frame rate
@@ -322,15 +322,15 @@ typedef struct MppEncRcCfg_t {
* fps_out_num
* output frame rate numerator, if 0 then default 30
*
* fps_out_denorm
* output frame rate denorminator, if 0 then default 1
* fps_out_denom
* output frame rate denominator, if 0 then default 1
*/
RK_S32 fps_in_flex;
RK_S32 fps_in_num;
RK_S32 fps_in_denorm;
RK_S32 fps_in_denom;
RK_S32 fps_out_flex;
RK_S32 fps_out_num;
RK_S32 fps_out_denorm;
RK_S32 fps_out_denom;
/*
* gop - group of picture, gap between Intra frame
@@ -562,13 +562,19 @@ typedef struct MppEncPrepCfg_t {
RK_S32 ver_stride;
/*
* Mpp encoder input data format config
* Mpp encoder input/output color config
*/
MppFrameFormat format;
MppFrameColorSpace color;
MppFrameColorPrimaries colorprim;
MppFrameColorTransferCharacteristic colortrc;
MppFrameColorRange range;
MppFrameChromaFormat format_out;
MppFrameChromaDownSampleMode chroma_ds_mode;
MppFrameColorRange range_out;
RK_S32 fix_chroma_en;
RK_S32 fix_chroma_u;
RK_S32 fix_chroma_v;
/* suffix ext means the user set config externally */
MppEncRotationCfg rotation;

View File

@@ -1,9 +0,0 @@
package rkcodec
import "C"
//#cgo pkg-config: rockchip_mpp
//#include <rockchip/mpp_frame.h>
import "C"
type MppFrame = C.MppFrame

145
mpi.go
View File

@@ -1,145 +0,0 @@
package rkcodec
//#cgo pkg-config: rockchip_mpp
/*
#include <rockchip/rk_mpi.h>
MPP_RET Mpi_decode(MppApi mpi, MppCtx ctx, MppPacket packet, MppFrame *frame) {
return mpi->decode(ctx, packet, frame);
}
MPP_RET Mpi_decode_put_packet(MppApi mpi, MppCtx ctx, MppPacket packet) {
return mpi->decode_put_packet(ctx, packet);
}
MPP_RET Mpi_decode_get_frame(MppApi mpi, MppCtx ctx, MppFrame *frame) {
return mpi->decode_get_frame(ctx, frame);
}
MPP_RET Mpi_encode(MppApi mpi, MppCtx ctx, MppFrame frame, MppPacket *packet) {
return mpi->encode(ctx, frame, packet);
}
MPP_RET Mpi_encode_put_frame(MppApi mpi, MppCtx ctx, MppFrame frame) {
return mpi->encode_put_frame(ctx, frame);
}
MPP_RET Mpi_encode_get_packet(MppApi mpi, MppCtx ctx, MppPacket *packet) {
return mpi->encode_get_packet(ctx, packet);
}
//MPP_RET Mpi_isp(MppApi mpi, MppCtx ctx, MppFrame dst, MppFrame src) {
// return mpi->isp(ctx, dst, src);
//}
//
//MPP_RET Mpi_isp_put_frame(MppApi mpi, MppCtx ctx, MppFrame frame) {
// return mpi->isp_put_frame(ctx, frame);
//}
//
//MPP_RET Mpi_isp_get_frame(MppApi mpi, MppCtx ctx, MppFrame *frame) {
// return mpi->isp_get_frame(ctx, frame);
//}
//
//MPP_RET Mpi_poll(MppApi mpi, MppCtx ctx, MppPortType type, MppPollType timeout) {
// return mpi->poll(ctx, type, timeout);
//}
//
//MPP_RET Mpi_dequeue(MppApi mpi, MppCtx ctx, MppPortType type, MppTask *task) {
// return mpi->dequeue(ctx, type, task);
//}
//
//MPP_RET Mpi_enqueue(MppApi mpi, MppCtx ctx, MppPortType type, MppTask task) {
// return mpi->enqueue(ctx, type, task);
//}
MPP_RET Mpi_reset(MppApi mpi, MppCtx ctx) {
return mpi->reset(ctx);
}
MPP_RET Mpi_control(MppApi mpi, MppCtx ctx, MpiCmd cmd, MppParam param) {
return mpi->control(ctx, cmd, param);
}
*/
import "C"
type MppContext struct {
mpi *C.struct_MppApi
ctx C.MppCtx
}
func CreateCtxAndApi(ctxType MppCtxType, codingType MppCodingType) *MppContext {
var mpi *C.struct_MppApi
var ctx C.MppCtx
C.mpp_create(&mpi, &ctx, ctxType)
C.mpp_init(ctx, codingType, 0)
return &MppContext{mpi: mpi, ctx: ctx}
}
func (c *MppContext) Decode(packet MppPacket, frame *MppFrame) {
C.Mpi_decode(c.mpi, c.ctx, packet.c, frame.c)
}
func (c *MppContext) DecodePutPacket(packet MppPacket) {
C.Mpi_decode_put_packet(c.mpi, c.ctx, packet.c)
}
func (c *MppContext) DecodeGetFrame(frame *MppFrame) {
C.Mpi_decode_get_frame(c.mpi, c.ctx, frame.c)
}
func (c *MppContext) Encode(frame MppFrame, packet *MppPacket) {
C.Mpi_encode(c.mpi, c.ctx, frame.c, packet.c)
}
func (c *MppContext) EncodePutFrame(frame MppFrame) {
C.Mpi_encode_put_frame(c.mpi, c.ctx, frame.c)
}
func (c *MppContext) EncodeGetPacket(packet *MppPacket) {
C.Mpi_encode_get_packet(c.mpi, c.ctx, packet.c)
}
func (c *MppContext) Reset() {
C.Mpi_reset(c.mpi, c.ctx)
}
func (c *MppContext) Control(cmd MpiCmd, param bool) {
param2 := C.int(0)
if param {
param2 = C.int(1)
}
C.Mpi_control(c.mpi, c.ctx, (C.enum_MpiCmd)(cmd), C.MppParam(param2))
}
func (c *MppContext) Destroy() {
C.mpp_destroy(c.mpi, c.ctx)
}
type MpiCmd C.enum_MpiCmd
const (
MpiCmdBase = MpiCmd(C.MPI_CMD_BASE)
MpiDecSetParserSplitMode = MpiCmd(C.MPI_DEC_SET_PARSER_SPLIT_MODE)
MppDecSetImmediateOut = MpiCmd(C.MPP_DEC_SET_IMMEDIATE_OUT)
MppSetInputBlock = MpiCmd(C.MPP_SET_INPUT_BLOCK)
MppSetInputTimeout = MpiCmd(C.MPP_SET_INPUT_TIMEOUT)
MppSetOutputBlock = MpiCmd(C.MPP_SET_OUTPUT_BLOCK)
MppSetOutputTimeout = MpiCmd(C.MPP_SET_OUTPUT_TIMEOUT)
)
type MppCtxType C.enum_MppCtxType
const (
MppCtxTypeDecoder = MppCtxType(C.MPP_CTX_DEC)
MppCtxTypeEncoder = MppCtxType(C.MPP_CTX_ENC)
)
type MppCodingType C.enum_MppCodingType
const (
MppCodingTypeAVC = MppCodingType(C.MPP_VIDEO_CodingAVC)
MppCodingTypeHEVC = MppCodingType(C.MPP_VIDEO_CodingHEVC)
MppCodingTypeVP8 = MppCodingType(C.MPP_VIDEO_CodingVP8)
MppCodingTypeVP9 = MppCodingType(C.MPP_VIDEO_CodingVP9)
MppCodingTypeMJPEG = MppCodingType(C.MPP_VIDEO_CodingMJPEG)
)

View File

@@ -1,5 +0,0 @@
package rkcodec
import "C"
type MppPacket = C.MppPacket