Commit 5a9728d8 authored by conrad's avatar conrad

separate oggzrip's codec identification out to a common routine in oggz_tools.c


git-svn-id: http://svn.annodex.net/liboggz/trunk@1060 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent beb6a66c
......@@ -21,6 +21,8 @@ endif
endif
noinst_HEADERS = oggz_tools.h
# Programs to build
bin_PROGRAMS = $(oggz_read_programs) $(oggz_rw_programs)
noinst_PROGRAMS = $(oggz_read_noinst_programs)
......@@ -37,5 +39,5 @@ oggzdump_LDADD = $(OGGZ_LIBS)
oggzmerge_SOURCES = oggzmerge.c
oggzmerge_LDADD = $(OGGZ_LIBS)
oggzrip_SOURCES = oggzrip.c
oggzrip_SOURCES = oggzrip.c oggz_tools.c
oggzrip_LDADD = $(OGGZ_LIBS)
/*
Copyright (C) 2005 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 "config.h"
#include <stdlib.h>
#include <string.h>
#include <oggz/oggz.h>
typedef struct {
const char *bos_str;
int bos_str_len;
const char *content_type;
} OTCodecIdent;
static const OTCodecIdent codec_ident[] = {
{"\200theora", 7, "theora"},
{"\001vorbis", 7, "vorbis"},
{"Speex", 5, "speex"},
{"Annodex", 8, "annodex"},
{NULL}
};
const char *
ot_page_identify (const ogg_page * og)
{
const char * ret = NULL;
int i;
/* try to identify stream codec name by looking at the first bytes of the
* first packet */
for (i = 0;; i++) {
const OTCodecIdent *ident = &codec_ident[i];
if (ident->bos_str == NULL) {
ret = NULL;
break;
}
if (og->body_len >= ident->bos_str_len &&
memcmp (og->body, ident->bos_str, ident->bos_str_len) == 0) {
ret = ident->content_type;
break;
}
}
return ret;
}
/*
Copyright (C) 2005 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.
*/
#ifndef __OGGZ_TOOLS_H__
#define __OGGZ_TOOLS_H__
#include "config.h"
const char *
ot_page_identify (const ogg_page * og);
#endif /* __OGGZ_TOOLS_H__ */
......@@ -45,6 +45,7 @@
#include <errno.h>
#include <oggz/oggz.h>
#include "oggz_tools.h"
#ifdef _WIN32
/* Supply missing headers and functions for Win32 */
......@@ -78,22 +79,8 @@ typedef struct {
int bos;
} ORStream;
typedef struct {
const char *bos_str;
int bos_str_len;
const char *content_type;
} ORCodecIdent;
static int streamid_count = 0;
static const ORCodecIdent codec_ident[] = {
{"\200theora", 7, "theora"},
{"\001vorbis", 7, "vorbis"},
{"Speex", 5, "speex"},
{"Annodex", 8, "annodex"},
{NULL}
};
static void
usage (char * progname)
{
......@@ -177,8 +164,8 @@ filter_stream_p (const ORData *ordata, ORStream *stream,
static ORStream *
orstream_new (const ORData *ordata, const ogg_page *og, long serialno)
{
int i;
const char * ident;
ORStream *stream = malloc (sizeof (ORStream));
assert (stream != NULL);
......@@ -186,19 +173,8 @@ orstream_new (const ORData *ordata, const ogg_page *og, long serialno)
stream->streamid = streamid_count++;
stream->content_type = "unknown";
/* try to identify stream codec name by looking at the first bytes of the
* first packet */
for (i = 0;; i++) {
const ORCodecIdent *ident = &codec_ident[i];
if (ident->bos_str == NULL)
break;
if (og->body_len >= ident->bos_str_len &&
memcmp (og->body, ident->bos_str, ident->bos_str_len) == 0) {
stream->content_type = ident->content_type;
break;
}
}
ident = ot_page_identify (og);
if (ident != NULL) stream->content_type = ident;
if (ordata->verbose)
fprintf (stderr,
......
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