Skip to content

Commit b054b0d

Browse files
committed
Add configurable permits for omx lock + other improvements.
1 parent 1a1c9ce commit b054b0d

File tree

13 files changed

+120
-49
lines changed

13 files changed

+120
-49
lines changed

piomxtextures_pocplayer/piomxtextures_pocplayer.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ CONFIG += -std=c++11
2727

2828
INCLUDEPATH += $$_PRO_FILE_PWD_/../3rdparty/LightLogger
2929

30-
SOURCES += main.cpp \
30+
SOURCES += main.cpp \
3131
poc_qmlutils.cpp \
3232
poc_utils.cpp \
3333
poc_uptime.cpp

piomxtextures_samples/piomxtextures_samples.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ TEMPLATE = lib
2525

2626
QT += quick multimedia
2727

28-
OTHER_FILES += video_*
28+
OTHER_FILES += video*
2929

3030
DISTFILES += \
3131
audio_simple.qml \

piomxtextures_src/omx_logging.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@
33
* Author: Luca Carlon
44
* Date: 05.07.2015
55
*
6-
* Copyright (c) 2015 Luca Carlon. All rights reserved.
6+
* Copyright (c) 2016 Luca Carlon.
7+
* All rights reserved.
78
*
8-
* This file is part of PiOmxTextures.
9-
*
10-
* PiOmxTextures is free software: you can redistribute it and/or modify
11-
* it under the terms of the GNU General Public License as published by
12-
* the Free Software Foundation, either version 3 of the License, or
13-
* (at your option) any later version.
14-
*
15-
* PiOmxTextures is distributed in the hope that it will be useful,
16-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18-
* GNU General Public License for more details.
19-
*
20-
* You should have received a copy of the GNU General Public License
21-
* along with PiOmxTextures. If not, see <http://www.gnu.org/licenses/>.
9+
* Redistribution and use in source and binary forms are permitted
10+
* provided that the above copyright notice and this paragraph are
11+
* duplicated in all such forms and that any documentation,
12+
* advertising materials, and other materials related to such
13+
* distribution and use acknowledge that the software was developed
14+
* by Luca Carlon. The name of Luca Carlon may not be
15+
* used to endorse or promote products derived
16+
* from this software without specific prior written permission.
17+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18+
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2220
*/
2321

2422
#ifndef OMX_LOGGING_H

piomxtextures_src/omx_mediaprocessor.cpp

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ OMX_MediaProcessor::OMX_MediaProcessor(OMX_EGLBufferProviderSh provider) :
186186
m_buffer_empty(true),
187187
m_pendingStop(false),
188188
m_pendingPause(false),
189+
m_pendingSeek(false),
189190
m_subtitle_index(0),
190191
m_audio_index(0),
191192
m_streamLength(0),
@@ -509,6 +510,7 @@ bool OMX_MediaProcessor::playInt()
509510
return false;
510511
}
511512

513+
log_info("Play command received.");
512514
if (m_av_clock->OMXPlaySpeed() != DVD_PLAYSPEED_NORMAL && m_av_clock->OMXPlaySpeed() != DVD_PLAYSPEED_PAUSE) {
513515
LOG_VERBOSE(LOG_TAG, "resume\n");
514516
m_playspeedCurrent = playspeed_normal;
@@ -573,6 +575,7 @@ bool OMX_MediaProcessor::stopInt()
573575
return false;
574576
}
575577

578+
log_info("Stop command received.");
576579
m_pendingStop = true;
577580

578581
// Wait for command completion.
@@ -622,33 +625,43 @@ bool OMX_MediaProcessor::pauseInt()
622625
m_player_subtitles.Pause();
623626
#endif
624627

628+
log_info("Pause command received");
625629
setSpeed(playspeeds[m_playspeedCurrent]);
626630
m_av_clock->OMXPause();
627631

628632
// Wait for command completion.
629633
m_mutexPending.lock();
630634
if (m_pendingPause) {
631-
LOG_VERBOSE(LOG_TAG, "Waiting for the pause command to finish.");
635+
LOG_VERBOSE(LOG_TAG, "Waiting for the pause command to finish");
632636
m_waitPendingCommand.wait(&m_mutexPending);
633637
}
634638
m_mutexPending.unlock();
635639

636640
setState(STATE_PAUSED);
637641

638-
log_verbose("Pause command issued.");
642+
log_verbose("Pause command completed");
639643
return true;
640644
}
641645

642646
/*------------------------------------------------------------------------------
643647
| OMX_MediaProcessor::seek
644648
+-----------------------------------------------------------------------------*/
645649
bool OMX_MediaProcessor::seek(qint64 position)
650+
{
651+
return INVOKE("seekInt",
652+
INVOKE_CONN,
653+
Q_ARG(qint64, position));
654+
}
655+
656+
/*------------------------------------------------------------------------------
657+
| OMX_MediaProcessor::seekInt
658+
+-----------------------------------------------------------------------------*/
659+
bool OMX_MediaProcessor::seekInt(qint64 position)
646660
{
647661
QMutexLocker locker(&m_sendCmd);
648662

649-
LOG_VERBOSE(LOG_TAG, "Seek %lldms.", position);
650663
if (!m_av_clock)
651-
return false;
664+
return false;
652665

653666
// Get current position in ms.
654667
qint64 currentMs = m_av_clock->OMXMediaTime(false)*1E-3;
@@ -658,8 +671,19 @@ bool OMX_MediaProcessor::seek(qint64 position)
658671
if (!incrementMs)
659672
return true;
660673

674+
log_info("Seek command to %lldms received", position);
661675
m_incrMs = incrementMs;
676+
m_pendingSeek = true;
677+
678+
// Wait for command completion.
679+
m_mutexPending.lock();
680+
if (m_pendingSeek) {
681+
log_verbose("Waiting for the seek command to finish.");
682+
m_waitPendingCommand.wait(&m_mutexPending);
683+
}
684+
m_mutexPending.unlock();
662685

686+
log_verbose("Seek command completed");
663687
return true;
664688
}
665689

@@ -830,16 +854,20 @@ void OMX_MediaProcessor::mediaDecoding()
830854

831855
if (m_omx_reader->SeekTime((int)seek_pos, m_incrMs < 0.0f, &startpts)) {
832856
unsigned t = (unsigned)(startpts*1e-6);
833-
log_info("Seek to: %02d:%02d:%02d", (t/3600), (t/60)%60, t%60);
857+
log_verbose("Seeked to: %02d:%02d:%02d", (t/3600), (t/60)%60, t%60);
834858
flushStreams(startpts);
859+
log_debug("Streams flushed");
835860
}
836861

837862
sentStarted = false;
838863

839-
if (m_omx_reader->IsEof())
864+
if (m_omx_reader->IsEof()) {
865+
log_debug("EOF");
840866
break;
867+
}
841868

842869
if (m_has_video && !m_player_video->Reset()) {
870+
log_debug("RESET failed on seek");
843871
m_incrMs = 0;
844872
break;
845873
}
@@ -861,6 +889,13 @@ void OMX_MediaProcessor::mediaDecoding()
861889
m_packetAfterSeek = false;
862890
m_seekFlush = false;
863891
m_incrMs = 0;
892+
893+
m_mutexPending.lock();
894+
if (UNLIKELY(m_pendingSeek)) {
895+
m_waitPendingCommand.wakeAll();
896+
m_pendingSeek = false;
897+
}
898+
m_mutexPending.unlock();
864899
}
865900
else if (UNLIKELY(m_packetAfterSeek && TRICKPLAY(m_av_clock->OMXPlaySpeed()))) {
866901
double seek_pos = 0;
@@ -969,11 +1004,12 @@ void OMX_MediaProcessor::mediaDecoding()
9691004
// Enable this to enable pause for buffering.
9701005
if (m_state != STATE_PAUSED && (m_omx_reader->IsEof() || m_omx_pkt || TRICKPLAY(m_av_clock->OMXPlaySpeed()) || (audio_fifo_high && video_fifo_high))) {
9711006
if (m_av_clock->OMXIsPaused()) {
972-
log_verbose("Resume %.2f,%.2f (%d,%d,%d,%d) EOF:%d PKT:%p\n",
1007+
log_verbose("Resume %.2f,%.2f (%d,%d,%d,%d) EOF:%d PKT:%p",
9731008
audio_fifo, video_fifo, audio_fifo_low, video_fifo_low, audio_fifo_high, video_fifo_high, m_omx_reader->IsEof(), m_omx_pkt);
9741009

9751010
setMediaStatus(OMX_MediaStatus::MEDIA_STATUS_BUFFERED);
9761011
m_av_clock->OMXResume();
1012+
log_debug("Resume completed");
9771013
}
9781014
}
9791015
else if (m_state == STATE_PAUSED || audio_fifo_low || video_fifo_low)
@@ -1139,29 +1175,40 @@ void OMX_MediaProcessor::setSpeed(int iSpeed)
11391175
+-----------------------------------------------------------------------------*/
11401176
void OMX_MediaProcessor::flushStreams(double pts)
11411177
{
1178+
log_debug("Stopping av_clock");
11421179
m_av_clock->OMXStop();
1180+
1181+
log_debug("Pausing av_clock");
11431182
m_av_clock->OMXPause();
11441183

11451184
if (m_has_video) {
1185+
log_verbose("Flushing");
11461186
m_player_video->Flush();
11471187
m_provider->flush();
11481188
}
11491189

1150-
if (m_has_audio)
1190+
if (m_has_audio) {
1191+
log_debug("Flushing audio");
11511192
m_player_audio->Flush();
1193+
}
11521194

1153-
if (pts != DVD_NOPTS_VALUE)
1195+
if (pts != DVD_NOPTS_VALUE) {
1196+
log_debug("Set media time in flushStreams");
11541197
m_av_clock->OMXMediaTime(pts);
1198+
}
11551199

11561200
#ifdef ENABLE_SUBTITLES
11571201
if (m_has_subtitle)
11581202
m_player_subtitles->Flush();
11591203
#endif
11601204

11611205
if (m_omx_pkt) {
1206+
log_debug("Freeing packet in flushStreams");
11621207
m_omx_reader->FreePacket(m_omx_pkt);
11631208
m_omx_pkt = NULL;
11641209
}
1210+
1211+
log_debug("flushStreams finished");
11651212
}
11661213

11671214
/*------------------------------------------------------------------------------

piomxtextures_src/omx_mediaprocessor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ private slots:
186186
bool playInt();
187187
bool stopInt();
188188
bool pauseInt();
189+
bool seekInt(qint64 position);
189190
void mediaDecoding();
190191
void closeAll();
191192
bool cleanup();
@@ -228,7 +229,8 @@ private slots:
228229
#endif
229230
bool m_buffer_empty;
230231
bool m_pendingStop;
231-
bool m_pendingPause;
232+
bool m_pendingPause;
233+
bool m_pendingSeek;
232234

233235
int m_subtitle_index;
234236
int m_audio_index;

piomxtextures_src/omx_omxplayer_logging.cpp

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

5454
#include "omx_logging.h"
5555

56-
#define ENABLE_OMXPLAYER_LOGS
56+
//#define ENABLE_OMXPLAYER_LOGS
5757

5858
/*------------------------------------------------------------------------------
5959
| definitions

piomxtextures_src/omx_staticconf.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static std::once_flag flag2;
3636
static std::once_flag flag3;
3737
static std::once_flag flag4;
3838
static std::once_flag flag5;
39+
static std::once_flag flag6;
3940

4041
/*------------------------------------------------------------------------------
4142
| OMX_StaticConf::getHalfFramerate
@@ -133,8 +134,26 @@ QString OMX_StaticConf::getOmxWatchdogFile()
133134
return;
134135
watchdogFile = QString(ba);
135136

136-
log_verbose("OMX_HEALTHY is %s", qPrintable(watchdogFile));
137+
log_info("OMX_HEALTHY is %s", qPrintable(watchdogFile));
137138
});
138139

139140
return watchdogFile;
140141
}
142+
143+
/*------------------------------------------------------------------------------
144+
| OMX_StaticConf::getOmxWatchdogPermits
145+
+-----------------------------------------------------------------------------*/
146+
int OMX_StaticConf::getOmxWatchdogPermits()
147+
{
148+
static int watchdogPermits = 1000;
149+
std::call_once(flag6, [] {
150+
QByteArray omxPermits = qgetenv("OMX_PERMITS");
151+
if (omxPermits.isEmpty() || omxPermits.isNull())
152+
return;
153+
watchdogPermits = QString::fromUtf8(omxPermits).toInt();
154+
155+
log_info("OMX_PERMITS is %d", watchdogPermits);
156+
});
157+
158+
return watchdogPermits;
159+
}

piomxtextures_src/omx_staticconf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class OMX_StaticConf
3939
static int getInterlaceQpu();
4040
static int getTextureCount();
4141
static bool getHalfFramerate();
42-
static QString getOmxWatchdogFile();
42+
static QString getOmxWatchdogFile();
43+
static int getOmxWatchdogPermits();
4344
};
4445

4546
#endif // OMX_STATICCONF_H

piomxtextures_src/omx_textureprovider.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,15 @@ class OMX_EGLBufferProvider : public QObject
144144
m_emptyQueue.clear();
145145
m_filledQueue.clear();
146146
m_currentDecoder = NULL;
147-
m_currentRenderer = NULL;
147+
148+
// Leave the current texture in the renderer.
149+
//m_currentRenderer = NULL;
148150

149151
m_emptyQueue.append(m_available);
150-
m_semEmpty.release(TEXTURE_COUNT - m_semEmpty.available());
152+
m_emptyQueue.removeAll(m_currentRenderer);
153+
154+
int t = m_currentRenderer ? 1 : 0;
155+
m_semEmpty.release(TEXTURE_COUNT - m_semEmpty.available() - t);
151156
}
152157

153158
public slots:

piomxtextures_src/omxplayer_lib/OMXCore.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
#endif
3939

4040
#include <omx_logging.h>
41+
#include <omx_staticconf.h>
4142

4243
//#define OMX_DEBUG_EVENTS
4344
//#define OMX_DEBUG_EVENTHANDLER
4445

4546
#ifdef OMX_THREAD_UNSAFE
4647
#define log_lock log_disabled
4748

48-
// lcarlon: temporary implementation.
49-
QSemaphore COMXCoreComponent::m_mxOmx(2);
49+
QSemaphore COMXCoreComponent::m_mxOmx(OMX_StaticConf::getOmxWatchdogPermits());
5050

5151
/*------------------------------------------------------------------------------
5252
| COMXCoreComponent::testOmx
@@ -55,7 +55,7 @@ bool COMXCoreComponent::testOmx()
5555
{
5656
// Try to lock and timeout in 1s.
5757
log_debug("Testing OpenMAX health...");
58-
const bool alive = m_mxOmx.tryAcquire(1, 1000);
58+
const bool alive = m_mxOmx.tryAcquire(1, 1000);
5959
if (alive)
6060
m_mxOmx.release();
6161

0 commit comments

Comments
 (0)