diff --git a/src/actions.cc b/src/actions.cc index 67d70d1..f08bdff 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -9,7 +9,7 @@ enum StreamSelection { FIRST_STREAM = -2, }; -void list_tags(ogg::Reader *reader, long select) +void list_tags(ogg::Decoder *reader, long select) { ogg::Stream *s; while ((s = reader->read_page()) != NULL) { @@ -21,7 +21,7 @@ void list_tags(ogg::Reader *reader, long select) } } -void delete_tags(ogg::Reader *reader, opustags::ogg::Writer *writer, long select) +void delete_tags(ogg::Decoder *reader, opustags::ogg::Encoder *writer, long select) { ogg::Stream *s; while ((s = reader->read_page()) != NULL) { diff --git a/src/actions.h b/src/actions.h new file mode 100644 index 0000000..e37007b --- /dev/null +++ b/src/actions.h @@ -0,0 +1,46 @@ +#pragma once + +#include "ogg.h" + +namespace opustags { + + // To be defined properly somewhere. + class Tags; + + // TagsHandler define various operations related to tags and stream in + // order to control the main loop. + // In its implementation, it is expected to receive an option structure. + struct TagsHandler { + + // Irrelevant streams don't even need to be parsed, so we can save some + // effort with this method. + // Returns true if the stream should be parsed, false if it should be + // ignored (list) or copied identically (edit). + bool relevant(int streamno) { return false; } + + // The list method is called by list_tags every time it has + // successfully parsed an OpusTags header. + void list(int streamno, const Tags&) {} + + // Transform the tags at will. + // Returns true if the tags were indeed modified, false to cancel any + // kind of modification. + bool edit(int streamno, Tags&) { return false; } + + // The work is done. + // When listing tags, once we've caught the streams we wanted, it's no + // use keeping reading the file for new streams. In that case, a true + // return value would abort any further processing. + bool done() { return false; } + + }; + + // Decode a file and call the handler's list method every time a tags + // header is read. + void list_tags(ogg::Decoder&, TagsHandler&); + + // Forward the input data to the output stream, transforming tags on-the-go + // with the handler's edit method. + void edit_tags(ogg::Decoder &in, ogg::Encoder &out, TagsHandler&); + +} diff --git a/src/ogg.h b/src/ogg.h index 34f2df7..14c15a4 100644 --- a/src/ogg.h +++ b/src/ogg.h @@ -32,11 +32,15 @@ namespace ogg Stream(int serialno); ~Stream(); - // Called by Reader once a page was read. - // Return true if it's ready, false if it expects more data. - // In the latter case, Reader::read_page will keep reading. + // Called by Decoder once a page was read. + // Returns true if it's ready, false if it expects more data. + // In the latter case, Decoder::read_page will keep reading. bool page_in(const ogg_page&); + // Make the stream behave as if it were unknown. + // As a consequence, no more effort would be made in extracting data. + void downgrade(); + StreamState state; StreamType type; Tags tags; @@ -44,10 +48,10 @@ namespace ogg ogg_stream_state stream; }; - struct Reader + struct Decoder { - Reader(std::istream&&); - ~Reader(); + Decoder(std::istream&&); + ~Decoder(); // Read a page, dispatch it, and return the stream it belongs to. // The read page is given to Stream::page_in before this function @@ -62,10 +66,10 @@ namespace ogg std::map streams; }; - struct Writer + struct Encoder { - Writer(std::ostream&&); - ~Writer(); + Encoder(std::ostream&&); + ~Encoder(); void write_page(const ogg_page&);