diff options
author | methodus <methodus@web.de> | 2012-10-13 23:43:30 +0200 |
---|---|---|
committer | methodus <methodus@web.de> | 2012-10-13 23:43:30 +0200 |
commit | 0c340aeb1ea7474b3c4256b0f3272bf70d33cadb (patch) | |
tree | 0a88c8c23ecd306bbc93590780b055b1eb643f40 /plugins/provider/recProvider | |
parent | 5ddef2b47d987323419a5411169dbb8a855f2e70 (diff) | |
download | vdr-plugin-upnp-0c340aeb1ea7474b3c4256b0f3272bf70d33cadb.tar.gz vdr-plugin-upnp-0c340aeb1ea7474b3c4256b0f3272bf70d33cadb.tar.bz2 |
Added recProvider to load and stream recordings
Diffstat (limited to 'plugins/provider/recProvider')
-rw-r--r-- | plugins/provider/recProvider/Makefile | 56 | ||||
-rwxr-xr-x | plugins/provider/recProvider/libupnp-rec-provider.so.1.0.0 | bin | 0 -> 256420 bytes | |||
-rw-r--r-- | plugins/provider/recProvider/recProvider.cpp | 143 |
3 files changed, 199 insertions, 0 deletions
diff --git a/plugins/provider/recProvider/Makefile b/plugins/provider/recProvider/Makefile new file mode 100644 index 0000000..85adf12 --- /dev/null +++ b/plugins/provider/recProvider/Makefile @@ -0,0 +1,56 @@ +# +# Makefile for a UPnP provider plugin +# +# $Id$ +# + +# +# This is the schema of the provider plugin. It is used +# to determine how a resource may be accessed. +# +SCHEMA = rec + +### The version number of this plugin (taken from the main source file): + +VERSION = $(shell grep 'static const char \*VERSION *=' $(SCHEMA)Provider.cpp | awk '{ print $$6 }' | sed -e 's/[";]//g') + +### The C++ compiler and options: + +CXX ?= g++ +CXXFLAGS ?= -g -O3 -Wall -Werror=overloaded-virtual -Wno-parentheses -fPIC + +UPNPDIR ?= ../../.. +VDRLIBDIR ?= $(UPNPDIR)/../../lib + +APIVERSION = $(shell sed -ne '/define UPNPPLUGIN_VERSION/s/^.*"\(.*\)".*$$/\1/p' $(UPNPDIR)/include/plugin.h) + +INCLUDES += -I$(UPNPDIR)/include + +DEFINES += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE + +OBJS = $(SCHEMA)Provider.o + +LIBS = -L$(VDRLIBDIR) -Wl,-R$(VDRLIBDIR) -lvdr-upnp + +all: libupnp-$(SCHEMA)-provider.so + +### Implicit rules: + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) -o $@ $< + +### Dependencies: + +MAKEDEP = $(CXX) -MM -MG +DEPFILE = .dependencies +$(DEPFILE): Makefile + @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.cpp) > $@ + +-include $(DEPFILE) + +libupnp-$(SCHEMA)-provider.so: $(OBJS) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) $(LIBS) -o $@ + @cp --remove-destination $@ $@.$(APIVERSION) + +clean: + @-rm -f $(OBJS) $(DEPFILE) *.so *.so.$(APIVERSION) core* *~ diff --git a/plugins/provider/recProvider/libupnp-rec-provider.so.1.0.0 b/plugins/provider/recProvider/libupnp-rec-provider.so.1.0.0 Binary files differnew file mode 100755 index 0000000..0719cd2 --- /dev/null +++ b/plugins/provider/recProvider/libupnp-rec-provider.so.1.0.0 diff --git a/plugins/provider/recProvider/recProvider.cpp b/plugins/provider/recProvider/recProvider.cpp new file mode 100644 index 0000000..ec6bca6 --- /dev/null +++ b/plugins/provider/recProvider/recProvider.cpp @@ -0,0 +1,143 @@ +/* + * vdrProvider.cpp + * + * Created on: 01.10.2012 + * Author: savop + */ + +#include <plugin.h> +#include <vdr/recording.h> +#include <vdr/channels.h> +#include <vdr/tools.h> +#include <vdr/config.h> +#include <vdr/videodir.h> +#include <string> +#include <sstream> +#include <tools.h> +#include <pwd.h> +#include <unistd.h> + +using namespace std; + +namespace upnp { + +class RecProvider : public cUPnPResourceProvider { +private: + + bool IsRootContainer(const string& uri){ + if(uri.find(GetRootContainer(), 0) != 0){ + isyslog("RecProvider\tUri does not contain the root."); + return false; + } else { + return true; + } + } + + bool GetFileStat(const string& uri, struct stat& fileStat){ + stringstream filename; + filename << VideoDirectory << "/" << uri.substr(6); + struct stat s; + if(stat(filename.str().c_str(), &s) == 0){ + fileStat = s; + return true; + } + + return false; + } + +public: + + RecProvider() + {} + + virtual ~RecProvider(){ + Cancel(2); + } + + virtual string ProvidesSchema(){ return "rec"; } + + virtual string GetRootContainer(){ + return ProvidesSchema() + "://"; + } + + virtual StringList GetContainerEntries(const string& uri){ + cerr << "Getting container entries for recordings in " << uri << endl; + + if(!IsRootContainer(uri)) return StringList(); + + StringList list; + + stringstream filename; string recFilename, p; + filename << VideoDirectory << "/" << uri.substr(6); + for(cRecording* rec = Recordings.First(); rec; rec = Recordings.Next(rec)){ + recFilename = rec->FileName(); + if(recFilename.find(filename.str()) == 0){ + p = recFilename.substr(filename.str().length()); + if(p.find_first_of('/')){ + p = p.substr(0, p.find_first_of('/')); + list.push_back(p); + } + } + } + + return list; + } + + virtual bool IsContainer(const string& uri){ + if(GetRootContainer().compare(uri) == 0) return true; + + if(!Recordings.GetByName(uri.substr(6).c_str())) return true; + else return false; + } + + virtual bool IsLink(const string& uri, string& target){ + return false; + } + + virtual long GetContainerUpdateId(const string& uri){ + struct stat fileStat; + if(GetFileStat(uri.substr(0,uri.find_last_of('/')), fileStat)){ + return std::max<time_t>(fileStat.st_ctim.tv_sec, fileStat.st_mtim.tv_sec); + } + + return 0; + } + + virtual bool GetMetadata(const string& uri, cMetadata& metadata){ + if(GetRootContainer().compare(uri) == 0){ + if(!cUPnPResourceProvider::GetMetadata(uri, metadata)) return false; + metadata.SetProperty(cMetadata::Property(property::object::KEY_PARENTID, string("0"))); + metadata.SetProperty(cMetadata::Property(property::object::KEY_TITLE, string("VDR Recordings"))); + + struct passwd *pw; + if((pw = getpwuid(getuid())) == NULL){ + metadata.SetProperty(cMetadata::Property(property::object::KEY_CREATOR, string("Klaus Schmidinger"))); + } else { + string name(pw->pw_gecos); name = name.substr(0,name.find(",,,",0)); + metadata.SetProperty(cMetadata::Property(property::object::KEY_CREATOR, name)); + } + + metadata.SetProperty(cMetadata::Property(property::object::KEY_DESCRIPTION, string("Watch TV recordings"))); + + return true; + } + + return false; + } + + virtual void Action(){ + while(Running()){ + int state = 0; + if(Recordings.NeedsUpdate() || Recordings.StateChanged(state)){ + OnContainerUpdate(GetRootContainer(), GetContainerUpdateId(GetRootContainer())); + } + sleep(5); + } + } + +}; + +UPNP_REGISTER_RESOURCE_PROVIDER(RecProvider); + +} // namespace upnp + |