[MPlayer-dev-eng] Re: audio out feature (not a request)

Tobias Diedrich ranma at tdiedrich.de
Sun Jun 19 01:47:15 CEST 2005


Nico Sabbi wrote:

> bad solution. You should rather write a rawaudio muxer like the rawvideo
> one, and call it from mencoder instead of from mplayer

Hmm, I just so happen to have a rawaudio muxer lying around here.  :-)
Not quite cleaned up yet (e.g. still uses printf), but should work.

BTW, I wonder if there would be any strong opinions against
splitting up the "SRCS = "-Line of libmpdemux/Makefile (and maybe
similar lines in other Makefiles) into multiple lines.  Having all
on one line causes merge failures if the local version is modified
(Easy to resolve, but still...).

-- 
Tobias						PGP: http://9ac7e0bc.uguu.de
-------------- next part --------------
Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/Makefile,v
retrieving revision 1.92
diff -u -r1.92 Makefile
--- Makefile	13 Jun 2005 20:39:17 -0000	1.92
+++ Makefile	18 Jun 2005 23:41:12 -0000
@@ -3,7 +3,7 @@
 
 include ../config.mak
 
-SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c muxer.c muxer_avi.c muxer_mpeg.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_ty.c demux_ty_osd.c demux_pva.c demux_viv.c demuxer.c dvdnav_stream.c open.c parse_es.c stream.c stream_file.c stream_netstream.c stream_vcd.c stream_null.c stream_ftp.c stream_smb.c stream_vstream.c tv.c tvi_dummy.c tvi_v4l.c tvi_v4l2.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c demux_ogg.c cdda.c demux_rawaudio.c demux_rawvideo.c cddb.c cdinfo.c demux_rawdv.c ai_alsa.c ai_alsa1x.c ai_oss.c audio_in.c demux_smjpeg.c demux_lmlm4.c cue_read.c extension.c demux_gif.c demux_ts.c demux_realaud.c url.c muxer_rawvideo.c demux_lavf.c demux_nsv.c demux_vqf.c stream_dvd.c stream_livedotcom.c demux_aac.c
+SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c muxer.c muxer_avi.c muxer_mpeg.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_ty.c demux_ty_osd.c demux_pva.c demux_viv.c demuxer.c dvdnav_stream.c open.c parse_es.c stream.c stream_file.c stream_netstream.c stream_vcd.c stream_null.c stream_ftp.c stream_smb.c stream_vstream.c tv.c tvi_dummy.c tvi_v4l.c tvi_v4l2.c tvi_bsdbt848.c frequencies.c demux_fli.c demux_real.c demux_y4m.c yuv4mpeg.c yuv4mpeg_ratio.c demux_nuv.c demux_film.c demux_roq.c mf.c demux_mf.c demux_audio.c demux_demuxers.c demux_ogg.c cdda.c demux_rawaudio.c demux_rawvideo.c cddb.c cdinfo.c demux_rawdv.c ai_alsa.c ai_alsa1x.c ai_oss.c audio_in.c demux_smjpeg.c demux_lmlm4.c cue_read.c extension.c demux_gif.c demux_ts.c demux_realaud.c url.c muxer_rawvideo.c muxer_rawaudio.c demux_lavf.c demux_nsv.c demux_vqf.c stream_dvd.c stream_livedotcom.c demux_aac.c
 ifeq ($(XMMS_PLUGINS),yes)
 SRCS += demux_xmms.c
 endif 
Index: muxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/muxer.c,v
retrieving revision 1.7
diff -u -r1.7 muxer.c
--- muxer.c	21 Feb 2005 23:18:31 -0000	1.7
+++ muxer.c	18 Jun 2005 23:41:12 -0000
@@ -41,6 +41,10 @@
       default:
 	if(! muxer_init_muxer_avi(muxer))
 	  return NULL;
+      case MUXER_TYPE_RAWAUDIO:
+        if(! muxer_init_muxer_rawaudio(muxer))
+	  return NULL;
+	break;
     }
     return muxer;
 }
--- muxer_rawaudio.c.none	1970-01-01 01:00:00.000000000 +0100
+++ muxer_rawaudio.c	2005-04-28 20:20:41.000000000 +0200
@@ -0,0 +1,99 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+#include "config.h"
+#include "../version.h"
+
+//#include "stream.h"
+//#include "demuxer.h"
+//#include "stheader.h"
+#include "aviheader.h"
+#include "ms_hdr.h"
+
+#include "bswap.h"
+
+#include "muxer.h"
+
+static muxer_stream_t* rawaudiofile_new_stream(muxer_t *muxer,int type){
+    muxer_stream_t* s;
+    if (!muxer) return NULL;
+    if(type == MUXER_TYPE_AUDIO && muxer->avih.dwStreams>=1){
+	printf("Too many streams! Rawaudio muxer supports only one audio stream !\n");
+	return NULL;
+    }
+    s=malloc(sizeof(muxer_stream_t));
+    memset(s,0,sizeof(muxer_stream_t));
+    if(!s) return NULL; // no mem!?
+    muxer->streams[muxer->avih.dwStreams]=s;
+    s->type=type;
+    s->id=muxer->avih.dwStreams;
+    s->timer=0.0;
+    s->size=0;
+    s->muxer=muxer;
+    switch(type){
+    case MUXER_TYPE_AUDIO:
+      s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
+      s->h.fccType=streamtypeAUDIO;
+      muxer->avih.dwStreams++;
+      break;
+    case MUXER_TYPE_VIDEO:
+      printf("Ignoring video stream!\n");
+      s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
+      s->h.fccType=streamtypeAUDIO;
+      break;
+    default:
+      printf("Warning! unknown stream type: %d\n",type);
+      return NULL;
+    }
+    return s;
+}
+
+static void write_rawaudio_chunk(FILE *f,int len,void* data){
+    if(len>0){
+	if(data){
+	    // DATA
+	    fwrite(data,len,1,f);
+	}
+    }
+}
+
+static void rawaudiofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
+    muxer_t *muxer=s->muxer;
+
+    // write out the chunk:
+    if (s->type == MUXER_TYPE_AUDIO)
+      write_rawaudio_chunk(muxer->file,len,s->buffer); /* unsigned char */
+
+    // alter counters:
+    if(s->h.dwSampleSize){
+	// CBR
+	s->h.dwLength+=len/s->h.dwSampleSize;
+	if(len%s->h.dwSampleSize) printf("Warning! len isn't divisable by samplesize!\n");
+    } else {
+	// VBR
+	s->h.dwLength++;
+    }
+    s->timer=(double)s->h.dwLength*s->h.dwScale/s->h.dwRate;
+    s->size+=len;
+    // if((unsigned int)len>s->h.dwSuggestedBufferSize) s->h.dwSuggestedBufferSize=len;
+
+}
+
+static void rawaudiofile_write_header(muxer_t *muxer){
+    return;
+}
+
+static void rawaudiofile_write_index(muxer_t *muxer){
+    return;
+}
+
+int muxer_init_muxer_rawaudio(muxer_t *muxer){
+  muxer->cont_new_stream = &rawaudiofile_new_stream;
+  muxer->cont_write_chunk = &rawaudiofile_write_chunk;
+  muxer->cont_write_header = &rawaudiofile_write_header;
+  muxer->cont_write_index = &rawaudiofile_write_index;
+  return 1;
+}


More information about the MPlayer-dev-eng mailing list