|
|
@@ -2,11 +2,7 @@
|
|
|
#include <QLoggingCategory>
|
|
|
#include "AVPlayer2/playercontroller.h"
|
|
|
|
|
|
-#define debug 0
|
|
|
-
|
|
|
-#if debug
|
|
|
Q_LOGGING_CATEGORY(playerControllerAudioDecodeThread, "player.controller.AudioDecodeThread")
|
|
|
-#endif
|
|
|
|
|
|
AudioDecodeThread::AudioDecodeThread(VideoState* pState)
|
|
|
: m_pState(pState)
|
|
|
@@ -14,19 +10,17 @@ AudioDecodeThread::AudioDecodeThread(VideoState* pState)
|
|
|
|
|
|
AudioDecodeThread::~AudioDecodeThread()
|
|
|
{
|
|
|
-#if debug
|
|
|
qCDebug(playerControllerAudioDecodeThread)
|
|
|
<< "[AudioDecodeThread] ~AudioDecodeThread, m_pState:" << (void*) m_pState;
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
void AudioDecodeThread::run()
|
|
|
{
|
|
|
- //qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] run start, m_pState:" << (void*) m_pState;
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] run start, m_pState:" << (void*) m_pState;
|
|
|
assert(m_pState);
|
|
|
VideoState* is = m_pState;
|
|
|
- // qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] VideoState* is:" << (void*) is
|
|
|
- // << ", abort_request:" << is->abort_request;
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] VideoState* is:" << (void*) is
|
|
|
+ << ", abort_request:" << is->abort_request;
|
|
|
AVFrame* frame = av_frame_alloc();
|
|
|
Frame* af;
|
|
|
#if USE_AVFILTER_AUDIO
|
|
|
@@ -39,31 +33,35 @@ void AudioDecodeThread::run()
|
|
|
int ret = 0;
|
|
|
|
|
|
if (!frame) {
|
|
|
- //qCWarning(playerControllerAudioDecodeThread) << "[AudioDecodeThread] av_frame_alloc failed!";
|
|
|
+ qCWarning(playerControllerAudioDecodeThread) << "[AudioDecodeThread] av_frame_alloc failed!";
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] Starting decode loop";
|
|
|
|
|
|
do {
|
|
|
if (is->abort_request) {
|
|
|
- //qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] abort_request set, exit.";
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] abort_request set, exit.";
|
|
|
break;
|
|
|
}
|
|
|
if (isExit()) {
|
|
|
- // qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] m_exit set, exit.";
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] m_exit set, exit.";
|
|
|
break;
|
|
|
}
|
|
|
- // qCDebug(playerControllerAudioDecodeThread)
|
|
|
- // << "[AudioDecodeThread] call decoder_decode_frame, auddec.avctx:"
|
|
|
- // << (void*) is->auddec.avctx;
|
|
|
+ qCDebug(playerControllerAudioDecodeThread)
|
|
|
+ << "[AudioDecodeThread] call decoder_decode_frame, auddec.avctx:"
|
|
|
+ << (void*) is->auddec.avctx;
|
|
|
if ((got_frame = decoder_decode_frame(&is->auddec, frame, nullptr)) < 0) {
|
|
|
- // qCWarning(playerControllerAudioDecodeThread)
|
|
|
- // << "[AudioDecodeThread] decoder_decode_frame failed, ret:" << got_frame;
|
|
|
+ qCWarning(playerControllerAudioDecodeThread)
|
|
|
+ << "[AudioDecodeThread] decoder_decode_frame failed, ret:" << got_frame;
|
|
|
goto the_end;
|
|
|
}
|
|
|
if (got_frame) {
|
|
|
- // qCDebug(playerControllerAudioDecodeThread)
|
|
|
- // << "[AudioDecodeThread] got audio frame, pts:" << frame->pts
|
|
|
- // << ", sample_rate:" << frame->sample_rate << ", nb_samples:" << frame->nb_samples;
|
|
|
+ qCDebug(playerControllerAudioDecodeThread)
|
|
|
+ << "[AudioDecodeThread] got audio frame, pts:" << frame->pts
|
|
|
+ << ", sample_rate:" << frame->sample_rate << ", nb_samples:" << frame->nb_samples
|
|
|
+ << ", format:" << av_get_sample_fmt_name(AVSampleFormat(frame->format))
|
|
|
+ << ", channels:" << frame->ch_layout.nb_channels;
|
|
|
tb = AVRational{1, frame->sample_rate};
|
|
|
|
|
|
#if USE_AVFILTER_AUDIO
|
|
|
@@ -111,11 +109,15 @@ void AudioDecodeThread::run()
|
|
|
is->req_afilter_reconfigure = 0;
|
|
|
}
|
|
|
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] adding frame to audio filter";
|
|
|
ret = av_buffersrc_add_frame(is->in_audio_filter, frame);
|
|
|
- if (ret < 0)
|
|
|
+ if (ret < 0) {
|
|
|
+ qCWarning(playerControllerAudioDecodeThread) << "[AudioDecodeThread] av_buffersrc_add_frame failed, ret:" << ret;
|
|
|
goto the_end;
|
|
|
+ }
|
|
|
|
|
|
while ((ret = av_buffersink_get_frame_flags(is->out_audio_filter, frame, 0)) >= 0) {
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] got filtered audio frame";
|
|
|
tb = av_buffersink_get_time_base(is->out_audio_filter);
|
|
|
#endif
|
|
|
|
|
|
@@ -127,6 +129,9 @@ void AudioDecodeThread::run()
|
|
|
af->serial = is->auddec.pkt_serial;
|
|
|
af->duration = av_q2d(AVRational{frame->nb_samples, frame->sample_rate});
|
|
|
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] pushing audio frame to queue, pts:" << af->pts
|
|
|
+ << ", duration:" << af->duration << ", serial:" << af->serial;
|
|
|
+
|
|
|
av_frame_move_ref(af->frame, frame);
|
|
|
frame_queue_push(&is->sampq);
|
|
|
|
|
|
@@ -134,11 +139,13 @@ void AudioDecodeThread::run()
|
|
|
if (is->audioq.serial != is->auddec.pkt_serial)
|
|
|
break;
|
|
|
}
|
|
|
- if (ret == AVERROR_EOF)
|
|
|
+ if (ret == AVERROR_EOF) {
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] audio filter EOF, marking decoder finished";
|
|
|
is->auddec.finished = is->auddec.pkt_serial;
|
|
|
+ }
|
|
|
#endif
|
|
|
} else {
|
|
|
- //qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] no frame decoded, continue.";
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] no frame decoded, continue.";
|
|
|
}
|
|
|
} while (got_frame);
|
|
|
|
|
|
@@ -153,9 +160,9 @@ the_end:
|
|
|
#endif
|
|
|
|
|
|
av_frame_free(&frame);
|
|
|
- // 可加日志输出
|
|
|
- // qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] run end, abort_request:"
|
|
|
- // << is->abort_request
|
|
|
- // << ", m_exit:" << (m_exit ? m_exit->load() : -1);
|
|
|
+ qCDebug(playerControllerAudioDecodeThread) << "[AudioDecodeThread] run end, abort_request:"
|
|
|
+ << is->abort_request
|
|
|
+ << ", m_exit:" << (m_exit ? m_exit->load() : -1)
|
|
|
+ << ", total frames processed in this session";
|
|
|
return;
|
|
|
}
|