Commit a43d4011 authored by ogg.k.ogg.k's avatar ogg.k.ogg.k Committed by conrad

add 'codecs' tool, to show a list of codecs present in a bitstream (only the...

add 'codecs' tool, to show a list of codecs present in a bitstream (only the first link in a chain is supported)
parent 1094f6c3
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
......
...@@ -118,6 +118,7 @@ Commands: ...@@ -118,6 +118,7 @@ Commands:
help Display help for a specific subcommand (eg. "oggz help chop") help Display help for a specific subcommand (eg. "oggz help chop")
Reporting: Reporting:
codecs Display the codecs present in an Ogg file
diff Hexdump the packets of two Ogg files and output differences. diff Hexdump the packets of two Ogg files and output differences.
dump Hexdump packets of an Ogg file, or revert an Ogg file from dump Hexdump packets of an Ogg file, or revert an Ogg file from
such a hexdump. such a hexdump.
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OGGZ_COMMANDS="chop comment diff dump help info known-codecs merge rip scan sort validate" OGGZ_COMMANDS="chop comment diff dump help info known-codecs merge rip scan sort validate codecs"
__oggzcomp () __oggzcomp ()
{ {
...@@ -160,6 +160,11 @@ _oggz_validate () ...@@ -160,6 +160,11 @@ _oggz_validate ()
_oggz_basic_cmd oggz-validate _oggz_basic_cmd oggz-validate
} }
_oggz_codecs ()
{
_oggz_basic_cmd oggz-codecs
}
_oggz_help () _oggz_help ()
{ {
__oggz_commands __oggz_commands
...@@ -201,6 +206,7 @@ _oggz () ...@@ -201,6 +206,7 @@ _oggz ()
scan) _oggz_scan ;; scan) _oggz_scan ;;
sort) _oggz_sort ;; sort) _oggz_sort ;;
validate) _oggz_validate ;; validate) _oggz_validate ;;
codecs) _oggz_codecs ;;
*) COMPREPLY=() ;; *) COMPREPLY=() ;;
esac esac
} }
...@@ -220,3 +226,4 @@ complete -o filenames -F _oggz_rip oggz-rip ...@@ -220,3 +226,4 @@ complete -o filenames -F _oggz_rip oggz-rip
complete -o filenames -F _oggz_scan oggz-scan complete -o filenames -F _oggz_scan oggz-scan
complete -o filenames -F _oggz_sort oggz-sort complete -o filenames -F _oggz_sort oggz-sort
complete -o filenames -F _oggz_validate oggz-validate complete -o filenames -F _oggz_validate oggz-validate
complete -o filenames -F _oggz_codecs oggz-codecs
...@@ -153,7 +153,7 @@ AC_ARG_ENABLE(read, ...@@ -153,7 +153,7 @@ AC_ARG_ENABLE(read,
if test "x${ac_enable_read}" = xyes ; then if test "x${ac_enable_read}" = xyes ; then
AC_DEFINE(OGGZ_CONFIG_READ, [1], [Build reading support]) AC_DEFINE(OGGZ_CONFIG_READ, [1], [Build reading support])
oggz_read_programs="oggz-dump oggz-info oggz-scan" oggz_read_programs="oggz-dump oggz-info oggz-scan oggz-codecs"
else else
AC_DEFINE(OGGZ_CONFIG_READ, [0], [Do not build reading support]) AC_DEFINE(OGGZ_CONFIG_READ, [0], [Do not build reading support])
fi fi
......
docdir=$(prefix)/share/doc/@PACKAGE@ docdir=$(prefix)/share/doc/@PACKAGE@
man_MANS = oggz.1 oggz-diff.1 oggz-dump.1 oggz-info.1 oggz-known-codecs.1 oggz-merge.1 oggz-chop.1 \ man_MANS = oggz.1 oggz-diff.1 oggz-dump.1 oggz-info.1 oggz-known-codecs.1 oggz-merge.1 oggz-chop.1 \
oggz-sort.1 oggz-rip.1 oggz-comment.1 oggz-scan.1 oggz-validate.1 oggz-sort.1 oggz-rip.1 oggz-comment.1 oggz-scan.1 oggz-validate.1 oggz-codecs.1
EXTRA_DIST = $(man_MANS) Doxyfile.in \ EXTRA_DIST = $(man_MANS) Doxyfile.in \
forcefeed.fig forcefeed.eps forcefeed.png \ forcefeed.fig forcefeed.eps forcefeed.png \
...@@ -13,7 +13,7 @@ noinst_DATA = doxygen-build.stamp ...@@ -13,7 +13,7 @@ noinst_DATA = doxygen-build.stamp
html: oggz.1.html oggz-diff.1.html oggz-dump.1.html oggz-info.1.html oggz-known-codecs.1.html \ html: oggz.1.html oggz-diff.1.html oggz-dump.1.html oggz-info.1.html oggz-known-codecs.1.html \
oggz-merge.1.html oggz-chop.1.html oggz-sort.1.html oggz-rip.1.html oggz-comment.1.html \ oggz-merge.1.html oggz-chop.1.html oggz-sort.1.html oggz-rip.1.html oggz-comment.1.html \
oggz-scan.1.html oggz-validate.1.html oggz-scan.1.html oggz-validate.1.html oggz-codecs.1.html oggz-codecs.1.html
if HAVE_MAN2HTML if HAVE_MAN2HTML
%.1.html: %.1 %.1.html: %.1
......
.TH "oggz-codecs" "1"
.SH "NAME"
oggz-info \(em Display a list of codecs found in one or more Ogg files and their bitstreams.
.SH "SYNOPSIS"
.PP
\fBoggz-codecs\fR [\-a | \-\-all ] [\-m | \-\-mime ] filename \&...
.PP
\fBoggz-codecs\fR [\-h | \-\-help ] [\-v | \-\-version ]
.SH "Description"
.PP
\fBoggz-codecs\fR displays a list of codecs found in one or more
Ogg files and their bitstreams.
.SH "Options"
.PP
\fBoggz-codecs\fR accepts the following options:
.SS "Display options"
.IP "\-a, \-\-all" 10
Display an entry for every bitstream, rather than displaying each codec once, even if present more than once.
.IP "\-m, \-\-mime" 10
Display each codec's MIME type, instead of its name.
.SS "Miscellaneous options"
.IP "\-h, \-\-help" 10
Display usage information and exit.
.IP "\-v, \-\-version" 10
Output version information and exit.
.SH "AUTHOR"
.PP
Conrad Parker March 10, 2005;
.SH "COPYRIGHT"
.PP
Copyright \(co 2005 CSIRO Australia
.SH "SEE ALSO"
.PP
\fBoggzinfo\fP\fB(1)\fP \fBhogg\fP\fB(1)\fP
.\" created by instant / docbook-to-man, Mon 23 Feb 2009, 12:35
...@@ -19,7 +19,7 @@ COMMON_SRCS=oggz_tools.c $(srcdir)/../liboggz/dirac.c ...@@ -19,7 +19,7 @@ COMMON_SRCS=oggz_tools.c $(srcdir)/../liboggz/dirac.c
oggz_any_programs = oggz oggz-known-codecs oggz_any_programs = oggz oggz-known-codecs
if OGGZ_CONFIG_READ if OGGZ_CONFIG_READ
oggz_read_programs = oggz-dump oggz-info oggz-scan oggz_read_programs = oggz-dump oggz-info oggz-scan oggz-codecs
oggz_read_noinst_programs = oggz_read_noinst_programs =
if OGGZ_CONFIG_WRITE if OGGZ_CONFIG_WRITE
...@@ -29,7 +29,7 @@ endif ...@@ -29,7 +29,7 @@ endif
endif endif
noinst_HEADERS = oggz_tools.h oggz_tools_dirac.h skeleton.h noinst_HEADERS = oggz_tools.h oggz_tools_dirac.h skeleton.h mimetypes.h
# Programs to build # Programs to build
bin_PROGRAMS = $(oggz_any_programs) $(oggz_read_programs) $(oggz_rw_programs) bin_PROGRAMS = $(oggz_any_programs) $(oggz_read_programs) $(oggz_rw_programs)
...@@ -68,6 +68,9 @@ oggz_scan_LDADD = $(OGGZ_LIBS) ...@@ -68,6 +68,9 @@ oggz_scan_LDADD = $(OGGZ_LIBS)
oggz_sort_SOURCES = oggz-sort.c $(COMMON_SRCS) oggz_sort_SOURCES = oggz-sort.c $(COMMON_SRCS)
oggz_sort_LDADD = $(OGGZ_LIBS) oggz_sort_LDADD = $(OGGZ_LIBS)
oggz_codecs_SOURCES = oggz-codecs.c mimetypes.c $(COMMON_SRCS)
oggz_codecs_LDADD = $(OGGZ_LIBS)
# Add symlinks for deprecated tool names, if they are already installed; # Add symlinks for deprecated tool names, if they are already installed;
# see http://lists.xiph.org/pipermail/ogg-dev/2008-July/001083.html # see http://lists.xiph.org/pipermail/ogg-dev/2008-July/001083.html
install-exec-local: install-exec-local:
......
#include <stddef.h>
#include "mimetypes.h"
/* MIME types, for use in Skeleton. This must be in the same order as
* enum OggzStreamContent defined in <oggz/oggz_constants.h> */
const char * const mime_type_names[] = {
"video/theora",
"audio/vorbis",
"audio/speex",
"audio/x-oggpcm",
"text/cmml",
"application/x-annodex-2",
NULL, /* Skeleton */
"audio/flac",
"audio/flac",
NULL, /* AnxData */
"audio/celt",
"application/x-kate",
"video/dirac",
NULL /* UNKNOWN */
};
#ifndef OGGZ_MIME_TYPES_H
#define OGGZ_MIME_TYPES_H
#ifdef __cplusplus
extern "C" {
#endif
extern const char * const mime_type_names[];
#ifdef __cplusplus
}
#endif
#endif /* OGGZ_MIME_TYPES_H */
...@@ -26,7 +26,7 @@ TESTS = httpdate_test ...@@ -26,7 +26,7 @@ TESTS = httpdate_test
noinst_HEADERS = cgi.h cmd.h header.h httpdate.h oggz-chop.h timespec.h noinst_HEADERS = cgi.h cmd.h header.h httpdate.h oggz-chop.h timespec.h
oggz_chop_SOURCES = oggz-chop.c $(srcdir)/../oggz_tools.c $(srcdir)/../skeleton.c \ oggz_chop_SOURCES = oggz-chop.c $(srcdir)/../oggz_tools.c $(srcdir)/../skeleton.c $(srcdir)/../mimetypes.c \
$(srcdir)/../../liboggz/dirac.c cmd.c cgi.c header.c httpdate.c main.c timespec.c $(srcdir)/../../liboggz/dirac.c cmd.c cgi.c header.c httpdate.c main.c timespec.c
oggz_chop_LDADD = $(OGGZ_LIBS) -lm oggz_chop_LDADD = $(OGGZ_LIBS) -lm
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "oggz-chop.h" #include "oggz-chop.h"
#include "skeleton.h" #include "skeleton.h"
#include "mimetypes.h"
#ifdef OGG_H_CONST_CORRECT #ifdef OGG_H_CONST_CORRECT
#define OGG_PAGE_CONST(x) (x) #define OGG_PAGE_CONST(x) (x)
...@@ -360,25 +361,6 @@ skeleton_write_packet (OCState * state, ogg_packet * op) ...@@ -360,25 +361,6 @@ skeleton_write_packet (OCState * state, ogg_packet * op)
return ret; return ret;
} }
/* MIME types, for use in Skeleton. This must be in the same order as
* enum OggzStreamContent defined in <oggz/oggz_constants.h> */
const char * type_names[] = {
"video/theora",
"audio/vorbis",
"audio/speex",
"audio/x-oggpcm",
"text/cmml",
"application/x-annodex-2",
NULL, /* Skeleton */
"audio/flac",
"audio/flac",
NULL, /* AnxData */
"audio/celt",
"application/x-kate",
"video/dirac",
NULL /* UNKNOWN */
};
static int static int
fisbone_init (OGGZ * oggz, OCState * state, OCTrackState * ts, long serialno) fisbone_init (OGGZ * oggz, OCState * state, OCTrackState * ts, long serialno)
{ {
...@@ -402,7 +384,7 @@ fisbone_init (OGGZ * oggz, OCState * state, OCTrackState * ts, long serialno) ...@@ -402,7 +384,7 @@ fisbone_init (OGGZ * oggz, OCState * state, OCTrackState * ts, long serialno)
/* XXX: C99 */ /* XXX: C99 */
#define CONTENT_TYPE_FMT "Content-Type: %s\r\n" #define CONTENT_TYPE_FMT "Content-Type: %s\r\n"
content_type = oggz_stream_get_content (oggz, serialno); content_type = oggz_stream_get_content (oggz, serialno);
name = type_names[content_type]; name = mime_type_names[content_type];
len = snprintf (NULL, 0, CONTENT_TYPE_FMT, name); len = snprintf (NULL, 0, CONTENT_TYPE_FMT, name);
if ((ts->fisbone.message_header_fields = malloc(len+1)) == NULL) { if ((ts->fisbone.message_header_fields = malloc(len+1)) == NULL) {
return -1; return -1;
......
/*
Copyright (C) 2008 Commonwealth Scientific and Industrial Research
Organisation (CSIRO) Australia
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of CSIRO Australia nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h> /* LONG_MAX */
#include <math.h>
#include <getopt.h>
#include <errno.h>
#include <oggz/oggz.h>
#include "oggz_tools.h"
#include "mimetypes.h"
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#else
# define PRId64 "I64d"
#endif
#define READ_BLOCKSIZE 16384
static int show_all = 0;
static int show_as_mime = 0;
/* Assumes UNKNOWN is last - fair assumption I think */
static int codecs_count[OGGZ_CONTENT_UNKNOWN+1] = {0};
static void
usage (const char * progname)
{
printf ("Usage: %s [options] filename ...\n", progname);
printf ("Display codecs used in one or more Ogg files and their bitstreams\n");
printf ("\nDisplay options\n");
printf (" -a, --all Display an entry for all bitstreams, rather than collapsing codecs used more than once\n");
printf (" -m, --mime Displays entries on a single line, separated by commas\n");
printf ("\nMiscellaneous options\n");
printf (" -h, --help Display this help and exit\n");
printf (" -v, --version Output version information and exit\n");
printf ("\n");
printf ("Please report bugs to <ogg-dev@xiph.org>\n");
}
#define SEP "------------------------------------------------------------"
typedef struct _OI_Info OI_Info;
/* Let's get functional */
typedef void (*OI_TrackFunc) (OI_Info * info, long serialno);
struct _OI_Info {
OGGZ * oggz;
OggzTable * tracks;
};
static void
oggz_info_apply (OI_TrackFunc func, OI_Info * info)
{
long serialno;
int n, i;
n = oggz_table_size (info->tracks);
for (i = 0; i < n; i++) {
oggz_table_nth (info->tracks, i, &serialno);
func (info, serialno);
}
}
static void
print_codec_name (OI_Info * info, long serialno)
{
OggzStreamContent content = oggz_stream_get_content(info->oggz, serialno);
if (!codecs_count[content]++ || show_all) {
if (show_as_mime) {
const char *mime_type = NULL;
if (content >= 0 && content < OGGZ_CONTENT_UNKNOWN)
mime_type = mime_type_names[content];
if (!mime_type) mime_type = "application/octet-stream";
printf("%s\n", mime_type);
}
else {
const char *codec_name = oggz_content_type (content);
if (!codec_name) codec_name = "unknown";
printf("%s\n", codec_name);
}
}
}
static int
read_page_pass1 (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
{
OI_Info * info = (OI_Info *)user_data;
oggz_table_insert (info->tracks, serialno, &read_page_pass1); /* NULL makes it barf, needs anything */
if (ogg_page_bos ((ogg_page *)og)) {
return 0;
}
else {
return OGGZ_STOP_OK;
}
}
static int
oi_pass1 (OGGZ * oggz, OI_Info * info)
{
long n, serialno;
oggz_seek (oggz, 0, SEEK_SET);
oggz_set_read_page (oggz, -1, read_page_pass1, info);
while ((n = oggz_read (oggz, READ_BLOCKSIZE)) > 0);
return 0;
}
int
main (int argc, char ** argv)
{
int show_version = 0;
int show_help = 0;
char * progname;
int i;
int many_files = 0;
char * infilename;
OGGZ * oggz;
OI_Info info;
char * optstring = "hvam";
#ifdef HAVE_GETOPT_LONG
static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{"all", no_argument, 0, 'a'},
{"mime", no_argument, 0, 'm'},
{NULL,0,0,0}
};
#endif
progname = argv[0];
if (argc < 2) {
usage (progname);
return (1);
}
if (!strncmp (argv[1], "-?", 2)) {
#ifdef HAVE_GETOPT_LONG
ot_print_options (long_options, optstring);
#else
ot_print_short_options (optstring);
#endif
exit (0);
}
while (1) {
#ifdef HAVE_GETOPT_LONG
i = getopt_long (argc, argv, optstring, long_options, NULL);
#else
i = getopt (argc, argv, optstring);
#endif
if (i == -1) break;
if (i == ':') {
usage (progname);
goto exit_err;
}
switch (i) {
case 'h': /* help */
show_help = 1;
break;
case 'v': /* version */
show_version = 1;
break;
case 'a':
show_all = 1;
break;
case 'm':
show_as_mime = 1;
break;
default:
break;
}
}
if (show_version) {
printf ("%s version " VERSION "\n", progname);
}
if (show_help) {
usage (progname);
}
if (show_version || show_help) {
goto exit_ok;
}
if (optind >= argc) {
usage (progname);
goto exit_err;
}
if (argc > optind+1) {
many_files = 1;
}
while (optind < argc) {
infilename = argv[optind++];
if ((oggz = oggz_open (infilename, OGGZ_READ|OGGZ_AUTO)) == NULL) {
fprintf (stderr, "%s: unable to open file %s\n", progname, infilename);
return (1);
}
info.oggz = oggz;
info.tracks = oggz_table_new ();
oi_pass1 (oggz, &info);
oggz_info_apply (print_codec_name, &info);
oggz_table_delete (info.tracks);
oggz_close (oggz);
}
exit_ok:
exit (0);
exit_err:
exit (1);
}
...@@ -65,6 +65,9 @@ usage (char * progname) ...@@ -65,6 +65,9 @@ usage (char * progname)
printf (" validate Validate the Ogg framing of one or more files.\n"); printf (" validate Validate the Ogg framing of one or more files.\n");
printf (" codecs Display the list of codecs found in one or more files and\n"
" their bitstreams.\n");
printf ("\nExtraction:\n"); printf ("\nExtraction:\n");
printf (" rip Extract one or more logical bitstreams from an Ogg file.\n"); printf (" rip Extract one or more logical bitstreams from an Ogg file.\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment