Commit 257508c3 authored by conrad's avatar conrad

split oggz-chop commandline functions out into oggz-chop/cmd.h


git-svn-id: http://svn.annodex.net/liboggz/trunk@3501 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent e786c4c9
## Process this file with automake to produce Makefile.in ## Process this file with automake to produce Makefile.in
INCLUDES = -I$(top_srcdir)/include @OGG_CFLAGS@ INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/include @OGG_CFLAGS@
OGGZDIR = ../../liboggz OGGZDIR = ../../liboggz
OGGZ_LIBS = $(OGGZDIR)/liboggz.la @OGG_LIBS@ OGGZ_LIBS = $(OGGZDIR)/liboggz.la @OGG_LIBS@
...@@ -14,6 +14,16 @@ endif ...@@ -14,6 +14,16 @@ endif
# Programs to build # Programs to build
bin_PROGRAMS = $(oggz_rw_programs) bin_PROGRAMS = $(oggz_rw_programs)
noinst_PROGRAMS = httpdate_test
oggz_chop_SOURCES = oggz-chop.c ../oggz_tools.c TESTS_ENVIRONMENT = $(VALGRIND_ENVIRONMENT)
TESTS = httpdate_test
noinst_HEADERS = alloc_snprintf.h cgi.h cmd.h header.h httpdate.h memory.h oggz-chop.h tests.h
oggz_chop_SOURCES = oggz-chop.c ../oggz_tools.c cmd.c main.c
oggz_chop_LDADD = $(OGGZ_LIBS) oggz_chop_LDADD = $(OGGZ_LIBS)
httpdate_test_SOURCES = httpdate.c httpdate_test.c
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "oggz-chop.h"
static char * progname;
static void
usage (char * progname)
{
printf ("Usage: %s [options] filename\n", progname);
printf ("Chop an Ogg file.\n");
printf ("\nOutput options\n");
printf (" -o filename, --output filename\n");
printf (" Specify output filename\n");
printf (" -s start_time, --start start_time\n");
printf (" Specify start time\n");
printf (" -e end_time, --end end_time\n");
printf (" Specify end time\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");
}
int
cmd_main (int argc, char * argv[])
{
int show_version = 0;
int show_help = 0;
double start = 0.0, end = -1.0;
char * infilename = NULL, * outfilename = NULL;
int i;
progname = argv[0];
if (argc < 2) {
usage (progname);
return (1);
}
while (1) {
char * optstring = "s:e:o:hv";
#ifdef HAVE_GETOPT_LONG
static struct option long_options[] = {
{"start", required_argument, 0, 's'},
{"end", required_argument, 0, 'e'},
{"output", required_argument, 0, 'o'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{0,0,0,0}
};
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 's': /* start */
start = atof (optarg);
break;
case 'e': /* end */
end = atof (optarg);
break;
case 'h': /* help */
show_help = 1;
break;
case 'v': /* version */
show_version = 1;
break;
case 'o': /* output */
outfilename = optarg;
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;
}
infilename = argv[optind++];
return chop (infilename, outfilename, start, end);
exit_ok:
return 0;
exit_err:
return 1;
}
#ifndef __CMD_H__
#define __CMD_H__
int cmd_main (int argc, char * argv[]);
#endif /* __CMD_H__ */
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "oggz-chop.h"
/*#include "cgi.h"*/
#include "cmd.h"
int
main (int argc, char * argv[])
{
int err = 0;
#if 0
if (cgi_test ()) {
err = cgi_main (&params);
} else {
err = cmd_main (&params, argc, argv);
}
#else
err = cmd_main (argc, argv);
#endif
if (err) return 1;
else return 0;
}
/* /*
Copyright (C) 2008 Annodex Association Copyright (C) 2008 Annodex Association
...@@ -37,56 +36,9 @@ ...@@ -37,56 +36,9 @@
#include <getopt.h> #include <getopt.h>
#include <errno.h> #include <errno.h>
#include <oggz/oggz.h> #include <oggz/oggz.h>
static char * progname; #include "oggz-chop.h"
static void
usage (char * progname)
{
printf ("Usage: %s [options] filename\n", progname);
printf ("Chop an Ogg file.\n");
printf ("\nOutput options\n");
printf (" -o filename, --output filename\n");
printf (" Specify output filename\n");
printf (" -s start_time, --start start_time\n");
printf (" Specify start time\n");
printf (" -e end_time, --end end_time\n");
printf (" Specify end time\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");
}
/************************************************************
* OCState
*/
typedef struct _OCState {
OggzTable * tracks;
FILE * outfile;
double start;
double end;
} OCState;
/************************************************************
* OCTrackState
*/
typedef struct _OCTrackState {
OggzTable * page_accum;
int headers_remaining;
long start_granule;
/* Greatest previously inferred keyframe value */
ogg_int64_t prev_keyframe;
} OCTrackState;
static OCTrackState * static OCTrackState *
track_state_new (void) track_state_new (void)
...@@ -325,7 +277,7 @@ read_bos (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data) ...@@ -325,7 +277,7 @@ read_bos (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
return OGGZ_CONTINUE; return OGGZ_CONTINUE;
} }
static int int
chop (char * infilename, char * outfilename, double start, double end) chop (char * infilename, char * outfilename, double start, double end)
{ {
OCState state; OCState state;
...@@ -344,8 +296,8 @@ chop (char * infilename, char * outfilename, double start, double end) ...@@ -344,8 +296,8 @@ chop (char * infilename, char * outfilename, double start, double end)
} else { } else {
state.outfile = fopen (outfilename, "wb"); state.outfile = fopen (outfilename, "wb");
if (state.outfile == NULL) { if (state.outfile == NULL) {
fprintf (stderr, "%s: unable to open output file %s\n", fprintf (stderr, "oggz-chop: unable to open output file %s\n",
progname, outfilename); outfilename);
return -1; return -1;
} }
} }
...@@ -363,91 +315,3 @@ chop (char * infilename, char * outfilename, double start, double end) ...@@ -363,91 +315,3 @@ chop (char * infilename, char * outfilename, double start, double end)
return 0; return 0;
} }
int
main (int argc, char * argv[])
{
int show_version = 0;
int show_help = 0;
double start = 0.0, end = -1.0;
char * infilename = NULL, * outfilename = NULL;
int i;
progname = argv[0];
if (argc < 2) {
usage (progname);
return (1);
}
while (1) {
char * optstring = "s:e:o:hv";
#ifdef HAVE_GETOPT_LONG
static struct option long_options[] = {
{"output", required_argument, 0, 'o'},
{"format", required_argument, 0, 'f'},
{"keyframe", no_argument, 0, 'k'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{0,0,0,0}
};
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 's': /* start */
start = atof (optarg);
break;
case 'e': /* end */
end = atof (optarg);
break;
case 'h': /* help */
show_help = 1;
break;
case 'v': /* version */
show_version = 1;
break;
case 'o': /* output */
outfilename = optarg;
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;
}
infilename = argv[optind++];
return chop (infilename, outfilename, start, end);
exit_ok:
return 0;
exit_err:
return 1;
}
/*
Copyright (C) 2008 Annodex Association
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 the Annodex Association 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 ASSOCIATION 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_CHOP_H__
#define __OGGZ_CHOP_H__
#include <oggz/oggz.h>
/************************************************************
* OCState
*/
typedef struct _OCState {
OggzTable * tracks;
FILE * outfile;
double start;
double end;
} OCState;
/************************************************************
* OCTrackState
*/
typedef struct _OCTrackState {
OggzTable * page_accum;
int headers_remaining;
long start_granule;
/* Greatest previously inferred keyframe value */
ogg_int64_t prev_keyframe;
} OCTrackState;
int chop (char * infilename, char * outfilename, double start, double end);
#endif /* __OGGZ_CHOP_H__ */
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