FreeRDP
Loading...
Searching...
No Matches
h264_openh264.c
1
21#include <freerdp/config.h>
22
23#include <winpr/winpr.h>
24#include <winpr/library.h>
25#include <winpr/assert.h>
26#include <winpr/cast.h>
27
28#include <freerdp/log.h>
29#include <freerdp/codec/h264.h>
30
31#include <wels/codec_def.h>
32#include <wels/codec_api.h>
33#include <wels/codec_ver.h>
34
35#include "h264.h"
36
37typedef void (*pWelsGetCodecVersionEx)(OpenH264Version* pVersion);
38
39typedef long (*pWelsCreateDecoder)(ISVCDecoder** ppDecoder);
40typedef void (*pWelsDestroyDecoder)(ISVCDecoder* pDecoder);
41
42typedef int (*pWelsCreateSVCEncoder)(ISVCEncoder** ppEncoder);
43typedef void (*pWelsDestroySVCEncoder)(ISVCEncoder* pEncoder);
44
45typedef struct
46{
47#if defined(WITH_OPENH264_LOADING)
48 HMODULE lib;
49 OpenH264Version version;
50#endif
51 pWelsGetCodecVersionEx WelsGetCodecVersionEx;
52 WINPR_ATTR_NODISCARD pWelsCreateDecoder WelsCreateDecoder;
53 pWelsDestroyDecoder WelsDestroyDecoder;
54 WINPR_ATTR_NODISCARD pWelsCreateSVCEncoder WelsCreateSVCEncoder;
55 pWelsDestroySVCEncoder WelsDestroySVCEncoder;
56 ISVCDecoder* pDecoder;
57 ISVCEncoder* pEncoder;
58 SEncParamExt EncParamExt;
59} H264_CONTEXT_OPENH264;
60
61#if defined(WITH_OPENH264_LOADING)
62static const char* openh264_library_names[] = {
63#if defined(_WIN32)
64 "openh264.dll"
65#elif defined(__APPLE__)
66 "libopenh264.dylib"
67#else
68 "libopenh264.so.7", "libopenh264.so.2.5.0", "libopenh264.so.2.4.1", "libopenh264.so.2.4.0",
69 "libopenh264.so.2.3.1", "libopenh264.so.2.3.0", "libopenh264.so",
70
71#endif
72};
73#endif
74
75static void openh264_trace_callback(void* ctx, int level, const char* message)
76{
77 H264_CONTEXT* h264 = ctx;
78 if (h264)
79 WLog_Print(h264->log, WLOG_TRACE, "%d - %s", level, message);
80}
81
82static int openh264_decompress(H264_CONTEXT* WINPR_RESTRICT h264,
83 const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize)
84{
85 DECODING_STATE state = dsInvalidArgument;
86 SBufferInfo sBufferInfo = WINPR_C_ARRAY_INIT;
87 SSysMEMBuffer* pSystemBuffer = nullptr;
88 H264_CONTEXT_OPENH264* sys = nullptr;
89 UINT32* iStride = nullptr;
90 BYTE** pYUVData = nullptr;
91
92 WINPR_ASSERT(h264);
93 WINPR_ASSERT(pSrcData || (SrcSize == 0));
94
95 sys = (H264_CONTEXT_OPENH264*)h264->pSystemData;
96 WINPR_ASSERT(sys);
97
98 iStride = h264->iStride;
99 WINPR_ASSERT(iStride);
100
101 pYUVData = h264->pYUVData;
102 WINPR_ASSERT(pYUVData);
103
104 if (!sys->pDecoder)
105 return -2001;
106
107 /*
108 * Decompress the image. The RDP host only seems to send I420 format.
109 */
110 pYUVData[0] = nullptr;
111 pYUVData[1] = nullptr;
112 pYUVData[2] = nullptr;
113
114 WINPR_ASSERT(sys->pDecoder);
115 state = (*sys->pDecoder)
116 ->DecodeFrame2(sys->pDecoder, pSrcData, WINPR_ASSERTING_INT_CAST(int, SrcSize),
117 pYUVData, &sBufferInfo);
118
119 if (sBufferInfo.iBufferStatus != 1)
120 {
121 if (state == dsNoParamSets)
122 {
123 /* this happens on the first frame due to missing parameter sets */
124 state =
125 (*sys->pDecoder)->DecodeFrame2(sys->pDecoder, nullptr, 0, pYUVData, &sBufferInfo);
126 }
127 else if (state == dsErrorFree)
128 {
129 /* call DecodeFrame2 again to decode without delay */
130 state =
131 (*sys->pDecoder)->DecodeFrame2(sys->pDecoder, nullptr, 0, pYUVData, &sBufferInfo);
132 }
133 else
134 {
135 WLog_Print(h264->log, WLOG_WARN, "DecodeFrame2 state: 0x%04X iBufferStatus: %d", state,
136 sBufferInfo.iBufferStatus);
137 return -2002;
138 }
139 }
140
141 if (state != dsErrorFree)
142 {
143 WLog_Print(h264->log, WLOG_WARN, "DecodeFrame2 state: 0x%02X", state);
144 return -2003;
145 }
146
147#if OPENH264_MAJOR >= 2
148 state = (*sys->pDecoder)->FlushFrame(sys->pDecoder, pYUVData, &sBufferInfo);
149 if (state != dsErrorFree)
150 {
151 WLog_Print(h264->log, WLOG_WARN, "FlushFrame state: 0x%02X", state);
152 return -2003;
153 }
154#endif
155
156 pSystemBuffer = &sBufferInfo.UsrData.sSystemBuffer;
157 iStride[0] = WINPR_ASSERTING_INT_CAST(uint32_t, pSystemBuffer->iStride[0]);
158 iStride[1] = WINPR_ASSERTING_INT_CAST(uint32_t, pSystemBuffer->iStride[1]);
159 iStride[2] = WINPR_ASSERTING_INT_CAST(uint32_t, pSystemBuffer->iStride[1]);
160
161 if (sBufferInfo.iBufferStatus != 1)
162 {
163 WLog_Print(h264->log, WLOG_WARN, "DecodeFrame2 iBufferStatus: %d",
164 sBufferInfo.iBufferStatus);
165 return 0;
166 }
167
168 if (state != dsErrorFree)
169 {
170 WLog_Print(h264->log, WLOG_WARN, "DecodeFrame2 state: 0x%02X", state);
171 return -2003;
172 }
173
174 if (pSystemBuffer->iFormat != videoFormatI420)
175 return -2004;
176
177 if (!pYUVData[0] || !pYUVData[1] || !pYUVData[2])
178 return -2005;
179
180 h264->YUVWidth = pSystemBuffer->iWidth;
181 h264->YUVHeight = pSystemBuffer->iHeight;
182
183 return 1;
184}
185
186static int openh264_compress(H264_CONTEXT* WINPR_RESTRICT h264,
187 const BYTE** WINPR_RESTRICT pYUVData,
188 const UINT32* WINPR_RESTRICT iStride, BYTE** WINPR_RESTRICT ppDstData,
189 UINT32* WINPR_RESTRICT pDstSize)
190{
191 int status = 0;
192 SFrameBSInfo info = WINPR_C_ARRAY_INIT;
193 SSourcePicture pic = WINPR_C_ARRAY_INIT;
194
195 H264_CONTEXT_OPENH264* sys = nullptr;
196
197 WINPR_ASSERT(h264);
198 WINPR_ASSERT(pYUVData);
199 WINPR_ASSERT(iStride);
200 WINPR_ASSERT(ppDstData);
201 WINPR_ASSERT(pDstSize);
202
203 sys = &((H264_CONTEXT_OPENH264*)h264->pSystemData)[0];
204 WINPR_ASSERT(sys);
205
206 if (!sys->pEncoder)
207 return -1;
208
209 if (!pYUVData[0] || !pYUVData[1] || !pYUVData[2])
210 return -1;
211
212 if ((h264->width > INT_MAX) || (h264->height > INT_MAX))
213 return -1;
214
215 if ((h264->FrameRate > INT_MAX) || (h264->NumberOfThreads > INT_MAX) ||
216 (h264->BitRate > INT_MAX) || (h264->QP > INT_MAX))
217 return -1;
218
219 WINPR_ASSERT(sys->pEncoder);
220 if ((sys->EncParamExt.iPicWidth != (int)h264->width) ||
221 (sys->EncParamExt.iPicHeight != (int)h264->height))
222 {
223 WINPR_ASSERT((*sys->pEncoder)->GetDefaultParams);
224 status = (*sys->pEncoder)->GetDefaultParams(sys->pEncoder, &sys->EncParamExt);
225
226 if (status < 0)
227 {
228 WLog_Print(h264->log, WLOG_ERROR,
229 "Failed to get OpenH264 default parameters (status=%d)", status);
230 return status;
231 }
232
233 EUsageType usageType = SCREEN_CONTENT_REAL_TIME;
234
235 switch (h264->UsageType)
236 {
237 case H264_CAMERA_VIDEO_NON_REAL_TIME:
238 usageType = CAMERA_VIDEO_NON_REAL_TIME;
239 break;
240 case H264_CAMERA_VIDEO_REAL_TIME:
241 usageType = CAMERA_VIDEO_REAL_TIME;
242 break;
243 case H264_SCREEN_CONTENT_NON_REAL_TIME:
244 usageType = SCREEN_CONTENT_NON_REAL_TIME;
245 break;
246 case H264_SCREEN_CONTENT_REAL_TIME:
247 default:
248 break;
249 }
250
251 sys->EncParamExt.iUsageType = usageType;
252 sys->EncParamExt.iPicWidth = WINPR_ASSERTING_INT_CAST(int, h264->width);
253 sys->EncParamExt.iPicHeight = WINPR_ASSERTING_INT_CAST(int, h264->height);
254 sys->EncParamExt.fMaxFrameRate = WINPR_ASSERTING_INT_CAST(short, h264->FrameRate);
255 sys->EncParamExt.iMaxBitrate = UNSPECIFIED_BIT_RATE;
256 sys->EncParamExt.bEnableDenoise = 0;
257 sys->EncParamExt.bEnableLongTermReference = 0;
258 sys->EncParamExt.iSpatialLayerNum = 1;
259 sys->EncParamExt.iMultipleThreadIdc =
260 WINPR_ASSERTING_INT_CAST(unsigned short, h264->NumberOfThreads);
261 sys->EncParamExt.sSpatialLayers[0].fFrameRate =
262 WINPR_ASSERTING_INT_CAST(short, h264->FrameRate);
263 sys->EncParamExt.sSpatialLayers[0].iVideoWidth = sys->EncParamExt.iPicWidth;
264 sys->EncParamExt.sSpatialLayers[0].iVideoHeight = sys->EncParamExt.iPicHeight;
265 sys->EncParamExt.sSpatialLayers[0].iMaxSpatialBitrate = sys->EncParamExt.iMaxBitrate;
266
267 switch (h264->RateControlMode)
268 {
269 case H264_RATECONTROL_VBR:
270 sys->EncParamExt.iRCMode = RC_BITRATE_MODE;
271 sys->EncParamExt.iTargetBitrate = (int)h264->BitRate;
272 sys->EncParamExt.sSpatialLayers[0].iSpatialBitrate =
273 sys->EncParamExt.iTargetBitrate;
274 sys->EncParamExt.bEnableFrameSkip = 1;
275 break;
276
277 case H264_RATECONTROL_CQP:
278 sys->EncParamExt.iRCMode = RC_OFF_MODE;
279 sys->EncParamExt.sSpatialLayers[0].iDLayerQp = (int)h264->QP;
280 sys->EncParamExt.bEnableFrameSkip = 0;
281 break;
282 default:
283 break;
284 }
285
286 if (sys->EncParamExt.iMultipleThreadIdc > 1)
287 {
288#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
289 sys->EncParamExt.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_AUTO_SLICE;
290#else
291 sys->EncParamExt.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
292#endif
293 }
294
295 WINPR_ASSERT((*sys->pEncoder)->InitializeExt);
296 status = (*sys->pEncoder)->InitializeExt(sys->pEncoder, &sys->EncParamExt);
297
298 if (status < 0)
299 {
300 WLog_Print(h264->log, WLOG_ERROR, "Failed to initialize OpenH264 encoder (status=%d)",
301 status);
302 return status;
303 }
304
305 WINPR_ASSERT((*sys->pEncoder)->GetOption);
306 status =
307 (*sys->pEncoder)
308 ->GetOption(sys->pEncoder, ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sys->EncParamExt);
309
310 if (status < 0)
311 {
312 WLog_Print(h264->log, WLOG_ERROR,
313 "Failed to get initial OpenH264 encoder parameters (status=%d)", status);
314 return status;
315 }
316 }
317 else
318 {
319 switch (h264->RateControlMode)
320 {
321 case H264_RATECONTROL_VBR:
322 if (sys->EncParamExt.iTargetBitrate != (int)h264->BitRate)
323 {
324 SBitrateInfo bitrate = WINPR_C_ARRAY_INIT;
325
326 sys->EncParamExt.iTargetBitrate = (int)h264->BitRate;
327 bitrate.iLayer = SPATIAL_LAYER_ALL;
328 bitrate.iBitrate = (int)h264->BitRate;
329
330 WINPR_ASSERT((*sys->pEncoder)->SetOption);
331 status = (*sys->pEncoder)
332 ->SetOption(sys->pEncoder, ENCODER_OPTION_BITRATE, &bitrate);
333
334 if (status < 0)
335 {
336 WLog_Print(h264->log, WLOG_ERROR,
337 "Failed to set encoder bitrate (status=%d)", status);
338 return status;
339 }
340 }
341
342 if ((uint32_t)sys->EncParamExt.fMaxFrameRate != h264->FrameRate)
343 {
344 sys->EncParamExt.fMaxFrameRate =
345 WINPR_ASSERTING_INT_CAST(float, h264->FrameRate);
346
347 WINPR_ASSERT((*sys->pEncoder)->SetOption);
348 status = (*sys->pEncoder)
349 ->SetOption(sys->pEncoder, ENCODER_OPTION_FRAME_RATE,
350 &sys->EncParamExt.fMaxFrameRate);
351
352 if (status < 0)
353 {
354 WLog_Print(h264->log, WLOG_ERROR,
355 "Failed to set encoder framerate (status=%d)", status);
356 return status;
357 }
358 }
359
360 break;
361
362 case H264_RATECONTROL_CQP:
363 if (sys->EncParamExt.sSpatialLayers[0].iDLayerQp != (int)h264->QP)
364 {
365 sys->EncParamExt.sSpatialLayers[0].iDLayerQp = (int)h264->QP;
366
367 WINPR_ASSERT((*sys->pEncoder)->SetOption);
368 status = (*sys->pEncoder)
369 ->SetOption(sys->pEncoder, ENCODER_OPTION_SVC_ENCODE_PARAM_EXT,
370 &sys->EncParamExt);
371
372 if (status < 0)
373 {
374 WLog_Print(h264->log, WLOG_ERROR,
375 "Failed to set encoder parameters (status=%d)", status);
376 return status;
377 }
378 }
379
380 break;
381 default:
382 break;
383 }
384 }
385
386 pic.iPicWidth = (int)h264->width;
387 pic.iPicHeight = (int)h264->height;
388 pic.iColorFormat = videoFormatI420;
389 pic.iStride[0] = (int)iStride[0];
390 pic.iStride[1] = (int)iStride[1];
391 pic.iStride[2] = (int)iStride[2];
392 pic.pData[0] = WINPR_CAST_CONST_PTR_AWAY(pYUVData[0], BYTE*);
393 pic.pData[1] = WINPR_CAST_CONST_PTR_AWAY(pYUVData[1], BYTE*);
394 pic.pData[2] = WINPR_CAST_CONST_PTR_AWAY(pYUVData[2], BYTE*);
395
396 WINPR_ASSERT((*sys->pEncoder)->EncodeFrame);
397 status = (*sys->pEncoder)->EncodeFrame(sys->pEncoder, &pic, &info);
398
399 if (status < 0)
400 {
401 WLog_Print(h264->log, WLOG_ERROR, "Failed to encode frame (status=%d)", status);
402 return status;
403 }
404
405 *ppDstData = info.sLayerInfo[0].pBsBuf;
406 *pDstSize = 0;
407
408 for (int i = 0; i < info.iLayerNum; i++)
409 {
410 for (int j = 0; j < info.sLayerInfo[i].iNalCount; j++)
411 {
412 const int val = info.sLayerInfo[i].pNalLengthInByte[j];
413 *pDstSize += WINPR_ASSERTING_INT_CAST(uint32_t, val);
414 }
415 }
416
417 return 1;
418}
419
420static void openh264_uninit(H264_CONTEXT* h264)
421{
422 H264_CONTEXT_OPENH264* sysContexts = nullptr;
423
424 WINPR_ASSERT(h264);
425
426 sysContexts = (H264_CONTEXT_OPENH264*)h264->pSystemData;
427
428 if (sysContexts)
429 {
430 for (UINT32 x = 0; x < h264->numSystemData; x++)
431 {
432 H264_CONTEXT_OPENH264* sys = &sysContexts[x];
433
434 if (sys->pDecoder)
435 {
436 (*sys->pDecoder)->Uninitialize(sys->pDecoder);
437 sysContexts->WelsDestroyDecoder(sys->pDecoder);
438 sys->pDecoder = nullptr;
439 }
440
441 if (sys->pEncoder)
442 {
443 (*sys->pEncoder)->Uninitialize(sys->pEncoder);
444 sysContexts->WelsDestroySVCEncoder(sys->pEncoder);
445 sys->pEncoder = nullptr;
446 }
447 }
448
449#if defined(WITH_OPENH264_LOADING)
450 if (sysContexts->lib)
451 FreeLibrary(sysContexts->lib);
452#endif
453 free(h264->pSystemData);
454 h264->pSystemData = nullptr;
455 }
456}
457
458#if defined(WITH_OPENH264_LOADING)
459static BOOL openh264_load_functionpointers(H264_CONTEXT* h264, const char* name)
460{
461 H264_CONTEXT_OPENH264* sysContexts;
462
463 WINPR_ASSERT(name);
464
465 if (!h264)
466 return FALSE;
467
468 sysContexts = h264->pSystemData;
469
470 if (!sysContexts)
471 return FALSE;
472
473 sysContexts->lib = LoadLibraryA(name);
474
475 if (!sysContexts->lib)
476 return FALSE;
477
478 sysContexts->WelsGetCodecVersionEx =
479 GetProcAddressAs(sysContexts->lib, "WelsGetCodecVersionEx", pWelsGetCodecVersionEx);
480 sysContexts->WelsCreateDecoder =
481 GetProcAddressAs(sysContexts->lib, "WelsCreateDecoder", pWelsCreateDecoder);
482 sysContexts->WelsDestroyDecoder =
483 GetProcAddressAs(sysContexts->lib, "WelsDestroyDecoder", pWelsDestroyDecoder);
484 sysContexts->WelsCreateSVCEncoder =
485 GetProcAddressAs(sysContexts->lib, "WelsCreateSVCEncoder", pWelsCreateSVCEncoder);
486 sysContexts->WelsDestroySVCEncoder =
487 GetProcAddressAs(sysContexts->lib, "WelsDestroySVCEncoder", pWelsDestroySVCEncoder);
488
489 if (!sysContexts->WelsCreateDecoder || !sysContexts->WelsDestroyDecoder ||
490 !sysContexts->WelsCreateSVCEncoder || !sysContexts->WelsDestroySVCEncoder ||
491 !sysContexts->WelsGetCodecVersionEx)
492 {
493 FreeLibrary(sysContexts->lib);
494 sysContexts->lib = nullptr;
495 return FALSE;
496 }
497
498 sysContexts->WelsGetCodecVersionEx(&sysContexts->version);
499 WLog_Print(h264->log, WLOG_DEBUG, "loaded %s %u.%u.%u", name, sysContexts->version.uMajor,
500 sysContexts->version.uMinor, sysContexts->version.uRevision);
501
502 if ((sysContexts->version.uMajor < 1) ||
503 ((sysContexts->version.uMajor == 1) && (sysContexts->version.uMinor < 6)))
504 {
505 WLog_Print(
506 h264->log, WLOG_ERROR,
507 "OpenH264 %s %u.%u.%u is too old, need at least version 1.6.0 for dynamic loading",
508 name, sysContexts->version.uMajor, sysContexts->version.uMinor,
509 sysContexts->version.uRevision);
510 FreeLibrary(sysContexts->lib);
511 sysContexts->lib = nullptr;
512 return FALSE;
513 }
514
515 return TRUE;
516}
517#endif
518
519static BOOL openh264_init(H264_CONTEXT* h264)
520{
521#if defined(WITH_OPENH264_LOADING)
522 BOOL success = FALSE;
523#endif
524 long status = 0;
525 H264_CONTEXT_OPENH264* sysContexts = nullptr;
526 static int traceLevel = WELS_LOG_DEBUG;
527#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
528 static EVideoFormatType videoFormat = videoFormatI420;
529#endif
530 static WelsTraceCallback traceCallback = openh264_trace_callback;
531
532 WINPR_ASSERT(h264);
533
534 h264->numSystemData = 1;
535 sysContexts =
536 (H264_CONTEXT_OPENH264*)calloc(h264->numSystemData, sizeof(H264_CONTEXT_OPENH264));
537
538 if (!sysContexts)
539 goto EXCEPTION;
540
541 h264->pSystemData = (void*)sysContexts;
542#if defined(WITH_OPENH264_LOADING)
543
544 for (size_t i = 0; i < ARRAYSIZE(openh264_library_names); i++)
545 {
546 const char* current = openh264_library_names[i];
547 success = openh264_load_functionpointers(h264, current);
548
549 if (success)
550 break;
551 }
552
553 if (!success)
554 goto EXCEPTION;
555
556#else
557 sysContexts->WelsGetCodecVersionEx = WelsGetCodecVersionEx;
558 sysContexts->WelsCreateDecoder = WelsCreateDecoder;
559 sysContexts->WelsDestroyDecoder = WelsDestroyDecoder;
560 sysContexts->WelsCreateSVCEncoder = WelsCreateSVCEncoder;
561 sysContexts->WelsDestroySVCEncoder = WelsDestroySVCEncoder;
562#endif
563
564 for (UINT32 x = 0; x < h264->numSystemData; x++)
565 {
566 SDecodingParam sDecParam = WINPR_C_ARRAY_INIT;
567 H264_CONTEXT_OPENH264* sys = &sysContexts[x];
568
569 if (h264->Compressor)
570 {
571#if defined(WITH_OPENH264_LOADING)
572 if (sysContexts->version.uMajor != OPENH264_MAJOR ||
573 sysContexts->version.uMinor != OPENH264_MINOR)
574 {
575 WLog_Print(h264->log, WLOG_WARN,
576 "OpenH264 encoder ABI mismatch: runtime %d.%d.%d vs compiled %d.%d.%d",
577 sysContexts->version.uMajor, sysContexts->version.uMinor,
578 sysContexts->version.uRevision, OPENH264_MAJOR, OPENH264_MINOR,
579 OPENH264_REVISION);
580 goto EXCEPTION;
581 }
582#endif
583 const int rc = sysContexts->WelsCreateSVCEncoder(&sys->pEncoder);
584 if (rc != 0)
585 {
586 WLog_Print(h264->log, WLOG_ERROR, "Failed to create OpenH264 encoder: %d", rc);
587 goto EXCEPTION;
588 }
589 if (!sys->pEncoder)
590 {
591 WLog_Print(h264->log, WLOG_ERROR, "Failed to create OpenH264 encoder");
592 goto EXCEPTION;
593 }
594 }
595 else
596 {
597 const long rc = sysContexts->WelsCreateDecoder(&sys->pDecoder);
598 if (rc != 0)
599 {
600 WLog_Print(h264->log, WLOG_ERROR, "Failed to create OpenH264 decoder: %ld", rc);
601 goto EXCEPTION;
602 }
603 if (!sys->pDecoder)
604 {
605 WLog_Print(h264->log, WLOG_ERROR, "Failed to create OpenH264 decoder");
606 goto EXCEPTION;
607 }
608
609#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
610 sDecParam.eOutputColorFormat = videoFormatI420;
611#endif
612 sDecParam.eEcActiveIdc = ERROR_CON_FRAME_COPY;
613 sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;
614 status = (*sys->pDecoder)->Initialize(sys->pDecoder, &sDecParam);
615
616 if (status != 0)
617 {
618 WLog_Print(h264->log, WLOG_ERROR,
619 "Failed to initialize OpenH264 decoder (status=%ld)", status);
620 goto EXCEPTION;
621 }
622
623#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
624 status =
625 (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_DATAFORMAT, &videoFormat);
626#endif
627
628 if (status != 0)
629 {
630 WLog_Print(h264->log, WLOG_ERROR,
631 "Failed to set data format option on OpenH264 decoder (status=%ld)",
632 status);
633 goto EXCEPTION;
634 }
635
636 if (WLog_GetLogLevel(h264->log) == WLOG_TRACE)
637 {
638 status = (*sys->pDecoder)
639 ->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_LEVEL, &traceLevel);
640
641 if (status != 0)
642 {
643 WLog_Print(h264->log, WLOG_ERROR,
644 "Failed to set trace level option on OpenH264 decoder (status=%ld)",
645 status);
646 goto EXCEPTION;
647 }
648
649 status = (*sys->pDecoder)
650 ->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_CALLBACK_CONTEXT,
651 (void*)&h264);
652
653 if (status != 0)
654 {
655 WLog_Print(h264->log, WLOG_ERROR,
656 "Failed to set trace callback context option on OpenH264 decoder "
657 "(status=%ld)",
658 status);
659 goto EXCEPTION;
660 }
661
662 status = (*sys->pDecoder)
663 ->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_CALLBACK,
664 (void*)&traceCallback);
665
666 if (status != 0)
667 {
668 WLog_Print(
669 h264->log, WLOG_ERROR,
670 "Failed to set trace callback option on OpenH264 decoder (status=%ld)",
671 status);
672 goto EXCEPTION;
673 }
674 }
675 }
676 }
677
678 h264->hwAccel = FALSE; /* not supported */
679 return TRUE;
680EXCEPTION:
681 openh264_uninit(h264);
682 return FALSE;
683}
684
685const H264_CONTEXT_SUBSYSTEM g_Subsystem_OpenH264 = { "OpenH264", openh264_init, openh264_uninit,
686 openh264_decompress, openh264_compress };