File: sdp.c

package info (click to toggle)
baresip 1.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,328 kB
  • sloc: ansic: 53,606; cpp: 2,268; makefile: 332; objc: 320; python: 259; sh: 40; xml: 19
file content (62 lines) | stat: -rw-r--r-- 1,179 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * @file avcodec/sdp.c  Video codecs using libavcodec -- SDP functions
 *
 * Copyright (C) 2010 Alfred E. Heggestad
 */

#include <re.h>
#include <baresip.h>
#include <libavcodec/avcodec.h>
#include "avcodec.h"


static const uint8_t h264_level_idc = 0x1f;


uint32_t h264_packetization_mode(const char *fmtp)
{
	struct pl pl, mode;

	if (!fmtp)
		return 0;

	pl_set_str(&pl, fmtp);

	if (fmt_param_get(&pl, "packetization-mode", &mode))
		return pl_u32(&mode);

	return 0;
}


int avcodec_h264_fmtp_enc(struct mbuf *mb, const struct sdp_format *fmt,
			  bool offer, void *arg)
{
	struct vidcodec *vc = arg;
	const uint8_t profile_idc = 0x42; /* baseline profile */
	const uint8_t profile_iop = 0xe0;
	(void)offer;

	if (!mb || !fmt || !vc)
		return 0;

	return mbuf_printf(mb, "a=fmtp:%s"
			   " %s"
			   ";profile-level-id=%02x%02x%02x"
			   "\r\n",
			   fmt->id, vc->variant,
			   profile_idc, profile_iop, h264_level_idc);
}


bool avcodec_h264_fmtp_cmp(const char *lfmtp, const char *rfmtp, void *arg)
{
	const struct vidcodec *vc = arg;
	(void)lfmtp;

	if (!vc)
		return false;

	return h264_packetization_mode(vc->variant) ==
		h264_packetization_mode(rfmtp);
}