Skip to content

Commit

Permalink
[omxplayer] Add ability to dump out audio/video data for later debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
popcornmix committed Oct 5, 2018
1 parent 9d2ec35 commit a9ae1b8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
9 changes: 9 additions & 0 deletions addons/resource.language.en_gb/resources/strings.po
Expand Up @@ -3170,6 +3170,15 @@ msgctxt "#697"
msgid "Verbose logging for OMXPLAYER"
msgstr ""

#: xbmc/settings/AdvancedSettings.cpp
msgctxt "#698"
msgid "Dump video frames to debug file"
msgstr ""

#: xbmc/settings/AdvancedSettings.cpp
msgctxt "#699"
msgid "Dump audio frames to debug file"
msgstr ""

#: xbmc/music/infoscanner/MusicInfoScanner.cpp
#: xbmc/music/MusicDatabase.cpp
Expand Down
4 changes: 3 additions & 1 deletion xbmc/commons/ilog.h
Expand Up @@ -44,7 +44,9 @@
#define LOGWINDOWING (1 << (LOGMASKBIT + 14))
#define LOGPVR (1 << (LOGMASKBIT + 15))
#define LOGEPG (1 << (LOGMASKBIT + 16))
#define LOGOMXPLAYER (1 << (LOGMASKBIT + 28))
#define LOGOMXPLAYER (1 << (LOGMASKBIT + 24))
#define LOGDUMPVIDEO (1 << (LOGMASKBIT + 25))
#define LOGDUMPAUDIO (1 << (LOGMASKBIT + 26))

#include "utils/params_check_macros.h"

Expand Down
63 changes: 63 additions & 0 deletions xbmc/cores/VideoPlayer/VideoPlayer.cpp
Expand Up @@ -72,11 +72,66 @@
#include "VideoPlayerAudio.h"
#include "windowing/WinSystem.h"
#include "DVDCodecs/DVDCodecUtils.h"
#include "filesystem/SpecialProtocol.h"

#include <iterator>

using namespace KODI::MESSAGING;

//#define DEBUG_PLAYBACK
static void dump_packet(DemuxPacket *packet, bool video, bool audio)
{
static CCriticalSection m_section;
static FILE *fp_video, *fp_audio;
if ((!video || !g_advancedSettings.CanLogComponent(LOGDUMPVIDEO)) &&
(!audio || !g_advancedSettings.CanLogComponent(LOGDUMPAUDIO)))
return;
const char *fname = video ? "video.dat" : "audio.dat";
FILE *&fp = video ? fp_video : fp_audio;
CSingleLock lock(m_section);
if (!packet)
{
if (fp)
{
CLog::Log(LOGNOTICE, "%s:: Closing file %p", __func__, static_cast<void*>(fp));
fclose(fp);
fp = NULL;
}
return;
}
if (!fp)
{
char filename[1024];
strcpy(filename, CSpecialProtocol::TranslatePath("special://logpath").c_str());
strcat(filename, fname);
#ifdef DEBUG_PLAYBACK
fp = fopen(filename, "rb");
#else
fp = fopen(filename, "wb");
#endif
CLog::Log(LOGNOTICE, "%s:: Opening file %s = %p", __func__, filename, static_cast<void*>(fp));
}
if (fp)
{
#ifdef DEBUG_PLAYBACK
DemuxPacket p = {0};
int s = fread(&p, sizeof p, 1, fp);
if (s==1)
{
packet->iSize = p.iSize;
packet->dts = p.dts;
packet->pts = p.pts;
_aligned_free(packet->pData);
packet->pData = (uint8_t*)_aligned_malloc(packet->iSize + FF_INPUT_BUFFER_PADDING_SIZE, 16);
fread(packet->pData, packet->iSize, 1, fp);
}
#else
if (fwrite(packet, sizeof *packet, 1, fp) == 1)
fwrite(packet->pData, packet->iSize, 1, fp);
#endif
}
}

//------------------------------------------------------------------------------
// selection streams
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1085,6 +1140,12 @@ bool CVideoPlayer::ReadPacket(DemuxPacket*& packet, CDemuxStream*& stream)
return true;
}

if(m_pDemuxer)
{
stream = m_pDemuxer->GetStream(packet->demuxerId, packet->iStreamId);
if (stream)
dump_packet(packet, CheckIsCurrent(m_CurrentVideo, stream, packet), CheckIsCurrent(m_CurrentAudio, stream, packet));
}
UpdateCorrection(packet, m_offset_pts);

if(packet->iStreamId < 0)
Expand Down Expand Up @@ -3890,6 +3951,8 @@ bool CVideoPlayer::CloseStream(CCurrentStream& current, bool bWaitForBuffers)
if (m_pDemuxer && STREAM_SOURCE_MASK(current.source) == STREAM_SOURCE_DEMUX)
m_pDemuxer->EnableStream(current.demuxerId, current.id, false);

dump_packet(NULL, current.player == VideoPlayer_VIDEO, current.player == VideoPlayer_AUDIO);

IDVDStreamPlayer* player = GetStreamPlayer(current.player);
if (player)
{
Expand Down
4 changes: 4 additions & 0 deletions xbmc/settings/AdvancedSettings.cpp
Expand Up @@ -1434,6 +1434,10 @@ void CAdvancedSettings::SettingOptionsLoggingComponentsFiller(SettingConstPtr se
#ifdef TARGET_RASPBERRY_PI
list.push_back(std::make_pair(g_localizeStrings.Get(697), LOGOMXPLAYER));
#endif
#ifdef TARGET_RASPBERRY_PI
list.push_back(std::make_pair(g_localizeStrings.Get(698), LOGDUMPVIDEO));
list.push_back(std::make_pair(g_localizeStrings.Get(699), LOGDUMPAUDIO));
#endif
}

void CAdvancedSettings::setExtraLogLevel(const std::vector<CVariant> &components)
Expand Down

0 comments on commit a9ae1b8

Please sign in to comment.