diff --git a/app/src/main/cpp/ffmpeg_pusher.cpp b/app/src/main/cpp/ffmpeg_pusher.cpp index 9ae1d16..4b4439b 100644 --- a/app/src/main/cpp/ffmpeg_pusher.cpp +++ b/app/src/main/cpp/ffmpeg_pusher.cpp @@ -4,7 +4,6 @@ #include #include -#include #include "ffmpeg_jni_define.h" #define TAG "FFmpegPusher" @@ -19,7 +18,6 @@ extern "C" { PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) { - AVOutputFormat *output_format = NULL; AVFormatContext *in_format = NULL, *out_format = NULL; AVPacket packet; const char *file_path, *live_url; @@ -77,8 +75,8 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) { // out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER; } } - output_format = out_format->oformat; - if (!(output_format->flags & AVFMT_NOFILE)) { + + if (!(out_format->oformat->flags & AVFMT_NOFILE)) { ret = avio_open(&out_format->pb, live_url, AVIO_FLAG_WRITE); if (ret < 0) { LOGE(TAG, "could not open output url '%s'", live_url); @@ -98,7 +96,7 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) { if (ret < 0) { break; } - //计算帧间隔,参考时钟/采样率 + // calculate pts and dts if (packet.pts == AV_NOPTS_VALUE) { AVRational time_base = in_format->streams[video_index]->time_base; int64_t cal_duration = (int64_t) (AV_TIME_BASE / @@ -123,9 +121,9 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) { //pts to dts packet.pts = av_rescale_q_rnd(packet.pts, in_stream->time_base, out_stream->time_base, - (AVRounding) (AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)); + AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX); packet.dts = av_rescale_q_rnd(packet.dts, in_stream->time_base, out_stream->time_base, - (AVRounding) (AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX)); + AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX); packet.duration = av_rescale_q(packet.duration, in_stream->time_base, out_stream->time_base); packet.pos = -1; @@ -146,13 +144,12 @@ PUSHER_FUNC(jint, pushStream, jstring filePath, jstring liveUrl) { //Write tail av_write_trailer(out_format); - end: - avformat_close_input(&in_format); +end: if (out_format && !(out_format->flags & AVFMT_NOFILE)) { avio_close(out_format->pb); } - avformat_free_context(in_format); avformat_free_context(out_format); + avformat_close_input(&in_format); env->ReleaseStringUTFChars(filePath, file_path); env->ReleaseStringUTFChars(liveUrl, live_url); if (ret < 0 && ret != AVERROR_EOF) { diff --git a/app/src/main/cpp/media_player.cpp b/app/src/main/cpp/media_player.cpp index 41a6e25..b6ca446 100644 --- a/app/src/main/cpp/media_player.cpp +++ b/app/src/main/cpp/media_player.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -486,8 +485,8 @@ MEDIA_PLAYER_FUNC(void, release){ av_free(player->yuv_frame); av_free(player->audio_buffer); av_free(player->audio_frame); - avcodec_close(player->video_codec_context); - avcodec_close(player->audio_codec_context); + avcodec_free_context(&player->video_codec_context); + avcodec_free_context(&player->audio_codec_context); avformat_close_input(&player->format_context); ANativeWindow_release(player->native_window); delete_queue(player); diff --git a/app/src/main/cpp/openSL_audio_player.cpp b/app/src/main/cpp/openSL_audio_player.cpp index 4080337..0236b69 100644 --- a/app/src/main/cpp/openSL_audio_player.cpp +++ b/app/src/main/cpp/openSL_audio_player.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #ifdef __cplusplus extern "C" { @@ -241,7 +240,7 @@ int releaseAudioPlayer() { av_packet_unref(&packet); av_free(outputBuffer); av_free(aFrame); - avcodec_close(aCodecCtx); + avcodec_free_context(&aCodecCtx); avformat_close_input(&aFormatCtx); return 0; } diff --git a/app/src/main/cpp/video_filter.c b/app/src/main/cpp/video_filter.c index f05dd70..2a15982 100644 --- a/app/src/main/cpp/video_filter.c +++ b/app/src/main/cpp/video_filter.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/app/src/main/cpp/video_player.cpp b/app/src/main/cpp/video_player.cpp index 8cc034c..c8a356f 100644 --- a/app/src/main/cpp/video_player.cpp +++ b/app/src/main/cpp/video_player.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #ifdef __cplusplus extern "C" { @@ -130,7 +129,7 @@ VIDEO_PLAYER_FUNC(jint, play, jstring filePath, jobject surface) { av_free(buffer); av_free(pFrameRGBA); av_free(pFrame); - avcodec_close(pCodecCtx); + avcodec_free_context(&pCodecCtx); avformat_close_input(&pFormatCtx); return 0; }