Skip to content

Commit 87afb5c

Browse files
committed
2 parents e17be4c + 952f7fb commit 87afb5c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

FFmpegLibrary/jni/player.c

+18-6
Original file line numberDiff line numberDiff line change
@@ -1543,12 +1543,21 @@ static int player_set_data_source(State *state, const char *file_path,
15431543
player->stream_indexs[AVMEDIA_TYPE_AUDIO], -1, NULL, 0);
15441544

15451545
if (st_index[AVMEDIA_TYPE_AUDIO] >= 0) {
1546-
err = stream_component_open(player, st_index[AVMEDIA_TYPE_AUDIO]);
1547-
if (err < 0)
1548-
goto error;
1549-
err = player_create_audio_track(player, state);
1550-
if (err < 0)
1551-
goto error;
1546+
AVCodecContext *avctx = ic->streams[st_index[AVMEDIA_TYPE_AUDIO]]->codec;
1547+
if (avctx->sample_rate > 0 && avctx->channels > 0) {
1548+
LOGI(3, "player_set_data_source open audio");
1549+
err = stream_component_open(player, st_index[AVMEDIA_TYPE_AUDIO]);
1550+
if (err < 0)
1551+
goto error;
1552+
1553+
err = player_create_audio_track(player, state);
1554+
if (err < 0)
1555+
goto error;
1556+
} else {
1557+
LOGI(3, "player_set_data_source: audio sample rate or channels are not recognized");
1558+
// Note: we try to ignore the un-recognized audio stream
1559+
player->stream_indexs[AVMEDIA_TYPE_AUDIO] = -1;
1560+
}
15521561
}
15531562
if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) {
15541563
err = stream_component_open(player, st_index[AVMEDIA_TYPE_VIDEO]);
@@ -1804,6 +1813,9 @@ void jni_player_dealloc(JNIEnv *env, jobject thiz) {
18041813
}
18051814
pthread_mutex_unlock(&player->mutex_operation);
18061815
LOGI(1, "jni_player_dealloc: render stopped...");
1816+
pthread_mutex_destroy(&player->mutex_operation);
1817+
pthread_mutex_destroy(&player->mutex_queue);
1818+
pthread_cond_destroy(&player->cond_queue);
18071819
free(player);
18081820
LOGI(1, "jni_player_dealloc: bye bye");
18091821
}

0 commit comments

Comments
 (0)