sample_win32.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:6k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*****************************************************************************
  2.  *
  3.  * This program is free software ; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2 of the License, or
  6.  * (at your option) any later version.
  7.  *
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11.  * GNU General Public License for more details.
  12.  *
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this program; if not, write to the Free Software
  15.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  16.  *
  17.  * $Id: sample_win32.c 548 2006-01-08 22:41:57Z picard $
  18.  *
  19.  * The Core Pocket Media Player
  20.  * Copyright (c) 2004-2005 Gabor Kovacs
  21.  *
  22.  ****************************************************************************/
  23. #include "../common/common.h"
  24. #include "../interface/win.h"
  25. #include "../interface/benchresult.h"
  26. #include "dumpoutput.h"
  27. const tchar_t URL[] = T("c:\sample.avi");
  28. //const tchar_t URL[] = T("F:\samples\h264.ref\HCMP1_HHI_A.264");
  29. //#define LOADALL FOURCC('F','M','T','_')
  30. //#define TIMELIMIT TICKSPERSEC*5
  31. #define BENCHMARK
  32. //#define FULLSCREEN
  33. static bool_t Play;
  34. static void EnumDir(const tchar_t* Path,const tchar_t* Exts)
  35. {
  36. streamdir DirItem;
  37. stream* Stream = GetStream(Path,1);
  38. if (Stream)
  39. {
  40. int Result = Stream->EnumDir(Stream,Path,Exts,1,&DirItem);
  41. while (Result == ERR_NONE)
  42. {
  43. tchar_t FullPath[MAXPATH];
  44. AbsPath(FullPath,TSIZEOF(FullPath),DirItem.FileName,Path);
  45. if (DirItem.Size < 0)
  46. EnumDir(FullPath,Exts);
  47. else
  48. if (DirItem.Type == FTYPE_AUDIO || DirItem.Type == FTYPE_VIDEO)
  49. {
  50. int n;
  51. node* Player = Context()->Player;
  52. Player->Get(Player,PLAYER_LIST_COUNT,&n,sizeof(n));
  53. Player->Set(Player,PLAYER_LIST_URL+n,FullPath,sizeof(FullPath));
  54. }
  55. Result = Stream->EnumDir(Stream,NULL,NULL,0,&DirItem);
  56. }
  57. NodeDelete((node*)Stream);
  58. }
  59. }
  60. int SilentError(void* p,int Param,int Param2)
  61. {
  62. DebugMessage((const tchar_t*)Param2);
  63. return ERR_NONE;
  64. }
  65. int PlayerNotify(node* Player,int Param,int Param2)
  66. {
  67. if (Param == PLAYER_BENCHMARK)
  68. {
  69. node* p;
  70. bool_t Bool = 0;
  71. Player->Set(Player,PLAYER_FULLSCREEN,&Bool,sizeof(Bool));
  72. p = NodeCreate(BENCHRESULT_ID);
  73. if (p) ((win*)p)->Popup((win*)p,NULL);
  74. NodeDelete(p);
  75. }
  76. if (Param == PLAYER_PLAY)
  77. Play = Param2;
  78. if (Param == PLAYER_PERCENT)
  79. {
  80. #ifdef TIMELIMIT
  81. tick_t Pos;
  82. if (Player->Get(Player,PLAYER_POSITION,&Pos,sizeof(Pos))==ERR_NONE && Pos>TIMELIMIT)
  83. {
  84. int a,b;
  85. Player->Get(Player,PLAYER_LIST_CURRENT,&a,sizeof(a));
  86. Player->Get(Player,PLAYER_LIST_COUNT,&b,sizeof(b));
  87. if (a==b-1) 
  88. Play = 0;
  89. else
  90. Player->Set(Player,PLAYER_NEXT,NULL,0);
  91. }
  92. #endif
  93. }
  94. return ERR_NONE;
  95. }
  96. void Main()
  97. {
  98. int Int;
  99. notify Notify;
  100. bool_t Bool;
  101. node* Player = Context()->Player;
  102. DumpOutput_Init();
  103. Int = 0;//NULLAUDIO_ID;
  104. Player->Set(Player,PLAYER_AOUTPUTID,&Int,sizeof(Int));
  105. //Int = DUMPVIDEO_ID;
  106. //Player->Set(Player,PLAYER_VOUTPUTID,&Int,sizeof(Int));
  107. Notify.Func = PlayerNotify;
  108. Notify.This = Player;
  109. Player->Set(Player,PLAYER_NOTIFY,&Notify,sizeof(Notify));
  110. // empty saved playlist
  111. Int = 0;
  112. Player->Set(Player,PLAYER_LIST_COUNT,&Int,sizeof(Int));
  113. // turn off repeat
  114. Bool = 0;
  115. Player->Set(Player,PLAYER_REPEAT,&Bool,sizeof(Bool));
  116. Context_Wnd((void*)1); //fake window handle
  117. #if defined(TARGET_WIN32) && !defined(TARGET_WINCE) && !defined(FULLSCREEN)
  118. {
  119. rect Rect;
  120. Rect.x = 600;
  121. Rect.y = 40;
  122. Rect.Width = 320;
  123. Rect.Height = 240;
  124. Player->Set(Player,PLAYER_SKIN_VIEWPORT,&Rect,sizeof(Rect));
  125. }
  126. #else
  127. Bool = 1;
  128. Player->Set(Player,PLAYER_FULLSCREEN,&Bool,sizeof(Bool));
  129. #endif
  130. #ifdef LOADALL
  131. {
  132. int ExtsLen = 1024;
  133. tchar_t* Exts = malloc(ExtsLen*sizeof(tchar_t));
  134. if (Exts)
  135. {
  136. int* i;
  137. array List;
  138. Exts[0]=0;
  139. NodeEnumClass(&List,LOADALL);
  140. for (i=ARRAYBEGIN(List,int);i!=ARRAYEND(List,int);++i)
  141. {
  142. const tchar_t* s = LangStr(*i,NODE_EXTS);
  143. if (s[0])
  144. {
  145. if (Exts[0]) tcscat_s(Exts,ExtsLen,T(";"));
  146. tcscat_s(Exts,ExtsLen,s);
  147. }
  148. }
  149. ArrayClear(&List);
  150. EnumDir(T("d:\samples"),Exts);
  151. free(Exts);
  152. }
  153. Context()->Error.Func = SilentError;
  154. }
  155. #else
  156. Player->Set(Player,PLAYER_LIST_URL+0,URL,sizeof(URL));
  157. #endif
  158. Int = 0;
  159. Player->Set(Player,PLAYER_LIST_CURRIDX,&Int,sizeof(Int));
  160. ((player*)Player)->Paint(Player,NULL,0,0);
  161. #ifdef BENCHMARK
  162. Bool = 1;
  163. Context()->Advanced->Set(Context()->Advanced,ADVANCED_BENCHFROMPOS,&Bool,sizeof(Bool));
  164. Int = 0;
  165. Player->Set(Player,PLAYER_BENCHMARK,&Int,sizeof(Int));
  166. #else
  167. Bool = 1;
  168. Player->Set(Player,PLAYER_PLAY,&Bool,sizeof(Bool));
  169. #endif
  170. Play = 1;
  171. while (Play)
  172. {
  173. #ifndef MULTITHREAD
  174. if (((player*)Player)->Process(Player) == ERR_BUFFER_FULL)
  175. ThreadSleep(GetTimeFreq()/250);
  176. #else
  177. ThreadSleep(GetTimeFreq()/10);
  178. #endif
  179. }
  180. Context_Wnd(NULL);
  181. DumpOutput_Done();
  182. }
  183. #include <windows.h>
  184. #if !defined(TARGET_WINCE) && defined(UNICODE)
  185. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hParent,LPSTR CmdA,int CmdShow)
  186. {
  187. WCHAR Cmd[MAXCMD];
  188. mbstowcs(Cmd,CmdA,sizeof(Cmd)/sizeof(WCHAR)); //!!!
  189. #else
  190. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hParent,TCHAR* Cmd,int CmdShow)
  191. {
  192. #endif
  193. #ifndef NDEBUG
  194. DLLTest(); // just to help debugging plugins. comment out if not needed
  195. //DLLTest2(); // just to help debugging plugins. comment out if not needed
  196. #endif
  197. if (Context_Init("sample","sample",3,Cmd,NULL))
  198. {
  199. Main();
  200. Context_Done();
  201. }
  202. }