Ver código fonte

2024年9月12日: ZJZGJ-ckq

Casper 6 meses atrás
pai
commit
40a71a6b5d

Diferenças do arquivo suprimidas por serem muito extensas
+ 34 - 54
1.txt


+ 7 - 1
ZJ_OPENH264/.vscode/settings.json

@@ -73,7 +73,13 @@
         "typeindex": "cpp",
         "typeinfo": "cpp",
         "valarray": "cpp",
-        "variant": "cpp"
+        "variant": "cpp",
+        "csetjmp": "cpp",
+        "*.ipp": "cpp",
+        "charconv": "cpp",
+        "regex": "cpp",
+        "scoped_allocator": "cpp",
+        "shared_mutex": "cpp"
     },
     "C_Cpp.errorSquiggles": "disabled"
 }

BIN
ZJ_OPENH264/webrtcinterop/build/libwebrtcinterop.a


+ 25 - 112
ZJ_OPENH264/webrtcinterop/jetson_nv_encoder.cpp

@@ -80,47 +80,10 @@ int32_t JetsonVideoEncoder::InitEncode(const webrtc::VideoCodec* codec_settings,
   height_ = codec_settings->height;
 
   target_bitrate_bps_ = codec_settings->startBitrate * 1000;
-    std::cout << "g=heig " << width_ << height_ <<  target_bitrate_bps_ << std::endl;
-
-key_frame_interval_ = codec_settings->H264().keyFrameInterval;
-
-//   if (codec_settings->codecType == webrtc::kVideoCodecH264) {
-//     key_frame_interval_ = codec_settings->H264().keyFrameInterval;
-//   } 
-//   else if (codec_settings->codecType == webrtc::kVideoCodecH265) {
-//     // key_frame_interval_ = codec_settings->H265().keyFrameInterval;
-//     key_frame_interval_ = 3000;
-//   } else if (codec_settings->codecType == webrtc::kVideoCodecVP8) {
-//     key_frame_interval_ = codec_settings->VP8().keyFrameInterval;
-//   } else if (codec_settings->codecType == webrtc::kVideoCodecVP9) {
-//     key_frame_interval_ = codec_settings->VP9().keyFrameInterval;
-//     RTC_LOG(LS_INFO) << "numberOfTemporalLayers: "
-//                      << codec_settings->VP9().numberOfTemporalLayers;
-//     RTC_LOG(LS_INFO) << "denoisingOn: " << codec_settings->VP9().denoisingOn;
-//     RTC_LOG(LS_INFO) << "keyFrameInterval: "
-//                      << codec_settings->VP9().keyFrameInterval;
-//     RTC_LOG(LS_INFO) << "adaptiveQpMode: "
-//                      << codec_settings->VP9().adaptiveQpMode;
-//     RTC_LOG(LS_INFO) << "automaticResizeOn: "
-//                      << codec_settings->VP9().automaticResizeOn;
-//     RTC_LOG(LS_INFO) << "numberOfSpatialLayers: "
-//                      << codec_settings->VP9().numberOfSpatialLayers;
-//     RTC_LOG(LS_INFO) << "interLayerPred: "
-//                      << codec_settings->VP9().interLayerPred;
-//   } else if (codec_settings->codecType == webrtc::kVideoCodecAV1) {
-//     auto scalability_mode = codec_settings->GetScalabilityMode();
-//     if (!scalability_mode) {
-//       RTC_LOG(LS_WARNING) << "Scalability mode is not set, using 'L1T1'.";
-//       scalability_mode = webrtc::ScalabilityMode::kL1T1;
-//     }
-//     RTC_LOG(LS_INFO) << "InitEncode scalability_mode:"
-//                      << (int)*scalability_mode;
-//     svc_controller_ = webrtc::CreateScalabilityStructure(*scalability_mode);
-//     scalability_mode_ = *scalability_mode;
-
-
-//     key_frame_interval_ = 3000;
-//   }
+    // std::cout << "g=heig " << width_ << height_ <<  target_bitrate_bps_ << std::endl;
+
+  key_frame_interval_ = codec_settings->H264().keyFrameInterval;
+
   framerate_ = codec_settings->maxFramerate;
 
   RTC_LOG(LS_INFO) << "InitEncode " << framerate_ << "fps "
@@ -154,12 +117,8 @@ int32_t JetsonVideoEncoder::JetsonConfigure() {
   encoder_ = NvVideoEncoder::createVideoEncoder("enc0");
   INIT_ERROR(!encoder_, "Failed to createVideoEncoder");
 
-//   ret =
-//       encoder_->setCapturePlaneFormat(VideoCodecToV4L2Format(codec_.codecType),
-//                                       width_, height_, 2 * 1024 * 1024);
-  ret =
-      encoder_->setCapturePlaneFormat(V4L2_PIX_FMT_H264,
-                                      width_, height_, 2 * 1024 * 1024);
+  ret =encoder_->setCapturePlaneFormat(V4L2_PIX_FMT_H264,width_, height_, 2 * 1024 * 1024);
+  printf("width_;%d, height_:%d\n",width_,height_);
   INIT_ERROR(ret < 0, "Failed to encoder setCapturePlaneFormat");
 
   ret = encoder_->setOutputPlaneFormat(V4L2_PIX_FMT_YUV420M, width_, height_);
@@ -172,20 +131,22 @@ int32_t JetsonVideoEncoder::JetsonConfigure() {
     INIT_ERROR(ret < 0, "Failed to setProfile");
 
     // ret = encoder_->setLevel(V4L2_MPEG_VIDEO_H264_LEVEL_5_1);
+    ret = encoder_->setLevel(V4L2_MPEG_VIDEO_H264_LEVEL_2_1);
     // INIT_ERROR(ret < 0, "Failed to setLevel");
 
     ret = encoder_->setNumBFrames(0);
     INIT_ERROR(ret < 0, "Failed to setNumBFrames");
 
-    // ret = encoder_->setInsertSpsPpsAtIdrEnabled(true);
-    // INIT_ERROR(ret < 0, "Failed to setInsertSpsPpsAtIdrEnabled");
+    ret = encoder_->setInsertSpsPpsAtIdrEnabled(true);
+    INIT_ERROR(ret < 0, "Failed to setInsertSpsPpsAtIdrEnabled");
 
-    // ret = encoder_->setInsertVuiEnabled(true);
-    // INIT_ERROR(ret < 0, "Failed to setInsertSpsPpsAtIdrEnabled");
+    ret = encoder_->setInsertVuiEnabled(true);
+    INIT_ERROR(ret < 0, "Failed to setInsertSpsPpsAtIdrEnabled");
 
 
-    // ret = encoder_->setHWPresetType(V4L2_ENC_HW_PRESET_FAST);
-    // INIT_ERROR(ret < 0, "Failed to setHWPresetType");
+    ret = encoder_->setHWPresetType(V4L2_ENC_HW_PRESET_FAST);
+    // ret = encoder_->setHWPresetType(V4L2_ENC_HW_PRESET_ULTRAFAST);
+    INIT_ERROR(ret < 0, "Failed to setHWPresetType");
   } 
 
   ret = encoder_->setRateControlMode(V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
@@ -196,9 +157,6 @@ int32_t JetsonVideoEncoder::JetsonConfigure() {
   SetBitrateBps(target_bitrate_bps_);
 
   ret = encoder_->setIDRInterval(key_frame_interval_);
-  // ret = encoder_->setIDRInterval(24);
-  // std::cout << "key   " << key_frame_interval_ << " " << framerate_ << std::endl;
-  // ret = encoder_->setIDRInterval(256);
   INIT_ERROR(ret < 0, "Failed to setIDRInterval");
 
   // ret = encoder_->setIFrameInterval(0);
@@ -396,6 +354,7 @@ int32_t JetsonVideoEncoder::RegisterEncodeCompleteCallback(
 }
 
 void JetsonVideoEncoder::SetRates(const RateControlParameters& parameters) {
+  // printf("SetRatesSetRatesSetRatesSetRatesSetRatesSetRatesSetRates\n");
   if (encoder_ == nullptr)
     return;
   if (parameters.bitrate.get_sum_bps() <= 0 || parameters.framerate_fps <= 0)
@@ -434,14 +393,7 @@ void JetsonVideoEncoder::SetBitrateBps(uint32_t bitrate_bps) {
   configured_bitrate_bps_ = bitrate_bps;
 
 
-//   if (codec_.codecType == webrtc::kVideoCodecVP9) {
-//     auto adjusted_bps = bitrate_bps * 60 / configured_framerate_;
-//     RTC_LOG(LS_INFO) << __FUNCTION__ << " bps=" << bitrate_bps
-//                      << " adjusted_bps=" << adjusted_bps;
-//     bitrate_bps = adjusted_bps;
-//   } else {
-//     RTC_LOG(LS_INFO) << __FUNCTION__ << " bps=" << bitrate_bps;
-//   }
+
 
   if (encoder_->setBitrate(bitrate_bps) < 0) {
     RTC_LOG(LS_ERROR) << "Failed to setBitrate";
@@ -453,39 +405,17 @@ webrtc::VideoEncoder::EncoderInfo JetsonVideoEncoder::GetEncoderInfo() const {
   EncoderInfo info;
   info.supports_native_handle = true;
   info.implementation_name = "Jetson Video Encoder";
-//   if (codec_.codecType == webrtc::kVideoCodecH264) {
-    static const int kLowH264QpThreshold = 34;
-    static const int kHighH264QpThreshold = 40;
-    info.scaling_settings = VideoEncoder::ScalingSettings(kLowH264QpThreshold,
-                                                          kHighH264QpThreshold);
-//   } else if (codec_.codecType == webrtc::kVideoCodecH265) {
-//     static const int kLowH265QpThreshold = 34;
-//     static const int kHighH265QpThreshold = 40;
-//     info.scaling_settings = VideoEncoder::ScalingSettings(kLowH265QpThreshold,
-//                                                           kHighH265QpThreshold);
-//   } 
-//   else if (codec_.codecType == webrtc::kVideoCodecVP8) {
-//     static const int kLowVp8QpThreshold = 29;
-//     static const int kHighVp8QpThreshold = 95;
-//     info.scaling_settings =
-//         VideoEncoder::ScalingSettings(kLowVp8QpThreshold, kHighVp8QpThreshold);
-//   } else if (codec_.codecType == webrtc::kVideoCodecVP9) {
-//     static const int kLowVp9QpThreshold = 150;
-//     static const int kHighVp9QpThreshold = 151;
-//     info.scaling_settings =
-//         VideoEncoder::ScalingSettings(kLowVp9QpThreshold, kHighVp9QpThreshold);
-//   } else if (codec_.codecType == webrtc::kVideoCodecAV1) {
-//     static const int kLowAv1QpThreshold = 145;
-//     static const int kHighAv1QpThreshold = 205;
-//     info.scaling_settings =
-//         VideoEncoder::ScalingSettings(kLowAv1QpThreshold, kHighAv1QpThreshold);
-//   }
+  static const int kLowH264QpThreshold = 24;  //34
+  static const int kHighH264QpThreshold = 37; //40
+  info.scaling_settings = VideoEncoder::ScalingSettings(kLowH264QpThreshold,
+                                                        kHighH264QpThreshold);
   return info;
 }
 
 int32_t JetsonVideoEncoder::Encode(
     const webrtc::VideoFrame& input_frame,
     const std::vector<webrtc::VideoFrameType>* frame_types) {
+      // printf("encode  encode \n");
   if (!callback_) {
     RTC_LOG(LS_WARNING)
         << "InitEncode() has been called, but a callback function "
@@ -501,16 +431,9 @@ int32_t JetsonVideoEncoder::Encode(
 //   std::shared_ptr<JetsonJpegDecoder> decoder;
   if (frame_buffer->type() == webrtc::VideoFrameBuffer::Type::kNative) {
     use_native_ = true;
-    // JetsonBuffer* jetson_buffer =
-    //     static_cast<JetsonBuffer*>(frame_buffer.get());
-    // video_type = jetson_buffer->VideoType();
-    // raw_width_ = jetson_buffer->RawWidth();
-    // raw_height_ = jetson_buffer->RawHeight();
-    // use_dmabuff_ = true;
-    // fd = jetson_buffer->DecodedFd();
-    // decode_pixfmt_ = jetson_buffer->V4L2PixelFormat();
-    // decoder = jetson_buffer->JpegDecoder();
+   
   } else {
+
     use_native_ = false;
   }
 
@@ -662,7 +585,6 @@ int32_t JetsonVideoEncoder::Encode(
           encoder_->output_plane.getNumQueuedBuffers());
       v4l2_buf.index = encoder_->output_plane.getNumQueuedBuffers();
     }
-
     rtc::scoped_refptr<const webrtc::I420BufferInterface> i420_buffer =
         frame_buffer->ToI420();
     for (uint32_t i = 0; i < buffer->n_planes; i++) {
@@ -747,18 +669,14 @@ int32_t JetsonVideoEncoder::SendFrame(
   // }
 
   if (enc_metadata->KeyFrame) {
-    // std::cout << "------------------------------------" << std::endl;
     encoded_image_._frameType= webrtc::VideoFrameType::kVideoFrameKey;
   } else {
     encoded_image_._frameType= webrtc::VideoFrameType::kVideoFrameDelta;
-    // std::cout << "-----------kVideoFrameDelta----------------" << std::endl;
-
-
   }
 
   webrtc::CodecSpecificInfo codec_specific;
   codec_specific.codecType = codec_.codecType;
-//   if (codec_.codecType == webrtc::kVideoCodecH264) {
+
     auto encoded_image_buffer =
         webrtc::EncodedImageBuffer::Create(buffer, size);
     encoded_image_.SetEncodedData(encoded_image_buffer);
@@ -766,13 +684,8 @@ int32_t JetsonVideoEncoder::SendFrame(
     codec_specific.codecSpecific.H264.packetization_mode =
         webrtc::H264PacketizationMode::NonInterleaved;
         // webrtc::H264PacketizationMode::SingleNalUnit;
-//   } 
-//   else if (codec_.codecType == webrtc::kVideoCodecH265) {
-//     auto encoded_image_buffer =
-//         webrtc::EncodedImageBuffer::Create(buffer, size);
-//     encoded_image_.SetEncodedData(encoded_image_buffer);
+        
 
-//   } 
   RTC_LOG(LS_VERBOSE) << "key_frame=" << enc_metadata->KeyFrame
                       << " size=" << size << " qp=" << encoded_image_.qp_;
 

+ 1 - 0
ZJ_OPENH264/webrtcinterop/openh264_imp.cpp

@@ -474,6 +474,7 @@ int32_t H264EncoderImpl::Encode(
     encoded_images_[i].SetTimestamp(input_frame.timestamp());
     encoded_images_[i]._frameType = ConvertToVideoFrameType(info.eFrameType);
     encoded_images_[i].SetSpatialIndex(configurations_[i].simulcast_idx);
+    // printf("frametype:%d",encoded_images_[i]._frameType );
 
     // Split encoded image up into fragments. This also updates
     // |encoded_image_|.

+ 1 - 7
ZJ_OPENH264/webrtcinterop/sri_build_encoder_factory.cpp

@@ -57,16 +57,10 @@ public:
 		const webrtc::SdpVideoFormat& format) override {
 		if (absl::EqualsIgnoreCase(format.name, cricket::kH264CodecName)) {
 			if (webrtc::H264Encoder::IsSupported()) {
-				printf("进入h264 encode \n");
-				
+				// printf("进入h264 encode \n");
 					// return absl::make_unique<webrtc::H264EncoderImpl>(cricket::VideoCodec(format)); 
-
 					//jetson nvenc加速
 					return absl::make_unique<webrtc::JetsonVideoEncoder>(cricket::VideoCodec(format));  
-
-
-					
-				
 			}			
 		}
 

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff