Skip to content

Commit

Permalink
Improve logging (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppaneksamsung authored and GitHub Enterprise committed Jan 4, 2021
1 parent bcd294d commit 045f1c9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
42 changes: 42 additions & 0 deletions JuvoPlayer.TizenTests/Tests/DashPlayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@

namespace JuvoPlayer.TizenTests.Tests
{
public static class PlayerExtensions
{
public static Task<IList<Exception>> AllExceptions(this IPlayer player)
{
return player
.OnEvent()
.OfType<ExceptionEvent>()
.Select(exceptionEvent => exceptionEvent.Exception)
.ToList()
.FirstAsync()
.ToTask();
}
}

[TestFixture]
public class DashPlayerTests
{
Expand Down Expand Up @@ -198,10 +212,12 @@ public void Playback_PlayCalled_PlaysSuccessfully(Clip clip)
RunTest(async () =>
{
IPlayer dashPlayer = null;
Task<IList<Exception>> exceptions = null;
try
{
var stopwatch = Stopwatch.StartNew();
dashPlayer = BuildPlayer(clip);
exceptions = dashPlayer.AllExceptions();
await dashPlayer.Prepare();
_logger.Info($"After prepare {stopwatch.Elapsed}");
dashPlayer.Play();
Expand All @@ -215,6 +231,11 @@ public void Playback_PlayCalled_PlaysSuccessfully(Clip clip)
{
if (dashPlayer != null)
await dashPlayer.DisposeAsync();
if (exceptions != null)
{
foreach (var exception in await exceptions)
_logger.Error(exception);
}
}
});
}
Expand All @@ -227,13 +248,15 @@ public void Playback_StartFrom20thSecond_PlaysSuccessfully(Clip clip)
RunTest(async () =>
{
IPlayer dashPlayer = null;
Task<IList<Exception>> exceptions = null;
try
{
var configuration =
new Configuration {StartTime = TimeSpan.FromSeconds(20)};
dashPlayer = BuildPlayer(
clip,
configuration);
exceptions = dashPlayer.AllExceptions();
await dashPlayer.Prepare();
dashPlayer.Play();
await Task.Delay(TimeSpan.FromSeconds(2));
Expand All @@ -246,6 +269,11 @@ public void Playback_StartFrom20thSecond_PlaysSuccessfully(Clip clip)
{
if (dashPlayer != null)
await dashPlayer.DisposeAsync();
if (exceptions != null)
{
foreach (var exception in await exceptions)
_logger.Error(exception);
}
}
});
}
Expand All @@ -256,10 +284,12 @@ private async Task SeekTest(
Func<TimeSpan, IEnumerable<TimeSpan>> generator)
{
IPlayer dashPlayer = null;
Task<IList<Exception>> exceptions = null;
try
{
var stopwatch = Stopwatch.StartNew();
dashPlayer = BuildPlayer(clip);
exceptions = dashPlayer.AllExceptions();
await dashPlayer.Prepare();
var duration = dashPlayer.Duration;
if (duration == null)
Expand Down Expand Up @@ -301,6 +331,11 @@ private async Task SeekTest(
{
if (dashPlayer != null)
await dashPlayer.DisposeAsync();
if (exceptions != null)
{
foreach (var exception in await exceptions)
_logger.Error(exception);
}
}
}

Expand Down Expand Up @@ -342,9 +377,11 @@ private async Task SetStreamGroupsTest(
Func<StreamGroup[], (StreamGroup[], IStreamSelector[])[]> generator)
{
IPlayer dashPlayer = null;
Task<IList<Exception>> exceptions = null;
try
{
dashPlayer = BuildPlayer(clip);
exceptions = dashPlayer.AllExceptions();
await dashPlayer.Prepare();
dashPlayer.Play();
await Task.Delay(TimeSpan.FromSeconds(3));
Expand All @@ -368,6 +405,11 @@ await dashPlayer.SetStreamGroups(
{
if (dashPlayer != null)
await dashPlayer.DisposeAsync();
if (exceptions != null)
{
foreach (var exception in await exceptions)
_logger.Error(exception);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion JuvoPlayer/Dash/DataChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/

using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using JuvoLogger;
Expand Down Expand Up @@ -65,6 +66,7 @@ public DataChunk(

public async Task Load()
{
var stopwatch = Stopwatch.StartNew();
_logger.Info($"{_uri} {_start} {_length} starts");
try
{
Expand All @@ -84,7 +86,8 @@ await _downloader.Download(
_demuxerClient.Offset += _downloaded;
}

_logger.Info($"{_uri} {_start} {_length} ends");
_logger.Info($"{_uri} {_start} {_length} ends. " +
$"Loading took {stopwatch.ElapsedMilliseconds} ms");
}
}

Expand Down
5 changes: 4 additions & 1 deletion JuvoPlayer/Dash/IndexChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using JuvoLogger;
Expand Down Expand Up @@ -60,6 +61,7 @@ public IndexChunk(

public async Task Load()
{
var stopwatch = Stopwatch.StartNew();
try
{
_logger.Info($"{_indexUri} {_start} {_length} starts");
Expand Down Expand Up @@ -98,7 +100,8 @@ public async Task Load()
}
finally
{
_logger.Info($"{_indexUri} {_start} {_length} ends");
_logger.Info($"{_indexUri} {_start} {_length} ends. " +
$"Loading took {stopwatch.ElapsedMilliseconds} ms");
}
}

Expand Down
5 changes: 4 additions & 1 deletion JuvoPlayer/Dash/InitializationChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using JuvoLogger;
Expand Down Expand Up @@ -66,6 +67,7 @@ public InitializationChunk(

public async Task Load()
{
var stopwatch = Stopwatch.StartNew();
try
{
_logger.Info($"{_initUri} {_start} {_length} starts");
Expand All @@ -91,7 +93,8 @@ await _downloader.Download(
_demuxerClient.Offset += _downloaded;
}

_logger.Info($"{_initUri} {_start} {_length} ends");
_logger.Info($"{_initUri} {_start} {_length} ends. " +
$"Loading took {stopwatch.ElapsedMilliseconds} ms");
}
}

Expand Down
8 changes: 8 additions & 0 deletions JuvoPlayer/Drms/CdmContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
using JuvoLogger;
using JuvoPlayer.Common;

namespace JuvoPlayer.Drms
{
public class CdmContext : IDisposable
{
private readonly ILogger _logger = LoggerManager.GetInstance().GetLogger("JuvoPlayer");
private bool _isDisposed;
private readonly IList<DrmInitData> _drmInitDatas;
private readonly IList<string> _sessionIds;
Expand Down Expand Up @@ -99,6 +101,7 @@ public IObservable<ExceptionEvent> OnException()
private void CreateSessionAndGenerateRequest(DrmInitData drmInitData)
{
var sessionId = _cdmInstance.CreateSession();
_logger.Info($"{nameof(sessionId)} = {sessionId}");
_sessionIds.Add(sessionId);
_cdmInstance.GenerateRequest(
sessionId,
Expand Down Expand Up @@ -131,6 +134,7 @@ private async void AcquireLicenseAndUpdateSession(
string sessionId,
byte[] data)
{
_logger.Info($"{nameof(sessionId)} = {sessionId}");
byte[] response;
try
{
Expand All @@ -140,12 +144,14 @@ private async void AcquireLicenseAndUpdateSession(
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to acquire a license ({nameof(sessionId)} = {sessionId})");
_exceptionSubject.OnNext(new ExceptionEvent(ex));
throw;
}

if (_isDisposed)
return;
_logger.Info( $"Updating session ({nameof(sessionId)} = {sessionId})");
_cdmInstance.UpdateSession(
sessionId,
response);
Expand All @@ -161,6 +167,8 @@ public void Dispose()
CloseAllSessions();
_cdmInstance?.Dispose();
_onMessageSubscription?.Dispose();
_exceptionSubject.OnCompleted();
_exceptionSubject.Dispose();
}
finally
{
Expand Down
4 changes: 3 additions & 1 deletion JuvoPlayer/Drms/CdmInstanceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace JuvoPlayer.Drms
public class CdmInstanceWrapper : ICdmInstance
{
private readonly ICdmInstance _impl;
private readonly ISubject<ExceptionEvent> _exceptionSubject;
private readonly Subject<ExceptionEvent> _exceptionSubject;

public CdmInstanceWrapper(ICdmInstance impl)
{
Expand All @@ -40,6 +40,8 @@ public void Dispose()
{
Intercept(() =>
_impl.Dispose());
_exceptionSubject.OnCompleted();
_exceptionSubject.Dispose();
}

public string CreateSession()
Expand Down
1 change: 1 addition & 0 deletions JuvoPlayer/Players/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ public async Task DisposeAsync()
_platformPlayerEosSubscription?.Dispose();
_platformPlayer?.Dispose();
_cdmContext?.Dispose();
_eventSubject.OnCompleted();
_eventSubject.Dispose();
}

Expand Down

0 comments on commit 045f1c9

Please sign in to comment.