Commit b11c2aa9 authored by luyikei's avatar luyikei
Browse files

IProducer::cut(), Media, Clip: Introduce unique_ptr to handle IProducer

parent 4ecbe7b6
......@@ -24,6 +24,8 @@
#define IPRODUCER_H
#include <cstdint>
#include <memory>
#include "Backend/IService.h"
namespace Backend
......@@ -59,7 +61,7 @@ namespace Backend
virtual void setBoundaries( int64_t begin, int64_t end ) = 0;
// Absolute position in frames
virtual IProducer* cut( int64_t begin = 0, int64_t end = EndOfMedia ) = 0;
virtual std::unique_ptr<IProducer> cut( int64_t begin = 0, int64_t end = EndOfMedia ) = 0;
virtual bool isCut( ) const = 0 ;
virtual bool sameClip( IProducer& that ) const = 0;
......
......@@ -161,10 +161,10 @@ MLTProducer::setBoundaries( int64_t begin, int64_t end )
m_producer->set_in_and_out( begin, end );
}
Backend::IProducer*
std::unique_ptr<Backend::IProducer>
MLTProducer::cut( int64_t begin, int64_t end )
{
return new MLTProducer( m_producer->cut( begin, end ) );
return std::unique_ptr<IProducer>( new MLTProducer( m_producer->cut( begin, end ) ) );
}
bool
......
......@@ -57,7 +57,7 @@ class MLTProducer : virtual public IProducer, public MLTService
virtual void setEnd( int64_t end ) override;
virtual void setBoundaries( int64_t begin, int64_t end ) override;
virtual IProducer* cut( int64_t begin = 0, int64_t end = EndOfMedia ) override;
virtual std::unique_ptr<IProducer> cut( int64_t begin = 0, int64_t end = EndOfMedia ) override;
virtual bool isCut() const override;
virtual bool sameClip( IProducer& that ) const override;
......
......@@ -37,7 +37,7 @@
Clip::Clip( Media *media, qint64 begin /*= 0*/, qint64 end /*= Backend::IProducer::EndOfMedia */, const QString& uuid /*= QString()*/ ) :
Workflow::Helper( uuid ),
m_media( media ),
m_producer( m_media->producer()->cut( begin, end ) ),
m_producer( std::move( m_media->producer()->cut( begin, end ) ) ),
m_parent( media->baseClip() ),
m_clipWorkflow( nullptr )
{
......@@ -69,7 +69,6 @@ Clip::~Clip()
{
emit unloaded( this );
delete m_childs;
delete m_producer;
if ( isRootClip() == true )
delete m_media;
}
......@@ -261,7 +260,7 @@ Clip::toVariant() const
h.insert( "begin", begin() );
h.insert( "end", end() );
}
h.insert( "filters", EffectHelper::toVariant( m_producer ) );
h.insert( "filters", EffectHelper::toVariant( m_producer.get() ) );
return QVariant( h );
}
......@@ -297,7 +296,7 @@ Clip::setFormats( Formats formats )
Backend::IProducer*
Clip::producer()
{
return m_producer;
return m_producer.get();
}
void
......
......@@ -35,6 +35,8 @@
#include <QXmlStreamWriter>
#include "Backend/IProducer.h"
#include <memory>
class MediaContainer;
class Media;
class ClipWorkflow;
......@@ -139,7 +141,7 @@ class Clip : public Workflow::Helper
private:
Media* m_media;
Backend::IProducer* m_producer;
std::unique_ptr<Backend::IProducer> m_producer;
QStringList m_metaTags;
QString m_notes;
......
......@@ -71,7 +71,6 @@ Media::Media(const QString &path )
Media::~Media()
{
delete m_producer;
delete m_fileInfo;
}
......@@ -120,13 +119,13 @@ Media::toVariant() const
Backend::IProducer*
Media::producer()
{
return m_producer;
return m_producer.get();
}
const Backend::IProducer*
Media::producer() const
{
return m_producer;
return m_producer.get();
}
void
......@@ -138,8 +137,7 @@ Media::setFilePath( const QString &filePath )
m_fileName = m_fileInfo->fileName();
m_mrl = "file:///" + QUrl::toPercentEncoding( filePath, "/" );
delete m_producer;
m_producer = new Backend::MLT::MLTProducer( qPrintable( filePath ) );
m_producer.reset( new Backend::MLT::MLTProducer( qPrintable( filePath ) ) );
}
#ifdef WITH_GUI
......
......@@ -31,6 +31,9 @@
#define MEDIA_H__
#include "config.h"
#include <memory>
#include <QString>
#include <QObject>
#include <QFileInfo>
......@@ -110,7 +113,7 @@ public:
QPixmap& snapshot();
#endif
protected:
Backend::IProducer* m_producer;
std::unique_ptr<Backend::IProducer> m_producer;
QString m_mrl;
QFileInfo* m_fileInfo;
FileType m_fileType;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment