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

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: benchresult.c 543 2006-01-07 22:06:24Z picard $
  18.  *
  19.  * The Core Pocket Media Player
  20.  * Copyright (c) 2004-2005 Gabor Kovacs
  21.  *
  22.  ****************************************************************************/
  23. #include "../common/common.h"
  24. #include "win.h"
  25. #include "benchresult.h"
  26. typedef struct benchresult
  27. {
  28. win Win;
  29. int64_t TimeDate;
  30. tchar_t Log[2048];
  31. } benchresult;
  32. static NOINLINE void AddLog(benchresult* p, int Class, int Id, const tchar_t* Buffer)
  33. {
  34. stcatprintf_s(p->Log,TSIZEOF(p->Log),T("%-30s %sn"),LangStrDef(Class,Id),Buffer);
  35. }
  36. static NOINLINE void AddItem(benchresult* p, winunit* y, int Id, const tchar_t* Buffer)
  37. {
  38. WinPropLabel(&p->Win,y,LangStr(BENCHRESULT_ID,Id),Buffer);
  39. AddLog(p,BENCHRESULT_ID,Id,Buffer);
  40. }
  41. static int Command(benchresult* p,int Cmd)
  42. {
  43. if (Cmd == BENCHRESULT_SAVE)
  44. {
  45. tchar_t URL[MAXPATH];
  46. tchar_t FileName[32];
  47. stprintf_s(FileName,TSIZEOF(FileName),T("bench_%06d_%06d"),(int)(p->TimeDate/1000000000),(int)((p->TimeDate/1000)%1000000));
  48. SaveDocument(FileName,p->Log,URL,TSIZEOF(URL));
  49. ShowMessage(LangStr(BENCHRESULT_ID,NODE_NAME),LangStr(BENCHRESULT_ID,BENCHRESULT_SAVED),URL);
  50. return ERR_NONE;
  51. }
  52. return ERR_INVALID_PARAM;
  53. }
  54. static int Init(benchresult* p)
  55. {
  56. node* Player = Context()->Player;
  57. node* Platform = Context()->Platform;
  58. node* Format;
  59. node* Input;
  60. node* VOutput;
  61. node* AOutput;
  62. winunit y;
  63. int i;
  64. int Frames;
  65. int Samples;
  66. int Bytes;
  67. tick_t Tick;
  68. tick_t OrigTick;
  69. point SizeSrc;
  70. point SizeDst;
  71. packetformat Video;
  72. packetformat Audio;
  73. tchar_t Buffer[256];
  74. fraction f;
  75. p->TimeDate = GetTimeDate();
  76. Player->Get(Player,PLAYER_FORMAT,&Format,sizeof(Format));
  77. Player->Get(Player,PLAYER_INPUT,&Input,sizeof(Input));
  78. VOutput = NULL;
  79. AOutput = NULL;
  80. OrigTick = 0;
  81. Frames = 0;
  82. Samples = 0;
  83. Bytes = 0;
  84. memset(&Video,0,sizeof(Video));
  85. memset(&Audio,0,sizeof(Audio));
  86. stprintf_s(p->Log,TSIZEOF(p->Log),LangStrDef(BENCHRESULT_ID,BENCHRESULT_LOG),Context()->ProgramName,Context()->ProgramVersion);
  87. tcscat_s(p->Log,TSIZEOF(p->Log),T("nn"));
  88. if (Format)
  89. {
  90. int No;
  91. pin Pin;
  92. packetformat PacketFormat;
  93. Format->Get(Format,FORMAT_FILEPOS,&Bytes,sizeof(Bytes));
  94. for (No=0;Format->Get(Format,FORMAT_STREAM+No,&Pin,sizeof(Pin))==ERR_NONE;++No)
  95. if (Pin.Node && Format->Get(Format,(FORMAT_STREAM+No)|PIN_FORMAT,&PacketFormat,sizeof(PacketFormat))==ERR_NONE)
  96. {
  97. if (PacketFormat.Type == PACKET_VIDEO) 
  98. {
  99. Video = PacketFormat;
  100. Player->Get(Player,PLAYER_VOUTPUT,&VOutput,sizeof(VOutput));
  101. if (VOutput)
  102. VOutput->Get(VOutput,OUT_TOTAL,&Frames,sizeof(Frames));
  103. }
  104. if (PacketFormat.Type == PACKET_AUDIO) 
  105. {
  106. Audio = PacketFormat;
  107. Player->Get(Player,PLAYER_AOUTPUT,&AOutput,sizeof(AOutput));
  108. if (AOutput)
  109. {
  110. packetformat Format;
  111. AOutput->Get(AOutput,OUT_TOTAL,&Samples,sizeof(Samples));
  112. if (AOutput->Get(AOutput,OUT_INPUT|PIN_FORMAT,&Format,sizeof(Format))==ERR_NONE &&
  113. Format.Type == PACKET_AUDIO)
  114. {
  115. if (Format.Format.Audio.Bits>=8)
  116. Samples /= Format.Format.Audio.Bits/8;
  117. if (!(Format.Format.Audio.Flags & PCM_PLANES) && Format.Format.Audio.Channels)
  118. Samples /= Format.Format.Audio.Channels;
  119. }
  120. }
  121. }
  122. }
  123. }
  124. y = 4;
  125. Player->Get(Player,PLAYER_BENCHMARK,&Tick,sizeof(Tick));
  126. if (Frames && Video.PacketRate.Num)
  127. OrigTick = Scale64(Frames,(int64_t)Video.PacketRate.Den*TICKSPERSEC,Video.PacketRate.Num);
  128. else
  129. if (Samples && Audio.Format.Audio.SampleRate)
  130. OrigTick = Scale(Samples,TICKSPERSEC,Audio.Format.Audio.SampleRate);
  131. if (Tick && OrigTick)
  132. {
  133. f.Num = OrigTick;
  134. f.Den = Tick;
  135. FractionToString(Buffer,TSIZEOF(Buffer),&f,1,2);
  136. AddItem(p,&y,BENCHRESULT_SPEED,Buffer);
  137. }
  138. if (Frames)
  139. {
  140. IntToString(Buffer,TSIZEOF(Buffer),Frames,0);
  141. AddItem(p,&y,BENCHRESULT_FRAMES,Buffer);
  142. }
  143. if (Samples)
  144. {
  145. IntToString(Buffer,TSIZEOF(Buffer),Samples,0);
  146. AddItem(p,&y,BENCHRESULT_SAMPLES,Buffer);
  147. }
  148. if (Bytes)
  149. {
  150. IntToString(Buffer,TSIZEOF(Buffer),Bytes/1024,0);
  151. tcscat_s(Buffer,TSIZEOF(Buffer),T(" KB"));
  152. AddItem(p,&y,BENCHRESULT_BYTES,Buffer);
  153. }
  154. y += 6;
  155. tcscat_s(p->Log,TSIZEOF(p->Log),T("n"));
  156. TickToString(Buffer,TSIZEOF(Buffer),Tick,0,1,0);
  157. AddItem(p,&y,BENCHRESULT_TIME,Buffer);
  158. if (Frames && Tick)
  159. {
  160. f.Num = Frames;
  161. f.Den = Tick;
  162. Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT);
  163. f.Num *= TICKSPERSEC;
  164. FractionToString(Buffer,TSIZEOF(Buffer),&f,0,2);
  165. AddItem(p,&y,BENCHRESULT_FPS,Buffer);
  166. }
  167. if (Samples && Tick)
  168. {
  169. f.Num = Samples;
  170. f.Den = Tick;
  171. Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT);
  172. f.Num *= TICKSPERSEC;
  173. FractionToString(Buffer,TSIZEOF(Buffer),&f,0,0);
  174. AddItem(p,&y,BENCHRESULT_SRATE,Buffer);
  175. }
  176. if (Bytes && Tick)
  177. {
  178. f.Num = Scale(Bytes,8,1000);
  179. f.Den = Tick;
  180. Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT);
  181. f.Num *= TICKSPERSEC;
  182. if (f.Den && (f.Num/f.Den) > 1000)
  183. {
  184. Simplify(&f,MAX_INT,MAX_INT/1024);
  185. f.Den *= 1000;
  186. FractionToString(Buffer,TSIZEOF(Buffer),&f,0,1);
  187. tcscat_s(Buffer,TSIZEOF(Buffer),T(" Mbit/s"));
  188. }
  189. else
  190. {
  191. FractionToString(Buffer,TSIZEOF(Buffer),&f,0,0);
  192. tcscat_s(Buffer,TSIZEOF(Buffer),T(" kbit/s"));
  193. }
  194. AddItem(p,&y,BENCHRESULT_BANDWIDTH,Buffer);
  195. }
  196. y += 6;
  197. tcscat_s(p->Log,TSIZEOF(p->Log),T("n"));
  198. if (OrigTick)
  199. {
  200. TickToString(Buffer,TSIZEOF(Buffer),OrigTick,0,1,0);
  201. AddItem(p,&y,BENCHRESULT_ORIG_TIME,Buffer);
  202. }
  203. if (Video.PacketRate.Num)
  204. {
  205. FractionToString(Buffer,TSIZEOF(Buffer),&Video.PacketRate,0,2);
  206. AddItem(p,&y,BENCHRESULT_ORIG_FPS,Buffer);
  207. }
  208. if (Audio.Format.Audio.SampleRate)
  209. {
  210. IntToString(Buffer,TSIZEOF(Buffer),Audio.Format.Audio.SampleRate,0);
  211. AddItem(p,&y,BENCHRESULT_ORIG_SRATE,Buffer);
  212. }
  213. if (Bytes && OrigTick)
  214. {
  215. f.Num = Scale(Bytes,8,1000);
  216. f.Den = OrigTick;
  217. Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT);
  218. f.Num *= TICKSPERSEC;
  219. if (f.Den && (f.Num/f.Den) > 1000)
  220. {
  221. f.Den *= 1000;
  222. FractionToString(Buffer,TSIZEOF(Buffer),&f,0,1);
  223. tcscat_s(Buffer,TSIZEOF(Buffer),T(" Mbit/s"));
  224. }
  225. else
  226. {
  227. FractionToString(Buffer,TSIZEOF(Buffer),&f,0,0);
  228. tcscat_s(Buffer,TSIZEOF(Buffer),T(" kbit/s"));
  229. }
  230. AddItem(p,&y,BENCHRESULT_ORIG_BANDWIDTH,Buffer);
  231. }
  232. if (Frames && Samples)
  233. {
  234. y += 9;
  235. WinLabel(&p->Win,&y,-1,-1,LangStr(BENCHRESULT_ID,BENCHRESULT_MSG),11,0,NULL);
  236. }
  237. tcscat_s(p->Log,TSIZEOF(p->Log),T("n"));
  238. if (Input && Input->Get(Input,STREAM_URL,Buffer,sizeof(Buffer))==ERR_NONE)
  239. AddLog(p,BENCHRESULT_ID,BENCHRESULT_URL,Buffer);
  240. if (Input && Input->Get(Input,STREAM_LENGTH,&i,sizeof(i))==ERR_NONE)
  241. {
  242. IntToString(Buffer,TSIZEOF(Buffer),i,0);
  243. AddLog(p,BENCHRESULT_ID,BENCHRESULT_FILESIZE,Buffer);
  244. }
  245. if (Platform)
  246. {
  247. if (Platform->Get(Platform,PLATFORM_TYPE,Buffer,sizeof(Buffer))==ERR_NONE)
  248. AddLog(p,PLATFORM_ID,PLATFORM_TYPE,Buffer);
  249. if (Platform->Get(Platform,PLATFORM_VERSION,Buffer,sizeof(Buffer))==ERR_NONE)
  250. AddLog(p,PLATFORM_ID,PLATFORM_VERSION,Buffer);
  251. if (Platform->Get(Platform,PLATFORM_OEMINFO,Buffer,sizeof(Buffer))==ERR_NONE)
  252. AddLog(p,PLATFORM_ID,PLATFORM_OEMINFO,Buffer);
  253. ThreadSleep(GetTimeFreq()/10);
  254. if (Platform->Get(Platform,PLATFORM_CPUMHZ,&i,sizeof(i))==ERR_NONE)
  255. {
  256. IntToString(Buffer,TSIZEOF(Buffer),i,0);
  257. tcscat_s(Buffer,TSIZEOF(Buffer),T(" Mhz"));
  258. AddLog(p,PLATFORM_ID,PLATFORM_CPUMHZ,Buffer);
  259. }
  260. }
  261. if (VOutput)
  262. {
  263. tcscpy_s(Buffer,TSIZEOF(Buffer),LangStrDef(VOutput->Class,NODE_NAME));
  264. if (VOutput->Get(VOutput,OUT_OUTPUT|PIN_FORMAT,&Video,sizeof(Video))==ERR_NONE)
  265. {
  266. if (Video.Format.Video.Direction & DIR_SWAPXY)
  267. SwapInt(&Video.Format.Video.Width,&Video.Format.Video.Height);
  268. stcatprintf_s(Buffer,TSIZEOF(Buffer),T(" %dx%d %dbits"),Video.Format.Video.Width,Video.Format.Video.Height,Video.Format.Video.Pixel.BitCount);
  269. }
  270. if (QueryAdvanced(ADVANCED_SLOW_VIDEO))
  271. tcscat_s(Buffer,TSIZEOF(Buffer),T(" Slow"));
  272. if (QueryAdvanced(ADVANCED_COLOR_LOOKUP))
  273. tcscat_s(Buffer,TSIZEOF(Buffer),T(" Lookup"));
  274. AddLog(p,PLAYER_ID,PLAYER_VOUTPUT,Buffer);
  275. }
  276. if (Player->Get(Player,PLAYER_BENCHMARK_SRC,&SizeSrc,sizeof(point))==ERR_NONE &&
  277. Player->Get(Player,PLAYER_BENCHMARK_DST,&SizeDst,sizeof(point))==ERR_NONE && 
  278. SizeSrc.x>0 && SizeSrc.y>0)
  279. {
  280. stprintf_s(Buffer,TSIZEOF(Buffer),T("%dx%d -> %dx%d"),SizeSrc.x,SizeSrc.y,SizeDst.x,SizeDst.y);
  281. AddLog(p,BENCHRESULT_ID,BENCHRESULT_ZOOM,Buffer);
  282. }
  283. if (AOutput)
  284. {
  285. tcscpy_s(Buffer,TSIZEOF(Buffer),LangStrDef(AOutput->Class,NODE_NAME));
  286. if (AOutput->Get(AOutput,OUT_OUTPUT|PIN_FORMAT,&Audio,sizeof(Audio))==ERR_NONE)
  287. stcatprintf_s(Buffer,TSIZEOF(Buffer),T(" %dHz %dBits %dCh."),Audio.Format.Audio.SampleRate,Audio.Format.Audio.Bits,Audio.Format.Audio.Channels);
  288. AddLog(p,PLAYER_ID,PLAYER_AOUTPUT,Buffer);
  289. }
  290. return ERR_NONE;
  291. }
  292. static const menudef MenuDef[] =
  293. {
  294. { 0, PLATFORM_ID, PLATFORM_DONE, },
  295. { 0, BENCHRESULT_ID, BENCHRESULT_SAVE, },
  296. MENUDEF_END
  297. };
  298. WINCREATE(BenchResult)
  299. static int Create(benchresult* p)
  300. {
  301. BenchResultCreate(&p->Win);
  302. p->Win.WinWidth = 180;
  303. p->Win.WinHeight = 240;
  304. p->Win.Flags |= WIN_DIALOG|WIN_NOTABSTOP;
  305. p->Win.MenuDef = MenuDef;
  306. p->Win.Init = (nodefunc)Init;
  307. p->Win.Command = (wincommand)Command;
  308. p->Win.LabelWidth = min(88,p->Win.ScreenWidth-45);
  309. return ERR_NONE;
  310. }
  311. static const nodedef BenchResult = 
  312. {
  313. sizeof(benchresult),
  314. BENCHRESULT_ID,
  315. WIN_CLASS,
  316. PRI_DEFAULT,
  317. (nodecreate)Create,
  318. };
  319. void BenchResult_Init()
  320. {
  321. NodeRegisterClass(&BenchResult);
  322. }
  323. void BenchResult_Done()
  324. {
  325. NodeUnRegisterClass(BENCHRESULT_ID);
  326. }