main.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #ifndef NSVPLAY_MAIN_H
  2. #define NSVPLAY_MAIN_H
  3. #include <bfc/platform/types.h>
  4. #include "../nsvlib.h"
  5. #include "../dec_if.h"
  6. #define SHOW_STREAM_TITLE_AT_TOP 1
  7. class Subtitles;
  8. class SubsItem;
  9. #include "IDataReader.h"
  10. typedef struct
  11. {
  12. const char *language;
  13. const char *utf8_text;
  14. unsigned int start_frame, end_frame;
  15. unsigned char xPos, yPos;
  16. unsigned char colorRed, colorGreen, colorBlue;
  17. signed char fontSize;
  18. int extraDataSize;
  19. const void *extraData;
  20. } SUBTITLE_INFO;
  21. class IVideoOutput
  22. {
  23. public:
  24. virtual ~IVideoOutput() { }
  25. virtual int open(int w, int h, int vflip, double aspectratio, unsigned int fmt)=0;
  26. #ifdef _WIN32
  27. virtual void setcallback(LRESULT (*msgcallback)(void *token, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam), void *token) { }
  28. #else
  29. virtual void setcallback(void *func, void *token) { } // currently unused, here to reserve the spot in the vtable
  30. #endif
  31. virtual void close()=0;
  32. virtual void draw(void *frame)=0;
  33. virtual void drawSubtitle(SubsItem *item) { }
  34. virtual void showStatusMsg(const char *text) { }
  35. virtual int get_latency() { return 0; }
  36. virtual void notifyBufferState(int bufferstate) { } /* 0-255*/
  37. virtual intptr_t extended(intptr_t param1, intptr_t param2, intptr_t param3) { return 0; } // Dispatchable, eat this!
  38. };
  39. template<class T>
  40. class ClassList {
  41. public:
  42. ~ClassList() {
  43. int l=getlen()-1;
  44. for(int i=l;i>-1;i--) delete(get(i));
  45. }
  46. void put(T *item) {
  47. m_buf.add(&item,sizeof(T *));
  48. }
  49. T *get(int n) {
  50. if(n>=getlen()) return NULL;
  51. return ((T **)m_buf.get())[n];
  52. }
  53. int getlen() {
  54. return (int)(m_buf.getlen()/sizeof(SubsItem *));
  55. }
  56. private:
  57. GrowBuf m_buf;
  58. };
  59. class SubtitlesItem {
  60. public:
  61. SubtitlesItem(const char *language, Subtitles *subs) :
  62. m_subs(subs) {
  63. m_language=_strdup(language);
  64. m_subs=subs;
  65. }
  66. ~SubtitlesItem() {
  67. free((void *)m_language);
  68. }
  69. const char *m_language;
  70. Subtitles *m_subs;
  71. };
  72. class NSVDecoder {
  73. public:
  74. NSVDecoder(const char *url, IVideoOutput *output, char *subtitleurl=NULL);
  75. ~NSVDecoder();
  76. char *get_error();
  77. char *get_status();
  78. int run(int * volatile quit=NULL);
  79. void pause(int pause);
  80. ULONGLONG getpos();
  81. unsigned int getpos_frames() { return framecnt; }
  82. unsigned int getlen(); // returns 0xFFFFFFFF on unknown
  83. void setvolume(int volume) { m_volume=volume; if (aud_output) aud_output->setvolume(volume); }
  84. void setpan(int pan) { m_pan=pan; if (aud_output) aud_output->setpan(pan); }
  85. int getvolume() { return m_volume; }
  86. int getpan() { return m_pan; }
  87. int canseek();
  88. void seek(unsigned int newpos);
  89. char *getFromMeta(char *name);
  90. char *getUrl() { return m_url; }
  91. const char *getServerHeader(char *name);
  92. char *getTitle();
  93. char *getStatus();
  94. void getAudioDesc(char *buf);
  95. void getVideoDesc(char *buf);
  96. char *getAudioType() { return m_audio_type; }
  97. char *getVideoType() { return m_video_type; }
  98. unsigned int getFileSize(); // 0xFFFFFFFF if unknown
  99. int getBitrate();
  100. int getAudioBitrate();
  101. int getVideoBitrate();
  102. int getWidth() { return unpacket.getWidth(); }
  103. int getHeight() { return unpacket.getHeight(); }
  104. double getFrameRate() { return use_framerate_override?framerate_override:unpacket.getFrameRate(); }
  105. int getBufferPos() { if (m_prebuffer) return m_bufstate; return 256; } // 0-256
  106. int subsEnabled() { return m_enable_subtitles; }
  107. void enableSubs(int e) {
  108. m_enable_subtitles=e;
  109. if(!e&&m_out) m_out->drawSubtitle(NULL);
  110. }
  111. int getSubsFontSize() { return m_subs_fontsize; }
  112. void setSubsFontSize(int s) {
  113. m_subs_fontsize=s;
  114. if(m_out) m_out->drawSubtitle(NULL); //will redraw current subtitle with new size
  115. }
  116. void SetPreciseSeeking(int prec) { m_precise_seeking=prec; }
  117. void SetBuffering(int total_ms, int initial_ms, int after_underrun);
  118. void SetBufferMemoryLimit(int bytes) { m_buf_memlimit=bytes; }
  119. const char *getSubLanguage(int index);
  120. void setSubLanguage(int index) { m_cur_subtitle=index; }
  121. int getCurSubLanguage() { return m_cur_subtitle; }
  122. void CloseVideo()
  123. {
  124. if (m_out_opened)
  125. m_out->close();
  126. m_out_opened=0;
  127. }
  128. private:
  129. ULONGLONG m_avresync_time;
  130. int m_pb_init,m_pb_init_ur,m_buffer_total;
  131. int m_prebuffer;
  132. int m_bufstate;
  133. int proTimerStart;
  134. int proTimerEnd;
  135. float profiletime;
  136. float prostart;
  137. float proend;
  138. float timeref;
  139. int m_again;
  140. void ProcessSubtitleBlock(void *data, int len);
  141. int m_paused;
  142. ULONGLONG hack_l_curpos;
  143. ULONGLONG hack_l_curpos_ot;
  144. int m_buf_memlimit;
  145. IVideoOutput *m_out;
  146. int m_out_opened;
  147. nsv_InBS inbs;
  148. nsv_InBS audiobs,videobs;
  149. nsv_InBS auxbs;
  150. int video_frames_avail,audio_frames_avail;
  151. nsv_Unpacketer unpacket;
  152. unsigned int framecnt;
  153. int hdrsearched;
  154. int nsvbitstream_search;
  155. int64_t m_audio_writepos;
  156. unsigned int m_need_seek;
  157. int seek_dumpframes, seek_dumpaudiosamples;
  158. int pcm_samplerate;
  159. int m_precise_seeking;
  160. char *m_err;
  161. char *m_url;
  162. char *m_title;
  163. int vid_decoder_isnotnull,aud_decoder_isnotnull;
  164. IVideoDecoder *vid_decoder;
  165. IAudioDecoder *aud_decoder;
  166. IAudioOutput *aud_output;
  167. IDataReader *file_reader;
  168. int needkf;
  169. double aspect;
  170. double framerate_override;
  171. int use_framerate_override;
  172. nsv_fileHeader fileheader;
  173. unsigned int avg_framesize_cnt,avg_framesize_tot;
  174. unsigned int avg_framesize_cnt_v,avg_framesize_tot_v;
  175. unsigned int avg_framesize_cnt_a,avg_framesize_tot_a;
  176. int vidout_ready;
  177. int vid_flip;
  178. void *vidout;
  179. unsigned int vidout_type;
  180. unsigned int vidout_time;
  181. unsigned int vidout_codec_width;
  182. unsigned int vidout_codec_height;
  183. char m_audio_type[5];
  184. char m_video_type[5];
  185. int m_volume, m_pan;
  186. int m_enable_subtitles;
  187. int m_subs_fontsize;
  188. ClassList<SubtitlesItem> m_subtitles;
  189. int m_cur_subtitle;
  190. Subtitles *insertSubtitlesItem(const char *language, const char *subfile);
  191. Subtitles *findSubtitles(const char *language);
  192. };
  193. void Decoders_Init(char *wapluginspath=NULL);
  194. void Decoders_Quit();
  195. IAudioDecoder *CreateAudioDecoder(unsigned int type, int *wasNotNull, IAudioOutput **output);
  196. IVideoDecoder *CreateVideoDecoder(int w, int h, double framerate, unsigned int type, int *flip, int *wasNotNull=NULL);
  197. IDataReader *CreateReader(const char *url);
  198. #endif //NSVPLAY_MAIN_H