39 NDIlib_recv_create_t *
recv;
58 av_log(avctx,
AV_LOG_DEBUG,
"%s: pkt->dts = pkt->pts = %"PRId64
", duration=%"PRId64
", timecode=%"PRId64
"\n",
64 memcpy(pkt->
data, v->p_data, pkt->
size);
74 NDIlib_audio_frame_interleaved_16s_t dst;
83 av_log(avctx,
AV_LOG_DEBUG,
"%s: pkt->dts = pkt->pts = %"PRId64
", duration=%"PRId64
", timecode=%"PRId64
"\n",
89 dst.reference_level = 0;
90 dst.p_data = (
short *)pkt->
data;
91 NDIlib_util_audio_to_interleaved_16s(a, &dst);
101 const NDIlib_source_t *ndi_srcs =
NULL;
102 const NDIlib_find_create_t find_create_desc = { .show_local_sources =
true,
106 ctx->
ndi_find = NDIlib_find_create2(&find_create_desc);
116 f = NDIlib_find_wait_for_sources(ctx->
ndi_find, t);
122 ndi_srcs = NDIlib_find_get_current_sources(ctx->
ndi_find, &n);
127 for (i = 0; i <
n; i++) {
129 av_log(avctx,
AV_LOG_INFO,
"\t'%s'\t'%s'\n", ndi_srcs[i].p_ndi_name, ndi_srcs[i].p_ip_address);
131 if (!strcmp(name, ndi_srcs[i].p_ndi_name)) {
132 *source_to_connect_to = ndi_srcs[i];
143 NDIlib_recv_create_t recv_create_desc;
144 const NDIlib_tally_t tally_state = { .on_program =
true, .on_preview =
false };
147 if (!NDIlib_initialize()) {
161 recv_create_desc.color_format = NDIlib_recv_color_format_e_UYVY_RGBA;
162 recv_create_desc.bandwidth = NDIlib_recv_bandwidth_highest;
166 ctx->
recv = NDIlib_recv_create(&recv_create_desc);
173 NDIlib_recv_set_tally(ctx->
recv, &tally_state);
196 av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den,
tmp.num,
tmp.den, 1000);
197 st->codecpar->sample_aspect_ratio = st->sample_aspect_ratio;
200 st->codecpar->width = v->xres;
201 st->codecpar->height = v->yres;
203 st->codecpar->bit_rate =
av_rescale(v->xres * v->yres * 16, v->frame_rate_N, v->frame_rate_D);
204 st->codecpar->field_order = v->frame_format_type == NDIlib_frame_format_type_progressive
207 if (NDIlib_FourCC_type_UYVY == v->FourCC || NDIlib_FourCC_type_UYVA == v->FourCC) {
209 st->codecpar->codec_tag =
MKTAG(
'U',
'Y',
'V',
'Y');
210 if (NDIlib_FourCC_type_UYVA == v->FourCC)
212 }
else if (NDIlib_FourCC_type_BGRA == v->FourCC) {
214 st->codecpar->codec_tag =
MKTAG(
'B',
'G',
'R',
'A');
215 }
else if (NDIlib_FourCC_type_BGRX == v->FourCC) {
217 st->codecpar->codec_tag =
MKTAG(
'B',
'G',
'R',
'0');
218 }
else if (NDIlib_FourCC_type_RGBA == v->FourCC) {
220 st->codecpar->codec_tag =
MKTAG(
'R',
'G',
'B',
'A');
221 }
else if (NDIlib_FourCC_type_RGBX == v->FourCC) {
223 st->codecpar->codec_tag =
MKTAG(
'R',
'G',
'B',
'0');
225 av_log(avctx,
AV_LOG_ERROR,
"Unsupported video stream format, v->FourCC=%d\n", v->FourCC);
265 NDIlib_video_frame_t v;
266 NDIlib_audio_frame_t
a;
267 NDIlib_metadata_frame_t m;
268 NDIlib_frame_type_e t;
271 t = NDIlib_recv_capture(ctx->
recv, &v, &a, &m, 40);
274 if (t == NDIlib_frame_type_video) {
279 NDIlib_recv_free_video(ctx->
recv, &v);
282 else if (t == NDIlib_frame_type_audio) {
287 NDIlib_recv_free_audio(ctx->
recv, &a);
290 else if (t == NDIlib_frame_type_metadata)
291 NDIlib_recv_free_metadata(ctx->
recv, &m);
292 else if (t == NDIlib_frame_type_error){
306 NDIlib_recv_destroy(ctx->
recv);
314 #define OFFSET(x) offsetof(struct NDIContext, x)
315 #define DEC AV_OPT_FLAG_DECODING_PARAM
334 .
name =
"libndi_newtek",
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int index
stream index in AVFormatContext
const char * av_default_item_name(void *ptr)
Return the context name.
static const AVOption options[]
int ctx_flags
Flags signalling stream properties.
static int ndi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
AVInputFormat ff_libndi_newtek_demuxer
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int ndi_read_header(AVFormatContext *avctx)
NDIlib_recv_create_t * recv
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
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.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#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.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
char * url
input or output URL.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVMediaType codec_type
General type of the encoded data.
static int ndi_create_video_stream(AVFormatContext *avctx, NDIlib_video_frame_t *v)
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int flags
A combination of AV_PKT_FLAG values.
static int ndi_read_close(AVFormatContext *avctx)
NDIlib_find_instance_t ndi_find
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static const AVClass libndi_newtek_demuxer_class
static int ndi_find_sources(AVFormatContext *avctx, const char *name, NDIlib_source_t *source_to_connect_to)
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AV_LOG_INFO
Standard information.
static AVRational av_make_q(int num, int den)
Create an AVRational.
Describe the class of an AVClass context structure.
static int ndi_create_audio_stream(AVFormatContext *avctx, NDIlib_audio_frame_t *a)
Rational number (pair of numerator and denominator).
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
static int ndi_set_video_packet(AVFormatContext *avctx, NDIlib_video_frame_t *v, AVPacket *pkt)
static int ndi_set_audio_packet(AVFormatContext *avctx, NDIlib_audio_frame_t *a, AVPacket *pkt)
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
int sample_rate
Audio only.
void * priv_data
Format private data.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
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)
AVRational r_frame_rate
Real base framerate of the stream.
#define AVERROR_EXTERNAL
Generic error in an external library.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...