1 /* GStreamer plugin for forward error correction
2 * Copyright (C) 2017 Pexip
3 *
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.
8 *
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.
13 *
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
17 *
18 * Author: Mikhail Fludkov <misha@pexip.com>
19 */
20
21 #include "rtpredcommon.h"
22
23 gsize
rtp_red_block_header_get_length(gboolean is_redundant)24 rtp_red_block_header_get_length (gboolean is_redundant)
25 {
26 return is_redundant ? sizeof (RedBlockHeader) : 1;
27 }
28
29 gboolean
rtp_red_block_is_redundant(gpointer red_block)30 rtp_red_block_is_redundant (gpointer red_block)
31 {
32 return ((RedBlockHeader *) red_block)->F;
33 }
34
35 guint8
rtp_red_block_get_payload_type(gpointer red_block)36 rtp_red_block_get_payload_type (gpointer red_block)
37 {
38 return ((RedBlockHeader *) red_block)->pt;
39 }
40
41 guint16
rtp_red_block_get_payload_length(gpointer red_block)42 rtp_red_block_get_payload_length (gpointer red_block)
43 {
44 RedBlockHeader *hdr = (RedBlockHeader *) red_block;
45 return (hdr->length_hi << 8) | hdr->length_lo;
46 }
47
48 guint16
rtp_red_block_get_timestamp_offset(gpointer red_block)49 rtp_red_block_get_timestamp_offset (gpointer red_block)
50 {
51 RedBlockHeader *hdr = (RedBlockHeader *) red_block;
52 return (hdr->timestamp_offset_hi << 6) | hdr->timestamp_offset_lo;
53 }
54
55 void
rtp_red_block_set_payload_type(gpointer red_block,guint8 pt)56 rtp_red_block_set_payload_type (gpointer red_block, guint8 pt)
57 {
58 ((RedBlockHeader *) red_block)->pt = pt;
59 }
60
61 void
rtp_red_block_set_is_redundant(gpointer red_block,gboolean is_redundant)62 rtp_red_block_set_is_redundant (gpointer red_block, gboolean is_redundant)
63 {
64 ((RedBlockHeader *) red_block)->F = is_redundant;
65 }
66
67 void
rtp_red_block_set_timestamp_offset(gpointer red_block,guint16 timestamp_offset)68 rtp_red_block_set_timestamp_offset (gpointer red_block,
69 guint16 timestamp_offset)
70 {
71 RedBlockHeader *hdr = (RedBlockHeader *) red_block;
72
73 g_assert (rtp_red_block_is_redundant (red_block));
74 g_assert_cmpint (timestamp_offset, <=, RED_BLOCK_TIMESTAMP_OFFSET_MAX);
75
76 hdr->timestamp_offset_lo = timestamp_offset & 0x3f;
77 hdr->timestamp_offset_hi = timestamp_offset >> 6;
78 }
79
80 void
rtp_red_block_set_payload_length(gpointer red_block,guint16 length)81 rtp_red_block_set_payload_length (gpointer red_block, guint16 length)
82 {
83 RedBlockHeader *hdr = (RedBlockHeader *) red_block;
84
85 g_assert (rtp_red_block_is_redundant (red_block));
86 g_assert_cmpint (length, <=, RED_BLOCK_LENGTH_MAX);
87
88 hdr->length_lo = length & 0xff;
89 hdr->length_hi = length >> 8;
90 }
91