mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1133386 - Introduce an XASSERT() macro to libcubeb rather than (ab)using assert(). r=padenot f=dmajor
This commit is contained in:
parent
3ecd4eb3a8
commit
1b8685913f
@ -5,4 +5,4 @@ Makefile.in build files for the Mozilla build system.
|
||||
|
||||
The cubeb git repository is: git://github.com/kinetiknz/cubeb.git
|
||||
|
||||
The git commit ID used was 699aadf4d5e4c14a7e87b4f4add9cbc938feecc2.
|
||||
The git commit ID used was cacaae79dd8b7220202d0dfe3f889d55e23a77a5.
|
||||
|
@ -39,5 +39,12 @@ struct cubeb_ops {
|
||||
|
||||
};
|
||||
|
||||
#endif /* CUBEB_INTERNAL_0eb56756_4e20_4404_a76d_42bf88cd15a5 */
|
||||
#define XASSERT(expr) do { \
|
||||
if (!(expr)) { \
|
||||
fprintf(stderr, "%s:%d - fatal error: %s\n", __FILE__, __LINE__, #expr); \
|
||||
*((volatile int *) NULL) = 0; \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif /* CUBEB_INTERNAL_0eb56756_4e20_4404_a76d_42bf88cd15a5 */
|
||||
|
@ -5,15 +5,9 @@
|
||||
* accompanying file LICENSE for details.
|
||||
*/
|
||||
// This enables assert in release, and lets us have debug-only code
|
||||
#ifdef NDEBUG
|
||||
#define DEBUG
|
||||
#undef NDEBUG
|
||||
#endif // #ifdef NDEBUG
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include "config.h"
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <windows.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <windef.h>
|
||||
@ -25,6 +19,7 @@
|
||||
#include "cubeb/cubeb-stdint.h"
|
||||
#include "cubeb_resampler.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cmath>
|
||||
|
||||
/**Taken from winbase.h, Not in MinGW.*/
|
||||
@ -102,7 +97,7 @@ public:
|
||||
{
|
||||
EnterCriticalSection(&critical_section);
|
||||
#ifdef DEBUG
|
||||
assert(owner != GetCurrentThreadId() && "recursive locking");
|
||||
XASSERT(owner != GetCurrentThreadId() && "recursive locking");
|
||||
owner = GetCurrentThreadId();
|
||||
#endif
|
||||
}
|
||||
@ -122,7 +117,7 @@ public:
|
||||
{
|
||||
#ifdef DEBUG
|
||||
/* This implies owner != 0, because GetCurrentThreadId cannot return 0. */
|
||||
assert(owner == GetCurrentThreadId());
|
||||
XASSERT(owner == GetCurrentThreadId());
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -389,7 +384,7 @@ template<typename T>
|
||||
void
|
||||
upmix(T * in, long inframes, T * out, int32_t in_channels, int32_t out_channels)
|
||||
{
|
||||
assert(out_channels >= in_channels);
|
||||
XASSERT(out_channels >= in_channels);
|
||||
/* If we are playing a mono stream over stereo speakers, copy the data over. */
|
||||
if (in_channels == 1 && out_channels == 2) {
|
||||
mono_to_stereo(in, inframes, out);
|
||||
@ -412,7 +407,7 @@ template<typename T>
|
||||
void
|
||||
downmix(T * in, long inframes, T * out, int32_t in_channels, int32_t out_channels)
|
||||
{
|
||||
assert(in_channels >= out_channels);
|
||||
XASSERT(in_channels >= out_channels);
|
||||
/* We could use a downmix matrix here, applying mixing weight based on the
|
||||
* channel, but directsound and winmm simply drop the channels that cannot be
|
||||
* rendered by the hardware, so we do the same for consistency. */
|
||||
@ -452,7 +447,7 @@ refill(cubeb_stream * stm, float * data, long frames_needed)
|
||||
|
||||
/* XXX: Handle this error. */
|
||||
if (out_frames < 0) {
|
||||
assert(false);
|
||||
XASSERT(false);
|
||||
}
|
||||
|
||||
/* Go in draining mode if we got fewer frames than requested. */
|
||||
@ -463,7 +458,7 @@ refill(cubeb_stream * stm, float * data, long frames_needed)
|
||||
|
||||
/* If this is not true, there will be glitches.
|
||||
* It is alright to have produced less frames if we are draining, though. */
|
||||
assert(out_frames == frames_needed || stm->draining);
|
||||
XASSERT(out_frames == frames_needed || stm->draining);
|
||||
|
||||
if (should_upmix(stm)) {
|
||||
upmix(dest, out_frames, data,
|
||||
@ -539,7 +534,7 @@ wasapi_stream_render_loop(LPVOID stream)
|
||||
is_playing = false;
|
||||
continue;
|
||||
}
|
||||
assert(padding <= stm->buffer_frame_count);
|
||||
XASSERT(padding <= stm->buffer_frame_count);
|
||||
|
||||
if (stm->draining) {
|
||||
if (padding == 0) {
|
||||
@ -572,7 +567,7 @@ wasapi_stream_render_loop(LPVOID stream)
|
||||
}
|
||||
break;
|
||||
case WAIT_TIMEOUT:
|
||||
assert(stm->shutdown_event == wait_array[0]);
|
||||
XASSERT(stm->shutdown_event == wait_array[0]);
|
||||
is_playing = false;
|
||||
hr = -1;
|
||||
break;
|
||||
@ -628,7 +623,7 @@ HRESULT register_notification_client(cubeb_stream * stm)
|
||||
|
||||
HRESULT unregister_notification_client(cubeb_stream * stm)
|
||||
{
|
||||
assert(stm);
|
||||
XASSERT(stm);
|
||||
|
||||
if (!stm->device_enumerator) {
|
||||
return S_OK;
|
||||
@ -768,7 +763,7 @@ wasapi_get_max_channel_count(cubeb * ctx, uint32_t * max_channels)
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
assert(ctx && max_channels);
|
||||
XASSERT(ctx && max_channels);
|
||||
|
||||
IMMDevice * device;
|
||||
hr = get_default_endpoint(&device);
|
||||
@ -920,7 +915,7 @@ handle_channel_layout(cubeb_stream * stm, WAVEFORMATEX ** mix_format, const cub
|
||||
format_pcm->dwChannelMask = KSAUDIO_SPEAKER_STEREO;
|
||||
break;
|
||||
default:
|
||||
assert(false && "Channel layout not supported.");
|
||||
XASSERT(false && "Channel layout not supported.");
|
||||
break;
|
||||
}
|
||||
(*mix_format)->nChannels = stream_params->channels;
|
||||
@ -941,7 +936,7 @@ handle_channel_layout(cubeb_stream * stm, WAVEFORMATEX ** mix_format, const cub
|
||||
* eventual upmix/downmix ourselves */
|
||||
LOG("Using WASAPI suggested format: channels: %d\n", closest->nChannels);
|
||||
WAVEFORMATEXTENSIBLE * closest_pcm = reinterpret_cast<WAVEFORMATEXTENSIBLE *>(closest);
|
||||
assert(closest_pcm->SubFormat == format_pcm->SubFormat);
|
||||
XASSERT(closest_pcm->SubFormat == format_pcm->SubFormat);
|
||||
CoTaskMemFree(*mix_format);
|
||||
*mix_format = closest;
|
||||
} else if (hr == AUDCLNT_E_UNSUPPORTED_FORMAT) {
|
||||
@ -967,7 +962,7 @@ int setup_wasapi_stream(cubeb_stream * stm)
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
assert(!stm->client && "WASAPI stream already setup, close it first.");
|
||||
XASSERT(!stm->client && "WASAPI stream already setup, close it first.");
|
||||
|
||||
hr = get_default_endpoint(&device);
|
||||
if (FAILED(hr)) {
|
||||
@ -1096,11 +1091,11 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream,
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
assert(context && stream);
|
||||
XASSERT(context && stream);
|
||||
|
||||
cubeb_stream * stm = (cubeb_stream *)calloc(1, sizeof(cubeb_stream));
|
||||
|
||||
assert(stm);
|
||||
XASSERT(stm);
|
||||
|
||||
stm->context = context;
|
||||
stm->data_callback = data_callback;
|
||||
@ -1160,7 +1155,7 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream,
|
||||
|
||||
void close_wasapi_stream(cubeb_stream * stm)
|
||||
{
|
||||
assert(stm);
|
||||
XASSERT(stm);
|
||||
|
||||
stm->stream_reset_lock->assert_current_thread_owns();
|
||||
|
||||
@ -1181,7 +1176,7 @@ void close_wasapi_stream(cubeb_stream * stm)
|
||||
|
||||
void wasapi_stream_destroy(cubeb_stream * stm)
|
||||
{
|
||||
assert(stm);
|
||||
XASSERT(stm);
|
||||
|
||||
unregister_notification_client(stm);
|
||||
|
||||
@ -1204,7 +1199,7 @@ int wasapi_stream_start(cubeb_stream * stm)
|
||||
{
|
||||
auto_lock lock(stm->stream_reset_lock);
|
||||
|
||||
assert(stm && !stm->thread && !stm->shutdown_event);
|
||||
XASSERT(stm && !stm->thread && !stm->shutdown_event);
|
||||
|
||||
stm->shutdown_event = CreateEvent(NULL, 0, 0, NULL);
|
||||
if (!stm->shutdown_event) {
|
||||
@ -1231,7 +1226,7 @@ int wasapi_stream_start(cubeb_stream * stm)
|
||||
|
||||
int wasapi_stream_stop(cubeb_stream * stm)
|
||||
{
|
||||
assert(stm);
|
||||
XASSERT(stm);
|
||||
|
||||
auto_lock lock(stm->stream_reset_lock);
|
||||
|
||||
@ -1253,7 +1248,7 @@ int wasapi_stream_stop(cubeb_stream * stm)
|
||||
|
||||
int wasapi_stream_get_position(cubeb_stream * stm, uint64_t * position)
|
||||
{
|
||||
assert(stm && position);
|
||||
XASSERT(stm && position);
|
||||
|
||||
*position = clock_get(stm);
|
||||
|
||||
@ -1262,7 +1257,7 @@ int wasapi_stream_get_position(cubeb_stream * stm, uint64_t * position)
|
||||
|
||||
int wasapi_stream_get_latency(cubeb_stream * stm, uint32_t * latency)
|
||||
{
|
||||
assert(stm && latency);
|
||||
XASSERT(stm && latency);
|
||||
|
||||
auto_lock lock(stm->stream_reset_lock);
|
||||
|
||||
@ -1295,7 +1290,7 @@ int wasapi_stream_set_volume(cubeb_stream * stm, float volume)
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
assert(channels <= 10 && "bump the array size");
|
||||
XASSERT(channels <= 10 && "bump the array size");
|
||||
|
||||
for (uint32_t i = 0; i < channels; i++) {
|
||||
volumes[i] = volume;
|
||||
|
@ -4,7 +4,6 @@
|
||||
* This program is made available under an ISC-style license. See the
|
||||
* accompanying file LICENSE for details.
|
||||
*/
|
||||
#undef NDEBUG
|
||||
#define __MSVCRT_VERSION__ 0x0700
|
||||
#undef WINVER
|
||||
#define WINVER 0x0501
|
||||
@ -12,11 +11,11 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <malloc.h>
|
||||
#include <assert.h>
|
||||
#include <windows.h>
|
||||
#include <mmreg.h>
|
||||
#include <mmsystem.h>
|
||||
#include <process.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "cubeb/cubeb.h"
|
||||
@ -95,7 +94,7 @@ bytes_per_frame(cubeb_stream_params params)
|
||||
bytes = sizeof(float);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
XASSERT(0);
|
||||
}
|
||||
|
||||
return bytes * params.channels;
|
||||
@ -106,10 +105,10 @@ winmm_get_next_buffer(cubeb_stream * stm)
|
||||
{
|
||||
WAVEHDR * hdr = NULL;
|
||||
|
||||
assert(stm->free_buffers > 0 && stm->free_buffers <= NBUFS);
|
||||
XASSERT(stm->free_buffers > 0 && stm->free_buffers <= NBUFS);
|
||||
hdr = &stm->buffers[stm->next_buffer];
|
||||
assert(hdr->dwFlags & WHDR_PREPARED ||
|
||||
(hdr->dwFlags & WHDR_DONE && !(hdr->dwFlags & WHDR_INQUEUE)));
|
||||
XASSERT(hdr->dwFlags & WHDR_PREPARED ||
|
||||
(hdr->dwFlags & WHDR_DONE && !(hdr->dwFlags & WHDR_INQUEUE)));
|
||||
stm->next_buffer = (stm->next_buffer + 1) % NBUFS;
|
||||
stm->free_buffers -= 1;
|
||||
|
||||
@ -126,7 +125,7 @@ winmm_refill_stream(cubeb_stream * stm)
|
||||
|
||||
EnterCriticalSection(&stm->lock);
|
||||
stm->free_buffers += 1;
|
||||
assert(stm->free_buffers > 0 && stm->free_buffers <= NBUFS);
|
||||
XASSERT(stm->free_buffers > 0 && stm->free_buffers <= NBUFS);
|
||||
|
||||
if (stm->draining) {
|
||||
LeaveCriticalSection(&stm->lock);
|
||||
@ -155,17 +154,17 @@ winmm_refill_stream(cubeb_stream * stm)
|
||||
if (got < 0) {
|
||||
LeaveCriticalSection(&stm->lock);
|
||||
/* XXX handle this case */
|
||||
assert(0);
|
||||
XASSERT(0);
|
||||
return;
|
||||
} else if (got < wanted) {
|
||||
stm->draining = 1;
|
||||
}
|
||||
stm->written += got;
|
||||
|
||||
assert(hdr->dwFlags & WHDR_PREPARED);
|
||||
XASSERT(hdr->dwFlags & WHDR_PREPARED);
|
||||
|
||||
hdr->dwBufferLength = got * bytes_per_frame(stm->params);
|
||||
assert(hdr->dwBufferLength <= stm->buffer_size);
|
||||
XASSERT(hdr->dwBufferLength <= stm->buffer_size);
|
||||
|
||||
if (stm->soft_volume != -1.0) {
|
||||
if (stm->params.format == CUBEB_SAMPLE_FLOAT32NE) {
|
||||
@ -197,14 +196,14 @@ static unsigned __stdcall
|
||||
winmm_buffer_thread(void * user_ptr)
|
||||
{
|
||||
cubeb * ctx = (cubeb *) user_ptr;
|
||||
assert(ctx);
|
||||
XASSERT(ctx);
|
||||
|
||||
for (;;) {
|
||||
DWORD r;
|
||||
PSLIST_ENTRY item;
|
||||
|
||||
r = WaitForSingleObject(ctx->event, INFINITE);
|
||||
assert(r == WAIT_OBJECT_0);
|
||||
XASSERT(r == WAIT_OBJECT_0);
|
||||
|
||||
/* Process work items in batches so that a single stream can't
|
||||
starve the others by continuously adding new work to the top of
|
||||
@ -236,7 +235,7 @@ winmm_buffer_callback(HWAVEOUT waveout, UINT msg, DWORD_PTR user_ptr, DWORD_PTR
|
||||
}
|
||||
|
||||
item = _aligned_malloc(sizeof(struct cubeb_stream_item), MEMORY_ALLOCATION_ALIGNMENT);
|
||||
assert(item);
|
||||
XASSERT(item);
|
||||
item->stream = stm;
|
||||
InterlockedPushEntrySList(stm->context->work, &item->head);
|
||||
|
||||
@ -278,16 +277,16 @@ winmm_init(cubeb ** context, char const * context_name)
|
||||
{
|
||||
cubeb * ctx;
|
||||
|
||||
assert(context);
|
||||
XASSERT(context);
|
||||
*context = NULL;
|
||||
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
assert(ctx);
|
||||
XASSERT(ctx);
|
||||
|
||||
ctx->ops = &winmm_ops;
|
||||
|
||||
ctx->work = _aligned_malloc(sizeof(*ctx->work), MEMORY_ALLOCATION_ALIGNMENT);
|
||||
assert(ctx->work);
|
||||
XASSERT(ctx->work);
|
||||
InitializeSListHead(ctx->work);
|
||||
|
||||
ctx->event = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
@ -325,8 +324,8 @@ winmm_destroy(cubeb * ctx)
|
||||
{
|
||||
DWORD r;
|
||||
|
||||
assert(ctx->active_streams == 0);
|
||||
assert(!InterlockedPopEntrySList(ctx->work));
|
||||
XASSERT(ctx->active_streams == 0);
|
||||
XASSERT(!InterlockedPopEntrySList(ctx->work));
|
||||
|
||||
DeleteCriticalSection(&ctx->lock);
|
||||
|
||||
@ -334,7 +333,7 @@ winmm_destroy(cubeb * ctx)
|
||||
ctx->shutdown = 1;
|
||||
SetEvent(ctx->event);
|
||||
r = WaitForSingleObject(ctx->thread, INFINITE);
|
||||
assert(r == WAIT_OBJECT_0);
|
||||
XASSERT(r == WAIT_OBJECT_0);
|
||||
CloseHandle(ctx->thread);
|
||||
}
|
||||
|
||||
@ -362,8 +361,8 @@ winmm_stream_init(cubeb * context, cubeb_stream ** stream, char const * stream_n
|
||||
int i;
|
||||
size_t bufsz;
|
||||
|
||||
assert(context);
|
||||
assert(stream);
|
||||
XASSERT(context);
|
||||
XASSERT(stream);
|
||||
|
||||
*stream = NULL;
|
||||
|
||||
@ -413,7 +412,7 @@ winmm_stream_init(cubeb * context, cubeb_stream ** stream, char const * stream_n
|
||||
LeaveCriticalSection(&context->lock);
|
||||
|
||||
stm = calloc(1, sizeof(*stm));
|
||||
assert(stm);
|
||||
XASSERT(stm);
|
||||
|
||||
stm->context = context;
|
||||
|
||||
@ -432,7 +431,7 @@ winmm_stream_init(cubeb * context, cubeb_stream ** stream, char const * stream_n
|
||||
if (bufsz % bytes_per_frame(stm->params) != 0) {
|
||||
bufsz += bytes_per_frame(stm->params) - (bufsz % bytes_per_frame(stm->params));
|
||||
}
|
||||
assert(bufsz % bytes_per_frame(stm->params) == 0);
|
||||
XASSERT(bufsz % bytes_per_frame(stm->params) == 0);
|
||||
|
||||
stm->buffer_size = bufsz;
|
||||
|
||||
@ -467,7 +466,7 @@ winmm_stream_init(cubeb * context, cubeb_stream ** stream, char const * stream_n
|
||||
WAVEHDR * hdr = &stm->buffers[i];
|
||||
|
||||
hdr->lpData = calloc(1, bufsz);
|
||||
assert(hdr->lpData);
|
||||
XASSERT(hdr->lpData);
|
||||
hdr->dwBufferLength = bufsz;
|
||||
hdr->dwFlags = 0;
|
||||
|
||||
@ -504,7 +503,7 @@ winmm_stream_destroy(cubeb_stream * stm)
|
||||
/* Wait for all blocks to complete. */
|
||||
while (enqueued > 0) {
|
||||
r = WaitForSingleObject(stm->event, INFINITE);
|
||||
assert(r == WAIT_OBJECT_0);
|
||||
XASSERT(r == WAIT_OBJECT_0);
|
||||
|
||||
EnterCriticalSection(&stm->lock);
|
||||
enqueued = NBUFS - stm->free_buffers;
|
||||
@ -535,7 +534,7 @@ winmm_stream_destroy(cubeb_stream * stm)
|
||||
}
|
||||
|
||||
EnterCriticalSection(&stm->context->lock);
|
||||
assert(stm->context->active_streams >= 1);
|
||||
XASSERT(stm->context->active_streams >= 1);
|
||||
stm->context->active_streams -= 1;
|
||||
LeaveCriticalSection(&stm->context->lock);
|
||||
|
||||
@ -545,7 +544,7 @@ winmm_stream_destroy(cubeb_stream * stm)
|
||||
static int
|
||||
winmm_get_max_channel_count(cubeb * ctx, uint32_t * max_channels)
|
||||
{
|
||||
assert(ctx && max_channels);
|
||||
XASSERT(ctx && max_channels);
|
||||
|
||||
/* We don't support more than two channels in this backend. */
|
||||
*max_channels = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user