Argus Camera Sample
Argus Camera Sample
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VideoPipeline.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2021, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * 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 NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef VIDEO_PIPELINE_H
30 #define VIDEO_PIPELINE_H
31 
32 #include <EGL/egl.h>
33 #include <EGL/eglext.h>
34 
35 #ifdef GST_SUPPORTED
36 #include <gst/gst.h>
37 #endif
38 
39 namespace ArgusSamples
40 {
41 
42 /**
43  * Record a video from a EGL stream
44  */
46 {
47 public:
48  VideoPipeline();
50 
51  /**
52  * Supported video formats
53  */
54  typedef enum
55  {
60  } VideoFormat;
61 
62  /**
63  * Video BitRate presets
64  */
65  typedef enum
66  {
67  VIDEO_BITRATE_4M = 4000000,
68  VIDEO_BITRATE_8M = 8000000,
69  VIDEO_BITRATE_14M = 14000000,
70  VIDEO_BITRATE_20M = 20000000,
71  VIDEO_BITRATE_MAX = 240000000
72  } VideoBitRate;
73 
74  /**
75  * Video Bitrate control method as per encoder properties
76  */
77  typedef enum
78  {
80  VIDEO_CONTROLRATE_VARIABLE = 1, // use as default, for variable bitrate
81  VIDEO_CONTROLRATE_CONSTANT = 2 // to get constant bitrate
83 
84  /**
85  * Supported video file types
86  */
87  typedef enum
88  {
94  } VideoFileType;
95 
96  /**
97  * Video AVC profile types, each profile indicates support for various
98  * performance bounds and different annexes.
99  */
100  typedef enum {
107 
108  /**
109  * Destroy the video pipeline
110  */
111  bool destroy();
112 
113  /**
114  * Setup the video pipeline for recording
115  *
116  * @param[in] videoStream EGL stream to record from
117  * @param[in] width Width of the recorded video
118  * @param[in] height Height of the recorded video
119  * @param[in] frameRate Frame rate
120  * @param[in] fileName File name
121  * @param[in] videoFormat Video format
122  * @param[in] videoFileType Video file type
123  * @param[in] bitRate Bitrate, if 0 the bitrate will be selected depending on the
124  * resolution
125  * @param[in] controlRate Bit Rate control method
126  * @param[in] enableTwoPassCBR enables 2-pass for constant bitRate
127  */
128  bool setupForRecording(EGLStreamKHR videoStream, uint32_t width, uint32_t height,
129  float frameRate, const char *fileName,
130  VideoFormat videoFormat = VIDEO_FORMAT_H265,
131  VideoFileType videoFileType = VIDEO_FILE_TYPE_MKV,
132  uint32_t bitRate = 0,
134  bool enableTwoPassCBR = false);
135 
136  /**
137  * Setup the video pipeline for playback
138  *
139  * @param[out] videoStream EGL stream
140  * @param[in] fileName File name
141  */
142  bool setupForPlayback(EGLStreamKHR *videoStream, const char *fileName);
143 
144  /**
145  * Start recording/playback
146  */
147  bool start();
148 
149  /**
150  * Pause recording/playback
151  */
152  bool pause();
153 
154  /**
155  * Toggle recording/playback
156  */
157  bool toggle();
158 
159  /**
160  * Rewind (playback only)
161  */
162  bool rewind();
163 
164  /**
165  * Stop recording/playback
166  */
167  bool stop();
168 
169  /**
170  * Get the file extension for a video file type.
171  */
172  static const char* getFileExtension(VideoFileType fileType);
173 
174  /**
175  * Get the aspect ratio of the video. The video has to be in paused or playing state.
176  *
177  * @param aspectRatio [out]
178  */
179  bool getAspectRatio(float *aspectRatio) const;
180 
181  /**
182  * Get indicator of video recording being supported
183  */
184  static bool isSupported();
185 
186 private:
187 #ifdef GST_SUPPORTED
188  GstState m_state;
189 
190  GstElement *m_pipeline;
191 #endif
192 };
193 
194 }; // namespace ArgusSamples
195 
196 #endif // VIDEO_PIPELINE_H