Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion playkit/src/main/java/com/kaltura/playkit/PKLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class PKLog {

@NonNull
public final String tag;
private int level = VERBOSE;
private int level;

public enum Level {
verbose(VERBOSE), debug(DEBUG), info(INFO), warn(WARN), error(ERROR), off(Integer.MAX_VALUE);
Expand Down Expand Up @@ -103,6 +103,9 @@ private PKLog(@NonNull String tag) {
return new PKLog(tag);
}

public boolean isLoggable(Level level) {
return Log.isLoggable(tag, level.value);
}

// VERBOSE

Expand Down
12 changes: 9 additions & 3 deletions playkit/src/main/java/com/kaltura/playkit/PlayKitManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import android.content.Context;
import androidx.annotation.Nullable;

import com.google.gson.Gson;
import com.kaltura.playkit.player.MediaSupport;
import com.kaltura.playkit.profiler.PlayKitProfiler;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -54,7 +56,6 @@ static PKPlugin createPlugin(String name) {
}

public static Player loadPlayer(Context context, @Nullable PKPluginConfigs pluginConfigs, MessageBus messageBus) {

MediaSupport.initializeDrm(context, null);

if (shouldSendDeviceCapabilitiesReport) {
Expand All @@ -67,13 +68,18 @@ public static Player loadPlayer(Context context, @Nullable PKPluginConfigs plugi
}

public static Player loadPlayer(Context context, @Nullable PKPluginConfigs pluginConfigs) {

return loadPlayer(context, pluginConfigs, null);
}


public static void disableDeviceCapabilitiesReport() {
shouldSendDeviceCapabilitiesReport = false;
}

public static final class ProfilerConfig {
public String postURL;
public float sendPercentage;

private ProfilerConfig() {}
}
}

81 changes: 79 additions & 2 deletions playkit/src/main/java/com/kaltura/playkit/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import androidx.annotation.NonNull;

import android.telephony.TelephonyManager;
import android.util.Base64;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;

import java.io.BufferedInputStream;
Expand All @@ -45,6 +48,7 @@
import static android.content.Context.UI_MODE_SERVICE;
import static com.kaltura.playkit.utils.Consts.HTTP_METHOD_GET;
import static com.kaltura.playkit.utils.Consts.HTTP_METHOD_POST;
import static com.kaltura.playkit.utils.Consts.MILLISECONDS_MULTIPLIER_FLOAT;

/**
* @hide
Expand Down Expand Up @@ -293,4 +297,77 @@ public static String getDeviceType(Context context) {
}
return deviceType;
}

public static class GsonObject {
private final JsonObject jo = new JsonObject();

public JsonObject jsonObject() {
return jo;
}

public GsonObject add(String key, String value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, Number value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, long value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, float value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, boolean value) {
jo.addProperty(key, value);
return this;
}

public GsonObject add(String key, Throwable value) {
jo.addProperty(key, "" + value);
return this;
}

public GsonObject add(String key, JsonElement value) {
jo.add(key, value);
return this;
}

public GsonObject add(String key, @Nullable GsonObject value) {
jo.add(key, value != null ? value.jo : null);
return this;
}

public GsonObject addAll(@Nullable JsonObject otherJo) {
if (otherJo != null) {
for (Map.Entry<String, JsonElement> entry : otherJo.entrySet()) {
jo.add(entry.getKey(), entry.getValue());
}
}
return this;
}

public GsonObject addAll(@Nullable GsonObject otherGo) {
if (otherGo != null) {
for (Map.Entry<String, JsonElement> entry : otherGo.jo.entrySet()) {
jo.add(entry.getKey(), entry.getValue());
}
}
return this;
}

public GsonObject addTime(String key, long millis) {
jo.addProperty(key, millis / MILLISECONDS_MULTIPLIER_FLOAT);
return this;
}

public void end() {}
}
}
18 changes: 18 additions & 0 deletions playkit/src/main/java/com/kaltura/playkit/player/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import com.kaltura.android.exoplayer2.analytics.AnalyticsListener;
import com.kaltura.playkit.PKMediaConfig;
import com.kaltura.playkit.Utils;
import com.kaltura.playkit.profiler.PlayKitProfiler;

import okhttp3.EventListener;

Expand All @@ -28,4 +30,20 @@ public void onDurationChanged(long duration) {/*NOOP*/}

public void onApplicationPaused() {/*NOOP*/}
public void onApplicationResumed() {/*NOOP*/}

public static class Event extends Utils.GsonObject {

private final PlayKitProfiler profiler;

public Event(PlayKitProfiler profiler, String name) {
this.profiler = profiler;
add("_ts", profiler.timestamp());
add("_name", name);
}

@Override
public void end() {
profiler.append(jsonObject());
}
}
}
Loading