Skip to content

Commit

Permalink
Extract Resource enums
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlStraussberger committed Jan 12, 2024
1 parent 82c91e7 commit 563e2e1
Show file tree
Hide file tree
Showing 38 changed files with 539 additions and 489 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ add_library(libgerbera STATIC
src/action_request.h
src/cds/cds_container.cc
src/cds/cds_container.h
src/cds/cds_enums.h
src/cds/cds_enums.cc
src/cds/cds_item.cc
src/cds/cds_item.h
src/cds/cds_objects.cc
Expand Down
99 changes: 99 additions & 0 deletions src/cds/cds_enums.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*GRB*
Gerbera - https://gerbera.io/
cds_types.cc - this file is part of Gerbera.
Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
Leonhard Wimmer <leo@mediatomb.cc>
Copyright (C) 2016-2024 Gerbera Contributors
Gerbera is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
Gerbera 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 Gerbera. If not, see <http://www.gnu.org/licenses/>.
*/

/// \file cds_types.cc

#include "cds_enums.h" // API

#include <algorithm>
#include <array>
#include <fmt/format.h>

#include "exceptions.h"
#include "util/logger.h"

static constexpr std::array chKeys = {
std::pair(ContentHandler::DEFAULT, "Default"),
#ifdef HAVE_LIBEXIF
std::pair(ContentHandler::LIBEXIF, "LibExif"),
#endif
#ifdef HAVE_TAGLIB
std::pair(ContentHandler::ID3, "TagLib"),
#endif
std::pair(ContentHandler::TRANSCODE, "Transcode"),
std::pair(ContentHandler::EXTURL, "Exturl"),
std::pair(ContentHandler::MP4, "MP4"),
#ifdef HAVE_FFMPEGTHUMBNAILER
std::pair(ContentHandler::FFTH, "FFmpegThumbnailer"),
#endif
std::pair(ContentHandler::FLAC, "Flac"),
std::pair(ContentHandler::FANART, "Fanart"),
std::pair(ContentHandler::CONTAINERART, "ContainerArt"),
#ifdef HAVE_MATROSKA
std::pair(ContentHandler::MATROSKA, "Matroska"),
#endif
#ifdef HAVE_WAVPACK
std::pair(ContentHandler::WAVPACK, "WavPack"),
#endif
std::pair(ContentHandler::SUBTITLE, "Subtitle"),
std::pair(ContentHandler::METAFILE, "MetaFile"),
std::pair(ContentHandler::RESOURCE, "Resource"),
};

bool EnumMapper::checkContentHandler(const std::string& contHandler)
{
auto chEntry = std::find_if(chKeys.begin(), chKeys.end(), [contHandler](auto&& entry) { return contHandler == entry.second; });
return chEntry != chKeys.end();
}

ContentHandler EnumMapper::remapContentHandler(const std::string& contHandler)
{
auto chEntry = std::find_if(chKeys.begin(), chKeys.end(), [contHandler](auto&& entry) { return contHandler == entry.second; });
if (chEntry != chKeys.end()) {
return chEntry->first;
}
throw_std_runtime_error("Invalid content handler value {}", contHandler);
}

ContentHandler EnumMapper::remapContentHandler(int ch)
{
return static_cast<ContentHandler>(ch);
}

std::string EnumMapper::mapContentHandler2String(ContentHandler ch)
{
auto chEntry = std::find_if(chKeys.begin(), chKeys.end(), [ch](auto&& entry) { return ch == entry.first; });
if (chEntry != chKeys.end()) {
return chEntry->second;
}
throw_std_runtime_error("Invalid content handler value {}", ch);
}

std::string EnumMapper::getPurposeDisplay(ResourcePurpose purpose)
{
return purposeToDisplay.at(purpose);
}
133 changes: 133 additions & 0 deletions src/cds/cds_enums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*GRB*
Gerbera - https://gerbera.io/
cds_types.h - this file is part of Gerbera.
Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>,
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
Leonhard Wimmer <leo@mediatomb.cc>
Copyright (C) 2016-2024 Gerbera Contributors
Gerbera is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
Gerbera 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 Gerbera. If not, see <http://www.gnu.org/licenses/>.
*/

/// \file cds_types.h

#ifndef __CDS_TYPES_H__
#define __CDS_TYPES_H__

#include <map>
#include <string>

// ATTENTION: These values need to be changed in web/js/items.js too.
#define OBJECT_TYPE_CONTAINER 0x00000001u
#define OBJECT_TYPE_ITEM 0x00000002u
#define OBJECT_TYPE_ITEM_EXTERNAL_URL 0x00000008u

#define STRING_OBJECT_TYPE_CONTAINER "container"
#define STRING_OBJECT_TYPE_ITEM "item"
#define STRING_OBJECT_TYPE_EXTERNAL_URL "external_url"

static constexpr bool IS_CDS_CONTAINER(unsigned int type)
{
return type & OBJECT_TYPE_CONTAINER;
}
static constexpr bool IS_CDS_ITEM_EXTERNAL_URL(unsigned int type)
{
return type & OBJECT_TYPE_ITEM_EXTERNAL_URL;
}

#define OBJECT_FLAG_RESTRICTED 0x00000001u
#define OBJECT_FLAG_SEARCHABLE 0x00000002u
#define OBJECT_FLAG_USE_RESOURCE_REF 0x00000004u
#define OBJECT_FLAG_PERSISTENT_CONTAINER 0x00000008u
#define OBJECT_FLAG_PLAYLIST_REF 0x00000010u
#define OBJECT_FLAG_PROXY_URL 0x00000020u
#define OBJECT_FLAG_ONLINE_SERVICE 0x00000040u
#define OBJECT_FLAG_OGG_THEORA 0x00000080u

#define OBJECT_AUTOSCAN_NONE 0u
#define OBJECT_AUTOSCAN_UI 1u
#define OBJECT_AUTOSCAN_CFG 2u

enum class ResourcePurpose : int {
Content = 0,
Thumbnail,
Subtitle,
Transcode
};

enum class ResourceAttribute : int {
SIZE = 0,
DURATION,
BITRATE,
SAMPLEFREQUENCY,
NRAUDIOCHANNELS,
RESOLUTION,
COLORDEPTH,
PROTOCOLINFO,
RESOURCE_FILE,
TYPE,
FANART_OBJ_ID,
FANART_RES_ID,
BITS_PER_SAMPLE,
LANGUAGE,
AUDIOCODEC,
VIDEOCODEC,
FORMAT,
MAX
};

// content handler Id's
enum class ContentHandler : int {
DEFAULT = 0,
LIBEXIF = 1,
ID3 = 2,
TRANSCODE = 3,
EXTURL = 4,
MP4 = 5,
FFTH = 6,
FLAC = 7,
FANART = 8,
MATROSKA = 9,
SUBTITLE = 10,
CONTAINERART = 11,
WAVPACK = 12,
METAFILE = 13,
RESOURCE = 20,
};

class EnumMapper {
private:
inline static const std::map<ResourcePurpose, std::string> purposeToDisplay {
{ ResourcePurpose::Content, "Content" },
{ ResourcePurpose::Thumbnail, "Thumbnail" },
{ ResourcePurpose::Subtitle, "Subtitle" },
{ ResourcePurpose::Transcode, "Transcode" },
};

public:
static std::string mapContentHandler2String(ContentHandler ch);
static bool checkContentHandler(const std::string& contHandler);
static ContentHandler remapContentHandler(const std::string& contHandler);
static ContentHandler remapContentHandler(int ch);

static ResourcePurpose remapPurpose(int ip) { return static_cast<ResourcePurpose>(ip); }
static std::string getPurposeDisplay(ResourcePurpose purpose);
};

#endif
1 change: 0 additions & 1 deletion src/cds/cds_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include "cds_container.h"
#include "cds_item.h"
#include "cds_resource.h"
#include "database/database.h"
#include "util/tools.h"
#include "util/upnp_clients.h"
Expand Down
30 changes: 1 addition & 29 deletions src/cds/cds_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,6 @@
#include "common.h"
#include "metadata/metadata_handler.h"

// ATTENTION: These values need to be changed in web/js/items.js too.
#define OBJECT_TYPE_CONTAINER 0x00000001u
#define OBJECT_TYPE_ITEM 0x00000002u
#define OBJECT_TYPE_ITEM_EXTERNAL_URL 0x00000008u

#define STRING_OBJECT_TYPE_CONTAINER "container"
#define STRING_OBJECT_TYPE_ITEM "item"
#define STRING_OBJECT_TYPE_EXTERNAL_URL "external_url"

static constexpr bool IS_CDS_CONTAINER(unsigned int type)
{
return type & OBJECT_TYPE_CONTAINER;
}
static constexpr bool IS_CDS_ITEM_EXTERNAL_URL(unsigned int type) { return type & OBJECT_TYPE_ITEM_EXTERNAL_URL; }

#define OBJECT_FLAG_RESTRICTED 0x00000001u
#define OBJECT_FLAG_SEARCHABLE 0x00000002u
#define OBJECT_FLAG_USE_RESOURCE_REF 0x00000004u
#define OBJECT_FLAG_PERSISTENT_CONTAINER 0x00000008u
#define OBJECT_FLAG_PLAYLIST_REF 0x00000010u
#define OBJECT_FLAG_PROXY_URL 0x00000020u
#define OBJECT_FLAG_ONLINE_SERVICE 0x00000040u
#define OBJECT_FLAG_OGG_THEORA 0x00000080u

#define OBJECT_AUTOSCAN_NONE 0u
#define OBJECT_AUTOSCAN_UI 1u
#define OBJECT_AUTOSCAN_CFG 2u

/// \brief Generic object in the Content Directory.
class CdsObject {
protected:
Expand Down Expand Up @@ -357,7 +329,7 @@ class CdsObject {
}

/// \brief Query resource tag with the given purpose
std::shared_ptr<CdsResource> getResource(CdsResource::Purpose purpose) const
std::shared_ptr<CdsResource> getResource(ResourcePurpose purpose) const
{
auto it = std::find_if(resources.begin(), resources.end(), [=](auto&& res) { return purpose == res->getPurpose(); });
if (it != resources.end()) {
Expand Down

0 comments on commit 563e2e1

Please sign in to comment.