Skip to content

Commit

Permalink
report source video format in callback and try to set wanted capture …
Browse files Browse the repository at this point in the history
…resolution
  • Loading branch information
zoff99 committed Nov 9, 2023
1 parent 5d864b4 commit 834028d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
57 changes: 51 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.6";
static final String Version = "0.99.7";

public static native String ffmpegav_version();
public static native String ffmpegav_libavutil_version();
Expand All @@ -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;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
19 changes: 16 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,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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ class MainActivity
avstatestorevplayfpsstate.updateIncomingResolution("")
avstatestorevplayfpsstate.update(0)
avstatestorevcapfpsstate.updateSourceResolution("")
avstatestorevcapfpsstate.updateSourceFormat("")
avstatestorevcapfpsstate.update(0)

}
Expand Down

0 comments on commit 834028d

Please sign in to comment.