Skip to content

Commit

Permalink
update hls attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Jan 28, 2018
1 parent 127e444 commit 0cc6259
Show file tree
Hide file tree
Showing 131 changed files with 899 additions and 1,454 deletions.
4 changes: 2 additions & 2 deletions BDInfo/BDROM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public delegate bool OnPlaylistFileScanError(
public BDROM(
string path, IFileSystem fileSystem, ITextEncoding textEncoding)
{
if (string.IsNullOrWhiteSpace(path))
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
Expand Down Expand Up @@ -334,7 +334,7 @@ public void Scan()
private FileSystemMetadata GetDirectoryBDMV(
string path)
{
if (string.IsNullOrWhiteSpace(path))
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
Expand Down
28 changes: 14 additions & 14 deletions Emby.Dlna/DlnaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,55 +132,55 @@ private void LogUnmatchedProfile(DeviceIdentification profile)

private bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo)
{
if (!string.IsNullOrWhiteSpace(profileInfo.DeviceDescription))
if (!string.IsNullOrEmpty(profileInfo.DeviceDescription))
{
if (deviceInfo.DeviceDescription == null || !IsRegexMatch(deviceInfo.DeviceDescription, profileInfo.DeviceDescription))
return false;
}

if (!string.IsNullOrWhiteSpace(profileInfo.FriendlyName))
if (!string.IsNullOrEmpty(profileInfo.FriendlyName))
{
if (deviceInfo.FriendlyName == null || !IsRegexMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName))
return false;
}

if (!string.IsNullOrWhiteSpace(profileInfo.Manufacturer))
if (!string.IsNullOrEmpty(profileInfo.Manufacturer))
{
if (deviceInfo.Manufacturer == null || !IsRegexMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer))
return false;
}

if (!string.IsNullOrWhiteSpace(profileInfo.ManufacturerUrl))
if (!string.IsNullOrEmpty(profileInfo.ManufacturerUrl))
{
if (deviceInfo.ManufacturerUrl == null || !IsRegexMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl))
return false;
}

if (!string.IsNullOrWhiteSpace(profileInfo.ModelDescription))
if (!string.IsNullOrEmpty(profileInfo.ModelDescription))
{
if (deviceInfo.ModelDescription == null || !IsRegexMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription))
return false;
}

if (!string.IsNullOrWhiteSpace(profileInfo.ModelName))
if (!string.IsNullOrEmpty(profileInfo.ModelName))
{
if (deviceInfo.ModelName == null || !IsRegexMatch(deviceInfo.ModelName, profileInfo.ModelName))
return false;
}

if (!string.IsNullOrWhiteSpace(profileInfo.ModelNumber))
if (!string.IsNullOrEmpty(profileInfo.ModelNumber))
{
if (deviceInfo.ModelNumber == null || !IsRegexMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber))
return false;
}

if (!string.IsNullOrWhiteSpace(profileInfo.ModelUrl))
if (!string.IsNullOrEmpty(profileInfo.ModelUrl))
{
if (deviceInfo.ModelUrl == null || !IsRegexMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl))
return false;
}

if (!string.IsNullOrWhiteSpace(profileInfo.SerialNumber))
if (!string.IsNullOrEmpty(profileInfo.SerialNumber))
{
if (deviceInfo.SerialNumber == null || !IsRegexMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber))
return false;
Expand Down Expand Up @@ -235,7 +235,7 @@ private bool IsMatch(IDictionary<string, string> headers, DeviceIdentification p
private bool IsMatch(IDictionary<string, string> headers, HttpHeaderInfo header)
{
// Handle invalid user setup
if (string.IsNullOrWhiteSpace(header.Name))
if (string.IsNullOrEmpty(header.Name))
{
return false;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ private DeviceProfile ParseProfileFile(string path, DeviceProfileType type)

public DeviceProfile GetProfile(string id)
{
if (string.IsNullOrWhiteSpace(id))
if (string.IsNullOrEmpty(id))
{
throw new ArgumentNullException("id");
}
Expand Down Expand Up @@ -429,7 +429,7 @@ public void CreateProfile(DeviceProfile profile)
{
profile = ReserializeProfile(profile);

if (string.IsNullOrWhiteSpace(profile.Name))
if (string.IsNullOrEmpty(profile.Name))
{
throw new ArgumentException("Profile is missing Name");
}
Expand All @@ -444,11 +444,11 @@ public void UpdateProfile(DeviceProfile profile)
{
profile = ReserializeProfile(profile);

if (string.IsNullOrWhiteSpace(profile.Id))
if (string.IsNullOrEmpty(profile.Id))
{
throw new ArgumentException("Profile is missing Id");
}
if (string.IsNullOrWhiteSpace(profile.Name))
if (string.IsNullOrEmpty(profile.Name))
{
throw new ArgumentException("Profile is missing Name");
}
Expand Down
2 changes: 1 addition & 1 deletion Emby.Dlna/Eventing/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private EventSubscriptionResponse GetEventSubscriptionResponse(string subscripti
};

response.Headers["SID"] = subscriptionId;
response.Headers["TIMEOUT"] = string.IsNullOrWhiteSpace(requestedTimeoutString) ? ("SECOND-" + timeoutSeconds.ToString(_usCulture)) : requestedTimeoutString;
response.Headers["TIMEOUT"] = string.IsNullOrEmpty(requestedTimeoutString) ? ("SECOND-" + timeoutSeconds.ToString(_usCulture)) : requestedTimeoutString;

return response;
}
Expand Down
94 changes: 27 additions & 67 deletions Emby.Dlna/PlayTo/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,17 @@ public Device(DeviceInfo deviceProperties, IHttpClient httpClient, ILogger logge
_timerFactory = timerFactory;
}

private int GetPlaybackTimerIntervalMs()
{
return 1000;
}

private int GetInactiveTimerIntervalMs()
{
return 60000;
}

public void Start()
{
_timer = _timerFactory.Create(TimerCallback, null, GetPlaybackTimerIntervalMs(), GetInactiveTimerIntervalMs());

_timerActive = false;
_logger.Debug("Dlna Device.Start");
_timer = _timerFactory.Create(TimerCallback, null, 1000, Timeout.Infinite);
}

private DateTime _lastVolumeRefresh;
private bool _volumeRefreshActive;
private void RefreshVolumeIfNeeded()
{
if (!_timerActive)
if (!_volumeRefreshActive)
{
return;
}
Expand Down Expand Up @@ -155,21 +145,17 @@ private async void RefreshVolume(CancellationToken cancellationToken)
}

private readonly object _timerLock = new object();
private bool _timerActive;
private void RestartTimer()
private void RestartTimer(bool immediate = false)
{
if (_disposed)
return;

lock (_timerLock)
{
if (!_timerActive)
{
_logger.Debug("RestartTimer");
_timer.Change(10, GetPlaybackTimerIntervalMs());
}
if (_disposed)
return;

_timerActive = true;
_volumeRefreshActive = true;

var time = immediate ? 100 : 10000;
_timer.Change(time, Timeout.Infinite);
}
}

Expand All @@ -183,18 +169,9 @@ private void RestartTimerInactive()
if (_disposed)
return;

if (_timerActive)
{
_logger.Debug("RestartTimerInactive");
var interval = GetInactiveTimerIntervalMs();
_volumeRefreshActive = false;

if (_timer != null)
{
_timer.Change(interval, interval);
}
}

_timerActive = false;
_timer.Change(Timeout.Infinite, Timeout.Infinite);
}
}

Expand Down Expand Up @@ -331,6 +308,8 @@ public async Task Seek(TimeSpan value, CancellationToken cancellationToken)

await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, avCommands.BuildPost(command, service.ServiceType, String.Format("{0:hh}:{0:mm}:{0:ss}", value), "REL_TIME"))
.ConfigureAwait(false);

RestartTimer(true);
}

public async Task SetAvTransport(string url, string header, string metaData, CancellationToken cancellationToken)
Expand Down Expand Up @@ -372,7 +351,7 @@ public async Task SetAvTransport(string url, string header, string metaData, Can
// Others won't
}

RestartTimer();
RestartTimer(true);
}

private string CreateDidlMeta(string value)
Expand Down Expand Up @@ -404,6 +383,8 @@ public async Task SetPlay(CancellationToken cancellationToken)
var avCommands = await GetAVProtocolAsync(cancellationToken).ConfigureAwait(false);

await SetPlay(avCommands, cancellationToken).ConfigureAwait(false);

RestartTimer(true);
}

public async Task SetStop(CancellationToken cancellationToken)
Expand All @@ -418,6 +399,8 @@ public async Task SetStop(CancellationToken cancellationToken)

await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, avCommands.BuildPost(command, service.ServiceType, 1))
.ConfigureAwait(false);

RestartTimer(true);
}

public async Task SetPause(CancellationToken cancellationToken)
Expand All @@ -434,21 +417,20 @@ public async Task SetPause(CancellationToken cancellationToken)
.ConfigureAwait(false);

TransportState = TRANSPORTSTATE.PAUSED;

RestartTimer(true);
}

#endregion

#region Get data

private int _successiveStopCount;
private int _connectFailureCount;
private async void TimerCallback(object sender)
{
if (_disposed)
return;

const int maxSuccessiveStopReturns = 5;

try
{
var cancellationToken = CancellationToken.None;
Expand Down Expand Up @@ -496,16 +478,10 @@ private async void TimerCallback(object sender)
// If we're not playing anything make sure we don't get data more often than neccessry to keep the Session alive
if (transportState.Value == TRANSPORTSTATE.STOPPED)
{
_successiveStopCount++;

if (_successiveStopCount >= maxSuccessiveStopReturns)
{
RestartTimerInactive();
}
RestartTimerInactive();
}
else
{
_successiveStopCount = 0;
RestartTimer();
}
}
Expand All @@ -514,14 +490,13 @@ private async void TimerCallback(object sender)
RestartTimerInactive();
}
}
catch (HttpException)
catch (Exception ex)
{
if (_disposed)
return;

//_logger.ErrorException("Error updating device info for {0}", ex, Properties.Name);

_successiveStopCount++;
_connectFailureCount++;

if (_connectFailureCount >= 3)
Expand All @@ -534,24 +509,7 @@ private async void TimerCallback(object sender)
return;
}
}
if (_successiveStopCount >= maxSuccessiveStopReturns)
{
RestartTimerInactive();
}
}
catch (Exception ex)
{
if (_disposed)
return;

_logger.ErrorException("Error updating device info for {0}", ex, Properties.Name);

_successiveStopCount++;

if (_successiveStopCount >= maxSuccessiveStopReturns)
{
RestartTimerInactive();
}
RestartTimerInactive();
}
}

Expand Down Expand Up @@ -885,6 +843,7 @@ private async Task<TransportCommands> GetAVProtocolAsync(CancellationToken cance
string url = NormalizeUrl(Properties.BaseUrl, avService.ScpdUrl);

var httpClient = new SsdpHttpClient(_httpClient, _config);

var document = await httpClient.GetDataAsync(url, cancellationToken).ConfigureAwait(false);

avCommands = TransportCommands.Create(document);
Expand Down Expand Up @@ -916,6 +875,7 @@ private async Task<TransportCommands> GetRenderingProtocolAsync(CancellationToke
string url = NormalizeUrl(Properties.BaseUrl, avService.ScpdUrl);

var httpClient = new SsdpHttpClient(_httpClient, _config);
_logger.Debug("Dlna Device.GetRenderingProtocolAsync");
var document = await httpClient.GetDataAsync(url, cancellationToken).ConfigureAwait(false);

rendererCommands = TransportCommands.Create(document);
Expand Down
Loading

0 comments on commit 0cc6259

Please sign in to comment.