FreeRDP
tsmf_decoder.c
1 
20 #include <freerdp/config.h>
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 
26 #include <freerdp/addin.h>
27 #include <freerdp/client/channels.h>
28 
29 #include "tsmf_types.h"
30 #include "tsmf_constants.h"
31 #include "tsmf_decoder.h"
32 
33 static ITSMFDecoder* tsmf_load_decoder_by_name(const char* name)
34 {
35  ITSMFDecoder* decoder = NULL;
36  union
37  {
38  PVIRTUALCHANNELENTRY pvce;
39  TSMF_DECODER_ENTRY entry;
40  } cnv;
41  cnv.pvce = freerdp_load_channel_addin_entry("tsmf", name, "decoder", 0);
42 
43  if (!cnv.entry)
44  return NULL;
45 
46  const UINT rc = cnv.entry(&decoder);
47 
48  if ((rc != CHANNEL_RC_OK) || !decoder)
49  {
50  WLog_ERR(TAG, "failed to call export function in %s", name);
51  return NULL;
52  }
53 
54  return decoder;
55 }
56 
57 static BOOL tsmf_decoder_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* media_type)
58 {
59  if (decoder->SetFormat(decoder, media_type))
60  return TRUE;
61  else
62  return FALSE;
63 }
64 
65 ITSMFDecoder* tsmf_load_decoder(const char* name, TS_AM_MEDIA_TYPE* media_type)
66 {
67  ITSMFDecoder* decoder = NULL;
68 
69  if (name)
70  decoder = tsmf_load_decoder_by_name(name);
71 
72 #if defined(WITH_GSTREAMER_1_0)
73  if (!decoder)
74  decoder = tsmf_load_decoder_by_name("gstreamer");
75 #endif
76 
77 #if defined(WITH_VIDEO_FFMPEG)
78  if (!decoder)
79  decoder = tsmf_load_decoder_by_name("ffmpeg");
80 #endif
81 
82  if (decoder)
83  {
84  if (!tsmf_decoder_set_format(decoder, media_type))
85  {
86  decoder->Free(decoder);
87  decoder = NULL;
88  }
89  }
90 
91  return decoder;
92 }
93 
94 BOOL tsmf_check_decoder_available(const char* name)
95 {
96  ITSMFDecoder* decoder = NULL;
97  BOOL retValue = FALSE;
98 
99  if (name)
100  {
101  decoder = tsmf_load_decoder_by_name(name);
102  }
103 #if defined(WITH_GSTREAMER_1_0)
104  if (!decoder)
105  decoder = tsmf_load_decoder_by_name("gstreamer");
106 #endif
107 
108 #if defined(WITH_VIDEO_FFMPEG)
109  if (!decoder)
110  decoder = tsmf_load_decoder_by_name("ffmpeg");
111 #endif
112 
113  if (decoder)
114  {
115  decoder->Free(decoder);
116  decoder = NULL;
117  retValue = TRUE;
118  }
119 
120  return retValue;
121 }