diff options
-rw-r--r-- | common/tools.cpp | 15 | ||||
-rw-r--r-- | include/media/mediaManager.h | 29 | ||||
-rw-r--r-- | include/tools.h | 2 | ||||
-rw-r--r-- | media/mediaManager.cpp | 61 |
4 files changed, 107 insertions, 0 deletions
diff --git a/common/tools.cpp b/common/tools.cpp index 7ddfc4f..d64b86b 100644 --- a/common/tools.cpp +++ b/common/tools.cpp @@ -137,6 +137,21 @@ string GenerateUUIDRandomly(){ return uuid.str(); } +void StringExplode(string str, string separator, StringVector results) { + int found; + found = str.find_first_of(separator); + while(found != string::npos){ + if(found > 0){ + results.push_back(str.substr(0,found)); + } + str = str.substr(found+1); + found = str.find_first_of(separator); + } + if(str.length() > 0){ + results.push_back(str); + } +} + } // namespace tools namespace ixml { diff --git a/include/media/mediaManager.h b/include/media/mediaManager.h index 41707d1..7e97799 100644 --- a/include/media/mediaManager.h +++ b/include/media/mediaManager.h @@ -18,6 +18,33 @@ namespace upnp { +class cMediaManager; + +class cResourceStreamer { + friend class cMediaManager; +private: + cUPnPResourceProvider* provider; + cMetadata::Resource* resource; + + cMediaManager* manager; + + StringVector protocolInfo; + + cResourceStreamer(cMediaManager* manager, cUPnPResourceProvider* provider, cMetadata::Resource* resource); +public: + std::string GetContentFeatures() const; + size_t GetContentLength() const; + std::string GetContentType() const; + std::string GetTransferMode(const std::string& requestedMode ) const; + std::string GetRange() const; + std::string GetAvailableSeekRange(const std::string& seekRequest) const; + + bool Open(string uri); + size_t Read(char* buf, size_t bufLen); + bool Seek(size_t offset, int origin); + void Close(); +}; + class cMediaManager : public cThread { private: @@ -67,6 +94,8 @@ public: static BrowseFlag ToBrowseFlag(std::string browseFlag); + cResourceStreamer* GetResourceStreamer(std::string objectID); + private: void Action(); diff --git a/include/tools.h b/include/tools.h index e322adc..008b74a 100644 --- a/include/tools.h +++ b/include/tools.h @@ -121,6 +121,8 @@ namespace tools { string GenerateUUIDFromURL(string url); string GenerateUUIDRandomly(); + + void StringExplode(string str, string separator, StringVector results); } namespace ixml { diff --git a/media/mediaManager.cpp b/media/mediaManager.cpp index 38e623d..33fafbd 100644 --- a/media/mediaManager.cpp +++ b/media/mediaManager.cpp @@ -32,6 +32,67 @@ static const char* Details = "details"; } +cResourceStreamer::cResourceStreamer(cMediaManager* manager, cUPnPResourceProvider* provider, cMetadata::Resource* resource) +: provider(provider) +, resource(resource) +, manager(manager) +{ + if(resource) + tools::StringExplode(resource->protocolInfo,"*",protocolInfo); +} + +std::string cResourceStreamer::GetContentFeatures() const { + if(resource == NULL) return string(); + + return protocolInfo[3]; +} + +std::string cResourceStreamer::GetContentType() const { + if(resource == NULL) return string(); + + return protocolInfo[2]; +} + +size_t cResourceStreamer::GetContentLength() const { + if(resource == NULL) return 0; + + return resource->GetSize(); +} + +std::string cResourceStreamer::GetTransferMode(const string&) const { + std::string mime = GetContentType(); + + if(mime.empty()) return mime; + + if(mime.find("video",0) == 0 || mime.find("audio",0) == 0) return "Streaming"; + else return "Interactive"; +} + +std::string cResourceStreamer::GetRange() const { + return string(); +} + +std::string cResourceStreamer::GetAvailableSeekRange(const string& seekRequest) const { + return string(); +} + +bool cResourceStreamer::Open(string uri){ + return provider->Open(uri); +} + +size_t cResourceStreamer::Read(char* buf, size_t bufLen){ + return provider->Read(buf, bufLen); +} + +bool cResourceStreamer::Seek(size_t offset, int origin){ + return provider->Seek(offset, origin); +} + +void cResourceStreamer::Close(){ + provider->Close(); +} + + cMediaManager::cMediaManager() : mSystemUpdateID(0) , mDatabaseFile("metadata.db") |