mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor/Create APT/DNF Repository (#1648)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include <grabber/AudioGrabber.h>
|
||||
#include <grabber/audio/AudioGrabber.h>
|
||||
#include <math.h>
|
||||
#include <QImage>
|
||||
#include <QObject>
|
||||
|
@@ -1,11 +1,31 @@
|
||||
#include <grabber/AudioGrabberLinux.h>
|
||||
#include <grabber/audio/AudioGrabberLinux.h>
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
typedef void* (*THREADFUNCPTR)(void*);
|
||||
static void * AudioThreadRunner(void* params)
|
||||
{
|
||||
AudioGrabberLinux* This = static_cast<AudioGrabberLinux*>(params);
|
||||
|
||||
Debug(This->getLog(), "Audio Thread Started");
|
||||
|
||||
snd_pcm_sframes_t framesAvailable = 0;
|
||||
|
||||
while (This->_isRunning.load(std::memory_order_acquire))
|
||||
{
|
||||
snd_pcm_wait(This->_captureDevice, 1000);
|
||||
|
||||
if ((framesAvailable = snd_pcm_avail(This->_captureDevice)) > 0)
|
||||
This->processAudioBuffer(framesAvailable);
|
||||
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
Debug(This->getLog(), "Audio Thread Shutting Down");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AudioGrabberLinux::AudioGrabberLinux()
|
||||
: AudioGrabber()
|
||||
@@ -121,7 +141,7 @@ bool AudioGrabberLinux::configureCaptureInterface()
|
||||
snd_pcm_close(_captureDevice);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ((error = snd_pcm_hw_params_set_access(_captureDevice, _captureDeviceConfig, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
|
||||
{
|
||||
Error(_log, "Failed to configure interleaved mode: %s", snd_strerror(error));
|
||||
@@ -129,7 +149,7 @@ bool AudioGrabberLinux::configureCaptureInterface()
|
||||
snd_pcm_close(_captureDevice);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if ((error = snd_pcm_hw_params_set_format(_captureDevice, _captureDeviceConfig, SND_PCM_FORMAT_S16_LE)) < 0)
|
||||
{
|
||||
Error(_log, "Failed to configure capture format: %s", snd_strerror(error));
|
||||
@@ -169,7 +189,7 @@ bool AudioGrabberLinux::configureCaptureInterface()
|
||||
snd_pcm_close(_captureDevice);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -189,11 +209,6 @@ bool AudioGrabberLinux::start()
|
||||
_isRunning.store(true, std::memory_order_release);
|
||||
|
||||
pthread_attr_t threadAttributes;
|
||||
int threadPriority = 1;
|
||||
|
||||
sched_param schedulerParameter;
|
||||
schedulerParameter.sched_priority = threadPriority;
|
||||
|
||||
if (pthread_attr_init(&threadAttributes) != 0)
|
||||
{
|
||||
Debug(_log, "Failed to create thread attributes");
|
||||
@@ -201,7 +216,7 @@ bool AudioGrabberLinux::start()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pthread_create(&_audioThread, &threadAttributes, static_cast<THREADFUNCPTR>(&AudioThreadRunner), static_cast<void*>(this)) != 0)
|
||||
if (pthread_create(&_audioThread, &threadAttributes, &AudioThreadRunner, static_cast<void*>(this)) != 0)
|
||||
{
|
||||
Debug(_log, "Failed to create audio capture thread");
|
||||
stop();
|
||||
@@ -239,7 +254,7 @@ void AudioGrabberLinux::processAudioBuffer(snd_pcm_sframes_t frames)
|
||||
ssize_t bytes = snd_pcm_frames_to_bytes(_captureDevice, frames);
|
||||
|
||||
int16_t * buffer = static_cast<int16_t*>(calloc(static_cast<size_t>(bytes / 2), sizeof(int16_t)));
|
||||
|
||||
|
||||
if (frames == 0)
|
||||
{
|
||||
buffer[0] = 0;
|
||||
@@ -293,25 +308,3 @@ QString AudioGrabberLinux::getDeviceName(const QString& devicePath) const
|
||||
|
||||
return _deviceProperties.value(devicePath).name;
|
||||
}
|
||||
|
||||
static void * AudioThreadRunner(void* params)
|
||||
{
|
||||
AudioGrabberLinux* This = static_cast<AudioGrabberLinux*>(params);
|
||||
|
||||
Debug(This->getLog(), "Audio Thread Started");
|
||||
|
||||
snd_pcm_sframes_t framesAvailable = 0;
|
||||
|
||||
while (This->_isRunning.load(std::memory_order_acquire))
|
||||
{
|
||||
snd_pcm_wait(This->_captureDevice, 1000);
|
||||
|
||||
if ((framesAvailable = snd_pcm_avail(This->_captureDevice)) > 0)
|
||||
This->processAudioBuffer(framesAvailable);
|
||||
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
Debug(This->getLog(), "Audio Thread Shutting Down");
|
||||
return nullptr;
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <grabber/AudioGrabberWindows.h>
|
||||
#include <grabber/audio/AudioGrabberWindows.h>
|
||||
|
||||
#include <climits>
|
||||
|
||||
@@ -71,7 +71,7 @@ bool AudioGrabberWindows::configureCaptureInterface()
|
||||
notificationSize -= notificationSize % audioFormat.nBlockAlign;
|
||||
|
||||
bufferCaptureSize = notificationSize * AUDIO_NOTIFICATION_COUNT;
|
||||
|
||||
|
||||
DSCBUFFERDESC bufferDesc;
|
||||
bufferDesc.dwSize = sizeof(DSCBUFFERDESC);
|
||||
bufferDesc.dwFlags = 0;
|
||||
@@ -80,7 +80,7 @@ bool AudioGrabberWindows::configureCaptureInterface()
|
||||
bufferDesc.lpwfxFormat = &audioFormat;
|
||||
bufferDesc.dwFXCount = 0;
|
||||
bufferDesc.lpDSCFXDesc = NULL;
|
||||
|
||||
|
||||
// Create Capture Device's Buffer
|
||||
LPDIRECTSOUNDCAPTUREBUFFER preBuffer;
|
||||
if (FAILED(recordingDevice->CreateCaptureBuffer(&bufferDesc, &preBuffer, NULL)))
|
||||
@@ -101,7 +101,7 @@ bool AudioGrabberWindows::configureCaptureInterface()
|
||||
}
|
||||
|
||||
preBuffer->Release();
|
||||
|
||||
|
||||
// Create Notifications
|
||||
LPDIRECTSOUNDNOTIFY8 notify;
|
||||
|
||||
@@ -112,7 +112,7 @@ bool AudioGrabberWindows::configureCaptureInterface()
|
||||
recordingBuffer->Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Create Events
|
||||
notificationEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
|
||||
@@ -133,11 +133,11 @@ bool AudioGrabberWindows::configureCaptureInterface()
|
||||
positionNotify[i].dwOffset = (notificationSize * i) + notificationSize - 1;
|
||||
positionNotify[i].hEventNotify = notificationEvent;
|
||||
}
|
||||
|
||||
|
||||
// Set Notifications
|
||||
notify->SetNotificationPositions(AUDIO_NOTIFICATION_COUNT, positionNotify);
|
||||
notify->Release();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -162,12 +162,12 @@ bool AudioGrabberWindows::start()
|
||||
}
|
||||
|
||||
Info(_log, "Capture audio from %s", QSTRING_CSTR(getDeviceName(_device)));
|
||||
|
||||
|
||||
if (!this->configureCaptureInterface())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (FAILED(recordingBuffer->Start(DSCBSTART_LOOPING)))
|
||||
{
|
||||
Error(_log, "Failed starting audio capture from '%s'", QSTRING_CSTR(getDeviceName(_device)));
|
||||
@@ -214,7 +214,7 @@ void AudioGrabberWindows::stop()
|
||||
{
|
||||
Error(_log, "Audio capture failed to stop: '%s'", QSTRING_CSTR(getDeviceName(_device)));
|
||||
}
|
||||
|
||||
|
||||
if (FAILED(recordingBuffer->Release()))
|
||||
{
|
||||
Error(_log, "Failed to release recording buffer: '%s'", QSTRING_CSTR(getDeviceName(_device)));
|
||||
@@ -306,7 +306,7 @@ void AudioGrabberWindows::processAudioBuffer()
|
||||
|
||||
// Buffer wrapped around, read second position
|
||||
if (capturedAudio2 != NULL)
|
||||
{
|
||||
{
|
||||
bufferCapturePosition += capturedAudio2Length;
|
||||
bufferCapturePosition %= bufferCaptureSize; // Circular Buffer
|
||||
}
|
||||
@@ -318,13 +318,13 @@ void AudioGrabberWindows::processAudioBuffer()
|
||||
{
|
||||
CopyMemory(readBuffer + capturedAudioLength, capturedAudio2, capturedAudio2Length);
|
||||
}
|
||||
|
||||
|
||||
// Release Buffer Lock
|
||||
recordingBuffer->Unlock(capturedAudio, capturedAudioLength, capturedAudio2, capturedAudio2Length);
|
||||
|
||||
|
||||
// Process Audio Frame
|
||||
this->processAudioFrame(readBuffer, frameSize);
|
||||
|
||||
|
||||
delete[] readBuffer;
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <grabber/AudioWrapper.h>
|
||||
#include <grabber/audio/AudioWrapper.h>
|
||||
#include <hyperion/GrabberWrapper.h>
|
||||
#include <QObject>
|
||||
#include <QMetaType>
|
||||
|
@@ -1,35 +1,38 @@
|
||||
# Define the current source locations
|
||||
SET( CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/grabber )
|
||||
SET( CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/audio )
|
||||
|
||||
if (WIN32)
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
FILE ( GLOB AUDIO_GRABBER_SOURCES "${CURRENT_HEADER_DIR}/Audio*Windows.h" "${CURRENT_HEADER_DIR}/AudioGrabber.h" "${CURRENT_HEADER_DIR}/AudioWrapper.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*Windows.cpp" "${CURRENT_SOURCE_DIR}/AudioGrabber.cpp" "${CURRENT_SOURCE_DIR}/AudioWrapper.cpp")
|
||||
elseif(${CMAKE_SYSTEM} MATCHES "Linux")
|
||||
FILE ( GLOB AUDIO_GRABBER_SOURCES "${CURRENT_HEADER_DIR}/Audio*Linux.h" "${CURRENT_HEADER_DIR}/AudioGrabber.h" "${CURRENT_HEADER_DIR}/AudioWrapper.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*Linux.cpp" "${CURRENT_SOURCE_DIR}/AudioGrabber.cpp" "${CURRENT_SOURCE_DIR}/AudioWrapper.cpp")
|
||||
elseif (APPLE)
|
||||
#TODO
|
||||
#FILE ( GLOB AUDIO_GRABBER_SOURCES "${CURRENT_HEADER_DIR}/Audio*Apple.h" "${CURRENT_HEADER_DIR}/AudioGrabber.h" "${CURRENT_HEADER_DIR}/AudioWrapper.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*Apple.cpp" "${CURRENT_SOURCE_DIR}/AudioGrabber.cpp" "${CURRENT_SOURCE_DIR}/AudioWrapper.cpp")
|
||||
if(WIN32)
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
set(AUDIO_GRABBER_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/include/grabber/audio/AudioGrabberWindows.h
|
||||
${CMAKE_SOURCE_DIR}/libsrc/grabber/audio/AudioGrabberWindows.cpp
|
||||
)
|
||||
elseif(CMAKE_HOST_UNIX AND NOT APPLE)
|
||||
set(AUDIO_GRABBER_SOURCES
|
||||
${CMAKE_SOURCE_DIR}/include/grabber/audio/AudioGrabberLinux.h
|
||||
${CMAKE_SOURCE_DIR}/libsrc/grabber/audio/AudioGrabberLinux.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library( audio-grabber ${AUDIO_GRABBER_SOURCES} )
|
||||
add_library(audio-grabber
|
||||
${CMAKE_SOURCE_DIR}/include/grabber/audio/AudioGrabber.h
|
||||
${CMAKE_SOURCE_DIR}/include/grabber/audio/AudioWrapper.h
|
||||
${CMAKE_SOURCE_DIR}/libsrc/grabber/audio/AudioGrabber.cpp
|
||||
${CMAKE_SOURCE_DIR}/libsrc/grabber/audio/AudioWrapper.cpp
|
||||
${AUDIO_GRABBER_SOURCES}
|
||||
)
|
||||
|
||||
set(AUDIO_LIBS hyperion)
|
||||
|
||||
|
||||
if (WIN32)
|
||||
set(AUDIO_LIBS ${AUDIO_LIBS} DSound)
|
||||
elseif(${CMAKE_SYSTEM} MATCHES "Linux")
|
||||
find_package(ALSA REQUIRED)
|
||||
if (ALSA_FOUND)
|
||||
include_directories(${ALSA_INCLUDE_DIRS})
|
||||
set(AUDIO_LIBS ${AUDIO_LIBS} ${ALSA_LIBRARIES})
|
||||
endif(ALSA_FOUND)
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
set(AUDIO_LIBS ${AUDIO_LIBS} Threads::Threads) # PRIVATE
|
||||
if(WIN32)
|
||||
set(AUDIO_LIBS DSound)
|
||||
elseif(CMAKE_HOST_UNIX AND NOT APPLE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(ALSA REQUIRED)
|
||||
find_package(Threads REQUIRED)
|
||||
set(AUDIO_LIBS ${ALSA_LIBRARIES} Threads::Threads)
|
||||
endif()
|
||||
|
||||
target_link_libraries(audio-grabber
|
||||
hyperion
|
||||
${AUDIO_LIBS}
|
||||
)
|
||||
|
||||
target_link_libraries(audio-grabber ${AUDIO_LIBS} ${QT_LIBRARIES})
|
||||
if(CMAKE_HOST_UNIX AND NOT APPLE)
|
||||
target_include_directories(audio-grabber PUBLIC ${ALSA_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
Reference in New Issue
Block a user