Skip to content

Commit

Permalink
[Multimedia] Fix VD SVACE issues (#5445)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsgwon authored and hinohie committed Aug 9, 2023
1 parent 8c7eea1 commit df9910f
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 47 deletions.
4 changes: 3 additions & 1 deletion src/Tizen.Multimedia.AudioIO/WavPlayer/WavPlayerError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ internal static void Validate(this WavPlayerError error, string message)

case WavPlayerError.InvalidOperation:
throw new InvalidOperationException(message);

default:
break;
}
}
}

}
22 changes: 13 additions & 9 deletions src/Tizen.Multimedia.MediaPlayer/Player/PlayerError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,36 @@ internal enum PlayerErrorCode

internal static class PlayerErrorCodeExtensions
{
internal static void ThrowIfFailed(this PlayerErrorCode err, Player player, string message)
internal static void ThrowIfFailed(this PlayerErrorCode errorCode, Player player, string message)
{
if (err == PlayerErrorCode.None)
if (errorCode == PlayerErrorCode.None)
{
return;
}

var ex = err.GetException(message);
var ex = errorCode.GetException(message);

if (ex == null)
{
// Notify only when it can't be handled.
player?.NotifyError((int)err, message);
player?.NotifyError((int)errorCode, message);

throw new InvalidOperationException($"{message} : Unknown error({err.ToString()}).");
throw new InvalidOperationException($"{message} : Unknown error({errorCode.ToString()}).");
}

throw ex;
}

internal static Exception GetException(this PlayerErrorCode err, string message)
internal static Exception GetException(this PlayerErrorCode errorCode, string message)
{
if (err == PlayerErrorCode.None)
if (errorCode == PlayerErrorCode.None)
{
return null;
}

string msg = $"{ (message ?? "Operation failed") } : { err.ToString() }.";
string msg = $"{ (message ?? "Operation failed") } : { errorCode.ToString() }.";

switch (err)
switch (errorCode)
{
case PlayerErrorCode.InvalidArgument:
case PlayerErrorCode.InvalidUri:
Expand Down Expand Up @@ -133,6 +133,10 @@ internal static Exception GetException(this PlayerErrorCode err, string message)

case PlayerErrorCode.NotAvailable:
throw new NotAvailableException(msg);

default:
Log.Info(PlayerLog.Tag, "Unknow error: " + errorCode);
break;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ internal static void ThrowIfError(this MetadataEditorError errorCode, string err
case MetadataEditorError.OperationFailed:
case MetadataEditorError.UpdateNotPossible:
throw new InvalidOperationException(errorMessages);

default:
Log.Error(typeof(MetadataEditor).FullName, $"Unknown error : {errorCode.ToString()}");
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ internal enum MetadataExtractorError

internal static class MetadataExtractorRetValidator
{
internal static void ThrowIfError(MetadataExtractorError error, string errorMessage)
internal static void ThrowIfError(MetadataExtractorError errorCode, string errorMessage)
{
switch (error)
if (errorCode == MetadataExtractorError.None)
{
return;
}

switch (errorCode)
{
case MetadataExtractorError.InvalidParameter:
throw new ArgumentException(errorMessage);
Expand All @@ -54,6 +59,10 @@ internal static void ThrowIfError(MetadataExtractorError error, string errorMess

case MetadataExtractorError.OperationFailed:
throw new InvalidOperationException(errorMessage);

default:
Log.Error(typeof(MetadataExtractor).FullName, $"Unknown error : {errorCode.ToString()}");
break;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Tizen.Multimedia.Recorder/Recorder/RecorderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public static IEnumerable<RecorderFileFormat> GetSupportedFileFormats(this Recor
case RecorderVideoCodec.Theora:
yield return RecorderFileFormat.Ogg;
break;

default:
break;
}
}

Expand Down Expand Up @@ -93,6 +96,9 @@ public static IEnumerable<RecorderFileFormat> GetSupportedFileFormats(this Recor
case RecorderAudioCodec.Pcm:
yield return RecorderFileFormat.Wav;
break;

default:
break;
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Tizen.Multimedia.Remoting/MediaController/MediaControlEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ internal static MediaControlPlaybackState ToPublic(this MediaControllerNativePla
case MediaControllerNativePlaybackState.Connecting: return MediaControlPlaybackState.Connecting;
case MediaControllerNativePlaybackState.Buffering: return MediaControlPlaybackState.Buffering;
case MediaControllerNativePlaybackState.Error: return MediaControlPlaybackState.Error;
default: break;
}

Debug.Fail($"Not supported code for playback state{nativeState}.");
Expand All @@ -417,6 +418,7 @@ internal static MediaControllerNativePlaybackState ToNative(this MediaControlPla
case MediaControlPlaybackState.Connecting: return MediaControllerNativePlaybackState.Connecting;
case MediaControlPlaybackState.Buffering: return MediaControllerNativePlaybackState.Buffering;
case MediaControlPlaybackState.Error: return MediaControllerNativePlaybackState.Error;
default: break;
}
return MediaControllerNativePlaybackState.None;
}
Expand All @@ -433,6 +435,7 @@ internal static MediaControlPlaybackCommand ToPublic(this MediaControllerNativeP
case MediaControllerNativePlaybackAction.FastForward: return MediaControlPlaybackCommand.FastForward;
case MediaControllerNativePlaybackAction.Rewind: return MediaControlPlaybackCommand.Rewind;
case MediaControllerNativePlaybackAction.Toggle: return MediaControlPlaybackCommand.Toggle;
default: break;
}

Debug.Fail($"Not supported code for playback command{nativeAction}.");
Expand All @@ -451,6 +454,7 @@ internal static MediaControllerNativePlaybackAction ToNative(this MediaControlPl
case MediaControlPlaybackCommand.FastForward: return MediaControllerNativePlaybackAction.FastForward;
case MediaControlPlaybackCommand.Rewind: return MediaControllerNativePlaybackAction.Rewind;
case MediaControlPlaybackCommand.Toggle: return MediaControllerNativePlaybackAction.Toggle;
default: break;
}
return MediaControllerNativePlaybackAction.Play;
}
Expand Down Expand Up @@ -490,6 +494,8 @@ internal static MediaControlNativeDisplayMode ToNative(this MediaControlDisplayM
case MediaControlDisplayMode.CroppedFull:
nativeMode = MediaControlNativeDisplayMode.CroppedFull;
break;
default:
break;
}
return nativeMode;
}
Expand All @@ -512,6 +518,8 @@ internal static MediaControlDisplayMode ToPublic(this MediaControlNativeDisplayM
case MediaControlNativeDisplayMode.CroppedFull:
nativeMode = MediaControlDisplayMode.CroppedFull;
break;
default:
break;
}
return nativeMode;
}
Expand Down Expand Up @@ -550,6 +558,8 @@ internal static MediaControlNativeDisplayRotation ToNative(this Rotation mode)
case Rotation.Rotate270:
nativeMode = MediaControlNativeDisplayRotation.Rotate270;
break;
default:
break;
}
return nativeMode;
}
Expand All @@ -572,6 +582,8 @@ internal static Rotation ToPublic(this MediaControlNativeDisplayRotation mode)
case MediaControlNativeDisplayRotation.Rotate270:
nativeMode = Rotation.Rotate270;
break;
default:
break;
}
return nativeMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ internal static void ThrowIfError(this MediaControllerError error, string messag

case MediaControllerError.PermissionDenied:
throw new UnauthorizedAccessException(msg);

default:
break;
}

throw new InvalidOperationException($"Unknown error({error}) : {message}");
Expand Down
4 changes: 2 additions & 2 deletions src/Tizen.Multimedia.Remoting/WebRTC/WebRTCDataChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public WebRTCDataChannel(WebRTC webRtc, string label, Bundle bundle)
NativeDataChannel.Create(webRtc.Handle, label, bundle_, out _handle).
ThrowIfFailed("Failed to create webrtc data channel");

Debug.Assert(_handle != null);
Debug.Assert(_handle != IntPtr.Zero);

Label = label;
}
Expand Down Expand Up @@ -227,7 +227,7 @@ protected virtual void Dispose(bool disposing)
return;
}

if (_handle != null)
if (_handle != IntPtr.Zero)
{
NativeDataChannel.Destroy(_handle);
_disposed = true;
Expand Down
2 changes: 2 additions & 0 deletions src/Tizen.Multimedia.Remoting/WebRTC/WebRTCError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ internal static void ThrowIfFailed(this WebRTCErrorCode errorCode, string messag
throw new ArgumentException(errMessage);
case WebRTCErrorCode.PermissionDenied:
throw new UnauthorizedAccessException(errMessage);
default:
break;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tizen.Multimedia.Remoting/WebRTC/WebRTCSignalingServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected virtual void Dispose(bool disposing)
return;
}

if (_handle != null)
if (_handle != IntPtr.Zero)
{
SignalingServer.Destroy(_handle);
_disposed = true;
Expand Down Expand Up @@ -243,7 +243,7 @@ protected virtual void Dispose(bool disposing)
return;
}

if (_handle != null)
if (_handle != IntPtr.Zero)
{
SignalingClient.Disconnect(_handle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ internal static RecorderVideoCodec ToRecorderEnum(this StreamRecorderVideoCodec

case StreamRecorderVideoCodec.Mpeg4:
return RecorderVideoCodec.Mpeg4;

default:
break;
}

Debug.Fail("Unknown video codec value.");
Expand All @@ -181,6 +184,9 @@ internal static StreamRecorderVideoCodec ToStreamRecorderEnum(this RecorderVideo

case RecorderVideoCodec.Mpeg4:
return StreamRecorderVideoCodec.Mpeg4;

default:
break;
}

throw new NotSupportedException($"{value.ToString()} is not supported.");
Expand All @@ -199,6 +205,9 @@ internal static RecorderAudioCodec ToRecorderEnum(this StreamRecorderAudioCodec

case StreamRecorderAudioCodec.Pcm:
return RecorderAudioCodec.Pcm;

default:
break;
}

Debug.Fail("Unknown audio codec value.");
Expand All @@ -218,6 +227,9 @@ internal static StreamRecorderAudioCodec ToStreamRecorderEnum(this RecorderAudio

case RecorderAudioCodec.Pcm:
return StreamRecorderAudioCodec.Pcm;

default:
break;
}

throw new NotSupportedException($"{value.ToString()} is not supported.");
Expand All @@ -242,6 +254,9 @@ internal static RecorderFileFormat ToRecorderEnum(this StreamRecorderFileFormat

case StreamRecorderFileFormat.Wav:
return RecorderFileFormat.Wav;

default:
break;
}

Debug.Fail("Unknown file format value.");
Expand All @@ -267,6 +282,9 @@ internal static StreamRecorderFileFormat ToStreamRecorderEnum(this RecorderFileF

case RecorderFileFormat.Wav:
return StreamRecorderFileFormat.Wav;

default:
break;
}

throw new NotSupportedException($"{value.ToString()} is not supported.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ internal static StreamRecorderErrorCode Ignore(this StreamRecorderErrorCode erro
return (ignore == errorCode) ? StreamRecorderErrorCode.None : errorCode;
}

internal static void ThrowIfError(this StreamRecorderErrorCode err, string errorMessage)
internal static void ThrowIfError(this StreamRecorderErrorCode errorCode, string errorMessage)
{
if (err == StreamRecorderErrorCode.None)
if (errorCode == StreamRecorderErrorCode.None)
{
return;
}

switch (err)
switch (errorCode)
{
case StreamRecorderErrorCode.InvalidParameter:
throw new ArgumentException(errorMessage);
Expand All @@ -67,6 +67,10 @@ internal static void ThrowIfError(this StreamRecorderErrorCode err, string error

case StreamRecorderErrorCode.OutOfStorage:
throw new IOException(errorMessage);

default:
Log.Error("Tizen.Multimedia.StreamRecorder", $"Unknown error : {errorCode.ToString()}");
break;
}
}
}
Expand Down
Loading

0 comments on commit df9910f

Please sign in to comment.