1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef _RTP_PRIV_H_
29#define _RTP_PRIV_H_
30
31#include "containers/containers.h"
32
33#include "containers/core/containers_private.h"
34#include "containers/core/containers_bits.h"
35#include "containers/core/containers_list.h"
36
37typedef VC_CONTAINER_STATUS_T (*PAYLOAD_HANDLER_T)(VC_CONTAINER_T *p_ctx,
38 VC_CONTAINER_TRACK_T *track, VC_CONTAINER_PACKET_T *p_packet, uint32_t flags);
39
40/** Parameter list entry type. */
41typedef struct parameter_tag
42{
43 const char *name;
44 const char *value;
45} PARAMETER_T;
46
47/** Prototype for MIME parameter handling.
48 * Each MIME type has a certain set of parameter names it uses, so a handler is
49 * needed for each type. This is that handler's prototype.
50 */
51typedef VC_CONTAINER_STATUS_T (*PARAMETER_HANDLER_T)(VC_CONTAINER_T *p_ctx, VC_CONTAINER_TRACK_T *track, const VC_CONTAINERS_LIST_T *params);
52
53/** Track module flag bit numbers (up to seven) */
54typedef enum
55{
56 TRACK_SSRC_SET = 0,
57 TRACK_HAS_MARKER,
58 TRACK_NEW_PACKET,
59} track_module_flag_bit_t;
60
61/** RTP track data */
62typedef struct VC_CONTAINER_TRACK_MODULE_T
63{
64 PAYLOAD_HANDLER_T payload_handler; /**< Extracts the data from the payload */
65 uint8_t *buffer; /**< Buffer into which the RTP packet is read */
66 VC_CONTAINER_BITS_T payload; /**< Payload bit bit_stream */
67 uint8_t flags; /**< Combination of track module flags */
68 uint8_t payload_type; /**< The expected payload type */
69 uint16_t max_seq_num; /**< Highest seq. number seen */
70 uint32_t timestamp; /**< RTP timestamp of packet */
71 uint32_t timestamp_base; /**< RTP timestamp value that equates to time zero */
72 uint32_t last_timestamp_top; /**< Top two bits of RTP timestamp of previous packet */
73 uint32_t timestamp_wraps; /**< Count of the times that the timestamp has wrapped */
74 uint32_t timestamp_clock; /**< Clock frequency of RTP timestamp values */
75 uint32_t expected_ssrc; /**< The expected SSRC, if set */
76 uint32_t base_seq; /**< Base seq number */
77 uint32_t bad_seq; /**< Last 'bad' seq number + 1 */
78 uint32_t probation; /**< Sequential packets till source is valid */
79 uint32_t received; /**< RTP packets received */
80 void *extra; /**< Payload specific data */
81} VC_CONTAINER_TRACK_MODULE_T;
82
83/** Determine minimum number of bytes needed to hold a number of bits */
84#define BITS_TO_BYTES(X) (((X) + 7) >> 3)
85
86/** Collection of bit manipulation routines */
87/* @{ */
88#define SET_BIT(V, B) V |= (1 << (B))
89#define CLEAR_BIT(V, B) V &= ~(1 << (B))
90#define BIT_IS_SET(V, B) (!(!((V) & (1 << (B)))))
91#define BIT_IS_CLEAR(V, B) (!((V) & (1 << (B))))
92/* }@ */
93
94
95/** Get a parameter's value as a decimal number.
96 *
97 * \param param_list The list of parameter name/value pairs.
98 * \param name The paramter's name.
99 * \param value Where to put the converted value.
100 * \return True if successful, false if the parameter was not found or didn't convert. */
101bool rtp_get_parameter_u32(const VC_CONTAINERS_LIST_T *param_list, const char *name, uint32_t *value);
102
103/** Get a parameter's value as a hexadecimal number.
104 *
105 * \param param_list The list of parameter name/value pairs.
106 * \param name The paramter's name.
107 * \param value Where to put the converted value.
108 * \return True if successful, false if the parameter was not found or didn't convert. */
109bool rtp_get_parameter_x32(const VC_CONTAINERS_LIST_T *param_list, const char *name, uint32_t *value);
110
111#endif /* _RTP_PRIV_H_ */
112