subtitle_decode_thread.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // ***********************************************************/
  2. // subtitle_decode_thread.cpp
  3. //
  4. // Copy Right @ Steven Huang. All rights reserved.
  5. //
  6. // Subtitles decode thread.
  7. // ***********************************************************/
  8. #include "subtitle_decode_thread.h"
  9. SubtitleDecodeThread::SubtitleDecodeThread(QObject* parent, VideoState* pState)
  10. : QThread(parent), m_pState(pState)
  11. {
  12. }
  13. SubtitleDecodeThread::~SubtitleDecodeThread()
  14. {
  15. }
  16. void SubtitleDecodeThread::run()
  17. {
  18. assert(m_pState);
  19. VideoState* is = m_pState;
  20. Frame* sp;
  21. int got_subtitle;
  22. double pts = 0;
  23. for (;;)
  24. {
  25. if (!(sp = frame_queue_peek_writable(&is->subpq)))
  26. return;
  27. if ((got_subtitle = decoder_decode_frame(&is->subdec, nullptr, &sp->sub)) <
  28. 0)
  29. break;
  30. pts = 0;
  31. if (got_subtitle && sp->sub.format == 1)
  32. {
  33. if (sp->sub.pts != AV_NOPTS_VALUE)
  34. pts = sp->sub.pts / (double)AV_TIME_BASE;
  35. sp->pts = pts;
  36. sp->serial = is->subdec.pkt_serial;
  37. sp->width = is->subdec.avctx->width;
  38. sp->height = is->subdec.avctx->height;
  39. sp->uploaded = 0;
  40. /* now we can update the picture count */
  41. frame_queue_push(&is->subpq);
  42. }
  43. else if (got_subtitle)
  44. {
  45. qWarning("Not handled subtitle type:%d", sp->sub.format);
  46. avsubtitle_free(&sp->sub);
  47. }
  48. }
  49. qDebug("-------- subtitle decode thread exit.");
  50. return;
  51. }