Skip to content

Commit 6320659

Browse files
committed
Fixes for carlonluca#51 and several improvements.
1 parent bf0e76b commit 6320659

File tree

14 files changed

+279
-78
lines changed

14 files changed

+279
-78
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tools/build*
22
*.pro.user*
3-
3rdparty*
3+
3rdparty*/*
44
3rdparty/*
55
openmaxil_backend/3rdparty/*
66
piomxtextures_qt_driver/mediaplayer/.qmake.conf

changelog.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
Changelog
22

3+
Version 5.2.0
4+
=============
5+
1. Bump ffmpeg to 2.8.5.
6+
2. Fixed leaks when video processor is destroyed.
7+
8+
Version 5.1.0
9+
=============
10+
11+
Version 5.0.0
12+
=============
13+
14+
Version 4.5.0
15+
=============
16+
17+
Version 4.4.0
18+
=============
19+
320
Version 4.3.0
421
=============
522
1. Updated for Qt 5.4.0.

piomxtextures_lib/piomxtextures_lib.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
TEMPLATE = lib
2525

26-
VERSION = 5.1.0
26+
VERSION = 5.2.0
2727

2828
QT += core core-private gui gui-private opengl quick quick-private
2929
CONFIG += no_private_qt_headers_warning

piomxtextures_pocplayer/qml/POC_TextPosition.qml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import "POC_StringUtils.js" as POC_StringUtils
2626

2727
// The duration text.
2828
Text {
29-
id: textPosition
30-
text: formatText();
29+
id: textPosition
30+
text: formatText();
3131

32-
function formatText() {
33-
var position = POC_StringUtils.secondsToHHMMSS(parent.source.position/1000);
34-
var duration = POC_StringUtils.secondsToHHMMSS(parent.source.duration/1000);
35-
return position + "/" + duration;
36-
}
32+
function formatText() {
33+
var position = POC_StringUtils.secondsToHHMMSS(parent.source.position/1000);
34+
var duration = POC_StringUtils.secondsToHHMMSS(parent.source.duration/1000);
35+
return position + "/" + duration;
36+
}
3737
}

piomxtextures_qt_driver/mediaplayer/openmaxilplayercontrol.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ OpenMAXILPlayerControl::OpenMAXILPlayerControl(QObject *parent)
7676
: QMediaPlayerControl(parent)
7777
, m_ownStream(false)
7878
, m_seekToStartPending(false)
79-
, m_pendingSeekPosition(-1)
79+
, m_pendingSeekPosition(-1)
8080
, m_texProvider(make_shared<OMX_EGLBufferProvider>())
8181
, m_mediaProcessor(new OMX_MediaProcessor(m_texProvider))
8282
, m_renderer(NULL)
8383
{
84-
logi_debug_func;
84+
logi_debug_func;
8585

8686
connect(m_mediaProcessor, SIGNAL(stateChanged(OMX_MediaProcessor::OMX_MediaProcessorState)),
8787
this, SLOT(onStateChanged(OMX_MediaProcessor::OMX_MediaProcessorState)));
8888
connect(m_mediaProcessor, SIGNAL(mediaStatusChanged(OMX_MediaProcessor::OMX_MediaStatus)),
8989
this, SLOT(onMediaStatusChanged(OMX_MediaProcessor::OMX_MediaStatus)));
9090
connect(m_mediaProcessor, SIGNAL(metadataChanged(QVariantMap)),
91-
this, SIGNAL(metaDataChanged(QVariantMap)));
91+
this, SIGNAL(metaDataChanged(QVariantMap)));
9292
}
9393

9494
/*------------------------------------------------------------------------------

piomxtextures_qt_driver/mediaplayer/openmaxilplayercontrol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private slots:
127127
bool m_ownStream;
128128
bool m_seekToStartPending;
129129

130-
qint64 m_pendingSeekPosition;
130+
qint64 m_pendingSeekPosition;
131131

132132
QMediaContent m_currentResource;
133133

piomxtextures_qt_driver/mediaplayer/openmaxilvideorenderercontrol.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QVideoSurfaceFormat>
3030
#include <QTimer>
3131
#include <QMutex>
32+
#include <QDateTime>
3233
#ifdef OGL_CONTEXT_FROM_SURFACE
3334
#include <QVariant>
3435
#endif // OGL_CONTEXT_FROM_SURFACE
@@ -37,6 +38,37 @@
3738

3839
#include "omx_logging.h"
3940

41+
/*------------------------------------------------------------------------------
42+
| definitions
43+
+-----------------------------------------------------------------------------*/
44+
//#define OMX_RENDER_WATCHDOG
45+
#define OMX_RENDER_WATCHDOG_FILE "/tmp/omx_render_signal"
46+
47+
#ifdef OMX_RENDER_WATCHDOG
48+
/*------------------------------------------------------------------------------
49+
| handleWatchdogFile
50+
+-----------------------------------------------------------------------------*/
51+
inline void handleWatchdogFile()
52+
{
53+
static QFile f(OMX_RENDER_WATCHDOG_FILE);
54+
static QDateTime lastTouch = QDateTime::currentDateTime();
55+
56+
const QDateTime current = QDateTime::currentDateTime();
57+
if (current.toMSecsSinceEpoch() - lastTouch.toMSecsSinceEpoch() < 1000)
58+
return;
59+
60+
if (!f.open(QIODevice::WriteOnly)) {
61+
log_warn("Failed to touch " OMX_RENDER_WATCHDOG_FILE ".");
62+
return;
63+
}
64+
65+
lastTouch = current;
66+
67+
f.close();
68+
}
69+
70+
#endif // OMX_RENDER_WATCHDOG
71+
4072
/*------------------------------------------------------------------------------
4173
| OpenMAXILVideoBuffer class
4274
+-----------------------------------------------------------------------------*/
@@ -191,7 +223,7 @@ void OpenMAXILVideoRendererControl::onTexturesReady()
191223
// Just take one random texture to determine the size. Do not place
192224
// any texture yet in the scene as I can't guarantee it is filled
193225
// already with valid data.
194-
m_buffer = new OpenMAXILVideoBuffer(
226+
m_buffer = new OpenMAXILVideoBuffer(
195227
QAbstractVideoBuffer::GLTextureHandle,
196228
0
197229
);
@@ -244,11 +276,10 @@ void OpenMAXILVideoRendererControl::onUpdateTriggered()
244276
return;
245277
if (UNLIKELY(!m_surface || !m_frame || !m_surfaceFormat))
246278
return;
247-
248279
if (UNLIKELY(!m_surface->isActive() && !m_surface->start(*m_surfaceFormat)))
249280
log_warn("Failed to start surface.");
250281

251-
GLuint t = m_mediaProcessor->m_provider->getNextTexture();
282+
const GLuint t = m_mediaProcessor->m_provider->getNextTexture();
252283

253284
// It seems that in some cases the fillBufferDone arrives even after
254285
// completely flushing the pipeline. This presents frames to be shown
@@ -257,6 +288,10 @@ void OpenMAXILVideoRendererControl::onUpdateTriggered()
257288
return;
258289
m_buffer->setHandle(t);
259290
m_surface->present(*m_frame);
291+
292+
#ifdef OMX_RENDER_WATCHDOG
293+
handleWatchdogFile();
294+
#endif // OMX_RENDER_WATCHDOG
260295
}
261296

262297
/*------------------------------------------------------------------------------

piomxtextures_src/omx_mediaprocessor.cpp

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ const char* OMX_MediaProcessor::M_STATUS[] = {
9797

9898
#define INVOKE(...) \
9999
QMetaObject::invokeMethod(this, __VA_ARGS__)
100+
#define INVOKE_CONN \
101+
Qt::QueuedConnection
100102

101103
/*------------------------------------------------------------------------------
102104
| get_mem_gpu
@@ -136,13 +138,27 @@ static void start_watchdog_once()
136138
}
137139
#endif // OMX_LOCK_WATCHDOG
138140

141+
/*------------------------------------------------------------------------------
142+
| OMX_MediaProcessorHelper::onFreeRequest
143+
+-----------------------------------------------------------------------------*/
144+
void OMX_MediaProcessorHelper::onFreeRequest()
145+
{
146+
m_provider->free();
147+
m_provider->deinit();
148+
}
149+
139150
/*------------------------------------------------------------------------------
140151
| OMX_MediaProcessor::OMX_MediaProcessor
141152
+-----------------------------------------------------------------------------*/
142153
OMX_MediaProcessor::OMX_MediaProcessor(OMX_EGLBufferProviderSh provider) :
143154
QObject(),
144155
m_provider(provider),
145-
m_thread(new OMX_QThread),
156+
#define THREADED_GL
157+
#ifdef THREADED_GL
158+
m_thread(new QThread),
159+
#else
160+
m_thread(QOpenGLContext::globalShareContext()->thread()),
161+
#endif
146162
m_state(STATE_INACTIVE),
147163
m_mediaStatus(MEDIA_STATUS_NO_MEDIA),
148164
m_sendCmd(QMutex::Recursive),
@@ -204,7 +220,7 @@ OMX_MediaProcessor::OMX_MediaProcessor(OMX_EGLBufferProviderSh provider) :
204220
moveToThread(m_thread);
205221
m_thread->start();
206222

207-
INVOKE("init");
223+
INVOKE("init", INVOKE_CONN);
208224
}
209225

210226
/*------------------------------------------------------------------------------
@@ -213,16 +229,21 @@ OMX_MediaProcessor::OMX_MediaProcessor(OMX_EGLBufferProviderSh provider) :
213229
void OMX_MediaProcessor::init()
214230
{
215231
log_info("Initializing GPU context in media processor...");
216-
m_provider->init();
232+
233+
const OMX_MediaProcessorHelper* helper = new OMX_MediaProcessorHelper(m_provider, m_thread);
217234

218235
connect(this, SIGNAL(destroyed(QObject*)),
219-
m_provider.get(), SLOT(free()));
220-
connect(this, SIGNAL(destroyed(QObject*)),
221-
m_provider.get(), SLOT(deinit()));
236+
helper, SLOT(onFreeRequest()));
222237
connect(this, SIGNAL(destroyed(QObject*)),
223-
m_thread, SLOT(quit()));
224-
connect(m_thread, SIGNAL(finished()),
225-
m_thread, SLOT(deleteLater()));
238+
helper, SLOT(deleteLater()));
239+
if (m_thread != QOpenGLContext::globalShareContext()->thread()) {
240+
connect(this, SIGNAL(destroyed(QObject*)),
241+
m_thread, SLOT(quit()));
242+
connect(m_thread, SIGNAL(finished()),
243+
m_thread, SLOT(deleteLater()));
244+
}
245+
246+
m_provider->init();
226247
}
227248

228249
/*------------------------------------------------------------------------------
@@ -257,7 +278,7 @@ QStringList OMX_MediaProcessor::streams()
257278
+-----------------------------------------------------------------------------*/
258279
bool OMX_MediaProcessor::setFilename(const QString& filename)
259280
{
260-
return INVOKE("setFilenameWrapper", Q_ARG(QString, filename));
281+
return INVOKE("setFilenameWrapper", INVOKE_CONN, Q_ARG(QString, filename));
261282
}
262283

263284
/*------------------------------------------------------------------------------
@@ -492,15 +513,15 @@ bool OMX_MediaProcessor::playInt()
492513
+-----------------------------------------------------------------------------*/
493514
bool OMX_MediaProcessor::play()
494515
{
495-
return INVOKE("playInt");
516+
return INVOKE("playInt", INVOKE_CONN);
496517
}
497518

498519
/*------------------------------------------------------------------------------
499520
| OMX_MediaProcessor::stop
500521
+-----------------------------------------------------------------------------*/
501522
bool OMX_MediaProcessor::stop()
502523
{
503-
return INVOKE("stopInt");
524+
return INVOKE("stopInt", INVOKE_CONN);
504525
}
505526

506527
/*------------------------------------------------------------------------------
@@ -544,7 +565,7 @@ bool OMX_MediaProcessor::stopInt()
544565
+-----------------------------------------------------------------------------*/
545566
bool OMX_MediaProcessor::pause()
546567
{
547-
return INVOKE("pauseInt");
568+
return INVOKE("pauseInt", INVOKE_CONN);
548569
}
549570

550571
/*------------------------------------------------------------------------------
@@ -680,8 +701,8 @@ bool OMX_MediaProcessor::muted()
680701
void OMX_MediaProcessor::mediaDecoding()
681702
{
682703
// See description in the qmakefile.
683-
//#define ENABLE_PROFILE_MAIN_LOOP
684-
//#define ENABLE_PAUSE_FOR_BUFFERING
704+
//#define ENABLE_PROFILE_MAIN_LOOP
705+
//#define ENABLE_PAUSE_FOR_BUFFERING
685706

686707
LOG_VERBOSE(LOG_TAG, "Decoding thread started.");
687708
emit playbackStarted();
@@ -928,9 +949,30 @@ void OMX_MediaProcessor::mediaDecoding()
928949
if (!m_omx_pkt)
929950
m_omx_pkt = m_omx_reader->Read();
930951

931-
if (m_omx_pkt)
952+
if (m_omx_pkt) {
932953
sendEos = false;
933954

955+
//#define DUMP_FFMPEG_PACKETS
956+
#ifdef DUMP_FFMPEG_PACKETS
957+
OMXPacket* p = m_omx_pkt;
958+
QFile f("demuxed.txt");
959+
if (!f.open(QIODevice::WriteOnly | QIODevice::Append))
960+
log_warn("Failed to open file for writing frames.");
961+
else {
962+
QTextStream s(&f);
963+
s << p->pts << ", "
964+
<< p->dts << ", "
965+
<< p->now << ", "
966+
<< p->duration << ", "
967+
<< p->size << ", "
968+
<< QByteArray::fromRawData((const char*)p->data, p->size) << ", "
969+
<< p->stream_index << ", "
970+
<< p->codec_type << ".";
971+
}
972+
f.close();
973+
#endif
974+
}
975+
934976
if (UNLIKELY(m_omx_reader->IsEof() && !m_omx_pkt)) {
935977
// demuxer EOF, but may have not played out data yet
936978
if ((m_has_video && m_player_video->GetCached()) ||

piomxtextures_src/omx_mediaprocessor.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ class COMXStreamInfo;
6767
class OMXVideoConfig;
6868
class OMXAudioConfig;
6969

70+
/*------------------------------------------------------------------------------
71+
| OMX_MediaProcessorHelper class
72+
+-----------------------------------------------------------------------------*/
73+
class OMX_MediaProcessorHelper : public QObject
74+
{
75+
Q_OBJECT
76+
public:
77+
OMX_MediaProcessorHelper(OMX_EGLBufferProviderSh provider, QThread* t) {
78+
moveToThread(t);
79+
m_provider = provider;
80+
}
81+
82+
virtual ~OMX_MediaProcessorHelper() {}
83+
84+
public slots:
85+
void onFreeRequest();
86+
87+
private:
88+
OMX_EGLBufferProviderSh m_provider;
89+
};
90+
7091
/*------------------------------------------------------------------------------
7192
| OMX_MediaProcessor class
7293
+-----------------------------------------------------------------------------*/
@@ -171,7 +192,7 @@ private slots:
171192
void flushStreams(double pts);
172193
void convertMetaData();
173194

174-
OMX_QThread* m_thread;
195+
QThread* m_thread;
175196
QString m_filename;
176197

177198
AVFormatContext* fmt_ctx;
@@ -263,9 +284,10 @@ inline OMX_MediaProcessor::OMX_MediaStatus OMX_MediaProcessor::mediaStatus() {
263284
| OMX_MediaProcessor::setState
264285
+-----------------------------------------------------------------------------*/
265286
inline void OMX_MediaProcessor::setState(OMX_MediaProcessorState state) {
266-
log_verbose("State changing from %s to %s...", STATE_STR[m_state], STATE_STR[state]);
267287
if (m_state == state)
268288
return;
289+
290+
log_verbose("State changing from %s to %s...", STATE_STR[m_state], STATE_STR[state]);
269291
m_state = state;
270292
emit stateChanged(state);
271293
}
@@ -276,6 +298,7 @@ inline void OMX_MediaProcessor::setState(OMX_MediaProcessorState state) {
276298
inline void OMX_MediaProcessor::setMediaStatus(OMX_MediaStatus status) {
277299
if (m_mediaStatus == status)
278300
return;
301+
279302
log_verbose("Media status changing from %s to %s...", M_STATUS[m_mediaStatus], M_STATUS[status]);
280303
m_mediaStatus = status;
281304
emit mediaStatusChanged(status);

0 commit comments

Comments
 (0)