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.
19 using Tizen.Internals.Errors;
21 namespace Tizen.Multimedia.MediaCodec
23 internal enum MediaCodecErrorCode
25 CodecDefinedBase = -0x019B0000,
27 None = ErrorCode.None,
28 OutOfMemory = ErrorCode.OutOfMemory,
29 InvalidParameter = ErrorCode.InvalidParameter,
30 InvalidOperation = ErrorCode.InvalidOperation,
31 NotSupportedOnDevice = ErrorCode.NotSupported,
32 PermissionDenied = ErrorCode.PermissionDenied,
34 InvalidState = CodecDefinedBase | 0x01,
35 InvalidInBuffer = CodecDefinedBase | 0x02,
36 InvalidOutBuffer = CodecDefinedBase | 0x03,
37 Internal = CodecDefinedBase | 0x04,
38 NotInitialized = CodecDefinedBase | 0x05,
39 InvalidStream = CodecDefinedBase | 0x06,
40 CodecNotFound = CodecDefinedBase | 0x07,
41 DecodingError = CodecDefinedBase | 0x08,
42 OutOfStorage = CodecDefinedBase | 0x09,
43 StreamNotFound = CodecDefinedBase | 0x0a,
44 NotSupportedFormat = CodecDefinedBase | 0x0b,
45 NoAvailableBuffer = CodecDefinedBase | 0x0c,
46 OverflowInBuffer = CodecDefinedBase | 0x0d,
47 ResourceOverloaded = CodecDefinedBase | 0x0e,
48 ResourceConflict = CodecDefinedBase | 0x0f
52 /// Specifies the errors of <see cref="MediaCodec"/>.
54 /// <seealso cref="MediaCodec.ErrorOccurred"/>
55 /// <since_tizen> 3 </since_tizen>
56 public enum MediaCodecError
59 /// The format is not supported.
61 NotSupportedFormat = MediaCodecErrorCode.NotSupportedFormat,
64 /// An internal error.
66 InternalError = MediaCodecErrorCode.Internal,
69 /// Not enough storage.
71 OutOfStorage = MediaCodecErrorCode.OutOfStorage,
74 /// The stream is invalid.
76 InvalidStream = MediaCodecErrorCode.InvalidStream,
79 internal static class MediaCodecErrorExtensions
81 internal static void ThrowIfFailed(this MediaCodecErrorCode errorCode, string message)
83 if (errorCode == MediaCodecErrorCode.None)
88 string msg = $"{ (message ?? "Operation failed") } : { errorCode.ToString() }.";
92 case MediaCodecErrorCode.OutOfMemory:
93 throw new OutOfMemoryException(msg);
95 case MediaCodecErrorCode.InvalidParameter:
96 throw new ArgumentException(msg);
98 case MediaCodecErrorCode.CodecNotFound:
99 case MediaCodecErrorCode.DecodingError:
100 case MediaCodecErrorCode.InvalidOperation:
101 case MediaCodecErrorCode.InvalidState:
102 case MediaCodecErrorCode.InvalidInBuffer:
103 case MediaCodecErrorCode.InvalidOutBuffer:
104 case MediaCodecErrorCode.Internal:
105 case MediaCodecErrorCode.InvalidStream:
106 case MediaCodecErrorCode.NotInitialized:
107 case MediaCodecErrorCode.ResourceConflict:
108 case MediaCodecErrorCode.ResourceOverloaded:
109 case MediaCodecErrorCode.StreamNotFound:
110 throw new InvalidOperationException(msg);
112 case MediaCodecErrorCode.NotSupportedOnDevice:
113 case MediaCodecErrorCode.NotSupportedFormat:
114 throw new NotSupportedException(msg);
116 case MediaCodecErrorCode.PermissionDenied:
117 throw new UnauthorizedAccessException(msg);
119 case MediaCodecErrorCode.OutOfStorage:
120 throw new IOException($"{msg}; Not enough disk space or specified path is not available to .");
122 case MediaCodecErrorCode.NoAvailableBuffer:
123 case MediaCodecErrorCode.OverflowInBuffer:
124 throw new InternalBufferOverflowException(msg);
127 throw new Exception($"Unknown error : {errorCode.ToString()}.");