diff --git a/t/CMakeLists.txt b/t/CMakeLists.txt index c705314..2ceef8b 100644 --- a/t/CMakeLists.txt +++ b/t/CMakeLists.txt @@ -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( diff --git a/t/oggdump.cc b/t/oggdump.cc new file mode 100644 index 0000000..d84ac9c --- /dev/null +++ b/t/oggdump.cc @@ -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 + +#include +#include + +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; +}