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

List:       kde-commits
Subject:    extragear/network/ktorrent
From:       Joris Guisson <joris.guisson () gmail ! com>
Date:       2010-10-10 17:55:00
Message-ID: 20101010175500.AEE8E3E1F2 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1184530 by guisson:

Add chunkbar in VideoWidget when showing a stream, also improve stability of media \
player

 M  +2 -2      libktcore/torrent/chunkbar.cpp  
 M  +1 -1      libktcore/torrent/chunkbar.h  
 M  +1 -0      plugins/mediaplayer/CMakeLists.txt  
 M  +15 -0     plugins/mediaplayer/mediafile.cpp  
 M  +3 -0      plugins/mediaplayer/mediafile.h  
 M  +26 -0     plugins/mediaplayer/mediafilestream.cpp  
 M  +1 -0      plugins/mediaplayer/mediafilestream.h  
 M  +11 -1     plugins/mediaplayer/mediaplayer.cpp  
 M  +5 -2      plugins/mediaplayer/mediaplayeractivity.cpp  
 A             plugins/mediaplayer/videochunkbar.cpp   [License: GPL (v2+)]
 A             plugins/mediaplayer/videochunkbar.h   \
plugins/mediaplayer/mediafilestream.h#1184437 [License: GPL (v2+)]  M  +32 -10    \
plugins/mediaplayer/videowidget.cpp    M  +4 -0      \
plugins/mediaplayer/videowidget.h  


--- trunk/extragear/network/ktorrent/libktcore/torrent/chunkbar.cpp #1184529:1184530
@@ -100,14 +100,14 @@
 	ChunkBar::~ChunkBar()
 	{}
 	
-	void ChunkBar::updateBar()
+	void ChunkBar::updateBar(bool force)
 	{
 		const BitSet & bs = getBitSet();
 		QSize s = contentsRect().size();
 		
 		bool changed = !(curr == bs);
 
-		if (changed || pixmap.isNull() || pixmap.width() != s.width())
+		if (changed || pixmap.isNull() || pixmap.width() != s.width() || force)
 		{
 			pixmap = QPixmap(s);
 			pixmap.fill(palette().color(QPalette::Active,QPalette::Base));
--- trunk/extragear/network/ktorrent/libktcore/torrent/chunkbar.h #1184529:1184530
@@ -55,7 +55,7 @@
 	
 		virtual const bt::BitSet & getBitSet() const = 0;
 		virtual void drawContents(QPainter *p);
-		virtual void updateBar();
+		virtual void updateBar(bool force = false);
 	
 	protected:
 		
--- trunk/extragear/network/ktorrent/plugins/mediaplayer/CMakeLists.txt \
#1184529:1184530 @@ -12,6 +12,7 @@
 	mediafilestream.cpp 
 	mediaplayer.cpp 
 	videowidget.cpp
+	videochunkbar.cpp
 )
 
 set(screensaver_xml ${KTORRENT_DBUS_XML_DIR}/org.freedesktop.ScreenSaver.xml)
--- trunk/extragear/network/ktorrent/plugins/mediaplayer/mediafile.cpp \
#1184529:1184530 @@ -21,6 +21,7 @@
 #include "mediafile.h"
 #include <QFile>
 #include <QStringList>
+#include <KMimeType>
 #include <interfaces/torrentinterface.h>
 #include <interfaces/torrentfileinterface.h>
 #include <util/functions.h>
@@ -186,6 +187,20 @@
 		return bt::TorrentFileStream::WPtr(tfs);
 	}
 	
+	bool MediaFile::isVideo() const
+	{
+		if (tc->getStats().multi_file_torrent)
+		{
+			return tc->getTorrentFile(idx).isVideo();
+		}
+		else
+		{
+			KMimeType::Ptr ptr = KMimeType::findByPath(path());
+			return ptr->name().startsWith("video");
+		}
+	}
+
+	
 	///////////////////////////////////////////////////////
 	MediaFileRef::MediaFileRef()
 	{
--- trunk/extragear/network/ktorrent/plugins/mediaplayer/mediafile.h #1184529:1184530
@@ -97,6 +97,9 @@
 		/// Create a TorrentFileStream object for this MediaFile and return a weak pointer \
to it  bt::TorrentFileStream::WPtr stream();
 		
+		/// Is this a video ?
+		bool isVideo() const;
+		
 		typedef QSharedPointer<MediaFile> Ptr;
 		typedef QWeakPointer<MediaFile> WPtr;
 	private:
--- trunk/extragear/network/ktorrent/plugins/mediaplayer/mediafilestream.cpp \
#1184529:1184530 @@ -21,6 +21,7 @@
 #include "mediafilestream.h"
 #include <torrent/torrentfilestream.h>
 #include <util/log.h>
+#include <settings.h>
 
 using namespace bt;
 
@@ -49,8 +50,16 @@
 		if (waiting_for_data)
 		{
 			TorrentFileStream::Ptr s = stream.toStrongRef();
+			// Make sure there is enough data buffered for smooth playback
 			if (s)
 			{
+				qint64 left = s->size() - s->pos();
+				qint64 min_amount_needed = Settings::previewSizeVideo();
+				if (left < min_amount_needed)
+					min_amount_needed = left;
+					
+				if (s->bytesAvailable() >= min_amount_needed)
+				{
 				const QByteArray data = s->read(4096);
 				if (!data.isEmpty()) 
 				{
@@ -59,6 +68,9 @@
 				}
 			}
 			else
+					Out(SYS_MPL|LOG_DEBUG) << "Not enough data available: " << s->bytesAvailable()  \
<< " (need " << min_amount_needed <<  ")" << endl; +			}
+			else
 				endOfData();
 		}
 	}
@@ -72,6 +84,14 @@
 			return;
 		}
 		
+		// Make sure there is enough data buffered for smooth playback
+		qint64 left = s->size() - s->pos();
+		qint64 min_amount_needed = Settings::previewSizeVideo();
+		if (left < min_amount_needed)
+			min_amount_needed = left;
+		
+		if (s->bytesAvailable() >= min_amount_needed)
+		{
 		QByteArray data = s->read(4096);
 		if (data.isEmpty()) 
 		{
@@ -82,6 +102,12 @@
 			writeData(data);
 		}
 	}
+		else
+		{
+			Out(SYS_MPL|LOG_DEBUG) << "Not enough data available: " << s->bytesAvailable()  \
<< " (need " << min_amount_needed <<  ")" << endl; +			waiting_for_data = true;
+		}
+	}
 
 	void MediaFileStream::reset()
 	{
--- trunk/extragear/network/ktorrent/plugins/mediaplayer/mediafilestream.h \
#1184529:1184530 @@ -23,6 +23,7 @@
 
 #include <phonon/abstractmediastream.h>
 #include <torrent/torrentfilestream.h>
+#include <boost/concept_check.hpp>
 
 namespace bt
 {
--- trunk/extragear/network/ktorrent/plugins/mediaplayer/mediaplayer.cpp \
#1184529:1184530 @@ -74,8 +74,18 @@
 		else
 		{
 			Out(SYS_MPL|LOG_NOTICE) << "MediaPlayer: playing " << file.path() << endl;
-			media->setCurrentSource(file.createMediaSource());
+			Phonon::MediaSource ms = file.createMediaSource(); 
+			media->setCurrentSource(ms);
+			MediaFile::Ptr ptr = file.mediaFile();
+			if (ptr)
+			{
 			media->play();
+			}
+			else
+			{
+				media->play();
+			}
+			
 			history.append(file);
 		}
 	}
--- trunk/extragear/network/ktorrent/plugins/mediaplayer/mediaplayeractivity.cpp \
#1184529:1184530 @@ -147,7 +147,7 @@
 		if (idx >= 0)
 			path = path.mid(idx+1);
 		
-		if (path.isNull())
+		if (path.isEmpty())
 			path = i18n("Media Player");
 		
 		if (video)
@@ -354,11 +354,14 @@
 			video->hide();
 			video->setFullScreen(false);
 			
-			QString path = media_player->media0bject()->currentSource().fileName();
+			QString path = media_player->getCurrentSource().path();
 			int idx = path.lastIndexOf(bt::DirSeparator());
 			if (idx >= 0)
 				path = path.mid(idx+1);
 			
+			if (path.isEmpty())
+				path = i18n("Media Player");
+			
 			idx = tabs->addTab(video,KIcon("video-x-generic"),path);
 			tabs->setTabToolTip(idx,i18n("Movie player"));
 			tabs->setCurrentIndex(idx);
--- trunk/extragear/network/ktorrent/plugins/mediaplayer/videowidget.cpp \
#1184529:1184530 @@ -33,23 +33,29 @@
 #include <Phonon/VolumeSlider>
 #include <solid/powermanagement.h>
 #include <util/log.h>
+#include <torrent/chunkbar.h>
 #include "videowidget.h"
 #include "mediaplayer.h"
+#include "videochunkbar.h"
 #include "screensaver_interface.h"
 
+
 using namespace bt;
 
 namespace kt
 {
 
+
 	VideoWidget::VideoWidget(MediaPlayer* player,QWidget* parent)
-		: QWidget(parent),player(player),fullscreen(false),screensaver_cookie(0),powermanagement_cookie(0)
 +		: QWidget(parent),player(player),chunk_bar(0),fullscreen(false),
+		screensaver_cookie(0),powermanagement_cookie(0)
 	{
 		QVBoxLayout* vlayout = new QVBoxLayout(this);
 		vlayout->setMargin(0);
 		vlayout->setSpacing(0);
 		video = new Phonon::VideoWidget(this);
-		vlayout->addWidget(video);
+		chunk_bar = new VideoChunkBar(player->getCurrentSource(),this);
+		chunk_bar->setVisible(player->media0bject()->currentSource().type() == \
Phonon::MediaSource::Stream);  
 		QHBoxLayout* hlayout = new QHBoxLayout(0);
 		
@@ -61,21 +67,24 @@
 		QAction* tfs = tb->addAction(KIcon("view-fullscreen"),i18n("Toggle Fullscreen"));
 		tfs->setCheckable(true);
 		connect(tfs,SIGNAL(toggled(bool)),this,SIGNAL(toggleFullScreen(bool)));
-		hlayout->addWidget(tb);
 		
-		
 		slider = new Phonon::SeekSlider(this);
 		slider->setMediaObject(player->media0bject());
 		slider->setMaximumHeight(tb->iconSize().height());
-		hlayout->addWidget(slider);
 		
-		
 		volume = new Phonon::VolumeSlider(this);
 		volume->setAudioOutput(player->output());
 		volume->setMaximumHeight(tb->iconSize().height());
 		volume->setMaximumWidth(5*tb->iconSize().width());
+		
+		hlayout->addWidget(tb);
+		hlayout->addWidget(slider);
 		hlayout->addWidget(volume);
 		
+		chunk_bar->setFixedHeight(hlayout->sizeHint().height() * 0.75);
+		
+		vlayout->addWidget(chunk_bar);
+		vlayout->addWidget(video);
 		vlayout->addLayout(hlayout);
 	
 		Phonon::createPath(player->media0bject(),video);
@@ -84,6 +93,8 @@
 				this,SLOT(onStateChanged(Phonon::State, Phonon::State)));
 		onStateChanged(player->media0bject()->state(),Phonon::StoppedState);
 		
+		connect(player->media0bject(),SIGNAL(tick(qint64)),this,SLOT(timerTick(qint64)));
+		
 		inhibitScreenSaver(true);
 	}
 
@@ -112,12 +123,14 @@
 	{
 		if (on)
 		{
+			chunk_bar->setVisible(player->media0bject()->currentSource().type() == \
Phonon::MediaSource::Stream);  slider->show();
 			volume->show();
 			tb->show();
 		}
 		else
 		{
+			chunk_bar->hide();
 			slider->hide();
 			volume->hide();
 			tb->hide();
@@ -131,14 +144,16 @@
 			
 		if (slider->isVisible())
 		{
-			int h = height() - slider->height();
-			if (event->y() < h - 10) // use a 10 pixel safety buffer to avoid fibrilation
+			int bh = height() - slider->height();
+			int th = chunk_bar->height();
+			if (event->y() < bh - 10 && event->y() > th + 10) // use a 10 pixel safety buffer \
to avoid fibrilation  setControlsVisible(false);
 		}
 		else
 		{
-			int h = height() - slider->height();
-			if (event->y() >= h)
+			int bh = height() - slider->height();
+			int th = chunk_bar->height();
+			if (event->y() >= bh || event->y() <= th)
 				setControlsVisible(true);
 		}
 	}
@@ -209,4 +224,11 @@
 		}
 	}
 
+	void VideoWidget::timerTick(qint64 time)
+	{
+		if (chunk_bar->isVisible())
+			chunk_bar->timeElapsed(time);
 }
+
+
+}
--- trunk/extragear/network/ktorrent/plugins/mediaplayer/videowidget.h \
#1184529:1184530 @@ -32,6 +32,8 @@
 
 namespace kt
 {
+
+	class VideoChunkBar;
 	class MediaPlayer;
 
 	/**
@@ -59,6 +61,7 @@
 		void stop();
 		void setControlsVisible(bool on);
 		void onStateChanged(Phonon::State cur,Phonon::State old);
+		void timerTick(qint64 time);
 		
 	signals:
 		void toggleFullScreen(bool on);
@@ -75,6 +78,7 @@
 		QAction* pause_act;
 		QAction* stop_act;
 		Phonon::VolumeSlider* volume;
+		VideoChunkBar* chunk_bar;
 		bool fullscreen;
 		uint screensaver_cookie;
 		int powermanagement_cookie;


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

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