[MPlayer-dev-eng] Suggested diffs to enable mplayer to stream audio to other apps

Triode triode1 at btinternet.com
Sun Nov 28 20:26:59 CET 2004


Hi,

I have been working on a streaming audio project, using mplayer due to its excellent support of codecs and different formats.  I
would like to propose my diffs for consideration for adding to the mplayer source.  Ideally I would like to get this into the
standard code base as my application is intended to be a plugin for an open source server, and it would aid distribution if any
potential users could use a standard mplayer distribution.

First the application: I use mplayer as part of an audio pipeline to enable remote streams to be processed.

The application works something like this:
mplayer -slient -ao pcm -aofile - <url> | lame <> etc

To do this I have made a couple of minor mods to allow all messages to stdout to be suppressed and allow pcm audio to be streamed to 
stdout.

The changes are:
- new command line option "-slient" to allow all messages to stdout to be suppressed
- definition of a special -aofile filename "-" to mean send audio output to stdout
- additional error checking on write in ao_pcm.c to allow mplayer to shut down if the pipeline is broken
- removal of all printf's from one of the relavent files (aviprint.c) - I've changed the whole file to mp_msg - hopefully this is
useful and I've got the right message levels.

I realise the "-silent" option stands out a bit because I read argv before normal, but I couldn't find a more elagant way of
avoiding all status messages, even the mplayer banners, going to stdout without changing normal operation.

Thanks,

Adrian

------------------------------------------------------------------------------------------------------------------
diff -dru -x'*.o' -x'*.a' -x.depend MPlayer-20041126/cfg-mplayer.h MPlayer-mod/cfg-mplayer.h
--- MPlayer-20041126/cfg-mplayer.h      2004-11-14 11:27:57.000000000 +0000
+++ MPlayer-mod/cfg-mplayer.h   2004-11-27 08:25:21.000000000 +0000
@@ -422,6 +422,7 @@

        {"identify", &identify, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
        {"really-quiet", &verbose, CONF_TYPE_FLAG, CONF_GLOBAL, 0, -10, NULL},
+       {"slient", &verbose, CONF_TYPE_FLAG, CONF_GLOBAL, 0, -10, NULL},
        {"-help", help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL},
        {"help", help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL},
        {"h", help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL},
Only in MPlayer-mod: codec-cfg
Only in MPlayer-mod: codecs.conf.h
Only in MPlayer-mod: config.h
Only in MPlayer-mod: config.mak
Only in MPlayer-mod: help_mp.h
diff -dru -x'*.o' -x'*.a' -x.depend MPlayer-20041126/libao2/ao_pcm.c MPlayer-mod/libao2/ao_pcm.c
--- MPlayer-20041126/libao2/ao_pcm.c    2004-09-18 21:31:27.000000000 +0100
+++ MPlayer-mod/libao2/ao_pcm.c 2004-11-27 08:35:26.000000000 +0000
@@ -119,7 +119,12 @@
               (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
        mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_PCM_HintInfo);

-       fp = fopen(ao_outputfilename, "wb");
+       // "-" is a special file name to send stream to stdout, use with "-slient" to ensure audio not corrupted by status messages
+        if (!strcmp(ao_outputfilename, "-"))
+                fp = stdout;
+        else
+                fp = fopen(ao_outputfilename, "wb");
+
        if(fp) {
                if(ao_pcm_waveheader){ /* Reserve space for wave header */
                        fwrite(&wavhdr,sizeof(wavhdr),1,fp);
@@ -187,7 +192,10 @@
 #endif

        //printf("PCM: Writing chunk!\n");
-       fwrite(data,len,1,fp);
+       if (fwrite(data,len,1,fp) != 1){
+         mp_msg(MSGT_AO,MSGL_FATAL,MSGTR_ErrorWritingFile,ao_outputfilename);
+          exit_player(MSGTR_Exit_error);
+       }

        if(ao_pcm_waveheader)
                wavhdr.data_length += len;
Only in MPlayer-mod/libao2: config.mak
diff -dru -x'*.o' -x'*.a' -x.depend MPlayer-20041126/libmpdemux/aviprint.c MPlayer-mod/libmpdemux/aviprint.c
--- MPlayer-20041126/libmpdemux/aviprint.c      2004-04-28 11:18:33.000000000 +0100
+++ MPlayer-mod/libmpdemux/aviprint.c   2004-11-26 17:07:14.000000000 +0000
@@ -16,7 +16,7 @@
 //#include "stheader.h"

 void print_avih_flags(MainAVIHeader *h){
-  printf("MainAVIHeader.dwFlags: (%ld)%s%s%s%s%s%s\n",h->dwFlags,
+  mp_msg (MSGT_HEADER, MSGL_V, "MainAVIHeader.dwFlags: (%ld)%s%s%s%s%s%s\n",h->dwFlags,
     (h->dwFlags&AVIF_HASINDEX)?" HAS_INDEX":"",
     (h->dwFlags&AVIF_MUSTUSEINDEX)?" MUST_USE_INDEX":"",
     (h->dwFlags&AVIF_ISINTERLEAVED)?" IS_INTERLEAVED":"",
@@ -27,107 +27,107 @@
 }

 void print_avih(MainAVIHeader *h){
-  printf("======= AVI Header =======\n");
-  printf("us/frame: %ld  (fps=%5.3f)\n",h->dwMicroSecPerFrame,1000000.0f/(float)h->dwMicroSecPerFrame);
-  printf("max bytes/sec: %ld\n",h->dwMaxBytesPerSec);
-  printf("padding: %ld\n",h->dwPaddingGranularity);
+  mp_msg (MSGT_HEADER, MSGL_V, "======= AVI Header =======\n");
+  mp_msg (MSGT_HEADER, MSGL_V, "us/frame: %ld  (fps=%5.3f)\n",h->dwMicroSecPerFrame,1000000.0f/(float)h->dwMicroSecPerFrame);
+  mp_msg (MSGT_HEADER, MSGL_V, "max bytes/sec: %ld\n",h->dwMaxBytesPerSec);
+  mp_msg (MSGT_HEADER, MSGL_V, "padding: %ld\n",h->dwPaddingGranularity);
   print_avih_flags(h);
-  printf("frames  total: %ld   initial: %ld\n",h->dwTotalFrames,h->dwInitialFrames);
-  printf("streams: %ld\n",h->dwStreams);
-  printf("Suggested BufferSize: %ld\n",h->dwSuggestedBufferSize);
-  printf("Size:  %ld x %ld\n",h->dwWidth,h->dwHeight);
-  printf("==========================\n");
+  mp_msg (MSGT_HEADER, MSGL_V, "frames  total: %ld   initial: %ld\n",h->dwTotalFrames,h->dwInitialFrames);
+  mp_msg (MSGT_HEADER, MSGL_V, "streams: %ld\n",h->dwStreams);
+  mp_msg (MSGT_HEADER, MSGL_V, "Suggested BufferSize: %ld\n",h->dwSuggestedBufferSize);
+  mp_msg (MSGT_HEADER, MSGL_V, "Size:  %ld x %ld\n",h->dwWidth,h->dwHeight);
+  mp_msg (MSGT_HEADER, MSGL_V, "==========================\n");
 }

 void print_strh(AVIStreamHeader *h){
-  printf("====== STREAM Header =====\n");
-  printf("Type: %.4s   FCC: %.4s (%X)\n",(char *)&h->fccType,(char *)&h->fccHandler,(unsigned int)h->fccHandler);
-  printf("Flags: %ld\n",h->dwFlags);
-  printf("Priority: %d   Language: %d\n",h->wPriority,h->wLanguage);
-  printf("InitialFrames: %ld\n",h->dwInitialFrames);
-  printf("Rate: %ld/%ld = %5.3f\n",h->dwRate,h->dwScale,(float)h->dwRate/(float)h->dwScale);
-  printf("Start: %ld   Len: %ld\n",h->dwStart,h->dwLength);
-  printf("Suggested BufferSize: %ld\n",h->dwSuggestedBufferSize);
-  printf("Quality %ld\n",h->dwQuality);
-  printf("Sample size: %ld\n",h->dwSampleSize);
-  printf("==========================\n");
+  mp_msg (MSGT_HEADER, MSGL_V, "====== STREAM Header =====\n");
+  mp_msg (MSGT_HEADER, MSGL_V, "Type: %.4s   FCC: %.4s (%X)\n",(char *)&h->fccType,(char *)&h->fccHandler,(unsigned
int)h->fccHandler);
+  mp_msg (MSGT_HEADER, MSGL_V, "Flags: %ld\n",h->dwFlags);
+  mp_msg (MSGT_HEADER, MSGL_V, "Priority: %d   Language: %d\n",h->wPriority,h->wLanguage);
+  mp_msg (MSGT_HEADER, MSGL_V, "InitialFrames: %ld\n",h->dwInitialFrames);
+  mp_msg (MSGT_HEADER, MSGL_V, "Rate: %ld/%ld = %5.3f\n",h->dwRate,h->dwScale,(float)h->dwRate/(float)h->dwScale);
+  mp_msg (MSGT_HEADER, MSGL_V, "Start: %ld   Len: %ld\n",h->dwStart,h->dwLength);
+  mp_msg (MSGT_HEADER, MSGL_V, "Suggested BufferSize: %ld\n",h->dwSuggestedBufferSize);
+  mp_msg (MSGT_HEADER, MSGL_V, "Quality %ld\n",h->dwQuality);
+  mp_msg (MSGT_HEADER, MSGL_V, "Sample size: %ld\n",h->dwSampleSize);
+  mp_msg (MSGT_HEADER, MSGL_V, "==========================\n");
 }

 void print_wave_header(WAVEFORMATEX *h){
-  printf("======= WAVE Format =======\n");
-  printf("Format Tag: %d (0x%X)\n",h->wFormatTag,h->wFormatTag);
-  printf("Channels: %d\n",h->nChannels);
-  printf("Samplerate: %ld\n",h->nSamplesPerSec);
-  printf("avg byte/sec: %ld\n",h->nAvgBytesPerSec);
-  printf("Block align: %d\n",h->nBlockAlign);
-  printf("bits/sample: %d\n",h->wBitsPerSample);
-  printf("cbSize: %d\n",h->cbSize);
+  mp_msg (MSGT_HEADER, MSGL_V, "======= WAVE Format =======\n");
+  mp_msg (MSGT_HEADER, MSGL_V, "Format Tag: %d (0x%X)\n",h->wFormatTag,h->wFormatTag);
+  mp_msg (MSGT_HEADER, MSGL_V, "Channels: %d\n",h->nChannels);
+  mp_msg (MSGT_HEADER, MSGL_V, "Samplerate: %ld\n",h->nSamplesPerSec);
+  mp_msg (MSGT_HEADER, MSGL_V, "avg byte/sec: %ld\n",h->nAvgBytesPerSec);
+  mp_msg (MSGT_HEADER, MSGL_V, "Block align: %d\n",h->nBlockAlign);
+  mp_msg (MSGT_HEADER, MSGL_V, "bits/sample: %d\n",h->wBitsPerSample);
+  mp_msg (MSGT_HEADER, MSGL_V, "cbSize: %d\n",h->cbSize);
   if(h->wFormatTag==0x55 && h->cbSize>=12){
       MPEGLAYER3WAVEFORMAT* h2=(MPEGLAYER3WAVEFORMAT *)h;
-      printf("mp3.wID=%d\n",h2->wID);
-      printf("mp3.fdwFlags=0x%lX\n",h2->fdwFlags);
-      printf("mp3.nBlockSize=%d\n",h2->nBlockSize);
-      printf("mp3.nFramesPerBlock=%d\n",h2->nFramesPerBlock);
-      printf("mp3.nCodecDelay=%d\n",h2->nCodecDelay);
+      mp_msg (MSGT_HEADER, MSGL_V, "mp3.wID=%d\n",h2->wID);
+      mp_msg (MSGT_HEADER, MSGL_V, "mp3.fdwFlags=0x%lX\n",h2->fdwFlags);
+      mp_msg (MSGT_HEADER, MSGL_V, "mp3.nBlockSize=%d\n",h2->nBlockSize);
+      mp_msg (MSGT_HEADER, MSGL_V, "mp3.nFramesPerBlock=%d\n",h2->nFramesPerBlock);
+      mp_msg (MSGT_HEADER, MSGL_V, "mp3.nCodecDelay=%d\n",h2->nCodecDelay);
   }
   else if (h->cbSize > 0)
   {
     int i;
     uint8_t* p = ((uint8_t*)h) + sizeof(WAVEFORMATEX);
-    printf("Unknown extra header dump: ");
+    mp_msg (MSGT_HEADER, MSGL_V, "Unknown extra header dump: ");
     for (i = 0; i < h->cbSize; i++)
-       printf("[%x] ", p[i]);
-    printf("\n");
+       mp_msg (MSGT_HEADER, MSGL_V, "[%x] ", p[i]);
+    mp_msg (MSGT_HEADER, MSGL_V, "\n");
   }
-  printf("===========================\n");
+  mp_msg (MSGT_HEADER, MSGL_V, "===========================\n");
 }


 void print_video_header(BITMAPINFOHEADER *h){
-  printf("======= VIDEO Format ======\n");
-       printf("  biSize %d\n", h->biSize);
-       printf("  biWidth %d\n", h->biWidth);
-       printf("  biHeight %d\n", h->biHeight);
-       printf("  biPlanes %d\n", h->biPlanes);
-       printf("  biBitCount %d\n", h->biBitCount);
-       printf("  biCompression %d='%.4s'\n", h->biCompression, (char *)&h->biCompression);
-       printf("  biSizeImage %d\n", h->biSizeImage);
+  mp_msg (MSGT_HEADER, MSGL_V, "======= VIDEO Format ======\n");
+       mp_msg (MSGT_HEADER, MSGL_V, "  biSize %d\n", h->biSize);
+       mp_msg (MSGT_HEADER, MSGL_V, "  biWidth %d\n", h->biWidth);
+       mp_msg (MSGT_HEADER, MSGL_V, "  biHeight %d\n", h->biHeight);
+       mp_msg (MSGT_HEADER, MSGL_V, "  biPlanes %d\n", h->biPlanes);
+       mp_msg (MSGT_HEADER, MSGL_V, "  biBitCount %d\n", h->biBitCount);
+       mp_msg (MSGT_HEADER, MSGL_V, "  biCompression %d='%.4s'\n", h->biCompression, (char *)&h->biCompression);
+       mp_msg (MSGT_HEADER, MSGL_V, "  biSizeImage %d\n", h->biSizeImage);
   if (h->biSize > sizeof(BITMAPINFOHEADER))
   {
     int i;
     uint8_t* p = ((uint8_t*)h) + sizeof(BITMAPINFOHEADER);
-    printf("Unknown extra header dump: ");
+    mp_msg (MSGT_HEADER, MSGL_V, "Unknown extra header dump: ");
     for (i = 0; i < h->biSize-sizeof(BITMAPINFOHEADER); i++)
-       printf("[%x] ", *(p+i));
-    printf("\n");
+       mp_msg (MSGT_HEADER, MSGL_V, "[%x] ", *(p+i));
+    mp_msg (MSGT_HEADER, MSGL_V, "\n");
   }
-  printf("===========================\n");
+  mp_msg (MSGT_HEADER, MSGL_V, "===========================\n");
 }

 void print_vprp(VideoPropHeader *vprp){
   int i;
-  printf("======= Video Properties Header =======\n");
-  printf("Format: %d  VideoStandard: %d\n",
+  mp_msg (MSGT_HEADER, MSGL_V, "======= Video Properties Header =======\n");
+  mp_msg (MSGT_HEADER, MSGL_V, "Format: %d  VideoStandard: %d\n",
          vprp->VideoFormatToken,vprp->VideoStandard);
-  printf("VRefresh: %d  HTotal: %d  VTotal: %d\n",
+  mp_msg (MSGT_HEADER, MSGL_V, "VRefresh: %d  HTotal: %d  VTotal: %d\n",
          vprp->dwVerticalRefreshRate, vprp->dwHTotalInT, vprp->dwVTotalInLines);
-  printf("FrameAspect: %d:%d  Framewidth: %d  Frameheight: %d\n",
+  mp_msg (MSGT_HEADER, MSGL_V, "FrameAspect: %d:%d  Framewidth: %d  Frameheight: %d\n",
          vprp->dwFrameAspectRatio >> 16, vprp->dwFrameAspectRatio & 0xffff,
          vprp->dwFrameWidthInPixels, vprp->dwFrameHeightInLines);
-  printf("Fields: %d\n", vprp->nbFieldPerFrame);
+  mp_msg (MSGT_HEADER, MSGL_V, "Fields: %d\n", vprp->nbFieldPerFrame);
   for (i=0; i<vprp->nbFieldPerFrame; i++) {
     VIDEO_FIELD_DESC *vfd = &vprp->FieldInfo[i];
-    printf("  == Field %d description ==\n", i);
-    printf("  CompressedBMHeight: %d  CompressedBMWidth: %d\n",
+    mp_msg (MSGT_HEADER, MSGL_V, "  == Field %d description ==\n", i);
+    mp_msg (MSGT_HEADER, MSGL_V, "  CompressedBMHeight: %d  CompressedBMWidth: %d\n",
            vfd->CompressedBMHeight, vfd->CompressedBMWidth);
-    printf("  ValidBMHeight: %d  ValidBMWidth: %d\n",
+    mp_msg (MSGT_HEADER, MSGL_V, "  ValidBMHeight: %d  ValidBMWidth: %d\n",
            vfd->ValidBMHeight, vfd->ValidBMWidth);
-    printf("  ValidBMXOffset: %d  ValidBMYOffset: %d\n",
+    mp_msg (MSGT_HEADER, MSGL_V, "  ValidBMXOffset: %d  ValidBMYOffset: %d\n",
            vfd->ValidBMXOffset, vfd->ValidBMYOffset);
-    printf("  VideoXOffsetInT: %d  VideoYValidStartLine: %d\n",
+    mp_msg (MSGT_HEADER, MSGL_V, "  VideoXOffsetInT: %d  VideoYValidStartLine: %d\n",
            vfd->VideoXOffsetInT, vfd->VideoYValidStartLine);
   }
-  printf("=======================================\n");
+  mp_msg (MSGT_HEADER, MSGL_V, "=======================================\n");
 }

 void print_index(AVIINDEXENTRY *idx,int idx_size){
@@ -138,7 +138,7 @@
   for(i=0;i<idx_size;i++){
     int id=avi_stream_id(idx[i].ckid);
     if(id<0 || id>255) id=255;
-    printf("%5d:  %.4s  %4X  %016llX  len:%6ld  pos:%7d->%7.3f %7d->%7.3f\n",i,
+    mp_msg (MSGT_HEADER, MSGL_V, "%5d:  %.4s  %4X  %016llX  len:%6ld  pos:%7d->%7.3f %7d->%7.3f\n",i,
       (char *)&idx[i].ckid,
       (unsigned int)idx[i].dwFlags&0xffff,
       (uint64_t)AVI_IDX_OFFSET(&idx[i]),
Only in MPlayer-mod/libvo: config.mak
Only in MPlayer-mod: mencoder
Only in MPlayer-mod: mplayer
diff -dru -x'*.o' -x'*.a' -x.depend MPlayer-20041126/mplayer.c MPlayer-mod/mplayer.c
--- MPlayer-20041126/mplayer.c  2004-11-25 22:23:59.000000000 +0000
+++ MPlayer-mod/mplayer.c       2004-11-27 08:26:08.000000000 +0000
@@ -987,6 +987,10 @@

   mp_msg_init();
   mp_msg_set_level(MSGL_STATUS);
+  for (i=0; i<argc;  i++)
+    if (!strcmp(argv[i], "-slient"))
+        mp_msg_set_level(MSGL_ERR);
+

   mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2004 MPlayer Team\n");
   /* Test for cpu capabilities (and corresponding OS support) for optimizing */
Only in MPlayer-mod: myconfig
Only in MPlayer-20041126: .swp
Only in MPlayer-mod: version.h




More information about the MPlayer-dev-eng mailing list