annotate libmpcodecs/ad_pcm.c @ 24992:5701e23ebcb4

Better handling of win32 GUI thread: 1. Use _beginthreadex to create the GUI thread to avoid possible memory leak when linked to MS CRT. 2. Terminate the GUI thread in an cleaner way using PostThreadMessage() rather than the unrecommended TerminateThread().
author zuxy
date Sun, 11 Nov 2007 08:14:57 +0000
parents 666efb20e7d5
children dfa8a510c81c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
1 #include <stdio.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
2 #include <stdlib.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
3 #include <unistd.h>
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
4
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
5 #include "config.h"
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
6 #include "ad_internal.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16307
diff changeset
7 #include "libaf/af_format.h"
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
8
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
9 static ad_info_t info =
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
10 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
11 "Uncompressed PCM audio decoder",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
12 "pcm",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
13 "Nick Kurshev",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
14 "A'rpi",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
15 ""
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
16 };
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
17
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
18 LIBAD_EXTERN(pcm)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
19
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
20 static int init(sh_audio_t *sh_audio)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
21 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
22 WAVEFORMATEX *h=sh_audio->wf;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
23 sh_audio->i_bps=h->nAvgBytesPerSec;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
24 sh_audio->channels=h->nChannels;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
25 sh_audio->samplerate=h->nSamplesPerSec;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
26 sh_audio->samplesize=(h->wBitsPerSample+7)/8;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
27 sh_audio->sample_format=AF_FORMAT_S16_LE; // default
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
28 switch(sh_audio->format){ /* hardware formats: */
12539
4edbef7dd28d More support for audio format 0x0
rtognimp
parents: 12498
diff changeset
29 case 0x0:
12447
fde132f084ce fix bigendian problems (left-right swapped 8bit pcms), add 32bit support
reimar
parents: 12080
diff changeset
30 case 0x1: // Microsoft PCM
14833
78385a72a8bb Add support for 32-bit float WAV files and support for extended WAV files
ivo
parents: 14245
diff changeset
31 case 0xfffe: // Extended
12447
fde132f084ce fix bigendian problems (left-right swapped 8bit pcms), add 32bit support
reimar
parents: 12080
diff changeset
32 switch (sh_audio->samplesize) {
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
33 case 1: sh_audio->sample_format=AF_FORMAT_U8; break;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
34 case 2: sh_audio->sample_format=AF_FORMAT_S16_LE; break;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
35 case 3: sh_audio->sample_format=AF_FORMAT_S24_LE; break;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
36 case 4: sh_audio->sample_format=AF_FORMAT_S32_LE; break;
12447
fde132f084ce fix bigendian problems (left-right swapped 8bit pcms), add 32bit support
reimar
parents: 12080
diff changeset
37 }
fde132f084ce fix bigendian problems (left-right swapped 8bit pcms), add 32bit support
reimar
parents: 12080
diff changeset
38 break;
14833
78385a72a8bb Add support for 32-bit float WAV files and support for extended WAV files
ivo
parents: 14245
diff changeset
39 case 0x3: // IEEE float
78385a72a8bb Add support for 32-bit float WAV files and support for extended WAV files
ivo
parents: 14245
diff changeset
40 sh_audio->sample_format=AF_FORMAT_FLOAT_LE;
78385a72a8bb Add support for 32-bit float WAV files and support for extended WAV files
ivo
parents: 14245
diff changeset
41 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
42 case 0x6: sh_audio->sample_format=AF_FORMAT_A_LAW;break;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
43 case 0x7: sh_audio->sample_format=AF_FORMAT_MU_LAW;break;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
44 case 0x11: sh_audio->sample_format=AF_FORMAT_IMA_ADPCM;break;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
45 case 0x50: sh_audio->sample_format=AF_FORMAT_MPEG2;break;
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
46 /* case 0x2000: sh_audio->sample_format=AFMT_AC3; */
12498
827d908c7705 Fix "raw " audio in mov files.
rtognimp
parents: 12478
diff changeset
47 case 0x20776172: // 'raw '
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
48 sh_audio->sample_format=AF_FORMAT_S16_BE;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
49 if(sh_audio->samplesize==1) sh_audio->sample_format=AF_FORMAT_U8;
12498
827d908c7705 Fix "raw " audio in mov files.
rtognimp
parents: 12478
diff changeset
50 break;
8102
2759150cc687 qt swot support
alex
parents: 7180
diff changeset
51 case 0x736F7774: // 'twos'
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
52 sh_audio->sample_format=AF_FORMAT_S16_BE;
12447
fde132f084ce fix bigendian problems (left-right swapped 8bit pcms), add 32bit support
reimar
parents: 12080
diff changeset
53 // intended fall-through
20704
666efb20e7d5 Fix comment, it's 'sowt', not 'swot' ('twos' reversed)
reimar
parents: 19383
diff changeset
54 case 0x74776F73: // 'sowt'
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
55 if(sh_audio->samplesize==1) sh_audio->sample_format=AF_FORMAT_S8;
6233
e2f1b1b8f8b4 8bit 'twos' S8 pcm audio support - fixes MOTI1E.MOV
arpi
parents: 5827
diff changeset
56 break;
14055
efe58d68689e fl32: BE float32 PCM audio in mov files
rtognimp
parents: 13553
diff changeset
57 case 0x32336c66: // 'fl32', bigendian float32
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
58 sh_audio->sample_format=AF_FORMAT_FLOAT_BE;
14055
efe58d68689e fl32: BE float32 PCM audio in mov files
rtognimp
parents: 13553
diff changeset
59 sh_audio->samplesize=4;
efe58d68689e fl32: BE float32 PCM audio in mov files
rtognimp
parents: 13553
diff changeset
60 break;
17858
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
61 case 0x666c3332: // '23lf', little endian float32, MPlayer internal fourCC
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
62 sh_audio->sample_format=AF_FORMAT_FLOAT_LE;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
63 sh_audio->samplesize=4;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
64 break;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
65 /* case 0x34366c66: // 'fl64', bigendian float64
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
66 sh_audio->sample_format=AF_FORMAT_FLOAT_BE;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
67 sh_audio->samplesize=8;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
68 break;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
69 case 0x666c3634: // '46lf', little endian float64, MPlayer internal fourCC
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
70 sh_audio->sample_format=AF_FORMAT_FLOAT_LE;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
71 sh_audio->samplesize=8;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
72 break;*/
17813
f34f61843448 QuickTime in24 and in32 PCM audio support
rathann
parents: 17012
diff changeset
73 case 0x34326e69: // 'in24', bigendian int24
f34f61843448 QuickTime in24 and in32 PCM audio support
rathann
parents: 17012
diff changeset
74 sh_audio->sample_format=AF_FORMAT_S24_BE;
f34f61843448 QuickTime in24 and in32 PCM audio support
rathann
parents: 17012
diff changeset
75 sh_audio->samplesize=3;
f34f61843448 QuickTime in24 and in32 PCM audio support
rathann
parents: 17012
diff changeset
76 break;
17858
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
77 case 0x696e3234: // '42ni', little endian int24, MPlayer internal fourCC
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
78 sh_audio->sample_format=AF_FORMAT_S24_LE;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
79 sh_audio->samplesize=3;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
80 break;
17813
f34f61843448 QuickTime in24 and in32 PCM audio support
rathann
parents: 17012
diff changeset
81 case 0x32336e69: // 'in32', bigendian int32
f34f61843448 QuickTime in24 and in32 PCM audio support
rathann
parents: 17012
diff changeset
82 sh_audio->sample_format=AF_FORMAT_S32_BE;
f34f61843448 QuickTime in24 and in32 PCM audio support
rathann
parents: 17012
diff changeset
83 sh_audio->samplesize=4;
f34f61843448 QuickTime in24 and in32 PCM audio support
rathann
parents: 17012
diff changeset
84 break;
17858
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
85 case 0x696e3332: // '23ni', little endian int32, MPlayer internal fourCC
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
86 sh_audio->sample_format=AF_FORMAT_S32_LE;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
87 sh_audio->samplesize=4;
996e419c1671 in24/in32/fl32 little/big-endian QuickTime PCM audio support
rathann
parents: 17813
diff changeset
88 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14055
diff changeset
89 default: if(sh_audio->samplesize!=2) sh_audio->sample_format=AF_FORMAT_U8;
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
90 }
16134
a1fd1a7eeb35 lavf demuxer with raw PCM fix (and a related hang)
reimar
parents: 14833
diff changeset
91 if (!sh_audio->samplesize) // this would cause MPlayer to hang later
a1fd1a7eeb35 lavf demuxer with raw PCM fix (and a related hang)
reimar
parents: 14833
diff changeset
92 sh_audio->samplesize = 2;
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
93 return 1;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
94 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
95
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
96 static int preinit(sh_audio_t *sh)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
97 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
98 sh->audio_out_minsize=2048;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
99 return 1;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
100 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
101
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
102 static void uninit(sh_audio_t *sh)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
103 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
104 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
105
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
106 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
107 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
108 int skip;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
109 switch(cmd)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
110 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
111 case ADCTRL_SKIP_FRAME:
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
112 skip=sh->i_bps/16;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
113 skip=skip&(~3);
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
114 demux_read_data(sh->ds,NULL,skip);
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
115 return CONTROL_TRUE;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
116 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
117 return CONTROL_UNKNOWN;
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
118 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
119
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
120 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
121 {
16307
03cd6abe5664 avoid reading more than maxlen bytes.
reimar
parents: 16134
diff changeset
122 unsigned len = sh_audio->channels*sh_audio->samplesize;
19383
0a6382b5b6ee Change pcm decode_audio to return data based on minlen instead of maxlen
uau
parents: 17868
diff changeset
123 len = (minlen + len - 1) / len * len;
0a6382b5b6ee Change pcm decode_audio to return data based on minlen instead of maxlen
uau
parents: 17868
diff changeset
124 if (len > maxlen)
0a6382b5b6ee Change pcm decode_audio to return data based on minlen instead of maxlen
uau
parents: 17868
diff changeset
125 // if someone needs hundreds of channels adjust audio_out_minsize
0a6382b5b6ee Change pcm decode_audio to return data based on minlen instead of maxlen
uau
parents: 17868
diff changeset
126 // based on channels in preinit()
0a6382b5b6ee Change pcm decode_audio to return data based on minlen instead of maxlen
uau
parents: 17868
diff changeset
127 return -1;
5455
5546543ae874 cleanup
arpi
parents: 5453
diff changeset
128 len=demux_read_data(sh_audio->ds,buf,len);
5546543ae874 cleanup
arpi
parents: 5453
diff changeset
129 return len;
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
130 }