main.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #ifndef IN_VORBIS_MAIN_H
  2. #define IN_VORBIS_MAIN_H
  3. #define WINSOCK_API_LINKAGE
  4. #ifndef STRICT
  5. #define STRICT
  6. #endif
  7. #include <windows.h>
  8. extern int (*warand)();
  9. extern float (*warandf)();
  10. inline void * z_malloc(int x)
  11. {
  12. void* foo=malloc(x);
  13. if (foo) memset(foo,0,x);
  14. return foo;
  15. }
  16. #include <shlwapi.h>
  17. #include <malloc.h>
  18. #define uitoa(x,y) _itoa(x,y,10)
  19. #define atoui atoi
  20. #include <vorbis\vorbisfile.h>
  21. #include "c_string.h"
  22. #include "../Winamp/in2.h"
  23. extern In_Module mod;
  24. #include "resource.h"
  25. #define VER L"1.79"
  26. #define _NAME "Nullsoft Vorbis Decoder"
  27. extern "C"
  28. {
  29. extern const char *INI_FILE;
  30. extern const wchar_t *INI_DIRECTORY;
  31. }
  32. class CfgVar
  33. {
  34. private:
  35. String name;
  36. CfgVar * next;
  37. static CfgVar * list;
  38. public:
  39. static void ReadConfig();
  40. static void WriteConfig();
  41. //helpers
  42. static bool read_struct(const char *inifile, const char *section, const char * name,void * ptr,UINT size);
  43. static void write_struct(const char *inifile, const char *section, const char * name,void * ptr,UINT size);
  44. static void write_int(const char *inifile, const char *section, const char * name,int val);
  45. static int read_int(const char *inifile, const char *section,const char * name,int def);
  46. protected:
  47. CfgVar(const char * n) : name(n) {next=list;list=this;}
  48. virtual void Read(const char * name)=0;
  49. virtual void Write(const char * name)=0;
  50. };
  51. class CfgInt : private CfgVar
  52. {
  53. private:
  54. int def,value;
  55. public:
  56. CfgInt(const char * name,int _def) : CfgVar(name) {value=def=_def;}
  57. inline int operator=(int x) {value=x;return value;}
  58. inline operator int() {return value;}
  59. private:
  60. virtual void Read(const char * name);
  61. virtual void Write(const char * name);
  62. };
  63. class CfgString : private CfgVar, public StringW
  64. {
  65. private:
  66. StringW def;
  67. public:
  68. CfgString(const char * name,const char * _def) : CfgVar(name), StringW(_def), def(_def) {}
  69. private:
  70. virtual void Read(const char * name);
  71. virtual void Write(const char * name);
  72. };
  73. template<class T>
  74. class CfgStructT : private CfgVar
  75. {
  76. public:
  77. T data;
  78. CfgStructT(const char * name) : CfgVar(name) {}
  79. private:
  80. void Read(const char * name) { read_struct(INI_FILE, "in_vorbis",name,&data,sizeof(data));}
  81. void Write(const char * name) {if (IsValueDefault()) WritePrivateProfileStringA("in_vorbis", name, 0, INI_FILE); else write_struct(INI_FILE, "in_vorbis", name, &data, sizeof(data));}
  82. protected:
  83. virtual bool IsValueDefault() {return 0;}
  84. };
  85. class CfgFont : public CfgStructT<LOGFONT>
  86. {
  87. private:
  88. void get_def(LOGFONT * f) {memset(f,0,sizeof(LOGFONT));GetObject(GetStockObject(DEFAULT_GUI_FONT),sizeof(LOGFONT),f);}
  89. virtual bool IsValueDefault()
  90. {
  91. LOGFONT t;
  92. get_def(&t);
  93. return !memcmp(&data,&t,sizeof(LOGFONT));
  94. }
  95. public:
  96. CfgFont(const char * name) : CfgStructT<LOGFONT>(name)
  97. {
  98. get_def(&data);
  99. }
  100. };
  101. extern int32_t priority_tab[7];
  102. extern HINSTANCE hIns;
  103. extern CfgString cfg_ssave_format,cfg_dumpdir;
  104. int is_http(const char* url);
  105. class VorbisFile
  106. {
  107. protected:
  108. virtual int f_seek(__int64 offset,int whence)=0;
  109. virtual size_t f_read(UINT siz,void * ptr)=0;
  110. virtual UINT f_tell()=0;
  111. static int _f_close(void *);
  112. static int _f_seek(void* rs,__int64 offset,int whence);
  113. static size_t _f_read(void* ptr,size_t size,size_t nmemb,void * rs);
  114. static long _f_tell(void* rs);
  115. static ov_callbacks oc;
  116. static VorbisFile * Create_HTTP(const char * url,bool is_info);
  117. VorbisFile(const wchar_t * u, bool is_info) : url(u) {memset(&vf,0,sizeof(vf));stopping=0;abort_prebuf=0;avg_kbps=0;use_prebuf=0;primary=!is_info; baseoffs=0;}
  118. bool init();
  119. virtual void post_init() {};
  120. UINT avg_kbps;
  121. bool Aborting();
  122. __int64 baseoffs;
  123. public:
  124. enum {TYPE_LOCAL,TYPE_HTTP};
  125. virtual int GetType()=0;
  126. virtual bool IsLive() {return 0;}
  127. virtual void do_prebuf() {use_prebuf=1;abort_prebuf=0;};
  128. StringW url;
  129. String withlp;
  130. String stream_title;
  131. bool stopping,abort_prebuf,use_prebuf;
  132. bool primary;//display status messages or not
  133. OggVorbis_File vf;
  134. UINT get_avg_bitrate()
  135. {
  136. if (avg_kbps>0) return avg_kbps;
  137. vorbis_info * vi=ov_info(&vf,-1);
  138. if (!vi) return 0;
  139. return vi->bitrate_nominal/1000;
  140. }
  141. const char* get_meta(const char* tag,UINT c);
  142. void set_meta(const vorbis_comment * vc,int links);
  143. static VorbisFile * Create(const wchar_t * url,bool is_info);
  144. double Length() {return ov_time_total(&vf,-1);}
  145. double GetPos() {return ov_time_tell(&vf);}
  146. int Seek(double p);
  147. void Status(const wchar_t * zzz);
  148. virtual UINT FileSize()=0;
  149. virtual ~VorbisFile() {ov_clear(&vf);}
  150. virtual void Idle() {Sleep(10);}
  151. virtual void setBaseOffset(__int64 offs) { baseoffs=offs; }
  152. float GetGain();
  153. };
  154. extern VorbisFile * theFile;
  155. extern StringW cur_file;
  156. extern CRITICAL_SECTION sync;
  157. BOOL modify_file(const wchar_t* url,const vorbis_comment * comments,int links);
  158. void winampGetExtendedFileInfoW_Cleanup(void);
  159. void UpdateFileTimeChanged(const wchar_t *fn);
  160. void do_cfg(int s);
  161. bool KeywordMatch(const char *mainString, const char *keyword);
  162. class Info
  163. {
  164. public:
  165. Info(const wchar_t *filename);
  166. ~Info();
  167. bool Save();
  168. int Error() { return vc==0?1:0; }
  169. int GetNumMetadataItems();
  170. void EnumMetadata(int n,wchar_t *key,int keylen, wchar_t *val, int vallen);
  171. void RemoveMetadata(wchar_t * key);
  172. void RemoveMetadata(int n);
  173. void SetMetadata(wchar_t *key, wchar_t *val);
  174. void SetMetadata(int n, wchar_t *key, wchar_t *val);
  175. void SetTag(int n,wchar_t *key); // changes the key name
  176. private:
  177. const wchar_t *filename;
  178. vorbis_comment * vc;
  179. int numstreams, stream;
  180. };
  181. // {B6CB4A7C-A8D0-4c55-8E60-9F7A7A23DA0F}
  182. static const GUID playbackConfigGroupGUID =
  183. { 0xb6cb4a7c, 0xa8d0, 0x4c55, { 0x8e, 0x60, 0x9f, 0x7a, 0x7a, 0x23, 0xda, 0xf } };
  184. #endif //IN_VORBIS_MAIN_H