Revision cec188e4
Added by David Sorber over 9 years ago
| software/photo_compress_archiver/PhotoCompressArchiver.cc | ||
|---|---|---|
|
|
||
|
// TODO: need to handle the case were number of input files is less than
|
||
|
// the number of threads
|
||
|
uint32_t num_threads = m_num_cores;
|
||
|
uint32_t num_threads = 1;//m_num_cores;
|
||
|
uint32_t sublist_len = m_num_input_files / num_threads;
|
||
|
|
||
|
for (uint32_t idx = 0; idx < num_threads; ++idx)
|
||
| ... | ... | |
|
delete worker;
|
||
|
}
|
||
|
|
||
|
// Print out compression information if compressing
|
||
|
if (! m_decompress)
|
||
|
{
|
||
|
OUT(std::cout << "\n Total compressed bytes: "
|
||
| ... | ... | |
|
|
||
|
// Build a list of the output files names for use in output file monitoring
|
||
|
// below. Output file names have ".jpg" or ".jpeg" replaced with ".pjg"
|
||
|
// in compression mode and vice versa in decompression mode.
|
||
|
std::vector<std::string*> output_filenames;
|
||
|
for (auto& filepath : *file_sublist)
|
||
|
{
|
||
| ... | ... | |
|
uint32_t end_pos = filepath.string().find(".");
|
||
|
std::string* filename = new std::string(filepath.string().begin(),
|
||
|
filepath.string().begin() + end_pos);
|
||
|
(*filename) += ".pjg";
|
||
|
|
||
|
if (m_decompress)
|
||
|
{
|
||
|
// Decompression mode
|
||
|
(*filename) += ".jpg";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Compression mode
|
||
|
(*filename) += ".pjg";
|
||
|
}
|
||
|
|
||
|
output_filenames.push_back(filename);
|
||
|
}
|
||
| ... | ... | |
|
{
|
||
|
// This is the child process...
|
||
|
// Set child process's stdout to the pipe entry
|
||
|
while ((dup2(filedes[1], STDOUT_FILENO) == -1) && (errno == EINTR)) {}
|
||
|
close(filedes[1]);
|
||
|
close(filedes[0]);
|
||
|
//~ while ((dup2(filedes[1], STDOUT_FILENO) == -1) && (errno == EINTR)) {}
|
||
|
//~ close(filedes[1]);
|
||
|
//~ close(filedes[0]);
|
||
|
|
||
|
// Child after fork
|
||
|
execv(PROG_NAME, (char **)exec_argv);
|
||
| ... | ... | |
|
// Check if timeout has occurred
|
||
|
if (bailout_ctr == BAILOUT_MAX)
|
||
|
{
|
||
|
OUT(std::cerr << "T[" << tid << "] ERROR: timed out while waiting "
|
||
|
OUT(std::cerr << "T[" << tid << "] " << BOLD << RED << "ERROR: "
|
||
|
<< ENDC << "timed out while waiting "
|
||
|
<< "for output file: "
|
||
|
<< *output_filenames[output_idx] << "; aborting"
|
||
|
<< std::endl;)
|
||
|
|
||
|
int status;
|
||
|
waitpid(pid, &status, 0);
|
||
|
|
||
|
OUT(std::cerr << "T[" << tid << "] " << BOLD << RED << "ERROR: "
|
||
|
<< ENDC << PURPLE << " RC => " << status << ENDC
|
||
|
<< std::endl;)
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
| software/photo_compress_archiver/main.cc | ||
|---|---|---|
|
void header()
|
||
|
{
|
||
|
std::cout << BOLD << "Photo Compress Archiver -- " << version << "\n" << ENDC;
|
||
|
std::cout << " Copyright 2017 - David Sorber\n";
|
||
|
std::cout << " >>> Utilizing packJPG by Matthias Stirner\n" << std::endl;
|
||
|
std::cout << " Copyright 2017 - David Sorber\n";
|
||
|
std::cout << " >>> Utilizing packJPG by Matthias Stirner\n" << std::endl;
|
||
|
}
|
||
|
|
||
|
void usage(char** argv)
|
||
| ... | ... | |
|
// Display header and
|
||
|
header();
|
||
|
uint32_t num_cores = std::thread::hardware_concurrency();
|
||
|
std::cout << " [" << num_cores << " cores detected]\n";
|
||
|
std::cout << "[" << num_cores << " cores detected]\n";
|
||
|
|
||
|
// Decode/store decompress option
|
||
|
bool decompress = false;
|
||
Adding some minor edits along with a bit of debug code.