start_play_thread.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // ***********************************************************/
  2. // start_play_thread.cpp
  3. //
  4. // Copy Right @ Steven Huang. All rights reserved.
  5. //
  6. // start play thread. Do the audio device initialization work
  7. // which is time-consuming to avoid GUI freezing.
  8. // ***********************************************************/
  9. #include "start_play_thread.h"
  10. #include "AVPlayer2/video_state.h"
  11. #include "playercontroller.h"
  12. StartPlayThread::StartPlayThread(PlayerController* playerController, QObject* parent)
  13. : QThread(parent)
  14. , m_playerController(playerController)
  15. {}
  16. StartPlayThread::~StartPlayThread() {}
  17. void StartPlayThread::run()
  18. {
  19. assert(m_playerController);
  20. bool ret = false;
  21. #if !NDEBUG
  22. QElapsedTimer timer;
  23. timer.start();
  24. #endif
  25. float vol = 1.0;
  26. //pParent->volume_settings(false);
  27. AVSampleFormat sample_fmt = AV_SAMPLE_FMT_S16; // play out format
  28. VideoStateData* pVideoStateData = m_playerController->videoStateData();
  29. if (pVideoStateData) {
  30. AVCodecContext* pAudio = pVideoStateData->get_contex(AVMEDIA_TYPE_AUDIO);
  31. VideoState* pState = pVideoStateData->get_state();
  32. if (pAudio) {
  33. AudioPlayThread* pThread = m_playerController->audioPlayThread();
  34. if (pThread) {
  35. ret = pThread->init_device(pAudio->sample_rate,
  36. pAudio->ch_layout.nb_channels,
  37. sample_fmt,
  38. vol); // pAudio->sample_fmt
  39. if (!ret) {
  40. qWarning("audio play init_device failed.");
  41. }
  42. if (ret) {
  43. ret = pThread->init_resample_param(pAudio, sample_fmt, pState);
  44. if (!ret) {
  45. qWarning("audio play init resample param failed.");
  46. }
  47. }
  48. }
  49. }
  50. }
  51. emit audio_device_init(ret);
  52. #if !NDEBUG
  53. qDebug("Start play operation took %d milliseconds", timer.elapsed());
  54. #endif
  55. qDebug("-------- start play thread(audio device initial) exit,ret=%d.", ret);
  56. }