|
|
@@ -8,6 +8,8 @@
|
|
|
|
|
|
#include "read_thread.h"
|
|
|
#include "AVPlayer2/playercontroller.h"
|
|
|
+#include <QLoggingCategory>
|
|
|
+Q_LOGGING_CATEGORY(playerControllerReadThread, "player.controller.ReadThread")
|
|
|
|
|
|
extern int infinite_buffer;
|
|
|
extern int64_t start_time;
|
|
|
@@ -16,12 +18,12 @@ static int64_t duration = AV_NOPTS_VALUE;
|
|
|
ReadThread::ReadThread(VideoState* pState)
|
|
|
: m_pPlayData(pState)
|
|
|
{
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] constructed, pState:" << (void*)pState;
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] constructed, pState:" << (void*) pState;
|
|
|
}
|
|
|
|
|
|
ReadThread::~ReadThread()
|
|
|
{
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] destructed.";
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] destructed.";
|
|
|
stop();
|
|
|
join();
|
|
|
}
|
|
|
@@ -53,21 +55,22 @@ int ReadThread::loop_read()
|
|
|
if (!pkt) {
|
|
|
av_log(nullptr, AV_LOG_FATAL, "Could not allocate packet.\n");
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
- qCWarning(playerControllerLog) << "[ReadThread] av_packet_alloc failed!";
|
|
|
+ qCWarning(playerControllerReadThread) << "[ReadThread] av_packet_alloc failed!";
|
|
|
return ret;
|
|
|
}
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] loop_read start, file:" << (is && is->ic ? is->ic->url : "null");
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] loop_read start, file:"
|
|
|
+ << (is && is->ic ? is->ic->url : "null");
|
|
|
|
|
|
is->read_thread_exit = 0;
|
|
|
|
|
|
for (;;) {
|
|
|
- if (m_exit) {
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] m_exit set, break.";
|
|
|
+ if (m_exit && *m_exit) {
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] m_exit set, break.";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if (is->abort_request) {
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] abort_request set, break.";
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] abort_request set, break.";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
@@ -80,7 +83,9 @@ int ReadThread::loop_read()
|
|
|
}
|
|
|
|
|
|
if (is->seek_req) {
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] seek_req, seek_pos:" << is->seek_pos << ", seek_rel:" << is->seek_rel << ", seek_flags:" << is->seek_flags;
|
|
|
+ qCDebug(playerControllerReadThread)
|
|
|
+ << "[ReadThread] seek_req, seek_pos:" << is->seek_pos
|
|
|
+ << ", seek_rel:" << is->seek_rel << ", seek_flags:" << is->seek_flags;
|
|
|
int64_t seek_target = is->seek_pos;
|
|
|
int64_t seek_min = is->seek_rel > 0 ? seek_target - is->seek_rel + 2 : INT64_MIN;
|
|
|
int64_t seek_max = is->seek_rel < 0 ? seek_target - is->seek_rel - 2 : INT64_MAX;
|
|
|
@@ -88,9 +93,11 @@ int ReadThread::loop_read()
|
|
|
ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, is->seek_flags);
|
|
|
if (ret < 0) {
|
|
|
av_log(nullptr, AV_LOG_ERROR, "%s: error while seeking\n", is->ic->url);
|
|
|
- qCWarning(playerControllerLog) << "[ReadThread] avformat_seek_file failed, ret:" << ret;
|
|
|
+ qCWarning(playerControllerReadThread)
|
|
|
+ << "[ReadThread] avformat_seek_file failed, ret:" << ret;
|
|
|
} else {
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] avformat_seek_file success, flush queues.";
|
|
|
+ qCDebug(playerControllerReadThread)
|
|
|
+ << "[ReadThread] avformat_seek_file success, flush queues.";
|
|
|
if (is->audio_stream >= 0)
|
|
|
packet_queue_flush(&is->audioq);
|
|
|
if (is->subtitle_stream >= 0)
|
|
|
@@ -111,7 +118,8 @@ int ReadThread::loop_read()
|
|
|
}
|
|
|
|
|
|
if (is->queue_attachments_req) {
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] queue_attachments_req, video_st:" << (void*)is->video_st;
|
|
|
+ qCDebug(playerControllerReadThread)
|
|
|
+ << "[ReadThread] queue_attachments_req, video_st:" << (void*) is->video_st;
|
|
|
if (is->video_st && is->video_st->disposition & AV_DISPOSITION_ATTACHED_PIC) {
|
|
|
ret = av_packet_ref(pkt, &is->video_st->attached_pic);
|
|
|
if (ret < 0)
|
|
|
@@ -130,7 +138,7 @@ int ReadThread::loop_read()
|
|
|
&& stream_has_enough_packets(is->subtitle_st,
|
|
|
is->subtitle_stream,
|
|
|
&is->subtitleq)))) {
|
|
|
- qCDebug(playerControllerLog)
|
|
|
+ qCDebug(playerControllerReadThread)
|
|
|
<< "[ReadThread] queues full, waiting... audioq:" << is->audioq.size
|
|
|
<< ", videoq:" << is->videoq.size << ", subtitleq:" << is->subtitleq.size;
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
@@ -140,9 +148,11 @@ int ReadThread::loop_read()
|
|
|
|
|
|
ret = av_read_frame(is->ic, pkt);
|
|
|
if (ret < 0) {
|
|
|
- qCWarning(playerControllerLog) << "[ReadThread] av_read_frame failed, ret:" << ret << ", eof:" << is->eof << ", pb_error:" << (is->ic->pb ? is->ic->pb->error : 0);
|
|
|
+ qCWarning(playerControllerReadThread)
|
|
|
+ << "[ReadThread] av_read_frame failed, ret:" << ret << ", eof:" << is->eof
|
|
|
+ << ", pb_error:" << (is->ic->pb ? is->ic->pb->error : 0);
|
|
|
if ((ret == AVERROR_EOF || avio_feof(is->ic->pb)) && !is->eof) {
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] EOF reached, send null packets.";
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] EOF reached, send null packets.";
|
|
|
if (is->video_stream >= 0)
|
|
|
packet_queue_put_nullpacket(&is->videoq, pkt, is->video_stream);
|
|
|
if (is->audio_stream >= 0)
|
|
|
@@ -158,7 +168,7 @@ int ReadThread::loop_read()
|
|
|
}
|
|
|
}
|
|
|
if (is->ic->pb && is->ic->pb->error) {
|
|
|
- qCWarning(playerControllerLog) << "[ReadThread] IO error detected.";
|
|
|
+ qCWarning(playerControllerReadThread) << "[ReadThread] IO error detected.";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
@@ -167,7 +177,9 @@ int ReadThread::loop_read()
|
|
|
continue;
|
|
|
} else {
|
|
|
is->eof = 0;
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] av_read_frame success, stream_index:" << pkt->stream_index << ", pts:" << pkt->pts;
|
|
|
+ qCDebug(playerControllerReadThread)
|
|
|
+ << "[ReadThread] av_read_frame success, stream_index:" << pkt->stream_index
|
|
|
+ << ", pts:" << pkt->pts;
|
|
|
}
|
|
|
|
|
|
/* check if packet is in play range specified by user, then queue, otherwise
|
|
|
@@ -182,23 +194,27 @@ int ReadThread::loop_read()
|
|
|
/ 1000000
|
|
|
<= ((double) duration / 1000000);
|
|
|
if (pkt->stream_index == is->audio_stream && pkt_in_play_range) {
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] put audio packet, pts:" << pkt->pts;
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] put audio packet, pts:" << pkt->pts;
|
|
|
packet_queue_put(&is->audioq, pkt);
|
|
|
} else if (pkt->stream_index == is->video_stream && pkt_in_play_range
|
|
|
&& !(is->video_st->disposition & AV_DISPOSITION_ATTACHED_PIC)) {
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] put video packet, pts:" << pkt->pts;
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] put video packet, pts:" << pkt->pts;
|
|
|
packet_queue_put(&is->videoq, pkt);
|
|
|
} else if (pkt->stream_index == is->subtitle_stream && pkt_in_play_range) {
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] put subtitle packet, pts:" << pkt->pts;
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] put subtitle packet, pts:" << pkt->pts;
|
|
|
packet_queue_put(&is->subtitleq, pkt);
|
|
|
} else {
|
|
|
- qCDebug(playerControllerLog)
|
|
|
+ qCDebug(playerControllerReadThread)
|
|
|
<< "[ReadThread] drop packet, stream_index:" << pkt->stream_index;
|
|
|
av_packet_unref(pkt);
|
|
|
}
|
|
|
}
|
|
|
- qCWarning(playerControllerLog) << "[ReadThread] loop_read about to exit, eof:" << is->eof << ", audioq.size:" << is->audioq.size << ", videoq.size:" << is->videoq.size << ", subtitleq.size:" << is->subtitleq.size << ", abort_request:" << is->abort_request << ", m_exit:" << m_exit;
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] loop_read exit, set read_thread_exit = -1";
|
|
|
+ qCWarning(playerControllerReadThread)
|
|
|
+ << "[ReadThread] loop_read about to exit, eof:" << is->eof
|
|
|
+ << ", audioq.size:" << is->audioq.size << ", videoq.size:" << is->videoq.size
|
|
|
+ << ", subtitleq.size:" << is->subtitleq.size << ", abort_request:" << is->abort_request
|
|
|
+ << ", m_exit:" << (m_exit ? m_exit->load() : -1);
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] loop_read exit, set read_thread_exit = -1";
|
|
|
is->read_thread_exit = -1;
|
|
|
av_packet_free(&pkt);
|
|
|
return 0;
|
|
|
@@ -206,8 +222,8 @@ int ReadThread::loop_read()
|
|
|
|
|
|
void ReadThread::run()
|
|
|
{
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] run start";
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] run start";
|
|
|
int ret = loop_read();
|
|
|
- qCDebug(playerControllerLog) << "[ReadThread] run end, loop_read ret:" << ret;
|
|
|
+ qCDebug(playerControllerReadThread) << "[ReadThread] run end, loop_read ret:" << ret;
|
|
|
// 可加日志输出
|
|
|
}
|