Plays MJPEG Video using the RGA. THe RGA allows resize of the JPEG file.
Dependencies: GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP SDBlockDevice_GR_PEACH TLV320_RBSP USBHost_custom
Fork of RGA_HelloWorld by
Overview
This demo shows how play a MJPEG and WAV file video using the RZA1 hardware RGA, JCU and SSIF. The JCU decodes each MJPEG frame. The SSIF plays the raw WAV file, and the RGA supplies the GUI and resize of the JPEG image.
MJPEG Creation
Requirements
- Python 3.1
- FFMPEG https://ffmpeg.org/download.html
Python Script
SD Card
- Rename the jpg file to Renesas.jpg and audio file Renesas.wav
- Download this image file and rename is Background.jpg
Diff: main.cpp
- Revision:
- 2:c7faef0ef374
- Parent:
- 0:84e4649e7707
- Child:
- 4:ce438477eddb
--- a/main.cpp Wed Jan 20 02:35:42 2016 +0000 +++ b/main.cpp Thu Jan 21 10:10:19 2016 +0000 @@ -17,7 +17,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - + #include "mbed.h" #include "rga_func.h" #include "DisplayBace.h" @@ -25,56 +25,38 @@ /* LCD Parameter */ -#define LCD_INPUT_CLOCK 66.67f -#define LCD_OUTPUT_CLOCK 33.26f - -#define LCD_PIXEL_WIDTH 800 -#define LCD_PIXEL_HEIGHT 480 -#define LCD_H_BACK_PORCH (128 + 36) -#define LCD_H_FRONT_PORCH 92 -#define LCD_V_BACK_PORCH (35 + 5) -#define LCD_V_FRONT_PORCH 5 +#define LCD_INPUT_CLOCK (66.67f) +#define LCD_OUTPUT_CLOCK (33.26f) -/* Func Button Image */ -#define XPOS_BUTTON1 50 -#define YPOS_BUTTON1 350 -#define XPOS_BUTTON2 230 -#define YPOS_BUTTON2 YPOS_BUTTON1 -#define XPOS_BUTTON3 410 -#define YPOS_BUTTON3 YPOS_BUTTON1 -#define XPOS_BUTTON4 XPOS_BUTTON1 -#define YPOS_BUTTON4 420 -#define XPOS_BUTTON5 XPOS_BUTTON2 -#define YPOS_BUTTON5 YPOS_BUTTON4 -#define XPOS_BUTTON6 XPOS_BUTTON3 -#define YPOS_BUTTON6 YPOS_BUTTON4 -#define XPOS_BUTTON7 615 -#define YPOS_BUTTON7 YPOS_BUTTON4 -/* Func Button Image Size */ -#define WIDTH_BUTTON 120 -#define HEIGHT_BUTTON 40 -/* Return Button Image */ -#define XPOS_RET_BUTTON 640 -#define YPOS_RET_BUTTON 10 -/* Return Button Image Size */ -#define WIDTH_RET_BUTTON 150 -#define HEIGHT_RET_BUTTON 84 +#define LCD_PIXEL_WIDTH (800) +#define LCD_PIXEL_HEIGHT (480) +#define LCD_H_BACK_PORCH (128 + 36) +#define LCD_H_FRONT_PORCH (92) +#define LCD_V_BACK_PORCH (35 + 5) +#define LCD_V_FRONT_PORCH (5) /* FRAME BUFFER Parameter */ -#define FRAME_BUFFER_BYTE_PER_PIXEL 2 +#define FRAME_BUFFER_BYTE_PER_PIXEL (2) #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) +#define DRAW_RECTANGLE_CNT_MAX (4) + typedef enum { - RGA_FUNC_DRAW_RECTANGLE = 0x00, + RGA_FUNC_NON, + RGA_FUNC_DRAW_RECTANGLE, RGA_FUNC_DRAW_IMAGE, RGA_FUNC_DISSOLVE, RGA_FUNC_SCROLL, RGA_FUNC_ZOOM, RGA_FUNC_ROTATION, RGA_FUNC_ACCELERATE, - RGA_FUNC_MAX_NUM, - RGA_FUNC_RETURN = 0xFE, - RGA_FUNC_NON = 0xFF + RGA_FUNC_ANIME_EASE, + RGA_FUNC_ANIME_LINEAR, + RGA_FUNC_ANIME_EASE_IN, + RGA_FUNC_ANIME_EASE_OUT, + RGA_FUNC_ANIME_EASE_IN_OUT, + RGA_FUNC_RETURN, + RGA_FUNC_END }func_code_t; DigitalOut lcd_pwon(P7_15); @@ -108,20 +90,38 @@ func_code_t func_code; /* func code of the key picture. */ } key_pic_info_t; -static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ -static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ +static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ +static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ static frame_buffer_t frame_buffer_info; static volatile int32_t vsync_count = 0; -static const key_pic_info_t key_tbl[RGA_FUNC_MAX_NUM] = { - /* X position */ /* Y position */ /* Width size */ /* Height size */ /* Func code */ - { XPOS_BUTTON1, YPOS_BUTTON1, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_DRAW_RECTANGLE }, /* RGA Func1 */ - { XPOS_BUTTON2, YPOS_BUTTON2, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_DRAW_IMAGE }, /* RGA Func2 */ - { XPOS_BUTTON3, YPOS_BUTTON3, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_DISSOLVE }, /* RGA Func3 */ - { XPOS_BUTTON4, YPOS_BUTTON4, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_SCROLL }, /* RGA Func4 */ - { XPOS_BUTTON5, YPOS_BUTTON5, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_ZOOM }, /* RGA Func5 */ - { XPOS_BUTTON6, YPOS_BUTTON6, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_ROTATION }, /* RGA Func6 */ - { XPOS_BUTTON7, YPOS_BUTTON7, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_ACCELERATE } /* RGA Func7 */ +static const key_pic_info_t top_screen_key_tbl[] = { + /* X Y Width Height Func code */ + { 50, 350, 120, 52, RGA_FUNC_DRAW_RECTANGLE }, /* RGA Func1 */ + { 230, 350, 120, 52, RGA_FUNC_DRAW_IMAGE }, /* RGA Func2 */ + { 410, 350, 120, 52, RGA_FUNC_DISSOLVE }, /* RGA Func3 */ + { 50, 420, 120, 52, RGA_FUNC_SCROLL }, /* RGA Func4 */ + { 230, 420, 120, 52, RGA_FUNC_ZOOM }, /* RGA Func5 */ + { 410, 420, 120, 52, RGA_FUNC_ROTATION }, /* RGA Func6 */ + { 615, 420, 120, 52, RGA_FUNC_ACCELERATE }, /* RGA Func7 */ + { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ +}; + +static const key_pic_info_t return_key_tbl[] = { + /* X Y Width Height Func code */ + { 640, 10, 150, 84, RGA_FUNC_RETURN }, /* Return Top Screen */ + { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ +}; + +static const key_pic_info_t animetion_timing_key_tbl[] = { + /* X Y Width Height Func code */ + { 640, 10, 150, 84, RGA_FUNC_RETURN }, /* Return Top Screen */ + { 17, 372, 136, 50, RGA_FUNC_ANIME_EASE }, /* ease */ + { 173, 372, 136, 50, RGA_FUNC_ANIME_LINEAR }, /* linear */ + { 330, 372, 136, 50, RGA_FUNC_ANIME_EASE_IN }, /* ease-in */ + { 487, 372, 136, 50, RGA_FUNC_ANIME_EASE_OUT }, /* ease-out */ + { 644, 372, 136, 50, RGA_FUNC_ANIME_EASE_IN_OUT }, /* ease-in-out */ + { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ }; static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) { @@ -216,8 +216,9 @@ lcd_cntrst.write(1.0); } -static void Update_LCD_Display(uint8_t* disp_buf) { - Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0, (void *)disp_buf); +static void Update_LCD_Display(frame_buffer_t * frmbuf_info) { + Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0, + (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]); Wait_Vsync(1); } @@ -242,34 +243,22 @@ return ret; } -static func_code_t Scan_FuncCode(uint32_t pos_x, const uint32_t pos_y) { - int func_cnt; +static func_code_t Scan_Key(const key_pic_info_t * key_tbl, const uint32_t pos_x, const uint32_t pos_y) { func_code_t ret = RGA_FUNC_NON; - for (func_cnt = 0; ((func_cnt < RGA_FUNC_MAX_NUM) && (ret == RGA_FUNC_NON)); func_cnt++) { + while (ret == RGA_FUNC_NON) { + if (key_tbl->func_code == RGA_FUNC_END) { + break; + } /* Check the range of the X position */ - if ((pos_x >= key_tbl[func_cnt].pic_pos_x) && (pos_x <= (key_tbl[func_cnt].pic_pos_x + key_tbl[func_cnt].pic_width))) { + if ((pos_x >= key_tbl->pic_pos_x) && (pos_x <= (key_tbl->pic_pos_x + key_tbl->pic_width))) { /* Check the range of the Y position */ - if ((pos_y >= key_tbl[func_cnt].pic_pos_y) && (pos_y <= (key_tbl[func_cnt].pic_pos_y + key_tbl[func_cnt].pic_height))) { + if ((pos_y >= key_tbl->pic_pos_y) && (pos_y <= (key_tbl->pic_pos_y + key_tbl->pic_height))) { /* Decide the func code. */ - ret = key_tbl[func_cnt].func_code; + ret = key_tbl->func_code; } } - } - - return ret; -} - -static func_code_t Scan_ReturnCode(uint32_t pos_x, const uint32_t pos_y) { - func_code_t ret = RGA_FUNC_NON; - - /* Check the range of the X position */ - if ((pos_x >= XPOS_RET_BUTTON) && (pos_x <= (XPOS_RET_BUTTON + WIDTH_RET_BUTTON))) { - /* Check the range of the Y position */ - if ((pos_y >= YPOS_RET_BUTTON) && (pos_y <= (YPOS_RET_BUTTON + HEIGHT_RET_BUTTON))) { - /* Decide the func code. */ - ret = RGA_FUNC_RETURN; - } + key_tbl++; } return ret; @@ -284,76 +273,210 @@ } static void Exe_RGA_Func(int func_name, frame_buffer_t* frmbuf_info) { - uint8_t* disp_buf; + uint8_t touch_num = 0; + uint32_t pos_x0 = 0; + uint32_t pos_y0 = 0; + func_code_t func_code; switch (func_name) { case RGA_FUNC_DRAW_RECTANGLE: - /* Swap frame buffer */ - Swap_FrameBuffer(frmbuf_info); - disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; - RGA_Func_DrawRectangle(frmbuf_info); - Update_LCD_Display(disp_buf); + bool key_on = false; + int cnt; + int color_cnt = 0; + int x_0 = 0; + int y_0 = 0; + draw_rectangle_pos_t pos_tbl[DRAW_RECTANGLE_CNT_MAX] = {0}; + + pos_tbl[0].style = "#FF0000"; /* red */ + pos_tbl[1].style = "#00FF00"; /* green */ + pos_tbl[2].style = "#0000FF"; /* blue */ + pos_tbl[3].style = "#000000"; /* black */ + + while (1) { + /* Get coordinates */ + Get_Coordinates(&touch_num, &pos_x0, &pos_y0); + if (touch_num != 0) { + if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { + break; + } + if (key_on == false) { + key_on = true; + if (color_cnt == 0) { + for (cnt = 0; cnt < DRAW_RECTANGLE_CNT_MAX; cnt++) { + pos_tbl[cnt].x = 0; + pos_tbl[cnt].y = 0; + pos_tbl[cnt].w = 0; + pos_tbl[cnt].h = 0; + } + } + x_0 = pos_x0; + y_0 = pos_y0; + } + if (x_0 < pos_x0) { + pos_tbl[color_cnt].x = x_0; + pos_tbl[color_cnt].w = pos_x0 - x_0; + } else { + pos_tbl[color_cnt].x = pos_x0; + pos_tbl[color_cnt].w = x_0 - pos_x0; + } + if (y_0 < pos_y0) { + pos_tbl[color_cnt].y = y_0; + pos_tbl[color_cnt].h = pos_y0 - y_0; + } else { + pos_tbl[color_cnt].y = pos_y0; + pos_tbl[color_cnt].h = y_0 - pos_y0; + } + } else { + if (key_on != false) { + color_cnt++; + if (color_cnt == DRAW_RECTANGLE_CNT_MAX) { + color_cnt = 0; + } + } + key_on = false; + } + /* Draw screen */ + Swap_FrameBuffer(frmbuf_info); + RGA_Func_DrawRectangle(frmbuf_info, pos_tbl, DRAW_RECTANGLE_CNT_MAX); + Update_LCD_Display(frmbuf_info); + } break; case RGA_FUNC_DRAW_IMAGE: - /* Swap frame buffer */ - Swap_FrameBuffer(frmbuf_info); - disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; - RGA_Func_DrawImage(frmbuf_info); - Update_LCD_Display(disp_buf); + int center_pos_x = 320; + int center_pos_y = 110; + while (1) { + /* Get coordinates */ + Get_Coordinates(&touch_num, &pos_x0, &pos_y0); + if (touch_num != 0) { + if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { + break; + } + center_pos_x = pos_x0; + center_pos_y = pos_y0; + } + /* Draw screen */ + Swap_FrameBuffer(frmbuf_info); + RGA_Func_DrawImage(frmbuf_info, center_pos_x, center_pos_y); + Update_LCD_Display(frmbuf_info); + } break; case RGA_FUNC_DISSOLVE: - int diss_frame_num; - float32_t work_alpha; - for (diss_frame_num = 0; diss_frame_num < DISSOLVE_MAX_NUM; diss_frame_num += 1) { - /* Swap frame buffer */ + float32_t work_alpha = 0.0f; + while (1) { + /* Get coordinates */ + Get_Coordinates(&touch_num, &pos_x0, &pos_y0); + if (touch_num != 0) { + if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { + break; + } + work_alpha = (float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH); + } + /* Draw screen */ Swap_FrameBuffer(frmbuf_info); - disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; - work_alpha = diss_frame_num / (float32_t)(DISSOLVE_MAX_NUM - 1); RGA_Func_Dissolve(frmbuf_info, work_alpha); - Update_LCD_Display(disp_buf); + Update_LCD_Display(frmbuf_info); } break; case RGA_FUNC_SCROLL: - int work_width_pos; - for (work_width_pos = 0; work_width_pos < SCROLL_MAX_NUM; work_width_pos++) { - /* Swap frame buffer */ + int work_width_pos = 0; + while (1) { + /* Get coordinates */ + Get_Coordinates(&touch_num, &pos_x0, &pos_y0); + if (touch_num != 0) { + if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { + break; + } + work_width_pos = SCROLL_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH)); + } + /* Draw screen */ Swap_FrameBuffer(frmbuf_info); - disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; RGA_Func_Scroll(frmbuf_info, work_width_pos); - Update_LCD_Display(disp_buf); + Update_LCD_Display(frmbuf_info); } break; case RGA_FUNC_ZOOM: - int work_height_pos; - for (work_height_pos = 0; work_height_pos <= ZOOM_MAX_NUM; work_height_pos++) { - /* Swap frame buffer */ + int work_height_pos = ZOOM_MAX_NUM; + while (1) { + /* Get coordinates */ + Get_Coordinates(&touch_num, &pos_x0, &pos_y0); + if (touch_num != 0) { + if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { + break; + } + work_height_pos = ZOOM_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH)); + } + /* Draw screen */ Swap_FrameBuffer(frmbuf_info); - disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; - RGA_Func_Zoom(frmbuf_info, work_height_pos); - Update_LCD_Display(disp_buf); + RGA_Func_Zoom(frmbuf_info, work_height_pos); + Update_LCD_Display(frmbuf_info); } break; case RGA_FUNC_ROTATION: - graphics_matrix_float_t work_angle; - for (work_angle = 0; work_angle <= ROTATION_MAX_NUM; work_angle++) { - /* Swap frame buffer */ + graphics_matrix_float_t work_angle = 0; + while (1) { + /* Get coordinates */ + Get_Coordinates(&touch_num, &pos_x0, &pos_y0); + if (touch_num != 0) { + if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { + break; + } + work_angle = ROTATION_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH)); + } + /* Draw screen */ Swap_FrameBuffer(frmbuf_info); - disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; RGA_Func_Rotation(frmbuf_info, work_angle); - Update_LCD_Display(disp_buf); + Update_LCD_Display(frmbuf_info); } break; case RGA_FUNC_ACCELERATE: - int acce_frame_num; + int acce_frame_num = 0; + int animation_timing = 0; float32_t work_relative_pos; - Get_AnimationTiming("ease"); - for (acce_frame_num = 0; acce_frame_num <= ACCELERATE_MAX_NUM; acce_frame_num++) { - /* Swap frame buffer */ + while (1) { + /* Get coordinates */ + Get_Coordinates(&touch_num, &pos_x0, &pos_y0); + if (touch_num != 0) { + func_code_t func_code; + + func_code = Scan_Key(animetion_timing_key_tbl, pos_x0, pos_y0); + if (func_code == RGA_FUNC_RETURN) { + break; + } + switch (func_code) { + case RGA_FUNC_ANIME_EASE: + animation_timing = 0; + acce_frame_num = 0; + break; + case RGA_FUNC_ANIME_LINEAR: + animation_timing = 1; + acce_frame_num = 0; + break; + case RGA_FUNC_ANIME_EASE_IN: + animation_timing = 2; + acce_frame_num = 0; + break; + case RGA_FUNC_ANIME_EASE_OUT: + animation_timing = 3; + acce_frame_num = 0; + break; + case RGA_FUNC_ANIME_EASE_IN_OUT: + animation_timing = 4; + acce_frame_num = 0; + break; + default: + /* Do Nothing */ + break; + } + } + work_relative_pos = acce_frame_num / (float32_t)ACCELERATE_MAX_NUM; + acce_frame_num++; + if (acce_frame_num > ACCELERATE_MAX_NUM) { + acce_frame_num = 0; + } + /* Draw screen */ Swap_FrameBuffer(frmbuf_info); - disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; - work_relative_pos = acce_frame_num / (float32_t)ACCELERATE_MAX_NUM; - RGA_Func_Accelerate(frmbuf_info, work_relative_pos); - Update_LCD_Display(disp_buf); + RGA_Func_Accelerate(frmbuf_info, animation_timing, work_relative_pos); + Update_LCD_Display(frmbuf_info); } break; default : @@ -364,8 +487,6 @@ int main(void) { func_code_t func_code; - frame_buffer_t* work_frm_buf; - uint8_t* disp_buffer; uint8_t touch_num = 0; uint32_t pos_x0 = 0; uint32_t pos_y0 = 0; @@ -382,40 +503,35 @@ frame_buffer_info.stride = LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL; frame_buffer_info.height = LCD_PIXEL_HEIGHT; frame_buffer_info.pixel_format = PIXEL_FORMAT_RGB565; - disp_buffer = frame_buffer_info.buffer_address[0]; - Init_LCD_Display(disp_buffer); + Init_LCD_Display(frame_buffer_info.buffer_address[0]); /* Display Top Screen */ - work_frm_buf = &frame_buffer_info; - Set_RGAObject(work_frm_buf); - RGA_Func_DrawTopScreen(work_frm_buf); + Set_RGAObject(&frame_buffer_info); + RGA_Func_DrawTopScreen(&frame_buffer_info); Start_LCD_Display(); while (1) { + /* Get Coordinates */ Get_Coordinates(&touch_num, &pos_x0, &pos_y0); if (touch_num != 0) { - func_code = Scan_FuncCode(pos_x0, pos_y0); + func_code = Scan_Key(top_screen_key_tbl, pos_x0, pos_y0); if (func_code != RGA_FUNC_NON) { + /* Wait key off */ + while (1) { + Get_Coordinates(&touch_num, &pos_x0, &pos_y0); + if (touch_num == 0) { + break; + } + Thread::wait(50); + } + /* Execute RGA functions */ - Exe_RGA_Func(func_code, work_frm_buf); - Thread::wait(1000); - /* Display Return Button */ - disp_buffer = work_frm_buf->buffer_address[work_frm_buf->draw_buffer_index]; - RGA_Func_DrawReturnButton(work_frm_buf); - Update_LCD_Display(disp_buffer); - /* Wait until Return Code is pressed */ - while (func_code != RGA_FUNC_RETURN) { - Get_Coordinates(&touch_num, &pos_x0, &pos_y0); - if (touch_num != 0) { - func_code = Scan_ReturnCode(pos_x0, pos_y0); - } - Thread::wait(100); - } + Exe_RGA_Func(func_code, &frame_buffer_info); + /* Return Top Screen */ - Swap_FrameBuffer(work_frm_buf); - disp_buffer = work_frm_buf->buffer_address[work_frm_buf->draw_buffer_index]; - RGA_Func_DrawTopScreen(work_frm_buf); - Update_LCD_Display(disp_buffer); + Swap_FrameBuffer(&frame_buffer_info); + RGA_Func_DrawTopScreen(&frame_buffer_info); + Update_LCD_Display(&frame_buffer_info); } } Thread::wait(100);