fix gc error
This commit is contained in:
30
audio.c
30
audio.c
@@ -45,9 +45,12 @@ SDL_AudioSpec js2SDL_AudioSpec(JSContext *js, JSValue v) {
|
||||
JSValue SDL_AudioSpec2js(JSContext *js, SDL_AudioSpec spec) {
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj, "format", SDL_AudioFormat2js(js, spec.format));
|
||||
JS_SetPropertyStr(js, obj, "channels", JS_NewInt32(js, spec.channels));
|
||||
JS_SetPropertyStr(js, obj, "freq", JS_NewInt32(js, spec.freq));
|
||||
JSValue _fmt = SDL_AudioFormat2js(js, spec.format);
|
||||
JS_SetPropertyStr(js, obj, "format", _fmt);
|
||||
JSValue _ch = JS_NewInt32(js, spec.channels);
|
||||
JS_SetPropertyStr(js, obj, "channels", _ch);
|
||||
JSValue _freq = JS_NewInt32(js, spec.freq);
|
||||
JS_SetPropertyStr(js, obj, "freq", _freq);
|
||||
JS_RETURN(obj);
|
||||
}
|
||||
|
||||
@@ -58,7 +61,8 @@ JSValue js_get_audio_drivers(JSContext *js, JSValue self, int argc, JSValue *arg
|
||||
JS_LOCAL(arr, JS_NewArray(js));
|
||||
for (int i = 0; i < count; i++) {
|
||||
const char *driver = SDL_GetAudioDriver(i);
|
||||
JS_SetPropertyNumber(js, arr, i, JS_NewString(js, driver));
|
||||
JSValue _s = JS_NewString(js, driver);
|
||||
JS_SetPropertyNumber(js, arr, i, _s);
|
||||
}
|
||||
JS_RETURN(arr);
|
||||
}
|
||||
@@ -74,7 +78,8 @@ JSValue js_get_audio_playback_devices(JSContext *js, JSValue self, int argc, JSV
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(arr, JS_NewArray(js));
|
||||
for (int i = 0; devices[i]; i++) {
|
||||
JS_SetPropertyNumber(js, arr, i, SDL_AudioDeviceID2js(js, devices[i]));
|
||||
JSValue _id = SDL_AudioDeviceID2js(js, devices[i]);
|
||||
JS_SetPropertyNumber(js, arr, i, _id);
|
||||
}
|
||||
SDL_free(devices);
|
||||
JS_RETURN(arr);
|
||||
@@ -86,7 +91,8 @@ JSValue js_get_audio_recording_devices(JSContext *js, JSValue self, int argc, JS
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(arr, JS_NewArray(js));
|
||||
for (int i = 0; devices[i]; i++) {
|
||||
JS_SetPropertyNumber(js, arr, i, SDL_AudioDeviceID2js(js, devices[i]));
|
||||
JSValue _id = SDL_AudioDeviceID2js(js, devices[i]);
|
||||
JS_SetPropertyNumber(js, arr, i, _id);
|
||||
}
|
||||
SDL_free(devices);
|
||||
JS_RETURN(arr);
|
||||
@@ -207,8 +213,10 @@ JSC_CCALL(audio_stream_get_format,
|
||||
} else {
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj, "src", SDL_AudioSpec2js(js, src));
|
||||
JS_SetPropertyStr(js, obj, "dst", SDL_AudioSpec2js(js, dst));
|
||||
JSValue _src = SDL_AudioSpec2js(js, src);
|
||||
JS_SetPropertyStr(js, obj, "src", _src);
|
||||
JSValue _dst = SDL_AudioSpec2js(js, dst);
|
||||
JS_SetPropertyStr(js, obj, "dst", _dst);
|
||||
JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame);
|
||||
ret = obj;
|
||||
}
|
||||
@@ -326,8 +334,10 @@ JSValue js_load_wav(JSContext *js, JSValue self, int argc, JSValue *argv) {
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj, "spec", SDL_AudioSpec2js(js, spec));
|
||||
JS_SetPropertyStr(js, obj, "data", js_new_blob_stoned_copy(js, data, len));
|
||||
JSValue _spec = SDL_AudioSpec2js(js, spec);
|
||||
JS_SetPropertyStr(js, obj, "spec", _spec);
|
||||
JSValue _data = js_new_blob_stoned_copy(js, data, len);
|
||||
JS_SetPropertyStr(js, obj, "data", _data);
|
||||
SDL_free(data);
|
||||
JS_RETURN(obj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user