VLCThumbnailer.h 1.97 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
#pragma once

25
#include "compat/ConditionVariable.h"
26 27 28
#include "compat/Thread.h"
#include "medialibrary/Types.h"
#include "Types.h"
29

30 31
#include <queue>
#include <atomic>
32

33 34 35
namespace medialibrary
{

36
class VLCThumbnailer
37
{
38 39
public:
    class Generator
40
    {
41 42 43
    public:
        virtual ~Generator() = default;
        virtual bool generate( MediaPtr media, const std::string& mrl ) = 0;
44 45 46 47 48
    };

    explicit VLCThumbnailer( MediaLibraryPtr ml );
    virtual ~VLCThumbnailer();
    void requestThumbnail( MediaPtr media );
49 50
    void pause();
    void resume();
51 52

private:
53 54
    void run();
    void stop();
55

56
    bool generateThumbnail( MediaPtr task );
57

58
private:
59

60 61

private:
62
    MediaLibraryPtr m_ml;
63
    compat::Mutex m_mutex;
64
    compat::ConditionVariable m_cond;
65
    std::queue<MediaPtr> m_tasks;
66
    std::atomic_bool m_run;
67
    std::unique_ptr<Generator> m_generator;
68
    compat::Thread m_thread;
69
    bool m_paused;
70
};
71 72

}