@ -1,4 +1,6 @@
using MediaBrowser.Controller.Devices ;
using MediaBrowser.Common.Net ;
using MediaBrowser.Controller.Configuration ;
using MediaBrowser.Controller.Devices ;
using MediaBrowser.Controller.Entities ;
using MediaBrowser.Controller.Library ;
using MediaBrowser.Controller.Net ;
@ -59,23 +61,27 @@ namespace MediaBrowser.Api.Playback
private readonly IMediaSourceManager _mediaSourceManager ;
private readonly IDeviceManager _deviceManager ;
private readonly ILibraryManager _libraryManager ;
private readonly IServerConfigurationManager _config ;
private readonly INetworkManager _networkManager ;
public MediaInfoService ( IMediaSourceManager mediaSourceManager , IDeviceManager deviceManager , ILibraryManager libraryManager )
public MediaInfoService ( IMediaSourceManager mediaSourceManager , IDeviceManager deviceManager , ILibraryManager libraryManager , IServerConfigurationManager config , INetworkManager networkManager )
{
_mediaSourceManager = mediaSourceManager ;
_deviceManager = deviceManager ;
_libraryManager = libraryManager ;
_config = config ;
_networkManager = networkManager ;
}
public async Task < object > Get ( GetPlaybackInfo request )
{
var result = await GetPlaybackInfo ( request . Id , request . UserId ). ConfigureAwait ( false ) ;
var result = await GetPlaybackInfo ( request . Id , request . UserId , new [ ] { MediaType . Audio , MediaType . Video } ). ConfigureAwait ( false ) ;
return ToOptimizedResult ( result ) ;
}
public async Task < object > Get ( GetLiveMediaInfo request )
{
var result = await GetPlaybackInfo ( request . Id , request . UserId ). ConfigureAwait ( false ) ;
var result = await GetPlaybackInfo ( request . Id , request . UserId , new [ ] { MediaType . Audio , MediaType . Video } ). ConfigureAwait ( false ) ;
return ToOptimizedResult ( result ) ;
}
@ -122,29 +128,38 @@ namespace MediaBrowser.Api.Playback
public async Task < object > Post ( GetPostedPlaybackInfo request )
{
var info = await GetPlaybackInfo ( request . Id , request . UserId , request . MediaSourceId , request . LiveStreamId ) . ConfigureAwait ( false ) ;
var authInfo = AuthorizationContext . GetAuthorizationInfo ( Request ) ;
var profile = request . DeviceProfile ;
if ( profile = = null )
var caps = _deviceManager . GetCapabilities ( authInfo . DeviceId ) ;
if ( caps ! = null )
{
var caps = _deviceManager . GetCapabilities ( authInfo . DeviceId ) ;
if ( caps ! = null )
if ( profile = = null )
{
profile = caps . DeviceProfile ;
}
}
var maxBitrate = request . MaxStreamingBitrate ;
if ( _config . Configuration . RemoteClientBitrateLimit > 0 & & ! _networkManager . IsInLocalNetwork ( Request . RemoteIp ) )
{
maxBitrate = Math . Min ( maxBitrate ? ? _config . Configuration . RemoteClientBitrateLimit , _config . Configuration . RemoteClientBitrateLimit ) ;
}
var info = await GetPlaybackInfo ( request . Id , request . UserId , new [ ] { MediaType . Audio , MediaType . Video } , request . MediaSourceId , request . LiveStreamId ) . ConfigureAwait ( false ) ;
if ( profile ! = null )
{
var mediaSourceId = request . MediaSourceId ;
SetDeviceSpecificData ( request . Id , info , profile , authInfo , request . MaxStreamingBitrate , request . StartTimeTicks ? ? 0 , mediaSourceId , request . AudioStreamIndex , request . SubtitleStreamIndex ) ;
SetDeviceSpecificData ( request . Id , info , profile , authInfo , max Bitrate, request . StartTimeTicks ? ? 0 , mediaSourceId , request . AudioStreamIndex , request . SubtitleStreamIndex ) ;
}
return ToOptimizedResult ( info ) ;
}
private async Task < PlaybackInfoResponse > GetPlaybackInfo ( string id , string userId , string mediaSourceId = null , string liveStreamId = null )
private async Task < PlaybackInfoResponse > GetPlaybackInfo ( string id , string userId , string [ ] supportedLiveMediaTypes , string mediaSourceId = null , string liveStreamId = null )
{
var result = new PlaybackInfoResponse ( ) ;
@ -153,7 +168,7 @@ namespace MediaBrowser.Api.Playback
IEnumerable < MediaSourceInfo > mediaSources ;
try
{
mediaSources = await _mediaSourceManager . GetPlayackMediaSources ( id , userId , true , CancellationToken. None ) . ConfigureAwait ( false ) ;
mediaSources = await _mediaSourceManager . GetPlayackMediaSources ( id , userId , true , supportedLiveMediaTypes, CancellationToken. None ) . ConfigureAwait ( false ) ;
}
catch ( PlaybackException ex )
{