Skip to content

Commit

Permalink
improvement(avformatdemuxer): covert o to AVERROR_EOF in read cb
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Jul 3, 2020
1 parent 27a0575 commit d091136
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion framework/data_source/dataSourceIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace Cicada {
{
auto *pHandle = static_cast<dataSourceIO *>(arg);
// AF_LOGE("read_callback", "%s %d \n", __func__, size);
return pHandle->mPDataSource->Read(buffer, size);
int ret = pHandle->mPDataSource->Read(buffer, size);
return ret ? ret : AVERROR_EOF;
}

int64_t dataSourceIO::seek_callback(void *arg, int64_t offset, int whence)
Expand Down
17 changes: 14 additions & 3 deletions framework/demuxer/avFormatDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ namespace Cicada {

if (mReadCb != nullptr ) {
uint8_t *read_buffer = static_cast<uint8_t *>(av_malloc(INITIAL_BUFFER_SIZE));
mPInPutPb = avio_alloc_context(read_buffer, INITIAL_BUFFER_SIZE, 0, mUserArg, mReadCb, nullptr, mSeekCb);
mPInPutPb = avio_alloc_context(read_buffer, INITIAL_BUFFER_SIZE, 0, this, mReadCb ? avio_callback_read : nullptr, nullptr,
mSeekCb ? avio_callback_seek : nullptr);

if (mPInPutPb == nullptr) {
av_free(read_buffer);
Expand Down Expand Up @@ -232,7 +233,7 @@ namespace Cicada {
err = av_read_frame(mCtx, pkt);

if (err < 0) {
if (err != AVERROR(EAGAIN)) {
if (err != AVERROR(EAGAIN) && err != AVERROR_EOF) {
if (mCtx->pb && mCtx->pb->error != AVERROR_EXIT) {
av_log(NULL, AV_LOG_WARNING, "%s:%d: %s, ctx->pb->error=%d\n", __FILE__, __LINE__, getErrorString(err),
mCtx->pb->error);
Expand Down Expand Up @@ -704,5 +705,15 @@ namespace Cicada {
mQueCond.notify_one();
#endif
}

int avFormatDemuxer::avio_callback_read(void *arg, uint8_t *buffer, int size)
{
auto *demuxer = static_cast<avFormatDemuxer *>(arg);
int ret = demuxer->mReadCb(demuxer->mUserArg, buffer, size);
return ret ? ret : AVERROR_EOF;
}
int64_t avFormatDemuxer::avio_callback_seek(void *arg, int64_t offset, int whence)
{
auto *demuxer = static_cast<avFormatDemuxer *>(arg);
return demuxer->mSeekCb(demuxer->mUserArg, offset, whence);
}
}
4 changes: 4 additions & 0 deletions framework/demuxer/avFormatDemuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ namespace Cicada {

int ReadPacketInternal(std::unique_ptr<IAFPacket> &packet);

static inline int avio_callback_read(void *arg, uint8_t *buffer, int size);

static inline int64_t avio_callback_seek(void *arg, int64_t offset, int whence);

#if AF_HAVE_PTHREAD

int readLoop();
Expand Down

0 comments on commit d091136

Please sign in to comment.