mirror of
https://github.com/fmang/opustags.git
synced 2024-11-10 07:27:22 +01:00
assign sequential numbers to streams
see issue #14 I remain unsure of whether we should include unknown streams in the sequence in a distant future, if we extend the tool to support more stream types, the numbers would change to include the newly supported streams in the sequence
This commit is contained in:
parent
eb968dc513
commit
1ff2553f5f
@ -4,6 +4,8 @@ using namespace opustags;
|
||||
|
||||
void opustags::list_tags(ogg::Decoder &dec, ITagsHandler &handler, bool full)
|
||||
{
|
||||
std::map<long, int> sequence_numbers;
|
||||
int stream_count = 0;
|
||||
int remaining_streams = 0;
|
||||
std::shared_ptr<ogg::Stream> s;
|
||||
while (!handler.done()) {
|
||||
@ -14,14 +16,16 @@ void opustags::list_tags(ogg::Decoder &dec, ITagsHandler &handler, bool full)
|
||||
}
|
||||
switch (s->state) {
|
||||
case ogg::HEADER_READY:
|
||||
if (s->type == ogg::UNKNOWN_STREAM)
|
||||
; // ignore
|
||||
else if (!handler.relevant(s->stream.serialno))
|
||||
s->downgrade();
|
||||
if (s->type != ogg::UNKNOWN_STREAM) {
|
||||
stream_count++;
|
||||
sequence_numbers[s->stream.serialno] = stream_count;
|
||||
if (!handler.relevant(stream_count))
|
||||
s->downgrade();
|
||||
}
|
||||
remaining_streams++;
|
||||
break;
|
||||
case ogg::TAGS_READY:
|
||||
handler.list(s->stream.serialno, s->tags);
|
||||
handler.list(sequence_numbers[s->stream.serialno], s->tags);
|
||||
s->downgrade(); // no more use for it
|
||||
default:
|
||||
remaining_streams--;
|
||||
@ -34,6 +38,8 @@ void opustags::list_tags(ogg::Decoder &dec, ITagsHandler &handler, bool full)
|
||||
void opustags::edit_tags(
|
||||
ogg::Decoder &in, ogg::Encoder &out, ITagsHandler &handler)
|
||||
{
|
||||
std::map<long, int> sequence_numbers;
|
||||
int stream_count = 0;
|
||||
std::shared_ptr<ogg::Stream> s;
|
||||
for (;;) {
|
||||
s = in.read_page();
|
||||
@ -42,19 +48,22 @@ void opustags::edit_tags(
|
||||
switch (s->state) {
|
||||
|
||||
case ogg::HEADER_READY:
|
||||
if (s->type != ogg::UNKNOWN_STREAM) {
|
||||
stream_count++;
|
||||
sequence_numbers[s->stream.serialno] = stream_count;
|
||||
if (!handler.relevant(stream_count))
|
||||
s->downgrade(); // makes it UNKNOWN
|
||||
}
|
||||
if (s->type == ogg::UNKNOWN_STREAM) {
|
||||
out.write_raw_page(in.current_page);
|
||||
} else if (!handler.relevant(s->stream.serialno)) {
|
||||
s->downgrade();
|
||||
out.write_raw_page(in.current_page);
|
||||
} else {
|
||||
out.forward(*s);
|
||||
}
|
||||
break;
|
||||
|
||||
case ogg::TAGS_READY:
|
||||
handler.edit(s->stream.serialno, s->tags);
|
||||
handler.list(s->stream.serialno, s->tags);
|
||||
handler.edit(sequence_numbers[s->stream.serialno], s->tags);
|
||||
handler.list(sequence_numbers[s->stream.serialno], s->tags);
|
||||
out.write_tags(s->stream.serialno, s->tags);
|
||||
break;
|
||||
|
||||
|
@ -97,7 +97,7 @@ TEST_CASE("fake editing of an Opus stream should preserve the stream", "[actions
|
||||
REQUIRE(same_files(in, out));
|
||||
}
|
||||
|
||||
TEST_CASE("editing one stream", "[actions]")
|
||||
TEST_CASE("editing a specific stream", "[actions]")
|
||||
{
|
||||
std::ifstream in("../tests/samples/mystery-beep.ogg");
|
||||
std::stringstream out;
|
||||
@ -105,7 +105,7 @@ TEST_CASE("editing one stream", "[actions]")
|
||||
{
|
||||
ogg::Decoder dec(in);
|
||||
ogg::Encoder enc(out);
|
||||
InsertionTagsHandler editor(-336916309, "pwnd", "yes");
|
||||
InsertionTagsHandler editor(2, "pwnd", "yes");
|
||||
edit_tags(dec, enc, editor);
|
||||
}
|
||||
|
||||
@ -124,12 +124,11 @@ TEST_CASE("editing one stream", "[actions]")
|
||||
s2[i] = b.read_page();
|
||||
}
|
||||
|
||||
REQUIRE(s2[0]->stream.serialno == -336916309);
|
||||
REQUIRE(s2[0]->type == ogg::OPUS_STREAM);
|
||||
REQUIRE(s2[1]->type == ogg::UNKNOWN_STREAM);
|
||||
REQUIRE(s2[2]->type == ogg::OPUS_STREAM);
|
||||
REQUIRE(s2[0]->tags.get("pwnd") == "yes");
|
||||
REQUIRE(!s2[2]->tags.contains("pwnd"));
|
||||
REQUIRE(!s2[0]->tags.contains("pwnd"));
|
||||
REQUIRE(s2[2]->tags.get("pwnd") == "yes");
|
||||
|
||||
REQUIRE(same_streams(a, b));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user