Skip to content

Commit

Permalink
Shows the current selected bitrate and the corresponding Representati…
Browse files Browse the repository at this point in the history
…onID as an overlay on top of the video. (#23)
  • Loading branch information
dsilhavy authored Aug 16, 2023
1 parent a29035c commit eea1162
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 3 deletions.
1 change: 1 addition & 0 deletions fivegmag_5GMSdAwareApplication/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.fivegmag:a5gmscommonlibrary:1.0.2'
implementation 'com.fivegmag:a5gmsmediastreamhandler:1.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
<!--<entry key="m8LocalAfAndAs">m8/config_local_af.json</entry>-->
<entry key="m85GMAGHost">https://rt.5g-mag.com/</entry>
<!-- <entry key="m8LocalDummyHost">http://10.147.67.179:3003/m8/</entry>-->
<entry key="m8LocalDummyHost">http://192.168.178.78:3003/m8/</entry>
<!-- <entry key="m8LocalDummyHost">http://194.95.175.90:3003/m8/</entry> -->
</properties>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.Spinner
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.media3.common.util.UnstableApi
import com.fivegmag.a5gmscommonlibrary.models.EntryPoint
Expand All @@ -26,6 +27,7 @@ import com.fivegmag.a5gmsmediastreamhandler.MediaSessionHandlerAdapter
import androidx.media3.ui.PlayerView
import kotlinx.serialization.json.*
import okhttp3.ResponseBody
import org.greenrobot.eventbus.EventBus
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -38,10 +40,12 @@ import java.util.*

const val TAG = "5GMS Aware Application"

@UnstableApi class MainActivity : AppCompatActivity(), AdapterView.OnItemSelectedListener {
@UnstableApi
class MainActivity : AppCompatActivity(), AdapterView.OnItemSelectedListener {

private val mediaSessionHandlerAdapter = MediaSessionHandlerAdapter()
private val exoPlayerAdapter = ExoPlayerAdapter()
private val mediaStreamHandlerEventHandler = MediaStreamHandlerEventHandler()
private var currentSelectedStreamIndex: Int = 0
private lateinit var currentSelectedM8Key: String
private lateinit var m8InterfaceApi: M8InterfaceApi
Expand All @@ -63,17 +67,25 @@ const val TAG = "5GMS Aware Application"
exoPlayerAdapter,
::onConnectionToMediaSessionHandlerEstablished
)
val representationInfoTextView = findViewById<TextView>(R.id.representationInfo)
mediaStreamHandlerEventHandler.initialize(representationInfoTextView, this)
} catch (e: Exception) {
e.printStackTrace()
}
}

override fun onStop() {
EventBus.getDefault().unregister(mediaStreamHandlerEventHandler);
super.onStop()
// Unbind from the service
mediaSessionHandlerAdapter.reset(this)
}

override fun onStart() {
super.onStart()
EventBus.getDefault().register(mediaStreamHandlerEventHandler);
}

private fun loadConfiguration() {
try {
val inputStream: InputStream = this.assets.open("config.properties.xml")
Expand Down Expand Up @@ -168,22 +180,24 @@ const val TAG = "5GMS Aware Application"
R.id.idStreamSpinner -> {
currentSelectedStreamIndex = position
}

R.id.idM8Spinner -> {
currentSelectedM8Key = parent.selectedItem as String
val selectedUri = URI(configProperties.getProperty(currentSelectedM8Key))
if(selectedUri.isAbsolute) {
if (selectedUri.isAbsolute) {
setM8DataViaEndpoint(selectedUri.toString())
} else {
setM8DataViaJson(selectedUri.toString())
}
}

else -> { // Note the block
}
}
}
}

private fun setM8DataViaEndpoint(m8HostingEndpoint : String) {
private fun setM8DataViaEndpoint(m8HostingEndpoint: String) {
try {
initializeRetrofitForM8InterfaceApi(m8HostingEndpoint)
val call: Call<ResponseBody>? =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.fivegmag.a5gmsdawareapplication

import android.content.Context
import android.widget.TextView
import androidx.media3.common.util.UnstableApi
import com.fivegmag.a5gmscommonlibrary.eventbus.DownstreamFormatChangedEvent
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

@UnstableApi
/**
* This class handles messages that are dispatched by the Media Stream Handler.
* Implements a pub/sub pattern using the eventbus library.
*
*/
class MediaStreamHandlerEventHandler {

private lateinit var representationInfoTextView: TextView
private lateinit var context: Context

fun initialize(repInfoTextView: TextView, ctxt: Context) {
representationInfoTextView = repInfoTextView
context = ctxt
}

@Subscribe(threadMode = ThreadMode.MAIN)
fun onDownstreamFormatChangedEvent(event: DownstreamFormatChangedEvent) {
// Handle the event
if (event.mediaLoadData.trackFormat?.containerMimeType?.contains(
"video",
ignoreCase = true
) == true
) {
val kbitsPerSecond =
event.mediaLoadData.trackFormat?.peakBitrate?.div(1000).toString()
val id = event.mediaLoadData.trackFormat?.id.toString()
val text = context.getString(R.string.representationInfo, kbitsPerSecond, id)
representationInfoTextView.text = text
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/idStreamSpinner" />

<TextView
android:id="@+id/representationInfo"
android:layout_width="348dp"
android:layout_height="19dp"
android:text=""
android:textColor="#FFFFFF"
app:layout_constraintStart_toStartOf="@+id/idExoPlayerVIew"
app:layout_constraintTop_toTopOf="@+id/idExoPlayerVIew" />


</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/idStreamSpinner" />

<TextView
android:id="@+id/representationInfo"
android:layout_width="352dp"
android:layout_height="23dp"
android:text=""
android:textColor="#FFFFFF"
app:layout_constraintStart_toStartOf="@+id/idExoPlayerVIew"
app:layout_constraintTop_toTopOf="@+id/idExoPlayerVIew" />


</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<string name="labelM8Selection">Select M8 Input</string>
<string name="labelStreamSelection">Select a Stream</string>
<string name="startPlaybackButton">Start Playback</string>
<string name="representationInfo">%1$s kbit/s - Rep ID: %2$s</string>
</resources>

0 comments on commit eea1162

Please sign in to comment.