diff --git a/android/app/CMakeLists.txt b/android/app/CMakeLists.txt
index 375ea7d..af7718e 100644
--- a/android/app/CMakeLists.txt
+++ b/android/app/CMakeLists.txt
@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.2)
-add_library(chiaki-jni SHARED src/main/cpp/chiaki-jni.c)
+add_library(chiaki-jni SHARED
+ src/main/cpp/chiaki-jni.c
+ src/main/cpp/video-decoder.h
+ src/main/cpp/video-decoder.c)
target_link_libraries(chiaki-jni chiaki-lib)
find_library(ANDROID_LIB_LOG log)
diff --git a/android/app/src/main/cpp/chiaki-jni.c b/android/app/src/main/cpp/chiaki-jni.c
index d9816f0..f0ebbb4 100644
--- a/android/app/src/main/cpp/chiaki-jni.c
+++ b/android/app/src/main/cpp/chiaki-jni.c
@@ -1,5 +1,22 @@
+/*
+ * This file is part of Chiaki.
+ *
+ * Chiaki is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chiaki is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Chiaki. If not, see .
+ */
#include
+
#include
#include
@@ -8,6 +25,8 @@
#include
+#include "video-decoder.h"
+
#define LOG_TAG "Chiaki"
#define JNI_VERSION JNI_VERSION_1_6
@@ -85,6 +104,8 @@ typedef struct android_chiaki_session_t
jclass java_session_class;
jmethodID java_session_event_login_pin_request_meth;
jmethodID java_session_event_quit_meth;
+
+ AndroidChiakiVideoDecoder video_decoder;
} AndroidChiakiSession;
static JNIEnv *attach_thread_jni()
@@ -190,23 +211,28 @@ JNIEXPORT void JNICALL Java_com_metallic_chiaki_lib_ChiakiNative_sessionCreate(J
err = CHIAKI_ERR_MEMORY;
goto beach;
}
-
- err = chiaki_session_init(&session->session, &connect_info, &global_log);
-
+ memset(session, 0, sizeof(AndroidChiakiSession));
+ err = android_chiaki_video_decoder_init(&session->video_decoder, &global_log);
if(err != CHIAKI_ERR_SUCCESS)
{
- session->java_session = NULL;
+ free(session);
+ session = NULL;
goto beach;
}
+ err = chiaki_session_init(&session->session, &connect_info, &global_log);
+ if(err != CHIAKI_ERR_SUCCESS)
+ goto beach;
+
session->java_session = E->NewGlobalRef(env, java_session);
session->java_session_class = E->GetObjectClass(env, session->java_session);
session->java_session_event_login_pin_request_meth = E->GetMethodID(env, session->java_session_class, "eventLoginPinRequest", "(Z)V");
session->java_session_event_quit_meth = E->GetMethodID(env, session->java_session_class, "eventQuit", "(ILjava/lang/String;)V");
chiaki_session_set_event_cb(&session->session, android_chiaki_event_cb, session);
+ chiaki_session_set_video_sample_cb(&session->session, android_chiaki_video_decoder_video_sample, &session->video_decoder);
- beach:
+beach:
free(host_str);
E->SetIntField(env, result, E->GetFieldID(env, result_class, "errorCode", "I"), (jint)err);
E->SetLongField(env, result, E->GetFieldID(env, result_class, "sessionPtr", "J"), (jlong)session);
@@ -220,6 +246,7 @@ JNIEXPORT void JNICALL Java_com_metallic_chiaki_lib_ChiakiNative_sessionFree(JNI
return;
chiaki_session_fini(&session->session);
free(session);
+ android_chiaki_video_decoder_fini(&session->video_decoder);
E->DeleteGlobalRef(env, session->java_session);
}
diff --git a/android/app/src/main/cpp/video-decoder.c b/android/app/src/main/cpp/video-decoder.c
new file mode 100644
index 0000000..47c3be5
--- /dev/null
+++ b/android/app/src/main/cpp/video-decoder.c
@@ -0,0 +1,38 @@
+/*
+ * This file is part of Chiaki.
+ *
+ * Chiaki is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chiaki is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Chiaki. If not, see .
+ */
+
+#include "video-decoder.h"
+
+#include
+
+ChiakiErrorCode android_chiaki_video_decoder_init(AndroidChiakiVideoDecoder *decoder, ChiakiLog *log)
+{
+ decoder->log = log;
+ decoder->video_codec = NULL;
+ return chiaki_mutex_init(&decoder->mutex, false);
+}
+
+void android_chiaki_video_decoder_fini(AndroidChiakiVideoDecoder *decoder)
+{
+ chiaki_mutex_fini(&decoder->mutex);
+}
+
+void android_chiaki_video_decoder_video_sample(uint8_t *buf, size_t buf_size, void *user)
+{
+ AndroidChiakiVideoDecoder *decoder = user;
+ CHIAKI_LOGD(decoder->log, "Got video sample of size %zu", buf_size);
+}
\ No newline at end of file
diff --git a/android/app/src/main/cpp/video-decoder.h b/android/app/src/main/cpp/video-decoder.h
new file mode 100644
index 0000000..29ab4bf
--- /dev/null
+++ b/android/app/src/main/cpp/video-decoder.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of Chiaki.
+ *
+ * Chiaki is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chiaki is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Chiaki. If not, see .
+ */
+
+#ifndef CHIAKI_JNI_VIDEO_DECODER_H
+#define CHIAKI_JNI_VIDEO_DECODER_H
+
+#include
+#include
+
+typedef struct AMediaCodec AMediaCodec;
+
+typedef struct android_chiaki_video_decoder_t
+{
+ ChiakiLog *log;
+ ChiakiMutex mutex;
+ AMediaCodec *video_codec;
+} AndroidChiakiVideoDecoder;
+
+ChiakiErrorCode android_chiaki_video_decoder_init(AndroidChiakiVideoDecoder *decoder, ChiakiLog *log);
+void android_chiaki_video_decoder_fini(AndroidChiakiVideoDecoder *decoder);
+void android_chiaki_video_decoder_video_sample(uint8_t *buf, size_t buf_size, void *user);
+
+#endif
\ No newline at end of file