Skip to content

Commit 1d0a1ca

Browse files
committed
Reorg code
1 parent 6c59bf4 commit 1d0a1ca

File tree

3 files changed

+3
-32
lines changed

3 files changed

+3
-32
lines changed

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/live/BidiViewModel.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import com.google.firebase.Firebase
1111
import com.google.firebase.ai.FirebaseAI
1212
import com.google.firebase.ai.type.FunctionCallPart
1313
import com.google.firebase.ai.type.FunctionResponsePart
14-
import com.google.firebase.ai.type.InlineDataPart
14+
import com.google.firebase.ai.type.InlineData
1515
import com.google.firebase.ai.type.LiveSession
1616
import com.google.firebase.ai.type.PublicPreviewAPI
1717
import com.google.firebase.ai.type.ResponseModality
@@ -22,15 +22,11 @@ import com.google.firebase.app
2222
import com.google.firebase.quickstart.ai.FIREBASE_AI_SAMPLES
2323
import com.google.firebase.quickstart.ai.feature.live.StreamRealtimeRoute
2424
import com.google.firebase.quickstart.ai.feature.text.functioncalling.WeatherRepository.Companion.fetchWeather
25-
import kotlinx.coroutines.CoroutineScope
26-
import kotlinx.coroutines.Dispatchers
27-
import kotlinx.coroutines.delay
2825
import kotlinx.coroutines.launch
2926
import kotlinx.coroutines.runBlocking
3027
import kotlinx.serialization.json.JsonObject
3128
import kotlinx.serialization.json.jsonPrimitive
3229
import java.io.ByteArrayOutputStream
33-
import kotlin.time.Duration.Companion.seconds
3430

3531
@OptIn(PublicPreviewAPI::class)
3632
class BidiViewModel(
@@ -97,7 +93,7 @@ class BidiViewModel(
9793
val jpegBytes = byteArrayOutputStream.toByteArray()
9894

9995
liveSession.sendVideoRealtime(
100-
InlineDataPart(jpegBytes, "image/jpeg")
96+
InlineData(jpegBytes, "image/jpeg")
10197
)
10298
}
10399
}

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/live/CameraView.kt

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,4 @@ private class SecondIntervalAnalyzer(private val onFrameCaptured: (Bitmap) -> Un
9797
}
9898
image.close()
9999
}
100-
}
101-
102-
@SuppressLint("UnsafeOptInUsageError")
103-
private fun ImageProxy.toBitmap(): Bitmap {
104-
val yBuffer = planes[0].buffer // Y
105-
val uBuffer = planes[1].buffer // U
106-
val vBuffer = planes[2].buffer // V
107-
108-
val ySize = yBuffer.remaining()
109-
val uSize = uBuffer.remaining()
110-
val vSize = vBuffer.remaining()
111-
112-
val nv21 = ByteArray(ySize + uSize + vSize)
113-
114-
//U and V are swapped
115-
yBuffer.get(nv21, 0, ySize)
116-
vBuffer.get(nv21, ySize, vSize)
117-
uBuffer.get(nv21, ySize + vSize, uSize)
118-
119-
val yuvImage = YuvImage(nv21, ImageFormat.NV21, this.width, this.height, null)
120-
val out = ByteArrayOutputStream()
121-
yuvImage.compressToJpeg(Rect(0, 0, yuvImage.width, yuvImage.height), 100, out)
122-
val imageBytes = out.toByteArray()
123-
return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
124-
}
100+
}

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/live/StreamRealtimeVideoScreen.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.google.firebase.quickstart.ai.feature.live
22

33
import android.Manifest
4-
import android.graphics.Bitmap
54
import androidx.annotation.RequiresPermission
65
import androidx.compose.foundation.layout.Box
76
import androidx.compose.foundation.layout.fillMaxHeight

0 commit comments

Comments
 (0)