update dash manifest

This commit is contained in:
Luke Pulverenti 2015-03-10 00:22:42 -04:00
parent c42f8eba68
commit 1dc37ee362
2 changed files with 54 additions and 14 deletions

View File

@ -134,7 +134,19 @@ namespace MediaBrowser.Api.Playback
data += "-" + (state.Request.DeviceId ?? string.Empty); data += "-" + (state.Request.DeviceId ?? string.Empty);
data += "-" + (state.Request.ClientTime ?? string.Empty); data += "-" + (state.Request.ClientTime ?? string.Empty);
return Path.Combine(folder, data.GetMD5().ToString("N") + (outputFileExtension ?? string.Empty).ToLower()); var dataHash = data.GetMD5().ToString("N");
if (EnableOutputInSubFolder)
{
return Path.Combine(folder, dataHash, dataHash + (outputFileExtension ?? string.Empty).ToLower());
}
return Path.Combine(folder, dataHash + (outputFileExtension ?? string.Empty).ToLower());
}
protected virtual bool EnableOutputInSubFolder
{
get { return false; }
} }
protected readonly CultureInfo UsCulture = new CultureInfo("en-US"); protected readonly CultureInfo UsCulture = new CultureInfo("en-US");

View File

@ -38,8 +38,7 @@ namespace MediaBrowser.Api.Playback.Hls
} }
} }
[Route("/Videos/{Id}/dash/audio/{SegmentId}.m4s", "GET")] [Route("/Videos/{Id}/dash/{SegmentType}/{SegmentId}.m4s", "GET")]
[Route("/Videos/{Id}/dash/video/{SegmentId}.m4s", "GET")]
public class GetDashSegment : VideoStreamRequest public class GetDashSegment : VideoStreamRequest
{ {
/// <summary> /// <summary>
@ -47,11 +46,18 @@ namespace MediaBrowser.Api.Playback.Hls
/// </summary> /// </summary>
/// <value>The segment id.</value> /// <value>The segment id.</value>
public string SegmentId { get; set; } public string SegmentId { get; set; }
/// <summary>
/// Gets or sets the type of the segment.
/// </summary>
/// <value>The type of the segment.</value>
public string SegmentType { get; set; }
} }
public class MpegDashService : BaseHlsService public class MpegDashService : BaseHlsService
{ {
public MpegDashService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, ILiveTvManager liveTvManager, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IProcessManager processManager, IMediaSourceManager mediaSourceManager, INetworkManager networkManager) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, liveTvManager, dlnaManager, subtitleEncoder, deviceManager, processManager, mediaSourceManager) public MpegDashService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, ILiveTvManager liveTvManager, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IProcessManager processManager, IMediaSourceManager mediaSourceManager, INetworkManager networkManager)
: base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, liveTvManager, dlnaManager, subtitleEncoder, deviceManager, processManager, mediaSourceManager)
{ {
NetworkManager = networkManager; NetworkManager = networkManager;
} }
@ -72,6 +78,14 @@ namespace MediaBrowser.Api.Playback.Hls
return result; return result;
} }
protected override bool EnableOutputInSubFolder
{
get
{
return true;
}
}
private async Task<object> GetAsync(GetMasterManifest request, string method) private async Task<object> GetAsync(GetMasterManifest request, string method)
{ {
if (string.Equals(request.AudioCodec, "copy", StringComparison.OrdinalIgnoreCase)) if (string.Equals(request.AudioCodec, "copy", StringComparison.OrdinalIgnoreCase))
@ -156,7 +170,7 @@ namespace MediaBrowser.Api.Playback.Hls
builder.Append("</Representation>"); builder.Append("</Representation>");
builder.Append("</AdaptationSet>"); builder.Append("</AdaptationSet>");
return builder.ToString(); return builder.ToString();
} }
@ -275,7 +289,7 @@ namespace MediaBrowser.Api.Playback.Hls
public object Get(GetDashSegment request) public object Get(GetDashSegment request)
{ {
return GetDynamicSegment(request, request.SegmentId).Result; return GetDynamicSegment(request, request.SegmentId, request.SegmentType).Result;
} }
private void AppendSegmentList(StreamState state, StringBuilder builder, string type) private void AppendSegmentList(StreamState state, StringBuilder builder, string type)
@ -314,7 +328,7 @@ namespace MediaBrowser.Api.Playback.Hls
builder.Append("</SegmentList>"); builder.Append("</SegmentList>");
} }
private async Task<object> GetDynamicSegment(VideoStreamRequest request, string segmentId) private async Task<object> GetDynamicSegment(VideoStreamRequest request, string segmentId, string segmentType)
{ {
if ((request.StartTimeTicks ?? 0) > 0) if ((request.StartTimeTicks ?? 0) > 0)
{ {
@ -332,7 +346,7 @@ namespace MediaBrowser.Api.Playback.Hls
var segmentExtension = GetSegmentFileExtension(state); var segmentExtension = GetSegmentFileExtension(state);
var segmentPath = GetSegmentPath(playlistPath, segmentExtension, index); var segmentPath = GetSegmentPath(playlistPath, segmentType, segmentExtension, index);
var segmentLength = state.SegmentLength; var segmentLength = state.SegmentLength;
TranscodingJob job = null; TranscodingJob job = null;
@ -491,7 +505,7 @@ namespace MediaBrowser.Api.Playback.Hls
return job != null && !job.HasExited; return job != null && !job.HasExited;
} }
public int? GetCurrentTranscodingIndex(string playlist, string segmentExtension) public int? GetCurrentTranscodingIndex(string playlist, string segmentExtension)
{ {
var file = GetLastTranscodingFile(playlist, segmentExtension, FileSystem); var file = GetLastTranscodingFile(playlist, segmentExtension, FileSystem);
@ -573,15 +587,29 @@ namespace MediaBrowser.Api.Playback.Hls
return int.Parse(segmentId, NumberStyles.Integer, UsCulture); return int.Parse(segmentId, NumberStyles.Integer, UsCulture);
} }
private string GetSegmentPath(string playlist, string segmentExtension, int index) private string GetSegmentPath(string playlist, string segmentType, string segmentExtension, int index)
{ {
var folder = Path.GetDirectoryName(playlist); var folder = Path.GetDirectoryName(playlist);
var filename = Path.GetFileNameWithoutExtension(playlist); var id = string.Equals(segmentType, "video", StringComparison.OrdinalIgnoreCase)
? "0"
: "1";
return Path.Combine(folder, filename + index.ToString("000", UsCulture) + segmentExtension); string filename;
if (index == 0)
{
filename = "init-stream" + id + segmentExtension;
}
else
{
var number = index.ToString("00000", CultureInfo.InvariantCulture);
filename = "chunk-stream" + id + "-" + number + segmentExtension;
}
return Path.Combine(folder, filename);
} }
protected override string GetAudioArguments(StreamState state) protected override string GetAudioArguments(StreamState state)
{ {
var codec = state.OutputAudioCodec; var codec = state.OutputAudioCodec;
@ -636,7 +664,7 @@ namespace MediaBrowser.Api.Playback.Hls
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream;
args+= " " + GetVideoQualityParam(state, H264Encoder, true) + keyFrameArg; args += " " + GetVideoQualityParam(state, H264Encoder, true) + keyFrameArg;
args += " -r 24 -g 24"; args += " -r 24 -g 24";