sample main loops for ogg manipulation

linking now breaks because the ogg module isn't implemented
This commit is contained in:
Frédéric Mangano
2016-02-20 13:20:49 +01:00
parent e198b5f9ef
commit a8a6552f29
2 changed files with 59 additions and 1 deletions

56
src/actions.cc Normal file
View File

@ -0,0 +1,56 @@
#include "ogg.h"
// Here we're going to illustrate how to use the ogg module.
using namespace opustags;
enum StreamSelection {
ALL_STREAMS = -1,
FIRST_STREAM = -2,
};
void list_tags(ogg::Reader *reader, long select)
{
ogg::Stream *s;
while ((s = reader->read_page()) != NULL) {
if (s->state == ogg::TAGS_READY && (select == ALL_STREAMS || select == FIRST_STREAM || s->stream.serialno == select)) {
// print_tags(s->tags);
if (select != ALL_STREAMS)
break;
}
}
}
void delete_tags(ogg::Reader *reader, opustags::ogg::Writer *writer, long select)
{
ogg::Stream *s;
while ((s = reader->read_page()) != NULL) {
switch (s->state) {
case ogg::HEADER_READY:
// TODO what if select == FIRST_STREAM?
if (select != ALL_STREAMS && s->stream.serialno != select)
// act like nothing happened and copy this "unknown" stream identically
s->type = ogg::UNKNOWN_STREAM;
// fall through
case ogg::RAW_READY:
writer->write_raw_page(s->current_page);
break;
case ogg::TAGS_READY:
// only streams selected at HEADER_READY reach this point
writer->write_tags(s->stream.serialno, ogg::Tags());
break;
case ogg::DATA_READY:
writer->write_page(s->current_page);
break;
default:
;
}
}
}
// To write edit_tags, we're gonna need something like the options structure in
// order to know what to do exactly.
// The command-line interface has yet to be done, but it'd be nice it let the
// user edit several streams at once, like :
// $ opustags --stream 1 --set TITLE=Foo --stream 2 --set TITLE=Bar

View File

@ -5,7 +5,8 @@
#include <map>
#include <ogg/ogg.h>
namespace opustags::ogg
namespace opustags {
namespace ogg
{
typedef std::map<std::string, std::string> Tags;
@ -89,3 +90,4 @@ namespace opustags::ogg
std::map<int, ogg_stream_state> streams;
};
}
}