57
57
#define NAL_IDR 5
58
58
#define NAL_SPS 7
59
59
#define NAL_PPS 8
60
- #define NAL_SEI 6
60
+ #define NAL_SEI 6
61
+ #define NAL_DELIMITER 9
62
+
61
63
62
64
#define SLICE_TYPE_P 0
63
65
#define SLICE_TYPE_B 1
@@ -92,6 +94,7 @@ static int frame_bit_rate = -1;
92
94
static int frame_rate = 30 ;
93
95
static int ip_period = 1 ;
94
96
static int roi_test_enable = 0 ;
97
+ static int aud_nal_enable = 1 ;
95
98
96
99
static VAEntrypoint select_entrypoint = VAEntrypointEncSlice ;
97
100
@@ -117,6 +120,9 @@ build_packed_pic_buffer(unsigned char **header_buffer);
117
120
static int
118
121
build_packed_seq_buffer (unsigned char * * header_buffer );
119
122
123
+ static int
124
+ build_nal_delimiter (unsigned char * * header_buffer );
125
+
120
126
static int
121
127
build_packed_sei_pic_timing (unsigned int cpb_removal_length ,
122
128
unsigned int dpb_output_length ,
@@ -157,6 +163,8 @@ static struct {
157
163
VABufferID packed_sei_buf_id ;
158
164
VABufferID misc_parameter_hrd_buf_id ;
159
165
VABufferID misc_parameter_roi_buf_id ;
166
+ VABufferID packed_aud_header_param_buf_id ;
167
+ VABufferID packed_aud_buf_id ;
160
168
161
169
int num_slices ;
162
170
int codedbuf_i_size ;
@@ -754,6 +762,32 @@ static int begin_picture(FILE *yuv_fp, int frame_num, int display_num, int slice
754
762
else
755
763
avcenc_context .current_input_surface = SID_INPUT_PICTURE_0 ;
756
764
765
+ if (aud_nal_enable ) {
766
+ VAEncPackedHeaderParameterBuffer packed_header_param_buffer ;
767
+ unsigned int length_in_bits ;
768
+ unsigned char * packed_buffer = NULL ;
769
+
770
+ length_in_bits = build_nal_delimiter (& packed_buffer );
771
+ packed_header_param_buffer .type = VAEncPackedHeaderRawData ;
772
+ packed_header_param_buffer .bit_length = length_in_bits ;
773
+ packed_header_param_buffer .has_emulation_bytes = 1 ;
774
+ va_status = vaCreateBuffer (va_dpy ,
775
+ avcenc_context .context_id ,
776
+ VAEncPackedHeaderParameterBufferType ,
777
+ sizeof (packed_header_param_buffer ), 1 , & packed_header_param_buffer ,
778
+ & avcenc_context .packed_aud_header_param_buf_id );
779
+ CHECK_VASTATUS (va_status ,"vaCreateBuffer" );
780
+
781
+ va_status = vaCreateBuffer (va_dpy ,
782
+ avcenc_context .context_id ,
783
+ VAEncPackedHeaderDataBufferType ,
784
+ (length_in_bits + 7 ) / 8 , 1 , packed_buffer ,
785
+ & avcenc_context .packed_aud_buf_id );
786
+ CHECK_VASTATUS (va_status ,"vaCreateBuffer" );
787
+
788
+ free (packed_buffer );
789
+ }
790
+
757
791
if (is_idr ) {
758
792
VAEncPackedHeaderParameterBuffer packed_header_param_buffer ;
759
793
unsigned int length_in_bits ;
@@ -901,6 +935,12 @@ int avcenc_render_picture()
901
935
unsigned int num_va_buffers = 0 ;
902
936
int i ;
903
937
938
+ if (avcenc_context .packed_aud_header_param_buf_id != VA_INVALID_ID )
939
+ va_buffers [num_va_buffers ++ ] = avcenc_context .packed_aud_header_param_buf_id ;
940
+
941
+ if (avcenc_context .packed_aud_buf_id != VA_INVALID_ID )
942
+ va_buffers [num_va_buffers ++ ] = avcenc_context .packed_aud_buf_id ;
943
+
904
944
va_buffers [num_va_buffers ++ ] = avcenc_context .seq_param_buf_id ;
905
945
va_buffers [num_va_buffers ++ ] = avcenc_context .pic_param_buf_id ;
906
946
@@ -928,6 +968,7 @@ int avcenc_render_picture()
928
968
if (avcenc_context .misc_parameter_roi_buf_id != VA_INVALID_ID )
929
969
va_buffers [num_va_buffers ++ ] = avcenc_context .misc_parameter_roi_buf_id ;
930
970
971
+
931
972
va_status = vaBeginPicture (va_dpy ,
932
973
avcenc_context .context_id ,
933
974
surface_ids [avcenc_context .current_input_surface ]);
@@ -985,6 +1026,8 @@ static void end_picture()
985
1026
avcenc_destroy_buffers (& avcenc_context .codedbuf_buf_id , 1 );
986
1027
avcenc_destroy_buffers (& avcenc_context .misc_parameter_hrd_buf_id , 1 );
987
1028
avcenc_destroy_buffers (& avcenc_context .misc_parameter_roi_buf_id , 1 );
1029
+ avcenc_destroy_buffers (& avcenc_context .packed_aud_header_param_buf_id , 1 );
1030
+ avcenc_destroy_buffers (& avcenc_context .packed_aud_buf_id , 1 );
988
1031
989
1032
memset (avcenc_context .slice_param , 0 , sizeof (avcenc_context .slice_param ));
990
1033
avcenc_context .num_slices = 0 ;
@@ -1320,6 +1363,34 @@ build_header(FILE *avc_fp)
1320
1363
}
1321
1364
#endif
1322
1365
1366
+ static void nal_delimiter (bitstream * bs ,int slice_type )
1367
+ {
1368
+ if (slice_type == SLICE_TYPE_I || slice_type == FRAME_IDR )
1369
+ bitstream_put_ui (bs , 0 , 3 );
1370
+ else if (slice_type == SLICE_TYPE_P )
1371
+ bitstream_put_ui (bs , 1 , 3 );
1372
+ else if (slice_type == SLICE_TYPE_B )
1373
+ bitstream_put_ui (bs , 2 , 3 );
1374
+ else
1375
+ assert (0 );
1376
+ bitstream_put_ui (bs , 1 , 1 );
1377
+ bitstream_put_ui (bs , 0 , 4 );
1378
+ }
1379
+
1380
+ static int build_nal_delimiter (unsigned char * * header_buffer )
1381
+ {
1382
+ bitstream bs ;
1383
+
1384
+ bitstream_start (& bs );
1385
+ nal_start_code_prefix (& bs );
1386
+ nal_header (& bs , NAL_REF_IDC_NONE , NAL_DELIMITER );
1387
+ nal_delimiter (& bs ,current_frame_type );
1388
+ bitstream_end (& bs );
1389
+ * header_buffer = (unsigned char * )bs .buffer ;
1390
+ return bs .bit_offset ;
1391
+ }
1392
+
1393
+
1323
1394
static int
1324
1395
build_packed_pic_buffer (unsigned char * * header_buffer )
1325
1396
{
@@ -1915,6 +1986,8 @@ static void avcenc_context_init(int width, int height)
1915
1986
avcenc_context .packed_sei_header_param_buf_id = VA_INVALID_ID ;
1916
1987
avcenc_context .packed_sei_buf_id = VA_INVALID_ID ;
1917
1988
avcenc_context .misc_parameter_roi_buf_id = VA_INVALID_ID ;
1989
+ avcenc_context .packed_aud_header_param_buf_id = VA_INVALID_ID ;
1990
+ avcenc_context .packed_aud_buf_id = VA_INVALID_ID ;
1918
1991
1919
1992
if (qp_value == -1 )
1920
1993
avcenc_context .rate_control_method = VA_RC_CBR ;
0 commit comments