jellyfin/MediaBrowser.Dlna/PlayTo/StreamHelper.cs

73 lines
3.9 KiB
C#
Raw Normal View History

2014-03-22 22:10:33 -07:00
using MediaBrowser.Controller.Dlna;
2014-02-26 19:44:00 -07: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-22 22:10:33 -07:00
/// <param name="deviceProperties">The device properties.</param>
2014-02-26 19:44:00 -07:00
/// <param name="item">The item.</param>
2014-03-22 22:10:33 -07:00
/// <param name="streams">The streams.</param>
2014-02-26 19:44:00 -07:00
/// <param name="serverAddress">The server address.</param>
/// <returns>System.String.</returns>
2014-03-22 22:10:33 -07:00
internal static string GetAudioUrl(DeviceInfo deviceProperties, PlaylistItem item, List<MediaStream> streams, string serverAddress)
2014-02-26 19:44:00 -07:00
{
2014-03-23 09:42:02 -07:00
var dlnaCommand = BuildDlnaUrl(item.DeviceProfileName, item.MediaSourceId, deviceProperties.UUID, !item.Transcode, null, item.AudioCodec, item.AudioStreamIndex, item.SubtitleStreamIndex, null, 128000, item.StartPositionTicks, item.TranscodingSettings);
2014-02-26 19:44:00 -07:00
2014-03-22 22:10:33 -07:00
return string.Format("{0}/audio/{1}/stream{2}?{3}", serverAddress, item.ItemId, "." + item.Container.TrimStart('.'), dlnaCommand);
2014-02-26 19:44:00 -07: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 12:08:02 -07:00
internal static string GetVideoUrl(DeviceInfo deviceProperties, PlaylistItem item, List<MediaStream> streams, string serverAddress)
2014-02-26 19:44:00 -07:00
{
2014-03-23 09:42:02 -07:00
var dlnaCommand = BuildDlnaUrl(item.DeviceProfileName, item.MediaSourceId, deviceProperties.UUID, !item.Transcode, item.VideoCodec, item.AudioCodec, item.AudioStreamIndex, item.SubtitleStreamIndex, 1500000, 128000, item.StartPositionTicks, item.TranscodingSettings);
2014-02-26 19:44:00 -07:00
2014-03-22 12:37:15 -07:00
return string.Format("{0}/Videos/{1}/stream{2}?{3}", serverAddress, item.ItemId, item.Container, dlnaCommand);
2014-02-26 19:44:00 -07:00
}
/// <summary>
/// Builds the dlna URL.
/// </summary>
2014-03-23 09:42:02 -07:00
private static string BuildDlnaUrl(string deviceProfileName, 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-26 19:44:00 -07:00
{
2014-03-22 22:10:33 -07: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-26 19:44:00 -07:00
2014-03-22 22:10:33 -07:00
var usCulture = new CultureInfo("en-US");
2014-02-26 19:44:00 -07:00
2014-03-22 22:10:33 -07:00
var list = new List<string>
{
2014-03-23 09:42:02 -07:00
deviceProfileName ?? string.Empty,
2014-03-22 22:10:33 -07:00
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-26 19:44:00 -07:00
}
}
2014-03-14 07:27:32 -07:00
}