<commit_before>#include <jni.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <locale.h>

#include <mpv/client.h>
#include <mpv/opengl_cb.h>

#include <EGL/egl.h>

extern "C" {
    #include <libavcodec/jni.h>
}

#include "main.h"

#define ARRAYLEN(a) (sizeof(a)/sizeof(a[0]))
#define jname(name) Java_is_xyz_mpv_MPVLib_##name
#define jfunc(name, type) JNIEXPORT type JNICALL jname(name)
#define jvoidfunc(name)  jfunc(name, void)

extern "C" {
    jvoidfunc(prepareEnv) (JNIEnv* env, jobject obj);
    jvoidfunc(createLibmpvContext) (JNIEnv* env, jobject obj);
    jvoidfunc(initializeLibmpv) (JNIEnv* env, jobject obj);

    jvoidfunc(initgl) (JNIEnv* env, jobject obj);

    jvoidfunc(setLibmpvOptions) (JNIEnv* env, jobject obj);

    jvoidfunc(destroy) (JNIEnv* env, jobject obj);
    jvoidfunc(destroygl) (JNIEnv* env, jobject obj);

    jvoidfunc(command) (JNIEnv* env, jobject obj, jobjectArray jarray);
    jvoidfunc(resize) (JNIEnv* env, jobject obj, jint width, jint height);
    jvoidfunc(draw) (JNIEnv* env, jobject obj);
    jvoidfunc(step) (JNIEnv* env, jobject obj);
    jvoidfunc(play) (JNIEnv *env, jobject obj);
    jvoidfunc(pause) (JNIEnv *env, jobject obj);
    jvoidfunc(touch_1down) (JNIEnv* env, jobject obj, jint x, jint y);
    jvoidfunc(touch_1move) (JNIEnv* env, jobject obj, jint x, jint y);
    jvoidfunc(touch_1up) (JNIEnv* env, jobject obj, jint x, jint y);
    jvoidfunc(setconfigdir) (JNIEnv* env, jobject obj, jstring path);

    jfunc(getpropertyint, jint) (JNIEnv *env, jobject obj, jstring property);
    jvoidfunc(setpropertyint) (JNIEnv *env, jobject obj, jstring property, jint value);
    jfunc(getpropertyboolean, jboolean) (JNIEnv *env, jobject obj, jstring property);
    jvoidfunc(observeProperty) (JNIEnv *env, jobject obj, jstring property, jint format);
};

mpv_handle *mpv;
mpv_opengl_cb_context *mpv_gl;

int g_width, g_height;
char g_config_dir[2048];
char **g_command_queue[16] = {NULL};

static void die(const char *msg)
{
    ALOGE("%s", msg);
    exit(1);
}

static void *get_proc_address_mpv(void *fn_ctx, const char *name)
{
    return (void*)eglGetProcAddress(name);
}

jvoidfunc(prepareEnv) (JNIEnv* env, jobject obj) {
    setlocale(LC_NUMERIC, "C");

    JavaVM* vm = NULL;

    if (!env->GetJavaVM(&vm) && vm) {
        av_jni_set_java_vm(vm, NULL);
    }
}

jvoidfunc(createLibmpvContext) (JNIEnv* env, jobject obj) {
    if (mpv)
        die("Called createLibmpvContext when libmpv context already available!");

    mpv = mpv_create();
    if (!mpv)
        die("context init failed");
}

jvoidfunc(initializeLibmpv) (JNIEnv* env, jobject obj) {
    if (!mpv)
        die("Tried to call initializeLibmpv without context!");

    mpv_set_option_string(mpv, "config", "yes");
    mpv_set_option_string(mpv, "config-dir", g_config_dir);

    int osc = 1;
    mpv_set_option(mpv, "osc", MPV_FORMAT_FLAG, &osc);
    mpv_set_option_string(mpv, "script-opts", "osc-scalewindowed=1.5");

    if (mpv_initialize(mpv) < 0)
        die("mpv init failed");
}

jvoidfunc(setLibmpvOptions) (JNIEnv* env, jobject obj) {
    if (!mpv)
        die("setLibmpvOptions: mpv is not initialized");

    mpv_request_log_messages(mpv, "v");

    mpv_set_option_string(mpv, "hwdec", "mediacodec");<commit_msg>jni/main: disable OSC (for now)<commit_after>#include <jni.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <locale.h>

#include <mpv/client.h>
#include <mpv/opengl_cb.h>

#include <EGL/egl.h>

extern "C" {
    #include <libavcodec/jni.h>
}

#include "main.h"

#define ARRAYLEN(a) (sizeof(a)/sizeof(a[0]))
#define jname(name) Java_is_xyz_mpv_MPVLib_##name
#define jfunc(name, type) JNIEXPORT type JNICALL jname(name)
#define jvoidfunc(name)  jfunc(name, void)

extern "C" {
    jvoidfunc(prepareEnv) (JNIEnv* env, jobject obj);
    jvoidfunc(createLibmpvContext) (JNIEnv* env, jobject obj);
    jvoidfunc(initializeLibmpv) (JNIEnv* env, jobject obj);

    jvoidfunc(initgl) (JNIEnv* env, jobject obj);

    jvoidfunc(setLibmpvOptions) (JNIEnv* env, jobject obj);

    jvoidfunc(destroy) (JNIEnv* env, jobject obj);
    jvoidfunc(destroygl) (JNIEnv* env, jobject obj);

    jvoidfunc(command) (JNIEnv* env, jobject obj, jobjectArray jarray);
    jvoidfunc(resize) (JNIEnv* env, jobject obj, jint width, jint height);
    jvoidfunc(draw) (JNIEnv* env, jobject obj);
    jvoidfunc(step) (JNIEnv* env, jobject obj);
    jvoidfunc(play) (JNIEnv *env, jobject obj);
    jvoidfunc(pause) (JNIEnv *env, jobject obj);
    jvoidfunc(touch_1down) (JNIEnv* env, jobject obj, jint x, jint y);
    jvoidfunc(touch_1move) (JNIEnv* env, jobject obj, jint x, jint y);
    jvoidfunc(touch_1up) (JNIEnv* env, jobject obj, jint x, jint y);
    jvoidfunc(setconfigdir) (JNIEnv* env, jobject obj, jstring path);

    jfunc(getpropertyint, jint) (JNIEnv *env, jobject obj, jstring property);
    jvoidfunc(setpropertyint) (JNIEnv *env, jobject obj, jstring property, jint value);
    jfunc(getpropertyboolean, jboolean) (JNIEnv *env, jobject obj, jstring property);
    jvoidfunc(observeProperty) (JNIEnv *env, jobject obj, jstring property, jint format);
};

mpv_handle *mpv;
mpv_opengl_cb_context *mpv_gl;

int g_width, g_height;
char g_config_dir[2048];
char **g_command_queue[16] = {NULL};

static void die(const char *msg)
{
    ALOGE("%s", msg);
    exit(1);
}

static void *get_proc_address_mpv(void *fn_ctx, const char *name)
{
    return (void*)eglGetProcAddress(name);
}

jvoidfunc(prepareEnv) (JNIEnv* env, jobject obj) {
    setlocale(LC_NUMERIC, "C");

    JavaVM* vm = NULL;

    if (!env->GetJavaVM(&vm) && vm) {
        av_jni_set_java_vm(vm, NULL);
    }
}

jvoidfunc(createLibmpvContext) (JNIEnv* env, jobject obj) {
    if (mpv)
        die("Called createLibmpvContext when libmpv context already available!");

    mpv = mpv_create();
    if (!mpv)
        die("context init failed");
}

jvoidfunc(initializeLibmpv) (JNIEnv* env, jobject obj) {
    if (!mpv)
        die("Tried to call initializeLibmpv without context!");

    mpv_set_option_string(mpv, "config", "yes");
    mpv_set_option_string(mpv, "config-dir", g_config_dir);

    int osc = 0;
    mpv_set_option(mpv, "osc", MPV_FORMAT_FLAG, &osc);
    mpv_set_option_string(mpv, "script-opts", "osc-scalewindowed=1.5");

    if (mpv_initialize(mpv) < 0)
        die("mpv init failed");
}

jvoidfunc(setLibmpvOptions) (JNIEnv* env, jobject obj) {
    if (!mpv)
        die("setLibmpvOptions: mpv is not initialized");

    mpv_request_log_messages(mpv, "v");

    mpv_set_option_string(mpv, "hwdec", "mediacodec");
{'fraction_non_alphanumeric': 0.1396767307105825, 'fraction_numerical': 0.004574565416285453, 'mean_word_length': 4.59641638225256, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5076967', 'n_tokens_mistral': 2614, 'n_tokens_neox': 2570, 'n_words': 597}