annotate dll_init.c @ 49:727b1337f951

updated to libmpeg2-0.2.1-CVS
author arpi_esp
date Wed, 07 Mar 2001 01:15:02 +0000
parents 3b5f5d1c5041
children 92776006958f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 // ACM audio and VfW video codecs initialization
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 // based on the avifile library [http://divx.euro.ru]
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 int init_audio_codec(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 HRESULT ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 WAVEFORMATEX *in_fmt=(WAVEFORMATEX*)&avi_header.wf_ext;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 unsigned long srcsize=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 if(verbose) printf("======= Win32 (ACM) AUDIO Codec init =======\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 avi_header.srcstream=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 // if(in_fmt->nSamplesPerSec==0){ printf("Bad WAVE header!\n");exit(1); }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 // MSACM_RegisterAllDrivers();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 avi_header.wf.nChannels=in_fmt->nChannels;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 avi_header.wf.nSamplesPerSec=in_fmt->nSamplesPerSec;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 avi_header.wf.nAvgBytesPerSec=2*avi_header.wf.nSamplesPerSec*avi_header.wf.nChannels;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 avi_header.wf.wFormatTag=WAVE_FORMAT_PCM;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 avi_header.wf.nBlockAlign=2*in_fmt->nChannels;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 avi_header.wf.wBitsPerSample=16;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 avi_header.wf.cbSize=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 win32_codec_name = avi_header.audio_codec;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 ret=acmStreamOpen(&avi_header.srcstream,(HACMDRIVER)NULL,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 in_fmt,&avi_header.wf,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 NULL,0,0,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 if(ret){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 if(ret==ACMERR_NOTPOSSIBLE)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 printf("ACM_Decoder: Unappropriate audio format\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 printf("ACM_Decoder: acmStreamOpen error %d", ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 avi_header.srcstream=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 if(verbose) printf("Audio codec opened OK! ;-)\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 srcsize=in_fmt->nBlockAlign;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 acmStreamSize(avi_header.srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_SOURCE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 if(srcsize<OUTBURST) srcsize=OUTBURST;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 avi_header.audio_out_minsize=srcsize; // audio output min. size
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 if(verbose) printf("Audio ACM output buffer min. size: %d\n",srcsize);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 acmStreamSize(avi_header.srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 avi_header.audio_in_minsize=srcsize; // audio input min. size
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 if(verbose) printf("Audio ACM input buffer min. size: %d\n",srcsize);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 int init_video_codec(int outfmt){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 HRESULT ret;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 if(verbose) printf("======= Win32 (VFW) VIDEO Codec init =======\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 memset(&avi_header.o_bih, 0, sizeof(BITMAPINFOHEADER));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 avi_header.o_bih.biSize = sizeof(BITMAPINFOHEADER);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 win32_codec_name = avi_header.video_codec;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 avi_header.hic = ICOpen( 0x63646976, avi_header.bih.biCompression, ICMODE_FASTDECOMPRESS);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 // avi_header.hic = ICOpen( 0x63646976, avi_header.bih.biCompression, ICMODE_DECOMPRESS);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 if(!avi_header.hic){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 printf("ICOpen failed! unknown codec / wrong parameters?\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 // avi_header.bih.biBitCount=32;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 ret = ICDecompressGetFormat(avi_header.hic, &avi_header.bih, &avi_header.o_bih);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 if(ret){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 printf("ICDecompressGetFormat failed: Error %d\n", ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 if(verbose) printf("ICDecompressGetFormat OK\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 // printf("ICM_DECOMPRESS_QUERY=0x%X",ICM_DECOMPRESS_QUERY);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 // avi_header.o_bih.biWidth=avi_header.bih.biWidth;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 // avi_header.o_bih.biCompression = 0x32315659; // mmioFOURCC('U','Y','V','Y');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 // ret=ICDecompressGetFormatSize(avi_header.hic,&avi_header.o_bih);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 // avi_header.o_bih.biCompression = 3; //0x32315659;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 // avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 // avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 // avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 // avi_header.o_bih.biPlanes=3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 // avi_header.o_bih.biBitCount=16;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 if(outfmt==IMGFMT_YUY2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 avi_header.o_bih.biBitCount=16;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 avi_header.o_bih.biBitCount=outfmt&0xFF;// //24;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 avi_header.o_bih.biSizeImage=avi_header.o_bih.biWidth*avi_header.o_bih.biHeight*(avi_header.o_bih.biBitCount/8);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 if(!avi_header.flipped)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 avi_header.o_bih.biHeight=-avi_header.bih.biHeight; // flip image!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 if(outfmt==IMGFMT_YUY2 && !avi_header.yuv_hack_needed)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 // avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 if(verbose) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 printf("Starting decompression, format:\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 printf(" biSize %d\n", avi_header.bih.biSize);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 printf(" biWidth %d\n", avi_header.bih.biWidth);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 printf(" biHeight %d\n", avi_header.bih.biHeight);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 printf(" biPlanes %d\n", avi_header.bih.biPlanes);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 printf(" biBitCount %d\n", avi_header.bih.biBitCount);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 printf(" biCompression %d='%.4s'\n", avi_header.bih.biCompression, &avi_header.bih.biCompression);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 printf(" biSizeImage %d\n", avi_header.bih.biSizeImage);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 printf("Dest fmt:\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 printf(" biSize %d\n", avi_header.o_bih.biSize);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 printf(" biWidth %d\n", avi_header.o_bih.biWidth);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 printf(" biHeight %d\n", avi_header.o_bih.biHeight);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 printf(" biPlanes %d\n", avi_header.o_bih.biPlanes);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 printf(" biBitCount %d\n", avi_header.o_bih.biBitCount);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 printf(" biCompression %d='%.4s'\n", avi_header.o_bih.biCompression, &avi_header.o_bih.biCompression);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 printf(" biSizeImage %d\n", avi_header.o_bih.biSizeImage);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 ret = ICDecompressQuery(avi_header.hic, &avi_header.bih, &avi_header.o_bih);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 if(ret){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 printf("ICDecompressQuery failed: Error %d\n", ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 if(verbose) printf("ICDecompressQuery OK\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 ret = ICDecompressBegin(avi_header.hic, &avi_header.bih, &avi_header.o_bih);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 if(ret){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 printf("ICDecompressBegin failed: Error %d\n", ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 //avi_header.hic
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 //ICSendMessage(HIC hic,unsigned int msg,long lParam1,long lParam2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 { int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 for(i=73;i<256;i++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 printf("Calling ICM_USER+%d function...",i);fflush(stdout);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 ret = ICSendMessage(avi_header.hic,ICM_USER+i,NULL,NULL);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 printf(" ret=%d\n",ret);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 avi_header.our_out_buffer = malloc(avi_header.o_bih.biSizeImage);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 if(!avi_header.our_out_buffer){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 printf("not enough memory for decoded picture buffer (%d bytes)\n", avi_header.o_bih.biSizeImage);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 if(outfmt==IMGFMT_YUY2 && avi_header.yuv_hack_needed)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 // avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 if(verbose) printf("VIDEO CODEC Init OK!!! ;-)\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 }