subtitle_decode_thread.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include <QLoggingCategory>
  10. Q_LOGGING_CATEGORY(playerControllerSubtitleDecodeThread, "player.controller.SubtitleDecodeThread")
  11. SubtitleDecodeThread::SubtitleDecodeThread(VideoState* pState)
  12. : m_pState(pState)
  13. {
  14. }
  15. SubtitleDecodeThread::~SubtitleDecodeThread()
  16. {
  17. }
  18. void SubtitleDecodeThread::stop()
  19. {
  20. *m_exit = true;
  21. m_cv.notify_all();
  22. }
  23. void SubtitleDecodeThread::run()
  24. {
  25. assert(m_pState);
  26. VideoState* is = m_pState;
  27. Frame* sp;
  28. int got_subtitle;
  29. double pts = 0;
  30. for (;;)
  31. {
  32. if (m_exit && *m_exit)
  33. break;
  34. if (!(sp = frame_queue_peek_writable(&is->subpq)))
  35. return;
  36. if ((got_subtitle = decoder_decode_frame(&is->subdec, nullptr, &sp->sub)) < 0)
  37. break;
  38. pts = 0;
  39. if (got_subtitle && sp->sub.format == 1)
  40. {
  41. if (sp->sub.pts != AV_NOPTS_VALUE)
  42. pts = sp->sub.pts / (double)AV_TIME_BASE;
  43. sp->pts = pts;
  44. sp->serial = is->subdec.pkt_serial;
  45. sp->width = is->subdec.avctx->width;
  46. sp->height = is->subdec.avctx->height;
  47. sp->uploaded = 0;
  48. /* now we can update the picture count */
  49. frame_queue_push(&is->subpq);
  50. }
  51. else if (got_subtitle)
  52. {
  53. // qWarning("Not handled subtitle type:%d", sp->sub.format);
  54. avsubtitle_free(&sp->sub);
  55. }
  56. }
  57. // 可加日志输出
  58. return;
  59. }