virtual void TearDown() { delete pParamExt; delete pOption; delete pSrcPic; delete []pYUV; if (pPtrEnc) { WelsDestroySVCEncoder (pPtrEnc); pPtrEnc = NULL; } }
void TearDownEncoder() { // Stop the worker thread first if (worker_thread_) { worker_thread_->Join(); worker_thread_ = nullptr; } // Destroy OpenH264 encoder if (encoder_) { WelsDestroySVCEncoder(encoder_); encoder_ = nullptr; } }
static gboolean gst_openh264enc_stop (GstVideoEncoder * encoder) { GstOpenh264Enc *openh264enc; openh264enc = GST_OPENH264ENC (encoder); if (openh264enc->encoder != NULL) { openh264enc->encoder->Uninitialize (); WelsDestroySVCEncoder (openh264enc->encoder); openh264enc->encoder = NULL; } openh264enc->encoder = NULL; if (openh264enc->input_state) { gst_video_codec_state_unref (openh264enc->input_state); } openh264enc->input_state = NULL; GST_DEBUG_OBJECT (openh264enc, "openh264_enc_stop called"); return TRUE; }
static void openh264_uninit(H264_CONTEXT* h264) { H264_CONTEXT_OPENH264* sys = (H264_CONTEXT_OPENH264*) h264->pSystemData; if (sys) { if (sys->pDecoder) { (*sys->pDecoder)->Uninitialize(sys->pDecoder); WelsDestroyDecoder(sys->pDecoder); sys->pDecoder = NULL; } if (sys->pEncoder) { (*sys->pEncoder)->Uninitialize(sys->pEncoder); WelsDestroySVCEncoder(sys->pEncoder); sys->pEncoder = NULL; } free(sys); h264->pSystemData = NULL; } }
OpenH264EncoderImpl::~OpenH264EncoderImpl() { isvcEncoder->Uninitialize(); WelsDestroySVCEncoder(isvcEncoder); }
static gboolean gst_openh264enc_set_format (GstVideoEncoder * encoder, GstVideoCodecState * state) { GstOpenh264Enc *openh264enc = GST_OPENH264ENC (encoder); gchar *debug_caps; guint width, height, fps_n, fps_d; SEncParamExt enc_params; SliceModeEnum slice_mode = SM_SINGLE_SLICE; guint n_slices = 1; gint ret; GstCaps *outcaps; GstVideoCodecState *output_state; openh264enc->frame_count = 0; int video_format = videoFormatI420; debug_caps = gst_caps_to_string (state->caps); GST_DEBUG_OBJECT (openh264enc, "gst_e26d4_enc_set_format called, caps: %s", debug_caps); g_free (debug_caps); gst_openh264enc_stop (encoder); if (openh264enc->input_state) { gst_video_codec_state_unref (openh264enc->input_state); } openh264enc->input_state = gst_video_codec_state_ref (state); width = GST_VIDEO_INFO_WIDTH (&state->info); height = GST_VIDEO_INFO_HEIGHT (&state->info); fps_n = GST_VIDEO_INFO_FPS_N (&state->info); fps_d = GST_VIDEO_INFO_FPS_D (&state->info); if (openh264enc->encoder != NULL) { openh264enc->encoder->Uninitialize (); WelsDestroySVCEncoder (openh264enc->encoder); openh264enc->encoder = NULL; } WelsCreateSVCEncoder (&openh264enc->encoder); unsigned int uiTraceLevel = WELS_LOG_ERROR; openh264enc->encoder->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel); openh264enc->encoder->GetDefaultParams (&enc_params); enc_params.iUsageType = openh264enc->usage_type; enc_params.iPicWidth = width; enc_params.iPicHeight = height; enc_params.iTargetBitrate = openh264enc->bitrate; enc_params.iMaxBitrate = openh264enc->max_bitrate; enc_params.iRCMode = openh264enc->rate_control; enc_params.iTemporalLayerNum = 1; enc_params.iSpatialLayerNum = 1; enc_params.iLtrMarkPeriod = 30; enc_params.iMultipleThreadIdc = openh264enc->multi_thread; enc_params.bEnableDenoise = openh264enc->enable_denoise; enc_params.iComplexityMode = openh264enc->complexity; enc_params.uiIntraPeriod = openh264enc->gop_size; enc_params.bEnableBackgroundDetection = openh264enc->background_detection; enc_params.bEnableAdaptiveQuant = openh264enc->adaptive_quantization; enc_params.bEnableSceneChangeDetect = openh264enc->scene_change_detection; enc_params.bEnableFrameSkip = openh264enc->enable_frame_skip; enc_params.bEnableLongTermReference = 0; #if OPENH264_MINOR >= 4 enc_params.eSpsPpsIdStrategy = CONSTANT_ID; #else enc_params.bEnableSpsPpsIdAddition = 0; #endif enc_params.bPrefixNalAddingCtrl = 0; enc_params.fMaxFrameRate = fps_n * 1.0 / fps_d; enc_params.iLoopFilterDisableIdc = openh264enc->deblocking_mode; enc_params.sSpatialLayers[0].uiProfileIdc = PRO_BASELINE; enc_params.sSpatialLayers[0].iVideoWidth = enc_params.iPicWidth; enc_params.sSpatialLayers[0].iVideoHeight = enc_params.iPicHeight; enc_params.sSpatialLayers[0].fFrameRate = fps_n * 1.0 / fps_d; enc_params.sSpatialLayers[0].iSpatialBitrate = enc_params.iTargetBitrate; enc_params.sSpatialLayers[0].iMaxSpatialBitrate = enc_params.iMaxBitrate; if (openh264enc->slice_mode == GST_OPENH264_SLICE_MODE_N_SLICES) { if (openh264enc->num_slices == 1) slice_mode = SM_SINGLE_SLICE; else slice_mode = SM_FIXEDSLCNUM_SLICE; n_slices = openh264enc->num_slices; } else if (openh264enc->slice_mode == GST_OPENH264_SLICE_MODE_AUTO) { #if OPENH264_MAJOR == 1 && OPENH264_MINOR < 6 slice_mode = SM_AUTO_SLICE; #else slice_mode = SM_FIXEDSLCNUM_SLICE; n_slices = 0; #endif } else { GST_ERROR_OBJECT (openh264enc, "unexpected slice mode %d", openh264enc->slice_mode); slice_mode = SM_SINGLE_SLICE; } #if OPENH264_MAJOR == 1 && OPENH264_MINOR < 6 enc_params.sSpatialLayers[0].sSliceCfg.uiSliceMode = slice_mode; enc_params.sSpatialLayers[0].sSliceCfg.sSliceArgument.uiSliceNum = n_slices; #else enc_params.sSpatialLayers[0].sSliceArgument.uiSliceMode = slice_mode; enc_params.sSpatialLayers[0].sSliceArgument.uiSliceNum = n_slices; #endif openh264enc->framerate = (1 + fps_n / fps_d); ret = openh264enc->encoder->InitializeExt (&enc_params); if (ret != cmResultSuccess) { GST_ERROR_OBJECT (openh264enc, "failed to initialize encoder"); return FALSE; } openh264enc->encoder->SetOption (ENCODER_OPTION_DATAFORMAT, &video_format); outcaps = gst_caps_copy (gst_static_pad_template_get_caps (&gst_openh264enc_src_template)); output_state = gst_video_encoder_set_output_state (encoder, outcaps, state); gst_video_codec_state_unref (output_state); return gst_video_encoder_negotiate (encoder); }
MSOpenH264Encoder::~MSOpenH264Encoder() { if (mEncoder != 0) { WelsDestroySVCEncoder(mEncoder); } }