Fixed typos.
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Player / PlayerError.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 using System;
17 using System.IO;
18 using Tizen.Internals.Errors;
19
20 namespace Tizen.Multimedia
21 {
22     internal enum PlayerErrorCode
23     {
24         None = ErrorCode.None,
25         InvalidArgument = ErrorCode.InvalidParameter,
26         OutOfMemory = ErrorCode.OutOfMemory,
27         NoSuchFile = ErrorCode.NoSuchFile,
28         InvalidOperation = ErrorCode.InvalidOperation,
29         NoSpaceOnDevice = ErrorCode.FileNoSpaceOnDevice,
30         FeatureNotSupported = ErrorCode.NotSupported,
31         PermissionDenied = ErrorCode.PermissionDenied,
32         NoBufferSpace = ErrorCode.BufferSpace,
33         TizenPlayerError = -0x01940000,
34         PlayerErrorClass = TizenPlayerError | 0x20,
35         SeekFailed = PlayerErrorClass | 0x01,
36         InvalidState = PlayerErrorClass | 0x02,
37         NotSupportedFile = PlayerErrorClass | 0x03,
38         InvalidUri = PlayerErrorClass | 0x04,
39         SoundPolicyError = PlayerErrorClass | 0x05,
40         ConnectionFailed = PlayerErrorClass | 0x06,
41         VideoCaptureFailed = PlayerErrorClass | 0x07,
42         DrmExpired = PlayerErrorClass | 0x08,
43         DrmNoLicense = PlayerErrorClass | 0x09,
44         DrmFutureUse = PlayerErrorClass | 0x0a,
45         DrmNotPermitted = PlayerErrorClass | 0x0b,
46         ResourceLimit = PlayerErrorClass | 0x0c,
47         ServiceDisconnected = PlayerErrorClass | 0x0d,
48         NotSupportedAudioCodec = PlayerErrorClass | 0x0e,
49         NotSupportedVideoCodec = PlayerErrorClass | 0x0f,
50         NotSupportedSubtitle = PlayerErrorClass | 0x10
51     }
52
53     internal static class PlayerErrorCodeExtensions
54     {
55         internal static void ThrowIfFailed(this PlayerErrorCode err, string message)
56         {
57             if (err == PlayerErrorCode.None)
58             {
59                 return;
60             }
61
62             string msg = $"{ (message ?? "Operation failed") } : { err.ToString() }.";
63
64             switch (err)
65             {
66                 case PlayerErrorCode.InvalidArgument:
67                 case PlayerErrorCode.InvalidUri:
68                     throw new ArgumentException(msg);
69
70                 case PlayerErrorCode.NoSuchFile:
71                     throw new FileNotFoundException(msg);
72
73                 case PlayerErrorCode.OutOfMemory:
74                     throw new OutOfMemoryException(msg);
75
76                 case PlayerErrorCode.NoSpaceOnDevice:
77                     throw new IOException(msg);
78
79                 case PlayerErrorCode.PermissionDenied:
80                     throw new UnauthorizedAccessException(msg);
81
82                 case PlayerErrorCode.NotSupportedFile:
83                     throw new FileFormatException(msg);
84
85                 case PlayerErrorCode.FeatureNotSupported:
86                     throw new NotSupportedException(msg);
87
88                 case PlayerErrorCode.DrmExpired:
89                 case PlayerErrorCode.DrmNoLicense:
90                 case PlayerErrorCode.DrmFutureUse:
91                 case PlayerErrorCode.DrmNotPermitted:
92                     // TODO consider another exception.
93                 case PlayerErrorCode.InvalidOperation:
94                 case PlayerErrorCode.InvalidState:
95                 case PlayerErrorCode.SeekFailed:
96                 case PlayerErrorCode.ConnectionFailed:
97                 case PlayerErrorCode.VideoCaptureFailed:
98                     throw new InvalidOperationException(msg);
99
100                 case PlayerErrorCode.NoBufferSpace:
101                     throw new NoBufferSpaceException(msg);
102
103                 case PlayerErrorCode.ResourceLimit:
104                     throw new ResourceLimitException(msg);
105
106                 case PlayerErrorCode.NotSupportedAudioCodec:
107                     throw new CodecNotSupportedException(CodecKind.Audio);
108
109                 case PlayerErrorCode.NotSupportedVideoCodec:
110                     throw new CodecNotSupportedException(CodecKind.Video);
111
112             }
113
114             throw new Exception(msg);
115         }
116     }
117
118     /// <summary>
119     /// The exception that is thrown when there is no available space in a buffer.
120     /// </summary>
121     public class NoBufferSpaceException : InvalidOperationException
122     {
123         /// <summary>
124         /// Initializes a new instance of the NoBufferSpaceException class with a specified error message.
125         /// </summary>
126         /// <param name="message">Error description.</param>
127         public NoBufferSpaceException(string message) : base(message)
128         {
129         }
130     }
131
132     /// <summary>
133     /// The exception that is thrown when there is no available resource for internal use.
134     /// </summary>
135     public class ResourceLimitException : InvalidOperationException
136     {
137         /// <summary>
138         /// Initializes a new instance of the ResourceLimitException class with a specified error message.
139         /// </summary>
140         /// <param name="message">Error description.</param>
141         public ResourceLimitException(string message) : base(message)
142         {
143         }
144     }
145 }
146