Skip to content

Commit

Permalink
Fixes for #51 and several improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlonluca committed Feb 27, 2016
1 parent bf0e76b commit 6320659
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tools/build*
*.pro.user*
3rdparty*
3rdparty*/*
3rdparty/*
openmaxil_backend/3rdparty/*
piomxtextures_qt_driver/mediaplayer/.qmake.conf
Expand Down
17 changes: 17 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
Changelog

Version 5.2.0
=============
1. Bump ffmpeg to 2.8.5.
2. Fixed leaks when video processor is destroyed.

Version 5.1.0
=============

Version 5.0.0
=============

Version 4.5.0
=============

Version 4.4.0
=============

Version 4.3.0
=============
1. Updated for Qt 5.4.0.
Expand Down
2 changes: 1 addition & 1 deletion piomxtextures_lib/piomxtextures_lib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

TEMPLATE = lib

VERSION = 5.1.0
VERSION = 5.2.0

QT += core core-private gui gui-private opengl quick quick-private
CONFIG += no_private_qt_headers_warning
Expand Down
14 changes: 7 additions & 7 deletions piomxtextures_pocplayer/qml/POC_TextPosition.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import "POC_StringUtils.js" as POC_StringUtils

// The duration text.
Text {
id: textPosition
text: formatText();
id: textPosition
text: formatText();

function formatText() {
var position = POC_StringUtils.secondsToHHMMSS(parent.source.position/1000);
var duration = POC_StringUtils.secondsToHHMMSS(parent.source.duration/1000);
return position + "/" + duration;
}
function formatText() {
var position = POC_StringUtils.secondsToHHMMSS(parent.source.position/1000);
var duration = POC_StringUtils.secondsToHHMMSS(parent.source.duration/1000);
return position + "/" + duration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ OpenMAXILPlayerControl::OpenMAXILPlayerControl(QObject *parent)
: QMediaPlayerControl(parent)
, m_ownStream(false)
, m_seekToStartPending(false)
, m_pendingSeekPosition(-1)
, m_pendingSeekPosition(-1)
, m_texProvider(make_shared<OMX_EGLBufferProvider>())
, m_mediaProcessor(new OMX_MediaProcessor(m_texProvider))
, m_renderer(NULL)
{
logi_debug_func;
logi_debug_func;

connect(m_mediaProcessor, SIGNAL(stateChanged(OMX_MediaProcessor::OMX_MediaProcessorState)),
this, SLOT(onStateChanged(OMX_MediaProcessor::OMX_MediaProcessorState)));
connect(m_mediaProcessor, SIGNAL(mediaStatusChanged(OMX_MediaProcessor::OMX_MediaStatus)),
this, SLOT(onMediaStatusChanged(OMX_MediaProcessor::OMX_MediaStatus)));
connect(m_mediaProcessor, SIGNAL(metadataChanged(QVariantMap)),
this, SIGNAL(metaDataChanged(QVariantMap)));
this, SIGNAL(metaDataChanged(QVariantMap)));
}

/*------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private slots:
bool m_ownStream;
bool m_seekToStartPending;

qint64 m_pendingSeekPosition;
qint64 m_pendingSeekPosition;

QMediaContent m_currentResource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QVideoSurfaceFormat>
#include <QTimer>
#include <QMutex>
#include <QDateTime>
#ifdef OGL_CONTEXT_FROM_SURFACE
#include <QVariant>
#endif // OGL_CONTEXT_FROM_SURFACE
Expand All @@ -37,6 +38,37 @@

#include "omx_logging.h"

/*------------------------------------------------------------------------------
| definitions
+-----------------------------------------------------------------------------*/
//#define OMX_RENDER_WATCHDOG
#define OMX_RENDER_WATCHDOG_FILE "/tmp/omx_render_signal"

#ifdef OMX_RENDER_WATCHDOG
/*------------------------------------------------------------------------------
| handleWatchdogFile
+-----------------------------------------------------------------------------*/
inline void handleWatchdogFile()
{
static QFile f(OMX_RENDER_WATCHDOG_FILE);
static QDateTime lastTouch = QDateTime::currentDateTime();

const QDateTime current = QDateTime::currentDateTime();
if (current.toMSecsSinceEpoch() - lastTouch.toMSecsSinceEpoch() < 1000)
return;

if (!f.open(QIODevice::WriteOnly)) {
log_warn("Failed to touch " OMX_RENDER_WATCHDOG_FILE ".");
return;
}

lastTouch = current;

f.close();
}

#endif // OMX_RENDER_WATCHDOG

/*------------------------------------------------------------------------------
| OpenMAXILVideoBuffer class
+-----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -191,7 +223,7 @@ void OpenMAXILVideoRendererControl::onTexturesReady()
// Just take one random texture to determine the size. Do not place
// any texture yet in the scene as I can't guarantee it is filled
// already with valid data.
m_buffer = new OpenMAXILVideoBuffer(
m_buffer = new OpenMAXILVideoBuffer(
QAbstractVideoBuffer::GLTextureHandle,
0
);
Expand Down Expand Up @@ -244,11 +276,10 @@ void OpenMAXILVideoRendererControl::onUpdateTriggered()
return;
if (UNLIKELY(!m_surface || !m_frame || !m_surfaceFormat))
return;

if (UNLIKELY(!m_surface->isActive() && !m_surface->start(*m_surfaceFormat)))
log_warn("Failed to start surface.");

GLuint t = m_mediaProcessor->m_provider->getNextTexture();
const GLuint t = m_mediaProcessor->m_provider->getNextTexture();

// It seems that in some cases the fillBufferDone arrives even after
// completely flushing the pipeline. This presents frames to be shown
Expand All @@ -257,6 +288,10 @@ void OpenMAXILVideoRendererControl::onUpdateTriggered()
return;
m_buffer->setHandle(t);
m_surface->present(*m_frame);

#ifdef OMX_RENDER_WATCHDOG
handleWatchdogFile();
#endif // OMX_RENDER_WATCHDOG
}

/*------------------------------------------------------------------------------
Expand Down
74 changes: 58 additions & 16 deletions piomxtextures_src/omx_mediaprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const char* OMX_MediaProcessor::M_STATUS[] = {

#define INVOKE(...) \
QMetaObject::invokeMethod(this, __VA_ARGS__)
#define INVOKE_CONN \
Qt::QueuedConnection

/*------------------------------------------------------------------------------
| get_mem_gpu
Expand Down Expand Up @@ -136,13 +138,27 @@ static void start_watchdog_once()
}
#endif // OMX_LOCK_WATCHDOG

/*------------------------------------------------------------------------------
| OMX_MediaProcessorHelper::onFreeRequest
+-----------------------------------------------------------------------------*/
void OMX_MediaProcessorHelper::onFreeRequest()
{
m_provider->free();
m_provider->deinit();
}

/*------------------------------------------------------------------------------
| OMX_MediaProcessor::OMX_MediaProcessor
+-----------------------------------------------------------------------------*/
OMX_MediaProcessor::OMX_MediaProcessor(OMX_EGLBufferProviderSh provider) :
QObject(),
m_provider(provider),
m_thread(new OMX_QThread),
#define THREADED_GL
#ifdef THREADED_GL
m_thread(new QThread),
#else
m_thread(QOpenGLContext::globalShareContext()->thread()),
#endif
m_state(STATE_INACTIVE),
m_mediaStatus(MEDIA_STATUS_NO_MEDIA),
m_sendCmd(QMutex::Recursive),
Expand Down Expand Up @@ -204,7 +220,7 @@ OMX_MediaProcessor::OMX_MediaProcessor(OMX_EGLBufferProviderSh provider) :
moveToThread(m_thread);
m_thread->start();

INVOKE("init");
INVOKE("init", INVOKE_CONN);
}

/*------------------------------------------------------------------------------
Expand All @@ -213,16 +229,21 @@ OMX_MediaProcessor::OMX_MediaProcessor(OMX_EGLBufferProviderSh provider) :
void OMX_MediaProcessor::init()
{
log_info("Initializing GPU context in media processor...");
m_provider->init();

const OMX_MediaProcessorHelper* helper = new OMX_MediaProcessorHelper(m_provider, m_thread);

connect(this, SIGNAL(destroyed(QObject*)),
m_provider.get(), SLOT(free()));
connect(this, SIGNAL(destroyed(QObject*)),
m_provider.get(), SLOT(deinit()));
helper, SLOT(onFreeRequest()));
connect(this, SIGNAL(destroyed(QObject*)),
m_thread, SLOT(quit()));
connect(m_thread, SIGNAL(finished()),
m_thread, SLOT(deleteLater()));
helper, SLOT(deleteLater()));
if (m_thread != QOpenGLContext::globalShareContext()->thread()) {
connect(this, SIGNAL(destroyed(QObject*)),
m_thread, SLOT(quit()));
connect(m_thread, SIGNAL(finished()),
m_thread, SLOT(deleteLater()));
}

m_provider->init();
}

/*------------------------------------------------------------------------------
Expand Down Expand Up @@ -257,7 +278,7 @@ QStringList OMX_MediaProcessor::streams()
+-----------------------------------------------------------------------------*/
bool OMX_MediaProcessor::setFilename(const QString& filename)
{
return INVOKE("setFilenameWrapper", Q_ARG(QString, filename));
return INVOKE("setFilenameWrapper", INVOKE_CONN, Q_ARG(QString, filename));
}

/*------------------------------------------------------------------------------
Expand Down Expand Up @@ -492,15 +513,15 @@ bool OMX_MediaProcessor::playInt()
+-----------------------------------------------------------------------------*/
bool OMX_MediaProcessor::play()
{
return INVOKE("playInt");
return INVOKE("playInt", INVOKE_CONN);
}

/*------------------------------------------------------------------------------
| OMX_MediaProcessor::stop
+-----------------------------------------------------------------------------*/
bool OMX_MediaProcessor::stop()
{
return INVOKE("stopInt");
return INVOKE("stopInt", INVOKE_CONN);
}

/*------------------------------------------------------------------------------
Expand Down Expand Up @@ -544,7 +565,7 @@ bool OMX_MediaProcessor::stopInt()
+-----------------------------------------------------------------------------*/
bool OMX_MediaProcessor::pause()
{
return INVOKE("pauseInt");
return INVOKE("pauseInt", INVOKE_CONN);
}

/*------------------------------------------------------------------------------
Expand Down Expand Up @@ -680,8 +701,8 @@ bool OMX_MediaProcessor::muted()
void OMX_MediaProcessor::mediaDecoding()
{
// See description in the qmakefile.
//#define ENABLE_PROFILE_MAIN_LOOP
//#define ENABLE_PAUSE_FOR_BUFFERING
//#define ENABLE_PROFILE_MAIN_LOOP
//#define ENABLE_PAUSE_FOR_BUFFERING

LOG_VERBOSE(LOG_TAG, "Decoding thread started.");
emit playbackStarted();
Expand Down Expand Up @@ -928,9 +949,30 @@ void OMX_MediaProcessor::mediaDecoding()
if (!m_omx_pkt)
m_omx_pkt = m_omx_reader->Read();

if (m_omx_pkt)
if (m_omx_pkt) {
sendEos = false;

//#define DUMP_FFMPEG_PACKETS
#ifdef DUMP_FFMPEG_PACKETS
OMXPacket* p = m_omx_pkt;
QFile f("demuxed.txt");
if (!f.open(QIODevice::WriteOnly | QIODevice::Append))
log_warn("Failed to open file for writing frames.");
else {
QTextStream s(&f);
s << p->pts << ", "
<< p->dts << ", "
<< p->now << ", "
<< p->duration << ", "
<< p->size << ", "
<< QByteArray::fromRawData((const char*)p->data, p->size) << ", "
<< p->stream_index << ", "
<< p->codec_type << ".";
}
f.close();
#endif
}

if (UNLIKELY(m_omx_reader->IsEof() && !m_omx_pkt)) {
// demuxer EOF, but may have not played out data yet
if ((m_has_video && m_player_video->GetCached()) ||
Expand Down
27 changes: 25 additions & 2 deletions piomxtextures_src/omx_mediaprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ class COMXStreamInfo;
class OMXVideoConfig;
class OMXAudioConfig;

/*------------------------------------------------------------------------------
| OMX_MediaProcessorHelper class
+-----------------------------------------------------------------------------*/
class OMX_MediaProcessorHelper : public QObject
{
Q_OBJECT
public:
OMX_MediaProcessorHelper(OMX_EGLBufferProviderSh provider, QThread* t) {
moveToThread(t);
m_provider = provider;
}

virtual ~OMX_MediaProcessorHelper() {}

public slots:
void onFreeRequest();

private:
OMX_EGLBufferProviderSh m_provider;
};

/*------------------------------------------------------------------------------
| OMX_MediaProcessor class
+-----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -171,7 +192,7 @@ private slots:
void flushStreams(double pts);
void convertMetaData();

OMX_QThread* m_thread;
QThread* m_thread;
QString m_filename;

AVFormatContext* fmt_ctx;
Expand Down Expand Up @@ -263,9 +284,10 @@ inline OMX_MediaProcessor::OMX_MediaStatus OMX_MediaProcessor::mediaStatus() {
| OMX_MediaProcessor::setState
+-----------------------------------------------------------------------------*/
inline void OMX_MediaProcessor::setState(OMX_MediaProcessorState state) {
log_verbose("State changing from %s to %s...", STATE_STR[m_state], STATE_STR[state]);
if (m_state == state)
return;

log_verbose("State changing from %s to %s...", STATE_STR[m_state], STATE_STR[state]);
m_state = state;
emit stateChanged(state);
}
Expand All @@ -276,6 +298,7 @@ inline void OMX_MediaProcessor::setState(OMX_MediaProcessorState state) {
inline void OMX_MediaProcessor::setMediaStatus(OMX_MediaStatus status) {
if (m_mediaStatus == status)
return;

log_verbose("Media status changing from %s to %s...", M_STATUS[m_mediaStatus], M_STATUS[status]);
m_mediaStatus = status;
emit mediaStatusChanged(status);
Expand Down
Loading

0 comments on commit 6320659

Please sign in to comment.