Skip to content

Commit 01d1261

Browse files
author
Daniel Wang
committed
https://github.com/bilibili/ijkplayer/pull/5366
1 parent 90966b1 commit 01d1261

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

ijkmedia/ijkplayer/ff_ffplay.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4837,20 +4837,24 @@ int ffp_set_stream_selected(FFPlayer *ffp, int stream, int selected)
48374837
VideoState *is = ffp->is;
48384838
AVFormatContext *ic = NULL;
48394839
AVCodecParameters *codecpar = NULL;
4840-
if (!is)
4841-
return -1;
4842-
ic = is->ic;
4843-
if (!ic)
4840+
if (!is || !is->ic)
48444841
return -1;
48454842

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

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

48534852
if (selected) {
4853+
if (stream == is->video_stream || stream == is->audio_stream || stream == is->subtitle_stream) {
4854+
av_log(ffp, AV_LOG_ERROR, "stream has been selected\n");
4855+
return 0;
4856+
}
4857+
48544858
switch (codecpar->codec_type) {
48554859
case AVMEDIA_TYPE_VIDEO:
48564860
if (stream != is->video_stream && is->video_stream >= 0)
@@ -4868,7 +4872,10 @@ int ffp_set_stream_selected(FFPlayer *ffp, int stream, int selected)
48684872
av_log(ffp, AV_LOG_ERROR, "select invalid stream %d of video type %d\n", stream, codecpar->codec_type);
48694873
return -1;
48704874
}
4871-
return stream_component_open(ffp, stream);
4875+
4876+
int ret = stream_component_open(ffp, stream);
4877+
ffp_seek_to_l(ffp, current_pos);
4878+
return ret;
48724879
} else {
48734880
switch (codecpar->codec_type) {
48744881
case AVMEDIA_TYPE_VIDEO:
@@ -4884,7 +4891,7 @@ int ffp_set_stream_selected(FFPlayer *ffp, int stream, int selected)
48844891
stream_component_close(ffp, is->subtitle_stream);
48854892
break;
48864893
default:
4887-
av_log(ffp, AV_LOG_ERROR, "select invalid stream %d of audio type %d\n", stream, codecpar->codec_type);
4894+
av_log(ffp, AV_LOG_ERROR, "unselect invalid stream %d of audio type %d\n", stream, codecpar->codec_type);
48884895
return -1;
48894896
}
48904897
return 0;

ijkmedia/ijkplayer/ijkmeta.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ void ijkmeta_set_avformat_context_l(IjkMediaMeta *meta, AVFormatContext *ic)
227227
if (bitrate > 0) {
228228
ijkmeta_set_int64_l(stream_meta, IJKM_KEY_BITRATE, bitrate);
229229
}
230+
ijkmeta_set_int64_l(stream_meta, IJKM_KEY_STREAM_INDEX, st->index);
230231

231232
switch (codecpar->codec_type) {
232233
case AVMEDIA_TYPE_VIDEO: {

ijkmedia/ijkplayer/ijkmeta.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#define IJKM_VAL_TYPE__TIMEDTEXT "timedtext"
4444
#define IJKM_VAL_TYPE__UNKNOWN "unknown"
4545
#define IJKM_KEY_LANGUAGE "language"
46+
#define IJKM_KEY_STREAM_INDEX "index"
4647

4748
#define IJKM_KEY_CODEC_NAME "codec_name"
4849
#define IJKM_KEY_CODEC_PROFILE "codec_profile"

ios/IJKMediaPlayer/IJKMediaPlayer/IJKFFMoviePlayerController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#define k_IJKM_KEY_CODEC_NAME @"codec_name"
4242
#define k_IJKM_KEY_CODEC_PROFILE @"codec_profile"
4343
#define k_IJKM_KEY_CODEC_LONG_NAME @"codec_long_name"
44+
#define k_IJKM_KEY_LANGUAGE @"language"
45+
#define k_IJKM_KEY_STREAM_INDEX @"index"
4446

4547
// stream: video
4648
#define k_IJKM_KEY_WIDTH @"width"

ios/IJKMediaPlayer/IJKMediaPlayer/IJKFFMoviePlayerController.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ - (void)postEvent: (IJKFFMoviePlayerMessage *)msg
10911091
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_CODEC_PROFILE, nil);
10921092
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_CODEC_LONG_NAME, nil);
10931093
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_BITRATE, nil);
1094+
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_STREAM_INDEX, nil);
10941095

10951096
if (0 == strcmp(type, IJKM_VAL_TYPE__VIDEO)) {
10961097
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_WIDTH, nil);
@@ -1116,10 +1117,13 @@ - (void)postEvent: (IJKFFMoviePlayerMessage *)msg
11161117
} else if (0 == strcmp(type, IJKM_VAL_TYPE__AUDIO)) {
11171118
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_SAMPLE_RATE, nil);
11181119
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_CHANNEL_LAYOUT, nil);
1120+
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_LANGUAGE, nil);
11191121

11201122
if (audio_stream == i) {
11211123
_monitor.audioMeta = streamMeta;
11221124
}
1125+
} else if (0 == strcmp(type, IJKM_VAL_TYPE__TIMEDTEXT)) {
1126+
fillMetaInternal(streamMeta, streamRawMeta, IJKM_KEY_LANGUAGE, nil);
11231127
}
11241128
}
11251129
}

0 commit comments

Comments
 (0)