-
Notifications
You must be signed in to change notification settings - Fork 863
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
Added -pf option with values json and default (#345) #356
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this printformat_default
variable is superfluous. You simply use json format if printformat_json
is true and the "old way" otherwise.
I've made the change you requested. You're right, it's superfluous even in the future scenario I thought of when adding it, which was leaving room for different print formats. |
Don't worry, if any more formats are going to be supported in future, we'd make some enum and possibly some format table. This is ok as it is now. |
apps/transmitmedia.cpp
Outdated
cerr << "\"recv\": {"; | ||
cerr << "\"packets\":" << mon.pktRecv << ","; | ||
cerr << "\"packetsLost\":" << mon.pktRcvLoss << ","; | ||
cerr << "\"packetsDopped\":" << mon.pktRcvDrop << ","; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/packetsDopped/packetsDropped/ ?
apps/transmitmedia.cpp
Outdated
cerr << "BUFFERLEFT: SND: " << setw(11) << mon.byteAvailSndBuf << " RCV: " << setw(11) << mon.byteAvailRcvBuf << endl; | ||
if (printformat_json) | ||
{ | ||
cerr << "{"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be more efficient to write JSON into std::ostringstream and then send it to std::cerr in one go. Probably regular stats should do the same. If you rather not change this now I can do the change later together with other (overdue) clean up tasks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't cerr
buffer all data up until the endl
?
I'll fix the typo right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think std::cerr
buffers data by default, at least not according to the following quote from 'http://en.cppreference.com/w/cpp/io/cerr':
Once initialized, (std::cerr.flags() & unitbuf) != 0 (same for wcerr) meaning that any output sent to these stream objects is immediately flushed to the OS
Maybe another way to improve the code is to do std::cerr << std::unitbuf << ... << std::nounitbuf << std::endl
but I am not sure if this approach is much better since std::cerr
is shared and if something somewhere else (another thread) does a flush on it there can still be a mess. std::ostringstream
is probably still safer (and clearer) way to go.
…ild the output before printing it.
I've changed the statistics printer to use an intermediary |
This PR adds a json print format for the statistical (
-s
) output, activated by a-pf:json
option. I've left the code fairly general to allow for other print formats to be added in the future. As I said in the issue, the existing format is not very parser-friendly. I have not touched the default print format, so there is a disparity between them regarding the amount of monitoring data from they convey.The change is only for the
srt-live-transmit
/stransmit
app because I do not use and thus cannot properly test the file transfer option.