parent
5487dfc145
commit
e10799e0e8
@ -0,0 +1,171 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.Session;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PausedGroupState.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Class is not thread-safe, external locking is required when accessing methods.
|
||||
/// </remarks>
|
||||
public class PausedGroupState : SyncPlayAbstractState
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override GroupState GetGroupState()
|
||||
{
|
||||
return GroupState.Paused;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, PlayGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
// Change state
|
||||
var playingState = new PlayingGroupState();
|
||||
context.SetState(playingState);
|
||||
return playingState.HandleRequest(context, true, request, session, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, PauseGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
if (newState)
|
||||
{
|
||||
GroupInfo group = context.GetGroup();
|
||||
|
||||
// Pause group and compute the media playback position
|
||||
var currentTime = DateTime.UtcNow;
|
||||
var elapsedTime = currentTime - group.LastActivity;
|
||||
group.LastActivity = currentTime;
|
||||
// Seek only if playback actually started
|
||||
// Pause request may be issued during the delay added to account for latency
|
||||
group.PositionTicks += elapsedTime.Ticks > 0 ? elapsedTime.Ticks : 0;
|
||||
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Pause);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.AllGroup, command, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Client got lost, sending current state
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Pause);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.CurrentSession, command, cancellationToken);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, SeekGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
GroupInfo group = context.GetGroup();
|
||||
|
||||
// Sanitize PositionTicks
|
||||
var ticks = context.SanitizePositionTicks(request.PositionTicks);
|
||||
|
||||
// Seek
|
||||
group.PositionTicks = ticks;
|
||||
group.LastActivity = DateTime.UtcNow;
|
||||
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Seek);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.AllGroup, command, cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, BufferGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
GroupInfo group = context.GetGroup();
|
||||
|
||||
if (newState)
|
||||
{
|
||||
// Pause group and compute the media playback position
|
||||
var currentTime = DateTime.UtcNow;
|
||||
var elapsedTime = currentTime - group.LastActivity;
|
||||
group.LastActivity = currentTime;
|
||||
group.PositionTicks += elapsedTime.Ticks > 0 ? elapsedTime.Ticks : 0;
|
||||
|
||||
group.SetBuffering(session, true);
|
||||
|
||||
// Send pause command to all non-buffering sessions
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Pause);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.AllReady, command, cancellationToken);
|
||||
|
||||
var updateOthers = context.NewSyncPlayGroupUpdate(GroupUpdateType.GroupWait, session.UserName);
|
||||
context.SendGroupUpdate(session, SyncPlayBroadcastType.AllExceptCurrentSession, updateOthers, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: no idea?
|
||||
// group.SetBuffering(session, true);
|
||||
|
||||
// Client got lost, sending current state
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Pause);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.CurrentSession, command, cancellationToken);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, ReadyGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
GroupInfo group = context.GetGroup();
|
||||
|
||||
group.SetBuffering(session, false);
|
||||
|
||||
var requestTicks = context.SanitizePositionTicks(request.PositionTicks);
|
||||
|
||||
var currentTime = DateTime.UtcNow;
|
||||
var elapsedTime = currentTime - request.When;
|
||||
var clientPosition = TimeSpan.FromTicks(requestTicks) + elapsedTime;
|
||||
var delay = group.PositionTicks - clientPosition.Ticks;
|
||||
|
||||
if (group.IsBuffering())
|
||||
{
|
||||
// Others are still buffering, tell this client to pause when ready
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Pause);
|
||||
var pauseAtTime = currentTime.AddMilliseconds(delay);
|
||||
command.When = context.DateToUTCString(pauseAtTime);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.CurrentSession, command, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Let other clients resume as soon as the buffering client catches up
|
||||
if (delay > group.GetHighestPing() * 2)
|
||||
{
|
||||
// Client that was buffering is recovering, notifying others to resume
|
||||
group.LastActivity = currentTime.AddMilliseconds(
|
||||
delay
|
||||
);
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Play);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.AllExceptCurrentSession, command, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Client, that was buffering, resumed playback but did not update others in time
|
||||
delay = Math.Max(group.GetHighestPing() * 2, group.DefaultPing);
|
||||
|
||||
group.LastActivity = currentTime.AddMilliseconds(
|
||||
delay
|
||||
);
|
||||
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Play);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.AllGroup, command, cancellationToken);
|
||||
}
|
||||
|
||||
// Change state
|
||||
var playingState = new PlayingGroupState();
|
||||
context.SetState(playingState);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.Session;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PlayingGroupState.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Class is not thread-safe, external locking is required when accessing methods.
|
||||
/// </remarks>
|
||||
public class PlayingGroupState : SyncPlayAbstractState
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override GroupState GetGroupState()
|
||||
{
|
||||
return GroupState.Playing;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, PlayGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
GroupInfo group = context.GetGroup();
|
||||
|
||||
if (newState)
|
||||
{
|
||||
// Pick a suitable time that accounts for latency
|
||||
var delay = Math.Max(group.GetHighestPing() * 2, group.DefaultPing);
|
||||
|
||||
// Unpause group and set starting point in future
|
||||
// Clients will start playback at LastActivity (datetime) from PositionTicks (playback position)
|
||||
// The added delay does not guarantee, of course, that the command will be received in time
|
||||
// Playback synchronization will mainly happen client side
|
||||
group.LastActivity = DateTime.UtcNow.AddMilliseconds(
|
||||
delay
|
||||
);
|
||||
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Play);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.AllGroup, command, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Client got lost, sending current state
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Play);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.CurrentSession, command, cancellationToken);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, PauseGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
// Change state
|
||||
var pausedState = new PausedGroupState();
|
||||
context.SetState(pausedState);
|
||||
return pausedState.HandleRequest(context, true, request, session, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, SeekGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
// Change state
|
||||
var pausedState = new PausedGroupState();
|
||||
context.SetState(pausedState);
|
||||
return pausedState.HandleRequest(context, true, request, session, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, BufferGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
// Change state
|
||||
var pausedState = new PausedGroupState();
|
||||
context.SetState(pausedState);
|
||||
return pausedState.HandleRequest(context, true, request, session, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool HandleRequest(ISyncPlayStateContext context, bool newState, ReadyGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
// Group was not waiting, make sure client has latest state
|
||||
var command = context.NewSyncPlayCommand(SendCommandType.Play);
|
||||
context.SendCommand(session, SyncPlayBroadcastType.CurrentSession, command, cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Threading;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface IPlaybackGroupRequest.
|
||||
/// </summary>
|
||||
public interface IPlaybackGroupRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the playback request type.
|
||||
/// </summary>
|
||||
/// <value>The playback request type.</value>
|
||||
PlaybackRequestType Type();
|
||||
|
||||
/// <summary>
|
||||
/// Applies the request to a group.
|
||||
/// </summary>
|
||||
/// <value>The operation completion status.</value>
|
||||
bool Apply(ISyncPlayStateContext context, ISyncPlayState state, SessionInfo session, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
using System.Threading;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface ISyncPlayState.
|
||||
/// </summary>
|
||||
public interface ISyncPlayState
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the group state.
|
||||
/// </summary>
|
||||
/// <value>The group state.</value>
|
||||
GroupState GetGroupState();
|
||||
|
||||
/// <summary>
|
||||
/// Generic handle. Context's state can change.
|
||||
/// </summary>
|
||||
/// <param name="context">The context of the state.</param>
|
||||
/// <param name="newState">Whether the state has been just set.</param>
|
||||
/// <param name="request">The play action.</param>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <value>The operation completion status.</value>
|
||||
bool HandleRequest(ISyncPlayStateContext context, bool newState, IPlaybackGroupRequest request, SessionInfo session, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Handles a play action requested by a session. Context's state can change.
|
||||
/// </summary>
|
||||
/// <param name="context">The context of the state.</param>
|
||||
/// <param name="newState">Whether the state has been just set.</param>
|
||||
/// <param name="request">The play action.</param>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <value>The operation completion status.</value>
|
||||
bool HandleRequest(ISyncPlayStateContext context, bool newState, PlayGroupRequest request, SessionInfo session, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Handles a pause action requested by a session. Context's state can change.
|
||||
/// </summary>
|
||||
/// <param name="context">The context of the state.</param>
|
||||
/// <param name="newState">Whether the state has been just set.</param>
|
||||
/// <param name="request">The pause action.</param>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <value>The operation completion status.</value>
|
||||
bool HandleRequest(ISyncPlayStateContext context, bool newState, PauseGroupRequest request, SessionInfo session, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Handles a seek action requested by a session. Context's state can change.
|
||||
/// </summary>
|
||||
/// <param name="context">The context of the state.</param>
|
||||
/// <param name="newState">Whether the state has been just set.</param>
|
||||
/// <param name="request">The seek action.</param>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <value>The operation completion status.</value>
|
||||
bool HandleRequest(ISyncPlayStateContext context, bool newState, SeekGroupRequest request, SessionInfo session, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Handles a buffering action requested by a session. Context's state can change.
|
||||
/// </summary>
|
||||
/// <param name="context">The context of the state.</param>
|
||||
/// <param name="newState">Whether the state has been just set.</param>
|
||||
/// <param name="request">The buffering action.</param>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <value>The operation completion status.</value>
|
||||
bool HandleRequest(ISyncPlayStateContext context, bool newState, BufferGroupRequest request, SessionInfo session, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Handles a buffering-done action requested by a session. Context's state can change.
|
||||
/// </summary>
|
||||
/// <param name="context">The context of the state.</param>
|
||||
/// <param name="newState">Whether the state has been just set.</param>
|
||||
/// <param name="request">The buffering-done action.</param>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <value>The operation completion status.</value>
|
||||
bool HandleRequest(ISyncPlayStateContext context, bool newState, ReadyGroupRequest request, SessionInfo session, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates ping of a session. Context's state should not change.
|
||||
/// </summary>
|
||||
/// <param name="context">The context of the state.</param>
|
||||
/// <param name="newState">Whether the state has been just set.</param>
|
||||
/// <param name="request">The buffering-done action.</param>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <value>The operation completion status.</value>
|
||||
bool HandleRequest(ISyncPlayStateContext context, bool newState, PingGroupRequest request, SessionInfo session, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface ISyncPlayStateContext.
|
||||
/// </summary>
|
||||
public interface ISyncPlayStateContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the context's group.
|
||||
/// </summary>
|
||||
/// <value>The group.</value>
|
||||
GroupInfo GetGroup();
|
||||
|
||||
/// <summary>
|
||||
/// Sets a new state.
|
||||
/// </summary>
|
||||
/// <param name="state">The new state.</param>
|
||||
void SetState(ISyncPlayState state);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GroupUpdate message to the interested sessions.
|
||||
/// </summary>
|
||||
/// <param name="from">The current session.</param>
|
||||
/// <param name="type">The filtering type.</param>
|
||||
/// <param name="message">The message to send.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <value>The task.</value>
|
||||
Task SendGroupUpdate<T>(SessionInfo from, SyncPlayBroadcastType type, GroupUpdate<T> message, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a playback command to the interested sessions.
|
||||
/// </summary>
|
||||
/// <param name="from">The current session.</param>
|
||||
/// <param name="type">The filtering type.</param>
|
||||
/// <param name="message">The message to send.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <value>The task.</value>
|
||||
Task SendCommand(SessionInfo from, SyncPlayBroadcastType type, SendCommand message, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Builds a new playback command with some default values.
|
||||
/// </summary>
|
||||
/// <param name="type">The command type.</param>
|
||||
/// <value>The SendCommand.</value>
|
||||
SendCommand NewSyncPlayCommand(SendCommandType type);
|
||||
|
||||
/// <summary>
|
||||
/// Builds a new group update message.
|
||||
/// </summary>
|
||||
/// <param name="type">The update type.</param>
|
||||
/// <param name="data">The data to send.</param>
|
||||
/// <value>The GroupUpdate.</value>
|
||||
GroupUpdate<T> NewSyncPlayGroupUpdate<T>(GroupUpdateType type, T data);
|
||||
|
||||
/// <summary>
|
||||
/// Converts DateTime to UTC string.
|
||||
/// </summary>
|
||||
/// <param name="date">The date to convert.</param>
|
||||
/// <value>The UTC string.</value>
|
||||
string DateToUTCString(DateTime date);
|
||||
|
||||
/// <summary>
|
||||
/// Sanitizes the PositionTicks, considers the current playing item when available.
|
||||
/// </summary>
|
||||
/// <param name="positionTicks">The PositionTicks.</param>
|
||||
/// <value>The sanitized PositionTicks.</value>
|
||||
long SanitizePositionTicks(long? positionTicks);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class BufferingGroupRequest.
|
||||
/// </summary>
|
||||
public class BufferGroupRequest : IPlaybackGroupRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets when the request has been made by the client.
|
||||
/// </summary>
|
||||
/// <value>The date of the request.</value>
|
||||
public DateTime When { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the position ticks.
|
||||
/// </summary>
|
||||
/// <value>The position ticks.</value>
|
||||
public long PositionTicks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the playing item id.
|
||||
/// </summary>
|
||||
/// <value>The playing item id.</value>
|
||||
public Guid PlayingItemId { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public PlaybackRequestType Type()
|
||||
{
|
||||
return PlaybackRequestType.Buffer;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Apply(ISyncPlayStateContext context, ISyncPlayState state, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return state.HandleRequest(context, false, this, session, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Threading;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PauseGroupRequest.
|
||||
/// </summary>
|
||||
public class PauseGroupRequest : IPlaybackGroupRequest
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public PlaybackRequestType Type()
|
||||
{
|
||||
return PlaybackRequestType.Pause;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Apply(ISyncPlayStateContext context, ISyncPlayState state, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return state.HandleRequest(context, false, this, session, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System.Threading;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
||||
// FIXME: not really group related, can be moved up to SyncPlayController maybe?
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class UpdatePingGroupRequest.
|
||||
/// </summary>
|
||||
public class PingGroupRequest : IPlaybackGroupRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the ping time.
|
||||
/// </summary>
|
||||
/// <value>The ping time.</value>
|
||||
public long Ping { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public PlaybackRequestType Type()
|
||||
{
|
||||
return PlaybackRequestType.Ping;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Apply(ISyncPlayStateContext context, ISyncPlayState state, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return state.HandleRequest(context, false, this, session, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Threading;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PlayGroupRequest.
|
||||
/// </summary>
|
||||
public class PlayGroupRequest : IPlaybackGroupRequest
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public PlaybackRequestType Type()
|
||||
{
|
||||
return PlaybackRequestType.Play;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Apply(ISyncPlayStateContext context, ISyncPlayState state, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return state.HandleRequest(context, false, this, session, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class BufferingDoneGroupRequest.
|
||||
/// </summary>
|
||||
public class ReadyGroupRequest : IPlaybackGroupRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets when the request has been made by the client.
|
||||
/// </summary>
|
||||
/// <value>The date of the request.</value>
|
||||
public DateTime When { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the position ticks.
|
||||
/// </summary>
|
||||
/// <value>The position ticks.</value>
|
||||
public long PositionTicks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the playing item id.
|
||||
/// </summary>
|
||||
/// <value>The playing item id.</value>
|
||||
public Guid PlayingItemId { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public PlaybackRequestType Type()
|
||||
{
|
||||
return PlaybackRequestType.Ready;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Apply(ISyncPlayStateContext context, ISyncPlayState state, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return state.HandleRequest(context, false, this, session, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using System.Threading;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
using MediaBrowser.Controller.Session;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class SeekGroupRequest.
|
||||
/// </summary>
|
||||
public class SeekGroupRequest : IPlaybackGroupRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the position ticks.
|
||||
/// </summary>
|
||||
/// <value>The position ticks.</value>
|
||||
public long PositionTicks { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public PlaybackRequestType Type()
|
||||
{
|
||||
return PlaybackRequestType.Seek;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Apply(ISyncPlayStateContext context, ISyncPlayState state, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return state.HandleRequest(context, false, this, session, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
using System.Threading;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.SyncPlay;
|
||||
|
||||
namespace MediaBrowser.Controller.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class SyncPlayAbstractState.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Class is not thread-safe, external locking is required when accessing methods.
|
||||
/// </remarks>
|
||||
public abstract class SyncPlayAbstractState : ISyncPlayState
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public abstract GroupState GetGroupState();
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool HandleRequest(ISyncPlayStateContext context, bool newState, IPlaybackGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool HandleRequest(ISyncPlayStateContext context, bool newState, PlayGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool HandleRequest(ISyncPlayStateContext context, bool newState, PauseGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool HandleRequest(ISyncPlayStateContext context, bool newState, SeekGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool HandleRequest(ISyncPlayStateContext context, bool newState, BufferGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool HandleRequest(ISyncPlayStateContext context, bool newState, ReadyGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool HandleRequest(ISyncPlayStateContext context, bool newState, PingGroupRequest request, SessionInfo session, CancellationToken cancellationToken)
|
||||
{
|
||||
GroupInfo group = context.GetGroup();
|
||||
|
||||
// Collected pings are used to account for network latency when unpausing playback
|
||||
group.UpdatePing(session, request.Ping);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
namespace MediaBrowser.Model.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum GroupState.
|
||||
/// </summary>
|
||||
public enum GroupState
|
||||
{
|
||||
/// <summary>
|
||||
/// The group is in idle state. No media is playing.
|
||||
/// </summary>
|
||||
Idle,
|
||||
/// <summary>
|
||||
/// The group is in wating state. Playback is paused. Will start playing when users are ready.
|
||||
/// </summary>
|
||||
Waiting,
|
||||
/// <summary>
|
||||
/// The group is in paused state. Playback is paused. Will resume on play command.
|
||||
/// </summary>
|
||||
Paused,
|
||||
/// <summary>
|
||||
/// The group is in playing state. Playback is advancing.
|
||||
/// </summary>
|
||||
Playing
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Model.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PlaybackRequest.
|
||||
/// </summary>
|
||||
public class PlaybackRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the request type.
|
||||
/// </summary>
|
||||
/// <value>The request type.</value>
|
||||
public PlaybackRequestType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets when the request has been made by the client.
|
||||
/// </summary>
|
||||
/// <value>The date of the request.</value>
|
||||
public DateTime? When { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the position ticks.
|
||||
/// </summary>
|
||||
/// <value>The position ticks.</value>
|
||||
public long? PositionTicks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ping time.
|
||||
/// </summary>
|
||||
/// <value>The ping time.</value>
|
||||
public long? Ping { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
namespace MediaBrowser.Model.SyncPlay
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to filter the sessions of a group.
|
||||
/// </summary>
|
||||
public enum SyncPlayBroadcastType
|
||||
{
|
||||
/// <summary>
|
||||
/// All sessions will receive the message.
|
||||
/// </summary>
|
||||
AllGroup = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Only the specified session will receive the message.
|
||||
/// </summary>
|
||||
CurrentSession = 1,
|
||||
|
||||
/// <summary>
|
||||
/// All sessions, except the current one, will receive the message.
|
||||
/// </summary>
|
||||
AllExceptCurrentSession = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Only sessions that are not buffering will receive the message.
|
||||
/// </summary>
|
||||
AllReady = 3
|
||||
}
|
||||
}
|
Loading…
Reference in new issue