Skip to content

Commit

Permalink
add source and incoming video resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Nov 7, 2023
1 parent d569cd1 commit 592ad11
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/zoffcc/applications/ffmpegav/AVActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class AVActivity {

private static final String TAG = "ffmpegav.AVActivity";
static final String Version = "0.99.5";
static final String Version = "0.99.6";

public static native String ffmpegav_version();
public static native String ffmpegav_libavutil_version();
Expand All @@ -27,7 +27,7 @@ public class AVActivity {
final static java.nio.ByteBuffer audio_buffer_2 = java.nio.ByteBuffer.allocateDirect(audio_buffer_size_in_bytes2);

public static interface video_capture_callback {
void onSuccess(long width, long height, long pts, int fps);
void onSuccess(long width, long height, long source_width, long source_height, long pts, int fps);
void onError();
}
static video_capture_callback video_capture_callback_function = null;
Expand All @@ -52,11 +52,11 @@ public static void ffmpegav_set_video_capture_callback(video_capture_callback ca
video_capture_callback_function = callback;
}

public static void ffmpegav_callback_video_capture_frame_pts_cb_method(long width, long height, long pts, int fps)
public static void ffmpegav_callback_video_capture_frame_pts_cb_method(long width, long height, long source_width, long source_height, long pts, int fps)
{
// Log.i(TAG, "capture video frame w: " + width + " h: " + height + " pts: " + pts);
if (video_capture_callback_function != null) {
video_capture_callback_function.onSuccess(width, height, pts, fps);
video_capture_callback_function.onSuccess(width, height, source_width, source_height, pts, fps);
}
}

Expand Down Expand Up @@ -296,8 +296,8 @@ public static void main(String[] args) {

ffmpegav_set_video_capture_callback(new video_capture_callback() {
@Override
public void onSuccess(long width, long height, long pts, int fps) {
Log.i(TAG, "ffmpeg open video capture onSuccess:" + width + " " + height + " " + pts + " fps:" + fps);
public void onSuccess(long width, long height, long source_width, long source_height, long pts, int fps) {
Log.i(TAG, "ffmpeg open video capture onSuccess:" + width + " " + height + " " + source_width + " " + source_height + " " + pts + " fps:" + fps);
}
@Override
public void onError() {
Expand Down
20 changes: 13 additions & 7 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,13 @@ fun App()
}
)
val current_vplayfps_state by avstatestorevplayfpsstate.stateFlow.collectAsState()
Text(" fps: " + current_vplayfps_state.videoplayfps_state,
Text(if (current_vplayfps_state.videoplayfps_state == 0) "" else (" fps: " + current_vplayfps_state.videoplayfps_state),
fontSize = 13.sp,
modifier = Modifier.height(20.dp),
maxLines = 1)
Text(" " + current_vplayfps_state.incomingResolution,
fontSize = 13.sp,
maxLines = 1)
}
Column {
Icon(modifier = Modifier.padding(5.dp)
Expand Down Expand Up @@ -391,7 +394,10 @@ fun App()
update = {Log.i(TAG, "update2: " + video_out_box_small) }
)
val current_vicfps_state by avstatestorevcapfpsstate.stateFlow.collectAsState()
Text("fps: " + current_vicfps_state.videocapfps_state,
Text(if (current_vicfps_state.videocapfps_state == 0) "" else ("fps: " + current_vicfps_state.videocapfps_state),
fontSize = 13.sp,
maxLines = 1)
Text("" + current_vicfps_state.sourceResolution,
fontSize = 13.sp,
maxLines = 1)
}
Expand All @@ -405,8 +411,8 @@ fun App()
var video_in_devices by remember { mutableStateOf(ArrayList<String>()) }
val video_in_sources by remember { mutableStateOf(ArrayList<String>()) }
Column(modifier = Modifier.padding(5.dp)) {
Text(text = "audio in: " + avstatestore.state.audio_in_device_get() + " " + avstatestore.state.audio_in_source_get()
, fontSize = 13.sp, modifier = Modifier.fillMaxWidth(),
Text(text = "audio capture: " + avstatestore.state.audio_in_device_get() + " " + avstatestore.state.audio_in_source_get()
, fontSize = 12.sp, modifier = Modifier.fillMaxWidth(),
maxLines = 1)
Box {
IconButton(onClick = {
Expand Down Expand Up @@ -500,8 +506,8 @@ fun App()
}
}

Text("video in: " + avstatestore.state.video_in_device_get() + " " + avstatestore.state.video_in_source_get()
, fontSize = 13.sp, modifier = Modifier.fillMaxWidth(),
Text("video capture: " + avstatestore.state.video_in_device_get() + " " + avstatestore.state.video_in_source_get()
, fontSize = 12.sp, modifier = Modifier.fillMaxWidth(),
maxLines = 1)
Box {
IconButton(onClick = {
Expand Down Expand Up @@ -625,7 +631,7 @@ fun App()
modifier = Modifier.size(16.dp)) {
Icon(Icons.Filled.Refresh, null)
}
val items = listOf("640x480", "480x640", "1280x720", "720x1280")
val items = listOf("480x270", "640x480", "480x640", "960x540", "1280x720", "720x1280", "1920x1080", "1080x1920")
DropdownMenu(expanded = resolution_expanded,
onDismissRequest = { resolution_expanded = false },
){
Expand Down
46 changes: 43 additions & 3 deletions src/main/kotlin/com/zoffcc/applications/trifa/AVState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import java.io.File
import java.nio.ByteBuffer

data class AVStateCallState(val call_state: AVState.CALL_STATUS = AVState.CALL_STATUS.CALL_STATUS_NONE)
data class AVStateVideoCaptureFpsState(val videocapfps_state: Int = 0)
data class AVStateVideoPlayFpsState(val videoplayfps_state: Int = 0)
data class AVStateVideoCaptureFpsState(val videocapfps_state: Int = 0, val sourceResolution: String = "")
data class AVStateVideoPlayFpsState(val videoplayfps_state: Int = 0, val incomingResolution: String = "")

data class AVState(val a: Int)
{
Expand Down Expand Up @@ -55,6 +55,8 @@ data class AVState(val a: Int)
private var video_in_source = ""
private var video_in_resolution_width = 640
private var video_in_resolution_height = 480
private var video_in_source_resolution_width = 0
private var video_in_source_resolution_height = 0
private var current_video_in_fps = 0
var calling_state = CALL_STATUS.CALL_STATUS_NONE
private var devices_state = CALL_DEVICES_STATE.CALL_DEVICES_STATE_CLOSED
Expand Down Expand Up @@ -162,6 +164,24 @@ data class AVState(val a: Int)
}
}

fun video_in_source_resolution_get(): String
{
return (video_in_source_resolution_width.toString() + "x" + video_in_source_resolution_height.toString())
}

fun video_in_source_resolution_set(value: String?)
{
if ((value != null) && (value.length > 2))
{
try
{
video_in_source_resolution_width = value.split("x", limit = 2)[0].toInt()
video_in_source_resolution_height = value.split("x", limit = 2)[1].toInt()
} catch (_: Exception) {
}
}
}

fun current_video_in_fps_get(): Int
{
return current_video_in_fps
Expand Down Expand Up @@ -505,13 +525,19 @@ data class AVState(val a: Int)

AVActivity.ffmpegav_set_video_capture_callback(object : AVActivity.video_capture_callback
{
override fun onSuccess(width: Long, height: Long, pts: Long, fps: Int)
override fun onSuccess(width: Long, height: Long, source_width: Long, source_height: Long, pts: Long, fps: Int)
{
// Log.i(TAG, "ffmpeg open video capture onSuccess: $width $height $pts FPS: $fps")
if (current_video_in_fps_get() != fps) {
current_video_in_fps_set(fps)
avstatestorevcapfpsstate.update(fps)
}
if (!("" + source_width + "x" + source_height).equals(avstatestorevcapfpsstate.state.sourceResolution))
{
video_in_source_resolution_set("" + source_width + "x" + source_height)
avstatestorevcapfpsstate.updateSourceResolution("" + source_width + "x" + source_height)
}

val frame_width_px: Int = width.toInt()
val frame_height_px: Int = height.toInt()
val buffer_size_in_bytes3 = (frame_width_px * frame_height_px * 1.5f).toInt()
Expand Down Expand Up @@ -571,6 +597,7 @@ interface AVStateStoreVideoCaptureFpsState
val stateFlow: StateFlow<AVStateVideoCaptureFpsState>
val state get() = stateFlow.value
fun update(fps: Int)
fun updateSourceResolution(sourceResolution: String)
}

fun CoroutineScope.createAVStateStoreVideoCaptureFpsState(): AVStateStoreVideoCaptureFpsState
Expand All @@ -586,6 +613,12 @@ fun CoroutineScope.createAVStateStoreVideoCaptureFpsState(): AVStateStoreVideoCa
mutableStateFlow.value = state.copy(videocapfps_state = fps)
}
}
override fun updateSourceResolution(sourceResolution: String)
{
launch {
mutableStateFlow.value = state.copy(sourceResolution = sourceResolution)
}
}
}
}

Expand All @@ -594,6 +627,7 @@ interface AVStateStoreVideoPlayFpsState
val stateFlow: StateFlow<AVStateVideoPlayFpsState>
val state get() = stateFlow.value
fun update(fps: Int)
fun updateIncomingResolution(incomingResolution: String)
}

fun CoroutineScope.createAVStateStoreVideoPlayFpsState(): AVStateStoreVideoPlayFpsState
Expand All @@ -609,6 +643,12 @@ fun CoroutineScope.createAVStateStoreVideoPlayFpsState(): AVStateStoreVideoPlayF
mutableStateFlow.value = state.copy(videoplayfps_state = fps)
}
}
override fun updateIncomingResolution(incomingResolution: String)
{
launch {
mutableStateFlow.value = state.copy(incomingResolution = incomingResolution)
}
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import UIGroupMessage
import UIMessage
import User
import avstatestore
import avstatestorevcapfpsstate
import avstatestorevplayfpsstate
import com.zoffcc.applications.ffmpegav.AVActivity.ffmpegav_loadjni
import com.zoffcc.applications.sorm.FileDB
Expand Down Expand Up @@ -948,6 +949,15 @@ class MainActivity
}
}
new_video_in_frame(video_buffer_1, frame_width_px1, frame_height_px1)
try
{
if (!("" + frame_width_px + "x" + frame_height_px).equals(avstatestorevplayfpsstate.state.incomingResolution)) {
avstatestorevplayfpsstate.updateIncomingResolution("" + frame_width_px + "x" + frame_height_px)
}
}
catch(e: Exception)
{
}
}

@OptIn(DelicateCoroutinesApi::class)
Expand Down Expand Up @@ -1004,6 +1014,11 @@ class MainActivity
VideoInFrame.clear_video_in_frame()
AudioBar.set_cur_value(0, audio_in_bar)
AudioBar.set_cur_value(0, audio_out_bar)
avstatestorevplayfpsstate.updateIncomingResolution("")
avstatestorevplayfpsstate.update(0)
avstatestorevcapfpsstate.updateSourceResolution("")
avstatestorevcapfpsstate.update(0)

}

@JvmStatic
Expand Down

0 comments on commit 592ad11

Please sign in to comment.