2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "stream/stream.h"
33 static int channels
= 2;
34 static int samplerate
= 44100;
35 static int samplesize
= 2;
36 static int bitrate
= 0;
37 static int format
= 0x1; // Raw PCM
39 const m_option_t demux_rawaudio_opts
[] = {
40 { "channels", &channels
, CONF_TYPE_INT
,CONF_RANGE
,1,8, NULL
},
41 { "rate", &samplerate
, CONF_TYPE_INT
,CONF_RANGE
,1000,8*48000, NULL
},
42 { "samplesize", &samplesize
, CONF_TYPE_INT
,CONF_RANGE
,1,8, NULL
},
43 { "bitrate", &bitrate
, CONF_TYPE_INT
,CONF_MIN
,0,0, NULL
},
44 { "format", &format
, CONF_TYPE_INT
, CONF_MIN
, 0 , 0, NULL
},
45 {NULL
, NULL
, 0, 0, 0, 0, NULL
}
49 static demuxer_t
* demux_rawaudio_open(demuxer_t
* demuxer
) {
53 sh_audio
= new_sh_audio(demuxer
,0);
54 sh_audio
->wf
= w
= malloc(sizeof(WAVEFORMATEX
));
55 w
->wFormatTag
= sh_audio
->format
= format
;
56 w
->nChannels
= sh_audio
->channels
= channels
;
57 w
->nSamplesPerSec
= sh_audio
->samplerate
= samplerate
;
59 w
->nAvgBytesPerSec
= bitrate
/8;
61 w
->nAvgBytesPerSec
= bitrate
*125;
63 w
->nAvgBytesPerSec
= samplerate
*samplesize
*channels
;
64 w
->nBlockAlign
= channels
*samplesize
;
65 sh_audio
->samplesize
= samplesize
;
66 w
->wBitsPerSample
= 8*samplesize
;
69 demuxer
->movi_start
= demuxer
->stream
->start_pos
;
70 demuxer
->movi_end
= demuxer
->stream
->end_pos
;
72 demuxer
->audio
->id
= 0;
73 demuxer
->audio
->sh
= sh_audio
;
74 sh_audio
->ds
= demuxer
->audio
;
75 sh_audio
->needs_parsing
= 1;
80 static int demux_rawaudio_fill_buffer(demuxer_t
* demuxer
, demux_stream_t
*ds
) {
81 sh_audio_t
* sh_audio
= demuxer
->audio
->sh
;
82 int l
= sh_audio
->wf
->nAvgBytesPerSec
;
83 off_t spos
= stream_tell(demuxer
->stream
);
86 if(demuxer
->stream
->eof
)
89 dp
= new_demux_packet(l
);
90 dp
->pts
= (spos
- demuxer
->movi_start
) / (float)(sh_audio
->wf
->nAvgBytesPerSec
);
91 dp
->pos
= (spos
- demuxer
->movi_start
);
93 l
= stream_read(demuxer
->stream
,dp
->buffer
,l
);
94 resize_demux_packet(dp
, l
);
100 static void demux_rawaudio_seek(demuxer_t
*demuxer
,float rel_seek_secs
,float audio_delay
,int flags
){
101 stream_t
* s
= demuxer
->stream
;
102 sh_audio_t
* sh_audio
= demuxer
->audio
->sh
;
105 base
= (flags
& SEEK_ABSOLUTE
) ? demuxer
->movi_start
: stream_tell(s
);
106 if(flags
& SEEK_FACTOR
)
107 pos
= base
+ ((demuxer
->movi_end
- demuxer
->movi_start
)*rel_seek_secs
);
109 pos
= base
+ (rel_seek_secs
*sh_audio
->i_bps
);
111 pos
-= (pos
% (sh_audio
->channels
* sh_audio
->samplesize
) );
113 // printf("demux_rawaudio: streamtell=%d\n",(int)stream_tell(demuxer->stream));
116 const demuxer_desc_t demuxer_desc_rawaudio
= {
122 DEMUXER_TYPE_RAWAUDIO
,
125 demux_rawaudio_fill_buffer
,