Skip to content

Commit

Permalink
添加mediacodec的flags设置接口
Browse files Browse the repository at this point in the history
  • Loading branch information
SundoggyNew committed May 14, 2024
1 parent a97a2e5 commit e3425b7
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public void setMaxPacketNum(int num) {}

@Override
public void flushCache() {}

@Override
public void setMediaCodecFlags(int flags) {}

@Override
public void setDataSource(Context context, Uri uri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public void setMaxPacketNum(int num) {}
@Override
public void flushCache() {}

@Override
public void setMediaCodecFlags(int flags) {}

@TargetApi(Build.VERSION_CODES.M)
private static class MediaDataSourceProxy extends MediaDataSource {
private final IMediaDataSource mMediaDataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,5 @@ interface OnTimedTextListener {
void setFrameSpeed(float speed);
void setMaxPacketNum(int num);
void flushCache();
void setMediaCodecFlags(int flags);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1317,4 +1317,6 @@ public String onMediaCodecSelect(IMediaPlayer mp, String mimeType, int profile,
public native void setMaxPacketNum(int num);
@Override
public native void flushCache();
@Override
public native void setMediaCodecFlags(int flags);
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public void setFrameSpeed(float speed) {
@Override
public void setMaxPacketNum(int num) {}

@Override
public void setMediaCodecFlags(int flags) {}

@Override
public String getDataSource() {
return mBackEndMediaPlayer.getDataSource();
Expand Down
14 changes: 14 additions & 0 deletions ijkmedia/ijkplayer/android/ijkplayer_jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,19 @@ IjkMediaPlayer_flushCache(JNIEnv *env, jobject thiz)
return ;
}

static void
IjkMediaPlayer_setMediaCodecFlags(JNIEnv *env, jobject thiz, jint value)
{
IjkMediaPlayer *mp = jni_get_media_player(env, thiz);
JNI_CHECK_GOTO(mp, env, NULL, "mpjni: setMediaCodecFlags: null mp", LABEL_RETURN);

ijkmp_set_mediacodec_flags(mp, value);

LABEL_RETURN:
ijkmp_dec_ref_p(&mp);
return;
}

static void
IjkMediaPlayer_release(JNIEnv *env, jobject thiz)
{
Expand Down Expand Up @@ -1274,6 +1287,7 @@ static JNINativeMethod g_methods[] = {

{ "setFrameSpeed", "(F)V", (void *) IjkMediaPlayer_setFrameSpeed },
{ "setMaxPacketNum", "(I)V", (void *) IjkMediaPlayer_setMaxPacketNum },
{ "setMediaCodecFlags", "(I)V", (void *) IjkMediaPlayer_setMediaCodecFlags },
{ "_release", "()V", (void *) IjkMediaPlayer_release },
{ "_reset", "()V", (void *) IjkMediaPlayer_reset },
{ "setVolume", "(FF)V", (void *) IjkMediaPlayer_setVolume },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static int recreate_format_l(JNIEnv *env, IJKFF_Pipenode *node)
return -1;
}

static int reconfigure_codec_l(JNIEnv *env, IJKFF_Pipenode *node, jobject new_surface)
static int reconfigure_codec_l(JNIEnv *env, IJKFF_Pipenode *node, jobject new_surface, int flags)
{
IJKFF_Pipenode_Opaque *opaque = node->opaque;
int ret = 0;
Expand Down Expand Up @@ -321,7 +321,8 @@ static int reconfigure_codec_l(JNIEnv *env, IJKFF_Pipenode *node, jobject new_su
assert(opaque->weak_vout);
}

amc_ret = SDL_AMediaCodec_configure_surface(env, opaque->acodec, opaque->input_aformat, opaque->jsurface, NULL, 0);
ALOGI("SDL_AMediaCodec_configure_surface: %d\n", flags);
amc_ret = SDL_AMediaCodec_configure_surface(env, opaque->acodec, opaque->input_aformat, opaque->jsurface, NULL, flags);
if (amc_ret != SDL_AMEDIA_OK) {
ALOGE("%s:configure_surface: failed\n", __func__);
ret = -1;
Expand Down Expand Up @@ -413,7 +414,7 @@ static int reconfigure_codec(JNIEnv *env, IJKFF_Pipenode *node)
{
IJKFF_Pipenode_Opaque *opaque = node->opaque;
SDL_LockMutex(opaque->acodec_mutex);
int ret = reconfigure_codec_l(env, node);
int ret = reconfigure_codec_l(env, node, 0);
SDL_UnlockMutex(opaque->acodec_mutex);
return ret;
}
Expand Down Expand Up @@ -612,7 +613,7 @@ static int feed_input_buffer2(JNIEnv *env, IJKFF_Pipenode *node, int64_t timeUs,
opaque->aformat_need_recreate = false;
}

ret = reconfigure_codec_l(env, node, new_surface);
ret = reconfigure_codec_l(env, node, new_surface, 0);

J4A_DeleteGlobalRef__p(env, &new_surface);

Expand Down Expand Up @@ -911,7 +912,7 @@ static int feed_input_buffer(JNIEnv *env, IJKFF_Pipenode *node, int64_t timeUs,

opaque->acodec_reconfigure_request = true;
SDL_LockMutex(opaque->acodec_mutex);
ret = reconfigure_codec_l(env, node, new_surface);
ret = reconfigure_codec_l(env, node, new_surface, 0);
opaque->acodec_reconfigure_request = false;
SDL_CondSignal(opaque->acodec_cond);
SDL_UnlockMutex(opaque->acodec_mutex);
Expand Down Expand Up @@ -2060,7 +2061,7 @@ IJKFF_Pipenode *ffpipenode_create_video_decoder_from_android_mediacodec(FFPlayer
}

jsurface = ffpipeline_get_surface_as_global_ref(env, pipeline);
ret = reconfigure_codec_l(env, node, jsurface);
ret = reconfigure_codec_l(env, node, jsurface, ffp->mediacodec_flags);
J4A_DeleteGlobalRef__p(env, &jsurface);
if (ret != 0)
goto fail;
Expand Down
4 changes: 4 additions & 0 deletions ijkmedia/ijkplayer/ff_ffplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -5476,6 +5476,10 @@ void ffp_flush_player_cache(FFPlayer *ffp) {
}
}

void ffp_set_mediacodec_flags(FFPlayer *ffp, int flags) {
ffp->mediacodec_flags = flags;
}

uint32_t convert_hex_to_decimal(uint8_t *hex_data) {
uint32_t decimal_value = 0;
for (int i = 0; i < 4; i++) {
Expand Down
2 changes: 2 additions & 0 deletions ijkmedia/ijkplayer/ff_ffplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ void ffp_set_player_rate(FFPlayer *ffp, float speed);
void ffp_set_player_maxpacket(FFPlayer *ffp, int num);
//直播清理cache
void ffp_flush_player_cache(FFPlayer *ffp);
//设置mediacodec flags
void ffp_set_mediacodec_flags(FFPlayer *ffp, int flags);
int parse_sei(AVPacket *pkt, uint8_t *uuid, uint8_t **content, int *size);
int parse_sei_hevc(AVPacket *pkt, uint8_t *uuid, uint8_t **content, int *size);

Expand Down
1 change: 1 addition & 0 deletions ijkmedia/ijkplayer/ff_ffplay_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ typedef struct FFPlayer {
int64_t start_dts; // 开始录制时dts
float audio_speed; //追帧速度
int packet_max_num; //追帧包大小
int mediacodec_flags; //mediacodec的flags
} FFPlayer;

#define fftime_to_milliseconds(ts) (av_rescale(ts, 1000, AV_TIME_BASE))
Expand Down
8 changes: 8 additions & 0 deletions ijkmedia/ijkplayer/ijkplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,3 +859,11 @@ void ijkmp_flush_cache(IjkMediaPlayer *mp)
ffp_flush_player_cache(mp->ffplayer);
pthread_mutex_unlock(&mp->mutex);
}

void ijkmp_set_mediacodec_flags(IjkMediaPlayer *mp, int flags) {
assert(mp);
MPTRACE("ijkmp_set_mediacodec_flags()\n");
pthread_mutex_lock(&mp->mutex);
ffp_set_mediacodec_flags(mp->ffplayer, flags);
pthread_mutex_unlock(&mp->mutex);
}
1 change: 1 addition & 0 deletions ijkmedia/ijkplayer/ijkplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,5 @@ int ijkmp_stop_record(IjkMediaPlayer *mp);
void ijkmp_set_speed(IjkMediaPlayer *mp, float speed);
void ijkmp_set_maxpacket(IjkMediaPlayer *mp, int num);
void ijkmp_flush_cache(IjkMediaPlayer *mp);
void ijkmp_set_mediacodec_flags(IjkMediaPlayer *mp, int flags);
#endif

0 comments on commit e3425b7

Please sign in to comment.