22 #include <DeckLinkAPI.h>
41 static uint8_t calc_parity_and_line_offset(
int line)
43 uint8_t ret = (line < 313) << 5;
44 if (line >= 7 && line <= 22)
46 if (line >= 320 && line <= 335)
53 vbi_bit_slicer slicer;
55 vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, VBI_PIXFMT_UYVY);
57 if (vbi_bit_slice(&slicer, src, tgt + 4) ==
FALSE)
62 tgt[2] = calc_parity_and_line_offset(line);
103 unsigned long long size;
189 virtual HRESULT STDMETHODCALLTYPE
VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
240 IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioFrame)
243 void *audioFrameBytes;
244 BMDTimeValue frameTime;
245 BMDTimeValue frameDuration;
256 "Frame received (#%lu) - Valid (%liB) - QSize %fMB\n",
258 videoFrame->GetRowBytes() * videoFrame->GetHeight(),
259 (double)qsize / 1024 / 1024);
262 videoFrame->GetBytes(&frameBytes);
263 videoFrame->GetStreamTime(&frameTime, &frameDuration,
266 if (videoFrame->GetFlags() & bmdFrameHasNoInputSource) {
267 if (videoFrame->GetPixelFormat() == bmdFormat8BitYUV) {
269 0xEA80EA80, 0xD292D210, 0xA910A9A5, 0x90229035,
270 0x6ADD6ACA, 0x51EF515A, 0x286D28EF, 0x10801080 };
271 int width = videoFrame->GetWidth();
272 int height = videoFrame->GetHeight();
273 unsigned *p = (
unsigned *)frameBytes;
275 for (
int y = 0; y <
height; y++) {
276 for (
int x = 0; x <
width; x += 2)
277 *p++ = bars[(x * 8) /
width];
308 pkt.
size = videoFrame->GetRowBytes() *
309 videoFrame->GetHeight();
313 if (!
no_video &&
ctx->
teletext_lines && videoFrame->GetPixelFormat() == bmdFormat8BitYUV && videoFrame->GetWidth() == 720) {
314 IDeckLinkVideoFrameAncillary *vanc;
319 if (videoFrame->GetAncillaryData(&vanc) ==
S_OK) {
321 int64_t line_mask = 1;
324 for (i = 6; i < 336; i++, line_mask <<= 1) {
326 if ((
ctx->
teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (
void**)&buf) ==
S_OK) {
327 if (teletext_data_unit_from_vbi_data(i, buf, txt_buf) >= 0)
334 if (txt_buf - txt_buf0 > 1) {
335 int stuffing_units = (4 - ((45 + txt_buf - txt_buf0) / 46) % 4) % 4;
336 while (stuffing_units--) {
337 memset(txt_buf, 0xff, 46);
345 txt_pkt.
data = txt_buf0;
346 txt_pkt.
size = txt_buf - txt_buf0;
363 BMDTimeValue audio_pts;
368 audioFrame->GetBytes(&audioFrameBytes);
393 BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *
mode,
394 BMDDetectedVideoInputFormatFlags)
405 ctx->dli->SetCallback(
ctx->input_callback);
406 return ctx->dli->StartStreams();
416 if (
ctx->capture_started) {
417 ctx->dli->StopStreams();
418 ctx->dli->DisableVideoInput();
419 ctx->dli->DisableAudioInput();
438 IDeckLinkDisplayModeIterator *itermode;
439 IDeckLinkIterator *iter;
440 IDeckLink *dl =
NULL;
457 if (
ctx->teletext_lines) {
458 av_log(avctx,
AV_LOG_ERROR,
"Libzvbi support is needed for capturing teletext, please recompile FFmpeg.\n");
474 iter = CreateDeckLinkIteratorInstance();
481 if (
ctx->list_devices) {
487 tmp=strchr (fname,
'@');
489 mode_num = atoi (
tmp+1);
494 while (iter->Next(&dl) ==
S_OK) {
495 const char *displayName;
497 if (!strcmp(fname, displayName)) {
512 if (
ctx->dl->QueryInterface(IID_IDeckLinkInput, (
void **) &
ctx->dli) !=
S_OK) {
520 if (
ctx->list_formats) {
527 if (
ctx->dli->GetDisplayModeIterator(&itermode) !=
S_OK) {
550 st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
561 st->codecpar->width =
ctx->bmd_width;
562 st->codecpar->height =
ctx->bmd_height;
564 st->time_base.den =
ctx->bmd_tb_den;
565 st->time_base.num =
ctx->bmd_tb_num;
570 st->codecpar->codec_tag =
MKTAG(
'V',
'2',
'1',
'0');
574 st->codecpar->codec_tag =
MKTAG(
'U',
'Y',
'V',
'Y');
581 if (
ctx->teletext_lines) {
588 st->time_base.den =
ctx->bmd_tb_den;
589 st->time_base.num =
ctx->bmd_tb_num;
592 ctx->teletext_st = st;
596 result =
ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger,
ctx->audio_st->codecpar->channels);
598 if (result !=
S_OK) {
603 result =
ctx->dli->EnableVideoInput(
ctx->bmd_mode,
604 cctx->
v210 ? bmdFormat10BitYUV : bmdFormat8BitYUV,
605 bmdVideoInputFlagDefault);
607 if (result !=
S_OK) {
636 if (frame && (
ctx->bmd_field_dominance == bmdUpperFieldFirst ||
ctx->bmd_field_dominance == bmdLowerFieldFirst)) {
638 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)
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
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
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.
#define AV_LOG_VERBOSE
Detailed information.
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
int interlaced_frame
The content of the picture is interlaced.
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.
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
static void avpacket_queue_flush(AVPacketQueue *q)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
attribute_deprecated int av_dup_packet(AVPacket *pkt)
#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.
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)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static HRESULT decklink_start_input(AVFormatContext *avctx)
HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName)
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.
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
void * priv_data
Format private data.
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...
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
AVCodecParameters * codecpar
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)
AVPixelFormat
Pixel format.
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.