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 WINPR_ATTR_NODISCARD 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 return 1;
181}
182
183static int openh264_compress(H264_CONTEXT* WINPR_RESTRICT h264,
184 const BYTE** WINPR_RESTRICT pYUVData,
185 const UINT32* WINPR_RESTRICT iStride, BYTE** WINPR_RESTRICT ppDstData,
186 UINT32* WINPR_RESTRICT pDstSize)
187{
188 int status = 0;
189 SFrameBSInfo info = WINPR_C_ARRAY_INIT;
190 SSourcePicture pic = WINPR_C_ARRAY_INIT;
191
192 H264_CONTEXT_OPENH264* sys = nullptr;
193
194 WINPR_ASSERT(h264);
195 WINPR_ASSERT(pYUVData);
196 WINPR_ASSERT(iStride);
197 WINPR_ASSERT(ppDstData);
198 WINPR_ASSERT(pDstSize);
199
200 sys = &((H264_CONTEXT_OPENH264*)h264->pSystemData)[0];
201 WINPR_ASSERT(sys);
202
203 if (!sys->pEncoder)
204 return -1;
205
206 if (!pYUVData[0] || !pYUVData[1] || !pYUVData[2])
207 return -1;
208
209 if ((h264->width > INT_MAX) || (h264->height > INT_MAX))
210 return -1;
211
212 if ((h264->FrameRate > INT_MAX) || (h264->NumberOfThreads > INT_MAX) ||
213 (h264->BitRate > INT_MAX) || (h264->QP > INT_MAX))
214 return -1;
215
216 WINPR_ASSERT(sys->pEncoder);
217 if ((sys->EncParamExt.iPicWidth != (int)h264->width) ||
218 (sys->EncParamExt.iPicHeight != (int)h264->height))
219 {
220 WINPR_ASSERT((*sys->pEncoder)->GetDefaultParams);
221 status = (*sys->pEncoder)->GetDefaultParams(sys->pEncoder, &sys->EncParamExt);
222
223 if (status < 0)
224 {
225 WLog_Print(h264->log, WLOG_ERROR,
226 "Failed to get OpenH264 default parameters (status=%d)", status);
227 return status;
228 }
229
230 EUsageType usageType = SCREEN_CONTENT_REAL_TIME;
231
232 switch (h264->UsageType)
233 {
234 case H264_CAMERA_VIDEO_NON_REAL_TIME:
235 usageType = CAMERA_VIDEO_NON_REAL_TIME;
236 break;
237 case H264_CAMERA_VIDEO_REAL_TIME:
238 usageType = CAMERA_VIDEO_REAL_TIME;
239 break;
240 case H264_SCREEN_CONTENT_NON_REAL_TIME:
241 usageType = SCREEN_CONTENT_NON_REAL_TIME;
242 break;
243 case H264_SCREEN_CONTENT_REAL_TIME:
244 default:
245 break;
246 }
247
248 sys->EncParamExt.iUsageType = usageType;
249 sys->EncParamExt.iPicWidth = WINPR_ASSERTING_INT_CAST(int, h264->width);
250 sys->EncParamExt.iPicHeight = WINPR_ASSERTING_INT_CAST(int, h264->height);
251 sys->EncParamExt.fMaxFrameRate = WINPR_ASSERTING_INT_CAST(short, h264->FrameRate);
252 sys->EncParamExt.iMaxBitrate = UNSPECIFIED_BIT_RATE;
253 sys->EncParamExt.bEnableDenoise = 0;
254 sys->EncParamExt.bEnableLongTermReference = 0;
255 sys->EncParamExt.iSpatialLayerNum = 1;
256 sys->EncParamExt.iMultipleThreadIdc =
257 WINPR_ASSERTING_INT_CAST(unsigned short, h264->NumberOfThreads);
258 sys->EncParamExt.sSpatialLayers[0].fFrameRate =
259 WINPR_ASSERTING_INT_CAST(short, h264->FrameRate);
260 sys->EncParamExt.sSpatialLayers[0].iVideoWidth = sys->EncParamExt.iPicWidth;
261 sys->EncParamExt.sSpatialLayers[0].iVideoHeight = sys->EncParamExt.iPicHeight;
262 sys->EncParamExt.sSpatialLayers[0].iMaxSpatialBitrate = sys->EncParamExt.iMaxBitrate;
263
264 switch (h264->RateControlMode)
265 {
266 case H264_RATECONTROL_VBR:
267 sys->EncParamExt.iRCMode = RC_BITRATE_MODE;
268 sys->EncParamExt.iTargetBitrate = (int)h264->BitRate;
269 sys->EncParamExt.sSpatialLayers[0].iSpatialBitrate =
270 sys->EncParamExt.iTargetBitrate;
271 sys->EncParamExt.bEnableFrameSkip = 1;
272 break;
273
274 case H264_RATECONTROL_CQP:
275 sys->EncParamExt.iRCMode = RC_OFF_MODE;
276 sys->EncParamExt.sSpatialLayers[0].iDLayerQp = (int)h264->QP;
277 sys->EncParamExt.bEnableFrameSkip = 0;
278 break;
279 default:
280 break;
281 }
282
283 if (sys->EncParamExt.iMultipleThreadIdc > 1)
284 {
285#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
286 sys->EncParamExt.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_AUTO_SLICE;
287#else
288 sys->EncParamExt.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
289#endif
290 }
291
292 WINPR_ASSERT((*sys->pEncoder)->InitializeExt);
293 status = (*sys->pEncoder)->InitializeExt(sys->pEncoder, &sys->EncParamExt);
294
295 if (status < 0)
296 {
297 WLog_Print(h264->log, WLOG_ERROR, "Failed to initialize OpenH264 encoder (status=%d)",
298 status);
299 return status;
300 }
301
302 WINPR_ASSERT((*sys->pEncoder)->GetOption);
303 status =
304 (*sys->pEncoder)
305 ->GetOption(sys->pEncoder, ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &sys->EncParamExt);
306
307 if (status < 0)
308 {
309 WLog_Print(h264->log, WLOG_ERROR,
310 "Failed to get initial OpenH264 encoder parameters (status=%d)", status);
311 return status;
312 }
313 }
314 else
315 {
316 switch (h264->RateControlMode)
317 {
318 case H264_RATECONTROL_VBR:
319 if (sys->EncParamExt.iTargetBitrate != (int)h264->BitRate)
320 {
321 SBitrateInfo bitrate = WINPR_C_ARRAY_INIT;
322
323 sys->EncParamExt.iTargetBitrate = (int)h264->BitRate;
324 bitrate.iLayer = SPATIAL_LAYER_ALL;
325 bitrate.iBitrate = (int)h264->BitRate;
326
327 WINPR_ASSERT((*sys->pEncoder)->SetOption);
328 status = (*sys->pEncoder)
329 ->SetOption(sys->pEncoder, ENCODER_OPTION_BITRATE, &bitrate);
330
331 if (status < 0)
332 {
333 WLog_Print(h264->log, WLOG_ERROR,
334 "Failed to set encoder bitrate (status=%d)", status);
335 return status;
336 }
337 }
338
339 if ((uint32_t)sys->EncParamExt.fMaxFrameRate != h264->FrameRate)
340 {
341 sys->EncParamExt.fMaxFrameRate = WINPR_ASSERTING_INT_CAST(int, h264->FrameRate);
342
343 WINPR_ASSERT((*sys->pEncoder)->SetOption);
344 status = (*sys->pEncoder)
345 ->SetOption(sys->pEncoder, ENCODER_OPTION_FRAME_RATE,
346 &sys->EncParamExt.fMaxFrameRate);
347
348 if (status < 0)
349 {
350 WLog_Print(h264->log, WLOG_ERROR,
351 "Failed to set encoder framerate (status=%d)", status);
352 return status;
353 }
354 }
355
356 break;
357
358 case H264_RATECONTROL_CQP:
359 if (sys->EncParamExt.sSpatialLayers[0].iDLayerQp != (int)h264->QP)
360 {
361 sys->EncParamExt.sSpatialLayers[0].iDLayerQp = (int)h264->QP;
362
363 WINPR_ASSERT((*sys->pEncoder)->SetOption);
364 status = (*sys->pEncoder)
365 ->SetOption(sys->pEncoder, ENCODER_OPTION_SVC_ENCODE_PARAM_EXT,
366 &sys->EncParamExt);
367
368 if (status < 0)
369 {
370 WLog_Print(h264->log, WLOG_ERROR,
371 "Failed to set encoder parameters (status=%d)", status);
372 return status;
373 }
374 }
375
376 break;
377 default:
378 break;
379 }
380 }
381
382 pic.iPicWidth = (int)h264->width;
383 pic.iPicHeight = (int)h264->height;
384 pic.iColorFormat = videoFormatI420;
385 pic.iStride[0] = (int)iStride[0];
386 pic.iStride[1] = (int)iStride[1];
387 pic.iStride[2] = (int)iStride[2];
388 pic.pData[0] = WINPR_CAST_CONST_PTR_AWAY(pYUVData[0], BYTE*);
389 pic.pData[1] = WINPR_CAST_CONST_PTR_AWAY(pYUVData[1], BYTE*);
390 pic.pData[2] = WINPR_CAST_CONST_PTR_AWAY(pYUVData[2], BYTE*);
391
392 WINPR_ASSERT((*sys->pEncoder)->EncodeFrame);
393 status = (*sys->pEncoder)->EncodeFrame(sys->pEncoder, &pic, &info);
394
395 if (status < 0)
396 {
397 WLog_Print(h264->log, WLOG_ERROR, "Failed to encode frame (status=%d)", status);
398 return status;
399 }
400
401 *ppDstData = info.sLayerInfo[0].pBsBuf;
402 *pDstSize = 0;
403
404 for (int i = 0; i < info.iLayerNum; i++)
405 {
406 for (int j = 0; j < info.sLayerInfo[i].iNalCount; j++)
407 {
408 const int val = info.sLayerInfo[i].pNalLengthInByte[j];
409 *pDstSize += WINPR_ASSERTING_INT_CAST(uint32_t, val);
410 }
411 }
412
413 return 1;
414}
415
416static void openh264_uninit(H264_CONTEXT* h264)
417{
418 H264_CONTEXT_OPENH264* sysContexts = nullptr;
419
420 WINPR_ASSERT(h264);
421
422 sysContexts = (H264_CONTEXT_OPENH264*)h264->pSystemData;
423
424 if (sysContexts)
425 {
426 for (UINT32 x = 0; x < h264->numSystemData; x++)
427 {
428 H264_CONTEXT_OPENH264* sys = &sysContexts[x];
429
430 if (sys->pDecoder)
431 {
432 (*sys->pDecoder)->Uninitialize(sys->pDecoder);
433 sysContexts->WelsDestroyDecoder(sys->pDecoder);
434 sys->pDecoder = nullptr;
435 }
436
437 if (sys->pEncoder)
438 {
439 (*sys->pEncoder)->Uninitialize(sys->pEncoder);
440 sysContexts->WelsDestroySVCEncoder(sys->pEncoder);
441 sys->pEncoder = nullptr;
442 }
443 }
444
445#if defined(WITH_OPENH264_LOADING)
446 if (sysContexts->lib)
447 FreeLibrary(sysContexts->lib);
448#endif
449 free(h264->pSystemData);
450 h264->pSystemData = nullptr;
451 }
452}
453
454#if defined(WITH_OPENH264_LOADING)
455static BOOL openh264_load_functionpointers(H264_CONTEXT* h264, const char* name)
456{
457 H264_CONTEXT_OPENH264* sysContexts;
458
459 WINPR_ASSERT(name);
460
461 if (!h264)
462 return FALSE;
463
464 sysContexts = h264->pSystemData;
465
466 if (!sysContexts)
467 return FALSE;
468
469 sysContexts->lib = LoadLibraryA(name);
470
471 if (!sysContexts->lib)
472 return FALSE;
473
474 sysContexts->WelsGetCodecVersionEx =
475 GetProcAddressAs(sysContexts->lib, "WelsGetCodecVersionEx", pWelsGetCodecVersionEx);
476 sysContexts->WelsCreateDecoder =
477 GetProcAddressAs(sysContexts->lib, "WelsCreateDecoder", pWelsCreateDecoder);
478 sysContexts->WelsDestroyDecoder =
479 GetProcAddressAs(sysContexts->lib, "WelsDestroyDecoder", pWelsDestroyDecoder);
480 sysContexts->WelsCreateSVCEncoder =
481 GetProcAddressAs(sysContexts->lib, "WelsCreateSVCEncoder", pWelsCreateSVCEncoder);
482 sysContexts->WelsDestroySVCEncoder =
483 GetProcAddressAs(sysContexts->lib, "WelsDestroySVCEncoder", pWelsDestroySVCEncoder);
484
485 if (!sysContexts->WelsCreateDecoder || !sysContexts->WelsDestroyDecoder ||
486 !sysContexts->WelsCreateSVCEncoder || !sysContexts->WelsDestroySVCEncoder ||
487 !sysContexts->WelsGetCodecVersionEx)
488 {
489 FreeLibrary(sysContexts->lib);
490 sysContexts->lib = nullptr;
491 return FALSE;
492 }
493
494 sysContexts->WelsGetCodecVersionEx(&sysContexts->version);
495 WLog_Print(h264->log, WLOG_INFO, "loaded %s %d.%d.%d", name, sysContexts->version.uMajor,
496 sysContexts->version.uMinor, sysContexts->version.uRevision);
497
498 if ((sysContexts->version.uMajor < 1) ||
499 ((sysContexts->version.uMajor == 1) && (sysContexts->version.uMinor < 6)))
500 {
501 WLog_Print(
502 h264->log, WLOG_ERROR,
503 "OpenH264 %s %d.%d.%d is too old, need at least version 1.6.0 for dynamic loading",
504 name, sysContexts->version.uMajor, sysContexts->version.uMinor,
505 sysContexts->version.uRevision);
506 FreeLibrary(sysContexts->lib);
507 sysContexts->lib = nullptr;
508 return FALSE;
509 }
510
511 return TRUE;
512}
513#endif
514
515static BOOL openh264_init(H264_CONTEXT* h264)
516{
517#if defined(WITH_OPENH264_LOADING)
518 BOOL success = FALSE;
519#endif
520 long status = 0;
521 H264_CONTEXT_OPENH264* sysContexts = nullptr;
522 static int traceLevel = WELS_LOG_DEBUG;
523#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
524 static EVideoFormatType videoFormat = videoFormatI420;
525#endif
526 static WelsTraceCallback traceCallback = openh264_trace_callback;
527
528 WINPR_ASSERT(h264);
529
530 h264->numSystemData = 1;
531 sysContexts =
532 (H264_CONTEXT_OPENH264*)calloc(h264->numSystemData, sizeof(H264_CONTEXT_OPENH264));
533
534 if (!sysContexts)
535 goto EXCEPTION;
536
537 h264->pSystemData = (void*)sysContexts;
538#if defined(WITH_OPENH264_LOADING)
539
540 for (size_t i = 0; i < ARRAYSIZE(openh264_library_names); i++)
541 {
542 const char* current = openh264_library_names[i];
543 success = openh264_load_functionpointers(h264, current);
544
545 if (success)
546 break;
547 }
548
549 if (!success)
550 goto EXCEPTION;
551
552#else
553 sysContexts->WelsGetCodecVersionEx = WelsGetCodecVersionEx;
554 sysContexts->WelsCreateDecoder = WelsCreateDecoder;
555 sysContexts->WelsDestroyDecoder = WelsDestroyDecoder;
556 sysContexts->WelsCreateSVCEncoder = WelsCreateSVCEncoder;
557 sysContexts->WelsDestroySVCEncoder = WelsDestroySVCEncoder;
558#endif
559
560 for (UINT32 x = 0; x < h264->numSystemData; x++)
561 {
562 SDecodingParam sDecParam = WINPR_C_ARRAY_INIT;
563 H264_CONTEXT_OPENH264* sys = &sysContexts[x];
564
565 if (h264->Compressor)
566 {
567 sysContexts->WelsCreateSVCEncoder(&sys->pEncoder);
568
569 if (!sys->pEncoder)
570 {
571 WLog_Print(h264->log, WLOG_ERROR, "Failed to create OpenH264 encoder");
572 goto EXCEPTION;
573 }
574 }
575 else
576 {
577 sysContexts->WelsCreateDecoder(&sys->pDecoder);
578
579 if (!sys->pDecoder)
580 {
581 WLog_Print(h264->log, WLOG_ERROR, "Failed to create OpenH264 decoder");
582 goto EXCEPTION;
583 }
584
585#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
586 sDecParam.eOutputColorFormat = videoFormatI420;
587#endif
588 sDecParam.eEcActiveIdc = ERROR_CON_FRAME_COPY;
589 sDecParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_AVC;
590 status = (*sys->pDecoder)->Initialize(sys->pDecoder, &sDecParam);
591
592 if (status != 0)
593 {
594 WLog_Print(h264->log, WLOG_ERROR,
595 "Failed to initialize OpenH264 decoder (status=%ld)", status);
596 goto EXCEPTION;
597 }
598
599#if (OPENH264_MAJOR == 1) && (OPENH264_MINOR <= 5)
600 status =
601 (*sys->pDecoder)->SetOption(sys->pDecoder, DECODER_OPTION_DATAFORMAT, &videoFormat);
602#endif
603
604 if (status != 0)
605 {
606 WLog_Print(h264->log, WLOG_ERROR,
607 "Failed to set data format option on OpenH264 decoder (status=%ld)",
608 status);
609 goto EXCEPTION;
610 }
611
612 if (WLog_GetLogLevel(h264->log) == WLOG_TRACE)
613 {
614 status = (*sys->pDecoder)
615 ->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_LEVEL, &traceLevel);
616
617 if (status != 0)
618 {
619 WLog_Print(h264->log, WLOG_ERROR,
620 "Failed to set trace level option on OpenH264 decoder (status=%ld)",
621 status);
622 goto EXCEPTION;
623 }
624
625 status = (*sys->pDecoder)
626 ->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_CALLBACK_CONTEXT,
627 (void*)&h264);
628
629 if (status != 0)
630 {
631 WLog_Print(h264->log, WLOG_ERROR,
632 "Failed to set trace callback context option on OpenH264 decoder "
633 "(status=%ld)",
634 status);
635 goto EXCEPTION;
636 }
637
638 status = (*sys->pDecoder)
639 ->SetOption(sys->pDecoder, DECODER_OPTION_TRACE_CALLBACK,
640 (void*)&traceCallback);
641
642 if (status != 0)
643 {
644 WLog_Print(
645 h264->log, WLOG_ERROR,
646 "Failed to set trace callback option on OpenH264 decoder (status=%ld)",
647 status);
648 goto EXCEPTION;
649 }
650 }
651 }
652 }
653
654 h264->hwAccel = FALSE; /* not supported */
655 return TRUE;
656EXCEPTION:
657 openh264_uninit(h264);
658 return FALSE;
659}
660
661const H264_CONTEXT_SUBSYSTEM g_Subsystem_OpenH264 = { "OpenH264", openh264_init, openh264_uninit,
662 openh264_decompress, openh264_compress };