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