确保线程安全

This commit is contained in:
ziyue 2021-06-29 17:53:26 +08:00
parent 1b674a6ac2
commit 013109796d
2 changed files with 4 additions and 1 deletions

View File

@ -113,6 +113,7 @@ int AudioPlayer::getPCMChannel() {
}
int AudioPlayer::getPCMData(char *buf, int size) {
lock_guard<mutex> lck(_mtx);
if (_buffer.size() < size) {
return 0;
}
@ -121,6 +122,7 @@ int AudioPlayer::getPCMData(char *buf, int size) {
return size;
}
void AudioPlayer::inputFrame(const char *data, size_t size){
void AudioPlayer::inputFrame(const char *data, size_t size) {
lock_guard<mutex> lck(_mtx);
_buffer.append(data, size);
}

View File

@ -79,6 +79,7 @@ private:
private:
int _sample_rate, _channel;
SDL_AudioFormat _format;
mutex _mtx;
BufferLikeString _buffer;
SDLAudioDevice::Ptr _device;
};