Skip to content

Commit c2b8bd7

Browse files
committedApr 20, 2024·
Clear player code, start of writing FFmpegWrapper
1 parent 975ced8 commit c2b8bd7

File tree

9 files changed

+197
-518
lines changed

9 files changed

+197
-518
lines changed
 

‎app/src/main/java/uk/openvk/android/legacy/utils/media/OvkMediaPlayer.java

+91-91
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ public void run() {
101101
// C++ player native functions
102102
private native void naInit();
103103
private native String naShowLogo();
104-
private native Object naGenerateTrackInfo(int type);
105-
private native void naSetMinAudioBufferSize(int audioBufferSize);
106-
private native int naOpenFile(String filename);
107-
private native void naDecodeVideoFromPacket();
108-
private native void naDecodeAudioFromPacket(int aBuffLength);
109-
private native void naPlay();
110-
private native void naPause();
111-
private native void naStop();
112104
private native void naSetDebugMode(boolean value);
113105
private native int naGetPlaybackState();
106+
private native int naOpenFile(String filename);
107+
// private native Object naGenerateTrackInfo(int type);
108+
// private native void naSetMinAudioBufferSize(int audioBufferSize);
109+
// private native void naDecodeVideoFromPacket();
110+
// private native void naDecodeAudioFromPacket(int aBuffLength);
111+
// private native void naPlay();
112+
// private native void naPause();
113+
// private native void naStop();
114114

115115
public static interface OnPreparedListener {
116116
public void onPrepared(OvkMediaPlayer mp);
@@ -174,36 +174,36 @@ public void handleMessage(Message msg) {
174174

175175
@SuppressWarnings("MalformedFormatString")
176176
public ArrayList<OvkMediaTrack> getMediaInfo(String filename) {
177-
this.tracks = new ArrayList<>();
178-
OvkVideoTrack video_track;
179-
OvkAudioTrack audio_track;
180-
if(filename != null) {
181-
naOpenFile(filename);
182-
}
183-
video_track = (OvkVideoTrack) naGenerateTrackInfo(OvkMediaTrack.TYPE_VIDEO);
184-
audio_track = (OvkAudioTrack) naGenerateTrackInfo(OvkMediaTrack.TYPE_AUDIO);
185-
if(video_track == null && audio_track == null) {
186-
return null;
187-
}
188-
189-
if(audio_track != null) {
190-
Log.d(MPLAY_TAG,
191-
String.format("A: %s, %s Hz, %s bps, %s",
192-
audio_track.codec_name, audio_track.sample_rate,
193-
audio_track.bitrate, audio_track.channels)
194-
);
195-
tracks.add(audio_track);
196-
}
197-
if(video_track != null) {
198-
Log.d(MPLAY_TAG,
199-
String.format("V: %s, %.2f MHz, %sx%s, %s bps, %s fps",
200-
video_track.codec_name, ((double)video_track.sample_rate / 1000 / 1000),
201-
video_track.frame_size[0],
202-
video_track.frame_size[1], video_track.bitrate, video_track.frame_rate)
203-
);
204-
tracks.add(video_track);
205-
}
206-
this.tracks = tracks;
177+
// this.tracks = new ArrayList<>();
178+
// OvkVideoTrack video_track;
179+
// OvkAudioTrack audio_track;
180+
// if(filename != null) {
181+
// naOpenFile(filename);
182+
// }
183+
// video_track = (OvkVideoTrack) naGenerateTrackInfo(OvkMediaTrack.TYPE_VIDEO);
184+
// audio_track = (OvkAudioTrack) naGenerateTrackInfo(OvkMediaTrack.TYPE_AUDIO);
185+
// if(video_track == null && audio_track == null) {
186+
// return null;
187+
// }
188+
//
189+
// if(audio_track != null) {
190+
// Log.d(MPLAY_TAG,
191+
// String.format("A: %s, %s Hz, %s bps, %s",
192+
// audio_track.codec_name, audio_track.sample_rate,
193+
// audio_track.bitrate, audio_track.channels)
194+
// );
195+
// tracks.add(audio_track);
196+
// }
197+
// if(video_track != null) {
198+
// Log.d(MPLAY_TAG,
199+
// String.format("V: %s, %.2f MHz, %sx%s, %s bps, %s fps",
200+
// video_track.codec_name, ((double)video_track.sample_rate / 1000 / 1000),
201+
// video_track.frame_size[0],
202+
// video_track.frame_size[1], video_track.bitrate, video_track.frame_rate)
203+
// );
204+
// tracks.add(video_track);
205+
// }
206+
// this.tracks = tracks;
207207
return tracks;
208208
}
209209

@@ -269,57 +269,57 @@ public void run() {
269269

270270
@Override
271271
public void start() throws IllegalStateException {
272-
if(tracks != null) {
273-
naPlay();
274-
Log.d(MPLAY_TAG, "Playing...");
275-
//setPlaybackState(STATE_PLAYING);
276-
OvkAudioTrack audio_track = null;
277-
OvkVideoTrack video_track = null;
278-
for(int tracks_index = 0; tracks_index < tracks.size(); tracks_index++) {
279-
if(tracks.get(tracks_index) instanceof OvkAudioTrack) {
280-
audio_track = (OvkAudioTrack) tracks.get(tracks_index);
281-
} else if(tracks.get(tracks_index) instanceof OvkVideoTrack) {
282-
video_track = (OvkVideoTrack) tracks.get(tracks_index);
283-
}
284-
}
285-
final OvkAudioTrack finalAudioTrack = audio_track;
286-
final OvkVideoTrack finalVideoTrack = video_track;
287-
new Thread(new Runnable() {
288-
@Override
289-
public void run() {
290-
if(finalAudioTrack != null) {
291-
int ch_config = finalAudioTrack.channels == 2 ?
292-
AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO;
293-
Log.d(MPLAY_TAG, "Decoding audio track...");
294-
try {
295-
naDecodeAudioFromPacket(AudioTrack.getMinBufferSize(
296-
(int) finalAudioTrack.sample_rate, ch_config, AudioFormat.ENCODING_PCM_16BIT
297-
));
298-
} catch (OutOfMemoryError oom) {
299-
stop();
300-
}
301-
} else {
302-
Log.e(MPLAY_TAG, "Audio stream not found. Skipping...");
303-
}
304-
}
305-
}).start();
306-
307-
new Thread(new Runnable() {
308-
@Override
309-
public void run() {
310-
if(finalVideoTrack != null) {
311-
Log.d(MPLAY_TAG, "Decoding video track...");
312-
try {
313-
naDecodeVideoFromPacket();
314-
} catch (OutOfMemoryError oom) {
315-
stop();
316-
}
317-
} else {
318-
Log.e(MPLAY_TAG, "Video stream not found. Skipping...");
319-
}
320-
}
321-
}).start();
322-
}
272+
// if(tracks != null) {
273+
// naPlay();
274+
// Log.d(MPLAY_TAG, "Playing...");
275+
// //setPlaybackState(STATE_PLAYING);
276+
// OvkAudioTrack audio_track = null;
277+
// OvkVideoTrack video_track = null;
278+
// for(int tracks_index = 0; tracks_index < tracks.size(); tracks_index++) {
279+
// if(tracks.get(tracks_index) instanceof OvkAudioTrack) {
280+
// audio_track = (OvkAudioTrack) tracks.get(tracks_index);
281+
// } else if(tracks.get(tracks_index) instanceof OvkVideoTrack) {
282+
// video_track = (OvkVideoTrack) tracks.get(tracks_index);
283+
// }
284+
// }
285+
// final OvkAudioTrack finalAudioTrack = audio_track;
286+
// final OvkVideoTrack finalVideoTrack = video_track;
287+
// new Thread(new Runnable() {
288+
// @Override
289+
// public void run() {
290+
// if(finalAudioTrack != null) {
291+
// int ch_config = finalAudioTrack.channels == 2 ?
292+
// AudioFormat.CHANNEL_CONFIGURATION_STEREO : AudioFormat.CHANNEL_CONFIGURATION_MONO;
293+
// Log.d(MPLAY_TAG, "Decoding audio track...");
294+
// try {
295+
// naDecodeAudioFromPacket(AudioTrack.getMinBufferSize(
296+
// (int) finalAudioTrack.sample_rate, ch_config, AudioFormat.ENCODING_PCM_16BIT
297+
// ));
298+
// } catch (OutOfMemoryError oom) {
299+
// stop();
300+
// }
301+
// } else {
302+
// Log.e(MPLAY_TAG, "Audio stream not found. Skipping...");
303+
// }
304+
// }
305+
// }).start();
306+
//
307+
// new Thread(new Runnable() {
308+
// @Override
309+
// public void run() {
310+
// if(finalVideoTrack != null) {
311+
// Log.d(MPLAY_TAG, "Decoding video track...");
312+
// try {
313+
// naDecodeVideoFromPacket();
314+
// } catch (OutOfMemoryError oom) {
315+
// stop();
316+
// }
317+
// } else {
318+
// Log.e(MPLAY_TAG, "Video stream not found. Skipping...");
319+
// }
320+
// }
321+
// }).start();
322+
// }
323323
}
324324

325325
@SuppressWarnings("deprecation")
@@ -425,12 +425,12 @@ public void run() {
425425

426426
@Override
427427
public void stop() throws IllegalStateException {
428-
naStop();
428+
//naStop();
429429
}
430430

431431
@Override
432432
public void pause() throws IllegalStateException {
433-
naPause();
433+
//naPause();
434434
}
435435

436436
@Override

‎ndk-modules/ovkmplayer/Android.mk

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ LOCAL_ALLOW_UNDEFINED_SYMBOLS=false
3939
LOCAL_MODULE := ovkmplayer
4040
LOCAL_SRC_FILES := ovkmplay.cpp \
4141
utils/android.cpp \
42+
utils/ffwrap.cpp \
4243
decoders/audiodec.cpp \
4344
decoders/videodec.cpp \
4445
utils/pktqueue.cpp \
@@ -47,6 +48,7 @@ LOCAL_C_INCLUDES := $(PROJECT_PATH)/ndk-modules/ovkmplayer/builder/ffmpeg-$(FFMP
4748
LOCAL_C_INCLUDES += $(PROJECT_PATH)/ndk-modules/ovkmplayer/builder/ffmpeg-$(FFMPEG_VERSION) \
4849
$(PROJECT_PATH)/ndk-modules/ovkmplayer/utils \
4950
$(PROJECT_PATH)/ndk-modules/ovkmplayer/decoders \
51+
$(PROJECT_PATH)/ndk-modules/ovkmplayer/interfaces
5052
LOCAL_CFLAGS += -std=c++98
5153
LOCAL_CPP_FEATURES := exceptions
5254
LOCAL_SHARED_LIBRARIES := ffmpeg-prebuilt

‎ndk-modules/ovkmplayer/decoders/audiodec.cpp

-64
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66

77
#include <../utils/android.h>
88

9-
#define LOG_TAG "OVK-MPLAY-LIB"
10-
#define LOG_LEVEL 10
11-
#define LOGD(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__);}
12-
#define LOGI(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__);}
13-
#define LOGW(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__);}
14-
#define LOGE(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__);}
15-
169
#define AV_MAX_AUDIO_FRAME_SIZE 192000;
1710

1811
AVStream* gStream;
@@ -47,61 +40,4 @@ bool AudioDecoder::decode(void* ptr) {
4740
av_free(gBuffer);
4841

4942
return true;
50-
51-
/*AVFrame *pFrame = av_frame_alloc();
52-
int AUDIO_INBUF_SIZE = 4096;
53-
int decodedDataSize = 0,
54-
packetSize = avPkt.size,
55-
status = 0,
56-
tAudioFrames = 0;
57-
/*jclass jmPlay = env->GetObjectClass(instance);
58-
jmethodID renderAudioMid = env->GetMethodID(jmPlay, "renderAudio", "([BI)V");
59-
short* buffer = (short*)malloc(aBuffLength);
60-
jbyteArray jBuffer = env->NewByteArray(aBuffLength);
61-
62-
pFrame = av_frame_alloc();
63-
64-
if (debug_mode) {
65-
LOGD(10, "[DEBUG] Starting audio decoder...");
66-
}*/
67-
68-
/*while (gPlaybackState == FFMPEG_PLAYBACK_PLAYING &&
69-
(status = av_read_frame(gFormatCtx, &avPkt)) >= 0) {
70-
int len = avcodec_decode_audio4(
71-
gAudioCodecCtx,
72-
pFrame,
73-
&status,
74-
&avPkt
75-
);
76-
77-
if (status) {
78-
int dataSize = av_samples_get_buffer_size(NULL,
79-
gAudioCodecCtx->channels,
80-
pFrame->nb_samples,
81-
gAudioCodecCtx->sample_fmt,
82-
1);
83-
84-
if (debug_mode) {
85-
LOGD(10, "[DEBUG] Decoding audio frame #%d... | Length: %d of %d",
86-
tAudioFrames + 1, dataSize, aBuffLength
87-
);
88-
}
89-
90-
buffer = (short *) pFrame->data[0];
91-
env->SetByteArrayRegion(jBuffer, 0, (jsize) dataSize / gAudioCodecCtx->channels, (jbyte *) buffer);
92-
env->CallVoidMethod(instance, renderAudioMid, jBuffer, dataSize / gAudioCodecCtx->channels);
93-
}
94-
95-
tAudioFrames++;
96-
97-
av_free_packet(&avPkt);
98-
av_packet_unref(&avPkt);
99-
}
100-
101-
while (gPlaybackState == FFMPEG_PLAYBACK_PLAYING &&
102-
(status = av_read_frame(gFormatCtx, &avPkt)) >= 0) {
103-
if(avPkt->stream_index == pStreamIndex) {
104-
105-
}
106-
}*/
10743
}

‎ndk-modules/ovkmplayer/decoders/audiodec.h

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
#include <../utils/pktqueue.h>
99

10+
#define LOG_TAG "FFwrap"
11+
#define LOG_LEVEL 10
12+
#define LOGD(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__);}
13+
#define LOGI(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__);}
14+
#define LOGW(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__);}
15+
#define LOGE(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__);}
16+
1017
typedef void (*DecoderHandler) (short*, int);
1118

1219
// FFmpeg implementation headers (using LGPLv3.0 model)

‎ndk-modules/ovkmplayer/decoders/videodec.h

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
#include <../utils/pktqueue.h>
99

10+
#define LOG_TAG "FFwrap"
11+
#define LOG_LEVEL 10
12+
#define LOGD(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__);}
13+
#define LOGI(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__);}
14+
#define LOGW(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__);}
15+
#define LOGE(level, ...) if (level <= LOG_LEVEL) {__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__);}
16+
1017
// FFmpeg implementation headers (using LGPLv3.0 model)
1118
extern "C" {
1219
#define __STDC_CONSTANT_MACROS // workaround for compiler
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef MOBILE_ANDROID_LEGACY_INTERFACES_FFWRAP_H
2+
#define MOBILE_ANDROID_LEGACY_INTERFACES_FFWRAP_H
3+
4+
#include <stdint.h>
5+
6+
class IFFmpegWrapper {
7+
public:
8+
IFFmpegWrapper() {};
9+
virtual ~IFFmpegWrapper(){};
10+
virtual void onError(int cmdId,
11+
int errorCode) = 0;
12+
virtual void onResult(int cmdId,
13+
int resultCode) = 0;
14+
virtual void onStreamDecoding(uint8_t *buffer,
15+
int bufferLen,
16+
int streamIndex) = 0;
17+
virtual void onChangePlaybackState(int playbackState) = 0;
18+
private:
19+
bool gDebugMode;
20+
};
21+
22+
#endif

‎ndk-modules/ovkmplayer/ovkmplay.cpp

+24-363
Large diffs are not rendered by default.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Created by tretdm on 20.04.2024.
3+
//
4+
5+
#include "ffwrap.h"
6+
7+
FFmpegWrapper::FFmpegWrapper(bool pDebugMode, IFFmpegWrapper *pInterface) {
8+
9+
}
10+
11+
void FFmpegWrapper::setDebugMode(bool pDebugMode) {
12+
gDebugMode = pDebugMode;
13+
}
14+
15+
int FFmpegWrapper::getPlaybackState() {
16+
return gPlaybackState;
17+
}
18+
19+
void FFmpegWrapper::openInputFile(char* pFileName, bool afterFindStreams) {
20+
21+
}

‎ndk-modules/ovkmplayer/utils/ffwrap.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Created by tretdm on 20.04.2024.
3+
//
4+
5+
#ifndef MOBILE_ANDROID_LEGACY_FFWRAP_H
6+
#define MOBILE_ANDROID_LEGACY_FFWRAP_H
7+
8+
#include <../interfaces/ffwrap.h>
9+
10+
class FFmpegWrapper {
11+
public:
12+
FFmpegWrapper(bool pDebugMode, IFFmpegWrapper *pInterface);
13+
void setDebugMode(bool pDebugMode);
14+
int getPlaybackState();
15+
void openInputFile(char* pFileName, bool afterFindStreams);
16+
private:
17+
bool gDebugMode;
18+
int gPlaybackState;
19+
};
20+
21+
22+
23+
#endif //MOBILE_ANDROID_LEGACY_FFWRAP_H

0 commit comments

Comments
 (0)
Please sign in to comment.