Media.h 6.6 KB
Newer Older
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
1
/*****************************************************************************
2
 * Media.h : Represents a basic container for media informations.
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * 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.
 *****************************************************************************/

23
/** \file
24
  * This file contains the Media class declaration/definition.
25 26 27 28
  * It contains a VLCMedia and the meta-datas.
  * It's used by the Library
  */

29 30
#ifndef MEDIA_H__
#define MEDIA_H__
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
31

32 33 34
#include <QList>
#include <QString>
#include <QPixmap>
35
#include <QUuid>
36
#include <QObject>
37
#include <QFileInfo>
38
#include <QHash>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
39

40
#include "VLCMedia.h"
41
#include "Clip.h"
42

43 44 45
struct          audioData
{
    void*               datas;
46 47 48 49
    unsigned int*       freq;
    unsigned int*       nbChannels;
    unsigned int*       fourCCFormat;
    unsigned int*       frameSize;
50 51 52 53 54 55
    unsigned int        nbSample;
    unsigned char*      buffer;
    size_t              buffSize;
    QVector<int*>       frameList;
};

56 57
class Clip;

58 59 60
/**
  * Represents a basic container for media informations.
  */
61
class       Media : public QObject
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
62
{
63 64
    Q_OBJECT

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
65
public:
66 67 68 69
    /**
     *  \enum fType
     *  \brief enum to determine file type
     */
70
    enum    FileType
71 72 73 74 75
    {
        Audio,
        Video,
        Image
    };
76 77 78 79 80
    enum    InputType
    {
        File,
        Stream
    };
81
    Media( const QString& filePath, const QString& = QString() );
82
    virtual ~Media();
83

84 85 86 87 88 89 90 91 92
    /**
     *  \brief  This method adds a parameter that will stay constant though the whole life of this media (unless it is explicitely overided), even if it is cloned.
     */
    void                        addConstantParam( const QString& param );
    /**
     *  \brief  This method will add a parameter that will be restored to defaultValue when the flushVolatileParameter is called
     */
    void                        addVolatileParam( const QString& param, const QString& defaultValue );
    void                        flushVolatileParameters();
93
    LibVLCpp::Media*            getVLCMedia() { return m_vlcMedia; }
94

95 96
    void                        setSnapshot( QPixmap* snapshot );
    const QPixmap&              getSnapshot() const;
97

98
    const QFileInfo*            getFileInfo() const;
99 100
    const QString&              getMrl() const;
    const QString&              getFileName() const;
101

102 103 104 105
    /**
        \return                 Returns the length of this media (ie the
                                video duration) in milliseconds.
    */
106
    qint64                      getLength() const;
107 108 109 110 111 112
    /**
        \brief                  This methods is most of an entry point for the
                                MetadataManager than enything else.
                                If you use it to set a inconsistant media length
                                you'll just have to blame yourself !
    */
113
    void                        setLength( qint64 length );
114
    void                        setNbFrames( qint64 nbFrames );
115

116 117
    int                         getWidth() const;
    void                        setWidth( int width );
118

119 120
    int                         getHeight() const;
    void                        setHeight( int height );
121

122
    float                       getFps() const;
123
    void                        setFps( float fps );
124

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
125
    qint64                      getNbFrames() const;
126

127
    const QUuid&                getUuid() const;
128
    void                        setUuid( const QUuid& uuid );
129

130
    FileType                    getFileType() const;
131 132 133
    static const QString        VideoExtensions;
    static const QString        AudioExtensions;
    static const QString        ImageExtensions;
134 135
    InputType                   getInputType() const;
    static const QString        streamPrefix;
136

137 138 139 140 141 142 143
    void                        initAudioData( void* datas, unsigned int* freq, unsigned int* nbChannels, unsigned int* fourCCFormat, unsigned int* frameSize );
    void                        addAudioFrame( void* datas, unsigned char* buffer, size_t buffSize, unsigned int nbSample );

    audioData*                  getAudioData() { return &m_audioData; }
    QVector<int*>               getAudioFrameList() { return m_audioData.frameList; }
    unsigned int                getAudioNbSample() { return m_audioData.nbSample; }

144 145 146 147
    const QStringList&          getMetaTags() const;
    void                        setMetaTags( const QStringList& tags );
    bool                        matchMetaTag( const QString& tag ) const;

148
    void                        emitMetaDataComputed();
149

150 151
    bool                        hasMetadata() const;

152 153 154 155 156 157
    void                        addClip( Clip* clip );
    void                        removeClip( const QUuid& uuid );
    Clip*                       clip( const QUuid& uuid ) const { return m_clips[uuid]; }
    const QHash<QUuid, Clip*>*  clips() const { return &m_clips; }


158 159 160
private:
    void                        setFileType();

161
protected:
162
    static QPixmap*             defaultSnapshot;
163 164
    LibVLCpp::Media*            m_vlcMedia;
    QString                     m_mrl;
165
    QList<QString>              m_volatileParameters;
166
    QPixmap*                    m_snapshot;
167
    QUuid                       m_uuid;
168 169
    QFileInfo*                  m_fileInfo;
    qint64                      m_length;
170
    qint64                      m_nbFrames;
171 172
    unsigned int                m_width;
    unsigned int                m_height;
173
    float                       m_fps;
174 175
    int*                        m_audioSpectrum;
    audioData                   m_audioData;
176
    FileType                    m_fileType;
177
    InputType                   m_inputType;
178
    bool                        m_metadataParsed;
179
    QString                     m_fileName;
180
    QStringList                 m_metaTags;
181
    QHash<QUuid, Clip*>         m_clips;
182 183

signals:
184
    void                        metaDataComputed( Media* );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
185 186
};

187
#endif // CLIP_H__