2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Diagnostics;
21 namespace Tizen.Multimedia
23 internal static class AudioIOUtil
25 internal static void ThrowIfError(int errorCode, string msg = null)
27 AudioIOError code = (AudioIOError)errorCode;
28 // 현재는 에러코드 최상위 exception으로 전달, 추후 상황에 맞게 케이스 처리해야 함.
30 msg = (msg == null ? "" : msg + " ") + $": { code }";
34 Log.Info("Audio", "Code > 0, no error!!!!");
40 case AudioIOError.None:
42 case AudioIOError.OutOfMemory:
43 Log.Info("Audio", "OutOfMemoryException");
44 throw new OutOfMemoryException();
45 case AudioIOError.InvalidParameter:
46 Log.Info("Audio", "ArgumentException");
47 throw new ArgumentException(msg);
48 case AudioIOError.InvalidOperation:
49 throw new InvalidOperationException(msg);
50 case AudioIOError.PermissionDenied:
51 Log.Info("Audio", "Permission Denied Error");
52 throw new InvalidOperationException(msg);
53 case AudioIOError.NotSupported:
54 throw new NotSupportedException(msg);
55 case AudioIOError.DevicePolicyRestriction:
56 Log.Info("Audio", "Device_policy_restriction");
57 throw new Exception("Device_policy_restriction");
58 case AudioIOError.DeviceNotOpened:
59 Log.Info("Audio", "Device Not Opened Error");
60 throw new Exception("Device Not Opened Error");
61 case AudioIOError.DeviceNotClosed:
62 Log.Info("Audio", "Device Not Closed Error");
63 throw new Exception("Device Not Closed Error");
64 case AudioIOError.InvalidBuffer:
65 Log.Info("Audio", "Invalid Buffer Error");
66 throw new InvalidOperationException(msg);
67 case AudioIOError.SoundPolicy:
68 Log.Info("Audio", "Sound Policy Error");
69 throw new Exception(msg);
70 case AudioIOError.InvalidState:
71 Log.Info("Audio", "Invalid State Error");
72 throw new InvalidOperationException(msg);
73 case AudioIOError.NotSupportedType:
74 Log.Info("Audio", "Not supported stream type Error");
75 throw new NotSupportedException(msg);
77 Log.Info("Audio", "Unknown Exception" + code);
78 throw new Exception(msg);
82 internal static void ValidateState(AudioIOState curState, params AudioIOState[] desiredStates)
84 Debug.Assert(desiredStates.Length > 0);
86 if (desiredStates.Contains(curState))
91 throw new InvalidOperationException($"The audio is not in a valid state. " +
92 $"Current State : { curState }, Valid State : { string.Join(", ", desiredStates) }.");