diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/mediaManager.cpp | 212 | ||||
-rw-r--r-- | media/mediaManager.o | bin | 0 -> 387416 bytes | |||
-rw-r--r-- | media/pluginManager.cpp | 262 | ||||
-rw-r--r-- | media/pluginManager.o | bin | 0 -> 269696 bytes | |||
-rw-r--r-- | media/profile.cpp | 18 | ||||
-rw-r--r-- | media/profile.o | bin | 0 -> 12960 bytes |
6 files changed, 492 insertions, 0 deletions
diff --git a/media/mediaManager.cpp b/media/mediaManager.cpp new file mode 100644 index 0000000..9740a0b --- /dev/null +++ b/media/mediaManager.cpp @@ -0,0 +1,212 @@ +/* + * mediaManager.cpp + * + * Created on: 01.09.2012 + * Author: savop + */ + +#include "../include/plugin.h" +#include "../include/media/mediaManager.h" +#include "../include/server.h" +#include <upnp/upnp.h> +#include <sstream> +#include <tntdb/result.h> + +namespace upnp { + +cMediaManager::cMediaManager() +: mSystemUpdateID(0) +, mDatabaseFile("metadata.db") +{ +} + +cMediaManager::~cMediaManager(){ +} + +uint32_t cMediaManager::GetSystemUpdateID() const { + return mSystemUpdateID; +} + +IdList cMediaManager::GetContainerUpdateIDs(bool unevented){ + IdList list = mEventedContainerUpdateIDs; + + if(!unevented) + mEventedContainerUpdateIDs.clear(); + + return list; +} + +void cMediaManager::OnContainerUpdate(string containerID, long updateID){ + ++mSystemUpdateID; + + mEventedContainerUpdateIDs[containerID] = updateID; +} + +StringList cMediaManager::GetSearchCapabilities() const { + // TODO: SearchCapabilities ermitteln und zurückgeben. + StringList list; + + return list; +} + +StringList cMediaManager::GetSortCapabilities() const { + // TODO: SortCapabilities ermitteln und zurückgeben. + StringList list; + + return list; +} + +StringList cMediaManager::GetSupportedProtocolInfos() const { + // TODO: ProtocolInfos ermitteln und zurückgeben. + StringList list; + + return list; +} + +int cMediaManager::Browse(BrowseRequest& request){ + request.numberReturned = 0; + request.totalMatches = 0; + request.updateID = 0; + + return UPNP_E_SUCCESS; +} + +int cMediaManager::Search(SearchRequest& request){ + request.numberReturned = 0; + request.totalMatches = 0; + request.updateID = 0; + + return UPNP_E_SUCCESS; +} + +cMediaManager::BrowseFlag cMediaManager::ToBrowseFlag(std::string browseFlag) { + if (browseFlag.compare("BrowseMetadata") == 0) + return CD_BROWSE_METADATA; + else if (browseFlag.compare("BrowseDirectChildren") == 0) + return CD_BROWSE_DIRECT_CHILDREN; + else + return NumBrowseFlags; +} + +bool cMediaManager::Initialise(){ + try { + stringstream ss; + ss << "sqlite:" << mDatabaseFile; + + mConnection = tntdb::connect(ss.str()); + + dsyslog("UPNP\tPreparing database structure..."); + + if(CheckIntegrity()) return true; + + mConnection.beginTransaction(); + + tntdb::Statement objectTable = mConnection.prepare( + "CREATE TABLE metadata" + "(" + " objectID TEXT PRIMARY KEY," + " parentID TEXT NOT NULL," + " title TEXT NOT NULL," + " class TEXT NOT NULL," + " restricted INTEGER NOT NULL," + " description TEXT," + " ldescription TEXT," + " date TEXT," + " language TEXT," + " channelNr INTEGER," + " channelName TEXT," + " scheduledStart TEXT," + " scheduledEnd TEXT" + ")"); + + objectTable.execute(); + + tntdb::Statement detailsTable = mConnection.prepare( + "CREATE TABLE details" + "(" + " propertyID INTEGER PRIMARY KEY," + " objectID TEXT REFERENCES metadata (objectID) ON DELETE CASCADE ON UPDATE CASCADE," + " property TEXT," + " value TEXT" + ")"); + + detailsTable.execute(); + + tntdb::Statement resourcesTable = mConnection.prepare( + "CREATE TABLE resources" + "(" + " resourceID INTEGER PRIMARY KEY," + " objectID TEXT REFERENCES metadata (objectID) ON DELETE CASCADE ON UPDATE CASCADE," + " resourceUri TEXT NOT NULL," + " protocolInfo TEXT NOT NULL," + " size INTEGER," + " duration TEXT," + " resolution TEXT," + " bitrate INTEGER," + " sampleFreq INTEGER," + " bitsPerSample INTEGER," + " nrAudioChannels INTEGER," + " colorDepth INTEGER" + ")"); + + resourcesTable.execute(); + + tntdb::Statement rootContainer = mConnection.prepare( + "INSERT INTO metadata (objectID, parentID, title, class, restricted, description)" + " VALUES (:objectID, :parentID, :title, :class, :restricted, :description)" + ); + + rootContainer.setString("objectID", "0") + .setString("parentID", "-1") + .setString("title", cMediaServer::GetInstance()->GetServerDescription().friendlyName) + .setString("class", "object.container") + .setBool("restricted", true) + .setString("description", cMediaServer::GetInstance()->GetServerDescription().modelDescription) + .execute(); + + mConnection.commitTransaction(); + + return true; + + } catch (const std::exception& e) { + esyslog("UPnP\tException occurred while initializing database: %s", e.what()); + + mConnection.rollbackTransaction(); + + return false; + } + + return false; +} + +bool cMediaManager::CheckIntegrity(){ + + tntdb::Statement checkTable = mConnection.prepare( + "SELECT name FROM sqlite_master WHERE type='table' AND name=:table;" + ); + + if( checkTable.setString("table", "metadata").select().empty() ) return false; + if( checkTable.setString("table", "details").select().empty() ) return false; + if( checkTable.setString("table", "resources").select().empty() ) return false; + + tntdb::Statement checkObject = mConnection.prepare( + "SELECT objectID FROM metadata WHERE objectID='0' AND parentID='-1';" + ); + + if( checkObject.select().size() != 1 ) return false; + + return true; +} + +void cMediaManager::SetDatabaseFile(string file){ + if(file.empty()) mDatabaseFile = "metadata.db"; + else mDatabaseFile = file; +} + +void cMediaManager::Action(){ + +} + +} // namespace upnp + + diff --git a/media/mediaManager.o b/media/mediaManager.o Binary files differnew file mode 100644 index 0000000..aae1479 --- /dev/null +++ b/media/mediaManager.o diff --git a/media/pluginManager.cpp b/media/pluginManager.cpp new file mode 100644 index 0000000..232a9fe --- /dev/null +++ b/media/pluginManager.cpp @@ -0,0 +1,262 @@ +/* + * pluginManager.cpp + * + * Created on: 05.09.2012 + * Author: savop + */ + +#include "../include/plugin.h" +#include "../include/tools.h" +#include <string> + +using namespace std; + +namespace upnp { + +bool cMetadata::SetObjectIDByUri(string uri){ + return SetObjectID(tools::GenerateUUIDFromURL(uri)); +} + +bool cMetadata::SetParentIDByUri(string uri){ + return SetParentID(tools::GenerateUUIDFromURL(uri)); +} + +bool cMetadata::SetObjectID(string objectID){ + if(objectID.empty() || objectID.compare("0") == 0) return false; + + this->objectID = objectID; + + return true; +}; + +bool cMetadata::SetParentID(string parentID){ + if(objectID.compare("-1") == 0) return false; + + this->parentID = parentID; + + return true; +}; + +bool cMetadata::SetTitle(string title){ + this->title = title; + + return true; +}; + +bool cMetadata::SetUpnpClass(string upnpClass){ + //TODO: Validiere upnpClass. + this->upnpClass = upnpClass; + + return true; +}; + +bool cMetadata::SetRestricted(bool restricted){ + this->restricted = restricted; + + return true; +}; + +bool cMetadata::SetDescription(string description){ + this->description = description; + + return true; +}; + +bool cMetadata::SetLongDescription(string longDescription){ + this->longDescription = longDescription; + + return true; +}; + +bool cMetadata::SetDate(string date){ + this->date = date; + + return true; +}; + +bool cMetadata::SetLanguage(string language){ + this->language = language; + + return true; +}; + +bool cMetadata::SetChannelNr(int channelNr){ + this->channelNr = channelNr; + + return true; +}; + +bool cMetadata::SetChannelName(string channelName){ + this->channelName = channelName; + + return true; +}; + +bool cMetadata::SetScheduledStart(string scheduledStart){ + this->scheduledStart = scheduledStart; + + return true; +}; + +bool cMetadata::SetScheduledEnd(string scheduledEnd){ + this->scheduledEnd = scheduledEnd; + + return true; +}; + + +bool cMetadata::AddProperty(Property property){ + properties.insert(pair<string, Property>(property.GetKey(), property)); + return true; +} + +bool cMetadata::SetProperty(Property property, int index){ + PropertyRange ret = properties.equal_range(property.GetKey()); + + // No property with the given name found. Let's add it to the map. + if(ret.first == ret.second) return AddProperty(property); + + int i = 0; + for(PropertyMap::iterator it = ret.first; it != ret.second; ++it){ + if(i == index){ + (*it).second = property; + return true; + } + ++i; + } + + return false; + +} + +cMetadata::PropertyRange cMetadata::GetPropertiesByKey(string property) { + return properties.equal_range(property); +} + +cMetadata::PropertyRange cMetadata::GetAllProperties() { + PropertyRange range(properties.begin(), properties.end()); + return range; +} + +cMetadata::Property& cMetadata::GetPropertyByKey(string property) { + return (*properties.find(property)).second; +} + +cMetadata::Property::Property(string key, bool val) +: key(key) +{ + value = val ? "true" : "false"; +} + +cMetadata::Property::Property(string key, string value) +: key(key) +, value(value) +{ +} + +cMetadata::Property::Property(string key, long val) +: key(key) +{ + value = tools::ToString(val); +} + +string cMetadata::Property::GetString() const { + return value; +} + +bool cMetadata::Property::GetBoolean() const { + return value.compare("true") == 0 ? true : false; +} + +long cMetadata::Property::GetInteger() const { + return atol(value.c_str()); +} + +string cMetadata::Property::GetKey() const { + return key; +} + +bool cMetadata::Resource::SetResourceUri(string resourceUri){ + this->resourceUri = resourceUri; + return true; +} + +bool cMetadata::Resource::SetProtocolInfo(string protocolInfo){ + //TODO validiere protocolInfo. + + this->protocolInfo = protocolInfo; + return true; +} + +bool cMetadata::Resource::SetDuration(string duration){ + this->duration = duration; + return true; +} + +bool cMetadata::Resource::SetResolution(string resolution){ + this->resolution = resolution; + return true; +} + +bool cMetadata::Resource::SetBitrate(uint32_t bitrate){ + this->bitrate = bitrate; + return true; +} + +bool cMetadata::Resource::SetSize(uint32_t size){ + this->size = size; + return true; +} + +bool cMetadata::Resource::SetSampleFrequency(uint32_t sampleFrequency){ + this->sampleFrequency = sampleFrequency; + return true; +} + +bool cMetadata::Resource::SetBitsPerSample(uint32_t bitsPerSample){ + this->bitsPerSample = bitsPerSample; + return true; +} + +bool cMetadata::Resource::SetNrAudioChannels(uint32_t nrAudioChannels){ + this->nrAudioChannels = nrAudioChannels; + return true; +} + +bool cMetadata::Resource::SetColorDepth(uint32_t colorDepth){ + this->colorDepth = colorDepth; + return true; +} + +cMetadata* cUPnPResourceProvider::GetMetadata(string uri){ + + cMetadata* metadata = new cMetadata; + + metadata->SetTitle(uri.substr(uri.find_last_of("/")+1)); + metadata->SetUpnpClass("object.container"); + metadata->SetObjectIDByUri(uri); + metadata->SetParentIDByUri(uri.substr(0,uri.find_last_of("/"))); + metadata->SetRestricted(true); + + return metadata; + +} + +string cUPnPResourceProvider::GetHTTPUri(string uri){ + return string(); +} + +bool cUPnPResourceProvider::Open(string uri){ + return false; +} + +size_t cUPnPResourceProvider::Read(char* buf, size_t bufLen){ + return -1; +} + +void cUPnPResourceProvider::Close(){ +} + +} // namespace uünü + + diff --git a/media/pluginManager.o b/media/pluginManager.o Binary files differnew file mode 100644 index 0000000..ecfa185 --- /dev/null +++ b/media/pluginManager.o diff --git a/media/profile.cpp b/media/profile.cpp new file mode 100644 index 0000000..1b7b81c --- /dev/null +++ b/media/profile.cpp @@ -0,0 +1,18 @@ +/* + * profile.cpp + * + * Created on: 05.08.2012 + * Author: savop + */ + +#include "../include/media/profile.h" + +using namespace upnp; + +image::cIcon image::DLNA_ICON_PNG_SM_24A = { "image/png", 48, 48, 24 }; +image::cIcon image::DLNA_ICON_PNG_LRG_24A = { "image/png", 120, 120, 24 }; + +image::cIcon image::DLNA_ICON_JPEG_SM_24 = { "image/jpeg", 48, 48, 24 }; +image::cIcon image::DLNA_ICON_JPEG_LRG_24 = { "image/jpeg", 120, 120, 24 }; + + diff --git a/media/profile.o b/media/profile.o Binary files differnew file mode 100644 index 0000000..0f9045f --- /dev/null +++ b/media/profile.o |