subtitle_decode_thread.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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::run()
  19. {
  20. assert(m_pState);
  21. VideoState* is = m_pState;
  22. Frame* sp;
  23. int got_subtitle;
  24. double pts = 0;
  25. for (;;)
  26. {
  27. if (isExit())
  28. break;
  29. if (!(sp = frame_queue_peek_writable(&is->subpq)))
  30. return;
  31. if ((got_subtitle = decoder_decode_frame(&is->subdec, nullptr, &sp->sub)) < 0)
  32. break;
  33. pts = 0;
  34. if (got_subtitle && sp->sub.format == 1)
  35. {
  36. if (sp->sub.pts != AV_NOPTS_VALUE)
  37. pts = sp->sub.pts / (double)AV_TIME_BASE;
  38. sp->pts = pts;
  39. sp->serial = is->subdec.pkt_serial;
  40. sp->width = is->subdec.avctx->width;
  41. sp->height = is->subdec.avctx->height;
  42. sp->uploaded = 0;
  43. /* now we can update the picture count */
  44. frame_queue_push(&is->subpq);
  45. }
  46. else if (got_subtitle)
  47. {
  48. // qWarning("Not handled subtitle type:%d", sp->sub.format);
  49. avsubtitle_free(&sp->sub);
  50. }
  51. }
  52. // 可加日志输出
  53. return;
  54. }