diff --git a/src/main/java/com/zoffcc/applications/ffmpegav/AVActivity.java b/src/main/java/com/zoffcc/applications/ffmpegav/AVActivity.java index 02c13962..19cc2439 100644 --- a/src/main/java/com/zoffcc/applications/ffmpegav/AVActivity.java +++ b/src/main/java/com/zoffcc/applications/ffmpegav/AVActivity.java @@ -5,7 +5,7 @@ public class AVActivity { private static final String TAG = "ffmpegav.AVActivity"; - static final String Version = "0.99.6"; + static final String Version = "0.99.7"; public static native String ffmpegav_version(); public static native String ffmpegav_libavutil_version(); @@ -23,11 +23,54 @@ public class AVActivity { public static native int ffmpegav_close_audio_in_device(); public static native int ffmpegav_close_video_in_device(); + public static enum ffmpegav_video_source_format_name + { + // HINT: for more values see "codec_id.h" of ffmpeg source code + AV_CODEC_ID_NONE(0), + AV_CODEC_ID_MPEG1VIDEO(1), + AV_CODEC_ID_MPEG2VIDEO(2), + AV_CODEC_ID_H261(3), + AV_CODEC_ID_H263(4), + AV_CODEC_ID_RV10(5), + AV_CODEC_ID_RV20(6), + AV_CODEC_ID_MJPEG(7), + AV_CODEC_ID_RAWVIDEO(13), + AV_CODEC_ID_H264(27); + + public int value; + + private ffmpegav_video_source_format_name(int value) + { + this.value = value; + } + + public static String value_str(int value) + { + if (value == AV_CODEC_ID_NONE.value) + { + return "CODEC: NONE"; + } + else if (value == AV_CODEC_ID_MJPEG.value) + { + return "MJPEG"; + } + else if (value == AV_CODEC_ID_RAWVIDEO.value) + { + return "RAWVIDEO"; + } + else if (value == AV_CODEC_ID_H264.value) + { + return "H264"; + } + return "UNKNOWN"; + } + } + final static int audio_buffer_size_in_bytes2 = 20000; 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 source_width, long source_height, long pts, int fps); + void onSuccess(long width, long height, long source_width, long source_height, long pts, int fps, int source_format); void onError(); } static video_capture_callback video_capture_callback_function = null; @@ -52,11 +95,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 source_width, long source_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, int source_format) { // 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, source_width, source_height, pts, fps); + video_capture_callback_function.onSuccess(width, height, source_width, source_height, pts, fps, source_format); } } @@ -296,8 +339,10 @@ public static void main(String[] args) { ffmpegav_set_video_capture_callback(new video_capture_callback() { @Override - 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); + public void onSuccess(long width, long height, long source_width, long source_height, long pts, int fps, int source_format) { + Log.i(TAG, "ffmpeg open video capture onSuccess:" + width + " " + height + " " + + source_width + " " + source_height + " " + pts + " fps: " + fps + + " source_format: " + ffmpegav_video_source_format_name.value_str(source_format)); } @Override public void onError() { diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index dd4231ae..7f15cd96 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -400,6 +400,9 @@ fun App() Text("" + current_vicfps_state.sourceResolution, fontSize = 13.sp, maxLines = 1) + Text("" + current_vicfps_state.sourceFormat, + fontSize = 13.sp, + maxLines = 1) } var expanded_a by remember { mutableStateOf(false) } diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/AVState.kt b/src/main/kotlin/com/zoffcc/applications/trifa/AVState.kt index 6f55fc3e..3a7970dd 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/AVState.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/AVState.kt @@ -19,7 +19,7 @@ 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, val sourceResolution: String = "") +data class AVStateVideoCaptureFpsState(val videocapfps_state: Int = 0, val sourceResolution: String = "", val sourceFormat: String = "") data class AVStateVideoPlayFpsState(val videoplayfps_state: Int = 0, val incomingResolution: String = "") data class AVState(val a: Int) @@ -525,9 +525,10 @@ data class AVState(val a: Int) AVActivity.ffmpegav_set_video_capture_callback(object : AVActivity.video_capture_callback { - override fun onSuccess(width: Long, height: Long, source_width: Long, source_height: Long, pts: Long, fps: Int) + override fun onSuccess(width: Long, height: Long, source_width: Long, source_height: Long, pts: Long, fps: Int, source_format: Int) { - // Log.i(TAG, "ffmpeg open video capture onSuccess: $width $height $pts FPS: $fps") + Log.i(TAG, "ffmpeg open video capture onSuccess: $width $height $pts FPS: $fps Source Format: " + + AVActivity.ffmpegav_video_source_format_name.value_str(source_format)) if (current_video_in_fps_get() != fps) { current_video_in_fps_set(fps) avstatestorevcapfpsstate.update(fps) @@ -538,6 +539,11 @@ data class AVState(val a: Int) avstatestorevcapfpsstate.updateSourceResolution("" + source_width + "x" + source_height) } + if (!AVActivity.ffmpegav_video_source_format_name.value_str(source_format).equals(avstatestorevcapfpsstate.state.sourceFormat)) + { + avstatestorevcapfpsstate.updateSourceFormat(AVActivity.ffmpegav_video_source_format_name.value_str(source_format)) + } + 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() @@ -598,6 +604,7 @@ interface AVStateStoreVideoCaptureFpsState val state get() = stateFlow.value fun update(fps: Int) fun updateSourceResolution(sourceResolution: String) + fun updateSourceFormat(sourceFormat: String) } fun CoroutineScope.createAVStateStoreVideoCaptureFpsState(): AVStateStoreVideoCaptureFpsState @@ -619,6 +626,12 @@ fun CoroutineScope.createAVStateStoreVideoCaptureFpsState(): AVStateStoreVideoCa mutableStateFlow.value = state.copy(sourceResolution = sourceResolution) } } + override fun updateSourceFormat(sourceFormat: String) + { + launch { + mutableStateFlow.value = state.copy(sourceFormat = sourceFormat) + } + } } } diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt index c89e7fa8..377976f8 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt @@ -1017,6 +1017,7 @@ class MainActivity avstatestorevplayfpsstate.updateIncomingResolution("") avstatestorevplayfpsstate.update(0) avstatestorevcapfpsstate.updateSourceResolution("") + avstatestorevcapfpsstate.updateSourceFormat("") avstatestorevcapfpsstate.update(0) }