subtitle_decode_thread.cpp 1.6 KB

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