Commit fdce8a1b authored by Stefan Westerfeld's avatar Stefan Westerfeld

New add_stream_watermark() function - add watermark to in/out streams.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent d2afde6e
......@@ -545,7 +545,7 @@ info_format (const string& label, const RawFormat& format)
}
int
add_watermark (const string& infile, const string& outfile, const string& bits)
add_stream_watermark (AudioInputStream *in_stream, AudioOutputStream *out_stream, const string& bits)
{
auto bitvec = bit_str_to_vec (bits);
if (bitvec.empty())
......@@ -567,25 +567,6 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
bitvec = expanded_bitvec;
}
/* open input stream */
Error err;
std::unique_ptr<AudioInputStream> in_stream = AudioInputStream::create (infile, err);
if (err)
{
error ("audiowmark: error opening %s: %s\n", infile.c_str(), err.message());
return 1;
}
/* open output stream */
const int out_bit_depth = in_stream->bit_depth() > 16 ? 24 : 16;
std::unique_ptr<AudioOutputStream> out_stream;
out_stream = AudioOutputStream::create (outfile, in_stream->n_channels(), in_stream->sample_rate(), out_bit_depth, in_stream->n_frames(), err);
if (err)
{
error ("audiowmark: error writing to %s: %s\n", outfile.c_str(), err.message());
return 1;
}
/* sanity checks */
if (in_stream->sample_rate() != out_stream->sample_rate())
{
......@@ -599,12 +580,6 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
}
/* write some informational messages */
info ("Input: %s\n", Params::input_label.size() ? Params::input_label.c_str() : infile.c_str());
if (Params::input_format == Format::RAW)
info_format ("Raw Input", Params::raw_input_format);
info ("Output: %s\n", Params::output_label.size() ? Params::output_label.c_str() : outfile.c_str());
if (Params::output_format == Format::RAW)
info_format ("Raw Output", Params::raw_output_format);
info ("Message: %s\n", bit_vec_to_str (bitvec).c_str());
info ("Strength: %.6g\n\n", Params::water_delta * 1000);
......@@ -638,6 +613,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
size_t total_input_frames = 0;
size_t total_output_frames = 0;
Error err;
while (true)
{
err = in_stream->read_frames (samples, Params::frame_size);
......@@ -711,4 +687,37 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
return 0;
}
int
add_watermark (const string& infile, const string& outfile, const string& bits)
{
/* open input stream */
Error err;
std::unique_ptr<AudioInputStream> in_stream = AudioInputStream::create (infile, err);
if (err)
{
error ("audiowmark: error opening %s: %s\n", infile.c_str(), err.message());
return 1;
}
/* open output stream */
const int out_bit_depth = in_stream->bit_depth() > 16 ? 24 : 16;
std::unique_ptr<AudioOutputStream> out_stream;
out_stream = AudioOutputStream::create (outfile, in_stream->n_channels(), in_stream->sample_rate(), out_bit_depth, in_stream->n_frames(), err);
if (err)
{
error ("audiowmark: error writing to %s: %s\n", outfile.c_str(), err.message());
return 1;
}
/* write input/output stream details */
info ("Input: %s\n", Params::input_label.size() ? Params::input_label.c_str() : infile.c_str());
if (Params::input_format == Format::RAW)
info_format ("Raw Input", Params::raw_input_format);
info ("Output: %s\n", Params::output_label.size() ? Params::output_label.c_str() : outfile.c_str());
if (Params::output_format == Format::RAW)
info_format ("Raw Output", Params::raw_output_format);
return add_stream_watermark (in_stream.get(), out_stream.get(), bits);
}
......@@ -160,6 +160,7 @@ randomize_bit_order (const std::vector<T>& bit_vec, bool encode)
return out_bits;
}
int add_stream_watermark (AudioInputStream *in_stream, AudioOutputStream *out_stream, const std::string& bits);
int add_watermark (const std::string& infile, const std::string& outfile, const std::string& bits);
int get_watermark (const std::string& infile, const std::string& orig_pattern);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment