Mercurial > mplayer.hg
comparison dll_init.c @ 291:da98e96499bb
sh_audio/sh_video added, general codec cleanup
author | arpi_esp |
---|---|
date | Fri, 06 Apr 2001 01:18:59 +0000 |
parents | 92776006958f |
children | c3d7a28a0d1a |
comparison
equal
deleted
inserted
replaced
290:f40a55208b76 | 291:da98e96499bb |
---|---|
1 // ACM audio and VfW video codecs initialization | 1 // ACM audio and VfW video codecs initialization |
2 // based on the avifile library [http://divx.euro.ru] | 2 // based on the avifile library [http://divx.euro.ru] |
3 | 3 |
4 static char* a_in_buffer=NULL; | 4 int init_audio_codec(sh_audio_t *sh_audio){ |
5 static int a_in_buffer_len=0; | |
6 static int a_in_buffer_size=0; | |
7 | |
8 int init_audio_codec(){ | |
9 HRESULT ret; | 5 HRESULT ret; |
10 WAVEFORMATEX *in_fmt=(WAVEFORMATEX*)&avi_header.wf_ext; | 6 WAVEFORMATEX *in_fmt=&sh_audio->wf; |
11 unsigned long srcsize=0; | 7 unsigned long srcsize=0; |
12 | 8 |
13 if(verbose) printf("======= Win32 (ACM) AUDIO Codec init =======\n"); | 9 if(verbose) printf("======= Win32 (ACM) AUDIO Codec init =======\n"); |
14 | 10 |
15 avi_header.srcstream=NULL; | 11 sh_audio->srcstream=NULL; |
16 | 12 |
17 // if(in_fmt->nSamplesPerSec==0){ printf("Bad WAVE header!\n");exit(1); } | 13 // if(in_fmt->nSamplesPerSec==0){ printf("Bad WAVE header!\n");exit(1); } |
18 // MSACM_RegisterAllDrivers(); | 14 // MSACM_RegisterAllDrivers(); |
19 | 15 |
20 avi_header.wf.nChannels=in_fmt->nChannels; | 16 sh_audio->o_wf.nChannels=in_fmt->nChannels; |
21 avi_header.wf.nSamplesPerSec=in_fmt->nSamplesPerSec; | 17 sh_audio->o_wf.nSamplesPerSec=in_fmt->nSamplesPerSec; |
22 avi_header.wf.nAvgBytesPerSec=2*avi_header.wf.nSamplesPerSec*avi_header.wf.nChannels; | 18 sh_audio->o_wf.nAvgBytesPerSec=2*sh_audio->o_wf.nSamplesPerSec*sh_audio->o_wf.nChannels; |
23 avi_header.wf.wFormatTag=WAVE_FORMAT_PCM; | 19 sh_audio->o_wf.wFormatTag=WAVE_FORMAT_PCM; |
24 avi_header.wf.nBlockAlign=2*in_fmt->nChannels; | 20 sh_audio->o_wf.nBlockAlign=2*in_fmt->nChannels; |
25 avi_header.wf.wBitsPerSample=16; | 21 sh_audio->o_wf.wBitsPerSample=16; |
26 avi_header.wf.cbSize=0; | 22 sh_audio->o_wf.cbSize=0; |
27 | 23 |
28 win32_codec_name = avi_header.audio_codec; | 24 win32_codec_name = avi_header.audio_codec; |
29 ret=acmStreamOpen(&avi_header.srcstream,(HACMDRIVER)NULL, | 25 ret=acmStreamOpen(&sh_audio->srcstream,(HACMDRIVER)NULL, |
30 in_fmt,&avi_header.wf, | 26 in_fmt,&sh_audio->o_wf, |
31 NULL,0,0,0); | 27 NULL,0,0,0); |
32 if(ret){ | 28 if(ret){ |
33 if(ret==ACMERR_NOTPOSSIBLE) | 29 if(ret==ACMERR_NOTPOSSIBLE) |
34 printf("ACM_Decoder: Unappropriate audio format\n"); | 30 printf("ACM_Decoder: Unappropriate audio format\n"); |
35 else | 31 else |
36 printf("ACM_Decoder: acmStreamOpen error %d", ret); | 32 printf("ACM_Decoder: acmStreamOpen error %d", ret); |
37 avi_header.srcstream=NULL; | 33 sh_audio->srcstream=NULL; |
38 return 0; | 34 return 0; |
39 } | 35 } |
40 if(verbose) printf("Audio codec opened OK! ;-)\n"); | 36 if(verbose) printf("Audio codec opened OK! ;-)\n"); |
41 | 37 |
42 srcsize=in_fmt->nBlockAlign; | 38 srcsize=in_fmt->nBlockAlign; |
43 acmStreamSize(avi_header.srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_SOURCE); | 39 acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_SOURCE); |
44 if(srcsize<OUTBURST) srcsize=OUTBURST; | 40 if(srcsize<OUTBURST) srcsize=OUTBURST; |
45 avi_header.audio_out_minsize=srcsize; // audio output min. size | 41 sh_audio->audio_out_minsize=srcsize; // audio output min. size |
46 if(verbose) printf("Audio ACM output buffer min. size: %d\n",srcsize); | 42 if(verbose) printf("Audio ACM output buffer min. size: %d\n",srcsize); |
47 | 43 |
48 acmStreamSize(avi_header.srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION); | 44 acmStreamSize(sh_audio->srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION); |
49 avi_header.audio_in_minsize=srcsize; // audio input min. size | 45 sh_audio->audio_in_minsize=srcsize; // audio input min. size |
50 if(verbose) printf("Audio ACM input buffer min. size: %d\n",srcsize); | 46 if(verbose) printf("Audio ACM input buffer min. size: %d\n",srcsize); |
51 | 47 |
52 a_in_buffer_size=avi_header.audio_in_minsize; | 48 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; |
53 a_in_buffer=malloc(a_in_buffer_size); | 49 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); |
54 a_in_buffer_len=0; | 50 sh_audio->a_in_buffer_len=0; |
55 | 51 |
56 return 1; | 52 return 1; |
57 } | 53 } |
58 | 54 |
59 int acm_decode_audio(void* a_buffer,int len){ | 55 int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int len){ |
60 ACMSTREAMHEADER ash; | 56 ACMSTREAMHEADER ash; |
61 HRESULT hr; | 57 HRESULT hr; |
62 DWORD srcsize=0; | 58 DWORD srcsize=0; |
63 acmStreamSize(avi_header.srcstream,len , &srcsize, ACM_STREAMSIZEF_DESTINATION); | 59 acmStreamSize(sh_audio->srcstream,len , &srcsize, ACM_STREAMSIZEF_DESTINATION); |
64 if(verbose>=3)printf("acm says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,a_in_buffer_size,len); | 60 if(verbose>=3)printf("acm says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,len); |
65 // if(srcsize==0) srcsize=((WAVEFORMATEX *)&avi_header.wf_ext)->nBlockAlign; | 61 // if(srcsize==0) srcsize=((WAVEFORMATEX *)&sh_audio->o_wf_ext)->nBlockAlign; |
66 if(srcsize>a_in_buffer_size) srcsize=a_in_buffer_size; // !!!!!! | 62 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! |
67 if(a_in_buffer_len<srcsize){ | 63 if(sh_audio->a_in_buffer_len<srcsize){ |
68 a_in_buffer_len+= | 64 sh_audio->a_in_buffer_len+= |
69 demux_read_data(d_audio,&a_in_buffer[a_in_buffer_len], | 65 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], |
70 srcsize-a_in_buffer_len); | 66 srcsize-sh_audio->a_in_buffer_len); |
71 } | 67 } |
72 memset(&ash, 0, sizeof(ash)); | 68 memset(&ash, 0, sizeof(ash)); |
73 ash.cbStruct=sizeof(ash); | 69 ash.cbStruct=sizeof(ash); |
74 ash.fdwStatus=0; | 70 ash.fdwStatus=0; |
75 ash.dwUser=0; | 71 ash.dwUser=0; |
76 ash.pbSrc=a_in_buffer; | 72 ash.pbSrc=sh_audio->a_in_buffer; |
77 ash.cbSrcLength=a_in_buffer_len; | 73 ash.cbSrcLength=sh_audio->a_in_buffer_len; |
78 ash.pbDst=a_buffer; | 74 ash.pbDst=a_buffer; |
79 ash.cbDstLength=len; | 75 ash.cbDstLength=len; |
80 hr=acmStreamPrepareHeader(avi_header.srcstream,&ash,0); | 76 hr=acmStreamPrepareHeader(sh_audio->srcstream,&ash,0); |
81 if(hr){ | 77 if(hr){ |
82 printf("ACM_Decoder: acmStreamPrepareHeader error %d\n",hr); | 78 printf("ACM_Decoder: acmStreamPrepareHeader error %d\n",hr); |
83 return -1; | 79 return -1; |
84 } | 80 } |
85 hr=acmStreamConvert(avi_header.srcstream,&ash,0); | 81 hr=acmStreamConvert(sh_audio->srcstream,&ash,0); |
86 if(hr){ | 82 if(hr){ |
87 printf("ACM_Decoder: acmStreamConvert error %d\n",hr); | 83 printf("ACM_Decoder: acmStreamConvert error %d\n",hr); |
88 return -1; | 84 return -1; |
89 } | 85 } |
90 //printf("ACM convert %d -> %d (buf=%d)\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed,a_in_buffer_len); | 86 //printf("ACM convert %d -> %d (buf=%d)\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed,a_in_buffer_len); |
91 if(ash.cbSrcLengthUsed>=a_in_buffer_len){ | 87 if(ash.cbSrcLengthUsed>=sh_audio->a_in_buffer_len){ |
92 a_in_buffer_len=0; | 88 sh_audio->a_in_buffer_len=0; |
93 } else { | 89 } else { |
94 a_in_buffer_len-=ash.cbSrcLengthUsed; | 90 sh_audio->a_in_buffer_len-=ash.cbSrcLengthUsed; |
95 memcpy(a_in_buffer,&a_in_buffer[ash.cbSrcLengthUsed],a_in_buffer_len); | 91 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[ash.cbSrcLengthUsed],sh_audio->a_in_buffer_len); |
96 } | 92 } |
97 len=ash.cbDstLengthUsed; | 93 len=ash.cbDstLengthUsed; |
98 hr=acmStreamUnprepareHeader(avi_header.srcstream,&ash,0); | 94 hr=acmStreamUnprepareHeader(sh_audio->srcstream,&ash,0); |
99 if(hr){ | 95 if(hr){ |
100 printf("ACM_Decoder: acmStreamUnprepareHeader error %d\n",hr); | 96 printf("ACM_Decoder: acmStreamUnprepareHeader error %d\n",hr); |
101 } | 97 } |
102 return len; | 98 return len; |
103 } | 99 } |
107 int init_video_codec(int outfmt){ | 103 int init_video_codec(int outfmt){ |
108 HRESULT ret; | 104 HRESULT ret; |
109 | 105 |
110 if(verbose) printf("======= Win32 (VFW) VIDEO Codec init =======\n"); | 106 if(verbose) printf("======= Win32 (VFW) VIDEO Codec init =======\n"); |
111 | 107 |
112 memset(&avi_header.o_bih, 0, sizeof(BITMAPINFOHEADER)); | 108 memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER)); |
113 avi_header.o_bih.biSize = sizeof(BITMAPINFOHEADER); | 109 sh_video->o_bih.biSize = sizeof(BITMAPINFOHEADER); |
114 | 110 |
115 win32_codec_name = avi_header.video_codec; | 111 win32_codec_name = avi_header.video_codec; |
116 avi_header.hic = ICOpen( 0x63646976, avi_header.bih.biCompression, ICMODE_FASTDECOMPRESS); | 112 sh_video->hic = ICOpen( 0x63646976, sh_video->bih.biCompression, ICMODE_FASTDECOMPRESS); |
117 // avi_header.hic = ICOpen( 0x63646976, avi_header.bih.biCompression, ICMODE_DECOMPRESS); | 113 // sh_video->hic = ICOpen( 0x63646976, sh_video->bih.biCompression, ICMODE_DECOMPRESS); |
118 if(!avi_header.hic){ | 114 if(!sh_video->hic){ |
119 printf("ICOpen failed! unknown codec / wrong parameters?\n"); | 115 printf("ICOpen failed! unknown codec / wrong parameters?\n"); |
120 return 0; | 116 return 0; |
121 } | 117 } |
122 | 118 |
123 // avi_header.bih.biBitCount=32; | 119 // sh_video->bih.biBitCount=32; |
124 | 120 |
125 ret = ICDecompressGetFormat(avi_header.hic, &avi_header.bih, &avi_header.o_bih); | 121 ret = ICDecompressGetFormat(sh_video->hic, &sh_video->bih, &sh_video->o_bih); |
126 if(ret){ | 122 if(ret){ |
127 printf("ICDecompressGetFormat failed: Error %d\n", ret); | 123 printf("ICDecompressGetFormat failed: Error %d\n", ret); |
128 return 0; | 124 return 0; |
129 } | 125 } |
130 if(verbose) printf("ICDecompressGetFormat OK\n"); | 126 if(verbose) printf("ICDecompressGetFormat OK\n"); |
131 | 127 |
132 // printf("ICM_DECOMPRESS_QUERY=0x%X",ICM_DECOMPRESS_QUERY); | 128 // printf("ICM_DECOMPRESS_QUERY=0x%X",ICM_DECOMPRESS_QUERY); |
133 | 129 |
134 // avi_header.o_bih.biWidth=avi_header.bih.biWidth; | 130 // sh_video->o_bih.biWidth=sh_video->bih.biWidth; |
135 // avi_header.o_bih.biCompression = 0x32315659; // mmioFOURCC('U','Y','V','Y'); | 131 // sh_video->o_bih.biCompression = 0x32315659; // mmioFOURCC('U','Y','V','Y'); |
136 // ret=ICDecompressGetFormatSize(avi_header.hic,&avi_header.o_bih); | 132 // ret=ICDecompressGetFormatSize(sh_video->hic,&sh_video->o_bih); |
137 // avi_header.o_bih.biCompression = 3; //0x32315659; | 133 // sh_video->o_bih.biCompression = 3; //0x32315659; |
138 // avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); | 134 // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); |
139 // avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); | 135 // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); |
140 // avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); | 136 // sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); |
141 // avi_header.o_bih.biPlanes=3; | 137 // sh_video->o_bih.biPlanes=3; |
142 // avi_header.o_bih.biBitCount=16; | 138 // sh_video->o_bih.biBitCount=16; |
143 | 139 |
144 if(outfmt==IMGFMT_YUY2) | 140 if(outfmt==IMGFMT_YUY2) |
145 avi_header.o_bih.biBitCount=16; | 141 sh_video->o_bih.biBitCount=16; |
146 else | 142 else |
147 avi_header.o_bih.biBitCount=outfmt&0xFF;// //24; | 143 sh_video->o_bih.biBitCount=outfmt&0xFF;// //24; |
148 | 144 |
149 avi_header.o_bih.biSizeImage=avi_header.o_bih.biWidth*avi_header.o_bih.biHeight*(avi_header.o_bih.biBitCount/8); | 145 sh_video->o_bih.biSizeImage=sh_video->o_bih.biWidth*sh_video->o_bih.biHeight*(sh_video->o_bih.biBitCount/8); |
150 | 146 |
151 if(!avi_header.flipped) | 147 if(!avi_header.flipped) |
152 avi_header.o_bih.biHeight=-avi_header.bih.biHeight; // flip image! | 148 sh_video->o_bih.biHeight=-sh_video->bih.biHeight; // flip image! |
153 | 149 |
154 if(outfmt==IMGFMT_YUY2 && !avi_header.yuv_hack_needed) | 150 if(outfmt==IMGFMT_YUY2 && !avi_header.yuv_hack_needed) |
155 avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); | 151 sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); |
156 | 152 |
157 // avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); | 153 // sh_video->o_bih.biCompression = mmioFOURCC('U','Y','V','Y'); |
158 | 154 |
159 | 155 |
160 if(verbose) { | 156 if(verbose) { |
161 printf("Starting decompression, format:\n"); | 157 printf("Starting decompression, format:\n"); |
162 printf(" biSize %d\n", avi_header.bih.biSize); | 158 printf(" biSize %d\n", sh_video->bih.biSize); |
163 printf(" biWidth %d\n", avi_header.bih.biWidth); | 159 printf(" biWidth %d\n", sh_video->bih.biWidth); |
164 printf(" biHeight %d\n", avi_header.bih.biHeight); | 160 printf(" biHeight %d\n", sh_video->bih.biHeight); |
165 printf(" biPlanes %d\n", avi_header.bih.biPlanes); | 161 printf(" biPlanes %d\n", sh_video->bih.biPlanes); |
166 printf(" biBitCount %d\n", avi_header.bih.biBitCount); | 162 printf(" biBitCount %d\n", sh_video->bih.biBitCount); |
167 printf(" biCompression %d='%.4s'\n", avi_header.bih.biCompression, &avi_header.bih.biCompression); | 163 printf(" biCompression %d='%.4s'\n", sh_video->bih.biCompression, &sh_video->bih.biCompression); |
168 printf(" biSizeImage %d\n", avi_header.bih.biSizeImage); | 164 printf(" biSizeImage %d\n", sh_video->bih.biSizeImage); |
169 printf("Dest fmt:\n"); | 165 printf("Dest fmt:\n"); |
170 printf(" biSize %d\n", avi_header.o_bih.biSize); | 166 printf(" biSize %d\n", sh_video->o_bih.biSize); |
171 printf(" biWidth %d\n", avi_header.o_bih.biWidth); | 167 printf(" biWidth %d\n", sh_video->o_bih.biWidth); |
172 printf(" biHeight %d\n", avi_header.o_bih.biHeight); | 168 printf(" biHeight %d\n", sh_video->o_bih.biHeight); |
173 printf(" biPlanes %d\n", avi_header.o_bih.biPlanes); | 169 printf(" biPlanes %d\n", sh_video->o_bih.biPlanes); |
174 printf(" biBitCount %d\n", avi_header.o_bih.biBitCount); | 170 printf(" biBitCount %d\n", sh_video->o_bih.biBitCount); |
175 printf(" biCompression %d='%.4s'\n", avi_header.o_bih.biCompression, &avi_header.o_bih.biCompression); | 171 printf(" biCompression %d='%.4s'\n", sh_video->o_bih.biCompression, &sh_video->o_bih.biCompression); |
176 printf(" biSizeImage %d\n", avi_header.o_bih.biSizeImage); | 172 printf(" biSizeImage %d\n", sh_video->o_bih.biSizeImage); |
177 } | 173 } |
178 | 174 |
179 ret = ICDecompressQuery(avi_header.hic, &avi_header.bih, &avi_header.o_bih); | 175 ret = ICDecompressQuery(sh_video->hic, &sh_video->bih, &sh_video->o_bih); |
180 if(ret){ | 176 if(ret){ |
181 printf("ICDecompressQuery failed: Error %d\n", ret); | 177 printf("ICDecompressQuery failed: Error %d\n", ret); |
182 return 0; | 178 return 0; |
183 } | 179 } |
184 if(verbose) printf("ICDecompressQuery OK\n"); | 180 if(verbose) printf("ICDecompressQuery OK\n"); |
185 | 181 |
186 | 182 |
187 ret = ICDecompressBegin(avi_header.hic, &avi_header.bih, &avi_header.o_bih); | 183 ret = ICDecompressBegin(sh_video->hic, &sh_video->bih, &sh_video->o_bih); |
188 if(ret){ | 184 if(ret){ |
189 printf("ICDecompressBegin failed: Error %d\n", ret); | 185 printf("ICDecompressBegin failed: Error %d\n", ret); |
190 return 0; | 186 return 0; |
191 } | 187 } |
192 | 188 |
193 #if 0 | 189 #if 0 |
194 | 190 |
195 //avi_header.hic | 191 //sh_video->hic |
196 //ICSendMessage(HIC hic,unsigned int msg,long lParam1,long lParam2) | 192 //ICSendMessage(HIC hic,unsigned int msg,long lParam1,long lParam2) |
197 { int i; | 193 { int i; |
198 for(i=73;i<256;i++){ | 194 for(i=73;i<256;i++){ |
199 printf("Calling ICM_USER+%d function...",i);fflush(stdout); | 195 printf("Calling ICM_USER+%d function...",i);fflush(stdout); |
200 ret = ICSendMessage(avi_header.hic,ICM_USER+i,NULL,NULL); | 196 ret = ICSendMessage(sh_video->hic,ICM_USER+i,NULL,NULL); |
201 printf(" ret=%d\n",ret); | 197 printf(" ret=%d\n",ret); |
202 } | 198 } |
203 } | 199 } |
204 #endif | 200 #endif |
205 | 201 |
206 avi_header.our_out_buffer = malloc(avi_header.o_bih.biSizeImage); | 202 sh_video->our_out_buffer = malloc(sh_video->o_bih.biSizeImage); |
207 if(!avi_header.our_out_buffer){ | 203 if(!sh_video->our_out_buffer){ |
208 printf("not enough memory for decoded picture buffer (%d bytes)\n", avi_header.o_bih.biSizeImage); | 204 printf("not enough memory for decoded picture buffer (%d bytes)\n", sh_video->o_bih.biSizeImage); |
209 return 0; | 205 return 0; |
210 } | 206 } |
211 | 207 |
212 if(outfmt==IMGFMT_YUY2 && avi_header.yuv_hack_needed) | 208 if(outfmt==IMGFMT_YUY2 && avi_header.yuv_hack_needed) |
213 avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); | 209 sh_video->o_bih.biCompression = mmioFOURCC('Y','U','Y','2'); |
214 | 210 |
215 // avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!! | 211 // avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!! |
216 | 212 |
217 if(verbose) printf("VIDEO CODEC Init OK!!! ;-)\n"); | 213 if(verbose) printf("VIDEO CODEC Init OK!!! ;-)\n"); |
218 return 1; | 214 return 1; |