Skip to content

Commit

Permalink
refactor(ffmpeg_data_source): use avio* insteadof ffurl*
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai authored and I-m-SuperMan committed Aug 3, 2020
1 parent fcda864 commit 6841c17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 21 additions & 13 deletions framework/data_source/ffmpeg_data_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <utils/ffmpeg_utils.h>

extern "C" {
#include <libavformat/avio.h>
#include <libavutil/error.h>
#include <libavutil/common.h>
}
using std::string;
namespace Cicada {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion framework/data_source/ffmpeg_data_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]{};
Expand Down

0 comments on commit 6841c17

Please sign in to comment.