mirror of
https://github.com/fmang/opustags.git
synced 2025-07-12 12:05:24 +02:00
specify the expected behavior of the main loops
in particular, the TagsHandler interface also, rename the Reader/Writer classes to Decoder/Encoder for clarity
This commit is contained in:
@ -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) {
|
||||
|
46
src/actions.h
Normal file
46
src/actions.h
Normal file
@ -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&);
|
||||
|
||||
}
|
22
src/ogg.h
22
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<int, Stream> streams;
|
||||
};
|
||||
|
||||
struct Writer
|
||||
struct Encoder
|
||||
{
|
||||
Writer(std::ostream&&);
|
||||
~Writer();
|
||||
Encoder(std::ostream&&);
|
||||
~Encoder();
|
||||
|
||||
void write_page(const ogg_page&);
|
||||
|
||||
|
Reference in New Issue
Block a user