1/* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18/*                                                                               */
19/*********************************************************************************/
20
21/*
22**   File:   rtcp_encoder.h
23**
24**   Description:
25**      This module defines the RTCP class. This class is used to encode and
26**      decode RTCP packets. Please refer to the RTCP design document for
27**      details.
28*/
29
30#ifndef RTCP_ENCODER_H
31#define RTCP_ENCODER_H
32
33/*
34** Includes
35*/
36#ifndef OSCL_TYPES_H_INCLUDED
37#include "oscl_types.h"
38#endif
39#ifndef OSCL_BIN_STREAM_H_INCLUDED
40#include "oscl_bin_stream.h"
41#endif
42#ifndef RTCP_H
43#include "rtcp.h"
44#endif
45
46/*
47** Constants
48*/
49const int32 RTCP_ENCODER_MAX_CNAME_SIZE = 255;
50
51/*
52** Classes
53*/
54
55/*
56**      This class is used to encode and
57**      decode RTCP packets. Please refer to the RTCP design document for
58**      details.
59*/
60class RTCP_Encoder : public RTCP_Base
61{
62    public:
63
64        typedef enum
65        {
66            RTCP_SUCCESS,
67            FAIL,
68            OUTPUT_TRUNCATED,
69            INVALID_PAD_LENGTH
70        } Error_t;
71
72        OSCL_IMPORT_REF    RTCP_Encoder(const uint8 * cname = NULL,
73                                        int32 cname_length = 0,
74                                        const uint32 ssrc = 0,
75                                        const uint8 version = DEFAULT_RTPRTCP_VERSION);
76        ~RTCP_Encoder() {};
77
78        void SetSSRC(uint32 new_ssrc)
79        {
80            SSRC = new_ssrc;
81        };
82
83        void setCName(const uint8 * cname,
84                      int32 cname_length);
85
86        /*
87        ** Description:
88        **  This is a convenience function to put together the
89        **  typical compound RTCP containing an RR, an SDES, and
90        **  optionally an APP packet.  Set the APP packet to NULL
91        **  to skip it.
92        **
93        **  The output_buffer is an input/output parameter.  It should
94        **  be initialized to the memory location and size of the buffer
95        **  where the data should be written.  When the function returns
96        **  it will contains the ptr to the buffer and the actual size
97        **  written unless there was not enough room (i.e., return status
98        **  is OUTPUT_TRUNCATED).  In that case, the ptr will be NULL, and
99        **  the size will be size required to write everything.
100        */
101        OSCL_IMPORT_REF    Error_t EncodeCompoundRR(const RTCP_RR& rr_packet,
102                OsclMemoryFragment& output_buffer,
103                const RTCP_APP* app_packet,
104                uint8 pad_length = 0);
105
106
107        /*
108        ** Description:
109        **  This is a convenience function to put together the
110        **  typical compound RTCP containing an SR and an SDES,
111        **
112        **  Behavior is similar to EncodeCompoundRR above.
113        */
114        Error_t EncodeCompoundSR(const RTCP_SR& sr_packet,
115                                 OsclMemoryFragment& output_buffer,
116                                 uint8 pad_length = 0);
117
118
119        Error_t EncodeRR(const RTCP_RR& rr_packet,
120                         OsclMemoryFragment& output_buffer,
121                         uint8 pad_length = 0);
122
123        Error_t EncodeSR(const RTCP_SR& sr_packet,
124                         OsclMemoryFragment& output_buffer,
125                         uint8 pad_length = 0);
126
127
128
129        Error_t EncodeBYE(const RTCP_BYE& bye_packet,
130                          OsclMemoryFragment& output_buffer,
131                          uint8 pad_length = 0);
132
133        Error_t EncodeAPP(const RTCP_APP& app_packet,
134                          OsclMemoryFragment& output_buffer,
135                          uint8 pad_length = 0);
136
137        Error_t EncodeSDES(const RTCP_SDES& sdes_packet,
138                           OsclMemoryFragment& output_buffer,
139                           uint8 pad_length = 0);
140
141
142        int32 GetEncodedSize(const RTCP_RR& rr_packet);
143
144        int32 GetEncodedSize(const RTCP_SR& sr_packet);
145
146        int32 GetEncodedSize(const RTCP_SDES& sdes_packet);
147
148        int32 GetEncodedSize(const RTCP_APP& app_packet);
149
150
151
152
153
154
155
156
157    private:
158
159        uint8 cName[RTCP_ENCODER_MAX_CNAME_SIZE];
160        uint8 cName_length;
161        uint32 SSRC;
162
163        Error_t EncodeReportBlock(OsclBinOStreamBigEndian & outStream,/* Input
164                                                                 * stream
165                                                                 * reference
166                                                                 */
167                                  const RTCP_ReportBlock* report
168                                 );
169
170
171        Error_t output_rtcp_header(uint8 packet_type,
172                                   uint8 count_field,
173                                   uint16 size,
174                                   OsclBinOStreamBigEndian& outStream,
175                                   bool pad_bit);
176
177
178        Error_t EncodeSDESItem(OsclBinOStreamBigEndian& outStream,
179                               const SDES_item* item_ptr);
180
181
182        Error_t EncodeSDESChunk(OsclBinOStreamBigEndian& outStream,
183                                const SDES_chunk* chunk_ptr);
184
185
186};
187
188#endif
189