| 1 |
#ifndef ASFNETWORKINPUTSTREAM_H |
| 2 |
#define ASFNETWORKINPUTSTREAM_H |
| 3 |
|
| 4 |
#include "AsfInputStream.h" |
| 5 |
#include "avm_locker.h" |
| 6 |
#include "unistd.h" |
| 7 |
|
| 8 |
AVM_BEGIN_NAMESPACE; |
| 9 |
|
| 10 |
class ASXReader; |
| 11 |
class NetworkIterator; |
| 12 |
|
| 13 |
class URLString : public avm::string |
| 14 |
{ |
| 15 |
public: |
| 16 |
URLString() {} |
| 17 |
URLString(const avm::string& s) : avm::string(s) {} |
| 18 |
void escape(); |
| 19 |
//int getPort(int def = 80) { } |
| 20 |
}; |
| 21 |
|
| 22 |
class AsfNetworkInputStream: public AsfInputStream |
| 23 |
{ |
| 24 |
friend class NetworkIterator; |
| 25 |
static const uint_t CACHE_PACKETS = 160; |
| 26 |
|
| 27 |
public: |
| 28 |
enum Content |
| 29 |
{ |
| 30 |
Unknown, |
| 31 |
Plain, |
| 32 |
Live, |
| 33 |
Prerecorded, |
| 34 |
Redirect |
| 35 |
}; |
| 36 |
|
| 37 |
AsfNetworkInputStream() :m_pReader(0), m_pThread(0), m_pBuffer(0) {} |
| 38 |
virtual ~AsfNetworkInputStream(); |
| 39 |
virtual AsfIterator* getIterator(uint_t id); |
| 40 |
virtual void interrupt(); |
| 41 |
virtual double cacheSize() const; |
| 42 |
virtual void clear(); |
| 43 |
virtual bool isOpened() { return (m_bHeadersValid || m_pReader); } |
| 44 |
virtual bool isValid();// { return ((m_bHeadersValid && !m_bQuit) || m_pReader); } |
| 45 |
virtual bool isRedirector() { return (m_pReader != 0); } |
| 46 |
virtual bool getURLs(avm::vector<avm::string>& urls); |
| 47 |
|
| 48 |
int init(const char* pszFile); |
| 49 |
|
| 50 |
protected: |
| 51 |
static void* threadStarter(void*); |
| 52 |
void* threadFunc(); |
| 53 |
int createSocket(); |
| 54 |
Content checkContent(const char* request); |
| 55 |
int readContent(); |
| 56 |
int readRedirect(); |
| 57 |
void readHeader(size_t size, size_t skip = 0); |
| 58 |
ssize_t read(void* buffer, size_t size); |
| 59 |
ssize_t write(const void* buffer, size_t size); |
| 60 |
ssize_t dwrite(const void* buffer, size_t size); |
| 61 |
int seekInternal(uint_t time, NetworkIterator* requester); |
| 62 |
void unregister(NetworkIterator* requester); |
| 63 |
void flushPipe(); |
| 64 |
void escapeUrl(); |
| 65 |
|
| 66 |
size_t m_lReadBytes; |
| 67 |
ASXReader* m_pReader; |
| 68 |
PthreadTask* m_pThread; |
| 69 |
avm::vector<NetworkIterator*> m_Iterators; |
| 70 |
avm::string m_File, m_Server, m_Proxyhost; |
| 71 |
URLString m_Filename; |
| 72 |
URLString m_ServerFilename; |
| 73 |
int m_iSocket; |
| 74 |
int m_iPipeFd[2];//message on this pipe interrupts main reading thread |
| 75 |
int m_lfd; // localy stored asf stream |
| 76 |
uint16_t m_iProxyport; |
| 77 |
int m_iRandcntx; // random number to identify connection |
| 78 |
int m_iSeekId; // first stream which calls seek will be the master |
| 79 |
uint_t m_uiTime; |
| 80 |
off_t m_uiDataOffset; |
| 81 |
uint_t m_uiTimeshift; // network files should be moved to zero time |
| 82 |
char* m_pBuffer; |
| 83 |
int m_iRedirectSize; |
| 84 |
int m_iReadSize; |
| 85 |
mutable PthreadMutex m_Mutex; |
| 86 |
mutable PthreadCond m_Cond; |
| 87 |
Content m_Ctype; |
| 88 |
struct __attribute__((__packed__)) |
| 89 |
{ |
| 90 |
uint16_t kind; |
| 91 |
uint16_t size; |
| 92 |
uint32_t seq; |
| 93 |
uint16_t partflag; |
| 94 |
uint16_t size_confirm; |
| 95 |
|
| 96 |
void le16() |
| 97 |
{ |
| 98 |
kind = avm_get_le16(&kind); |
| 99 |
size = avm_get_le16(&size); |
| 100 |
seq = avm_get_le32(&seq); |
| 101 |
partflag = avm_get_le16(&partflag); |
| 102 |
size_confirm = avm_get_le16(&size_confirm); |
| 103 |
} |
| 104 |
} chhdr; |
| 105 |
|
| 106 |
bool m_bQuit; |
| 107 |
bool m_bHeadersValid; |
| 108 |
bool m_bFinished; |
| 109 |
bool m_bWaiting; |
| 110 |
bool m_bAcceptRanges; |
| 111 |
}; |
| 112 |
|
| 113 |
AVM_END_NAMESPACE; |
| 114 |
|
| 115 |
#endif // ASFNETWORKINPUTSTREAM_H |