Closed SilvanScherrer closed 9 years ago
if possible we should make that for beta 2 already. As right now java eats all sounds here. With libkai it might work again.
Its a good idea however the uniaud api is broken on the the latest uniaud builds.
According to the uniaud dev he is not aware of any defect with the latest uniaud. If you have a proof that it's broken, add a ticket to the uniaud trac.
Probably ticket 191 is the one being referred to, at least that is the one that I have seen. https://trac.netlabs.org/uniaud/ticket/191 It may be fixed by the patch in 231, I'll need to build and test. https://trac.netlabs.org/uniaud/ticket/231
The case seems a bit more difficult. According to David the source at netlabs is not what he delivers. His comment on my question: {{{ No, the netlabs uniaud svn is not up-to-date, and it is not even complete. I realize that I need to get the repository organized and get my stuff checked in. If my sources were simply checked out from the netlabs svn and modified, it would be easy to just check in what I have, but they are not. I probably have the only complete up-to-date set of sources that I gathered from many different places. It will take time to get everything organized and checked in. Just another item on my to-do list. }}}
I'll try to implement audio parts with libkai.
What are build envs and build tools ?
And how to build ?
https://github.com/bitwiseworks/mozilla-os2/issues/82 describes the problems I had building 24esr (31 is still too unstable to use). Big one is Python where I never could use Paul's build due to virtualenv problems and had to use the RPM/YUM build (along with the whole environment). Also see https://github.com/bitwiseworks/mozilla-os2/issues/70.
@komh that sounds really promising! Here are the instructions but they are for the RPM environment (as this is what I personally use), sorry: https://github.com/bitwiseworks/mozilla-os2/wiki/Developers#building-from-sources.
@dryeo @dmik thanks a lot. I'll try soon. ^^
configure fails. Any idea ?
loading cache ./config.cache
checking for path separator... ;
checking for Cygwin environment... no
checking for mingw32 environment... no
checking for EMX/OS2 environment... yes
checking for executable suffix... .exe
checking host system type... i386-pc-os2-emx
checking target system type... i386-pc-os2-emx
checking build system type... i386-pc-os2-emx
checking for mawk... no
checking for gawk... gawk
checking for python2.7... g:/usr/bin/python2.7.exe
Creating Python environment
New python executable in G:/lang/work/mozilla/mozilla-os2.git/obj-ff/_virtualenv/bin/python2.7.exe
Not overwriting existing python script G:/lang/work/mozilla/mozilla-os2.git/obj-ff/_virtualenv/bin/python.exe (you must use G:/lang/work/mozilla/mozilla-os2.git/obj-ff/_virtualenv/bin/python2.7.exe)
Installing setuptools, pip...
Complete output from command G:/lang/work/mozilla...nv/bin/python2.7.exe -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/__init__.py", line 9, in <module>
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/log.py", line 9, in <module>
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/_vendor/colorama/__init__.py", line 2, in <module>
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/_vendor/colorama/initialise.py", line 5, in <module>
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/_vendor/colorama/ansitowin32.py", line 6, in <module>
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/_vendor/colorama/winterm.py", line 2, in <module>
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv_support/pip-1.5.4-py2.py3-none-any.whl/pip/_vendor/colorama/win32.py", line 8, in <module>
File "g:/usr/lib/python2.7/ctypes/__init__.py", line 453, in <module>
pythonapi = PyDLL(None)
File "g:/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
NameError: global name '_dlopen' is not defined
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv.py", line 2339, in <module>
main()
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv.py", line 825, in main
symlink=options.symlink)
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv.py", line 993, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv.py", line 961, in install_wheel
'PIP_NO_INDEX': '1'
File "G:/lang/work/mozilla/mozilla-os2.git/python/virtualenv/virtualenv.py", line 903, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command G:/lang/work/mozilla...nv/bin/python2.7.exe -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
Traceback (most recent call last):
File "G:/lang/work/mozilla/mozilla-os2.git/python/mozbuild/mozbuild/virtualenv.py", line 473, in <module>
manager.ensure()
File "G:/lang/work/mozilla/mozilla-os2.git/python/mozbuild/mozbuild/virtualenv.py", line 128, in ensure
return self.build()
File "G:/lang/work/mozilla/mozilla-os2.git/python/mozbuild/mozbuild/virtualenv.py", line 371, in build
self.create()
File "G:/lang/work/mozilla/mozilla-os2.git/python/mozbuild/mozbuild/virtualenv.py", line 147, in create
raise Exception('Error creating virtualenv.')
Exception: Error creating virtualenv.
------ config.log ------
#ifndef __CYGWIN__
#define __CYGWIN__ __CYGWIN32__
#endif
return __CYGWIN__;
; return 0; }
configure:1215: checking for mingw32 environment
configure:1227: cc -c -march=i486 -mtune=i686 -idirafter f:/lang/os2tk45/h conftest.c 1>&5
cc: not found
configure: failed program was:
#line 1220 "configure"
#include "confdefs.h"
int main() {
return __MINGW32__;
; return 0; }
configure:1244: checking for EMX/OS2 environment
configure:1257: gcc.exe -c -march=i486 -mtune=i686 -idirafter f:/lang/os2tk45/h conftest.c 1>&5
configure:1288: checking for executable suffix
configure:1366: checking host system type
configure:1387: checking target system type
configure:1405: checking build system type
configure:1480: checking for mawk
configure:1480: checking for gawk
configure:1566: checking for python2.7
On 06/12/15 09:17 PM, KO Myung-Hun wrote:
configure fails. Any idea ?
Python needs patching, from issue#100,
--- __init__.py.b 2015-02-26 21:23:20.000000000 +0400
+++ __init__.py 2015-04-23 21:55:04.000000000 +0400
@@ -140,6 +140,10 @@
elif _os.name == "posix":
from _ctypes import dlopen as _dlopen
+elif _os.name == "os2":
+ def _dlopen(name, mode):
+ return
+
from _ctypes import sizeof, byref, addressof, alignment, resize
from _ctypes import get_errno, set_errno
from _ctypes import _SimpleCData
For 31ESR, read issue 100 Dave
@dryeo thanks, Dave!!!
I've ported libcubeb itself. However, I'm failing to build FF due to random TRAP 8 when bulding it. Sucks!. So I could not test it worked in FF. Especially, mozilla build system. Here is the patch. Test, please.
From d5fc88b462272cb84b942ff7d7d68df3e0b3438d Mon Sep 17 00:00:00 2001
From: KO Myung-Hun <komh@chollian.net>
Date: Thu, 18 Jun 2015 09:59:02 +0900
Subject: [PATCH] [OS/2] libcubeb: add OS/2 KAI support
---
configure.in | 2 +-
media/libcubeb/src/cubeb.c | 6 +
media/libcubeb/src/cubeb_kai.c | 288 +++++++++++++++++++++++++++++++++++++++++
media/libcubeb/src/moz.build | 6 +
4 files changed, 301 insertions(+), 1 deletion(-)
create mode 100644 media/libcubeb/src/cubeb_kai.c
diff --git a/configure.in b/configure.in
index 0c61ca4..08c8b58 100644
--- a/configure.in
+++ b/configure.in
@@ -4447,7 +4447,7 @@ cairo-os2)
MOZ_WIDGET_TOOLKIT=os2
USE_FC_FREETYPE=1
TK_CFLAGS='$(MOZ_CAIRO_CFLAGS) $(MOZ_PIXMAN_CFLAGS)'
- TK_LIBS='$(MOZ_CAIRO_LIBS) $(MOZ_PIXMAN_LIBS)'
+ TK_LIBS='$(MOZ_CAIRO_LIBS) $(MOZ_PIXMAN_LIBS) -lkai'
MOZ_PDF_PRINTING=1
;;
diff --git a/media/libcubeb/src/cubeb.c b/media/libcubeb/src/cubeb.c
index 3d8347d..11d1efa 100644
--- a/media/libcubeb/src/cubeb.c
+++ b/media/libcubeb/src/cubeb.c
@@ -54,6 +54,9 @@ int opensl_init(cubeb ** context, char const * context_name);
#if defined(USE_AUDIOTRACK)
int audiotrack_init(cubeb ** context, char const * context_name);
#endif
+#if defined(USE_KAI)
+int kai_init(cubeb ** context, char const * context_name);
+#endif
int
validate_stream_params(cubeb_stream_params stream_params)
@@ -120,6 +123,9 @@ cubeb_init(cubeb ** context, char const * context_name)
#if defined(USE_AUDIOTRACK)
audiotrack_init,
#endif
+#if defined(USE_KAI)
+ kai_init,
+#endif
};
int i;
diff --git a/media/libcubeb/src/cubeb_kai.c b/media/libcubeb/src/cubeb_kai.c
new file mode 100644
index 0000000..787820d
--- /dev/null
+++ b/media/libcubeb/src/cubeb_kai.c
@@ -0,0 +1,288 @@
+/*
+ * Copyright 짤 2015 Mozilla Foundation
+ *
+ * This program is made available under an ISC-style license. See the
+ * accompanying file LICENSE for details.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <sys/fmutex.h>
+
+#include <kai.h>
+
+#include "cubeb/cubeb.h"
+#include "cubeb-internal.h"
+
+#define NBUFS 2
+#define FRAME_SIZE 2048
+
+struct cubeb_stream_item {
+ cubeb_stream * stream;
+};
+
+static struct cubeb_ops const kai_ops;
+
+struct cubeb {
+ struct cubeb_ops const * ops;
+};
+
+struct cubeb_stream {
+ cubeb * context;
+ cubeb_stream_params params;
+ cubeb_data_callback data_callback;
+ cubeb_state_callback state_callback;
+ void * user_ptr;
+
+ HKAI hkai;
+ KAISPEC spec;
+ uint64_t total_frames;
+ _fmutex mutex;
+};
+
+static inline long
+frames_to_bytes(long frames, int channels)
+{
+ return frames * 2 * channels; /* 2 bytes per frame */
+}
+
+static inline long
+bytes_to_frames(long bytes, int channels)
+{
+ return bytes / 2 / channels; /* 2 bytes per frame */
+}
+
+static void kai_destroy(cubeb * ctx);
+
+/*static*/ int
+kai_init(cubeb ** context, char const * context_name)
+{
+ cubeb * ctx;
+
+ XASSERT(context);
+ *context = NULL;
+
+ if (kaiInit(KAIM_AUTO))
+ return CUBEB_ERROR;
+
+ ctx = calloc(1, sizeof(*ctx));
+ XASSERT(ctx);
+
+ ctx->ops = &kai_ops;
+
+ *context = ctx;
+
+ return CUBEB_OK;
+}
+
+static char const *
+kai_get_backend_id(cubeb * ctx)
+{
+ return "kai";
+}
+
+static void
+kai_destroy(cubeb * ctx)
+{
+ kaiDone();
+
+ free(ctx);
+}
+
+static ULONG APIENTRY
+kai_callback(PVOID cbdata, PVOID buffer, ULONG len)
+{
+ cubeb_stream * stm = cbdata;
+ long wanted_frames;
+ long frames;
+
+ wanted_frames = bytes_to_frames(len, stm->params.channels);
+ frames = stm->data_callback(stm, stm->user_ptr, buffer, wanted_frames);
+
+ _fmutex_request(&stm->mutex, 0);
+ stm->total_frames += frames;
+ _fmutex_release(&stm->mutex);
+
+ if (frames < wanted_frames)
+ stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_DRAINED);
+
+ return frames_to_bytes(frames, stm->params.channels);
+}
+
+static void kai_stream_destroy(cubeb_stream * stm);
+
+static int
+kai_stream_init(cubeb * context, cubeb_stream ** stream,
+ char const * stream_name, cubeb_stream_params stream_params,
+ unsigned int latency, cubeb_data_callback data_callback,
+ cubeb_state_callback state_callback, void * user_ptr)
+{
+ cubeb_stream * stm;
+ KAISPEC wanted_spec;
+
+ if (stream_params.format != CUBEB_SAMPLE_S16NE ||
+ stream_params.channels > 2) {
+ return CUBEB_ERROR_INVALID_FORMAT;
+ }
+
+ XASSERT(context);
+ XASSERT(stream);
+
+ *stream = NULL;
+
+ stm = calloc(1, sizeof(*stm));
+ XASSERT(stm);
+
+ stm->context = context;
+ stm->params = stream_params;
+ stm->data_callback = data_callback;
+ stm->state_callback = state_callback;
+ stm->user_ptr = user_ptr;
+
+ if (_fmutex_create(&stm->mutex, 0)) {
+ free(stm);
+ return CUBEB_ERROR;
+ }
+
+ wanted_spec.usDeviceIndex = 0;
+ wanted_spec.ulType = KAIT_PLAY;
+ wanted_spec.ulBitsPerSample = BPS_16;
+ wanted_spec.ulSamplingRate = stm->params.rate;
+ wanted_spec.ulDataFormat = MCI_WAVE_FORMAT_PCM;
+ wanted_spec.ulChannels = stm->params.channels;
+ wanted_spec.ulNumBuffers = NBUFS;
+ wanted_spec.ulBufferSize = frames_to_bytes(FRAME_SIZE,
+ stm->params.channels);
+ wanted_spec.fShareable = TRUE;
+ wanted_spec.pfnCallBack = kai_callback;
+ wanted_spec.pCallBackData = stm;
+
+ if (kaiOpen(&wanted_spec, &stm->spec, &stm->hkai)) {
+ _fmutex_close(&stm->mutex);
+ free(stm);
+ return CUBEB_ERROR;
+ }
+
+ *stream = stm;
+
+ return CUBEB_OK;
+}
+
+static void
+kai_stream_destroy(cubeb_stream * stm)
+{
+ kaiClose(stm->hkai);
+ _fmutex_close(&stm->mutex);
+ free(stm);
+}
+
+static int
+kai_get_max_channel_count(cubeb * ctx, uint32_t * max_channels)
+{
+ XASSERT(ctx && max_channels);
+
+ /* We don't support more than two channels in KAI. */
+ *max_channels = 2;
+
+ return CUBEB_OK;
+}
+
+static int
+kai_get_min_latency(cubeb * ctx, cubeb_stream_params params, uint32_t * latency)
+{
+ /* We have at least two buffers. One is being played, the other one is being
+ filled. So there is as much latency as one buffer. */
+ *latency = FRAME_SIZE * 1000 / params.rate;
+
+ return CUBEB_OK;
+}
+
+static int
+kai_get_preferred_sample_rate(cubeb * ctx, uint32_t * rate)
+{
+ KAISPEC wanted_spec;
+ KAISPEC spec;
+ HKAI hkai;
+
+ *rate = 48000;
+
+ wanted_spec.usDeviceIndex = 0;
+ wanted_spec.ulType = KAIT_PLAY;
+ wanted_spec.ulBitsPerSample = BPS_16;
+ wanted_spec.ulSamplingRate = *rate;
+ wanted_spec.ulDataFormat = MCI_WAVE_FORMAT_PCM;
+ wanted_spec.ulChannels = 2;
+ wanted_spec.ulNumBuffers = 2;
+ wanted_spec.ulBufferSize = frames_to_bytes(FRAME_SIZE, 2);
+ wanted_spec.fShareable = TRUE;
+ wanted_spec.pfnCallBack = kai_callback;
+ wanted_spec.pCallBackData = NULL;
+
+ /* Test 48KHz */
+ if (kaiOpen(&wanted_spec, &spec, &hkai)) {
+ /* Not supported. Fall back to 44.1KHz */
+ *rate = 44100;
+ } else {
+ /* Supported. Use 48KHz */
+ kaiClose(hkai);
+ }
+
+ return CUBEB_OK;
+}
+
+static int
+kai_stream_start(cubeb_stream * stm)
+{
+ if (kaiPlay(stm->hkai))
+ return CUBEB_ERROR;
+
+ stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STARTED);
+
+ return CUBEB_OK;
+}
+
+static int
+kai_stream_stop(cubeb_stream * stm)
+{
+ if (kaiStop(stm->hkai))
+ return CUBEB_ERROR;
+
+ stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STOPPED);
+
+ return CUBEB_OK;
+}
+
+static int
+kai_stream_get_position(cubeb_stream * stm, uint64_t * position)
+{
+ _fmutex_request(&stm->mutex, 0);
+ *position = stm->total_frames;
+ _fmutex_release(&stm->mutex);
+
+ return CUBEB_OK;
+}
+
+static int
+kai_stream_get_latency(cubeb_stream * stm, uint32_t * latency)
+{
+ /* Out of buffers, one is being played, the others are being filled.
+ So there is as much latency as total buffers - 1. */
+ *latency = bytes_to_frames(stm->spec.ulBufferSize, stm->params.channels)
+ * (stm->spec.ulNumBuffers - 1);
+
+ return CUBEB_OK;
+}
+
+static struct cubeb_ops const kai_ops = {
+ .init = kai_init,
+ .get_backend_id = kai_get_backend_id,
+ .get_max_channel_count= kai_get_max_channel_count,
+ .get_min_latency= kai_get_min_latency,
+ .get_preferred_sample_rate = kai_get_preferred_sample_rate,
+ .destroy = kai_destroy,
+ .stream_init = kai_stream_init,
+ .stream_destroy = kai_stream_destroy,
+ .stream_start = kai_stream_start,
+ .stream_stop = kai_stream_stop,
+ .stream_get_position = kai_stream_get_position,
+ .stream_get_latency = kai_stream_get_latency,
+};
diff --git a/media/libcubeb/src/moz.build b/media/libcubeb/src/moz.build
index 64a6146..b2b96cd 100644
--- a/media/libcubeb/src/moz.build
+++ b/media/libcubeb/src/moz.build
@@ -54,6 +54,12 @@ if CONFIG['OS_TARGET'] == 'Android':
]
DEFINES['USE_AUDIOTRACK'] = True
+if CONFIG['OS_TARGET'] == 'OS/2':
+ SOURCES += [
+ 'cubeb_kai.c',
+ ]
+ DEFINES['USE_KAI'] = True
+
MSVC_ENABLE_PGO = True
if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
--
1.9.5
Great news! I will test it ASAP (after I sort out the remains of #100).
Now, I can hear sounds. ^^
However, the above patch was wrong. First, FF seems to uses only FLOAT32 PCM format not S16 PCM format. Second, build patch does not work. -lkai shoud be append in toolkit/library.
I get a missing symbol for _XASSERT
As I said above, the above patch was wrong.
Here is the complete patch.
From c6529e2ab91d648870f321ecb0149e5d99fe0c69 Mon Sep 17 00:00:00 2001
From: KO Myung-Hun <komh@chollian.net>
Date: Thu, 18 Jun 2015 09:59:02 +0900
Subject: [PATCH] [OS/2] libcubeb: add OS/2 KAI support
---
media/libcubeb/src/cubeb.c | 6 +
media/libcubeb/src/cubeb_kai.c | 317 ++++++++++++++++++++++++++++++++++++++++
media/libcubeb/src/moz.build | 6 +
toolkit/library/libxul.mozbuild | 1 +
4 files changed, 330 insertions(+)
create mode 100644 media/libcubeb/src/cubeb_kai.c
diff --git a/media/libcubeb/src/cubeb.c b/media/libcubeb/src/cubeb.c
index 3d8347d..11d1efa 100644
--- a/media/libcubeb/src/cubeb.c
+++ b/media/libcubeb/src/cubeb.c
@@ -54,6 +54,9 @@ int opensl_init(cubeb ** context, char const * context_name);
#if defined(USE_AUDIOTRACK)
int audiotrack_init(cubeb ** context, char const * context_name);
#endif
+#if defined(USE_KAI)
+int kai_init(cubeb ** context, char const * context_name);
+#endif
int
validate_stream_params(cubeb_stream_params stream_params)
@@ -120,6 +123,9 @@ cubeb_init(cubeb ** context, char const * context_name)
#if defined(USE_AUDIOTRACK)
audiotrack_init,
#endif
+#if defined(USE_KAI)
+ kai_init,
+#endif
};
int i;
diff --git a/media/libcubeb/src/cubeb_kai.c b/media/libcubeb/src/cubeb_kai.c
new file mode 100644
index 0000000..7c1b7b4
--- /dev/null
+++ b/media/libcubeb/src/cubeb_kai.c
@@ -0,0 +1,317 @@
+/*
+ * Copyright 짤 2015 Mozilla Foundation
+ *
+ * This program is made available under an ISC-style license. See the
+ * accompanying file LICENSE for details.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+#include <sys/fmutex.h>
+
+#include <kai.h>
+
+#include "cubeb/cubeb.h"
+#include "cubeb-internal.h"
+
+/* We don't support more than 2 channels in KAI */
+#define MAX_CHANNELS 2
+
+#define NBUFS 2
+#define FRAME_SIZE 2048
+
+struct cubeb_stream_item {
+ cubeb_stream * stream;
+};
+
+static struct cubeb_ops const kai_ops;
+
+struct cubeb {
+ struct cubeb_ops const * ops;
+};
+
+struct cubeb_stream {
+ cubeb * context;
+ cubeb_stream_params params;
+ cubeb_data_callback data_callback;
+ cubeb_state_callback state_callback;
+ void * user_ptr;
+
+ HKAI hkai;
+ KAISPEC spec;
+ uint64_t total_frames;
+ _fmutex mutex;
+ float float_buffer[FRAME_SIZE * MAX_CHANNELS];
+};
+
+static inline long
+frames_to_bytes(long frames, cubeb_stream_params params)
+{
+ return frames * 2 * params.channels; /* 2 bytes per frame */
+}
+
+static inline long
+bytes_to_frames(long bytes, cubeb_stream_params params)
+{
+ return bytes / 2 / params.channels; /* 2 bytes per frame */
+}
+
+static void kai_destroy(cubeb * ctx);
+
+/*static*/ int
+kai_init(cubeb ** context, char const * context_name)
+{
+ cubeb * ctx;
+
+ assert(context);
+ *context = NULL;
+
+ if (kaiInit(KAIM_AUTO))
+ return CUBEB_ERROR;
+
+ ctx = calloc(1, sizeof(*ctx));
+ assert(ctx);
+
+ ctx->ops = &kai_ops;
+
+ *context = ctx;
+
+ return CUBEB_OK;
+}
+
+static char const *
+kai_get_backend_id(cubeb * ctx)
+{
+ return "kai";
+}
+
+static void
+kai_destroy(cubeb * ctx)
+{
+ kaiDone();
+
+ free(ctx);
+}
+
+static void
+float_to_s16ne(int16_t *dst, float *src, size_t n)
+{
+ long l;
+
+ while (n--) {
+ l = lrintf(*src++ * 0x8000);
+ if (l > 32767)
+ l = 32767;
+ if (l < -32768)
+ l = -32768;
+ *dst++ = (int16_t)l;
+ }
+}
+
+static ULONG APIENTRY
+kai_callback(PVOID cbdata, PVOID buffer, ULONG len)
+{
+ cubeb_stream * stm = cbdata;
+ void *p;
+ long wanted_frames;
+ long frames;
+
+ p = stm->params.format == CUBEB_SAMPLE_FLOAT32NE
+ ? stm->float_buffer : buffer;
+
+ wanted_frames = bytes_to_frames(len, stm->params);
+ frames = stm->data_callback(stm, stm->user_ptr, p, wanted_frames);
+
+ _fmutex_request(&stm->mutex, 0);
+ stm->total_frames += frames;
+ _fmutex_release(&stm->mutex);
+
+ if (frames < wanted_frames)
+ stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_DRAINED);
+
+ if (stm->params.format == CUBEB_SAMPLE_FLOAT32NE)
+ float_to_s16ne(buffer, p, len / sizeof(int16_t));
+
+ return frames_to_bytes(frames, stm->params);
+}
+
+static void kai_stream_destroy(cubeb_stream * stm);
+
+static int
+kai_stream_init(cubeb * context, cubeb_stream ** stream,
+ char const * stream_name, cubeb_stream_params stream_params,
+ unsigned int latency, cubeb_data_callback data_callback,
+ cubeb_state_callback state_callback, void * user_ptr)
+{
+ cubeb_stream * stm;
+ KAISPEC wanted_spec;
+
+ if (stream_params.channels < 1 || stream_params.channels > MAX_CHANNELS)
+ return CUBEB_ERROR_INVALID_FORMAT;
+
+ assert(context);
+ assert(stream);
+
+ *stream = NULL;
+
+ stm = calloc(1, sizeof(*stm));
+ assert(stm);
+
+ stm->context = context;
+ stm->params = stream_params;
+ stm->data_callback = data_callback;
+ stm->state_callback = state_callback;
+ stm->user_ptr = user_ptr;
+
+ if (_fmutex_create(&stm->mutex, 0)) {
+ free(stm);
+ return CUBEB_ERROR;
+ }
+
+ wanted_spec.usDeviceIndex = 0;
+ wanted_spec.ulType = KAIT_PLAY;
+ wanted_spec.ulBitsPerSample = BPS_16;
+ wanted_spec.ulSamplingRate = stm->params.rate;
+ wanted_spec.ulDataFormat = MCI_WAVE_FORMAT_PCM;
+ wanted_spec.ulChannels = stm->params.channels;
+ wanted_spec.ulNumBuffers = NBUFS;
+ wanted_spec.ulBufferSize = frames_to_bytes(FRAME_SIZE, stm->params);
+ wanted_spec.fShareable = TRUE;
+ wanted_spec.pfnCallBack = kai_callback;
+ wanted_spec.pCallBackData = stm;
+
+ if (kaiOpen(&wanted_spec, &stm->spec, &stm->hkai)) {
+ _fmutex_close(&stm->mutex);
+ free(stm);
+ return CUBEB_ERROR;
+ }
+
+ *stream = stm;
+
+ return CUBEB_OK;
+}
+
+static void
+kai_stream_destroy(cubeb_stream * stm)
+{
+ kaiClose(stm->hkai);
+ _fmutex_close(&stm->mutex);
+ free(stm);
+}
+
+static int
+kai_get_max_channel_count(cubeb * ctx, uint32_t * max_channels)
+{
+ assert(ctx && max_channels);
+
+ *max_channels = MAX_CHANNELS;
+
+ return CUBEB_OK;
+}
+
+static int
+kai_get_min_latency(cubeb * ctx, cubeb_stream_params params, uint32_t * latency)
+{
+ /* We have at least two buffers. One is being played, the other one is being
+ filled. So there is as much latency as one buffer. */
+ *latency = FRAME_SIZE * 1000 / params.rate;
+
+ return CUBEB_OK;
+}
+
+static int
+kai_get_preferred_sample_rate(cubeb * ctx, uint32_t * rate)
+{
+ cubeb_stream_params params;
+ KAISPEC wanted_spec;
+ KAISPEC spec;
+ HKAI hkai;
+
+ params.format = CUBEB_SAMPLE_S16NE;
+ params.rate = 48000;
+ params.channels = 2;
+
+ wanted_spec.usDeviceIndex = 0;
+ wanted_spec.ulType = KAIT_PLAY;
+ wanted_spec.ulBitsPerSample = BPS_16;
+ wanted_spec.ulSamplingRate = params.rate;
+ wanted_spec.ulDataFormat = MCI_WAVE_FORMAT_PCM;
+ wanted_spec.ulChannels = params.channels;
+ wanted_spec.ulNumBuffers = NBUFS;
+ wanted_spec.ulBufferSize = frames_to_bytes(FRAME_SIZE, params);
+ wanted_spec.fShareable = TRUE;
+ wanted_spec.pfnCallBack = kai_callback;
+ wanted_spec.pCallBackData = NULL;
+
+ /* Test 48KHz */
+ if (kaiOpen(&wanted_spec, &spec, &hkai)) {
+ /* Not supported. Fall back to 44.1KHz */
+ params.rate = 44100;
+ } else {
+ /* Supported. Use 48KHz */
+ kaiClose(hkai);
+ }
+
+ *rate = params.rate;
+
+ return CUBEB_OK;
+}
+
+static int
+kai_stream_start(cubeb_stream * stm)
+{
+ if (kaiPlay(stm->hkai))
+ return CUBEB_ERROR;
+
+ stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STARTED);
+
+ return CUBEB_OK;
+}
+
+static int
+kai_stream_stop(cubeb_stream * stm)
+{
+ if (kaiStop(stm->hkai))
+ return CUBEB_ERROR;
+
+ stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STOPPED);
+
+ return CUBEB_OK;
+}
+
+static int
+kai_stream_get_position(cubeb_stream * stm, uint64_t * position)
+{
+ _fmutex_request(&stm->mutex, 0);
+ *position = stm->total_frames;
+ _fmutex_release(&stm->mutex);
+
+ return CUBEB_OK;
+}
+
+static int
+kai_stream_get_latency(cubeb_stream * stm, uint32_t * latency)
+{
+ /* Out of buffers, one is being played, the others are being filled.
+ So there is as much latency as total buffers - 1. */
+ *latency = bytes_to_frames(stm->spec.ulBufferSize, stm->params)
+ * (stm->spec.ulNumBuffers - 1);
+
+ return CUBEB_OK;
+}
+
+static struct cubeb_ops const kai_ops = {
+ .init = kai_init,
+ .get_backend_id = kai_get_backend_id,
+ .get_max_channel_count= kai_get_max_channel_count,
+ .get_min_latency= kai_get_min_latency,
+ .get_preferred_sample_rate = kai_get_preferred_sample_rate,
+ .destroy = kai_destroy,
+ .stream_init = kai_stream_init,
+ .stream_destroy = kai_stream_destroy,
+ .stream_start = kai_stream_start,
+ .stream_stop = kai_stream_stop,
+ .stream_get_position = kai_stream_get_position,
+ .stream_get_latency = kai_stream_get_latency,
+};
diff --git a/media/libcubeb/src/moz.build b/media/libcubeb/src/moz.build
index 64a6146..ae17add 100644
--- a/media/libcubeb/src/moz.build
+++ b/media/libcubeb/src/moz.build
@@ -54,6 +54,12 @@ if CONFIG['OS_TARGET'] == 'Android':
]
DEFINES['USE_AUDIOTRACK'] = True
+if CONFIG['OS_TARGET'] == 'OS2':
+ SOURCES += [
+ 'cubeb_kai.c',
+ ]
+ DEFINES['USE_KAI'] = True
+
MSVC_ENABLE_PGO = True
if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
diff --git a/toolkit/library/libxul.mozbuild b/toolkit/library/libxul.mozbuild
index 6bfe2f7..7badebd 100644
--- a/toolkit/library/libxul.mozbuild
+++ b/toolkit/library/libxul.mozbuild
@@ -55,5 +55,6 @@ if CONFIG['OS_ARCH'] == 'OS2':
'/widget/os2',
'/xpcom/base',
]
+ LDFLAGS += ['-lkai']
# This file is (only) included from subdirectories, and the file is here.
RESFILE = '../xulrunos2.res'
--
1.9.5
And I tested here.
http://hpr.dogphilosophy.net/test/
MP3 and FLAC are not supported. It's a codec problem.
Finally, there are widget/os2/nsSound.*. They are used really ? Then, how can I test them ? Just playing local WAV files, opens a dialog asking to open or to save.
On 06/19/15 07:59 PM, KO Myung-Hun wrote:
Finally, there are widget/os2/nsSound.*. They are used really ? Then, how can I test them ? Just playing local WAV files, opens a dialog asking to open or to save.
They're used for things like the new email sound that SM and TB make and they never stopped working as they use the system (MMOS2) sounds. See widget/os2/MozSounds.cmd. You can build SM to test, I updated the source at bitbucket the other day and it is working as well as FF. BTW there is an option to use FFmpeg in configure that is currently disabled.
@dryeo there is no way to confirm in FF ? @SilvanScherrer this part as well should be replaced by libkai ?
@komh That would be really nice to drop MMPM code completely. I will look at how it can be tested in FF.
@dryeo Yes, FFmpeg is an option too. But there is something on the way IIRC. I will re-check that once I'm done with #100.
On 06/20/15 08:57 AM, KO Myung-Hun wrote:
@dryeo https://github.com/dryeo there is no way to confirm in FF ?
Sure, run MozSounds.cmd, enable events, eg E All, open the WPS sound object and assign sounds to the events and then test by opening menus etc. After getting irritated by the sounds, use MozSounds.cmd to disable.
@komh Built SM with the latest cubeb patch and tested with a webm conformance video I have and Big Buck Bunny.webm. The good news is sound works and stays in sync. Problems are sound is really quiet, with my speakers turned all the way up, I can just barely hear it. The volume object has no affect and opening the Unimixer PM app kills the sound. Muting and unmuting in the browser brings it back at the same low volume. The VP8 support also works well though the scaling is crappy when going to full screen with lots of artifacts. btw there are some test clips under content/media/test @dmik Seems that Mozilla actually expects libav 09.1 and dynamically loads libavcodec, libavutil and libavformat. I'll try building it later and look at quickly hacking content/media/fmp4/ffmpeg/FFmpegRuntimeLinker.cpp to use DosLoadModule to load the correct short named above DLLs. Also currently libav exports symbols by ordinal, wonder if it needs changing to exporting by function when loading with DosLoadModule()?
@dryeo cubeb in Mozilla does not have ability of volume control. Crosscheck in FF on other platforms, please.
For VP8 comment, I'm afraid I don't unerstand what you mean. Maybe, do you mean libvpx parts have problems ?
And thanks for MozSound.cmd. I'll try.
@dmik I think, play parts only should be replaced, but not decoding parts.
By VP8, I meant vpx but I was mistaken, the video is theora+ogg. Testing on my T42 (Pentium M 1.6Ghz) using Big Buck Bunny.ogv. FF 35 on windows plays at a decent volume and the volume can be adjusted in the browser window or using the system volume control. Video is somewhat jerky, sound is smooth. SM2.21 compiled with Sydneyaudio on eCS2.2b2 works much the same as Windows. Volume is the same, volume can be adjusted in the browser, using the system volume control and the Uniaud PM mixer. Video is smoother then on Windows, possibly because Windows has so many background tasks running. Video needs to be paused and unpaused sometimes to keep running. This is a Sydneyaudio problem and the reason it was replaced. SM 2.28 with your libcubeb patch on the same system, I can barely hear the video and using the volume doesn't help. Same SM 2.28 on my desktop is also very quiet, volume in browser window does work but not the system volume or the Uniaud PM mixer. You can test by going to Youtube, signing up for webm videos and playing any video. There will be a volume control in the lower right of the video when the mouse is over the video, much like when using the Flash video player.
Strange, I can hear sounds at proper db. The problem that volume is not controlled by system volume, is not related to cubeb/kai. It's up to uniaud driver, especially uniaud32. And although I don't use PM uniaud mixer, unimix is working. However, controlling volume level does not work well. Mute/unmute are working surely.
Instead, you can test dart mode by renaming x:\mmos2\dll\uniaud.dll to something different. In this case, system volume will work.
Patch for nsSound.cpp. Besides this, you should fix typo of kai.h. Replace __cpluslus with __cplusplus at end of it.
From 8814d57e09c7c5340ec50959ae4ab59dd3375ed9 Mon Sep 17 00:00:00 2001
From: KO Myung-Hun <komh@chollian.net>
Date: Sun, 21 Jun 2015 16:25:06 +0900
Subject: [PATCH] [OS/2] widget: replace MMOS2 sound play parts with libkai
---
widget/os2/nsSound.cpp | 96 +++++++++++++++++++++++++++++++++++++-------------
1 file changed, 71 insertions(+), 25 deletions(-)
diff --git a/widget/os2/nsSound.cpp b/widget/os2/nsSound.cpp
index eced0d0..3e2a059 100644
--- a/widget/os2/nsSound.cpp
+++ b/widget/os2/nsSound.cpp
@@ -18,6 +18,8 @@
#include <mmioos2.h>
#include <mcios2.h>
+#include <kai.h>
+
#include "nsSound.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
@@ -52,13 +54,17 @@ static char * sSoundFiles[EVENT_CNT] = {0}; // an array of sound file names
// function pointer definitions (underscore works around redef. warning)
static HMMIO (*APIENTRY _mmioOpen)(PSZ, PMMIOINFO, ULONG);
static USHORT (*APIENTRY _mmioClose)(HMMIO, USHORT);
-static ULONG (*APIENTRY _mciSendCommand)(USHORT, USHORT, ULONG, PVOID, USHORT);
+static ULONG (*APIENTRY _mmioGetHeader)(HMMIO, PVOID, LONG, PLONG, ULONG,
+ ULONG);
+static LONG (*APIENTRY _mmioRead)(HMMIO, PCHAR, LONG);
// helper functions
static void initSounds(void);
static bool initDlls(void);
static void playSound(void *aArgs);
static FOURCC determineFourCC(uint32_t aDataLen, const char *aData);
+static ULONG APIENTRY kaiCallback(PVOID pCBData, PVOID pBuffer,
+ ULONG cchBuffer);
/*****************************************************************************/
/* nsSound implementation */
@@ -387,10 +393,8 @@ static bool initDlls(void)
sDllInit = TRUE;
HMODULE hmodMMIO = 0;
- HMODULE hmodMDM = 0;
char szError[32];
- if (DosLoadModule(szError, sizeof(szError), "MMIO", &hmodMMIO) ||
- DosLoadModule(szError, sizeof(szError), "MDM", &hmodMDM)) {
+ if (DosLoadModule(szError, sizeof(szError), "MMIO", &hmodMMIO)) {
DBG_MSG("initDlls: DosLoadModule failed");
sDllError = TRUE;
return FALSE;
@@ -398,7 +402,8 @@ static bool initDlls(void)
if (DosQueryProcAddr(hmodMMIO, 0L, "mmioOpen", (PFN *)&_mmioOpen) ||
DosQueryProcAddr(hmodMMIO, 0L, "mmioClose", (PFN *)&_mmioClose) ||
- DosQueryProcAddr(hmodMDM, 0L, "mciSendCommand", (PFN *)&_mciSendCommand)) {
+ DosQueryProcAddr(hmodMMIO, 0L, "mmioGetHeader", (PFN *)&_mmioGetHeader) ||
+ DosQueryProcAddr(hmodMMIO, 0L, "mmioRead", (PFN *)&_mmioRead)) {
DBG_MSG("initDlls: DosQueryProcAddr failed");
sDllError = TRUE;
return FALSE;
@@ -418,6 +423,7 @@ static void playSound(void * aArgs)
BOOL fOK = FALSE;
HMMIO hmmio = 0;
MMIOINFO mi;
+ HKAI hkai = 0;
do {
if (!initDlls())
@@ -440,38 +446,61 @@ static void playSound(void * aArgs)
break;
}
- // open the sound device
- MCI_OPEN_PARMS mop;
- memset(&mop, 0, sizeof(mop));
- mop.pszElementName = (PSZ)hmmio;
- mop.pszDeviceType = (PSZ)MAKEULONG(MCI_DEVTYPE_WAVEFORM_AUDIO, 0);
- if (_mciSendCommand(0, MCI_OPEN,
- MCI_OPEN_MMIO | MCI_OPEN_TYPE_ID |
- MCI_OPEN_SHAREABLE | MCI_WAIT,
- (PVOID)&mop, 0)) {
- DBG_MSG("playSound: MCI_OPEN failed");
+ if (kaiInit(KAIM_AUTO)) {
+ DBG_MSG("playSound: kaiInit failed");
break;
}
- fOK = TRUE;
- // play the sound
- MCI_PLAY_PARMS mpp;
- memset(&mpp, 0, sizeof(mpp));
- if (_mciSendCommand(mop.usDeviceID, MCI_PLAY, MCI_WAIT, &mpp, 0)) {
- DBG_MSG("playSound: MCI_PLAY failed");
+ MMAUDIOHEADER mmAudioHeader;
+ LONG lBytesRead;
+
+ // get header
+ if (_mmioGetHeader(hmmio, &mmAudioHeader, sizeof(MMAUDIOHEADER),
+ &lBytesRead, 0, 0)) {
+ DBG_MSG("playSound: _mmioGetHeader failed");
+ break;
}
- // stop & close the device
- _mciSendCommand(mop.usDeviceID, MCI_STOP, MCI_WAIT, &mpp, 0);
- if (_mciSendCommand(mop.usDeviceID, MCI_CLOSE, MCI_WAIT, &mpp, 0)) {
- DBG_MSG("playSound: MCI_CLOSE failed");
+ KAISPEC ksWanted, ksObtained;
+
+ ksWanted.usDeviceIndex = 0;
+ ksWanted.ulType = KAIT_PLAY;
+ ksWanted.ulBitsPerSample = mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample;
+ ksWanted.ulSamplingRate = mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec;
+ ksWanted.ulDataFormat = mmAudioHeader.mmXWAVHeader.WAVEHeader.usFormatTag;
+ ksWanted.ulChannels = mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels;
+ ksWanted.ulNumBuffers = 2; // at leat 2 buffers are needed
+ ksWanted.ulBufferSize = 2048 * ksWanted.ulBitsPerSample / 8 *
+ ksWanted.ulChannels; // 2048 samples
+ ksWanted.fShareable = TRUE;
+ ksWanted.pfnCallBack = kaiCallback;
+ ksWanted.pCallBackData = &hmmio;
+
+ // open KAI instance
+ if (kaiOpen(&ksWanted, &ksObtained, &hkai)) {
+ DBG_MSG("playSound: kaiOpen failed");
+ break;
}
+ fOK = TRUE;
+
+ // set thread priority to maximum to prevent choppy shound at startup
+ DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0);
+
+ // play the sound
+ kaiPlay(hkai);
+
+ // wait to complete
+ while (kaiStatus(hkai) == KAIS_PLAYING)
+ DosSleep(1);
} while (0);
if (!fOK)
WinAlarm(HWND_DESKTOP, WA_WARNING);
+ kaiClose(hkai);
+ kaiDone();
+
if (hmmio)
_mmioClose(hmmio, 0);
DosFreeMem(aArgs);
@@ -515,3 +544,20 @@ static FOURCC determineFourCC(uint32_t aDataLen, const char *aData)
/*****************************************************************************/
+// Callback function called from KAI
+
+static ULONG APIENTRY kaiCallback(PVOID pCBData, PVOID pBuffer,
+ ULONG cchBuffer)
+{
+ HMMIO hmmio = *(HMMIO *)pCBData;
+ LONG len;
+
+ len = _mmioRead(hmmio, (PCHAR)pBuffer, cchBuffer);
+ // If error, stop
+ if (len == (LONG)MMIO_ERROR)
+ len = 0;
+
+ return len;
+}
+
+/*****************************************************************************/
--
1.9.5
@komh sorry for the late reply. Yes we should replace all MMOS2 code with libkai. But I guess you already replaced them all. Right?
Built FF with both patches. The event sounds seem to work fine, webm video is still too quiet. Moving uniaud.dll out of the way, the webm video plays at normal volume
@dryeo Dave did you play with unimix. It might be possible some values for volumes are to low
Will it have some switch to the dart mode insread of that renaming of uniaud32.dll?
@sylvan I've tried playing with unimixpm and now the text version. Nothing has helped yet though it is possible I missed something in the 36 controls on this board. The event sounds work at the correct volume.
@SilvanScherrer Yes, I've done already.
@an64 I've added that feature to libkai already. See https://github.com/komh/kai/commit/646b9da30abad71d04dbeccb9aa34fe7f4a43f0c. I'll release new libkai soon.
@dryeo which webm videos are you testing ? If URL, post it. If file, provide small clip to me. At least, in my box, there is not volume problem.
@SilvanScherrer, I've played with both unimixpm and now the textmode unixmix. I may have missed something as there are 36 options.
@komh I've tried a few, mostly Big Buck Bunny, BigBuckBunny_512kb.ogv (probably from archive.com), but I just went to bigbuckbunny.org and tried streaming the lowest bitrate ogg http://mirrorblender.top-ix.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_stereo.ogg and it is even quieter.
@dryeo Thanks, I'll test it soon. And would you mind posting your output of unixmix -list when you hear quiet sound ?
@dryeo I've tested it. In fact, system sound which is 8-bits seems to be louder than the above ogg stream. However I don't feel that it is too much quiet. In addition, I failed to see the differences of volume on uniaud and dart.
BTW, you can hear barely sounds in http://hpr.dogphilosophy.net/test/, too ?
@komh That page isn't loading. I built Mplayer and it is the same volume, then tested with VLC. I seem to have set it to use DART at some point, using KAI it is also the same volume. So it is something to do with my systems (including a pretty fresh install of 2.2b2). I'll try some different uniaud versions later.
The above path for nsSound.cpp has a problem. If a system sound is played while playing a movie, FF crashes. I'll post the fixed patch, soon.
@komh Thanks!
Here is the fixed patch.
From 2d27090975d9c8bb4443cd1d34d95710d25b97c3 Mon Sep 17 00:00:00 2001
From: KO Myung-Hun <komh@chollian.net>
Date: Sun, 21 Jun 2015 16:25:06 +0900
Subject: [PATCH] [OS/2] widget: replace MMOS2 sound play parts with libkai
---
widget/os2/nsSound.cpp | 100 ++++++++++++++++++++++++++++++++++++-------------
1 file changed, 75 insertions(+), 25 deletions(-)
diff --git a/widget/os2/nsSound.cpp b/widget/os2/nsSound.cpp
index a961546..aeba643 100644
--- a/widget/os2/nsSound.cpp
+++ b/widget/os2/nsSound.cpp
@@ -18,6 +18,8 @@
#include <mmioos2.h>
#include <mcios2.h>
+#include <kai.h>
+
#include "nsSound.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
@@ -52,13 +54,17 @@ static char * sSoundFiles[EVENT_CNT] = {0}; // an array of sound file names
// function pointer definitions (underscore works around redef. warning)
static HMMIO (*APIENTRY _mmioOpen)(PSZ, PMMIOINFO, ULONG);
static USHORT (*APIENTRY _mmioClose)(HMMIO, USHORT);
-static ULONG (*APIENTRY _mciSendCommand)(USHORT, USHORT, ULONG, PVOID, USHORT);
+static ULONG (*APIENTRY _mmioGetHeader)(HMMIO, PVOID, LONG, PLONG, ULONG,
+ ULONG);
+static LONG (*APIENTRY _mmioRead)(HMMIO, PCHAR, LONG);
// helper functions
static void initSounds(void);
static bool initDlls(void);
static void playSound(void *aArgs);
static FOURCC determineFourCC(uint32_t aDataLen, const char *aData);
+static ULONG APIENTRY kaiCallback(PVOID pCBData, PVOID pBuffer,
+ ULONG cchBuffer);
/*****************************************************************************/
/* nsSound implementation */
@@ -390,10 +396,8 @@ static bool initDlls(void)
sDllInit = TRUE;
HMODULE hmodMMIO = 0;
- HMODULE hmodMDM = 0;
char szError[32];
- if (DosLoadModule(szError, sizeof(szError), "MMIO", &hmodMMIO) ||
- DosLoadModule(szError, sizeof(szError), "MDM", &hmodMDM)) {
+ if (DosLoadModule(szError, sizeof(szError), "MMIO", &hmodMMIO)) {
DBG_MSG("initDlls: DosLoadModule failed");
sDllError = TRUE;
return FALSE;
@@ -401,7 +405,8 @@ static bool initDlls(void)
if (DosQueryProcAddr(hmodMMIO, 0L, "mmioOpen", (PFN *)&_mmioOpen) ||
DosQueryProcAddr(hmodMMIO, 0L, "mmioClose", (PFN *)&_mmioClose) ||
- DosQueryProcAddr(hmodMDM, 0L, "mciSendCommand", (PFN *)&_mciSendCommand)) {
+ DosQueryProcAddr(hmodMMIO, 0L, "mmioGetHeader", (PFN *)&_mmioGetHeader) ||
+ DosQueryProcAddr(hmodMMIO, 0L, "mmioRead", (PFN *)&_mmioRead)) {
DBG_MSG("initDlls: DosQueryProcAddr failed");
sDllError = TRUE;
return FALSE;
@@ -443,33 +448,61 @@ static void playSound(void * aArgs)
break;
}
- // open the sound device
- MCI_OPEN_PARMS mop;
- memset(&mop, 0, sizeof(mop));
- mop.pszElementName = (PSZ)hmmio;
- mop.pszDeviceType = (PSZ)MAKEULONG(MCI_DEVTYPE_WAVEFORM_AUDIO, 0);
- if (_mciSendCommand(0, MCI_OPEN,
- MCI_OPEN_MMIO | MCI_OPEN_TYPE_ID |
- MCI_OPEN_SHAREABLE | MCI_WAIT,
- (PVOID)&mop, 0)) {
- DBG_MSG("playSound: MCI_OPEN failed");
+ if (kaiInit(KAIM_AUTO)) {
+ DBG_MSG("playSound: kaiInit failed");
break;
}
- fOK = TRUE;
- // play the sound
- MCI_PLAY_PARMS mpp;
- memset(&mpp, 0, sizeof(mpp));
- if (_mciSendCommand(mop.usDeviceID, MCI_PLAY, MCI_WAIT, &mpp, 0)) {
- DBG_MSG("playSound: MCI_PLAY failed");
+ MMAUDIOHEADER mmAudioHeader;
+ LONG lBytesRead;
+
+ // get header
+ if (_mmioGetHeader(hmmio, &mmAudioHeader, sizeof(MMAUDIOHEADER),
+ &lBytesRead, 0, 0)) {
+ DBG_MSG("playSound: _mmioGetHeader failed");
+
+ kaiDone();
+ break;
}
- // stop & close the device
- _mciSendCommand(mop.usDeviceID, MCI_STOP, MCI_WAIT, &mpp, 0);
- if (_mciSendCommand(mop.usDeviceID, MCI_CLOSE, MCI_WAIT, &mpp, 0)) {
- DBG_MSG("playSound: MCI_CLOSE failed");
+ KAISPEC ksWanted, ksObtained;
+ HKAI hkai;
+
+ ksWanted.usDeviceIndex = 0;
+ ksWanted.ulType = KAIT_PLAY;
+ ksWanted.ulBitsPerSample = mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample;
+ ksWanted.ulSamplingRate = mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec;
+ ksWanted.ulDataFormat = mmAudioHeader.mmXWAVHeader.WAVEHeader.usFormatTag;
+ ksWanted.ulChannels = mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels;
+ ksWanted.ulNumBuffers = 2; // at leat 2 buffers are needed
+ ksWanted.ulBufferSize = 2048 * ksWanted.ulBitsPerSample / 8 *
+ ksWanted.ulChannels; // 2048 samples
+ ksWanted.fShareable = TRUE;
+ ksWanted.pfnCallBack = kaiCallback;
+ ksWanted.pCallBackData = &hmmio;
+
+ // open KAI instance
+ if (kaiOpen(&ksWanted, &ksObtained, &hkai)) {
+ DBG_MSG("playSound: kaiOpen failed");
+
+ kaiDone();
+ break;
}
+ fOK = TRUE;
+
+ // set thread priority to maximum to prevent choppy shound at startup
+ DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0);
+
+ // play the sound
+ kaiPlay(hkai);
+
+ // wait to complete
+ while (kaiStatus(hkai) == KAIS_PLAYING)
+ DosSleep(1);
+
+ kaiClose(hkai);
+ kaiDone();
} while (0);
if (!fOK)
@@ -518,3 +551,20 @@ static FOURCC determineFourCC(uint32_t aDataLen, const char *aData)
/*****************************************************************************/
+// Callback function called from KAI
+
+static ULONG APIENTRY kaiCallback(PVOID pCBData, PVOID pBuffer,
+ ULONG cchBuffer)
+{
+ HMMIO hmmio = *(HMMIO *)pCBData;
+ LONG len;
+
+ len = _mmioRead(hmmio, (PCHAR)pBuffer, cchBuffer);
+ // If error, stop
+ if (len == (LONG)MMIO_ERROR)
+ len = 0;
+
+ return len;
+}
+
+/*****************************************************************************/
--
1.9.5
@komh I have successfully built your patches and they appear to work here. I will have to add a --with-libkai option to configure though and leave old MMPM code in for the time being. Then I will commit your patches. Thanks for your work.
I've fixed my low volume issue by turning the "Front Playback Volume" up to full. System volume control still has no affect but the PMUnixmix in Hobbes incoming works well, including simplifying finding the fix. Perhaps something to be added to the README under troubleshooting.
I tried Firefox on my notebook and sound works now, indeed. A few things to mention: sometimes I get system freezes and even kernel traps in UNIAUD32 while playing sounds but that certainly has nothing to do with FF. I get the same behavior with e.g. mplayer. My hardware in this case is Lenove T400, if that matters. In mplayer sound only works in -ao kai:dart
mode, -ao kai:uniaud
gives me just noise (and very jerky video playback). This applies to UNIAUD32.SYS v1.9.26 — If I try the newer v2.2.1, I always get noise (seems that it works in uniaud mode by default).
libkai
prefers UNIAUD API to DART by default, if the required operation mode is not specified.To force
libkai
operation via DART or UNIAUD API, theKAI_AUTOMODE
environment variable can be used, which can either be set toDART
(forces operation via DART),UNIAUD
(forces operation via UNIAUD API) or an empty string (leavinglibkai
to decide on its own).
The above should be added to the readme file in the OS/2 Firefox distribution. Thank you.
@komh good news, i thought this ticket will never move forward. A non firefox task is left open: update the uniaud driver that includes all the latest alsa updates to make it work on newer hardware.
@dryeo good that a least one switch of unimix could make it work :)
@komh the patches (modified to preserve the old code) are added in 531b310329a48094efe7b69783b90b0fc5faf682. This commit also brings two new configure options to deal with libkai: --disable-libkai
to disable libkai support (which means no sound in HTML5 and use MMPM directly for widget sounds) and --with-libkai=DIR
which allows to specify the location where to look for libkai headers and libraries. I will create the libkai RPM which will make --with-libkai
not normally necessary.
@dmik those problems that you are encountering are well-known problems. Uniaud API support of Uniaud driver has been broken. See http://trac.netlabs.org/uniaud/ticket/231. And I don't use 2.2.1 due to the same reason as you. In case of TRAP of UNIAUD32, libkai as well has nothing to do with it. UNIAUD32 itself should be fixed.
I created the RPMs for libkai (check http://trac.netlabs.org/rpm/browser/spec/trunk/SPECS/libkai.spec), they will appear shortly on netlabs. Now, after doing yum install libkai-devel
, you don't need any additional options to get it built-in (as a DLL). I also updated the README with the new instructions and a proper link to the libkai DLL in 2d8078e1a29a130d96273430a6d6dd2528fd5bf6.
BTW, playing with KAI_AUTOMODE doesn't make any difference here. Perhaps because MMPM uses Uniaud here anyway.
I guess this issue may be closed now. @komh, thank you for your great effort!
On 07/01/15 05:42 AM, Dmitriy Kuminov wrote:
BTW, playing with KAI_AUTOMODE doesn't make any difference here. Perhaps because MMPM uses Uniaud here anyway.
Using the default volume settings, I get low volume with it set to UNIAUD and good volume with the DART setting. Should not this issue include updating the environmental variables section of README.OS2 with KAI_AUTOMODE?
@dryeo KAI_AUTOMODE is already described in README.OS2 in section Audio in the above commit.
BTW, there is a good link to test various audio formats in HTML5: http://hpr.dogphilosophy.net/test/. Here all formats except MP3 and FLAC work perfectly. For the latter two we probably need to enable some other library (ffmpeg?), looks like a license issue to me.
On 07/01/15 08:15 AM, Dmitriy Kuminov wrote:
except MP3 and FLAC work perfectly. For the latter two we probably need to enable some other library (ffmpeg?), looks like a license issue to me.
I believe on Linux it is gstreamer (which uses FFmpeg and other libraries) and on Windows and OSX, it uses the system codecs. FLAC shouldn't have any licence issues (libraries are a BSD type license). MP3 has patent issues (which may be expired now and depends on country)
Use libkai instead of MMOS2. This gives the advantage, that libkai uses uniaud api direct when uniaud is installed and MMOS2 when no uniaud is found.