create the oggdump tool

This commit is contained in:
Frédéric Mangano-Tarumi 2018-12-03 18:43:02 -05:00
parent 71c9dd7209
commit 6da1a8703d
2 changed files with 45 additions and 0 deletions

View File

@ -10,6 +10,9 @@ target_link_libraries(ogg.t libopustags)
add_executable(cli.t EXCLUDE_FROM_ALL cli.cc)
target_link_libraries(cli.t libopustags)
add_executable(oggdump EXCLUDE_FROM_ALL oggdump.cc)
target_link_libraries(oggdump libopustags)
configure_file(gobble.opus . COPYONLY)
add_custom_target(

42
t/oggdump.cc Normal file
View File

@ -0,0 +1,42 @@
/**
* \file t/oggdump.cc
*
* Dump brief information about the pages containted in an Ogg file.
*
* This tool is not build by default or installed, and is mainly meant to help understand how Ogg
* files are built, and to debug.
*/
#include <opustags.h>
#include <iostream>
#include <string.h>
int main(int argc, char** argv)
{
if (argc != 2) {
std::cerr << "Usage: oggdump FILE\n";
return 1;
}
ot::file input = fopen(argv[1], "r");
if (input == nullptr) {
std::cerr << "Error opening '" << argv[1] << "': " << strerror(errno) << "\n";
return 1;
}
ot::ogg_reader reader(input.get());
ot::status rc;
while ((rc = reader.read_page()) == ot::st::ok) {
std::cout << "Stream " << ogg_page_serialno(&reader.page) << ", "
"page #" << ogg_page_pageno(&reader.page) << ", "
<< ogg_page_packets(&reader.page) << " packet(s)";
if (ogg_page_bos(&reader.page)) std::cout << ", BoS";
if (ogg_page_eos(&reader.page)) std::cout << ", EoS";
if (ogg_page_continued(&reader.page)) std::cout << ", continued";
std::cout << "\n";
}
if (rc != ot::st::ok && rc != ot::st::end_of_stream) {
std::cerr << "error: " << rc.message << "\n";
return 1;
}
return 0;
}