搜书大师 v23.2版本的 MD5 值为:5ee433f6456b6278bd6e80a5d44df55e
以下内容为反编译后的 DataLoaderHelper.java 源代码,内容仅作参考
package com.bykv.vk.component.ttvideo;
import android.content.Context;
import android.text.TextUtils;
import com.bykv.vk.component.ttvideo.log.VideoEventEngineUploader;
import com.bykv.vk.component.ttvideo.mediakit.medialoader.AVMDLDataLoader;
import com.bykv.vk.component.ttvideo.mediakit.medialoader.AVMDLDataLoaderConfigure;
import com.bykv.vk.component.ttvideo.mediakit.medialoader.AVMDLDataLoaderListener;
import com.bykv.vk.component.ttvideo.utils.Error;
import com.bykv.vk.component.ttvideo.utils.TTVideoEngineLog;
import com.flyersoft.source.conf.IntentAction;
import com.lygame.aaa.b41;
import com.lygame.aaa.bf0;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.ReentrantLock;
import org.json.JSONObject;
public class DataLoaderHelper implements AVMDLDataLoaderListener, com.bykv.vk.component.ttvideo.mediakit.medialoader.c {
public static final int DATALOADER_KEY_ENABLE_ALOG = 512;
public static final int DATALOADER_KEY_INT_MAXCACHESIZE = 1;
public static final int DATALOADER_KEY_INT_OPENTIMEOUT = 3;
public static final int DATALOADER_KEY_INT_PARALLEL_NUM = 11;
public static final int DATALOADER_KEY_INT_RWTIMEOUT = 2;
public static final int DATALOADER_KEY_INT_TRYCOUNT = 4;
public static final int DATALOADER_KEY_SET_MDL_PROTOCOL_ENABLE = 1005;
public static final int DATALOADER_KEY_STRING_CACHEDIR = 0;
public static final int IsClose = 1;
public static final int IsPlayTask = 1;
public static final int IsPreloadTask = 2;
public static final int IsStart = 0;
public static final int IsUnknown = 0;
public static final String MDL_PREFIX = "mdl://";
private static final DataLoaderHelper a = new DataLoaderHelper();
private static int b = 0;
private static int c = 0;
private static int d = 0;
private final d f;
private final d g;
private final d h;
private final d i;
private AVMDLDataLoader m;
private VideoEventEngineUploader o;
private boolean q;
private final ConcurrentHashMap<String, c> j = new ConcurrentHashMap<>();
private final HashMap<String, ArrayList<TTVideoEngine>> k = new HashMap<>();
private final ReentrantLock l = new ReentrantLock();
private boolean p = true;
private int r = 0;
private final ReentrantLock s = new ReentrantLock();
private volatile int e = 1;
private AVMDLDataLoaderConfigure n = AVMDLDataLoaderConfigure.getDefaultonfigure();
public class DataLoaderCacheInfo {
public long mMediaSize = 0;
public long mCacheSizeFromZero = 0;
public String mLocalFilePath = null;
public DataLoaderCacheInfo(DataLoaderHelper dataLoaderHelper) {
}
}
public static class DataLoaderTaskProgressInfo {
public String mKey = null;
public String mVideoId = null;
public String mLocalFilePath = null;
public long mMediaSize = 0;
public long mCacheSizeFromZero = 0;
public int mTaskType = 0;
}
public class b {
public String a = null;
public long b = 0;
public PreloaderURLItem c = null;
public boolean d = false;
public List<a> e = new CopyOnWriteArrayList();
public class a {
public String a = null;
public String b = null;
public String[] c = null;
public String d = null;
public long e = 0;
public long f = 0;
public long g = 0;
public long h = 0;
public long i = 0;
public a(b bVar) {
}
}
public b(DataLoaderHelper dataLoaderHelper) {
}
public a a(String str) {
if (this.e.size() > 0) {
for (int i = 0; i < this.e.size(); i++) {
a aVar = this.e.get(i);
if (aVar.a.equals(str)) {
return aVar;
}
}
}
return null;
}
public IPreLoaderItemCallBackListener a() {
PreloaderURLItem preloaderURLItem = this.c;
if (preloaderURLItem == null || preloaderURLItem.getCallBackListener() == null) {
return null;
}
return this.c.getCallBackListener();
}
public void a(int i) {
TTVideoEngineLog.d("DataLoaderHelper", "startMDLPreloadTask _notifyError " + i);
if (a() != null) {
DataLoaderHelper.a();
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount engine callback " + DataLoaderHelper.d + ", KEY_IS_PRELOAD_END_FAIL");
PreLoaderItemCallBackInfo preLoaderItemCallBackInfo = new PreLoaderItemCallBackInfo(3);
preLoaderItemCallBackInfo.preloadError = new Error(Error.DataLoaderPreload, i);
a().preloadItemInfo(preLoaderItemCallBackInfo);
}
}
public void a(String str, long j) {
if (this.e.size() == 0) {
a aVar = new a(this);
aVar.a = str;
aVar.g = j;
this.e.add(aVar);
} else {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] DataLoaderTaskItem setup fail");
}
this.b = j;
}
public a b(String str) {
if (TextUtils.isEmpty(str)) {
return null;
}
a a2 = a(str);
if (a2 != null) {
return a2;
}
a aVar = new a(this);
aVar.a = str;
this.e.add(aVar);
return aVar;
}
}
public class c {
public String a;
public int b = 0;
public List<a> c = null;
public class a {
public String e;
public String a = null;
public long b = 0;
public long c = 0;
public List<C0806a> d = null;
public Error f = null;
public class C0806a {
public long a = 0;
public long b = 0;
public C0806a(a aVar) {
}
}
public a(c cVar) {
}
public long a() {
List<C0806a> list = this.d;
if (list == null || list.size() <= 0) {
return 0L;
}
return this.d.get(r0.size() - 1).b;
}
void a(long j) {
if (this.d == null) {
this.d = new ArrayList();
}
if (this.d.size() == 0) {
this.d.add(new C0806a(this));
}
this.d.get(0).a = 0L;
this.d.get(0).b = j;
}
public boolean b() {
long j = this.c;
long min = j > 0 ? Math.min(j, this.b) : this.b;
List<C0806a> list = this.d;
C0806a c0806a = list != null ? list.get(list.size() - 1) : null;
if (this.f == null) {
return c0806a != null && this.b > 0 && c0806a.a + c0806a.b >= min;
}
return true;
}
}
public c(DataLoaderHelper dataLoaderHelper) {
}
private a a(String str) {
List<a> list;
if (!TextUtils.isEmpty(str) && (list = this.c) != null) {
for (a aVar : list) {
if (aVar.a.equals(str)) {
return aVar;
}
}
}
return null;
}
public long a() {
long j = 0;
if (this.c != null) {
for (int i = 0; i < this.c.size(); i++) {
j += this.c.get(i).a();
}
}
return j;
}
public void a(b bVar) {
String str = bVar.a;
if (this.c == null) {
this.c = new ArrayList();
}
for (b.a aVar : bVar.e) {
boolean z = true;
a a2 = a(aVar.a);
if (a2 == null) {
a2 = new a(this);
z = false;
}
a2.a = aVar.a;
a2.b = aVar.h;
a2.a(aVar.i);
a2.c = aVar.g;
a2.e = aVar.d;
if (!z) {
this.c.add(a2);
}
}
}
public void a(String str, Error error) {
a a2 = a(str);
if (a2 != null) {
a2.f = error;
}
}
public boolean b() {
if (this.b != 2) {
TTVideoEngineLog.d("DataLoaderHelper", "task is not a preload task");
return false;
}
if (this.c != null) {
for (int i = 0; i < this.c.size(); i++) {
a aVar = this.c.get(i);
if (aVar != null && !aVar.b()) {
return false;
}
}
}
return true;
}
public boolean c() {
boolean z;
int i;
if (this.c != null) {
z = true;
i = 0;
for (int i2 = 0; i2 < this.c.size(); i2++) {
a aVar = this.c.get(i2);
if (aVar == null || aVar.b()) {
i++;
} else {
z = false;
}
}
} else {
z = true;
i = 0;
}
return z || (i >= 2 && this.b == 1);
}
}
public class d {
private final ReentrantLock a;
private final ArrayList<b> b;
private long c;
private d(DataLoaderHelper dataLoaderHelper) {
this.a = new ReentrantLock();
this.b = new ArrayList<>();
this.c = 0L;
}
private Boolean e() {
if (this.c >= 1) {
return Boolean.valueOf(((long) this.b.size()) >= this.c);
}
return Boolean.FALSE;
}
public long a() {
this.a.lock();
long size = this.b.size();
this.a.unlock();
return size;
}
public void a(long j) {
this.c = j;
}
boolean a(b bVar) {
Boolean bool;
if (bVar == null || bVar.e.size() == 0) {
return false;
}
this.a.lock();
if (e().booleanValue()) {
bool = Boolean.FALSE;
} else {
this.b.add(bVar);
bool = Boolean.TRUE;
}
this.a.unlock();
return bool.booleanValue();
}
public boolean a(String str) {
int i = 0;
if (TextUtils.isEmpty(str)) {
return false;
}
Boolean bool = Boolean.FALSE;
this.a.lock();
while (true) {
if (i >= this.b.size()) {
break;
}
if (this.b.get(i).a(str) != null) {
bool = Boolean.TRUE;
break;
}
i++;
}
this.a.unlock();
return bool.booleanValue();
}
public b b() {
this.a.lock();
if (this.b.size() == 0) {
this.a.unlock();
return null;
}
b bVar = this.b.get(r0.size() - 1);
this.a.unlock();
return bVar;
}
public b b(b bVar) {
b bVar2;
if (TextUtils.isEmpty(bVar.a)) {
bVar2 = null;
} else {
bVar2 = c(bVar.a);
if (bVar2 != null) {
return bVar2;
}
}
Iterator<b.a> it = bVar.e.iterator();
while (it.hasNext() && (bVar2 = d(it.next().a)) == null) {
}
return bVar2;
}
public b b(String str) {
b bVar = null;
if (TextUtils.isEmpty(str)) {
return null;
}
this.a.lock();
int i = 0;
while (true) {
if (i >= this.b.size()) {
break;
}
b bVar2 = this.b.get(i);
if (bVar2.a(str) != null) {
bVar = bVar2;
break;
}
i++;
}
this.a.unlock();
return bVar;
}
public b c() {
this.a.lock();
if (this.b.size() == 0) {
this.a.unlock();
return null;
}
b bVar = this.b.get(r0.size() - 1);
this.b.remove(bVar);
this.a.unlock();
return bVar;
}
public b c(String str) {
b bVar = null;
if (TextUtils.isEmpty(str)) {
return null;
}
this.a.lock();
int i = 0;
while (true) {
if (i >= this.b.size()) {
break;
}
b bVar2 = this.b.get(i);
if (!TextUtils.isEmpty(bVar2.a) && bVar2.a.equals(str)) {
bVar = bVar2;
break;
}
i++;
}
if (bVar != null) {
this.b.remove(bVar);
}
this.a.unlock();
return bVar;
}
public b d(String str) {
b bVar = null;
if (TextUtils.isEmpty(str)) {
return null;
}
this.a.lock();
int i = 0;
while (true) {
if (i >= this.b.size()) {
break;
}
b bVar2 = this.b.get(i);
if (bVar2.a(str) != null) {
bVar = bVar2;
break;
}
i++;
}
if (bVar != null) {
TTVideoEngineLog.d("DataLoaderHelper", "popItem remove this " + this + ", item " + bVar);
this.b.remove(bVar);
}
this.a.unlock();
return bVar;
}
public ArrayList<b> d() {
try {
this.a.lock();
return new ArrayList<>(this.b);
} finally {
this.a.unlock();
}
}
}
private DataLoaderHelper() {
this.f = new d();
this.g = new d();
this.h = new d();
this.i = new d();
}
static int a() {
int i = d;
d = i + 1;
return i;
}
private DataLoaderCacheInfo a(String str) {
DataLoaderCacheInfo dataLoaderCacheInfo = null;
if (str == null) {
return null;
}
String[] split = str.split(bf0.COMMA);
if (split.length >= 4) {
dataLoaderCacheInfo = new DataLoaderCacheInfo(this);
dataLoaderCacheInfo.mLocalFilePath = split[3];
if (!TextUtils.isEmpty(split[0])) {
dataLoaderCacheInfo.mCacheSizeFromZero = Long.parseLong(split[0]);
}
if (!TextUtils.isEmpty(split[1])) {
dataLoaderCacheInfo.mMediaSize = Long.parseLong(split[1]);
}
TTVideoEngineLog.d("DataLoaderHelper", "get cache info.");
}
return dataLoaderCacheInfo;
}
private String a(String str, String str2, long j, long j2, String[] strArr, String str3) {
String str4;
if (TextUtils.isEmpty(str) || strArr == null || strArr.length < 1) {
return null;
}
String[] strArr2 = (String[]) strArr.clone();
long j3 = j2 > 0 ? j2 : 0L;
for (String str5 : strArr2) {
if (!b(str5)) {
return null;
}
}
String[] a2 = a(strArr2);
String encodeUrl = encodeUrl(str);
if (TextUtils.isEmpty(encodeUrl)) {
return null;
}
StringBuilder sb = new StringBuilder();
sb.append("preloadProxyQuery: key = ");
String str6 = str;
sb.append(str);
sb.append(", rawKey = ");
sb.append(str2);
TTVideoEngineLog.i("DataLoaderHelper", sb.toString());
if (!TextUtils.isEmpty(str2)) {
str6 = str2;
}
String encodeUrl2 = encodeUrl(str6);
if (TextUtils.isEmpty(encodeUrl2)) {
encodeUrl2 = "videoId";
}
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("?rk=");
stringBuffer.append(encodeUrl2);
stringBuffer.append("&k=");
stringBuffer.append(encodeUrl);
if (j3 > 0) {
stringBuffer.append("&s=");
stringBuffer.append(j + j3);
}
if (!TextUtils.isEmpty(str3)) {
try {
str4 = URLEncoder.encode(str3, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
str4 = null;
}
if (!TextUtils.isEmpty(str4)) {
stringBuffer.append("&p=");
stringBuffer.append(str4);
}
}
StringBuffer stringBuffer2 = new StringBuffer();
for (int i = 0; i < a2.length; i++) {
String encodeUrlByQuery = encodeUrlByQuery(a2[i]);
StringBuffer stringBuffer3 = new StringBuffer();
if (!TextUtils.isEmpty(encodeUrlByQuery)) {
stringBuffer3.append("&u");
stringBuffer3.append(i);
stringBuffer3.append("=");
stringBuffer3.append(encodeUrlByQuery);
}
if (stringBuffer.length() + stringBuffer2.length() + stringBuffer3.length() + 32 > 3096) {
break;
}
stringBuffer2.append(stringBuffer3);
}
if (stringBuffer2.length() < 1) {
return null;
}
stringBuffer.append(stringBuffer2);
return stringBuffer.toString();
}
private void a(b bVar) {
String str;
if (bVar == null) {
str = "_notifyPreloadCancel taskItem is null";
} else {
if (!bVar.d) {
bVar.d = true;
if (bVar.a() == null) {
TTVideoEngineLog.d("DataLoaderHelper", "_notifyPreloadCancel getCallBackListener is null");
return;
}
d++;
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount engine callback " + d + ", KEY_IS_PRELOAD_END_CANCEL");
bVar.a().preloadItemInfo(new PreLoaderItemCallBackInfo(5));
return;
}
str = "_notifyPreloadCancel didCanceled";
}
TTVideoEngineLog.d("DataLoaderHelper", str);
}
private void a(b bVar, b.a aVar) {
if (bVar == null) {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] start mdl preload task fail. item is null");
return;
}
if (aVar == null) {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] start mdl preload task fail. track is null");
notifyPreloadError(bVar.c, -100004);
return;
}
TTVideoEngineLog.i("DataLoaderHelper", "[preload] start mdl preload task. key = " + aVar.a);
String str = aVar.a;
String[] strArr = aVar.c;
if (strArr != null) {
String a2 = a(str, bVar.a, aVar.f, 0L, strArr, aVar.d);
aVar.b = a2;
if (!TextUtils.isEmpty(a2)) {
TTVideoEngineLog.d("DataLoaderHelper", "allPreloadTasks enqueueItem " + this.h + ", item " + bVar);
this.h.a(bVar);
if (aVar.f > 0) {
long j = aVar.e;
if (j > 0) {
this.m.a(aVar.b, (int) j);
}
this.m.a(aVar.b, (int) aVar.f, (int) aVar.g);
} else {
this.m.a(aVar.b, (int) aVar.g);
}
TTVideoEngineLog.i("DataLoaderHelper", String.format("[preload] exect preload task ,key is %s; videoId = %s", aVar.a, bVar.a));
return;
}
}
bVar.a(-100001);
}
private void a(com.bykv.vk.component.ttvideo.mediakit.medialoader.a aVar, boolean z, boolean z2) {
String str;
b b2;
d dVar;
b.a a2;
String str2;
c loadProgressByRawKey;
if (aVar == null || TextUtils.isEmpty(aVar.d)) {
str = "_progressInfoString return";
} else {
String[] split = aVar.d.split(bf0.COMMA);
if (split.length >= 4) {
boolean z3 = false;
try {
long longValue = Long.valueOf(split[0]).longValue();
long longValue2 = Long.valueOf(split[1]).longValue();
if (longValue2 <= 0 && !z2) {
TTVideoEngineLog.i("DataLoaderHelper", "[preload] mediaSize <= 0 return " + aVar.d);
return;
}
String str3 = split[2];
String str4 = split[3];
if (!z && !z2) {
b2 = this.i.b(str3);
if (b2 == null) {
TTVideoEngineLog.i("DataLoaderHelper", "[preload] play temItem == null return " + aVar.d);
return;
}
dVar = this.i;
a2 = b2.a(str3);
if (a2 != null) {
a2.h = longValue2;
a2.i = longValue;
a2.d = str4;
}
str2 = !TextUtils.isEmpty(b2.a) ? str3 : b2.a;
loadProgressByRawKey = getLoadProgressByRawKey(str2);
if (loadProgressByRawKey == null) {
loadProgressByRawKey = new c(this);
}
loadProgressByRawKey.a = b2.a;
loadProgressByRawKey.b = !z ? 2 : 1;
loadProgressByRawKey.a(b2);
putByRawKey(str2, loadProgressByRawKey);
if (!loadProgressByRawKey.c() || z2) {
if (!z3) {
dVar.d(str3);
}
removeLoadProgressByRawKey(str2);
if (!z) {
c(b2);
}
if (b2.a() != null || !z2) {
TTVideoEngineLog.d("DataLoaderHelper", "_progressInfoString getCallBackListener is null or preloadEnd " + z2);
return;
}
d++;
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount engine callback " + d + ", KEY_IS_PRELOAD_END_SUCCEED");
dVar.d(str3);
DataLoaderTaskProgressInfo dataLoaderTaskProgressInfo = new DataLoaderTaskProgressInfo();
dataLoaderTaskProgressInfo.mCacheSizeFromZero = longValue;
dataLoaderTaskProgressInfo.mMediaSize = longValue2;
dataLoaderTaskProgressInfo.mKey = str3;
dataLoaderTaskProgressInfo.mLocalFilePath = str4;
dataLoaderTaskProgressInfo.mVideoId = b2.a;
dataLoaderTaskProgressInfo.mTaskType = loadProgressByRawKey.b;
PreLoaderItemCallBackInfo preLoaderItemCallBackInfo = new PreLoaderItemCallBackInfo(2);
preLoaderItemCallBackInfo.preloadDataInfo = dataLoaderTaskProgressInfo;
preLoaderItemCallBackInfo.loadProgress = loadProgressByRawKey;
b2.a().preloadItemInfo(preLoaderItemCallBackInfo);
TTVideoEngineLog.i("DataLoaderHelper", "[preload] notify end cache size = " + loadProgressByRawKey.a());
return;
}
return;
}
b2 = this.h.b(str3);
if (b2 == null) {
TTVideoEngineLog.i("DataLoaderHelper", "[preload] preload temItem == null return " + aVar.d);
return;
}
dVar = this.h;
z3 = true;
a2 = b2.a(str3);
if (a2 != null) {
}
if (!TextUtils.isEmpty(b2.a)) {
}
loadProgressByRawKey = getLoadProgressByRawKey(str2);
if (loadProgressByRawKey == null) {
}
loadProgressByRawKey.a = b2.a;
loadProgressByRawKey.b = !z ? 2 : 1;
loadProgressByRawKey.a(b2);
putByRawKey(str2, loadProgressByRawKey);
if (loadProgressByRawKey.c()) {
}
if (!z3) {
}
removeLoadProgressByRawKey(str2);
if (!z) {
}
if (b2.a() != null) {
}
TTVideoEngineLog.d("DataLoaderHelper", "_progressInfoString getCallBackListener is null or preloadEnd " + z2);
return;
} catch (Exception e) {
TTVideoEngineLog.d(e);
return;
}
}
str = "_progressInfoString temArray.length " + split.length;
}
TTVideoEngineLog.d("DataLoaderHelper", str);
}
private void a(String str, String str2, long j, PreloaderURLItem preloaderURLItem) {
if (TextUtils.isEmpty(str)) {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] key invalid.");
notifyPreloadError(preloaderURLItem, -100001);
return;
}
if (this.m == null || this.e != 0) {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] need load mdl first.");
notifyPreloadError(preloaderURLItem, -100002);
return;
}
if (this.g.a(str) || this.f.a(str)) {
TTVideoEngineLog.d("DataLoaderHelper", "[preload] add the same key task.");
notifyPreloadError(preloaderURLItem, -100003);
return;
}
b bVar = new b(this);
bVar.a(str, j);
bVar.a = str2;
bVar.c = preloaderURLItem;
this.f.a(bVar);
d();
}
private boolean a(d dVar) {
TTVideoEngineLog.d("DataLoaderHelper", "cancelTasks");
boolean z = false;
if (dVar.a() > 0) {
while (true) {
b c2 = dVar.c();
if (c2 == null) {
break;
}
z = true;
a(c2);
}
}
return z;
}
private String[] a(String[] strArr) {
if (strArr == null || strArr.length <= 1) {
return strArr;
}
ArrayList arrayList = new ArrayList();
arrayList.add(strArr[0]);
for (int i = 1; i < strArr.length; i++) {
String str = strArr[i];
Boolean bool = Boolean.TRUE;
int size = arrayList.size() - 1;
while (true) {
if (size < 0) {
break;
}
if (((String) arrayList.get(size)).equals(str)) {
bool = Boolean.FALSE;
break;
}
size--;
}
if (bool.booleanValue()) {
arrayList.add(str);
}
}
String[] strArr2 = new String[arrayList.size()];
arrayList.toArray(strArr2);
return strArr2;
}
private void b(b bVar) {
if (bVar == null) {
d();
return;
}
if (this.m == null) {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] need load mdl first.");
return;
}
this.g.b(bVar);
long j = bVar.b;
PreloaderURLItem preloaderURLItem = bVar.c;
if (preloaderURLItem != null && preloaderURLItem.getUrls() != null && bVar.c.getUrls().length > 0) {
b.a aVar = bVar.e.get(0);
aVar.c = bVar.c.getUrls();
aVar.g = bVar.b;
aVar.d = bVar.c.getFilePath();
a(bVar, aVar);
}
if (bVar.a() != null) {
PreLoaderItemCallBackInfo preLoaderItemCallBackInfo = new PreLoaderItemCallBackInfo(6);
preLoaderItemCallBackInfo.preloadType = 0;
preLoaderItemCallBackInfo.videoPreloadSize = j;
preLoaderItemCallBackInfo.audioPreloadSize = 0L;
bVar.a().preloadItemInfo(preLoaderItemCallBackInfo);
TTVideoEngineLog.i("DataLoaderHelper", "[preload] notify info. type = 0");
}
d();
}
private boolean b(String str) {
if (TextUtils.isEmpty(str)) {
return false;
}
String lowerCase = str.toLowerCase();
return (lowerCase.startsWith("http://127.0.0.1") || lowerCase.startsWith("http://localhost") || lowerCase.startsWith(MDL_PREFIX) || lowerCase.startsWith("file://") || lowerCase.startsWith(com.ksdk.ssds.manager.b.b) || lowerCase.endsWith(".mpd") || lowerCase.contains(".mpd?")) ? false : true;
}
private ArrayList<TTVideoEngine> c(String str) {
ArrayList<TTVideoEngine> arrayList = null;
if (TextUtils.isEmpty(str)) {
return null;
}
try {
this.l.lock();
ArrayList<TTVideoEngine> arrayList2 = this.k.get(str);
if (arrayList2 != null) {
arrayList = new ArrayList<>(arrayList2);
TTVideoEngineLog.i("DataLoaderHelper", "get engine ref,rawKey = " + str + " engine ref count: " + arrayList.size());
}
return arrayList;
} finally {
this.l.unlock();
}
}
private void c(b bVar) {
boolean z;
ArrayList<TTVideoEngine> c2;
ArrayList<b> d2 = this.i.d();
int i = 0;
while (true) {
if (i >= d2.size()) {
z = true;
break;
}
b bVar2 = d2.get(i);
if (!TextUtils.isEmpty(bVar2.a) && !TextUtils.isEmpty(bVar.a) && bVar2.a.equals(bVar.a)) {
z = false;
break;
}
i++;
}
if (!z || (c2 = c(bVar.a)) == null || c2.size() == 0) {
return;
}
for (int i2 = 0; i2 < c2.size(); i2++) {
c2.get(i2).a();
}
}
private boolean c() {
if (this.m != null) {
return true;
}
if (AVMDLDataLoader.a(false, false) != 0) {
TTVideoEngineLog.e("DataLoaderHelper", "library has not been loaded");
return false;
}
try {
AVMDLDataLoader a2 = AVMDLDataLoader.a();
this.m = a2;
a2.a(this.n);
this.m.a((AVMDLDataLoaderListener) this);
this.m.a((com.bykv.vk.component.ttvideo.mediakit.medialoader.c) this);
return true;
} catch (Exception e) {
TTVideoEngineLog.d(e);
return false;
}
}
private void d() {
if (this.m == null) {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] need load mdl first.");
return;
}
b b2 = this.f.b();
if (b2 != null && this.g.a(b2)) {
this.f.c();
if (b2.c != null) {
b(b2);
}
}
}
public static String encodeUrl(String str) {
if (TextUtils.isEmpty(str)) {
return str;
}
try {
return URLEncoder.encode(str, "UTF-8");
} catch (UnsupportedEncodingException unused) {
return null;
}
}
public static String encodeUrlByQuery(String str) {
if (TextUtils.isEmpty(str)) {
return str;
}
TTVideoEngineLog.d("TTHelperEncode", "before encode:" + str);
try {
String f = AVMDLDataLoader.f(str);
if (TextUtils.isEmpty(f)) {
TTVideoEngineLog.d("TTHelperEncode", "call native encode fail,try java");
f = URLEncoder.encode(str, "UTF-8");
}
TTVideoEngineLog.d("TTHelperEncode", "after encode:" + f);
return f;
} catch (UnsupportedEncodingException unused) {
return null;
}
}
public static DataLoaderHelper getDataLoader() {
return a;
}
public void _addEngine(TTVideoEngine tTVideoEngine, String str) {
if (TextUtils.isEmpty(str)) {
return;
}
try {
this.l.lock();
ArrayList<TTVideoEngine> arrayList = this.k.get(str);
if (arrayList == null) {
arrayList = new ArrayList<>();
this.k.put(str, arrayList);
}
if (!arrayList.contains(tTVideoEngine)) {
arrayList.add(tTVideoEngine);
TTVideoEngineLog.i("DataLoaderHelper", "add engine ref,rawKey = " + str + " engine ref count: " + arrayList.size());
}
} finally {
this.l.unlock();
}
}
public String _proxyUrl(String str, String str2, long j, String[] strArr, String str3) {
String e;
b c2;
b.a b2;
if (this.e != 0 || TextUtils.isEmpty(str) || strArr == null || strArr.length < 1) {
return null;
}
String[] strArr2 = (String[]) strArr.clone();
for (String str4 : strArr2) {
if (!b(str4)) {
TTVideoEngineLog.d("DataLoaderHelper", "not support");
return str4;
}
}
if (this.m == null) {
TTVideoEngineLog.e("DataLoaderHelper", "start mdl first");
return null;
}
this.s.lock();
try {
String i = this.m.i();
if (TextUtils.isEmpty(i)) {
TTVideoEngineLog.e("DataLoaderHelper", "local host error");
return null;
}
String a2 = a(str, str2, 0L, j, strArr2, str3);
if (TextUtils.isEmpty(a2)) {
return null;
}
StringBuffer stringBuffer = new StringBuffer();
int i2 = this.r;
this.r = i2 + 1;
StringBuffer stringBuffer2 = new StringBuffer();
TTVideoEngineLog.i("DataLoaderHelper", "proxy url, mInvalidMdlProcotol: " + this.p);
if (!this.p && this.q) {
stringBuffer.append(MDL_PREFIX);
stringBuffer.append(b41.ID_ATTR);
stringBuffer.append(i2);
stringBuffer.append(com.ksdk.ssds.manager.b.b);
stringBuffer.append(a2);
stringBuffer2.append(a2);
e = this.m.e(a2);
if (!TextUtils.isEmpty(e)) {
stringBuffer.append("&ah=");
stringBuffer.append(e);
stringBuffer.append("&ah=");
stringBuffer.append(e);
}
String stringBuffer3 = stringBuffer.toString();
TTVideoEngineLog.i("DataLoaderHelper", "_proxyUrl: " + stringBuffer3);
this.s.unlock();
c2 = this.i.c(str2);
if (c2 == null) {
c2 = new b(this);
}
b2 = c2.b(str);
if (b2 != null) {
b2.a = str;
c2.a = str2;
b2.b = stringBuffer3;
b2.c = strArr2;
b2.d = str3;
this.i.a(c2);
}
return stringBuffer3;
}
stringBuffer.append("http://");
stringBuffer.append(i);
stringBuffer.append(com.ksdk.ssds.manager.b.b);
stringBuffer.append(i2);
stringBuffer.append(a2);
stringBuffer2.append(a2);
e = this.m.e(a2);
if (!TextUtils.isEmpty(e)) {
}
String stringBuffer32 = stringBuffer.toString();
TTVideoEngineLog.i("DataLoaderHelper", "_proxyUrl: " + stringBuffer32);
this.s.unlock();
c2 = this.i.c(str2);
if (c2 == null) {
}
b2 = c2.b(str);
if (b2 != null) {
}
return stringBuffer32;
} finally {
this.s.unlock();
}
}
public void _removeEngine(TTVideoEngine tTVideoEngine, String str) {
if (TextUtils.isEmpty(str)) {
return;
}
try {
this.l.lock();
ArrayList<TTVideoEngine> arrayList = this.k.get(str);
if (arrayList != null) {
arrayList.remove(tTVideoEngine);
TTVideoEngineLog.i("DataLoaderHelper", "remove engine ref,rawKey = " + str + " engine ref count: " + arrayList.size());
if (arrayList.size() == 0) {
this.k.remove(str);
}
}
} finally {
this.l.unlock();
}
}
public void _removePlayTask(String str) {
this.i.d(str);
}
public void addTask(PreloaderURLItem preloaderURLItem) {
b++;
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount addTask " + b);
if (preloaderURLItem == null) {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] url item invalid");
return;
}
this.s.lock();
try {
a(preloaderURLItem.getKey(), preloaderURLItem.getVideoId(), preloaderURLItem.getPreloadSize(), preloaderURLItem);
} finally {
this.s.unlock();
}
}
public void cancelAllTasks() {
if (this.m == null || this.e != 0) {
TTVideoEngineLog.e("DataLoaderHelper", "need start mdl first");
return;
}
this.s.lock();
try {
cancelAllTasksInternal();
} finally {
try {
} finally {
}
}
}
public void cancelAllTasksInternal() {
TTVideoEngineLog.d("DataLoaderHelper", "cancelAllTasksInternal");
a(this.g);
a(this.f);
if (a(this.h)) {
this.m.g();
}
}
public void cancelTask(String str) {
b d2;
if (TextUtils.isEmpty(str)) {
return;
}
if (this.m == null || this.e != 0) {
TTVideoEngineLog.e("DataLoaderHelper", "need start mdl first");
return;
}
this.s.lock();
try {
d2 = this.f.d(str);
} finally {
try {
} finally {
}
}
if (d2 == null && (d2 = this.g.d(str)) == null) {
d2 = this.h.d(str);
if (d2 != null) {
this.m.a(str);
}
TTVideoEngineLog.i("DataLoaderHelper", "[preload] cancel preload task. key = " + str);
}
a(d2);
TTVideoEngineLog.i("DataLoaderHelper", "[preload] cancel preload task. key = " + str);
}
public void clearAllCaches() {
AVMDLDataLoader aVMDLDataLoader;
if (this.e != 0) {
return;
}
this.s.lock();
try {
aVMDLDataLoader = this.m;
} finally {
try {
} finally {
}
}
if (aVMDLDataLoader == null) {
TTVideoEngineLog.e("DataLoaderHelper", "mInnerDataLoader == null");
} else {
aVMDLDataLoader.h();
}
}
public void close() {
this.s.lock();
try {
if (this.e == 1) {
TTVideoEngineLog.e("DataLoaderHelper", "DataLoader not started, not need close");
} else {
this.m.f();
cancelAllTasksInternal();
this.e = 1;
}
} finally {
this.s.unlock();
}
}
public DataLoaderCacheInfo getCacheInfoByFilePath(String str, String str2) {
this.s.lock();
try {
AVMDLDataLoader aVMDLDataLoader = this.m;
if (aVMDLDataLoader != null) {
return a(aVMDLDataLoader.a(str, str2));
}
} finally {
try {
return null;
} finally {
}
}
return null;
}
public long getCacheSize(String str) {
long j = 0;
if (this.e != 0) {
return 0L;
}
this.s.lock();
try {
AVMDLDataLoader aVMDLDataLoader = this.m;
if (aVMDLDataLoader != null) {
long d2 = aVMDLDataLoader.d(str);
if (d2 > 0) {
j = d2;
}
}
} finally {
try {
return j;
} finally {
}
}
return j;
}
public long getCacheSizeByFilePath(String str, String str2) {
TTVideoEngineLog.d("DataLoaderHelper", "getCacheSizeByFilePath key:" + str + ", filePath:" + str2);
this.s.lock();
try {
DataLoaderCacheInfo cacheInfoByFilePath = getCacheInfoByFilePath(str, str2);
long j = cacheInfoByFilePath != null ? cacheInfoByFilePath.mCacheSizeFromZero : 0L;
TTVideoEngineLog.d("DataLoaderHelper", "getCacheSizeByFilePath result:" + j);
return j;
} catch (Throwable th) {
try {
TTVideoEngineLog.d(th);
return 0L;
} finally {
this.s.unlock();
}
}
}
@Override
public String getCheckSumInfo(String str) {
return null;
}
@Override
public long getInt64Value(int i, long j) {
return 0L;
}
public c getLoadProgressByRawKey(String str) {
if (!TextUtils.isEmpty(str)) {
return this.j.get(str);
}
TTVideoEngineLog.e("DataLoaderHelper", "[preload] get, param is invalid key is null");
return null;
}
@Override
public String getStringValue(int i, long j, String str) {
return null;
}
public void notifyPreloadError(PreloaderURLItem preloaderURLItem, int i) {
TTVideoEngineLog.d("DataLoaderHelper", "notifyPreloadError " + i);
IPreLoaderItemCallBackListener callBackListener = preloaderURLItem.getCallBackListener();
if (callBackListener != null) {
d++;
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount engine callback " + d + ", KEY_IS_PRELOAD_END_FAIL");
PreLoaderItemCallBackInfo preLoaderItemCallBackInfo = new PreLoaderItemCallBackInfo(3);
preLoaderItemCallBackInfo.preloadError = new Error(Error.DataLoaderPreload, i);
callBackListener.preloadItemInfo(preLoaderItemCallBackInfo);
}
}
@Override
public void onNotify(com.bykv.vk.component.ttvideo.mediakit.medialoader.a aVar) {
String str;
int i;
VideoEventEngineUploader videoEventEngineUploader;
String str2;
String[] split;
String str3;
JSONObject jSONObject;
if (aVar == null) {
return;
}
try {
jSONObject = aVar.g;
} catch (Exception e) {
e.printStackTrace();
}
if (jSONObject != null) {
str = jSONObject.toString();
i = aVar.a;
if (i != 0 && i != 15) {
if (i != 20) {
if (i == 3 || i == 4) {
TTVideoEngineLog.d("DataLoaderHelper", "KeyIsFileCacheProgress log = " + aVar.d + ", what = " + aVar.a + ", task type = " + aVar.c + " code = " + ((int) aVar.b));
if (aVar.a == 4) {
c++;
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount mdl callback " + c + ", KeyIsPreloadEnd");
}
if (aVar.d != null) {
long j = aVar.c;
if (j != 3) {
a(aVar, j == 2, aVar.a == 4);
return;
}
return;
}
return;
}
if (i == 7) {
c++;
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount mdl callback " + c + ", KeyIsIsPreloadCancel");
if (TextUtils.isEmpty(aVar.d)) {
TTVideoEngineLog.d("DataLoaderHelper", "KeyIsIsPreloadCancel log is empty");
return;
}
TTVideoEngineLog.d("DataLoaderHelper", "KeyIsIsPreloadCancel " + aVar.d);
String[] split2 = aVar.d.split(bf0.COMMA);
if (split2.length < 4) {
return;
}
String str4 = split2[2];
b b2 = this.h.b(str4);
this.h.d(str4);
a(b2);
return;
}
if (i != 8) {
if (i != 10 && i != 11) {
return;
}
}
}
TTVideoEngineLog.d("DataLoaderHelper", "KeyIsPreloadFail " + aVar.a + " " + aVar.c + " " + aVar.d);
if (aVar.a == 8) {
c++;
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount mdl callback " + c + ", KeyIsPreloadFail");
}
str2 = aVar.d;
if ((str2 == null && aVar.c == 3) || str2 == null) {
return;
}
TTVideoEngineLog.i("DataLoaderHelper", " task fail log = " + aVar.d + ", code = " + aVar.b + ", task type = " + aVar.c);
split = aVar.d.split(bf0.COMMA);
if (split.length >= 1) {
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount temArray.length " + split.length);
return;
}
String str5 = split[0];
b b3 = this.h.b(str5);
if (b3 == null) {
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount item is null");
return;
}
d dVar = this.h;
Error error = new Error(Error.DataLoaderPreload, (int) aVar.b, aVar.d);
String str6 = TextUtils.isEmpty(b3.a) ? str5 : b3.a;
c loadProgressByRawKey = getLoadProgressByRawKey(str6);
if (loadProgressByRawKey == null) {
loadProgressByRawKey = new c(this);
}
loadProgressByRawKey.a = b3.a;
loadProgressByRawKey.b = (int) aVar.c;
loadProgressByRawKey.a(b3);
loadProgressByRawKey.a(str5, error);
putByRawKey(str6, loadProgressByRawKey);
if (loadProgressByRawKey.c() || loadProgressByRawKey.b()) {
dVar.d(str5);
TTVideoEngineLog.i("DataLoaderHelper", "pop all task item. videoId = " + b3.a + " key = " + str5);
removeLoadProgressByRawKey(str6);
if (b3.a() != null && aVar.c == 2) {
PreLoaderItemCallBackInfo preLoaderItemCallBackInfo = new PreLoaderItemCallBackInfo(3);
preLoaderItemCallBackInfo.preloadError = error;
preLoaderItemCallBackInfo.loadProgress = loadProgressByRawKey;
preLoaderItemCallBackInfo.preloadDataInfo = null;
d++;
TTVideoEngineLog.d("DataLoaderHelper", "preloadCount engine callback " + d + ", KEY_IS_PRELOAD_END_FAIL");
b3.a().preloadItemInfo(preLoaderItemCallBackInfo);
return;
}
str3 = "getCallBackListener IS NULL";
} else {
str3 = "preloadCount callback " + loadProgressByRawKey.c() + "isPreloadComplete " + loadProgressByRawKey.b();
}
TTVideoEngineLog.d("DataLoaderHelper", str3);
return;
}
TTVideoEngineLog.d("DataLoaderHelper", "uploadLog type:" + aVar.a + ", logType:" + aVar.e + ", TaskLog: " + str);
videoEventEngineUploader = this.o;
if (videoEventEngineUploader == null) {
videoEventEngineUploader.onEvent(aVar.e, aVar.g);
return;
}
return;
}
str = "";
i = aVar.a;
if (i != 0) {
if (i != 20) {
}
TTVideoEngineLog.d("DataLoaderHelper", "KeyIsPreloadFail " + aVar.a + " " + aVar.c + " " + aVar.d);
if (aVar.a == 8) {
}
str2 = aVar.d;
if (str2 == null) {
}
TTVideoEngineLog.i("DataLoaderHelper", " task fail log = " + aVar.d + ", code = " + aVar.b + ", task type = " + aVar.c);
split = aVar.d.split(bf0.COMMA);
if (split.length >= 1) {
}
}
TTVideoEngineLog.d("DataLoaderHelper", "uploadLog type:" + aVar.a + ", logType:" + aVar.e + ", TaskLog: " + str);
videoEventEngineUploader = this.o;
if (videoEventEngineUploader == null) {
}
}
@Override
public void onStartComplete() {
TTVideoEngineLog.d("DataLoaderHelper", "MediaDataLoader start complete");
}
public void putByRawKey(String str, c cVar) {
if (TextUtils.isEmpty(str) || cVar == null) {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] param is invalid");
} else {
this.j.put(str, cVar);
}
}
public void removeCacheFile(String str, boolean z) {
if (TextUtils.isEmpty(str)) {
return;
}
this.s.lock();
try {
if (this.m == null) {
TTVideoEngineLog.e("DataLoaderHelper", "mInnerDataLoader == null");
} else {
TTVideoEngineLog.i("DataLoaderHelper", "remove mdl file. key " + str);
if (z) {
this.m.c(str);
} else {
this.m.b(str);
}
}
} finally {
try {
} finally {
}
}
}
public void removeLoadProgressByRawKey(String str) {
if (TextUtils.isEmpty(str)) {
TTVideoEngineLog.e("DataLoaderHelper", "[preload] remove, param is invalid key is null");
} else {
this.j.remove(str);
}
}
public void setCacheInfoLists(String[] strArr, long[] jArr) {
TTVideoEngineLog.d("DataLoaderHelper", "setCacheInfoLists dirs:" + Arrays.toString(strArr) + ", maxCaches " + Arrays.toString(jArr));
this.s.lock();
try {
this.n.setCacheInfoList(strArr, jArr);
} finally {
this.s.unlock();
}
}
public void setContext(Context context) {
this.s.lock();
this.s.unlock();
}
public synchronized void setEngineUploader(VideoEventEngineUploader videoEventEngineUploader) {
TTVideoEngineLog.d("DataLoaderHelper", "setEngineUploader " + videoEventEngineUploader);
this.o = videoEventEngineUploader;
}
public void setIntValue(int i, int i2) {
this.s.lock();
TTVideoEngineLog.d("DataLoaderHelper", "setIntValue key = " + i + ", value = " + i2);
try {
try {
} catch (Exception e) {
e.printStackTrace();
}
if (i == 11) {
this.n.mPreloadParallelNum = i2;
AVMDLDataLoader aVMDLDataLoader = this.m;
if (aVMDLDataLoader != null) {
aVMDLDataLoader.a(102, i2);
}
} else if (i != 512) {
boolean z = true;
if (i == 1005) {
if (i2 != 1) {
z = false;
}
this.q = z;
TTVideoEngineLog.i("DataLoaderHelper", "config DATALOADER_KEY_SET_MDL_PROTOCOL_ENABLE: " + this.q);
} else if (i == 1) {
this.n.mMaxCacheSize = i2;
} else if (i == 2) {
this.n.mRWTimeOut = i2;
} else {
if (i != 3) {
if (i == 4) {
this.n.mTryCount = i2;
}
}
this.n.mOpenTimeOut = i2;
}
} else {
this.n.mAlogEnable = i2;
AVMDLDataLoader aVMDLDataLoader2 = this.m;
if (aVMDLDataLoader2 != null) {
aVMDLDataLoader2.a(7225, i2);
}
}
} finally {
this.s.unlock();
}
}
public void setStringValue(int i, String str) {
TTVideoEngineLog.d("DataLoaderHelper", "setStringValue key = " + i + ", value = " + str);
this.s.lock();
if (i == 0) {
try {
try {
this.n.mCacheDir = str;
} catch (Exception e) {
TTVideoEngineLog.d(e);
}
} finally {
this.s.unlock();
}
}
}
public void start() {
TTVideoEngineLog.d("DataLoaderHelper", IntentAction.start);
this.s.lock();
try {
if (this.e == 0) {
TTVideoEngineLog.e("DataLoaderHelper", "DataLoader has started not need start");
} else {
if (!c()) {
throw new Exception("init data loader fail");
}
this.g.a(4L);
if (this.n == null) {
this.n = AVMDLDataLoaderConfigure.getDefaultonfigure();
}
if (this.o != null) {
this.n.mEnableReportTaskLog = 1;
}
this.m.a(this.n);
if (this.m.d() < 0) {
throw new Exception("start data loader fail");
}
long a2 = this.m.a(7218);
if (a2 == -1) {
this.p = true;
}
this.e = 0;
TTVideoEngineLog.d("DataLoaderHelper", "DataLoader start mdlProtocolHandle:" + a2);
}
} finally {
this.s.unlock();
}
}
}