annotate libao2/ao_kai.c @ 35627:51358e7bde85

Cosmetic: Add and adjust comments.
author ib
date Thu, 10 Jan 2013 10:48:27 +0000
parents d50e20b4e441
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30439
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
1 /*
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
2 * OS/2 KAI audio output driver
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
3 *
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
4 * Copyright (c) 2010 by KO Myung-Hun (komh@chollian.net)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
5 *
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
6 * This file is part of MPlayer.
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
7 *
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
11 * (at your option) any later version.
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
12 *
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
16 * GNU General Public License for more details.
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
17 *
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License along
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
21 */
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
22
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
23 #define INCL_DOS
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
24 #define INCL_DOSERRORS
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
25 #include <os2.h>
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
26
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
27 #include <stdio.h>
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
28 #include <stdlib.h>
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
29 #include <sys/time.h>
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
30 #include <float.h>
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
31
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
32 #include <kai.h>
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
33
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
34 #include "config.h"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
35 #include "libaf/af_format.h"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
36 #include "audio_out.h"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
37 #include "audio_out_internal.h"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
38 #include "mp_msg.h"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
39 #include "libvo/fastmemcpy.h"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
40 #include "subopt-helper.h"
30839
d50e20b4e441 Include libavutil/avutil.h for FFMIN
komh
parents: 30460
diff changeset
41 #include "libavutil/avutil.h"
30439
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
42 #include "libavutil/fifo.h"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
43
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
44 static const ao_info_t info = {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
45 "KAI audio output",
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
46 "kai",
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
47 "KO Myung-Hun <komh@chollian.net>",
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
48 ""
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
49 };
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
50
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
51 LIBAO_EXTERN(kai)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
52
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
53 #define OUTBURST_SAMPLES 512
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
54 #define DEFAULT_SAMPLES (OUTBURST_SAMPLES << 2)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
55
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
56 #define CHUNK_SIZE ao_data.outburst
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
57
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
58 static AVFifoBuffer *m_audioBuf;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
59
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
60 static int m_nBufSize = 0;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
61
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
62 static volatile int m_fQuit = FALSE;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
63
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
64 static KAISPEC m_kaiSpec;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
65
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
66 static HKAI m_hkai;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
67
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
68 static int write_buffer(unsigned char *data, int len)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
69 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
70 int nFree = av_fifo_space(m_audioBuf);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
71
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
72 len = FFMIN(len, nFree);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
73
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
74 return av_fifo_generic_write(m_audioBuf, data, len, NULL);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
75 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
76
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
77 static int read_buffer(unsigned char *data, int len)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
78 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
79 int nBuffered = av_fifo_size(m_audioBuf);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
80
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
81 len = FFMIN(len, nBuffered);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
82
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
83 av_fifo_generic_read(m_audioBuf, data, len, NULL);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
84 return len;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
85 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
86
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
87 // end ring buffer stuff
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
88
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
89 static ULONG APIENTRY kai_audio_callback(PVOID pCBData, PVOID pBuffer,
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
90 ULONG ulSize)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
91 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
92 int nReadLen;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
93
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
94 nReadLen = read_buffer(pBuffer, ulSize);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
95 if (nReadLen < ulSize && !m_fQuit) {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
96 memset((uint8_t *)pBuffer + nReadLen, m_kaiSpec.bSilence, ulSize - nReadLen);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
97 nReadLen = ulSize;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
98 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
99
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
100 return nReadLen;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
101 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
102
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
103 // to set/get/query special features/parameters
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
104 static int control(int cmd, void *arg)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
105 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
106 switch (cmd) {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
107 case AOCONTROL_GET_VOLUME:
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
108 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
109 ao_control_vol_t *vol = arg;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
110
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
111 vol->left = vol->right = kaiGetVolume(m_hkai, MCI_STATUS_AUDIO_ALL);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
112
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
113 return CONTROL_OK;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
114 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
115
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
116 case AOCONTROL_SET_VOLUME:
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
117 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
118 int mid;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
119 ao_control_vol_t *vol = arg;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
120
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
121 mid = (vol->left + vol->right) / 2;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
122 kaiSetVolume(m_hkai, MCI_SET_AUDIO_ALL, mid);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
123
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
124 return CONTROL_OK;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
125 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
126 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
127
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
128 return CONTROL_UNKNOWN;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
129 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
130
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
131 static void print_help(void)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
132 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
133 mp_msg(MSGT_AO, MSGL_FATAL,
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
134 "\n-ao kai commandline help:\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
135 "Example: mplayer -ao kai:noshare\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
136 " open audio in exclusive mode\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
137 "\nOptions:\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
138 " uniaud\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
139 " Use UNIAUD audio driver\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
140 " dart\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
141 " Use DART audio driver\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
142 " (no)share\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
143 " Open audio in shareable or exclusive mode\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
144 " bufsize=<size>\n"
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
145 " Set buffer size to <size> in samples(default: 2048)\n");
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
146 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
147
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
148 // open & set up audio device
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
149 // return: 1=success 0=fail
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
150 static int init(int rate, int channels, int format, int flags)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
151 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
152 int fUseUniaud = 0;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
153 int fUseDart = 0;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
154 int fShare = 1;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
155 ULONG kaiMode;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
156 KAICAPS kc;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
157 int nSamples = DEFAULT_SAMPLES;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
158 int nBytesPerSample;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
159 KAISPEC ksWanted;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
160
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
161 const opt_t subopts[] = {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
162 {"uniaud", OPT_ARG_BOOL, &fUseUniaud, NULL},
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
163 {"dart", OPT_ARG_BOOL, &fUseDart, NULL},
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
164 {"share", OPT_ARG_BOOL, &fShare, NULL},
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
165 {"bufsize", OPT_ARG_INT, &nSamples, int_non_neg},
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
166 {NULL}
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
167 };
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
168
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
169 const char *audioDriver[] = {"DART", "UNIAUD",};
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
170
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
171 if (subopt_parse(ao_subdevice, subopts) != 0) {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
172 print_help();
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
173 return 0;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
174 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
175
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
176 if (fUseUniaud && fUseDart)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
177 mp_msg(MSGT_VO, MSGL_WARN,"KAI: Multiple mode specified!!!\n");
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
178
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
179 if (fUseUniaud)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
180 kaiMode = KAIM_UNIAUD;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
181 else if (fUseDart)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
182 kaiMode = KAIM_DART;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
183 else
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
184 kaiMode = KAIM_AUTO;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
185
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
186 if (kaiInit(kaiMode)) {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
187 mp_msg(MSGT_VO, MSGL_ERR, "KAI: Init failed!!!\n");
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
188 return 0;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
189 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
190
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
191 kaiCaps(&kc);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
192 mp_msg(MSGT_AO, MSGL_V, "KAI: selected audio driver = %s\n",
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
193 audioDriver[kc.ulMode - 1]);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
194 mp_msg(MSGT_AO, MSGL_V, "KAI: PDD name = %s, maximum channels = %lu\n",
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
195 kc.szPDDName, kc.ulMaxChannels);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
196
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
197 if (!nSamples)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
198 nSamples = DEFAULT_SAMPLES;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
199
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
200 mp_msg(MSGT_AO, MSGL_V, "KAI: open in %s mode, buffer size = %d sample(s)\n",
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
201 fShare ? "shareable" : "exclusive", nSamples);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
202
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
203 switch (format) {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
204 case AF_FORMAT_S16_LE:
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
205 case AF_FORMAT_S8:
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
206 break;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
207
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
208 default:
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
209 format = AF_FORMAT_S16_LE;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
210 mp_msg(MSGT_AO, MSGL_V, "KAI: format %s not supported defaulting to Signed 16-bit Little-Endian\n",
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
211 af_fmt2str_short(format));
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
212 break;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
213 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
214
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
215 nBytesPerSample = (af_fmt2bits(format) >> 3) * channels;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
216
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
217 ksWanted.usDeviceIndex = 0;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
218 ksWanted.ulType = KAIT_PLAY;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
219 ksWanted.ulBitsPerSample = af_fmt2bits(format);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
220 ksWanted.ulSamplingRate = rate;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
221 ksWanted.ulDataFormat = MCI_WAVE_FORMAT_PCM;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
222 ksWanted.ulChannels = channels;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
223 ksWanted.ulNumBuffers = 2;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
224 ksWanted.ulBufferSize = nBytesPerSample * nSamples;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
225 ksWanted.fShareable = fShare;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
226 ksWanted.pfnCallBack = kai_audio_callback;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
227 ksWanted.pCallBackData = NULL;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
228
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
229 if (kaiOpen(&ksWanted, &m_kaiSpec, &m_hkai)) {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
230 mp_msg(MSGT_VO, MSGL_ERR, "KAI: Open failed!!!\n");
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
231 return 0;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
232 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
233
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
234 mp_msg(MSGT_AO, MSGL_V, "KAI: obtained buffer count = %lu, size = %lu bytes\n",
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
235 m_kaiSpec.ulNumBuffers, m_kaiSpec.ulBufferSize);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
236
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
237 m_fQuit = FALSE;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
238
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
239 ao_data.channels = channels;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
240 ao_data.samplerate = rate;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
241 ao_data.format = format;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
242 ao_data.bps = nBytesPerSample * rate;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
243 ao_data.outburst = nBytesPerSample * OUTBURST_SAMPLES;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
244 ao_data.buffersize = m_kaiSpec.ulBufferSize;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
245
30460
2675229bd06f Audio buffer is too large so that it takes too long time to respond to audio
komh
parents: 30439
diff changeset
246 m_nBufSize = (m_kaiSpec.ulBufferSize * m_kaiSpec.ulNumBuffers) << 2;
30439
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
247
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
248 // multiple of CHUNK_SIZE
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
249 m_nBufSize = (m_nBufSize / CHUNK_SIZE) * CHUNK_SIZE;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
250
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
251 // and one more chunk plus round up
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
252 m_nBufSize += 2 * CHUNK_SIZE;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
253
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
254 mp_msg(MSGT_AO, MSGL_V, "KAI: internal audio buffer size = %d bytes\n",
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
255 m_nBufSize);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
256
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
257 m_audioBuf = av_fifo_alloc(m_nBufSize);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
258
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
259 kaiPlay(m_hkai);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
260
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
261 // might cause PM DLLs to be loaded which incorrectly enable SIG_FPE,
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
262 // which AAC decoding might trigger.
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
263 // so, mask off all floating-point exceptions.
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
264 _control87(MCW_EM, MCW_EM);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
265
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
266 return 1;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
267 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
268
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
269 // close audio device
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
270 static void uninit(int immed)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
271 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
272 m_fQuit = TRUE;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
273
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
274 if (!immed)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
275 while (kaiStatus(m_hkai) & KAIS_PLAYING)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
276 DosSleep(1);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
277
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
278 kaiClose(m_hkai);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
279
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
280 kaiDone();
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
281
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
282 av_fifo_free(m_audioBuf);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
283 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
284
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
285 // stop playing and empty buffers (for seeking/pause)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
286 static void reset(void)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
287 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
288 kaiPause(m_hkai);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
289
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
290 // Reset ring-buffer state
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
291 av_fifo_reset(m_audioBuf);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
292
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
293 kaiResume(m_hkai);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
294 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
295
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
296 // stop playing, keep buffers (for pause)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
297 static void audio_pause(void)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
298 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
299 kaiPause(m_hkai);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
300 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
301
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
302 // resume playing, after audio_pause()
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
303 static void audio_resume(void)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
304 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
305 kaiResume(m_hkai);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
306 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
307
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
308 // return: how many bytes can be played without blocking
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
309 static int get_space(void)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
310 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
311 return av_fifo_space(m_audioBuf);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
312 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
313
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
314 // plays 'len' bytes of 'data'
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
315 // it should round it down to outburst*n
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
316 // return: number of bytes played
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
317 static int play(void *data, int len, int flags)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
318 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
319
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
320 if (!(flags & AOPLAY_FINAL_CHUNK))
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
321 len = (len / ao_data.outburst) * ao_data.outburst;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
322
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
323 return write_buffer(data, len);
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
324 }
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
325
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
326 // return: delay in seconds between first and last sample in buffer
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
327 static float get_delay(void)
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
328 {
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
329 int nBuffered = av_fifo_size(m_audioBuf); // could be less
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
330
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
331 return (float)nBuffered / (float)ao_data.bps;
2118e8876a2b Add OS/2 KAI audio driver support
komh
parents:
diff changeset
332 }