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