summaryrefslogtreecommitdiffstats
path: root/kfile-plugins/theora
diff options
context:
space:
mode:
Diffstat (limited to 'kfile-plugins/theora')
-rw-r--r--kfile-plugins/theora/Makefile.am22
-rw-r--r--kfile-plugins/theora/configure.in.bot7
-rw-r--r--kfile-plugins/theora/configure.in.in26
-rw-r--r--kfile-plugins/theora/kfile_theora.cpp322
-rw-r--r--kfile-plugins/theora/kfile_theora.desktop60
-rw-r--r--kfile-plugins/theora/kfile_theora.h42
6 files changed, 479 insertions, 0 deletions
diff --git a/kfile-plugins/theora/Makefile.am b/kfile-plugins/theora/Makefile.am
new file mode 100644
index 00000000..e2029d87
--- /dev/null
+++ b/kfile-plugins/theora/Makefile.am
@@ -0,0 +1,22 @@
+## Makefile.am for ogg/vorbis file meta info plugin
+
+# set the include path for X, qt and KDE
+INCLUDES = $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = kfile_theora.h
+
+kde_module_LTLIBRARIES = kfile_theora.la
+
+kfile_theora_la_SOURCES = kfile_theora.cpp
+kfile_theora_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kfile_theora_la_LIBADD = $(LIB_KIO) -logg -lvorbis -ltheora
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) kfile_theora.cpp -o $(podir)/kfile_theora.pot
+
+services_DATA = kfile_theora.desktop
+servicesdir = $(kde_servicesdir)
diff --git a/kfile-plugins/theora/configure.in.bot b/kfile-plugins/theora/configure.in.bot
new file mode 100644
index 00000000..926a39e9
--- /dev/null
+++ b/kfile-plugins/theora/configure.in.bot
@@ -0,0 +1,7 @@
+if test "x$with_theora" = xcheck && test "x$have_theora" = xno; then
+ echo ""
+ echo "Ogg Theora support was not found."
+ echo "a KFile-plugin for displaying Ogg Theora Information"
+ echo "has been disabled from compilation."
+ all_tests=bad
+fi
diff --git a/kfile-plugins/theora/configure.in.in b/kfile-plugins/theora/configure.in.in
new file mode 100644
index 00000000..b9d8836d
--- /dev/null
+++ b/kfile-plugins/theora/configure.in.in
@@ -0,0 +1,26 @@
+AC_DEFUN([KDE_CHECK_THEORA],
+[
+have_theora=yes
+
+KDE_CHECK_HEADER(theora/theora.h,
+ [], [have_theora=no])
+
+KDE_CHECK_LIB(theora, theora_info_init,
+ [], [have_theora=no], [-lvorbis -logg])
+])
+
+AC_ARG_WITH(theora,
+ [AC_HELP_STRING(--with-theora,
+ [enable support for Ogg Theora @<:@default=check@:>@])],
+ [], with_theora=check)
+
+have_theora=no
+if test "x$with_theora" != xno; then
+ KDE_CHECK_THEORA
+
+ if test "x$with_theora" != xcheck && test "x$have_theora" != xyes; then
+ AC_MSG_ERROR([--with-theora was given, but test for Theora failed])
+ fi
+fi
+
+AM_CONDITIONAL(include_theora_SUBDIR, test "x$have_theora" = xyes)
diff --git a/kfile-plugins/theora/kfile_theora.cpp b/kfile-plugins/theora/kfile_theora.cpp
new file mode 100644
index 00000000..35dee3d9
--- /dev/null
+++ b/kfile-plugins/theora/kfile_theora.cpp
@@ -0,0 +1,322 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Jean-Baptiste Mardelle *
+ * bj@altern.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include <qfile.h>
+#include <config.h>
+#include "kfile_theora.h"
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kgenericfactory.h>
+
+#include "theora/theora.h"
+#include "vorbis/codec.h"
+
+ogg_stream_state t_stream_state;
+ogg_stream_state v_stream_state;
+
+int theora_p=0;
+int vorbis_p=0;
+
+static int queue_page(ogg_page *page)
+{
+ if(theora_p)
+ ogg_stream_pagein(&t_stream_state,page);
+ if(vorbis_p)
+ ogg_stream_pagein(&v_stream_state,page);
+ return 0;
+}
+
+static int buffer_data(FILE *in,ogg_sync_state *oy)
+{
+ char *buffer=ogg_sync_buffer(oy,4096);
+ int bytes=fread(buffer,1,4096,in);
+ ogg_sync_wrote(oy,bytes);
+ return(bytes);
+}
+
+typedef KGenericFactory<theoraPlugin> theoraFactory;
+
+K_EXPORT_COMPONENT_FACTORY(kfile_theora, theoraFactory( "kfile_theora" ))
+
+theoraPlugin::theoraPlugin(QObject *parent, const char *name,
+ const QStringList &args)
+ : KFilePlugin(parent, name, args)
+{
+// kdDebug(7034) << "theora plugin\n";
+
+ KFileMimeTypeInfo* info = addMimeTypeInfo( "video/x-theora" );
+
+ KFileMimeTypeInfo::GroupInfo* group = 0;
+ KFileMimeTypeInfo::ItemInfo* item;
+
+ // video group
+
+ group = addGroupInfo(info, "Video", i18n("Video Details"));
+ setAttributes(group, 0);
+ item = addItemInfo(group, "Length", i18n("Length"), QVariant::Int);
+ setUnit(item, KFileMimeTypeInfo::Seconds);
+ setHint(item, KFileMimeTypeInfo::Length);
+ item = addItemInfo(group, "Resolution", i18n("Resolution"), QVariant::Size);
+ setHint(item, KFileMimeTypeInfo::Size);
+ setUnit(item, KFileMimeTypeInfo::Pixels);
+ item = addItemInfo(group, "FrameRate", i18n("Frame Rate"), QVariant::Int);
+ setUnit(item, KFileMimeTypeInfo::FramesPerSecond);
+ item = addItemInfo(group, "TargetBitrate", i18n("Target Bitrate"), QVariant::Int);
+ setUnit(item, KFileMimeTypeInfo::Bitrate);
+ item = addItemInfo(group, "Quality", i18n("Quality"), QVariant::Int);
+
+ // audio group
+
+ group = addGroupInfo(info, "Audio", i18n("Audio Details"));
+ setAttributes(group, 0);
+ addItemInfo(group, "Channels", i18n("Channels"), QVariant::Int);
+
+ item = addItemInfo(group, "SampleRate", i18n("Sample Rate"), QVariant::Int);
+ setUnit(item, KFileMimeTypeInfo::Hertz);
+}
+
+bool theoraPlugin::readInfo( KFileMetaInfo& info, uint what)
+{
+ // most of the ogg stuff was borrowed from libtheora/examples/player_example.c
+ FILE *fp;
+
+ ogg_sync_state o_sync_state;
+ ogg_packet o_packet;
+ ogg_page o_page;
+
+ theora_info t_info;
+ theora_comment t_comment;
+ theora_state t_state;
+ vorbis_info v_info;
+ vorbis_comment v_comment;
+
+ theora_p=0;
+ vorbis_p=0;
+ int theora_serial=0;
+ int stateflag=0;
+
+ ogg_int64_t duration=0;
+
+ // libtheora is still a bit unstable and sadly the init_ functions don't
+ // take care of things the way one would expect. So, let's do some explicit
+ // clearing of these fields.
+
+ memset(&t_info, 0, sizeof(theora_info));
+ memset(&t_comment, 0, sizeof(theora_comment));
+ memset(&t_state, 0, sizeof(theora_state));
+
+ bool readTech = false;
+
+ if (what & (KFileMetaInfo::Fastest |
+ KFileMetaInfo::DontCare |
+ KFileMetaInfo::TechnicalInfo))
+ readTech = true;
+
+ if ( info.path().isEmpty() ) // remote file
+ return false;
+
+ fp = fopen(QFile::encodeName(info.path()),"rb");
+ if (!fp)
+ {
+ kdDebug(7034) << "Unable to open " << QFile::encodeName(info.path()) << endl;
+ return false;
+ }
+
+ ogg_sync_init(&o_sync_state);
+
+ /* init supporting Vorbis structures needed in header parsing */
+ vorbis_info_init(&v_info);
+ vorbis_comment_init(&v_comment);
+
+ /* init supporting Theora structures needed in header parsing */
+ theora_comment_init(&t_comment);
+ theora_info_init(&t_info);
+
+ while(!stateflag && buffer_data(fp,&o_sync_state)!=0)
+ {
+ while (ogg_sync_pageout(&o_sync_state,&o_page)>0)
+ {
+ ogg_stream_state stream_test;
+ /* is this a mandated initial header? If not, stop parsing */
+ if(!ogg_page_bos(&o_page))
+ {
+ queue_page(&o_page);
+ stateflag=1;
+ break;
+ }
+
+ ogg_stream_init(&stream_test,ogg_page_serialno(&o_page));
+ ogg_stream_pagein(&stream_test,&o_page);
+ ogg_stream_packetout(&stream_test,&o_packet);
+
+ /* identify the codec: try theora */
+ if(!theora_p && theora_decode_header(&t_info,&t_comment,&o_packet)>=0)
+ {
+ /* it is theora */
+ memcpy(&t_stream_state,&stream_test,sizeof(stream_test));
+ theora_serial=ogg_page_serialno(&o_page);
+ theora_p=1;
+ }
+ else if(!vorbis_p && vorbis_synthesis_headerin(&v_info,&v_comment,&o_packet)>=0)
+ {
+ /* it is vorbis */
+ memcpy(&v_stream_state,&stream_test,sizeof(stream_test));
+ vorbis_p=1;
+ }
+ else
+ {
+ /* whatever it is, we don't care about it */
+ ogg_stream_clear(&stream_test);
+ }
+ }
+ }
+
+ /* we're expecting more header packets. */
+ bool corruptedHeaders=false;
+
+ while((theora_p && theora_p<3) || (vorbis_p && vorbis_p<3))
+ {
+ int ret;
+ /* look for further theora headers */
+ while(theora_p && (theora_p<3) && (ret=ogg_stream_packetout(&t_stream_state,&o_packet)))
+ {
+ if(ret<0)
+ {
+ kdDebug(7034)<<"Error parsing Theora stream headers; corrupt stream?\n"<<endl;
+ corruptedHeaders=true;
+ }
+ if(theora_decode_header(&t_info,&t_comment,&o_packet))
+ {
+ kdDebug(7034)<<"Error parsing Theora stream headers; corrupt stream?"<<endl;
+ corruptedHeaders=true;
+ }
+ theora_p++;
+ if(theora_p==3)
+ break;
+ }
+
+ /* look for more vorbis header packets */
+ while(vorbis_p && (vorbis_p<3) && (ret=ogg_stream_packetout(&v_stream_state,&o_packet)))
+ {
+ if(ret<0)
+ {
+ kdDebug(7034)<<"Error parsing Vorbis stream headers; corrupt stream"<<endl;
+ corruptedHeaders=true;
+ }
+ if(vorbis_synthesis_headerin(&v_info,&v_comment,&o_packet))
+ {
+ kdDebug(7034)<<"Error parsing Vorbis stream headers; corrupt stream?"<<endl;
+ corruptedHeaders=true;
+ }
+ vorbis_p++;
+ if(vorbis_p==3)
+ break;
+ }
+ /* The header pages/packets will arrive before anything else we
+ care about, or the stream is not obeying spec */
+
+ if(ogg_sync_pageout(&o_sync_state,&o_page)>0)
+ {
+ queue_page(&o_page);
+ /* demux into the appropriate stream */
+ }
+ else
+ {
+ int ret=buffer_data(fp,&o_sync_state); /* someone needs more data */
+ if(ret==0)
+ {
+ kdDebug(7034)<<"End of file while searching for codec headers."<<endl;
+ corruptedHeaders=true;
+ }
+ }
+ }
+
+ /* and now we have it all. initialize decoders */
+ if(theora_p && !corruptedHeaders)
+ {
+ theora_decode_init(&t_state,&t_info);
+ }
+ else
+ {
+ /* tear down the partial theora setup */
+ theora_info_clear(&t_info);
+ theora_comment_clear(&t_comment);
+
+ vorbis_info_clear(&v_info);
+ vorbis_comment_clear(&v_comment);
+ ogg_sync_clear(&o_sync_state);
+ fclose(fp);
+ return false;
+ }
+ //queue_page(&o_page);
+
+ while (buffer_data(fp,&o_sync_state))
+ {
+ while (ogg_sync_pageout(&o_sync_state,&o_page)>0)
+ {
+ // The following line was commented out by Scott Wheeler <wheeler@kde.org>
+ // We don't actually need to store all of the pages / packets in memory since
+ // (a) libtheora doesn't use them anyway in the one call that we make after this
+ // that usese t_state and (b) it basically buffers the entire file to memory if
+ // we queue them up like this and that sucks where a typical file size is a few
+ // hundred megs.
+
+ // queue_page(&o_page);
+ }
+ if (theora_serial==ogg_page_serialno(&o_page))
+ duration=(ogg_int64_t) theora_granule_time(&t_state,ogg_page_granulepos(&o_page));
+ }
+
+ if (readTech)
+ {
+ int stream_fps=0;
+ if (t_info.fps_denominator!=0)
+ stream_fps=t_info.fps_numerator/t_info.fps_denominator;
+ KFileMetaInfoGroup videogroup = appendGroup(info, "Video");
+ appendItem(videogroup, "Length", int (duration));
+ appendItem(videogroup, "Resolution", QSize(t_info.frame_width,t_info.frame_height));
+ appendItem(videogroup, "FrameRate", stream_fps);
+ appendItem(videogroup, "Quality", (int) t_info.quality);
+
+ KFileMetaInfoGroup audiogroup = appendGroup(info, "Audio");
+ appendItem(audiogroup, "Channels", v_info.channels);
+ appendItem(audiogroup, "SampleRate", int(v_info.rate));
+ }
+ fclose(fp);
+
+ if (vorbis_p)
+ {
+ ogg_stream_clear(&v_stream_state);
+ vorbis_comment_clear(&v_comment);
+ vorbis_info_clear(&v_info);
+ }
+
+ ogg_stream_clear(&t_stream_state);
+ theora_clear(&t_state);
+ theora_comment_clear(&t_comment);
+ theora_info_clear(&t_info);
+ ogg_sync_clear(&o_sync_state);
+
+ return true;
+}
+
+#include "kfile_theora.moc"
+
diff --git a/kfile-plugins/theora/kfile_theora.desktop b/kfile-plugins/theora/kfile_theora.desktop
new file mode 100644
index 00000000..6e519085
--- /dev/null
+++ b/kfile-plugins/theora/kfile_theora.desktop
@@ -0,0 +1,60 @@
+[Desktop Entry]
+Type=Service
+Name=theora Info
+Name[bg]=Информация за theora
+Name[bn]=থিওরা তথ্য
+Name[br]=Titouroù diwar-benn theora
+Name[bs]=theora informacije
+Name[ca]=Informació theora
+Name[cs]=theora info
+Name[de]=Theora-Info
+Name[el]=Πληροφορίες theora
+Name[eo]=theora-informo
+Name[es]=Info Theora
+Name[et]=Theora info
+Name[eu]=theora informazioa
+Name[fa]=اطلاعات theora
+Name[fi]=Theoran tiedot
+Name[fr]=Informations theora
+Name[ga]=Eolas faoi theora
+Name[gl]=Información theora
+Name[he]=מידע theora
+Name[hu]=Theora-jellemzők
+Name[is]=theora upplýsingar
+Name[it]=Informazioni su theora
+Name[ja]=theora 情報
+Name[kk]=theora мәліметі
+Name[km]=ព័ត៌មាន theora
+Name[ko]=theora 정보
+Name[lt]=theora Informacija
+Name[mk]=theora информации
+Name[nb]=theora-info
+Name[nds]=Theora-Info
+Name[ne]=थिवरा सूचना
+Name[nl]=theora-informatie
+Name[nn]=theora-info
+Name[pa]=theora (ਥੋਰਾ) ਜਾਣਕਾਰੀ
+Name[pl]=Informacja o pliku theora
+Name[pt]=Informação do theora
+Name[pt_BR]=Informação sobre theora
+Name[ru]=Сведения о theora
+Name[sk]=theora info
+Name[sl]=Podatki o Theora
+Name[sr]=Информације о theora-и
+Name[sr@Latn]=Informacije o theora-i
+Name[sv]=Theora-information
+Name[ta]= தியோரா தகவல்
+Name[th]=ข้อมูล theora
+Name[tr]=theora Bilgisi
+Name[uk]=Інформація по theora
+Name[zh_CN]=theora 信息
+Name[zh_HK]=theora 資訊
+Name[zh_TW]=theora 資訊
+ServiceTypes=KFilePlugin
+X-KDE-Library=kfile_theora
+# change MimeType here! (example: inode/directory)
+MimeType=video/x-theora
+# change PreferredGroups here! (example: FolderInfo)
+PreferredGroups=
+# change PreferredItems here! (example: Items;Size)
+PreferredItems=Size,Length
diff --git a/kfile-plugins/theora/kfile_theora.h b/kfile-plugins/theora/kfile_theora.h
new file mode 100644
index 00000000..c2cb990e
--- /dev/null
+++ b/kfile-plugins/theora/kfile_theora.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Jean-Baptiste Mardelle *
+ * bj@altern.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef __KFILE_THEORA_H__
+#define __KFILE_THEORA_H__
+
+/**
+ * Note: For further information look into <$KDEDIR/include/kfilemetainfo.h>
+ */
+#include <kfilemetainfo.h>
+
+class QStringList;
+
+class theoraPlugin: public KFilePlugin
+{
+ Q_OBJECT
+
+public:
+ theoraPlugin( QObject *parent, const char *name, const QStringList& args );
+
+ virtual bool readInfo( KFileMetaInfo& info, uint what);
+};
+
+#endif // __KFILE_THEORA_H__
+