PageRenderTime 341ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/working/avcodec_to_widget_10/t_box_player_ctx.h

http://mingw-lib.googlecode.com/
C Header | 179 lines | 160 code | 8 blank | 11 comment | 10 complexity | 85ad6e0607b15ff50ff6ca81e7841f8a MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, MPL-2.0-no-copyleft-exception
  1. // $URL: http://mingw-lib.googlecode.com/svn/trunk/working/avcodec_to_widget_10/t_box_player_ctx.h $
  2. // $Rev: 351 $
  3. // $Author: akio.miyoshi $
  4. // $Date:: 2010-08-03 04:54:21 +0200#$
  5. #ifndef T_BOX_PLAYER_H
  6. #define T_BOX_PLAYER_H
  7. #include "stable.h"
  8. #include "t_box.h"
  9. #include "t_av_packet.h"
  10. #include "t_generator.h" //==> t_box_audio.h
  11. #include "t_box_bar.h"
  12. #include "input/t_box_input_sequence.h"
  13. #include "t_box_stream.h"
  14. class T_Box_Stream_Main : public T_Box_Stream
  15. {
  16. Q_OBJECT
  17. public:
  18. explicit T_Box_Stream_Main(T_Box_Core *a_core)
  19. : T_Box_Stream(a_core)
  20. {
  21. this->openAudio();
  22. this->openVideo();
  23. }
  24. //~T_Box_Stream_Main();
  25. //T_Box_Core *core();
  26. //bool openAudio();
  27. //bool openVideo();
  28. //T_AV_Packet *readPacket();
  29. protected:
  30. void run()
  31. {
  32. for(;;)
  33. {
  34. msleep(1);
  35. if(this->closing())
  36. {
  37. break;
  38. }
  39. T_AV_Packet *v_packet = NULL;
  40. {
  41. v_packet = this->readPacket();
  42. if(!v_packet)
  43. {
  44. this->core()->seekManager()->registerTiming(LONG_LONG_MAX);
  45. break;
  46. }
  47. this->core()->seekManager()->registerTiming(v_packet->timing());
  48. delete v_packet;
  49. }
  50. }
  51. }
  52. };
  53. struct T_Box_Stream_Info
  54. {
  55. bool isValid;
  56. int stream_index;
  57. AVCodecContext *codec_ctx;
  58. AVCodec *codec;
  59. AVStream *stream;
  60. T_AV_Packet_Queue packet_queue;
  61. explicit T_Box_Stream_Info(T_Box_Player_Context *a_player_ctx, AVMediaType a_media_type);
  62. };
  63. class T_Box_Player_Context : public QObject
  64. {
  65. Q_OBJECT
  66. public:
  67. T_Box_Input_Sequence *m_box_input;
  68. AVFormatContext *m_format_ctx;
  69. T_Box_Core m_core;
  70. T_Box_Stream_Info m_audio;
  71. T_Box_Stream_Info m_video;
  72. //T_Stopwatch m_stopwatch;
  73. QAudioOutput *m_audioOutput;
  74. T_Generator *m_generator;
  75. T_VideoProgressBar *m_seek_bar;
  76. T_BufferProgressBar *m_buffering_bar;
  77. T_AVPicture m_video_decode_buff; //FIXME
  78. T_Box_Stream_Main m_stream_main;
  79. public:
  80. explicit T_Box_Player_Context(T_Box_Input_Sequence *a_box_input, AVFormatContext *a_format_ctx);
  81. ~T_Box_Player_Context();
  82. void setAudioOutput(QAudioOutput *a_audioOutput)
  83. {
  84. m_audioOutput = a_audioOutput;
  85. }
  86. qint64 duration()
  87. {
  88. return ((qint64)1000) * this->m_format_ctx->duration / AV_TIME_BASE;
  89. }
  90. QString durationToString(const QString &a_format)
  91. {
  92. QTime v_duration_clock(0, 0, 0, 0);
  93. v_duration_clock = v_duration_clock.addMSecs(this->duration());
  94. return v_duration_clock.toString(a_format);
  95. }
  96. bool needBuffering()
  97. {
  98. #if USE_DECODE_THREAD
  99. QSharedPointer<T_AV_Packet> v_head = m_video.packet_queue.head();
  100. if(v_head && v_head->frameNo()<=T_Box::PLAYER_AHEAD_IMAGE && v_head->isDecoded())
  101. {
  102. //return false;
  103. }
  104. else
  105. {
  106. static bool v_emergency = false;
  107. if(v_emergency)
  108. {
  109. if(m_video.packet_queue.decodedCount(T_Box::PLAYER_IMAGE_STOCK)<T_Box::PLAYER_IMAGE_STOCK)
  110. {
  111. return true;
  112. }
  113. }
  114. v_emergency = false;
  115. if(m_video.packet_queue.decodedCount(T_Box::PLAYER_AHEAD_IMAGE)<T_Box::PLAYER_AHEAD_IMAGE)
  116. {
  117. v_emergency = true;
  118. return true;
  119. }
  120. }
  121. #endif
  122. if(m_video.packet_queue.duration(this->timeline()->elapsed())<T_Box::PLAYER_BUFFER_TIME)
  123. {
  124. return true;
  125. }
  126. return false;
  127. }
  128. T_Box_Seek_Manager *seekManager()
  129. {
  130. return m_core.seekManager();
  131. }
  132. T_Stopwatch *timeline()
  133. {
  134. return m_core.timeline();
  135. }
  136. void start();
  137. void finish();
  138. bool handleSeek(bool decodeVideo = false);
  139. protected:
  140. qint64 seek(qint64 a_msec, bool decodeVideo = false);
  141. T_AV_Packet *readPacket();
  142. T_AV_Packet *enqueuePacket(bool decodeVideo = false);
  143. protected:
  144. friend class T_Box_Player_Packet_Thread;
  145. friend class T_Box_Player_Decode_Thread;
  146. class T_Box_Player_Packet_Thread *m_packet_thread;
  147. class T_Box_Player_Decode_Thread *m_decode_thread;
  148. };
  149. class T_Box_Player_Packet_Thread : public T_Box_Thread
  150. {
  151. public:
  152. explicit T_Box_Player_Packet_Thread(T_Box_Player_Context *a_player_ctx)
  153. : m_player_ctx(a_player_ctx)
  154. {
  155. }
  156. protected:
  157. virtual void run();
  158. T_Box_Player_Context *m_player_ctx;
  159. };
  160. class T_Box_Player_Decode_Thread : public T_Box_Thread
  161. {
  162. public:
  163. explicit T_Box_Player_Decode_Thread(T_Box_Player_Context *a_player_ctx)
  164. : m_player_ctx(a_player_ctx)
  165. {
  166. }
  167. protected:
  168. virtual void run();
  169. T_Box_Player_Context *m_player_ctx;
  170. };
  171. #endif // T_BOX_PLAYER_H