11 #include "stream/stream.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
) {
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
;
42 w
->nAvgBytesPerSec
= bitrate
/8;
44 w
->nAvgBytesPerSec
= bitrate
*125;
46 w
->nAvgBytesPerSec
= samplerate
*samplesize
*channels
;
47 w
->nBlockAlign
= channels
*samplesize
;
48 sh_audio
->samplesize
= samplesize
;
49 w
->wBitsPerSample
= 8*samplesize
;
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
;
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
& 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
);
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
,