31 #include <DeckLinkAPI.h>
42 #include "libklvanc/vanc.h"
43 #include "libklvanc/vanc-lines.h"
44 #include "libklvanc/pixels.h"
62 return ((
GetWidth() + 47) / 48) * 128;
67 return bmdFormat8BitYUV;
69 return bmdFormat10BitYUV;
71 virtual BMDFrameFlags STDMETHODCALLTYPE
GetFlags (
void)
74 return _avframe->
linesize[0] < 0 ? bmdFrameFlagFlipVertical : bmdFrameFlagDefault;
76 return bmdFrameFlagDefault;
178 " Only AV_PIX_FMT_UYVY422 is supported.\n");
181 ctx->raw_format = bmdFormat8BitYUV;
184 " Only V210 and wrapped frame with AV_PIX_FMT_UYVY422 are supported.\n");
187 ctx->raw_format = bmdFormat10BitYUV;
197 " Check available formats with -list_formats 1.\n");
200 if (
ctx->dlo->EnableVideoOutput(
ctx->bmd_mode,
201 ctx->supports_vanc ? bmdVideoOutputVANC : bmdVideoOutputFlagDefault) !=
S_OK) {
208 ctx->dlo->SetScheduledFrameCompletionCallback(
ctx->output_callback);
212 ctx->frames_preroll /= 1000;
215 ctx->frames_buffer =
ctx->frames_preroll * 2;
216 ctx->frames_buffer =
FFMIN(
ctx->frames_buffer, 60);
219 ctx->frames_buffer_available_spots =
ctx->frames_buffer;
222 avctx->
url,
ctx->frames_preroll,
ctx->frames_buffer);
244 " Only 48kHz is supported.\n");
249 " Only 2, 8 or 16 channels are supported.\n");
252 if (
ctx->dlo->EnableAudioOutput(bmdAudioSampleRate48kHz,
253 bmdAudioSampleType16bitInteger,
255 bmdAudioOutputStreamTimestamped) !=
S_OK) {
259 if (
ctx->dlo->BeginAudioPreroll() !=
S_OK) {
278 if (
ctx->playback_started) {
280 ctx->dlo->StopScheduledPlayback(
ctx->last_pts *
ctx->bmd_tb_num,
281 &actual,
ctx->bmd_tb_den);
282 ctx->dlo->DisableVideoOutput();
284 ctx->dlo->DisableAudioOutput();
289 if (
ctx->output_callback)
290 delete ctx->output_callback;
296 klvanc_context_destroy(
ctx->vanc_ctx);
306 AVPacket *
pkt,
struct klvanc_line_set_s *vanc_lines)
308 struct klvanc_packet_eia_708b_s *cdp;
320 ret = klvanc_create_eia708_cdp(&cdp);
328 klvanc_destroy_eia708_cdp(cdp);
332 if (cc_count > KLVANC_MAX_CC_COUNT) {
334 cc_count = KLVANC_MAX_CC_COUNT;
338 cdp->header.ccdata_present = 1;
339 cdp->header.caption_service_active = 1;
340 cdp->ccdata.cc_count = cc_count;
341 for (i = 0; i < cc_count; i++) {
342 if (data [3*i] & 0x04)
343 cdp->ccdata.cc[i].cc_valid = 1;
344 cdp->ccdata.cc[i].cc_type = data[3*i] & 0x03;
345 cdp->ccdata.cc[i].cc_data[0] = data[3*i+1];
346 cdp->ccdata.cc[i].cc_data[1] = data[3*i+2];
350 ret = klvanc_convert_EIA_708B_to_words(cdp, &cdp_words, &len);
351 klvanc_destroy_eia708_cdp(cdp);
357 ret = klvanc_line_insert(ctx->vanc_ctx, vanc_lines, cdp_words, len, 11, 0);
368 struct klvanc_line_set_s vanc_lines = { 0 };
374 construct_cc(avctx, ctx, pkt, &vanc_lines);
376 IDeckLinkVideoFrameAncillary *vanc;
377 int result = ctx->
dlo->CreateAncillaryData(bmdFormat10BitYUV, &vanc);
378 if (result !=
S_OK) {
386 for (i = 0; i < vanc_lines.num_lines; i++) {
387 struct klvanc_line_s *
line = vanc_lines.lines[i];
396 real_line = line->line_number;
398 result = vanc->GetBufferForVerticalBlankingLine(real_line, &buf);
399 if (result !=
S_OK) {
405 result = klvanc_generate_vanc_line_v210(ctx->vanc_ctx, line, (
uint8_t *) buf,
415 if (result !=
S_OK) {
421 for (i = 0; i < vanc_lines.num_lines; i++)
422 klvanc_line_free(vanc_lines.lines[i]);
464 if (decklink_construct_vanc(avctx, ctx, pkt, frame))
485 hr = ctx->
dlo->ScheduleVideoFrame((
class IDeckLinkVideoFrame *) frame,
492 " error %08x.\n", (uint32_t) hr);
496 ctx->
dlo->GetBufferedVideoFrameCount(&buffered);
498 if (pkt->
pts > 2 && buffered <= 2)
500 " Video may misbehave!\n");
505 if (ctx->
audio && ctx->
dlo->EndAudioPreroll() !=
S_OK) {
527 ctx->
dlo->GetBufferedAudioSampleFrameCount(&buffered);
528 if (pkt->
pts > 1 && !buffered)
530 " Audio will misbehave!\n");
532 if (ctx->
dlo->ScheduleAudioSamples(pkt->
data, sample_count, pkt->
pts,
533 bmdAudioSampleRate48kHz,
NULL) !=
S_OK) {
559 if (klvanc_context_create(&ctx->vanc_ctx) < 0) {
577 if (ctx->
dl->QueryInterface(IID_IDeckLinkOutput, (
void **) &ctx->
dlo) !=
S_OK) {
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
decklink_frame(struct decklink_ctx *ctx, AVFrame *avframe, AVCodecID codec_id, int height, int width)
enum AVFieldOrder field_order
Video only.
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
static const char * format[]
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)
ptrdiff_t const GLvoid * data
virtual long STDMETHODCALLTYPE GetWidth(void)
#define AV_LOG_WARNING
Something somehow does not look correct.
ATSC A53 Part 4 Closed Captions.
static int decklink_setup_video(AVFormatContext *avctx, AVStream *st)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
static int decklink_write_audio_packet(AVFormatContext *avctx, AVPacket *pkt)
decklink_frame(struct decklink_ctx *ctx, AVPacket *avpacket, AVCodecID codec_id, int height, int width)
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)
This struct describes the properties of an encoded stream.
av_cold int ff_decklink_write_trailer(AVFormatContext *avctx)
static int decklink_write_video_packet(AVFormatContext *avctx, AVPacket *pkt)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv)
virtual long STDMETHODCALLTYPE GetHeight(void)
AVStream ** streams
A list of all streams in the file.
void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs)
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)
int frames_buffer_available_spots
int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs)
static int decklink_setup_audio(AVFormatContext *avctx, AVStream *st)
Main libavdevice API header.
virtual ULONG STDMETHODCALLTYPE Release(void)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
virtual HRESULT STDMETHODCALLTYPE ScheduledPlaybackHasStopped(void)
AVPacket * av_packet_clone(const AVPacket *src)
Create a new packet that references the same data as src.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
char * url
input or output URL.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int ff_decklink_list_output_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list)
enum AVMediaType codec_type
General type of the encoded data.
virtual BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat(void)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction)
struct decklink_ctx * _ctx
av_cold int ff_decklink_write_header(AVFormatContext *avctx)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
uint32_t buffercount_type
int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction)
virtual long STDMETHODCALLTYPE GetRowBytes(void)
#define pthread_mutex_unlock(a)
Passthrough codec, AVFrames wrapped in AVPacket.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
static void error(const char *err)
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
virtual ULONG STDMETHODCALLTYPE AddRef(void)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
virtual BMDFrameFlags STDMETHODCALLTYPE GetFlags(void)
virtual HRESULT STDMETHODCALLTYPE GetBytes(void **buffer)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void ff_decklink_cleanup(AVFormatContext *avctx)
int sample_rate
Audio only.
virtual HRESULT STDMETHODCALLTYPE ScheduledFrameCompleted(IDeckLinkVideoFrame *_frame, BMDOutputFrameCompletionResult result)
virtual HRESULT STDMETHODCALLTYPE GetAncillaryData(IDeckLinkVideoFrameAncillary **ancillary)
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
virtual ULONG STDMETHODCALLTYPE AddRef(void)
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
void * priv_data
Format private data.
int ff_decklink_write_packet(AVFormatContext *avctx, AVPacket *pkt)
virtual HRESULT STDMETHODCALLTYPE SetAncillaryData(IDeckLinkVideoFrameAncillary *ancillary)
IDeckLinkVideoFrameAncillary * _ancillary
AVCodecParameters * codecpar
Codec parameters associated with this stream.
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
uint16_t cdp_sequence_num
virtual HRESULT STDMETHODCALLTYPE GetTimecode(BMDTimecodeFormat format, IDeckLinkTimecode **timecode)
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
virtual ULONG STDMETHODCALLTYPE Release(void)