38 NDIlib_recv_create_t *
recv;
57 av_log(avctx,
AV_LOG_DEBUG,
"%s: pkt->dts = pkt->pts = %"PRId64
", duration=%"PRId64
", timecode=%"PRId64
"\n",
63 memcpy(pkt->
data, v->p_data, pkt->
size);
73 NDIlib_audio_frame_interleaved_16s_t dst;
82 av_log(avctx,
AV_LOG_DEBUG,
"%s: pkt->dts = pkt->pts = %"PRId64
", duration=%"PRId64
", timecode=%"PRId64
"\n",
88 dst.reference_level = 0;
89 dst.p_data = (
short *)pkt->
data;
90 NDIlib_util_audio_to_interleaved_16s(a, &dst);
100 const NDIlib_source_t *ndi_srcs =
NULL;
101 const NDIlib_find_create_t find_create_desc = { .show_local_sources =
true,
102 .p_groups =
NULL, .p_extra_ips =
NULL };
105 ctx->
ndi_find = NDIlib_find_create2(&find_create_desc);
115 f = NDIlib_find_wait_for_sources(ctx->
ndi_find, t);
121 ndi_srcs = NDIlib_find_get_current_sources(ctx->
ndi_find, &n);
126 for (i = 0; i <
n; i++) {
128 av_log(avctx,
AV_LOG_INFO,
"\t'%s'\t'%s'\n", ndi_srcs[i].p_ndi_name, ndi_srcs[i].p_ip_address);
130 if (!strcmp(name, ndi_srcs[i].p_ndi_name)) {
131 *source_to_connect_to = ndi_srcs[i];
142 NDIlib_recv_create_t recv_create_desc;
143 const NDIlib_tally_t tally_state = { .on_program =
true, .on_preview =
false };
146 if (!NDIlib_initialize()) {
160 recv_create_desc.color_format = NDIlib_recv_color_format_e_UYVY_RGBA;
161 recv_create_desc.bandwidth = NDIlib_recv_bandwidth_highest;
165 ctx->
recv = NDIlib_recv_create(&recv_create_desc);
172 NDIlib_recv_set_tally(ctx->
recv, &tally_state);
195 av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den,
tmp.num,
tmp.den, 1000);
196 st->codecpar->sample_aspect_ratio = st->sample_aspect_ratio;
199 st->codecpar->width = v->xres;
200 st->codecpar->height = v->yres;
202 st->codecpar->bit_rate =
av_rescale(v->xres * v->yres * 16, v->frame_rate_N, v->frame_rate_D);
203 st->codecpar->field_order = v->frame_format_type == NDIlib_frame_format_type_progressive
206 if (NDIlib_FourCC_type_UYVY == v->FourCC || NDIlib_FourCC_type_UYVA == v->FourCC) {
208 st->codecpar->codec_tag =
MKTAG(
'U',
'Y',
'V',
'Y');
209 if (NDIlib_FourCC_type_UYVA == v->FourCC)
211 }
else if (NDIlib_FourCC_type_BGRA == v->FourCC) {
213 st->codecpar->codec_tag =
MKTAG(
'B',
'G',
'R',
'A');
214 }
else if (NDIlib_FourCC_type_BGRX == v->FourCC) {
216 st->codecpar->codec_tag =
MKTAG(
'B',
'G',
'R',
'0');
217 }
else if (NDIlib_FourCC_type_RGBA == v->FourCC) {
219 st->codecpar->codec_tag =
MKTAG(
'R',
'G',
'B',
'A');
220 }
else if (NDIlib_FourCC_type_RGBX == v->FourCC) {
222 st->codecpar->codec_tag =
MKTAG(
'R',
'G',
'B',
'0');
224 av_log(avctx,
AV_LOG_ERROR,
"Unsupported video stream format, v->FourCC=%d\n", v->FourCC);
264 NDIlib_video_frame_t v;
265 NDIlib_audio_frame_t
a;
266 NDIlib_metadata_frame_t m;
267 NDIlib_frame_type_e t;
270 t = NDIlib_recv_capture(ctx->
recv, &v, &a, &m, 40);
273 if (t == NDIlib_frame_type_video) {
278 NDIlib_recv_free_video(ctx->
recv, &v);
281 else if (t == NDIlib_frame_type_audio) {
286 NDIlib_recv_free_audio(ctx->
recv, &a);
289 else if (t == NDIlib_frame_type_metadata)
290 NDIlib_recv_free_metadata(ctx->
recv, &m);
291 else if (t == NDIlib_frame_type_error){
305 NDIlib_recv_destroy(ctx->
recv);
313 #define OFFSET(x) offsetof(struct NDIContext, x)
314 #define DEC AV_OPT_FLAG_DECODING_PARAM
332 .
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...