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

Windows CE

开发平台:

C/C++

  1. /*****************************************************************************  *  * This program is free software ; you can redistribute it and/or modify  * it under the terms of the GNU General Public License as published by  * the Free Software Foundation; either version 2 of the License, or  * (at your option) any later version.  *  * This program is distributed in the hope that it will be useful,  * but WITHOUT ANY WARRANTY; without even the implied warranty of  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  * GNU General Public License for more details.  *  * You should have received a copy of the GNU General Public License  * along with this program; if not, write to the Free Software  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *  * $Id: mediainfo.c 543 2006-01-07 22:06:24Z picard $  *  * The Core Pocket Media Player  * Copyright (c) 2004-2005 Gabor Kovacs  *  ****************************************************************************/ #include "../common/common.h"
  2. #include "win.h"
  3. #include "mediainfo.h"
  4. static int CommentNo[] = { COMMENT_TITLE, COMMENT_ARTIST, COMMENT_AUTHOR, COMMENT_TRACK, COMMENT_ALBUM, COMMENT_YEAR, 
  5.    COMMENT_GENRE, COMMENT_COPYRIGHT, COMMENT_COMMENT, 0, COMMENT_LANGUAGE, 0 };
  6. static void Comment(win* Win,player* Player,winunit* y,int Stream) { tchar_t s[256]; int i; for (i=0;CommentNo[i];++i) if (Player->CommentByName(Player,Stream,PlayerComment(CommentNo[i]),s,TSIZEOF(s))) { if (Stream>=0 && Player->CommentByName(Player,-1,PlayerComment(CommentNo[i]),NULL,0)) continue; WinPropLabel(Win,y,LangStr(PLAYER_ID,CommentNo[i]),s); } if (Stream>=0) for (++i;CommentNo[i];++i) if (Player->CommentByName(Player,Stream,PlayerComment(CommentNo[i]),s,TSIZEOF(s))) WinPropLabel(Win,y,LangStr(PLAYER_ID,CommentNo[i]),s); } static void Info(win* Win,node* Node,winunit* y,int Name) { int No; datadef DataDef; if (Name) WinPropLabel(Win,y,LangStr(MEDIAINFO_ID,Name),LangStr(Node->Class,NODE_NAME)); for (No=0;NodeEnum(Node,No,&DataDef)==ERR_NONE;++No) if (!(DataDef.Flags & (DF_OUTPUT|DF_HIDDEN))) { tchar_t s[256]; tick_t Tick; int i; bool_t Ok = 0; switch (DataDef.Type) { case TYPE_TICK: Ok = Node->Get(Node,DataDef.No,&Tick,sizeof(Tick))==ERR_NONE; TickToString(s,TSIZEOF(s),Tick,0,1,0); break; case TYPE_INT: Ok = Node->Get(Node,DataDef.No,&i,sizeof(i))==ERR_NONE; IntToString(s,TSIZEOF(s),i,(DataDef.Flags & DF_HEX)!=0); if (DataDef.Flags & DF_KBYTE) tcscat_s(s,TSIZEOF(s),T(" KB")); break; case TYPE_STRING: Ok = Node->Get(Node,DataDef.No,s,sizeof(s))==ERR_NONE; break; } if (Ok) WinPropLabel(Win,y,DataDef.Name,s); } } static int Init(win* p)
  7. {
  8. tchar_t s[256];
  9. packetformat Format;
  10. int No;
  11. node* VOutput = NULL;
  12. node* Reader = NULL;
  13. node* Input = NULL;
  14. node* Player = Context()->Player;
  15. winunit y;
  16. Player->Get(Player,PLAYER_FORMAT,&Reader,sizeof(Reader)); Player->Get(Player,PLAYER_INPUT,&Input,sizeof(Input)); Player->Get(Player,PLAYER_VOUTPUT,&VOutput,sizeof(VOutput));
  17. y = 4; if (Input) Info(p,Input,&y,0); if (Reader) { pin Pin; Info(p,Reader,&y,MEDIAINFO_FORMAT); Comment(p,(player*)Player,&y,-1); for (No=0;Reader->Get(Reader,FORMAT_STREAM+No,&Pin,sizeof(Pin))==ERR_NONE;++No) if (PlayerGetStream((player*)Player,No,&Format,NULL,0,NULL))
  18. { y += 6;
  19. if (Format.Type != PACKET_NONE)
  20. {
  21. if (!PacketFormatName(&Format,s,TSIZEOF(s))) s[0] =0;
  22. WinPropLabel(p,&y,LangStr(PLAYER_ID,STREAM_NAME+Format.Type),s);
  23. }
  24. switch (Format.Type)
  25. {
  26. case PACKET_NONE:
  27. break;
  28. case PACKET_VIDEO:
  29. if (Pin.Node && Compressed(&Format.Format.Video.Pixel)) Info(p,Pin.Node,&y,MEDIAINFO_CODEC); if (Format.Format.Video.Width && Format.Format.Video.Height) { stprintf_s(s,TSIZEOF(s),T("%d x %d"),Format.Format.Video.Width,Format.Format.Video.Height); WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_SIZE),s); } if (Format.PacketRate.Num) { FractionToString(s,TSIZEOF(s),&Format.PacketRate,0,3); WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_FPS),s); } if (Format.ByteRate) { IntToString(s,TSIZEOF(s),(Format.ByteRate+62)/125,0); tcscat_s(s,TSIZEOF(s),T(" kbit/s")); // 1000byte/sec WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_BITRATE),s); } break;
  30. case PACKET_AUDIO:
  31. if (Pin.Node && Format.Format.Audio.Format != AUDIOFMT_PCM) Info(p,Pin.Node,&y,MEDIAINFO_CODEC);
  32. s[0] = 0; if (Format.Format.Audio.SampleRate) { IntToString(s+tcslen(s),TSIZEOF(s)-tcslen(s),Format.Format.Audio.SampleRate,0); tcscat_s(s,TSIZEOF(s),T(" Hz ")); }
  33. switch (Format.Format.Audio.Channels) {
  34. case 0: break;
  35. case 1: tcscat_s(s,TSIZEOF(s),LangStr(MEDIAINFO_ID,MEDIAINFO_AUDIO_MONO)); break;
  36. case 2: tcscat_s(s,TSIZEOF(s),LangStr(MEDIAINFO_ID,MEDIAINFO_AUDIO_STEREO)); break;
  37. default: stcatprintf_s(s,TSIZEOF(s),T("%d Ch"),Format.Format.Audio.Channels); break;
  38. }
  39. if (s[0])
  40. WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_FORMAT),s);
  41. if (Format.ByteRate) { IntToString(s,TSIZEOF(s),(Format.ByteRate+62)/125,0); tcscat_s(s,TSIZEOF(s),T(" kbit/s")); // 1000bit/sec WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_BITRATE),s); }
  42. break;
  43. case PACKET_SUBTITLE:
  44. if (Pin.Node)
  45. Info(p,Pin.Node,&y,MEDIAINFO_CODEC);
  46. break;
  47. } Comment(p,(player*)Player,&y,No); }
  48. if (VOutput)
  49. {
  50. int Total = 0;
  51. int Dropped = 0;
  52. VOutput->Get(VOutput,OUT_TOTAL,&Total,sizeof(int));
  53. VOutput->Get(VOutput,OUT_DROPPED,&Dropped,sizeof(int));
  54. Total += Dropped;
  55. if (Total)
  56. {
  57. y += 6;
  58. IntToString(s,TSIZEOF(s),Total,0);
  59. WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_VIDEO_TOTAL),s);
  60. IntToString(s,TSIZEOF(s),Dropped,0);
  61. WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_VIDEO_DROPPED),s);
  62. Player->Get(Player,PLAYER_VSTREAM,&No,sizeof(No));
  63. if (No>=0 && Reader->Get(Reader,(FORMAT_STREAM+No)|PIN_FORMAT,&Format,sizeof(Format))==ERR_NONE &&
  64. Format.Type == PACKET_VIDEO && Format.PacketRate.Num)
  65. {
  66. Simplify(&Format.PacketRate,(1<<30)/Total,(1<<30)/Total);
  67. Format.PacketRate.Num *= Total - Dropped;
  68. Format.PacketRate.Den *= Total;
  69. FractionToString(s,TSIZEOF(s),&Format.PacketRate,0,3);
  70. WinPropLabel(p,&y,LangStr(MEDIAINFO_ID,MEDIAINFO_AVG_FPS),s);
  71. }
  72. }
  73. }
  74. }
  75. return ERR_NONE;
  76. }
  77. static const menudef MenuDef[] = { { 0,PLATFORM_ID, PLATFORM_DONE }, MENUDEF_END };
  78. WINCREATE(MediaInfo)
  79. static int Create(win* p) {
  80. MediaInfoCreate(p);
  81. p->LabelWidth = 64;
  82. p->WinWidth = 180;
  83. p->WinHeight = 240;
  84. p->Flags |= WIN_DIALOG|WIN_NOTABSTOP;
  85. p->MenuDef = MenuDef;
  86. p->Init = (nodefunc)Init;
  87. return ERR_NONE;
  88. }
  89. static const nodedef MediaInfo =
  90. {
  91. sizeof(win),
  92. MEDIAINFO_ID,
  93. WIN_CLASS,
  94. PRI_DEFAULT,
  95. (nodecreate)Create
  96. };
  97. void MediaInfo_Init()
  98. {
  99. NodeRegisterClass(&MediaInfo);
  100. }
  101. void MediaInfo_Done() { NodeUnRegisterClass(MEDIAINFO_ID); }