Skip to content

Commit 25b0155

Browse files
committed
PoC-S33:coding work of data path: UI <----> JNI <----> whisper.cpp <----> kantv-play <----> kantv-core
1 parent 5c9d115 commit 25b0155

38 files changed

+910
-111
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ build
5757

5858
cdeosplayer/kantv/src/main/assets/audio.wav
5959
cdeosplayer/kantv/src/main/assets/deepspeech-0.9.3-models.tflite
60+
61+
#generated by source code,so skip it
62+
cdeosplayer/kantv/src/main/jniLibs/arm64-v8a/libopenblas.so

cdeosplayer/cdeosplayer-exo2/src/main/java/cdeos/media/exo2/CDEOSExo2MediaPlayer.java

+12
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,12 @@ public void setEnableRecord(boolean bEnableRecord) {
503503
CDEUtils.setTVRecording(bEnableRecord);
504504
}
505505

506+
//TODO
507+
@Override
508+
public void setEnableASR(boolean bEnableASR) {
509+
CDEUtils.setTVASR(bEnableASR);
510+
}
511+
506512
//FIXME
507513
@Override
508514
public void updateRecordingStatus(boolean bEnableRecord) {
@@ -526,6 +532,12 @@ public boolean getEnableRecord() {
526532
return CDEUtils.getTVRecording();
527533
}
528534

535+
//TODO
536+
@Override
537+
public boolean getEnableASR() {
538+
return CDEUtils.getTVASR();
539+
}
540+
529541

530542
@Override
531543
public void setDurationDumpES(int durationDumpES) {

cdeosplayer/cdeosplayer-lib/src/main/java/cdeos/media/player/AndroidMediaPlayer.java

+11
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,11 @@ public void setEnableDumpAudioES(boolean bEnable) {
625625
public void setEnableRecord(boolean bEnableRecord) {
626626
}
627627

628+
//TODO
629+
@Override
630+
public void setEnableASR(boolean bEnableRecord) {
631+
}
632+
628633
//TODO
629634
@Override
630635
public void updateRecordingStatus(boolean bEnableRecord) {
@@ -636,6 +641,12 @@ public boolean getEnableRecord() {
636641
return false;
637642
}
638643

644+
//TODO
645+
@Override
646+
public boolean getEnableASR() {
647+
return false;
648+
}
649+
639650
//TODO
640651
@Override
641652
public void setDurationDumpES(int durationDumpES) {

cdeosplayer/cdeosplayer-lib/src/main/java/cdeos/media/player/CDEAssetLoader.java

+5
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ public static void copyAssetFile(Context context, String srcFilePath, String des
4242
FileOutputStream outStream = null;
4343
try {
4444
File destFile = new File(destFilePath);
45+
46+
if (destFile.exists())
47+
return;
48+
4549
if (!destFile.exists()) {
4650
destFile.createNewFile();
4751
}
52+
4853
inStream = context.getAssets().open(srcFilePath);
4954
outStream = new FileOutputStream(destFilePath);
5055

cdeosplayer/cdeosplayer-lib/src/main/java/cdeos/media/player/CDEUtils.java

+22
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222

2323
import android.app.Activity;
2424
import android.app.ActivityManager;
25+
import android.app.AlertDialog;
2526
import android.bluetooth.BluetoothAdapter;
2627
import android.content.Context;
28+
import android.content.DialogInterface;
2729
import android.content.Intent;
2830
import android.graphics.Bitmap;
2931
import android.hardware.Sensor;
@@ -232,6 +234,7 @@ public class CDEUtils {
232234
private static int mRecordSize = 20; //default record size is 20 Mbytes
233235
private static int mRecordMode = 0; //0:video, 1:audio, 2:video&audio
234236
private static boolean mIsTVRecording = false;
237+
private static boolean mIsTVASR = false;
235238
private static String mRecordingFileName = "";
236239
private static boolean mEnableRecordVideoES = true;
237240
private static boolean mEnableRecordAudioES = false;
@@ -3664,6 +3667,14 @@ public static void setTVRecording(boolean bRecording) {
36643667
mIsTVRecording = bRecording;
36653668
}
36663669

3670+
public static boolean getTVASR() {
3671+
return mIsTVASR;
3672+
}
3673+
3674+
public static void setTVASR(boolean bASR) {
3675+
mIsTVASR = bASR;
3676+
}
3677+
36673678

36683679
public static void setRecordDuration(int recordDuration) {
36693680
mRecordDuration = recordDuration;
@@ -3824,5 +3835,16 @@ public static boolean isDisableUM(){
38243835
return mDisableUM;
38253836
}
38263837

3838+
public static void showMsgBox(Context context, String message) {
3839+
AlertDialog dialog = new AlertDialog.Builder(context).create();
3840+
dialog.setMessage(message);
3841+
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
3842+
public void onClick(DialogInterface dialog, int which) {
3843+
3844+
}
3845+
});
3846+
dialog.show();
3847+
}
3848+
38273849
public static native int kantv_anti_tamper();
38283850
}

cdeosplayer/cdeosplayer-lib/src/main/java/cdeos/media/player/FFmpegMediaPlayer.java

+37-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import android.view.Surface;
4343
import android.view.SurfaceHolder;
4444

45+
import org.ggml.whispercpp.whispercpp;
46+
4547
import java.io.FileDescriptor;
4648
import java.io.FileNotFoundException;
4749
import java.io.IOException;
@@ -179,13 +181,14 @@ public final class FFmpegMediaPlayer extends AbstractMediaPlayer {
179181
private long mTotalPauseTime;
180182
private boolean bIsPaused;
181183
private int mDecryptMode = CDEUtils.DECRYPT_SOFT;
182-
private boolean mDisableAudioTrack = false; //troubleshooting Huaxia's <<狄仁杰>>
184+
private boolean mDisableAudioTrack = false;
183185
private boolean mDisableVideoTrack = false;
184186
private boolean mEnableDumpVideoES = false;
185187
private boolean mEnableDumpAudioES = false;
186188
private int mDurationDumpES = 10; //default dumped duration is 10 seconds
187189

188190
private boolean mEnableRecord = false;
191+
private boolean mEnableASR = false;
189192

190193
private String mVideoTitle;
191194

@@ -218,6 +221,7 @@ public static void loadLibrariesOnce(IjkLibLoader libLoader) {
218221
CDELog.j(TAG, "load library kantv-play");
219222
libLoader.loadLibrary("kantv-play");
220223
CDELog.j(TAG, "after load library kantv-play");
224+
221225
mIsLibLoaded = true;
222226
}
223227
}
@@ -261,6 +265,15 @@ private void initPlayer(IjkLibLoader libLoader) {
261265
loadLibrariesOnce(libLoader);
262266
initNativeOnce();
263267

268+
//TODO
269+
try {
270+
CDELibraryLoader.load("whispercpp");
271+
CDELog.j(TAG, "cpu core counts:" + whispercpp.get_cpu_core_counts());
272+
} catch (Exception e) {
273+
CDELog.j(TAG, "failed to initialize whispercpp jni");
274+
return;
275+
}
276+
264277
//should I put it in another better place?
265278
mBeginTime = System.currentTimeMillis();
266279

@@ -856,6 +869,7 @@ public void setEnableRecord(boolean bEnableRecord) {
856869
_setEnableRecord(mEnableRecord ? 1 : 0);
857870
}
858871

872+
859873
//TODO
860874
@Override
861875
public void updateRecordingStatus(boolean bEnableRecord) {
@@ -871,6 +885,23 @@ public boolean getEnableRecord() {
871885
return mEnableRecord;
872886
}
873887

888+
@Override
889+
public void setEnableASR(boolean bEnableASR) {
890+
mEnableASR = bEnableASR;
891+
CDELog.d(TAG, "enable ASR: " + mEnableASR);
892+
_setEnableASR(mEnableASR ? 1 : 0);
893+
}
894+
895+
@Override
896+
public boolean getEnableASR() {
897+
int isASRing= _getEnableASR();
898+
if (0 == isASRing)
899+
mEnableASR = false;
900+
else
901+
mEnableASR = true;
902+
return mEnableASR;
903+
}
904+
874905

875906
@Override
876907
public void setDurationDumpES(int durationDumpES) {
@@ -918,6 +949,10 @@ public String getAudioDecoderName() {
918949

919950
public native int _getEnableRecord();
920951

952+
public native void _setEnableASR(int bEnableASR);
953+
954+
public native int _getEnableASR();
955+
921956
@Override
922957
public native void seekTo(long msec) throws IllegalStateException;
923958

@@ -1296,7 +1331,7 @@ public void handleMessage(Message msg) {
12961331
// No real default action so far.
12971332
return;
12981333
case MEDIA_TIMED_TEXT:
1299-
CDELog.j(TAG, "subtitle coming");
1334+
CDELog.d(TAG, "subtitle coming");
13001335
if (msg.obj == null) {
13011336
player.notifyOnTimedText(null);
13021337
} else {

cdeosplayer/cdeosplayer-lib/src/main/java/cdeos/media/player/IMediaPlayer.java

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ void setDataSource(String path)
141141
void updateRecordingStatus(boolean bEnableRecord);
142142
boolean getEnableRecord();
143143

144+
void setEnableASR(boolean bEnableASR);
145+
boolean getEnableASR();
146+
144147
void setDurationDumpES(int durationDumpES);//per seconds
145148
String getVideoInfo();
146149
String getAudioInfo();

cdeosplayer/cdeosplayer-lib/src/main/java/cdeos/media/player/MediaPlayerProxy.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -173,24 +173,36 @@ public void setEnableDumpAudioES(boolean bEnable) {
173173
mBackEndMediaPlayer.setEnableDumpAudioES(bEnable);
174174
}
175175

176-
//TODO
176+
177177
@Override
178178
public void setEnableRecord(boolean bEnableRecord) {
179179
mBackEndMediaPlayer.setEnableRecord(bEnableRecord);
180180
}
181181

182+
183+
@Override
184+
public void setEnableASR(boolean bEnableASR) {
185+
mBackEndMediaPlayer.setEnableASR(bEnableASR);
186+
}
187+
182188
@Override
183189
public void updateRecordingStatus(boolean bEnableRecord) {
184190
mBackEndMediaPlayer.updateRecordingStatus(bEnableRecord);
185191
}
186192

187-
//TODO
193+
188194
@Override
189195
public boolean getEnableRecord() {
190196
return false;
191197
}
192198

193199

200+
@Override
201+
public boolean getEnableASR() {
202+
return false;
203+
}
204+
205+
194206
@Override
195207
public void setDurationDumpES(int durationDumpES) {
196208
mBackEndMediaPlayer.setDurationDumpES(durationDumpES);

cdeosplayer/cdeosplayer-lib/src/main/java/org/ggml/whispercpp/whispercpp.java

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
public class whispercpp {
77
private static final String TAG = whispercpp.class.getName();
88

9+
public static final int WHISPER_ASR_MODE_NORMAL = 0;
10+
public static final int WHISPER_ASR_MODE_PRESURETEST = 1;
11+
12+
public static native void asr_init(String strModelPath, int nThreadCounts, int nDevMode);
13+
14+
public static native void asr_finalize();
15+
916
public static native String get_systeminfo();
1017

1118
public static native int get_cpu_core_counts();

cdeosplayer/constants.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ project.ext {
3939
compileSdkVersion = 34
4040
buildToolsVersion = "34.0.0"
4141
targetSdkVersion = 34
42-
minSdkVersion = 26 //34 is too strict and the generated apk couldn't run on vivo Android phone
42+
//34 is too strict and the generated apk couldn't run on low-end vivo Android phone,target phone should be above Android 8
43+
minSdkVersion = 26
4344
appTargetSdkVersion = 29
4445

4546
//version and version code of KanTV
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"kantvServer": "www.cde-os.com",
3-
"releaseMode": "1",
3+
"releaseMode": "0",
44
"apkVersion": "1.3.1",
55
"apkForTV": "0"
66
}
Binary file not shown.

cdeosplayer/kantv/src/main/java/com/cdeos/kantv/base/BaseAppCompatActivity.java

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import butterknife.ButterKnife;
4545
import butterknife.Unbinder;
46+
import cdeos.media.player.CDEAssetLoader;
4647
import skin.support.SkinCompatManager;
4748
import skin.support.observe.SkinObservable;
4849
import skin.support.observe.SkinObserver;
@@ -367,6 +368,10 @@ public void initApp() {
367368
CDELog.j(TAG, "screen width x height (dp) = : " + screenWidth + "x" + screenHeight);
368369
CDELog.j(TAG, "isRunningOnTV = " + CDEUtils.isRunningOnTV());
369370

371+
//for realtime subtitle demo with prebuilt android apk
372+
String ggmlModelFileName = "ggml-tiny-q5_1.bin"; //31M
373+
CDEAssetLoader.copyAssetFile(mContext, ggmlModelFileName, CDEUtils.getDataPath() + ggmlModelFileName);
374+
370375
if (CDEUtils.isRunningOnTV()) {
371376
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
372377
CDEUtils.setScreenOrientation(CDEUtils.SCREEN_ORIENTATION_LANDSCAPE);

cdeosplayer/kantv/src/main/java/com/cdeos/kantv/player/common/widgets/SettingPlayerView.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class SettingPlayerView extends LinearLayout implements View.OnClickListe
3838

3939
private Switch tvRecordingSw;
4040
private Switch landscapeChangeSw;
41+
private Switch tvASRSw;
42+
4143
private LinearLayout audioRl;
4244
private RadioGroup mAspectRatioOptions;
4345

@@ -71,6 +73,7 @@ public SettingPlayerView(Context context, AttributeSet attrs) {
7173

7274
landscapeChangeSw = this.findViewById(R.id.landscape_change_sw);
7375
tvRecordingSw = this.findViewById(R.id.tv_recording_sw);
76+
tvASRSw = this.findViewById(R.id.tv_asr_sw);
7477

7578
mAspectRatioOptions.setOnCheckedChangeListener((group, checkedId) -> {
7679
if (checkedId == R.id.aspect_fit_parent) {
@@ -149,7 +152,11 @@ public SettingPlayerView(Context context, AttributeSet attrs) {
149152
// tvRecordingSw.setChecked(true);
150153
//else
151154
// tvRecordingSw.setChecked(false);
152-
155+
tvASRSw.setOnCheckedChangeListener((buttonView, isChecked) -> {
156+
CDELog.j(TAG, "tv ASR status:" + isChecked);
157+
listener.setTVASRStatus(isChecked);
158+
});
159+
CDELog.j(TAG, "isASR enabled:" + CDEUtils.getTVASR());
153160
setPlayerSpeedView(3);
154161
}
155162

@@ -160,6 +167,17 @@ public void updateUIStatus(boolean isRecording) {
160167
tvRecordingSw.setChecked(true);
161168
else
162169
tvRecordingSw.setChecked(false);
170+
171+
}
172+
173+
public void updateASRUIStatus(boolean isASR) {
174+
CDELog.j(TAG, "isASR:" + isASR);
175+
CDELog.j(TAG, "isASR:" + CDEUtils.getTVASR());
176+
177+
if (CDEUtils.getTVASR())
178+
tvASRSw.setChecked(true);
179+
else
180+
tvASRSw.setChecked(false);
163181
}
164182

165183
@Override
@@ -287,5 +305,7 @@ public interface SettingVideoListener {
287305
void setLandscapeStatus(boolean bLandScape);
288306

289307
void setTVRecordingStatus(boolean bRecording);
308+
309+
void setTVASRStatus(boolean bEnableASR);
290310
}
291311
}

0 commit comments

Comments
 (0)