99
1010#include "encoder_soft_h264.h"
1111
12- #define PRESET "ultrafast"
13- #define TUNE "zerolatency"
14- #define PROFILE "baseline"
15-
1612static char errbuf [256 ];
1713
1814static void set_error (const char * format , ...) {
@@ -32,7 +28,6 @@ typedef struct {
3228 x264_t * x_handler ;
3329 x264_picture_t x_pic_in ;
3430 x264_picture_t x_pic_out ;
35- uint64_t next_pts ;
3631 pthread_mutex_t mutex ;
3732} encoder_soft_h264_priv_t ;
3833
@@ -41,10 +36,18 @@ bool encoder_soft_h264_create(const parameters_t *params, int stride, int colors
4136 encoder_soft_h264_priv_t * encp = (encoder_soft_h264_priv_t * )(* enc );
4237 memset (encp , 0 , sizeof (encoder_soft_h264_priv_t ));
4338
44- int res = x264_param_default_preset (& encp -> x_params , PRESET , TUNE );
45- if (res < 0 ) {
46- set_error ("x264_param_default_preset() failed" );
47- goto failed ;
39+ if (strcmp (params -> software_h264_profile , "baseline" ) == 0 ) {
40+ int res = x264_param_default_preset (& encp -> x_params , "ultrafast" , "zerolatency" );
41+ if (res < 0 ) {
42+ set_error ("x264_param_default_preset() failed" );
43+ goto failed ;
44+ }
45+ } else {
46+ int res = x264_param_default_preset (& encp -> x_params , "superfast" , NULL );
47+ if (res < 0 ) {
48+ set_error ("x264_param_default_preset() failed" );
49+ goto failed ;
50+ }
4851 }
4952
5053 encp -> x_params .i_width = params -> width ;
@@ -68,8 +71,9 @@ bool encoder_soft_h264_create(const parameters_t *params, int stride, int colors
6871 encp -> x_params .rc .i_vbv_max_bitrate = params -> bitrate / 1000 ;
6972 encp -> x_params .rc .i_rc_method = X264_RC_ABR ;
7073 encp -> x_params .i_bframe = 0 ;
74+ encp -> x_params .i_level_idc = (int )(atof (params -> software_h264_level ) * 10.0f );
7175
72- res = x264_param_apply_profile (& encp -> x_params , PROFILE );
76+ int res = x264_param_apply_profile (& encp -> x_params , params -> software_h264_profile );
7377 if (res < 0 ) {
7478 set_error ("x264_param_apply_profile() failed" );
7579 goto failed ;
@@ -103,7 +107,7 @@ void encoder_soft_h264_encode(encoder_soft_h264_t *enc, uint8_t *buffer_mapped,
103107 encp -> x_pic_in .img .plane [0 ] = buffer_mapped ; // Y
104108 encp -> x_pic_in .img .plane [1 ] = encp -> x_pic_in .img .plane [0 ] + encp -> x_pic_in .img .i_stride [0 ] * encp -> params -> height ; // U
105109 encp -> x_pic_in .img .plane [2 ] = encp -> x_pic_in .img .plane [1 ] + (encp -> x_pic_in .img .i_stride [0 ] / 2 ) * (encp -> params -> height / 2 ); // V
106- encp -> x_pic_in .i_pts = encp -> next_pts ++ ;
110+ encp -> x_pic_in .i_pts = ( int64_t ) timestamp ;
107111
108112 pthread_mutex_lock (& encp -> mutex );
109113
@@ -113,7 +117,9 @@ void encoder_soft_h264_encode(encoder_soft_h264_t *enc, uint8_t *buffer_mapped,
113117
114118 pthread_mutex_unlock (& encp -> mutex );
115119
116- encp -> output_cb (nal -> p_payload , frame_size , timestamp );
120+ if (nal != NULL ) {
121+ encp -> output_cb (nal -> p_payload , frame_size , (uint64_t )encp -> x_pic_out .i_pts );
122+ }
117123}
118124
119125void encoder_soft_h264_reload_params (encoder_soft_h264_t * enc , const parameters_t * params ) {
0 commit comments