Add explanatory comments to the #endif part of multiple inclusion guards.
[mplayer/greg.git] / libmpdemux / demux_rawaudio.c
blob8c08f73467e7d488c750838c6fc9258e6fca83dd
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 extern int demuxer_type;
17 static int channels = 2;
18 static int samplerate = 44100;
19 static int samplesize = 2;
20 static int bitrate = 0;
21 static int format = 0x1; // Raw PCM
23 const m_option_t demux_rawaudio_opts[] = {
24 { "channels", &channels, CONF_TYPE_INT,CONF_RANGE,1,8, NULL },
25 { "rate", &samplerate, CONF_TYPE_INT,CONF_RANGE,1000,8*48000, NULL },
26 { "samplesize", &samplesize, CONF_TYPE_INT,CONF_RANGE,1,8, NULL },
27 { "bitrate", &bitrate, CONF_TYPE_INT,CONF_MIN,0,0, NULL },
28 { "format", &format, CONF_TYPE_INT, CONF_MIN, 0 , 0, NULL },
29 {NULL, NULL, 0, 0, 0, 0, NULL}
33 static demuxer_t* demux_rawaudio_open(demuxer_t* demuxer) {
34 sh_audio_t* sh_audio;
35 WAVEFORMATEX* w;
37 sh_audio = new_sh_audio(demuxer,0);
38 sh_audio->wf = w = malloc(sizeof(WAVEFORMATEX));
39 w->wFormatTag = sh_audio->format = format;
40 w->nChannels = sh_audio->channels = channels;
41 w->nSamplesPerSec = sh_audio->samplerate = samplerate;
42 if (bitrate > 999)
43 w->nAvgBytesPerSec = bitrate/8;
44 else if (bitrate > 0)
45 w->nAvgBytesPerSec = bitrate*125;
46 else
47 w->nAvgBytesPerSec = samplerate*samplesize*channels;
48 w->nBlockAlign = channels*samplesize;
49 sh_audio->samplesize = samplesize;
50 w->wBitsPerSample = 8*samplesize;
51 w->cbSize = 0;
53 demuxer->movi_start = demuxer->stream->start_pos;
54 demuxer->movi_end = demuxer->stream->end_pos;
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 & 1) ? demuxer->movi_start : stream_tell(s);
88 if(flags & 2)
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 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