QtGStreamer  0.10.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
urihandler.cpp
00001 /*
00002     Copyright (C) 2010  George Kiagiadakis <kiagiadakis.george@gmail.com>
00003 
00004     This library is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as published
00006     by the Free Software Foundation; either version 2.1 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public License
00015     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 #include "urihandler.h"
00018 #include "element.h"
00019 #include <gst/gsturi.h>
00020 #include <QtCore/QUrl>
00021 #include <QtCore/QStringList>
00022 
00023 namespace QGst {
00024 
00025 //static
00026 bool UriHandler::protocolIsSupported(UriType type, const char *protocol)
00027 {
00028     return gst_uri_protocol_is_supported(static_cast<GstURIType>(type), protocol);
00029 }
00030 
00031 //static
00032 ElementPtr UriHandler::makeFromUri(UriType type, const QUrl & uri, const char *elementName)
00033 {
00034     GstElement *e = gst_element_make_from_uri(static_cast<GstURIType>(type), uri.toEncoded(), elementName);
00035     if (e) {
00036         gst_object_ref_sink(e);
00037     }
00038     return ElementPtr::wrap(e, false);
00039 }
00040 
00041 UriType UriHandler::uriType() const
00042 {
00043     return static_cast<UriType>(gst_uri_handler_get_uri_type(object<GstURIHandler>()));
00044 }
00045 
00046 QStringList UriHandler::supportedProtocols() const
00047 {
00048     QStringList result;
00049     char **protocols = gst_uri_handler_get_protocols(object<GstURIHandler>());
00050     if (protocols) {
00051         for (char **p = protocols; p && *p; ++p) {
00052             result.append(QString::fromUtf8(*p));
00053         }
00054     }
00055     return result;
00056 }
00057 
00058 QUrl UriHandler::uri() const
00059 {
00060     //QUrl::fromEncoded doesn't work because the returned URI
00061     //is encoded using percent encoding even for slashes.
00062     return QUrl::fromPercentEncoding(gst_uri_handler_get_uri(object<GstURIHandler>()));
00063 }
00064 
00065 bool UriHandler::setUri(const QUrl & uri)
00066 {
00067     return gst_uri_handler_set_uri(object<GstURIHandler>(), uri.toEncoded());
00068 }
00069 
00070 } //namespace QGst