Alexandre Lision | 8af73cb | 2013-12-10 14:11:20 -0500 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
| 3 | * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | #include <pjmedia-videodev/errno.h> |
| 20 | #include <pj/string.h> |
| 21 | #include <pj/unicode.h> |
| 22 | |
| 23 | /* PJMEDIA-videodev's own error codes/messages |
| 24 | * MUST KEEP THIS ARRAY SORTED!! |
| 25 | * Message must be limited to 64 chars! |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | #if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0) |
| 30 | |
| 31 | |
| 32 | #if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0) |
| 33 | |
| 34 | static const struct |
| 35 | { |
| 36 | int code; |
| 37 | const char *msg; |
| 38 | } err_str[] = |
| 39 | { |
| 40 | PJ_BUILD_ERR( PJMEDIA_EVID_ERR, "Unspecified video device error" ), |
| 41 | PJ_BUILD_ERR( PJMEDIA_EVID_SYSERR, "Unknown error from video driver" ), |
| 42 | PJ_BUILD_ERR( PJMEDIA_EVID_INIT, "video subsystem not initialized" ), |
| 43 | PJ_BUILD_ERR( PJMEDIA_EVID_INVDEV, "Invalid video device" ), |
| 44 | PJ_BUILD_ERR( PJMEDIA_EVID_NODEV, "Found no video devices" ), |
| 45 | PJ_BUILD_ERR( PJMEDIA_EVID_NODEFDEV, "Unable to find default video device" ), |
| 46 | PJ_BUILD_ERR( PJMEDIA_EVID_NOTREADY, "video device not ready" ), |
| 47 | PJ_BUILD_ERR( PJMEDIA_EVID_INVCAP, "Invalid or unsupported video capability" ), |
| 48 | PJ_BUILD_ERR( PJMEDIA_EVID_INVOP, "Invalid or unsupported video device operation" ), |
| 49 | PJ_BUILD_ERR( PJMEDIA_EVID_BADFORMAT, "Bad or invalid video device format" ), |
| 50 | PJ_BUILD_ERR( PJMEDIA_EVID_SAMPFORMAT, "Invalid video device sample format"), |
| 51 | PJ_BUILD_ERR( PJMEDIA_EVID_BADLATENCY, "Bad video latency setting") |
| 52 | |
| 53 | }; |
| 54 | |
| 55 | #endif /* PJ_HAS_ERROR_STRING */ |
| 56 | |
| 57 | |
| 58 | |
| 59 | /* |
| 60 | * pjmedia_videodev_strerror() |
| 61 | */ |
| 62 | PJ_DEF(pj_str_t) pjmedia_videodev_strerror(pj_status_t statcode, |
| 63 | char *buf, pj_size_t bufsize ) |
| 64 | { |
| 65 | pj_str_t errstr; |
| 66 | |
| 67 | #if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0) |
| 68 | |
| 69 | /* videodev error */ |
| 70 | if (statcode >= PJMEDIA_VIDEODEV_ERRNO_START && |
| 71 | statcode < PJMEDIA_VIDEODEV_ERRNO_END) |
| 72 | { |
| 73 | /* Find the error in the table. |
| 74 | * Use binary search! |
| 75 | */ |
| 76 | int first = 0; |
| 77 | int n = PJ_ARRAY_SIZE(err_str); |
| 78 | |
| 79 | while (n > 0) { |
| 80 | int half = n/2; |
| 81 | int mid = first + half; |
| 82 | |
| 83 | if (err_str[mid].code < statcode) { |
| 84 | first = mid+1; |
| 85 | n -= (half+1); |
| 86 | } else if (err_str[mid].code > statcode) { |
| 87 | n = half; |
| 88 | } else { |
| 89 | first = mid; |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | |
| 95 | if (PJ_ARRAY_SIZE(err_str) && err_str[first].code == statcode) { |
| 96 | pj_str_t msg; |
| 97 | |
| 98 | msg.ptr = (char*)err_str[first].msg; |
| 99 | msg.slen = pj_ansi_strlen(err_str[first].msg); |
| 100 | |
| 101 | errstr.ptr = buf; |
| 102 | pj_strncpy_with_null(&errstr, &msg, bufsize); |
| 103 | return errstr; |
| 104 | |
| 105 | } |
| 106 | } |
| 107 | #endif /* PJ_HAS_ERROR_STRING */ |
| 108 | |
| 109 | /* Error not found. */ |
| 110 | errstr.ptr = buf; |
| 111 | errstr.slen = pj_ansi_snprintf(buf, bufsize, |
| 112 | "Unknown pjmedia-videodev error %d", |
| 113 | statcode); |
| 114 | if (errstr.slen < 1 || errstr.slen >= (pj_ssize_t)bufsize) |
| 115 | errstr.slen = bufsize - 1; |
| 116 | return errstr; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | #endif /* PJMEDIA_HAS_VIDEO */ |