1 /*****************************************************************************
2  * rtp2250.h: Real-time Transport Protocol for MPEG-1/MPEG-2 audio/video
3  *****************************************************************************
4  * Copyright (C) 2016 VideoLAN
5  *
6  * Authors: Christophe Massiot <massiot@via.ecp.fr>
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject
14  * to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *****************************************************************************/
27 
28 /*
29  * Normative references:
30  *  - IETF RFC 2250 RTP Payload Format for MPEG1/MPEG2 Video (January 1998)
31  */
32 
33 #ifndef __BITSTREAM_IETF_RTP2250_H__
34 #define __BITSTREAM_IETF_RTP2250_H__
35 
36 #include <stdint.h>   /* uint8_t, uint16_t, etc... */
37 #include <stdbool.h>  /* bool */
38 
39 #include <bitstream/ietf/rtp.h>
40 
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif
45 
46 /*
47  * Reminder : MPEG video-specific header
48     0                   1                   2                   3
49     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
50    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51    |    MBZ  |T|         TR        | |N|S|B|E|  P  | | BFC | | FFC |
52    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53                                    AN              FBV     FFV
54  */
55 
56 #define RTP2250V_HEADER_SIZE 4
57 
rtp2250v_set_hdr(uint8_t * p_rtpv)58 static inline void rtp2250v_set_hdr(uint8_t *p_rtpv)
59 {
60     p_rtpv[0] = 0x0;
61     p_rtpv[1] = 0x0;
62     p_rtpv[2] = 0x0;
63     p_rtpv[3] = 0x0;
64 }
65 
rtp2250v_check_hdr(const uint8_t * p_rtpv)66 static inline bool rtp2250v_check_hdr(const uint8_t *p_rtpv)
67 {
68     return (p_rtpv[0] & 0xf8) == 0x0;
69 }
70 
rtp2250v_set_mpeg2(uint8_t * p_rtpv)71 static inline void rtp2250v_set_mpeg2(uint8_t *p_rtpv)
72 {
73     p_rtpv[0] |= 0x4;
74 }
75 
rtp2250v_check_mpeg2(const uint8_t * p_rtpv)76 static inline bool rtp2250v_check_mpeg2(const uint8_t *p_rtpv)
77 {
78     return !!(p_rtpv[0] & 0x4);
79 }
80 
81 /*
82  * Reminder : MPEG-2 video-specific header extension
83     0                   1                   2                   3
84     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
85    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
86    |X|E|f_[0,0]|f_[0,1]|f_[1,0]|f_[1,1]| DC| PS|T|P|C|Q|V|A|R|H|G|D|
87    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
88  */
89 
90 #define RTP2250VX_HEADER_SIZE 4
91 
rtp2250v_set_mpeg2_hdr(uint8_t * p_rtpv)92 static inline void rtp2250v_set_mpeg2_hdr(uint8_t *p_rtpv)
93 {
94     p_rtpv[4] = 0x0;
95     p_rtpv[5] = 0x0;
96     p_rtpv[6] = 0x0;
97     p_rtpv[7] = 0x0;
98 }
99 
100 /*
101  * Reminder : MPEG Audio-specific header
102     0                   1                   2                   3
103     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
104    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
105    |             MBZ               |          Frag_offset          |
106    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
107  */
108 
109 #define RTP2250A_HEADER_SIZE 4
110 
rtp2250a_set_hdr(uint8_t * p_rtpa)111 static inline void rtp2250a_set_hdr(uint8_t *p_rtpa)
112 {
113     p_rtpa[0] = 0x0;
114     p_rtpa[1] = 0x0;
115     p_rtpa[2] = 0x0;
116     p_rtpa[3] = 0x0;
117 }
118 
rtp2250a_check_hdr(const uint8_t * p_rtpa)119 static inline bool rtp2250a_check_hdr(const uint8_t *p_rtpa)
120 {
121     return p_rtpa[0] == 0x0 && p_rtpa[1] == 0x0;
122 }
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 #endif
129