#define LOG_NDEBUG 0 #define LOG_TAG "rgaClip" #include "myrga.h" #include #include #include #include #include #include #include #include #include /// // #include "../drmrga.h" #include #include #include #include #include #include #include #include #include // #include /// rga_client_t rga_client; static pthread_mutex_t rga_info_mutex = PTHREAD_MUTEX_INITIALIZER; static rga_frame_info_t rga_last_info = {0}; void rga_get_last_frame_info(rga_frame_info_t *out) { if (!out) { return; } pthread_mutex_lock(&rga_info_mutex); *out = rga_last_info; pthread_mutex_unlock(&rga_info_mutex); } // const int SRCFMT = RK_FORMAT_YCrCb_420_SP; const int SRCFMT = RK_FORMAT_YCbCr_420_SP; const int DSTFMT = RK_FORMAT_RGB_888; // const int DSTWidth = 640; // const int DSTHeight = 640; int rga_client_t::convert(unsigned char *src, int sw, int sh, int swstride, int shstride, char *out) { RockchipRga &rga(RockchipRga::getInstance()); int ret = 0; char *buf = (char *)src; // get_buf_from_file(buf, SRCFMT, sw, sh, 1); // out should be 1280*720*3 buf = out; // get_buf_from_file(buf, DSTFMT, DSTWidth, DSTHeight, 0); while (1) { // ********** rga_info_t Init ********** rga_info_t rgasrc; rga_info_t rgadst; memset(&rgasrc, 0, sizeof(rga_info_t)); rgasrc.fd = -1; rgasrc.mmuFlag = 1; rgasrc.virAddr = src; memset(&rgadst, 0, sizeof(rga_info_t)); rgadst.fd = -1; rgadst.mmuFlag = 1; rgadst.virAddr = out; struct timeval tpend1, tpend2; long usec1 = 0; gettimeofday(&tpend1, NULL); rgadst.color = 0xcccccc; rga_set_rect(&rgadst.rect, 0, 0, DSTWidth, DSTHeight, DSTWidth, DSTHeight, DSTFMT); rga.RkRgaCollorFill(&rgadst); float widthratio = 1.0 * swstride / DSTWidth; float heightratio = 1.0 * shstride / DSTHeight; int TMPWIDTH = DSTWidth; int TMPHEIGHT = DSTHeight; int startwidth = 0; int startheight = 0; if (widthratio < heightratio) { TMPWIDTH = int(swstride / heightratio); startwidth = int((DSTWidth - TMPWIDTH) / 2); } else { TMPHEIGHT = int(shstride / widthratio); startheight = int((DSTHeight - TMPHEIGHT) / 2); } pthread_mutex_lock(&rga_info_mutex); rga_last_info.seq += 1; rga_last_info.src_width = sw; rga_last_info.src_height = sh; rga_last_info.src_h_stride = swstride; rga_last_info.src_v_stride = shstride; rga_last_info.dst_width = DSTWidth; rga_last_info.dst_height = DSTHeight; rga_last_info.dst_x = startwidth; rga_last_info.dst_y = startheight; rga_last_info.dst_rect_width = TMPWIDTH; rga_last_info.dst_rect_height = TMPHEIGHT; pthread_mutex_unlock(&rga_info_mutex); // ********** set the rect_info ********** rga_set_rect(&rgasrc.rect, 0, 0, sw, sh, // stride swstride, shstride, SRCFMT); /* rga_set_rect(&rgadst.rect, 0, 0, DSTWidth, DSTHeight, // stride DSTWidth, DSTHeight, DSTFMT); */ rga_set_rect(&rgadst.rect, startwidth, startheight, TMPWIDTH, TMPHEIGHT, DSTWidth, DSTHeight, DSTFMT); // ************ set the rga_mod ,rotation\composition\scale\copy .... ********** // rgasrc.blend = 0xff0105; // rga_set_rect(&rgasrc.rect, 0, 0, sw, sh, swstride, shstride, SRCFMT); // rga_set_rect(&rgadst.rect, 0, 0, DSTWidth, DSTHeight, DSTWidth, DSTHeight, DSTFMT); // ********** call rga_Interface ********** ret = rga.RkRgaBlit(&rgasrc, &rgadst, NULL); gettimeofday(&tpend2, NULL); usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; printf("rga cost_time=%ld ms\n", usec1); if (ret) { printf("rgaFillColor error : %s\n", strerror(errno)); } { // ********** output buf data to file ********* /* char* dstbuf = (char *)dst; output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); */ } // printf("threadloop\n"); usleep(5000); break; } return 0; } void initRkRga() { } void deinitRkRga() { } // using namespace android; /* int main() { int ret = 0; int srcWidth,srcHeight,srcFormat; int dstWidth,dstHeight,dstFormat; void *src = NULL; void *dst = NULL; srcWidth = 1280; srcHeight = 720; // srcFormat = HAL_PIXEL_FORMAT_RGBA_8888; srcFormat = RK_FORMAT_RGBA_8888; dstWidth = 1280; dstHeight = 720; //dstFormat = HAL_PIXEL_FORMAT_RGBA_8888; dstFormat = RK_FORMAT_RGBA_8888; // ********** apply for buffer ********** src = malloc(srcWidth * srcHeight * 4); if (!src) return -ENOMEM; //********** apply for buffer ********** dst = malloc(dstWidth * dstHeight * 4); if (!dst) { free(src); return -ENOMEM; } RockchipRga& rkRga(RockchipRga::get()); // ********** get data to src_buffer or init buffer********** char* buf = (char *)src; #if 1 get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 1); #else memset(buf,0x55,4*1280*720); #endif // ********** get data to dst_buffer or init buffer ********** buf = (char *)dst; #if 1 get_buf_from_file(buf, srcFormat, srcWidth, srcHeight, 0); #else memset(buf,0x00,4*1280*720); #endif while(1) { // ********** rga_info_t Init ********** rga_info_t rgasrc; rga_info_t rgadst; memset(&rgasrc, 0, sizeof(rga_info_t)); rgasrc.fd = -1; rgasrc.mmuFlag = 1; rgasrc.virAddr = src; memset(&rgadst, 0, sizeof(rga_info_t)); rgadst.fd = -1; rgadst.mmuFlag = 1; rgadst.virAddr = dst; // ********** set the rect_info ********** rga_set_rect(&rgasrc.rect, 0,0,srcWidth,srcHeight, // stride srcWidth,srcHeight, srcFormat); rga_set_rect(&rgadst.rect, 0,0,dstWidth,dstHeight, // stride dstWidth,dstHeight, dstFormat); // ************ set the rga_mod ,rotation\composition\scale\copy .... ********** rgasrc.blend = 0xff0105; // ********** call rga_Interface ********** struct timeval tpend1, tpend2; long usec1 = 0; gettimeofday(&tpend1, NULL); ret = rkRga.RkRgaBlit(&rgasrc, &rgadst, NULL); gettimeofday(&tpend2, NULL); usec1 = 1000 * (tpend2.tv_sec - tpend1.tv_sec) + (tpend2.tv_usec - tpend1.tv_usec) / 1000; printf("cost_time=%ld ms\n", usec1); if (ret) { printf("rgaFillColor error : %s\n", strerror(errno)); } { // ********** output buf data to file ********* char* dstbuf = (char *)dst; output_buf_data_to_file(dstbuf, dstFormat, dstWidth, dstHeight, 0); } printf("threadloop\n"); usleep(500000); break; } return 0; } */