Skip to content

Commit

Permalink
[ndnrtc-client] set defaults for parameters, when not specified in co…
Browse files Browse the repository at this point in the history
…nfig file
  • Loading branch information
peetonn committed Sep 13, 2018
1 parent 4b2eb40 commit f152e56
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 117 deletions.
160 changes: 57 additions & 103 deletions cpp/client/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,20 @@ int loadParamsFromFile(const string &cfgFileName, ClientParams &params,
}

const Setting &root = cfg.getRoot();
const Setting &general = root[SECTION_GENERAL_KEY];

GeneralParams gp;
if (loadGeneralSettings(general, gp) == EXIT_FAILURE)
if (cfg.exists(SECTION_GENERAL_KEY))
{
LogError("") << "loading general settings from file: " << cfgFileName
<< " met error!" << std::endl;
return 1;
const Setting &general = root[SECTION_GENERAL_KEY];

GeneralParams gp;
if (loadGeneralSettings(general, gp) == EXIT_FAILURE)
{
LogError("") << "loading general settings from file: " << cfgFileName
<< " met error!" << std::endl;
return 1;
}
else
params.setGeneralParameters(gp);
}
else
params.setGeneralParameters(gp);

ConsumerClientParams consumerParams;
loadConsumerSettings(root, consumerParams);
Expand All @@ -118,21 +121,22 @@ int loadConsumerSettings(const Setting &root, ConsumerClientParams &params)
}

const Setting &consumerRootSettings = root[CONSUMER_KEY];
bool hasBasicAudio = false, hasBasicVideo = false;

try
{
// setup consumer general settings
const Setting &consumerBasicSettings = consumerRootSettings[SECTION_BASIC_KEY];

bool hasBasicAudio = consumerBasicSettings.exists(SECTION_AUDIO_KEY);
hasBasicAudio = consumerBasicSettings.exists(SECTION_AUDIO_KEY);

if (hasBasicAudio)
{
const Setting &consumerBasicAudioSettings = consumerBasicSettings[SECTION_AUDIO_KEY];
hasBasicAudio = (loadBasicConsumerSettings(consumerBasicAudioSettings, params.generalAudioParams_) == EXIT_SUCCESS);
}

bool hasBasicVideo = consumerBasicSettings.exists(SECTION_VIDEO_KEY);
hasBasicVideo = consumerBasicSettings.exists(SECTION_VIDEO_KEY);

if (hasBasicVideo)
{
Expand All @@ -144,44 +148,28 @@ int loadConsumerSettings(const Setting &root, ConsumerClientParams &params)
{
loadBasicStatSettings(consumerBasicSettings[BASIC_STAT_KEY], params.statGatheringParams_);
}
}
catch (const SettingNotFoundException &e)
{
LogWarn("") << "Setting not found at path: " << e.getPath() << std::endl;
}

try
{ // setup stream settings
const Setting &streamSettings = consumerRootSettings[SECTION_STREAMS_KEY];

for (int i = 0; i < streamSettings.getLength(); i++)
{
ConsumerStreamParams csp;

if (loadStreamParams(streamSettings[i], csp) == EXIT_SUCCESS)
{
if (!hasBasicAudio && csp.type_ == ConsumerStreamParams::MediaStreamTypeAudio)
{
LogWarn("") << "Found audio stream to fetch (" << csp.streamName_
<< "), but no basic audio settings were provided. Skipping." << std::endl;
continue;
}
if (!hasBasicVideo && csp.type_ == ConsumerStreamParams::MediaStreamTypeVideo)
{
LogWarn("") << "Found video stream to fetch (" << csp.streamName_
<< "), but no basic video settings were provided. Skipping." << std::endl;
continue;
}

params.fetchedStreams_.push_back(csp);
}
} // for i
}
catch (const SettingNotFoundException &nfex)
try
{ // setup stream settings
const Setting &streamSettings = consumerRootSettings[SECTION_STREAMS_KEY];
for (int i = 0; i < streamSettings.getLength(); i++)
{
LogError("") << "Error when loading stream settings!" << std::endl;
return (EXIT_FAILURE);
}
ConsumerStreamParams csp;
if (loadStreamParams(streamSettings[i], csp) == EXIT_SUCCESS)
params.fetchedStreams_.push_back(csp);
} // for i
}
catch (const SettingNotFoundException &e)
catch (const SettingNotFoundException &nfex)
{
LogError("") << "Setting not found at path: " << e.getPath() << std::endl;
LogError("") << "Error when loading stream settings!" << std::endl;
return (EXIT_FAILURE);
}

return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -251,18 +239,9 @@ int loadConfigFile(const string &cfgFileName, Config &cfg)

int loadBasicConsumerSettings(const Setting &s, GeneralConsumerParams &gcp)
{
if (lookupNumber(s, "interest_lifetime", gcp.interestLifetime_) == EXIT_FAILURE)
{
LogError("") << "Reading interest_lifetime from file met error!" << std::endl;
return (EXIT_FAILURE);
}

if (lookupNumber(s, "jitter_size", gcp.jitterSizeMs_) == EXIT_FAILURE)
{
LogError("") << "Reading jitter_size from file met error!" << std::endl;
return (EXIT_FAILURE);
}

lookupNumber(s, "interest_lifetime", gcp.interestLifetime_);
lookupNumber(s, "jitter_size", gcp.jitterSizeMs_);

return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -329,16 +308,16 @@ int loadGeneralSettings(const Setting &general, GeneralParams &generalParams)
general.lookupValue("use_fec", generalParams.useFec_);
general.lookupValue("use_avsync", generalParams.useAvSync_);

const Setting &ndnNetwork = general["ndnnetwork"];

ndnNetwork.lookupValue("connect_host", generalParams.host_);
LogTrace("") << "generalParams.host_: " << generalParams.host_ << std::endl;
if (lookupNumber(ndnNetwork, "connect_port", generalParams.portNum_) == EXIT_FAILURE)
if (general.exists("ndnnetwork"))
{
LogError("") << "Lookup connect_port from file met error!" << std::endl;
return (EXIT_FAILURE);
const Setting &ndnNetwork = general["ndnnetwork"];

ndnNetwork.lookupValue("connect_host", generalParams.host_);
LogTrace("") << "generalParams.host_: " << generalParams.host_ << std::endl;

lookupNumber(ndnNetwork, "connect_port", generalParams.portNum_);
LogTrace("") << "generalParams.portNum_: " << generalParams.portNum_ << std::endl;
}
LogTrace("") << "generalParams.portNum_: " << generalParams.portNum_ << std::endl;
}
catch (const SettingNotFoundException &nfex)
{
Expand Down Expand Up @@ -471,7 +450,6 @@ int loadStreamParams(const Setting &s, ClientMediaStreamParams &params)
}
catch (const SettingNotFoundException &nfex)
{
cout << "check " << nfex.getPath() << std::endl;
LogError("") << "Setting not found at path: " << nfex.getPath() << std::endl;
return (EXIT_FAILURE);
}
Expand All @@ -495,53 +473,29 @@ int loadFreshnessSettings(const Setting &s,

int loadThreadParams(const Setting &s, VideoThreadParams &params)
{
if (!s.lookupValue("name", params.threadName_))
{
LogError("") << "Thread name must be specified" << std::endl;
return (EXIT_FAILURE);
}

s.lookupValue("name", params.threadName_);
lookupNumber(s, "average_segnum_delta", params.segInfo_.deltaAvgSegNum_);
lookupNumber(s, "average_segnum_delta_parity", params.segInfo_.deltaAvgParitySegNum_);
lookupNumber(s, "average_segnum_key", params.segInfo_.keyAvgSegNum_);
lookupNumber(s, "average_segnum_key_parity", params.segInfo_.keyAvgParitySegNum_);

const Setting &coderSettings = s["coder"];

if (lookupNumber(coderSettings, "frame_rate", params.coderParams_.codecFrameRate_) == EXIT_FAILURE)
{
LogError("") << "Lookuping frame_rate from file met error!" << std::endl;
return (EXIT_FAILURE);
}

if (lookupNumber(coderSettings, "gop", params.coderParams_.gop_) == EXIT_FAILURE)
if (s.exists("coder"))
{
LogError("") << "Lookuping gop from file met error!" << std::endl;
return (EXIT_FAILURE);
}

if (lookupNumber(coderSettings, "start_bitrate", params.coderParams_.startBitrate_) == EXIT_FAILURE)
{
LogError("") << "Lookuping start_bitrate from file met error!" << std::endl;
return (EXIT_FAILURE);
}

if (lookupNumber(coderSettings, "max_bitrate", params.coderParams_.maxBitrate_) == EXIT_FAILURE)
{
LogError("") << "Lookuping max_bitrate from file met error!" << std::endl;
return (EXIT_FAILURE);
}
const Setting &coderSettings = s["coder"];

if (lookupNumber(coderSettings, "encode_height", params.coderParams_.encodeHeight_) == EXIT_FAILURE)
{
LogError("") << "Lookuping encode_height from file met error!" << std::endl;
return (EXIT_FAILURE);
lookupNumber(coderSettings, "frame_rate", params.coderParams_.codecFrameRate_);
lookupNumber(coderSettings, "gop", params.coderParams_.gop_);
lookupNumber(coderSettings, "start_bitrate", params.coderParams_.startBitrate_);
lookupNumber(coderSettings, "max_bitrate", params.coderParams_.maxBitrate_);
lookupNumber(coderSettings, "encode_height", params.coderParams_.encodeHeight_);
lookupNumber(coderSettings, "encode_width", params.coderParams_.encodeWidth_);
coderSettings.lookupValue("drop_frames", params.coderParams_.dropFramesOn_);
}

if (lookupNumber(coderSettings, "encode_width", params.coderParams_.encodeWidth_) == EXIT_FAILURE)
{
LogError("") << "Lookuping encode_width from file met error!" << std::endl;
return (EXIT_FAILURE);
}

coderSettings.lookupValue("drop_frames", params.coderParams_.dropFramesOn_);

return EXIT_SUCCESS;
}

Expand Down
35 changes: 21 additions & 14 deletions cpp/include/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ namespace ndnrtc
// media thread parameters
class MediaThreadParams : public Params {
public:
MediaThreadParams(){}
MediaThreadParams():threadName_(""){}
MediaThreadParams(std::string threadName):threadName_(threadName){}
MediaThreadParams(std::string threadName, FrameSegmentsInfo segInfo):
threadName_(threadName), segInfo_(segInfo){}
virtual ~MediaThreadParams(){}

std::string threadName_ = "";
std::string threadName_;
FrameSegmentsInfo segInfo_;

virtual void write(std::ostream& os) const
Expand Down Expand Up @@ -152,8 +152,8 @@ namespace ndnrtc
unsigned int encodeWidth_, encodeHeight_;
bool dropFramesOn_;

VideoCoderParams():codecFrameRate_(0),gop_(0),startBitrate_(0),
maxBitrate_(0),encodeWidth_(0),encodeHeight_(0),dropFramesOn_(false){}
VideoCoderParams():codecFrameRate_(30),gop_(30),startBitrate_(1000),
maxBitrate_(5000),encodeWidth_(1280),encodeHeight_(720),dropFramesOn_(false){}

void write(std::ostream& os) const
{
Expand Down Expand Up @@ -221,8 +221,10 @@ namespace ndnrtc
unsigned int sampleKeyMs_;
} FreshnessPeriodParams;

unsigned int segmentSize_ = 0;
FreshnessPeriodParams freshness_ = {0, 0, 0};
GeneralProducerParams():segmentSize_(8000), freshness_({10, 15, 900}){}

unsigned int segmentSize_;
FreshnessPeriodParams freshness_;

void write(std::ostream& os) const
{
Expand All @@ -243,8 +245,9 @@ namespace ndnrtc
MediaStreamTypeData = 2
} MediaStreamType;

MediaStreamParams(){}
MediaStreamParams(const std::string& name):streamName_(name){}
MediaStreamParams():streamName_(""), synchronizedStreamName_(""), type_(MediaStreamTypeAudio){}
MediaStreamParams(const std::string& name):streamName_(name),
synchronizedStreamName_(""), type_(MediaStreamTypeAudio){}
MediaStreamParams(const MediaStreamParams& other)
{
copyFrom(other);
Expand All @@ -264,10 +267,10 @@ namespace ndnrtc
}

GeneralProducerParams producerParams_;
std::string streamName_ = "";
std::string synchronizedStreamName_ = "";
std::string streamName_;
std::string synchronizedStreamName_;
CaptureDeviceParams captureDevice_;
MediaStreamType type_ = MediaStreamTypeAudio;
MediaStreamType type_;

size_t getThreadNum() const { return mediaThreads_.size(); }
void addMediaThread(const AudioThreadParams& tp)
Expand Down Expand Up @@ -334,8 +337,10 @@ namespace ndnrtc
// general consumer parameters
class GeneralConsumerParams : public Params {
public:
unsigned int interestLifetime_ = 0;
unsigned int jitterSizeMs_ = 0;
unsigned int interestLifetime_;
unsigned int jitterSizeMs_;

GeneralConsumerParams():interestLifetime_(2000), jitterSizeMs_(150){}

void write(std::ostream& os) const
{
Expand All @@ -359,7 +364,9 @@ namespace ndnrtc
unsigned int portNum_;

GeneralParams():loggingLevel_(ndnlog::NdnLoggerDetailLevelNone),
useFec_(false), useAvSync_(false), portNum_(6363){}
logFile_("ndnrtc.log"), logPath_("/tmp"),
useFec_(false), useAvSync_(true),
host_("localhost"), portNum_(6363) {}

void write(std::ostream& os) const
{
Expand Down

0 comments on commit f152e56

Please sign in to comment.