22 #include <DeckLinkAPI.h>
25 #include <semaphore.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;
258 "Frame received (#%lu) - Valid (%liB) - QSize %fMB\n",
260 videoFrame->GetRowBytes() * videoFrame->GetHeight(),
261 (double)qsize / 1024 / 1024);
264 videoFrame->GetBytes(&frameBytes);
265 videoFrame->GetStreamTime(&frameTime, &frameDuration,
268 if (videoFrame->GetFlags() & bmdFrameHasNoInputSource) {
269 if (videoFrame->GetPixelFormat() == bmdFormat8BitYUV) {
271 0xEA80EA80, 0xD292D210, 0xA910A9A5, 0x90229035,
272 0x6ADD6ACA, 0x51EF515A, 0x286D28EF, 0x10801080 };
273 int width = videoFrame->GetWidth();
274 int height = videoFrame->GetHeight();
275 unsigned *p = (
unsigned *)frameBytes;
277 for (
int y = 0; y <
height; y++) {
278 for (
int x = 0; x <
width; x += 2)
279 *p++ = bars[(x * 8) /
width];
310 pkt.
size = videoFrame->GetRowBytes() *
311 videoFrame->GetHeight();
315 if (!
no_video &&
ctx->
teletext_lines && videoFrame->GetPixelFormat() == bmdFormat8BitYUV && videoFrame->GetWidth() == 720) {
316 IDeckLinkVideoFrameAncillary *vanc;
321 if (videoFrame->GetAncillaryData(&vanc) ==
S_OK) {
323 int64_t line_mask = 1;
326 for (i = 6; i < 336; i++, line_mask <<= 1) {
328 if ((
ctx->
teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (
void**)&buf) ==
S_OK) {
329 if (teletext_data_unit_from_vbi_data(i, buf, txt_buf) >= 0)
336 if (txt_buf - txt_buf0 > 1) {
337 int stuffing_units = (4 - ((45 + txt_buf - txt_buf0) / 46) % 4) % 4;
338 while (stuffing_units--) {
339 memset(txt_buf, 0xff, 46);
347 txt_pkt.
data = txt_buf0;
348 txt_pkt.
size = txt_buf - txt_buf0;
367 BMDTimeValue audio_pts;
373 audioFrame->GetBytes(&audioFrameBytes);
399 BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *
mode,
400 BMDDetectedVideoInputFormatFlags)
411 ctx->dli->SetCallback(
ctx->input_callback);
412 return ctx->dli->StartStreams();
422 if (
ctx->capture_started) {
423 ctx->dli->StopStreams();
424 ctx->dli->DisableVideoInput();
425 ctx->dli->DisableAudioInput();
444 IDeckLinkDisplayModeIterator *itermode;
445 IDeckLinkIterator *iter;
446 IDeckLink *dl =
NULL;
463 if (
ctx->teletext_lines) {
464 av_log(avctx,
AV_LOG_ERROR,
"Libzvbi support is needed for capturing teletext, please recompile FFmpeg.\n");
480 iter = CreateDeckLinkIteratorInstance();
487 if (
ctx->list_devices) {
493 tmp=strchr (fname,
'@');
495 mode_num = atoi (tmp+1);
500 while (iter->Next(&dl) ==
S_OK) {
501 const char *displayName;
503 if (!strcmp(fname, displayName)) {
518 if (
ctx->dl->QueryInterface(IID_IDeckLinkInput, (
void **) &
ctx->dli) !=
S_OK) {
526 if (
ctx->list_formats) {
533 if (
ctx->dli->GetDisplayModeIterator(&itermode) !=
S_OK) {
556 st->codec->sample_rate = bmdAudioSampleRate48kHz;
567 st->codec->width =
ctx->bmd_width;
568 st->codec->height =
ctx->bmd_height;
570 st->codec->time_base.den =
ctx->bmd_tb_den;
571 st->codec->time_base.num =
ctx->bmd_tb_num;
576 st->codec->codec_tag =
MKTAG(
'V',
'2',
'1',
'0');
580 st->codec->codec_tag =
MKTAG(
'U',
'Y',
'V',
'Y');
587 if (
ctx->teletext_lines) {
594 st->codec->time_base.den =
ctx->bmd_tb_den;
595 st->codec->time_base.num =
ctx->bmd_tb_num;
598 ctx->teletext_st = st;
602 result =
ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger,
ctx->audio_st->codec->channels);
604 if (result !=
S_OK) {
609 result =
ctx->dli->EnableVideoInput(
ctx->bmd_mode,
610 cctx->
v210 ? bmdFormat10BitYUV : bmdFormat8BitYUV,
611 bmdVideoInputFlagDefault);
613 if (result !=
S_OK) {
642 if (frame && (
ctx->bmd_field_dominance == bmdUpperFieldFirst ||
ctx->bmd_field_dominance == bmdLowerFieldFirst)) {
644 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.
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.
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)
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.
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.