[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kaffeine/2.0.1] src: dvbliveview: show play time
From:       Mauro Carvalho Chehab <mchehab () osg ! samsung ! com>
Date:       2016-05-31 16:07:02
Message-ID: E1b7mC6-0006he-Ee () scm ! kde ! org
[Download RAW message or body]

Git commit 4654c8cbf801f13bb2965396bca6a860ecbf28b9 by Mauro Carvalho Chehab.
Committed on 31/05/2016 at 15:51.
Pushed by mauroc into tag '2.0.1'.

dvbliveview: show play time

While we cannot seek with dvb liveview, let's at least
show the play time.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

M  +4    -1    src/backend-vlc/vlcmediawidget.cpp
M  +25   -0    src/dvb/dvbliveview.cpp
M  +3    -0    src/dvb/dvbliveview_p.h
M  +4    -4    src/mediawidget.cpp
M  +1    -0    src/mediawidget.h

http://commits.kde.org/kaffeine/4654c8cbf801f13bb2965396bca6a860ecbf28b9

diff --git a/src/backend-vlc/vlcmediawidget.cpp b/src/backend-vlc/vlcmediawidget.cpp
index 5ab0eb8..672b5b4 100644
--- a/src/backend-vlc/vlcmediawidget.cpp
+++ b/src/backend-vlc/vlcmediawidget.cpp
@@ -377,6 +377,9 @@ int VlcMediaWidget::updatePlaybackStatus()
 
 void VlcMediaWidget::updateCurrentTotalTime()
 {
+	if (playbackStatus == MediaWidget::Idle)
+		return;
+
 	currentTime = int(libvlc_media_player_get_time(vlcMediaPlayer));
 	totalTime = int(libvlc_media_player_get_length(vlcMediaPlayer));
 
@@ -388,7 +391,7 @@ void VlcMediaWidget::updateCurrentTotalTime()
 		totalTime = 0;
 	}
 
-	if (currentTime > totalTime) {
+	if (totalTime && currentTime > totalTime) {
 		currentTime = totalTime;
 	}
 }
diff --git a/src/dvb/dvbliveview.cpp b/src/dvb/dvbliveview.cpp
index 21aa3e3..8d80c4f 100644
--- a/src/dvb/dvbliveview.cpp
+++ b/src/dvb/dvbliveview.cpp
@@ -605,6 +605,8 @@ qInfo() << "DvbLiveViewInternal::DvbLiveViewInternal";
 	notifier = new QSocketNotifier(writeFd, QSocketNotifier::Write, this);
 	notifier->setEnabled(false);
 	connect(notifier, SIGNAL(activated(int)), this, SLOT(writeToPipe()));
+
+	emptyBuffer = true;
 }
 
 DvbLiveViewInternal::~DvbLiveViewInternal()
@@ -634,6 +636,7 @@ void DvbLiveViewInternal::resetPipe()
 		}
 	}
 
+	emptyBuffer = true;
 	buffer.clear();
 }
 
@@ -664,6 +667,20 @@ void DvbLiveViewInternal::writeToPipe()
 	}
 }
 
+void DvbLiveViewInternal::validateCurrentTotalTime(int &currentTime, int &totalTime) const
+{
+	if (emptyBuffer)
+		return;
+
+	totalTime = startTime.msecsTo(QTime::currentTime());
+
+	// Adjust it, if needed
+	if (currentTime > totalTime)
+		currentTime = totalTime -1;
+
+}
+
+
 void DvbLiveViewInternal::processData(const char data[188])
 {
 	buffer.append(data, 188);
@@ -676,9 +693,17 @@ void DvbLiveViewInternal::processData(const char data[188])
 		if (writeFd >= 0) {
 			buffers.append(buffer);
 			writeToPipe();
+			if (emptyBuffer) {
+				startTime = QTime::currentTime();
+				emptyBuffer = false;
+			}
 		}
 	} else {
 		timeShiftFile.write(buffer); // FIXME avoid buffer reallocation
+		if (emptyBuffer) {
+			startTime = QTime::currentTime();
+			emptyBuffer = false;
+		}
 	}
 
 	buffer.clear();
diff --git a/src/dvb/dvbliveview_p.h b/src/dvb/dvbliveview_p.h
index 69fba5b..48f31c2 100644
--- a/src/dvb/dvbliveview_p.h
+++ b/src/dvb/dvbliveview_p.h
@@ -73,6 +73,8 @@ public:
 	QFile timeShiftFile;
 	QString fileName;
 	DvbOsd dvbOsd;
+	bool emptyBuffer;
+	QTime startTime;
 
 	bool overrideAudioStreams() const { return !audioStreams.isEmpty(); }
 	bool overrideSubtitles() const { return !subtitles.isEmpty(); }
@@ -108,6 +110,7 @@ public:
 			url = QUrl::fromLocalFile(fileName);
 	}
 
+	virtual void validateCurrentTotalTime(int &currentTime, int &totalTime) const;
 	bool hideCurrentTotalTime() const { return !timeshift; }
 
 	bool timeshift;
diff --git a/src/mediawidget.cpp b/src/mediawidget.cpp
index d77f612..5c8cbb1 100644
--- a/src/mediawidget.cpp
+++ b/src/mediawidget.cpp
@@ -1005,10 +1005,9 @@ void MediaWidget::currentTotalTimeChanged()
 	if (source->getType() == MediaSource::Url)
 		emit playlistTrackLengthChanged(totalTime);
 
-	if (source->hideCurrentTotalTime()) {
-		currentTime = 0;
-		totalTime = 0;
-	}
+	// If the player backend doesn't implement currentTime and/or
+	// totalTime, the source can implement such logic
+	source->validateCurrentTotalTime(currentTime, totalTime);
 
 	blockBackendUpdates = true;
 	seekSlider->setRange(0, totalTime);
@@ -1030,6 +1029,7 @@ void MediaWidget::seekableChanged()
 	seekSlider->setEnabled(seekable);
 	navigationMenu->setEnabled(seekable);
 	jumpToPositionAction->setEnabled(seekable);
+	timeButton->setEnabled(seekable);
 }
 
 void MediaWidget::contextMenuEvent(QContextMenuEvent *event)
diff --git a/src/mediawidget.h b/src/mediawidget.h
index 85b761e..6bd6d27 100644
--- a/src/mediawidget.h
+++ b/src/mediawidget.h
@@ -256,6 +256,7 @@ public:
 
 	virtual Type getType() const { return Url; }
 	virtual QUrl getUrl() const { return QUrl(); }
+	virtual void validateCurrentTotalTime(int &, int &) const { }
 	virtual bool hideCurrentTotalTime() const { return false; }
 	virtual bool overrideAudioStreams() const { return false; }
 	virtual bool overrideSubtitles() const { return false; }

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic