Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ntv2linux #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pro.user
*.pro.user.*
74 changes: 74 additions & 0 deletions ajapreviewwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef AJAPREVIEW_WIDGET_H
#define AJAPREVIEW_WIDGET_H

#include <QBasicTimer>
#include <QtCore>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QtWidgets>
#else
#include <QtGui>
#endif
#include <QThread>
#include <QList>
#include <QRectF>
#if defined (INCLUDE_AJACC)
#include "ajacc/includes/ntv2caption608types.h"
#endif // defined (INCLUDE_AJACC)

class AJAPreviewWidget;

#define AJAPREVIEW_WIDGET_X (960)
#define AJAPREVIEW_WIDGET_Y (540)

typedef struct
{
bool display;
QRectF roiRect; /// normalize to width and height 0.0-1.0
QColor roiRectColor;

} ROIStruct;

typedef QList<ROIStruct> ROIRectList;


class AJAPreviewWidget : public QFrame
{
Q_OBJECT

public:
AJAPreviewWidget (QWidget * parent = 0);

signals:
void wheelDelta (int delta);
void droppedFile (QString fileName);

public slots:
void updateFrame (const QImage &image,bool clear);
void updateFrameWithStatus (const QImage &image,const QString &statusString,bool clear);
void updateFrameWithROI (const QImage &image,ROIRectList roiList, bool clear);
void updateROI (ROIRectList roiList);
void updateStatusString (const QString statusString);
#if defined (INCLUDE_AJACC)
void updateCaptionScreen (const ushort * inScreen);
#endif // defined (INCLUDE_AJACC)

protected:
void paintEvent (QPaintEvent * event);
void wheelEvent (QWheelEvent * event);

void dragEnterEvent (QDragEnterEvent *event);
void dropEvent (QDropEvent *event);

private:
QPixmap _pixmap;
QString _statusString;
int _step;
ROIRectList _roiList;
QSize _unscaledImageSize;
#if defined (INCLUDE_AJACC)
QString _captionStrings [15];
#endif // defined (INCLUDE_AJACC)

}; // AJAPreviewWidget

#endif // AJAPREVIEW_WIDGET_H
16 changes: 13 additions & 3 deletions gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
#-------------------------------------------------

QT += core gui
QT += core multimedia widgets gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

Expand All @@ -15,17 +15,27 @@ TEMPLATE = app
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DEPRECATED_WARNINGS AJALinux

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

QMAKE_LIBFLAGS += -lajantv2 #TODO - Figure out why/if this is needed

SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h
HEADERS += mainwindow.h \
ntv2qtpreview.h

NTV2_SDK_PATH=/home/mark/ntv2sdklinux_13.1.0.1

LIBS += $$NTV2_SDK_PATH/lib

INCLUDEPATH += $$NTV2_SDK_PATH/ajalibraries/ajantv2/includes\
$$NTV2_SDK_PATH/ajalibraries/ajantv2/src/lin\
$$NTV2_SDK_PATH/ajalibraries/

FORMS += mainwindow.ui
874 changes: 0 additions & 874 deletions gui.pro.user

This file was deleted.

874 changes: 0 additions & 874 deletions gui.pro.user.a42c32b

This file was deleted.

315 changes: 0 additions & 315 deletions gui.pro.user.ee88e62

This file was deleted.

28 changes: 14 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#include "mainwindow.h"
#include <QApplication>
#include "ntv2qtpreview.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;

#include <QtCore>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QtWidgets>
#else
#include <QtGui>
#endif

int main (int argc, char * argv [])
{
QApplication app (argc, argv);
NTV2QtPreview window;

/*QGraphicsView* w = new QGraphicsView();
QGraphicsScene *scn = new QGraphicsScene( w );
scn->setSceneRect( w->rect() );
w->setScene( scn );
w->setFixedSize( 400, 400 );
QPixmap pix( "c:\\pix_jpg.jpg" );
scn->addPixmap( pix );*/
window.setWindowTitle ("NTV2 Qt Preview");
window.show ();

w.show();
return app.exec ();

return a.exec();
}
194 changes: 194 additions & 0 deletions ntv2framegrabber.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/**
@file ntv2framegrabber.h
@brief Header file for the NTV2FrameGrabber class.
@copyright Copyright (C) 2013-2014 AJA Video Systems, Inc. All rights reserved.
**/

#ifndef NTV2FRAMEGRABBER_H
#define NTV2FRAMEGRABBER_H

#include <QBasicTimer>
#include <QtCore>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QtWidgets>
#else
#include <QtGui>
#endif
#include <QThread>
#include <QtMultimedia>
#include "ntv2card.h"
#include "ntv2enums.h"
#include "ntv2task.h"
#include "ntv2rp188.h"
#include "ajabase/common/types.h"
#include "ajabase/system/process.h"
#if defined (INCLUDE_AJACC)
#include "ajacc/includes/ntv2captiondecoder608.h"
#include "ajacc/includes/ntv2captiondecoder708.h"
#endif // INCLUDE_AJACC

#define QTPREVIEW_WIDGET_X (960)
#define QTPREVIEW_WIDGET_Y (540)



/**
@brief A QThread that captures audio/video from NTV2-compatible AJA devices and uses Qt signals to emit ARGB video frames.
To simplify things, I assume the input signal is YCbCr, and the input goes through a color space converter (CSC) to an
ARGB FrameStore. I can also output 2 channels of Audio to the host audio system using Qt's QAudioOutput device.
**/

class NTV2FrameGrabber : public QThread
{
Q_OBJECT

// Instance Methods
public:
/**
@brief Constructs me.
@param[in] pInParentObject Optionally specifies my parent object. Defaults to NULL (no parent).
**/
NTV2FrameGrabber (QObject * pInParentObject = NULL);

virtual ~NTV2FrameGrabber (); ///< @brief My destructor.

/**
@brief Sets the input to be used for capture on the AJA device being used.
@param[in] inInputSource Specifies the input source to be used.
**/
void SetInputSource (const NTV2InputSource inInputSource);

/**
@brief Enables or disables host audio playback.
@param[in] inWithAudio If true, enables host audio playback; otherwise disables it.
**/
inline void SetWithAudio (const bool inWithAudio) {mbWithAudio = inWithAudio; mRestart = true;}

/**
@brief Sets the AJA device to be used for capture.
@param[in] inDeviceIndex Specifies the zero-based index number of the device to be used.
**/
void SetDeviceIndex (const UWord inDeviceIndex);

void SetTimeCodeSource (const NTV2TCIndex inTCSource);

UWord GetDeviceIndex (void) const;

/**
@brief Enables or disables checking for 4K/UHD video (on devices that supported 4K/UHD).
@param[in] inCheckFor4K If true, enables checking for 4K/UHD video; otherwise disables it.
**/
inline void CheckFor4kInput (const bool inCheckFor4K) {mCheckFor4K = inCheckFor4K;}

/**
@brief Enables or disables deinterlacing of non-progressive video.
@param[in] inDeinterlace If true, enables deinterlacing of non-progressive video; otherwise disables it.
**/
inline void SetDeinterlaceNonProgressiveVideo (const bool inDeinterlace) {mDeinterlace = inDeinterlace;}

inline bool GetDeinterlaceNonProgressiveVideo (void) const {return mDeinterlace;} ///< @return True if deinterlacing is enabled; otherwise false.

protected:
void ClearCaptionBuffer (const bool inSignalClients = false);
void GrabCaptions (void); ///< @brief Performs caption data extraction & decoding


signals:
/**
@brief This is signaled (called) when a new frame has been captured and is available for display.
@param[in] inImage A QImage that contains the frame image.
@param[in] inClear True if a redraw should take place -- i.e., if the frame is the first of a valid video stream,
or if there is currently no valid video.
**/
void newFrame (const QImage & inImage, const bool inClear);

/**
@brief This is signaled (called) when my status string changes.
@param[in] inStatus The QString containing the status message.
**/
void newStatusString (const QString & inStatus);

/**
@brief This is signaled (called) when my caption screen buffer changes.
@param[in] pInScreen Points to the (screen) array of Utf16 characters.
**/
void captionScreenChanged (const ushort * pInScreen);

private slots:
void changeCaptionChannel (int id); ///< @brief This gets called when a different NTV2Line21Channel is requested.


protected:
virtual void run (void); ///< @brief My thread function.

bool SetupInput (void); ///< @brief Configures my AJA device for capture
void StopAutoCirculate (void); ///< @brief Stops capturing
void SetupAudio (void); ///< @brief Performs audio configuration

/**
@brief Writes audio samples for channels 1 and 2 that are in the given audio buffer to my QAudioOutput device,
which should play out on the host.

@param pInOutAudioBuffer Specifies a valid, non-NULL pointer to a buffer containing the audio samples
that were captured from my AJA device for a single frame. This is not a 'const'
pointer because the buffer content will be changed.
On entry, the buffer will contain 6, 8 or 16 channels of 4-byte (32-bit) audio
samples: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF...
On exit, the buffer will contain unsigned 2-byte (16-bit) samples in LRLRLRLR order,
which is what Qt's QAudioOutput object is expecting. (The least significant 16 bits
of each sample from the AJA device are discarded.)

@param inNumValidBytes Specifies the number of valid bytes that are in the audio buffer.
**/
void OutputAudio (ULWord * pInOutAudioBuffer, const ULWord inNumValidBytes);

bool CheckForValidInput (void);

NTV2VideoFormat GetVideoFormatFromInputSource (void);

bool IsInput3Gb (const NTV2InputSource inputSource);

// Instance Data
private:
bool mRestart; ///< @brief Set true to reconfigure me and restart AutoCirculate
bool mAbort; ///< @brief Used in my destructor to immediately cause me to exit
bool mCheckFor4K; ///< @brief Check for 4K/UHD video?
bool mDeinterlace; ///< @brief De-interlace non-progressive video?

CNTV2Card mNTV2Card; ///< @brief Used to talk to monitor & control the device
UWord mBoardNumber; ///< @brief Index number of the device I'm using
NTV2DeviceID mDeviceID; ///< @brief Device ID of the device I'm using
NTV2Channel mChannel; ///< @brief AutoCirculate capture
ULWord mNumChannels; ///< @brief Number of capture frame channels
NTV2VideoFormat mCurrentVideoFormat; ///< @brief Current video format seen on selected device input
NTV2VideoFormat mLastVideoFormat; ///< @brief Used to detect input video format changes
ULWord mDebounceCounter; ///< @brief Used for detecting stable input video
bool mFormatIsProgressive; ///< @brief True if input video format is progressive (not interlaced)
NTV2InputSource mInputSource; ///< @brief User-selected input source
NTV2FrameDimensions mFrameDimensions; ///< @brief Frame dimensions, pixels X lines
NTV2FrameBufferFormat mFrameBufferFormat; ///< @brief My frame buffer format
AUTOCIRCULATE_TRANSFER mTransferStruct; ///< @brief AutoCirculate transfer object
NTV2EveryFrameTaskMode mSavedTaskMode; ///< @brief Used to restore the previous task mode

bool mbWithAudio; ///< @brief Capture audio?
QAudioOutput * mAudioOutput; ///< @brief Used to play captured audio on host audio system
QAudioFormat mFormat; ///< @brief Output audio stream format information
QIODevice * mAudioDevice; ///< @brief Host audio device
ULWord mNumAudioChannels; ///< @brief Number of audio channels being captured on the AJA device
NTV2AudioSystem mAudioSystem; ///< @brief Audio subsystem to use

std::string mTimeCode; ///< @brief Currently displayed timecode
NTV2TCIndex mTimeCodeSource; ///< @brief Timecode source
#if defined (INCLUDE_AJACC)
CNTV2CaptionDecoder608Ptr m608Decoder; ///< @brief My 608 closed-caption decoder
CNTV2CaptionDecoder708Ptr m708Decoder; ///< @brief My 708 closed-caption decoder
ushort mScreenBuffer [15][32]; ///< @brief My caption buffer

static void Caption608Changed (void * pInstance, const NTV2Caption608ChangeInfo & inChangeInfo);
void caption608Changed (const NTV2Caption608ChangeInfo & inChangeInfo);
#endif // defined (INCLUDE_AJACC)

}; // class NTV2FrameGrabber


#endif // NTV2FRAMEGRABBER_H
Loading