Skip to content

Commit

Permalink
remove log and throw duplicates - #13
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouqueau committed Apr 19, 2016
1 parent 61e65d6 commit 0a8ffaf
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 203 deletions.
4 changes: 2 additions & 2 deletions src/apps/dashcastx/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void printDetectedOptions(option::Parser &parse, option::Option * const options)
std::cout << "Several URLs detected: " << std::endl;
for (int i = 0; i < parse.nonOptionsCount(); ++i)
std::cout << "Unknown option: " << parse.nonOption(i) << std::endl;
throw std::runtime_error("Parse error. Please check message and usage above.");
throw std::runtime_error("Parse error (1). Please check message and usage above.");
}

for (option::Option* opt = options[NUMERIC]; opt; opt = opt->next())
Expand All @@ -111,7 +111,7 @@ dashcastXOptions processArgs(int argc, char const* argv[]) {

if (parse.error()) {
option::printUsage(std::cout, usage);
throw std::runtime_error("Parse error. Please check message and usage above.");
throw std::runtime_error("Parse error (2). Please check message and usage above.");
} else if (options[HELP] || argc == 0 || parse.nonOptionsCount() == 0) {
option::printUsage(std::cout, usage);
throw std::runtime_error("Please check message and usage above.");
Expand Down
6 changes: 2 additions & 4 deletions src/lib_media/common/libav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ void pixelFormat2libavPixFmt(const enum PixelFormat format, AVPixelFormat &avPix
case YUV420P: avPixfmt = AV_PIX_FMT_YUV420P; break;
case YUYV422: avPixfmt = AV_PIX_FMT_YUYV422; break;
case RGB24: avPixfmt = AV_PIX_FMT_RGB24; break;
default:
throw std::runtime_error("Unknown pixel format to convert (1). Please contact your vendor.");
default: throw std::runtime_error("Unknown pixel format to convert (1). Please contact your vendor.");
}
}

Expand All @@ -204,8 +203,7 @@ enum PixelFormat libavPixFmt2PixelFormat(const AVPixelFormat &avPixfmt) {
case AV_PIX_FMT_YUV420P: return YUV420P;
case AV_PIX_FMT_YUYV422: return YUYV422;
case AV_PIX_FMT_RGB24: return RGB24;
default:
throw std::runtime_error("Unknown pixel format to convert (2). Please contact your vendor.");
default: throw std::runtime_error("Unknown pixel format to convert (2). Please contact your vendor.");
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/lib_media/common/pcm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ static const uint8_t AUDIO_PCM_PLANES_MAX = 8;
namespace {
uint8_t getNumChannelsFromLayout(Modules::AudioLayout layout) {
switch (layout) {
case Modules::Mono:
return 1;
case Modules::Stereo:
return 2;
default:
throw std::runtime_error("Unknown audio layout");
case Modules::Mono: return 1;
case Modules::Stereo: return 2;
default: throw std::runtime_error("Unknown audio layout");
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib_media/common/picture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class PictureFormat {
case YUV420P: return res.width * res.height * 3 / 2;
case YUYV422: return res.width * res.height * 2;
case RGB24: return res.width * res.height * 3;
default:
throw std::runtime_error("Unknown pixel format. Please contact your vendor.");
default: throw std::runtime_error("Unknown pixel format. Please contact your vendor.");
}
}

Expand Down
15 changes: 5 additions & 10 deletions src/lib_media/decode/libav_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,15 @@ LibavDecode::LibavDecode(const MetadataPktLibav &metadata)
avcodec_copy_context(codecCtx, metadata.getAVCodecContext());

switch (codecCtx->codec_type) {
case AVMEDIA_TYPE_VIDEO:
case AVMEDIA_TYPE_AUDIO:
break;
default:
Log::msg(Log::Warning, "[LibavDecode] codec_type %s not supported. Must be audio or video.", codecCtx->codec_type);
throw std::runtime_error("[LibavDecode] Unknown decode type. Failed.");
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));
}

//find an appropriate decode
auto codec = avcodec_find_decoder(codecCtx->codec_id);
if (!codec) {
Log::msg(Log::Warning, "[LibavDecode] Codec not found");
throw std::runtime_error("[LibavDecode] Decoder not found.");
}
if (!codec)
throw std::runtime_error(format("[LibavDecode] 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;
Expand Down
3 changes: 1 addition & 2 deletions src/lib_media/demux/gpac_demux_mp4_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,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) {
Log::msg(Log::Error, "Could not open file %s for reading (%s).", path, gf_error_to_string(e));
throw std::runtime_error("File not found");
throw std::runtime_error(format("Could not open file %s for reading (%s).", path, gf_error_to_string(e)));
}
reader->init(movie);
output = addOutput(new OutputDefault);
Expand Down
12 changes: 4 additions & 8 deletions src/lib_media/demux/libav_demux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ bool LibavDemux::webcamOpen(const std::string &options) {
}

LibavDemux::LibavDemux(const std::string &url) {
if (!(m_formatCtx = avformat_alloc_context())) {
Log::msg(Log::Warning, "[LibavDemux] Can't allocate format context");
throw std::runtime_error("Format Context allocation failed.");
}
if (!(m_formatCtx = avformat_alloc_context()))
throw std::runtime_error("[LibavDemux] Can't allocate format context");

const std::string device = url.substr(0, url.find(":"));
if (device == "webcam") {
Expand All @@ -78,16 +76,14 @@ LibavDemux::LibavDemux(const std::string &url) {
dict.set("probesize", "100M");
dict.set("analyzeduration", "100M");
if (avformat_open_input(&m_formatCtx, url.c_str(), nullptr, &dict)) {
Log::msg(Log::Warning, "[LibavDemux] Error when opening input '%s'", url);
if (m_formatCtx) avformat_close_input(&m_formatCtx);
throw std::runtime_error("Format Context init failed.");
throw std::runtime_error(format("[LibavDemux] 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) {
Log::msg(Log::Warning, "[LibavDemux] Couldn't get additional video stream info");
avformat_close_input(&m_formatCtx);
throw std::runtime_error("Couldn't find stream info.");
throw std::runtime_error("[LibavDemux] Couldn't get additional video stream info");
}

restamp = uptr(new Transform::Restamp(Transform::Restamp::Reset));
Expand Down
18 changes: 6 additions & 12 deletions src/lib_media/encode/libav_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,12 @@ LibavEncode::LibavEncode(Type type, const LibavEncodeParams &params)
if(!entry)
throw std::runtime_error("Could not get codecName.");
AVCodec *codec = avcodec_find_encoder_by_name(entry->value);
if (!codec) {
Log::msg(Log::Warning, "[libav_encode] codec '%s' not found, disable output.", entry->value);
throw std::runtime_error(format("Codec '%s' not found.", entry->value));
}
if (!codec)
throw std::runtime_error(format("[libav_encode] codec '%s' not found, disable output.", entry->value));

codecCtx = avcodec_alloc_context3(codec);
if (!codecCtx) {
Log::msg(Log::Warning, "[libav_encode] could not allocate the codec context.");
throw std::runtime_error("Codec context allocation failed.");
}
if (!codecCtx)
throw std::runtime_error("[libav_encode] could not allocate the codec context.");

/* parameters */
switch (type) {
Expand Down Expand Up @@ -133,10 +129,8 @@ LibavEncode::LibavEncode(Type type, const LibavEncodeParams &params)

/* open it */
codecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER; //gives access to the extradata (e.g. H264 SPS/PPS, etc.)
if (avcodec_open2(codecCtx, codec, &codecDict) < 0) {
Log::msg(Log::Warning, "[libav_encode] could not open codec, disable output.");
throw std::runtime_error("Codec creation failed.");
}
if (avcodec_open2(codecCtx, codec, &codecDict) < 0)
throw std::runtime_error("[libav_encode] could not open codec, disable output.");

/* check all optionsDict have been consumed */
auto opt = stringDup(codecOptions.c_str());
Expand Down
6 changes: 2 additions & 4 deletions src/lib_media/in/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ namespace In {

File::File(std::string const& fn) {
file = fopen(fn.c_str(), "rb");
if (!file) {
Log::msg(Log::Error, "Can't open file for reading: %s", fn);
throw std::runtime_error("File not found");
}
if (!file)
throw std::runtime_error(format("Can't open file for reading: %s", fn));

fseek(file, 0, SEEK_END);
auto size = ftell(file);
Expand Down
Loading

0 comments on commit 0a8ffaf

Please sign in to comment.