Skip to content

Commit

Permalink
Merge pull request #1058 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
3.0.5569.0
  • Loading branch information
LukePulverenti committed Mar 31, 2015
2 parents d7d88b9 + 03b424f commit 67a6edd
Show file tree
Hide file tree
Showing 236 changed files with 5,822 additions and 2,256 deletions.
55 changes: 30 additions & 25 deletions MediaBrowser.Api/ApiEntryPoint.cs
Expand Up @@ -132,7 +132,7 @@ protected virtual void Dispose(bool dispose)
/// Called when [transcode beginning].
/// </summary>
/// <param name="path">The path.</param>
/// <param name="streamId">The stream identifier.</param>
/// <param name="playSessionId">The play session identifier.</param>
/// <param name="transcodingJobId">The transcoding job identifier.</param>
/// <param name="type">The type.</param>
/// <param name="process">The process.</param>
Expand All @@ -141,7 +141,7 @@ protected virtual void Dispose(bool dispose)
/// <param name="cancellationTokenSource">The cancellation token source.</param>
/// <returns>TranscodingJob.</returns>
public TranscodingJob OnTranscodeBeginning(string path,
string streamId,
string playSessionId,
string transcodingJobId,
TranscodingJobType type,
Process process,
Expand All @@ -160,7 +160,7 @@ protected virtual void Dispose(bool dispose)
DeviceId = deviceId,
CancellationTokenSource = cancellationTokenSource,
Id = transcodingJobId,
StreamId = streamId
PlaySessionId = playSessionId
};

_activeTranscodingJobs.Add(job);
Expand All @@ -187,7 +187,7 @@ public void ReportTranscodingProgress(TranscodingJob job, StreamState state, Tim

if (!string.IsNullOrWhiteSpace(deviceId))
{
var audioCodec = state.ActualOutputVideoCodec;
var audioCodec = state.ActualOutputAudioCodec;
var videoCodec = state.ActualOutputVideoCodec;

_sessionManager.ReportTranscodingInfo(deviceId, new TranscodingInfo
Expand Down Expand Up @@ -274,32 +274,37 @@ public TranscodingJob OnTranscodeBeginRequest(string path, TranscodingJobType ty
return null;
}

job.ActiveRequestCount++;

job.DisposeKillTimer();
OnTranscodeBeginRequest(job);

return job;
}
}

public void OnTranscodeBeginRequest(TranscodingJob job)
{
job.ActiveRequestCount++;

job.DisposeKillTimer();
}

public void OnTranscodeEndRequest(TranscodingJob job)
{
job.ActiveRequestCount--;

if (job.ActiveRequestCount == 0)
{
if (job.Type == TranscodingJobType.Progressive)
{
const int timerDuration = 1000;
// TODO: Lower this hls timeout
var timerDuration = job.Type == TranscodingJobType.Progressive ?
1000 :
7200000;

if (job.KillTimer == null)
{
job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
}
else
{
job.KillTimer.Change(timerDuration, Timeout.Infinite);
}
if (job.KillTimer == null)
{
job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
}
else
{
job.KillTimer.Change(timerDuration, Timeout.Infinite);
}
}
}
Expand All @@ -319,10 +324,10 @@ private void OnTranscodeKillTimerStopped(object state)
/// Kills the single transcoding job.
/// </summary>
/// <param name="deviceId">The device id.</param>
/// <param name="streamId">The stream identifier.</param>
/// <param name="playSessionId">The play session identifier.</param>
/// <param name="deleteFiles">The delete files.</param>
/// <returns>Task.</returns>
internal void KillTranscodingJobs(string deviceId, string streamId, Func<string, bool> deleteFiles)
internal void KillTranscodingJobs(string deviceId, string playSessionId, Func<string, bool> deleteFiles)
{
if (string.IsNullOrEmpty(deviceId))
{
Expand All @@ -333,7 +338,7 @@ internal void KillTranscodingJobs(string deviceId, string streamId, Func<string,
{
if (string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase))
{
return string.IsNullOrWhiteSpace(streamId) || string.Equals(streamId, j.StreamId, StringComparison.OrdinalIgnoreCase);
return string.IsNullOrWhiteSpace(playSessionId) || string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase);
}
return false;
Expand Down Expand Up @@ -498,7 +503,7 @@ private void DeleteHlsPartialStreamFiles(string outputFilePath)
.ToList();

Exception e = null;

foreach (var file in filesToDelete)
{
try
Expand Down Expand Up @@ -534,10 +539,10 @@ private void DeleteHlsPartialStreamFiles(string outputFilePath)
public class TranscodingJob
{
/// <summary>
/// Gets or sets the stream identifier.
/// Gets or sets the play session identifier.
/// </summary>
/// <value>The stream identifier.</value>
public string StreamId { get; set; }
/// <value>The play session identifier.</value>
public string PlaySessionId { get; set; }
/// <summary>
/// Gets or sets the path.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions MediaBrowser.Api/BaseApiService.cs
Expand Up @@ -73,6 +73,17 @@ protected object ToOptimizedResultUsingCache<T>(Guid cacheKey, DateTime? lastDat
return ResultFactory.GetOptimizedResultUsingCache(Request, cacheKey, lastDateModified, cacheDuration, factoryFn);
}

/// <summary>
/// Infers the server address from the url
/// </summary>
/// <returns></returns>
protected string GetServerAddress()
{
var index = Request.AbsoluteUri.IndexOf(Request.PathInfo, StringComparison.OrdinalIgnoreCase);

return Request.AbsoluteUri.Substring(0, index);
}

protected void AssertCanUpdateUser(IUserManager userManager, string userId)
{
var auth = AuthorizationContext.GetAuthorizationInfo(Request);
Expand Down

0 comments on commit 67a6edd

Please sign in to comment.