[Mplayer-cvslog] CVS: main/libmpdemux cdda.c,NONE,1.1 demux_rawaudio.c,NONE,1.1 Makefile,1.28,1.29 demuxer.c,1.98,1.99 demuxer.h,1.40,1.41 open.c,1.44,1.45 opt-reg.c,1.1,1.2 stream.c,1.36,1.37 stream.h,1.41,1.42

Alban Bedel CVS albeu at mplayerhq.hu
Tue Jun 11 16:29:54 CEST 2002


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv8061/libmpdemux

Modified Files:
	Makefile demuxer.c demuxer.h open.c opt-reg.c stream.c 
	stream.h 
Added Files:
	cdda.c demux_rawaudio.c 
Log Message:
Support for playing audio cds using cdparanoia. Include a raw audio
demuxer wich can be used for other purpose.


--- NEW FILE ---
#include "config.h"

#ifdef HAVE_CDDA

#include "stream.h"
#include "../cfgparser.h"

#include <cdda_interface.h>
#include <cdda_paranoia.h>

#include <stdio.h>
#include <stdlib.h>


static int speed = -1;
static int paranoia_mode = 1;
static char* generic_dev = NULL;
static int sector_size = 0;
static int search_overlap = -1;
static int toc_bias = 0;
static int toc_offset = 0;
static int no_skip = 0;

static config_t cdda_opts[] = {
  { "speed", &speed, CONF_TYPE_INT, CONF_RANGE,1,100, NULL },
  { "paranoia", &paranoia_mode, CONF_TYPE_INT,CONF_RANGE, 0, 2, NULL },
  { "generic-dev", &generic_dev, CONF_TYPE_STRING, 0, 0, 0, NULL },
  { "sector-size", &sector_size, CONF_TYPE_INT, CONF_RANGE,1,100, NULL },
  { "overlap", &search_overlap, CONF_TYPE_INT, CONF_RANGE,0,75, NULL },
  { "toc-bias", &toc_bias, CONF_TYPE_INT, 0, 0, 0, NULL },
  { "toc-offset", &toc_offset, CONF_TYPE_INT, 0, 0, 0, NULL },
  { "noskip", &no_skip, CONF_TYPE_FLAG, 0 , 0, 1, NULL },
  { "skip", &no_skip, CONF_TYPE_FLAG, 0 , 1, 0, NULL },
  {NULL, NULL, 0, 0, 0, 0, NULL}
};

static config_t cdda_conf[] = {
  { "cdda", &cdda_opts, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
  { NULL,NULL, 0, 0, 0, 0, NULL}
};

void cdda_register_options(m_config_t* cfg) {
  m_config_register_options(cfg,cdda_conf);
}

typedef struct {
  cdrom_drive* cd;
  cdrom_paranoia* cdp;
  int sector;
  int start_sector;
  int end_sector;
} cdda_priv;

stream_t* open_cdda(char* dev,char* track) {
  stream_t* st;
  int start_track = 0;
  int end_track = 0;
  int mode = paranoia_mode;
  int offset = toc_offset;
  cdrom_drive* cdd = NULL;
  cdda_priv* priv;
  char* end = strchr(track,'-');

  if(!end)
    start_track = end_track = atoi(track);
  else {
    int st_len = end - track;
    int ed_len = strlen(track) - 1 - st_len;

    if(st_len) {
      char st[st_len + 1];
      strncpy(st,track,st_len);
      st[st_len] = '\0';
      start_track = atoi(st);
    }
    if(ed_len) {
      char ed[ed_len + 1];
      strncpy(ed,end+1,ed_len);
      ed[ed_len] = '\0';
      end_track = atoi(ed);
    }
  }
    
  if(generic_dev)
    cdd = cdda_identify_scsi(generic_dev,dev,0,NULL);
  else
    cdd = cdda_identify(dev,0,NULL);

  if(!cdd) {
    mp_msg(MSGT_OPEN,MSGL_ERR,"Can't open cdda device\n");
    return NULL;
  }

  cdda_verbose_set(cdd, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT);


  if(sector_size) {
    cdd->nsectors = sector_size;
    cdd->bigbuff = sector_size * CD_FRAMESIZE_RAW;
  }

  if(cdda_open(cdd) != 0) {
    mp_msg(MSGT_OPEN,MSGL_ERR,"Can't open disc\n");
    cdda_close(cdd);
    return NULL;
  }

  priv = (cdda_priv*)malloc(sizeof(cdda_priv));
  priv->cd = cdd;

  if(toc_bias)
    offset -= cdda_track_firstsector(cdd,1);

  if(offset) {
    int i;
    for(i = 0 ; i < cdd->tracks + 1 ; i++)
      cdd->disc_toc[i].dwStartSector += offset;
  }

  if(speed)
    cdda_speed_set(cdd,speed);

  if(start_track)
    priv->start_sector = cdda_track_firstsector(cdd,start_track);
  else
    priv->start_sector = cdda_disc_firstsector(cdd);

  if(end_track) {
    int last = cdda_tracks(cdd);
    if(end_track > last) end_track = last;
    priv->end_sector = cdda_track_lastsector(cdd,end_track);
  } else
    priv->end_sector = cdda_disc_lastsector(cdd);

  priv->cdp = paranoia_init(cdd);
  if(priv->cdp == NULL) {
    cdda_close(cdd);
    free(priv);
    return NULL;
  }

  if(mode == 0)
    mode = PARANOIA_MODE_DISABLE;
  else if(mode == 1)
    mode = PARANOIA_MODE_OVERLAP;
  else
    mode = PARANOIA_MODE_FULL;
  
  if(no_skip)
    mode |= PARANOIA_MODE_NEVERSKIP;

  if(search_overlap >= 0)
    paranoia_overlapset(cdd,search_overlap);

  paranoia_seek(priv->cdp,priv->start_sector,SEEK_SET);
  priv->sector = priv->start_sector;

  st = new_stream(-1,STREAMTYPE_CDDA);
  st->priv = priv;
  st->start_pos = priv->start_sector*CD_FRAMESIZE_RAW;
  st->end_pos = priv->end_sector*CD_FRAMESIZE_RAW;

  return st;
}

static void cdparanoia_callback(long inpos, int function) {
}

int read_cdda(stream_t* s) {
  cdda_priv* p = (cdda_priv*)s->priv;
  int16_t * buf;
  
  buf = paranoia_read(p->cdp,cdparanoia_callback);

  p->sector++;
  s->pos = p->sector*CD_FRAMESIZE_RAW;
  memcpy(s->buffer,buf,CD_FRAMESIZE_RAW);

  if(p->sector == p->end_sector)
    s->eof = 1;

  return CD_FRAMESIZE_RAW;
}

void seek_cdda(stream_t* s) {
  cdda_priv* p = (cdda_priv*)s->priv;
  int sec = s->pos/CD_FRAMESIZE_RAW;

  if(sec < p->start_sector)
    sec = p->start_sector;
  else if(sec > p->end_sector)
    sec = p->end_sector;

  p->sector = sec;
  s->pos = sec*CD_FRAMESIZE_RAW;

  paranoia_seek(p->cdp,sec,SEEK_SET);

}

void close_cdda(stream_t* s) {
  cdda_priv* p = (cdda_priv*)s->priv;
  paranoia_free(p->cdp);
  cdda_close(p->cd);
}

#endif

--- NEW FILE ---

#include "config.h"

#include <stdlib.h>
#include <stdio.h>

#include "../cfgparser.h"

#include "stream.h"
#include "demuxer.h"
#include "stheader.h"


int use_rawaudio = 0;
static int channels = 2;
static int samplerate = 44100;
static int samplesize = 2;
static int format = 0x1; // Raw PCM

static config_t demux_rawaudio_opts[] = {
  { "on", &use_rawaudio, CONF_TYPE_FLAG, 0,0, 1, NULL },
  { "channels", &channels, CONF_TYPE_INT,CONF_RANGE,1,8, NULL },
  { "rate", &samplerate, CONF_TYPE_INT,CONF_RANGE,1000,8*48000, NULL },
  { "samplesize", &samplesize, CONF_TYPE_INT,CONF_RANGE,1,8, NULL },
  { "format", &format, CONF_TYPE_INT, CONF_MIN, 0 , 0, NULL },
  {NULL, NULL, 0, 0, 0, 0, NULL}
};

static config_t demux_rawaudio_conf[] = {
  { "rawaudio", &demux_rawaudio_opts, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
  { NULL,NULL, 0, 0, 0, 0, NULL}
};

void demux_rwaudio_register_options(m_config_t* cfg) {
  m_config_register_options(cfg,demux_rawaudio_conf);
}

extern void resync_audio_stream(sh_audio_t *sh_audio);

int demux_rawaudio_open(demuxer_t* demuxer) {
  sh_audio_t* sh_audio;
  WAVEFORMATEX* w;

  sh_audio = new_sh_audio(demuxer,0);
  sh_audio->wf = w = (WAVEFORMATEX*)malloc(sizeof(WAVEFORMATEX));
  w->wFormatTag = sh_audio->format = format;
  w->nChannels = sh_audio->channels = channels;
  w->nSamplesPerSec = sh_audio->samplerate = samplerate;
  w->nAvgBytesPerSec = samplerate*samplesize*channels;
  w->nBlockAlign = channels*samplesize;
  sh_audio->samplesize = samplesize;
  w->wBitsPerSample = 8*samplesize;
  w->cbSize = 0;

  demuxer->movi_start = demuxer->stream->start_pos;
  demuxer->movi_end = demuxer->stream->end_pos;

  demuxer->audio->sh = sh_audio;
  sh_audio->ds = demuxer->audio;

  return 1;
}

int demux_rawaudio_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) {
  sh_audio_t* sh_audio = demuxer->audio->sh;
  int l = sh_audio->wf->nAvgBytesPerSec;
  off_t spos = stream_tell(demuxer->stream);
  demux_packet_t*  dp;

  if(demuxer->stream->eof)
    return 0;

  dp = new_demux_packet(l);
  ds->pts = spos / (float)(sh_audio->wf->nAvgBytesPerSec);
  ds->pos = spos;

  stream_read(demuxer->stream,dp->buffer,l);
  ds_add_packet(ds,dp);

  return 1;
}

void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
  stream_t* s = demuxer->stream;
  sh_audio_t* sh_audio = demuxer->audio->sh;
  off_t base,pos;

  base = (flags & 1) ? demuxer->movi_start : stream_tell(s);
  if(flags & 2)
    pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
  else
    pos = base + (rel_seek_secs*sh_audio->i_bps);

  pos -= (pos % (sh_audio->channels * sh_audio->samplesize) );
  stream_seek(s,pos);
  resync_audio_stream(sh_audio);
}

Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/Makefile,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Makefile	14 May 2002 22:32:37 -0000	1.28
+++ Makefile	11 Jun 2002 14:29:51 -0000	1.29
@@ -3,7 +3,7 @@
 
 include ../config.mak
 
-SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c aviwrite.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_viv.c demuxer.c dvdauth.c dvdnav_stream.c open.c parse_es.c stream.c tv.c tvi_dummy.c tvi_v4l.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 opt-reg.c mpdemux.c demux_ogg.c demux_bmp.c
+SRCS = mp3_hdr.c video.c mpeg_hdr.c cache2.c asfheader.c aviheader.c aviprint.c aviwrite.c demux_asf.c demux_avi.c demux_mov.c parse_mp4.c demux_mpg.c demux_viv.c demuxer.c dvdauth.c dvdnav_stream.c open.c parse_es.c stream.c tv.c tvi_dummy.c tvi_v4l.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 opt-reg.c mpdemux.c demux_ogg.c demux_bmp.c cdda.c demux_rawaudio.c
 ifeq ($(STREAMING),yes)
 SRCS += asf_streaming.c url.c http.c network.c rtp.c asf_mmst_streaming.c
 endif

Index: demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -r1.98 -r1.99
--- demuxer.c	25 May 2002 22:13:23 -0000	1.98
+++ demuxer.c	11 Jun 2002 14:29:51 -0000	1.99
@@ -260,6 +260,7 @@
 int demux_audio_fill_buffer(demux_stream_t *ds);
 extern int demux_demuxers_fill_buffer(demuxer_t *demux,demux_stream_t *ds);
 extern int demux_ogg_fill_buffer(demuxer_t *d);
+extern int demux_rawaudio_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds);
 
 int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds){
   // Note: parameter 'ds' can be NULL!
@@ -287,6 +288,7 @@
     case DEMUXER_TYPE_AUDIO: return demux_audio_fill_buffer(ds);
     case DEMUXER_TYPE_DEMUXERS: return demux_demuxers_fill_buffer(demux,ds);
     case DEMUXER_TYPE_OGG: return demux_ogg_fill_buffer(demux);
+    case DEMUXER_TYPE_RAWAUDIO: return demux_rawaudio_fill_buffer(demux,ds);
   }
   return 0;
 }
@@ -501,9 +503,12 @@
 extern void demux_open_nuv(demuxer_t *demuxer);
 extern int demux_audio_open(demuxer_t* demuxer);
 extern int demux_ogg_open(demuxer_t* demuxer);
+extern int demux_rawaudio_open(demuxer_t* demuxer);
 
 extern demuxer_t* init_avi_with_ogg(demuxer_t* demuxer);
 
+extern int use_rawaudio;
+
 
 static demuxer_t* demux_open_stream(stream_t *stream,int file_format,int audio_id,int video_id,int dvdsub_id){
 
@@ -525,6 +530,11 @@
   file_format=DEMUXER_TYPE_MF;
  }
 
+if(stream->type == STREAMTYPE_CDDA || use_rawaudio) {
+  demuxer = new_demuxer(stream,DEMUXER_TYPE_RAWAUDIO,audio_id,video_id,dvdsub_id);
+  file_format = DEMUXER_TYPE_RAWAUDIO;
+}
+
 #ifdef USE_TV
 //=============== Try to open as TV-input: =================
 if((tv_param_on == 1) &&
@@ -789,6 +799,10 @@
 demuxer->file_format=file_format;
 
 switch(file_format){
+ case DEMUXER_TYPE_RAWAUDIO: {
+   demux_rawaudio_open(demuxer);
+   break;
+ }
  case DEMUXER_TYPE_MF: {
   if (!demux_open_mf(demuxer)) return NULL;
   break;
@@ -999,6 +1013,7 @@
 #ifdef HAVE_OGGVORBIS
 extern void demux_ogg_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
 #endif
+extern void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
 
 int demux_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
     demux_stream_t *d_audio=demuxer->audio;
@@ -1071,6 +1086,8 @@
  case DEMUXER_TYPE_OGG:
       demux_ogg_seek(demuxer,rel_seek_secs,flags);  break;
 #endif
+ case DEMUXER_TYPE_RAWAUDIO:
+      demux_rawaudio_seek(demuxer,rel_seek_secs,flags);  break;
 
 
 } // switch(demuxer->file_format)

Index: demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- demuxer.h	29 May 2002 17:14:38 -0000	1.40
+++ demuxer.h	11 Jun 2002 14:29:51 -0000	1.41
@@ -28,10 +28,11 @@
 #define DEMUXER_TYPE_AUDIO 17
 #define DEMUXER_TYPE_OGG 18
 #define DEMUXER_TYPE_BMP 19
+#define DEMUXER_TYPE_RAWAUDIO 20
 // This should always match the higest demuxer type number.
 // Unless you want to disallow users to force the demuxer to some types
 #define DEMUXER_TYPE_MIN 0
-#define DEMUXER_TYPE_MAX 19
+#define DEMUXER_TYPE_MAX 20
 
 #define DEMUXER_TYPE_DEMUXERS (1<<16)
 // A virtual demuxer type for the network code

Index: open.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/open.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- open.c	7 Jun 2002 00:42:08 -0000	1.44
+++ open.c	11 Jun 2002 14:29:51 -0000	1.45
@@ -67,6 +67,10 @@
 extern int stream_open_tv(stream_t *stream, tvi_handle_t *tvh);
 #endif
 
+#ifdef HAVE_CDDA
+stream_t* open_cdda(char* dev,char* track);
+#endif
+
 // Open a new stream  (stdin/file/vcd/url)
 
 stream_t* open_stream(char* filename,int vcd_track,int* file_format){
@@ -78,6 +82,11 @@
 #endif
 #ifdef __FreeBSD__
 int bsize = VCD_SECTOR_SIZE;
+#endif
+
+#ifdef HAVE_CDDA
+if(strncmp("cdda://",filename,7) == 0)
+  return open_cdda(cdrom_device ? cdrom_device : DEFAULT_CDROM_DEVICE,filename+7);
 #endif
 
 //============ Open VideoCD track ==============

Index: opt-reg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/opt-reg.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- opt-reg.c	20 Feb 2002 16:59:25 -0000	1.1
+++ opt-reg.c	11 Jun 2002 14:29:51 -0000	1.2
@@ -6,10 +6,17 @@
 
 extern void demux_audio_register_options(m_config_t* cfg);
 extern void demuxer_register_options(m_config_t* cfg);
+extern void demux_rwaudio_register_options(m_config_t* cfg);
+#ifdef HAVE_CDDA
+extern void cdda_register_options(m_config_t* cfg);
+#endif
 
 void libmpdemux_register_options(m_config_t* cfg) {
 
   demux_audio_register_options(cfg);
   demuxer_register_options(cfg);
-
+  demux_rwaudio_register_options(cfg);
+#ifdef HAVE_CDDA
+  cdda_register_options(cfg);
+#endif
 }

Index: stream.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- stream.c	4 Jun 2002 19:17:52 -0000	1.36
+++ stream.c	11 Jun 2002 14:29:51 -0000	1.37
@@ -35,6 +35,12 @@
 void dvd_seek(void* d,off_t pos);
 #endif
 
+#ifdef HAVE_CDDA
+int read_cdda(stream_t* s);
+void seek_cdda(stream_t* s);
+void close_cdda(stream_t* s);
+#endif
+
 //=================== STREAMER =========================
 
 int stream_fill_buffer(stream_t *s){
@@ -53,6 +59,11 @@
 #else
     len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break;
 #endif
+#ifdef HAVE_CDDA
+  case STREAMTYPE_CDDA:
+    len = read_cdda(s);
+    break;
+#endif
 #ifdef HAVE_VCD
   case STREAMTYPE_VCD:
 #ifdef VCD_CACHE
@@ -147,6 +158,13 @@
 #endif
     break;
 #endif
+#ifdef HAVE_CDDA
+  case STREAMTYPE_CDDA: {
+    s->pos=newpos;
+    seek_cdda(s);
+    break;
+  }
+#endif
 #ifdef USE_DVDNAV
   case STREAMTYPE_DVDNAV: {
     if (newpos==0) {
@@ -260,6 +278,10 @@
     waitpid(s->cache_pid,NULL,0);
   }
   if(s->fd>0) close(s->fd);
+#ifdef HAVE_CDDA
+  if(s->type == STREAMTYPE_CDDA)
+    close_cdda(s);
+#endif
   if(s->priv) free(s->priv);
   free(s);
 }

Index: stream.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- stream.h	29 May 2002 17:14:38 -0000	1.41
+++ stream.h	11 Jun 2002 14:29:51 -0000	1.42
@@ -17,6 +17,7 @@
 #define STREAMTYPE_MF   7
 #define STREAMTYPE_DS   8
 #define STREAMTYPE_DVDNAV 9   // we cannot safely "seek" in this...
+#define STREAMTYPE_CDDA 10
 
 #define VCD_SECTOR_SIZE 2352
 #define VCD_SECTOR_OFFS 24




More information about the MPlayer-cvslog mailing list