annotate libao2/ao_dart.c @ 30195:775e8b3e3d0c

sync with en/mplayer.1 r30197
author jrash
date Fri, 08 Jan 2010 11:25:18 +0000
parents 1772a5171ac7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
1 /*
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
2 * OS/2 DART audio output driver
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
3 *
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
4 * Copyright (c) 2007-2009 by KO Myung-Hun (komh@chollian.net)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
5 *
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
6 * This file is part of MPlayer.
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
7 *
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
11 * (at your option) any later version.
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
12 *
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
16 * GNU General Public License for more details.
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
17 *
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License along
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
21 */
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
22
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
23 #define INCL_DOS
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
24 #define INCL_DOSERRORS
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
25 #include <os2.h>
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
26
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
27 #include <stdio.h>
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
28 #include <stdlib.h>
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
29 #include <sys/time.h>
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
30 #include <float.h>
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
31
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
32 #include <dart.h>
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
33
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
34 #include "config.h"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
35 #include "libaf/af_format.h"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
36 #include "audio_out.h"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
37 #include "audio_out_internal.h"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
38 #include "mp_msg.h"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
39 #include "libvo/fastmemcpy.h"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
40 #include "subopt-helper.h"
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
41 #include "libavutil/fifo.h"
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
42
28823
9a5b8c2ed6de Make ao_info_t structs const.
reimar
parents: 28740
diff changeset
43 static const ao_info_t info = {
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
44 "DART audio output",
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
45 "dart",
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
46 "KO Myung-Hun <komh@chollian.net>",
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
47 ""
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
48 };
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
49
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
50 LIBAO_EXTERN(dart)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
51
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
52 #define OUTBURST_SAMPLES 512
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
53 #define DEFAULT_DART_SAMPLES (OUTBURST_SAMPLES << 2)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
54
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
55 #define CHUNK_SIZE ao_data.outburst
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
56
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
57 static AVFifoBuffer *m_audioBuf;
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
58
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
59 static int m_nBufSize = 0;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
60
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
61 static volatile int m_fQuit = FALSE;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
62
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
63 static int write_buffer(unsigned char *data, int len)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
64 {
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
65 int nFree = av_fifo_space(m_audioBuf);
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
66
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
67 if (len > nFree)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
68 len = nFree;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
69
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
70 return av_fifo_generic_write(m_audioBuf, data, len, NULL);
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
71 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
72
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
73 static int read_buffer(unsigned char *data, int len)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
74 {
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
75 int nBuffered = av_fifo_size(m_audioBuf);
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
76
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
77 if (len > nBuffered)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
78 len = nBuffered;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
79
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
80 av_fifo_generic_read(m_audioBuf, data, len, NULL);
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
81 return len;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
82 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
83
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
84 // end ring buffer stuff
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
85
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
86 static ULONG APIENTRY dart_audio_callback(PVOID pCBData, PVOID pBuffer,
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
87 ULONG ulSize)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
88 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
89 int nReadLen;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
90
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
91 nReadLen = read_buffer(pBuffer, ulSize);
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
92 if (nReadLen < ulSize && !m_fQuit) {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
93 memset((uint8_t *)pBuffer + nReadLen, DART.bSilence, ulSize - nReadLen);
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
94 nReadLen = ulSize;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
95 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
96
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
97 return nReadLen;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
98 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
99
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
100 // to set/get/query special features/parameters
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
101 static int control(int cmd, void *arg)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
102 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
103 switch (cmd) {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
104 case AOCONTROL_GET_VOLUME:
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
105 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
106 ao_control_vol_t *vol = arg;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
107
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
108 vol->left = vol->right = LOUSHORT(dartGetVolume());
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
109
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
110 return CONTROL_OK;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
111 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
112
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
113 case AOCONTROL_SET_VOLUME:
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
114 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
115 int mid;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
116 ao_control_vol_t *vol = arg;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
117
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
118 mid = (vol->left + vol->right) / 2;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
119 dartSetVolume(MCI_SET_AUDIO_ALL, mid);
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
120
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
121 return CONTROL_OK;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
122 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
123 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
124
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
125 return CONTROL_UNKNOWN;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
126 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
127
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
128 static void print_help(void)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
129 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
130 mp_msg(MSGT_AO, MSGL_FATAL,
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
131 "\n-ao dart commandline help:\n"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
132 "Example: mplayer -ao dart:noshare\n"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
133 " open DART in exclusive mode\n"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
134 "\nOptions:\n"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
135 " (no)share\n"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
136 " Open DART in shareable or exclusive mode\n"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
137 " bufsize=<size>\n"
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
138 " Set buffer size to <size> in samples(default: 2048)\n");
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
139 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
140
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
141 // open & set up audio device
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
142 // return: 1=success 0=fail
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
143 static int init(int rate, int channels, int format, int flags)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
144 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
145 int fShare = 1;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
146 int nDartSamples = DEFAULT_DART_SAMPLES;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
147 int nBytesPerSample;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
148
29586
2eff450157cd The suboption parser now takes a const options list, so mark them all const.
reimar
parents: 29498
diff changeset
149 const opt_t subopts[] = {
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
150 {"share", OPT_ARG_BOOL, &fShare, NULL},
30122
1772a5171ac7 Fix function declarations to avoid casting function pointers.
reimar
parents: 29586
diff changeset
151 {"bufsize", OPT_ARG_INT, &nDartSamples, int_non_neg},
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
152 {NULL}
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
153 };
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
154
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
155 if (subopt_parse(ao_subdevice, subopts) != 0) {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
156 print_help();
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
157 return 0;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
158 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
159
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
160 if (!nDartSamples)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
161 nDartSamples = DEFAULT_DART_SAMPLES;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
162
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
163 mp_msg(MSGT_AO, MSGL_V, "DART: opened in %s mode, buffer size = %d sample(s)\n",
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
164 fShare ? "shareable" : "exclusive", nDartSamples);
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
165
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
166 switch (format) {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
167 case AF_FORMAT_S16_LE:
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
168 case AF_FORMAT_S8:
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
169 break;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
170
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
171 default:
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
172 format = AF_FORMAT_S16_LE;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
173 mp_msg(MSGT_AO, MSGL_V, "DART: format %s not supported defaulting to Signed 16-bit Little-Endian\n",
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
174 af_fmt2str_short(format));
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
175 break;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
176 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
177
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
178 nBytesPerSample = (af_fmt2bits(format) >> 3) * channels;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
179
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
180 if (dartInit(0, af_fmt2bits(format), rate, MCI_WAVE_FORMAT_PCM, channels,
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
181 2, nBytesPerSample * nDartSamples, fShare,
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
182 dart_audio_callback, NULL))
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
183 return 0;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
184
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
185 mp_msg(MSGT_AO, MSGL_V, "DART: obtained buffer size = %lu bytes\n",
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
186 DART.ulBufferSize);
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
187
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
188 m_fQuit = FALSE;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
189
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
190 ao_data.channels = channels;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
191 ao_data.samplerate = rate;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
192 ao_data.format = format;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
193 ao_data.bps = nBytesPerSample * rate;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
194 ao_data.outburst = nBytesPerSample * OUTBURST_SAMPLES;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
195 ao_data.buffersize = DART.ulBufferSize;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
196
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
197 // multiple of CHUNK_SIZE
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
198 m_nBufSize = ((DART.ulBufferSize << 2) / CHUNK_SIZE) * CHUNK_SIZE;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
199 // and one more chunk plus round up
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
200 m_nBufSize += 2 * CHUNK_SIZE;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
201
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
202 m_audioBuf = av_fifo_alloc(m_nBufSize);
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
203
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
204 dartPlay();
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
205
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
206 // might cause PM DLLs to be loaded which incorrectly enable SIG_FPE,
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
207 // which AAC decoding might trigger.
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
208 // so, mask off all floating-point exceptions.
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
209 _control87(MCW_EM, MCW_EM);
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
210
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
211 return 1;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
212 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
213
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
214 // close audio device
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
215 static void uninit(int immed)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
216 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
217 m_fQuit = TRUE;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
218
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
219 if (!immed) {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
220 while (DART.fPlaying)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
221 DosSleep(1);
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
222 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
223
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
224 dartClose();
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
225
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
226 av_fifo_free(m_audioBuf);
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
227 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
228
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
229 // stop playing and empty buffers (for seeking/pause)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
230 static void reset(void)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
231 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
232 dartPause();
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
233
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
234 // Reset ring-buffer state
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
235 av_fifo_reset(m_audioBuf);
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
236
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
237 dartResume();
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
238 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
239
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
240 // stop playing, keep buffers (for pause)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
241 static void audio_pause(void)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
242 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
243 dartPause();
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
244 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
245
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
246 // resume playing, after audio_pause()
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
247 static void audio_resume(void)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
248 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
249 dartResume();
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
250 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
251
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
252 // return: how many bytes can be played without blocking
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
253 static int get_space(void)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
254 {
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
255 return av_fifo_space(m_audioBuf);
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
256 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
257
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
258 // plays 'len' bytes of 'data'
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
259 // it should round it down to outburst*n
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
260 // return: number of bytes played
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
261 static int play(void *data, int len, int flags)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
262 {
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
263
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
264 if (!(flags & AOPLAY_FINAL_CHUNK))
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
265 len = (len / ao_data.outburst) * ao_data.outburst;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
266
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
267 return write_buffer(data, len);
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
268 }
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
269
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
270 // return: delay in seconds between first and last sample in buffer
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
271 static float get_delay(void)
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
272 {
29498
c4fe7474709d Change ao_dart to use AVFifoBuffer instead of its own fifo implementation, too.
reimar
parents: 28823
diff changeset
273 int nBuffered = av_fifo_size(m_audioBuf); // could be less
28740
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
274
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
275 return (float)nBuffered / (float)ao_data.bps;
1f76d86e49ae DART audio output driver for OS/2 by KO Myung-Hun, komh chollian net
diego
parents:
diff changeset
276 }