Skip to content

add UUID in LOG() in decoder #3080

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

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions torchvision/csrc/cpu/decoder/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ bool Decoder::enableLogLevel(int level) const {
}

void Decoder::logCallback(int level, const std::string& message) {
LOG(INFO) << "Msg, level: " << level << ", msg: " << message;
LOG(INFO) << "Msg, uuid=" << params_.loggingUuid << " level=" << level
<< " msg=" << message;
}

/* static */
Expand Down Expand Up @@ -221,16 +222,18 @@ bool Decoder::init(
cleanUp();

if ((params.uri.empty() || in) && (!params.uri.empty() || !in)) {
LOG(ERROR) << "Either external URI gets provided"
<< " or explicit input callback";
LOG(ERROR)
<< "uuid=" << params_.loggingUuid
<< " either external URI gets provided or explicit input callback";
return false;
}

// set callback and params
params_ = params;

if (!(inputCtx_ = avformat_alloc_context())) {
LOG(ERROR) << "Cannot allocate format context";
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " cannot allocate format context";
return false;
}

Expand All @@ -243,7 +246,8 @@ bool Decoder::init(
params_.timeoutMs,
params_.maxSeekableBytes,
params_.isImage ? &type : nullptr)) < 0) {
LOG(ERROR) << "can't initiate seekable buffer";
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " can't initiate seekable buffer";
cleanUp();
return false;
}
Expand Down Expand Up @@ -271,7 +275,8 @@ bool Decoder::init(
uint8_t* avioCtxBuffer =
(uint8_t*)av_malloc(avioCtxBufferSize + kIoPaddingSize);
if (!avioCtxBuffer) {
LOG(ERROR) << "av_malloc cannot allocate " << avioCtxBufferSize
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " av_malloc cannot allocate " << avioCtxBufferSize
<< " bytes";
cleanUp();
return false;
Expand All @@ -285,7 +290,8 @@ bool Decoder::init(
&Decoder::readFunction,
nullptr,
result == 1 ? &Decoder::seekFunction : nullptr))) {
LOG(ERROR) << "avio_alloc_context failed";
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " avio_alloc_context failed";
av_free(avioCtxBuffer);
cleanUp();
return false;
Expand Down Expand Up @@ -323,7 +329,8 @@ bool Decoder::init(
guard = std::make_unique<std::thread>([&f, this]() {
auto timeout = std::chrono::milliseconds(params_.timeoutMs);
if (std::future_status::timeout == f.wait_for(timeout)) {
LOG(ERROR) << "Cannot open stream within " << params_.timeoutMs
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " cannot open stream within " << params_.timeoutMs
<< " ms";
interrupted_ = true;
}
Expand All @@ -346,7 +353,8 @@ bool Decoder::init(
}

if (result < 0 || interrupted_) {
LOG(ERROR) << "avformat_open_input failed, error: "
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " avformat_open_input failed, error="
<< Util::generateErrorDesc(result);
cleanUp();
return false;
Expand All @@ -355,14 +363,15 @@ bool Decoder::init(
result = avformat_find_stream_info(inputCtx_, nullptr);

if (result < 0) {
LOG(ERROR) << "avformat_find_stream_info failed, error: "
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " avformat_find_stream_info failed, error="
<< Util::generateErrorDesc(result);
cleanUp();
return false;
}

if (!openStreams(metadata)) {
LOG(ERROR) << "Cannot activate streams";
LOG(ERROR) << "uuid=" << params_.loggingUuid << " cannot activate streams";
cleanUp();
return false;
}
Expand Down Expand Up @@ -418,7 +427,8 @@ bool Decoder::openStreams(std::vector<DecoderMetadata>* metadata) {
params_.loggingUuid);
CHECK(stream);
if (stream->openCodec(metadata) < 0) {
LOG(ERROR) << "Cannot open codec " << i;
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " open codec failed, stream_idx=" << i;
return false;
}
streams_.emplace(i, std::move(stream));
Expand Down Expand Up @@ -518,13 +528,15 @@ 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)) < 0) {
LOG(ERROR) << "processPacket failed with code: " << result;
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " processPacket failed with code=" << result;
break;
}

if (!gotFrame && params_.maxProcessNoBytes != 0 &&
++numConsecutiveNoBytes > params_.maxProcessNoBytes) {
LOG(ERROR) << "Exceeding max amount of consecutive no bytes";
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " exceeding max amount of consecutive no bytes";
break;
}
if (result > 0) {
Expand All @@ -538,7 +550,8 @@ int Decoder::getFrame(size_t workingTimeInMs) {
if (result < 0) {
if (params_.maxPackageErrors != 0 && // check errors
++decodingErrors >= params_.maxPackageErrors) { // reached the limit
LOG(ERROR) << "Exceeding max amount of consecutive package errors";
LOG(ERROR) << "uuid=" << params_.loggingUuid
<< " exceeding max amount of consecutive package errors";
break;
}
} else {
Expand Down