Mercurial > mplayer.hg
annotate libmpdemux/demux_rawaudio.c @ 36358:d53606fdb693
Autodetect if pthread_cancel is available.
Necessary for properly working reception of streams
via UDP, e.g. via FFmpeg's RTSP-over-UDP implementation.
author | reimar |
---|---|
date | Sat, 21 Sep 2013 16:39:24 +0000 |
parents | 7c8d240d37a6 |
children | 92dd1764392a |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
2 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
3 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
7 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
8 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
12 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
13 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
26378
diff
changeset
|
17 */ |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
18 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
19 #include "config.h" |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
20 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
21 #include <stdlib.h> |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
22 #include <stdio.h> |
8165 | 23 #include <unistd.h> |
8451 | 24 #include <string.h> |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
25 |
17012 | 26 #include "m_option.h" |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
27 |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
19062
diff
changeset
|
28 #include "stream/stream.h" |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
29 #include "demuxer.h" |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
30 #include "stheader.h" |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
31 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
32 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
33 static int channels = 2; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
34 static int samplerate = 44100; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
35 static int samplesize = 2; |
12281
e6f6dac5d77b
needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents:
10891
diff
changeset
|
36 static int bitrate = 0; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
37 static int format = 0x1; // Raw PCM |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
38 |
25241
bb7c65f2a289
Make m_option_t arrays referenced by cfg-common.h const
reimar
parents:
22605
diff
changeset
|
39 const m_option_t demux_rawaudio_opts[] = { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
40 { "channels", &channels, CONF_TYPE_INT,CONF_RANGE,1,8, NULL }, |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
41 { "rate", &samplerate, CONF_TYPE_INT,CONF_RANGE,1000,8*48000, NULL }, |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
42 { "samplesize", &samplesize, CONF_TYPE_INT,CONF_RANGE,1,8, NULL }, |
12281
e6f6dac5d77b
needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents:
10891
diff
changeset
|
43 { "bitrate", &bitrate, CONF_TYPE_INT,CONF_MIN,0,0, NULL }, |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
44 { "format", &format, CONF_TYPE_INT, CONF_MIN, 0 , 0, NULL }, |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
45 {NULL, NULL, 0, 0, 0, 0, NULL} |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
46 }; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
47 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
48 |
16175 | 49 static demuxer_t* demux_rawaudio_open(demuxer_t* demuxer) { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
50 sh_audio_t* sh_audio; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
51 WAVEFORMATEX* w; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
52 |
31609
cd81fce1f010
Make the stream language an argument to the stream creation function
reimar
parents:
30270
diff
changeset
|
53 sh_audio = new_sh_audio(demuxer,0, NULL); |
32111 | 54 sh_audio->wf = w = malloc(sizeof(*w)); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
55 w->wFormatTag = sh_audio->format = format; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
56 w->nChannels = sh_audio->channels = channels; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
57 w->nSamplesPerSec = sh_audio->samplerate = samplerate; |
12281
e6f6dac5d77b
needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents:
10891
diff
changeset
|
58 if (bitrate > 999) |
e6f6dac5d77b
needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents:
10891
diff
changeset
|
59 w->nAvgBytesPerSec = bitrate/8; |
e6f6dac5d77b
needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents:
10891
diff
changeset
|
60 else if (bitrate > 0) |
e6f6dac5d77b
needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents:
10891
diff
changeset
|
61 w->nAvgBytesPerSec = bitrate*125; |
e6f6dac5d77b
needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents:
10891
diff
changeset
|
62 else |
e6f6dac5d77b
needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents:
10891
diff
changeset
|
63 w->nAvgBytesPerSec = samplerate*samplesize*channels; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
64 w->nBlockAlign = channels*samplesize; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
65 sh_audio->samplesize = samplesize; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
66 w->wBitsPerSample = 8*samplesize; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
67 w->cbSize = 0; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
68 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
69 demuxer->movi_start = demuxer->stream->start_pos; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
70 demuxer->movi_end = demuxer->stream->end_pos; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
71 |
26299
4d56038ec730
Fix lots and lots of other demuxers broken by r26301
reimar
parents:
25883
diff
changeset
|
72 demuxer->audio->id = 0; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
73 demuxer->audio->sh = sh_audio; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
74 sh_audio->ds = demuxer->audio; |
30270
02d2d9fc2009
-demuxer rawaudio data will often need parsing (e.g. when it is used for raw
reimar
parents:
29487
diff
changeset
|
75 sh_audio->needs_parsing = 1; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
76 |
16175 | 77 return demuxer; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
78 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
79 |
16175 | 80 static int demux_rawaudio_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
81 sh_audio_t* sh_audio = demuxer->audio->sh; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
82 int l = sh_audio->wf->nAvgBytesPerSec; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
83 off_t spos = stream_tell(demuxer->stream); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
84 demux_packet_t* dp; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
85 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
86 if(demuxer->stream->eof) |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
87 return 0; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
88 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
89 dp = new_demux_packet(l); |
9707
53e738a54064
Fix a 100L bug wich killed mencoder timing and switch to the new
albeu
parents:
8524
diff
changeset
|
90 dp->pts = (spos - demuxer->movi_start) / (float)(sh_audio->wf->nAvgBytesPerSec); |
53e738a54064
Fix a 100L bug wich killed mencoder timing and switch to the new
albeu
parents:
8524
diff
changeset
|
91 dp->pos = (spos - demuxer->movi_start); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
92 |
10891
65ed62e138fa
Fixed 'reading after EOF'. demuxers didn't check, how many they've read!
lumag
parents:
10594
diff
changeset
|
93 l = stream_read(demuxer->stream,dp->buffer,l); |
65ed62e138fa
Fixed 'reading after EOF'. demuxers didn't check, how many they've read!
lumag
parents:
10594
diff
changeset
|
94 resize_demux_packet(dp, l); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
95 ds_add_packet(ds,dp); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
96 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
97 return 1; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
98 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
99 |
17636 | 100 static void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
101 stream_t* s = demuxer->stream; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
102 sh_audio_t* sh_audio = demuxer->audio->sh; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
103 off_t base,pos; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
104 |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
105 base = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : stream_tell(s); |
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
106 if(flags & SEEK_FACTOR) |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
107 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
108 else |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
109 pos = base + (rel_seek_secs*sh_audio->i_bps); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
110 |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
111 pos -= (pos % (sh_audio->channels * sh_audio->samplesize) ); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
112 stream_seek(s,pos); |
8524 | 113 // printf("demux_rawaudio: streamtell=%d\n",(int)stream_tell(demuxer->stream)); |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff
changeset
|
114 } |
16175 | 115 |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25241
diff
changeset
|
116 const demuxer_desc_t demuxer_desc_rawaudio = { |
16175 | 117 "Raw audio demuxer", |
118 "rawaudio", | |
119 "rawaudio", | |
120 "?", | |
121 "", | |
122 DEMUXER_TYPE_RAWAUDIO, | |
123 0, // no autodetect | |
124 NULL, | |
125 demux_rawaudio_fill_buffer, | |
126 demux_rawaudio_open, | |
127 NULL, | |
128 demux_rawaudio_seek, | |
129 }; |