mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-20 13:08:50 +02:00
ce3ae8e423
* aja: Initial commit of AJA capture/output plugin * aja: Fix clang-format on aja-output-ui code * aja: Remove script used during dev/testing * aja: Address pull request feedback from @RytoEX * aja: Remove the SDK sources and update CMakeLists to point to new headers-only/static libs dependency distribution. * aja: Only build AJA plugin on x64 on macOS for now * aja: Remove the non-English placeholder locale files. The english strings/files will be produced via crowdin, according to @ddrboxman. * aja: Add FindLibAJANTV2.cmake script to locate the ajantv2 headers and static libs in the OBS external deps package(s). Tested on Windows x64. macOS and Linux x64 TBD. * aja: Add ajantv2/includes to FindLibAJANTV2 include search paths * aja: Remove commented code from aja CMakeLists * aja: Remove debug code and comments that are no longer needed. * aja: Fix indentation * aja: Remove disablement of clang-format in routing table and SDIWireFormat map * aja: Use spaces for all indentation in widget crosspoint arrays where we disable clang-format * aja: Address code style comments made by @RytoEX * aja: Fix uneven indentation * aja: More fixes to if/else placement and remove superfluous comments. * aja: Rename 'dwns' to 'deactivateWhileNotShowing' for clarity. The DeckLink plugin still uses the variable name 'dwns' and should be changed, if desired, in a separate PR. * aja: Remove X11Extras dependency from AJA Output frontend plugin * aja: Add patch from Jim to find AJA release/debug libs * aja: Improve AV sync of queued video/audio sent to the AJA card in the AJA Output plugin.
161 lines
3.4 KiB
C++
161 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include "aja-props.hpp"
|
|
|
|
#include <ajantv2/includes/ntv2testpatterngen.h>
|
|
|
|
#include <ajabase/common/types.h>
|
|
#include <ajabase/system/thread.h>
|
|
|
|
// #define AJA_WRITE_DEBUG_WAV
|
|
#ifdef AJA_WRITE_DEBUG_WAV
|
|
#include <ajabase/common/wavewriter.h>
|
|
#endif
|
|
|
|
#include <deque>
|
|
#include <memory>
|
|
#include <mutex>
|
|
|
|
struct VideoFrame {
|
|
struct video_data frame;
|
|
int64_t frameNum;
|
|
size_t size;
|
|
};
|
|
|
|
struct AudioFrames {
|
|
struct audio_data frames;
|
|
size_t offset;
|
|
size_t size;
|
|
};
|
|
|
|
//TODO(paulh): Refactor me into OutputProps
|
|
struct FrameTimes {
|
|
double obsFps;
|
|
uint64_t obsFrameTime;
|
|
double cardFps;
|
|
uint64_t cardFrameTime;
|
|
};
|
|
|
|
using VideoQueue = std::deque<VideoFrame>;
|
|
using AudioQueue = std::deque<AudioFrames>;
|
|
|
|
class CNTV2Card; // forward decl
|
|
|
|
class AJAOutput {
|
|
public:
|
|
enum {
|
|
// min queue sizes computed in AJAOutput
|
|
kVideoQueueMaxSize = 15,
|
|
kAudioQueueMaxSize =
|
|
96, // ~(48000 / 1024 samples per audio_frame) * 2sec
|
|
};
|
|
|
|
AJAOutput(CNTV2Card *card, const std::string &cardID,
|
|
const std::string &outputID, UWord deviceIndex,
|
|
const NTV2DeviceID deviceID);
|
|
|
|
~AJAOutput();
|
|
|
|
CNTV2Card *GetCard();
|
|
|
|
void Initialize(const OutputProps &props);
|
|
|
|
void SetOBSOutput(obs_output_t *output);
|
|
obs_output_t *GetOBSOutput();
|
|
|
|
void SetOutputProps(const OutputProps &props);
|
|
OutputProps GetOutputProps() const;
|
|
|
|
void GenerateTestPattern(NTV2VideoFormat vf, NTV2PixelFormat pf,
|
|
NTV2TestPatternSelect pattern);
|
|
|
|
void QueueVideoFrame(struct video_data *frame, size_t size);
|
|
void QueueAudioFrames(struct audio_data *frames, size_t size);
|
|
void ClearVideoQueue();
|
|
void ClearAudioQueue();
|
|
size_t VideoQueueSize();
|
|
size_t AudioQueueSize();
|
|
|
|
bool HaveEnoughAudio(size_t needAudioSize);
|
|
void DMAAudioFromQueue(NTV2AudioSystem audioSys);
|
|
void DMAVideoFromQueue();
|
|
|
|
void CreateThread(bool enable = false);
|
|
void StopThread();
|
|
bool ThreadRunning();
|
|
static void OutputThread(AJAThread *thread, void *ctx);
|
|
|
|
std::string mCardID;
|
|
std::string mOutputID;
|
|
UWord mDeviceIndex;
|
|
NTV2DeviceID mDeviceID;
|
|
|
|
FrameTimes mFrameTimes;
|
|
|
|
uint32_t mAudioPlayCursor;
|
|
uint32_t mAudioWriteCursor;
|
|
uint32_t mAudioWrapAddress;
|
|
uint32_t mAudioRate;
|
|
|
|
uint64_t mAudioQueueSamples;
|
|
uint64_t mAudioWriteSamples;
|
|
uint64_t mAudioPlaySamples;
|
|
|
|
uint32_t mNumCardFrames;
|
|
uint32_t mFirstCardFrame;
|
|
uint32_t mLastCardFrame;
|
|
uint32_t mWriteCardFrame;
|
|
uint32_t mPlayCardFrame;
|
|
uint32_t mPlayCardNext;
|
|
uint32_t mFrameRateNum;
|
|
uint32_t mFrameRateDen;
|
|
|
|
uint64_t mVideoQueueFrames;
|
|
uint64_t mVideoWriteFrames;
|
|
uint64_t mVideoPlayFrames;
|
|
|
|
uint64_t mFirstVideoTS;
|
|
uint64_t mFirstAudioTS;
|
|
uint64_t mLastVideoTS;
|
|
uint64_t mLastAudioTS;
|
|
|
|
int64_t mVideoDelay;
|
|
int64_t mAudioDelay;
|
|
int64_t mAudioVideoSync;
|
|
int64_t mAudioAdjust;
|
|
int64_t mLastStatTime;
|
|
#ifdef AJA_WRITE_DEBUG_WAV
|
|
AJAWavWriter *mWaveWriter;
|
|
#endif
|
|
|
|
private:
|
|
void calculate_card_frame_indices(uint32_t numFrames, NTV2DeviceID id,
|
|
NTV2Channel channel,
|
|
NTV2VideoFormat vf,
|
|
NTV2PixelFormat pf);
|
|
|
|
uint32_t get_frame_count();
|
|
|
|
void dma_audio_samples(NTV2AudioSystem audioSys, uint32_t *data,
|
|
size_t size);
|
|
|
|
CNTV2Card *mCard;
|
|
|
|
OutputProps mOutputProps;
|
|
|
|
NTV2TestPatternBuffer mTestPattern;
|
|
|
|
bool mIsRunning;
|
|
bool mAudioStarted;
|
|
|
|
AJAThread mRunThread;
|
|
mutable std::mutex mVideoLock;
|
|
mutable std::mutex mAudioLock;
|
|
mutable std::mutex mRunThreadLock;
|
|
|
|
std::unique_ptr<VideoQueue> mVideoQueue;
|
|
std::unique_ptr<AudioQueue> mAudioQueue;
|
|
|
|
obs_output_t *mOBSOutput;
|
|
};
|