Use enum values for data_kind and media_kind

This commit is contained in:
chme 2015-04-23 11:34:44 +02:00
parent 9f6afe0607
commit 659f9c09bb
9 changed files with 38 additions and 23 deletions

View File

@ -1106,7 +1106,7 @@ artwork_get_item_mfi(struct evbuffer *evbuf, struct media_file_info *mfi, int ma
return format; return format;
} }
if (mfi->data_kind == 0) if (mfi->data_kind == DATA_KIND_FILE)
{ {
format = artwork_get_item_path(evbuf, mfi->path, mfi->artwork, max_w, max_h, path); format = artwork_get_item_path(evbuf, mfi->path, mfi->artwork, max_w, max_h, path);

View File

@ -85,6 +85,21 @@ struct pairing_info {
char *guid; char *guid;
}; };
enum media_kind {
MEDIA_KIND_MUSIC = 0,
MEDIA_KIND_MOVIE = 2,
MEDIA_KIND_PODCAST = 4,
MEDIA_KIND_AUDIOBOOK = 8,
MEDIA_KIND_TVSHOW = 64,
};
enum data_kind {
DATA_KIND_FILE = 0,
DATA_KIND_URL = 1,
DATA_KIND_SPOTIFY = 2,
DATA_KIND_PIPE = 3,
};
struct media_file_info { struct media_file_info {
char *path; char *path;
uint32_t index; uint32_t index;

View File

@ -537,7 +537,7 @@ fixup_tags(struct media_file_info *mfi)
/* Handle TV shows, try to present prettier metadata */ /* Handle TV shows, try to present prettier metadata */
if (mfi->tv_series_name && strlen(mfi->tv_series_name) != 0) if (mfi->tv_series_name && strlen(mfi->tv_series_name) != 0)
{ {
mfi->media_kind = 64; /* tv show */ mfi->media_kind = MEDIA_KIND_TVSHOW; /* tv show */
/* Default to artist = series_name */ /* Default to artist = series_name */
if (mfi->artist && strlen(mfi->artist) == 0) if (mfi->artist && strlen(mfi->artist) == 0)
@ -608,7 +608,7 @@ fixup_tags(struct media_file_info *mfi)
mfi->album_artist_sort = strdup(""); mfi->album_artist_sort = strdup("");
} }
} }
else if (mfi->media_kind == 4) /* Podcast */ else if (mfi->media_kind == MEDIA_KIND_PODCAST) /* Podcast */
{ {
if (mfi->album_artist) if (mfi->album_artist)
free(mfi->album_artist); free(mfi->album_artist);
@ -691,12 +691,12 @@ filescanner_process_media(char *path, time_t mtime, off_t size, int type, struct
if (type & F_SCAN_TYPE_FILE) if (type & F_SCAN_TYPE_FILE)
{ {
mfi->data_kind = 0; /* real file */ mfi->data_kind = DATA_KIND_FILE; /* real file */
ret = scan_metadata_ffmpeg(path, mfi); ret = scan_metadata_ffmpeg(path, mfi);
} }
else if (type & F_SCAN_TYPE_URL) else if (type & F_SCAN_TYPE_URL)
{ {
mfi->data_kind = 1; /* url/stream */ mfi->data_kind = DATA_KIND_URL; /* url/stream */
ret = scan_metadata_ffmpeg(path, mfi); ret = scan_metadata_ffmpeg(path, mfi);
if (ret < 0) if (ret < 0)
{ {
@ -709,12 +709,12 @@ filescanner_process_media(char *path, time_t mtime, off_t size, int type, struct
} }
else if (type & F_SCAN_TYPE_SPOTIFY) else if (type & F_SCAN_TYPE_SPOTIFY)
{ {
mfi->data_kind = 2; /* iTunes has no spotify data kind, but we use 2 */ mfi->data_kind = DATA_KIND_SPOTIFY; /* iTunes has no spotify data kind, but we use 2 */
ret = mfi->artist && mfi->album && mfi->title; ret = mfi->artist && mfi->album && mfi->title;
} }
else if (type & F_SCAN_TYPE_PIPE) else if (type & F_SCAN_TYPE_PIPE)
{ {
mfi->data_kind = 3; /* iTunes has no pipe data kind, but we use 3 */ mfi->data_kind = DATA_KIND_PIPE; /* iTunes has no pipe data kind, but we use 3 */
mfi->type = strdup("wav"); mfi->type = strdup("wav");
mfi->codectype = strdup("wav"); mfi->codectype = strdup("wav");
mfi->description = strdup("PCM16 pipe"); mfi->description = strdup("PCM16 pipe");
@ -735,14 +735,14 @@ filescanner_process_media(char *path, time_t mtime, off_t size, int type, struct
if (type & F_SCAN_TYPE_COMPILATION) if (type & F_SCAN_TYPE_COMPILATION)
mfi->compilation = 1; mfi->compilation = 1;
if (type & F_SCAN_TYPE_PODCAST) if (type & F_SCAN_TYPE_PODCAST)
mfi->media_kind = 4; /* podcast */ mfi->media_kind = MEDIA_KIND_PODCAST; /* podcast */
if (type & F_SCAN_TYPE_AUDIOBOOK) if (type & F_SCAN_TYPE_AUDIOBOOK)
mfi->media_kind = 8; /* audiobook */ mfi->media_kind = MEDIA_KIND_AUDIOBOOK; /* audiobook */
if (!mfi->item_kind) if (!mfi->item_kind)
mfi->item_kind = 2; /* music */ mfi->item_kind = 2; /* music */
if (!mfi->media_kind) if (!mfi->media_kind)
mfi->media_kind = 1; /* music */ mfi->media_kind = MEDIA_KIND_MUSIC; /* music */
unicode_fixup_mfi(mfi); unicode_fixup_mfi(mfi);

View File

@ -346,14 +346,14 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3) #if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
# ifndef HAVE_FFMPEG # ifndef HAVE_FFMPEG
// Without this, libav is slow to probe some internet streams // Without this, libav is slow to probe some internet streams
if (mfi->data_kind == 1) if (mfi->data_kind == DATA_KIND_URL)
{ {
ctx = avformat_alloc_context(); ctx = avformat_alloc_context();
ctx->probesize = 64000; ctx->probesize = 64000;
} }
# endif # endif
if (mfi->data_kind == 1) if (mfi->data_kind == DATA_KIND_URL)
{ {
free(path); free(path);
ret = http_stream_setup(&path, file); ret = http_stream_setup(&path, file);
@ -493,7 +493,7 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
DPRINTF(E_DBG, L_SCAN, "Duration %d ms, bitrate %d kbps\n", mfi->song_length, mfi->bitrate); DPRINTF(E_DBG, L_SCAN, "Duration %d ms, bitrate %d kbps\n", mfi->song_length, mfi->bitrate);
/* Try to extract ICY metadata if url/stream */ /* Try to extract ICY metadata if url/stream */
if (mfi->data_kind == 1) if (mfi->data_kind == DATA_KIND_URL)
{ {
icy_metadata = http_icy_metadata_get(ctx, 0); icy_metadata = http_icy_metadata_get(ctx, 0);
if (icy_metadata && icy_metadata->name) if (icy_metadata && icy_metadata->name)
@ -753,12 +753,12 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
if (mfi->media_kind == 10) if (mfi->media_kind == 10)
{ {
/* I have no idea why this is, but iTunes reports a media kind of 64 for stik==10 (?!) */ /* I have no idea why this is, but iTunes reports a media kind of 64 for stik==10 (?!) */
mfi->media_kind = 64; mfi->media_kind = MEDIA_KIND_TVSHOW;
} }
/* Unspecified video files are "Movies", media_kind 2 */ /* Unspecified video files are "Movies", media_kind 2 */
else if (mfi->has_video == 1) else if (mfi->has_video == 1)
{ {
mfi->media_kind = 2; mfi->media_kind = MEDIA_KIND_MOVIE;
} }
skip_extract: skip_extract:

View File

@ -474,7 +474,7 @@ process_track_file(plist_t trk)
ret = get_dictval_bool_from_key(trk, "Podcast", &boolean); ret = get_dictval_bool_from_key(trk, "Podcast", &boolean);
if ((ret == 0) && boolean) if ((ret == 0) && boolean)
{ {
mfi->media_kind = 4; mfi->media_kind = MEDIA_KIND_PODCAST;
} }
/* Don't let album_artist set to "Unknown artist" if we've /* Don't let album_artist set to "Unknown artist" if we've

View File

@ -415,7 +415,7 @@ httpd_stream_file(struct evhttp_request *req, int id)
return; return;
} }
if (mfi->data_kind != 0) if (mfi->data_kind != DATA_KIND_FILE)
{ {
evhttp_send_error(req, 500, "Cannot stream radio station"); evhttp_send_error(req, 500, "Cannot stream radio station");

View File

@ -590,7 +590,7 @@ scrobble(struct lastfm_command *cmd)
goto noscrobble; goto noscrobble;
// Don't scrobble non-music and radio stations // Don't scrobble non-music and radio stations
if ((mfi->media_kind != 1) || (mfi->data_kind == 1)) if ((mfi->media_kind != MEDIA_KIND_MUSIC) || (mfi->data_kind == DATA_KIND_URL))
goto noscrobble; goto noscrobble;
// Don't scrobble songs with unknown artist // Don't scrobble songs with unknown artist

View File

@ -1373,7 +1373,7 @@ source_open(struct player_source *ps, int no_md)
// Setup the source type responsible for getting the audio // Setup the source type responsible for getting the audio
switch (mfi->data_kind) switch (mfi->data_kind)
{ {
case 1: case DATA_KIND_URL:
ps->type = SOURCE_HTTP; ps->type = SOURCE_HTTP;
ret = http_stream_setup(&url, mfi->path); ret = http_stream_setup(&url, mfi->path);
@ -1386,7 +1386,7 @@ source_open(struct player_source *ps, int no_md)
ret = transcode_setup(&ps->ctx, mfi, NULL, 0); ret = transcode_setup(&ps->ctx, mfi, NULL, 0);
break; break;
case 2: case DATA_KIND_SPOTIFY:
ps->type = SOURCE_SPOTIFY; ps->type = SOURCE_SPOTIFY;
#ifdef HAVE_SPOTIFY_H #ifdef HAVE_SPOTIFY_H
ret = spotify_playback_play(mfi); ret = spotify_playback_play(mfi);
@ -1395,7 +1395,7 @@ source_open(struct player_source *ps, int no_md)
#endif #endif
break; break;
case 3: case DATA_KIND_PIPE:
ps->type = SOURCE_PIPE; ps->type = SOURCE_PIPE;
ret = pipe_setup(mfi); ret = pipe_setup(mfi);
break; break;

View File

@ -507,13 +507,13 @@ transcode_setup(struct transcode_ctx **nctx, struct media_file_info *mfi, off_t
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3) #if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
# ifndef HAVE_FFMPEG # ifndef HAVE_FFMPEG
// Without this, libav is slow to probe some internet streams, which leads to RAOP timeouts // Without this, libav is slow to probe some internet streams, which leads to RAOP timeouts
if (mfi->data_kind == 1) if (mfi->data_kind == DATA_KIND_URL)
{ {
ctx->fmtctx = avformat_alloc_context(); ctx->fmtctx = avformat_alloc_context();
ctx->fmtctx->probesize = 64000; ctx->fmtctx->probesize = 64000;
} }
# endif # endif
if (mfi->data_kind == 1) if (mfi->data_kind == DATA_KIND_URL)
av_dict_set(&options, "icy", "1", 0); av_dict_set(&options, "icy", "1", 0);
ret = avformat_open_input(&ctx->fmtctx, mfi->path, NULL, &options); ret = avformat_open_input(&ctx->fmtctx, mfi->path, NULL, &options);