diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index df9afa8..0b53630 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -34,7 +34,14 @@ set(SRC_METADATA set(SRC_FFPLAYER ffplayer/queue/FrameQueue.cpp - ffplayer/queue/PacketQueue.cpp) + ffplayer/queue/PacketQueue.cpp + ffplayer/decode/BaseDecoder.cpp + ffplayer/decode/FFAudioDecoder.cpp + ffplayer/decode/FFVideoDecoder.cpp + ffplayer/clock/MediaClock.cpp + ffplayer/render/android/AudioAndroidRender.cpp + ffplayer/FFMessageQueue.cpp + ffplayer/FFMediaPlayer.cpp) add_library( # Sets the name of the library. media-handle @@ -74,6 +81,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") include_directories(.) include_directories(include) include_directories(metadata) +include_directories(ffplayer) if(${CMAKE_ANDROID_ARCH_ABI} MATCHES "armeabi-v7a") include_directories(include/armeabi-v7a) diff --git a/app/src/main/cpp/ffplayer/FFMessageQueue.cpp b/app/src/main/cpp/ffplayer/FFMessageQueue.cpp index efcaaec..3999402 100644 --- a/app/src/main/cpp/ffplayer/FFMessageQueue.cpp +++ b/app/src/main/cpp/ffplayer/FFMessageQueue.cpp @@ -1,6 +1,3 @@ -// -// Created by xu fulong on 2022/9/24. -// #include "FFMessageQueue.h" diff --git a/app/src/main/cpp/ffplayer/FFMessageQueue.h b/app/src/main/cpp/ffplayer/FFMessageQueue.h index 2c4ec83..bad8e28 100644 --- a/app/src/main/cpp/ffplayer/FFMessageQueue.h +++ b/app/src/main/cpp/ffplayer/FFMessageQueue.h @@ -1,6 +1,3 @@ -// -// Created by xu fulong on 2022/9/24. -// #ifndef FFMPEGANDROID_FFMESSAGEQUEUE_H #define FFMPEGANDROID_FFMESSAGEQUEUE_H @@ -26,6 +23,8 @@ #define FFP_MSG_COMPONENT_OPEN 409 #define FFP_MSG_VIDEO_SEEK_RENDERING_START 410 #define FFP_MSG_AUDIO_SEEK_RENDERING_START 411 +#define FFP_MSG_DECODER_OPEN_ERROR 412 +#define FFP_MSG_DEMUX_ERROR 413 #define FFP_MSG_BUFFERING_START 500 #define FFP_MSG_BUFFERING_END 501 @@ -36,6 +35,7 @@ #define FFP_MSG_PLAYBACK_STATE_CHANGED 700 #define FFP_MSG_TIMED_TEXT 800 #define FFP_MSG_VIDEO_DECODER_OPEN 900 +#define FFP_MSG_OPEN_ERROR 901 #define FFP_REQ_START 1001 #define FFP_REQ_PAUSE 1002 diff --git a/app/src/main/cpp/ffplayer/clock/MediaClock.cpp b/app/src/main/cpp/ffplayer/clock/MediaClock.cpp new file mode 100644 index 0000000..dce88ac --- /dev/null +++ b/app/src/main/cpp/ffplayer/clock/MediaClock.cpp @@ -0,0 +1,50 @@ + +#include +#include "MediaClock.h" + +MediaClock::MediaClock() { + m_speed = 1.0; + m_pause = false; + setClock(NAN); +} + +void MediaClock::setClock(double pts) { + double time = (double) av_gettime_relative() / 1000000.0; + setClock(pts, time); +} + +void MediaClock::setClock(double pts, double time) { + m_pts = pts; + m_last_update = time; + m_pts_drift = m_pts - time; +} + +double MediaClock::getClock() const { + if (m_pause) { + return m_pts; + } else { + double time = (double) av_gettime_relative() / 1000000.0; + return m_pts_drift + time - (time - m_last_update) * (1.0 - m_speed); + } +} + +void MediaClock::setSpeed(double speed) { + setClock(getClock()); + m_speed = speed; +} + +double MediaClock::getSpeed() const { + return m_speed; +} + +void MediaClock::syncToSlave(MediaClock *slave) { + double clock = getClock(); + double slave_clock = slave->getClock(); + if (!isnan(slave_clock) && (isnan(clock) || fabs(clock - slave_clock) > AV_NOSYNC_THRESHOLD)) { + setClock(slave_clock); + } +} + +MediaClock::~MediaClock() { + +} \ No newline at end of file diff --git a/app/src/main/cpp/ffplayer/clock/MediaClock.h b/app/src/main/cpp/ffplayer/clock/MediaClock.h new file mode 100644 index 0000000..0b1df8b --- /dev/null +++ b/app/src/main/cpp/ffplayer/clock/MediaClock.h @@ -0,0 +1,45 @@ + +#ifndef FFMPEGANDROID_MEDIACLOCK_H +#define FFMPEGANDROID_MEDIACLOCK_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif +#include +#ifdef __cplusplus +} +#endif + +class MediaClock { + +private: + bool m_pause; + double m_pts; + double m_speed; + double m_pts_drift; + double m_last_update; + +public: + + MediaClock(); + + void setClock(double pts); + + void setClock(double pts, double time); + + double getClock() const; + + void setSpeed(double speed); + + double getSpeed() const; + + void syncToSlave(MediaClock *slave); + + virtual ~MediaClock(); + +}; + + +#endif //FFMPEGANDROID_MEDIACLOCK_H diff --git a/app/src/main/cpp/ffplayer/ffplay_define.h b/app/src/main/cpp/ffplayer/ffplay_define.h index ca05036..90968f4 100644 --- a/app/src/main/cpp/ffplayer/ffplay_define.h +++ b/app/src/main/cpp/ffplayer/ffplay_define.h @@ -1,6 +1,3 @@ -// -// Created by xu fulong on 2022/9/22. -// #ifndef FFMPEGANDROID_FFPLAY_DEFINE_H #define FFMPEGANDROID_FFPLAY_DEFINE_H @@ -57,7 +54,7 @@ class PlayerParams { public: std::mutex mutex; - MessageQueue *messageQueue; + FFMessageQueue *messageQueue; int64_t videoDuration; AVInputFormat *iformat;