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

修复切换音轨崩溃与音视频不同步问题 #5366

Open
wants to merge 4 commits 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
17 changes: 11 additions & 6 deletions ijkmedia/ijkplayer/ff_ffplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -4837,20 +4837,23 @@ int ffp_set_stream_selected(FFPlayer *ffp, int stream, int selected)
VideoState *is = ffp->is;
AVFormatContext *ic = NULL;
AVCodecParameters *codecpar = NULL;
if (!is)
return -1;
ic = is->ic;
if (!ic)
if (!is || !is->ic)
return -1;

ic = is->ic;
if (stream < 0 || stream >= ic->nb_streams) {
av_log(ffp, AV_LOG_ERROR, "invalid stream index %d >= stream number (%d)\n", stream, ic->nb_streams);
return -1;
}

codecpar = ic->streams[stream]->codecpar;
long current_pos = ffp_get_current_position_l(ffp);

if (selected) {
if (stream == is->video_stream || stream == is->audio_stream || stream == is->subtitle_stream) {
av_log(ffp, AV_LOG_ERROR, "stream has been selected\n");
return 0;
}
switch (codecpar->codec_type) {
case AVMEDIA_TYPE_VIDEO:
if (stream != is->video_stream && is->video_stream >= 0)
Expand All @@ -4868,7 +4871,9 @@ int ffp_set_stream_selected(FFPlayer *ffp, int stream, int selected)
av_log(ffp, AV_LOG_ERROR, "select invalid stream %d of video type %d\n", stream, codecpar->codec_type);
return -1;
}
return stream_component_open(ffp, stream);
int ret = stream_component_open(ffp, stream);
ffp_seek_to_l(ffp, current_pos);
return ret;
} else {
switch (codecpar->codec_type) {
case AVMEDIA_TYPE_VIDEO:
Expand All @@ -4884,7 +4889,7 @@ int ffp_set_stream_selected(FFPlayer *ffp, int stream, int selected)
stream_component_close(ffp, is->subtitle_stream);
break;
default:
av_log(ffp, AV_LOG_ERROR, "select invalid stream %d of audio type %d\n", stream, codecpar->codec_type);
av_log(ffp, AV_LOG_ERROR, "unselect invalid stream %d of audio type %d\n", stream, codecpar->codec_type);
return -1;
}
return 0;
Expand Down
1 change: 1 addition & 0 deletions ijkmedia/ijkplayer/ijkmeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ void ijkmeta_set_avformat_context_l(IjkMediaMeta *meta, AVFormatContext *ic)
if (bitrate > 0) {
ijkmeta_set_int64_l(stream_meta, IJKM_KEY_BITRATE, bitrate);
}
ijkmeta_set_int64_l(stream_meta, IJKM_KEY_STREAM_INDEX, st->index);

switch (codecpar->codec_type) {
case AVMEDIA_TYPE_VIDEO: {
Expand Down
1 change: 1 addition & 0 deletions ijkmedia/ijkplayer/ijkmeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define IJKM_VAL_TYPE__TIMEDTEXT "timedtext"
#define IJKM_VAL_TYPE__UNKNOWN "unknown"
#define IJKM_KEY_LANGUAGE "language"
#define IJKM_KEY_STREAM_INDEX "index"

#define IJKM_KEY_CODEC_NAME "codec_name"
#define IJKM_KEY_CODEC_PROFILE "codec_profile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#define k_IJKM_KEY_CODEC_NAME @"codec_name"
#define k_IJKM_KEY_CODEC_PROFILE @"codec_profile"
#define k_IJKM_KEY_CODEC_LONG_NAME @"codec_long_name"
#define k_IJKM_KEY_LANGUAGE @"language"
#define k_IJKM_KEY_STREAM_INDEX @"index"

// stream: video
#define k_IJKM_KEY_WIDTH @"width"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ - (void)postEvent: (IJKFFMoviePlayerMessage *)msg
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_CODEC_PROFILE, nil);
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_CODEC_LONG_NAME, nil);
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_BITRATE, nil);
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_STREAM_INDEX, nil);

if (0 == strcmp(type, IJKM_VAL_TYPE__VIDEO)) {
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_WIDTH, nil);
Expand All @@ -1116,10 +1117,13 @@ - (void)postEvent: (IJKFFMoviePlayerMessage *)msg
} else if (0 == strcmp(type, IJKM_VAL_TYPE__AUDIO)) {
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_SAMPLE_RATE, nil);
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_CHANNEL_LAYOUT, nil);
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_LANGUAGE, nil);

if (audio_stream == i) {
_monitor.audioMeta = streamMeta;
}
} else if (0 == strcmp(type, IJKM_VAL_TYPE__TIMEDTEXT)) {
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_LANGUAGE, nil);
}
}
}
Expand Down