giofile.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /***************************************************************************\
  2. *
  3. * (C) copyright Fraunhofer - IIS (1998)
  4. * All Rights Reserved
  5. *
  6. * filename: giofile.h
  7. * project : MPEG Decoder
  8. * author : Martin Sieler
  9. * date : 1998-02-11
  10. * contents/description: HEADER - file I/O class for MPEG Decoder
  11. *
  12. *
  13. \***************************************************************************/
  14. #ifndef _GIOFILE_H
  15. #define _GIOFILE_H
  16. /* ------------------------ includes --------------------------------------*/
  17. #include <windows.h>
  18. #include "CVbriHeader.h"
  19. #include "jnetlib/jnetlib.h"
  20. #include "../vlb/dataio.h"
  21. #include "ID3v2.h"
  22. #include "LAMEInfo.h"
  23. #include "../nu/RingBuffer.h"
  24. #include "../apev2/tag.h"
  25. #include "ifc_mpeg_stream_reader.h"
  26. /*-------------------------- defines --------------------------------------*/
  27. /*-------------------------------------------------------------------------*/
  28. class CGioFile : public DataIOControl, public ifc_mpeg_stream_reader
  29. {
  30. public:
  31. CGioFile();
  32. virtual ~CGioFile();
  33. int Open(const wchar_t *pszName, int maxbufsizek);
  34. int Close();
  35. int Read(void *pBuffer, int cbToRead, int *pcbRead);
  36. int Peek(void *pBuffer, int cbToRead, int *pcbRead);
  37. //dataiocontrol interface
  38. int IO(void *buf, int size, int count)
  39. {
  40. int l=0;
  41. Read(buf,count,&l);
  42. return l;
  43. }
  44. int Seek(long offset, int origin)
  45. {
  46. return 0;
  47. }
  48. //int Close() { return 0; }
  49. int EndOf(void)
  50. {
  51. return IsEof();
  52. }
  53. int DICGetLastError()
  54. {
  55. return DATA_IO_ERROR_NONE;
  56. }
  57. int DICGetDirection()
  58. {
  59. return DATA_IO_READ;
  60. }
  61. unsigned int GetAvgVBRBitrate(void)
  62. {
  63. if (m_vbr_ms && m_vbr_frames)
  64. {
  65. if (m_vbr_bytes && encodingMethod != ENCODING_METHOD_CBR)
  66. return (unsigned int)(m_vbr_bytes * 8 / m_vbr_ms);
  67. else
  68. return (unsigned int)(mpeg_length * 8 / m_vbr_ms);
  69. }
  70. return 0;
  71. }
  72. bool IsEof() const;
  73. bool lengthVerified;
  74. bool isSeekReset()
  75. {
  76. if (m_is_stream && m_seek_reset && m_is_stream_seek)
  77. {
  78. m_seek_reset = false;
  79. m_is_stream_seek = false;
  80. return true;
  81. }
  82. else
  83. return false;
  84. }
  85. bool IsStreamSeekable()
  86. {
  87. return m_is_stream_seekable;
  88. }
  89. int GetHeaderOffset();
  90. int PercentAvailable()
  91. {
  92. if (!m_is_stream) return 0;
  93. if (!recvbuffersize) return 0;
  94. if (!m_connection) return 0;
  95. if (constate != 5) return 0;
  96. uint64_t bytes_100 = jnl_connection_receive_bytes_available(m_connection)*100;
  97. bytes_100 /= recvbuffersize;
  98. return (int)bytes_100;
  99. }
  100. int RunStream()
  101. {
  102. if (m_is_stream && m_connection)
  103. {
  104. if (constate != 5) Read(NULL,0,NULL);
  105. else jnl_connection_run(m_connection, -1, -1, NULL, NULL);
  106. int p=jnl_connection_get_state(m_connection);
  107. if (p==JNL_CONNECTION_STATE_ERROR||
  108. p==JNL_CONNECTION_STATE_CLOSED)
  109. return 2;
  110. return 1;
  111. }
  112. return 0;
  113. }
  114. int IsStream()
  115. {
  116. return m_is_stream;
  117. }
  118. void GetStreamInfo(wchar_t *, size_t len);
  119. DWORD GetContentLength(void) const;
  120. DWORD GetCurrentPosition(void) const;
  121. void SetCurrentPosition(long dwPos, int How);
  122. enum { GIO_FILE_BEGIN, GIO_FILE_CURRENT, GIO_FILE_END };
  123. uint64_t mpeg_length; /* length of valid audio data */
  124. uint64_t mpeg_position; /* starting position of first valid decodable non-header MPEG frame */
  125. uint64_t file_position; /* position within the MPEG data that we've read so far */
  126. uint64_t m_vbr_bytes;
  127. int m_vbr_frames, m_vbr_ms;
  128. int encodingMethod;
  129. uint64_t m_vbr_samples;
  130. int prepad, postpad;
  131. void Seek(int posms, int br);
  132. bool IsSeekable();
  133. unsigned char id3v1_data[128];
  134. char stream_url[256];
  135. char stream_name[256];
  136. char stream_genre[256];
  137. char stream_current_title[256];
  138. char *m_content_type;
  139. int uvox_last_message;
  140. char *uvox_3901;
  141. char *uvox_3902;
  142. typedef struct {
  143. char *uvox_stream_artwork;
  144. int uvox_stream_artwork_len;
  145. int uvox_stream_artwork_type;
  146. char *uvox_playing_artwork;
  147. int uvox_playing_artwork_len;
  148. int uvox_playing_artwork_type;
  149. } UVOX_ARTWORK;
  150. UVOX_ARTWORK uvox_artwork;
  151. ID3v2 info;
  152. float GetGain();
  153. unsigned char m_vbr_toc[100];
  154. int m_vbr_frame_len;
  155. int m_vbr_flag;
  156. CVbriHeader *m_vbr_hdr;
  157. FILETIME last_write_time;
  158. void *GetID3v1()
  159. {
  160. if (m_id3v1_len == 128)
  161. return id3v1_data;
  162. else
  163. return 0;
  164. }
  165. void *GetID3v2(uint32_t *len)
  166. {
  167. if (stream_id3v2_buf)
  168. {
  169. *len = stream_id3v2_read;
  170. return stream_id3v2_buf;
  171. }
  172. else
  173. return 0;
  174. }
  175. void *GetLyrics3(uint32_t *len)
  176. {
  177. if (lyrics3_data)
  178. {
  179. *len = lyrics3_size;
  180. return lyrics3_data;
  181. }
  182. else
  183. return 0;
  184. }
  185. void *GetAPEv2(uint32_t *len)
  186. {
  187. if (apev2_data)
  188. {
  189. *len = m_apev2_len;
  190. return apev2_data;
  191. }
  192. return 0;
  193. }
  194. protected:
  195. void ReadiTunesGaps();
  196. private:
  197. /* ID3v2 */
  198. int m_id3v1_len;
  199. /* ID3v2 */
  200. uint32_t stream_id3v2_read;
  201. char *stream_id3v2_buf;
  202. int m_id3v2_len;
  203. /* Lyrics3 */
  204. uint32_t lyrics3_size;
  205. char *lyrics3_data;
  206. /* APEv2 */
  207. uint32_t m_apev2_len;
  208. char *apev2_data;
  209. APEv2::Tag apev2;
  210. int m_is_stream;
  211. jnl_dns_t m_dns;
  212. jnl_connection_t m_connection;
  213. char last_full_url[4096];
  214. int is_stream_seek;
  215. char *host;
  216. char *proxy_host;
  217. char *req;
  218. unsigned short port;
  219. char *lpinfo;
  220. char *proxy_lp;
  221. char *request;
  222. int constate;
  223. char save_filename[256];
  224. char server_name[128];
  225. int recvbuffersize;
  226. int64_t stream_bytes_read;
  227. int64_t stream_metabytes_read;
  228. unsigned int timeout_start;
  229. char force_lpinfo[256];
  230. unsigned char *m_full_buffer;
  231. int is_uvox;
  232. int uvox_stream_data_len;
  233. int uvox_message_cnt, uvox_desyncs;
  234. int uvox_sid,uvox_maxbr, uvox_avgbr,uvox_maxmsg;
  235. unsigned char *uvox_stream_data;
  236. char *uvox_meta[2][32];
  237. int meta_interval,meta_pos;
  238. uint64_t m_full_buffer_pos/*,m_full_buffer_len*/;
  239. char stream_title_save[580];
  240. char last_title_sent[256];
  241. RingBuffer peekBuffer;
  242. //unsigned char m_peekbuf[8192];
  243. //int m_peekbuf_used;
  244. bool no_peek_hack;
  245. int doConnect(const char *str, int start_offset);
  246. void processMetaData(char *data, int lent, int msgId = 0);
  247. int m_redircnt;
  248. int m_auth_tries;
  249. HANDLE hFile;
  250. bool fEof;
  251. char dlg_realm[256];
  252. static INT_PTR CALLBACK httpDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  253. int m_http_response;
  254. bool m_seek_reset;
  255. bool m_is_stream_seek;
  256. bool m_is_stream_seekable;
  257. bool m_useaproxy;
  258. RECVS_DISPATCH;
  259. };
  260. /*-------------------------------------------------------------------------*/
  261. #endif