diff --git a/framework/data_source/ffmpeg_data_source.cpp b/framework/data_source/ffmpeg_data_source.cpp index 1fb2c33a1..ccf3a2397 100644 --- a/framework/data_source/ffmpeg_data_source.cpp +++ b/framework/data_source/ffmpeg_data_source.cpp @@ -11,8 +11,8 @@ #include extern "C" { +#include #include -#include } using std::string; namespace Cicada { @@ -35,7 +35,7 @@ namespace Cicada { { AVDictionary *format_opts = nullptr; av_dict_set_int(&format_opts, "rw_timeout", mConfig.low_speed_time_ms * 1000, 0); - int ret = ffurl_open(&mPuc, mUri.c_str(), AVIO_FLAG_READ | AVIO_FLAG_NONBLOCK, &mInterruptCB, &format_opts); + int ret = avio_open2(&mPuc, mUri.c_str(), AVIO_FLAG_READ | AVIO_FLAG_NONBLOCK, &mInterruptCB, &format_opts); if (ret == AVERROR_PROTOCOL_NOT_FOUND) { ret = FRAMEWORK_ERR_PROTOCOL_NOT_SUPPORT; @@ -45,7 +45,7 @@ namespace Cicada { } if (rangeStart != INT64_MIN) { - ffurl_seek(mPuc, (int64_t) rangeStart, SEEK_SET); + avio_seek(mPuc, (int64_t) rangeStart, SEEK_SET); } return ret; @@ -54,22 +54,30 @@ namespace Cicada { void ffmpegDataSource::Close() { if (mPuc) { - ffurl_closep(&mPuc); - mPuc = nullptr; + avio_closep(&mPuc); } } int64_t ffmpegDataSource::Seek(int64_t offset, int whence) { - if (whence == SEEK_SIZE) { - whence = AVSEEK_SIZE; + if (mPuc == nullptr) { + return -EINVAL; } - - if (mPuc) { - return ffurl_seek(mPuc, offset, whence); + int64_t pos = offset; + switch (whence) { + case SEEK_SIZE: + return avio_size(mPuc); + case SEEK_END: { + int64_t size = avio_size(mPuc); + if (size <= 0) { + return -EINVAL; + } + pos = size + offset; + whence = SEEK_SET; + } + default: + return avio_seek(mPuc, pos, whence); } - - return -EINVAL; } int ffmpegDataSource::Read(void *buf, size_t nbyte) @@ -82,7 +90,7 @@ namespace Cicada { } } - int ret = ffurl_read(mPuc, (unsigned char *) buf, nbyte); + int ret = avio_read(mPuc, (unsigned char *) buf, nbyte); if (ret == AVERROR_EOF) { ret = 0; diff --git a/framework/data_source/ffmpeg_data_source.h b/framework/data_source/ffmpeg_data_source.h index 7cdb60a35..0f142cbc0 100644 --- a/framework/data_source/ffmpeg_data_source.h +++ b/framework/data_source/ffmpeg_data_source.h @@ -64,7 +64,7 @@ namespace Cicada { static ffmpegDataSource se; private: - URLContext *mPuc{}; + AVIOContext *mPuc{}; AVIOInterruptCB mInterruptCB{}; int mInterrupted{}; char mErrorMsg[AV_ERROR_MAX_STRING_SIZE]{};