22 #include <DeckLinkAPI.h>
45 static uint8_t calc_parity_and_line_offset(
int line)
47 uint8_t ret = (line < 313) << 5;
48 if (line >= 7 && line <= 22)
50 if (line >= 320 && line <= 335)
57 vbi_bit_slicer slicer;
59 vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, VBI_PIXFMT_UYVY);
61 if (vbi_bit_slice(&slicer, src, tgt + 4) ==
FALSE)
66 tgt[2] = calc_parity_and_line_offset(line);
107 unsigned long long size;
193 virtual HRESULT STDMETHODCALLTYPE
VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
245 IDeckLinkAudioInputPacket *audioFrame,
251 BMDTimeValue bmd_pts;
252 BMDTimeValue bmd_duration;
257 res = audioFrame->GetPacketTime(&bmd_pts, time_base.
den);
261 res = videoFrame->GetStreamTime(&bmd_pts, &bmd_duration, time_base.
den);
265 res = videoFrame->GetHardwareReferenceTimestamp(time_base.
den, &bmd_pts, &bmd_duration);
272 pts = bmd_pts / time_base.
num;
283 IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioFrame)
286 void *audioFrameBytes;
287 BMDTimeValue frameTime;
288 BMDTimeValue frameDuration;
289 int64_t wallclock = 0;
302 "Frame received (#%lu) - Valid (%liB) - QSize %fMB\n",
304 videoFrame->GetRowBytes() * videoFrame->GetHeight(),
305 (double)qsize / 1024 / 1024);
308 videoFrame->GetBytes(&frameBytes);
309 videoFrame->GetStreamTime(&frameTime, &frameDuration,
312 if (videoFrame->GetFlags() & bmdFrameHasNoInputSource) {
313 if (
ctx->
draw_bars && videoFrame->GetPixelFormat() == bmdFormat8BitYUV) {
315 0xEA80EA80, 0xD292D210, 0xA910A9A5, 0x90229035,
316 0x6ADD6ACA, 0x51EF515A, 0x286D28EF, 0x10801080 };
317 int width = videoFrame->GetWidth();
318 int height = videoFrame->GetHeight();
319 unsigned *p = (
unsigned *)frameBytes;
321 for (
int y = 0; y <
height; y++) {
322 for (
int x = 0; x <
width; x += 2)
323 *p++ = bars[(x * 8) /
width];
348 pkt.
size = videoFrame->GetRowBytes() *
349 videoFrame->GetHeight();
353 if (!
no_video &&
ctx->
teletext_lines && videoFrame->GetPixelFormat() == bmdFormat8BitYUV && videoFrame->GetWidth() == 720) {
354 IDeckLinkVideoFrameAncillary *vanc;
359 if (videoFrame->GetAncillaryData(&vanc) ==
S_OK) {
361 int64_t line_mask = 1;
364 for (i = 6; i < 336; i++, line_mask <<= 1) {
366 if ((
ctx->
teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (
void**)&buf) ==
S_OK) {
367 if (teletext_data_unit_from_vbi_data(i, buf, txt_buf) >= 0)
374 if (txt_buf - txt_buf0 > 1) {
375 int stuffing_units = (4 - ((45 + txt_buf - txt_buf0) / 46) % 4) % 4;
376 while (stuffing_units--) {
377 memset(txt_buf, 0xff, 46);
385 txt_pkt.
data = txt_buf0;
386 txt_pkt.
size = txt_buf - txt_buf0;
403 BMDTimeValue audio_pts;
408 audioFrame->GetBytes(&audioFrameBytes);
427 BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *
mode,
428 BMDDetectedVideoInputFormatFlags)
439 ctx->dli->SetCallback(
ctx->input_callback);
440 return ctx->dli->StartStreams();
450 if (
ctx->capture_started) {
451 ctx->dli->StopStreams();
452 ctx->dli->DisableVideoInput();
453 ctx->dli->DisableAudioInput();
493 if (
ctx->teletext_lines) {
494 av_log(avctx,
AV_LOG_ERROR,
"Libzvbi support is needed for capturing teletext, please recompile FFmpeg.\n");
511 if (
ctx->list_devices) {
517 tmp=strchr (fname,
'@');
519 av_log(avctx,
AV_LOG_WARNING,
"The @mode syntax is deprecated and will be removed. Please use the -format_code option.\n");
520 mode_num = atoi (
tmp+1);
529 if (
ctx->dl->QueryInterface(IID_IDeckLinkInput, (
void **) &
ctx->dli) !=
S_OK) {
537 if (
ctx->list_formats) {
545 av_log(avctx,
AV_LOG_ERROR,
"Could not set mode number %d or format code %s for %s\n",
561 st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
573 st->codecpar->width =
ctx->bmd_width;
574 st->codecpar->height =
ctx->bmd_height;
576 st->time_base.den =
ctx->bmd_tb_den;
577 st->time_base.num =
ctx->bmd_tb_num;
582 st->codecpar->codec_tag =
MKTAG(
'V',
'2',
'1',
'0');
583 st->codecpar->bit_rate =
av_rescale(
ctx->bmd_width *
ctx->bmd_height * 64, st->time_base.den, st->time_base.num * 3);
587 st->codecpar->codec_tag =
MKTAG(
'U',
'Y',
'V',
'Y');
588 st->codecpar->bit_rate =
av_rescale(
ctx->bmd_width *
ctx->bmd_height * 16, st->time_base.den, st->time_base.num);
595 if (
ctx->teletext_lines) {
603 st->time_base.den =
ctx->bmd_tb_den;
604 st->time_base.num =
ctx->bmd_tb_num;
607 ctx->teletext_st = st;
611 result =
ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger,
ctx->audio_st->codecpar->channels);
613 if (result !=
S_OK) {
619 result =
ctx->dli->EnableVideoInput(
ctx->bmd_mode,
620 cctx->
v210 ? bmdFormat10BitYUV : bmdFormat8BitYUV,
621 bmdVideoInputFlagDefault);
623 if (result !=
S_OK) {
651 if (frame && (
ctx->bmd_field_dominance == bmdUpperFieldFirst ||
ctx->bmd_field_dominance == bmdLowerFieldFirst)) {
653 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.
#define pthread_mutex_lock(a)
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
Convenience header that includes libavutil's core.
static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
int ff_decklink_init_device(AVFormatContext *avctx, const char *name)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
DecklinkPtsSource audio_pts_source
static const BMDVideoConnection decklink_video_connection_map[]
DecklinkPtsSource audio_pts_source
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static const BMDAudioConnection decklink_audio_connection_map[]
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t direction, int num)
#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.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
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)
#define pthread_mutex_unlock(a)
static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
static void error(const char *err)
#define FF_ARRAY_ELEMS(a)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int ff_decklink_list_devices(AVFormatContext *avctx)
static AVRational av_make_q(int num, int den)
Create an AVRational.
DecklinkPtsSource video_pts_source
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static HRESULT decklink_start_input(AVFormatContext *avctx)
static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block)
Rational number (pair of numerator and denominator).
static int64_t pts
Global timestamp for the audio frames.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
void ff_decklink_cleanup(AVFormatContext *avctx)
static int64_t get_pkt_pts(IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioFrame, int64_t wallclock, DecklinkPtsSource pts_src, AVRational time_base, int64_t *initial_pts)
static void avpacket_queue_end(AVPacketQueue *q)
struct AVPacketList * next
common internal and external API header
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.
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...
DecklinkPtsSource video_pts_source
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)
This structure stores compressed data.
mode
Use these values in ebur128_init (or'ed).
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.