diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index ae0daf8..e7c52f8 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -27,7 +27,7 @@ add_library( # Sets the name of the library. src/main/cpp/ffmpeg/ffmpeg_hw.c src/main/cpp/audio_player.c src/main/cpp/openSL_audio_player.c - src/main/cpp/video_player.c + src/main/cpp/video_player.cpp src/main/cpp/ffmpeg_pusher.cpp src/main/cpp/packet_queue.cpp src/main/cpp/media_player.cpp diff --git a/app/src/main/cpp/video_player.c b/app/src/main/cpp/video_player.cpp similarity index 93% rename from app/src/main/cpp/video_player.c rename to app/src/main/cpp/video_player.cpp index 8ba996b..8cc034c 100644 --- a/app/src/main/cpp/video_player.c +++ b/app/src/main/cpp/video_player.cpp @@ -1,16 +1,23 @@ // // Created by frank on 2018/2/1. // -#include "libavcodec/avcodec.h" -#include "libavformat/avformat.h" -#include "libswscale/swscale.h" #include #include #include #include -#include #include + +#ifdef __cplusplus +extern "C" { +#endif +#include "libavcodec/avcodec.h" +#include "libavformat/avformat.h" +#include "libswscale/swscale.h" +#include "libavutil/imgutils.h" #include "ffmpeg_jni_define.h" +#ifdef __cplusplus +} +#endif #define TAG "VideoPlayer" @@ -19,7 +26,7 @@ long duration = 0; VIDEO_PLAYER_FUNC(jint, play, jstring filePath, jobject surface) { - const char *file_name = (*env)->GetStringUTFChars(env, filePath, JNI_FALSE); + const char *file_name = env->GetStringUTFChars( filePath, JNI_FALSE); LOGE(TAG, "open file:%s\n", file_name); av_register_all(); AVFormatContext *pFormatCtx = avformat_alloc_context(); @@ -33,7 +40,7 @@ VIDEO_PLAYER_FUNC(jint, play, jstring filePath, jobject surface) { } int videoStream = -1, i; for (i = 0; i < pFormatCtx->nb_streams; i++) { - if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO + if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && videoStream < 0) { videoStream = i; } @@ -106,7 +113,7 @@ VIDEO_PLAYER_FUNC(jint, play, jstring filePath, jobject surface) { sws_scale(sws_ctx, (uint8_t const *const *) pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGBA->data, pFrameRGBA->linesize); - uint8_t *dst = windowBuffer.bits; + uint8_t *dst = static_cast(windowBuffer.bits); int dstStride = windowBuffer.stride * 4; uint8_t *src = pFrameRGBA->data[0]; int srcStride = pFrameRGBA->linesize[0];