From df17e48129b3854bde84c9987c9ff32378934182 Mon Sep 17 00:00:00 2001 From: Mozi <29089388+pzhlkj6612@users.noreply.github.com> Date: Tue, 28 Jan 2020 22:53:43 +0800 Subject: [PATCH] Avoid `unref` the packet if no packet got Patch for 0175326182c6d4e284cd23c657480e6bbf18b896 `av_packet_unref()` the uninitialized AVPacket will crash the program on macOS and Ubuntu. --- Entities/MusicPlayer/musicPlayer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Entities/MusicPlayer/musicPlayer.cpp b/Entities/MusicPlayer/musicPlayer.cpp index e3d2c703..e50bb733 100644 --- a/Entities/MusicPlayer/musicPlayer.cpp +++ b/Entities/MusicPlayer/musicPlayer.cpp @@ -148,14 +148,18 @@ int PlayThread::audio_decode_frame(mediaState* MS, uint8_t* audio_buf) int returns = -1; //除非音频解码成功返回音频数据,否则返回 -1 + if (packet_queue_get(&MS->audioq, &packet, 0) < 0) + { + qDebug()<<"PlayThread::audio_decode_frame: no packet got"; + return returns; + } + + while (true) { - if (packet_queue_get(&MS->audioq, &packet, 0) < 0) - { - break; - } if (packet.pts == AV_NOPTS_VALUE) { + // useless ? break; }