1 /* GStreamer plugin for forward error correction
2 * Copyright (C) 2017 Pexip
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 * Author: Mikhail Fludkov <misha@pexip.com>
21 #ifndef __RTP_ULPFEC_COMMON_H__
22 #define __RTP_ULPFEC_COMMON_H__
25 #include <gst/rtp/rtp.h>
29 #define GST_WARNING_RTP_PACKET(obj, name, pkt) rtp_ulpfec_log_rtppacket (GST_CAT_DEFAULT, GST_LEVEL_WARNING, obj, name, pkt)
30 #define GST_LOG_RTP_PACKET(obj, name, pkt) rtp_ulpfec_log_rtppacket (GST_CAT_DEFAULT, GST_LEVEL_LOG, obj, name, pkt)
31 #define GST_DEBUG_RTP_PACKET(obj, name, pkt) rtp_ulpfec_log_rtppacket (GST_CAT_DEFAULT, GST_LEVEL_DEBUG, obj, name, pkt)
32 #define GST_INFO_RTP_PACKET(obj, name, pkt) rtp_ulpfec_log_rtppacket (GST_CAT_DEFAULT, GST_LEVEL_INFO, obj, name, pkt)
33 #define GST_WARNING_FEC_PACKET(obj, pkt) rtp_ulpfec_log_fec_packet (GST_CAT_DEFAULT, GST_LEVEL_WARNING, obj, pkt)
34 #define GST_DEBUG_FEC_PACKET(obj, pkt) rtp_ulpfec_log_fec_packet (GST_CAT_DEFAULT, GST_LEVEL_DEBUG, obj, pkt)
35 #define GST_INFO_FEC_PACKET(obj, pkt) rtp_ulpfec_log_fec_packet (GST_CAT_DEFAULT, GST_LEVEL_INFO, obj, pkt)
37 #define RTP_ULPFEC_PROTECTED_PACKETS_MAX(L) ((L) ? 48 : 16)
38 #define RTP_ULPFEC_SEQ_BASE_OFFSET_MAX(L) (RTP_ULPFEC_PROTECTED_PACKETS_MAX(L) - 1)
41 * RtpUlpFecMapInfo: Helper wraper around GstRTPBuffer
43 * @rtp: mapped RTP buffer
46 // FIXME: it used to contain more fileds now we are left with only GstRTPBuffer.
47 // it will be nice to use it directly
51 /* FIXME: parse/write these properly instead of relying in packed structs */
54 #define ATTRIBUTE_PACKED
56 #define ATTRIBUTE_PACKED __attribute__ ((packed))
62 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
63 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 |E|L|P|X| CC |M| PT recovery | SN base |
65 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 Figure 3: FEC Header Format
73 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
87 } ATTRIBUTE_PACKED RtpUlpFecHeader;
102 } ATTRIBUTE_PACKED RtpUlpFecHeader;
107 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
108 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
109 | Protection Length | mask |
110 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
111 | mask cont. (present only when L = 1) |
112 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114 Figure 4: ULP Level Header Format
118 guint16 protection_len;
120 guint32 mask_continued;
121 } ATTRIBUTE_PACKED RtpUlpFecLevelHeader;
126 #undef ATTRIBUTE_PACKED
129 gboolean rtp_ulpfec_map_info_map (GstBuffer *buffer, RtpUlpFecMapInfo *info);
130 void rtp_ulpfec_map_info_unmap (RtpUlpFecMapInfo *info);
131 void rtp_buffer_to_ulpfec_bitstring (GstRTPBuffer *rtp, GArray *dst_arr,
132 gboolean fec_buffer, gboolean fec_mask_long);
133 GstBuffer * rtp_ulpfec_bitstring_to_media_rtp_buffer (GArray *arr,
134 gboolean fec_mask_long, guint32 ssrc, guint16 seq);
135 GstBuffer * rtp_ulpfec_bitstring_to_fec_rtp_buffer (GArray *arr, guint16 seq_base, gboolean fec_mask_long,
136 guint64 fec_mask, gboolean marker, guint8 pt, guint16 seq,
137 guint32 timestamp, guint32 ssrc);
139 #ifndef GST_DISABLE_GST_DEBUG
140 void rtp_ulpfec_log_rtppacket (GstDebugCategory * cat, GstDebugLevel level,
141 gpointer object, const gchar *name,
144 void rtp_ulpfec_log_fec_packet (GstDebugCategory * cat, GstDebugLevel level,
145 gpointer object, GstRTPBuffer *fecrtp);
147 #define rtp_ulpfec_log_rtppacket(cat,level,obj,name,rtp) /* NOOP */
148 #define rtp_ulpfec_log_fec_packet(cat,level,obj,fecrtp) /* NOOP */
151 RtpUlpFecHeader * rtp_ulpfec_buffer_get_fechdr (GstRTPBuffer *rtp);
152 guint rtp_ulpfec_get_headers_len (gboolean fec_mask_long);
153 guint16 rtp_ulpfec_hdr_get_protection_len (RtpUlpFecHeader const *fec_hdr);
154 guint64 rtp_ulpfec_packet_mask_from_seqnum (guint16 seq, guint16 fec_seq_base, gboolean fec_mask_long);
155 guint64 rtp_ulpfec_buffer_get_mask (GstRTPBuffer *rtp);
156 guint16 rtp_ulpfec_buffer_get_seq_base (GstRTPBuffer *rtp);
157 gboolean rtp_ulpfec_mask_is_long (guint64 mask);
158 gboolean rtp_ulpfec_buffer_is_valid (GstRTPBuffer * rtp);