22 #include <DeckLinkAPI.h> 
   25 #include <semaphore.h> 
   70     unsigned long long size;
 
  156         virtual HRESULT STDMETHODCALLTYPE 
VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
 
  207     IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioFrame)
 
  210     void *audioFrameBytes;
 
  211     BMDTimeValue frameTime;
 
  212     BMDTimeValue frameDuration;
 
  225                     "Frame received (#%lu) - Valid (%liB) - QSize %fMB\n",
 
  227                     videoFrame->GetRowBytes() * videoFrame->GetHeight(),
 
  228                     (double)qsize / 1024 / 1024);
 
  231         videoFrame->GetBytes(&frameBytes);
 
  232         videoFrame->GetStreamTime(&frameTime, &frameDuration,
 
  235         if (videoFrame->GetFlags() & bmdFrameHasNoInputSource) {
 
  236             if (videoFrame->GetPixelFormat() == bmdFormat8BitYUV) {
 
  238                 0xEA80EA80, 0xD292D210, 0xA910A9A5, 0x90229035,
 
  239                 0x6ADD6ACA, 0x51EF515A, 0x286D28EF, 0x10801080 };
 
  240             int width  = videoFrame->GetWidth();
 
  241             int height = videoFrame->GetHeight();
 
  242             unsigned *p = (
unsigned *)frameBytes;
 
  245                 for (
int x = 0; x < 
width; x += 2)
 
  246                     *p++ = bars[(x * 8) / 
width];
 
  277         pkt.
size         = videoFrame->GetRowBytes() *
 
  278                            videoFrame->GetHeight();
 
  290         BMDTimeValue audio_pts;
 
  296         audioFrame->GetBytes(&audioFrameBytes);
 
  322     BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *
mode,
 
  323     BMDDetectedVideoInputFormatFlags)
 
  334     ctx->dli->SetCallback(
ctx->input_callback);
 
  335     return ctx->dli->StartStreams();
 
  345     if (
ctx->capture_started) {
 
  346         ctx->dli->StopStreams();
 
  347         ctx->dli->DisableVideoInput();
 
  348         ctx->dli->DisableAudioInput();
 
  367     IDeckLinkDisplayModeIterator *itermode;
 
  368     IDeckLinkIterator *iter;
 
  369     IDeckLink *dl = 
NULL;
 
  384     iter = CreateDeckLinkIteratorInstance();
 
  391     if (
ctx->list_devices) {
 
  397     tmp=strchr (fname, 
'@');
 
  399         mode_num = atoi (tmp+1);
 
  404     while (iter->Next(&dl) == 
S_OK) {
 
  405         const char *displayName;
 
  407         if (!strcmp(fname, displayName)) {
 
  422     if (
ctx->dl->QueryInterface(IID_IDeckLinkInput, (
void **) &
ctx->dli) != 
S_OK) {
 
  430     if (
ctx->list_formats) {
 
  437     if (
ctx->dli->GetDisplayModeIterator(&itermode) != 
S_OK) {
 
  460     st->codec->sample_rate = bmdAudioSampleRate48kHz;
 
  461     st->codec->channels    = 2;
 
  471     st->codec->width       = 
ctx->bmd_width;
 
  472     st->codec->height      = 
ctx->bmd_height;
 
  474     st->codec->time_base.den      = 
ctx->bmd_tb_den;
 
  475     st->codec->time_base.num      = 
ctx->bmd_tb_num;
 
  480         st->codec->codec_tag   = 
MKTAG(
'V', 
'2', 
'1', 
'0');
 
  484         st->codec->codec_tag   = 
MKTAG(
'U', 
'Y', 
'V', 
'Y');
 
  491     result = 
ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger, 2);
 
  493     if (result != 
S_OK) {
 
  498     result = 
ctx->dli->EnableVideoInput(
ctx->bmd_mode,
 
  499                                         cctx->
v210 ? bmdFormat10BitYUV : bmdFormat8BitYUV,
 
  500                                         bmdVideoInputFlagDefault);
 
  502     if (result != 
S_OK) {
 
  531     if (frame && (
ctx->bmd_field_dominance == bmdUpperFieldFirst || 
ctx->bmd_field_dominance == bmdLowerFieldFirst)) {
 
  533         if (
ctx->bmd_field_dominance == bmdUpperFieldFirst) {
 
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1 
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
void av_free_packet(AVPacket *pkt)
Free a packet. 
This structure describes decoded (raw) audio or video data. 
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
#define AV_LOG_WARNING
Something somehow does not look correct. 
int index
stream index in AVFormatContext 
static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
int av_dup_packet(AVPacket *pkt)
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file. 
static double av_q2d(AVRational a)
Convert rational to double. 
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
int interlaced_frame
The content of the picture is interlaced. 
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown. 
int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int tb_num, int tb_den, decklink_direction_t direction, int num)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe. 
static void avpacket_queue_flush(AVPacketQueue *q)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered. 
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers. 
av_cold int ff_decklink_read_close(AVFormatContext *avctx)
int flags
A combination of AV_PKT_FLAG values. 
AVCodecContext * codec
Codec context associated with this stream. 
char filename[1024]
input or output filename 
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction)
static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted. 
int ff_decklink_list_devices(AVFormatContext *avctx)
main external API structure. 
static HRESULT decklink_start_input(AVFormatContext *avctx)
HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
BYTE int const BYTE int int int height
static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block)
static void avpacket_queue_end(AVPacketQueue *q)
struct AVPacketList * next
static unsigned long long avpacket_queue_size(AVPacketQueue *q)
int ff_decklink_read_packet(AVFormatContext *avctx, AVPacket *pkt)
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values. 
int top_field_first
If the content is interlaced, is top field displayed first. 
int channels
number of audio channels 
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
void * priv_data
Format private data. 
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
av_cold int ff_decklink_read_header(AVFormatContext *avctx)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int frame_number
Frame counter, set by libavcodec. 
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define MKTAG(a, b, c, d)
This structure stores compressed data. 
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.