External MOVIE (Sample)
GUI_MOVIE_CreateMovieEx.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | GUI_MOVIE_CreateMovieEx.zip |
This sample demonstrates how to display an emWin movie from external memory. It supports both the usage of Windows file system and emFile.
Code
/*********************************************************************
* SEGGER Microcontroller GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2020 SEGGER Microcontroller GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : GUI_MOVIE_CreateMovieEx.c
Purpose : Sample that demonstrates how to play an emWin movie
file from extern memory.
This sample supports both usage in the Windows
Simulation as well as usage on a target device using
emFile.
Requirements: WindowManager - ( )
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#else
#include "FS.h"
#endif
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#ifdef WIN32
#define FILE_PATH "C:\\Work\\emWin\\Intern\\TutorialV6\\Movies\\Video.emf"
#else
#define FILE_PATH "Video.emf"
#endif
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static int _TimeStart;
static int _TimeEnd;
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _GetData
*
* Function description
* Reading data directly from file system
*/
int _GetData(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off) {
U32 NumBytesRead;
#ifdef WIN32
HANDLE hFile;
hFile = *(HANDLE *)p;
SetFilePointer(hFile, Off, 0, FILE_BEGIN);
ReadFile(hFile, (U8 *)*ppData, NumBytes, &NumBytesRead, NULL);
#else
FS_FILE * pFile;
pFile = (FS_FILE *)p;
FS_SetFilePos(pFile, Off, FS_FILE_BEGIN);
NumBytesRead = FS_Read(pFile, (U8 *)*ppData, NumBytes);
#endif
return NumBytesRead;
}
/*********************************************************************
*
* _cbNotify
*
* Function description
* Uses multiple buffering (if available) to avoid tearing effects.
*/
static void _cbNotify(GUI_HMEM hMovie, int Notification, U32 CurrentFrame) {
char acBuffer[32];
int TimeD;
int Fps;
GUI_USE_PARA(hMovie);
GUI_USE_PARA(CurrentFrame);
switch (Notification) {
case GUI_MOVIE_NOTIFICATION_PREDRAW:
//
// Begin multi-buffering if available.
//
GUI_MULTIBUF_Begin();
//
// Cache is used instead if there is no multi-buffering.
//
LCD_ControlCache(LCD_CC_LOCK);
_TimeStart = GUI_GetTime();
break;
case GUI_MOVIE_NOTIFICATION_POSTDRAW:
//
// Calculate and show FPS.
//
_TimeEnd = GUI_GetTime();
TimeD = (_TimeEnd - _TimeStart) ? _TimeEnd - _TimeStart : 1;
Fps = (1000 / TimeD);
if (Fps > 30) {
sprintf(acBuffer, "FPS: max.");
} else {
sprintf(acBuffer, "FPS: %d", Fps);
}
GUI_DispStringAt(acBuffer, 0, 0);
//
// End multi-buffering / cache.
//
LCD_ControlCache(LCD_CC_UNLOCK);
GUI_MULTIBUF_End();
break;
case GUI_MOVIE_NOTIFICATION_START:
break;
case GUI_MOVIE_NOTIFICATION_STOP:
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
GUI_MOVIE_HANDLE hMovie;
GUI_MOVIE_INFO Info;
#ifdef WIN32
HANDLE hFile;
#define PARAM &hFile
#else
FS_FILE * pFile;
const char acVolumeName[64];
#define PARAM pFile
#endif
//
// Init emWin.
//
GUI_Init();
#ifdef WIN32
hFile = CreateFile(FILE_PATH, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
#else
//
// Start emFile.
//
FS_Init();
//
// Enable long file name support.
//
FS_FAT_SupportLFN();
//
// Mount volume.
//
FS_GetVolumeName(0, acVolumeName, sizeof(acVolumeName));
if (FS_Mount(acVolumeName) > 0) {
//
// Open file.
//
pFile = FS_FOpen(FILE_PATH, "r");
}
#endif
//
// Get info about movie.
//
if(GUI_MOVIE_GetInfoEx(_GetData, PARAM, &Info) == 0) {
//
// Create movie handle and show it in an endless loop.
//
hMovie = GUI_MOVIE_CreateEx(_GetData, PARAM, _cbNotify);
if (hMovie) {
GUI_MOVIE_Show(hMovie, 0, 0, 1);
}
}
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/