Sound für synchrone Wiedergabe geändert
This commit is contained in:
37
include/audiothread.h
Normal file
37
include/audiothread.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
#include <atomic>
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
// Audio passthrough: captures from the grabber's ALSA device and plays it
|
||||
// straight to the default output with small buffers (low latency, so the
|
||||
// sound stays in sync with the video preview). Same implementation as in
|
||||
// the HDMI viewer.
|
||||
class AudioThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AudioThread(const QString &device, QObject *parent = nullptr);
|
||||
~AudioThread() override;
|
||||
|
||||
void stop();
|
||||
|
||||
signals:
|
||||
void errorOccurred(const QString &message);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
QString m_device;
|
||||
std::atomic<bool> m_running{false};
|
||||
|
||||
// PCM parameters
|
||||
static constexpr unsigned int k_defaultRate = 48000;
|
||||
static constexpr unsigned int k_defaultChannels = 2;
|
||||
static constexpr snd_pcm_uframes_t k_periodFrames = 1024;
|
||||
};
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <QProcess>
|
||||
|
||||
#include "v4l2worker.h"
|
||||
#include "audiothread.h"
|
||||
|
||||
// A uniform, icon-only push button used for the video toolbar (start/stop,
|
||||
// freeze, screenshot, record, fullscreen, audio, ...). All toolbar buttons
|
||||
@@ -142,14 +143,12 @@ private:
|
||||
|
||||
// Audio passthrough: plays the grabber's ALSA capture device (e.g. the
|
||||
// "USB Audio" card that accompanies a /dev/videoN HDMI/USB grabber)
|
||||
// straight to the default output, the same way the HDMI viewer does it.
|
||||
// Implemented by shelling out to `ffplay -f alsa -i <device>` with
|
||||
// -nodisp (audio only, no extra window) - same approach as recording,
|
||||
// just piping the other direction (device -> speakers instead of
|
||||
// frames -> file).
|
||||
// straight to the default output. Uses the same native ALSA
|
||||
// capture->playback thread (AudioThread) as the HDMI viewer, with small
|
||||
// buffers so the sound stays in sync with the video preview.
|
||||
QComboBox *m_audioCombo = nullptr;
|
||||
QPushButton *m_audioBtn = nullptr;
|
||||
QProcess *m_audioProcess = nullptr;
|
||||
AudioThread *m_audioThread = nullptr;
|
||||
bool m_audioActive = false;
|
||||
|
||||
// Fullscreen overlay window (nullptr when not open). Owns itself via
|
||||
|
||||
Reference in New Issue
Block a user