Debian Codegraph @

Xpjproject/pjmedia/src/pjmedia-videodev/errno.c

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