diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index fcf6e6a9..73e1c3c5 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -389,7 +389,7 @@ Java_com_xypower_mpapp_MicroPhotoService_init( extern "C" JNIEXPORT jboolean JNICALL Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto( JNIEnv* env, - jobject pThis, jlong handler, jint channel, jint preset, jlong scheduleTime, jboolean photoOrVideo) { + jobject pThis, jlong handler, jint channel, jint preset, jlong scheduleTime, jstring url, jint mediaType) { if (channel < 0 || channel > 0xFFFF) { @@ -401,12 +401,27 @@ Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto( return JNI_FALSE; } - unsigned char type = photoOrVideo ? 0 : 1; + uint8_t type = (uint8_t)mediaType; // std::thread th(&Runner::RequestCapture, pTerminal, (unsigned int)channel, (unsigned int)preset, type, (uint64_t)scheduleTime, 0, true); // th.detach(); if (channel < 0x100) { - pTerminal->RequestCapture((uint32_t)channel, (unsigned int)preset, type, (uint64_t)scheduleTime, 0, true); + if (mediaType == XY_MEDIA_TYPE_PHOTO || mediaType == XY_MEDIA_TYPE_VIDEO) + { + pTerminal->RequestCapture((uint32_t)channel, (unsigned int)preset, type, (uint64_t)scheduleTime, 0, true); + } + else if (mediaType == XY_MEDIA_TYPE_STREAM) + { + // virtual bool StartStream(unsigned char channel, unsigned char preset, const std::string& url, uint32_t* photoId = NULL); + // virtual bool StopStream(unsigned char channel, unsigned char preset, uint32_t photoId); + uint32_t photoId = 0; + std::string urlStr = jstring2string(env, url); + pTerminal->StartStream(channel, preset, urlStr, &photoId); + } + else if (mediaType == XY_MEDIA_TYPE_STREAM_OFF) + { + pTerminal->StopStream(channel, preset, 0); + } } else { @@ -418,7 +433,6 @@ Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto( return JNI_TRUE; } - extern "C" JNIEXPORT jlong JNICALL Java_com_xypower_mpapp_MicroPhotoService_takePhoto( JNIEnv* env, diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 0e3a29ac..3ea2b50a 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -98,10 +98,17 @@ public class MicroPhotoService extends Service { public static final int MSG_WHAT_LOG = 10; - public final static int MSG_WHAT_SENDING_HB = 40; - public final static int MSG_WHAT_MAX = 1000; + public final static int MEDIA_TYPE_PHOTO = 0; + public final static int MEDIA_TYPE_VIDEO = 1; + + public final static int MEDIA_TYPE_LOG = 2; + + public final static int MEDIA_TYPE_STREAMING = 0x10; + public final static int MEDIA_TYPE_STREAMING_OFF = 0x11; + + public final static int BROADCAST_REQUEST_CODE_HEARTBEAT = 1; public final static int BROADCAST_REQUEST_CODE_TAKING_PHOTO = 2; public final static int BROADCAST_REQUEST_CODE_GPS = 3; @@ -127,14 +134,15 @@ public class MicroPhotoService extends Service { private static final String EXTRA_PARAM_CHANNEL = "Channel"; private static final String EXTRA_PARAM_PRESET = "Preset"; private static final String EXTRA_PARAM_PHOTO_OR_VIDEO = "PhotoOrVideo"; + + private static final String EXTRA_PARAM_MEDIA_TYPE = "mediaType"; + + private static final String EXTRA_PARAM_URL = "url"; private static final String EXTRA_PARAM_SCHEDULES = "Schedules"; private static final String EXTRA_PARAM_SCHEDULE = "Schedule_"; private static final String EXTRA_PARAM_TAKING_TIME = "TakingTime"; private static final String EXTRA_PARAM_TIME = "Time"; - // private static final String EXTRA_PARAM_TIMER_UID = "TimerUid"; - // private static final String EXTRA_PARAM_TIMEOUT = "Timeout"; - // private static final String EXTRA_PARAM_TIMES = "Times"; - // private static final String EXTRA_PARAM_ELASPED_TIMES = "ElapsedTimes"; + private static final String FOREGROUND_CHANNEL_ID = "fg_mpapp"; public static class STATE_SERVICE { public static final int CONNECTED = 10; @@ -513,7 +521,7 @@ public class MicroPhotoService extends Service { int channel = (int) ((val & 0xFFFF000L) >> 12); int preset = (int) ((val & 0xFF0L) >> 4); - boolean photoOrVideo = ((val & 0xFL) == 0); + int mediaType = (int)(val & 0xFL); if (channel >= 256) { @@ -523,7 +531,7 @@ public class MicroPhotoService extends Service { { infoLog("IMG Timer Fired: CH=" + channel + " PR=" + preset); } - mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, ts, photoOrVideo); + mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, ts, null, mediaType); } } @@ -536,12 +544,20 @@ public class MicroPhotoService extends Service { } else if (TextUtils.equals(ACTION_TAKE_PHOTO_MANUALLY, action)) { int channel = intent.getIntExtra(EXTRA_PARAM_CHANNEL, 0); int preset = intent.getIntExtra(EXTRA_PARAM_PRESET, 0xFF); + String url = intent.getStringExtra(EXTRA_PARAM_URL); // long ts = intent.getLongExtra(EXTRA_PARAM_TIME, 0); - boolean photoOrVideo = intent.getBooleanExtra(EXTRA_PARAM_PHOTO_OR_VIDEO, true); + + int mediaType = 0; + if (intent.hasExtra(EXTRA_PARAM_MEDIA_TYPE)) { + mediaType = intent.getIntExtra(EXTRA_PARAM_MEDIA_TYPE, 0); + } else if (intent.hasExtra(EXTRA_PARAM_PHOTO_OR_VIDEO)) { + boolean photoOrVideo = intent.getBooleanExtra(EXTRA_PARAM_PHOTO_OR_VIDEO, true); + mediaType = photoOrVideo ? 0 : 1; + } long ts = System.currentTimeMillis() / 1000; Log.i(TAG, "Take Photo CH=" + channel + " PR=" + preset + " Mannually"); - mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, 0, photoOrVideo); + mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, 0, url, mediaType); } else if (TextUtils.equals(ACTION_UPDATE_CONFIGS, action)) { int restart = intent.getIntExtra("restart", 0); Log.i(TAG, "UPD CFG Fired ACTION=" + action + " restart=" + restart); @@ -1605,7 +1621,7 @@ cellSignalStrengthGsm.getDbm(); protected native long[] getPhotoTimeData(long handler, long startTime); protected native long[] getPhotoTimeData2(long handler); // protected native long[] getNextScheduleItem(long handler); - protected native boolean notifyToTakePhoto(long handler, int channel, int preset, long scheduleTime, boolean photoOrVideo); + protected native boolean notifyToTakePhoto(long handler, int channel, int preset, long scheduleTime, String url, int mediaType); protected native boolean sendHeartbeat(long handler, int signalLevel); protected native boolean reloadConfigs(long handler);