Replace a mention of MPlayer by MEncoder in the MEncoder section.
[mplayer/glamo.git] / libmpdemux / demux_rawaudio.c
blob5e4ce8f84f8544c6e541f6e59a736b99e2d3263f
2 #include "config.h"
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <string.h>
9 #include "m_option.h"
11 #include "stream/stream.h"
12 #include "demuxer.h"
13 #include "stheader.h"
16 static int channels = 2;
17 static int samplerate = 44100;
18 static int samplesize = 2;
19 static int bitrate = 0;
20 static int format = 0x1; // Raw PCM
22 const m_option_t demux_rawaudio_opts[] = {
23 { "channels", &channels, CONF_TYPE_INT,CONF_RANGE,1,8, NULL },
24 { "rate", &samplerate, CONF_TYPE_INT,CONF_RANGE,1000,8*48000, NULL },
25 { "samplesize", &samplesize, CONF_TYPE_INT,CONF_RANGE,1,8, NULL },
26 { "bitrate", &bitrate, CONF_TYPE_INT,CONF_MIN,0,0, NULL },
27 { "format", &format, CONF_TYPE_INT, CONF_MIN, 0 , 0, NULL },
28 {NULL, NULL, 0, 0, 0, 0, NULL}
32 static demuxer_t* demux_rawaudio_open(demuxer_t* demuxer) {
33 sh_audio_t* sh_audio;
34 WAVEFORMATEX* w;
36 sh_audio = new_sh_audio(demuxer,0);
37 sh_audio->wf = w = malloc(sizeof(WAVEFORMATEX));
38 w->wFormatTag = sh_audio->format = format;
39 w->nChannels = sh_audio->channels = channels;
40 w->nSamplesPerSec = sh_audio->samplerate = samplerate;
41 if (bitrate > 999)
42 w->nAvgBytesPerSec = bitrate/8;
43 else if (bitrate > 0)
44 w->nAvgBytesPerSec = bitrate*125;
45 else
46 w->nAvgBytesPerSec = samplerate*samplesize*channels;
47 w->nBlockAlign = channels*samplesize;
48 sh_audio->samplesize = samplesize;
49 w->wBitsPerSample = 8*samplesize;
50 w->cbSize = 0;
52 demuxer->movi_start = demuxer->stream->start_pos;
53 demuxer->movi_end = demuxer->stream->end_pos;
55 demuxer->audio->id = 0;
56 demuxer->audio->sh = sh_audio;
57 sh_audio->ds = demuxer->audio;
59 return demuxer;
62 static int demux_rawaudio_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) {
63 sh_audio_t* sh_audio = demuxer->audio->sh;
64 int l = sh_audio->wf->nAvgBytesPerSec;
65 off_t spos = stream_tell(demuxer->stream);
66 demux_packet_t* dp;
68 if(demuxer->stream->eof)
69 return 0;
71 dp = new_demux_packet(l);
72 dp->pts = (spos - demuxer->movi_start) / (float)(sh_audio->wf->nAvgBytesPerSec);
73 dp->pos = (spos - demuxer->movi_start);
75 l = stream_read(demuxer->stream,dp->buffer,l);
76 resize_demux_packet(dp, l);
77 ds_add_packet(ds,dp);
79 return 1;
82 static void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
83 stream_t* s = demuxer->stream;
84 sh_audio_t* sh_audio = demuxer->audio->sh;
85 off_t base,pos;
87 base = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : stream_tell(s);
88 if(flags & SEEK_FACTOR)
89 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
90 else
91 pos = base + (rel_seek_secs*sh_audio->i_bps);
93 pos -= (pos % (sh_audio->channels * sh_audio->samplesize) );
94 stream_seek(s,pos);
95 // printf("demux_rawaudio: streamtell=%d\n",(int)stream_tell(demuxer->stream));
99 const demuxer_desc_t demuxer_desc_rawaudio = {
100 "Raw audio demuxer",
101 "rawaudio",
102 "rawaudio",
103 "?",
105 DEMUXER_TYPE_RAWAUDIO,
106 0, // no autodetect
107 NULL,
108 demux_rawaudio_fill_buffer,
109 demux_rawaudio_open,
110 NULL,
111 demux_rawaudio_seek,
112 NULL