1 /* 2 * Copyright (C) 2016 SurroundIO 3 * Author: Martin Kelly <martin@surround.io> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, write to the 17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef __GST_ANDROID_HARDWARE_SENSOR_H__ 22 #define __GST_ANDROID_HARDWARE_SENSOR_H__ 23 24 #include <gst/gst.h> 25 #include <jni.h> 26 27 #include "gstsensors.h" 28 29 G_BEGIN_DECLS 30 31 typedef struct GstAHSensor 32 { 33 /* < private > */ 34 jobject object; 35 } GstAHSensor; 36 37 typedef struct GstAHSensorData 38 { 39 jfloatArray array; 40 gfloat *values; 41 } GstAHSensorData; 42 43 typedef struct GstAHSensorEvent 44 { 45 /* 46 * Note that we don't use the Android event timestamp, as it's not reliable. 47 * See https://code.google.com/p/android/issues/detail?id=7981 for more 48 * details. 49 */ 50 gint32 accuracy; 51 GstAHSensorData data; 52 } GstAHSensorEvent; 53 54 typedef struct GstAHSensorEventListener 55 { 56 /* < private > */ 57 jobject object; 58 59 gboolean registered; 60 } GstAHSensorEventListener; 61 62 typedef struct GstAHSensorManager 63 { 64 /* < private > */ 65 jobject object; 66 } GstAHSensorManager; 67 68 gint gst_android_sensor_type_from_string (const gchar * type_str); 69 70 /* android.hardware.SensorListener onSensorChanged */ 71 typedef void (*GstAHSensorCallback) (jobject sensor_event, gpointer user_data); 72 73 /* android.hardware.SensorListener onAccuracyChanged */ 74 typedef void (*GstAHSAccuracyCallback) (jobject sensor, gint32 accuracy, 75 gpointer user_data); 76 77 gboolean gst_android_hardware_sensor_init (void); 78 void gst_android_hardware_sensor_deinit (void); 79 80 /* 81 * Example usage (excluding error checking): 82 * 83 * GstAHSensorManager *manager = gst_ah_sensor_get_manager (); 84 * GstAHSensor *sensor = 85 * gst_ah_sensor_get_default_sensor (manager, * sensor_type); 86 * GstAHSensorEventListener *listener = 87 * gst_ah_sensor_create_listener * (change_cb, accuracy_cb, self); 88 * gst_ah_sensor_register_listener (manager, listener, sensor, 89 * SensorDelay_SENSOR_DELAY_NORMAL); 90 */ 91 GstAHSensorManager *gst_ah_sensor_get_manager (void); 92 GstAHSensor *gst_ah_sensor_get_default_sensor (GstAHSensorManager * manager, 93 gint32 sensor_type); 94 GstAHSensorEventListener *gst_ah_sensor_create_listener (GstAHSensorCallback 95 sensor_cb, GstAHSAccuracyCallback accuracy_cb, gpointer user_data); 96 gboolean gst_ah_sensor_register_listener (GstAHSensorManager * self, 97 GstAHSensorEventListener * listener, GstAHSensor * sensor, gint32 delay); 98 void gst_ah_sensor_unregister_listener (GstAHSensorManager * self, 99 GstAHSensorEventListener * listener); 100 101 gboolean gst_ah_sensor_populate_event (GstAHSensorEvent * event, 102 jobject event_object, gint size); 103 void gst_ah_sensor_free_sensor_data (GstAHSensorData * data); 104 105 /* 106 * These constants come from the matching SENSOR_DELAY_* TYPE_* constants found 107 * in the Android documentation: 108 * 109 * SENSOR_DELAY_*: 110 * https://developer.android.com/reference/android/hardware/SensorManager.html 111 * 112 * TYPE_*: 113 * https://developer.android.com/reference/android/hardware/Sensor.html 114 * 115 * They are intended to be passed into the registerListener callback for 116 * listener registration. Note that, although these are hardcoded, we also do 117 * paranoid runtime checks during plugin init to verify that the API values 118 * haven't changed. This is unlikely but seems like a good precaution. When 119 * adding values, please keep the two lists in sync. 120 */ 121 enum 122 { 123 AHS_SENSOR_DELAY_FASTEST = 0, 124 AHS_SENSOR_DELAY_GAME = 1, 125 AHS_SENSOR_DELAY_NORMAL = 3, 126 AHS_SENSOR_DELAY_UI = 2 127 }; 128 129 enum 130 { 131 AHS_SENSOR_TYPE_ACCELEROMETER = 0x1, 132 AHS_SENSOR_TYPE_AMBIENT_TEMPERATURE = 0xd, 133 AHS_SENSOR_TYPE_GAME_ROTATION_VECTOR = 0xf, 134 AHS_SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 0x14, 135 AHS_SENSOR_TYPE_GRAVITY = 0x9, 136 AHS_SENSOR_TYPE_GYROSCOPE = 0x4, 137 AHS_SENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 0x10, 138 AHS_SENSOR_TYPE_HEART_RATE = 0x15, 139 AHS_SENSOR_TYPE_LIGHT = 0x5, 140 AHS_SENSOR_TYPE_LINEAR_ACCELERATION = 0xa, 141 AHS_SENSOR_TYPE_MAGNETIC_FIELD = 0x2, 142 AHS_SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 0xe, 143 AHS_SENSOR_TYPE_ORIENTATION = 0x3, 144 AHS_SENSOR_TYPE_PRESSURE = 0x6, 145 AHS_SENSOR_TYPE_PROXIMITY = 0x8, 146 AHS_SENSOR_TYPE_RELATIVE_HUMIDITY = 0xc, 147 AHS_SENSOR_TYPE_ROTATION_VECTOR = 0xb, 148 AHS_SENSOR_TYPE_SIGNIFICANT_MOTION = 0x11, 149 AHS_SENSOR_TYPE_STEP_COUNTER = 0x13, 150 AHS_SENSOR_TYPE_STEP_DETECTOR = 0x12 151 }; 152 153 gsize gst_ah_sensor_get_sensor_data_size (gint sensor_type); 154 155 G_END_DECLS 156 #endif /* __GST_ANDROID_HARDWARE_SENSOR_H__ */ 157