Merge branch 'streaming'

This commit is contained in:
ejurgensen 2013-08-15 22:02:33 +02:00
commit 5a0879de7f
6 changed files with 60 additions and 152 deletions

View File

@ -72,7 +72,7 @@ forked_daapd_SOURCES = main.c \
logger.c logger.h \
conffile.c conffile.h \
filescanner.c filescanner.h \
filescanner_ffmpeg.c filescanner_urlfile.c filescanner_m3u.c $(ITUNESSRC) \
filescanner_ffmpeg.c filescanner_m3u.c $(ITUNESSRC) \
mdns_avahi.c mdns.h \
remote_pairing.c remote_pairing.h \
evhttp/http.c evhttp/evhttp.h \

View File

@ -66,6 +66,7 @@
struct deferred_pl {
char *path;
time_t mtime;
struct deferred_pl *next;
};
@ -181,7 +182,7 @@ fixup_tags(struct media_file_info *mfi)
* Default to mpeg4 video/audio for unknown file types
* in an attempt to allow streaming of DRM-afflicted files
*/
if (strcmp(mfi->codectype, "unkn") == 0)
if (mfi->codectype && strcmp(mfi->codectype, "unkn") == 0)
{
if (mfi->has_video)
{
@ -294,8 +295,8 @@ fixup_tags(struct media_file_info *mfi)
}
static void
process_media_file(char *file, time_t mtime, off_t size, int compilation)
void
process_media_file(char *file, time_t mtime, off_t size, int compilation, int url)
{
struct media_file_info mfi;
char *filename;
@ -354,10 +355,8 @@ process_media_file(char *file, time_t mtime, off_t size, int compilation)
if ((strcmp(ext, ".pls") == 0)
|| (strcmp(ext, ".url") == 0))
{
mfi.data_kind = 1; /* url/stream */
DPRINTF(E_INFO, L_SCAN, "No support for .url and .pls in this version, use .m3u\n");
ret = scan_url_file(file, &mfi);
if (ret < 0)
goto out;
}
else if ((strcmp(ext, ".png") == 0)
@ -366,13 +365,28 @@ process_media_file(char *file, time_t mtime, off_t size, int compilation)
/* Artwork - don't scan */
goto out;
}
else if ((strcmp(ext, ".db") == 0)
|| (strcmp(ext, ".ini") == 0))
{
/* System files - don't scan */
goto out;
}
else if ((filename[1] == '_')
|| (filename[1] == '.'))
{
/* Hidden files - don't scan */
goto out;
}
}
/* General case */
if (ret < 0)
{
ret = scan_metadata_ffmpeg(file, &mfi);
if (url == 0)
mfi.data_kind = 0; /* real file */
if (url == 1)
mfi.data_kind = 1; /* url/stream */
}
if (ret < 0)
@ -403,7 +417,7 @@ process_media_file(char *file, time_t mtime, off_t size, int compilation)
}
static void
process_playlist(char *file)
process_playlist(char *file, time_t mtime)
{
char *ext;
@ -411,7 +425,7 @@ process_playlist(char *file)
if (ext)
{
if (strcmp(ext, ".m3u") == 0)
scan_m3u_playlist(file);
scan_m3u_playlist(file, mtime);
#ifdef ITUNES
else if (strcmp(ext, ".xml") == 0)
scan_itunes_itml(file);
@ -421,7 +435,7 @@ process_playlist(char *file)
/* Thread: scan */
static void
defer_playlist(char *path)
defer_playlist(char *path, time_t mtime)
{
struct deferred_pl *pl;
@ -444,6 +458,7 @@ defer_playlist(char *path)
return;
}
pl->mtime = mtime;
pl->next = playlists;
playlists = pl;
@ -460,7 +475,7 @@ process_deferred_playlists(void)
{
playlists = pl->next;
process_playlist(pl->path);
process_playlist(pl->path, pl->mtime);
free(pl->path);
free(pl);
@ -489,9 +504,9 @@ process_file(char *file, time_t mtime, off_t size, int compilation, int flags)
)
{
if (flags & F_SCAN_BULK)
defer_playlist(file);
defer_playlist(file, mtime);
else
process_playlist(file);
process_playlist(file, mtime);
return;
}
@ -504,7 +519,7 @@ process_file(char *file, time_t mtime, off_t size, int compilation, int flags)
}
/* Not any kind of special file, so let's see if it's a media file */
process_media_file(file, mtime, size, compilation);
process_media_file(file, mtime, size, compilation, 0);
}

View File

@ -10,15 +10,15 @@ filescanner_init(void);
void
filescanner_deinit(void);
void
process_media_file(char *file, time_t mtime, off_t size, int compilation, int url);
/* Actual scanners */
int
scan_metadata_ffmpeg(char *file, struct media_file_info *mfi);
int
scan_url_file(char *file, struct media_file_info *mfi);
void
scan_m3u_playlist(char *file);
scan_m3u_playlist(char *file, time_t mtime);
#ifdef ITUNES
void

View File

@ -41,7 +41,7 @@
void
scan_m3u_playlist(char *file)
scan_m3u_playlist(char *file, time_t mtime)
{
FILE *fp;
struct playlist_info *pli;
@ -165,6 +165,17 @@ scan_m3u_playlist(char *file)
buf[len] = '\0';
}
/* Check if line is an URL */
if (strcmp(buf, "http://") > 0)
{
DPRINTF(E_DBG, L_SCAN, "Playlist contains URL entry\n");
filename = strdup(buf);
process_media_file(filename, mtime, 0, 0, 1);
goto urlexit;
}
/* Absolute vs. relative path */
if (buf[0] == '/')
{
@ -191,6 +202,7 @@ scan_m3u_playlist(char *file)
continue;
}
urlexit:
ret = db_pl_add_item_bypath(pl_id, filename);
if (ret < 0)
DPRINTF(E_WARN, L_SCAN, "Could not add %s to playlist\n", filename);

View File

@ -1,121 +0,0 @@
/*
* Copyright (C) 2009-2010 Julien BLACHE <jb@jblache.org>
*
* Rewritten from mt-daapd code:
* Copyright (C) 2003 Ron Pedde (ron@pedde.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "logger.h"
#include "db.h"
#include "misc.h"
#include "filescanner.h"
int
scan_url_file(char *file, struct media_file_info *mfi)
{
FILE *fp;
char *head;
char *tail;
char buf[256];
size_t len;
int ret;
DPRINTF(E_DBG, L_SCAN, "Getting URL file info\n");
fp = fopen(file, "r");
if (!fp)
{
DPRINTF(E_WARN, L_SCAN, "Could not open '%s' for reading: %s\n", file, strerror(errno));
return -1;
}
head = fgets(buf, sizeof(buf), fp);
fclose(fp);
if (!head)
{
DPRINTF(E_WARN, L_SCAN, "Error reading from file '%s': %s", file, strerror(errno));
return -1;
}
len = strlen(buf);
if (buf[len - 1] != '\n')
{
DPRINTF(E_WARN, L_SCAN, "URL info in file '%s' too large for buffer\n", file);
return -1;
}
while (isspace(buf[len - 1]))
{
len--;
buf[len] = '\0';
}
tail = strchr(head, ',');
if (!tail)
{
DPRINTF(E_LOG, L_SCAN, "Badly formatted .url file; expected format is bitrate,descr,url\n");
return -1;
}
head = tail + 1;
tail = strchr(head, ',');
if (!tail)
{
DPRINTF(E_LOG, L_SCAN, "Badly formatted .url file; expected format is bitrate,descr,url\n");
return -1;
}
*tail = '\0';
mfi->title = strdup(head);
mfi->url = strdup(tail + 1);
ret = safe_atou32(buf, &mfi->bitrate);
if (ret < 0)
{
DPRINTF(E_WARN, L_SCAN, "Could not read bitrate\n");
return -1;
}
DPRINTF(E_DBG, L_SCAN," Title: %s\n", mfi->title);
DPRINTF(E_DBG, L_SCAN," Bitrate: %d\n", mfi->bitrate);
DPRINTF(E_DBG, L_SCAN," URL: %s\n", mfi->url);
mfi->type = strdup("pls");
/* codectype = NULL */
mfi->description = strdup("Playlist URL");
return 0;
}

View File

@ -579,6 +579,7 @@ main(int argc, char **argv)
}
av_register_all();
avformat_network_init();
av_log_set_callback(logger_ffmpeg);
#if LIBAVFORMAT_VERSION_MAJOR < 53
register_ffmpeg_evbuffer_url_protocol();
@ -814,6 +815,7 @@ main(int argc, char **argv)
signal_block_fail:
gcrypt_init_fail:
avformat_network_deinit();
av_lockmgr_register(NULL);
ffmpeg_init_fail: