Skip to content

Commit 1a82172

Browse files
committed
add fps debugging flag
1 parent 9a96199 commit 1a82172

File tree

5 files changed

+61
-30
lines changed

5 files changed

+61
-30
lines changed

jni/jni/com_media_ffmpeg_FFMpegPlayer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,13 @@ com_media_ffmpeg_FFMpegPlayer_native_init(JNIEnv *env)
340340
jniThrowException(env, "java/lang/RuntimeException", "Can't find MediaPlayer.mNativeContext");
341341
return;
342342
}
343-
/*
343+
344344
fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
345345
"(Ljava/lang/Object;IIILjava/lang/Object;)V");
346346
if (fields.post_event == NULL) {
347347
jniThrowException(env, "java/lang/RuntimeException", "Can't find FFMpegMediaPlayer.postEventFromNative");
348348
return;
349349
}
350-
*/
351350
}
352351

353352
static void

jni/jni/onLoad.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ int jniThrowException(JNIEnv* env, const char* className, const char* msg) {
5252
JNIEnv* getJNIEnv() {
5353
JNIEnv* env = NULL;
5454
if (sVm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
55-
__android_log_print(ANDROID_LOG_ERROR,
56-
TAG,
57-
"Failed to obtain JNIEnv");
58-
return NULL;
55+
__android_log_print(ANDROID_LOG_ERROR,
56+
TAG,
57+
"Failed to obtain JNIEnv");
58+
return NULL;
5959
}
6060
return env;
6161
}

jni/libmediaplayer/mediaplayer.cpp

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern "C" {
2525
#include "mediaplayer.h"
2626
#include "output.h"
2727

28+
#define FPS_DEBUGGING false
29+
2830
static MediaPlayer* sPlayer;
2931

3032
MediaPlayer::MediaPlayer()
@@ -263,27 +265,25 @@ bool MediaPlayer::shouldCancel(PacketQueue* queue)
263265
&& queue->size() == 0));
264266
}
265267

266-
267-
/*
268-
timeval pTime;
269-
int frames = 0;
270-
double t1 = -1;
271-
double t2 = -1;
272-
273-
gettimeofday(&pTime, NULL);
274-
t2=pTime.tv_sec+(pTime.tv_usec/1000000.0);
275-
if(t1 == -1 || t2 > t1 + 1)
276-
{
277-
__android_log_print(ANDROID_LOG_ERROR, TAG, "Video frame rate: %ifps", frames);
278-
t1=t2;
279-
frames = 0;
280-
}
281-
frames++;
282-
283-
*/
284-
285268
void MediaPlayer::decode(AVFrame* frame, double pts)
286269
{
270+
if(FPS_DEBUGGING) {
271+
timeval pTime;
272+
static int frames = 0;
273+
static double t1 = -1;
274+
static double t2 = -1;
275+
276+
gettimeofday(&pTime, NULL);
277+
t2 = pTime.tv_sec + (pTime.tv_usec / 1000000.0);
278+
if (t1 == -1 || t2 > t1 + 1) {
279+
__android_log_print(ANDROID_LOG_INFO, TAG, "Video fps:%i", frames);
280+
//sPlayer->notify(MEDIA_INFO_FRAMERATE_VIDEO, frames, -1);
281+
t1 = t2;
282+
frames = 0;
283+
}
284+
frames++;
285+
}
286+
287287
// Convert the image from its native format to RGB
288288
sws_scale(sPlayer->mConvertCtx,
289289
frame->data,
@@ -298,6 +298,23 @@ void MediaPlayer::decode(AVFrame* frame, double pts)
298298

299299
void MediaPlayer::decode(int16_t* buffer, int buffer_size)
300300
{
301+
if(FPS_DEBUGGING) {
302+
timeval pTime;
303+
static int frames = 0;
304+
static double t1 = -1;
305+
static double t2 = -1;
306+
307+
gettimeofday(&pTime, NULL);
308+
t2 = pTime.tv_sec + (pTime.tv_usec / 1000000.0);
309+
if (t1 == -1 || t2 > t1 + 1) {
310+
__android_log_print(ANDROID_LOG_INFO, TAG, "Audio fps:%i", frames);
311+
//sPlayer->notify(MEDIA_INFO_FRAMERATE_AUDIO, frames, -1);
312+
t1 = t2;
313+
frames = 0;
314+
}
315+
frames++;
316+
}
317+
301318
if(Output::AudioDriver_write(buffer, buffer_size) <= 0) {
302319
__android_log_print(ANDROID_LOG_ERROR, TAG, "Couldn't write samples to audio track");
303320
}
@@ -505,13 +522,13 @@ void MediaPlayer::ffmpegNotify(void* ptr, int level, const char* fmt, va_list vl
505522

506523
void MediaPlayer::notify(int msg, int ext1, int ext2)
507524
{
508-
__android_log_print(ANDROID_LOG_INFO, TAG, "message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
525+
//__android_log_print(ANDROID_LOG_INFO, TAG, "message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
509526
bool send = true;
510527
bool locked = false;
511528

512529
if ((mListener != 0) && send) {
513-
__android_log_print(ANDROID_LOG_INFO, TAG, "callback application");
530+
//__android_log_print(ANDROID_LOG_INFO, TAG, "callback application");
514531
mListener->notify(msg, ext1, ext2);
515-
__android_log_print(ANDROID_LOG_INFO, TAG, "back from callback");
532+
//__android_log_print(ANDROID_LOG_INFO, TAG, "back from callback");
516533
}
517534
}

jni/libmediaplayer/mediaplayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ enum media_info_type {
8686
MEDIA_INFO_NOT_SEEKABLE = 801,
8787
// New media metadata is available.
8888
MEDIA_INFO_METADATA_UPDATE = 802,
89+
90+
MEDIA_INFO_FRAMERATE_VIDEO = 900,
91+
MEDIA_INFO_FRAMERATE_AUDIO,
8992
};
9093

9194

src/com/media/ffmpeg/FFMpegPlayer.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.media.ffmpeg;
22

33
import android.os.PowerManager;
4+
import android.util.Log;
45
import android.view.Surface;
56
import android.view.SurfaceHolder;
67
import android.media.AudioManager;
@@ -66,6 +67,9 @@ public class FFMpegPlayer
6667
*/
6768
public static final int MEDIA_INFO_METADATA_UPDATE = 802;
6869

70+
public static final int MEDIA_INFO_FRAMERATE_VIDEO = 900;
71+
public static final int MEDIA_INFO_FRAMERATE_AUDIO = 901;
72+
6973
private final static String TAG = "MediaPlayer";
7074

7175
private int mNativeContext; // accessed by native methods
@@ -96,7 +100,15 @@ public FFMpegPlayer() {
96100
*/
97101
private static void postEventFromNative(Object mediaplayer_ref,
98102
int what, int arg1, int arg2, Object obj)
99-
{
103+
{
104+
switch(what) {
105+
case MEDIA_INFO_FRAMERATE_VIDEO:
106+
Log.d(TAG, "Video fps:" + arg1);
107+
break;
108+
case MEDIA_INFO_FRAMERATE_AUDIO:
109+
Log.d(TAG, "Audio fps:" + arg1);
110+
break;
111+
}
100112
}
101113

102114
/**
@@ -334,7 +346,7 @@ private void updateSurfaceScreenOn() {
334346

335347

336348

337-
private static native final void native_init();
349+
private static native final void native_init() throws RuntimeException;
338350
private native final void native_setup(Object mediaplayer_this);
339351
private native final void native_finalize();
340352

0 commit comments

Comments
 (0)