@ -2,7 +2,6 @@
using MediaBrowser.Controller.Configuration ;
using MediaBrowser.Controller.Configuration ;
using MediaBrowser.Controller.Devices ;
using MediaBrowser.Controller.Devices ;
using MediaBrowser.Controller.Dlna ;
using MediaBrowser.Controller.Dlna ;
using MediaBrowser.Controller.Entities ;
using MediaBrowser.Controller.Library ;
using MediaBrowser.Controller.Library ;
using MediaBrowser.Controller.MediaEncoding ;
using MediaBrowser.Controller.MediaEncoding ;
using MediaBrowser.Model.Dlna ;
using MediaBrowser.Model.Dlna ;
@ -14,18 +13,15 @@ using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization ;
using MediaBrowser.Model.Serialization ;
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Globalization ;
using System.Globalization ;
using System.IO ;
using System.IO ;
using System.Linq ;
using System.Linq ;
using System.Text ;
using System.Text ;
using System.Threading ;
using System.Threading ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
using MediaBrowser.Common.IO ;
using MediaBrowser.Model.IO ;
using MediaBrowser.Common.Net ;
using MediaBrowser.Common.Net ;
using MediaBrowser.Controller ;
using MediaBrowser.Controller ;
using MediaBrowser. Controller.IO ;
using MediaBrowser. Model.Diagnostics ;
namespace MediaBrowser.Api.Playback
namespace MediaBrowser.Api.Playback
{
{
@ -1158,32 +1154,24 @@ namespace MediaBrowser.Api.Playback
var transcodingId = Guid . NewGuid ( ) . ToString ( "N" ) ;
var transcodingId = Guid . NewGuid ( ) . ToString ( "N" ) ;
var commandLineArgs = GetCommandLineArguments ( outputPath , state , true ) ;
var commandLineArgs = GetCommandLineArguments ( outputPath , state , true ) ;
var process = new Proces s
var process = ApiEntryPoint . Instance . ProcessFactory . Create ( new Proces sOption s
{
{
StartInfo = new ProcessStartInfo
CreateNoWindow = true ,
{
UseShellExecute = false ,
CreateNoWindow = true ,
UseShellExecute = false ,
// Must consume both stdout and stderr or deadlocks may occur
// Must consume both stdout and stderr or deadlocks may occur
//RedirectStandardOutput = true,
//RedirectStandardOutput = true,
RedirectStandardError = true ,
RedirectStandardError = true ,
RedirectStandardInput = true ,
RedirectStandardInput = true ,
FileName = MediaEncoder . EncoderPath ,
FileName = MediaEncoder . EncoderPath ,
Arguments = commandLineArgs ,
Arguments = commandLineArgs ,
WindowStyle = ProcessWindowStyle . Hidden ,
IsHidden = true ,
ErrorDialog = false
ErrorDialog = false ,
} ,
EnableRaisingEvents = true ,
WorkingDirectory = ! string . IsNullOrWhiteSpace ( workingDirectory ) ? workingDirectory : null
EnableRaisingEvents = true
} ) ;
} ;
if ( ! string . IsNullOrWhiteSpace ( workingDirectory ) )
{
process . StartInfo . WorkingDirectory = workingDirectory ;
}
var transcodingJob = ApiEntryPoint . Instance . OnTranscodeBeginning ( outputPath ,
var transcodingJob = ApiEntryPoint . Instance . OnTranscodeBeginning ( outputPath ,
state . Request . PlaySessionId ,
state . Request . PlaySessionId ,
@ -1268,7 +1256,7 @@ namespace MediaBrowser.Api.Playback
{
{
if ( EnableThrottling ( state ) )
if ( EnableThrottling ( state ) )
{
{
transcodingJob . TranscodingThrottler = state . TranscodingThrottler = new TranscodingThrottler ( transcodingJob , Logger , ServerConfigurationManager );
transcodingJob . TranscodingThrottler = state . TranscodingThrottler = new TranscodingThrottler ( transcodingJob , Logger , ServerConfigurationManager , ApiEntryPoint . Instance . TimerFactory , FileSystem );
state . TranscodingThrottler . Start ( ) ;
state . TranscodingThrottler . Start ( ) ;
}
}
}
}
@ -1520,7 +1508,7 @@ namespace MediaBrowser.Api.Playback
/// <param name="process">The process.</param>
/// <param name="process">The process.</param>
/// <param name="job">The job.</param>
/// <param name="job">The job.</param>
/// <param name="state">The state.</param>
/// <param name="state">The state.</param>
private void OnFfMpegProcessExited ( Process process , TranscodingJob job , StreamState state )
private void OnFfMpegProcessExited ( I Process process , TranscodingJob job , StreamState state )
{
{
if ( job ! = null )
if ( job ! = null )
{
{
@ -2408,97 +2396,98 @@ namespace MediaBrowser.Api.Playback
{
{
return Task . FromResult ( true ) ;
return Task . FromResult ( true ) ;
}
}
return Task . FromResult ( true ) ;
var dict = new Dictionary < string , string > ( ) ;
//var dict = new Dictionary<string, string>() ;
var outputAudio = GetAudioEncoder ( state ) ;
//var outputAudio = GetAudioEncoder(state);
if ( ! string . IsNullOrWhiteSpace ( outputAudio ) )
//if (!string.IsNullOrWhiteSpace(outputAudio))
{
//{
dict [ "outputAudio" ] = outputAudio ;
// dict["outputAudio"] = outputAudio;
}
//}
var outputVideo = GetVideoEncoder ( state ) ;
if ( ! string . IsNullOrWhiteSpace ( outputVideo ) )
{
dict [ "outputVideo" ] = outputVideo ;
}
if ( ServerConfigurationManager . Configuration . CodecsUsed . Contains ( outputAudio ? ? string . Empty , StringComparer . OrdinalIgnoreCase ) & &
//var outputVideo = GetVideoEncoder(state);
ServerConfigurationManager . Configuration . CodecsUsed . Contains ( outputVideo ? ? string . Empty , StringComparer . OrdinalIgnoreCase ) )
//if (!string.IsNullOrWhiteSpace(outputVideo))
{
//{
return Task . FromResult ( true ) ;
// dict["outputVideo"] = outputVideo;
}
//}
dict [ "id" ] = AppHost . SystemId ;
//if (ServerConfigurationManager.Configuration.CodecsUsed.Contains(outputAudio ?? string.Empty, StringComparer.OrdinalIgnoreCase) &&
dict [ "type" ] = state . VideoRequest = = null ? "Audio" : "Video" ;
// ServerConfigurationManager.Configuration.CodecsUsed.Contains(outputVideo ?? string.Empty, StringComparer.OrdinalIgnoreCase))
//{
// return Task.FromResult(true);
//}
var audioStream = state . AudioStream ;
//dict["id"] = AppHost.SystemId;
if ( audioStream ! = null & & ! string . IsNullOrWhiteSpace ( audioStream . Codec ) )
//dict["type"] = state.VideoRequest == null ? "Audio" : "Video";
{
dict [ "inputAudio" ] = audioStream . Codec ;
}
var videoStream = state . VideoStream ;
//var audioStream = state.AudioStream;
if ( videoStream ! = null & & ! string . IsNullOrWhiteSpace ( videoStream . Codec ) )
//if (audioStream != null && !string.IsNullOrWhiteSpace(audioStream.Codec))
{
// {
dict [ "inputVideo" ] = videoStream . Codec ;
// dict["inputAudio"] = audioStream.Codec ;
}
// }
var cert = GetType ( ) . Assembly . GetModules ( ) . First ( ) . GetSignerCertificate ( ) ;
//var videoStream = state.VideoStream;
if ( cert ! = null )
//if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
{
//{
dict [ "assemblySig" ] = cert . GetCertHashString ( ) ;
// dict["inputVideo"] = videoStream.Codec;
dict [ "certSubject" ] = cert . Subject ? ? string . Empty ;
//}
dict [ "certIssuer" ] = cert . Issuer ? ? string . Empty ;
}
else
{
return Task . FromResult ( true ) ;
}
if ( state . SupportedAudioCodecs . Count > 0 )
//var cert = GetType().Assembly.GetModules().First().GetSignerCertificate();
{
//if (cert != null)
dict [ "supportedAudioCodecs" ] = string . Join ( "," , state . SupportedAudioCodecs . ToArray ( ) ) ;
//{
}
// dict["assemblySig"] = cert.GetCertHashString();
// dict["certSubject"] = cert.Subject ?? string.Empty;
// dict["certIssuer"] = cert.Issuer ?? string.Empty;
//}
//else
//{
// return Task.FromResult(true);
//}
var auth = AuthorizationContext . GetAuthorizationInfo ( Request ) ;
//if (state.SupportedAudioCodecs.Count > 0)
//{
// dict["supportedAudioCodecs"] = string.Join(",", state.SupportedAudioCodecs.ToArray());
//}
dict [ "appName" ] = auth . Client ? ? string . Empty ;
//var auth = AuthorizationContext.GetAuthorizationInfo(Request);
dict [ "appVersion" ] = auth . Version ? ? string . Empty ;
dict [ "device" ] = auth . Device ? ? string . Empty ;
dict [ "deviceId" ] = auth . DeviceId ? ? string . Empty ;
dict [ "context" ] = "streaming" ;
//Logger.Info(JsonSerializer.SerializeToString(dict));
//dict["appName"] = auth.Client ?? string.Empty;
if ( ! ServerConfigurationManager . Configuration . CodecsUsed . Contains ( outputAudio ? ? string . Empty , StringComparer . OrdinalIgnoreCase ) )
//dict["appVersion"] = auth.Version ?? string.Empty;
{
//dict["device"] = auth.Device ?? string.Empty;
var list = ServerConfigurationManager . Configuration . CodecsUsed . ToList ( ) ;
//dict["deviceId"] = auth.DeviceId ?? string.Empty;
list . Add ( outputAudio ) ;
//dict["context"] = "streaming";
ServerConfigurationManager . Configuration . CodecsUsed = list . ToArray ( ) ;
}
if ( ! ServerConfigurationManager . Configuration . CodecsUsed . Contains ( outputVideo ? ? string . Empty , StringComparer . OrdinalIgnoreCase ) )
////Logger.Info(JsonSerializer.SerializeToString(dict));
{
//if (!ServerConfigurationManager.Configuration.CodecsUsed.Contains(outputAudio ?? string.Empty, StringComparer.OrdinalIgnoreCase))
var list = ServerConfigurationManager . Configuration . CodecsUsed . ToList ( ) ;
//{
list . Add ( outputVideo ) ;
// var list = ServerConfigurationManager.Configuration.CodecsUsed.ToList();
ServerConfigurationManager . Configuration . CodecsUsed = list . ToArray ( ) ;
// list.Add(outputAudio);
}
// ServerConfigurationManager.Configuration.CodecsUsed = list.ToArray();
//}
ServerConfigurationManager . SaveConfiguration ( ) ;
//if (!ServerConfigurationManager.Configuration.CodecsUsed.Contains(outputVideo ?? string.Empty, StringComparer.OrdinalIgnoreCase))
//{
// var list = ServerConfigurationManager.Configuration.CodecsUsed.ToList();
// list.Add(outputVideo);
// ServerConfigurationManager.Configuration.CodecsUsed = list.ToArray();
//}
//Logger.Info(JsonSerializer.SerializeToString(dict));
//ServerConfigurationManager.SaveConfiguration();
var options = new HttpRequestOptions ( )
{
Url = "https://mb3admin.com/admin/service/transcoding/report" ,
CancellationToken = CancellationToken . None ,
LogRequest = false ,
LogErrors = false ,
BufferContent = false
} ;
options . RequestContent = JsonSerializer . SerializeToString ( dict ) ;
options . RequestContentType = "application/json" ;
return HttpClient . Post ( options ) ;
////Logger.Info(JsonSerializer.SerializeToString(dict));
//var options = new HttpRequestOptions()
//{
// Url = "https://mb3admin.com/admin/service/transcoding/report",
// CancellationToken = CancellationToken.None,
// LogRequest = false,
// LogErrors = false,
// BufferContent = false
//};
//options.RequestContent = JsonSerializer.SerializeToString(dict);
//options.RequestContentType = "application/json";
//return HttpClient.Post(options);
}
}
/// <summary>
/// <summary>