1 /** 2 * @file 3 * @brief Header file for all Exception classes 4 * @author Jonathan Thomas <jonathan@openshot.org> 5 * 6 * @ref License 7 */ 8 9 /* LICENSE 10 * 11 * Copyright (c) 2008-2019 OpenShot Studios, LLC 12 * <http://www.openshotstudios.com/>. This file is part of 13 * OpenShot Library (libopenshot), an open-source project dedicated to 14 * delivering high quality video editing and animation solutions to the 15 * world. For more information visit <http://www.openshot.org/>. 16 * 17 * OpenShot Library (libopenshot) is free software: you can redistribute it 18 * and/or modify it under the terms of the GNU Lesser General Public License 19 * as published by the Free Software Foundation, either version 3 of the 20 * License, or (at your option) any later version. 21 * 22 * OpenShot Library (libopenshot) is distributed in the hope that it will be 23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 * GNU Lesser General Public License for more details. 26 * 27 * You should have received a copy of the GNU Lesser General Public License 28 * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>. 29 */ 30 31 #ifndef OPENSHOT_EXCEPTIONS_H 32 #define OPENSHOT_EXCEPTIONS_H 33 34 #include <string> 35 36 namespace openshot { 37 38 /** 39 * @brief Base exception class with a custom message variable. 40 * 41 * A std::exception-derived exception class with custom message. 42 * All OpenShot exception classes inherit from this class. 43 */ 44 class ExceptionBase : public std::exception 45 { 46 protected: 47 std::string m_message; 48 public: ExceptionBase(std::string message)49 ExceptionBase(std::string message) : m_message(message) { } ~ExceptionBase()50 virtual ~ExceptionBase() noexcept {} what()51 virtual const char* what() const noexcept { 52 // return custom message 53 return m_message.c_str(); 54 } 55 }; 56 57 /// Exception when a required chunk is missing 58 class ChunkNotFound : public ExceptionBase 59 { 60 public: 61 int64_t frame_number; 62 int64_t chunk_number; 63 int64_t chunk_frame; 64 /** 65 * @brief Constructor 66 * 67 * @param message A message to accompany the exception 68 * @param frame_number The frame number being processed 69 * @param chunk_number The chunk requested 70 * @param chunk_frame The chunk frame 71 */ ChunkNotFound(std::string message,int64_t frame_number,int64_t chunk_number,int64_t chunk_frame)72 ChunkNotFound(std::string message, int64_t frame_number, int64_t chunk_number, int64_t chunk_frame) 73 : ExceptionBase(message), frame_number(frame_number), chunk_number(chunk_number), chunk_frame(chunk_frame) { } ~ChunkNotFound()74 virtual ~ChunkNotFound() noexcept {} 75 }; 76 77 78 /// Exception when accessing a blackmagic decklink card 79 class DecklinkError : public ExceptionBase 80 { 81 public: 82 /** 83 * @brief Constructor 84 * 85 * @param message A message to accompany the exception 86 */ DecklinkError(std::string message)87 DecklinkError(std::string message) 88 : ExceptionBase(message) { } ~DecklinkError()89 virtual ~DecklinkError() noexcept {} 90 }; 91 92 /// Exception when decoding audio packet 93 class ErrorDecodingAudio : public ExceptionBase 94 { 95 public: 96 int64_t frame_number; 97 /** 98 * @brief Constructor 99 * 100 * @param message A message to accompany the exception 101 * @param frame_number The frame number being processed 102 */ ErrorDecodingAudio(std::string message,int64_t frame_number)103 ErrorDecodingAudio(std::string message, int64_t frame_number) 104 : ExceptionBase(message), frame_number(frame_number) { } ~ErrorDecodingAudio()105 virtual ~ErrorDecodingAudio() noexcept {} 106 }; 107 108 /// Exception when encoding audio packet 109 class ErrorEncodingAudio : public ExceptionBase 110 { 111 public: 112 int64_t frame_number; 113 /** 114 * @brief Constructor 115 * 116 * @param message A message to accompany the exception 117 * @param frame_number The frame number being processed 118 */ ErrorEncodingAudio(std::string message,int64_t frame_number)119 ErrorEncodingAudio(std::string message, int64_t frame_number) 120 : ExceptionBase(message), frame_number(frame_number) { } ~ErrorEncodingAudio()121 virtual ~ErrorEncodingAudio() noexcept {} 122 }; 123 124 /// Exception when encoding audio packet 125 class ErrorEncodingVideo : public ExceptionBase 126 { 127 public: 128 int64_t frame_number; 129 /** 130 * @brief Constructor 131 * 132 * @param message A message to accompany the exception 133 * @param frame_number The frame number being processed 134 */ ErrorEncodingVideo(std::string message,int64_t frame_number)135 ErrorEncodingVideo(std::string message, int64_t frame_number) 136 : ExceptionBase(message), frame_number(frame_number) { } ~ErrorEncodingVideo()137 virtual ~ErrorEncodingVideo() noexcept {} 138 }; 139 140 /// Exception when an invalid # of audio channels are detected 141 class InvalidChannels : public ExceptionBase 142 { 143 public: 144 std::string file_path; 145 /** 146 * @brief Constructor 147 * 148 * @param message A message to accompany the exception 149 * @param file_path (optional) The input file being processed 150 */ 151 InvalidChannels(std::string message, std::string file_path="") ExceptionBase(message)152 : ExceptionBase(message), file_path(file_path) { } ~InvalidChannels()153 virtual ~InvalidChannels() noexcept {} 154 }; 155 156 /// Exception when no valid codec is found for a file 157 class InvalidCodec : public ExceptionBase 158 { 159 public: 160 std::string file_path; 161 /** 162 * @brief Constructor 163 * 164 * @param message A message to accompany the exception 165 * @param file_path (optional) The input file being processed 166 */ 167 InvalidCodec(std::string message, std::string file_path="") ExceptionBase(message)168 : ExceptionBase(message), file_path(file_path) { } ~InvalidCodec()169 virtual ~InvalidCodec() noexcept {} 170 }; 171 172 /// Exception for files that can not be found or opened 173 class InvalidFile : public ExceptionBase 174 { 175 public: 176 std::string file_path; 177 /** 178 * @brief Constructor 179 * 180 * @param message A message to accompany the exception 181 * @param file_path The input file being processed 182 */ InvalidFile(std::string message,std::string file_path)183 InvalidFile(std::string message, std::string file_path) 184 : ExceptionBase(message), file_path(file_path) { } ~InvalidFile()185 virtual ~InvalidFile() noexcept {} 186 }; 187 188 /// Exception when no valid format is found for a file 189 class InvalidFormat : public ExceptionBase 190 { 191 public: 192 std::string file_path; 193 /** 194 * @brief Constructor 195 * 196 * @param message A message to accompany the exception 197 * @param file_path (optional) The input file being processed 198 */ 199 InvalidFormat(std::string message, std::string file_path="") ExceptionBase(message)200 : ExceptionBase(message), file_path(file_path) { } ~InvalidFormat()201 virtual ~InvalidFormat() noexcept {} 202 }; 203 204 /// Exception for invalid JSON 205 class InvalidJSON : public ExceptionBase 206 { 207 public: 208 std::string file_path; 209 /** 210 * @brief Constructor 211 * 212 * @param message A message to accompany the exception 213 * @param file_path (optional) The input file being processed 214 */ 215 InvalidJSON(std::string message, std::string file_path="") ExceptionBase(message)216 : ExceptionBase(message), file_path(file_path) { } ~InvalidJSON()217 virtual ~InvalidJSON() noexcept {} 218 }; 219 220 /// Exception when invalid encoding options are used 221 class InvalidOptions : public ExceptionBase 222 { 223 public: 224 std::string file_path; 225 /** 226 * @brief Constructor 227 * 228 * @param message A message to accompany the exception 229 * @param file_path (optional) The input file being processed 230 */ 231 InvalidOptions(std::string message, std::string file_path="") ExceptionBase(message)232 : ExceptionBase(message), file_path(file_path) { } ~InvalidOptions()233 virtual ~InvalidOptions() noexcept {} 234 }; 235 236 /// Exception when invalid sample rate is detected during encoding 237 class InvalidSampleRate : public ExceptionBase 238 { 239 public: 240 std::string file_path; 241 /** 242 * @brief Constructor 243 * 244 * @param message A message to accompany the exception 245 * @param file_path (optional) The input file being processed 246 */ 247 InvalidSampleRate(std::string message, std::string file_path="") ExceptionBase(message)248 : ExceptionBase(message), file_path(file_path) { } ~InvalidSampleRate()249 virtual ~InvalidSampleRate() noexcept {} 250 }; 251 252 /// Exception for missing JSON Change key 253 class InvalidJSONKey : public ExceptionBase 254 { 255 public: 256 std::string json; 257 /** 258 * @brief Constructor 259 * 260 * @param message A message to accompany the exception 261 * @param json The json data being processed 262 */ InvalidJSONKey(std::string message,std::string json)263 InvalidJSONKey(std::string message, std::string json) 264 : ExceptionBase(message), json(json) { } ~InvalidJSONKey()265 virtual ~InvalidJSONKey() noexcept {} 266 }; 267 268 /// Exception when no streams are found in the file 269 class NoStreamsFound : public ExceptionBase 270 { 271 public: 272 std::string file_path; 273 /** 274 * @brief Constructor 275 * 276 * @param message A message to accompany the exception 277 * @param file_path (optional) The input file being processed 278 */ 279 NoStreamsFound(std::string message, std::string file_path="") ExceptionBase(message)280 : ExceptionBase(message), file_path(file_path) { } ~NoStreamsFound()281 virtual ~NoStreamsFound() noexcept {} 282 }; 283 284 /// Exception for frames that are out of bounds. 285 class OutOfBoundsFrame : public ExceptionBase 286 { 287 public: 288 int64_t FrameRequested; 289 int64_t MaxFrames; 290 /** 291 * @brief Constructor 292 * 293 * @param message A message to accompany the exception 294 * @param frame_requested The out-of-bounds frame number requested 295 * @param max_frames The maximum available frame number 296 */ OutOfBoundsFrame(std::string message,int64_t frame_requested,int64_t max_frames)297 OutOfBoundsFrame(std::string message, int64_t frame_requested, int64_t max_frames) 298 : ExceptionBase(message), FrameRequested(frame_requested), MaxFrames(max_frames) { } ~OutOfBoundsFrame()299 virtual ~OutOfBoundsFrame() noexcept {} 300 }; 301 302 /// Exception for an out of bounds key-frame point. 303 class OutOfBoundsPoint : public ExceptionBase 304 { 305 public: 306 int PointRequested; 307 int MaxPoints; 308 /** 309 * @brief Constructor 310 * 311 * @param message A message to accompany the exception 312 * @param point_requested The out-of-bounds point requested 313 * @param max_points The maximum available point value 314 */ OutOfBoundsPoint(std::string message,int point_requested,int max_points)315 OutOfBoundsPoint(std::string message, int point_requested, int max_points) 316 : ExceptionBase(message), PointRequested(point_requested), MaxPoints(max_points) { } ~OutOfBoundsPoint()317 virtual ~OutOfBoundsPoint() noexcept {} 318 }; 319 320 /// Exception when memory could not be allocated 321 class OutOfMemory : public ExceptionBase 322 { 323 public: 324 std::string file_path; 325 /** 326 * @brief Constructor 327 * 328 * @param message A message to accompany the exception 329 * @param file_path (optional) The input file being processed 330 */ 331 OutOfMemory(std::string message, std::string file_path="") ExceptionBase(message)332 : ExceptionBase(message), file_path(file_path) { } ~OutOfMemory()333 virtual ~OutOfMemory() noexcept {} 334 }; 335 336 /// Exception when a reader is closed, and a frame is requested 337 class ReaderClosed : public ExceptionBase 338 { 339 public: 340 std::string file_path; 341 /** 342 * @brief Constructor 343 * 344 * @param message A message to accompany the exception 345 * @param file_path (optional) The input file being processed 346 */ 347 ReaderClosed(std::string message, std::string file_path="") ExceptionBase(message)348 : ExceptionBase(message), file_path(file_path) { } ~ReaderClosed()349 virtual ~ReaderClosed() noexcept {} 350 }; 351 352 /// Exception when resample fails 353 class ResampleError : public ExceptionBase 354 { 355 public: 356 std::string file_path; 357 /** 358 * @brief Constructor 359 * 360 * @param message A message to accompany the exception 361 * @param file_path (optional) The input file being processed 362 */ 363 ResampleError(std::string message, std::string file_path="") ExceptionBase(message)364 : ExceptionBase(message), file_path(file_path) { } ~ResampleError()365 virtual ~ResampleError() noexcept {} 366 }; 367 368 #define TMS_DEP_MSG "The library no longer throws this exception. It will be removed in a future release." 369 370 #ifndef SWIG 371 /// Exception when too many seek attempts happen 372 class 373 __attribute__ ((deprecated(TMS_DEP_MSG))) 374 TooManySeeks : public ExceptionBase 375 { 376 public: 377 std::string file_path; 378 /** 379 * @brief Constructor 380 * 381 * @param message A message to accompany the exception 382 * @param file_path (optional) The input file being processed 383 */ 384 TooManySeeks(std::string message, std::string file_path="") __attribute__ ((deprecated(TMS_DEP_MSG))); ~TooManySeeks()385 virtual ~TooManySeeks() noexcept {} 386 }; 387 #endif 388 389 /// Exception when a writer is closed, and a frame is requested 390 class WriterClosed : public ExceptionBase 391 { 392 public: 393 std::string file_path; 394 /** 395 * @brief Constructor 396 * 397 * @param message A message to accompany the exception 398 * @param file_path (optional) The output file being written 399 */ 400 WriterClosed(std::string message, std::string file_path="") ExceptionBase(message)401 : ExceptionBase(message), file_path(file_path) { } ~WriterClosed()402 virtual ~WriterClosed() noexcept {} 403 }; 404 } 405 406 #endif 407