From 223b5fab18963adb232aaf7293b03c502d03ddd8 Mon Sep 17 00:00:00 2001 From: selim mustafaev Date: Thu, 30 Mar 2017 23:16:44 +0300 Subject: [PATCH] some code for audio support --- examples/ffPlayer.cpp | 19 +++++++++++++++++++ include/ffcpp/Player.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/examples/ffPlayer.cpp b/examples/ffPlayer.cpp index 6dde1a8..b9f7b4b 100644 --- a/examples/ffPlayer.cpp +++ b/examples/ffPlayer.cpp @@ -22,6 +22,9 @@ private: SDLWindowPtr _wnd; SDLRendererPtr _renderer; SDLTexturePtr _texture; + SDL_AudioSpec _audioSpec; + SDL_AudioDeviceID _aDevId; + std::packaged_task _renderTask; public: @@ -37,6 +40,17 @@ public: _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"); + + 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() { @@ -55,6 +69,11 @@ public: } } +private: + static void audioCallback(void* userdata, Uint8* stream, int len) { + + } + public: virtual AVPixelFormat getPixelFormat() const noexcept override { return AV_PIX_FMT_YUV420P; diff --git a/include/ffcpp/Player.h b/include/ffcpp/Player.h index ca85cf8..e4bbd4f 100644 --- a/include/ffcpp/Player.h +++ b/include/ffcpp/Player.h @@ -8,6 +8,7 @@ #include #include #include +#include namespace ffcpp { @@ -18,6 +19,11 @@ namespace ffcpp { int uPitch, int vPitch) = 0; }; + struct IAudioSink { + virtual void setPauseCallback(std::function callback) = 0; + virtual void setAudioDataCallback(std::function callback) = 0; + }; + enum class PlayerState { Shutdown, Stopped,