Commit fb54737c authored by Stefan Westerfeld's avatar Stefan Westerfeld

testhls: add simple segment watermarking by zero padding / tmpfile

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 9e9bbdf3
......@@ -31,5 +31,5 @@ testlimiter_LDFLAGS = $(COMMON_LIBS)
testmpegts_SOURCES = testmpegts.cc $(COMMON_SRC)
testmpegts_LDFLAGS = $(COMMON_LIBS)
testhls_SOURCES = testhls.cc $(COMMON_SRC)
testhls_SOURCES = testhls.cc wmadd.cc $(COMMON_SRC)
testhls_LDFLAGS = $(COMMON_LIBS)
......@@ -23,6 +23,7 @@
#include "utils.hh"
#include "mpegts.hh"
#include "wavdata.hh"
#include "wmcommon.hh"
using std::string;
using std::regex;
......@@ -238,6 +239,48 @@ hls_embed_context (const string& in_dir, const string& out_dir, const string& fi
return 0;
}
int
mark_zexpand (WavData& wav_data, size_t zero_frames, const string& bits)
{
vector<float> samples;
samples = wav_data.samples();
samples.insert (samples.begin(), zero_frames * wav_data.n_channels(), /* value */ 0);
wav_data.set_samples (samples);
FILE *tmp_in = tmpfile();
ScopedFile tmp_in_s (tmp_in);
string tmp_in_name = string_printf ("/dev/fd/%d", fileno (tmp_in));
FILE *tmp_out = tmpfile();
ScopedFile tmp_out_s (tmp_out);
string tmp_out_name = string_printf ("/dev/fd/%d", fileno (tmp_out));
Error err = wav_data.save (tmp_in_name);
if (err)
{
error ("mark zexpand save: %s", err.message());
return 1;
}
int rc = add_watermark (tmp_in_name, tmp_out_name, bits);
if (rc != 0)
return rc;
err = wav_data.load (tmp_out_name);
if (err)
{
error ("mark zexpand load: %s", err.message());
return 1;
}
samples = wav_data.samples();
samples.erase (samples.begin(), samples.begin() + zero_frames * wav_data.n_channels());
wav_data.set_samples (samples);
return 0;
}
int
hls_mark (const string& infile, const string& outfile, const string& bits)
{
......@@ -272,6 +315,10 @@ hls_mark (const string& infile, const string& outfile, const string& bits)
size_t next_ctx = min<size_t> (1024 * 3, next_size);
size_t prev_ctx = min<size_t> (1024 * 3, prev_size);
int zrc = mark_zexpand (wav_data, start_pos - prev_size, bits);
if (zrc != 0)
return zrc;
/* erase extra samples caused by concatting with prev.ts */
auto samples = wav_data.samples();
samples.erase (samples.begin(), samples.begin() + (prev_size - prev_ctx) * wav_data.n_channels());
......
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