• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 /**
21  * SECTION:gsterror
22  * @title: GstGError
23  * @short_description: Categorized error messages
24  * @see_also: #GstMessage
25  * @symbols:
26  * - gst_error_get_message
27  * - gst_stream_error_quark
28  * - gst_core_error_quark
29  * - gst_resource_error_quark
30  * - gst_library_error_quark
31  *
32  * GStreamer elements can throw non-fatal warnings and fatal errors.
33  * Higher-level elements and applications can programmatically filter
34  * the ones they are interested in or can recover from,
35  * and have a default handler handle the rest of them.
36  *
37  * The rest of this section will use the term "error"
38  * to mean both (non-fatal) warnings and (fatal) errors; they are treated
39  * similarly.
40  *
41  * Errors from elements are the combination of a #GError and a debug string.
42  * The #GError contains:
43  * - a domain type: CORE, LIBRARY, RESOURCE or STREAM
44  * - a code: an enum value specific to the domain
45  * - a translated, human-readable message
46  * - a non-translated additional debug string, which also contains
47  * - file and line information
48  *
49  * Elements do not have the context required to decide what to do with
50  * errors.  As such, they should only inform about errors, and stop their
51  * processing.  In short, an element doesn't know what it is being used for.
52  *
53  * It is the application or compound element using the given element that
54  * has more context about the use of the element. Errors can be received by
55  * listening to the #GstBus of the element/pipeline for #GstMessage objects with
56  * the type %GST_MESSAGE_ERROR or %GST_MESSAGE_WARNING. The thrown errors should
57  * be inspected, and filtered if appropriate.
58  *
59  * An application is expected to, by default, present the user with a
60  * dialog box (or an equivalent) showing the error message.  The dialog
61  * should also allow a way to get at the additional debug information,
62  * so the user can provide bug reporting information.
63  *
64  * A compound element is expected to forward errors by default higher up
65  * the hierarchy; this is done by default in the same way as for other types
66  * of #GstMessage.
67  *
68  * When applications or compound elements trigger errors that they can
69  * recover from, they can filter out these errors and take appropriate action.
70  * For example, an application that gets an error from xvimagesink
71  * that indicates all XVideo ports are taken, the application can attempt
72  * to use another sink instead.
73  *
74  * Elements throw errors using the #GST_ELEMENT_ERROR convenience macro:
75  *
76  * ## Throwing an error
77  *
78  *   |[
79  *     GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
80  *       (_("No file name specified for reading.")), (NULL));
81  *   ]|
82  *
83  * Things to keep in mind:
84  *
85  *   * Don't go off inventing new error codes.  The ones
86  *     currently provided should be enough.  If you find your type of error
87  *     does not fit the current codes, you should use FAILED.
88  *   * Don't provide a message if the default one suffices.
89  *     this keeps messages more uniform.  Use (%NULL) - not forgetting the
90  *     parentheses.
91  *   * If you do supply a custom message, it should be
92  *     marked for translation.  The message should start with a capital
93  *     and end with a period.  The message should describe the error in short,
94  *     in a human-readable form, and without any complex technical terms.
95  *     A user interface will present this message as the first thing a user
96  *     sees.  Details, technical info, ... should go in the debug string.
97  *
98  *   * The debug string can be as you like.  Again, use (%NULL)
99  *     if there's nothing to add - file and line number will still be
100  *     passed.  #GST_ERROR_SYSTEM can be used as a shortcut to give
101  *     debug information on a system call error.
102  *
103  */
104 
105 /* FIXME 2.0: the entire error system needs an overhaul - it's not very
106  * useful the way it is. Also, we need to be able to specify additional
107  * 'details' for errors (e.g. disk/file/resource error -> out-of-space; or
108  * put the url/filename/device name that caused the error somewhere)
109  * without having to add enums for every little thing.
110  *
111  * FIXME 2.0: get rid of GST_{CORE,LIBRARY,RESOURCE,STREAM}_ERROR_NUM_ERRORS.
112  * Maybe also replace _quark() functions with g_quark_from_static_string()?
113  */
114 #ifdef HAVE_CONFIG_H
115 #include "config.h"
116 #endif
117 
118 #include "gst_private.h"
119 #include <gst/gst.h>
120 #include "gst-i18n-lib.h"
121 
122 #define QUARK_FUNC(string)                                              \
123 GQuark gst_ ## string ## _error_quark (void) {                          \
124   static GQuark quark;                                                  \
125   if (!quark)                                                           \
126     quark = g_quark_from_static_string ("gst-" # string "-error-quark"); \
127   return quark; }
128 
129 #define FILE_A_BUG "  Please file a bug at " PACKAGE_BUGREPORT "."
130 
131 static const gchar *
gst_error_get_core_error(GstCoreError code)132 gst_error_get_core_error (GstCoreError code)
133 {
134   switch (code) {
135     case GST_CORE_ERROR_FAILED:
136       return _("GStreamer encountered a general core library error.");
137     case GST_CORE_ERROR_TOO_LAZY:
138       return _("GStreamer developers were too lazy to assign an error code "
139           "to this error." FILE_A_BUG);
140     case GST_CORE_ERROR_NOT_IMPLEMENTED:
141       return _("Internal GStreamer error: code not implemented." FILE_A_BUG);
142     case GST_CORE_ERROR_STATE_CHANGE:
143       return _("GStreamer error: state change failed and some element failed "
144           "to post a proper error message with the reason for the failure.");
145     case GST_CORE_ERROR_PAD:
146       return _("Internal GStreamer error: pad problem." FILE_A_BUG);
147     case GST_CORE_ERROR_THREAD:
148       return _("Internal GStreamer error: thread problem." FILE_A_BUG);
149     case GST_CORE_ERROR_NEGOTIATION:
150       return _("GStreamer error: negotiation problem.");
151     case GST_CORE_ERROR_EVENT:
152       return _("Internal GStreamer error: event problem." FILE_A_BUG);
153     case GST_CORE_ERROR_SEEK:
154       return _("Internal GStreamer error: seek problem." FILE_A_BUG);
155     case GST_CORE_ERROR_CAPS:
156       return _("Internal GStreamer error: caps problem." FILE_A_BUG);
157     case GST_CORE_ERROR_TAG:
158       return _("Internal GStreamer error: tag problem." FILE_A_BUG);
159     case GST_CORE_ERROR_MISSING_PLUGIN:
160       return _("Your GStreamer installation is missing a plug-in.");
161     case GST_CORE_ERROR_CLOCK:
162       return _("GStreamer error: clock problem.");
163     case GST_CORE_ERROR_DISABLED:
164       return _("This application is trying to use GStreamer functionality "
165           "that has been disabled.");
166     case GST_CORE_ERROR_NUM_ERRORS:
167     default:
168       break;
169   }
170   return NULL;
171 }
172 
173 static const gchar *
gst_error_get_library_error(GstLibraryError code)174 gst_error_get_library_error (GstLibraryError code)
175 {
176   switch (code) {
177     case GST_LIBRARY_ERROR_FAILED:
178       return _("GStreamer encountered a general supporting library error.");
179     case GST_LIBRARY_ERROR_TOO_LAZY:
180       return _("GStreamer developers were too lazy to assign an error code "
181           "to this error." FILE_A_BUG);
182     case GST_LIBRARY_ERROR_INIT:
183       return _("Could not initialize supporting library.");
184     case GST_LIBRARY_ERROR_SHUTDOWN:
185       return _("Could not close supporting library.");
186     case GST_LIBRARY_ERROR_SETTINGS:
187       return _("Could not configure supporting library.");
188     case GST_LIBRARY_ERROR_ENCODE:
189       return _("Encoding error.");
190     case GST_LIBRARY_ERROR_NUM_ERRORS:
191     default:
192       break;
193   }
194   return NULL;
195 }
196 
197 static const gchar *
gst_error_get_resource_error(GstResourceError code)198 gst_error_get_resource_error (GstResourceError code)
199 {
200   switch (code) {
201     case GST_RESOURCE_ERROR_FAILED:
202       return _("GStreamer encountered a general resource error.");
203     case GST_RESOURCE_ERROR_TOO_LAZY:
204       return _("GStreamer developers were too lazy to assign an error code "
205           "to this error." FILE_A_BUG);
206     case GST_RESOURCE_ERROR_NOT_FOUND:
207       return _("Resource not found.");
208     case GST_RESOURCE_ERROR_BUSY:
209       return _("Resource busy or not available.");
210     case GST_RESOURCE_ERROR_OPEN_READ:
211       return _("Could not open resource for reading.");
212     case GST_RESOURCE_ERROR_OPEN_WRITE:
213       return _("Could not open resource for writing.");
214     case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
215       return _("Could not open resource for reading and writing.");
216     case GST_RESOURCE_ERROR_CLOSE:
217       return _("Could not close resource.");
218     case GST_RESOURCE_ERROR_READ:
219       return _("Could not read from resource.");
220     case GST_RESOURCE_ERROR_WRITE:
221       return _("Could not write to resource.");
222     case GST_RESOURCE_ERROR_SEEK:
223       return _("Could not perform seek on resource.");
224     case GST_RESOURCE_ERROR_SYNC:
225       return _("Could not synchronize on resource.");
226     case GST_RESOURCE_ERROR_SETTINGS:
227       return _("Could not get/set settings from/on resource.");
228     case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
229       return _("No space left on the resource.");
230     case GST_RESOURCE_ERROR_NOT_AUTHORIZED:
231       return _("Not authorized to access resource.");
232 #ifdef OHOS_EXT_FUNC
233     // ohos.ext.func.0012
234     case GST_RESOURCE_ERROR_TIME_OUT:
235       return _("Could not open resource for reading time out.");
236 #endif
237     case GST_RESOURCE_ERROR_NUM_ERRORS:
238     default:
239       break;
240   }
241   return NULL;
242 }
243 
244 static const gchar *
gst_error_get_stream_error(GstStreamError code)245 gst_error_get_stream_error (GstStreamError code)
246 {
247   switch (code) {
248     case GST_STREAM_ERROR_FAILED:
249       return _("GStreamer encountered a general stream error.");
250     case GST_STREAM_ERROR_TOO_LAZY:
251       return _("GStreamer developers were too lazy to assign an error code "
252           "to this error." FILE_A_BUG);
253     case GST_STREAM_ERROR_NOT_IMPLEMENTED:
254       return _("Element doesn't implement handling of this stream. "
255           "Please file a bug.");
256     case GST_STREAM_ERROR_TYPE_NOT_FOUND:
257       return _("Could not determine type of stream.");
258     case GST_STREAM_ERROR_WRONG_TYPE:
259       return _("The stream is of a different type than handled by this "
260           "element.");
261     case GST_STREAM_ERROR_CODEC_NOT_FOUND:
262       return _("There is no codec present that can handle the stream's type.");
263     case GST_STREAM_ERROR_DECODE:
264       return _("Could not decode stream.");
265     case GST_STREAM_ERROR_ENCODE:
266       return _("Could not encode stream.");
267     case GST_STREAM_ERROR_DEMUX:
268       return _("Could not demultiplex stream.");
269     case GST_STREAM_ERROR_MUX:
270       return _("Could not multiplex stream.");
271     case GST_STREAM_ERROR_FORMAT:
272       return _("The stream is in the wrong format.");
273     case GST_STREAM_ERROR_DECRYPT:
274       return _("The stream is encrypted and decryption is not supported.");
275     case GST_STREAM_ERROR_DECRYPT_NOKEY:
276       return _("The stream is encrypted and can't be decrypted because no "
277           "suitable key has been supplied.");
278     case GST_STREAM_ERROR_NUM_ERRORS:
279     default:
280       break;
281   }
282 
283   return NULL;
284 }
285 
286 QUARK_FUNC (core);
287 QUARK_FUNC (library);
288 QUARK_FUNC (resource);
289 QUARK_FUNC (stream);
290 
291 /**
292  * gst_error_get_message:
293  * @domain: the GStreamer error domain this error belongs to.
294  * @code: the error code belonging to the domain.
295  *
296  * Get a string describing the error message in the current locale.
297  *
298  * Returns: (transfer full): a newly allocated string describing
299  *     the error message (in UTF-8 encoding)
300  */
301 gchar *
gst_error_get_message(GQuark domain,gint code)302 gst_error_get_message (GQuark domain, gint code)
303 {
304   const gchar *message = NULL;
305 
306   if (domain == GST_CORE_ERROR)
307     message = gst_error_get_core_error ((GstCoreError) code);
308   else if (domain == GST_LIBRARY_ERROR)
309     message = gst_error_get_library_error ((GstLibraryError) code);
310   else if (domain == GST_RESOURCE_ERROR)
311     message = gst_error_get_resource_error ((GstResourceError) code);
312   else if (domain == GST_STREAM_ERROR)
313     message = gst_error_get_stream_error ((GstStreamError) code);
314   else {
315     g_warning ("No error messages for domain %s", g_quark_to_string (domain));
316     return g_strdup_printf (_("No error message for domain %s."),
317         g_quark_to_string (domain));
318   }
319   if (message)
320     return g_strdup (message);
321   else
322     return
323         g_strdup_printf (_
324         ("No standard error message for domain %s and code %d."),
325         g_quark_to_string (domain), code);
326 }
327