subtitle_decode_thread.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. #include "subtitle_decode_thread.h"
  3. #include <QLoggingCategory>
  4. Q_LOGGING_CATEGORY(playerControllerSubtitleDecodeThread, "player.controller.SubtitleDecodeThread")
  5. SubtitleDecodeThread::SubtitleDecodeThread(VideoState* pState)
  6. : m_pState(pState)
  7. {
  8. }
  9. SubtitleDecodeThread::~SubtitleDecodeThread()
  10. {
  11. }
  12. void SubtitleDecodeThread::run()
  13. {
  14. assert(m_pState);
  15. VideoState* is = m_pState;
  16. Frame* sp;
  17. int got_subtitle;
  18. double pts = 0;
  19. for (;;)
  20. {
  21. if (isExit())
  22. break;
  23. if (!(sp = frame_queue_peek_writable(&is->subpq)))
  24. return;
  25. if ((got_subtitle = decoder_decode_frame(&is->subdec, nullptr, &sp->sub)) < 0)
  26. break;
  27. pts = 0;
  28. if (got_subtitle && sp->sub.format == 1)
  29. {
  30. if (sp->sub.pts != AV_NOPTS_VALUE)
  31. pts = sp->sub.pts / (double)AV_TIME_BASE;
  32. sp->pts = pts;
  33. sp->serial = is->subdec.pkt_serial;
  34. sp->width = is->subdec.avctx->width;
  35. sp->height = is->subdec.avctx->height;
  36. sp->uploaded = 0;
  37. /* now we can update the picture count */
  38. frame_queue_push(&is->subpq);
  39. }
  40. else if (got_subtitle)
  41. {
  42. // qWarning("Not handled subtitle type:%d", sp->sub.format);
  43. avsubtitle_free(&sp->sub);
  44. }
  45. }
  46. // 可加日志输出
  47. return;
  48. }