|
|
|
@ -22,6 +22,8 @@ using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using CommonIO;
|
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Playback
|
|
|
|
|
{
|
|
|
|
@ -69,6 +71,9 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
|
protected IZipClient ZipClient { get; private set; }
|
|
|
|
|
protected IJsonSerializer JsonSerializer { get; private set; }
|
|
|
|
|
|
|
|
|
|
public static IServerApplicationHost AppHost;
|
|
|
|
|
public static IHttpClient HttpClient;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="BaseStreamingService" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -1112,6 +1117,7 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StartThrottler(state, transcodingJob);
|
|
|
|
|
ReportUsage(state);
|
|
|
|
|
|
|
|
|
|
return transcodingJob;
|
|
|
|
|
}
|
|
|
|
@ -1131,7 +1137,7 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
|
return state.InputProtocol == MediaProtocol.File &&
|
|
|
|
|
state.RunTimeTicks.HasValue &&
|
|
|
|
|
state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks &&
|
|
|
|
|
state.IsInputVideo &&
|
|
|
|
|
state.IsInputVideo &&
|
|
|
|
|
state.VideoType == VideoType.VideoFile &&
|
|
|
|
|
!string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
|
string.Equals(GetVideoEncoder(state), "libx264", StringComparison.OrdinalIgnoreCase);
|
|
|
|
@ -2197,6 +2203,121 @@ namespace MediaBrowser.Api.Playback
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void ReportUsage(StreamState state)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await ReportUsageInternal(state).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Task ReportUsageInternal(StreamState state)
|
|
|
|
|
{
|
|
|
|
|
if (!ServerConfigurationManager.Configuration.EnableAnonymousUsageReporting)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.Equals(MediaEncoder.EncoderLocationType, "Default", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dict = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
|
|
var outputAudio = GetAudioEncoder(state);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(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) &&
|
|
|
|
|
ServerConfigurationManager.Configuration.CodecsUsed.Contains(outputVideo ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dict["id"] = AppHost.SystemId;
|
|
|
|
|
dict["type"] = state.VideoRequest == null ? "Audio" : "Video";
|
|
|
|
|
|
|
|
|
|
var audioStream = state.AudioStream;
|
|
|
|
|
if (audioStream != null && !string.IsNullOrWhiteSpace(audioStream.Codec))
|
|
|
|
|
{
|
|
|
|
|
dict["inputAudio"] = audioStream.Codec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var videoStream = state.VideoStream;
|
|
|
|
|
if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
|
|
|
|
|
{
|
|
|
|
|
dict["inputVideo"] = videoStream.Codec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cert = GetType().Assembly.GetModules().First().GetSignerCertificate();
|
|
|
|
|
if (cert != null)
|
|
|
|
|
{
|
|
|
|
|
dict["assemblySig"] = cert.GetCertHashString();
|
|
|
|
|
dict["certSubject"] = cert.Subject ?? string.Empty;
|
|
|
|
|
dict["certIssuer"] = cert.Issuer ?? string.Empty;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state.SupportedAudioCodecs.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
dict["supportedAudioCodecs"] = string.Join(",", state.SupportedAudioCodecs.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var auth = AuthorizationContext.GetAuthorizationInfo(Request);
|
|
|
|
|
|
|
|
|
|
dict["appName"] = auth.Client ?? string.Empty;
|
|
|
|
|
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));
|
|
|
|
|
if (!ServerConfigurationManager.Configuration.CodecsUsed.Contains(outputAudio ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var list = ServerConfigurationManager.Configuration.CodecsUsed.ToList();
|
|
|
|
|
list.Add(outputAudio);
|
|
|
|
|
ServerConfigurationManager.Configuration.CodecsUsed = list.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ServerConfigurationManager.Configuration.CodecsUsed.Contains(outputVideo ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var list = ServerConfigurationManager.Configuration.CodecsUsed.ToList();
|
|
|
|
|
list.Add(outputVideo);
|
|
|
|
|
ServerConfigurationManager.Configuration.CodecsUsed = list.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerConfigurationManager.SaveConfiguration();
|
|
|
|
|
|
|
|
|
|
//Logger.Info(JsonSerializer.SerializeToString(dict));
|
|
|
|
|
var options = new HttpRequestOptions()
|
|
|
|
|
{
|
|
|
|
|
Url = "https://mb3admin.com/admin/service/transcoding/report",
|
|
|
|
|
CancellationToken = CancellationToken.None,
|
|
|
|
|
LogRequest = false,
|
|
|
|
|
LogErrors = false
|
|
|
|
|
};
|
|
|
|
|
options.RequestContent = JsonSerializer.SerializeToString(dict);
|
|
|
|
|
options.RequestContentType = "application/json";
|
|
|
|
|
|
|
|
|
|
return HttpClient.Post(options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the dlna headers.
|
|
|
|
|
/// </summary>
|
|
|
|
|