QtGStreamer  0.10.2
 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/gsturi.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  GstElement *e = gst_element_make_from_uri(static_cast<GstURIType>(type), uri.toEncoded(), elementName);
35  if (e) {
36  gst_object_ref_sink(e);
37  }
38  return ElementPtr::wrap(e, false);
39 }
40 
41 UriType UriHandler::uriType() const
42 {
43  return static_cast<UriType>(gst_uri_handler_get_uri_type(object<GstURIHandler>()));
44 }
45 
46 QStringList UriHandler::supportedProtocols() const
47 {
48  QStringList result;
49  char **protocols = gst_uri_handler_get_protocols(object<GstURIHandler>());
50  if (protocols) {
51  for (char **p = protocols; p && *p; ++p) {
52  result.append(QString::fromUtf8(*p));
53  }
54  }
55  return result;
56 }
57 
58 QUrl UriHandler::uri() const
59 {
60  //QUrl::fromEncoded doesn't work because the returned URI
61  //is encoded using percent encoding even for slashes.
62  return QUrl::fromPercentEncoding(gst_uri_handler_get_uri(object<GstURIHandler>()));
63 }
64 
65 bool UriHandler::setUri(const QUrl & uri)
66 {
67  return gst_uri_handler_set_uri(object<GstURIHandler>(), uri.toEncoded());
68 }
69 
70 } //namespace QGst