Skip to content

Commit 30df0b2

Browse files
committed
[ogg_opus_player] fix global init sdl2 audio subsystem
1 parent 245ee4f commit 30df0b2

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

packages/ogg_opus_player/src/ogg_opus_player.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "dart_api_dl.h"
1212
#include "SDL.h"
1313

14+
#include "ogg_opus_utils.h"
15+
1416
//#define _OPUS_OGG_PLAYER_LOG
1517

1618
namespace {
@@ -167,11 +169,7 @@ void SdlOggOpusPlayer::ReadAudioData(Uint8 *stream, int len) {
167169
bool global_init = false;
168170

169171
int SdlOggOpusPlayer::Initialize() {
170-
171-
if (!global_init) {
172-
SDL_InitSubSystem(SDL_INIT_AUDIO);
173-
global_init = true;
174-
}
172+
global_init_sdl2();
175173

176174
SDL_AudioSpec wanted_spec, spec;
177175
wanted_spec.silence = 0;
@@ -226,6 +224,13 @@ double SdlOggOpusPlayer::CurrentTime() {
226224

227225
}
228226

227+
void global_init_sdl2() {
228+
if (!global_init) {
229+
SDL_InitSubSystem(SDL_INIT_AUDIO);
230+
global_init = true;
231+
}
232+
}
233+
229234
void *ogg_opus_player_create(const char *file_path, Dart_Port_DL send_port) {
230235
auto *player = new SdlOggOpusPlayer(file_path, send_port);
231236
return player;

packages/ogg_opus_player/src/ogg_opus_recorder.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <iostream>
1111

1212
#include "SDL.h"
13+
#include "ogg_opus_utils.h"
1314

1415
namespace {
1516

@@ -92,6 +93,9 @@ class SdlOggOpusRecorder {
9293
void WriteAudioData(Uint8 *stream, int size);
9394
};
9495
int SdlOggOpusRecorder::Init(const char *file_name) {
96+
97+
global_init_sdl2();
98+
9599
SDL_AudioSpec wanted_spec;
96100
SDL_AudioSpec spec;
97101
wanted_spec.freq = 16000;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Created by yangbin on 2022/8/2.
3+
//
4+
5+
#ifndef OGG_OPUS_PLAYER_LIBRARY__OGG_OPUS_UTILS_H_
6+
#define OGG_OPUS_PLAYER_LIBRARY__OGG_OPUS_UTILS_H_
7+
8+
9+
void global_init_sdl2();
10+
11+
#endif //OGG_OPUS_PLAYER_LIBRARY__OGG_OPUS_UTILS_H_

0 commit comments

Comments
 (0)