[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-multimedia
Subject:    Patch to enable saving *cast streams locally
From:       Rik Hemsley <rik () kde ! org>
Date:       2002-02-25 13:09:33
[Download RAW message or body]

This is probably the Wrong Way - should be done before splayplayobject,
but here's the patch anyway, in case someone fancies doing it the Right
Way.

Cheers,
Rik



Index: mpeglib_artsplug/splayPlayObject.idl
===================================================================
RCS file: /home/kde/kdemultimedia/mpeglib_artsplug/splayPlayObject.idl,v
retrieving revision 1.1
diff -u -3 -p -r1.1 splayPlayObject.idl
--- mpeglib_artsplug/splayPlayObject.idl	2001/05/14 17:16:20	1.1
+++ mpeglib_artsplug/splayPlayObject.idl	2002/02/25 13:05:28
@@ -9,6 +9,8 @@ interface SplayPlayObject : Arts::Stream
 
   out audio stream left,right;
 
+  void setSaveStreamLocally(boolean yn);
+  void setSaveDirectory(string dir);
 };
 
 
Index: mpeglib_artsplug/splayPlayObject_impl.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/mpeglib_artsplug/splayPlayObject_impl.cpp,v
retrieving revision 1.6
diff -u -3 -p -r1.6 splayPlayObject_impl.cpp
--- mpeglib_artsplug/splayPlayObject_impl.cpp	2001/11/24 16:38:27	1.6
+++ mpeglib_artsplug/splayPlayObject_impl.cpp	2002/02/25 13:05:30
@@ -10,6 +10,8 @@
 
  */
 
+#include <cstdio>
+
 #include "splayPlayObject_impl.h"
 #include "../mpeglib/lib/splay/splayDecoder.h"
 #include "../mpeglib/lib/frame/audioFrameQueue.h"
@@ -49,6 +51,8 @@
 
 SplayPlayObject_impl::SplayPlayObject_impl() {
 
+  localFile = 0;
+  saveStreamLocally = false;
   flpos=0.0;
   
   splay=new SplayDecoder();
@@ -76,6 +80,11 @@ SplayPlayObject_impl::SplayPlayObject_im
 
 SplayPlayObject_impl::~SplayPlayObject_impl() {
   arts_debug("~SplayPlayObject_impl -s");
+  if (0 != localFile)
+  {
+    fclose(localFile);
+    localFile = 0;
+  }
   delete splay;
   delete frameQueue;
   delete framer; 
@@ -119,6 +128,7 @@ bool SplayPlayObject_impl::loadMedia(con
 
 bool SplayPlayObject_impl::streamMedia(InputStream instream) {
   arts_debug("streamMedia");
+
   lStreaming=true;
   currentStream = instream;
   StreamPlayObject self = StreamPlayObject::_from_base(_copy());
@@ -186,6 +196,8 @@ void SplayPlayObject_impl::processQueue(
       AudioFrame* emptyFrame= frameQueue->emptyQueueDequeue();
       if (splay->decode(framer->outdata(),framer->len(),emptyFrame)==true) {
          frameQueue->dataQueueEnqueue(emptyFrame);
+         if (0 != localFile)
+           fwrite(framer->outdata(), 1, framer->len(), localFile);
          cnt++;
       }
       break;
@@ -245,9 +257,43 @@ poState SplayPlayObject_impl::state() {
 
 void SplayPlayObject_impl::play() {
   arts_debug("play:");
+
   if (file == NULL) {
+
     arts_debug("file is NULL:");
+
     if (lStreaming && _state != posPlaying) {
+
+      // -------------------------
+      // Local file saving support.
+      if (0 != localFile)
+      {
+        fclose(localFile);
+        localFile = 0;
+      }
+
+      if (saveStreamLocally)
+      {
+        char filename[PATH_MAX];
+
+        snprintf
+          (
+            filename,
+            PATH_MAX - 1,
+            (saveDirectory + "/artsout-%d.mp3").c_str(),
+            int(time(0))
+          );
+
+        cerr << "SplayPlayObject_impl::streamMedia: filename == `" << filename << \
"'" << endl; +        localFile = fopen(filename, "w+");
+      }
+      else
+      {
+        cerr << "SplayPlayObject_impl::streamMedia: Not saving locally" << endl;
+      }
+      // -------------------------
+
+
       currentStream.streamStart();
       _state = posPlaying;
     }
@@ -370,7 +416,7 @@ void SplayPlayObject_impl::calculateBloc
     // check how many output samples we will be able to generate from that
     long samplesToConvert = long((double)readSamplesOk/speed)-4;
     if(samplesToConvert < 0) samplesToConvert = 0;
-    if(samplesToConvert > wantSamples) samplesToConvert = wantSamples;
+    if(samplesToConvert > long(wantSamples)) samplesToConvert = wantSamples;
 
     // do the conversion
     interpolate_mono_float_float(samplesToConvert,flpos,speed,
@@ -480,6 +526,8 @@ void SplayPlayObject_impl::getMoreSample
       AudioFrame* emptyFrame= frameQueue->emptyQueueDequeue();
       if (splay->decode(framer->outdata(),framer->len(),emptyFrame)==true) {
          frameQueue->dataQueueEnqueue(emptyFrame);
+         if (0 != localFile)
+           fwrite(framer->outdata(), 1, framer->len(), localFile);
          cnt++;
       }
       break;
@@ -493,6 +541,18 @@ void SplayPlayObject_impl::getMoreSample
     halt();
     return;
   }
+}
+
+void SplayPlayObject_impl::setSaveStreamLocally(bool b)
+{
+  cerr << "SplayPlayObject_impl::setSaveStreamLocally(" << b << ")" << endl;
+  saveStreamLocally = b;
+}
+
+void SplayPlayObject_impl::setSaveDirectory(const string & dir)
+{
+  cerr << "SplayPlayObject_impl::setSaveDirectory(" << dir << ")" << endl;
+  saveDirectory = dir;
 }
 
 REGISTER_IMPLEMENTATION(SplayPlayObject_impl);
Index: mpeglib_artsplug/splayPlayObject_impl.h
===================================================================
RCS file: /home/kde/kdemultimedia/mpeglib_artsplug/splayPlayObject_impl.h,v
retrieving revision 1.3
diff -u -3 -p -r1.3 splayPlayObject_impl.h
--- mpeglib_artsplug/splayPlayObject_impl.h	2001/10/29 20:55:53	1.3
+++ mpeglib_artsplug/splayPlayObject_impl.h	2002/02/25 13:05:30
@@ -64,7 +64,11 @@ class SplayPlayObject_impl :
   DataPacket<mcopbyte> *currentPacket;
   int currentPos;
 
+  FILE * localFile;
 
+  bool saveStreamLocally;
+  string saveDirectory;
+
 public:
 
   SplayPlayObject_impl();
@@ -96,6 +100,9 @@ public:
   void calculateBlock(unsigned long samples);
   void streamEnd();
 
+  virtual void setSaveStreamLocally(bool);
+  virtual void setSaveDirectory(const string &);
+
  private:
   Arts::InputStream currentStream;   
  
@@ -103,9 +110,6 @@ public:
   void checkPacketBuffer(int size);
   void getMoreSamples(int needLen);
   void processQueue();
-
-
-
 };
 
 
Index: noatun/library/app.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/noatun/library/app.cpp,v
retrieving revision 1.7
diff -u -3 -p -r1.7 app.cpp
--- noatun/library/app.cpp	2002/02/17 02:33:56	1.7
+++ noatun/library/app.cpp	2002/02/25 13:05:32
@@ -152,6 +152,7 @@ READBOOLOPT(loopList, "LoopList", true)
 READBOOLOPT(hackUpPlaylist, "HackUpPlaylist", true)
 READBOOLOPT(fastMixer, "FastMixer", false)
 READBOOLOPT(clearOnOpen, "ClearOnOpen", false)
+READBOOLOPT(saveStreamsLocally, "SaveStreamsLocally", false)
 READBOOLOPT_EX(oneInstance, "MultipleInstances", true, "KDE", true)
 
 #undef READBOOLOPT
@@ -207,6 +208,14 @@ void NoatunApp::setRememberPositions(boo
 	KConfig *config=KGlobal::config();
 	config->setGroup("");
 	config->writeEntry("RememberPositions", b);
+	KGlobal::config()->sync();
+}
+
+void NoatunApp::setSaveStreamsLocally(bool b)
+{
+	KConfig *config=KGlobal::config();
+	config->setGroup("");
+	config->writeEntry("SaveStreamsLocally", b);
 	KGlobal::config()->sync();
 }
 
Index: noatun/library/cmodule.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/noatun/library/cmodule.cpp,v
retrieving revision 1.54
diff -u -3 -p -r1.54 cmodule.cpp
--- noatun/library/cmodule.cpp	2002/01/26 00:55:59	1.54
+++ noatun/library/cmodule.cpp	2002/02/25 13:05:33
@@ -238,6 +238,8 @@ General::General(QObject *parent) : CMod
 	QWhatsThis::add(mFastVolume, i18n("Use the hardware mixer instead of aRts'. It \
affects all streams, not just Noatun's, but is a little faster."));  
 	QFrame *dlSaverFrame = new QFrame(this);
+	mSaveLocally = new QCheckBox(i18n("&Save streams locally"), dlSaverFrame);
+	mSaveLocally->setChecked(napp->saveStreamsLocally());
 	QLabel *dlsaver=new QLabel(i18n("&Download Directory"), dlSaverFrame);
 	mDlSaver=new KURLRequester(napp->saveDirectory(), dlSaverFrame);
 	dlsaver->setBuddy(mDlSaver);
@@ -268,9 +270,11 @@ General::General(QObject *parent) : CMod
 	layout->addWidget(dlSaverFrame);
 	layout->addStretch();
 
-	QHBoxLayout *layoutSaver = new QHBoxLayout(dlSaverFrame, KDialog::marginHint(), \
                KDialog::spacingHint());
-	layoutSaver->addWidget(dlsaver);
-	layoutSaver->addWidget(mDlSaver);
+	QVBoxLayout *layoutSaver = new QVBoxLayout(dlSaverFrame, KDialog::marginHint(), \
KDialog::spacingHint()); +	layoutSaver->addWidget(mSaveLocally);
+	QHBoxLayout *layoutSaverBottom = new QHBoxLayout(layoutSaver);
+	layoutSaverBottom->addWidget(dlsaver);
+	layoutSaverBottom->addWidget(mDlSaver);
 
 }
 
@@ -280,6 +284,7 @@ void General::save()
 	napp->setAutoPlay(mAutoPlay->isChecked());
 	napp->setOneInstance(mOneInstance->isChecked());
 	napp->setClearOnOpen(mClearOnOpen->isChecked());
+	napp->setSaveStreamsLocally(mSaveLocally->isChecked());
 	napp->setSaveDirectory(mDlSaver->url());
 	napp->setHackUpPlaylist(mHackUpPlaylist->isChecked());
 	napp->setFastMixer(mFastVolume->isChecked());
Index: noatun/library/cmodule.h
===================================================================
RCS file: /home/kde/kdemultimedia/noatun/library/cmodule.h,v
retrieving revision 1.23
diff -u -3 -p -r1.23 cmodule.h
--- noatun/library/cmodule.h	2001/10/23 18:53:14	1.23
+++ noatun/library/cmodule.h	2002/02/25 13:05:33
@@ -51,7 +51,7 @@ private slots:
 
 private:
 	QCheckBox *mAutoPlay, *mLoopList, *mOneInstance, *mRememberPositions,
-	          *mClearOnOpen, *mHackUpPlaylist, *mFastVolume;
+	          *mClearOnOpen, *mHackUpPlaylist, *mFastVolume, *mSaveLocally;
 	KURLRequester *mDlSaver;
 	KLineEdit *mTitleFormat;
 };
Index: noatun/library/engine.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/noatun/library/engine.cpp,v
retrieving revision 1.74
diff -u -3 -p -r1.74 engine.cpp
--- noatun/library/engine.cpp	2002/01/06 04:19:10	1.74
+++ noatun/library/engine.cpp	2002/02/25 13:05:36
@@ -1,3 +1,5 @@
+#include <dynamicrequest.h>
+
 #include <noatun/engine.h>
 #include <noatun/equalizer.h>
 #include <noatun/player.h>
@@ -302,6 +304,25 @@ bool Engine::open(const PlaylistItem &fi
 		return false;
 	}
 
+	// See if this is an SplayPlayObject. If so, it handles saving
+	// streams to the local disk, so we tell it about our settings
+	// for saving streams locally, before we let it start playing.
+
+	if ("SplayPlayObject" == playObject()._interfaceName())
+	{
+		if (!Arts::DynamicRequest(playObject()).
+			method("setSaveStreamLocally").param(napp->saveStreamsLocally()).invoke())
+		{
+			qDebug("Failed to call setSaveStreamLocally");
+		}
+		if (!Arts::DynamicRequest(playObject()).
+			method("setSaveDirectory").param(napp->saveDirectory().ascii()).invoke())
+		{
+			qDebug("Failed to call setSaveDirectory");
+		}
+	}
+
+
 	d->playobj->object()._node()->start();
 	
 	// TODO: check for existence of left & right streams
@@ -318,6 +339,7 @@ bool Engine::play()
 	if (!mPlay) return true;
 	if(!d->playobj)
 		return false;
+
 	d->playobj->play();
 	return true;
 }
Index: noatun/library/noatun/app.h
===================================================================
RCS file: /home/kde/kdemultimedia/noatun/library/noatun/app.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 app.h
--- noatun/library/noatun/app.h	2002/01/15 04:56:02	1.2
+++ noatun/library/noatun/app.h	2002/02/25 13:05:36
@@ -82,6 +82,7 @@ public: //options
 	bool hackUpPlaylist() const;
 	bool fastMixer() const;
 	QString titleFormat() const;
+	bool saveStreamsLocally() const;
 	
 	void setOneInstance(bool);
 	void setLoopList(bool);
@@ -92,6 +93,7 @@ public: //options
 	void setHackUpPlaylist(bool);
 	void setFastMixer(bool);
 	void setTitleFormat(const QString &);
+	void setSaveStreamsLocally(bool);
 
 	/**
 	 * Adds an item to the plugin menu.


_______________________________________________
kde-multimedia mailing list
kde-multimedia@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-multimedia

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic