1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#pragma once
#include "libvideostitch/allocator.hpp"
#include "libvideostitch/stitchOutput.hpp"
#include <QAudioOutput>
#include <condition_variable>
#include <queue>
class VS_GUI_EXPORT AudioPlayer
: public QObject,
public VideoStitch::Output::AudioWriter,
public VideoStitch::Core::PanoRenderer // fake renderer to register the video timestamps for synchronization
{
Q_OBJECT
public:
explicit AudioPlayer(QObject* parent = 0);
virtual ~AudioPlayer();
QIODevice* device();
void pushAudio(VideoStitch::Audio::Samples& audioSamples) override;
std::string getName() const override;
void render(std::shared_ptr<VideoStitch::Core::PanoOpenGLSurface>, mtime_t) override;
void renderCubemap(std::shared_ptr<VideoStitch::Core::CubemapOpenGLSurface>, mtime_t) override;
void renderEquiangularCubemap(std::shared_ptr<VideoStitch::Core::CubemapOpenGLSurface>, mtime_t) override;
public slots:
void handleStateChanged(QAudio::State);
void onActivatePlayBack(bool b);
private:
void logError(QAudio::Error err);
static void run(AudioPlayer*);
std::thread* worker;
std::mutex mu;
bool exit = false;
std::queue<VideoStitch::Audio::Samples> audioQueue;
std::atomic<mtime_t> currentTimestamp;
QAudioFormat fmt;
QAudioOutput* audioOutput;
QAudioDeviceInfo info;
QIODevice* dev = nullptr;
mtime_t delay;
qreal volume;
};