Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linux-dvb] MP3 support for VDR.



Is anyone working on MP3 support for VDR?

Just as an experiment, I have made the attached tiny
modification to vdr 0.71, which allows me to play one
hardcoded MP3 file by selecting a new item in VDRs
main menu.

What I would like to implement (unless anyone else
is already working on this) is:

*  A main menu item "MP3 play lists" that brings up
   a sub menu similar to the Recordings menu with a
   bunch of play lists - maybe from a predefined
   directory such as "/video/mp3_play_lists".
   The play lists are simple ASCII files that contain
   one MP3 file path per line.

*  Pressing OK with the cursor over a play list file
   name starts playing files from that play list.
   The last 39 characters of the current path name
   (and maybe some additional info) will be displayed 
   in the OSD.
   Pressing OK skips the rest of this file and  starts
   playing the next file.
   Pressing Back stops playing this play list and goes
   back to the "list of play lists" menu.

It is unlikely that I will have time to implement more
than the above features, but any hints or thoughts are
of course welcome.


Carsten.




 diff -ru VDR/dvbapi.c /wald/home/cko/linux/VDR/dvbapi.c
--- VDR/dvbapi.c	Sat Feb 24 14:13:19 2001
+++ /wald/home/cko/linux/VDR/dvbapi.c	Thu Mar  8 01:37:27 2001
@@ -7,6 +7,8 @@
  * $Id: dvbapi.c 1.61 2001/02/24 13:13:19 kls Exp $
  */
 
+#define _GNU_SOURCE
+
 #include "dvbapi.h"
 #include <errno.h>
 #include <fcntl.h>
@@ -14,6 +16,7 @@
 #include <jpeglib.h>
 }
 #include <stdlib.h>
+#include <stdio.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -2327,6 +2330,51 @@
 {
   if (replayBuffer)
      replayBuffer->Play();
+}
+
+
+
+#define FRAMESIZE 1024
+#define PCM_HEADER_SIZE 16
+
+void cDvbApi::PlayMP3(const char * const path)
+{
+   char *command = NULL;
+   asprintf(&command, "mpg123 -v -r 48000 --cdr - %s", path);
+   FILE * mpg123 = popen(command, "r");
+   if (mpg123 == NULL)
+   {
+      LOG_ERROR;
+      return;
+   }
+   unsigned char buffer[PCM_HEADER_SIZE + FRAMESIZE];
+   buffer[0] = 0x00;
+   buffer[1] = 0x00;
+   buffer[2] = 0x01;
+   buffer[3] = 0xbd;
+   buffer[6] = 0x80;
+   buffer[7] = 0x00;
+   buffer[8] = 0x00;
+   buffer[9] = 0xa0;  // substream ID
+   buffer[10] = 0x00; // other stuff (see DVD specs), ignored by driver
+   buffer[11] = 0x00;
+   buffer[12] = 0x00;
+   buffer[13] = 0x00;
+   buffer[14] = 0x00;
+   buffer[15] = 0x00;
+   
+   FILE *videoDevStream = fdopen(videoDev, "w");
+ 
+   for (;;) {
+      const size_t size = fread(&buffer[PCM_HEADER_SIZE], sizeof(unsigned char), FRAMESIZE, mpg123);
+      if (size <= 0) break;
+      const unsigned short length = size + PCM_HEADER_SIZE - 6;
+      buffer[4] = (length >> 8) & 0xff;
+      buffer[5] = length & 0xff;
+      fwrite(buffer, sizeof(unsigned char), length + 6, videoDevStream);
+   }
+   fclose(videoDevStream);
+   pclose(mpg123);
 }
 
 void cDvbApi::Forward(void)
diff -ru VDR/dvbapi.h /wald/home/cko/linux/VDR/dvbapi.h
--- VDR/dvbapi.h	Sun Feb 11 11:41:10 2001
+++ /wald/home/cko/linux/VDR/dvbapi.h	Thu Mar  8 00:47:10 2001
@@ -220,6 +220,8 @@
        // Pauses the current replay session, or resumes a paused session.
   void Play(void);
        // Resumes normal replay mode.
+  void PlayMP3(const char * const path);
+       // Plays an MP3 file.
   void Forward(void);
        // Runs the current replay session forward at a higher speed.
   void Backward(void);
diff -ru VDR/menu.c /wald/home/cko/linux/VDR/menu.c
--- VDR/menu.c	Sat Feb 24 15:53:40 2001
+++ /wald/home/cko/linux/VDR/menu.c	Thu Mar  8 01:14:06 2001
@@ -1704,9 +1704,10 @@
   Add(new cOsdItem(hk(2, tr("Channels")),   osChannels));
   Add(new cOsdItem(hk(3, tr("Timers")),     osTimers));
   Add(new cOsdItem(hk(4, tr("Recordings")), osRecordings));
-  Add(new cOsdItem(hk(5, tr("Setup")),      osSetup));
+  Add(new cOsdItem(hk(5, tr("MP3")), osMP3));
+  Add(new cOsdItem(hk(6, tr("Setup")),      osSetup));
   if (Commands.Count())
-     Add(new cOsdItem(hk(6, tr("Commands")),  osCommands));
+     Add(new cOsdItem(hk(7, tr("Commands")),  osCommands));
   if (Replaying)
      Add(new cOsdItem(tr(" Stop replaying"), osStopReplay));
   const char *s = NULL;
@@ -1733,6 +1734,8 @@
     case osChannels:   return AddSubMenu(new cMenuChannels);
     case osTimers:     return AddSubMenu(new cMenuTimers);
     case osRecordings: return AddSubMenu(new cMenuRecordings);
+    case osMP3:        cDvbApi::PrimaryDvbApi->PlayMP3("/mp3/Erste_Allgemeine_Verunsicherung/Geld_oder_Leben/07-Fata_Morgana.mp3"); 
+                       break;
     case osSetup:      return AddSubMenu(new cMenuSetup);
     case osCommands:   return AddSubMenu(new cMenuCommands);
     case osStopRecord: if (Interface->Confirm(tr("Stop recording?"))) {
Only in /wald/home/cko/linux/VDR: menu.o
diff -ru VDR/osd.h /wald/home/cko/linux/VDR/osd.h
--- VDR/osd.h	Sat Feb  3 16:13:59 2001
+++ /wald/home/cko/linux/VDR/osd.h	Thu Mar  8 01:00:36 2001
@@ -33,6 +33,7 @@
                 osSwitchDvb,
                 osBack,
                 osEnd,
+                osMP3,
               };
 
 class cOsdItem : public cListObject {


--- 
Info:
To unsubscribe send a mail to listar@linuxtv.org with "unsubscribe linux-dvb" as subject.



Home | Main Index | Thread Index