Browse Source

support file playback with StreamBuilder

Luke Pulverenti 10 years ago
parent
commit
ceb88b1359

+ 6 - 0
MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj

@@ -356,12 +356,18 @@
     <Compile Include="..\MediaBrowser.Model\Dlna\HttpHeaderInfo.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\HttpHeaderInfo.cs">
       <Link>Dlna\HttpHeaderInfo.cs</Link>
       <Link>Dlna\HttpHeaderInfo.cs</Link>
     </Compile>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\Dlna\ILocalPlayer.cs">
+      <Link>Dlna\ILocalPlayer.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfile.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfile.cs">
       <Link>Dlna\MediaFormatProfile.cs</Link>
       <Link>Dlna\MediaFormatProfile.cs</Link>
     </Compile>
     </Compile>
     <Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfileResolver.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfileResolver.cs">
       <Link>Dlna\MediaFormatProfileResolver.cs</Link>
       <Link>Dlna\MediaFormatProfileResolver.cs</Link>
     </Compile>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\Dlna\NullLocalPlayer.cs">
+      <Link>Dlna\NullLocalPlayer.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Dlna\PlaybackErrorCode.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\PlaybackErrorCode.cs">
       <Link>Dlna\PlaybackErrorCode.cs</Link>
       <Link>Dlna\PlaybackErrorCode.cs</Link>
     </Compile>
     </Compile>

+ 9 - 0
MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj

@@ -288,6 +288,9 @@
     <Compile Include="..\MediaBrowser.Model\Dlna\ContentFeatureBuilder.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\ContentFeatureBuilder.cs">
       <Link>Dlna\ContentFeatureBuilder.cs</Link>
       <Link>Dlna\ContentFeatureBuilder.cs</Link>
     </Compile>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\Dlna\DefaultLocalPlayer.cs">
+      <Link>Dlna\DefaultLocalPlayer.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Dlna\DeviceIdentification.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\DeviceIdentification.cs">
       <Link>Dlna\DeviceIdentification.cs</Link>
       <Link>Dlna\DeviceIdentification.cs</Link>
     </Compile>
     </Compile>
@@ -321,12 +324,18 @@
     <Compile Include="..\MediaBrowser.Model\Dlna\HttpHeaderInfo.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\HttpHeaderInfo.cs">
       <Link>Dlna\HttpHeaderInfo.cs</Link>
       <Link>Dlna\HttpHeaderInfo.cs</Link>
     </Compile>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\Dlna\ILocalPlayer.cs">
+      <Link>Dlna\ILocalPlayer.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfile.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfile.cs">
       <Link>Dlna\MediaFormatProfile.cs</Link>
       <Link>Dlna\MediaFormatProfile.cs</Link>
     </Compile>
     </Compile>
     <Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfileResolver.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\MediaFormatProfileResolver.cs">
       <Link>Dlna\MediaFormatProfileResolver.cs</Link>
       <Link>Dlna\MediaFormatProfileResolver.cs</Link>
     </Compile>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\Dlna\NullLocalPlayer.cs">
+      <Link>Dlna\NullLocalPlayer.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Dlna\PlaybackErrorCode.cs">
     <Compile Include="..\MediaBrowser.Model\Dlna\PlaybackErrorCode.cs">
       <Link>Dlna\PlaybackErrorCode.cs</Link>
       <Link>Dlna\PlaybackErrorCode.cs</Link>
     </Compile>
     </Compile>

+ 0 - 11
MediaBrowser.Model/Dlna/AudioOptions.cs

@@ -46,17 +46,6 @@ namespace MediaBrowser.Model.Dlna
         /// </summary>
         /// </summary>
         /// <value>The audio transcoding bitrate.</value>
         /// <value>The audio transcoding bitrate.</value>
         public int? AudioTranscodingBitrate { get; set; }
         public int? AudioTranscodingBitrate { get; set; }
-
-        /// <summary>
-        /// Gets or sets a value indicating whether [supports direct remote content].
-        /// </summary>
-        /// <value><c>true</c> if [supports direct remote content]; otherwise, <c>false</c>.</value>
-        public bool SupportsDirectRemoteContent { get; set; }
-        /// <summary>
-        /// Gets or sets a value indicating whether [supports custom HTTP headers].
-        /// </summary>
-        /// <value><c>true</c> if [supports custom HTTP headers]; otherwise, <c>false</c>.</value>
-        public bool SupportsCustomHttpHeaders { get; set; }
         
         
         /// <summary>
         /// <summary>
         /// Gets the maximum bitrate.
         /// Gets the maximum bitrate.

+ 22 - 0
MediaBrowser.Model/Dlna/DefaultLocalPlayer.cs

@@ -0,0 +1,22 @@
+using System.IO;
+
+namespace MediaBrowser.Model.Dlna
+{
+    public class DefaultLocalPlayer : ILocalPlayer
+    {
+        public bool CanAccessFile(string path)
+        {
+            return File.Exists(path);
+        }
+
+        public bool CanAccessDirectory(string path)
+        {
+            return Directory.Exists(path);
+        }
+
+        public virtual bool CanAccessUrl(string url, bool requiresCustomRequestHeaders)
+        {
+            return false;
+        }
+    }
+}

+ 26 - 0
MediaBrowser.Model/Dlna/ILocalPlayer.cs

@@ -0,0 +1,26 @@
+
+namespace MediaBrowser.Model.Dlna
+{
+    public interface ILocalPlayer
+    {
+        /// <summary>
+        /// Determines whether this instance [can access file] the specified path.
+        /// </summary>
+        /// <param name="path">The path.</param>
+        /// <returns><c>true</c> if this instance [can access file] the specified path; otherwise, <c>false</c>.</returns>
+        bool CanAccessFile(string path);
+        /// <summary>
+        /// Determines whether this instance [can access directory] the specified path.
+        /// </summary>
+        /// <param name="path">The path.</param>
+        /// <returns><c>true</c> if this instance [can access directory] the specified path; otherwise, <c>false</c>.</returns>
+        bool CanAccessDirectory(string path);
+        /// <summary>
+        /// Determines whether this instance [can access URL] the specified URL.
+        /// </summary>
+        /// <param name="url">The URL.</param>
+        /// <param name="requiresCustomRequestHeaders">if set to <c>true</c> [requires custom request headers].</param>
+        /// <returns><c>true</c> if this instance [can access URL] the specified URL; otherwise, <c>false</c>.</returns>
+        bool CanAccessUrl(string url, bool requiresCustomRequestHeaders);
+    }
+}

+ 21 - 0
MediaBrowser.Model/Dlna/NullLocalPlayer.cs

@@ -0,0 +1,21 @@
+
+namespace MediaBrowser.Model.Dlna
+{
+    public class NullLocalPlayer : ILocalPlayer
+    {
+        public bool CanAccessFile(string path)
+        {
+            return false;
+        }
+
+        public bool CanAccessDirectory(string path)
+        {
+            return false;
+        }
+
+        public bool CanAccessUrl(string url, bool requiresCustomRequestHeaders)
+        {
+            return false;
+        }
+    }
+}

+ 28 - 10
MediaBrowser.Model/Dlna/StreamBuilder.cs

@@ -10,6 +10,17 @@ namespace MediaBrowser.Model.Dlna
 {
 {
     public class StreamBuilder
     public class StreamBuilder
     {
     {
+        private readonly ILocalPlayer _localPlayer;
+
+        public StreamBuilder(ILocalPlayer localPlayer)
+        {
+            _localPlayer = localPlayer;
+        }
+        public StreamBuilder()
+            : this(new NullLocalPlayer())
+        {
+        }
+
         public StreamInfo BuildAudioItem(AudioOptions options)
         public StreamInfo BuildAudioItem(AudioOptions options)
         {
         {
             ValidateAudioInput(options);
             ValidateAudioInput(options);
@@ -73,7 +84,7 @@ namespace MediaBrowser.Model.Dlna
                 StreamInfo streamInfo = BuildVideoItem(i, options);
                 StreamInfo streamInfo = BuildVideoItem(i, options);
                 if (streamInfo != null)
                 if (streamInfo != null)
                 {
                 {
-                streams.Add(streamInfo);
+                    streams.Add(streamInfo);
                 }
                 }
             }
             }
 
 
@@ -180,7 +191,15 @@ namespace MediaBrowser.Model.Dlna
 
 
                         if (all)
                         if (all)
                         {
                         {
-                            playlistItem.PlayMethod = PlayMethod.DirectStream;
+                            if (item.Protocol == MediaProtocol.File && _localPlayer.CanAccessFile(item.Path))
+                            {
+                                playlistItem.PlayMethod = PlayMethod.DirectPlay;
+                            }
+                            else
+                            {
+                                playlistItem.PlayMethod = PlayMethod.DirectStream;
+                            }
+
                             playlistItem.Container = item.Container;
                             playlistItem.Container = item.Container;
 
 
                             return playlistItem;
                             return playlistItem;
@@ -530,18 +549,17 @@ namespace MediaBrowser.Model.Dlna
 
 
             if (mediaSource.Protocol == MediaProtocol.Http)
             if (mediaSource.Protocol == MediaProtocol.Http)
             {
             {
-                if (!options.SupportsDirectRemoteContent)
+                if (_localPlayer.CanAccessUrl(mediaSource.Path, mediaSource.RequiredHttpHeaders.Count > 0))
                 {
                 {
-                    return null;
+                    return PlayMethod.DirectPlay;
                 }
                 }
+            }
 
 
-                if (mediaSource.RequiredHttpHeaders.Count > 0 && !options.SupportsCustomHttpHeaders)
-                {
-                    return null;
-                }
+            else if (mediaSource.Protocol == MediaProtocol.File && _localPlayer.CanAccessFile(mediaSource.Path))
+            {
                 return PlayMethod.DirectPlay;
                 return PlayMethod.DirectPlay;
             }
             }
-
+            
             return PlayMethod.DirectStream;
             return PlayMethod.DirectStream;
         }
         }
 
 
@@ -574,7 +592,7 @@ namespace MediaBrowser.Model.Dlna
                     {
                     {
                         return profile;
                         return profile;
                     }
                     }
-                    
+
                     // For sync we can handle the longer extraction times
                     // For sync we can handle the longer extraction times
                     if (context == EncodingContext.Static && subtitleStream.IsTextSubtitleStream)
                     if (context == EncodingContext.Static && subtitleStream.IsTextSubtitleStream)
                     {
                     {

+ 3 - 0
MediaBrowser.Model/MediaBrowser.Model.csproj

@@ -124,7 +124,10 @@
     <Compile Include="Devices\LocalFileInfo.cs" />
     <Compile Include="Devices\LocalFileInfo.cs" />
     <Compile Include="Devices\DeviceInfo.cs" />
     <Compile Include="Devices\DeviceInfo.cs" />
     <Compile Include="Devices\DevicesOptions.cs" />
     <Compile Include="Devices\DevicesOptions.cs" />
+    <Compile Include="Dlna\DefaultLocalPlayer.cs" />
     <Compile Include="Dlna\EncodingContext.cs" />
     <Compile Include="Dlna\EncodingContext.cs" />
+    <Compile Include="Dlna\ILocalPlayer.cs" />
+    <Compile Include="Dlna\NullLocalPlayer.cs" />
     <Compile Include="Dlna\PlaybackErrorCode.cs" />
     <Compile Include="Dlna\PlaybackErrorCode.cs" />
     <Compile Include="Dlna\PlaybackException.cs" />
     <Compile Include="Dlna\PlaybackException.cs" />
     <Compile Include="Dlna\Profiles\DefaultProfile.cs" />
     <Compile Include="Dlna\Profiles\DefaultProfile.cs" />

+ 2 - 2
Nuget/MediaBrowser.Common.Internal.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
     <metadata>
     <metadata>
         <id>MediaBrowser.Common.Internal</id>
         <id>MediaBrowser.Common.Internal</id>
-        <version>3.0.582</version>
+        <version>3.0.583</version>
         <title>MediaBrowser.Common.Internal</title>
         <title>MediaBrowser.Common.Internal</title>
         <authors>Luke</authors>
         <authors>Luke</authors>
         <owners>ebr,Luke,scottisafool</owners>
         <owners>ebr,Luke,scottisafool</owners>
@@ -12,7 +12,7 @@
         <description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
         <description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
         <copyright>Copyright © Media Browser 2013</copyright>
         <copyright>Copyright © Media Browser 2013</copyright>
         <dependencies>
         <dependencies>
-            <dependency id="MediaBrowser.Common" version="3.0.582" />
+            <dependency id="MediaBrowser.Common" version="3.0.583" />
             <dependency id="NLog" version="3.2.0.0" />
             <dependency id="NLog" version="3.2.0.0" />
             <dependency id="SimpleInjector" version="2.7.0" />
             <dependency id="SimpleInjector" version="2.7.0" />
         </dependencies>
         </dependencies>

+ 1 - 1
Nuget/MediaBrowser.Common.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
     <metadata>
     <metadata>
         <id>MediaBrowser.Common</id>
         <id>MediaBrowser.Common</id>
-        <version>3.0.582</version>
+        <version>3.0.583</version>
         <title>MediaBrowser.Common</title>
         <title>MediaBrowser.Common</title>
         <authors>Media Browser Team</authors>
         <authors>Media Browser Team</authors>
         <owners>ebr,Luke,scottisafool</owners>
         <owners>ebr,Luke,scottisafool</owners>

+ 1 - 1
Nuget/MediaBrowser.Model.Signed.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
     <metadata>
     <metadata>
         <id>MediaBrowser.Model.Signed</id>
         <id>MediaBrowser.Model.Signed</id>
-        <version>3.0.582</version>
+        <version>3.0.583</version>
         <title>MediaBrowser.Model - Signed Edition</title>
         <title>MediaBrowser.Model - Signed Edition</title>
         <authors>Media Browser Team</authors>
         <authors>Media Browser Team</authors>
         <owners>ebr,Luke,scottisafool</owners>
         <owners>ebr,Luke,scottisafool</owners>

+ 2 - 2
Nuget/MediaBrowser.Server.Core.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
 <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
     <metadata>
     <metadata>
         <id>MediaBrowser.Server.Core</id>
         <id>MediaBrowser.Server.Core</id>
-        <version>3.0.582</version>
+        <version>3.0.583</version>
         <title>Media Browser.Server.Core</title>
         <title>Media Browser.Server.Core</title>
         <authors>Media Browser Team</authors>
         <authors>Media Browser Team</authors>
         <owners>ebr,Luke,scottisafool</owners>
         <owners>ebr,Luke,scottisafool</owners>
@@ -12,7 +12,7 @@
         <description>Contains core components required to build plugins for Media Browser Server.</description>
         <description>Contains core components required to build plugins for Media Browser Server.</description>
         <copyright>Copyright © Media Browser 2013</copyright>
         <copyright>Copyright © Media Browser 2013</copyright>
         <dependencies>
         <dependencies>
-            <dependency id="MediaBrowser.Common" version="3.0.582" />
+            <dependency id="MediaBrowser.Common" version="3.0.583" />
         </dependencies>
         </dependencies>
     </metadata>
     </metadata>
     <files>
     <files>