From c9adcf6bd7793ed819214711a51498f59d356793 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Tue, 21 Oct 2014 23:23:04 +0200 Subject: [PATCH] Don't copy MediaStream instances With the large char-buffer, a copy of them will be very inefficent. Explicitly add functions for the conversion to a MediaStream but do not allow a copy constructor. --- src/libtomahawk/audio/AudioOutput.cpp | 11 +++++++++-- src/libtomahawk/audio/AudioOutput.h | 5 +++-- src/libtomahawk/utils/MediaStream.cpp | 18 ------------------ src/libtomahawk/utils/MediaStream.h | 7 ++++--- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/libtomahawk/audio/AudioOutput.cpp b/src/libtomahawk/audio/AudioOutput.cpp index c84da9363..61b0a07da 100644 --- a/src/libtomahawk/audio/AudioOutput.cpp +++ b/src/libtomahawk/audio/AudioOutput.cpp @@ -154,9 +154,16 @@ AudioOutput::setAutoDelete ( bool ad ) void -AudioOutput::setCurrentSource( MediaStream stream ) +AudioOutput::setCurrentSource( const QUrl& stream ) { - setCurrentSource( new MediaStream(stream) ); + setCurrentSource( new MediaStream( stream ) ); +} + + +void +AudioOutput::setCurrentSource( QIODevice* stream ) +{ + setCurrentSource( new MediaStream( stream ) ); } diff --git a/src/libtomahawk/audio/AudioOutput.h b/src/libtomahawk/audio/AudioOutput.h index 768da5a0d..2c3d7ce24 100644 --- a/src/libtomahawk/audio/AudioOutput.h +++ b/src/libtomahawk/audio/AudioOutput.h @@ -46,8 +46,9 @@ public: AudioState state(); - void setCurrentSource(MediaStream stream); - void setCurrentSource(MediaStream* stream); + void setCurrentSource( const QUrl& stream); + void setCurrentSource( QIODevice* stream); + void setCurrentSource( MediaStream* stream ); void play(); void pause(); diff --git a/src/libtomahawk/utils/MediaStream.cpp b/src/libtomahawk/utils/MediaStream.cpp index dde1147f9..9d71d61c4 100644 --- a/src/libtomahawk/utils/MediaStream.cpp +++ b/src/libtomahawk/utils/MediaStream.cpp @@ -77,24 +77,6 @@ MediaStream::MediaStream( QIODevice* device ) } -MediaStream::MediaStream( const MediaStream& copy ) - : QObject( copy.parent() ) -{ - m_type = copy.m_type; - m_url = copy.m_url; - m_ioDevice = copy.m_ioDevice; - m_started = copy.m_started; - m_bufferingFinished = copy.m_bufferingFinished; - m_eos = copy.m_eos; - m_pos = copy.m_pos; - m_streamSize = copy.m_streamSize; - - if ( m_type == IODevice ) { - QObject::connect( m_ioDevice, SIGNAL( readChannelFinished() ), this, SLOT( bufferingFinished() ) ); - } -} - - MediaStream::~MediaStream() { tDebug() << Q_FUNC_INFO; diff --git a/src/libtomahawk/utils/MediaStream.h b/src/libtomahawk/utils/MediaStream.h index e1f7b0f9f..c35a74eaf 100644 --- a/src/libtomahawk/utils/MediaStream.h +++ b/src/libtomahawk/utils/MediaStream.h @@ -39,9 +39,8 @@ public: enum MediaType { Unknown = -1, Empty = 0, Url = 1, Stream = 2, IODevice = 3 }; MediaStream( QObject* parent = 0 ); - MediaStream( const MediaStream& copy ); - MediaStream( const QUrl &url ); - MediaStream( QIODevice* device ); + explicit MediaStream( const QUrl &url ); + explicit MediaStream( QIODevice* device ); virtual ~MediaStream(); MediaType type(); @@ -74,6 +73,8 @@ protected: qint64 m_streamSize; char m_buffer[1048576]; +private: + Q_DISABLE_COPY( MediaStream ); }; #endif // MEDIASTREAM_H