Skip to content

Commit

Permalink
logs and exception are prefixed by the module name - fix 53
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouqueau committed Apr 19, 2016
1 parent 0a8ffaf commit c950d44
Show file tree
Hide file tree
Showing 40 changed files with 249 additions and 214 deletions.
16 changes: 8 additions & 8 deletions src/apps/dashcastx/pipeliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ namespace {
Encode::LibavEncode* createEncoder(std::shared_ptr<const IMetadata> metadata, const dashcastXOptions &opt, size_t i) {
auto const codecType = metadata->getStreamType();
if (codecType == VIDEO_PKT) {
Log::msg(Log::Info, "[Encoder] Found video stream");
Log::msg(Info, "[Encoder] Found video stream");
Encode::LibavEncodeParams p;
p.isLowLatency = opt.isLive;
p.res = opt.v[i].res;
p.bitrate_v = opt.v[i].bitrate;
return new Encode::LibavEncode(Encode::LibavEncode::Video, p);
} else if (codecType == AUDIO_PKT) {
Log::msg(Log::Info, "[Encoder] Found audio stream");
Log::msg(Info, "[Encoder] Found audio stream");
return new Encode::LibavEncode(Encode::LibavEncode::Audio);
} else {
Log::msg(Log::Info, "[Encoder] Found unknown stream");
Log::msg(Info, "[Encoder] Found unknown stream");
return nullptr;
}
}

ModuleS* createConverter(std::shared_ptr<const IMetadata> metadata, const Resolution &dstRes) {
auto const codecType = metadata->getStreamType();
if (codecType == VIDEO_PKT) {
Log::msg(Log::Info, "[Converter] Found video stream");
Log::msg(Info, "[Converter] Found video stream");
auto dstFormat = PictureFormat(dstRes, YUV420P);
return new Transform::VideoConvert(dstFormat);
} else if (codecType == AUDIO_PKT) {
Log::msg(Log::Info, "[Converter] Found audio stream");
Log::msg(Info, "[Converter] Found audio stream");
auto format = PcmFormat(44100, 2, AudioLayout::Stereo, AudioSampleFormat::F32, AudioStruct::Planar);
return new Transform::AudioConvert(format);
} else {
Log::msg(Log::Info, "[Converter] Found unknown stream");
Log::msg(Info, "[Converter] Found unknown stream");
return nullptr;
}
}
Expand All @@ -55,14 +55,14 @@ void declarePipeline(Pipeline &pipeline, const dashcastXOptions &opt) {

const bool transcode = opt.v.size() > 0 ? true : false;
if (!transcode) {
Log::msg(Log::Warning, "[DashcastX] No transcode. Make passthru.");
Log::msg(Warning, "[DashcastX] No transcode. Make passthru.");
}

int numDashInputs = 0;
for (size_t i = 0; i < demux->getNumOutputs(); ++i) {
auto const metadata = getMetadataFromOutput<MetadataPktLibav>(demux->getOutput(i));
if (!metadata) {
Log::msg(Log::Warning, "[DashcastX] Unknown metadata for stream %s. Ignoring.", i);
Log::msg(Warning, "[DashcastX] Unknown metadata for stream %s. Ignoring.", i);
break;
}

Expand Down
6 changes: 3 additions & 3 deletions src/apps/player/pipeliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ using namespace Pipelines;
namespace {
ModuleS* createRenderer(int codecType) {
if (codecType == VIDEO_PKT) {
Log::msg(Log::Info, "Found video stream");
Log::msg(Info, "Found video stream");
return new Render::SDLVideo();
} else if (codecType == AUDIO_PKT) {
Log::msg(Log::Info, "Found audio stream");
Log::msg(Info, "Found audio stream");
return new Render::SDLAudio();
} else {
Log::msg(Log::Info, "Found unknown stream");
Log::msg(Info, "Found unknown stream");
return new Out::Null;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/lib_media/common/libav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ extern "C" {
}

namespace {
Log::Level avLogLevel(int level) {
Level avLogLevel(int level) {
switch (level) {
case AV_LOG_QUIET:
case AV_LOG_PANIC:
case AV_LOG_FATAL:
case AV_LOG_ERROR:
return Log::Warning;
return Warning;
case AV_LOG_WARNING:
case AV_LOG_INFO:
return Log::Info;
return Info;
case AV_LOG_VERBOSE:
return Log::Debug;
return Debug;
case AV_LOG_DEBUG:
case AV_LOG_TRACE:
return Log::Quiet;
return Quiet;
default:
assert(0);
return Log::Debug;
return Debug;
}
}

Expand Down Expand Up @@ -221,7 +221,7 @@ DataAVPacket::DataAVPacket(size_t size)
}

DataAVPacket::~DataAVPacket() {
Log::msg(Log::Debug, "Freeing %s, pts=%s", this, pkt->pts);
Log::msg(Debug, "Freeing %s, pts=%s", this, pkt->pts);
}

uint8_t* DataAVPacket::data() {
Expand Down Expand Up @@ -258,7 +258,7 @@ void buildAVDictionary(const std::string &moduleName, AVDictionary **dict, const
char *tokval = nullptr;
while (tok && (tokval = strtok(nullptr, "- "))) {
if (av_dict_set(dict, tok, tokval, 0) < 0) {
Log::msg(Log::Warning, "[%s] unknown %s option \"%s\" with value \"%s\"", moduleName.c_str(), type, tok, tokval);
Log::msg(Warning, "[%s] unknown %s option \"%s\" with value \"%s\"", moduleName.c_str(), type, tok, tokval);
}
tok = strtok(nullptr, "- ");
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib_media/common/pcm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ class PcmFormat {

bool operator==(const PcmFormat& other) const {
if (other.sampleRate != sampleRate) {
Log::msg(Log::Info, "[Audio] Incompatible configuration: sample rate is %s, expect %s.", other.sampleRate, sampleRate);
Log::msg(Info, "[Audio] Incompatible configuration: sample rate is %s, expect %s.", other.sampleRate, sampleRate);
return false;
}
if (other.numChannels != numChannels) {
Log::msg(Log::Info, "[Audio] Incompatible configuration: channel number is %s, expect %s.", other.numChannels, numChannels);
Log::msg(Info, "[Audio] Incompatible configuration: channel number is %s, expect %s.", other.numChannels, numChannels);
return false;
}
if (other.layout != layout) {
Log::msg(Log::Info, "[Audio] Incompatible configuration: layout is %s, expect %s.", other.layout, layout);
Log::msg(Info, "[Audio] Incompatible configuration: layout is %s, expect %s.", other.layout, layout);
return false;
}
if (other.sampleFormat != sampleFormat) {
Log::msg(Log::Info, "[Audio] Incompatible configuration: sample format is %s, expect %s.", other.sampleFormat, sampleFormat);
Log::msg(Info, "[Audio] Incompatible configuration: sample format is %s, expect %s.", other.sampleFormat, sampleFormat);
return false;
}
if (other.numPlanes != numPlanes) {
Log::msg(Log::Info, "[Audio] Incompatible configuration: plane number is %s, expect %s.", other.numPlanes, numPlanes);
Log::msg(Info, "[Audio] Incompatible configuration: plane number is %s, expect %s.", other.numPlanes, numPlanes);
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions src/lib_media/decode/jpegturbo_decode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "jpegturbo_decode.hpp"
#include "../common/libav.hpp"
#include "lib_utils/log.hpp"
#include "lib_utils/tools.hpp"
extern "C" {
#include <turbojpeg.h>
Expand Down Expand Up @@ -63,12 +62,12 @@ void JPEGTurboDecode::process(Data data_) {
int w, h, jpegSubsamp;
auto jpegBuf = data->data();
if (tjDecompressHeader2(jtHandle->get(), (unsigned char*)jpegBuf, (unsigned long)data->size(), &w, &h, &jpegSubsamp) < 0) {
Log::msg(Log::Warning, "[jpegturbo_decode] error encountered while decompressing header.");
log(Warning, "error encountered while decompressing header.");
return;
}
auto out = DataPicture::create(output, Resolution(w, h), RGB24);
if (tjDecompress2(jtHandle->get(), (unsigned char*)jpegBuf, (unsigned long)data->size(), out->data(), w, 0/*pitch*/, h, pixelFmt, TJFLAG_FASTDCT) < 0) {
Log::msg(Log::Warning, "[jpegturbo_decode] error encountered while decompressing frame.");
log(Warning, "error encountered while decompressing frame.");
return;
}
ensureMetadata(w, h, pixelFmt);
Expand Down
13 changes: 6 additions & 7 deletions src/lib_media/decode/libav_decode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "libav_decode.hpp"
#include "../common/pcm.hpp"
#include "lib_utils/log.hpp"
#include "lib_utils/tools.hpp"
#include "lib_ffpp/ffpp.hpp"
#include <cassert>
Expand All @@ -22,19 +21,19 @@ LibavDecode::LibavDecode(const MetadataPktLibav &metadata)
switch (codecCtx->codec_type) {
case AVMEDIA_TYPE_VIDEO: break;
case AVMEDIA_TYPE_AUDIO: break;
default: throw std::runtime_error(format("[LibavDecode] codec_type %s not supported. Must be audio or video.", codecCtx->codec_type));
default: throw error(format("codec_type %s not supported. Must be audio or video.", codecCtx->codec_type));
}

//find an appropriate decode
auto codec = avcodec_find_decoder(codecCtx->codec_id);
if (!codec)
throw std::runtime_error(format("[LibavDecode] Decoder not found for codecID(%s).", codecCtx->codec_id));
throw error(format("Decoder not found for codecID(%s).", codecCtx->codec_id));

//force single threaded as h264 probing seems to miss SPS/PPS and seek fails silently
ffpp::Dict dict;
dict.set("threads", "1");
if (avcodec_open2(codecCtx, codec, &dict) < 0) {
throw std::runtime_error("[LibavDecode] Couldn't open stream.");
throw error("Couldn't open stream.");
}

switch (codecCtx->codec_type) {
Expand All @@ -51,7 +50,7 @@ LibavDecode::LibavDecode(const MetadataPktLibav &metadata)
break;
}
default:
throw std::runtime_error("[LibavDecode] Invalid output type.");
throw error("Invalid output type.");
}
}

Expand All @@ -64,7 +63,7 @@ bool LibavDecode::processAudio(const DataAVPacket *data) {
AVPacket *pkt = data->getPacket();
int gotFrame;
if (avcodec_decode_audio4(codecCtx, avFrame->get(), &gotFrame, pkt) < 0) {
Log::msg(Log::Warning, "[LibavDecode] Error encoutered while decoding audio.");
log(Warning, "Error encoutered while decoding audio.");
return false;
}
if (gotFrame) {
Expand Down Expand Up @@ -111,7 +110,7 @@ bool LibavDecode::processVideo(const DataAVPacket *data) {
AVPacket *pkt = data->getPacket();
int gotPicture;
if (avcodec_decode_video2(codecCtx, avFrame->get(), &gotPicture, pkt) < 0) {
Log::msg(Log::Warning, "[LibavDecode] Error encoutered while decoding video.");
log(Warning, "Error encoutered while decoding video.");
return false;
}
if (gotPicture) {
Expand Down
11 changes: 5 additions & 6 deletions src/lib_media/demux/gpac_demux_mp4_full.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "gpac_demux_mp4_full.hpp"
#include "lib_utils/log.hpp"
#include "lib_utils/tools.hpp"
#include <string>
#include <sstream>
Expand Down Expand Up @@ -47,7 +46,7 @@ bool GPACDemuxMP4Full::openData() {
GF_ISOFile *movie;
GF_Err e = gf_isom_open_progressive(reader->dataUrl.c_str(), 0, 0, &movie, &missingBytes);
if ((e != GF_OK && e != GF_ISOM_INCOMPLETE_FILE) || reader->movie) {
Log::msg(Log::Warning, "Error opening fragmented mp4 in progressive mode: %s (missing %s bytes)",
log(Warning, "Error opening fragmented mp4 in progressive mode: %s (missing %s bytes)",
gf_error_to_string(e), missingBytes);

return false;
Expand All @@ -74,7 +73,7 @@ bool GPACDemuxMP4Full::processSample() {
newSampleCount = reader->movie->getSampleCount(reader->trackNumber);
if (newSampleCount > reader->sampleCount) {
/* New samples have been added to the file */
Log::msg(Log::Info, "Found %s new samples (total: %s)",
log(Info, "Found %s new samples (total: %s)",
newSampleCount - reader->sampleCount,
newSampleCount);
if (reader->sampleCount == 0) {
Expand All @@ -99,7 +98,7 @@ bool GPACDemuxMP4Full::processSample() {

reader->samplesProcessed++;
/*here we dump some sample info: samp->data, samp->dataLength, samp->isRAP, samp->DTS, samp->CTS_Offset */
Log::msg(Log::Debug,
log(Debug,
"Found sample #%s(#%s) of length %s , RAP: %s, DTS : %s, CTS : %s",
reader->sampleIndex,
reader->samplesProcessed,
Expand All @@ -120,7 +119,7 @@ bool GPACDemuxMP4Full::processSample() {
u64 newBufferStart = 0;
u64 missingBytes;

Log::msg(Log::Debug, "Releasing unnecessary buffers");
log(Debug, "Releasing unnecessary buffers");
/* release internal structures associated with the samples read so far */
reader->movie->resetTables(true);

Expand All @@ -146,7 +145,7 @@ bool GPACDemuxMP4Full::processSample() {

return true;
} catch(gpacpp::Error const& e) {
Log::msg(Log::Warning, "Could not get sample: %s", gf_error_to_string(e.error_));
log(Warning, "Could not get sample: %s", gf_error_to_string(e.error_));
return false;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/lib_media/demux/gpac_demux_mp4_simple.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "gpac_demux_mp4_simple.hpp"
#include "lib_utils/log.hpp"
#include "lib_utils/tools.hpp"

#include "lib_gpacpp/gpacpp.hpp"
Expand Down Expand Up @@ -28,7 +27,7 @@ GPACDemuxMP4Simple::GPACDemuxMP4Simple(std::string const& path)
u64 missingBytes;
GF_Err e = gf_isom_open_progressive(path.c_str(), 0, 0, &movie, &missingBytes);
if ((e != GF_OK && e != GF_ISOM_INCOMPLETE_FILE) || movie == nullptr) {
throw std::runtime_error(format("Could not open file %s for reading (%s).", path, gf_error_to_string(e)));
throw error(format("Could not open file %s for reading (%s).", path, gf_error_to_string(e)));
}
reader->init(movie);
output = addOutput(new OutputDefault);
Expand All @@ -44,7 +43,7 @@ void GPACDemuxMP4Simple::process(Data /*data*/) {
std::unique_ptr<gpacpp::IsoSample> ISOSample;
ISOSample = reader->movie->getSample(reader->trackNumber, reader->sampleIndex, sampleDescriptionIndex);

Log::msg(Log::Debug, "Found sample #%s/%s of length %s, RAP %s, DTS: %s, CTS: %s",
log(Debug, "Found sample #%s/%s of length %s, RAP %s, DTS: %s, CTS: %s",
reader->sampleIndex,
reader->sampleCount,
ISOSample->dataLength,
Expand All @@ -59,7 +58,7 @@ void GPACDemuxMP4Simple::process(Data /*data*/) {
} catch (gpacpp::Error const& err) {
if (err.error_ == GF_ISOM_INCOMPLETE_FILE) {
u64 missingBytes = reader->movie->getMissingBytes(reader->trackNumber);
Log::msg(Log::Error, "Missing %s bytes on input file", missingBytes);
log(Error, "Missing %s bytes on input file", missingBytes);
} else {
return;
}
Expand Down
19 changes: 9 additions & 10 deletions src/lib_media/demux/libav_demux.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "libav_demux.hpp"
#include "../transform/restamp.hpp"
#include "../common/libav.hpp"
#include "lib_utils/log.hpp"
#include "lib_utils/tools.hpp"
#include "lib_ffpp/ffpp.hpp"
#include <cassert>
Expand Down Expand Up @@ -45,11 +44,11 @@ bool isRaw(AVCodecContext *codecCtx) {

namespace Demux {
void LibavDemux::webcamList() {
Log::msg(Log::Warning, "[LibavDemux] Webcam list:");
log(Warning, "Webcam list:");
ffpp::Dict dict;
buildAVDictionary("[LibavDemux]", &dict, "-list_devices true", "format");
buildAVDictionary(typeid(*this).name(), &dict, "-list_devices true", "format");
avformat_open_input(&m_formatCtx, "video=dummy:audio=dummy", av_find_input_format(webcamFormat()), &dict);
Log::msg(Log::Warning, "\n[LibavDemux] Webcam example: webcam:video=\"Integrated Webcam\":audio=\"Microphone (Realtek High Defini\"");
log(Warning, "Webcam example: webcam:video=\"Integrated Webcam\":audio=\"Microphone (Realtek High Defini\"");
}

bool LibavDemux::webcamOpen(const std::string &options) {
Expand All @@ -61,14 +60,14 @@ bool LibavDemux::webcamOpen(const std::string &options) {

LibavDemux::LibavDemux(const std::string &url) {
if (!(m_formatCtx = avformat_alloc_context()))
throw std::runtime_error("[LibavDemux] Can't allocate format context");
throw error("Can't allocate format context");

const std::string device = url.substr(0, url.find(":"));
if (device == "webcam") {
if (url == device || !webcamOpen(url.substr(url.find(":") + 1))) {
webcamList();
if (m_formatCtx) avformat_close_input(&m_formatCtx);
throw std::runtime_error("Webcam init failed.");
throw error("Webcam init failed.");
}
restamp = uptr(new Transform::Restamp(Transform::Restamp::ClockSystem)); /*some webcams timestamps don't start at 0 (based on UTC)*/
} else {
Expand All @@ -77,13 +76,13 @@ LibavDemux::LibavDemux(const std::string &url) {
dict.set("analyzeduration", "100M");
if (avformat_open_input(&m_formatCtx, url.c_str(), nullptr, &dict)) {
if (m_formatCtx) avformat_close_input(&m_formatCtx);
throw std::runtime_error(format("[LibavDemux] Error when opening input '%s'", url));
throw error(format("Error when opening input '%s'", url));
}

//if you don't call you may miss the first frames
if (avformat_find_stream_info(m_formatCtx, nullptr) < 0) {
avformat_close_input(&m_formatCtx);
throw std::runtime_error("[LibavDemux] Couldn't get additional video stream info");
throw error("Couldn't get additional video stream info");
}

restamp = uptr(new Transform::Restamp(Transform::Restamp::Reset));
Expand Down Expand Up @@ -132,7 +131,7 @@ void LibavDemux::process(Data data) {
if (status < 0) {
if (status == (int)AVERROR_EOF || (m_formatCtx->pb && m_formatCtx->pb->eof_reached)) {
} else if (m_formatCtx->pb && m_formatCtx->pb->error) {
Log::msg(Log::Warning, "[LibavDemux] Stream contains an irrecoverable error - leaving");
log(Warning, "Stream contains an irrecoverable error - leaving");
}
return;
}
Expand All @@ -142,7 +141,7 @@ void LibavDemux::process(Data data) {
outputs[pkt->stream_index]->emit(out);
}

Log::msg(Log::Info, "[LibavDemux] Exit from an external event.");
log(Info, "Exit from an external event.");
}

}
Expand Down
Loading

0 comments on commit c950d44

Please sign in to comment.