"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "metadata.c" between
minidlna-1.1.5.tar.gz and minidlna-1.2.0.tar.gz

About: ReadyMedia (formerly known as MiniDLNA) is a simple media server software, with the aim of being fully compliant with DLNA/UPnP-AV clients.

metadata.c  (minidlna-1.1.5):metadata.c  (minidlna-1.2.0)
/* MiniDLNA media server /* MiniDLNA media server
* Copyright (C) 2008-2009 Justin Maggard * Copyright (C) 2008-2017 Justin Maggard
* *
* This file is part of MiniDLNA. * This file is part of MiniDLNA.
* *
* MiniDLNA is free software; you can redistribute it and/or modify * MiniDLNA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* MiniDLNA is distributed in the hope that it will be useful, * MiniDLNA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
skipping to change at line 152 skipping to change at line 152
strcpy(p, ".srt"); strcpy(p, ".srt");
ret = access(file, R_OK); ret = access(file, R_OK);
if (ret != 0) if (ret != 0)
{ {
strcpy(p, ".smi"); strcpy(p, ".smi");
ret = access(file, R_OK); ret = access(file, R_OK);
} }
if (ret == 0) if (ret == 0)
{ {
sql_exec(db, "INSERT into CAPTIONS" sql_exec(db, "INSERT OR REPLACE into CAPTIONS"
" (ID, PATH) " " (ID, PATH) "
"VALUES" "VALUES"
" (%lld, %Q)", detailID, file); " (%lld, %Q)", detailID, file);
} }
} }
void void
parse_nfo(const char *path, metadata_t *m) parse_nfo(const char *path, metadata_t *m)
{ {
FILE *nfo; FILE *nfo;
char buf[65536]; char *buf;
struct NameValueParserData xml; struct NameValueParserData xml;
struct stat file; struct stat file;
size_t nread; size_t nread;
char *val, *val2; char *val, *val2;
if( stat(path, &file) != 0 || if (stat(path, &file) != 0 ||
file.st_size > 65536 ) file.st_size > 65535)
{ {
DPRINTF(E_INFO, L_METADATA, "Not parsing very large .nfo file %s\ n", path); DPRINTF(E_INFO, L_METADATA, "Not parsing very large .nfo file %s\ n", path);
return; return;
} }
DPRINTF(E_DEBUG, L_METADATA, "Parsing .nfo file: %s\n", path); DPRINTF(E_DEBUG, L_METADATA, "Parsing .nfo file: %s\n", path);
buf = calloc(1, file.st_size + 1);
if (buf)
return;
nfo = fopen(path, "r"); nfo = fopen(path, "r");
if( !nfo ) if (!nfo)
{
free(buf);
return; return;
}
nread = fread(&buf, 1, sizeof(buf), nfo); nread = fread(&buf, 1, sizeof(buf), nfo);
fclose(nfo);
ParseNameValue(buf, nread, &xml, 0); ParseNameValue(buf, nread, &xml, 0);
//printf("\ttype: %s\n", GetValueFromNameValueList(&xml, "rootElement")); //printf("\ttype: %s\n", GetValueFromNameValueList(&xml, "rootElement"));
val = GetValueFromNameValueList(&xml, "title"); val = GetValueFromNameValueList(&xml, "title");
if( val ) if (val)
{ {
char *esc_tag, *title; char *esc_tag, *title;
val2 = GetValueFromNameValueList(&xml, "episodetitle"); val2 = GetValueFromNameValueList(&xml, "episodetitle");
if( val2 ) if (val2)
xasprintf(&title, "%s - %s", val, val2); xasprintf(&title, "%s - %s", val, val2);
else else
title = strdup(val); title = strdup(val);
esc_tag = unescape_tag(title, 1); esc_tag = unescape_tag(title, 1);
m->title = escape_tag(esc_tag, 1); m->title = escape_tag(esc_tag, 1);
free(esc_tag); free(esc_tag);
free(title); free(title);
} }
val = GetValueFromNameValueList(&xml, "plot"); val = GetValueFromNameValueList(&xml, "plot");
if( val ) { if (val)
{
char *esc_tag = unescape_tag(val, 1); char *esc_tag = unescape_tag(val, 1);
m->comment = escape_tag(esc_tag, 1); m->comment = escape_tag(esc_tag, 1);
free(esc_tag); free(esc_tag);
} }
val = GetValueFromNameValueList(&xml, "capturedate"); val = GetValueFromNameValueList(&xml, "capturedate");
if( val ) { if (val)
{
char *esc_tag = unescape_tag(val, 1); char *esc_tag = unescape_tag(val, 1);
m->date = escape_tag(esc_tag, 1); m->date = escape_tag(esc_tag, 1);
free(esc_tag); free(esc_tag);
} }
val = GetValueFromNameValueList(&xml, "genre"); val = GetValueFromNameValueList(&xml, "genre");
if( val ) if (val)
{ {
free(m->genre);
char *esc_tag = unescape_tag(val, 1); char *esc_tag = unescape_tag(val, 1);
free(m->genre);
m->genre = escape_tag(esc_tag, 1); m->genre = escape_tag(esc_tag, 1);
free(esc_tag); free(esc_tag);
} }
val = GetValueFromNameValueList(&xml, "mime"); val = GetValueFromNameValueList(&xml, "mime");
if( val ) if (val)
{ {
free(m->mime);
char *esc_tag = unescape_tag(val, 1); char *esc_tag = unescape_tag(val, 1);
free(m->mime);
m->mime = escape_tag(esc_tag, 1); m->mime = escape_tag(esc_tag, 1);
free(esc_tag); free(esc_tag);
} }
ClearNameValueList(&xml); ClearNameValueList(&xml);
fclose(nfo); free(buf);
} }
void void
free_metadata(metadata_t *m, uint32_t flags) free_metadata(metadata_t *m, uint32_t flags)
{ {
if( flags & FLAG_TITLE ) if( flags & FLAG_TITLE )
free(m->title); free(m->title);
if( flags & FLAG_ARTIST ) if( flags & FLAG_ARTIST )
free(m->artist); free(m->artist);
if( flags & FLAG_ALBUM ) if( flags & FLAG_ALBUM )
skipping to change at line 357 skipping to change at line 366
{ {
if( !getenv("LANG") ) if( !getenv("LANG") )
strcpy(lang, "en_US"); strcpy(lang, "en_US");
else else
strncpyt(lang, getenv("LANG"), sizeof(lang)); strncpyt(lang, getenv("LANG"), sizeof(lang));
} }
if( readtags((char *)path, &song, &file, lang, type) != 0 ) if( readtags((char *)path, &song, &file, lang, type) != 0 )
{ {
DPRINTF(E_WARN, L_METADATA, "Cannot extract tags from %s!\n", pat h); DPRINTF(E_WARN, L_METADATA, "Cannot extract tags from %s!\n", pat h);
freetags(&song); freetags(&song);
free_metadata(&m, free_flags); free_metadata(&m, free_flags);
return 0; return 0;
} }
if( song.dlna_pn ) if( song.dlna_pn )
m.dlna_pn = strdup(song.dlna_pn); m.dlna_pn = strdup(song.dlna_pn);
if( song.year ) if( song.year )
xasprintf(&m.date, "%04d-01-01", song.year); xasprintf(&m.date, "%04d-01-01", song.year);
xasprintf(&m.duration, "%d:%02d:%02d.%03d", m.duration = duration_str(song.song_length);
(song.song_length/3600000),
(song.song_length/60000%60),
(song.song_length/1000%60),
(song.song_length%1000));
if( song.title && *song.title ) if( song.title && *song.title )
{ {
m.title = trim(song.title); m.title = trim(song.title);
if( (esc_tag = escape_tag(m.title, 0)) ) if( (esc_tag = escape_tag(m.title, 0)) )
{ {
free_flags |= FLAG_TITLE; free_flags |= FLAG_TITLE;
m.title = esc_tag; m.title = esc_tag;
} }
} }
else else
skipping to change at line 412 skipping to change at line 417
} }
/* If there is a album artist or band associated with the album, /* If there is a album artist or band associated with the album,
use it for virtual containers. */ use it for virtual containers. */
if( i < ROLE_ALBUMARTIST ) if( i < ROLE_ALBUMARTIST )
{ {
for( i = ROLE_ALBUMARTIST; i <= ROLE_BAND; i++ ) for( i = ROLE_ALBUMARTIST; i <= ROLE_BAND; i++ )
{ {
if( song.contributor[i] && *song.contributor[i] ) if( song.contributor[i] && *song.contributor[i] )
break; break;
} }
if( i <= ROLE_BAND ) if( i <= ROLE_BAND )
{ {
m.artist = trim(song.contributor[i]); m.artist = trim(song.contributor[i]);
if( strlen(m.artist) > 48 ) if( strlen(m.artist) > 48 )
{ {
m.artist = strdup("Various Artists"); m.artist = strdup("Various Artists");
free_flags |= FLAG_ARTIST; free_flags |= FLAG_ARTIST;
} }
else if( (esc_tag = escape_tag(m.artist, 0)) ) else if( (esc_tag = escape_tag(m.artist, 0)) )
{ {
m.artist = esc_tag; m.artist = esc_tag;
skipping to change at line 474 skipping to change at line 479
song.track, m.dlna_pn, song.mime?song.mime:m.mime, alb um_art); song.track, m.dlna_pn, song.mime?song.mime:m.mime, alb um_art);
if( ret != SQLITE_OK ) if( ret != SQLITE_OK )
{ {
DPRINTF(E_ERROR, L_METADATA, "Error inserting details for '%s'!\n ", path); DPRINTF(E_ERROR, L_METADATA, "Error inserting details for '%s'!\n ", path);
ret = 0; ret = 0;
} }
else else
{ {
ret = sqlite3_last_insert_rowid(db); ret = sqlite3_last_insert_rowid(db);
} }
freetags(&song); freetags(&song);
free_metadata(&m, free_flags); free_metadata(&m, free_flags);
return ret; return ret;
} }
/* For libjpeg error handling */ /* For libjpeg error handling */
jmp_buf setjmp_buffer; jmp_buf setjmp_buffer;
static void static void
libjpeg_error_handler(j_common_ptr cinfo) libjpeg_error_handler(j_common_ptr cinfo)
{ {
skipping to change at line 589 skipping to change at line 594
} }
if( ed->size ) if( ed->size )
{ {
/* We might need to verify that the thumbnail is 160x160 or small er */ /* We might need to verify that the thumbnail is 160x160 or small er */
if( ed->size > 12000 ) if( ed->size > 12000 )
{ {
imsrc = image_new_from_jpeg(NULL, 0, ed->data, ed->size, 1, ROTATE_NONE); imsrc = image_new_from_jpeg(NULL, 0, ed->data, ed->size, 1, ROTATE_NONE);
if( imsrc ) if( imsrc )
{ {
if( (imsrc->width <= 160) && (imsrc->height <= 16 0) ) if( (imsrc->width <= 160) && (imsrc->height <= 16 0) )
thumb = 1; thumb = 1;
image_free(imsrc); image_free(imsrc);
} }
} }
else else
thumb = 1; thumb = 1;
} }
//DEBUG DPRINTF(E_DEBUG, L_METADATA, " * thumbnail: %d\n", thumb); //DEBUG DPRINTF(E_DEBUG, L_METADATA, " * thumbnail: %d\n", thumb);
exif_data_unref(ed); exif_data_unref(ed);
skipping to change at line 666 skipping to change at line 671
return ret; return ret;
} }
int64_t int64_t
GetVideoMetadata(const char *path, char *name) GetVideoMetadata(const char *path, char *name)
{ {
struct stat file; struct stat file;
int ret, i; int ret, i;
struct tm *modtime; struct tm *modtime;
AVFormatContext *ctx = NULL; AVFormatContext *ctx = NULL;
AVCodecContext *ac = NULL, *vc = NULL; AVStream *astream = NULL, *vstream = NULL;
int audio_stream = -1, video_stream = -1; int audio_stream = -1, video_stream = -1;
enum audio_profiles audio_profile = PROFILE_AUDIO_UNKNOWN; enum audio_profiles audio_profile = PROFILE_AUDIO_UNKNOWN;
char fourcc[4]; char fourcc[4];
int64_t album_art = 0; int64_t album_art = 0;
char nfo[MAXPATHLEN], *ext; char nfo[MAXPATHLEN], *ext;
struct song_metadata video; struct song_metadata video;
metadata_t m; metadata_t m;
uint32_t free_flags = 0xFFFFFFFF; uint32_t free_flags = 0xFFFFFFFF;
char *path_cpy, *basepath; char *path_cpy, *basepath;
skipping to change at line 695 skipping to change at line 700
ret = lav_open(&ctx, path); ret = lav_open(&ctx, path);
if( ret != 0 ) if( ret != 0 )
{ {
char err[128]; char err[128];
av_strerror(ret, err, sizeof(err)); av_strerror(ret, err, sizeof(err));
DPRINTF(E_WARN, L_METADATA, "Opening %s failed! [%s]\n", path, er r); DPRINTF(E_WARN, L_METADATA, "Opening %s failed! [%s]\n", path, er r);
return 0; return 0;
} }
//dump_format(ctx, 0, NULL, 0); //dump_format(ctx, 0, NULL, 0);
for( i=0; i<ctx->nb_streams; i++) for( i=0; i < ctx->nb_streams; i++)
{ {
if( ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO && if( lav_codec_type(ctx->streams[i]) == AVMEDIA_TYPE_AUDIO &&
audio_stream == -1 ) audio_stream == -1 )
{ {
audio_stream = i; audio_stream = i;
ac = ctx->streams[audio_stream]->codec; astream = ctx->streams[audio_stream];
continue; continue;
} }
else if( ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO && else if( lav_codec_type(ctx->streams[i]) == AVMEDIA_TYPE_VIDEO &&
!lav_is_thumbnail_stream(ctx->streams[i], &m.thumb_data, &m.thumb_size) && !lav_is_thumbnail_stream(ctx->streams[i], &m.thumb_data, &m.thumb_size) &&
video_stream == -1 ) video_stream == -1 )
{ {
video_stream = i; video_stream = i;
vc = ctx->streams[video_stream]->codec; vstream = ctx->streams[video_stream];
continue; continue;
} }
} }
path_cpy = strdup(path); path_cpy = strdup(path);
basepath = basename(path_cpy); basepath = basename(path_cpy);
if( !vc ) if( !vstream )
{ {
/* This must not be a video file. */ /* This must not be a video file. */
lav_close(ctx); lav_close(ctx);
if( !is_audio(path) ) if( !is_audio(path) )
DPRINTF(E_DEBUG, L_METADATA, "File %s does not contain a video stream.\n", basepath); DPRINTF(E_DEBUG, L_METADATA, "File %s does not contain a video stream.\n", basepath);
free(path_cpy); free(path_cpy);
return 0; return 0;
} }
if( ac ) if( astream )
{ {
aac_object_type_t aac_type = AAC_INVALID; aac_object_type_t aac_type = AAC_INVALID;
switch( ac->codec_id ) switch( lav_codec_id(astream) )
{ {
case AV_CODEC_ID_MP3: case AV_CODEC_ID_MP3:
audio_profile = PROFILE_AUDIO_MP3; audio_profile = PROFILE_AUDIO_MP3;
break; break;
case AV_CODEC_ID_AAC: case AV_CODEC_ID_AAC:
if( !ac->extradata_size || if( !lav_codec_extradata(astream) )
!ac->extradata )
{ {
DPRINTF(E_DEBUG, L_METADATA, "No AAC type \n"); DPRINTF(E_DEBUG, L_METADATA, "No AAC type \n");
} }
else else
{ {
uint8_t data; uint8_t data;
memcpy(&data, ac->extradata, 1); memcpy(&data, lav_codec_extradata(astream ), 1);
aac_type = data >> 3; aac_type = data >> 3;
} }
switch( aac_type ) switch( aac_type )
{ {
/* AAC Low Complexity variants */ /* AAC Low Complexity variants */
case AAC_LC: case AAC_LC:
case AAC_LC_ER: case AAC_LC_ER:
if( ac->sample_rate < 8000 || if( lav_sample_rate(astream) < 80
ac->sample_rate > 48000 ) 00 ||
lav_sample_rate(astream) > 48
000 )
{ {
DPRINTF(E_DEBUG, L_METADA TA, "Unsupported AAC: sample rate is not 8000 < %d < 48000\n", DPRINTF(E_DEBUG, L_METADA TA, "Unsupported AAC: sample rate is not 8000 < %d < 48000\n",
ac->sample_rate); lav_sample_rate(a stream));
break; break;
} }
/* AAC @ Level 1/2 */ /* AAC @ Level 1/2 */
if( ac->channels <= 2 && if( lav_channels(astream) <= 2 &&
ac->bit_rate <= 576000 ) lav_bit_rate(astream) <= 5760
00 )
audio_profile = PROFILE_A UDIO_AAC; audio_profile = PROFILE_A UDIO_AAC;
else if( ac->channels <= 6 && else if( lav_channels(astream) <=
ac->bit_rate <= 1440000 6 &&
) lav_bit_rate(astream) <=
1440000 )
audio_profile = PROFILE_A UDIO_AAC_MULT5; audio_profile = PROFILE_A UDIO_AAC_MULT5;
else else
DPRINTF(E_DEBUG, L_METADA DPRINTF(E_DEBUG, L_METADA
TA, "Unhandled AAC: %d channels, %d bitrate\n", TA, "Unhandled AAC: %lld channels, %lld bitrate\n",
ac->channels, (long long)lav_ch
ac->bit_rate); annels(astream),
(long long)lav_bi
t_rate(astream));
break; break;
default: default:
DPRINTF(E_DEBUG, L_METADATA, "Unh andled AAC type [%d]\n", aac_type); DPRINTF(E_DEBUG, L_METADATA, "Unh andled AAC type [%d]\n", aac_type);
break; break;
} }
break; break;
case AV_CODEC_ID_AC3: case AV_CODEC_ID_AC3:
case AV_CODEC_ID_DTS: case AV_CODEC_ID_DTS:
audio_profile = PROFILE_AUDIO_AC3; audio_profile = PROFILE_AUDIO_AC3;
break; break;
case AV_CODEC_ID_WMAV1: case AV_CODEC_ID_WMAV1:
case AV_CODEC_ID_WMAV2: case AV_CODEC_ID_WMAV2:
/* WMA Baseline: stereo, up to 48 KHz, up to 192, 999 bps */ /* WMA Baseline: stereo, up to 48 KHz, up to 192, 999 bps */
if ( ac->bit_rate <= 193000 ) if ( lav_bit_rate(astream) <= 193000 )
audio_profile = PROFILE_AUDIO_WMA_BASE; audio_profile = PROFILE_AUDIO_WMA_BASE;
/* WMA Full: stereo, up to 48 KHz, up to 385 Kbps */ /* WMA Full: stereo, up to 48 KHz, up to 385 Kbps */
else if ( ac->bit_rate <= 385000 ) else if ( lav_bit_rate(astream) <= 385000 )
audio_profile = PROFILE_AUDIO_WMA_FULL; audio_profile = PROFILE_AUDIO_WMA_FULL;
break; break;
case AV_CODEC_ID_WMAPRO: case AV_CODEC_ID_WMAPRO:
audio_profile = PROFILE_AUDIO_WMA_PRO; audio_profile = PROFILE_AUDIO_WMA_PRO;
break; break;
case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP2:
audio_profile = PROFILE_AUDIO_MP2; audio_profile = PROFILE_AUDIO_MP2;
break; break;
case AV_CODEC_ID_AMR_NB: case AV_CODEC_ID_AMR_NB:
audio_profile = PROFILE_AUDIO_AMR; audio_profile = PROFILE_AUDIO_AMR;
break; break;
default: default:
if( (ac->codec_id >= AV_CODEC_ID_PCM_S16LE) && if( (lav_codec_id(astream) >= AV_CODEC_ID_PCM_S16
(ac->codec_id < AV_CODEC_ID_ADPCM_IMA_QT) ) LE) &&
(lav_codec_id(astream) < AV_CODEC_ID_ADPCM_IM
A_QT) )
audio_profile = PROFILE_AUDIO_PCM; audio_profile = PROFILE_AUDIO_PCM;
else else
DPRINTF(E_DEBUG, L_METADATA, "Unhandled a udio codec [0x%X]\n", ac->codec_id); DPRINTF(E_DEBUG, L_METADATA, "Unhandled a udio codec [0x%X]\n", lav_codec_id(astream));
break; break;
} }
m.frequency = ac->sample_rate; m.frequency = lav_sample_rate(astream);
m.channels = ac->channels; m.channels = lav_channels(astream);
} }
if( vc ) if( vstream )
{ {
int off; int off;
int duration, hours, min, sec, ms;
ts_timestamp_t ts_timestamp = NONE; ts_timestamp_t ts_timestamp = NONE;
DPRINTF(E_DEBUG, L_METADATA, "Container: '%s' [%s]\n", ctx->iform at->name, basepath); DPRINTF(E_DEBUG, L_METADATA, "Container: '%s' [%s]\n", ctx->iform at->name, basepath);
xasprintf(&m.resolution, "%dx%d", vc->width, vc->height); xasprintf(&m.resolution, "%dx%d", lav_width(vstream), lav_height( vstream));
if( ctx->bit_rate > 8 ) if( ctx->bit_rate > 8 )
m.bitrate = ctx->bit_rate / 8; m.bitrate = ctx->bit_rate / 8;
if( ctx->duration > 0 ) { if( ctx->duration > 0 )
duration = (int)(ctx->duration / AV_TIME_BASE); m.duration = duration_str(ctx->duration / (AV_TIME_BASE/1
hours = (int)(duration / 3600); 000));
min = (int)(duration / 60 % 60);
sec = (int)(duration % 60);
ms = (int)(ctx->duration / (AV_TIME_BASE/1000) % 1000);
xasprintf(&m.duration, "%d:%02d:%02d.%03d", hours, min, s
ec, ms);
}
/* NOTE: The DLNA spec only provides for ASF (WMV), TS, PS, and M P4 containers. /* NOTE: The DLNA spec only provides for ASF (WMV), TS, PS, and M P4 containers.
* Skip DLNA parsing for everything else. */ * Skip DLNA parsing for everything else. */
if( strcmp(ctx->iformat->name, "avi") == 0 ) if( strcmp(ctx->iformat->name, "avi") == 0 )
{ {
xasprintf(&m.mime, "video/x-msvideo"); xasprintf(&m.mime, "video/x-msvideo");
if( vc->codec_id == AV_CODEC_ID_MPEG4 ) if( lav_codec_id(vstream) == AV_CODEC_ID_MPEG4 )
{ {
fourcc[0] = vc->codec_tag & 0xff; fourcc[0] = lav_codec_tag(vstream) & 0xff;
fourcc[1] = vc->codec_tag>>8 & 0xff; fourcc[1] = lav_codec_tag(vstream)>>8 & 0xff;
fourcc[2] = vc->codec_tag>>16 & 0xff; fourcc[2] = lav_codec_tag(vstream)>>16 & 0xff;
fourcc[3] = vc->codec_tag>>24 & 0xff; fourcc[3] = lav_codec_tag(vstream)>>24 & 0xff;
if( memcmp(fourcc, "XVID", 4) == 0 || if( memcmp(fourcc, "XVID", 4) == 0 ||
memcmp(fourcc, "DX50", 4) == 0 || memcmp(fourcc, "DX50", 4) == 0 ||
memcmp(fourcc, "DIVX", 4) == 0 ) memcmp(fourcc, "DIVX", 4) == 0 )
xasprintf(&m.creator, "DiVX"); xasprintf(&m.creator, "DiVX");
} }
} }
else if( strcmp(ctx->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") == 0 && else if( strcmp(ctx->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") == 0 &&
ends_with(path, ".mov") ) ends_with(path, ".mov") )
xasprintf(&m.mime, "video/quicktime"); xasprintf(&m.mime, "video/quicktime");
else if( strncmp(ctx->iformat->name, "matroska", 8) == 0 ) else if( strncmp(ctx->iformat->name, "matroska", 8) == 0 )
xasprintf(&m.mime, "video/x-matroska"); xasprintf(&m.mime, "video/x-matroska");
else if( strcmp(ctx->iformat->name, "flv") == 0 ) else if( strcmp(ctx->iformat->name, "flv") == 0 )
xasprintf(&m.mime, "video/x-flv"); xasprintf(&m.mime, "video/x-flv");
if( m.mime ) if( m.mime )
goto video_no_dlna; goto video_no_dlna;
switch( vc->codec_id ) switch( lav_codec_id(vstream) )
{ {
case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG1VIDEO:
if( strcmp(ctx->iformat->name, "mpeg") == 0 ) if( strcmp(ctx->iformat->name, "mpeg") == 0 )
{ {
if( (vc->width == 352) && if( (lav_width(vstream) == 352) &&
(vc->height <= 288) ) (lav_height(vstream) <= 288) )
{ {
m.dlna_pn = strdup("MPEG1"); m.dlna_pn = strdup("MPEG1");
} }
xasprintf(&m.mime, "video/mpeg"); xasprintf(&m.mime, "video/mpeg");
} }
break; break;
case AV_CODEC_ID_MPEG2VIDEO: case AV_CODEC_ID_MPEG2VIDEO:
m.dlna_pn = malloc(64); m.dlna_pn = malloc(64);
off = sprintf(m.dlna_pn, "MPEG_"); off = sprintf(m.dlna_pn, "MPEG_");
if( strcmp(ctx->iformat->name, "mpegts") == 0 ) if( strcmp(ctx->iformat->name, "mpegts") == 0 )
{ {
int raw_packet_size; int raw_packet_size;
int dlna_ts_present = dlna_timestamp_is_p resent(path, &raw_packet_size); int dlna_ts_present = dlna_timestamp_is_p resent(path, &raw_packet_size);
DPRINTF(E_DEBUG, L_METADATA, "Stream %d o f %s is %s MPEG2 TS packet size %d\n", DPRINTF(E_DEBUG, L_METADATA, "Stream %d o f %s is %s MPEG2 TS packet size %d\n",
video_stream, basepath, m.resolut ion, raw_packet_size); video_stream, basepath, m.resolut ion, raw_packet_size);
off += sprintf(m.dlna_pn+off, "TS_"); off += sprintf(m.dlna_pn+off, "TS_");
if( (vc->width >= 1280) && if( (lav_width(vstream) >= 1280) &&
(vc->height >= 720) ) (lav_height(vstream) >= 720) )
{ {
off += sprintf(m.dlna_pn+off, "HD _NA"); off += sprintf(m.dlna_pn+off, "HD _NA");
} }
else else
{ {
off += sprintf(m.dlna_pn+off, "SD _"); off += sprintf(m.dlna_pn+off, "SD _");
if( (vc->height == 576) || if( (lav_height(vstream) == 576)
(vc->height == 288) ) ||
(lav_height(vstream) == 288)
)
off += sprintf(m.dlna_pn+ off, "EU"); off += sprintf(m.dlna_pn+ off, "EU");
else else
off += sprintf(m.dlna_pn+ off, "NA"); off += sprintf(m.dlna_pn+ off, "NA");
} }
if( raw_packet_size == MPEG_TS_PACKET_LEN GTH_DLNA ) if( raw_packet_size == MPEG_TS_PACKET_LEN GTH_DLNA )
{ {
if (dlna_ts_present) if (dlna_ts_present)
ts_timestamp = VALID; ts_timestamp = VALID;
else else
ts_timestamp = EMPTY; ts_timestamp = EMPTY;
skipping to change at line 923 skipping to change at line 920
xasprintf(&m.mime, "video /vnd.dlna.mpeg-tts"); xasprintf(&m.mime, "video /vnd.dlna.mpeg-tts");
default: default:
break; break;
} }
} }
else if( strcmp(ctx->iformat->name, "mpeg") == 0 ) else if( strcmp(ctx->iformat->name, "mpeg") == 0 )
{ {
DPRINTF(E_DEBUG, L_METADATA, "Stream %d o f %s is %s MPEG2 PS\n", DPRINTF(E_DEBUG, L_METADATA, "Stream %d o f %s is %s MPEG2 PS\n",
video_stream, basepath, m.resolut ion); video_stream, basepath, m.resolut ion);
off += sprintf(m.dlna_pn+off, "PS_"); off += sprintf(m.dlna_pn+off, "PS_");
if( (vc->height == 576) || if( (lav_height(vstream) == 576) ||
(vc->height == 288) ) (lav_height(vstream) == 288) )
off += sprintf(m.dlna_pn+off, "PA L"); off += sprintf(m.dlna_pn+off, "PA L");
else else
off += sprintf(m.dlna_pn+off, "NT SC"); off += sprintf(m.dlna_pn+off, "NT SC");
xasprintf(&m.mime, "video/mpeg"); xasprintf(&m.mime, "video/mpeg");
} }
else else
{ {
DPRINTF(E_DEBUG, L_METADATA, "Stream %d o f %s [%s] is %s non-DLNA MPEG2\n", DPRINTF(E_DEBUG, L_METADATA, "Stream %d o f %s [%s] is %s non-DLNA MPEG2\n",
video_stream, basepath, ctx->ifor mat->name, m.resolution); video_stream, basepath, ctx->ifor mat->name, m.resolution);
free(m.dlna_pn); free(m.dlna_pn);
skipping to change at line 950 skipping to change at line 947
off = sprintf(m.dlna_pn, "AVC_"); off = sprintf(m.dlna_pn, "AVC_");
if( strcmp(ctx->iformat->name, "mpegts") == 0 ) if( strcmp(ctx->iformat->name, "mpegts") == 0 )
{ {
AVRational display_aspect_ratio; AVRational display_aspect_ratio;
int fps, interlaced; int fps, interlaced;
int raw_packet_size; int raw_packet_size;
int dlna_ts_present = dlna_timestamp_is_p resent(path, &raw_packet_size); int dlna_ts_present = dlna_timestamp_is_p resent(path, &raw_packet_size);
off += sprintf(m.dlna_pn+off, "TS_"); off += sprintf(m.dlna_pn+off, "TS_");
if (vc->sample_aspect_ratio.num) { if (lav_sample_aspect_ratio(vstream).num) {
av_reduce(&display_aspect_ratio.n um, &display_aspect_ratio.den, av_reduce(&display_aspect_ratio.n um, &display_aspect_ratio.den,
vc->width * vc->sample lav_width(vstream) * la
_aspect_ratio.num, v_sample_aspect_ratio(vstream).num,
vc->height * vc->sample lav_height(vstream) * l
_aspect_ratio.den, av_sample_aspect_ratio(vstream).den,
1024*1024); 1024*1024);
} }
fps = lav_get_fps(ctx->streams[video_stre fps = lav_get_fps(vstream);
am]); interlaced = lav_get_interlaced(vstream);
interlaced = lav_get_interlaced(vc, ctx-> if( ((((lav_width(vstream) == 1920 || lav
streams[video_stream]); _width(vstream) == 1440) && lav_height(vstream) == 1080) ||
if( ((((vc->width == 1920 || vc->width == (lav_width(vstream) == 720 && lav_h
1440) && vc->height == 1080) || eight(vstream) == 480)) && fps == 59 && interlaced) ||
(vc->width == 720 && vc->height == ((lav_width(vstream) == 1280 && lav_h
480)) && fps == 59 && interlaced) || eight(vstream) == 720) && fps == 59 && !interlaced) )
((vc->width == 1280 && vc->height ==
720) && fps == 59 && !interlaced) )
{ {
if( (vc->profile == FF_PROFILE_H2 64_MAIN || vc->profile == FF_PROFILE_H264_HIGH) && if( (lav_profile(vstream) == FF_P ROFILE_H264_MAIN || lav_profile(vstream) == FF_PROFILE_H264_HIGH) &&
audio_profile == PROFILE_AUDI O_AC3 ) audio_profile == PROFILE_AUDI O_AC3 )
{ {
off += sprintf(m.dlna_pn+ off, "HD_60_"); off += sprintf(m.dlna_pn+ off, "HD_60_");
vc->profile = FF_PROFILE_ SKIP; lav_profile(vstream) = FF _PROFILE_SKIP;
} }
} }
else if( ((vc->width == 1920 && vc->heigh else if( ((lav_width(vstream) == 1920 &&
t == 1080) || lav_height(vstream) == 1080) ||
(vc->width == 1440 && vc->heigh (lav_width(vstream) == 1440 &&
t == 1080) || lav_height(vstream) == 1080) ||
(vc->width == 1280 && vc->heigh (lav_width(vstream) == 1280 &&
t == 720) || lav_height(vstream) == 720) ||
(vc->width == 720 && vc->heigh (lav_width(vstream) == 720 &&
t == 576)) && lav_height(vstream) == 576)) &&
interlaced && fps == 50 ) interlaced && fps == 50 )
{ {
if( (vc->profile == FF_PROFILE_H2 64_MAIN || vc->profile == FF_PROFILE_H264_HIGH) && if( (lav_profile(vstream) == FF_P ROFILE_H264_MAIN || lav_profile(vstream) == FF_PROFILE_H264_HIGH) &&
audio_profile == PROFILE_AUDI O_AC3 ) audio_profile == PROFILE_AUDI O_AC3 )
{ {
off += sprintf(m.dlna_pn+ off, "HD_50_"); off += sprintf(m.dlna_pn+ off, "HD_50_");
vc->profile = FF_PROFILE_ SKIP; lav_profile(vstream) = FF _PROFILE_SKIP;
} }
} }
switch( vc->profile ) switch( lav_profile(vstream) )
{ {
case FF_PROFILE_H264_BASELINE: case FF_PROFILE_H264_BASELINE:
case FF_PROFILE_H264_CONSTRAINED_ BASELINE: case FF_PROFILE_H264_CONSTRAINED_ BASELINE:
off += sprintf(m.dlna_pn+ off, "BL_"); off += sprintf(m.dlna_pn+ off, "BL_");
if( vc->width <= 352 && if( lav_width(vstream) <
vc->height <= 288 && = 352 &&
vc->bit_rate <= 38400 lav_height(vstream) <
0 ) = 288 &&
lav_bit_rate(vstream)
<= 384000 )
{ {
off += sprintf(m. dlna_pn+off, "CIF15_"); off += sprintf(m. dlna_pn+off, "CIF15_");
break; break;
} }
else if( vc->width <= 35 else if( lav_width(vstrea
2 && m) <= 352 &&
vc->height <= 28 lav_height(vstre
8 && am) <= 288 &&
vc->bit_rate <= lav_bit_rate(vst
3000000 ) ream) <= 3000000 )
{ {
off += sprintf(m. dlna_pn+off, "CIF30_"); off += sprintf(m. dlna_pn+off, "CIF30_");
break; break;
} }
/* Fall back to Main Prof ile if it doesn't match a Baseline DLNA profile. */ /* Fall back to Main Prof ile if it doesn't match a Baseline DLNA profile. */
else else
off -= 3; off -= 3;
default: default:
case FF_PROFILE_H264_MAIN: case FF_PROFILE_H264_MAIN:
off += sprintf(m.dlna_pn+ off, "MP_"); off += sprintf(m.dlna_pn+ off, "MP_");
if( vc->profile != FF_PRO if( lav_profile(vstream)
FILE_H264_BASELINE && != FF_PROFILE_H264_BASELINE &&
vc->profile != FF_PRO lav_profile(vstream)
FILE_H264_CONSTRAINED_BASELINE && != FF_PROFILE_H264_CONSTRAINED_BASELINE &&
vc->profile != FF_PRO lav_profile(vstream)
FILE_H264_MAIN ) != FF_PROFILE_H264_MAIN )
{ {
DPRINTF(E_DEBUG, L_METADATA, "Unknown AVC profile %d; assuming MP. [%s]\n", DPRINTF(E_DEBUG, L_METADATA, "Unknown AVC profile %d; assuming MP. [%s]\n",
vc->profi le, basepath); lav_profi le(vstream), basepath);
} }
if( vc->width <= 720 && if( lav_width(vstream) <
vc->height <= 576 && = 720 &&
vc->bit_rate <= 10000 lav_height(vstream) <
000 ) = 576 &&
lav_bit_rate(vstream)
<= 10000000 )
{ {
off += sprintf(m. dlna_pn+off, "SD_"); off += sprintf(m. dlna_pn+off, "SD_");
} }
else if( vc->width <= 19 else if( lav_width(vstrea
20 && m) <= 1920 &&
vc->height <= 11 lav_height(vstre
52 && am) <= 1152 &&
vc->bit_rate <= lav_bit_rate(vst
20000000 ) ream) <= 20000000 )
{ {
off += sprintf(m. dlna_pn+off, "HD_"); off += sprintf(m. dlna_pn+off, "HD_");
} }
else else
{ {
DPRINTF(E_DEBUG, DPRINTF(E_DEBUG,
L_METADATA, "Unsupported h.264 video profile! [%s, %dx%d, %dbps : %s]\n", L_METADATA, "Unsupported h.264 video profile! [%s, %dx%d, %lldbps : %s]\n",
m.dlna_pn m.dlna_pn
, vc->width, vc->height, vc->bit_rate, basepath); , lav_width(vstream), lav_height(vstream),
(long lon
g)lav_bit_rate(vstream), basepath);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
} }
break; break;
case FF_PROFILE_H264_HIGH: case FF_PROFILE_H264_HIGH:
off += sprintf(m.dlna_pn+ off, "HP_"); off += sprintf(m.dlna_pn+ off, "HP_");
if( vc->width <= 1920 && if( lav_width(vstream) <
vc->height <= 1152 && = 1920 &&
vc->bit_rate <= 30000 lav_height(vstream) <
000 && = 1152 &&
lav_bit_rate(vstream)
<= 30000000 &&
audio_profile == PROF ILE_AUDIO_AC3 ) audio_profile == PROF ILE_AUDIO_AC3 )
{ {
off += sprintf(m. dlna_pn+off, "HD_"); off += sprintf(m. dlna_pn+off, "HD_");
} }
else else
{ {
DPRINTF(E_DEBUG, DPRINTF(E_DEBUG,
L_METADATA, "Unsupported h.264 HP video profile! [%dbps, %d audio : %s]\n", L_METADATA, "Unsupported h.264 HP video profile! [%lldbps, %d audio : %s]\n",
vc->bit_r (long lon
ate, audio_profile, basepath); g)lav_bit_rate(vstream), audio_profile, basepath);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
} }
break; break;
case FF_PROFILE_SKIP: case FF_PROFILE_SKIP:
break; break;
} }
if( !m.dlna_pn ) if( !m.dlna_pn )
break; break;
switch( audio_profile ) switch( audio_profile )
skipping to change at line 1079 skipping to change at line 1077
DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for %s file [%s]\n", DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for %s file [%s]\n",
m.dlna_pn, basepa th); m.dlna_pn, basepa th);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
break; break;
} }
if( !m.dlna_pn ) if( !m.dlna_pn )
break; break;
if( raw_packet_size == MPEG_TS_PACKET_LEN GTH_DLNA ) if( raw_packet_size == MPEG_TS_PACKET_LEN GTH_DLNA )
{ {
if( vc->profile == FF_PROFILE_H26 4_HIGH || if( lav_profile(vstream) == FF_PR OFILE_H264_HIGH ||
dlna_ts_present ) dlna_ts_present )
ts_timestamp = VALID; ts_timestamp = VALID;
else else
ts_timestamp = EMPTY; ts_timestamp = EMPTY;
} }
else if( raw_packet_size != MPEG_TS_PACKE T_LENGTH ) else if( raw_packet_size != MPEG_TS_PACKE T_LENGTH )
{ {
DPRINTF(E_DEBUG, L_METADATA, "Uns upported DLNA TS packet size [%d] (%s)\n", DPRINTF(E_DEBUG, L_METADATA, "Uns upported DLNA TS packet size [%d] (%s)\n",
raw_packet_size, basepath ); raw_packet_size, basepath );
free(m.dlna_pn); free(m.dlna_pn);
skipping to change at line 1110 skipping to change at line 1108
case EMPTY: case EMPTY:
xasprintf(&m.mime, "video /vnd.dlna.mpeg-tts"); xasprintf(&m.mime, "video /vnd.dlna.mpeg-tts");
default: default:
break; break;
} }
} }
else if( strcmp(ctx->iformat->name, "mov,mp4,m4a, 3gp,3g2,mj2") == 0 ) else if( strcmp(ctx->iformat->name, "mov,mp4,m4a, 3gp,3g2,mj2") == 0 )
{ {
off += sprintf(m.dlna_pn+off, "MP4_"); off += sprintf(m.dlna_pn+off, "MP4_");
switch( vc->profile ) { switch( lav_profile(vstream) ) {
case FF_PROFILE_H264_BASELINE: case FF_PROFILE_H264_BASELINE:
case FF_PROFILE_H264_CONSTRAINED_BASELINE : case FF_PROFILE_H264_CONSTRAINED_BASELINE :
if( vc->width <= 352 && if( lav_width(vstream) <= 352 &&
vc->height <= 288 ) lav_height(vstream) <= 288 )
{ {
if( ctx->bit_rate < 60000 0 ) if( ctx->bit_rate < 60000 0 )
off += sprintf(m. dlna_pn+off, "BL_CIF15_"); off += sprintf(m. dlna_pn+off, "BL_CIF15_");
else if( ctx->bit_rate < 5000000 ) else if( ctx->bit_rate < 5000000 )
off += sprintf(m. dlna_pn+off, "BL_CIF30_"); off += sprintf(m. dlna_pn+off, "BL_CIF30_");
else else
goto mp4_mp_fallb ack; goto mp4_mp_fallb ack;
if( audio_profile == PROF ILE_AUDIO_AMR ) if( audio_profile == PROF ILE_AUDIO_AMR )
{ {
skipping to change at line 1150 skipping to change at line 1148
off -= 13 ; off -= 13 ;
goto mp4_ mp_fallback; goto mp4_ mp_fallback;
} }
} }
else else
{ {
off -= 9; off -= 9;
goto mp4_mp_fallb ack; goto mp4_mp_fallb ack;
} }
} }
else if( vc->width <= 720 && else if( lav_width(vstream) <= 7
vc->height <= 576 ) 20 &&
lav_height(vstream) <= 5
76 )
{ {
if( vc->level == 30 && if( lav_level(vstream) == 30 &&
audio_profile == PROF ILE_AUDIO_AAC && audio_profile == PROF ILE_AUDIO_AAC &&
ctx->bit_rate <= 5000 000 ) ctx->bit_rate <= 5000 000 )
off += sprintf(m. dlna_pn+off, "BL_L3L_SD_AAC"); off += sprintf(m. dlna_pn+off, "BL_L3L_SD_AAC");
else if( vc->level <= 31 && else if( lav_level(vstrea m) <= 31 &&
audio_profile == PROFILE_AUDIO_AAC && audio_profile == PROFILE_AUDIO_AAC &&
ctx->bit_rate <= 15000000 ) ctx->bit_rate <= 15000000 )
off += sprintf(m. dlna_pn+off, "BL_L31_HD_AAC"); off += sprintf(m. dlna_pn+off, "BL_L31_HD_AAC");
else else
goto mp4_mp_fallb ack; goto mp4_mp_fallb ack;
} }
else if( vc->width <= 1280 && else if( lav_width(vstream) <= 1
vc->height <= 720 ) 280 &&
lav_height(vstream) <= 7
20 )
{ {
if( vc->level <= 31 && if( lav_level(vstream) <= 31 &&
audio_profile == PROF ILE_AUDIO_AAC && audio_profile == PROF ILE_AUDIO_AAC &&
ctx->bit_rate <= 1500 0000 ) ctx->bit_rate <= 1500 0000 )
off += sprintf(m. dlna_pn+off, "BL_L31_HD_AAC"); off += sprintf(m. dlna_pn+off, "BL_L31_HD_AAC");
else if( vc->level <= 32 && else if( lav_level(vstrea m) <= 32 &&
audio_profile == PROFILE_AUDIO_AAC && audio_profile == PROFILE_AUDIO_AAC &&
ctx->bit_rate <= 21000000 ) ctx->bit_rate <= 21000000 )
off += sprintf(m. dlna_pn+off, "BL_L32_HD_AAC"); off += sprintf(m. dlna_pn+off, "BL_L32_HD_AAC");
else else
goto mp4_mp_fallb ack; goto mp4_mp_fallb ack;
} }
else else
goto mp4_mp_fallback; goto mp4_mp_fallback;
break; break;
case FF_PROFILE_H264_MAIN: case FF_PROFILE_H264_MAIN:
mp4_mp_fallback: mp4_mp_fallback:
off += sprintf(m.dlna_pn+off, "MP _"); off += sprintf(m.dlna_pn+off, "MP _");
/* AVC MP4 SD profiles - 10 Mbps max */ /* AVC MP4 SD profiles - 10 Mbps max */
if( vc->width <= 720 && if( lav_width(vstream) <= 720 &&
vc->height <= 576 && lav_height(vstream) <= 576 &&
vc->bit_rate <= 10000000 ) lav_bit_rate(vstream) <= 1000
0000 )
{ {
sprintf(m.dlna_pn+off, "S D_"); sprintf(m.dlna_pn+off, "S D_");
if( audio_profile == PROF ILE_AUDIO_AC3 ) if( audio_profile == PROF ILE_AUDIO_AC3 )
off += sprintf(m. dlna_pn+off, "AC3"); off += sprintf(m. dlna_pn+off, "AC3");
else if( audio_profile == PROFILE_AUDIO_AAC || else if( audio_profile == PROFILE_AUDIO_AAC ||
audio_profile == PROFILE_AUDIO_AAC_MULT5 ) audio_profile == PROFILE_AUDIO_AAC_MULT5 )
off += sprintf(m. dlna_pn+off, "AAC_MULT5"); off += sprintf(m. dlna_pn+off, "AAC_MULT5");
else if( audio_profile == PROFILE_AUDIO_MP3 ) else if( audio_profile == PROFILE_AUDIO_MP3 )
off += sprintf(m. dlna_pn+off, "MPEG1_L3"); off += sprintf(m. dlna_pn+off, "MPEG1_L3");
else else
m.dlna_pn[10] = ' \0'; m.dlna_pn[10] = ' \0';
} }
else if( vc->width <= 1280 && else if( lav_width(vstream) <= 1
vc->height <= 720 && 280 &&
vc->bit_rate <= 15000000 lav_height(vstream) <= 7
&& 20 &&
lav_bit_rate(vstream) <=
15000000 &&
audio_profile == PROFILE _AUDIO_AAC ) audio_profile == PROFILE _AUDIO_AAC )
{ {
off += sprintf(m.dlna_pn+ off, "HD_720p_AAC"); off += sprintf(m.dlna_pn+ off, "HD_720p_AAC");
} }
else if( vc->width <= 1920 && else if( lav_width(vstream) <= 1
vc->height <= 1080 && 920 &&
vc->bit_rate <= 21000000 lav_height(vstream) <= 1
&& 080 &&
lav_bit_rate(vstream) <=
21000000 &&
audio_profile == PROFILE _AUDIO_AAC ) audio_profile == PROFILE _AUDIO_AAC )
{ {
off += sprintf(m.dlna_pn+ off, "HD_1080i_AAC"); off += sprintf(m.dlna_pn+ off, "HD_1080i_AAC");
} }
if( strlen(m.dlna_pn) <= 11 ) if( strlen(m.dlna_pn) <= 11 )
{ {
DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for %s file %s\n", DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for %s file %s\n",
m.dlna_pn, basepa th); m.dlna_pn, basepa th);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
} }
break; break;
case FF_PROFILE_H264_HIGH: case FF_PROFILE_H264_HIGH:
if( vc->width <= 1920 && if( lav_width(vstream) <= 1920 &
vc->height <= 1080 && &
vc->bit_rate <= 25000000 && lav_height(vstream) <= 1080 &
&
lav_bit_rate(vstream) <= 2500
0000 &&
audio_profile == PROFILE_AUDI O_AAC ) audio_profile == PROFILE_AUDI O_AAC )
{ {
off += sprintf(m.dlna_pn+ off, "HP_HD_AAC"); off += sprintf(m.dlna_pn+ off, "HP_HD_AAC");
} }
break; break;
default: default:
DPRINTF(E_DEBUG, L_METADATA, "AVC profile [%d] not recognized for file %s\n", DPRINTF(E_DEBUG, L_METADATA, "AVC profile [%d] not recognized for file %s\n",
vc->profile, basepath); lav_profile(vstream), bas epath);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
break; break;
} }
} }
else else
{ {
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
} }
DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is h.264\n", video_stream, basepath); DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is h.264\n", video_stream, basepath);
break; break;
case AV_CODEC_ID_MPEG4: case AV_CODEC_ID_MPEG4:
fourcc[0] = vc->codec_tag & 0xff; fourcc[0] = lav_codec_tag(vstream) & 0xff;
fourcc[1] = vc->codec_tag>>8 & 0xff; fourcc[1] = lav_codec_tag(vstream)>>8 & 0xff;
fourcc[2] = vc->codec_tag>>16 & 0xff; fourcc[2] = lav_codec_tag(vstream)>>16 & 0xff;
fourcc[3] = vc->codec_tag>>24 & 0xff; fourcc[3] = lav_codec_tag(vstream)>>24 & 0xff;
DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is MPEG4 [%c%c%c%c/0x%X]\n", DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is MPEG4 [%c%c%c%c/0x%X]\n",
video_stream, basepath, video_stream, basepath,
isprint(fourcc[0]) ? fourcc[0] : '_', isprint(fourcc[0]) ? fourcc[0] : '_',
isprint(fourcc[1]) ? fourcc[1] : '_', isprint(fourcc[1]) ? fourcc[1] : '_',
isprint(fourcc[2]) ? fourcc[2] : '_', isprint(fourcc[2]) ? fourcc[2] : '_',
isprint(fourcc[3]) ? fourcc[3] : '_', isprint(fourcc[3]) ? fourcc[3] : '_',
vc->codec_tag); lav_codec_tag(vstream));
if( strcmp(ctx->iformat->name, "mov,mp4,m4a,3gp,3 g2,mj2") == 0 ) if( strcmp(ctx->iformat->name, "mov,mp4,m4a,3gp,3 g2,mj2") == 0 )
{ {
m.dlna_pn = malloc(128); m.dlna_pn = malloc(128);
off = sprintf(m.dlna_pn, "MPEG4_P2_"); off = sprintf(m.dlna_pn, "MPEG4_P2_");
if( ends_with(path, ".3gp") ) if( ends_with(path, ".3gp") )
{ {
xasprintf(&m.mime, "video/3gpp"); xasprintf(&m.mime, "video/3gpp");
switch( audio_profile ) switch( audio_profile )
{ {
case PROFILE_AUDIO_AAC: case PROFILE_AUDIO_AAC:
off += sprintf(m. dlna_pn+off, "3GPP_SP_L0B_AAC"); off += sprintf(m. dlna_pn+off, "3GPP_SP_L0B_AAC");
break; break;
case PROFILE_AUDIO_AMR: case PROFILE_AUDIO_AMR:
off += sprintf(m. dlna_pn+off, "3GPP_SP_L0B_AMR"); off += sprintf(m. dlna_pn+off, "3GPP_SP_L0B_AMR");
break; break;
default: default:
DPRINTF(E_DEBUG, DPRINTF(E_DEBUG,
L_METADATA, "No DLNA profile found for MPEG4-P2 3GP/0x%X file %s\n", L_METADATA, "No DLNA profile found for MPEG4-P2 3GP/%d file %s\n",
ac->codec audio_pro
_id, basepath); file, basepath);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
break; break;
} }
} }
else else
{ {
if( ctx->bit_rate <= 1000000 && if( ctx->bit_rate <= 1000000 &&
audio_profile == PROFILE_AUDI O_AAC ) audio_profile == PROFILE_AUDI O_AAC )
{ {
off += sprintf(m.dlna_pn+ off, "MP4_ASP_AAC"); off += sprintf(m.dlna_pn+ off, "MP4_ASP_AAC");
} }
else if( ctx->bit_rate <= 4000000 && else if( ctx->bit_rate <= 4000000 &&
vc->width <= 640 && lav_width(vstream) <= 6
vc->height <= 480 && 40 &&
lav_height(vstream) <= 4
80 &&
audio_profile == PROFILE _AUDIO_AAC ) audio_profile == PROFILE _AUDIO_AAC )
{ {
off += sprintf(m.dlna_pn+ off, "MP4_SP_VGA_AAC"); off += sprintf(m.dlna_pn+ off, "MP4_SP_VGA_AAC");
} }
else else
{ {
DPRINTF(E_DEBUG, L_METADA DPRINTF(E_DEBUG, L_METADA
TA, "Unsupported h.264 video profile! [%dx%d, %dbps]\n", TA, "Unsupported h.264 video profile! [%dx%d, %lldbps]\n",
vc->width, lav_width(vstream
vc->height, ),
ctx->bit_rate); lav_height(vstrea
m),
(long long)ctx->b
it_rate);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
} }
} }
} }
break; break;
case AV_CODEC_ID_WMV3: case AV_CODEC_ID_WMV3:
/* I'm not 100% sure this is correct, but it work s on everything I could get my hands on */ /* I'm not 100% sure this is correct, but it work s on everything I could get my hands on */
if( vc->extradata_size > 0 ) if( lav_codec_extradata(vstream) )
{ {
if( !((vc->extradata[0] >> 3) & 1) ) if( !((lav_codec_extradata(vstream)[0] >>
vc->level = 0; 3) & 1) )
if( !((vc->extradata[0] >> 6) & 1) ) lav_level(vstream) = 0;
vc->profile = 0; if( !((lav_codec_extradata(vstream)[0] >>
6) & 1) )
lav_profile(vstream) = 0;
} }
case AV_CODEC_ID_VC1: case AV_CODEC_ID_VC1:
if( strcmp(ctx->iformat->name, "asf") != 0 ) if( strcmp(ctx->iformat->name, "asf") != 0 )
{ {
DPRINTF(E_DEBUG, L_METADATA, "Skipping DL NA parsing for non-ASF VC1 file %s\n", path); DPRINTF(E_DEBUG, L_METADATA, "Skipping DL NA parsing for non-ASF VC1 file %s\n", path);
break; break;
} }
m.dlna_pn = malloc(64); m.dlna_pn = malloc(64);
off = sprintf(m.dlna_pn, "WMV"); off = sprintf(m.dlna_pn, "WMV");
DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is VC1\n", video_stream, basepath); DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is VC1\n", video_stream, basepath);
xasprintf(&m.mime, "video/x-ms-wmv"); xasprintf(&m.mime, "video/x-ms-wmv");
if( (vc->width <= 176) && if( (lav_width(vstream) <= 176) &&
(vc->height <= 144) && (lav_height(vstream) <= 144) &&
(vc->level == 0) ) (lav_level(vstream) == 0) )
{ {
off += sprintf(m.dlna_pn+off, "SPLL_"); off += sprintf(m.dlna_pn+off, "SPLL_");
switch( audio_profile ) switch( audio_profile )
{ {
case PROFILE_AUDIO_MP3: case PROFILE_AUDIO_MP3:
off += sprintf(m.dlna_pn+ off, "MP3"); off += sprintf(m.dlna_pn+ off, "MP3");
break; break;
case PROFILE_AUDIO_WMA_BASE: case PROFILE_AUDIO_WMA_BASE:
off += sprintf(m.dlna_pn+ off, "BASE"); off += sprintf(m.dlna_pn+ off, "BASE");
break; break;
default: default:
DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for WMVSPLL/0x%X file %s\n", DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for WMVSPLL/0x%X file %s\n",
audio_profile, ba sepath); audio_profile, ba sepath);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
break; break;
} }
} }
else if( (vc->width <= 352) && else if( (lav_width(vstream) <= 352) &&
(vc->height <= 288) && (lav_height(vstream) <= 288) &&
(vc->profile == 0) && (lav_profile(vstream) == 0) &&
(ctx->bit_rate/8 <= 384000) ) (ctx->bit_rate/8 <= 384000) )
{ {
off += sprintf(m.dlna_pn+off, "SPML_"); off += sprintf(m.dlna_pn+off, "SPML_");
switch( audio_profile ) switch( audio_profile )
{ {
case PROFILE_AUDIO_MP3: case PROFILE_AUDIO_MP3:
off += sprintf(m.dlna_pn+ off, "MP3"); off += sprintf(m.dlna_pn+ off, "MP3");
break; break;
case PROFILE_AUDIO_WMA_BASE: case PROFILE_AUDIO_WMA_BASE:
off += sprintf(m.dlna_pn+ off, "BASE"); off += sprintf(m.dlna_pn+ off, "BASE");
break; break;
default: default:
DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for WMVSPML/0x%X file %s\n", DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for WMVSPML/0x%X file %s\n",
audio_profile, ba sepath); audio_profile, ba sepath);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
break; break;
} }
} }
else if( (vc->width <= 720) && else if( (lav_width(vstream) <= 720) &&
(vc->height <= 576) && (lav_height(vstream) <= 576) &&
(ctx->bit_rate/8 <= 10000000) ) (ctx->bit_rate/8 <= 10000000) )
{ {
off += sprintf(m.dlna_pn+off, "MED_"); off += sprintf(m.dlna_pn+off, "MED_");
switch( audio_profile ) switch( audio_profile )
{ {
case PROFILE_AUDIO_WMA_PRO: case PROFILE_AUDIO_WMA_PRO:
off += sprintf(m.dlna_pn+ off, "PRO"); off += sprintf(m.dlna_pn+ off, "PRO");
break; break;
case PROFILE_AUDIO_WMA_FULL: case PROFILE_AUDIO_WMA_FULL:
off += sprintf(m.dlna_pn+ off, "FULL"); off += sprintf(m.dlna_pn+ off, "FULL");
skipping to change at line 1395 skipping to change at line 1393
off += sprintf(m.dlna_pn+ off, "BASE"); off += sprintf(m.dlna_pn+ off, "BASE");
break; break;
default: default:
DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for WMVMED/0x%X file %s\n", DPRINTF(E_DEBUG, L_METADA TA, "No DLNA profile found for WMVMED/0x%X file %s\n",
audio_profile, ba sepath); audio_profile, ba sepath);
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
break; break;
} }
} }
else if( (vc->width <= 1920) && else if( (lav_width(vstream) <= 1920) &&
(vc->height <= 1080) && (lav_height(vstream) <= 1080) &&
(ctx->bit_rate/8 <= 20000000) ) (ctx->bit_rate/8 <= 20000000) )
{ {
off += sprintf(m.dlna_pn+off, "HIGH_"); off += sprintf(m.dlna_pn+off, "HIGH_");
switch( audio_profile ) switch( audio_profile )
{ {
case PROFILE_AUDIO_WMA_PRO: case PROFILE_AUDIO_WMA_PRO:
off += sprintf(m.dlna_pn+ off, "PRO"); off += sprintf(m.dlna_pn+ off, "PRO");
break; break;
case PROFILE_AUDIO_WMA_FULL: case PROFILE_AUDIO_WMA_FULL:
off += sprintf(m.dlna_pn+ off, "FULL"); off += sprintf(m.dlna_pn+ off, "FULL");
skipping to change at line 1421 skipping to change at line 1419
free(m.dlna_pn); free(m.dlna_pn);
m.dlna_pn = NULL; m.dlna_pn = NULL;
break; break;
} }
} }
break; break;
case AV_CODEC_ID_MSMPEG4V3: case AV_CODEC_ID_MSMPEG4V3:
xasprintf(&m.mime, "video/x-msvideo"); xasprintf(&m.mime, "video/x-msvideo");
default: default:
DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is %s [type %d]\n", DPRINTF(E_DEBUG, L_METADATA, "Stream %d of %s is %s [type %d]\n",
video_stream, basepath, m.resolution, vc- >codec_id); video_stream, basepath, m.resolution, lav _codec_id(vstream));
break; break;
} }
} }
if( strcmp(ctx->iformat->name, "asf") == 0 ) if( strcmp(ctx->iformat->name, "asf") == 0 )
{ {
if( readtags((char *)path, &video, &file, "en_US", "asf") == 0 ) if( readtags((char *)path, &video, &file, "en_US", "asf") == 0 )
{ {
if( video.title && *video.title ) if( video.title && *video.title )
{ {
skipping to change at line 1551 skipping to change at line 1549
freetags(&video); freetags(&video);
lav_close(ctx); lav_close(ctx);
ret = sql_exec(db, "INSERT into DETAILS" ret = sql_exec(db, "INSERT into DETAILS"
" (PATH, SIZE, TIMESTAMP, DURATION, DATE, CHANNELS, BI TRATE, SAMPLERATE, RESOLUTION," " (PATH, SIZE, TIMESTAMP, DURATION, DATE, CHANNELS, BI TRATE, SAMPLERATE, RESOLUTION,"
" TITLE, CREATOR, ARTIST, GENRE, COMMENT, DLNA_PN, MI ME, ALBUM_ART) " " TITLE, CREATOR, ARTIST, GENRE, COMMENT, DLNA_PN, MI ME, ALBUM_ART) "
"VALUES" "VALUES"
" (%Q, %lld, %lld, %Q, %Q, %u, %u, %u, %Q, '%q', %Q, % Q, %Q, %Q, %Q, '%q', %lld);", " (%Q, %lld, %lld, %Q, %Q, %u, %u, %u, %Q, '%q', %Q, % Q, %Q, %Q, %Q, '%q', %lld);",
path, (long long)file.st_size, (long long)file.st_mtim e, m.duration, path, (long long)file.st_size, (long long)file.st_mtim e, m.duration,
m.date, m.channels, m.bitrate, m.frequency, m.resoluti on, m.date, m.channels, m.bitrate, m.frequency, m.resoluti on,
m.title, m.creator, m.artist, m.genre, m.comment, m.dl m.title, m.creator, m.artist, m.genre, m.comment, m.dl
na_pn, na_pn,
m.mime, album_art); m.mime, album_art);
if( ret != SQLITE_OK ) if( ret != SQLITE_OK )
{ {
DPRINTF(E_ERROR, L_METADATA, "Error inserting details for '%s'!\n ", path); DPRINTF(E_ERROR, L_METADATA, "Error inserting details for '%s'!\n ", path);
ret = 0; ret = 0;
} }
else else
{ {
ret = sqlite3_last_insert_rowid(db); ret = sqlite3_last_insert_rowid(db);
check_for_captions(path, ret); check_for_captions(path, ret);
} }
 End of changes. 101 change blocks. 
210 lines changed or deleted 242 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS