1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Improved handling frame numbers to have a smoother progress display during replay of recordings with B-frames

This commit is contained in:
Klaus Schmidinger 2016-12-22 11:33:12 +01:00
parent fd85701a84
commit be4cdcf170
9 changed files with 120 additions and 44 deletions

View File

@ -3328,6 +3328,8 @@ Thomas Reufer <thomas@reufer.ch>
for making the cPlayer member functions FramesPerSecond, GetIndex and GetReplayMode for making the cPlayer member functions FramesPerSecond, GetIndex and GetReplayMode
'const' 'const'
for fixing resuming replay at a given position, which was off by one frame for fixing resuming replay at a given position, which was off by one frame
for improving handling frame numbers to have a smoother progress display during
replay of recordings with B-frames
Eike Sauer <EikeSauer@t-online.de> Eike Sauer <EikeSauer@t-online.de>
for reporting a problem with channels that need more than 5 TS packets for detecting for reporting a problem with channels that need more than 5 TS packets for detecting

View File

@ -8857,3 +8857,5 @@ Video Disk Recorder Revision History
'const' (thanks to Thomas Reufer). 'const' (thanks to Thomas Reufer).
- Fixed resuming replay at a given position, which was off by one frame (thanks - Fixed resuming replay at a given position, which was off by one frame (thanks
to Thomas Reufer). to Thomas Reufer).
- Improved handling frame numbers to have a smoother progress display during
replay of recordings with B-frames (thanks to Thomas Reufer).

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: dvbplayer.c 4.2 2016/12/22 09:40:30 kls Exp $ * $Id: dvbplayer.c 4.3 2016/12/22 10:43:10 kls Exp $
*/ */
#include "dvbplayer.h" #include "dvbplayer.h"
@ -17,13 +17,14 @@
// --- cPtsIndex ------------------------------------------------------------- // --- cPtsIndex -------------------------------------------------------------
#define PTSINDEX_ENTRIES 500 #define PTSINDEX_ENTRIES 1024
class cPtsIndex { class cPtsIndex {
private: private:
struct tPtsIndex { struct tPtsIndex {
uint32_t pts; // no need for 33 bit - some devices don't even supply the msb uint32_t pts; // no need for 33 bit - some devices don't even supply the msb
int index; int index;
bool independent;
}; };
tPtsIndex pi[PTSINDEX_ENTRIES]; tPtsIndex pi[PTSINDEX_ENTRIES];
int w, r; int w, r;
@ -33,8 +34,9 @@ public:
cPtsIndex(void); cPtsIndex(void);
void Clear(void); void Clear(void);
bool IsEmpty(void); bool IsEmpty(void);
void Put(uint32_t Pts, int Index); void Put(uint32_t Pts, int Index, bool Independent);
int FindIndex(uint32_t Pts); int FindIndex(uint32_t Pts);
int FindFrameNumber(uint32_t Pts);
}; };
cPtsIndex::cPtsIndex(void) cPtsIndex::cPtsIndex(void)
@ -55,10 +57,11 @@ bool cPtsIndex::IsEmpty(void)
return w == r; return w == r;
} }
void cPtsIndex::Put(uint32_t Pts, int Index) void cPtsIndex::Put(uint32_t Pts, int Index, bool Independent)
{ {
cMutexLock MutexLock(&mutex); cMutexLock MutexLock(&mutex);
pi[w].pts = Pts; pi[w].pts = Pts;
pi[w].independent = Independent;
pi[w].index = Index; pi[w].index = Index;
w = (w + 1) % PTSINDEX_ENTRIES; w = (w + 1) % PTSINDEX_ENTRIES;
if (w == r) if (w == r)
@ -87,6 +90,36 @@ int cPtsIndex::FindIndex(uint32_t Pts)
return Index; return Index;
} }
int cPtsIndex::FindFrameNumber(uint32_t Pts)
{
cMutexLock MutexLock(&mutex);
if (w == r)
return lastFound; // replay always starts at an I frame
bool Valid = false;
int d;
int FrameNumber = 0;
int UnplayedIFrame = 2; // GOPs may intersect, so we're looping until we found two unplayed I frames
for (int i = r; i != w && UnplayedIFrame; ) {
d = Pts - pi[i].pts;
if (d > 0x7FFFFFFF)
d = 0xFFFFFFFF - d; // handle rollover
if (d > 0) {
if (pi[i].independent) {
FrameNumber = pi[i].index; // an I frame's index represents its frame number
Valid = true;
}
else
FrameNumber++; // for every played non-I frame, increase frame number
}
else
if (pi[i].independent)
--UnplayedIFrame;
if (++i >= PTSINDEX_ENTRIES)
i = 0;
}
return Valid ? FrameNumber : FindIndex(Pts); // fall back during trick speeds
}
// --- cNonBlockingFileReader ------------------------------------------------ // --- cNonBlockingFileReader ------------------------------------------------
class cNonBlockingFileReader : public cThread { class cNonBlockingFileReader : public cThread {
@ -251,6 +284,7 @@ public:
virtual double FramesPerSecond(void) { return framesPerSecond; } virtual double FramesPerSecond(void) { return framesPerSecond; }
virtual void SetAudioTrack(eTrackType Type, const tTrackId *TrackId); virtual void SetAudioTrack(eTrackType Type, const tTrackId *TrackId);
virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false); virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false);
virtual bool GetFrameNumber(int &Current, int &Total);
virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed); virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed);
}; };
@ -606,7 +640,7 @@ void cDvbPlayer::Action(void)
pc = playFrame->Count(); pc = playFrame->Count();
if (p) { if (p) {
if (playFrame->Index() >= 0 && playFrame->Pts() != 0) if (playFrame->Index() >= 0 && playFrame->Pts() != 0)
ptsIndex.Put(playFrame->Pts(), playFrame->Index()); ptsIndex.Put(playFrame->Pts(), playFrame->Index(), playFrame->Independent());
if (firstPacket) { if (firstPacket) {
if (isPesRecording) { if (isPesRecording) {
PlayPes(NULL, 0); PlayPes(NULL, 0);
@ -880,7 +914,7 @@ void cDvbPlayer::Goto(int Index, bool Still)
if (playMode == pmPause) if (playMode == pmPause)
DevicePlay(); DevicePlay();
DeviceStillPicture(b, r); DeviceStillPicture(b, r);
ptsIndex.Put(isPesRecording ? PesGetPts(b) : TsGetPts(b, r), Index); ptsIndex.Put(isPesRecording ? PesGetPts(b) : TsGetPts(b, r), Index, true);
} }
playMode = pmStill; playMode = pmStill;
readIndex = Index; readIndex = Index;
@ -925,6 +959,17 @@ bool cDvbPlayer::GetIndex(int &Current, int &Total, bool SnapToIFrame)
return false; return false;
} }
bool cDvbPlayer::GetFrameNumber(int &Current, int &Total)
{
if (index) {
Current = ptsIndex.FindFrameNumber(DeviceGetSTC());
Total = index->Last();
return true;
}
Current = Total = -1;
return false;
}
bool cDvbPlayer::GetReplayMode(bool &Play, bool &Forward, int &Speed) bool cDvbPlayer::GetReplayMode(bool &Play, bool &Forward, int &Speed)
{ {
Play = (playMode == pmPlay || playMode == pmFast); Play = (playMode == pmPlay || playMode == pmFast);
@ -1011,6 +1056,15 @@ bool cDvbPlayerControl::GetIndex(int &Current, int &Total, bool SnapToIFrame)
return false; return false;
} }
bool cDvbPlayerControl::GetFrameNumber(int &Current, int &Total)
{
if (player) {
player->GetFrameNumber(Current, Total);
return true;
}
return false;
}
bool cDvbPlayerControl::GetReplayMode(bool &Play, bool &Forward, int &Speed) bool cDvbPlayerControl::GetReplayMode(bool &Play, bool &Forward, int &Speed)
{ {
return player && player->GetReplayMode(Play, Forward, Speed); return player && player->GetReplayMode(Play, Forward, Speed);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: dvbplayer.h 4.1 2015/08/02 13:01:44 kls Exp $ * $Id: dvbplayer.h 4.2 2016/12/22 10:36:50 kls Exp $
*/ */
#ifndef __DVBPLAYER_H #ifndef __DVBPLAYER_H
@ -50,6 +50,10 @@ public:
bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false); bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false);
// Returns the current and total frame index, optionally snapped to the // Returns the current and total frame index, optionally snapped to the
// nearest I-frame. // nearest I-frame.
bool GetFrameNumber(int &Current, int &Total);
// Returns the current and total frame number. In contrast to GetIndex(),
// this function respects the chronological order of frames, which is
// different from its index for streams containing B frames (e.g. H264)
bool GetReplayMode(bool &Play, bool &Forward, int &Speed); bool GetReplayMode(bool &Play, bool &Forward, int &Speed);
// Returns the current replay mode (if applicable). // Returns the current replay mode (if applicable).
// 'Play' tells whether we are playing or pausing, 'Forward' tells whether // 'Play' tells whether we are playing or pausing, 'Forward' tells whether

11
menu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: menu.c 4.18 2016/12/13 12:49:10 kls Exp $ * $Id: menu.c 4.19 2016/12/22 11:00:13 kls Exp $
*/ */
#include "menu.h" #include "menu.h"
@ -5435,6 +5435,7 @@ cReplayControl::cReplayControl(bool PauseLive)
lastPlay = lastForward = false; lastPlay = lastForward = false;
lastSpeed = -2; // an invalid value lastSpeed = -2; // an invalid value
timeoutShow = 0; timeoutShow = 0;
lastProgressUpdate = 0;
timeSearchActive = false; timeSearchActive = false;
cRecording Recording(fileName); cRecording Recording(fileName);
cStatus::MsgReplaying(this, Recording.Name(), Recording.FileName(), true); cStatus::MsgReplaying(this, Recording.Name(), Recording.FileName(), true);
@ -5583,8 +5584,8 @@ void cReplayControl::ShowMode(void)
bool cReplayControl::ShowProgress(bool Initial) bool cReplayControl::ShowProgress(bool Initial)
{ {
int Current, Total; int Current, Total;
if (Initial || time(NULL) - lastProgressUpdate >= 1) {
if (GetIndex(Current, Total) && Total > 0) { if (GetFrameNumber(Current, Total) && Total > 0) {
if (!visible) { if (!visible) {
displayReplay = Skins.Current()->DisplayReplay(modeOnly); displayReplay = Skins.Current()->DisplayReplay(modeOnly);
displayReplay->SetMarks(&marks); displayReplay->SetMarks(&marks);
@ -5600,6 +5601,7 @@ bool cReplayControl::ShowProgress(bool Initial)
lastCurrent = lastTotal = -1; lastCurrent = lastTotal = -1;
} }
if (Current != lastCurrent || Total != lastTotal) { if (Current != lastCurrent || Total != lastTotal) {
time(&lastProgressUpdate);
if (Setup.ShowRemainingTime || Total != lastTotal) { if (Setup.ShowRemainingTime || Total != lastTotal) {
int Index = Total; int Index = Total;
if (Setup.ShowRemainingTime) if (Setup.ShowRemainingTime)
@ -5619,6 +5621,7 @@ bool cReplayControl::ShowProgress(bool Initial)
ShowMode(); ShowMode();
return true; return true;
} }
}
return false; return false;
} }
@ -5858,6 +5861,8 @@ eOSState cReplayControl::ProcessKey(eKeys Key)
return osEnd; return osEnd;
if (Key == kNone && !marksModified) if (Key == kNone && !marksModified)
marks.Update(); marks.Update();
if (Key != kNone)
lastProgressUpdate = 0;
if (visible) { if (visible) {
if (timeoutShow && time(NULL) > timeoutShow) { if (timeoutShow && time(NULL) > timeoutShow) {
Hide(); Hide();

3
menu.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: menu.h 4.4 2015/09/13 14:17:56 kls Exp $ * $Id: menu.h 4.5 2016/12/22 10:55:36 kls Exp $
*/ */
#ifndef __MENU_H #ifndef __MENU_H
@ -300,6 +300,7 @@ private:
bool lastPlay, lastForward; bool lastPlay, lastForward;
int lastSpeed; int lastSpeed;
time_t timeoutShow; time_t timeoutShow;
time_t lastProgressUpdate;
bool timeSearchActive, timeSearchHide; bool timeSearchActive, timeSearchHide;
int timeSearchTime, timeSearchPos; int timeSearchTime, timeSearchPos;
void TimeSearchDisplay(void); void TimeSearchDisplay(void);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: player.h 4.1 2016/12/22 09:22:27 kls Exp $ * $Id: player.h 4.2 2016/12/22 10:38:11 kls Exp $
*/ */
#ifndef __PLAYER_H #ifndef __PLAYER_H
@ -57,6 +57,10 @@ public:
virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false) { return false; } virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false) { return false; }
// Returns the current and total frame index, optionally snapped to the // Returns the current and total frame index, optionally snapped to the
// nearest I-frame. // nearest I-frame.
virtual bool GetFrameNumber(int &Current, int &Total) { return false; }
// Returns the current and total frame number. In contrast to GetIndex(),
// this function respects the chronological order of frames, which is
// different from its index for streams containing B frames (e.g. H264)
virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed) { return false; } virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed) { return false; }
// Returns the current replay mode (if applicable). // Returns the current replay mode (if applicable).
// 'Play' tells whether we are playing or pausing, 'Forward' tells whether // 'Play' tells whether we are playing or pausing, 'Forward' tells whether
@ -100,6 +104,7 @@ public:
///< string. The default implementation returns an empty string. ///< string. The default implementation returns an empty string.
double FramesPerSecond(void) const { return player->FramesPerSecond(); } double FramesPerSecond(void) const { return player->FramesPerSecond(); }
bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false) const { return player->GetIndex(Current, Total, SnapToIFrame); } bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false) const { return player->GetIndex(Current, Total, SnapToIFrame); }
bool GetFrameNumber(int &Current, int &Total) const { return player->GetFrameNumber(Current, Total); }
bool GetReplayMode(bool &Play, bool &Forward, int &Speed) const { return player->GetReplayMode(Play, Forward, Speed); } bool GetReplayMode(bool &Play, bool &Forward, int &Speed) const { return player->GetReplayMode(Play, Forward, Speed); }
static void Launch(cControl *Control); static void Launch(cControl *Control);
static void Attach(void); static void Attach(void);

View File

@ -7,7 +7,7 @@
* Parts of this file were inspired by the 'ringbuffy.c' from the * Parts of this file were inspired by the 'ringbuffy.c' from the
* LinuxDVB driver (see linuxtv.org). * LinuxDVB driver (see linuxtv.org).
* *
* $Id: ringbuffer.c 2.5 2012/09/22 11:26:49 kls Exp $ * $Id: ringbuffer.c 4.1 2016/12/22 10:26:13 kls Exp $
*/ */
#include "ringbuffer.h" #include "ringbuffer.h"
@ -390,12 +390,13 @@ void cRingBufferLinear::Del(int Count)
// --- cFrame ---------------------------------------------------------------- // --- cFrame ----------------------------------------------------------------
cFrame::cFrame(const uchar *Data, int Count, eFrameType Type, int Index, uint32_t Pts) cFrame::cFrame(const uchar *Data, int Count, eFrameType Type, int Index, uint32_t Pts, bool Independent)
{ {
count = abs(Count); count = abs(Count);
type = Type; type = Type;
index = Index; index = Index;
pts = Pts; pts = Pts;
independent = Type == ftAudio ? true : Independent;
if (Count < 0) if (Count < 0)
data = (uchar *)Data; data = (uchar *)Data;
else { else {

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: ringbuffer.h 2.5 2013/02/16 15:20:37 kls Exp $ * $Id: ringbuffer.h 4.1 2016/12/22 10:26:13 kls Exp $
*/ */
#ifndef __RINGBUFFER_H #ifndef __RINGBUFFER_H
@ -113,8 +113,9 @@ private:
eFrameType type; eFrameType type;
int index; int index;
uint32_t pts; uint32_t pts;
bool independent;
public: public:
cFrame(const uchar *Data, int Count, eFrameType = ftUnknown, int Index = -1, uint32_t Pts = 0); cFrame(const uchar *Data, int Count, eFrameType = ftUnknown, int Index = -1, uint32_t Pts = 0, bool independent = false);
///< Creates a new cFrame object. ///< Creates a new cFrame object.
///< If Count is negative, the cFrame object will take ownership of the given ///< If Count is negative, the cFrame object will take ownership of the given
///< Data. Otherwise it will allocate Count bytes of memory and copy Data. ///< Data. Otherwise it will allocate Count bytes of memory and copy Data.
@ -124,6 +125,7 @@ public:
eFrameType Type(void) const { return type; } eFrameType Type(void) const { return type; }
int Index(void) const { return index; } int Index(void) const { return index; }
uint32_t Pts(void) const { return pts; } uint32_t Pts(void) const { return pts; }
bool Independent(void) const { return independent; }
}; };
class cRingBufferFrame : public cRingBuffer { class cRingBufferFrame : public cRingBuffer {