Valkka  1.6.1
OpenSource Video Management
constant.h
Go to the documentation of this file.
1 #ifndef constant_HEADER_GUARD
2 #define constant_HEADER_GUARD
3 /*
4  * constant.h : Constant/default values, version numbers
5  *
6  * (c) Copyright 2017-2024 Sampsa Riikonen
7  *
8  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi>
9  *
10  * This file is part of the Valkka library.
11  *
12  * Valkka is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>
24  *
25  */
26 
37 #include "common.h"
38 
39 #define GLX_CONTEXT_MAJOR_VERSION 0x2091
40 #define GLX_CONTEXT_MINOR_VERSION 0x2092
41 
42 #define ALIGNMENT 1
43 /*
44 
45 https://stackoverflow.com/questions/35678041/what-is-linesize-alignment-meaning
46 https://softwareengineering.stackexchange.com/questions/328775/how-important-is-memory-alignment-does-it-still-matter
47 
48 - decoder returns YUV frames that are aligned
49 - ..during YUV => RGB interpolation (SwScaleFrameFilter, etc.), we get rid of the alignment (i.e. the extra padding bytes)
50 - ..anyway, that must be done at some moment before passing the frames downstream (for analyzers, etc.)
51 
52 - how to use the alignment parameter? there is a lot of folklore on this.
53  (should read the ffmpeg source code carefully)
54 
55 0 == choose automatically
56 32 == reasonable padding value (although depends on the CPU)
57 1 == ffmpeg itself uses this. It seems to mean "no aligment"
58 
59 => KEEP ALIGNMENT = 1
60 
61 - ..there might be performance benefits in using, for the final rgb bitmap images, widths that are multiples of 32
62 */
63 
64 static const int VERSION_MAJOR = 1; // <pyapi>
65 static const int VERSION_MINOR = 6; // <pyapi>
66 static const int VERSION_PATCH = 1; // <pyapi>
67 
68 static const unsigned LIVE_GET_PARAMETER_PING = 50; // ping the camera with GET_PARAMETER_PING every N:th second while the connection is active
69 
70 static const unsigned DEFAULT_OPENGLTHREAD_BUFFERING_TIME = 300; // in milliseconds // <pyapi>
71 static const bool DEFAULT_FRAMEFIFO_FLUSH_WHEN_FULL = false; // <pyapi>
72 static const bool DEFAULT_OPENGLFRAMEFIFO_FLUSH_WHEN_FULL = false; // <pyapi>
73 static const long int DEFAULT_TIMESTAMP_RESET_TIME = 60000; // <pyapi>
74 // static const long int TIMESTAMP_CORRECT_TRESHOLD = 30000; // <pyapi> // timestamp correctors start correcting timestamps if they are this much off (in milliseconds)
75 static const long int TIMESTAMP_CORRECT_TRESHOLD = 2000; // <pyapi> // people don't get it.. and besides, it might be difficult to adjust camera's internal clock. So, if frame is 2+ seconds late,
76 // the timestamp will be step-corrected
77 static const std::size_t FS_GRAIN_SIZE = 4096; // <pyapi> // grain size for ValkkaFS
78 
79 namespace Timeout {
80  const static long unsigned thread =250; // Timeout::thread
81  const static long unsigned livethread =250; // Timeout::livethread
82  const static long unsigned avthread =250; // Timeout::avthread
83  const static long unsigned openglthread =250; // Timeout::openglthread
84  const static long unsigned valkkafswriterthread = 250; // Timeout::valkkafswriterthread
85  const static long unsigned valkkafsreaderthread = 250; // Timeout::valkkafswriterthread
86  const static long unsigned filecachethread = 1000; // Timeout::valkkacachethread
87  // const static long unsigned filecachethread = 500; // Timeout::valkkacachethread
88  const static long unsigned usbthread =250; // Timeout::usbthread
89  const static long int filethread =2000; // Timeout::filethread
90  const static long int fdwritethread =250; // Timeout::filethread
91 }
92 
93 
96 
97  // DEFAULT_PAYLOAD_SIZE_H264 = 1024*100, ///< Default buffer size in Live555 for h264
99  // DEFAULT_PAYLOAD_SIZE_H264 = 1024*500, ///< Default buffer size in Live555 for h264
100  // DEFAULT_PAYLOAD_SIZE_H264 = 1024*10, ///< Default buffer size in Live555 for h264 // debug
101  // DEFAULT_PAYLOAD_SIZE_H264 = 1024, // use this small value for debugging (( debug
102 
104 };
105 
106 enum MaxSizes {
107  N_MAX_SLOTS =256,
109  // N_MAX_GPU_STACK =200 // not used..
110 };
111 
112 
113 // using BitmapType = unsigned;
114 // using SlotNumber = unsigned short; // swig does not get this ..
115 
116 typedef unsigned BitmapType;
117 typedef unsigned short SlotNumber; // <pyapi>
118 typedef std::size_t IdNumber; // <pyapi>
119 
120 static const SlotNumber I_MAX_SLOTS = 255; // Slot number maximum index. Max number of slots = I_MAX_SLOTS+1
121 static const int I_MAX_SUBSESSIONS = 3;
122 
123 
132 struct BitmapPars {
133  BitmapPars(BitmapType type=0, int width=0, int height=0, int w_fac=1, int h_fac=1) : type(type), width(width), height(height), w_fac(w_fac), h_fac(h_fac) {
134  y_size =width*height;
135  u_size =y_size/w_fac/h_fac;
136  v_size =u_size;
137 
138  // linesize aka maximum allowed width
139  y_width =width;
140  u_width =width/w_fac;
141  v_width =u_width;
142 
143  y_height =height;
144  u_height =height/h_fac;
145  v_height =u_height;
146 
147  // the default
148  y_linesize =y_width;
149  u_linesize =u_width;
150  v_linesize =v_width;
151  };
152 
153  BitmapType type;
154 
155  int width;
156  int height;
157  int w_fac;
158  int h_fac;
159 
160  int y_size;
161  int u_size;
162  int v_size;
163 
164  int y_width;
165  int u_width;
166  int v_width;
167 
168  int y_height;
169  int u_height;
170  int v_height;
171 
172  int y_linesize;
173  int u_linesize;
174  int v_linesize;
175 };
176 
177 inline bool operator==(BitmapPars const &a, BitmapPars const &b) { // is copyable ?
178  return ( (a.y_linesize == b.y_linesize) and (a.u_linesize == b.u_linesize) and (a.v_linesize == b.v_linesize) );
179 }
180 
181 inline std::ostream &operator<<(std::ostream &os, BitmapPars const &m) {
182  return os << "<BitmapPars: type=" << int(m.type) << " w, h=" << m.width << ", " << m.height << ">";
183 }
184 
185 static const BitmapPars N720 (1,1280,720, 2,2);
186 static const BitmapPars N1080 (2,1920,1080,2,2);
187 
188 // static const BitmapPars N1440 (3,2560,1440,2,2); // this is 2K, but not "universal" one, where all 2Ks would fit
189 static const BitmapPars N1440 (3,3000,1690,2,2); // all 2Ks will fit here :) Takes more than two times less space than 4K
190 
191 static const BitmapPars N4K (4,4032,3000,2,2);
192 
193 static const std::vector<uint8_t> nalstamp = {0,0,0,1};
194 
195 
196 #endif
List of common header files.
MaxSizes
Definition: constant.h:106
@ N_MAX_SLOTS
Maximum number of slots (used both by livethread.cpp and openglthread.cpp.
Definition: constant.h:107
@ N_MAX_DECODERS
Maximum number of decoders per one AVThread instance.
Definition: constant.h:108
PayloadSizes
Definition: constant.h:94
@ DEFAULT_PAYLOAD_SIZE_PCMU
Default buffer size in Live555 for pcmu.
Definition: constant.h:103
@ DEFAULT_PAYLOAD_SIZE_H264
Default buffer size in Live555 for h264.
Definition: constant.h:98
@ DEFAULT_PAYLOAD_SIZE
Default buffer size in Live555 for h264 // debug // not used anymore.
Definition: constant.h:95
For AVBitmapFrames, linesizes are the widths + padding bytes.
Definition: constant.h:132
int w_fac
width factor for chroma plane
Definition: constant.h:157
int h_fac
height factor for chroma plane
Definition: constant.h:158
int height
height of luma plane
Definition: constant.h:156
int width
width of luma plane
Definition: constant.h:155