⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mediaplayer.c

📁 BREW SDK 3.1。BREW应用程序的开发包。
💻 C
📖 第 1 页 / 共 5 页
字号:
/*===========================================================================

FILE: MediaPlayer.c

SERVICES: Sample Media Player applet showing usage of BREW IMedia interfaces.

DESCRIPTION
  This file contains the implementation of a MediaPlayer applet using the
  AEE IMedia interface services.
  MediaPlayer app
  (1) Plays MIDI, MP3, QCP and PMD media formats
  (2) Records QCP file
  (3) Displays BMP, BCI, PNG and JPEG image formats
  (4) Provides playback/record controls: stop, rewind, ff, pause, resume.
  (5) Allows image panning for images
  (6) Provides volume controls
  (7) Can display images/video in Full Screen mode
  (8) Can be started either in stand-alone mode or as a plugin

  Demonstrates usage of
  (1) IMedia API
  (2) AEEMediaUtil_CreateMedia()
  (3) IImageCtl
 
   	   Copyright ?2000-2002 QUALCOMM Incorporated.
	                  All Rights Reserved.
                   QUALCOMM Proprietary/GTDR

===========================================================================*/

/*===============================================================================
                     INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEAppGen.h"	      // AEEApplet structure and Applet services
#include "mediaplayer.bid"
#include "mediaplayer.brh"

// AEE Services used by app
#include "AEEStdLib.h"        // AEE Stb Lib Services
#include "AEEMenu.h"          // AEE Menu Services
#include "AEEFile.h"          // AEE File Manager Services
#include "AEEMedia.h"         // AEE Multimedia Services
#include "AEEImageCtl.h"      // AEE ImageCtl Services
#include "AEEMimeTypes.h"     // AEE MIME definitions

#include "AEEMediaUtil.h"     // AEE Media Utility functions
#include "nmdef.h"

/*===========================================================================
                      INTERFACE DEFINITION
===========================================================================*/
//
// This is a generic IWindow interface.
//
typedef struct _IWindow  IWindow;
QINTERFACE(IWindow)
{
   // Enables/Disables the window. Window controls will not process
   // events if the window is disabled.
   void     (*Enable)(IWindow * po, boolean bEnable);

   // Redraws the window if enabled
   void     (*Redraw)(IWindow * po);

   // Handles the events routed to the window
   boolean  (*HandleEvent)(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam);

   // Releases the window resources
   void     (*Delete)(IWindow * po);
};

#define IWINDOW_Enable(p)                 GET_PVTBL(p, IWindow)->Enable(p, TRUE)
#define IWINDOW_Disable(p)                GET_PVTBL(p, IWindow)->Enable(p, FALSE)
#define IWINDOW_Redraw(p)                 GET_PVTBL(p, IWindow)->Redraw(p)
#define IWINDOW_HandleEvent(p, e, w, dw)  GET_PVTBL(p, IWindow)->HandleEvent(p, e, w, dw)
#define IWINDOW_Delete(p)                 GET_PVTBL(p, IWindow)->Delete(p)

/*===============================================================================
                     MACROS
=============================================================================== */
#define MP_IWINDOW_SETVTBL(pVtbl, pfnEn, pfnRd, pfnHE, pfnDel) \
   (pVtbl)->Enable      = (pfnEn); \
   (pVtbl)->Redraw      = (pfnRd); \
   (pVtbl)->HandleEvent = (pfnHE); \
   (pVtbl)->Delete      = (pfnDel)

#define MP_RELEASEIF(p)                MP_FreeIF((IBase **)&(p))
#define MP_RELEASEWIN(p)               MP_FreeWin((IWindow **)&(p))
#define MP_WINERR_RETURN(p)            { MP_RELEASEWIN(p); return NULL; }

#define MP_ISPLUGIN(p)                 ((p)->m_pOwner->m_bPlugin)

#define MP_DRAWHEADER(pme)             MP_DrawImage((pme)->m_pOwner->m_pHdrImage, &(pme)->m_pOwner->m_rectHdr, TRUE)

#define MP_ISEVTKEY(e)                 ((e) == EVT_KEY)
#define MP_ISCLR(e)                    (MP_ISEVTKEY(e) && wParam == AVK_CLR)
#define MP_ISEVTCMD(e)                 ((e) == EVT_COMMAND)
#define MP_ISCMD(e, c)                 (MP_ISEVTCMD(e) && (c) == wParam)
#define MP_ISFULLSCRN(p)               ((p)->m_bImage && (p)->m_bFullScreen)

#define CMediaPlayer_CancelRedraw(p)   { CALLBACK_Cancel(&(p)->m_cbRedraw); (p)->m_bRedraw = FALSE; }
#define CMediaPlayer_DisableWin(p)     { IWINDOW_Disable((p)->m_pWin); CMediaPlayer_CancelRedraw(p); }

#define CPlayerWin_IsImage(p)          ((p)->m_eWin == MPPW_IMAGE)
#define CPlayerWin_IsMedia(p)          ((p)->m_eWin == MPPW_PLAY || (p)->m_eWin == MPPW_RECORD)

/*===========================================================================
                      PUBLIC DATA DECLARATIONS
===========================================================================*/

/*-------------------------------------------------------------------
            Defines
-------------------------------------------------------------------*/
#define MP_SPLASH_TIMER       750

#define MP_MAX_STRLEN         64
#define MP_MAX_FILES          32
#define MP_MEDIA_DIR          "media"
#define MP_QCP_REC_FILE       "sample.qcp"
#define MP_EXT_SEPARATOR      ", "

#define MP_VOLUME_STEP        25
#define MP_SEEK_TIME          10000    // 10 seconds
#define MP_PROG_TIMER         2000

#define MP_HEADER_CY          16 
#define MP_ICONVIEWCTL_CY     20

#define MP_PROGBAR_DX_DIV     3     // dx is dx/3 of main rectangle
#define MP_PROGBAR_DY_DIV     2     // dy is dy/2 of main rectangle
#define MP_PROGBAR_DX_OFFSET  4     // dx is reduced by offset
#define MP_CLR_PROG_FILL      MAKE_RGB(0, 128, 192)

#define EVT_CREATEMEDIA       EVT_USER
#define EVT_CREATEMEDIA_QCP   EVT_USER + 1

// Based on Menu style sheet:
#define MENU8_FT                 AEE_FT_NONE
#define MENU8_SELECT_FT          AEE_FT_RAISED
#define MENU8_RO                 AEE_RO_TRANSPARENT
#define MENU8_SELECT_RO          AEE_RO_TRANSPARENT
#define MENU8_COLOR_MASK 	      (MC_BACK | MC_SEL_BACK | MC_SEL_TEXT)
#define MENU8_BACKGROUND	      MAKE_RGB(255,255,204)
#define MENU8_SELECT_BACKGROUND	MAKE_RGB(153, 204, 204)
#define MENU8_SELECT_TEXT	      RGB_BLACK

#define TB8_BACKGROUND	         MAKE_RGB(192,192,192)
#define TB8_SELECT_BACKGROUND	   MAKE_RGB(192, 192, 192)

/*-------------------------------------------------------------------
            Type Declarations
-------------------------------------------------------------------*/
typedef enum MPWindow
{
   MPW_NONE,
   MPW_MAIN,
   MPW_FILELIST,
   MPW_PLAYER,
#if defined(MEDIAPLAYER_SETTINGS)
   MPW_SETTINGS,
#endif // defined(MEDIAPLAYER_SETTINGS)
   MPW_LAST
} MPWindow;

typedef enum MPPlayerWin
{
   MPPW_PLAY,
   MPPW_RECORD,
   MPPW_IMAGE
} MPPlayerWin;

typedef struct CMediaPlayer   CMediaPlayer;
typedef struct CWindow        CWindow;
typedef struct CMainWin       CMainWin;
typedef struct CFileListWin   CFileListWin;
typedef struct CPlayerWin     CPlayerWin;
typedef struct CProgCtl       CProgCtl;

#define INHERIT_CWindow(iname) \
   DECLARE_VTBL(iname) \
   CMediaPlayer * m_pOwner; \
   IShell *       m_pIShell; \
   IDisplay *     m_pIDisplay; \
   flg            m_bActive:1

// Base class of all IWindow objects.
struct CWindow
{
   INHERIT_CWindow(IWindow);
};

// Main window: Displays main menu.
struct CMainWin
{
   INHERIT_CWindow(IWindow);

   IImage *       m_pLogo;
   AEERect        m_rectLogo;
   IMenuCtl *     m_pMainMenu;
   flg            m_bAbout:1;
};

// File list window: Lists files in media dir for selection.
struct CFileListWin
{
   INHERIT_CWindow(IWindow);

   IMenuCtl *     m_pFileMenu;
   char *         m_szFileArray[MP_MAX_FILES];
   int            m_NumFiles; // Number of files read into m_szFileArray
};

// Progress control: includes progress bar and the title
struct CProgCtl
{
   IShell *          m_pIShell;
   IDisplay *        m_pIDisplay;
   IStatic *         m_pTitle;
   AEERect           m_rectMain;
   AEERect           m_rectBar;
};

// Player window: Plays the media.
struct CPlayerWin
{
   INHERIT_CWindow(IWindow);

   MPPlayerWin       m_eWin;           // Window type

   IStatic *         m_pTitle;         // Media title text
   AECHAR            m_szText[MP_MAX_STRLEN];

   IImage *          m_pIdleImage;     // Image rect placeholder
   AEERect           m_rectImage;      // Image/Video rectangle
   AEERect           m_rectImageCopy;  // Saved Image/Video rectangle when full screen is displayed

   char *            m_pszFile;        // Saved file name alloc'd by CMediaPlayer

   CProgCtl          m_ProgCtl;        // ProgCtl
   uint16            m_wPct;

   IMenuCtl *        m_pPlayerMenu;

   AEEMediaData      m_md;             // Media data
   IMedia *          m_pMedia;         // IMedia-based object

   IImageCtl *       m_pImageCtl;      // ImageCtl displaying the selected image
   IImage *          m_pImage;         // Image contained in ImageCtl

   uint32            m_dwTotalTime;    // Total playback time
   uint32            m_dwPlayPos;      // Current playback pos
   uint16            m_wVolume;        // Volume

   flg               m_bPlayRec:1;     // = TRUE, if Playback progress flag
   flg               m_bImage:1;       // = TRUE, if media contains Video/Image component.
   flg               m_bFullScreen:1;  // = TRUE, if Video/Image is displayed full screen
   flg               m_bProgTimer:1;   // = TRUE, if prog timer is running. Regular display is not updated.
};

//
// MediaPlayer app global structure.
// Note: m_bPlugin == TRUE indicates that MediaPlayer tries to 
// play the file directly in CPlayerWin. Pressing CLR will close
// the app.
//
struct CMediaPlayer
{
   AEEApplet         a;

	int               m_cxWidth;
	int               m_cyHeight;
   uint16            m_nColorDepth;
   int               m_nNChSize;    // Large char size
   int               m_nLChSize;    // Normal char size

   IImage *          m_pHdrImage;
   AEERect           m_rectHdr;

   MPWindow          m_eActiveWin;  // Active window
   MPWindow          m_eSuspendWin; // Suspended window
   IWindow *         m_pWin;

   uint16            m_wMainWin;    // CurSel of CMainWin
   uint16            m_wFileListWin;// CurSel of CFileListWin

   char *            m_pszAudioExt; // Registered audio extension string: "mid, mp3, ..."
   char *            m_pszVideoExt; // Registered video extension string: "pmd, ..."
   char *            m_pszImageExt; // Registered image extension string: "bmp, png, ..."

   AEECallback       m_cbRedraw;
   flg               m_bRedraw:1;   // Processing redraw

   flg               m_bPlugin:1;   // = TRUE, if MediaPlayer is in Plugin mode.
};

/*-------------------------------------------------------------------
            Function Prototypes
-------------------------------------------------------------------*/
static boolean    CMediaPlayer_InitAppData(IApplet* po);
static boolean    CMediaPlayer_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam);
static void       CMediaPlayer_DrawSplash(CMediaPlayer * pme);
static boolean    CMediaPlayer_SetWindow(CMediaPlayer * pme, MPWindow eWin, uint32 dwParam);
static void       CMediaPlayer_Redraw(CMediaPlayer * pme, boolean bDefer);
static void       CMediaPlayer_RedrawNotify(CMediaPlayer * pme);
static void       CMediaPlayer_PlayFile(CMediaPlayer * pme, const char * pszFile);
static void       CMediaPlayer_RecordQCPFile(CMediaPlayer * pme, const char * pszFile);
static boolean    CMediaPlayer_PlayImage(CMediaPlayer * pme, const char * pszFile);
static uint16     CMediaPlayer_FindHandlerType(CMediaPlayer * pme, const char * pszFile);
static uint16     CMediaPlayer_IsExtension(CMediaPlayer * pme, const char * pszFile, char * pszExt, int nExtLen);

// CWindow abstract window
static IWindow *  CWindow_New(int16 nSize, CMediaPlayer * pOwner, VTBL(IWindow) * pvt);
static boolean    CWindow_ProcessEnable(IWindow * po, boolean bEnable);

// Main window
static IWindow *  CMainWin_New(CMediaPlayer * pOwner);
static void       CMainWin_Delete(IWindow * po);
static void       CMainWin_Enable(IWindow * po, boolean bEnable);
static void       CMainWin_Redraw(IWindow * po);
static boolean    CMainWin_HandleEvent(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam);

static void       CMainWin_About(CMainWin * pme);

// File List window
static IWindow *  CFileListWin_New(CMediaPlayer * pOwner);
static void       CFileListWin_Delete(IWindow * po);
static void       CFileListWin_Enable(IWindow * po, boolean bEnable);
static void       CFileListWin_Redraw(IWindow * po);
static boolean    CFileListWin_HandleEvent(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam);

// Player window
static IWindow *  CPlayerWin_New(CMediaPlayer * pOwner, MPPlayerWin eWin);
static void       CPlayerWin_Delete(IWindow * po);
static void       CPlayerWin_Enable(IWindow * po, boolean bEnable);
static void       CPlayerWin_Redraw(IWindow * po);
static boolean    CPlayerWin_HandleEvent(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam);

static void       CPlayerWin_MediaNotify(void * pUser, AEEMediaCmdNotify * pCmdNotify);
static void       CPlayerWin_ImageNotify(void * pUser, IImage * pImage, AEEImageInfo * pi, int nErr);
static void       CPlayerWin_UpdateProgCtl(CPlayerWin * pme, int nCmd, int nSubCmd, uint16 wResID);
static boolean    CPlayerWin_IsPause(CPlayerWin * pme);
static void       CPlayerWin_ProgTimerNotify(CPlayerWin * pme);
static boolean    CPlayerWin_SetMediaData(CPlayerWin * pme, AEEMediaData *pmd);
static boolean    CPlayerWin_FullScreen(CPlayerWin * pme, boolean bFull, boolean bDeferRedraw);

// ProgCtl
static boolean    CProgCtl_Init(CProgCtl * pme, AEERect * pRectMain);
static void       CProgCtl_SetPos(CProgCtl * pme, AECHAR * psz, uint16 wPct);
static void       CProgCtl_Release(CProgCtl * pme);
static void       CProgCtl_DrawHist(CProgCtl * pme, uint16 wPct);

// Helper Functions
static void       MP_DrawImage(IImage * pImage, AEERect * pRect, boolean bCenter);
static boolean    MP_AddMenuItem(IMenuCtl * pMenu, uint16 wTextID, AECHAR * pText, uint16 wImageID, uint16 wItemID, uint32 dwData);
static void       MP_ErrorDlg(CMediaPlayer * pme, uint16 wResErrID);
static char *     MP_GetFileName(const char * psz);
static void       MP_FrameRect(IDisplay * pd, AEERect * pRect);
static void       MP_FitStaticText(IDisplay * pd, IStatic * ps, AEEFont font, AECHAR * pszText);
static void       MP_SetMenuAttr(IMenuCtl * pMenu, AEECLSID clsMenu, uint16 nColorDepth, AEERect * pRect, uint32 dwProps);
static void       MP_FreeIF(IBase ** ppif);
static void       MP_FreeWin(IWindow ** ppif);
static boolean    MP_AddExtension(char ** ppszExtList, char * psz);

/*-------------------------------------------------------------------
            Global Constant Definitions
-------------------------------------------------------------------*/

/*-------------------------------------------------------------------
            Global Data Definitions
-------------------------------------------------------------------*/

/*-------------------------------------------------------------------
            Static variable Definitions
-------------------------------------------------------------------*/

//
// MediaPlayer app can either be statically built into BREW or dynamically linked during run-time.
// If AEE_STATIC is defined, then MediaPlayer app will be a static app.
// NOTE: Static apps can be built only by OEMs or Carriers. App developers can build dynamic apps only.
//
#if defined(AEE_STATIC)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -