summaryrefslogtreecommitdiff
path: root/pictureCache.h
blob: 2cf1bd6c55e308d77eb10b15d826ef0386472cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef CPICTURECACHE_H
#define CPICTURECACHE_H

#include <memory>
#include <iostream>
#include <fstream>
#include <deque>
#include <string>
#include <future>

#include <vdr/thread.h>
#include <vdr/plugin.h>

#include "viewGridNavigator.h"

enum ImageResolution {
    SD384,
    SD480,
    HD720,
    HD1080
};

class cPictureCache {
private:
    struct CacheInfo {
        CacheInfo(std::string Uri, int Width, int Height, std::function<void(cGridElement *)> OnCached,
                  cGridElement *Calle) {
            uri = Uri;
            width = Width;
            height = Height;
            onCached = OnCached;
            calle = Calle;
        };
        std::string uri;
        int width;
        int height;
        std::function<void(cGridElement *)> onCached;
        cGridElement *calle;
        bool downloaded;
    };

    cPictureCache();

    std::map<std::string, bool> m_mCached;
    std::vector<std::future<void>> m_vFutures;
    volatile bool m_bAllInvalidated;

    std::string FileName(std::string uri, int width);

    std::string TranscodeUri(std::string uri, int width, int height);

    static bool DownloadFileAndSave(std::string uri, std::string localFile);

    bool Cached(std::string uri, int width);

    std::string m_cacheDir;

public:
    static cPictureCache &GetInstance() {
        static cPictureCache instance;
        return instance;
    }

    std::string GetPath(std::string uri, int width, int height, bool &cached,
                        std::function<void(cGridElement *)> OnCached = NULL, cGridElement *calle = NULL);
};

#endif // CPICTURECACHE_H