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

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: subtitle.c 271 2005-08-09 08:31:35Z picard $
  18.  *
  19.  * The Core Pocket Media Player
  20.  * Copyright (c) 2004-2005 Gabor Kovacs
  21.  *
  22.  ****************************************************************************/
  23. #include "stdafx.h"
  24. #define SUBTITLE_INPUT 0x100
  25. #define SUBTITLE_OUTPUT 0x101
  26. typedef struct subtitle
  27. {
  28. node VMT;
  29. int Format;
  30. node* Output;
  31. } subtitle;
  32. static int SetFormat( subtitle* p, const int* Format )
  33. {
  34. if (Format)
  35. {
  36. p->Format = *Format;
  37. }
  38. return ERR_NONE;
  39. }
  40. static int SetOutput( subtitle* p, node* Node )
  41. {
  42. p->Output = Node;
  43. return ERR_NONE;
  44. }
  45. static void Discontinuity( subtitle* p )
  46. {
  47. //...
  48. }
  49. static int Decode( subtitle* p, const packet* Packet )
  50. {
  51. char a[256];
  52. tchar_t s[256];
  53. int Len;
  54. if (Packet->CurrTime >= 0 && Packet->RefTime >= (Packet->CurrTime + SHOWAHEAD))
  55. return ERR_BUFFER_FULL;
  56. //...
  57. Len = Packet->Length;
  58. if (Len>255)
  59. Len=255;
  60. memcpy(a,Packet->Data[0],Len);
  61. a[Len] = 0;
  62. if (p->Format == STRING_UTF8)
  63. UTF8ToTcs(s,a,256);
  64. else
  65. StrToTcs(s,a,256);
  66. DEBUG_MSG3(-1,T("Subtitle %d %d: %s"),Packet->RefTime,Packet->CurrTime,s);
  67. return ERR_NONE;
  68. }
  69. const datadef SubtitleParams[] = 
  70. {
  71. { SUBTITLE_ID, TYPE_CLASS },
  72. { SUBTITLE_INPUT, TYPE_PACKET, DF_INPUT, PACKET_SUBTITLE },
  73. { SUBTITLE_OUTPUT, TYPE_NODE, DF_OUTPUT, VOUT_CLASS },
  74. DATADEF_END
  75. };
  76. static int Enum( subtitle* p, int No, datadef* Param )
  77. {
  78. return NodeEnumType(&No,Param,NodeParams,FlowParams,SubtitleParams,NULL);
  79. }
  80. static int Get( subtitle* p, int No, void* Data, int Size )
  81. {
  82. int Result = ERR_INVALID_PARAM;
  83. switch (No)
  84. {
  85. case NODE_ID: GETVALUE(SUBTITLE_ID,int); break;
  86. case SUBTITLE_INPUT|PACKET_FORMAT: GETVALUE(p->Format,int); break;
  87. case SUBTITLE_OUTPUT: GETVALUE(p->Output,node*); break;
  88. }
  89. return Result;
  90. }
  91. static int Set( subtitle* p, int No, const void* Data, int Size )
  92. {
  93. int Result = ERR_INVALID_PARAM;
  94. switch (No)
  95. {
  96. case SUBTITLE_INPUT | PACKET_FORMAT: 
  97. if (!Size || Size == sizeof(int))
  98. {
  99. if (!Size) Data = NULL;
  100. Result = SetFormat(p,(const int*)Data);
  101. }
  102. break;
  103. case SUBTITLE_INPUT:
  104. if (Size == sizeof(packet))
  105. Result = Decode(p,(const packet*)Data);
  106. break;
  107. case SUBTITLE_OUTPUT:
  108. if (Size == sizeof(node*) && NodeIsClass(*(node**)Data,VOUT_CLASS))
  109. Result = SetOutput(p,*(node**)Data);
  110. break;
  111. case FLOW_EMPTY:
  112. Discontinuity(p);
  113. break;
  114. }
  115. return Result;
  116. }
  117. static subtitle SubTitle;
  118. void SubTitle_Init()
  119. {
  120. NodeFill(&SubTitle.VMT,sizeof(subtitle),(nodeenum)Enum,(nodeget)Get,(nodeset)Set);
  121. NodeRegister(&SubTitle.VMT,PRI_DEFAULT); 
  122. }
  123. void SubTitle_Done()
  124. {
  125. NodeUnRegister(&SubTitle.VMT);
  126. }