Commit 01310979 by ziyue

确保线程安全

parent 1b674a6a
...@@ -113,6 +113,7 @@ int AudioPlayer::getPCMChannel() { ...@@ -113,6 +113,7 @@ int AudioPlayer::getPCMChannel() {
} }
int AudioPlayer::getPCMData(char *buf, int size) { int AudioPlayer::getPCMData(char *buf, int size) {
lock_guard<mutex> lck(_mtx);
if (_buffer.size() < size) { if (_buffer.size() < size) {
return 0; return 0;
} }
...@@ -121,6 +122,7 @@ int AudioPlayer::getPCMData(char *buf, int size) { ...@@ -121,6 +122,7 @@ int AudioPlayer::getPCMData(char *buf, int size) {
return 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); _buffer.append(data, size);
} }
...@@ -79,6 +79,7 @@ private: ...@@ -79,6 +79,7 @@ private:
private: private:
int _sample_rate, _channel; int _sample_rate, _channel;
SDL_AudioFormat _format; SDL_AudioFormat _format;
mutex _mtx;
BufferLikeString _buffer; BufferLikeString _buffer;
SDLAudioDevice::Ptr _device; SDLAudioDevice::Ptr _device;
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论