summaryrefslogtreecommitdiff
path: root/src/protocols/types/ContentType.cpp
blob: b5b0041c5b6128efc78c4c885df6a6695075610a (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
#include "ContentType.hpp"
#include <drm_mode.h>
#include <stdexcept>
#include <format>

namespace NContentType {
    static std::unordered_map<std::string, eContentType> const table = {
        {"none", CONTENT_TYPE_NONE}, {"photo", CONTENT_TYPE_PHOTO}, {"video", CONTENT_TYPE_VIDEO}, {"game", CONTENT_TYPE_GAME}};

    eContentType fromString(const std::string name) {
        auto it = table.find(name);
        if (it != table.end())
            return it->second;
        else
            return CONTENT_TYPE_NONE;
    }

    std::string toString(eContentType type) {
        for (const auto& [k, v] : table) {
            if (v == type)
                return k;
        }
        return "";
    }

    eContentType fromWP(wpContentTypeV1Type contentType) {
        switch (contentType) {
            case WP_CONTENT_TYPE_V1_TYPE_NONE: return CONTENT_TYPE_NONE;
            case WP_CONTENT_TYPE_V1_TYPE_PHOTO: return CONTENT_TYPE_PHOTO;
            case WP_CONTENT_TYPE_V1_TYPE_VIDEO: return CONTENT_TYPE_VIDEO;
            case WP_CONTENT_TYPE_V1_TYPE_GAME: return CONTENT_TYPE_GAME;
            default: return CONTENT_TYPE_NONE;
        }
    }

    uint16_t toDRM(eContentType contentType) {
        switch (contentType) {
            case CONTENT_TYPE_NONE: return DRM_MODE_CONTENT_TYPE_GRAPHICS;
            case CONTENT_TYPE_PHOTO: return DRM_MODE_CONTENT_TYPE_PHOTO;
            case CONTENT_TYPE_VIDEO: return DRM_MODE_CONTENT_TYPE_CINEMA;
            case CONTENT_TYPE_GAME: return DRM_MODE_CONTENT_TYPE_GAME;
            default: return DRM_MODE_CONTENT_TYPE_NO_DATA;
        }
    }
}