-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Attempt to fix FFMPEG 5.0 compatibility #5644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
2a05e5f
43922a6
866b30a
d0cadf9
3a927c6
7984483
f9c8987
5e11472
4c6c8fc
08232e4
2f79d6c
d124ee1
df9cb7e
2f7c02a
926a11e
2602ef4
b978ba1
0f02ed9
50d234f
1ffc0ad
f0212c0
41c0ad9
1811fa1
93e0863
3487c68
3c7e998
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,25 +18,6 @@ constexpr size_t kIoBufferSize = 96 * 1024; | |
constexpr size_t kIoPaddingSize = AV_INPUT_BUFFER_PADDING_SIZE; | ||
constexpr size_t kLogBufferSize = 1024; | ||
|
||
int ffmpeg_lock(void** mutex, enum AVLockOp op) { | ||
std::mutex** handle = (std::mutex**)mutex; | ||
switch (op) { | ||
case AV_LOCK_CREATE: | ||
*handle = new std::mutex(); | ||
break; | ||
case AV_LOCK_OBTAIN: | ||
(*handle)->lock(); | ||
break; | ||
case AV_LOCK_RELEASE: | ||
(*handle)->unlock(); | ||
break; | ||
case AV_LOCK_DESTROY: | ||
delete *handle; | ||
break; | ||
} | ||
return 0; | ||
} | ||
|
||
bool mapFfmpegType(AVMediaType media, MediaType* type) { | ||
switch (media) { | ||
case AVMEDIA_TYPE_AUDIO: | ||
|
@@ -202,8 +183,6 @@ void Decoder::initOnce() { | |
avcodec_register_all(); | ||
#endif | ||
avformat_network_init(); | ||
// register ffmpeg lock manager | ||
av_lockmgr_register(&ffmpeg_lock); | ||
av_log_set_callback(Decoder::logFunction); | ||
av_log_set_level(AV_LOG_ERROR); | ||
VLOG(1) << "Registered ffmpeg libs"; | ||
|
@@ -277,7 +256,7 @@ bool Decoder::init( | |
break; | ||
} | ||
|
||
fmt = av_find_input_format(fmtName); | ||
fmt = (AVInputFormat*)av_find_input_format(fmtName); | ||
} | ||
|
||
const size_t avioCtxBufferSize = kIoBufferSize; | ||
|
@@ -505,10 +484,14 @@ int Decoder::getFrame(size_t workingTimeInMs) { | |
// once decode() method gets called and grab some bytes | ||
// run this method again | ||
// init package | ||
AVPacket avPacket; | ||
av_init_packet(&avPacket); | ||
avPacket.data = nullptr; | ||
avPacket.size = 0; | ||
// update 03/22: moving memory management to ffmpeg | ||
AVPacket* avPacket; | ||
avPacket = av_packet_alloc(); | ||
if (avPacket == NULL) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this NULL be replaced by nullptr? the internal linter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we return inside this if-clause, otherwise we will access the NULL pointer in the next line. |
||
LOG(ERROR) << "decoder as not able to allocate the packet."; | ||
} | ||
avPacket->data = nullptr; | ||
avPacket->size = 0; | ||
|
||
auto end = std::chrono::steady_clock::now() + | ||
std::chrono::milliseconds(workingTimeInMs); | ||
|
@@ -521,7 +504,7 @@ int Decoder::getFrame(size_t workingTimeInMs) { | |
size_t decodingErrors = 0; | ||
bool decodedFrame = false; | ||
while (!interrupted_ && inRange_.any() && !decodedFrame && watcher()) { | ||
result = av_read_frame(inputCtx_, &avPacket); | ||
result = av_read_frame(inputCtx_, avPacket); | ||
if (result == AVERROR(EAGAIN)) { | ||
VLOG(4) << "Decoder is busy..."; | ||
std::this_thread::yield(); | ||
|
@@ -538,10 +521,11 @@ int Decoder::getFrame(size_t workingTimeInMs) { | |
break; | ||
} | ||
|
||
// get stream | ||
auto stream = findByIndex(avPacket.stream_index); | ||
// get stream; if stream cannot be found reset the packet to | ||
// default settings | ||
auto stream = findByIndex(avPacket->stream_index); | ||
if (stream == nullptr || !inRange_.test(stream->getIndex())) { | ||
av_packet_unref(&avPacket); | ||
av_packet_unref(avPacket); | ||
continue; | ||
} | ||
|
||
|
@@ -553,7 +537,7 @@ int Decoder::getFrame(size_t workingTimeInMs) { | |
bool hasMsg = false; | ||
// packet either got consumed completely or not at all | ||
if ((result = processPacket( | ||
stream, &avPacket, &gotFrame, &hasMsg, params_.fastSeek)) < 0) { | ||
stream, avPacket, &gotFrame, &hasMsg, params_.fastSeek)) < 0) { | ||
LOG(ERROR) << "processPacket failed with code: " << result; | ||
break; | ||
} | ||
|
@@ -585,10 +569,10 @@ int Decoder::getFrame(size_t workingTimeInMs) { | |
|
||
result = 0; | ||
|
||
av_packet_unref(&avPacket); | ||
av_packet_unref(avPacket); | ||
} | ||
|
||
av_packet_unref(&avPacket); | ||
av_packet_unref(avPacket); | ||
bjuncek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
VLOG(2) << "Interrupted loop" | ||
<< ", interrupted_ " << interrupted_ << ", inRange_.any() " | ||
|
Uh oh!
There was an error while loading. Please reload this page.