From f2debe7f370cc0356dba9aa04103a6fa413ba95d Mon Sep 17 00:00:00 2001 From: Thomas Reufer Date: Thu, 7 Apr 2016 13:49:20 +0200 Subject: move end of stream notification to video decoder --- omxdevice.c | 4 ++-- video.c | 26 ++++++++++++++++++++------ video.h | 17 ++++++++++++----- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/omxdevice.c b/omxdevice.c index e0b5c74..8f578a1 100644 --- a/omxdevice.c +++ b/omxdevice.c @@ -98,7 +98,6 @@ int cOmxDevice::Init(void) ELOG("failed to initialize audio!"); return -1; } - m_omx->SetEndOfStreamCallback(&OnEndOfStream, this); cRpiSetup::SetVideoSetupChangedCallback(&OnVideoSetupChanged, this); return 0; } @@ -352,7 +351,8 @@ int cOmxDevice::PlayVideo(const uchar *Data, int Length, bool EndOfFrame) pts != OMX_INVALID_PTS) { if (cRpiSetup::IsVideoCodecSupported(codec)) - m_video = new cRpiOmxVideoDecoder(codec, m_omx, &OnStreamStart, this); + m_video = new cRpiOmxVideoDecoder(codec, m_omx, + &OnStreamStart, &OnEndOfStream, this); else Skins.QueueMessage(mtError, tr("video format not supported!")); } diff --git a/video.c b/video.c index fcb191a..3f5a92c 100644 --- a/video.c +++ b/video.c @@ -34,11 +34,12 @@ const unsigned char cRpiVideoDecoder::s_h264EndOfSequence[8] = { cRpiVideoDecoder::cRpiVideoDecoder(cVideoCodec::eCodec codec, void (*onStreamStart)(void*, const cVideoFrameFormat *format), - void* onStreamStartData) : + void (*onEndOfStream)(void*), void* callbackData) : m_codec(codec), m_format(), m_onStreamStart(onStreamStart), - m_onStreamStartData(onStreamStartData) + m_onEndOfStream(onEndOfStream), + m_callbackData(callbackData) { m_format.width = 0; m_format.height = 0; @@ -51,17 +52,30 @@ cRpiVideoDecoder::cRpiVideoDecoder(cVideoCodec::eCodec codec, cRpiVideoDecoder::~cRpiVideoDecoder() { } +void cRpiVideoDecoder::NotifyStreamStart(void) +{ + if (m_onStreamStart) + m_onStreamStart(m_callbackData, &m_format); +} + +void cRpiVideoDecoder::NotifyEndOfStream(void) +{ + if (m_onEndOfStream) + m_onEndOfStream(m_callbackData); +} + /* ------------------------------------------------------------------------- */ cRpiOmxVideoDecoder::cRpiOmxVideoDecoder(cVideoCodec::eCodec codec, cOmx *omx, void (*onStreamStart)(void*, const cVideoFrameFormat *format), - void* onStreamStartData) : - cRpiVideoDecoder(codec, onStreamStart, onStreamStartData), + void (*onEndOfStream)(void*), void* callbackData) : + cRpiVideoDecoder(codec, onStreamStart, onEndOfStream, callbackData), m_omx(omx) { DLOG("new OMX %s video codec", cVideoCodec::Str(codec)); m_omx->SetVideoCodec(codec); m_omx->SetStreamStartCallback(OnStreamStart, this); + m_omx->SetEndOfStreamCallback(OnEndOfStream, this); m_omx->SetBufferStallCallback(OnBufferStall, this); } @@ -69,6 +83,7 @@ cRpiOmxVideoDecoder::~cRpiOmxVideoDecoder() { Clear(true); m_omx->SetBufferStallCallback(0, 0); + m_omx->SetEndOfStreamCallback(0, 0); m_omx->SetStreamStartCallback(0, 0); m_omx->StopVideo(); } @@ -141,8 +156,7 @@ void cRpiOmxVideoDecoder::HandleStreamStart(int width, int height, m_format.pixelHeight = pixelHeight; // forward to device instance - if (m_onStreamStart) - m_onStreamStart(m_onStreamStartData, &m_format); + NotifyStreamStart(); // if necessary, setup deinterlacer m_omx->SetupDeinterlacer( diff --git a/video.h b/video.h index d05ddc6..67ef923 100644 --- a/video.h +++ b/video.h @@ -31,8 +31,9 @@ class cRpiVideoDecoder public: - cRpiVideoDecoder(cVideoCodec::eCodec codec, void (*onStreamStart)( - void*, const cVideoFrameFormat *format), void* onStreamStartData); + cRpiVideoDecoder(cVideoCodec::eCodec codec, + void (*onStreamStart)(void*, const cVideoFrameFormat *format), + void (*onEndOfStream)(void*), void* callbackData); virtual ~cRpiVideoDecoder(); cVideoCodec::eCodec GetCodec(void) { return m_codec; }; @@ -54,8 +55,12 @@ protected: cVideoCodec::eCodec m_codec; cVideoFrameFormat m_format; + void NotifyStreamStart(void); + void NotifyEndOfStream(void); + void (*m_onStreamStart)(void*, const cVideoFrameFormat *format); - void *m_onStreamStartData; + void (*m_onEndOfStream)(void*); + void *m_callbackData; }; @@ -66,7 +71,7 @@ public: cRpiOmxVideoDecoder(cVideoCodec::eCodec codec, cOmx *omx, void (*onStreamStart)(void*, const cVideoFrameFormat *format), - void* onStreamStartData); + void (*onEndOfStream)(void*), void* callbackData); virtual ~cRpiOmxVideoDecoder(); virtual bool WriteData(const unsigned char *data, @@ -86,8 +91,10 @@ protected: { (static_cast (data))->HandleStreamStart( width, height, frameRate, scanMode, pixelWidth, pixelHeight); } - void HandleBufferStall(void); + static void OnEndOfStream(void *data) + { (static_cast (data))->NotifyEndOfStream(); } + void HandleBufferStall(void); static void OnBufferStall(void *data) { (static_cast (data))->HandleBufferStall(); } -- cgit v1.2.3