From 876a736ae631fdc5c43c37ed1d9a358df0161301 Mon Sep 17 00:00:00 2001 From: kszaq Date: Mon, 2 Oct 2017 22:06:50 +0200 Subject: DVDVideoCodecAmlogic: remove pts-based frame rate tracking In most cases frame tracking based on pts provided by amcodec is wrong, causing unnecessary frame rate switch. We can simply rely on frame rate provided by ffmpeg. --- .../DVDCodecs/Video/DVDVideoCodecAmlogic.cpp | 64 ---------------------- .../DVDCodecs/Video/DVDVideoCodecAmlogic.h | 1 - 2 files changed, 65 deletions(-) diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp index 1e5dd5a164..10f954bd04 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp @@ -85,7 +85,6 @@ CDVDVideoCodecAmlogic::CDVDVideoCodecAmlogic(CProcessInfo &processInfo) , m_pFormatName("amcodec") , m_opened(false) , m_codecControlFlags(0) - , m_last_pts(0.0) , m_frame_queue(NULL) , m_queue_depth(0) , m_framerate(0.0) @@ -566,69 +565,6 @@ void CDVDVideoCodecAmlogic::FrameRateTracking(uint8_t *pData, int iSize, double pthread_mutex_unlock(&m_queue_mutex); - float duration = cur_pts - m_last_pts; - m_last_pts = cur_pts; - - // clamp duration to sensible range, - // 66 fsp to 20 fsp - if (duration >= 15000.0 && duration <= 50000.0) - { - double framerate; - switch((int)(0.5 + duration)) - { - // 59.940 (16683.333333) - case 16000 ... 17000: - framerate = 60000.0 / 1001.0; - break; - - // 50.000 (20000.000000) - case 20000: - framerate = 50000.0 / 1000.0; - break; - - // 49.950 (20020.000000) - case 20020: - framerate = 50000.0 / 1001.0; - break; - - // 29.970 (33366.666656) - case 32000 ... 35000: - framerate = 30000.0 / 1001.0; - break; - - // 25.000 (40000.000000) - case 39900 ... 40100: - framerate = 25000.0 / 1000.0; - break; - - // 23.976 (41708.33333) - case 40200 ... 43200: - // 23.976 seems to have the crappiest encodings :) - framerate = 24000.0 / 1001.0; - break; - - default: - framerate = 0.0; - //CLog::Log(LOGDEBUG, "%s: unknown duration(%f), cur_pts(%f)", - // __MODULE_NAME__, duration, cur_pts); - break; - } - - if (framerate > 0.0 && (int)m_framerate != (int)framerate) - { - m_framerate = framerate; - m_video_rate = (int)(0.5 + (96000.0 / framerate)); - - if (m_Codec) - m_Codec->SetVideoRate(m_video_rate); - - m_processInfo.SetVideoFps(m_framerate); - - CLog::Log(LOGDEBUG, "%s: detected new framerate(%f), video_rate(%d)", - __MODULE_NAME__, m_framerate, m_video_rate); - } - } - FrameQueuePop(); } } diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h index ee0775f15c..031be1b880 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h @@ -100,7 +100,6 @@ protected: bool m_opened; int m_codecControlFlags; CDVDStreamInfo m_hints; - double m_last_pts; frame_queue *m_frame_queue; int32_t m_queue_depth; pthread_mutex_t m_queue_mutex; -- cgit v1.2.3 From 064704a9ac156b2f485471e62a6acb72eebbf2ce Mon Sep 17 00:00:00 2001 From: kszaq Date: Sun, 11 Feb 2018 21:42:19 +0100 Subject: DVDVideoCodecAmlogic: remove frame queue After removing pts-based framerate tracking the queue is useless. --- .../DVDCodecs/Video/DVDVideoCodecAmlogic.cpp | 97 ---------------------- .../DVDCodecs/Video/DVDVideoCodecAmlogic.h | 6 -- 2 files changed, 103 deletions(-) diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp index 10f954bd04..7fa9dcbeb1 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp @@ -73,20 +73,11 @@ void CAMLVideoBufferPool::Return(int id) /***************************************************************************/ -typedef struct frame_queue { - double dts; - double pts; - double sort_time; - struct frame_queue *nextframe; -} frame_queue; - CDVDVideoCodecAmlogic::CDVDVideoCodecAmlogic(CProcessInfo &processInfo) : CDVDVideoCodec(processInfo) , m_pFormatName("amcodec") , m_opened(false) , m_codecControlFlags(0) - , m_frame_queue(NULL) - , m_queue_depth(0) , m_framerate(0.0) , m_video_rate(0) , m_mpeg2_sequence(NULL) @@ -94,13 +85,11 @@ CDVDVideoCodecAmlogic::CDVDVideoCodecAmlogic(CProcessInfo &processInfo) , m_bitparser(NULL) , m_bitstream(NULL) { - pthread_mutex_init(&m_queue_mutex, NULL); } CDVDVideoCodecAmlogic::~CDVDVideoCodecAmlogic() { Dispose(); - pthread_mutex_destroy(&m_queue_mutex); } CDVDVideoCodec* CDVDVideoCodecAmlogic::Create(CProcessInfo &processInfo) @@ -332,9 +321,6 @@ void CDVDVideoCodecAmlogic::Dispose(void) if (m_bitparser) delete m_bitparser, m_bitparser = NULL; - while (m_queue_depth) - FrameQueuePop(); - m_opened = false; } @@ -392,9 +378,6 @@ bool CDVDVideoCodecAmlogic::AddData(const DemuxPacket &packet) void CDVDVideoCodecAmlogic::Reset(void) { - while (m_queue_depth) - FrameQueuePop(); - m_Codec->Reset(); m_mpeg2_sequence_pts = 0; m_has_keyframe = false; @@ -460,68 +443,6 @@ void CDVDVideoCodecAmlogic::SetSpeed(int iSpeed) m_Codec->SetSpeed(iSpeed); } -void CDVDVideoCodecAmlogic::FrameQueuePop(void) -{ - if (!m_frame_queue || m_queue_depth == 0) - return; - - pthread_mutex_lock(&m_queue_mutex); - // pop the top frame off the queue - frame_queue *top = m_frame_queue; - m_frame_queue = top->nextframe; - m_queue_depth--; - pthread_mutex_unlock(&m_queue_mutex); - - // and release it - free(top); -} - -void CDVDVideoCodecAmlogic::FrameQueuePush(double dts, double pts) -{ - frame_queue *newframe = (frame_queue*)calloc(sizeof(frame_queue), 1); - newframe->dts = dts; - newframe->pts = pts; - // if both dts or pts are good we use those, else use decoder insert time for frame sort - if ((newframe->pts != DVD_NOPTS_VALUE) || (newframe->dts != DVD_NOPTS_VALUE)) - { - // if pts is borked (stupid avi's), use dts for frame sort - if (newframe->pts == DVD_NOPTS_VALUE) - newframe->sort_time = newframe->dts; - else - newframe->sort_time = newframe->pts; - } - - pthread_mutex_lock(&m_queue_mutex); - frame_queue *queueWalker = m_frame_queue; - if (!queueWalker || (newframe->sort_time < queueWalker->sort_time)) - { - // we have an empty queue, or this frame earlier than the current queue head. - newframe->nextframe = queueWalker; - m_frame_queue = newframe; - } - else - { - // walk the queue and insert this frame where it belongs in display order. - bool ptrInserted = false; - frame_queue *nextframe = NULL; - // - while (!ptrInserted) - { - nextframe = queueWalker->nextframe; - if (!nextframe || (newframe->sort_time < nextframe->sort_time)) - { - // if the next frame is the tail of the queue, or our new frame is earlier. - newframe->nextframe = nextframe; - queueWalker->nextframe = newframe; - ptrInserted = true; - } - queueWalker = nextframe; - } - } - m_queue_depth++; - pthread_mutex_unlock(&m_queue_mutex); -} - void CDVDVideoCodecAmlogic::FrameRateTracking(uint8_t *pData, int iSize, double dts, double pts) { // mpeg2 handling @@ -549,22 +470,4 @@ void CDVDVideoCodecAmlogic::FrameRateTracking(uint8_t *pData, int iSize, double } return; } - - // everything else - FrameQueuePush(dts, pts); - - // we might have out-of-order pts, - // so make sure we wait for at least 8 values in sorted queue. - if (m_queue_depth > 16) - { - pthread_mutex_lock(&m_queue_mutex); - - float cur_pts = m_frame_queue->pts; - if (cur_pts == DVD_NOPTS_VALUE) - cur_pts = m_frame_queue->dts; - - pthread_mutex_unlock(&m_queue_mutex); - - FrameQueuePop(); - } } diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h index 031be1b880..11522d92fa 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h @@ -28,7 +28,6 @@ #include class CAMLCodec; -struct frame_queue; struct mpeg2_sequence; class CBitstreamParser; class CBitstreamConverter; @@ -88,8 +87,6 @@ public: protected: void Dispose(void); - void FrameQueuePop(void); - void FrameQueuePush(double dts, double pts); void FrameRateTracking(uint8_t *pData, int iSize, double dts, double pts); //void RemoveInfo(CDVDAmlogicInfo* info); @@ -100,9 +97,6 @@ protected: bool m_opened; int m_codecControlFlags; CDVDStreamInfo m_hints; - frame_queue *m_frame_queue; - int32_t m_queue_depth; - pthread_mutex_t m_queue_mutex; double m_framerate; int m_video_rate; float m_aspect_ratio; -- cgit v1.2.3