start_play_thread.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "playercontroller.h"
  11. StartPlayThread::StartPlayThread(QObject* parent)
  12. : QThread(parent)
  13. {}
  14. StartPlayThread::~StartPlayThread() {}
  15. void StartPlayThread::run()
  16. {
  17. PlayerController* pParent = (PlayerController*) parent();
  18. assert(pParent);
  19. bool ret = false;
  20. #if !NDEBUG
  21. QElapsedTimer timer;
  22. timer.start();
  23. #endif
  24. float vol = 1.0;
  25. //pParent->volume_settings(false);
  26. AVSampleFormat sample_fmt = AV_SAMPLE_FMT_S16; // play out format
  27. VideoStateData* pVideoStateData = pParent->videoStateData();
  28. if (pVideoStateData) {
  29. AVCodecContext* pAudio = pVideoStateData->get_contex(AVMEDIA_TYPE_AUDIO);
  30. VideoState* pState = pVideoStateData->get_state();
  31. if (pAudio) {
  32. AudioPlayThread* pThread = pParent->audioPlayThread();
  33. if (pThread) {
  34. ret = pThread->init_device(pAudio->sample_rate,
  35. pAudio->ch_layout.nb_channels,
  36. sample_fmt,
  37. vol); // pAudio->sample_fmt
  38. if (!ret) {
  39. qWarning("audio play init_device failed.");
  40. }
  41. if (ret) {
  42. ret = pThread->init_resample_param(pAudio, sample_fmt, pState);
  43. if (!ret) {
  44. qWarning("audio play init resample param failed.");
  45. }
  46. }
  47. }
  48. }
  49. }
  50. emit audio_device_init(ret);
  51. #if !NDEBUG
  52. qDebug("Start play operation took %d milliseconds", timer.elapsed());
  53. #endif
  54. qDebug("-------- start play thread(audio device initial) exit,ret=%d.", ret);
  55. }