tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / gstreamer / URIUtils.cpp
1 /*
2     Copyright (C) 2012 Samsung Electronics.
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.1 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 License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21 #include "URIUtils.h"
22
23 #if ENABLE(TIZEN_MEDIA_STREAM)
24 #include "MediaStream.h"
25 #include "MediaStreamRegistry.h"
26 #endif // ENABLE(TIZEN_MEDIA_STREAM)
27
28 #if ENABLE(TIZEN_FILE_SYSTEM)
29 #include "AsyncFileSystem.h"
30 #include "Blob.h"
31 #include "BlobRegistryImpl.h"
32 #include "DOMFileSystemBase.h"
33 #include "LocalFileSystem.h"
34 #endif // ENABLE(TIZEN_FILE_SYSTEM)
35
36 namespace WebCore {
37
38 static void crackBlobURI(const String& url)
39 {
40 #if ENABLE(TIZEN_MEDIA_STREAM)
41     MediaStreamDescriptor* descriptor = MediaStreamRegistry::registry().lookupMediaStreamDescriptor(url);
42     if (descriptor) {
43         for (unsigned int i = 0; i < descriptor->numberOfVideoComponents(); i++) {
44             MediaStreamSource* source = descriptor->videoComponent(i)->source();
45             if (source) {
46                 int cameraId = (source->name() == "Self camera") ? 1 : 0;
47                 String& mutableUrl = const_cast<String&>(url);
48                 String cameraUrl = String::format("camera://%d", cameraId);
49                 mutableUrl.swap(cameraUrl);
50                 return;
51             }
52         }
53     }
54 #endif // ENABLE(TIZEN_MEDIA_STREAM)
55
56 #if ENABLE(TIZEN_FILE_SYSTEM)
57     const KURL blobURL(ParsedURLString, url.utf8().data());
58     RefPtr<BlobStorageData> blobStorage = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(blobURL);
59     if (blobStorage) {
60         String filePath;
61         for (unsigned int i = 0; i < blobStorage->items().size(); i++) {
62             const BlobDataItem& blobItem = blobStorage->items()[i];
63             if (blobItem.type == BlobDataItem::File) {
64                 String& mutableUrl = const_cast<String&>(url);
65                 String fileUrl = "file://" + blobItem.path;
66                 mutableUrl.swap(fileUrl);
67             }
68         }
69     }
70 #endif // ENABLE(TIZEN_FILE_SYSTEM)
71 }
72
73 static void crackFileSystemURI(const String& url)
74 {
75 #if ENABLE(TIZEN_FILE_SYSTEM)
76     const KURL filesystemURL(ParsedURLString, url.utf8().data());
77     FileSystemType type;
78     String filePath;
79     DOMFileSystemBase::crackFileSystemURL(filesystemURL, type, filePath);
80     String fileUrl = "file://" + LocalFileSystem::localFileSystem().fileSystemBasePath() + filePath;
81     String& mutableUrl = const_cast<String&>(url);
82     mutableUrl.swap(fileUrl);
83 #endif // ENABLE(TIZEN_FILE_SYSTEM)
84 }
85
86 void crackURI(const String& url)
87 {
88     if (url.contains("blob:"))
89         crackBlobURI(url);
90     else if (url.contains("filesystem:"))
91         crackFileSystemURI(url);
92 }
93
94 } // namespace WebCore