IO.hpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: IO.hpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 #ifndef _PS_PROXY_IO_HPP 00045 #define _PS_PROXY_IO_HPP 00046 00047 #include "global.hpp" 00048 #include <assert.h> 00049 #ifdef ISOMP4 00050 #include "ISOMovies.h" 00051 #endif 00052 //#include "VCondition.hpp" 00053 #include "VMutex.hpp" 00054 00055 class ESInfo; 00056 class Frame; 00057 class VThread; 00058 00059 00060 enum RTXState { NONE,ACK,NACK,NACKACK}; 00061 #define LAST_RTX_STATE NACKACK 00062 extern char* sRTXState[]; 00063 00064 typedef struct rtx_info { 00065 //address is taken from RTP data stream 00066 u16 remotePort; 00067 u16 localPort; 00068 struct rtp *session; 00069 u16 payloadType; 00070 u32 ticks; 00071 u32 mId; 00072 u32 rtxTimeInMs; 00073 RTXState state; 00074 rtx_info() { 00075 rtxTimeInMs=0; 00076 state=NONE; 00077 ticks=payloadType=remotePort=localPort=mId=0; 00078 session=NULL; 00079 }; 00080 rtx_info(RTXState type,u32 maxTime) { 00081 rtxTimeInMs=maxTime; 00082 state=type; 00083 ticks=payloadType=remotePort=localPort=mId=0; 00084 session=NULL; 00085 }; 00087 rtx_info(const rtx_info* r) { 00088 assert(r); 00089 remotePort = r->remotePort; 00090 localPort = r->localPort; 00091 payloadType = r->payloadType; 00092 ticks = r->ticks; 00093 mId = r->mId; 00094 rtxTimeInMs = r->rtxTimeInMs; 00095 state = r->state; 00096 session = NULL; 00097 } 00098 ~rtx_info() 00099 { 00100 }; 00101 } rtx_info; 00102 00103 typedef struct rtx_group { 00104 u32 midESInfo; 00105 rtx_info* rtx; 00106 const ESInfo* es; 00107 00108 rtx_group(RTXState type,u32 maxTime) { 00109 rtx=new rtx_info(type,maxTime); 00110 es=NULL; 00111 midESInfo=0; 00112 }; 00113 ~rtx_group() { 00114 if(rtx) 00115 delete rtx; 00116 }; 00117 } rtx_group; 00118 00119 enum Error { SA_OK, SA_Error, SA_EOF }; 00120 struct AU { 00122 u8 *payload; 00123 u8 *y,*u,*v; // on linux point to the components in the payload, on winCE it uses three diff. buffers 00125 u32 size; 00127 u32 cts; 00129 u32 dts; 00130 u32 duration; 00131 u32 sampleFlags; 00132 u8 prio; 00133 u32 frameType; 00134 Error err; 00135 00137 char *toString() { 00138 int auSize = sizeof(AU) - sizeof(u8 *); 00139 char *res = new char[auSize]; 00140 memcpy(res, &size, auSize); 00141 return res; 00142 }; 00144 bool fromString(char *in) { 00145 memcpy(&size, in, sizeof(AU) - sizeof(u8 *)); 00146 payload = NULL; 00147 return true; 00148 }; 00151 bool operator == (const AU & a1) { 00152 return a1.size == size && a1.cts == cts && a1.dts == dts 00153 && a1.duration == duration && a1.prio == prio; 00154 }; 00157 bool operator == (const AU * &a1) { 00158 return a1->size == size && a1->cts == cts && a1->dts == dts 00159 && a1->duration == duration && a1->prio == prio; 00160 }; 00161 AU() { 00162 payload=NULL; 00163 size = 0; 00164 cts = 0; 00165 dts = 0; 00166 duration = 0; 00167 sampleFlags = 0; 00168 prio = 255; 00169 frameType=0; 00170 err = SA_OK; 00171 }; 00173 AU(const AU & in) { 00174 payload=NULL; 00175 size = 0; 00176 cts = in.cts; 00177 dts = in.dts; 00178 duration = in.duration; 00179 sampleFlags = in.sampleFlags; 00180 prio = in.prio; 00181 frameType=in.frameType; 00182 err = in.err; 00183 }; 00184 AU(const AU * in) { 00185 payload=NULL; 00186 size = 0; 00187 cts = in->cts; 00188 dts = in->dts; 00189 duration = in->duration; 00190 sampleFlags = in->sampleFlags; 00191 prio = in->prio; 00192 frameType=in->frameType; 00193 err = in->err; 00194 }; 00195 ~AU() { 00196 if(payload) { 00197 delete[] payload; 00198 payload=NULL; 00199 } 00200 }; 00201 00202 }; 00203 00215 class IO: public VThread { 00216 00217 public: 00218 /* OPEN and MUTED means playing and streaming, adapting in the DC and in the DataSinks, 00219 * but MUTED does all except adaptation in the DataSinks, where the decoding normally 00220 * takes place...still, the I/O output writeFrame is called with the unadapted frame! 00221 * by this, global DC adaptors might still be used for eg. statistics 00222 * PAUSED is kinda like CLOSED, not playing and streaming, but it could be continued 00223 * PREFETCHING is used at beginning or on buffer underrun 00224 * STREAMERR is set, if eg. no header was received or, for the Rtp class, 00225 * the rtp udp ports where already in use 00226 * 00227 * StateInNumbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 00228 */ 00229 enum State { CLOSED, CLOSING, FORCE_CLOSING, OPENING, OPEN, PAUSED, MUTED, PREFETCHING, STREAMEOF, STREAMERR }; 00230 00231 #define IO_NETWORK_HIGHEST_PRIORITY 0 00232 00233 IO(); 00234 00235 virtual ~IO(); 00236 00241 virtual Frame * getFrame() = 0; 00242 00244 virtual int writeFrame(Frame * frm, ESInfo *es = NULL) = 0; 00245 00249 virtual bool open() = 0; 00250 00255 virtual bool close(bool immediate=false) = 0; 00256 00260 virtual bool destroy() = 0; 00261 00262 virtual State getState() const { return state;}; 00263 00265 virtual State setState(State s); 00266 00268 virtual int getBufferFillLevel() const = 0; 00269 00275 virtual int flushBuffer(long from_ts = 0, long to_ts = -1) 00276 { 00277 from_ts = from_ts; // 4Wall 00278 to_ts = to_ts; // 4Wall 00279 return 0; 00280 }; 00281 00283 virtual const char *getURL() const = 0; 00284 00293 virtual bool setToFrameNumber(u32 frameNumber) { 00294 dprintf_full("IO::setToFrameNumber dummy implementation\n"); 00295 return false; 00296 }; 00297 00304 virtual long setToClosestIFrame(u32 frameNumber, bool backwards = true) { 00305 dprintf_full("IO::setToClosestIFrame dummy implementation\n"); 00306 setToFrameNumber(frameNumber); 00307 backwards = backwards; 00308 return 0; 00309 }; 00310 00317 virtual bool setEndFrameNumber(u32 stopNumber) { 00318 endFrameNumber=stopNumber; 00319 return true; 00320 } 00321 00322 virtual u32 getEndFrameNumber() const { return endFrameNumber; } 00323 00324 virtual u32 getCurrentFrameNumber() const { return currentFrameNumber; }; 00325 00328 virtual void setResendFrameHeader(bool set) { resendFrameHeader=set;}; 00329 00330 virtual void run() { ; }; //immediately stop unused thread 00331 00332 virtual void setESInfo(ESInfo * es) =0; 00333 00334 virtual ESInfo* getESInfo() =0; 00335 00338 virtual u32 getFramesSeen() const { return framesSeen;}; 00339 00341 virtual void setRtxInfo(const rtx_info* rtx) { rtx = rtx; }; 00342 00343 //stupid default implementations... 00344 virtual State play(double prefetchTime=0.0); //implemented in IO.cpp 00345 00346 virtual State pause(); 00347 00348 virtual State mute(); 00349 00350 protected: 00351 00352 State state; 00358 bool resendFrameHeader; 00359 u32 currentFrameNumber; 00361 u32 endFrameNumber; 00362 VMutex mutexStateChanged; 00363 // VCondition condStateChanged; 00364 u32 framesSeen; 00365 }; 00366 #endif