jellyfin-server/MediaBrowser.Dlna/PlayTo/StreamHelper.cs

72 lines
3.8 KiB
C#
Raw Normal View History

2014-03-23 05:10:33 +00:00
using MediaBrowser.Controller.Dlna;
2014-02-27 02:44:00 +00:00
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace MediaBrowser.Dlna.PlayTo
{
class StreamHelper
{
/// <summary>
/// Gets the audio URL.
/// </summary>
2014-03-23 05:10:33 +00:00
/// <param name="deviceProperties">The device properties.</param>
2014-02-27 02:44:00 +00:00
/// <param name="item">The item.</param>
2014-03-23 05:10:33 +00:00
/// <param name="streams">The streams.</param>
2014-02-27 02:44:00 +00:00
/// <param name="serverAddress">The server address.</param>
/// <returns>System.String.</returns>
2014-03-23 05:10:33 +00:00
internal static string GetAudioUrl(DeviceInfo deviceProperties, PlaylistItem item, List<MediaStream> streams, string serverAddress)
2014-02-27 02:44:00 +00:00
{
2014-03-23 05:10:33 +00:00
var dlnaCommand = BuildDlnaUrl(item.MediaSourceId, deviceProperties.UUID, !item.Transcode, null, item.AudioCodec, item.AudioStreamIndex, item.SubtitleStreamIndex, null, 128000, item.StartPositionTicks, item.TranscodingSettings);
2014-02-27 02:44:00 +00:00
2014-03-23 05:10:33 +00:00
return string.Format("{0}/audio/{1}/stream{2}?{3}", serverAddress, item.ItemId, "." + item.Container.TrimStart('.'), dlnaCommand);
2014-02-27 02:44:00 +00:00
}
/// <summary>
/// Gets the video URL.
/// </summary>
/// <param name="deviceProperties">The device properties.</param>
/// <param name="item">The item.</param>
/// <param name="streams">The streams.</param>
/// <param name="serverAddress">The server address.</param>
/// <returns>The url to send to the device</returns>
2014-03-13 19:08:02 +00:00
internal static string GetVideoUrl(DeviceInfo deviceProperties, PlaylistItem item, List<MediaStream> streams, string serverAddress)
2014-02-27 02:44:00 +00:00
{
2014-03-23 05:10:33 +00:00
var dlnaCommand = BuildDlnaUrl(item.MediaSourceId, deviceProperties.UUID, !item.Transcode, item.VideoCodec, item.AudioCodec, item.AudioStreamIndex, item.SubtitleStreamIndex, 1500000, 128000, item.StartPositionTicks, item.TranscodingSettings);
2014-02-27 02:44:00 +00:00
2014-03-22 19:37:15 +00:00
return string.Format("{0}/Videos/{1}/stream{2}?{3}", serverAddress, item.ItemId, item.Container, dlnaCommand);
2014-02-27 02:44:00 +00:00
}
/// <summary>
/// Builds the dlna URL.
/// </summary>
2014-03-23 05:10:33 +00:00
private static string BuildDlnaUrl(string mediaSourceId, string deviceID, bool isStatic, string videoCodec, string audioCodec, int? audiostreamIndex, int? subtitleIndex, int? videoBitrate, int? audioBitrate, long? startPositionTicks, List<TranscodingSetting> settings)
2014-02-27 02:44:00 +00:00
{
2014-03-23 05:10:33 +00:00
var profile = settings.Where(i => i.Name == TranscodingSettingType.VideoProfile).Select(i => i.Value).FirstOrDefault();
var videoLevel = settings.Where(i => i.Name == TranscodingSettingType.VideoLevel).Select(i => i.Value).FirstOrDefault();
var maxAudioChannels = settings.Where(i => i.Name == TranscodingSettingType.MaxAudioChannels).Select(i => i.Value).FirstOrDefault();
2014-02-27 02:44:00 +00:00
2014-03-23 05:10:33 +00:00
var usCulture = new CultureInfo("en-US");
2014-02-27 02:44:00 +00:00
2014-03-23 05:10:33 +00:00
var list = new List<string>
{
deviceID ?? string.Empty,
mediaSourceId ?? string.Empty,
isStatic.ToString().ToLower(),
videoCodec ?? string.Empty,
audioCodec ?? string.Empty,
audiostreamIndex.HasValue ? audiostreamIndex.Value.ToString(usCulture) : string.Empty,
subtitleIndex.HasValue ? subtitleIndex.Value.ToString(usCulture) : string.Empty,
videoBitrate.HasValue ? videoBitrate.Value.ToString(usCulture) : string.Empty,
audioBitrate.HasValue ? audioBitrate.Value.ToString(usCulture) : string.Empty,
maxAudioChannels ?? string.Empty,
startPositionTicks.HasValue ? startPositionTicks.Value.ToString(usCulture) : string.Empty,
profile ?? string.Empty,
videoLevel ?? string.Empty
};
return string.Format("Params={0}", string.Join(";", list.ToArray()));
2014-02-27 02:44:00 +00:00
}
}
2014-03-14 14:27:32 +00:00
}