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

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: rawimage.c 284 2005-10-04 08:54:26Z picard $
  18.  *
  19.  * The Core Pocket Media Player
  20.  * Copyright (c) 2004-2005 Gabor Kovacs
  21.  *
  22.  ****************************************************************************/
  23. #include "common.h"
  24. static int Init(rawimage* p)
  25. {
  26. format_stream* s = Format_AddStream(&p->Format,sizeof(format_stream));
  27. if (s)
  28. {
  29. PacketFormatClear(&s->Format);
  30. s->Format.Type = PACKET_VIDEO;
  31. s->Format.Format.Video.Pixel.Flags = PF_FOURCC; //|PF_NOPREROTATE;
  32. s->Format.Format.Video.Pixel.FourCC = p->FourCC;
  33. s->PacketBurst = 1;
  34. s->DisableDrop = 1;
  35. Format_PrepairStream(&p->Format,s);
  36. }
  37. p->Total = 0;
  38. p->Format.HeaderLoaded = 1;
  39. p->Format.TimeStamps = 0;
  40. return ERR_NONE;
  41. }
  42. static int Packet(rawimage* p, format_reader* Reader, format_packet* Packet)
  43. {
  44. return ERR_INVALID_PARAM;
  45. }
  46. static int Seek(rawimage* p, tick_t Time, filepos_t FilePos,bool_t PrevKey)
  47. {
  48. if (Time==0 || FilePos==0)
  49. {
  50. p->Total = 0;
  51. p->Format.Reader->Seek(p->Format.Reader,0,SEEK_SET);
  52. return ERR_NONE;
  53. }
  54. return ERR_NOT_SUPPORTED;
  55. }
  56. static void Sended(rawimage* p, format_stream* Stream)
  57. {
  58. p->Total = 0;
  59. Format_AllocBufferBlock(&p->Format,Stream,0);
  60. }
  61. static int FillQueue(rawimage* p,format_reader* Reader)
  62. {
  63. return ERR_NONE;
  64. }
  65. static int ProcessStream(rawimage* p,format_stream* Stream)
  66. {
  67. int Result,Length;
  68. if (Stream->Pending)
  69. {
  70. Result = Format_Send(&p->Format,Stream);
  71. if (Result == ERR_BUFFER_FULL || Result == ERR_SYNCED)
  72. return Result;
  73. }
  74. Length = p->Format.FileSize;
  75. if (Length < 0)
  76. Length = 1024*1024;
  77. if (Stream->BufferBlockLength < Length)
  78. Format_AllocBufferBlock(&p->Format,Stream,Length);
  79. do
  80. {
  81. format_ref *i;
  82. format_ref *Ref = Stream->Reader->ReadAsRef(Stream->Reader,-MAX_INT);
  83. for (i=Ref;i;i=i->Next)
  84. {
  85. int n = i->Length;
  86. if (n > Stream->BufferBlockLength - p->Total)
  87. n = Stream->BufferBlockLength - p->Total;
  88. if (n>0)
  89. {
  90. WriteBlock(&Stream->BufferBlock,p->Total,i->Buffer->Block.Ptr + i->Begin,n);
  91. p->Total += n;
  92. }
  93. }
  94. Format_ReleaseRef(&p->Format,Ref);
  95. }
  96. while (Stream->Reader->BufferAvailable>0);
  97. if (!Stream->Reader->Eof(Stream->Reader) && p->Total<Stream->BufferBlockLength)
  98. return ERR_NEED_MORE_DATA;
  99. if (!p->Total)
  100. return Format_CheckEof(&p->Format,Stream);
  101. Stream->Packet.RefTime = 0;
  102. Stream->Packet.Data[0] = Stream->BufferBlock.Ptr;
  103. Stream->Packet.Length = p->Total;
  104. Stream->Pending = 1;
  105. if (Stream->LastTime < TIME_UNKNOWN)
  106. Stream->LastTime = TIME_UNKNOWN;
  107. Result = Format_Send(&p->Format,Stream);
  108. if (Result == ERR_BUFFER_FULL || Result == ERR_NEED_MORE_DATA)
  109. Result = ERR_NONE;
  110. return Result;
  111. }
  112. static int Create(rawimage* p)
  113. {
  114. const tchar_t* Format = LangStr(p->Format.Format.Class,RAWIMAGE_FORMAT);
  115. if (tcsnicmp(Format,T("vcodec/"),7)==0)
  116. p->FourCC = StringToFourCC(Format+7,1);
  117. if (!p->FourCC)
  118. return ERR_INVALID_PARAM;
  119. p->Format.Init = (fmtfunc)Init;
  120. p->Format.Seek = (fmtseek)Seek;
  121. p->Format.ReadPacket = (fmtreadpacket)Packet;
  122. p->Format.FillQueue = (fmtfill)FillQueue;
  123. p->Format.Process = (fmtstreamprocess)ProcessStream;
  124. p->Format.Sended = (fmtstream)Sended;
  125. p->Format.Timing = 0;
  126. return ERR_NONE;
  127. }
  128. static const nodedef RawImage =
  129. {
  130. sizeof(rawimage)|CF_ABSTRACT,
  131. RAWIMAGE_CLASS,
  132. FORMATBASE_CLASS,
  133. PRI_DEFAULT,
  134. (nodecreate)Create,
  135. NULL,
  136. };
  137. void RawImage_Init()
  138. {
  139.  NodeRegisterClass(&RawImage);
  140. }
  141. void RawImage_Done()
  142. {
  143. NodeUnRegisterClass(RAWIMAGE_CLASS);
  144. }