@ -1,4 +1,5 @@
using MediaBrowser.Common.Net ;
using System.IO ;
using MediaBrowser.Common.Net ;
using MediaBrowser.Controller.Channels ;
using MediaBrowser.Controller.Channels ;
using MediaBrowser.Controller.Drawing ;
using MediaBrowser.Controller.Drawing ;
using MediaBrowser.Controller.Entities ;
using MediaBrowser.Controller.Entities ;
@ -13,6 +14,7 @@ using System.Collections.Generic;
using System.Globalization ;
using System.Globalization ;
using System.Linq ;
using System.Linq ;
using System.Xml ;
using System.Xml ;
using MediaBrowser.Common.Extensions ;
namespace MediaBrowser.Dlna.Didl
namespace MediaBrowser.Dlna.Didl
{
{
@ -101,7 +103,7 @@ namespace MediaBrowser.Dlna.Didl
{
{
var sources = _user = = null ? video . GetMediaSources ( true ) . ToList ( ) : video . GetMediaSources ( true , _user ) . ToList ( ) ;
var sources = _user = = null ? video . GetMediaSources ( true ) . ToList ( ) : video . GetMediaSources ( true , _user ) . ToList ( ) ;
streamInfo = new StreamBuilder ( ) . BuildVideoItem ( new VideoOptions
streamInfo = new StreamBuilder ( ) . BuildVideoItem ( new VideoOptions
{
{
ItemId = video . Id . ToString ( "N" ) ,
ItemId = video . Id . ToString ( "N" ) ,
MediaSources = sources ,
MediaSources = sources ,
@ -137,6 +139,23 @@ namespace MediaBrowser.Dlna.Didl
{
{
AddVideoResource ( container , video , deviceId , filter , contentFeature , streamInfo ) ;
AddVideoResource ( container , video , deviceId , filter , contentFeature , streamInfo ) ;
}
}
foreach ( var subtitle in streamInfo . GetExternalSubtitles ( _serverAddress ) )
{
AddSubtitleElement ( container , subtitle ) ;
}
}
private void AddSubtitleElement ( XmlElement container , SubtitleStreamInfo info )
{
var res = container . OwnerDocument . CreateElement ( string . Empty , "res" , NS_DIDL ) ;
res . InnerText = info . Url ;
// TODO: Remove this hard-coding
res . SetAttribute ( "protocolInfo" , "http-get:*:text/srt:*" ) ;
container . AppendChild ( res ) ;
}
}
private void AddVideoResource ( XmlElement container , Video video , string deviceId , Filter filter , string contentFeatures , StreamInfo streamInfo )
private void AddVideoResource ( XmlElement container , Video video , string deviceId , Filter filter , string contentFeatures , StreamInfo streamInfo )
@ -598,9 +617,11 @@ namespace MediaBrowser.Dlna.Didl
}
}
AddImageResElement ( item , element , 4096 , 4096 , "jpg" ) ;
AddImageResElement ( item , element , 4096 , 4096 , "jpg" ) ;
AddImageResElement ( item , element , 4096 , 4096 , "png" ) ;
AddImageResElement ( item , element , 1024 , 768 , "jpg" ) ;
AddImageResElement ( item , element , 1024 , 768 , "jpg" ) ;
AddImageResElement ( item , element , 640 , 480 , "jpg" ) ;
AddImageResElement ( item , element , 640 , 480 , "jpg" ) ;
AddImageResElement ( item , element , 160 , 160 , "jpg" ) ;
AddImageResElement ( item , element , 160 , 160 , "jpg" ) ;
AddImageResElement ( item , element , 160 , 160 , "png" ) ;
}
}
private void AddImageResElement ( BaseItem item , XmlElement element , int maxWidth , int maxHeight , string format )
private void AddImageResElement ( BaseItem item , XmlElement element , int maxWidth , int maxHeight , string format )
@ -623,7 +644,7 @@ namespace MediaBrowser.Dlna.Didl
var width = albumartUrlInfo . Width ;
var width = albumartUrlInfo . Width ;
var height = albumartUrlInfo . Height ;
var height = albumartUrlInfo . Height ;
var contentFeatures = new ContentFeatureBuilder ( _profile ) . BuildImageHeader ( format , width , height );
var contentFeatures = new ContentFeatureBuilder ( _profile ) . BuildImageHeader ( format , width , height , imageInfo . IsDirectStream );
res . SetAttribute ( "protocolInfo" , String . Format (
res . SetAttribute ( "protocolInfo" , String . Format (
"http-get:*:{0}:{1}" ,
"http-get:*:{0}:{1}" ,
@ -631,6 +652,14 @@ namespace MediaBrowser.Dlna.Didl
contentFeatures
contentFeatures
) ) ;
) ) ;
res . SetAttribute ( "colorDepth" , "24" ) ;
if ( imageInfo . IsDirectStream )
{
// TODO: Add file size
//res.SetAttribute("size", imageInfo.Size.Value.ToString(_usCulture));
}
if ( width . HasValue & & height . HasValue )
if ( width . HasValue & & height . HasValue )
{
{
res . SetAttribute ( "resolution" , string . Format ( "{0}x{1}" , width . Value , height . Value ) ) ;
res . SetAttribute ( "resolution" , string . Format ( "{0}x{1}" , width . Value , height . Value ) ) ;
@ -705,7 +734,8 @@ namespace MediaBrowser.Dlna.Didl
Type = type ,
Type = type ,
ImageTag = tag ,
ImageTag = tag ,
Width = width ,
Width = width ,
Height = height
Height = height ,
File = imageInfo . Path
} ;
} ;
}
}
@ -717,6 +747,10 @@ namespace MediaBrowser.Dlna.Didl
internal int? Width ;
internal int? Width ;
internal int? Height ;
internal int? Height ;
internal bool IsDirectStream ;
internal string File ;
}
}
class ImageUrlInfo
class ImageUrlInfo
@ -741,6 +775,8 @@ namespace MediaBrowser.Dlna.Didl
var width = info . Width ;
var width = info . Width ;
var height = info . Height ;
var height = info . Height ;
info . IsDirectStream = false ;
if ( width . HasValue & & height . HasValue )
if ( width . HasValue & & height . HasValue )
{
{
var newSize = DrawingUtils . Resize ( new ImageSize
var newSize = DrawingUtils . Resize ( new ImageSize
@ -752,6 +788,18 @@ namespace MediaBrowser.Dlna.Didl
width = Convert . ToInt32 ( newSize . Width ) ;
width = Convert . ToInt32 ( newSize . Width ) ;
height = Convert . ToInt32 ( newSize . Height ) ;
height = Convert . ToInt32 ( newSize . Height ) ;
var inputFormat = ( Path . GetExtension ( info . File ) ? ? string . Empty )
. TrimStart ( '.' )
. Replace ( "jpeg" , "jpg" , StringComparison . OrdinalIgnoreCase ) ;
var normalizedFormat = format
. Replace ( "jpeg" , "jpg" , StringComparison . OrdinalIgnoreCase ) ;
if ( string . Equals ( inputFormat , normalizedFormat , StringComparison . OrdinalIgnoreCase ) )
{
info . IsDirectStream = maxWidth > = width . Value & & maxHeight > = height . Value ;
}
}
}
return new ImageUrlInfo
return new ImageUrlInfo