Ejemplo n.º 1
0
static BOOL openh264_init(H264_CONTEXT* h264)
{
	long status;
	SDecodingParam sDecParam;
	H264_CONTEXT_OPENH264* sys;
	static int traceLevel = WELS_LOG_DEBUG;
	static EVideoFormatType videoFormat = videoFormatI420;
	static WelsTraceCallback traceCallback = (WelsTraceCallback) openh264_trace_callback;

	sys = (H264_CONTEXT_OPENH264*) calloc(1, sizeof(H264_CONTEXT_OPENH264));

	if (!sys)
	{
		goto EXCEPTION;
	}

	h264->pSystemData = (void*) sys;

	if (h264->Compressor)
	{
		WelsCreateSVCEncoder(&sys->pEncoder);

		if (!sys->pEncoder)
		{
			WLog_ERR(TAG, "Failed to create OpenH264 encoder");
			goto EXCEPTION;
		}
	}
	else
	{
		WelsCreateDecoder(&sys->pDecoder);

		if (!sys->pDecoder)
		{
			WLog_ERR(TAG, "Failed to create OpenH264 decoder");
			goto EXCEPTION;
		}

		ZeroMemory(&sDecParam, sizeof(sDecParam));
		sDecParam.eOutputColorFormat  = videoFormatI420;
		sDecParam.eEcActiveIdc = ERROR_CON_FRAME_COPY;
		sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;

		status = (*sys->pDecoder)->Initialize(sys->pDecoder, &sDecParam);

		if (status != 0)
		{
			WLog_ERR(TAG, "Failed to initialize OpenH264 decoder (status=%ld)", status);
			goto EXCEPTION;
		}

		status = (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_DATAFORMAT, &videoFormat);

		if (status != 0)
		{
			WLog_ERR(TAG, "Failed to set data format option on OpenH264 decoder (status=%ld)", status);
		}

		if (g_openh264_trace_enabled)
		{
			status = (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_LEVEL, &traceLevel);

			if (status != 0)
			{
				WLog_ERR(TAG, "Failed to set trace level option on OpenH264 decoder (status=%ld)", status);
			}

			status = (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_CALLBACK, &traceCallback);

			if (status != 0)
			{
				WLog_ERR(TAG, "Failed to set trace callback option on OpenH264 decoder (status=%ld)", status);
			}

			status = (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_CALLBACK_CONTEXT, &h264);

			if (status != 0)
			{
				WLog_ERR(TAG, "Failed to set trace callback context option on OpenH264 decoder (status=%ld)", status);
			}
		}
	}

	return TRUE;

EXCEPTION:
	openh264_uninit(h264);

	return FALSE;
}
Ejemplo n.º 2
0
static BOOL openh264_init(H264_CONTEXT* h264)
{
#if defined (WITH_OPENH264_LOADING)
	BOOL success = FALSE;
	size_t i;
#endif
	UINT32 x;
	long status;
	SDecodingParam sDecParam;
	H264_CONTEXT_OPENH264* sysContexts;
	static int traceLevel = WELS_LOG_DEBUG;
#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
	static EVideoFormatType videoFormat = videoFormatI420;
#endif
	static WelsTraceCallback traceCallback = (WelsTraceCallback)
	        openh264_trace_callback;
	h264->numSystemData = 1;
	sysContexts = (H264_CONTEXT_OPENH264*) calloc(h264->numSystemData,
	              sizeof(H264_CONTEXT_OPENH264));

	if (!sysContexts)
		goto EXCEPTION;

	h264->pSystemData = (void*) sysContexts;
#if defined (WITH_OPENH264_LOADING)

	for (i = 0; i < ARRAYSIZE(openh264_library_names); i++)
	{
		const char* current = openh264_library_names[i];
		success = openh264_load_functionpointers(h264, current);

		if (success)
			break;
	}

	if (!success)
		goto EXCEPTION;

#else
	sysContexts->WelsGetCodecVersionEx = WelsGetCodecVersionEx;
	sysContexts->WelsCreateDecoder = WelsCreateDecoder;
	sysContexts->WelsDestroyDecoder = WelsDestroyDecoder;
	sysContexts->WelsCreateSVCEncoder = WelsCreateSVCEncoder;
	sysContexts->WelsDestroySVCEncoder = WelsDestroySVCEncoder;
#endif

	for (x = 0; x < h264->numSystemData; x++)
	{
		H264_CONTEXT_OPENH264* sys = &sysContexts[x];

		if (h264->Compressor)
		{
			sysContexts->WelsCreateSVCEncoder(&sys->pEncoder);

			if (!sys->pEncoder)
			{
				WLog_Print(h264->log, WLOG_ERROR, "Failed to create OpenH264 encoder");
				goto EXCEPTION;
			}
		}
		else
		{
			sysContexts->WelsCreateDecoder(&sys->pDecoder);

			if (!sys->pDecoder)
			{
				WLog_Print(h264->log, WLOG_ERROR, "Failed to create OpenH264 decoder");
				goto EXCEPTION;
			}

			ZeroMemory(&sDecParam, sizeof(sDecParam));
#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
			sDecParam.eOutputColorFormat  = videoFormatI420;
#endif
			sDecParam.eEcActiveIdc = ERROR_CON_FRAME_COPY;
			sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;
			status = (*sys->pDecoder)->Initialize(sys->pDecoder, &sDecParam);

			if (status != 0)
			{
				WLog_Print(h264->log, WLOG_ERROR, "Failed to initialize OpenH264 decoder (status=%ld)",
				           status);
				goto EXCEPTION;
			}

#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
			status = (*sys->pDecoder)->SetOption(
			             sys->pDecoder, DECODER_OPTION_DATAFORMAT,
			             &videoFormat);
#endif

			if (status != 0)
			{
				WLog_Print(h264->log, WLOG_ERROR,
				           "Failed to set data format option on OpenH264 decoder (status=%ld)",
				           status);
				goto EXCEPTION;
			}

			if (WLog_GetLogLevel(h264->log) == WLOG_TRACE)
			{
				status = (*sys->pDecoder)->SetOption(
				             sys->pDecoder, DECODER_OPTION_TRACE_LEVEL,
				             &traceLevel);

				if (status != 0)
				{
					WLog_Print(h264->log, WLOG_ERROR,
					           "Failed to set trace level option on OpenH264 decoder (status=%ld)",
					           status);
					goto EXCEPTION;
				}

				status = (*sys->pDecoder)->SetOption(
				             sys->pDecoder,
				             DECODER_OPTION_TRACE_CALLBACK_CONTEXT,
				             &h264);

				if (status != 0)
				{
					WLog_Print(h264->log, WLOG_ERROR,
					           "Failed to set trace callback context option on OpenH264 decoder (status=%ld)",
					           status);
					goto EXCEPTION;
				}

				status = (*sys->pDecoder)->SetOption(
				             sys->pDecoder, DECODER_OPTION_TRACE_CALLBACK,
				             &traceCallback);

				if (status != 0)
				{
					WLog_Print(h264->log, WLOG_ERROR,
					           "Failed to set trace callback option on OpenH264 decoder (status=%ld)",
					           status);
					goto EXCEPTION;
				}
			}
		}
	}

	return TRUE;
EXCEPTION:
	openh264_uninit(h264);
	return FALSE;
}