Commit 3d3a9e05 authored by Geoffrey Métais's avatar Geoffrey Métais

LibVLC: Implement record event

parent 16fba4e7
......@@ -47,6 +47,7 @@ static const libvlc_event_type_t mp_events[] = {
libvlc_MediaPlayerSeekableChanged,
libvlc_MediaPlayerPausableChanged,
libvlc_MediaPlayerLengthChanged,
libvlc_MediaPlayerRecordChanged,
-1,
};
......@@ -109,6 +110,10 @@ MediaPlayer_event_cb(vlcjni_object *p_obj, const libvlc_event_t *p_ev,
case libvlc_MediaPlayerLengthChanged:
p_java_event->arg1 = p_ev->u.media_player_length_changed.new_length;
break;
case libvlc_MediaPlayerRecordChanged:
p_java_event->arg1 = p_ev->u.media_player_record_changed.recording;
p_java_event->argc1 = p_ev->u.media_player_record_changed.file_path;
break;
}
p_java_event->type = p_ev->type;
return true;
......
......@@ -178,25 +178,29 @@ VLCJniObject_eventCallback(const libvlc_event_t *ev, void *data)
assert(p_obj->p_libvlc);
java_event jevent = { -1, 0, 0, 0.0 };
java_event jevent = { -1, 0, 0, 0.0, NULL };
if (!p_obj->p_owner->pf_event_cb(p_obj, ev, &jevent))
if (!(env = jni_get_env(THREAD_NAME)))
return;
if (!(env = jni_get_env(THREAD_NAME)))
if (!p_obj->p_owner->pf_event_cb(p_obj, ev, &jevent))
return;
jstring string = jevent.argc1 ? (*env)->NewStringUTF(env, jevent.argc1) : NULL;
if (p_obj->p_owner->weak)
(*env)->CallVoidMethod(env, p_obj->p_owner->weak,
fields.VLCObject.dispatchEventFromNativeID,
jevent.type, jevent.arg1, jevent.arg2,
jevent.argf1);
jevent.argf1, string);
else
(*env)->CallStaticVoidMethod(env, fields.VLCObject.clazz,
fields.VLCObject.dispatchEventFromWeakNativeID,
p_obj->p_owner->weakCompat,
jevent.type, jevent.arg1, jevent.arg2,
jevent.argf1);
jevent.argf1, string);
if (jevent.argc1)
(*env)->ReleaseStringUTFChars(env, string, jevent.argc1);
}
void
......
......@@ -66,6 +66,7 @@ struct java_event
jlong arg1;
jlong arg2;
jfloat argf1;
const char* argc1;
};
/* event manager callback dispatched to native struct implementing a
......
......@@ -206,7 +206,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
GET_ID(GetMethodID,
fields.VLCObject.dispatchEventFromNativeID,
fields.VLCObject.clazz,
"dispatchEventFromNative", "(IJJF)V");
"dispatchEventFromNative", "(IJJFLjava/lang/String;)V");
if (fields.SDK_INT <= 13)
{
......@@ -218,7 +218,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
GET_ID(GetStaticMethodID,
fields.VLCObject.dispatchEventFromWeakNativeID,
fields.VLCObject.clazz,
"dispatchEventFromWeakNative", "(Ljava/lang/Object;IJJF)V");
"dispatchEventFromWeakNative", "(Ljava/lang/Object;IJJFLjava/lang/String;)V");
} else
{
fields.VLCObject.getWeakReferenceID = NULL;
......
......@@ -27,6 +27,8 @@ import org.videolan.libvlc.util.HWDecoderUtil;
import java.util.ArrayList;
import androidx.annotation.Nullable;
@SuppressWarnings("unused, JniMissingFunction")
public class LibVLC extends VLCObject<LibVLC.Event> {
private static final String TAG = "VLC/LibVLC";
......@@ -103,7 +105,7 @@ public class LibVLC extends VLCObject<LibVLC.Event> {
public native String changeset();
@Override
protected Event onEventNative(int eventType, long arg1, long arg2, float argf1) {
protected Event onEventNative(int eventType, long arg1, long arg2, float argf1, @Nullable String args1) {
return null;
}
......
......@@ -22,7 +22,6 @@ package org.videolan.libvlc;
import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import androidx.annotation.Nullable;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.libvlc.util.HWDecoderUtil;
......@@ -30,6 +29,8 @@ import org.videolan.libvlc.util.VLCUtil;
import java.io.FileDescriptor;
import androidx.annotation.Nullable;
@SuppressWarnings("unused, JniMissingFunction")
public class Media extends VLCObject<Media.Event> {
private final static String TAG = "LibVLC/Media";
......@@ -492,7 +493,7 @@ public class Media extends VLCObject<Media.Event> {
}
@Override
protected synchronized Event onEventNative(int eventType, long arg1, long arg2, float argf1) {
protected synchronized Event onEventNative(int eventType, long arg1, long arg2, float argf1, @Nullable String args1) {
switch (eventType) {
case Event.MetaChanged:
// either we update all metas (if first call) or we update a specific meta
......
......@@ -106,7 +106,7 @@ public class MediaDiscoverer extends VLCObject<MediaDiscoverer.Event> {
}
@Override
protected Event onEventNative(int eventType, long arg1, long arg2, float argf1) {
protected Event onEventNative(int eventType, long arg1, long arg2, float argf1, @Nullable String args1) {
switch (eventType) {
case Event.Started:
case Event.Ended:
......
......@@ -23,6 +23,8 @@ package org.videolan.libvlc;
import android.os.Handler;
import android.util.SparseArray;
import androidx.annotation.Nullable;
@SuppressWarnings("unused, JniMissingFunction")
public class MediaList extends VLCObject<MediaList.Event> {
private final static String TAG = "LibVLC/MediaList";
......@@ -129,7 +131,7 @@ public class MediaList extends VLCObject<MediaList.Event> {
}
@Override
protected synchronized Event onEventNative(int eventType, long arg1, long arg2, float argf1) {
protected synchronized Event onEventNative(int eventType, long arg1, long arg2, float argf1, @Nullable String args1) {
if (mLocked)
throw new IllegalStateException("already locked from event callback");
mLocked = true;
......
......@@ -75,6 +75,14 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
public static final int ESAdded = 0x114;
public static final int ESDeleted = 0x115;
public static final int ESSelected = 0x116;
// public static final int Corked = 0x117;
// public static final int Uncorked = 0x118;
// public static final int Muted = 0x119;
// public static final int Unmuted = 0x11a;
// public static final int AudioVolume = 0x11b;
// public static final int AudioDevice = 0x11c;
// public static final int ChapterChanged = 0x11d;
public static final int RecordChanged = 0x11e;
protected Event(int type) {
super(type);
......@@ -91,6 +99,10 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
super(type, argf);
}
protected Event(int type, long arg1, @Nullable String args1) {
super(type, arg1, args1);
}
public long getTimeChanged() {
return arg1;
}
......@@ -120,6 +132,13 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
public float getBuffering() {
return argf1;
}
public boolean getRecording() {
return arg1 != 0;
}
@Nullable
public String getRecordPath() {
return args1;
}
}
public interface EventListener extends VLCEvent.Listener<MediaPlayer.Event> {}
......@@ -1307,7 +1326,7 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
}
@Override
protected synchronized Event onEventNative(int eventType, long arg1, long arg2, float argf1) {
protected synchronized Event onEventNative(int eventType, long arg1, long arg2, float argf1, @Nullable String args1) {
switch (eventType) {
case Event.MediaChanged:
case Event.Stopped:
......@@ -1338,6 +1357,8 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
case Event.SeekableChanged:
case Event.PausableChanged:
return new Event(eventType, arg1);
case Event.RecordChanged:
return new Event(eventType, arg1, args1);
}
return null;
}
......
......@@ -23,6 +23,7 @@ package org.videolan.libvlc;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.Nullable;
import androidx.collection.LongSparseArray;
public class RendererDiscoverer extends VLCObject<RendererDiscoverer.Event> {
......@@ -111,7 +112,7 @@ public class RendererDiscoverer extends VLCObject<RendererDiscoverer.Event> {
}
@Override
protected Event onEventNative(int eventType, long arg1, long arg2, float argf1) {
protected Event onEventNative(int eventType, long arg1, long arg2, float argf1, @Nullable String args1) {
switch (eventType) {
case Event.ItemAdded:
return new Event(eventType, arg1, insertItemFromEvent(arg1));
......
package org.videolan.libvlc;
import androidx.annotation.Nullable;
@SuppressWarnings("unused, JniMissingFunction")
public class RendererItem extends VLCObject<RendererItem.Event> {
......@@ -31,7 +33,7 @@ public class RendererItem extends VLCObject<RendererItem.Event> {
}
@Override
protected Event onEventNative(int eventType, long arg1, long arg2, float argf1) {
protected Event onEventNative(int eventType, long arg1, long arg2, float argf1, @Nullable String args1) {
return new Event(eventType);
}
......
......@@ -20,33 +20,47 @@
package org.videolan.libvlc;
import androidx.annotation.Nullable;
public abstract class VLCEvent {
public final int type;
protected final long arg1;
protected final long arg2;
protected final float argf1;
protected final String args1;
VLCEvent(int type) {
this.type = type;
this.arg1 = this.arg2 = 0;
this.argf1 = 0.0f;
this.args1 = null;
}
VLCEvent(int type, long arg1) {
this.type = type;
this.arg1 = arg1;
this.arg2 = 0;
this.argf1 = 0.0f;
this.args1 = null;
}
VLCEvent(int type, long arg1, long arg2) {
this.type = type;
this.arg1 = arg1;
this.arg2 = arg2;
this.argf1 = 0.0f;
this.args1 = null;
}
VLCEvent(int type, float argf) {
this.type = type;
this.arg1 = this.arg2 = 0;
this.argf1 = argf;
this.args1 = null;
}
VLCEvent(int type, long arg1, @Nullable String args1) {
this.type = type;
this.arg1 = arg1;
this.arg2 = 0;
this.argf1 = 0.0f;
this.args1 = args1;
}
void release() {
......
......@@ -25,6 +25,8 @@ import android.os.Looper;
import java.lang.ref.WeakReference;
import androidx.annotation.Nullable;
@SuppressWarnings("JniMissingFunction")
abstract class VLCObject<T extends VLCEvent> {
private VLCEvent.Listener<T> mEventListener = null;
......@@ -131,7 +133,7 @@ abstract class VLCObject<T extends VLCEvent> {
* @param argf1 first float argument
* @return Event that will be dispatched to listeners
*/
protected abstract T onEventNative(int eventType, long arg1, long arg2, float argf1);
protected abstract T onEventNative(int eventType, long arg1, long arg2, float argf1, String args1);
/**
* Called when native object is released (refcount is 0).
......@@ -143,10 +145,10 @@ abstract class VLCObject<T extends VLCEvent> {
/* JNI */
@SuppressWarnings("unused") /* Used from JNI */
private long mInstance = 0;
private synchronized void dispatchEventFromNative(int eventType, long arg1, long arg2, float argf1) {
private synchronized void dispatchEventFromNative(int eventType, long arg1, long arg2, float argf1, @Nullable String args1) {
if (isReleased())
return;
final T event = onEventNative(eventType, arg1, arg2, argf1);
final T event = onEventNative(eventType, arg1, arg2, argf1, args1);
class EventRunnable implements Runnable {
private final VLCEvent.Listener<T> listener;
......@@ -175,9 +177,9 @@ abstract class VLCObject<T extends VLCEvent> {
}
@SuppressWarnings("unchecked,unused") /* Used from JNI */
private static void dispatchEventFromWeakNative(Object weak, int eventType, long arg1, long arg2,
float argf1) {
float argf1, @Nullable String args1) {
VLCObject obj = ((WeakReference<VLCObject>)weak).get();
if (obj != null)
obj.dispatchEventFromNative(eventType, arg1, arg2, argf1);
obj.dispatchEventFromNative(eventType, arg1, arg2, argf1, args1);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment