From cc026ba2c4988b0882679c1b18bbd43d7714fc6e Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 27 Sep 2010 20:25:19 +0300 Subject: [PATCH] Die printfs, die Printfs on %llu and %zu are just not supported enough, so use iostreams. --- streamtools/dumppackets.cpp | 24 +++++++++++++----------- streamtools/output-drv-timecodev2.cpp | 20 +++++++++++--------- streamtools/playdump.cpp | 9 ++++----- streamtools/screenshot.cpp | 5 +++-- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/streamtools/dumppackets.cpp b/streamtools/dumppackets.cpp index 9397640..95aa6e0 100644 --- a/streamtools/dumppackets.cpp +++ b/streamtools/dumppackets.cpp @@ -1,30 +1,32 @@ #include "newpacket.hpp" -#include +#include +#include bool brief_mode = false; void handle_packet(packet* p) { - printf("Packet: channel %u[", p->rp_channel, p->rp_channel_perm); + std::cout << "Packet: channel " << p->rp_channel << "rp_channel_perm << ">["; for(size_t i = 0; i < p->rp_channel_name.length(); i++) { unsigned char ch = p->rp_channel_name[i]; if(ch < 32 || ch > 126) - printf("\\x%02X", ch); + std::cout << "\\x" << std::setfill('0') << std::setw(2) << std::hex << (uint16_t)ch; else if(ch == '[' || ch == ']' || ch == '\\') - printf("\\%c", ch); + std::cout << "\\" << ch; else - printf("%c", ch); + std::cout << ch; } - printf("] at %llu, type %u(%u), payload %zu:\n", (unsigned long long)p->rp_timestamp, p->rp_major, - p->rp_minor, p->rp_payload.size()); + std::cout << "] at " << p->rp_timestamp << ", type " << p->rp_major << "(" << (uint16_t)p->rp_minor << ") " + << "payload " << p->rp_payload.size() << ":" << std::endl; for(size_t i = 0; !brief_mode && i < p->rp_payload.size(); i += 16) { size_t j = p->rp_payload.size() - i; if(j > 16) j = 16; - printf("\t"); + std::cout << "\t"; for(size_t k = 0; k < j; k++) - printf("%02X ", p->rp_payload[i + k]); - printf("\n"); + std::cout << std::setfill('0') << std::setw(2) << std::hex + << (uint16_t)p->rp_payload[i + k] << " "; + std::cout << std::endl; } delete p; } @@ -33,7 +35,7 @@ int main(int argc, char** argv) { struct packet* p; if(argc != 2) { - fprintf(stderr, "syntax: %s \n", argv[0]); + std::cerr << "syntax: " << argv[0] << " " << std::endl; exit(1); } if(getenv("BRIEF_PACKETDUMP")) diff --git a/streamtools/output-drv-timecodev2.cpp b/streamtools/output-drv-timecodev2.cpp index 0dacb91..6fbd243 100644 --- a/streamtools/output-drv-timecodev2.cpp +++ b/streamtools/output-drv-timecodev2.cpp @@ -1,5 +1,5 @@ #include "output-drv.hpp" -#include +#include #include #include @@ -11,18 +11,20 @@ namespace output_driver_timecodev2(const std::string& filename) { if(filename != "-") - out = fopen(filename.c_str(), "wb"); + out = new std::ofstream(filename.c_str(), std::ios_base::binary); else - out = stdout; - if(!out) + out = &std::cout; + if(!*out) throw std::runtime_error("Unable to open output file"); - fprintf(out, "# timecode format v2\n"); - set_video_callback(*this, &output_driver_timecodev2::video_callback); + *out << "# timecode format v2" << std::endl; + set_video_callback(*this, + &output_driver_timecodev2::video_callback); } ~output_driver_timecodev2() { - fclose(out); + if(out != &std::cout) + delete out; } void ready() @@ -31,10 +33,10 @@ namespace void video_callback(uint64_t timestamp, const uint8_t* raw_rgbx_data) { - fprintf(out, "%llu\n", (unsigned long long)timestamp / 1000000); + *out << (unsigned long long)timestamp / 1000000 << std::endl; } private: - FILE* out; + std::ostream* out; }; class output_driver_timecodev2_factory : output_driver_factory diff --git a/streamtools/playdump.cpp b/streamtools/playdump.cpp index 42b1ce5..6540ffc 100644 --- a/streamtools/playdump.cpp +++ b/streamtools/playdump.cpp @@ -180,7 +180,7 @@ int main(int argc, char** argv) unsigned prev_height = -1; if(SDL_Init(SDL_INIT_VIDEO) < 0) { - fprintf(stderr, "Can't initialize SDL.\n"); + std::cerr << "Can't initialize SDL." << std::endl; return 1; } @@ -266,10 +266,9 @@ int main(int argc, char** argv) } if(enable_debug && realtime / 1000 > last_realtime_second) { last_realtime_second = realtime / 1000; - printf("\e[1GTime %lus: Frames: %llu(lagged:%llu), Audio: %llu(%llu)", - (unsigned long)last_realtime_second, (unsigned long long)total_frames, - (unsigned long long)lagged_frames, (unsigned long long)audiosamples, - (unsigned long long)audiobuffer.size()); + std::cout << "\e[1GTime " << last_realtime_second << "s: Frames: " << total_frames + << "(lagged:" << lagged_frames << "), Audio: " << audiosamples << "(" + << audiobuffer.size() << ")"; fflush(stdout); } //Decode the frame. diff --git a/streamtools/screenshot.cpp b/streamtools/screenshot.cpp index 3ba879d..f5b9ba2 100644 --- a/streamtools/screenshot.cpp +++ b/streamtools/screenshot.cpp @@ -78,7 +78,7 @@ int main(int argc, char** argv) else if(!strncmp(argv[i], "--prefix=", 9)) _prefix= argv[i] + 9; else if(!strncmp(argv[i], "-", 1)) { - fprintf(stderr, "Unknown option %s\n", argv[i]); + std::cerr << "Unknown option '" << argv[i] << "'." << std::endl; exit(1); } else { uint64_t stamp = parse_timespec(argv[i]); @@ -88,7 +88,8 @@ int main(int argc, char** argv) } if(!_input || !target_count) { - fprintf(stderr, "syntax: %s --input= [--prefix=] ...\n", argv[0]); + std::cerr << "syntax: " << argv[0] << " --input= [--prefix=] ..." + << std::endl; exit(1); } strcpy(prefix, _prefix); -- 2.11.4.GIT