1 /**
2  * Copyright (C) 2022 The Android Open Source Project
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 express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef VIDEOCONFIG_H
18 #define VIDEOCONFIG_H
19 
20 #include <stdint.h>
21 #include <binder/Parcel.h>
22 #include <binder/Parcelable.h>
23 #include <binder/Status.h>
24 #include <RtpConfig.h>
25 
26 namespace android
27 {
28 
29 namespace telephony
30 {
31 
32 namespace imsmedia
33 {
34 
35 using namespace android;
36 
37 #define CVO_DEFINE_NONE           (-1)
38 #define DEFAULT_FRAMERATE         (15)
39 #define DEFAULT_BITRATE           (384)
40 #define DEFAULT_RESOLUTION_WIDTH  (480)
41 #define DEFAULT_RESOLUTION_HEIGHT (640)
42 
43 /** Native representation of android.telephony.imsmedia.VideoConfig */
44 
45 /**
46  * The class represents RTP (Real Time Protocol) configuration for video stream.
47  */
48 class VideoConfig : public RtpConfig
49 {
50 public:
51     enum CodecType
52     {
53         CODEC_AVC = 1 << 5,
54         CODEC_HEVC = 1 << 6,
55     };
56 
57     enum VideoMode
58     {
59         VIDEO_MODE_PREVIEW = 0,
60         VIDEO_MODE_RECORDING,
61         VIDEO_MODE_PAUSE_IMAGE,
62     };
63 
64     enum VideoCodecProfile
65     {
66         /* Codec profile is not specified */
67         CODEC_PROFILE_NONE = 0,
68         /* AVC Codec Baseline profile */
69         AVC_PROFILE_BASELINE = 1,
70         /* AVC Codec Constrained Baseline profile */
71         AVC_PROFILE_CONSTRAINED_BASELINE = 0x00010000,
72         /* AVC Codec Constrained High profile */
73         AVC_PROFILE_CONSTRAINED_HIGH = 0x00080000,
74         /* AVC Codec High profile */
75         AVC_PROFILE_HIGH = 0x00000008,
76         /* AVC Codec Main profile */
77         AVC_PROFILE_MAIN = 0x00000002,
78         /* HEVC Codec Main profile */
79         HEVC_PROFILE_MAIN = 0x00000001,
80         /* HEVC Codec Main 10 profile */
81         HEVC_PROFILE_MAIN10 = 0x00000002,
82     };
83 
84     enum VideoCodecLevel
85     {
86         /* Video codec level is not specified */
87         CODEC_LEVEL_NONE = 0,
88         /* AVC Codec level 1 : 176x144, 64kbps, 15.0fps for QCIF */
89         AVC_LEVEL_1 = 1,
90         /* AVC Codec level 1b : 176x144, 128kbps, 15.0fps for QCIF */
91         AVC_LEVEL_1B = 0x00000002,
92         /* AVC Codec level 1.1 : 352x288, 192kbps, 10.0fps for QVGA, 7.5fps for CIF */
93         AVC_LEVEL_11 = 0x00000004,
94         /* AVC Codec level 1.2 : 352x288, 384kbps, 20.0fps for QVGA, 15.1fps for CIF */
95         AVC_LEVEL_12 = 0x00000008,
96         /* AVC Codec level 1.3 : 352x288, 768kbps, 39.6fps for QVGA, 30.0fps for CIF */
97         AVC_LEVEL_13 = 0x00000010,
98         /* AVC Codec level 2.0 : 352x288, 2Mbps */
99         AVC_LEVEL_2 = 0x00000020,
100         /* AVC Codec level 2.1 : 704x288, 352x576, 4Mbps */
101         AVC_LEVEL_21 = 0x00000040,
102         /* AVC Codec level 2.2 : 720x576, 4Mbps */
103         AVC_LEVEL_22 = 0x00000080,
104         /* AVC Codec level 3.0 : 720x576, 10Mbps */
105         AVC_LEVEL_3 = 0x00000100,
106         /* AVC Codec level 3.1 : 1280x720, 14Mbps */
107         AVC_LEVEL_31 = 0x00000200,
108         /* HEVC Codec high tier level 1 */
109         HEVC_HIGHTIER_LEVEL_1 = 0x00000002,
110         /* HEVC Codec high tier level 2 */
111         HEVC_HIGHTIER_LEVEL_2 = 0x00000008,
112         /* HEVC Codec high tier level 2.1 */
113         HEVC_HIGHTIER_LEVEL_21 = 0x00000020,
114         /* HEVC Codec high tier level 3 */
115         HEVC_HIGHTIER_LEVEL_3 = 0x00000080,
116         /* HEVC Codec high tier level 3.1 */
117         HEVC_HIGHTIER_LEVEL_31 = 0x00000200,
118         /* HEVC Codec high tier level 4 */
119         HEVC_HIGHTIER_LEVEL_4 = 0x00000800,
120         /* HEVC Codec high tier level 4.1 */
121         HEVC_HIGHTIER_LEVEL_41 = 0x00002000,
122         /* HEVC Codec main tier level 1 */
123         HEVC_MAINTIER_LEVEL_1 = 0x00000001,
124         /* HEVC Codec main tier level 2 */
125         HEVC_MAINTIER_LEVEL_2 = 0x00000004,
126         /* HEVC Codec main tier level 2.1 */
127         HEVC_MAINTIER_LEVEL_21 = 0x00000010,
128         /* HEVC Codec main tier level 3 */
129         HEVC_MAINTIER_LEVEL_3 = 0x00000040,
130         /* HEVC Codec main tier level 3.1 */
131         HEVC_MAINTIER_LEVEL_31 = 0x00000100,
132         /* HEVC Codec main tier level 4 */
133         HEVC_MAINTIER_LEVEL_4 = 0x00000400,
134         /* HEVC Codec main tier level 4.1 */
135         HEVC_MAINTIER_LEVEL_41 = 0x00001000,
136     };
137 
138     enum VideoPacketizationMode
139     {
140         MODE_SINGLE_NAL_UNIT = 0,
141         MODE_NON_INTERLEAVED,
142         MODE_INTERLEAVED,
143     };
144 
145     enum RtcpFbType
146     {
147         /* Rtcp fb type is not set*/
148         RTP_FB_NONE = 0,
149         /**
150          * The Generic NACK(Negative Acknowledgement) message identified by RTCP packet type
151          * value PT=RTPFB and FMT=1. RFC 4585.
152          */
153         RTP_FB_NACK = 1 << 0,
154         /**
155          * The Temporary Maximum Media Stream Bit Rate Request is identified by
156          * RTCP packet type value PT=RTPFB and FMT=3. RFC 5104.
157          */
158         RTP_FB_TMMBR = 1 << 1,
159         /**
160          * The Temporary Maximum Media Stream Bit Rate Notification is identified
161          * by RTCP packet type value PT=RTPFB and FMT=4. RFC 5104.
162          */
163         RTP_FB_TMMBN = 1 << 2,
164         /**
165          * Picture Loss Indication. The PLI FB message is identified
166          * by RTCP packet type value PT=PSFB and FMT=1. RFC 4585.
167          */
168         PSFB_PLI = 1 << 3,
169         /**
170          * Full Intra Request. The FIR message is identified by RTCP packet type
171          * value PT=PSFB and FMT=4. RFC 5104.
172          */
173         PSFB_FIR = 1 << 4,
174     };
175 
176     VideoConfig();
177     VideoConfig(VideoConfig* config);
178     VideoConfig(const VideoConfig& config);
179     virtual ~VideoConfig();
180     VideoConfig& operator=(const VideoConfig& config);
181     bool operator==(const VideoConfig& config) const;
182     bool operator!=(const VideoConfig& config) const;
183     virtual status_t writeToParcel(Parcel* out) const;
184     virtual status_t readFromParcel(const Parcel* in);
185     void setVideoMode(const int32_t mode);
186     int32_t getVideoMode();
187     void setCodecType(const int32_t type);
188     int32_t getCodecType();
189     void setFramerate(const int32_t framerate);
190     int32_t getFramerate();
191     void setBitrate(const int32_t bitrate);
192     int32_t getBitrate();
193     void setCodecProfile(const int32_t profile);
194     int32_t getCodecProfile();
195     void setCodecLevel(const int32_t level);
196     int32_t getCodecLevel();
197     void setIntraFrameInterval(const int32_t interval);
198     int32_t getIntraFrameInterval();
199     void setPacketizationMode(const int32_t mode);
200     int32_t getPacketizationMode();
201     int32_t getMaxMtuBytes();
202     void setMaxMtuBytes(const int32_t mtuBytes);
203     void setCameraId(const int32_t id);
204     int32_t getCameraId();
205     void setCameraZoom(const int32_t zoom);
206     int32_t getCameraZoom();
207     void setResolutionWidth(const int32_t width);
208     int32_t getResolutionWidth();
209     void setResolutionHeight(const int32_t height);
210     int32_t getResolutionHeight();
211     void setPauseImagePath(const String8& path);
212     String8 getPauseImagePath();
213     void setDeviceOrientationDegree(const int32_t degree);
214     int32_t getDeviceOrientationDegree();
215     void setCvoValue(const int32_t value);
216     int32_t getCvoValue();
217     void setRtcpFbType(const int32_t types);
218     int32_t getRtcpFbType();
219 
220 protected:
221     /* Sets video mode. */
222     int32_t videoMode;
223     /* Video Codec type. It can be H.264, HEVC codec. */
224     int32_t codecType;
225     /* Video frame rate in encoding streaming */
226     int32_t framerate;
227     /* Video bitrate of encoding streaming */
228     int32_t bitrate;
229     /* MaxMtuBytes of RTP packet will be defined here */
230     int32_t maxMtuBytes;
231     /* Video codec encoder profile */
232     int32_t codecProfile;
233     /* Video codec encoder level */
234     int32_t codecLevel;
235     /* Video codec encoder interval of intra-frames in seconds */
236     int32_t intraFrameIntervalSec;
237     /* Video Rtp packetization mode. The 0 means Single NAL unit mode, 1 means non-interleaved
238      * mode. And Interleaved mode is not supported. Check RFC 6184.
239      */
240     int32_t packetizationMode;
241     /* An identification of camera device to use */
242     int32_t cameraId;
243     /* A level of zoom of camera device. It can be 0 to 10. */
244     int32_t cameraZoom;
245     /* The width of resolution in transmit streaming */
246     int32_t resolutionWidth;
247     /* The height of resolution in transmit streaming */
248     int32_t resolutionHeight;
249     /* The path of jpg image for video mode VIDEO_MODE_PAUSE_IMAGE. */
250     String8 pauseImagePath;
251     /* The device orientation from sensor captured as degree unit */
252     int32_t deviceOrientationDegree;
253     /* The value to identify CVO RTP header extension features is enabled by the SDP negotiation.
254      * When the flag is set, MediaStack sends CVO RTP extension byte in the RTP header when the
255      * Video IDR frame is sent. if this value is -1, CVO is disabled, and non zero means CVO enabled
256      * with specified offset. Check RFC 5285 */
257     int32_t cvoValue;
258     /* The RTPFB, PSFB configuration with RTCP Protocol */
259     int32_t rtcpFbTypes;
260 };
261 
262 }  // namespace imsmedia
263 
264 }  // namespace telephony
265 
266 }  // namespace android
267 
268 #endif
269