00001 #ifndef Impala_Core_Stream_LavcProtocolImpl_h
00002 #define Impala_Core_Stream_LavcProtocolImpl_h
00003
00004
00005 #include "Link/Lavc/Lavc.h"
00006
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Stream
00012 {
00013
00014 class LavcProtocolImpl
00015 {
00016
00017 public:
00018
00019 virtual int Read(unsigned char* buffer, int size)
00020 {
00021 ILOG_DEBUG("Read: buffer = " << (void*) buffer << ", size = " << size);
00022 int nrRead = mIOBuffer->Read(buffer, size);
00023 ILOG_DEBUG("Read: nrRead = " << nrRead);
00024 return nrRead;
00025 }
00026
00027 virtual int64_t Seek(int64_t offset, int whence)
00028 {
00029 ILOG_DEBUG("Seek: offset = " << offset << ", whence = " << whence);
00030
00031 if (whence == 65536)
00032 {
00033 int64_t fileLen = (int64_t) mIOBuffer->Size();
00034 ILOG_DEBUG("Seek: file length = " << fileLen);
00035 return fileLen;
00036 }
00037
00038 int64_t newPos = (int64_t) mIOBuffer->Seek(offset, whence);
00039 ILOG_DEBUG("Seek: new position = " << newPos);
00040 return newPos;
00041 }
00042
00043 virtual int Close(URLContext* h)
00044 {
00045 ILOG_DEBUG("Closing target");
00046 delete mIOBuffer;
00047 h->priv_data = 0;
00048 return 0;
00049 }
00050
00051 protected:
00052
00053 LavcProtocolImpl() : mIOBuffer(0)
00054 {
00055 }
00056
00057 ~LavcProtocolImpl()
00058 {
00059 }
00060
00061 int OpenTarget(URLContext* h, const char* url, int flags)
00062 {
00063 ILOG_DEBUG("OpenTarget: url = " << url);
00064 String urlStr = url;
00065 int protocolLastPos = urlStr.find_first_of(':');
00066 String protocol = urlStr.substr(0, protocolLastPos + 1);
00067 String target = urlStr.substr(protocolLastPos + 1);
00068 ILOG_DEBUG("OpenTarget: target = " << target);
00069 Util::IOBuffer* ioBuf = this->CreateIOBuffer(target);
00070 if (!ioBuf->Valid())
00071 {
00072 delete ioBuf;
00073 return -1;
00074 }
00075
00076 h->priv_data = (void*) new LavcProtocolImpl(ioBuf);
00077 return 0;
00078 }
00079
00080 virtual Util::IOBuffer* CreateIOBuffer(String target)
00081 {
00082 return 0;
00083 }
00084
00085 private:
00086
00087 LavcProtocolImpl(Util::IOBuffer* ioBuf) : mIOBuffer(ioBuf)
00088 {
00089 }
00090
00091 Util::IOBuffer* mIOBuffer;
00092
00093 ILOG_VAR_DECL;
00094
00095 };
00096
00097 ILOG_VAR_INIT(LavcProtocolImpl, Impala.Core.Stream);
00098
00099
00100 static int
00101 LavcProtocolImpl_read(URLContext* h, unsigned char* buffer, int size)
00102 {
00103 return ((LavcProtocolImpl*) h->priv_data)->Read(buffer, size);
00104 }
00105
00106 static int64_t
00107 LavcProtocolImpl_seek(URLContext* h, int64_t offset, int whence)
00108 {
00109 return ((LavcProtocolImpl*) h->priv_data)->Seek(offset, whence);
00110 }
00111
00112 static int
00113 LavcProtocolImpl_close(URLContext* h)
00114 {
00115 return ((LavcProtocolImpl*) h->priv_data)->Close(h);
00116 }
00117
00118 }
00119 }
00120 }
00121
00122 #endif