diff --git a/mpp/CMakeLists.txt b/mpp/CMakeLists.txt index 7262bc46..960126f0 100644 --- a/mpp/CMakeLists.txt +++ b/mpp/CMakeLists.txt @@ -42,7 +42,7 @@ add_subdirectory(hal) set (MPP_SRC mpp_info.cpp mpp.cpp - mpi_impl.cpp + mpp_impl.cpp mpi.cpp ) diff --git a/mpp/inc/mpi_impl.h b/mpp/inc/mpi_impl.h index 7673f657..3e93a4fd 100644 --- a/mpp/inc/mpi_impl.h +++ b/mpp/inc/mpi_impl.h @@ -37,15 +37,6 @@ struct MpiImpl_t { Mpp *ctx; }; -#ifdef __cplusplus -extern "C" { -#endif - extern RK_U32 mpi_debug; -void get_mpi_debug(); - -#ifdef __cplusplus -} -#endif #endif /*__MPI_IMPL_H__*/ diff --git a/mpp/inc/mpp.h b/mpp/inc/mpp.h index d2886cad..c600afa5 100644 --- a/mpp/inc/mpp.h +++ b/mpp/inc/mpp.h @@ -22,6 +22,7 @@ #include "mpp_dec.h" #include "mpp_enc.h" #include "mpp_task.h" +#include "mpp_impl.h" #define MPP_DBG_FUNCTION (0x00000001) #define MPP_DBG_PACKET (0x00000002) @@ -175,6 +176,9 @@ private: /* backup extra packet for seek */ MppPacket mExtraPacket; + /* dump info for debug */ + MppDumpInfo mDump; + MPP_RET control_mpp(MpiCmd cmd, MppParam param); MPP_RET control_osal(MpiCmd cmd, MppParam param); MPP_RET control_codec(MpiCmd cmd, MppParam param); diff --git a/mpp/inc/mpp_impl.h b/mpp/inc/mpp_impl.h new file mode 100644 index 00000000..ad8bc339 --- /dev/null +++ b/mpp/inc/mpp_impl.h @@ -0,0 +1,52 @@ +/* + * + * 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_IMPL_H__ +#define __MPP_IMPL_H__ + +#include + +#include "rk_mpi.h" +#include "rk_type.h" +#include "mpp_log.h" + +/* dump data */ +typedef struct mpp_dump_info_t { + MppCtxType type; + + FILE *fp_in; // write input file + FILE *fp_out; // write output file + RK_U8 *fp_buf; // for resample frame + RK_U32 dump_width; + RK_U32 dump_height; +} MppDumpInfo; + +#ifdef __cplusplus +extern "C" { +#endif + +MPP_RET mpp_dump_init(MppDumpInfo *info, MppCtxType type); +MPP_RET mpp_dump_deinit(MppDumpInfo *info); + +MPP_RET mpp_dump_packet(MppDumpInfo *info, MppPacket pkt); +MPP_RET mpp_dump_frame(MppDumpInfo *info, MppFrame frame); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mpp/legacy/vpu_api_legacy.cpp b/mpp/legacy/vpu_api_legacy.cpp index ccefe827..30809b3a 100644 --- a/mpp/legacy/vpu_api_legacy.cpp +++ b/mpp/legacy/vpu_api_legacy.cpp @@ -32,9 +32,6 @@ #include "mpp_buffer_impl.h" #include "mpp_frame.h" -#define MAX_WRITE_HEIGHT (480) -#define MAX_WRITE_WIDTH (960) - RK_U32 vpu_api_debug = 0; static MppFrameFormat vpu_pic_type_remap_to_mpp(EncInputPictureType type) @@ -216,55 +213,6 @@ RET: return ret; } -static void vpu_api_dump_yuv(VPU_FRAME *vframe, FILE *fp, - MppBuffer buf, RK_U8 *fp_buf, RK_S64 pts) -{ - //!< Dump yuv - if (fp && !vframe->ErrorInfo) { - RK_U8 *ptr = vframe->vpumem.vir_addr ? - (RK_U8 *)vframe->vpumem.vir_addr : (RK_U8 *)mpp_buffer_get_ptr(buf); - - if ((vframe->FrameWidth >= 1920) || (vframe->FrameHeight >= 1080)) { - RK_U32 i = 0, j = 0, step = 0; - RK_U32 img_w = 0, img_h = 0; - RK_U8 *pdes = NULL, *psrc = NULL; - - step = MPP_MAX(vframe->FrameWidth / MAX_WRITE_WIDTH, vframe->FrameHeight / MAX_WRITE_HEIGHT); - img_w = vframe->FrameWidth / step; - img_h = vframe->FrameHeight / step; - pdes = fp_buf; - psrc = ptr; - for (i = 0; i < img_h; i++) { - for (j = 0; j < img_w; j++) { - pdes[j] = psrc[j * step]; - } - pdes += img_w; - psrc += step * vframe->FrameWidth; - } - pdes = fp_buf + img_w * img_h; - psrc = (RK_U8 *)ptr + vframe->FrameWidth * vframe->FrameHeight; - for (i = 0; i < (img_h / 2); i++) { - for (j = 0; j < (img_w / 2); j++) { - pdes[2 * j + 0] = psrc[2 * j * step + 0]; - pdes[2 * j + 1] = psrc[2 * j * step + 1]; - } - pdes += img_w; - psrc += step * vframe->FrameWidth * ((vframe->ColorType & VPU_OUTPUT_FORMAT_BIT_10) ? 2 : 1); - } - fwrite(fp_buf, 1, img_w * img_h * 3 / 2, fp); - if (vpu_api_debug & VPU_API_DBG_DUMP_LOG) { - mpp_log("[write_out_yuv] timeUs=%lld, FrameWidth=%d, FrameHeight=%d", pts, img_w, img_h); - } - } else { - fwrite(ptr, 1, vframe->FrameWidth * vframe->FrameHeight * 3 / 2, fp); - if (vpu_api_debug & VPU_API_DBG_DUMP_LOG) { - mpp_log("[write_out_yuv] timeUs=%lld, FrameWidth=%d, FrameHeight=%d", pts, vframe->FrameWidth, vframe->FrameHeight); - } - } - fflush(fp); - } -} - static int is_valid_dma_fd(int fd) { int ret = 1; @@ -340,8 +288,6 @@ VpuApiLegacy::VpuApiLegacy() : init_ok(0), frame_count(0), set_eos(0), - fp(NULL), - fp_buf(NULL), memGroup(NULL), format(MPP_FMT_YUV420P), fd_input(-1), @@ -352,11 +298,6 @@ VpuApiLegacy::VpuApiLegacy() : mpp_create(&mpp_ctx, &mpi); - if (vpu_api_debug & VPU_API_DBG_DUMP_YUV) { - fp = fopen("/sdcard/rk_mpp_dump.yuv", "wb"); - fp_buf = mpp_malloc(RK_U8, (MAX_WRITE_HEIGHT * MAX_WRITE_WIDTH * 2)); - } - memset(&enc_cfg, 0, sizeof(enc_cfg)); vpu_api_dbg_func("leave\n"); } @@ -364,14 +305,7 @@ VpuApiLegacy::VpuApiLegacy() : VpuApiLegacy::~VpuApiLegacy() { vpu_api_dbg_func("enter\n"); - if (fp) { - fclose(fp); - fp = NULL; - } - if (fp_buf) { - mpp_free(fp_buf); - fp_buf = NULL; - } + if (memGroup) { mpp_buffer_group_put(memGroup); memGroup = NULL; @@ -828,7 +762,6 @@ RK_S32 VpuApiLegacy::decode(VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut MppBuffer buf = mpp_frame_get_buffer(mframe); setup_VPU_FRAME_from_mpp_frame(vframe, mframe); - vpu_api_dump_yuv(vframe, fp, buf, fp_buf, mpp_frame_get_pts(mframe)); aDecOut->size = sizeof(VPU_FRAME); aDecOut->timeUs = mpp_frame_get_pts(mframe); @@ -937,7 +870,6 @@ RK_S32 VpuApiLegacy::decode_getoutframe(DecoderOut_t *aDecOut) MppBuffer buf = mpp_frame_get_buffer(mframe); setup_VPU_FRAME_from_mpp_frame(vframe, mframe); - vpu_api_dump_yuv(vframe, fp, buf, fp_buf, mpp_frame_get_pts(mframe)); aDecOut->size = sizeof(VPU_FRAME); aDecOut->timeUs = mpp_frame_get_pts(mframe); diff --git a/mpp/legacy/vpu_api_legacy.h b/mpp/legacy/vpu_api_legacy.h index b5fb8e0d..b958a09c 100644 --- a/mpp/legacy/vpu_api_legacy.h +++ b/mpp/legacy/vpu_api_legacy.h @@ -24,8 +24,6 @@ #define OMX_BUFFERFLAG_EOS 0x00000001 #define VPU_API_DBG_FUNCTION (0x00000001) -#define VPU_API_DBG_DUMP_YUV (0x00000002) -#define VPU_API_DBG_DUMP_LOG (0x00000004) #define VPU_API_DBG_INPUT (0x00000010) #define VPU_API_DBG_OUTPUT (0x00000020) @@ -71,9 +69,6 @@ private: RK_U32 frame_count; RK_U32 set_eos; - FILE *fp; - RK_U8 *fp_buf; - /* encoder parameters */ MppBufferGroup memGroup; MppFrameFormat format; diff --git a/mpp/mpi.cpp b/mpp/mpi.cpp index 56db43ca..fe49d760 100644 --- a/mpp/mpi.cpp +++ b/mpp/mpi.cpp @@ -26,6 +26,9 @@ #include "mpp.h" #include "mpp_info.h" #include "mpp_common.h" +#include "mpp_env.h" + +RK_U32 mpi_debug = 0; typedef struct { MppCtxType type; @@ -417,12 +420,13 @@ static MppApi mpp_api = { MPP_RET mpp_create(MppCtx *ctx, MppApi **mpi) { + mpp_env_get_u32("mpi_debug", &mpi_debug, 0); + if (NULL == ctx || NULL == mpi) { mpp_err_f("invalid input ctx %p mpi %p\n", ctx, mpi); return MPP_ERR_NULL_PTR; } - *ctx = NULL; *mpi = NULL; @@ -481,7 +485,6 @@ MPP_RET mpp_init(MppCtx ctx, MppCtxType type, MppCodingType coding) p->coding = coding; } while (0); - get_mpi_debug(); mpi_dbg_func("leave ret %d\n", ret); return ret; } diff --git a/mpp/mpi_impl.cpp b/mpp/mpi_impl.cpp deleted file mode 100644 index 04bf8d76..00000000 --- a/mpp/mpi_impl.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 "mpi" - -#include "rk_mpi.h" -#include "mpp_log.h" -#include "mpp_env.h" -#include "mpi_impl.h" - -RK_U32 mpi_debug = 0; - -void get_mpi_debug() -{ - mpp_env_get_u32("mpi_debug", &mpi_debug, 0); - mpp_env_get_u32("mpp_debug", &mpp_debug, 0); -} - diff --git a/mpp/mpp.cpp b/mpp/mpp.cpp index 81b5027e..26f1a4c2 100644 --- a/mpp/mpp.cpp +++ b/mpp/mpp.cpp @@ -21,6 +21,7 @@ #include "mpp_mem.h" #include "mpp_env.h" #include "mpp_time.h" +#include "mpp_impl.h" #include "mpp.h" #include "mpp_dec.h" @@ -172,6 +173,7 @@ MPP_RET Mpp::init(MppCtxType type, MppCodingType coding) } mpp_env_get_u32("mpp_debug", &mpp_debug, 0); + mpp_dump_init(&mDump, type); return MPP_OK; } @@ -269,6 +271,7 @@ void Mpp::clear() mpp_buffer_group_put(mFrameGroup); mFrameGroup = NULL; } + mpp_dump_deinit(&mDump); } MPP_RET Mpp::put_packet(MppPacket packet) @@ -291,6 +294,8 @@ MPP_RET Mpp::put_packet(MppPacket packet) mPackets->add_at_tail(&pkt, sizeof(pkt)); mPacketPutCount++; + // dump input packet + mpp_dump_packet(&mDump, packet); // when packet has been send clear the length mpp_packet_set_length(packet, 0); @@ -359,6 +364,10 @@ MPP_RET Mpp::get_frame(MppFrame *frame) } *frame = first; + + // dump output + mpp_dump_frame(&mDump, first); + return MPP_OK; } @@ -393,6 +402,8 @@ MPP_RET Mpp::put_frame(MppFrame frame) mpp_log_f("set input frame to task ret %d\n", ret); goto RET; } + // dump input + mpp_dump_frame(&mDump, frame); /* enqueue valid task to encoder */ ret = enqueue(MPP_PORT_INPUT, mInputTask); @@ -465,6 +476,9 @@ MPP_RET Mpp::get_packet(MppPacket *packet) if (mpp_debug & MPP_DBG_PTS) mpp_log_f("pts %lld\n", mpp_packet_get_pts(*packet)); + // dump output + mpp_dump_packet(&mDump, *packet); + ret = enqueue(MPP_PORT_OUTPUT, task); if (ret) mpp_log_f("enqueue on set ret %d\n", ret); diff --git a/mpp/mpp_impl.cpp b/mpp/mpp_impl.cpp new file mode 100644 index 00000000..d51bdd8e --- /dev/null +++ b/mpp/mpp_impl.cpp @@ -0,0 +1,163 @@ +/* + * + * 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 "mpp_impl" + +#include "mpp_mem.h" +#include "mpp_env.h" +#include "mpp_common.h" + +#include "mpp_impl.h" + +#define MAX_DUMP_WIDTH 960 +#define MAX_DUMP_HEIGHT 540 + +static const char dec_in_path[] = "/data/mpp_dec_in.bin"; +static const char enc_in_path[] = "/data/enc_dec_in.bin"; +static const char dec_out_path[] = "/data/mpp_dec_out.bin"; +static const char enc_out_path[] = "/data/enc_dec_out.bin"; + +MPP_RET mpp_dump_init(MppDumpInfo *info, MppCtxType type) +{ + const char *fname = NULL; + const char *path = NULL; + RK_U32 dump_frame_size; + + memset(info, 0, sizeof(*info)); + info->type = type; + + mpp_env_get_u32("mpp_dump_width", &info->dump_width, MAX_DUMP_WIDTH); + mpp_env_get_u32("mpp_dump_height", &info->dump_height, MAX_DUMP_HEIGHT); + + dump_frame_size = info->dump_width * info->dump_height * 3 / 2; + + if (mpp_debug & MPP_DBG_DUMP_IN) { + if (type == MPP_CTX_DEC) { + path = dec_in_path; + } else { + path = enc_in_path; + info->fp_buf = mpp_malloc(RK_U8, dump_frame_size); + } + + mpp_env_get_str("mpp_dump_in", &fname, path); + info->fp_in = fopen(fname, "w+b"); + mpp_log("open %s %p for input dump\n", fname, info->fp_in); + } + + if (mpp_debug & MPP_DBG_DUMP_OUT) { + if (type == MPP_CTX_DEC) { + path = dec_out_path; + info->fp_buf = mpp_malloc(RK_U8, dump_frame_size); + } else { + path = enc_out_path; + } + + mpp_env_get_str("mpp_dump_out", &fname, path); + info->fp_out = fopen(fname, "w+b"); + mpp_log("open %s %p for output dump\n", fname, info->fp_out); + } + + return MPP_OK; +} + +MPP_RET mpp_dump_deinit(MppDumpInfo *info) +{ + MPP_FCLOSE(info->fp_in); + MPP_FCLOSE(info->fp_out); + MPP_FREE(info->fp_buf); + + return MPP_OK; +} + +MPP_RET mpp_dump_packet(MppDumpInfo *info, MppPacket pkt) +{ + FILE *fp = (info->type == MPP_CTX_DEC) ? info->fp_in : info->fp_out; + + if (fp && pkt) { + fwrite(mpp_packet_get_data(pkt), 1, + mpp_packet_get_length(pkt), fp); + fflush(fp); + } + + return MPP_OK; +} + +MPP_RET mpp_dump_frame(MppDumpInfo *info, MppFrame frame) +{ + RK_U32 dump_width = info->dump_width; + RK_U32 dump_height = info->dump_height; + RK_U8 *fp_buf = info->fp_buf; + FILE *fp = (info->type == MPP_CTX_DEC) ? info->fp_out : info->fp_in; + + if (NULL == fp || NULL == fp_buf || NULL == frame) + return MPP_OK; + + MppBuffer buf = mpp_frame_get_buffer(frame); + if (NULL == buf) + return MPP_OK; + + RK_U32 width = mpp_frame_get_hor_stride(frame); + RK_U32 height = mpp_frame_get_ver_stride(frame); + RK_U8 *ptr = (RK_U8 *) mpp_buffer_get_ptr(buf); + + if (width > dump_width || height > dump_height) { + RK_U32 i = 0, j = 0, step = 0; + RK_U32 img_w = 0, img_h = 0; + RK_U8 *pdes = NULL, *psrc = NULL; + + step = MPP_MAX((width + dump_width - 1) / dump_width, + (height + dump_height - 1) / dump_height); + img_w = width / step; + img_h = height / step; + pdes = fp_buf; + psrc = ptr; + for (i = 0; i < img_h; i++) { + for (j = 0; j < img_w; j++) { + pdes[j] = psrc[j * step]; + } + pdes += img_w; + psrc += step * width; + } + pdes = fp_buf + img_w * img_h; + psrc = (RK_U8 *)ptr + width * height; + for (i = 0; i < (img_h / 2); i++) { + for (j = 0; j < (img_w / 2); j++) { + pdes[2 * j + 0] = psrc[2 * j * step + 0]; + pdes[2 * j + 1] = psrc[2 * j * step + 1]; + } + pdes += img_w; + psrc += step * width; + } + + fwrite(fp_buf, 1, img_w * img_h * 3 / 2, fp); + + width = img_w; + height = img_h; + } else { + fwrite(ptr, 1, width * height * 3 / 2, fp); + } + + fflush(fp); + + if (mpp_debug & MPP_DBG_DUMP_LOG) { + RK_S64 pts = mpp_frame_get_pts(frame); + + mpp_log("dump_yuv: [%d:%d] pts %lld", width, height, pts); + } + + return MPP_OK; +} diff --git a/mpp/mpp_info.cpp b/mpp/mpp_info.cpp index f180a4aa..dd3ce396 100644 --- a/mpp/mpp_info.cpp +++ b/mpp/mpp_info.cpp @@ -38,7 +38,7 @@ static char mpp_version_number[] = MPP_VER_NUM; static RK_CHIP_TYPE chip_version(void) { RK_CHIP_TYPE type = NONE; - char *value = NULL; + const char *value = NULL; RK_S32 ret = mpp_env_get_str("ro.product.board", &value, NULL); if (0 == ret) { diff --git a/osal/inc/mpp_log.h b/osal/inc/mpp_log.h index 3ddeda0a..656de9c6 100644 --- a/osal/inc/mpp_log.h +++ b/osal/inc/mpp_log.h @@ -57,6 +57,11 @@ #define MPP_DBG_PTS (0x00000002) #define MPP_DBG_INFO (0x00000004) #define MPP_DBG_PLATFORM (0x00000010) + +#define MPP_DBG_DUMP_LOG (0x00000100) +#define MPP_DBG_DUMP_IN (0x00000200) +#define MPP_DBG_DUMP_OUT (0x00000400) + #define MPP_ABORT (0x10000000) /*