[mpp_enc]: Add MppEncImpl layer

Change-Id: If9a63606c2ec4a1f96e422a06681cf8a11ec4c7b
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen 2019-09-19 17:46:11 +08:00
parent 14076644ea
commit 498a43aa2e
4 changed files with 95 additions and 52 deletions

View file

@ -17,9 +17,9 @@
#ifndef __MPP_ENC_H__
#define __MPP_ENC_H__
#include "mpp_thread.h"
#include "mpp_controller.h"
#include "mpp_hal.h"
#include "rk_type.h"
#include "mpp_err.h"
#include "rk_mpi_cmd.h"
/*
* Configure of encoder is separated into four parts.
@ -149,33 +149,7 @@
* + + + +
*/
typedef struct MppEnc_t MppEnc;
struct MppEnc_t {
MppCodingType coding;
Controller controller;
MppHal hal;
void *mpp;
// common resource
MppBufSlots frame_slots;
MppBufSlots packet_slots;
HalTaskGroup tasks;
// internal status and protection
Mutex lock;
RK_U32 reset_flag;
sem_t enc_reset;
RK_U32 wait_count;
RK_U32 work_count;
RK_U32 status_flag;
RK_U32 notify_flag;
/* Encoder configure set */
MppEncCfgSet cfg;
MppEncCfgSet set;
};
typedef void* MppEnc;
typedef struct {
MppCodingType coding;
@ -192,11 +166,11 @@ extern "C" {
void *mpp_enc_control_thread(void *data);
void *mpp_enc_hal_thread(void *data);
MPP_RET mpp_enc_init(MppEnc **enc, MppEncCfg *cfg);
MPP_RET mpp_enc_deinit(MppEnc *enc);
MPP_RET mpp_enc_control(MppEnc *enc, MpiCmd cmd, void *param);
MPP_RET mpp_enc_notify(MppEnc *enc, RK_U32 flag);
MPP_RET mpp_enc_reset(MppEnc *enc);
MPP_RET mpp_enc_init(MppEnc *ctx, MppEncCfg *cfg);
MPP_RET mpp_enc_deinit(MppEnc ctx);
MPP_RET mpp_enc_control(MppEnc ctx, MpiCmd cmd, void *param);
MPP_RET mpp_enc_notify(MppEnc ctx, RK_U32 flag);
MPP_RET mpp_enc_reset(MppEnc ctx);
/*
* preprocess config and rate-control config is common config then they will

View file

@ -0,0 +1,59 @@
/*
* 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.
*/
#ifndef __MPP_ENC_IMPL_H__
#define __MPP_ENC_IMPL_H__
#include "mpp_thread.h"
#include "mpp_controller.h"
#include "mpp_hal.h"
typedef struct MppEncImpl_t {
MppCodingType coding;
Controller controller;
MppHal hal;
void *mpp;
// common resource
MppBufSlots frame_slots;
MppBufSlots packet_slots;
HalTaskGroup tasks;
// internal status and protection
Mutex lock;
RK_U32 reset_flag;
sem_t enc_reset;
RK_U32 wait_count;
RK_U32 work_count;
RK_U32 status_flag;
RK_U32 notify_flag;
/* Encoder configure set */
MppEncCfgSet cfg;
MppEncCfgSet set;
} MppEncImpl;
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /*__MPP_ENC_IMPL_H__*/

View file

@ -25,6 +25,7 @@
#include "mpp_packet_impl.h"
#include "mpp.h"
#include "mpp_enc_impl.h"
#include "hal_h264e_api.h"
#define MPP_ENC_DBG_FUNCTION (0x00000001)
@ -124,7 +125,7 @@ static MPP_RET release_task_in_port(MppPort port)
return ret;
}
static MPP_RET check_enc_task_wait(MppEnc *enc, EncTask *task)
static MPP_RET check_enc_task_wait(MppEncImpl *enc, EncTask *task)
{
MPP_RET ret = MPP_OK;
RK_U32 notify = enc->notify_flag;
@ -161,7 +162,8 @@ static MPP_RET check_enc_task_wait(MppEnc *enc, EncTask *task)
void *mpp_enc_control_thread(void *data)
{
Mpp *mpp = (Mpp*)data;
MppEnc *enc = mpp->mEnc;
MppEncImpl *enc = (MppEncImpl *)mpp->mEnc;
MppHal hal = enc->hal;
MppThread *thd_enc = mpp->mThreadCodec;
EncTask task;
HalTaskInfo *task_info = &task.info;
@ -266,27 +268,27 @@ void *mpp_enc_control_thread(void *data)
{
AutoMutex auto_lock(&enc->lock);
ret = controller_encode(mpp->mEnc->controller, hal_task);
ret = controller_encode(enc->controller, hal_task);
if (ret) {
mpp_err("mpp %p controller_encode failed return %d", mpp, ret);
goto TASK_END;
}
}
enc_dbg_detail("mpp_hal_reg_gen hal %p task %p\n", mpp->mEnc->hal, task_info);
ret = mpp_hal_reg_gen((mpp->mEnc->hal), task_info);
enc_dbg_detail("mpp_hal_reg_gen hal %p task %p\n", hal, task_info);
ret = mpp_hal_reg_gen(hal, task_info);
if (ret) {
mpp_err("mpp %p hal_reg_gen failed return %d", mpp, ret);
goto TASK_END;
}
enc_dbg_detail("mpp_hal_hw_start hal %p task %p\n", mpp->mEnc->hal, task_info);
ret = mpp_hal_hw_start((mpp->mEnc->hal), task_info);
enc_dbg_detail("mpp_hal_hw_start hal %p task %p\n", hal, task_info);
ret = mpp_hal_hw_start(hal, task_info);
if (ret) {
mpp_err("mpp %p hal_hw_start failed return %d", mpp, ret);
goto TASK_END;
}
enc_dbg_detail("mpp_hal_hw_wait hal %p task %p\n", mpp->mEnc->hal, task_info);
ret = mpp_hal_hw_wait((mpp->mEnc->hal), task_info);
enc_dbg_detail("mpp_hal_hw_wait hal %p task %p\n", hal, task_info);
ret = mpp_hal_hw_wait(hal, task_info);
if (ret) {
mpp_err("mpp %p hal_hw_wait failed return %d", mpp, ret);
goto TASK_END;
@ -355,7 +357,7 @@ void *mpp_enc_control_thread(void *data)
return NULL;
}
MPP_RET mpp_enc_init(MppEnc **enc, MppEncCfg *cfg)
MPP_RET mpp_enc_init(MppEnc *enc, MppEncCfg *cfg)
{
MPP_RET ret;
MppCodingType coding = cfg->coding;
@ -363,7 +365,7 @@ MPP_RET mpp_enc_init(MppEnc **enc, MppEncCfg *cfg)
MppBufSlots packet_slots = NULL;
Controller controller = NULL;
MppHal hal = NULL;
MppEnc *p = NULL;
MppEncImpl *p = NULL;
RK_S32 task_count = 2;
IOInterruptCB cb = {NULL, NULL};
@ -376,7 +378,7 @@ MPP_RET mpp_enc_init(MppEnc **enc, MppEncCfg *cfg)
*enc = NULL;
p = mpp_calloc(MppEnc, 1);
p = mpp_calloc(MppEncImpl, 1);
if (NULL == p) {
mpp_err_f("failed to malloc context\n");
return MPP_ERR_MALLOC;
@ -452,8 +454,10 @@ MPP_RET mpp_enc_init(MppEnc **enc, MppEncCfg *cfg)
}
MPP_RET mpp_enc_deinit(MppEnc *enc)
MPP_RET mpp_enc_deinit(MppEnc ctx)
{
MppEncImpl *enc = (MppEncImpl *)ctx;
if (NULL == enc) {
mpp_err_f("found NULL input\n");
return MPP_ERR_NULL_PTR;
@ -485,8 +489,10 @@ MPP_RET mpp_enc_deinit(MppEnc *enc)
return MPP_OK;
}
MPP_RET mpp_enc_reset(MppEnc *enc)
MPP_RET mpp_enc_reset(MppEnc ctx)
{
MppEncImpl *enc = (MppEncImpl *)ctx;
enc_dbg_func("%p in\n", enc);
if (NULL == enc) {
mpp_err_f("found NULL input enc\n");
@ -506,8 +512,10 @@ MPP_RET mpp_enc_reset(MppEnc *enc)
return MPP_OK;
}
MPP_RET mpp_enc_notify(MppEnc *enc, RK_U32 flag)
MPP_RET mpp_enc_notify(MppEnc ctx, RK_U32 flag)
{
MppEncImpl *enc = (MppEncImpl *)ctx;
enc_dbg_func("%p in flag %08x\n", enc, flag);
Mpp *mpp = (Mpp *)enc->mpp;
MppThread *thd = mpp->mThreadCodec;
@ -529,8 +537,10 @@ MPP_RET mpp_enc_notify(MppEnc *enc, RK_U32 flag)
return MPP_OK;
}
MPP_RET mpp_enc_control(MppEnc *enc, MpiCmd cmd, void *param)
MPP_RET mpp_enc_control(MppEnc ctx, MpiCmd cmd, void *param)
{
MppEncImpl *enc = (MppEncImpl *)ctx;
if (NULL == enc || (NULL == param && cmd != MPP_ENC_SET_IDR_FRAME)) {
mpp_err_f("found NULL input enc %p cmd %x param %d\n", enc, cmd, param);
return MPP_ERR_NULL_PTR;

View file

@ -161,7 +161,7 @@ public:
MppThread *mThreadVproc;
MppDec mDec;
MppEnc *mEnc;
MppEnc mEnc;
private:
void clear();