gst_ios_init.m 2.59 KB
Newer Older
1 2 3
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

4
#include "gst_ios_init.h"
5

6 7 8 9 10 11 12 13 14 15 16 17
G_BEGIN_DECLS

#define GST_G_IO_MODULE_DECLARE(name) \
    extern void G_PASTE(g_io_module_, G_PASTE(name, _load_static)) (void)

#define GST_G_IO_MODULE_LOAD(name) \
    G_PASTE(g_io_module_, G_PASTE(name, _load_static)) ()

G_END_DECLS

#define GST_IOS_GIO_MODULE_GNUTLS

18 19 20 21 22
#if defined(GST_IOS_GIO_MODULE_GNUTLS)
  #include <gio/gio.h>
  GST_G_IO_MODULE_DECLARE(gnutls);
#endif

23
void gst_ios_pre_init(void)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
{
  NSString *resources = [[NSBundle mainBundle] resourcePath];
  NSString *tmp = NSTemporaryDirectory();
  NSString *cache = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];
  NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    
  const gchar *resources_dir = [resources UTF8String];
  const gchar *tmp_dir = [tmp UTF8String];
  const gchar *cache_dir = [cache UTF8String];
  const gchar *docs_dir = [docs UTF8String];
  gchar *ca_certificates;
    
  g_setenv ("TMP", tmp_dir, TRUE);
  g_setenv ("TEMP", tmp_dir, TRUE);
  g_setenv ("TMPDIR", tmp_dir, TRUE);
  g_setenv ("XDG_RUNTIME_DIR", resources_dir, TRUE);
  g_setenv ("XDG_CACHE_HOME", cache_dir, TRUE);
    
  g_setenv ("HOME", docs_dir, TRUE);
  g_setenv ("XDG_DATA_DIRS", resources_dir, TRUE);
  g_setenv ("XDG_CONFIG_DIRS", resources_dir, TRUE);
  g_setenv ("XDG_CONFIG_HOME", cache_dir, TRUE);
  g_setenv ("XDG_DATA_HOME", resources_dir, TRUE);
  g_setenv ("FONTCONFIG_PATH", resources_dir, TRUE);

  ca_certificates = g_build_filename (resources_dir, "ssl", "certs", "ca-certificates.crt", NULL);
  g_setenv ("CA_CERTIFICATES", ca_certificates, TRUE);
  g_free (ca_certificates);
52
}
53

54 55 56 57
void gst_ios_post_init(void)
{
  GstPluginFeature *plugin;
  GstRegistry *reg;
58 59
  /* Lower the ranks of filesrc and giosrc so iosavassetsrc is
   * tried first in gst_element_make_from_uri() for file:// */
60 61 62 63 64

#if defined(GST_IOS_GIO_MODULE_GNUTLS)
    GST_G_IO_MODULE_LOAD(gnutls);
#endif

65 66 67 68 69 70 71
  reg = gst_registry_get();
  plugin = gst_registry_lookup_feature(reg, "filesrc");
  if (plugin)
    gst_plugin_feature_set_rank(plugin, GST_RANK_SECONDARY);
  plugin = gst_registry_lookup_feature(reg, "giosrc");
  if (plugin)
    gst_plugin_feature_set_rank(plugin, GST_RANK_SECONDARY-1);
72 73 74 75 76 77 78 79
  if (!gst_registry_lookup_feature(reg, "vtdec_hw")) {
    /* Usually there is no vtdec_hw plugin on iOS - in that case
     * we are increasing vtdec rank since VideoToolbox on iOS
     * tries to use hardware implementation first */
    plugin = gst_registry_lookup_feature(reg, "vtdec");
    if (plugin)
      gst_plugin_feature_set_rank(plugin, GST_RANK_PRIMARY + 1);
    }
80
}