VideoTrack.cpp 4.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * Media Library
 *****************************************************************************
 * Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
 *
 * Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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 24 25 26
#if HAVE_CONFIG_H
# include "config.h"
#endif

27
#include "VideoTrack.h"
28
#include "Media.h"
29

30 31 32
namespace medialibrary
{

33
const std::string policy::VideoTrackTable::Name = "VideoTrack";
34
const std::string policy::VideoTrackTable::PrimaryKeyColumn = "id_track";
35
int64_t VideoTrack::* const policy::VideoTrackTable::PrimaryKey = &VideoTrack::m_id;
36

37
VideoTrack::VideoTrack( MediaLibraryPtr, sqlite::Row& row )
38
{
39 40 41 42
    row >> m_id
        >> m_codec
        >> m_width
        >> m_height
43
        >> m_fps
44 45 46
        >> m_mediaId
        >> m_language
        >> m_description;
47 48
}

49 50
VideoTrack::VideoTrack( MediaLibraryPtr, const std::string& codec, unsigned int width, unsigned int height,
                        float fps, int64_t mediaId, const std::string& language, const std::string& description )
51
    : m_id( 0 )
52 53 54 55
    , m_codec( codec )
    , m_width( width )
    , m_height( height )
    , m_fps( fps )
56
    , m_mediaId( mediaId )
57 58
    , m_language( language )
    , m_description( description )
59 60 61
{
}

62
int64_t VideoTrack::id() const
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
{
    return m_id;
}

const std::string& VideoTrack::codec() const
{
    return m_codec;
}

unsigned int VideoTrack::width() const
{
    return m_width;
}

unsigned int VideoTrack::height() const
{
    return m_height;
}

float VideoTrack::fps() const
{
    return m_fps;
}

87 88 89 90 91 92 93 94 95 96
const std::string& VideoTrack::language() const
{
    return m_language;
}

const std::string& VideoTrack::description() const
{
    return m_description;
}

97
std::shared_ptr<VideoTrack> VideoTrack::create( MediaLibraryPtr ml, const std::string& codec, unsigned int width,
98 99
                                                unsigned int height, float fps, int64_t mediaId,
                                                const std::string& language, const std::string& description )
100 101
{
    static const std::string req  = "INSERT INTO " + policy::VideoTrackTable::Name
102 103 104
            + "(codec, width, height, fps, media_id, language, description) VALUES(?, ?, ?, ?, ?, ?, ?)";
    auto track = std::make_shared<VideoTrack>( ml, codec, width, height, fps, mediaId, language, description );
    if ( insert( ml, track, req, codec, width, height, fps, mediaId, language, description ) == false )
105 106 107 108
        return nullptr;
    return track;
}

109
void VideoTrack::createTable( sqlite::Connection* dbConnection )
110
{
111
    const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::VideoTrackTable::Name
112
            + "(" +
113
                policy::VideoTrackTable::PrimaryKeyColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
114 115 116 117
                "codec TEXT,"
                "width UNSIGNED INTEGER,"
                "height UNSIGNED INTEGER,"
                "fps FLOAT,"
118
                "media_id UNSIGNED INT,"
119 120
                "language TEXT,"
                "description TEXT,"
121 122
                "FOREIGN KEY ( media_id ) REFERENCES " + policy::MediaTable::Name +
                    "(id_media) ON DELETE CASCADE"
123
            ")";
124
    const std::string indexReq = "CREATE INDEX IF NOT EXISTS video_track_media_idx ON " +
125
            policy::VideoTrackTable::Name + "(media_id)";
126 127
    sqlite::Tools::executeRequest( dbConnection, req );
    sqlite::Tools::executeRequest( dbConnection, indexReq );
128
}
129 130

}