QtGStreamer  1.2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
urihandler.cpp
1 /*
2  Copyright (C) 2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published
6  by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "urihandler.h"
18 #include "element.h"
19 #include <gst/gst.h>
20 #include <QtCore/QUrl>
21 #include <QtCore/QStringList>
22 
23 namespace QGst {
24 
25 //static
26 bool UriHandler::protocolIsSupported(UriType type, const char *protocol)
27 {
28  return gst_uri_protocol_is_supported(static_cast<GstURIType>(type), protocol);
29 }
30 
31 //static
32 ElementPtr UriHandler::makeFromUri(UriType type, const QUrl & uri, const char *elementName)
33 {
34  GError *error = NULL;
35  GstElement *e = gst_element_make_from_uri(static_cast<GstURIType>(type), uri.toEncoded(), elementName, &error);
36  if (error) {
37  throw QGlib::Error(error);
38  }
39  if (e) {
40  gst_object_ref_sink(e);
41  }
42  return ElementPtr::wrap(e, false);
43 }
44 
45 UriType UriHandler::uriType() const
46 {
47  return static_cast<UriType>(gst_uri_handler_get_uri_type(object<GstURIHandler>()));
48 }
49 
50 QStringList UriHandler::supportedProtocols() const
51 {
52  QStringList result;
53  const char * const *protocols = gst_uri_handler_get_protocols(object<GstURIHandler>());
54  if (protocols) {
55  for (const char * const *p = protocols; p && *p; ++p) {
56  result.append(QString::fromUtf8(*p));
57  }
58  }
59  return result;
60 }
61 
62 QUrl UriHandler::uri() const
63 {
64  //QUrl::fromEncoded doesn't work because the returned URI
65  //is encoded using percent encoding even for slashes.
66  return QUrl::fromPercentEncoding(gst_uri_handler_get_uri(object<GstURIHandler>()));
67 }
68 
69 bool UriHandler::setUri(const QUrl & uri)
70 {
71  GError *error = NULL;
72  bool result;
73  result = gst_uri_handler_set_uri(object<GstURIHandler>(), uri.toEncoded(), &error);
74  if (error) {
75  throw QGlib::Error(error);
76  }
77  return result;
78 }
79 
80 } //namespace QGst
static RefPointer< Element > wrap(typename Element::CType *nativePtr, bool increaseRef=true)
Wrapper class for GError.
Definition: error.h:30