summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormethodus <methodus@web.de>2012-10-13 22:58:00 +0200
committermethodus <methodus@web.de>2012-10-13 22:58:00 +0200
commit5ddef2b47d987323419a5411169dbb8a855f2e70 (patch)
tree6f07f31f337d6ab9693176c036c8898ef8ebc210
parentb450015b9a6c0d35c264e93fbc9bcdf92538f47a (diff)
downloadvdr-plugin-upnp-5ddef2b47d987323419a5411169dbb8a855f2e70.tar.gz
vdr-plugin-upnp-5ddef2b47d987323419a5411169dbb8a855f2e70.tar.bz2
Added codec toolkit for getting detailed media information
-rw-r--r--Makefile3
-rw-r--r--common/codec.cpp65
-rw-r--r--include/media/profile.h8
-rw-r--r--include/tools/codec.h53
-rw-r--r--media/mediaManager.cpp2
-rw-r--r--plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp50
6 files changed, 163 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 71adef3..761e2ca 100644
--- a/Makefile
+++ b/Makefile
@@ -73,12 +73,13 @@ OBJS = $(PLUGIN).o \
common/parser.o \
common/setup.o \
common/ixml.o \
+ common/codec.o \
media/profile.o \
media/mediaManager.o \
media/pluginManager.o \
$(TNTOBJ)
-LIBS += -lupnp -lcxxtools -ltntnet -ltntdb -ldl
+LIBS += -lupnp -lcxxtools -ltntnet -ltntdb -ldl -lavformat -lavcodec
### The main target:
diff --git a/common/codec.cpp b/common/codec.cpp
new file mode 100644
index 0000000..d38a8e5
--- /dev/null
+++ b/common/codec.cpp
@@ -0,0 +1,65 @@
+/*
+ * codec.cpp
+ *
+ * Created on: 13.10.2012
+ * Author: savop
+ */
+
+#include "../include/tools/codec.h"
+
+namespace upnp {
+
+namespace codec {
+
+cFormatContext::cFormatContext()
+: formatCtx(NULL)
+{
+ av_register_all();
+}
+
+cFormatContext::~cFormatContext(){
+ av_free(formatCtx);
+}
+
+bool cFormatContext::Open(const string& file){
+ if(avformat_open_input(&formatCtx, file.c_str(), NULL, NULL) == 0){
+ if(avformat_find_stream_info(formatCtx, NULL) == 0){
+ return true;
+ }
+ }
+
+ return false;
+}
+
+const AVCodec* cFormatContext::GetCodec(AVMediaType Type) const {
+ return avcodec_find_decoder(GetCodecContext(Type)->codec_id);
+}
+
+const AVCodecContext* cFormatContext::GetCodecContext(AVMediaType Type) const {
+ const AVStream* strm = GetStream(Type);
+ return strm?strm->codec:NULL;
+}
+
+const AVStream* cFormatContext::GetStream(AVMediaType Type) const {
+ if(!formatCtx) return NULL;
+ int Stream = -1; unsigned int i;
+ for(i = 0; i < formatCtx->nb_streams; i++){
+ if(formatCtx->streams[i]->codec->codec_type == Type){
+ Stream = i;
+ break;
+ }
+ }
+ if(Stream == -1){
+ return NULL;
+ }
+
+ return formatCtx->streams[Stream];
+}
+
+AVFormatContext* cFormatContext::operator*() const {
+ return formatCtx;
+}
+
+} // namespace codec
+
+} // namespace upnp
diff --git a/include/media/profile.h b/include/media/profile.h
index efac36d..845ed24 100644
--- a/include/media/profile.h
+++ b/include/media/profile.h
@@ -74,14 +74,6 @@ struct ProtocolInfo {
string ToString();
};
-namespace video {
-
-}
-
-namespace audio {
-
-}
-
namespace image {
struct cIcon {
diff --git a/include/tools/codec.h b/include/tools/codec.h
new file mode 100644
index 0000000..768fa15
--- /dev/null
+++ b/include/tools/codec.h
@@ -0,0 +1,53 @@
+/*
+ * codec.h
+ *
+ * Created on: 12.10.2012
+ * Author: savop
+ */
+
+#ifndef CODEC_H_
+#define CODEC_H_
+
+#ifdef __cplusplus
+ #define __STDC_CONSTANT_MACROS
+ #ifdef _STDINT_H
+ #undef _STDINT_H
+ #endif
+ #include <stdint.h>
+#endif
+
+extern "C" {
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+}
+
+#include <string>
+
+using namespace std;
+
+namespace upnp {
+
+namespace codec {
+
+class cFormatContext {
+public:
+ cFormatContext();
+ virtual ~cFormatContext();
+
+ bool Open(const string& file);
+
+ const AVCodec* GetCodec(AVMediaType Type) const;
+ const AVCodecContext* GetCodecContext(AVMediaType Type) const;
+ const AVStream* GetStream(AVMediaType Type) const;
+
+ AVFormatContext* operator*() const;
+private:
+ AVFormatContext* formatCtx;
+};
+
+}
+
+}
+
+
+#endif /* CODEC_H_ */
diff --git a/media/mediaManager.cpp b/media/mediaManager.cpp
index 377ed19..f5b833f 100644
--- a/media/mediaManager.cpp
+++ b/media/mediaManager.cpp
@@ -593,7 +593,7 @@ bool cMediaManager::Initialise(){
dsyslog("UPnP\tFound %d plugins", pluginManager->Count());
}
- dsyslog("UPNP\tScanning directories...");
+ dsyslog("UPnP\tScanning directories...");
// Do an full initial scan on startup.
upnp::cPluginManager::ProviderList providers = pluginManager->GetProviders();
for(upnp::cPluginManager::ProviderList::iterator it = providers.begin(); it != providers.end(); ++it){
diff --git a/plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp b/plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp
index 06948ac..a54c1af 100644
--- a/plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp
+++ b/plugins/profiler/vdrDVBProfiler/dvbProfiler.cpp
@@ -5,8 +5,10 @@
* Author: savop
*/
+#include <tools/codec.h>
#include <server.h>
#include <webserver.h>
+#include <vdr/recording.h>
#include <vdr/channels.h>
#include <vdr/epg.h>
#include <vdr/tools.h>
@@ -17,6 +19,8 @@
#include <media/profile.h>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <libavformat/avformat.h>
+#include <libavcodec/avcodec.h>
using namespace std;
@@ -45,8 +49,37 @@ public:
private:
virtual bool GetRecordingMetadata(const string& uri, cMetadata& metadata){
- //TODO
- return false;
+ cRecording* recording = Recordings.GetByName(uri.substr(6).c_str());
+
+ if(!recording) return false;
+
+ string parentUri = recording->FileName();
+
+ const cRecordingInfo* info = recording->Info();
+
+ metadata.SetObjectIDByUri(uri);
+ metadata.SetParentIDByUri(parentUri);
+ metadata.SetProperty(cMetadata::Property(property::object::KEY_CLASS, string("object.item.videoItem.videoBroadcast")));
+ metadata.SetProperty(cMetadata::Property(property::object::KEY_RESTRICTED, true));
+
+ metadata.SetProperty(cMetadata::Property(property::object::KEY_TITLE, string(info->Title())));
+ metadata.SetProperty(cMetadata::Property(property::object::KEY_DESCRIPTION, string(info->ShortText())));
+ metadata.SetProperty(cMetadata::Property(property::object::KEY_LONG_DESCRIPTION, string(info->Description())));
+
+ boost::posix_time::ptime date = boost::posix_time::from_time_t(info->GetEvent()->StartTime());
+ metadata.SetProperty(cMetadata::Property(property::object::KEY_DATE, boost::gregorian::to_iso_extended_string(date.date())));
+
+// cMetadata::Resource resource;
+//
+// codec::cFormatContext formatContext;
+//
+// if(formatContext.Open(recording->FileName())){
+//
+// }
+//
+// metadata.AddResource(resource);
+
+ return true;
}
virtual bool GetChannelMetadata(const string& uri, cMetadata& metadata){
@@ -63,6 +96,8 @@ private:
metadata.SetObjectIDByUri(uri);
metadata.SetParentIDByUri(parentUri);
+
+ // TODO: implement check for radio stations (this is ...audioItem.audioBroadcast)
metadata.SetProperty(cMetadata::Property(property::object::KEY_CLASS, string("object.item.videoItem.videoBroadcast")));
metadata.SetProperty(cMetadata::Property(property::object::KEY_RESTRICTED, true));
metadata.SetProperty(cMetadata::Property(property::object::KEY_CHANNEL_NAME, string(channel->Name())));
@@ -87,14 +122,17 @@ private:
metadata.SetProperty(cMetadata::Property(property::object::KEY_DATE, boost::gregorian::to_iso_extended_string(startTime.date())));
metadata.SetProperty(cMetadata::Property(property::object::KEY_SCHEDULED_START, boost::posix_time::to_iso_extended_string(startTime)));
metadata.SetProperty(cMetadata::Property(property::object::KEY_SCHEDULED_END, boost::posix_time::to_iso_extended_string(endTime)));
- metadata.SetProperty(cMetadata::Property(property::object::KEY_DESCRIPTION, string(event->ShortText())));
- metadata.SetProperty(cMetadata::Property(property::object::KEY_LONG_DESCRIPTION, string(event->Description())));
+ metadata.SetProperty(cMetadata::Property(property::object::KEY_DESCRIPTION, string(event->ShortText()?event->ShortText():"")));
+ metadata.SetProperty(cMetadata::Property(property::object::KEY_LONG_DESCRIPTION, string(event->Description()?event->Description():"")));
} else {
metadata.SetProperty(cMetadata::Property(property::object::KEY_TITLE, string(channel->Name())));
}
cMetadata::Resource resource;
+ resource.SetResourceUri(uri);
+
+ // TODO: implement check for radio stations
DLNA4thField fourthfield;
switch (channel->Vtype()) {
case 0x02:
@@ -116,7 +154,6 @@ private:
break;
}
- resource.SetResourceUri(uri);
resource.SetProtocolInfo(ProtocolInfo("video/mpeg", fourthfield).ToString());
if(event){
@@ -139,14 +176,11 @@ private:
struct stat fileStat;
- dsyslog("DVBProvider\tTry to get thumbnail for %s in %s", channel->Name(), filename.str().c_str());
if(stat(filename.str().c_str(), &fileStat) == 0){
thumbnail.SetResourceUri(uriStrm.str());
thumbnail.SetProtocolInfo(ProtocolInfo("image/jpeg", DLNA4thField("JPEG_TN")).ToString());
thumbnail.SetSize(fileStat.st_size);
metadata.AddResource(thumbnail);
- } else {
- dsyslog("DVBProvider\tFailed to stat %s", filename.str().c_str());
}
return true;