/// Fill out properties of a native media format with the current media format object.
/// </summary>
/// <param name="handle">A native handle to be written.</param>
- protected abstract void AsNativeHandle(IntPtr handle);
+ internal abstract void AsNativeHandle(IntPtr handle);
}
/// <summary>
/// Initializes a new instance of the ContainerMediaFormat class.
/// </summary>
/// <param name="mimeType">The mime type of the container format.</param>
- /// <exception cref="System.ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
+ /// <exception cref="ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
public ContainerMediaFormat(MediaFormatContainerMimeType mimeType)
: base(MediaFormatType.Container)
{
get;
}
- protected override void AsNativeHandle(IntPtr handle)
+ internal override void AsNativeHandle(IntPtr handle)
{
Debug.Assert(Type == MediaFormatType.Container);
public override string ToString()
{
- return $"[{ nameof(ContainerMediaFormat) }] MimeType : { MimeType }";
+ return $"MimeType={ MimeType.ToString() }";
}
public override bool Equals(object obj)
/// <param name="mimeType">The mime type of the format.</param>
/// <param name="width">The width value of the format.</param>
/// <param name="height">The height value of the format</param>
- /// <exception cref="System.ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">width, or height is less than zero.</exception>
+ /// <exception cref="ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
+ /// <exception cref="ArgumentOutOfRangeException">width, or height is less than zero.</exception>
public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height)
: this(mimeType, width, height, DefaultFrameRate)
{
/// </summary>
/// <param name="mimeType">The mime type of the format.</param>
/// <param name="size">The size of the format.</param>
- /// <exception cref="System.ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">width, or height is less than zero.</exception>
+ /// <exception cref="ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
+ /// <exception cref="ArgumentOutOfRangeException">width, or height is less than zero.</exception>
public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size)
: this(mimeType, size, DefaultFrameRate)
{
/// <param name="width">The width value of the format.</param>
/// <param name="height">The height value of the format</param>
/// <param name="frameRate">The frame rate of the format.</param>
- /// <exception cref="System.ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">width, height or frameRate is less than zero.</exception>
+ /// <exception cref="ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
+ /// <exception cref="ArgumentOutOfRangeException">width, height or frameRate is less than zero.</exception>
public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height,
int frameRate)
: this(mimeType, width, height, frameRate, DefaultBitRate)
/// <param name="size">The video size of the format.</param>
/// <param name="height">The height value of the format</param>
/// <param name="frameRate">The frame rate of the format.</param>
- /// <exception cref="System.ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">width, height or frameRate is less than zero.</exception>
+ /// <exception cref="ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
+ /// <exception cref="ArgumentOutOfRangeException">width, height or frameRate is less than zero.</exception>
public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size,
int frameRate)
: this(mimeType, size, frameRate, DefaultBitRate)
/// <param name="height">The height value of the format</param>
/// <param name="frameRate">The frame rate of the format.</param>
/// <param name="bitRate">The bit rate of the format.</param>
- /// <exception cref="System.ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">width, height, frameRate or bitRate is less than zero.</exception>
+ /// <exception cref="ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
+ /// <exception cref="ArgumentOutOfRangeException">width, height, frameRate or bitRate is less than zero.</exception>
public VideoMediaFormat(MediaFormatVideoMimeType mimeType, int width, int height,
int frameRate, int bitRate)
: this(mimeType, new Size(width, height), frameRate, bitRate)
/// <param name="size">The size of the format.</param>
/// <param name="frameRate">The frame rate of the format.</param>
/// <param name="bitRate">The bit rate of the format.</param>
- /// <exception cref="System.ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">width, height, frameRate or bitRate is less than zero.</exception>
+ /// <exception cref="ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
+ /// <exception cref="ArgumentOutOfRangeException">width, height, frameRate or bitRate is less than zero.</exception>
public VideoMediaFormat(MediaFormatVideoMimeType mimeType, Size size,
int frameRate, int bitRate)
: base(MediaFormatType.Video)
MultimediaDebug.AssertNoError(ret);
}
- protected override void AsNativeHandle(IntPtr handle)
+ internal override void AsNativeHandle(IntPtr handle)
{
Debug.Assert(Type == MediaFormatType.Video);
public override string ToString()
{
- return $"MimeType : { MimeType }, Size : ({ Size }), "
- + $"FrameRate : { FrameRate }, BitRate : { BitRate }";
+ return $@"MimeType={ MimeType.ToString() }, Size=({ Size.ToString() }), FrameRate=
+ { FrameRate.ToString() }, BitRate={ BitRate.ToString() }";
}
public override bool Equals(object obj)
/// <param name="sampleRate">The sample rate value of the format.</param>
/// <param name="bit">The bit value of the format.</param>
/// <param name="bitRate">The bit rate value of the format.</param>
- /// <exception cref="System.ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
+ /// <exception cref="ArgumentException">mimeType is invalid(i.e. undefined value).</exception>
+ /// <exception cref="ArgumentOutOfRangeException">
/// channel, sampleRate, bit or bitRate is less than zero.</exception>
public AudioMediaFormat(MediaFormatAudioMimeType mimeType,
int channel, int sampleRate, int bit, int bitRate)
/// <param name="sampleRate">The sample rate value of the format.</param>
/// <param name="bit">The bit value of the format.</param>
/// <param name="bitRate">The bit rate value of the format.</param>
- /// <exception cref="System.ArgumentException">
+ /// <exception cref="ArgumentException">
/// mimeType or aacType is invalid(i.e. undefined value).
/// <para>- or -</para>
/// aacType is not <see cref="MediaFormatAacType.None"/>, but mimeType is one of aac types.
/// </exception>
- /// <exception cref="System.ArgumentOutOfRangeException">
+ /// <exception cref="ArgumentOutOfRangeException">
/// channel, sampleRate, bit or bitRate is less than zero.</exception>
public AudioMediaFormat(MediaFormatAudioMimeType mimeType,
int channel, int sampleRate, int bit, int bitRate, MediaFormatAacType aacType)
Debug.Assert(Enum.IsDefined(typeof(MediaFormatAacType), aacType), "Invalid aac type!");
}
- protected override void AsNativeHandle(IntPtr handle)
+ internal override void AsNativeHandle(IntPtr handle)
{
Debug.Assert(Type == MediaFormatType.Audio);
public override string ToString()
{
- return $"MimeType : {MimeType }, Channel : { Channel }, SampleRate : { SampleRate }, "
- + $"Bit : { Bit }, BitRate : { BitRate }, AacType : { AacType }";
+ return $@"MimeTyp={ MimeType.ToString() }, Channel={ Channel.ToString() }, SampleRate=
+ { SampleRate }, Bit={ Bit.ToString() }, BitRate={ BitRate.ToString() }, AacType={ AacType.ToString() }";
}
public override bool Equals(object obj)
/// </summary>
/// <param name="mimeType">The mime type of the format.</param>
/// <param name="textType">The text type of the format.</param>
- /// <exception cref="System.ArgumentException">
+ /// <exception cref="ArgumentException">
/// mimeType or textType is invalid(i.e. undefined value).</exception>
public TextMediaFormat(MediaFormatTextMimeType mimeType, MediaFormatTextType textType)
: base(MediaFormatType.Text)
"Invalid text type!");
}
- protected override void AsNativeHandle(IntPtr handle)
+ internal override void AsNativeHandle(IntPtr handle)
{
Debug.Assert(Type == MediaFormatType.Text);
public override string ToString()
{
- return $"[{ nameof(TextMediaFormat) }] MimeType : { MimeType }, TextType : { TextType }";
+ return $"MimeType={ MimeType.ToString() }, TextType={ TextType.ToString() }";
}
public override bool Equals(object obj)
{
Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
RegisterSubtitleUpdatedCallback();
- RegisterErrorOccuuredCallback();
+ RegisterErrorOccurredCallback();
RegisterPlaybackInterruptedCallback();
RegisterVideoStreamChangedCallback();
RegisterBufferingCallback();
if (display == null)
{
Log.Info(PlayerLog.Tag, "set display to none");
- return Interop.Player.SetDisplay(_handle, (int)PlayerDisplayType.None, IntPtr.Zero);
+ return Interop.Player.SetDisplay(_handle, PlayerDisplayType.None, IntPtr.Zero);
}
Log.Info(PlayerLog.Tag, "set display to " + display.Type + " (" + display.EvasObject + ")");
Debug.Assert(Enum.IsDefined(typeof(PlayerDisplayType), display.Type));
Debug.Assert(display.EvasObject != null);
- return Interop.Player.SetDisplay(_handle, (int)display.Type, display.EvasObject);
+ return Interop.Player.SetDisplay(_handle, display.Type, display.EvasObject);
}
private void ReplaceDisplay(PlayerDisplay newDisplay)
if (!File.Exists(path))
{
- throw new FileNotFoundException($"The specified file does not exist : { path }.");
+ throw new FileNotFoundException($"The specified file does not exist.", path);
}
PlayerErrorConverter.ThrowIfError(Interop.Player.SetSubtitlePath(_handle, path),
/// <remarks>The player must be in the <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
/// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
/// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
- public Task<CapturedFrame> CaptureVideoAsync()
+ public async Task<CapturedFrame> CaptureVideoAsync()
{
Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
ValidatePlayerState(PlayerState.Playing, PlayerState.Paused);
TaskCompletionSource<CapturedFrame> t = new TaskCompletionSource<CapturedFrame>();
- Interop.Player.VideoCaptureCallback cb = (data, width, height, size, gchPtr) =>
+ Interop.Player.VideoCaptureCallback cb = (data, width, height, size, _) =>
{
Debug.Assert(size <= int.MaxValue);
Marshal.Copy(data, buf, 0, (int)size);
t.TrySetResult(new CapturedFrame(buf, width, height));
-
- GCHandle.FromIntPtr(gchPtr).Free();
};
- var gch = GCHandle.Alloc(cb);
- try
+ using (var cbKeeper = ObjectKeeper.Get(cb))
{
PlayerErrorConverter.ThrowIfError(
- Interop.Player.CaptureVideo(_handle, cb, GCHandle.ToIntPtr(gch)),
+ Interop.Player.CaptureVideo(_handle, cb, IntPtr.Zero),
"Failed to capture the video");
- }
- catch(Exception)
- {
- gch.Free();
- throw;
- }
- Log.Debug(PlayerLog.Tag, PlayerLog.Leave);
- return t.Task;
+ return await t.Task;
+ }
}
/// <summary>
/// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
/// <exception cref="ArgumentOutOfRangeException">The specified position is not valid.</exception>
/// <seealso cref="GetPlayPosition"/>
- public Task SetPlayPositionAsync(int position, bool accurate)
+ public async Task SetPlayPositionAsync(int position, bool accurate)
{
Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
Interop.Player.SeekCompletedCallback cb = _ => taskCompletionSource.TrySetResult(true);
- SetPlayPosition(position, accurate, cb);
- if (immediateResult)
+ using (var cbKeeper = ObjectKeeper.Get(cb))
{
- taskCompletionSource.TrySetResult(true);
+ SetPlayPosition(position, accurate, cb);
+ if (immediateResult)
+ {
+ taskCompletionSource.TrySetResult(true);
+ }
+
+ await taskCompletionSource.Task;
}
Log.Debug(PlayerLog.Tag, PlayerLog.Leave);
-
- return taskCompletionSource.Task;
}
/// <summary>
PlayerErrorConverter.ThrowIfError(ret, "Failed to set PlaybackInterrupted");
}
- private void RegisterErrorOccuuredCallback()
+ private void RegisterErrorOccurredCallback()
{
_playbackErrorCallback = (code, _) =>
{
{
Log.Debug(PlayerLog.Tag, "height : " + height + ", width : " + width
+ ", fps : " + fps + ", bitrate : " + bitrate);
- VideoStreamChangedEventArgs eventArgs = new VideoStreamChangedEventArgs(height, width, fps, bitrate);
- VideoStreamChanged?.Invoke(this, eventArgs);
+
+ VideoStreamChanged?.Invoke(this, new VideoStreamChangedEventArgs(height, width, fps, bitrate));
};
int ret = Interop.Player.SetVideoStreamChangedCb(GetHandle(), _videoStreamChangedCallback, IntPtr.Zero);
if (ret != (int)PlayerErrorCode.None)