GStreamer.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package org.freedesktop.gstreamer;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import android.content.Context;
  8. import android.content.res.AssetManager;
  9. public class GStreamer {
  10. private static native void nativeInit(Context context) throws Exception;
  11. public static void init(Context context) throws Exception {
  12. @INCLUDE_CA_CERTIFICATES@ copyCaCertificates(context);
  13. @INCLUDE_FONTS@ copyFonts(context);
  14. nativeInit(context);
  15. }
  16. @INCLUDE_FONTS@ private static void copyFonts(Context context) {
  17. @INCLUDE_FONTS@ AssetManager assetManager = context.getAssets();
  18. @INCLUDE_FONTS@ File filesDir = context.getFilesDir();
  19. @INCLUDE_FONTS@ File fontsFCDir = new File (filesDir, "fontconfig");
  20. @INCLUDE_FONTS@ File fontsDir = new File (fontsFCDir, "fonts");
  21. @INCLUDE_FONTS@ File fontsCfg = new File (fontsFCDir, "fonts.conf");
  22. @INCLUDE_FONTS@
  23. @INCLUDE_FONTS@ fontsDir.mkdirs();
  24. @INCLUDE_FONTS@
  25. @INCLUDE_FONTS@ try {
  26. @INCLUDE_FONTS@ /* Copy the config file */
  27. @INCLUDE_FONTS@ copyFile (assetManager, "fontconfig/fonts.conf", fontsCfg);
  28. @INCLUDE_FONTS@ /* Copy the fonts */
  29. @INCLUDE_FONTS@ for(String filename : assetManager.list("fontconfig/fonts/truetype")) {
  30. @INCLUDE_FONTS@ File font = new File(fontsDir, filename);
  31. @INCLUDE_FONTS@ copyFile (assetManager, "fontconfig/fonts/truetype/" + filename, font);
  32. @INCLUDE_FONTS@ }
  33. @INCLUDE_FONTS@ } catch (IOException e) {
  34. @INCLUDE_FONTS@ e.printStackTrace();
  35. @INCLUDE_FONTS@ }
  36. @INCLUDE_FONTS@ }
  37. @INCLUDE_CA_CERTIFICATES@ private static void copyCaCertificates(Context context) {
  38. @INCLUDE_CA_CERTIFICATES@ AssetManager assetManager = context.getAssets();
  39. @INCLUDE_CA_CERTIFICATES@ File filesDir = context.getFilesDir();
  40. @INCLUDE_CA_CERTIFICATES@ File sslDir = new File (filesDir, "ssl");
  41. @INCLUDE_CA_CERTIFICATES@ File certsDir = new File (sslDir, "certs");
  42. @INCLUDE_CA_CERTIFICATES@ File certs = new File (certsDir, "ca-certificates.crt");
  43. @INCLUDE_CA_CERTIFICATES@
  44. @INCLUDE_CA_CERTIFICATES@ certsDir.mkdirs();
  45. @INCLUDE_CA_CERTIFICATES@
  46. @INCLUDE_CA_CERTIFICATES@ try {
  47. @INCLUDE_CA_CERTIFICATES@ /* Copy the certificates file */
  48. @INCLUDE_CA_CERTIFICATES@ copyFile (assetManager, "ssl/certs/ca-certificates.crt", certs);
  49. @INCLUDE_CA_CERTIFICATES@ } catch (IOException e) {
  50. @INCLUDE_CA_CERTIFICATES@ e.printStackTrace();
  51. @INCLUDE_CA_CERTIFICATES@ }
  52. @INCLUDE_CA_CERTIFICATES@ }
  53. @INCLUDE_COPY_FILE@ private static void copyFile(AssetManager assetManager, String assetPath, File outFile) throws IOException {
  54. @INCLUDE_COPY_FILE@ InputStream in = null;
  55. @INCLUDE_COPY_FILE@ OutputStream out = null;
  56. @INCLUDE_COPY_FILE@ IOException exception = null;
  57. @INCLUDE_COPY_FILE@
  58. @INCLUDE_COPY_FILE@ if (outFile.exists())
  59. @INCLUDE_COPY_FILE@ outFile.delete();
  60. @INCLUDE_COPY_FILE@
  61. @INCLUDE_COPY_FILE@ try {
  62. @INCLUDE_COPY_FILE@ in = assetManager.open(assetPath);
  63. @INCLUDE_COPY_FILE@ out = new FileOutputStream(outFile);
  64. @INCLUDE_COPY_FILE@
  65. @INCLUDE_COPY_FILE@ byte[] buffer = new byte[1024];
  66. @INCLUDE_COPY_FILE@ int read;
  67. @INCLUDE_COPY_FILE@ while ((read = in.read(buffer)) != -1) {
  68. @INCLUDE_COPY_FILE@ out.write(buffer, 0, read);
  69. @INCLUDE_COPY_FILE@ }
  70. @INCLUDE_COPY_FILE@ out.flush();
  71. @INCLUDE_COPY_FILE@ } catch (IOException e) {
  72. @INCLUDE_COPY_FILE@ exception = e;
  73. @INCLUDE_COPY_FILE@ } finally {
  74. @INCLUDE_COPY_FILE@ if (in != null)
  75. @INCLUDE_COPY_FILE@ try {
  76. @INCLUDE_COPY_FILE@ in.close();
  77. @INCLUDE_COPY_FILE@ } catch (IOException e) {
  78. @INCLUDE_COPY_FILE@ if (exception == null)
  79. @INCLUDE_COPY_FILE@ exception = e;
  80. @INCLUDE_COPY_FILE@ }
  81. @INCLUDE_COPY_FILE@ if (out != null)
  82. @INCLUDE_COPY_FILE@ try {
  83. @INCLUDE_COPY_FILE@ out.close();
  84. @INCLUDE_COPY_FILE@ } catch (IOException e) {
  85. @INCLUDE_COPY_FILE@ if (exception == null)
  86. @INCLUDE_COPY_FILE@ exception = e;
  87. @INCLUDE_COPY_FILE@ }
  88. @INCLUDE_COPY_FILE@ if (exception != null)
  89. @INCLUDE_COPY_FILE@ throw exception;
  90. @INCLUDE_COPY_FILE@ }
  91. @INCLUDE_COPY_FILE@ }
  92. }