Go to the documentation of this file.
   34 #include <DeckLinkAPI.h> 
   59 #define MAX_WIDTH_VANC 1920 
   78     {bmdModeNTSC, 11, 19, 274, 282},
 
   79     {bmdModeNTSC2398, 11, 19, 274, 282},
 
   80     {bmdModePAL, 7, 22, 320, 335},
 
   81     {bmdModeNTSCp, 11, -1, -1, 39},
 
   82     {bmdModePALp, 7, -1, -1, 45},
 
   86     {bmdModeHD1080p2398, 8, -1, -1, 42},
 
   87     {bmdModeHD1080p24, 8, -1, -1, 42},
 
   88     {bmdModeHD1080p25, 8, -1, -1, 42},
 
   89     {bmdModeHD1080p2997, 8, -1, -1, 42},
 
   90     {bmdModeHD1080p30, 8, -1, -1, 42},
 
   91     {bmdModeHD1080i50, 8, 20, 570, 585},
 
   92     {bmdModeHD1080i5994, 8, 20, 570, 585},
 
   93     {bmdModeHD1080i6000, 8, 20, 570, 585},
 
   94     {bmdModeHD1080p50, 8, -1, -1, 42},
 
   95     {bmdModeHD1080p5994, 8, -1, -1, 42},
 
   96     {bmdModeHD1080p6000, 8, -1, -1, 42},
 
  100     {bmdModeHD720p50, 8, -1, -1, 26},
 
  101     {bmdModeHD720p5994, 8, -1, -1, 26},
 
  102     {bmdModeHD720p60, 8, -1, -1, 26},
 
  105     {bmdModeUnknown, 0, -1, -1, -1}
 
  115         virtual HRESULT STDMETHODCALLTYPE 
AllocateBuffer(
unsigned int bufferSize, 
void* *allocatedBuffer)
 
  119                 return E_OUTOFMEMORY;
 
  120             *allocatedBuffer = buf;
 
  128         virtual HRESULT STDMETHODCALLTYPE 
Commit() { 
return S_OK; }
 
  129         virtual HRESULT STDMETHODCALLTYPE 
Decommit() { 
return S_OK; }
 
  132         virtual HRESULT STDMETHODCALLTYPE 
QueryInterface(REFIID iid, LPVOID *ppv) { 
return E_NOINTERFACE; }
 
  149     IUnknown *obj = (
class IUnknown *)opaque;
 
  173     uint16_t vanc_sum = 0;
 
  174     for (
i = 3; 
i < 
len - 1; 
i++) {
 
  178         if ((!!p ^ !!(v & 0x100)) || (np != 1 && np != 2)) {
 
  185     vanc_sum |= ((~vanc_sum & 0x100) << 1);
 
  186     if (checksum != vanc_sum) {
 
  198         *dst++ = (
src[1] >> 2) + ((
src[2] & 15) << 6);
 
  199         *dst++ =  
src[4]       + ((
src[5] &  3) << 8);
 
  200         *dst++ = (
src[6] >> 4) + ((
src[7] & 63) << 4);
 
  208     for (
i = 0; 
i < 
width * 2 / 3; 
i++) {
 
  209         *dst++ =  
src[0]       + ((
src[1] & 3)  << 8);
 
  210         *dst++ = (
src[1] >> 2) + ((
src[2] & 15) << 6);
 
  211         *dst++ = (
src[2] >> 4) + ((
src[3] & 63) << 4);
 
  218     uint8_t 
ret = (
line < 313) << 5;
 
  235 static uint8_t* teletext_data_unit_from_vbi_data(
int line, uint8_t *
src, uint8_t *tgt, vbi_pixfmt fmt)
 
  237     vbi_bit_slicer slicer;
 
  239     vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, fmt);
 
  241     if (vbi_bit_slice(&slicer, 
src, tgt + 4) == FALSE)
 
  249 static uint8_t* teletext_data_unit_from_vbi_data_10bit(
int line, uint8_t *
src, uint8_t *tgt)
 
  253     uint8_t *pend = y + 720;
 
  258         *py++ = (
src[1] >> 4) + ((
src[2] & 15) << 4);
 
  259         *py++ = (
src[4] >> 2) + ((
src[5] & 3 ) << 6);
 
  260         *py++ = (
src[6] >> 6) + ((
src[7] & 63) << 2);
 
  263     return teletext_data_unit_from_vbi_data(
line, y, tgt, VBI_PIXFMT_YUV420);
 
  271     if (py[0] != 0x255 || py[1] != 0x255 || py[2] != 0x227)
 
  279     for (
i = 0; 
i < 42; 
i++)
 
  298         if (py[0] == 0x151 && py[1] == 0x115 && py[3] == 0x102) {       
 
  299             uint16_t *descriptors = py + 4;
 
  302             for (
i = 0; 
i < 5 && py < pend - 45; 
i++, py += 45) {
 
  303                 int line = (descriptors[
i] & 31) + (!(descriptors[
i] & 128)) * 313;
 
  314     uint16_t did = py[0];                                               
 
  315     uint16_t sdid = py[1];                                              
 
  316     uint16_t 
dc = py[2] & 255;                                          
 
  319     if (did == 0x143 && sdid == 0x102) {                                
 
  321     } 
else if (allow_multipacket && did == 0x143 && sdid == 0x203) {    
 
  323         while (py < pend - 3) {
 
  325             py += 4 + (py[2] & 255);                                    
 
  334     size_t i, 
len = (buf[5] & 0xff) + 6 + 1;
 
  335     uint8_t cdp_sum, rate;
 
  338     uint16_t *cdp = &buf[6]; 
 
  339     if (cdp[0] != 0x96 || cdp[1] != 0x69) {
 
  352     for (
i = 0; 
i < 
len - 1; 
i++)
 
  354     cdp_sum = cdp_sum ? 256 - cdp_sum : 0;
 
  355     if (cdp[
len - 1] != cdp_sum) {
 
  361     if (!(rate & 0x0f)) {
 
  371     if (!(cdp[4] & 0x43))  {
 
  376     hdr = (cdp[5] << 8) | cdp[6];
 
  377     if (cdp[7] != 0x72)  {
 
  383     if (!(cc_count & 0xe0)) {
 
  389     if ((
len - 13) < cc_count * 3) {
 
  394     if (cdp[
len - 4] != 0x74)  {
 
  399     ftr = (cdp[
len - 3] << 8) | cdp[
len - 2];
 
  411     for (
size_t i = 0; 
i < cc_count; 
i++) {
 
  412         cc[3*
i + 0] = cdp[9 + 3*
i+0] ;
 
  413         cc[3*
i + 1] = cdp[9 + 3*
i+1];
 
  414         cc[3*
i + 2] = cdp[9 + 3*
i+2];
 
  425     uint16_t *max_buf = buf + 
width;
 
  427     while (buf < max_buf - 6) {
 
  429         uint16_t did = buf[3] & 0xFF;                                  
 
  430         uint16_t sdid = buf[4] & 0xFF;                                 
 
  432         if (buf[0] != 0 || buf[1] != 0x3ff || buf[2] != 0x3ff) {
 
  436         len = (buf[5] & 0xff) + 6 + 1;
 
  437         if (
len > max_buf - buf) {
 
  443         if (did == 0x43 && (sdid == 0x02 || sdid == 0x03) && cctx->
teletext_lines &&
 
  444             width == 1920 && tgt_size >= 1920) {
 
  450         } 
else if (did == 0x61 && sdid == 0x01) {
 
  451             unsigned int data_len;
 
  477     const uint8_t KLV_DID = 0x44;
 
  478     const uint8_t KLV_IN_VANC_SDID = 0x04;
 
  482         uint16_t sequence_counter;
 
  483         std::vector<uint8_t> 
data;
 
  486     size_t total_size = 0;
 
  487     std::vector<std::vector<KLVPacket>> klv_packets(256);
 
  489     IDeckLinkVideoFrameAncillaryPackets *packets = 
nullptr;
 
  490     if (videoFrame->QueryInterface(IID_IDeckLinkVideoFrameAncillaryPackets, (
void**)&packets) != S_OK)
 
  493     IDeckLinkAncillaryPacketIterator *
it = 
nullptr;
 
  494     if (packets->GetPacketIterator(&
it) != S_OK) {
 
  499     IDeckLinkAncillaryPacket *
packet = 
nullptr;
 
  501         uint8_t *
data = 
nullptr;
 
  504         if (
packet->GetDID() == KLV_DID && 
packet->GetSDID() == KLV_IN_VANC_SDID) {
 
  507             if (
packet->GetBytes(bmdAncillaryPacketFormatUInt8, (
const void**) &
data, &
size) == S_OK) {
 
  510                     uint8_t mid = 
data[0];
 
  511                     uint16_t psc = 
data[1] << 8 | 
data[2];
 
  515                     auto& 
list = klv_packets[mid];
 
  516                     uint16_t expected_psc = 
list.size() + 1;
 
  518                     if (psc == expected_psc) {
 
  519                         uint32_t data_len = 
size - 3;
 
  520                         total_size += data_len;
 
  523                         packet.data.resize(data_len);
 
  524                         memcpy(
packet.data.data(), 
data + 3, data_len);
 
  531                             for (
auto& klv : 
list)
 
  532                                 total_size -= klv.data.size();
 
  547     if (total_size > 0) {
 
  548         std::vector<uint8_t> klv;
 
  549         klv.reserve(total_size);
 
  551         for (
size_t i = 0; 
i < klv_packets.size(); ++
i) {
 
  552             auto& 
list = klv_packets[
i];
 
  560                 klv.insert(klv.end(), 
packet.data.begin(), 
packet.data.end());
 
  568         klv_packet.
data = klv.data();
 
  569         klv_packet.
size = klv.size();
 
  583         virtual HRESULT STDMETHODCALLTYPE 
QueryInterface(REFIID iid, LPVOID *ppv) { 
return E_NOINTERFACE; }
 
  584         virtual ULONG STDMETHODCALLTYPE 
AddRef(
void);
 
  585         virtual ULONG STDMETHODCALLTYPE  
Release(
void);
 
  586         virtual HRESULT STDMETHODCALLTYPE 
VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
 
  587         virtual HRESULT STDMETHODCALLTYPE 
VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);
 
  625                            IDeckLinkAudioInputPacket *audioFrame,
 
  627                            int64_t abs_wallclock,
 
  633     BMDTimeValue bmd_pts;
 
  634     BMDTimeValue bmd_duration;
 
  635     HRESULT res = E_INVALIDARG;
 
  639                 res = audioFrame->GetPacketTime(&bmd_pts, time_base.
den);
 
  643                 res = videoFrame->GetStreamTime(&bmd_pts, &bmd_duration, time_base.
den);
 
  647                 res = videoFrame->GetHardwareReferenceTimestamp(time_base.
den, &bmd_pts, &bmd_duration);
 
  666         pts = bmd_pts / time_base.
num;
 
  680     IDeckLinkTimecode *timecode;
 
  682 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000 
  683     int hfr = (
tc_format == bmdTimecodeRP188HighFrameRate);
 
  687     if (videoFrame->GetTimecode(
tc_format, &timecode) == S_OK) {
 
  688         uint8_t hh, mm, 
ss, ff;
 
  689         if (timecode->GetComponents(&hh, &mm, &
ss, &ff) == S_OK) {
 
  692                 ff = ff << 1 | !!(timecode->GetFlags() & bmdTimecodeFieldMark);
 
  709 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000 
  725     IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioFrame)
 
  728     void *audioFrameBytes;
 
  729     BMDTimeValue frameTime;
 
  730     BMDTimeValue frameDuration;
 
  731     int64_t wallclock = 0, abs_wallclock = 0;
 
  735         if (videoFrame && !(videoFrame->GetFlags() & bmdFrameHasNoInputSource) &&
 
  747         if (
av_cmp_q(remainder, frame_duration) > 0) {
 
  765                     "Frame received (#%lu) - Valid (%liB) - QSize %fMB\n",
 
  767                     videoFrame->GetRowBytes() * videoFrame->GetHeight(),
 
  768                     (
double)qsize / 1024 / 1024);
 
  771         videoFrame->GetBytes(&frameBytes);
 
  772         videoFrame->GetStreamTime(&frameTime, &frameDuration,
 
  775         if (videoFrame->GetFlags() & bmdFrameHasNoInputSource) {
 
  776             if (
ctx->
draw_bars && videoFrame->GetPixelFormat() == bmdFormat8BitYUV) {
 
  778                     0xEA80EA80, 0xD292D210, 0xA910A9A5, 0x90229035,
 
  779                     0x6ADD6ACA, 0x51EF515A, 0x286D28EF, 0x10801080 };
 
  780                 int width  = videoFrame->GetWidth();
 
  781                 int height = videoFrame->GetHeight();
 
  782                 unsigned *p = (
unsigned *)frameBytes;
 
  784                 for (
int y = 0; y < 
height; y++) {
 
  785                     for (
int x = 0; x < 
width; x += 2)
 
  786                         *p++ = bars[(x * 8) / 
width];
 
  810                         uint8_t* packed_metadata;
 
  814                             int size = 
sizeof(uint32_t) * 4;
 
  827                             if (packed_metadata) {
 
  856         pkt.
data         = (uint8_t *)frameBytes;
 
  857         pkt.
size         = videoFrame->GetRowBytes() *
 
  858                            videoFrame->GetHeight();
 
  862             IDeckLinkVideoFrameAncillary *vanc;
 
  864             uint8_t txt_buf0[3531]; 
 
  865             uint8_t *txt_buf = txt_buf0;
 
  871             if (videoFrame->GetAncillaryData(&vanc) == S_OK) {
 
  873                 BMDPixelFormat vanc_format = vanc->GetPixelFormat();
 
  878                     (vanc_format == bmdFormat8BitYUV || vanc_format == bmdFormat10BitYUV)) {
 
  879                     int64_t line_mask = 1;
 
  881                     for (
i = 6; 
i < 336; 
i++, line_mask <<= 1) {
 
  883                         if ((
ctx->
teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(
i, (
void**)&buf) == S_OK) {
 
  884                             if (vanc_format == bmdFormat8BitYUV)
 
  885                                 txt_buf = teletext_data_unit_from_vbi_data(
i, buf, txt_buf, VBI_PIXFMT_UYVY);
 
  887                                 txt_buf = teletext_data_unit_from_vbi_data_10bit(
i, buf, txt_buf);
 
  894                 if (vanc_format == bmdFormat10BitYUV && videoFrame->GetWidth() <= 
MAX_WIDTH_VANC) {
 
  898                         if (vanc->GetBufferForVerticalBlankingLine(
i, (
void**)&buf) == S_OK) {
 
  900                             size_t vanc_size = videoFrame->GetWidth();
 
  902                                 vanc_size = vanc_size * 2;
 
  908                                                    txt_buf, 
sizeof(txt_buf0) - (txt_buf - txt_buf0), &
pkt);
 
  915                 if (txt_buf - txt_buf0 > 1) {
 
  916                     int stuffing_units = (4 - ((45 + txt_buf - txt_buf0) / 46) % 4) % 4;
 
  917                     while (stuffing_units--) {
 
  918                         memset(txt_buf, 0xff, 46);
 
  925                     txt_pkt.
data = txt_buf0;
 
  926                     txt_pkt.
size = txt_buf - txt_buf0;
 
  936             videoFrame->AddRef();
 
  946         BMDTimeValue audio_pts;
 
  950         audioFrame->GetBytes(&audioFrameBytes);
 
  958         pkt.
data         = (uint8_t *)audioFrameBytes;
 
  969     BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *
mode,
 
  970     BMDDetectedVideoInputFormatFlags formatFlags)
 
  976         ctx->
raw_format = (formatFlags & bmdDetectedVideoInputRGB444) ? bmdFormat8BitARGB : bmdFormat8BitYUV;
 
  985     if (
ctx->attr->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &autodetect_supported) != S_OK)
 
  987     if (autodetect_supported == 
false)
 
  991     ctx->bmd_mode  = bmdModeUnknown;
 
  994                                    bmdVideoInputEnableFormatDetection) != S_OK) {
 
  998     if (
ctx->dli->StartStreams() != S_OK) {
 
 1003     for (
i = 0; 
i < 30; 
i++) {
 
 1008         if (
ctx->bmd_mode != bmdModeUnknown &&
 
 1013     ctx->dli->PauseStreams();
 
 1014     ctx->dli->FlushStreams();
 
 1015     ctx->autodetect = 0;
 
 1016     if (
ctx->bmd_mode != bmdModeUnknown) {
 
 1036         ctx->dli->StopStreams();
 
 1037         ctx->dli->DisableVideoInput();
 
 1038         ctx->dli->DisableAudioInput();
 
 1099             av_log(avctx, 
AV_LOG_ERROR, 
"Value for audio bit depth option must be either 16 or 32\n");
 
 1104     if (
ctx->list_devices) {
 
 1114     if (
ctx->dl->QueryInterface(IID_IDeckLinkInput, (
void **) &
ctx->dli) != S_OK) {
 
 1128     if (
ctx->list_formats) {
 
 1144     allocator->Release();
 
 1158     if (
ctx->raw_format == (BMDPixelFormat)0)
 
 1159         ctx->raw_format = bmdFormat8BitYUV;
 
 1168     if (
ctx->teletext_lines && 
ctx->bmd_mode == bmdModePAL) {
 
 1169         av_log(avctx, 
AV_LOG_ERROR, 
"Libzvbi support is needed for capturing SD PAL teletext, please recompile FFmpeg.\n");
 
 1184     st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
 
 1196     st->codecpar->width       = 
ctx->bmd_width;
 
 1197     st->codecpar->height      = 
ctx->bmd_height;
 
 1199     st->time_base.den      = 
ctx->bmd_tb_den;
 
 1200     st->time_base.num      = 
ctx->bmd_tb_num;
 
 1201     st->r_frame_rate       = 
av_make_q(st->time_base.den, st->time_base.num);
 
 1203     switch(
ctx->raw_format) {
 
 1204     case bmdFormat8BitYUV:
 
 1207         st->codecpar->bit_rate    = 
av_rescale(
ctx->bmd_width * 
ctx->bmd_height * 16, st->time_base.den, st->time_base.num);
 
 1209     case bmdFormat10BitYUV:
 
 1211         st->codecpar->bit_rate    = 
av_rescale(
ctx->bmd_width * 
ctx->bmd_height * 64, st->time_base.den, st->time_base.num * 3);
 
 1213     case bmdFormat8BitARGB:
 
 1216         st->codecpar->bit_rate    = 
av_rescale(
ctx->bmd_width * 
ctx->bmd_height * 32, st->time_base.den, st->time_base.num);
 
 1218     case bmdFormat8BitBGRA:
 
 1221         st->codecpar->bit_rate    = 
av_rescale(
ctx->bmd_width * 
ctx->bmd_height * 32, st->time_base.den, st->time_base.num);
 
 1223     case bmdFormat10BitRGB:
 
 1225         st->codecpar->bit_rate    = 
av_rescale(
ctx->bmd_width * 
ctx->bmd_height * 30, st->time_base.den, st->time_base.num);
 
 1235     switch (
ctx->bmd_field_dominance) {
 
 1236     case bmdUpperFieldFirst:
 
 1239     case bmdLowerFieldFirst:
 
 1242     case bmdProgressiveFrame:
 
 1243     case bmdProgressiveSegmentedFrame:
 
 1252     if (
ctx->enable_klv) {
 
 1259         st->time_base.den        = 
ctx->bmd_tb_den;
 
 1260         st->time_base.num        = 
ctx->bmd_tb_num;
 
 1266     if (
ctx->teletext_lines) {
 
 1274         st->time_base.den         = 
ctx->bmd_tb_den;
 
 1275         st->time_base.num         = 
ctx->bmd_tb_num;
 
 1278         ctx->teletext_st = st;
 
 1281     av_log(avctx, 
AV_LOG_VERBOSE, 
"Using %d input audio channels\n", 
ctx->audio_st->codecpar->ch_layout.nb_channels);
 
 1282     result = 
ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, cctx->
audio_depth == 32 ? bmdAudioSampleType32bitInteger : bmdAudioSampleType16bitInteger, 
ctx->audio_st->codecpar->ch_layout.nb_channels);
 
 1292                                         bmdVideoInputFlagDefault);
 
 1302     if (
ctx->dli->StartStreams() != S_OK) {
 
 1325         if (side_metadata) {
 
  
static uint8_t * get_metadata(AVFormatContext *avctx, uint16_t *buf, size_t width, uint8_t *tgt, size_t tgt_size, AVPacket *pkt)
static void error(const char *err)
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_TIMECODE_STR_SIZE
static uint8_t * teletext_data_unit_from_ancillary_packet(uint16_t *py, uint16_t *pend, uint8_t *tgt, int64_t wanted_lines, int allow_multipacket)
int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
static int get_frame_timecode(AVFormatContext *avctx, decklink_ctx *ctx, AVTimecode *tc, IDeckLinkVideoInputFrame *videoFrame)
const BMDDisplayMode AUTODETECT_DEFAULT_MODE
DecklinkPtsSource video_pts_source
av_cold int ff_decklink_read_close(AVFormatContext *avctx)
@ AV_CODEC_ID_DVB_TELETEXT
const uint8_t ff_reverse[256]
virtual HRESULT STDMETHODCALLTYPE Decommit()
static const BMDPixelFormat decklink_raw_format_map[]
DecklinkPtsSource audio_pts_source
@ AV_PKT_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1:2014.
#define AV_LOG_VERBOSE
Detailed information.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
void ff_decklink_packet_queue_end(DecklinkPacketQueue *q)
int nb_channels
Number of channels in this layout.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int get_vanc_line_idx(BMDDisplayMode mode)
virtual ~decklink_allocator()
int ff_decklink_init_device(AVFormatContext *avctx, const char *name)
DecklinkPacketQueue queue
@ AV_FIELD_TT
Top coded_first, top displayed first.
void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs)
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
#define AV_FOURCC_MAX_STRING_SIZE
DecklinkPtsSource audio_pts_source
char * av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum)
Load timecode string in buf.
#define ss(width, name, subs,...)
static const BMDVideoConnection decklink_video_connection_map[]
int ff_decklink_read_packet(AVFormatContext *avctx, AVPacket *pkt)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
#define FF_ARRAY_ELEMS(a)
static const uint16_t mask[17]
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static uint8_t * teletext_data_unit_from_op47_data(uint16_t *py, uint16_t *pend, uint8_t *tgt, int64_t wanted_lines)
static const BMDAudioConnection decklink_audio_connection_map[]
static void decklink_object_free(void *opaque, uint8_t *data)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static int check_vanc_parity_checksum(uint16_t *buf, int len, uint16_t checksum)
int av_usleep(unsigned usec)
Sleep for a period of time.
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int block)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
and forward the result(frame or status change) to the corresponding input. If nothing is possible
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Rational number (pair of numerator and denominator).
static const BMDTimecodeFormat decklink_timecode_format_map[]
virtual HRESULT STDMETHODCALLTYPE Commit()
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
av_cold int ff_decklink_read_header(AVFormatContext *avctx)
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction)
AVChannelLayout ch_layout
Audio only.
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
int av_timecode_init_from_components(AVTimecode *tc, AVRational rate, int flags, int hh, int mm, int ss, int ff, void *log_ctx)
Init a timecode struct from the passed timecode components.
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
virtual HRESULT STDMETHODCALLTYPE ReleaseBuffer(void *buffer)
static int shift(int a, int b)
char * url
input or output URL.
static AVRational av_make_q(int num, int den)
Create an AVRational.
#define AV_NOPTS_VALUE
Undefined timestamp value.
char * av_fourcc_make_string(char *buf, uint32_t fourcc)
Fill the provided buffer with a string containing a FourCC (four-character code) representation.
int ff_decklink_list_input_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list)
static int get_bmd_timecode(AVFormatContext *avctx, AVTimecode *tc, AVRational frame_rate, BMDTimecodeFormat tc_format, IDeckLinkVideoInputFrame *videoFrame)
static int decklink_autodetect(struct decklink_cctx *cctx)
int av_packet_unpack_dictionary(const uint8_t *data, size_t size, AVDictionary **dict)
Unpack a dictionary from side_data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *q, int64_t queue_size)
int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction)
#define AVERROR_EXTERNAL
Generic error in an external library.
uint8_t * av_packet_pack_dictionary(AVDictionary *dict, size_t *size)
Pack a dictionary for use in side_data.
int flags
A combination of AV_PKT_FLAG values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
void ff_decklink_cleanup(AVFormatContext *avctx)
#define AV_LOG_INFO
Standard information.
static void fill_data_unit_head(int line, uint8_t *tgt)
DecklinkPtsSource video_pts_source
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
static uint8_t calc_parity_and_line_offset(int line)
uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum)
Convert frame number to SMPTE 12M binary representation.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
#define AV_TIME_BASE
Internal time base represented as integer.
static VANCLineNumber vanc_line_numbers[]
@ AV_FIELD_BB
Bottom coded first, bottom displayed first.
enum AVPacketSideDataType packet
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 AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static uint8_t * teletext_data_unit_from_op47_vbi_packet(int line, uint16_t *py, uint8_t *tgt)
@ AV_TIMECODE_FLAG_DROPFRAME
timecode is drop frame
static int linemask_matches(int line, int64_t mask)
static void unpack_v210(uint16_t *dst, const uint8_t *src, int width)
unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q)
#define AV_INPUT_BUFFER_PADDING_SIZE
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
int index
stream index in AVFormatContext
static void input_callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
static int64_t get_pkt_pts(IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioFrame, int64_t wallclock, int64_t abs_wallclock, DecklinkPtsSource pts_src, AVRational time_base, int64_t *initial_pts, int copyts)
AVRational r_frame_rate
Real base framerate of the stream.
int64_t av_gettime(void)
Get the current time in microseconds.
virtual ULONG STDMETHODCALLTYPE Release(void)
@ AV_PKT_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
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)
virtual ULONG STDMETHODCALLTYPE AddRef(void)
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s it
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv)
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define flags(name, subs,...)
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
static void extract_luma_from_v210(uint16_t *dst, const uint8_t *src, int width)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
void * priv_data
Format private data.
BMDTimecodeFormat tc_format
int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs)
static void handle_klv(AVFormatContext *avctx, decklink_ctx *ctx, IDeckLinkVideoInputFrame *videoFrame, int64_t pts)
BMDPixelFormat raw_format
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
static void clear_parity_bits(uint16_t *buf, int len)
virtual HRESULT STDMETHODCALLTYPE AllocateBuffer(unsigned int bufferSize, void **allocatedBuffer)
static uint8_t * vanc_to_cc(AVFormatContext *avctx, uint16_t *buf, size_t words, unsigned &cc_count)