Skip to content

Commit

Permalink
Add debug statistics OSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
rofafor committed Mar 8, 2018
1 parent 1f66da9 commit cf13443
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 67 deletions.
13 changes: 9 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,15 @@ Keymacros:
@vaapidevice Blue 2 3 disable auto-crop
@vaapidevice Blue 2 4 enable auto-crop
@vaapidevice Blue 2 5 toggle auto-crop
@vaapidevice Blue 3 0 stretch 4:3 to 16:9
@vaapidevice Blue 3 1 letter box 4:3 in 16:9
@vaapidevice Blue 3 2 center cut-out 4:3 to 16:9
@vaapidevice Blue 3 9 rotate 4:3 to 16:9 zoom mode
@vaapidevice Blue 3 0 stretch 4:3 to display
@vaapidevice Blue 3 1 letter box 4:3 in display
@vaapidevice Blue 3 2 center cut-out 4:3 to display
@vaapidevice Blue 3 9 rotate 4:3 to display zoom mode
@vaapidevice Blue 4 0 stretch other aspect ratios to display
@vaapidevice Blue 4 1 letter box other aspect ratios in display
@vaapidevice Blue 4 2 center cut-out other aspect ratios to display
@vaapidevice Blue 4 9 rotate other aspect ratios to display zoom mode
@vaapidevice Blue 5 0 toggle debug statistics osd

Running:
--------
Expand Down
20 changes: 20 additions & 0 deletions codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,26 @@ void CodecAudioFlushBuffers(AudioDecoder * decoder)
avcodec_flush_buffers(decoder->AudioCtx);
}

/**
** Get the audio decoder info.
**
** @param decoder audio decoder data
** @param codec_id audio codec id
*/
char *CodecAudioGetInfo(AudioDecoder * decoder, int codec_id)
{
if (decoder) {
char buffer[255];

if (snprintf(&buffer[0], sizeof(buffer), " Audio: %s %dHz %d channels", avcodec_get_name(codec_id),
decoder->SampleRate, decoder->Channels)) {
return strdup(buffer);
}
}

return NULL;
}

//----------------------------------------------------------------------------
// Codec
//----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ extern void CodecAudioOpen(AudioDecoder *, int);
/// Close audio codec.
extern void CodecAudioClose(AudioDecoder *);

/// Get audio decoder info
extern char *CodecAudioGetInfo(AudioDecoder *, int);

/// Set audio drift correction.
extern void CodecSetAudioDrift(int);

Expand Down
10 changes: 6 additions & 4 deletions po/de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ msgstr "anzeigen"
msgid "hide"
msgstr "verstecken"

msgid "Debug/OFF"
msgstr ""

msgid "Debug/ON"
msgstr ""

msgid "General"
msgstr "Allgemeines"

Expand Down Expand Up @@ -176,10 +182,6 @@ msgstr ""
msgid "Suspend VA-API Device"
msgstr ""

#, c-format
msgid " Frames missed(%d) duped(%d) dropped(%d) total(%d)"
msgstr " Frames verloren(%d) verdoppelt(%d) übersprungen(%d) Gesamt(%d)"

msgid "pass-through disabled"
msgstr ""

Expand Down
36 changes: 22 additions & 14 deletions vaapidev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ int PlayAudio(const uint8_t * data, int size, uint8_t id)
if (r > 0 && p[5] > (10 << 3)) {
codec_id = AV_CODEC_ID_EAC3;
}
/* faster ac3 detection at end of pes packet (no improvemnts)
/* faster ac3 detection at end of pes packet (no improvements)
if (AudioCodecID == codec_id && -r - 2 == n) {
r = n;
}
Expand Down Expand Up @@ -3032,22 +3032,30 @@ void Resume(void)
}

/*
** Get decoder statistics.
** Get video decoder statistics.
*/
char *GetVideoStats(void)
{
return MyVideoStream->HwDecoder ? VideoGetStats(MyVideoStream->HwDecoder) : NULL;
}

/*
** Get video decoder info.
**
** @param[out] missed missed frames
** @param[out] duped duped frames
** @param[out] dropped dropped frames
** @param[out] count number of decoded frames
*/
void GetStats(int *missed, int *duped, int *dropped, int *counter)
char *GetVideoInfo(void)
{
*missed = 0;
*duped = 0;
*dropped = 0;
*counter = 0;
if (MyVideoStream->HwDecoder) {
VideoGetStats(MyVideoStream->HwDecoder, missed, duped, dropped, counter);
}
return MyVideoStream->HwDecoder ? VideoGetInfo(MyVideoStream->HwDecoder,
avcodec_get_name(MyVideoStream->CodecID)) : NULL;
}

/*
** Get audio decoder info.
**
*/
char *GetAudioInfo(void)
{
return CodecAudioGetInfo(MyAudioDecoder, AudioCodecID);
}

/**
Expand Down
137 changes: 125 additions & 12 deletions vaapidevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,109 @@ extern "C" void LogMessage(int trace, int level, const char *format, ...)
}
}

class cDebugStatistics:public cThread
{
private:
cOsd * osd;
int area_w;
int area_h;
int area_bpp;

void Draw(void)
{
LOCK_THREAD;
if (osd)
{
const cFont *font = cFont::GetFont(fontSml);
int y = 0, h = font->Height();
char *info = GetVideoStats();
if (info)
{
osd->DrawText(0, y, info, clrWhite, clrGray50, font, 2160, h);
free(info);
} else
{
osd->DrawRectangle(0, y, 2160, y + h, clrGray50);
}
y += h;

info = GetVideoInfo();

if (info) {
osd->DrawText(0, y, info, clrWhite, clrGray50, font, 2160, h);
free(info);
} else {
osd->DrawRectangle(0, y, 2160, y + h, clrGray50);
}
y += h;

info = GetAudioInfo();

if (info) {
osd->DrawText(0, y, info, clrWhite, clrGray50, font, 2160, h);
free(info);
} else {
osd->DrawRectangle(0, y, 2160, y + h, clrGray50);
}

y += h;

osd->Flush();
}
}

bool Delete(void)
{
LOCK_THREAD;
if (Running()) {
Cancel(3);
DELETENULL(osd);
return true;
}
return false;
}

bool Create(void)
{
LOCK_THREAD;
if (!osd) {
osd = cOsdProvider::NewOsd(0, 0, 1);
tArea Area = { 0, 0, area_w, area_h, area_bpp };
osd->SetAreas(&Area, 1);
}
return osd != NULL;
}

protected:
virtual void Action(void)
{
Create();
while (Running()) {
Draw();
cCondWait::SleepMs(500);
}
}

public:
cDebugStatistics():cThread("VAAPI Stats"), osd(NULL), area_w(4096), area_h(2160), area_bpp(32) {
}

virtual ~ cDebugStatistics() {
Delete();
}

bool Toggle(void)
{
if (Delete()) {
return false;
}
Start();
return true;
}
};

static class cDebugStatistics *MyDebug;

/**
** Soft device plugin remote class.
*/
Expand Down Expand Up @@ -717,6 +820,8 @@ void cMenuSetupSoft::Create(void)
current = Current(); // get current menu item index
Clear(); // clear the menu

SetHelp(NULL, NULL, NULL, MyDebug->Active()? tr("Debug/OFF") : tr("Debug/ON"));

//
// general
//
Expand Down Expand Up @@ -855,6 +960,19 @@ eOSState cMenuSetupSoft::ProcessKey(eKeys key)
old_stde = Stde;
state = cMenuSetupPage::ProcessKey(key);

if (state == osUnknown) {
switch (key) {
case kBlue:
MyDebug->Toggle();
Create(); // update color key labels
state = osContinue;
break;
default:
state = osContinue;
break;
}
}

if (key != kNone) {
// update menu only, if something on the structure has changed
// this is needed because VDR menus are evil slow
Expand Down Expand Up @@ -1216,10 +1334,6 @@ class cSoftHdMenu:public cOsdMenu
void cSoftHdMenu::Create(void)
{
int current;
int missed;
int duped;
int dropped;
int counter;

current = Current(); // get current menu item index
Clear(); // clear the menu
Expand All @@ -1231,11 +1345,6 @@ void cSoftHdMenu::Create(void)
} else {
Add(new cOsdItem(hk(tr("Suspend VA-API Device")), osUser1));
}
Add(new cOsdItem(NULL, osUnknown, false));
Add(new cOsdItem(NULL, osUnknown, false));
GetStats(&missed, &duped, &dropped, &counter);
Add(new cOsdItem(cString::sprintf(tr(" Frames missed(%d) duped(%d) dropped(%d) total(%d)"), missed, duped, dropped,
counter), osUnknown, false));

SetCurrent(Get(current)); // restore selected menu entry
Display(); // display build menu
Expand Down Expand Up @@ -1361,6 +1470,9 @@ static void HandleHotkey(int code)
case 49: // rotate 16:9 -> window mode
VideoSetOtherDisplayFormat(-1);
break;
case 50: // toggle debug statistics osd
MyDebug->Toggle();
break;
default:
Error("Hot key %d is not supported", code);
break;
Expand Down Expand Up @@ -2010,6 +2122,7 @@ bool cPluginVaapiDevice::ProcessArgs(int argc, char *argv[])
bool cPluginVaapiDevice::Initialize(void)
{
MyDevice = new cVaapiDevice();
MyDebug = new cDebugStatistics();

return true;
}
Expand Down Expand Up @@ -2346,13 +2459,13 @@ static const char *SVDRPHelpText[] = {
" 32: center cut-out 4:3 to display\n" " 39: rotate 4:3 to display zoom mode\n"
" 40: stretch other aspect ratios to display\n" " 41: letter box other aspect ratios in display\n"
" 42: center cut-out other aspect ratios to display\n"
" 49: rotate other aspect ratios to display zoom mode\n",
" 49: rotate other aspect ratios to display zoom mode\n" " 50: toggle debug statistics osd\n",
"STAT\n" "\040 Display SuspendMode of the plugin.\n\n" " reply code is 910 + SuspendMode\n"
" SUSPEND_EXTERNAL == -1 (909)\n" " NOT_SUSPENDED == 0 (910)\n"
" SUSPEND_NORMAL == 1 (911)\n" " SUSPEND_DETACHED == 2 (912)\n",
"RAIS\n" "\040 Raise vaapidevice window\n\n" " If Xserver is not started by vaapidevice, the window which\n"
" contains the vaapidevice frontend will be raised to the front.\n" "TRAC [ <mode> ]\n"
" gets and/or sets used tracing mode.\n",
" contains the vaapidevice frontend will be raised to the front.\n",
"TRAC [ <mode> ]\n" " gets and/or sets used tracing mode.\n",
NULL
};

Expand Down
9 changes: 7 additions & 2 deletions vaapidevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ extern "C"
/// Resume plugin
extern void Resume(void);

/// Get decoder statistics
extern void GetStats(int *, int *, int *, int *);
/// Get video decoder statistics
extern char *GetVideoStats(void);
/// Get video decoder info
extern char *GetVideoInfo(void);
/// Get audio decoder info
extern char *GetAudioInfo(void);

/// C plugin scale video
extern void ScaleVideo(int, int, int, int);

Expand Down
Loading

0 comments on commit cf13443

Please sign in to comment.