Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add display URL and statistic info in playback UI for troubleshooting… #5266

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.TableLayout;

import java.util.Date;
import java.util.Locale;
import java.text.SimpleDateFormat;

import tv.danmaku.ijk.media.player.IMediaPlayer;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
Expand All @@ -20,6 +23,7 @@ public class InfoHudViewHolder {
private IMediaPlayer mMediaPlayer;
private long mLoadCost = 0;
private long mSeekCost = 0;
private final static String TAG = InfoHudViewHolder.class.getName();

public InfoHudViewHolder(Context context, TableLayout tableLayout) {
mTableLayoutBinder = new TableLayoutBinder(context, tableLayout);
Expand Down Expand Up @@ -119,6 +123,29 @@ public void handleMessage(Message msg) {
if (mp == null)
break;

String url = mp.getDataSource();
if (url == null)
break;
String tmpUrl = "";
int lineLength = 30;
int endPos = 0;
int beginPos = 0;
int otherLength = url.length();
for (int i = 0; i < (url.length() / lineLength + 1); i++) {
beginPos = i * lineLength;
if (otherLength <= lineLength) {
endPos = url.length();
tmpUrl = tmpUrl + url.substring(beginPos, endPos);
break;
} else {
endPos = beginPos + lineLength;
tmpUrl = tmpUrl + url.substring(beginPos, endPos) + "\r\n";
}
otherLength = otherLength - lineLength;
}
setRowValue(R.string.url, tmpUrl);


int vdec = mp.getVideoDecoder();
switch (vdec) {
case IjkMediaPlayer.FFP_PROPV_DECODER_AVCODEC:
Expand Down Expand Up @@ -152,6 +179,20 @@ public void handleMessage(Message msg) {
setRowValue(R.string.tcp_speed, String.format(Locale.US, "%s", formatedSpeed(tcpSpeed, 1000)));
setRowValue(R.string.bit_rate, String.format(Locale.US, "%.2f kbs", bitRate/1000f));

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

long startTime = mp.getBeginTime();
setRowValue(R.string.start_time, formatter.format(new Date(startTime)));

Date curTime = new Date(System.currentTimeMillis());
setRowValue(R.string.current_time, formatter.format(curTime));

long playTime = mp.getPlayTime();
setRowValue(R.string.play_time, String.valueOf(playTime) + " secs");

long pauseTime = mp.getPauseTime();
setRowValue(R.string.pause_time, String.valueOf(pauseTime) + " secs");

mHandler.removeMessages(MSG_UPDATE_HUD);
mHandler.sendEmptyMessageDelayed(MSG_UPDATE_HUD, 500);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<string name="toggle_render">Render</string>
<string name="toggle_ratio">Scale</string>
<string name="show_info">Info</string>
<string name="url">URL</string>
<string name="vdec">vdec</string>
<string name="fps">fps</string>
<string name="v_cache">v-cache</string>
Expand All @@ -23,6 +24,10 @@
<string name="seek_load_cost">seek_load_cost</string>
<string name="tcp_speed">tcp_speed</string>
<string name="bit_rate">bit_rate</string>
<string name="start_time">start_time</string>
<string name="current_time">current_time</string>
<string name="play_time">play_time</string>
<string name="pause_time">pause_time</string>

<string name="media_information">Media Information</string>
<string name="mi_player">Player</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.security.InvalidParameterException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

import tv.danmaku.ijk.media.player.annotations.AccessedByNative;
import tv.danmaku.ijk.media.player.annotations.CalledByNative;
Expand Down Expand Up @@ -169,6 +171,14 @@ public final class IjkMediaPlayer extends AbstractMediaPlayer {

private String mDataSource;

//statistic info for pressure test & troubleshooting purpose
private long mBeginTime; //beginning time of current playback
private long mTotalPlayTime;
private long mLastPauseTime;
private long mTotalPauseTime;
private boolean bIsPaused;


/**
* Default library loader
* Load them by yourself, if your libraries are not installed at default place.
Expand All @@ -187,7 +197,7 @@ public static void loadLibrariesOnce(IjkLibLoader libLoader) {
if (libLoader == null)
libLoader = sLocalLibLoader;

libLoader.loadLibrary("ijkffmpeg");
//libLoader.loadLibrary("ijkffmpeg");
libLoader.loadLibrary("ijksdl");
libLoader.loadLibrary("ijkplayer");
mIsLibLoaded = true;
Expand Down Expand Up @@ -231,6 +241,9 @@ private void initPlayer(IjkLibLoader libLoader) {
loadLibrariesOnce(libLoader);
initNativeOnce();

//should I put it in another better place?
mBeginTime = System.currentTimeMillis();

Looper looper;
if ((looper = Looper.myLooper()) != null) {
mEventHandler = new EventHandler(this, looper);
Expand Down Expand Up @@ -519,14 +532,21 @@ public void prepareAsync() throws IllegalStateException {

@Override
public void start() throws IllegalStateException {
Log.i(TAG, "start playing...");
stayAwake(true);
if (bIsPaused) {
mTotalPauseTime += System.currentTimeMillis() - mLastPauseTime;
Log.i(TAG, "mTotalPauseTime " + (mTotalPauseTime / 1000) );
}
_start();
bIsPaused = false;
}

private native void _start() throws IllegalStateException;

@Override
public void stop() throws IllegalStateException {
Log.i(TAG, "stop playing...");
stayAwake(false);
_stop();
}
Expand All @@ -536,11 +556,48 @@ public void stop() throws IllegalStateException {
@Override
public void pause() throws IllegalStateException {
stayAwake(false);
assert(bIsPaused == false);

if (!bIsPaused) {
mLastPauseTime = System.currentTimeMillis();
}
Log.i(TAG, "pause playing...");
_pause();
bIsPaused = !bIsPaused;
}

private native void _pause() throws IllegalStateException;


public long getBeginTime() {
return mBeginTime;
}


public long getPauseTime() {
long mCurrentPauseTime = 0;
if (bIsPaused) {
mCurrentPauseTime = System.currentTimeMillis() - mLastPauseTime;
}
return (mTotalPauseTime + mCurrentPauseTime) / 1000;
}


public long getPlayTime() {
DateFormat dateFormatterChina = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
TimeZone timeZoneChina = TimeZone.getTimeZone("Asia/Shanghai");
dateFormatterChina.setTimeZone(timeZoneChina);

if (isPlaying()) {
long curTime = System.currentTimeMillis();
mTotalPlayTime = ((curTime - mBeginTime - mTotalPauseTime) / 1000) ;

return mTotalPlayTime;
}
return mTotalPlayTime;
}


@SuppressLint("Wakelock")
@Override
public void setWakeMode(Context context, int mode) {
Expand Down Expand Up @@ -698,6 +755,7 @@ public int getVideoSarDen() {
*/
@Override
public void release() {
Log.i(TAG, "release");
stayAwake(false);
updateSurfaceScreenOn();
resetListeners();
Expand All @@ -708,6 +766,7 @@ public void release() {

@Override
public void reset() {
Log.i(TAG, "reset");
stayAwake(false);
_reset();
// make sure none of the listeners get called anymore
Expand Down Expand Up @@ -838,6 +897,7 @@ public long getSeekLoadDuration() {
return _getPropertyLong(FFP_PROP_INT64_LATEST_SEEK_LOAD_DURATION, 0);
}


private native float _getPropertyFloat(int property, float defaultValue);
private native void _setPropertyFloat(int property, float value);
private native long _getPropertyLong(int property, long defaultValue);
Expand Down