11 #include "stream/stream.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
) {
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
;
43 w
->nAvgBytesPerSec
= bitrate
/8;
45 w
->nAvgBytesPerSec
= bitrate
*125;
47 w
->nAvgBytesPerSec
= samplerate
*samplesize
*channels
;
48 w
->nBlockAlign
= channels
*samplesize
;
49 sh_audio
->samplesize
= samplesize
;
50 w
->wBitsPerSample
= 8*samplesize
;
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
;
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
);
68 if(demuxer
->stream
->eof
)
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
);
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
;
87 base
= (flags
& 1) ? demuxer
->movi_start
: stream_tell(s
);
89 pos
= base
+ ((demuxer
->movi_end
- demuxer
->movi_start
)*rel_seek_secs
);
91 pos
= base
+ (rel_seek_secs
*sh_audio
->i_bps
);
93 pos
-= (pos
% (sh_audio
->channels
* sh_audio
->samplesize
) );
95 // printf("demux_rawaudio: streamtell=%d\n",(int)stream_tell(demuxer->stream));
99 const demuxer_desc_t demuxer_desc_rawaudio
= {
105 DEMUXER_TYPE_RAWAUDIO
,
108 demux_rawaudio_fill_buffer
,