annotate libmpdemux/demux_rawaudio.c @ 16709:661e71fd3a60

Remove the "How to send patches appendix", the info is in the FAQ.
author diego
date Sat, 08 Oct 2005 18:41:58 +0000
parents 22f576c02442
children 9081ae3a702c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
1
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
2 #include "config.h"
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
3
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
4 #include <stdlib.h>
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
5 #include <stdio.h>
8165
388263fa5a11 FreeBSD fix
nexus
parents: 7867
diff changeset
6 #include <unistd.h>
8451
fb88ccbc5ccc compiler warning fixes
arpi
parents: 8165
diff changeset
7 #include <string.h>
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
8
9707
53e738a54064 Fix a 100L bug wich killed mencoder timing and switch to the new
albeu
parents: 8524
diff changeset
9 #include "../m_option.h"
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
10
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
11 #include "stream.h"
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
12 #include "demuxer.h"
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
13 #include "stheader.h"
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
14
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
15
9750
0d4904611455 Set deuxer_type instead of using our own global var.
albeu
parents: 9707
diff changeset
16 extern int demuxer_type;
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
17 static int channels = 2;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
18 static int samplerate = 44100;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
19 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
20 static int bitrate = 0;
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
21 static int format = 0x1; // Raw PCM
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
22
10594
57bdcdb061d7 Removed the historic cfgparser and switched full to the new config parser (altought some macros still remain for compatibility). As a side effect 90% of the warning messages are gone from the core. Things should be cleaner now and less confusing for newbies.
alex
parents: 9800
diff changeset
23 m_option_t demux_rawaudio_opts[] = {
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
24 { "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
25 { "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
26 { "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
27 { "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
28 { "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
29 {NULL, NULL, 0, 0, 0, 0, NULL}
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
30 };
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 extern void resync_audio_stream(sh_audio_t *sh_audio);
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
34
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
35 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
36 sh_audio_t* sh_audio;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
37 WAVEFORMATEX* w;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
38
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
39 sh_audio = new_sh_audio(demuxer,0);
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
40 sh_audio->wf = w = (WAVEFORMATEX*)malloc(sizeof(WAVEFORMATEX));
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
41 w->wFormatTag = sh_audio->format = format;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
42 w->nChannels = sh_audio->channels = channels;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
43 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
44 if (bitrate > 999)
e6f6dac5d77b needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents: 10891
diff changeset
45 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
46 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
47 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
48 else
e6f6dac5d77b needed for a/v sync with compressed audio (e.g. raw .mp2 or .ac3 file)
rfelker
parents: 10891
diff changeset
49 w->nAvgBytesPerSec = samplerate*samplesize*channels;
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
50 w->nBlockAlign = channels*samplesize;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
51 sh_audio->samplesize = samplesize;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
52 w->wBitsPerSample = 8*samplesize;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
53 w->cbSize = 0;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
54
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
55 demuxer->movi_start = demuxer->stream->start_pos;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
56 demuxer->movi_end = demuxer->stream->end_pos;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
57
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
58 demuxer->audio->sh = sh_audio;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
59 sh_audio->ds = demuxer->audio;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
60
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
61 return demuxer;
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
62 }
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
63
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
64 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
65 sh_audio_t* sh_audio = demuxer->audio->sh;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
66 int l = sh_audio->wf->nAvgBytesPerSec;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
67 off_t spos = stream_tell(demuxer->stream);
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
68 demux_packet_t* dp;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
69
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
70 if(demuxer->stream->eof)
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
71 return 0;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
72
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
73 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
74 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
75 dp->pos = (spos - demuxer->movi_start);
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
76
10891
65ed62e138fa Fixed 'reading after EOF'. demuxers didn't check, how many they've read!
lumag
parents: 10594
diff changeset
77 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
78 resize_demux_packet(dp, l);
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
79 ds_add_packet(ds,dp);
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
80
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
81 return 1;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
82 }
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
83
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
84 static void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
85 stream_t* s = demuxer->stream;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
86 sh_audio_t* sh_audio = demuxer->audio->sh;
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
87 off_t base,pos;
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 base = (flags & 1) ? demuxer->movi_start : stream_tell(s);
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
90 if(flags & 2)
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
91 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
92 else
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
93 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
94
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
95 pos -= (pos % (sh_audio->channels * sh_audio->samplesize) );
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
96 stream_seek(s,pos);
9800
2865ea4eca4b *** empty log message ***
albeu
parents: 9750
diff changeset
97 sh_audio->delay= (pos-ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len) / (float)(sh_audio->wf->nAvgBytesPerSec);
6384
f0b933918a22 Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
diff changeset
98 resync_audio_stream(sh_audio);
8524
fe542f0201ea CDDA seeking fixed
arpi
parents: 8451
diff changeset
99 // 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
100 }
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
101
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
102
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
103 demuxer_desc_t demuxer_desc_rawaudio = {
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
104 "Raw audio demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
105 "rawaudio",
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
106 "rawaudio",
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
107 "?",
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
108 "",
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
109 DEMUXER_TYPE_RAWAUDIO,
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
110 0, // no autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
111 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
112 demux_rawaudio_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
113 demux_rawaudio_open,
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
114 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
115 demux_rawaudio_seek,
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
116 NULL
6b86089c2edd Demuxer modularization
rtognimp
parents: 12281
diff changeset
117 };