ROHC compression/decompression library
comp_scaled_rtp_ts.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010,2011,2012,2013 Didier Barvaux
3  * Copyright 2007,2009,2010,2012,2013 Viveris Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file schemes/comp_scaled_rtp_ts.h
22  * @brief Scaled RTP Timestamp encoding
23  * @author David Moreau from TAS
24  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
25  * @author Didier Barvaux <didier@barvaux.org>
26  *
27  * See section 4.5.3 of RFC 3095 for details about Scaled RTP Timestamp
28  * encoding.
29  */
30 
31 #ifndef ROHC_COMP_SCHEMES_SCALED_RTP_TS_H
32 #define ROHC_COMP_SCHEMES_SCALED_RTP_TS_H
33 
34 #include "comp_wlsb.h"
35 #include "rohc_traces.h"
36 
37 #ifdef __KERNEL__
38 # include <linux/types.h>
39 #else
40 # include <stdbool.h>
41 #endif
42 
43 
44 /**
45  * @brief State of scaled RTP Timestamp encoding
46  *
47  * See section 4.5.3 of RFC 3095 for details about Scaled RTP Timestamp
48  * encoding.
49  */
50 typedef enum
51 {
52  /// Initialization state (TS_STRIDE value not yet computed)
53  INIT_TS = 1,
54  /// Initialization state (TS_STRIDE value computed and sent)
56  /// Compression state (TS_SCALED value computed and sent)
58 } ts_sc_state;
59 
60 
61 /**
62  * @brief Scaled RTP Timestamp encoding object
63  *
64  * See section 4.5.3 of RFC 3095 for details about Scaled RTP Timestamp
65  * encoding.
66  */
67 struct ts_sc_comp
68 {
69  /// The TS_STRIDE value
70  uint32_t ts_stride;
71 
72  /// The TS_SCALED value
73  uint32_t ts_scaled;
74  /** The W-LSB object used to encode the TS_SCALED value */
76 
77  /// The TS_OFFSET value
78  uint32_t ts_offset;
79 
80  /// The timestamp (TS)
81  uint32_t ts;
82  /** The W-LSB object used to encode the TS value */
84  /// The previous timestamp
85  uint32_t old_ts;
86 
87  /// The sequence number (SN)
88  uint16_t sn;
89  /// The previous sequence number
90  uint16_t old_sn;
91 
92  /// Whether timestamp is deducible from SN or not
94 
95  /// The state of the scaled RTP Timestamp encoding object
97  /** Whether old SN/TS values are initialized or not */
99  /// The number of packets sent in state INIT_STRIDE
101 
102  /// The difference between old and current TS
103  uint32_t ts_delta;
104 
105  /** The callback function used to manage traces */
107  /** The private context of the callback function used to manage traces */
109 };
110 
111 
112 
113 /*
114  * Function prototypes
115  */
116 
117 bool c_create_sc(struct ts_sc_comp *const ts_sc,
118  const size_t wlsb_window_width,
119  rohc_trace_callback2_t trace_cb,
120  void *const trace_cb_priv)
121  __attribute__((warn_unused_result));
122 void c_destroy_sc(struct ts_sc_comp *const ts_sc);
123 
124 void c_add_ts(struct ts_sc_comp *const ts_sc,
125  const uint32_t ts,
126  const uint16_t sn);
127 
128 void nb_bits_unscaled(const struct ts_sc_comp *const ts_sc,
129  size_t *const bits_nr_less_equal_than_2,
130  size_t *const bits_nr_more_than_2)
131  __attribute__((nonnull(1, 2, 3)));
132 void add_unscaled(const struct ts_sc_comp *const ts_sc, const uint16_t sn);
133 
134 void nb_bits_scaled(const struct ts_sc_comp *const ts_sc,
135  size_t *const bits_nr_less_equal_than_2,
136  size_t *const bits_nr_more_than_2)
137  __attribute__((nonnull(1, 2, 3)));
138 void add_scaled(const struct ts_sc_comp *const ts_sc, const uint16_t sn);
139 
140 uint32_t get_ts_stride(const struct ts_sc_comp *const ts_sc)
141  __attribute__((nonnull(1), warn_unused_result, pure));
142 uint32_t get_ts_scaled(const struct ts_sc_comp *const ts_sc)
143  __attribute__((nonnull(1), warn_unused_result, pure));
144 uint32_t get_ts_unscaled(const struct ts_sc_comp *const ts_sc)
145  __attribute__((nonnull(1), warn_unused_result, pure));
146 
147 bool rohc_ts_sc_is_deducible(const struct ts_sc_comp *const ts_sc)
148  __attribute__((nonnull(1), warn_unused_result, pure));
149 
150 #endif
151 
void nb_bits_scaled(const struct ts_sc_comp *const ts_sc, size_t *const bits_nr_less_equal_than_2, size_t *const bits_nr_more_than_2)
Return the number of bits needed to encode TS_SCALED.
Definition: comp_scaled_rtp_ts.c:420
uint32_t get_ts_unscaled(const struct ts_sc_comp *const ts_sc)
Return the unscaled TS value.
Definition: comp_scaled_rtp_ts.c:488
Scaled RTP Timestamp encoding object.
Definition: comp_scaled_rtp_ts.h:67
struct c_wlsb * ts_scaled_wlsb
Definition: comp_scaled_rtp_ts.h:75
uint32_t get_ts_scaled(const struct ts_sc_comp *const ts_sc)
Return the TS_SCALED value.
Definition: comp_scaled_rtp_ts.c:476
uint32_t ts_offset
The TS_OFFSET value.
Definition: comp_scaled_rtp_ts.h:78
uint32_t get_ts_stride(const struct ts_sc_comp *const ts_sc)
Return the TS_STRIDE value.
Definition: comp_scaled_rtp_ts.c:464
Initialization state (TS_STRIDE value computed and sent)
Definition: comp_scaled_rtp_ts.h:55
uint32_t ts_scaled
The TS_SCALED value.
Definition: comp_scaled_rtp_ts.h:73
bool rohc_ts_sc_is_deducible(const struct ts_sc_comp *const ts_sc)
Whether TimeStamp (TS) is deducible from the Sequence Number (SN) or not.
Definition: comp_scaled_rtp_ts.c:501
bool are_old_val_init
Definition: comp_scaled_rtp_ts.h:98
void add_scaled(const struct ts_sc_comp *const ts_sc, const uint16_t sn)
Add a new TS_SCALED value to the ts_sc_comp object.
Definition: comp_scaled_rtp_ts.c:451
void add_unscaled(const struct ts_sc_comp *const ts_sc, const uint16_t sn)
Add a new unscaled TS value to the ts_sc_comp object.
Definition: comp_scaled_rtp_ts.c:402
rohc_trace_callback2_t trace_callback
Definition: comp_scaled_rtp_ts.h:106
uint16_t sn
The sequence number (SN)
Definition: comp_scaled_rtp_ts.h:88
void(* rohc_trace_callback2_t)(void *const priv_ctxt, const rohc_trace_level_t level, const rohc_trace_entity_t entity, const int profile, const char *const format,...)
The function prototype for the trace callback.
Definition: rohc_traces.h:118
uint32_t old_ts
The previous timestamp.
Definition: comp_scaled_rtp_ts.h:85
Window-based Least Significant Bits (W-LSB) encoding.
Defines a W-LSB encoding object.
Definition: comp_wlsb.c:55
struct c_wlsb * ts_unscaled_wlsb
Definition: comp_scaled_rtp_ts.h:83
ts_sc_state state
The state of the scaled RTP Timestamp encoding object.
Definition: comp_scaled_rtp_ts.h:96
bool is_deducible
Whether timestamp is deducible from SN or not.
Definition: comp_scaled_rtp_ts.h:93
void nb_bits_unscaled(const struct ts_sc_comp *const ts_sc, size_t *const bits_nr_less_equal_than_2, size_t *const bits_nr_more_than_2)
Return the number of bits needed to encode unscaled TS.
Definition: comp_scaled_rtp_ts.c:385
Compression state (TS_SCALED value computed and sent)
Definition: comp_scaled_rtp_ts.h:57
bool c_create_sc(struct ts_sc_comp *const ts_sc, const size_t wlsb_window_width, rohc_trace_callback2_t trace_cb, void *const trace_cb_priv)
Create the ts_sc_comp object.
Definition: comp_scaled_rtp_ts.c:53
uint32_t ts
The timestamp (TS)
Definition: comp_scaled_rtp_ts.h:81
ts_sc_state
State of scaled RTP Timestamp encoding.
Definition: comp_scaled_rtp_ts.h:50
void c_add_ts(struct ts_sc_comp *const ts_sc, const uint32_t ts, const uint16_t sn)
Store the new TS, calculate new values and update the state.
Definition: comp_scaled_rtp_ts.c:128
void * trace_callback_priv
Definition: comp_scaled_rtp_ts.h:108
ROHC definitions for traces.
uint32_t ts_stride
The TS_STRIDE value.
Definition: comp_scaled_rtp_ts.h:70
size_t nr_init_stride_packets
The number of packets sent in state INIT_STRIDE.
Definition: comp_scaled_rtp_ts.h:100
uint16_t old_sn
The previous sequence number.
Definition: comp_scaled_rtp_ts.h:90
uint32_t ts_delta
The difference between old and current TS.
Definition: comp_scaled_rtp_ts.h:103
void c_destroy_sc(struct ts_sc_comp *const ts_sc)
Destroy the ts_sc_comp object.
Definition: comp_scaled_rtp_ts.c:111
Initialization state (TS_STRIDE value not yet computed)
Definition: comp_scaled_rtp_ts.h:53