start_play_thread.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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(QObject* parent)
  13. : QThread(parent)
  14. {}
  15. StartPlayThread::~StartPlayThread() {}
  16. void StartPlayThread::run()
  17. {
  18. PlayerController* pParent = (PlayerController*) parent();
  19. assert(pParent);
  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 = pParent->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 = pParent->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. }