StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.
Kotlin iptv-player
Decode Xtream live rows directly and streamline group identity
David Nashashcd992848e82f
diff --git a/data/src/androidTest/java/com/streamvault/data/remote/xtream/XtreamLiveComponentBenchmarkTest.kt b/data/src/androidTest/java/com/streamvault/data/remote/xtream/XtreamLiveComponentBenchmarkTest.ktnew file mode 100644index 00000000..9a1fb4ef--- /dev/null+++ b/data/src/androidTest/java/com/streamvault/data/remote/xtream/XtreamLiveComponentBenchmarkTest.kt@@ -0,0 +1,92 @@+package com.streamvault.data.remote.xtream++import android.os.Debug+import android.util.Log+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import com.google.gson.JsonParser+import com.google.gson.stream.JsonReader+import com.streamvault.data.remote.dto.XtreamLiveStreamRow+import com.streamvault.domain.util.ChannelNormalizer+import java.io.StringReader+import kotlinx.serialization.json.Json+import org.junit.Assert.assertEquals+import org.junit.Assume.assumeTrue+import org.junit.Test+import org.junit.runner.RunWith++/** Synthetic component comparison. It excludes network, Room and screen readiness. */+@RunWith(AndroidJUnit4::class)+class XtreamLiveComponentBenchmarkTest {+ private val json = Json { ignoreUnknownKeys = true; isLenient = true; explicitNulls = false; coerceInputValues = true }+ private val rows = 10_000++ @Test+ fun compareLiveDecoderAndGroupIdentity() {+ assumeTrue("Explicitly enable the component benchmark",+ InstrumentationRegistry.getArguments().getString("xtreamLiveComponentBenchmark") == "true")+ listOf(false, true).forEach { heavy ->+ val unused = if (heavy) ",\"unused_metadata\":{\"plot\":\"${"x".repeat(512)}\",\"nested\":[1,2,3]}" else ""+ val payload = (1..rows).joinToString(",", "[", "]") { id ->+ """{"stream_id":$id,"num":$id,"name":"US: Synthetic $id HD [EN]","category_ids":["${id % 100}"],"tv_archive":1,"tv_archive_duration":3,"container_extension":"m3u8"$unused}"""+ }+ val expected = rows.toLong() * (rows + 1) / 2+ val scenario = if (heavy) "extra-metadata" else "core-fields"+ repeat(2) { decode(payload, true); decode(payload, false) }+ repeat(5) { sample ->+ val order = if (sample % 2 == 0) listOf(true, false) else listOf(false, true)+ order.forEach { direct ->+ measure(scenario, "parse", if (direct) "direct" else "tree", sample, expected) { decode(payload, direct) }+ }+ }+ }+ val names = (1..rows).map { "US: Synthetic $it HD [EN]" }+ val expected = names.sumOf { ChannelNormalizer.classify(it, 42L).logicalGroupId.hashCode().toLong() }+ repeat(2) { groupIdentity(names, true); groupIdentity(names, false) }+ repeat(5) { sample ->+ val order = if (sample % 2 == 0) listOf(true, false) else listOf(false, true)+ order.forEach { direct ->+ measure("tagged-names", "group-id", if (direct) "identity" else "classification", sample, expected) {+ groupIdentity(names, direct)+ }+ }+ }+ Log.i(TAG, "event=complete rows=$rows samples=30")+ }++ private fun decode(payload: String, direct: Boolean): Long = JsonReader(StringReader(payload)).use { reader ->+ reader.isLenient = true+ reader.beginArray()+ var fingerprint = 0L+ var count = 0+ while (reader.hasNext()) {+ val row = if (direct) XtreamLiveRowReader.read(reader) else+ json.decodeFromString(XtreamLiveStreamRow.serializer(), JsonParser.parseReader(reader).toString())+ fingerprint += row.streamId+ count+++ }+ reader.endArray()+ assertEquals(rows, count)+ fingerprint+ }++ private fun groupIdentity(names: List<String>, direct: Boolean) = names.sumOf {+ (if (direct) ChannelNormalizer.getLogicalGroupId(it, 42L) else ChannelNormalizer.classify(it, 42L).logicalGroupId)+ .hashCode().toLong()+ }++ private fun measure(scenario: String, component: String, method: String, sample: Int, expected: Long, block: () -> Long) {+ val gcBefore = Debug.getRuntimeStat("art.gc.gc-count")?.toLongOrNull()+ val cpuStarted = Debug.threadCpuTimeNanos()+ val started = System.nanoTime()+ val fingerprint = block()+ val elapsedUs = (System.nanoTime() - started) / 1_000+ val cpuUs = (Debug.threadCpuTimeNanos() - cpuStarted) / 1_000+ val gcAfter = Debug.getRuntimeStat("art.gc.gc-count")?.toLongOrNull()+ assertEquals(expected, fingerprint)+ val gcDelta = if (gcBefore != null && gcAfter != null) gcAfter - gcBefore else -1+ Log.i(TAG, "scenario=$scenario component=$component method=$method sample=$sample rows=$rows elapsed_us=$elapsedUs cpu_us=$cpuUs gc_delta=$gcDelta")+ }++ private companion object { const val TAG = "XtreamLiveComponentBench" }+}diff --git a/data/src/main/java/com/streamvault/data/remote/xtream/OkHttpXtreamApiService.kt b/data/src/main/java/com/streamvault/data/remote/xtream/OkHttpXtreamApiService.ktindex c80e9a03..b503a15c 100644--- a/data/src/main/java/com/streamvault/data/remote/xtream/OkHttpXtreamApiService.kt+++ b/data/src/main/java/com/streamvault/data/remote/xtream/OkHttpXtreamApiService.kt@@ -4,6 +4,7 @@ import android.util.Logimport com.google.gson.JsonParserimport com.google.gson.stream.JsonReaderimport com.google.gson.stream.JsonToken+import com.google.gson.stream.MalformedJsonExceptionimport com.streamvault.data.remote.dto.XtreamAuthResponseimport com.streamvault.data.remote.dto.XtreamCategoryimport com.streamvault.data.remote.dto.XtreamEpgResponse@@ -17,6 +18,7 @@ import com.streamvault.data.remote.http.HttpRequestProfileimport com.streamvault.data.remote.http.safeRequestIdentitySummaryimport com.streamvault.data.remote.http.withRequestProfileimport java.io.IOException+import java.io.EOFExceptionimport java.io.InputStreamimport java.io.InputStreamReaderimport java.io.PushbackInputStream@@ -155,6 +157,7 @@ class OkHttpXtreamApiService(profile = RequestProfile.HEAVY_CATALOG,requestProfile = requestProfile,deserializer = XtreamLiveStreamRow.serializer(),+ readItem = { XtreamLiveRowReader.read(it, json.configuration.ignoreUnknownKeys) },onItem = onItem)@@ -328,6 +331,7 @@ class OkHttpXtreamApiService(profile: RequestProfile,requestProfile: HttpRequestProfile,deserializer: DeserializationStrategy<T>,+ readItem: ((JsonReader) -> T)? = null,onItem: suspend (T) -> Unit): Int = withContext(Dispatchers.IO) {val descriptor = describeEndpoint(endpoint)@@ -372,6 +376,7 @@ class OkHttpXtreamApiService(contentType = response.header("Content-Type"),maxBytes = responseBudgetFor(descriptor),deserializer = deserializer,+ readItem = readItem,onItem = if (timingEnabled) { item ->val callbackStart = System.nanoTime()try {@@ -386,6 +391,12 @@ class OkHttpXtreamApiService(}} catch (e: XtreamApiException) {throw e+ } catch (e: EOFException) {+ currentCoroutineContext().ensureActive()+ throw XtreamParsingException("Incomplete JSON array from ${descriptor.hint}", e)+ } catch (e: MalformedJsonException) {+ currentCoroutineContext().ensureActive()+ throw XtreamParsingException("Malformed JSON array from ${descriptor.hint}", e)} catch (e: IOException) {currentCoroutineContext().ensureActive()Log.w(@@ -491,6 +502,7 @@ class OkHttpXtreamApiService(contentType: String?,maxBytes: Long?,deserializer: DeserializationStrategy<T>,+ readItem: ((JsonReader) -> T)?,onItem: suspend (T) -> Unit): Int {val effectiveMaxBytes = maxBytes?.plus(RESPONSE_BUDGET_HEADROOM_BYTES)@@ -533,17 +545,12 @@ class OkHttpXtreamApiService(reader.beginArray()while (reader.hasNext()) {currentCoroutineContext().ensureActive()- val element = try {- JsonParser.parseReader(reader)- } catch (e: RuntimeException) {- throw XtreamParsingException(- "Malformed JSON from ${descriptor.hint}${sanitizedPreview(preview)?.let { " (preview=$it)" } ?: ""}",- e- )- }val item = try {- json.decodeFromString(deserializer, element.toString())- } catch (e: SerializationException) {+ if (readItem != null) readItem(reader) else {+ val element = JsonParser.parseReader(reader)+ json.decodeFromString(deserializer, element.toString())+ }+ } catch (e: RuntimeException) {throw XtreamParsingException("Malformed JSON from ${descriptor.hint}${sanitizedPreview(preview)?.let { " (preview=$it)" } ?: ""}",ediff --git a/data/src/main/java/com/streamvault/data/remote/xtream/XtreamLiveRowReader.kt b/data/src/main/java/com/streamvault/data/remote/xtream/XtreamLiveRowReader.ktnew file mode 100644index 00000000..7cc48f63--- /dev/null+++ b/data/src/main/java/com/streamvault/data/remote/xtream/XtreamLiveRowReader.kt@@ -0,0 +1,101 @@+package com.streamvault.data.remote.xtream++import com.google.gson.stream.JsonReader+import com.google.gson.stream.JsonToken+import com.streamvault.data.remote.dto.XtreamLiveStreamRow++/** Reads the sync projection without a per-row JSON tree or a second JSON parser. */+internal object XtreamLiveRowReader {+ private val listSeparator = Regex("""\s*(?:,|\|)\s*""")+ private const val MAX_LIST_DEPTH = 128++ fun read(reader: JsonReader, ignoreUnknownKeys: Boolean = true): XtreamLiveStreamRow {+ var num = 0+ var name = ""+ var streamId = 0L+ var streamIcon: String? = null+ var epgChannelId: String? = null+ var categoryId: String? = null+ var categoryName: String? = null+ var categoryIds: List<String>? = null+ var tvArchive = 0+ var tvArchiveDuration: Int? = null+ var containerExtension: String? = null+ var isAdult: Boolean? = null+ reader.beginObject()+ while (reader.hasNext()) {+ val key = reader.nextName()+ // Match the previous JSON-tree projection's last-key-wins behavior,+ // including a duplicate non-nullable field replaced with null.+ when (key) {+ "num" -> num = scalar(reader)?.toIntOrNull() ?: 0+ "name" -> name = scalar(reader)?.trim().orEmpty()+ "stream_id" -> streamId = scalar(reader)?.toLongOrNull() ?: 0L+ "stream_icon" -> streamIcon = nullableText(reader)+ "epg_channel_id" -> epgChannelId = nullableText(reader)+ "category_id" -> categoryId = nullableText(reader)+ "category_name" -> categoryName = nullableText(reader)+ "category_ids" -> categoryIds = stringList(reader, 0)+ "tv_archive" -> tvArchive = scalar(reader)?.toIntOrNull() ?: 0+ "tv_archive_duration" -> tvArchiveDuration = scalar(reader)?.toIntOrNull()+ "container_extension" -> containerExtension = nullableText(reader)+ "is_adult" -> isAdult = when (scalar(reader)?.trim()?.lowercase()) {+ "1", "true", "yes", "y", "on" -> true+ "0", "false", "no", "n", "off" -> false+ else -> null+ }+ else -> {+ if (!ignoreUnknownKeys) throw XtreamParsingException("Unexpected field in live row")+ reader.skipValue()+ }+ }+ }+ reader.endObject()+ return XtreamLiveStreamRow(num, name, streamId, streamIcon, epgChannelId, categoryId,+ categoryName, categoryIds, tvArchive, tvArchiveDuration, containerExtension, isAdult)+ }++ private fun scalar(reader: JsonReader): String? = when (reader.peek()) {+ JsonToken.STRING, JsonToken.NUMBER -> reader.nextString()+ JsonToken.BOOLEAN -> reader.nextBoolean().toString()+ JsonToken.NULL -> { reader.nextNull(); null }+ else -> { reader.skipValue(); null }+ }++ private fun nullableText(reader: JsonReader) = scalar(reader)?.trim()?.takeIf { it.isNotEmpty() }++ private fun stringList(reader: JsonReader, depth: Int): List<String>? {+ if (depth > MAX_LIST_DEPTH) throw XtreamParsingException("Live category list nesting limit exceeded")+ return when (reader.peek()) {+ JsonToken.NULL -> { reader.nextNull(); null }+ JsonToken.BEGIN_ARRAY -> {+ val values = ArrayList<String>()+ reader.beginArray()+ while (reader.hasNext()) values.addAll(stringList(reader, depth + 1).orEmpty())+ reader.endArray()+ normalize(values)+ }+ JsonToken.BEGIN_OBJECT -> {+ val values = LinkedHashMap<String, List<String>>()+ reader.beginObject()+ while (reader.hasNext()) {+ val key = reader.nextName()+ values[key] = stringList(reader, depth + 1).orEmpty()+ }+ reader.endObject()+ normalize(values.values.flatten())+ }+ else -> {+ val normalized = scalar(reader)?.trim().orEmpty()+ if (normalized.isEmpty() || normalized.equals("null", ignoreCase = true)) emptyList()+ else normalized.removePrefix("[").removeSuffix("]").split(listSeparator)+ .map { it.trim().trim('"', '\'') }+ .filter { it.isNotEmpty() && !it.equals("null", ignoreCase = true) }+ .ifEmpty { listOf(normalized.trim('"', '\'')) }+ }+ }+ }++ private fun normalize(values: List<String>) = values.map { it.trim().trim('"', '\'') }+ .filter { it.isNotEmpty() && !it.equals("null", ignoreCase = true) }+}diff --git a/data/src/main/java/com/streamvault/data/sync/SyncManagerXtreamLiveStrategy.kt b/data/src/main/java/com/streamvault/data/sync/SyncManagerXtreamLiveStrategy.ktindex 0d26d648..ed041333 100644--- a/data/src/main/java/com/streamvault/data/sync/SyncManagerXtreamLiveStrategy.kt+++ b/data/src/main/java/com/streamvault/data/sync/SyncManagerXtreamLiveStrategy.kt@@ -362,7 +362,9 @@ internal class SyncManagerXtreamLiveStrategy(elapsedMs = fullChannelsElapsedMs,itemCount = streamedRawCount,error = fullChannelsFailure,- nextStep = failureNextStep+ nextStep = if (decoderLabel == "thin" && fullChannelsFailure !is XtreamParsingException) {+ "category-bulk"+ } else failureNextStep)return CatalogSyncPayload(catalogResult = CatalogStrategyResult.Failure(@@ -407,7 +409,7 @@ internal class SyncManagerXtreamLiveStrategy(elapsedMs = fullChannelsElapsedMs,itemCount = streamedRawCount,error = null,- nextStep = failureNextStep+ nextStep = "category-bulk")return CatalogSyncPayload(catalogResult = CatalogStrategyResult.EmptyValid(diff --git a/data/src/test/java/com/streamvault/data/remote/xtream/XtreamLiveRowReaderTest.kt b/data/src/test/java/com/streamvault/data/remote/xtream/XtreamLiveRowReaderTest.ktnew file mode 100644index 00000000..ec13da3a--- /dev/null+++ b/data/src/test/java/com/streamvault/data/remote/xtream/XtreamLiveRowReaderTest.kt@@ -0,0 +1,79 @@+package com.streamvault.data.remote.xtream++import com.google.common.truth.Truth.assertThat+import com.google.gson.JsonParser+import com.google.gson.stream.JsonReader+import com.google.gson.stream.JsonToken+import com.streamvault.data.remote.dto.XtreamLiveStreamRow+import java.io.StringReader+import kotlin.random.Random+import kotlinx.serialization.json.Json+import org.junit.Test++class XtreamLiveRowReaderTest {+ private val json = Json { ignoreUnknownKeys = true; isLenient = true; explicitNulls = false; coerceInputValues = true }++ @Test+ fun `matches previous decoder for every retained field and lenient scalar type`() {+ val values = listOf("null", "true", "false", "1", "0", "-2", "1.0", "1e2", "9223372036854775807",+ "\"\"", "\" 7 \"", "\" Yes \"", "\"null\"", "\" +7 \"", "[]", "{}", "[1,null,\"2\"]",+ "{\"x\":1,\"y\":\"2|3\"}", "\"Téléfilm \\u05e9\\u05dc\\u05d5\\u05dd & News\\nHD\"")+ fields.forEach { field -> values.forEach { value -> assertEquivalent("{\"$field\":$value}") } }+ assertEquivalent("{}")+ }++ @Test+ fun `matches nested category ids and duplicate keys`() {+ listOf(+ """{"stream_id":1,"stream_id":null,"name":"old","name":null,"num":3,"num":null}""",+ """{"name":"first","name":"last","tv_archive":1,"tv_archive":{}}""",+ """{"category_ids":{"a":["1","2"],"b":{"x":"3|4","y":null},"a":"5"}}""",+ """{"category_ids":[[" 1 ","'2'"],{"a":[3,null,"null"],"b":"[4,5]"},"",true]}""",+ """{"category_ids":"[]","stream_icon":{},"container_extension":[],"name":123}""",+ """{"stream_id":"+42","name":"One","unknown":{"stream_id":9,"values":[{},[],null]},"direct_source":"ignored"}""",+ """{'stream_id':'7','name':'escaped \\ quote','category_ids':'1|2|3'}"""+ ).forEach(::assertEquivalent)+ }++ @Test+ fun `matches deterministic mixed provider rows`() {+ val random = Random(15)+ val values = listOf("null", "true", "0", "1", "\" News HD \"", "\".M3U8\"", "\"1|2\"",+ "{\"key\":[\"2\",null,\"3\"]}", "[]", "[\"4\",\"5\"]")+ repeat(1_000) {+ val body = fields.shuffled(random).take(random.nextInt(1, fields.size))+ .joinToString(",", "{", "}") { "\"$it\":${values.random(random)}" }+ assertEquivalent(body)+ }+ }++ @Test+ fun `strict configuration rejects unknown keys`() {+ val failure = JsonReader(StringReader("""{"stream_id":1,"extra":"ignored only in lenient configuration"}""")).use {+ runCatching { XtreamLiveRowReader.read(it, ignoreUnknownKeys = false) }.exceptionOrNull()+ }+ assertThat(failure).isInstanceOf(XtreamParsingException::class.java)+ }++ @Test+ fun `category list nesting has an explicit bound`() {+ val body = "{\"category_ids\":" + "[".repeat(130) + "1" + "]".repeat(130) + "}"+ val failure = runCatching { read(body) }.exceptionOrNull()+ assertThat(failure).isInstanceOf(XtreamParsingException::class.java)+ }++ private fun assertEquivalent(body: String) {+ // This is the exact previous per-row conversion: Gson tree, JSON text,+ // then the lenient Kotlin DTO serializer. It also fixes duplicate keys.+ val expected = json.decodeFromString(XtreamLiveStreamRow.serializer(), JsonParser.parseString(body).toString())+ assertThat(read(body)).isEqualTo(expected)+ }++ private fun read(body: String): XtreamLiveStreamRow = JsonReader(StringReader(body)).use {+ it.isLenient = true+ XtreamLiveRowReader.read(it).also { _ -> assertThat(it.peek()).isEqualTo(JsonToken.END_DOCUMENT) }+ }++ private val fields = listOf("num", "name", "stream_id", "stream_icon", "epg_channel_id", "category_id",+ "category_name", "category_ids", "tv_archive", "tv_archive_duration", "container_extension", "is_adult")+}diff --git a/docs/XTREAM_SYNC_IMPROVEMENT_PLAN.md b/docs/XTREAM_SYNC_IMPROVEMENT_PLAN.mdindex 913dcd53..6b6ed669 100644--- a/docs/XTREAM_SYNC_IMPROVEMENT_PLAN.md+++ b/docs/XTREAM_SYNC_IMPROVEMENT_PLAN.md@@ -9,6 +9,7 @@ Supporting evidence:- [Current sync engine review](XTREAM_SYNC_PERFORMANCE_REVIEW.md)- [Initial backend baseline](XTREAM_SYNC_INITIAL_BASELINE.md)- [Attempt isolation and recovery implementation](XTREAM_SYNC_RECOVERY_IMPLEMENTATION.md)+- [Live parsing and group identity implementation](XTREAM_SYNC_PARSING_IMPLEMENTATION.md)The reference implementation provides hypotheses to investigate, not a designauthority or proof of correctness. Choose behavior for this app's measured@@ -278,6 +279,15 @@ P6 is the first live performance release milestone; P7 follows it. Keep actualproduction AUTO behavior unchanged until the P6 gate. Experiments before thenuse explicit STREAM_ALL or debug configuration, with identical data coverage.+Implementation progress on 2026-10-09: P0 has an initial backend baseline and+isolated fixture; its complete release-device/readiness comparison remains open.+P1 attempt isolation and conservative receipt-based recovery are implemented and+validated. P2 direct live decoding and cheaper group identity are implemented+with field-equivalence checks and measured component CPU reductions. P3–P8+remain pending. Repeated 10,000-row runs still show memory-driven category+fallback, so the default-strategy gate has not been met. See the implementation+reports linked above for exact evidence and limits.+## P0 measurement and fixture deliverablesAdd a dedicated configurable Xtream performance fixture; do not inflate thediff --git a/docs/XTREAM_SYNC_PARSING_IMPLEMENTATION.md b/docs/XTREAM_SYNC_PARSING_IMPLEMENTATION.mdnew file mode 100644index 00000000..40745618--- /dev/null+++ b/docs/XTREAM_SYNC_PARSING_IMPLEMENTATION.md@@ -0,0 +1,105 @@+# Xtream live parsing and group identity++Implemented after the attempt-isolation package on+`codex/xtream-live-sync-performance`, 2026-10-09.++## Changes++The thin live sync projection now reads tokens directly into its DTO. It skips+unknown fields without building their JSON trees and removes the Gson-tree to+JSON-text to Kotlin-serializer conversion for every row. The existing domain+mapper continues to decide channel admission, category identity, adult flags,+text compatibility, catch-up values, stream URLs and protection defaults.++Retained fields preserve lenient scalar/list behavior, missing/null defaults,+last-key-wins handling, including nested category objects, and text escaping.+The service honors strict unknown-key configuration. Category-list recursion has+an explicit depth limit. Truncated and malformed array syntax is classified as+parsing failure; transport failures and cancellation keep their own semantics.+The legacy decoder remains available through the existing compatibility path.++Group-ID generation now executes the existing canonical-name/key algorithm+directly. It avoids calculating playback resolution, codec, language, source,+transport and variant attributes that sync does not use. Playback classification+continues to calculate those attributes. Frequently used canonical separators+reuse compiled expressions. The group-ID format and canonicalization stay the+same, preserving grouping identity across refreshes and providers.++## Component measurements++API 36 Android TV x86_64 emulator, debug library instrumentation. Each scenario+uses 10,000 synthetic entries, two warmups per method and five measured samples,+alternating method order. Measurements use a monotonic wall clock and Android's+current-thread CPU clock. Every parser sample verifies row count and stream-ID+sum; every group-ID sample verifies the aggregate identity against classification.++| Component | Previous method median CPU | New method median CPU | Previous/new median wall | Previous/new median GC count |+| --- | ---: | ---: | ---: | ---: |+| Core live fields | 322.492 ms | 62.959 ms | 375.706 / 73.299 ms | 36 / 8 |+| Core fields plus ignored metadata | 480.483 ms | 62.703 ms | 534.320 / 69.136 ms | 30 / 4 |+| Group identity for tagged names | 7,138.095 ms | 1,335.489 ms | 8,101.808 / 1,513.209 ms | 505 / 117 |++The parser CPU reduction is about 80% for core fields and 87% with extra+metadata; group-ID CPU falls about 81% for these names. GC counts cover the+whole process and can include other work. These are component measurements,+excluding network, Room, the app graph, promotion and screen readiness. They+cannot establish a total-sync multiplier or release-device performance.++All 30 measured samples completed with matching fingerprints. Report:+`build/xtream-sync-performance/p2-components-20261009T174801Z/report.json`.+The synthetic instrumentation benchmark is+`XtreamLiveComponentBenchmarkTest#compareLiveDecoderAndGroupIdentity`.+It requires an explicit argument so routine correctness suites skip the timed+comparison:++```powershell+.\gradlew.bat :data:connectedDebugAndroidTest '-Pandroid.testInstrumentationRunnerArguments.class=com.streamvault.data.remote.xtream.XtreamLiveComponentBenchmarkTest#compareLiveDecoderAndGroupIdentity' -Pandroid.testInstrumentationRunnerArguments.xtreamLiveComponentBenchmark=true+```++## Correctness and integration++Differential decoder checks compare directly against the previous conversion,+covering every retained field across loose scalar types, nested category IDs,+duplicate keys, escaping and 1,000 deterministic mixed provider rows. Additional+checks cover strict unknown keys and the nesting bound. Group-ID equivalence+covers multilingual, accented, blank, punctuation-only, tagged and quality names+across multiple provider IDs, alongside existing expected-identity checks.++The final integration build passed 207 data and 16 domain tests and built both+isolated benchmark APKs. The instrumentation opt-in guard was also verified:+routine runs skip the component comparison.++Synthetic Add Provider and Settings Live refresh passed in all three requested+modes: six samples, 2,000 saved channels in every sample and successful cleanup.+The STREAM_ALL account issued two bulk requests and no category requests across+its initial/refresh lifecycle; its initial import took 1,137 ms and refresh+1,090 ms. These single samples are smoke evidence, not a performance median.+Report: `build/xtream-sync-performance/20261009T175109203489Z/report.json`.++A larger STREAM_ALL run used 10,000 rows/100 categories, one warmup and five+measured initial/refresh pairs. All 12 samples, including warmups, retained all+10,000 channels and passed cleanup. The completion marker and sample count+matched, instrumentation passed, and request history was not truncated.+Report: `build/xtream-sync-performance/20261009T175359801867Z/report.json`.++| Phase | All measured samples median | Maximum | Measured samples |+| --- | ---: | ---: | ---: |+| Initial import | 4,566.944 ms | 26,110.422 ms | 5 |+| Settings Live refresh | 4,579.747 ms | 27,734.189 ms | 5 |++These groups mix strategies. Two measured accounts used only bulk requests,+with initial/refresh medians of 4,488.678 / 4,566.173 ms (two samples per phase).+The other accounts mixed bulk with category requests. Logs confirmed three+low-memory aborts and one pre-request full-catalog skip; aborted attempts safely+fell back and retained complete counts. Maximum measured sampled Java heap was+15,331,632 bytes, but Android's system-memory signal changed independently.+Request high-water was one: this implementation has no new retrieval overlap.++The payload checksum matches the original 10,000-row baseline. That baseline+ran entirely through categories, so these results do not establish a before/after+bulk speedup or a reliable AUTO time. They demonstrate faster components, a+working bulk path and a remaining source of inconsistent import time.++AUTO strategy, request concurrency and healthy-provider pacing remain governed+by their existing rules. The bounded pipeline and category scheduling packages+follow before the default-strategy release gate.diff --git a/domain/src/main/java/com/streamvault/domain/util/ChannelNormalizer.kt b/domain/src/main/java/com/streamvault/domain/util/ChannelNormalizer.ktindex 48f6720e..0a81649e 100644--- a/domain/src/main/java/com/streamvault/domain/util/ChannelNormalizer.kt+++ b/domain/src/main/java/com/streamvault/domain/util/ChannelNormalizer.kt@@ -18,6 +18,8 @@ object ChannelNormalizer {private val nonAlphaNumericRegex = Regex("""[^a-z0-9 ]""")private val frameRateRegex = Regex("""(?<!\d)(24|25|30|50|60)\s*fps(?!\d)""", RegexOption.IGNORE_CASE)private val heightRegex = Regex("""(?<!\d)(4320|2160|1440|1080|720|576|540|480|360|240)\s*p?(?!\d)""", RegexOption.IGNORE_CASE)+ private val plusRegex = Regex("""\+""")+ private val colonOrPipeRegex = Regex("""[:|]""")private val resolutionTags = linkedMapOf("8k" to 4320,@@ -108,8 +110,10 @@ object ChannelNormalizer {.sortedByDescending { it.length }.map { phrase -> Regex("""(?<![a-z0-9])${Regex.escape(phrase)}(?![a-z0-9])""", RegexOption.IGNORE_CASE) }- fun getLogicalGroupId(channelName: String, providerId: Long): String =- classify(channelName, providerId).logicalGroupId+ fun getLogicalGroupId(channelName: String, providerId: Long): String {+ val originalName = channelName.trim().ifBlank { "Channel" }+ return buildLogicalGroupId(originalName, buildCanonicalName(originalName), providerId)+ }/*** Returns true when the channel name is wrapped in hash markers,@@ -154,22 +158,8 @@ object ChannelNormalizer {)val canonicalName = buildCanonicalName(originalName)- val logicalKey = canonicalName- .stripAccents()- .lowercase(Locale.ROOT)- .replace(nonAlphaNumericRegex, " ")- .replace(collapseWhitespaceRegex, " ")- .trim()- .replace(" ", "")- .ifEmpty {- originalName.stripAccents()- .lowercase(Locale.ROOT)- .replace(nonAlphaNumericRegex, "")- .ifBlank { "channel${providerId}" }- }-return ChannelClassification(- logicalGroupId = "${providerId}_$logicalKey",+ logicalGroupId = buildLogicalGroupId(originalName, canonicalName, providerId),canonicalName = canonicalName,attributes = LiveChannelVariantAttributes(resolutionLabel = declaredHeight?.let(::heightToResolutionLabel),@@ -187,6 +177,24 @@ object ChannelNormalizer {)}+ private fun buildLogicalGroupId(originalName: String, canonicalName: String, providerId: Long): String {+ val logicalKey = canonicalName+ .stripAccents()+ .lowercase(Locale.ROOT)+ .replace(nonAlphaNumericRegex, " ")+ .replace(collapseWhitespaceRegex, " ")+ .trim()+ .replace(" ", "")+ .ifEmpty {+ originalName.stripAccents()+ .lowercase(Locale.ROOT)+ .replace(nonAlphaNumericRegex, "")+ .ifBlank { "channel${providerId}" }+ }++ return "${providerId}_$logicalKey"+ }+private fun buildCanonicalName(originalName: String): String {var cleaned = originalName.replace(bracketRegex, " ")@@ -199,8 +207,8 @@ object ChannelNormalizer {cleaned = frameRateRegex.replace(cleaned, " ")cleaned = cleaned- .replace(Regex("""\+"""), " + ")- .replace(Regex("""[:|]"""), " ")+ .replace(plusRegex, " + ")+ .replace(colonOrPipeRegex, " ").replace(separatorRegex, " ").replace(collapseWhitespaceRegex, " ").trim()diff --git a/domain/src/test/java/com/streamvault/domain/util/ChannelNormalizerTest.kt b/domain/src/test/java/com/streamvault/domain/util/ChannelNormalizerTest.ktindex 6f5f63ba..53885e82 100644--- a/domain/src/test/java/com/streamvault/domain/util/ChannelNormalizerTest.kt+++ b/domain/src/test/java/com/streamvault/domain/util/ChannelNormalizerTest.kt@@ -5,6 +5,18 @@ import org.junit.Testclass ChannelNormalizerTest {+ @Test+ fun `import group ids remain identical to full playback classification`() {+ val names = listOf("", " ", "BBC One", "Téléfilm", "שלום חדשות", "العربية", "😀", "+++", "1080p", "US: HBO Max",+ "CNN (US)", "|UK| Sky Sports 1", "Canal+", "[HD] News", "News & Movies", "CHANNEL 60fps")+ val variants = listOf("", " HD", " FHD HEVC", " 4K HDR10 50fps", " [EN] Backup", " |FR| HLS VIP", " (8K Dolby Vision)")+ names.forEach { name -> variants.forEach { variant -> listOf(0L, 1L, 42L, Long.MAX_VALUE).forEach { provider ->+ val value = name + variant+ assertThat(ChannelNormalizer.getLogicalGroupId(value, provider))+ .isEqualTo(ChannelNormalizer.classify(value, provider, "https://stream.invalid/hls/1080.m3u8").logicalGroupId)+ } } }+ }+@Testfun `strips HD quality tag`() {val id = ChannelNormalizer.getLogicalGroupId("BBC One HD", 1L)