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 Renesas

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 Script

SD Card

  • Rename the jpg file to Renesas.jpg and audio file Renesas.wav
  • Download this image file and rename is Background.jpg /media/uploads/zkimike/background.jpg
Revision:
13:0a5bd13f6e7f
Parent:
12:9a413bec6673
--- a/main.cpp	Fri Jan 05 22:41:01 2018 +0000
+++ b/main.cpp	Wed Jan 17 19:02:00 2018 +0000
@@ -349,10 +349,6 @@
         }
         break;
         case RGA_FUNC_VIDEO_PLAYER:
-        case RGA_FUNC_VIDEO_PLAY:
-        case RGA_FUNC_VIDEO_STOP:
-        case RGA_FUNC_VIDEO_FWD:
-        case RGA_FUNC_VIDEO_REV:
         {
             // FileSystem
             FILE * vfp = NULL;
@@ -378,6 +374,11 @@
             uint32_t audio_sample_size = 0;
             Timer timer;
             
+            // Control
+            bool audio_off = false;
+            bool video_off = false;
+            int8_t audio_skip = 0;
+            
             /*******************************************************************
             *   Initialize SDHC FileSystem
             *******************************************************************/
@@ -450,8 +451,31 @@
             TestPin2 = 0;
             TestPin3 = 0;
             timer.reset();
-            
+
             while (1) {
+                
+                switch ( video_mode ) {
+                    case RGA_FUNC_VIDEO_STOP:
+                        audio_skip = 0;
+                        audio_off = true;
+                        frame_skip = MJPEG_DIV-1;
+                        video_off = true;
+                    case RGA_FUNC_VIDEO_FWD:
+                        audio_skip = 4/MJPEG_DIV;
+                        audio_off = true;
+                        frame_skip += 4;
+                        video_off = false;
+                        break;
+                    case RGA_FUNC_VIDEO_REV:
+                    // TODO
+                        break;
+                    case RGA_FUNC_VIDEO_PLAY:
+                        audio_skip = 0;
+                        audio_off = false;
+                        frame_skip = MJPEG_DIV-1;
+                        video_off = false;
+                    default :
+                }
                 timer.start();
                 
                 // if device disconnected, try to connect again
@@ -461,12 +485,21 @@
                                 
                 // Read Next Video Frame
                 TestPin0 = 1;
-                for ( int i = 0; i < frame_skip; i++ ) {
+                if ( video_off != true ) {                
+                    for ( int i = 0; i < frame_skip; i++ ) {
+                        fread ( &framesize, sizeof(char), 4, vfp);
+                        fseek ( vfp, framesize, SEEK_CUR);
+                    }
                     fread ( &framesize, sizeof(char), 4, vfp);
-                    fseek ( vfp, framesize, SEEK_CUR);
+                    fread ( jpeg_frame_buffer2, sizeof(char), framesize, vfp);
+                } else {
+                    if ( vfp != NULL || afp != NULL ) {
+                        fclose(vfp);
+                        vfp = NULL;
+                        fclose(afp);
+                        afp = NULL;
+                    }
                 }
-                fread ( &framesize, sizeof(char), 4, vfp);
-                fread ( jpeg_frame_buffer2, sizeof(char), framesize, vfp);
                 TestPin0 = 0;
                 
                 // Read and play Next Audio Frame
@@ -484,19 +517,22 @@
                                    
                 /* Draw screen */
                 TestPin2 = 1;
-                Swap_FrameBuffer(frmbuf_info);
-                RGA_Func_VideoPlayer(frmbuf_info, jpeg_frame_buffer1, jpeg_frame_buffer2);
-                Update_LCD_Display(frmbuf_info);
+                if ( video_off != true ) {
+                    Swap_FrameBuffer(frmbuf_info);
+                    RGA_Func_VideoPlayer(frmbuf_info, jpeg_frame_buffer1, jpeg_frame_buffer2);
+                    Update_LCD_Display(frmbuf_info);
+                }
                 TestPin2 = 0;
                 buff_index++;
             
                 // Sync
                 TestPin3 = 1;
-                while( frame_period_ms > timer.read_ms());
+                while( frame_period_ms > timer.read_ms() && frame_skip < MJPEG_DIV );
                 timer.stop();
                 timer.reset();
                 TestPin3 = 0;               
-            }
+                
+            } // end of switch 
         }
         break;
         case RGA_FUNC_DISSOLVE: