39 #define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2) 41 struct sdp_session_level {
58 static void sdp_write_address(
char *buff,
int size,
const char *dest_addr,
59 const char *dest_type,
int ttl)
64 if (ttl > 0 && !strcmp(dest_type,
"IP4")) {
67 av_strlcatf(buff, size,
"c=IN %s %s/%d\r\n", dest_type, dest_addr, ttl);
69 av_strlcatf(buff, size,
"c=IN %s %s\r\n", dest_type, dest_addr);
74 static void sdp_write_header(
char *buff,
int size,
struct sdp_session_level *
s)
77 "o=- %d %d IN %s %s\r\n" 80 s->id, s->version, s->src_type, s->src_addr,
82 sdp_write_address(buff, size, s->dst_addr, s->dst_type, s->ttl);
85 s->start_time, s->end_time);
89 static int resolve_destination(
char *dest_addr,
int size,
char *
type,
104 getnameinfo(ai->ai_addr, ai->ai_addrlen, dest_addr, size,
107 if (ai->ai_family == AF_INET6)
115 static int resolve_destination(
char *dest_addr,
int size,
char *type,
122 static int sdp_get_address(
char *dest_addr,
int size,
int *ttl,
const char *url)
132 if (strcmp(proto,
"rtp") && strcmp(proto,
"srtp")) {
139 p = strchr(url,
'?');
144 *ttl = strtol(buff,
NULL, 10);
153 #define MAX_PSET_SIZE 1024 158 static const char pset_string[] =
"; sprop-parameter-sets=";
159 static const char profile_string[] =
"; profile-level-id=";
183 memcpy(psets, pset_string, strlen(pset_string));
184 p = psets + strlen(pset_string);
186 while (r < extradata + extradata_size) {
191 nal_type = *r & 0x1f;
193 if (nal_type != 7 && nal_type != 8) {
197 if (p != (psets + strlen(pset_string))) {
215 if (sps && sps_end - sps >= 4 && p - psets <= MAX_PSET_SIZE - strlen(profile_string) - 7) {
216 memcpy(p, profile_string, strlen(profile_string));
232 int ps_pos[3] = { 0 };
233 static const char *
const ps_names[3] = {
"vps",
"sps",
"pps" };
234 int num_arrays, num_nalus;
253 if (extradata_size < 23)
256 num_arrays = extradata[22];
258 for (i = 0; i < num_arrays; i++) {
259 int num_nalus, nalu_type;
260 if (pos + 3 > extradata_size)
262 nalu_type = extradata[
pos] & 0x3f;
267 else if (nalu_type == 33)
269 else if (nalu_type == 34)
271 num_nalus =
AV_RB16(&extradata[pos + 1]);
273 for (j = 0; j < num_nalus; j++) {
275 if (pos + 2 > extradata_size)
277 len =
AV_RB16(&extradata[pos]);
279 if (pos + len > extradata_size)
284 if (!ps_pos[0] || !ps_pos[1] || !ps_pos[2])
292 for (i = 0; i < 3; i++) {
297 av_strlcatf(psets, MAX_PSET_SIZE,
"sprop-%s=", ps_names[i]);
301 num_nalus =
AV_RB16(&extradata[pos + 1]);
303 for (j = 0; j < num_nalus; j++) {
304 int len =
AV_RB16(&extradata[pos]);
309 strpos = strlen(psets);
311 &extradata[pos], len)) {
341 memcpy(config,
"; config=", 9);
351 char *encoded_config;
352 const uint8_t *header_start[3];
353 int headers_len, header_len[3], config_len;
354 int first_header_size;
358 first_header_size = 42;
361 first_header_size = 30;
369 first_header_size, header_start,
375 headers_len = header_len[0] + header_len[2];
388 if (!encoded_config) {
393 config[0] = config[1] = config[2] = 0;
398 config[7] = (headers_len >> 8) & 0xff;
399 config[8] = headers_len & 0xff;
401 config[10] = header_len[0];
403 memcpy(config + 12, header_start[0], header_len[0]);
404 memcpy(config + 12 + header_len[0], header_start[2], header_len[2]);
410 return encoded_config;
414 "Not enough memory for configuration string\n");
424 int profile_level = 0x2B;
431 profile_level = 0x28;
434 profile_level = 0x29;
436 profile_level = 0x2A;
440 profile_level = 0x2B;
444 return profile_level;
457 for (rate_index = 0; rate_index < 16; rate_index++)
460 if (rate_index == 16) {
465 config_byte[0] = 0x40;
467 config_byte[2] = 0x20 | rate_index;
468 config_byte[3] = par->
channels << 4;
469 config_byte[4] = 0x3f;
470 config_byte[5] = 0xc0;
483 static char *sdp_write_media_attributes(
char *buff,
int size,
AVStream *st,
int payload_type,
AVFormatContext *fmt)
490 av_strlcatf(buff, size,
"a=rtpmap:%d VC2/90000\r\n", payload_type);
498 config = extradata2psets(fmt, p);
500 av_strlcatf(buff, size,
"a=rtpmap:%d H264/90000\r\n" 501 "a=fmtp:%d packetization-mode=%d%s\r\n",
503 payload_type, mode, config ? config :
"");
508 const char *pic_fmt =
NULL;
515 av_strlcatf(buff, size,
"a=rtpmap:%d H261/90000\r\n", payload_type);
517 av_strlcatf(buff, size,
"a=fmtp:%d %s\r\n", payload_type, pic_fmt);
529 av_strlcatf(buff, size,
"a=rtpmap:%d H263-2000/90000\r\n" 530 "a=framesize:%d %d-%d\r\n",
536 config = extradata2psets_hevc(p);
537 av_strlcatf(buff, size,
"a=rtpmap:%d H265/90000\r\n", payload_type);
540 payload_type, config);
544 config = extradata2config(fmt, p);
546 av_strlcatf(buff, size,
"a=rtpmap:%d MP4V-ES/90000\r\n" 547 "a=fmtp:%d profile-level-id=1%s\r\n",
549 payload_type, config ? config :
"");
554 config = latm_context2config(fmt, p);
557 av_strlcatf(buff, size,
"a=rtpmap:%d MP4A-LATM/%d/%d\r\n" 558 "a=fmtp:%d profile-level-id=%d;cpresent=0;config=%s\r\n",
560 payload_type, latm_context2profilelevel(p), config);
563 config = extradata2config(fmt, p);
568 av_log(fmt,
AV_LOG_ERROR,
"AAC with no global headers is currently not supported.\n");
574 av_strlcatf(buff, size,
"a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n" 575 "a=fmtp:%d profile-level-id=1;" 576 "mode=AAC-hbr;sizelength=13;indexlength=3;" 577 "indexdeltalength=3%s\r\n",
579 payload_type, config);
584 av_strlcatf(buff, size,
"a=rtpmap:%d L16/%d/%d\r\n",
590 av_strlcatf(buff, size,
"a=rtpmap:%d L24/%d/%d\r\n",
596 av_strlcatf(buff, size,
"a=rtpmap:%d PCMU/%d/%d\r\n",
602 av_strlcatf(buff, size,
"a=rtpmap:%d PCMA/%d/%d\r\n",
607 av_strlcatf(buff, size,
"a=rtpmap:%d AMR/%d/%d\r\n" 608 "a=fmtp:%d octet-align=1\r\n",
613 av_strlcatf(buff, size,
"a=rtpmap:%d AMR-WB/%d/%d\r\n" 614 "a=fmtp:%d octet-align=1\r\n",
620 config = xiph_extradata2config(fmt, p);
626 av_strlcatf(buff, size,
"a=rtpmap:%d vorbis/%d/%d\r\n" 627 "a=fmtp:%d configuration=%s\r\n",
629 payload_type, config);
635 pix_fmt =
"YCbCr-4:2:0";
638 pix_fmt =
"YCbCr-4:2:2";
641 pix_fmt =
"YCbCr-4:4:4";
649 config = xiph_extradata2config(fmt, p);
655 av_strlcatf(buff, size,
"a=rtpmap:%d theora/90000\r\n" 656 "a=fmtp:%d delivery-method=inline; " 657 "width=%d; height=%d; sampling=%s; " 658 "configuration=%s\r\n",
659 payload_type, payload_type,
664 av_strlcatf(buff, size,
"a=rtpmap:%d VP8/90000\r\n",
668 av_strlcatf(buff, size,
"a=rtpmap:%d VP9/90000\r\n",
673 av_strlcatf(buff, size,
"a=rtpmap:%d JPEG/90000\r\n",
678 av_strlcatf(buff, size,
"a=rtpmap:%d G722/%d/%d\r\n",
684 av_strlcatf(buff, size,
"a=rtpmap:%d AAL2-G726-%d/%d\r\n",
692 av_strlcatf(buff, size,
"a=rtpmap:%d G726-%d/%d\r\n",
700 "a=fmtp:%d mode=%d\r\n",
705 av_strlcatf(buff, size,
"a=rtpmap:%d speex/%d\r\n",
707 #if FF_API_LAVF_AVCTX 733 av_strlcatf(buff, size,
"a=rtpmap:%d opus/48000/2\r\n",
736 av_strlcatf(buff, size,
"a=fmtp:%d sprop-stereo=1\r\n",
751 const char *dest_addr,
const char *dest_type,
764 default : type =
"application";
break;
767 av_strlcatf(buff, size,
"m=%s %d RTP/AVP %d\r\n", type, port, payload_type);
768 sdp_write_address(buff, size, dest_addr, dest_type, ttl);
773 sdp_write_media_attributes(buff, size, st, payload_type, fmt);
779 struct sdp_session_level s = { 0 };
780 int i, j, port, ttl, is_multicast,
index = 0;
781 char dst[32], dst_type[5];
783 memset(buf, 0, size);
785 s.src_addr =
"127.0.0.1";
787 s.name = title ? title->
value :
"No Name";
792 port = sdp_get_address(dst,
sizeof(dst), &ttl, ac[0]->url ? ac[0]->url :
"");
793 is_multicast = resolve_destination(dst,
sizeof(dst), dst_type,
799 s.dst_type = dst_type;
801 if (!strcmp(dst_type,
"IP6")) {
807 sdp_write_header(buf, size, &s);
810 for (i = 0; i < n_files; i++) {
812 port = sdp_get_address(dst,
sizeof(dst), &ttl, ac[i]->url ? ac[i]->url :
"");
813 is_multicast = resolve_destination(dst,
sizeof(dst), dst_type,
820 dst[0] ? dst :
NULL, dst_type,
821 (port > 0) ? port + j * 2 : 0,
825 "a=control:streamid=%d\r\n", i + j);
827 if (ac[i]->pb && ac[i]->pb->
av_class) {
833 if (crypto_suite && crypto_suite[0])
835 "a=crypto:1 %s inline:%s\r\n",
836 crypto_suite, crypto_params);
852 const char *dest_addr,
const char *dest_type,
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
static enum AVPixelFormat pix_fmt
const uint8_t * ff_avc_find_startcode(const uint8_t *p, const uint8_t *end)
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
This struct describes the properties of an encoded stream.
static int64_t start_time
const AVClass * av_class
A class for private options.
int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size)
Generate an SDP for an RTP session.
int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
Attempt to find a specific tag in a URL.
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define PTRDIFF_SPECIFIER
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness)
Writes HEVC extradata (parameter sets, declarative SEI NAL units) to the provided AVIOContext...
enum AVMediaType codec_type
General type of the encoded data.
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
int ff_is_multicast_address(struct sockaddr *addr)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
int extradata_size
Size of the extradata content in bytes.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int block_align
Audio only.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use. ...
ff_const59 struct AVOutputFormat * oformat
The output container format.
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
#define MAX_EXTRADATA_SIZE
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
const int avpriv_mpeg4audio_sample_rates[16]
int sample_rate
Audio only.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
#define FF_ENABLE_DEPRECATION_WARNINGS
int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecParameters *par, int idx)
Return the payload type for a given stream used in the given format context.
void * priv_data
Format private data.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
Check whether a particular flag is set in a flags field.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx, const char *dest_addr, const char *dest_type, int port, int ttl, AVFormatContext *fmt)
Append the media-specific SDP fragment for the media stream c to the buffer buff. ...
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
mode
Use these values in ebur128_init (or'ed).