Show verified source snapshots without borrowing core pointers
This commit is contained in:
1 parent
6c692399c2
commit
0c613eacbc
3 files changed
+14
-10
No files matched your search
@@ -203,6 +203,7 @@ object NativeLib {
|
||||
fun streamFeed(id: Long, video: Boolean, pts: Long, key: Boolean, data: ByteArray): Int = nativeStreamFeed(id, video, pts, key, data)
|
||||
fun streamStop(id: Long) { nativeStreamStop(id) }
|
||||
fun streamPull(id: Long): ByteArray? = nativeStreamPull(id)
|
||||
fun streamSources(group: Long): String = nativeStreamSources(group) ?: "[]"
|
||||
fun streamOpusCreate(encode: Boolean): Long = nativeStreamOpusCreate(encode)
|
||||
fun streamOpusEncode(handle: Long, pcm: ShortArray): ByteArray? = nativeStreamOpusEncode(handle, pcm)
|
||||
fun streamOpusDecode(handle: Long, packet: ByteArray): ShortArray? = nativeStreamOpusDecode(handle, packet)
|
||||
@@ -211,6 +212,7 @@ object NativeLib {
|
||||
private external fun nativeStreamFeed(id: Long, video: Boolean, pts: Long, key: Boolean, data: ByteArray): Int
|
||||
private external fun nativeStreamStop(id: Long)
|
||||
private external fun nativeStreamPull(id: Long): ByteArray?
|
||||
private external fun nativeStreamSources(group: Long): String?
|
||||
private external fun nativeStreamOpusCreate(encode: Boolean): Long
|
||||
private external fun nativeStreamOpusEncode(handle: Long, pcm: ShortArray): ByteArray?
|
||||
private external fun nativeStreamOpusDecode(handle: Long, packet: ByteArray): ShortArray?
|
||||
|
||||
@@ -21,7 +21,6 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.utun.chat.R
|
||||
import com.utun.chat.data.H264AnnexB
|
||||
import com.utun.chat.data.LogManager
|
||||
import com.utun.chat.data.NativeLib
|
||||
import com.utun.chat.data.StreamController
|
||||
@@ -31,7 +30,6 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
private data class LiveSource(val id: Long, val name: String, val epoch: String)
|
||||
|
||||
@@ -63,15 +61,10 @@ fun StreamScreen(channelId: String, channelName: String, onBack: () -> Unit) {
|
||||
while (true) {
|
||||
if (NativeLib.isReady()) sources = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val json = JSONArray(NativeLib.getChannelMembers(channelId))
|
||||
(0 until json.length()).mapNotNull { i ->
|
||||
val json = JSONArray(NativeLib.streamSources(group))
|
||||
(0 until json.length()).map { i ->
|
||||
val member = json.getJSONObject(i)
|
||||
val profile = JSONObject(member.optString("ui").ifEmpty { "{}" })
|
||||
val source = profile.optString("stream_source")
|
||||
val fields = source.split(':')
|
||||
if (fields.size != 4 || fields[0].length != 16 || fields[0].toULongOrNull(16) == null ||
|
||||
member.optInt("dl") != 0 || member.optInt("on") == 0) null
|
||||
else LiveSource(member.getLong("ni"), member.optString("n"), fields[0])
|
||||
LiveSource(member.getString("id").toULong().toLong(), member.getString("name"), member.getString("epoch"))
|
||||
}
|
||||
} catch (e: Exception) { LogManager.addLog("WARN", "stream", "stream list: ${e.message}"); emptyList() }
|
||||
} else sources = emptyList()
|
||||
|
||||
@@ -32,6 +32,15 @@ JNIEXPORT void JNICALL Java_com_utun_chat_data_NativeLib_nativeStreamStop(JNIEnv
|
||||
(void)env; (void)obj; android_stream_stop((uint64_t)id);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_com_utun_chat_data_NativeLib_nativeStreamSources(JNIEnv *env, jobject obj, jlong group) {
|
||||
(void)obj;
|
||||
char *json = android_stream_sources((uint64_t)group);
|
||||
if (!json) return NULL;
|
||||
jstring output = (*env)->NewStringUTF(env, json); u_free(json);
|
||||
if (!output) DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "JNI stream source list string allocation failed");
|
||||
return output;
|
||||
}
|
||||
|
||||
JNIEXPORT jbyteArray JNICALL Java_com_utun_chat_data_NativeLib_nativeStreamPull(JNIEnv *env, jobject obj, jlong id) {
|
||||
(void)obj;
|
||||
size_t length = 0; uint8_t *data = android_stream_pull((uint64_t)id, &length);
|
||||
|
||||
Reference in new issue
Block a user