some code for audio support
This commit is contained in:
parent
36d3ab2a6e
commit
223b5fab18
@ -22,6 +22,9 @@ private:
|
|||||||
SDLWindowPtr _wnd;
|
SDLWindowPtr _wnd;
|
||||||
SDLRendererPtr _renderer;
|
SDLRendererPtr _renderer;
|
||||||
SDLTexturePtr _texture;
|
SDLTexturePtr _texture;
|
||||||
|
SDL_AudioSpec _audioSpec;
|
||||||
|
SDL_AudioDeviceID _aDevId;
|
||||||
|
|
||||||
std::packaged_task<void()> _renderTask;
|
std::packaged_task<void()> _renderTask;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -37,6 +40,17 @@ public:
|
|||||||
|
|
||||||
_texture.reset(SDL_CreateTexture(_renderer.get(), SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, WINDOW_WIDTH, WINDOW_HEIGHT));
|
_texture.reset(SDL_CreateTexture(_renderer.get(), SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, WINDOW_WIDTH, WINDOW_HEIGHT));
|
||||||
if(!_texture) throw std::runtime_error("Error creating SDL texture");
|
if(!_texture) throw std::runtime_error("Error creating SDL texture");
|
||||||
|
|
||||||
|
SDL_AudioSpec want;
|
||||||
|
SDL_zero(want);
|
||||||
|
want.freq = 44100;
|
||||||
|
want.format = AUDIO_S16;
|
||||||
|
want.channels = 2;
|
||||||
|
want.samples = 4096;
|
||||||
|
want.callback = SDLWindow::audioCallback;
|
||||||
|
|
||||||
|
_aDevId = SDL_OpenAudioDevice(nullptr, 0, &want, &_audioSpec, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||||
|
if(_aDevId == 0) throw std::runtime_error("Error opening audio device");
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleEvents() {
|
void handleEvents() {
|
||||||
@ -55,6 +69,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void audioCallback(void* userdata, Uint8* stream, int len) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual AVPixelFormat getPixelFormat() const noexcept override {
|
virtual AVPixelFormat getPixelFormat() const noexcept override {
|
||||||
return AV_PIX_FMT_YUV420P;
|
return AV_PIX_FMT_YUV420P;
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace ffcpp {
|
namespace ffcpp {
|
||||||
|
|
||||||
@ -18,6 +19,11 @@ namespace ffcpp {
|
|||||||
int uPitch, int vPitch) = 0;
|
int uPitch, int vPitch) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct IAudioSink {
|
||||||
|
virtual void setPauseCallback(std::function<void(bool)> callback) = 0;
|
||||||
|
virtual void setAudioDataCallback(std::function<void(uint8_t*,size_t)> callback) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
enum class PlayerState {
|
enum class PlayerState {
|
||||||
Shutdown,
|
Shutdown,
|
||||||
Stopped,
|
Stopped,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user