forked from jocover/jetson-ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNvVideoEncoder.h
775 lines (715 loc) · 28.6 KB
/
NvVideoEncoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
/*
* Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* <b>NVIDIA Multimedia API: Video Encode API</b>
*
*/
/**
* @defgroup l4t_mm_nvvideoencoder_group Video Encoder
* @ingroup l4t_mm_nvvideo_group
*
* Helper class that creates new V4L2
* video encoders, and it sets encoder capture and output plane
* formats.
* @{
*/
#ifndef __NV_VIDEO_ENCODER_H__
#define __NV_VIDEO_ENCODER_H__
#include "NvV4l2Element.h"
/**
* @brief Defines a helper class for V4L2 Video Encoder.
*
* The video encoder device node is \c "/dev/nvhost-msenc". The category name
* for the encoder is \c "NVENC".
*
* Refer to [V4L2 Video Encoder](group__V4L2Enc.html) for more information on the encoder.
*/
class NvVideoEncoder:public NvV4l2Element
{
public:
/**
* Creates a new V4L2 Video Encoder object named \a name.
*
* This method internally calls \c v4l2_open on the encoder dev node
* \c "/dev/nvhost-msenc" and checks for \c V4L2_CAP_VIDEO_M2M_MPLANE
* capability on the device. This method allows the caller to specify
* additional flags with which the device must be opened.
*
* The device is opened in blocking mode, which can be modified by passing
* the @a O_NONBLOCK flag to this method.
*
* @returns Reference to the newly created encoder object, else NULL in
* case of failure during initialization.
*/
static NvVideoEncoder *createVideoEncoder(const char *name, int flags = 0);
~NvVideoEncoder();
/**
* Sets the format on the encoder output plane.
*
* Calls \c VIDIOC_S_FMT IOCTL internally on the output plane.
*
* @pre Applications must set the capture plane format using #setCapturePlaneFormat before calling this method.
*
* @param[in] pixfmt One of the raw V4L2 pixel formats.
* @param[in] width Width of the input buffers in pixels.
* @param[in] height Height of the input buffers in pixels.
* @return 0 for success, -1 otherwise.
*/
int setOutputPlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height);
/**
* Sets the format on the converter capture plane.
*
* Calls \c VIDIOC_S_FMT IOCTL internally on the capture plane.
*
* @param[in] pixfmt One of the coded V4L2 pixel formats.
* @param[in] width Width of the input buffers in pixels.
* @param[in] height Height of the input buffers in pixels.
* @param[in] sizeimage Maximum size of the encoded buffers on the capture.
* plane in bytes
* @return 0 for success, -1 otherwise.
*/
int setCapturePlaneFormat(uint32_t pixfmt, uint32_t width,
uint32_t height, uint32_t sizeimage);
/**
* Sets the encode framerate.
*
* Calls the VIDIOC_S_PARM IOCTL on the encoder capture plane. Can be
* called any time after setFormat on both the planes.
*
* @param[in] framerate_num Numerator part of the framerate fraction.
* @param[in] framerate_den Denominator part of the framerate fraction.
*
* @return 0 for success, -1 otherwise.
*/
int setFrameRate(uint32_t framerate_num, uint32_t framerate_den);
/**
* Sets the encoder bitrate.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* \c V4L2_CID_MPEG_VIDEO_BITRATE. Can be called any time after setFormat on
* both the planes.
*
* @param[in] bitrate Bitrate of the encoded stream, in bits per second.
*
* @return 0 for success, -1 otherwise.
*/
int setBitrate(uint32_t bitrate);
/**
* Sets the encoder peak bitrate.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* \c V4L2_CID_MPEG_VIDEO_BITRATE_PEAK. Can be called any time after setFormat on
* both the planes. Takes effect in VBR mode
*
* @param[in] peak_bitrate Peak Bitrate of the encoded stream, in bits per second.
*
* @return 0 for success, -1 otherwise.
*/
int setPeakBitrate(uint32_t peak_bitrate);
/**
* Sets the encoder profile.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* \c V4L2_CID_MPEG_VIDEO_H264_PROFILE or #V4L2_CID_MPEG_VIDEO_H265_PROFILE,
* depending on the encoder type. Must be called after setFormat on both
* the planes and before \c requestBuffers on any of the planes.
*
* @param[in] profile Profile to be used for encoding.
*
* @return 0 for success, -1 otherwise.
*/
int setProfile(uint32_t profile);
/**
* Sets the encoder command.
*
* Calls the VIDIOC_ENCODER_CMD internally with encoder commands.
*
* @return 0 for succes, -1 otherwise.
*/
int setEncoderCommand(int cmd, int flags);
/**
* Set the encoder level.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* \c V4L2_CID_MPEG_VIDEO_H264_LEVEL or #V4L2_CID_MPEG_VIDEOENC_H265_LEVEL,
* depending on encoder type. Must be called after setFormat on both
* the planes and before \c requestBuffers on any of the planes.
*
* @param[in] level Level to be used for encoding
*
* @return 0 for success, -1 otherwise.
*/
int setLevel(uint32_t level);
/**
* Sets the encoder for maximum performance.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* V4L2_CID_MPEG_VIDEO_MAX_PERFORMANCE. Must be called after setFormat on both
* the planes and before requestBuffers on any of the planes.
*
* @param[in] flag Integer variable to indicate whether max performance is to be
* enabled/disabled.
*
* @return 0 for success, -1 otherwise.
*/
int setMaxPerfMode(int flag);
/**
* Sets constant QP for encoder.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* \c V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE to enable/disable rate control.
* If the value false is given, it disables RC and set constant QP parameters.
* Must be called after setFormat on both
* the planes and before \c requestBuffers on any of the planes.
*
* @param[in] enabled_rc Boolean value indicating whether to enable/disable
* the control.
*
* @return 0 for success, -1 otherwise.
*/
int setConstantQp(bool enabled_rc);
/**
* Sets the encoder rate control mode.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* \c V4L2_CID_MPEG_VIDEO_BITRATE_MODE. Must be called after setFormat on both
* the planes and before \c requestBuffers on any of the planes.
*
* @param[in] mode Type of rate control, one of enum
* v4l2_mpeg_video_bitrate_mode.
*
* @return 0 for success, -1 otherwise.
*/
int setRateControlMode(enum v4l2_mpeg_video_bitrate_mode mode);
/**
* Sets the encoder I-frame interval.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* \c V4L2_CID_MPEG_VIDEO_GOP_SIZE. Must be called after setFormat on both
* the planes and before \c requestBuffers on any of the planes.
*
* @param[in] interval Interval between two I frames, in number of frames.
*
* @return 0 for success, -1 otherwise.
*/
int setIFrameInterval(uint32_t interval);
/**
* Sets the encoder IDR interval.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEO_IDR_INTERVAL. Must be called after setFormat on both
* the planes and before \c requestBuffers on any of the planes.
*
* @param[in] interval Interval between two IDR frames, in number of frames.
*
* @return 0 for success, -1 otherwise.
*/
int setIDRInterval(uint32_t interval);
/**
* Forces an IDR frame.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* \c V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE. Must be called after
* setFormat on both the planes.
*
* @return 0 for success, -1 otherwise.
*/
int forceIDR();
/**
* Sets the encoder Temporal Tradeoff.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_TEMPORAL_TRADEOFF_LEVEL. Must be called after
* setFormat on both the planes and before \c requestBuffers on any of the
* planes.
*
* @param[in] level Temporal tradeoff level, one of
* v4l2_enc_temporal_tradeoff_level_type.
* @return 0 for success, -1 otherwise.
*/
int setTemporalTradeoff(v4l2_enc_temporal_tradeoff_level_type level);
/**
* Sets the encoder output slice length.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_SLICE_LENGTH_PARAM. Must be called after setFormat on
* both the planes and before \c requestBuffers on any of the planes.
*
* @param[in] type Slice length type, one of enum v4l2_enc_slice_length_type.
* @param[in] length Length of the slice, in bytes if the type is
* #V4L2_ENC_SLICE_LENGTH_TYPE_BITS, else in number of MBs if the type is
* #V4L2_ENC_SLICE_LENGTH_TYPE_MBLK.
* @return 0 for success, -1 otherwise.
*/
int setSliceLength(v4l2_enc_slice_length_type type, uint32_t length);
/**
* Sets the encoder HW Preset Type.
*
* Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_HW_PRESET_TYPE_PARAM. Must be called after setFormat() on
* both the planes and before \c requestBuffers on any of the planes.
*
* @param[in] type HW Preset Type, one of
* enum v4l2_enc_hw_preset_type_param.
* @return 0 for success, -1 otherwise.
*/
int setHWPresetType(v4l2_enc_hw_preset_type type);
/**
* Sets the Region of Interest (ROI) parameters for the next buffer, which will
* be queued on the output plane with index \a buffer_index.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_ROI_PARAMS. Must be called after
* requesting buffer on both the planes.
*
* @param[in] buffer_index Index of the output plane buffer to apply the ROI
* params.
* @param[in] params A reference to the parameters to be applied on the frame, structure of
* type v4l2_enc_frame_ROI_params.
* @return 0 for success, -1 otherwise.
*/
int setROIParams(uint32_t buffer_index, v4l2_enc_frame_ROI_params & params);
/**
* Sets the preprocessing enhancement (PPE) initialization parameters at the start of the session
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_PPE_INIT_PARAMS. Must be called after
* requesting buffer on both the planes.
*
* @param[in] params A reference to the parameters to be applied on the frame, structure of
* type v4l2_enc_ppe_init_params.
* @return 0 for success, -1 otherwise.
*/
int setPPEInitParams(v4l2_enc_ppe_init_params & params);
/**
* Enables External ROI.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_ENABLE_ROI_PARAM. Must be called after
* requesting buffer on both the planes.
*
* @param[in] params Parameters to be applied on the frame, structure of
* type #v4l2_enc_enable_roi_param.
* @return 0 for success, -1 otherwise.
*/
int enableROI(v4l2_enc_enable_roi_param ¶ms);
/**
* Enables Recon CRC.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_ENABLE_RECONCRC_PARAM. Must be called after
* requesting buffer on both the planes.
*
* @param[in] params Parameters to be applied on the frame, structure of
* type #v4l2_enc_enable_reconcrc_param.
* @return 0 for success, -1 otherwise.
*/
int enableReconCRC(v4l2_enc_enable_reconcrc_param ¶ms);
/**
* Enable External RPS
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_ENABLE_EXTERNAL_RPS_CONTROL. Must be called after
* requesting buffer on both the planes.
*
* @param[in] params Parameters to be applied on the frame, structure of
* type #v4l2_enc_enable_ext_rps_ctr
* @return 0 for success, -1 otherwise.
*/
int enableExternalRPS(v4l2_enc_enable_ext_rps_ctr ¶ms);
/**
* Enable External Picture RC
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_ENABLE_EXTERNAL_RATE_CONTROL. Must be called after
* requesting buffer on both the planes.
*
* @param[in] params Parameters to be applied on the frame, structure of
* type ##v4l2_enc_enable_ext_rate_ctr
* @return 0 for success, -1 otherwise.
*/
int enableExternalRC(v4l2_enc_enable_ext_rate_ctr ¶ms);
/**
* Enable AV1 Multi-tile configuration
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_AV1_TILE_CONFIGURATION. Must be called after
* setFormat on both the planes and before \c requestBuffers on any of the
* planes.
*
* @param[in] params Parameters to be applied, structure of
* type ##v4l2_enc_av1_tile_config
* @return 0 for success, -1 otherwise.
*/
int enableAV1Tile(v4l2_enc_av1_tile_config ¶ms);
/**
* Enable AV1 variance based SSIM RDO.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_AV1_ENABLE_SSIMRDO. Must be called after
* setFormat on both the planes.
*
* @param[in] enabled Boolean value indicating whether to enable/disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setAV1SsimRdo(bool enabled);
/**
* Disable AV1 CDF update in the symbol decoding process.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_AV1_DISABLE_CDF_UPDATE. The value true
* disables the CDF update. Must be called after setFormat on both
* the planes.
*
* @param[in] disabled Boolean value indicating whether to enable/disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setAV1DisableCDFUpdate(bool disabled);
/**
* Set input Metadata parameters for the next buffer which will
* be queued on output plane with index \a buffer_index
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_INPUT_METADATA. Must be called after
* requesting buffer on both the planes.
*
* @param[in] buffer_index Index of output plane buffer on which the external
* RC params should be applied.
* @param[in] params Parameters to be applied on the frame, structure of
* type #v4l2_ctrl_videoenc_input_metadata
* @return 0 for success, -1 otherwise.
*/
int SetInputMetaParams(uint32_t buffer_index, v4l2_ctrl_videoenc_input_metadata ¶ms);
/**
* Sets the virtual buffer size of the encoder.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_VIRTUALBUFFER_SIZE. Must be called after
* setFormat on both the planes.
*
* @param[in] size Virtual buffer size, in bytes.
* @return 0 for success, -1 otherwise.
*/
int setVirtualBufferSize(uint32_t size);
/**
* Sets the number of reference frames of the encoder.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_NUM_REFERENCE_FRAMES. Must be called after
* setFormat on both the planes.
*
* @param[in] num_frames Number of reference frames.
* @return 0 for success, -1 otherwise.
*/
int setNumReferenceFrames(uint32_t num_frames);
/**
* Sets slice intra-refresh interval params.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_SLICE_INTRAREFRESH_PARAM. Must be called after
* setFormat on both the planes.
*
* @param[in] interval Slice intra-refresh interval, in number of slices.
* @return 0 for success, -1 otherwise.
*/
int setSliceIntrarefresh(uint32_t interval);
/**
* Sets the number of B frames to P frames.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_NUM_BFRAMES. Must be called after
* setFormat on both the planes.
*
* @param[in] num Number of B frames.
* @return 0 for success, -1 otherwise.
*/
int setNumBFrames(uint32_t num);
/**
* Enables/disables insert SPS PPS at every IDR.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_INSERT_SPS_PPS_AT_IDR. Must be called after
* setFormat on both the planes.
*
* @param[in] enabled Boolean value indicating whether to enable/disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setInsertSpsPpsAtIdrEnabled(bool enabled);
/**
* Enables/disables CABAC entropy encoding for H264.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE. Must be called after
* setFormat on both the planes.
*
* @param[in] enabled Boolean value indicating whether to enable/disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setCABAC(bool enabled);
/**
* Enables/disables Slice level encoding for H264 / HEVC.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_ENABLE_SLICE_LEVEL_ENCODE. Must be called after
* setFormat on both the planes.
*
* @param[in] enabled Boolean value indicating whether to enable/disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setSliceLevelEncode(bool enabled);
/**
* Enables video encoder output motion vector metadata reporting.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_METADATA_MV. Must be called after setFormat on
* both the planes and before \c requestBuffers on any of the planes.
*
* @return 0 for success, -1 otherwise.
*/
int enableMotionVectorReporting();
/**
* Gets metadata for the encoded capture plane buffer.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_METADATA. Must be called for a buffer that has
* been dequeued from the capture plane. The returned metadata corresponds
* to the last dequeued buffer with index @a buffer_index.
*
* @param[in] buffer_index Index of the capture plane buffer whose metadata
* is required.
* @param[in,out] enc_metadata Reference to the metadata structure
* v4l2_ctrl_videoenc_outputbuf_metadata to be filled.
*
* @return 0 for success, -1 otherwise.
*/
int getMetadata(uint32_t buffer_index,
v4l2_ctrl_videoenc_outputbuf_metadata &enc_metadata);
/**
* Gets motion vector metadata for the encoded capture plane buffer.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_METADATA_MV. Must be called for a buffer that has
* been dequeued from the capture plane. The returned metadata corresponds
* to the last dequeued buffer with index @a buffer_index.
*
* @param[in] buffer_index Index of the capture plane buffer whose metadata
* is required.
* @param[in,out] enc_mv_metadata Reference to the metadata structure
* v4l2_ctrl_videoenc_outputbuf_metadata_MV to be filled.
*
* @return 0 for success, -1 otherwise.
*/
int getMotionVectors(uint32_t buffer_index,
v4l2_ctrl_videoenc_outputbuf_metadata_MV &enc_mv_metadata);
/**
* Sets QP values for I/P/B frames.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with control Id
* %V4L2_CID_MPEG_VIDEOENC_QP_RANGE. Must be called after
* setFormat on both the planes.
*
* @param[in] MinQpI Minimum Qp Value for I frame.
* @param[in] MaxQpI Minimum Qp Value for I frame.
* @param[in] MinQpP Minimum Qp Value for P frame.
* @param[in] MaxQpP Minimum Qp Value for P frame.
* @param[in] MinQpB Minimum Qp Value for B frame.
* @param[in] MaxQpB Minimum Qp Value for B frame.
* @returns 0 for success, -1 otherwise.
*/
int setQpRange(uint32_t MinQpI, uint32_t MaxQpI, uint32_t MinQpP,
uint32_t MaxQpP, uint32_t MinQpB, uint32_t MaxQpB);
/**
* Sets Sample Aspect Ratio width for VUI encoding.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with control Id
* \c V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH or
* #V4L2_CID_MPEG_VIDEOENC_H265_VUI_EXT_SAR_WIDTH, depending on the
* encoder type. Must be called after setFormat on both the planes.
*
* @param[in] sar_width SAR for width.
* @returns 0 for success, -1 otherwise.
*/
int setSampleAspectRatioWidth(uint32_t sar_width);
/**
* Sets Sample Aspect Ratio height for VUI encoding.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with control Id
* \c V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT or
* #V4L2_CID_MPEG_VIDEOENC_H265_VUI_EXT_SAR_HEIGHT, depending on the
* encoder type. Must be called after setFormat on both the planes.
*
* @param[in] sar_height SAR for height.
* @returns 0 for success, -1 otherwise.
*/
int setSampleAspectRatioHeight(uint32_t sar_height);
/**
* Enables/disables insert VUI.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* @c V4L2_CID_MPEG_VIDEOENC_INSERT_VUI. Must be called after
* setFormat on both the planes.
*
* @param[in] enabled Boolean value indicating whether to enable/disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setInsertVuiEnabled(bool enabled);
/**
* Enables/disables extended color format.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* @c V4L2_CID_MPEG_VIDEOENC_EXTEDED_COLORFORMAT. Must be called after
* setFormat on both the planes.
*
* @param[in] enabled Boolean value indicating whether to enable/disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setExtendedColorFormat(bool enabled);
/**
* Enables/disables insert AUD.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* @c V4L2_CID_MPEG_VIDEO_H264_AUD_SAR_ENABLE. Must be called after
* setFormat on both the planes.
*
* @param[in] enabled Boolean value indicating whether to enable/disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setInsertAudEnabled(bool enabled);
/**
* Enables/disables all i-frame encode.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* @c V4L2_CID_MPEG_VIDEOENC_ENABLE_ALLIFRAME_ENCODE. Must be called after
* setFormat on both the planes.
*
* @param[in] enabled Boolean value indicating whether to enable/disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setAlliFramesEncode(bool enabled);
/**
* Sets the encoder Picture Order Control type.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_POC_TYPE. Must be called after setFormat on both
* the planes and before \c requestBuffers on any of the planes.
*
* @param[in] pocType Set the Picture Order Count for the encoder.
*
* @return 0 for success, -1 otherwise.
*/
int setPocType(uint32_t pocType);
/**
* Sets the initial QP for I/P/B frames.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with control Id
* %V4L2_CID_MPEG_VIDEOENC_INIT_FRAME_QP. Must be called after
* setFormat on both the planes.
*
*
* @param[in] IinitQP Qp Value for I frame.
* @param[in] PinitQP Qp Value for P frame.
* @param[in] BinitQP Qp Value for B frame.
*
* @return 0 for success, -1 otherwise.
*/
int setInitQP(uint32_t IinitQP, uint32_t PinitQP, uint32_t BinitQP);
/**
* Sets the number of frames to encode.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEO_FRAMES_TO_ENCODE. Must be called after
* setFormat on both the planes.
*
* @param[in] framesToEncode Set the number of frames to encode.
*
* @return 0 for success, -1 otherwise.
*/
int setFramesToEncode(uint32_t framesToEncode);
/**
* Sets the H.265 encoder Chroma Format IDC.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_H265_CHROMA_FACTOR_IDC. Must be called after setFormat on both
* the planes and before \c requestBuffers on any of the planes.
*
* @param[in] crfactor Set @c chroma_factor_idc for the encoder.
*
* @return 0 for success, -1 otherwise.
*/
int setChromaFactorIDC(uint8_t crfactor);
/**
* Sets the lossless encoding for H.264/H.265.
*
* Calls the VIDIOC_S_EXT_CTRLS IOCTL internally with Control ID
* #V4L2_CID_MPEG_VIDEOENC_ENABLE_LOSSLESS. Must be called after setFormat on both
* the planes and before \c requestBuffers on any of the planes.
*
* @param[in] enabled Indicates whether to enable or disable
* the control.
* @return 0 for success, -1 otherwise.
*/
int setLossless(bool enabled);
/**
* Issues Poll on the device which blocks until :
* a) Either there is something to dequeue from capture or output plane or any events.
* b) Poll was interrupted by a call to the device using V4L2_CID_SET_POLL_INTERRUPT
* c) Application has already interrupted polling by V4L2_CID_SET_POLL_INTERRUPT
*/
int DevicePoll(v4l2_ctrl_video_device_poll *devicepoll);
/**
* Sets the polling interrupt, now if the application calls Poll, the device should
* not block, in other words polling is disabled.
*/
int SetPollInterrupt();
/**
* Clears the polling interrupt, now if the application calls Poll, the device should
* block until the event is triggered, in other words polling is enabled.
*/
int ClearPollInterrupt();
private:
/**
* Constructor used by #createVideoEncoder.
*/
NvVideoEncoder(const char *name, int flags);
static const NvElementProfiler::ProfilerField valid_fields =
NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS |
NvElementProfiler::PROFILER_FIELD_LATENCIES |
NvElementProfiler::PROFILER_FIELD_FPS;
};
/** @} */
#endif