Clip.cpp 4.38 KB
Newer Older
1
2
3
/*****************************************************************************
 * Clip.cpp : Represents a basic container for media informations.
 *****************************************************************************
4
 * Copyright (C) 2008-2016 VideoLAN
5
 *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7
 *          Yikei Lu    <luyikei.qmltu@gmail.com>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/** \file
  * This file contains the Clip class implementation.
  */

28
29
30
31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include "Clip.h"
luyikei's avatar
luyikei committed
33
#include "Main/Core.h"
luyikei's avatar
luyikei committed
34
#include "Backend/MLT/MLTInput.h"
35
36
37
#include "Library/Library.h"
#include "Media/Media.h"
#include "Project/Workspace.h"
38
#include "EffectsEngine/EffectHelper.h"
39
#include "Tools/VlmcDebug.h"
luyikei's avatar
luyikei committed
40
#include <QVariant>
41

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
42
Clip::Clip( QSharedPointer<Media> media, qint64 begin /*= 0*/, qint64 end /*= Backend::IInput::EndOfMedia */, const QUuid& uuid /*= QString()*/ ) :
luyikei's avatar
luyikei committed
43
        Workflow::Helper( uuid ),
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
44
        m_media( media ),
45
        m_input( media->input()->cut( begin, end ) ),
luyikei's avatar
luyikei committed
46
        m_isLinked( false )
47
{
luyikei's avatar
luyikei committed
48
49
50
51
52
53
    Formats f;
    if ( media->input()->hasAudio() == true )
        f |= Clip::Audio;
    if ( media->input()->hasVideo() == true )
        f |= Clip::Video;
    setFormats( f );
54
55
56
}

Clip::~Clip()
57
{
58
    emit unloaded( this );
59
60
}

61
QSharedPointer<Media>
luyikei's avatar
luyikei committed
62
Clip::media()
63
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
64
    return m_media;
65
66
}

67
QSharedPointer<const Media>
luyikei's avatar
luyikei committed
68
Clip::media() const
69
70
71
72
{
    return m_media;
}

73
74
qint64
Clip::lengthSecond() const
75
{
luyikei's avatar
luyikei committed
76
    return qRound64( m_input->playableLength() / m_input->fps() );
77
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
78

79
80
const QStringList&
Clip::metaTags() const
81
82
83
84
{
    return m_metaTags;
}

85
86
void
Clip::setMetaTags( const QStringList &tags )
87
88
89
90
{
    m_metaTags = tags;
}

91
92
bool
Clip::matchMetaTag( const QString &tag ) const
93
94
95
96
97
98
99
100
101
102
103
{
    if ( tag.length() == 0 )
        return true;
    QString metaTag;
    foreach ( metaTag, m_metaTags )
    {
        if ( metaTag.startsWith( tag, Qt::CaseInsensitive ) == true )
            return true;
    }
    return false;
}
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
104

105
106
const QString&
Clip::notes() const
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
107
108
109
110
{
    return m_notes;
}

111
112
void
Clip::setNotes( const QString &notes )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
113
114
115
{
    m_notes = notes;
}
116

117
118
const QUuid&
Clip::uuid() const
119
{
120
121
    Q_ASSERT( m_uuid.isNull() == false );
    return m_uuid;
122
123
}

124
125
126
void
Clip::setUuid( const QUuid &uuid )
{
127
    m_uuid = uuid;
128
129
}

130
131
132
qint64
Clip::begin() const
{
luyikei's avatar
luyikei committed
133
    return m_input->begin();
134
135
136
137
138
}

qint64
Clip::end() const
{
luyikei's avatar
luyikei committed
139
    return m_input->end();
140
141
142
143
144
}

void
Clip::setBegin( qint64 begin )
{
luyikei's avatar
luyikei committed
145
    m_input->setBegin( begin );
146
147
148
149
150
}

void
Clip::setEnd( qint64 end )
{
luyikei's avatar
luyikei committed
151
    m_input->setEnd( end );
152
153
154
155
156
}

qint64
Clip::length() const
{
luyikei's avatar
luyikei committed
157
    return m_input->playableLength();
158
159
160
161
162
}

void
Clip::setBoundaries( qint64 begin, qint64 end )
{
luyikei's avatar
luyikei committed
163
    m_input->setBoundaries( begin, end );
164
165
}

luyikei's avatar
luyikei committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
void
Clip::setLinkedClipUuid( const QUuid& uuid )
{
    m_linkedClipUuid = uuid;
}

const QUuid&
Clip::linkedClipUuid() const
{
    return m_linkedClipUuid;
}

void
Clip::setLinked( bool isLinked )
{
    m_isLinked = isLinked;
}

bool
Clip::isLinked() const
{
    return m_isLinked;
}

luyikei's avatar
luyikei committed
190
191
192
193
194
195
QVariant
Clip::toVariant() const
{
    QVariantHash h = {
        { "uuid", m_uuid.toString() },
        { "metatags", m_metaTags },
luyikei's avatar
luyikei committed
196
197
        { "notes", m_notes },
        { "formats", (int)formats() }
luyikei's avatar
luyikei committed
198
    };
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
199
200
    h.insert( "begin", begin() );
    h.insert( "end", end() );
luyikei's avatar
luyikei committed
201
202
203
204
205
206
207
    if ( isLinked() == true )
    {
        h.insert( "linkedClip", m_linkedClipUuid );
        h.insert( "linked", true );
    }
    else
        h.insert( "linked", false );
luyikei's avatar
luyikei committed
208
209
210
211
    return QVariant( h );

}

luyikei's avatar
luyikei committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
Clip::Formats
Clip::formats() const
{
    return m_formats;
}

void
Clip::setFormats( Formats formats )
{
    if ( formats.testFlag( Clip::None ) )
        m_formats = Clip::None;
    m_formats = formats;
}

luyikei's avatar
luyikei committed
226
227
Backend::IInput*
Clip::input()
luyikei's avatar
luyikei committed
228
{
luyikei's avatar
luyikei committed
229
    return m_input.get();
luyikei's avatar
luyikei committed
230
}