From f54382264efd0f53fc7b17c373ceb1def48f8710 Mon Sep 17 00:00:00 2001 From: "herman.chen" Date: Fri, 2 Sep 2016 08:33:35 +0800 Subject: [PATCH] [jpege]: add jpeg encoder basic flow Change-Id: I9227008e5c46ddca27df1e807e96813e57e1bb34 Signed-off-by: herman.chen --- mpp/codec/CMakeLists.txt | 7 +- mpp/codec/enc/CMakeLists.txt | 4 +- mpp/codec/enc/jpeg/CMakeLists.txt | 9 +++ mpp/codec/enc/jpeg/jpege_api.c | 98 +++++++++++++++++++++++++++ mpp/codec/inc/jpege_api.h | 32 +++++++++ mpp/codec/mpp_controller.cpp | 3 + mpp/common/jpege_syntax.h | 64 ++++++++++++++++++ mpp/hal/CMakeLists.txt | 7 +- mpp/hal/inc/hal_jpege_api.h | 33 +++++++++ mpp/hal/mpp_hal.cpp | 6 +- mpp/hal/vpu/jpege/CMakeLists.txt | 16 +++++ mpp/hal/vpu/jpege/hal_jpege_api.c | 108 ++++++++++++++++++++++++++++++ mpp/legacy/vpu_api_legacy.cpp | 5 ++ mpp/mpi.cpp | 1 + 14 files changed, 384 insertions(+), 9 deletions(-) create mode 100644 mpp/codec/enc/jpeg/CMakeLists.txt create mode 100644 mpp/codec/enc/jpeg/jpege_api.c create mode 100644 mpp/codec/inc/jpege_api.h create mode 100644 mpp/common/jpege_syntax.h create mode 100644 mpp/hal/inc/hal_jpege_api.h create mode 100644 mpp/hal/vpu/jpege/CMakeLists.txt create mode 100644 mpp/hal/vpu/jpege/hal_jpege_api.c diff --git a/mpp/codec/CMakeLists.txt b/mpp/codec/CMakeLists.txt index 75b572fc..dc3b088c 100644 --- a/mpp/codec/CMakeLists.txt +++ b/mpp/codec/CMakeLists.txt @@ -24,10 +24,9 @@ target_link_libraries(mpp_codec codec_mpg4d codec_vp8d codec_vp9d - codec_jpegd - codec_h264e + codec_jpegd + codec_h264e + codec_jpege codec_dummy_enc codec_dummy_dec mpp_base) - - diff --git a/mpp/codec/enc/CMakeLists.txt b/mpp/codec/enc/CMakeLists.txt index fb450a84..7b941853 100644 --- a/mpp/codec/enc/CMakeLists.txt +++ b/mpp/codec/enc/CMakeLists.txt @@ -2,4 +2,6 @@ add_subdirectory(dummy) -add_subdirectory(h264) \ No newline at end of file +add_subdirectory(h264) + +add_subdirectory(jpeg) \ No newline at end of file diff --git a/mpp/codec/enc/jpeg/CMakeLists.txt b/mpp/codec/enc/jpeg/CMakeLists.txt new file mode 100644 index 00000000..4d143ddc --- /dev/null +++ b/mpp/codec/enc/jpeg/CMakeLists.txt @@ -0,0 +1,9 @@ +# vim: syntax=cmake +include_directories(.) + +add_library(codec_jpege STATIC + jpege_api.c + ) + +target_link_libraries(codec_jpege mpp_base) +set_target_properties(codec_jpege PROPERTIES FOLDER "mpp/codec") diff --git a/mpp/codec/enc/jpeg/jpege_api.c b/mpp/codec/enc/jpeg/jpege_api.c new file mode 100644 index 00000000..39a4fcff --- /dev/null +++ b/mpp/codec/enc/jpeg/jpege_api.c @@ -0,0 +1,98 @@ +/* + * 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. + */ + +#define MODULE_TAG "jpege_api" + +#include "mpp_err.h" +#include "mpp_log.h" +#include "mpp_env.h" +#include "mpp_common.h" + +#include "jpege_api.h" + +typedef struct { + void *ctx; +} JpegeCtx; + +RK_U32 jpege_debug = 0; + +MPP_RET jpege_init(void *ctx, ControllerCfg *ctrlCfg) +{ + (void)ctx; + (void)ctrlCfg; + + return MPP_OK; +} + +MPP_RET jpege_deinit(void *ctx) +{ + (void)ctx; + + return MPP_OK; +} + +MPP_RET jpege_encode(void *ctx, HalEncTask *task) +{ + (void)ctx; + (void)task; + + return MPP_OK; +} + +MPP_RET jpege_reset(void *ctx) +{ + (void)ctx; + + return MPP_OK; +} + +MPP_RET jpege_flush(void *ctx) +{ + (void)ctx; + + return MPP_OK; +} + +MPP_RET jpege_config(void *ctx, RK_S32 cmd, void *param) +{ + (void)ctx; + (void)cmd; + (void)param; + + return MPP_OK; +} + +MPP_RET jpege_callback(void *ctx, void *feedback) +{ + (void)ctx; + (void)feedback; + + return MPP_OK; +} + +const ControlApi api_jpege_controller = { + "jpege_control", + MPP_VIDEO_CodingMJPEG, + sizeof(JpegeCtx), + 0, + jpege_init, + jpege_deinit, + jpege_encode, + jpege_reset, + jpege_flush, + jpege_config, + jpege_callback, +}; diff --git a/mpp/codec/inc/jpege_api.h b/mpp/codec/inc/jpege_api.h new file mode 100644 index 00000000..dff59929 --- /dev/null +++ b/mpp/codec/inc/jpege_api.h @@ -0,0 +1,32 @@ +/* + * 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 __JPEGE_API_H__ +#define __JPEGE_API_H__ + +#include "encoder_codec_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const ControlApi api_jpege_controller; + +#ifdef __cplusplus +} +#endif + +#endif /*__JPEGE_API_H__*/ diff --git a/mpp/codec/mpp_controller.cpp b/mpp/codec/mpp_controller.cpp index aa7bdc74..707f519d 100644 --- a/mpp/codec/mpp_controller.cpp +++ b/mpp/codec/mpp_controller.cpp @@ -19,7 +19,9 @@ #include "mpp_mem.h" #include "mpp_log.h" #include "mpp_common.h" + #include "h264e_api.h" +#include "jpege_api.h" #include "mpp_controller.h" /* @@ -27,6 +29,7 @@ */ static const ControlApi *controllers[] = { &api_h264e_controller, + &api_jpege_controller, }; typedef struct ControllerImpl_t { diff --git a/mpp/common/jpege_syntax.h b/mpp/common/jpege_syntax.h new file mode 100644 index 00000000..a515c263 --- /dev/null +++ b/mpp/common/jpege_syntax.h @@ -0,0 +1,64 @@ +#ifndef __JPEGE_SYNTAX_H__ +#define __JPEGE_SYNTAX_H__ + +#include "rk_type.h" + + + + + +typedef struct jpege_syntax_t { + RK_U32 qp; + RK_U32 qpMin; + RK_U32 qpMax; + RK_U32 xFill; + RK_U32 yFill; + RK_U32 frameNum; + RK_U32 idrPicId; + RK_U32 mbsInRow; + RK_U32 mbsInCol; + RK_U32 jpegMode; + RK_U32 cabacInitIdc; + RK_U32 enableCabac; + RK_U32 sliceSizeMbRows; + RK_U32 outputStrmBase; + RK_U32 outputStrmSize; + RK_U32 inputLumBase; // inputLumBase + RK_U32 inputCrBase; // inputCbBase + RK_U32 inputCbBase; // inputCrBase + RK_U32 pixelsOnRow; // inputImageFormat + RK_U32 jpegSliceEnable; + RK_U32 jpegRestartInterval; + RK_U32 inputLumaBaseOffset; + RK_U32 filterDisable; + RK_U32 inputChromaBaseOffset; + RK_S32 chromaQpIndexOffset; + RK_U32 strmStartMSB; + RK_U32 strmStartLSB; + RK_S32 madQpDelta; + RK_U32 firstFreeBit; + RK_U32 madThreshold; + RK_S32 sliceAlphaOffset; + RK_S32 sliceBetaOffset; + RK_U32 transform8x8Mode; + RK_U32 jpegcolor_conversion_coeff_a; //colorConversionCoeffA + RK_U32 jpegcolor_conversion_coeff_b; //colorConversionCoeffB + RK_U32 jpegcolor_conversion_coeff_c; //colorConversionCoeffC + RK_U32 jpegcolor_conversion_coeff_e; //colorConversionCoeffE + RK_U32 jpegcolor_conversion_coeff_f; //colorConversionCoeffF + RK_U32 jpegcolor_conversion_r_mask_msb; //rMaskMsb + RK_U32 jpegcolor_conversion_g_mask_msb; //gMaskMsb + RK_U32 jpegcolor_conversion_b_mask_msb; //bMaskMsb + + /* RKVENC extra syntax below */ + RK_S32 profile_idc; //TODO: may be removed later, get from sps/pps instead + RK_S32 level_idc; //TODO: may be removed later, get from sps/pps instead + RK_S32 link_table_en; + RK_S32 keyframe_max_interval; +} jpege_syntax; //EncJpegInstance.h + + + + + +#endif diff --git a/mpp/hal/CMakeLists.txt b/mpp/hal/CMakeLists.txt index 50e5b73d..18b26bd0 100644 --- a/mpp/hal/CMakeLists.txt +++ b/mpp/hal/CMakeLists.txt @@ -34,6 +34,8 @@ add_subdirectory(vpu/jpegd) add_subdirectory(rkenc/h264e) +add_subdirectory(vpu/jpege) + # ---------------------------------------------------------------------------- # add hardware worker implement # ---------------------------------------------------------------------------- @@ -54,8 +56,9 @@ target_link_libraries(mpp_hal hal_mpg4d hal_vp8d hal_vp9d - hal_jpegd - hal_h264e + hal_jpegd + hal_h264e + hal_jpege hal_dummy ${RKPLAT_VPU} ) diff --git a/mpp/hal/inc/hal_jpege_api.h b/mpp/hal/inc/hal_jpege_api.h new file mode 100644 index 00000000..50b74621 --- /dev/null +++ b/mpp/hal/inc/hal_jpege_api.h @@ -0,0 +1,33 @@ +/* +* +* 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 __HAL_JPEGE_API_H__ +#define __HAL_JPEGE_API_H__ + +#include "mpp_hal.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern const MppHalApi hal_api_jpege; + +#ifdef __cplusplus +} +#endif + +#endif /*__HAL_JPEGE_API_H__*/ diff --git a/mpp/hal/mpp_hal.cpp b/mpp/hal/mpp_hal.cpp index 2606d02c..e9e69032 100644 --- a/mpp/hal/mpp_hal.cpp +++ b/mpp/hal/mpp_hal.cpp @@ -27,14 +27,15 @@ #include "hal_h263d_api.h" #include "hal_h264d_api.h" +#include "hal_h264e_api.h" #include "hal_h265d_api.h" +#include "hal_vp8d_api.h" #include "hal_vp9d_api.h" #include "hal_avsd_api.h" #include "hal_m2vd_api.h" #include "hal_mpg4d_api.h" -#include "hal_vp8d_api.h" -#include "hal_h264e_api.h" #include "hal_jpegd_api.h" +#include "hal_jpege_api.h" // for test and demo #include "hal_dummy_dec_api.h" @@ -54,6 +55,7 @@ static const MppHalApi *hw_apis[] = { &hal_api_vp9d, &hal_api_jpegd, &hal_api_h264e, + &hal_api_jpege, &hal_api_dummy_dec, &hal_api_dummy_enc, }; diff --git a/mpp/hal/vpu/jpege/CMakeLists.txt b/mpp/hal/vpu/jpege/CMakeLists.txt new file mode 100644 index 00000000..5d9562b0 --- /dev/null +++ b/mpp/hal/vpu/jpege/CMakeLists.txt @@ -0,0 +1,16 @@ +# vim: syntax=cmake +# hal jpeg reg + +set(HAL_JPEGE_HDR + ) + +set(HAL_JPEGE_SRC + hal_jpege_api.c + ) + +add_library(hal_jpege STATIC + ${HAL_JPEGE_SRC} ${HAL_JPEGE_HDR} + ) + +set_target_properties(hal_jpege PROPERTIES FOLDER "mpp/hal") +target_link_libraries(hal_jpege mpp_base) diff --git a/mpp/hal/vpu/jpege/hal_jpege_api.c b/mpp/hal/vpu/jpege/hal_jpege_api.c new file mode 100644 index 00000000..768a2f47 --- /dev/null +++ b/mpp/hal/vpu/jpege/hal_jpege_api.c @@ -0,0 +1,108 @@ +/* + * 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. + */ + +#define MODULE_TAG "hal_jpege_api" + +#include "mpp_hal.h" + +#include "hal_jpege_api.h" + +typedef struct hal_jpege_ctx_s { + MppBufSlots frm_slots; + MppBufSlots pkt_slots; + IOInterruptCB int_cb; +} hal_jpege_ctx; + +RK_U32 hal_jpege_debug = 0; + +MPP_RET hal_jpege_init(void *hal, MppHalCfg *cfg) +{ + (void)hal; + (void)cfg; + + return MPP_OK; +} + +MPP_RET hal_jpege_deinit(void *hal) +{ + (void)hal; + + return MPP_OK; +} + +MPP_RET hal_jpege_gen_regs(void *hal, HalTaskInfo *task) +{ + (void)hal; + (void)task; + + return MPP_OK; +} + +MPP_RET hal_jpege_start(void *hal, HalTaskInfo *task) +{ + (void)task; + (void)hal; + + return MPP_OK; +} + +MPP_RET hal_jpege_wait(void *hal, HalTaskInfo *task) +{ + (void)task; + (void)hal; + + return MPP_OK; +} + +MPP_RET hal_jpege_reset(void *hal) +{ + (void)hal; + + return MPP_OK; +} + +MPP_RET hal_jpege_flush(void *hal) +{ + (void)hal; + + return MPP_OK; +} + +MPP_RET hal_jpege_control(void *hal, RK_S32 cmd_type, void *param) +{ + (void)hal; + (void)param; + (void)cmd_type; + + return MPP_OK; +} + +const MppHalApi hal_api_jpege = { + "jpege_vpu", + MPP_CTX_ENC, + MPP_VIDEO_CodingMJPEG, + sizeof(hal_jpege_ctx), + 0, + hal_jpege_init, + hal_jpege_deinit, + hal_jpege_gen_regs, + hal_jpege_start, + hal_jpege_wait, + hal_jpege_reset, + hal_jpege_flush, + hal_jpege_control, +}; + diff --git a/mpp/legacy/vpu_api_legacy.cpp b/mpp/legacy/vpu_api_legacy.cpp index 24c03b39..703374c1 100644 --- a/mpp/legacy/vpu_api_legacy.cpp +++ b/mpp/legacy/vpu_api_legacy.cpp @@ -731,6 +731,7 @@ RK_S32 VpuApiLegacy::encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, // copy encoded stream into output buffer, and set outpub stream size if (packet != NULL) { + RK_U32 eos = mpp_packet_get_eos(packet); RK_S64 pts = mpp_packet_get_pts(packet); RK_U32 flag = mpp_packet_get_flag(packet); size_t length = mpp_packet_get_length(packet); @@ -746,6 +747,10 @@ RK_S32 VpuApiLegacy::encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, } memcpy(aEncOut->data, (RK_U8*) mpp_buffer_get_ptr(str_buf), aEncOut->size); } + + vpu_api_dbg_output("get packet %p size %d pts %lld keyframe %d eos %d\n", + packet, length, pts, aEncOut->keyFrame, eos); + mpp_packet_deinit(&packet); } else { mpp_log("outputPacket is NULL!"); diff --git a/mpp/mpi.cpp b/mpp/mpi.cpp index 2709852f..60945add 100644 --- a/mpp/mpi.cpp +++ b/mpp/mpi.cpp @@ -45,6 +45,7 @@ static MppCodingTypeInfo support_list[] = { { MPP_CTX_DEC, MPP_VIDEO_CodingAVS, "dec", "avs+", }, { MPP_CTX_DEC, MPP_VIDEO_CodingMJPEG, "dec", "jpeg", }, { MPP_CTX_ENC, MPP_VIDEO_CodingAVC, "enc", "h.264/AVC", }, + { MPP_CTX_ENC, MPP_VIDEO_CodingMJPEG, "enc", "jpeg", }, }; #define check_mpp_ctx(ctx) _check_mpp_ctx(ctx, __FUNCTION__)