[NUT-devel] [NUT] (ods15): r114 - in /trunk/nututils: demux_avi.c demux_nut.c demux_ogg.c nutmerge.c nutmerge.h
syncmail at mplayerhq.hu
syncmail at mplayerhq.hu
Sun Mar 26 16:27:25 CEST 2006
Author: ods15
Date: Sun Mar 26 16:27:24 2006
New Revision: 114
Log:
slightly better (worse?) demuer struct setup for nutmerge
Modified:
trunk/nututils/demux_avi.c
trunk/nututils/demux_nut.c
trunk/nututils/demux_ogg.c
trunk/nututils/nutmerge.c
trunk/nututils/nutmerge.h
Modified: trunk/nututils/demux_avi.c
==============================================================================
--- trunk/nututils/demux_avi.c (original)
+++ trunk/nututils/demux_avi.c Sun Mar 26 16:27:24 2006
@@ -111,7 +111,7 @@
uint8_t * extra;
} AVIStreamContext;
-typedef struct {
+struct demuxer_priv_s {
full_riff_tree_t * riff;
MainAVIHeader * avih;
AVIStreamContext * stream; // this is an array, free this
@@ -120,7 +120,7 @@
FILE * in;
int cur;
uint8_t * buf;
-} AVIContext;
+};
static int mk_riff_tree(FILE * in, riff_tree_t * tree) {
int left;
@@ -252,7 +252,7 @@
return 0;
}
-static int avi_read_main_header(AVIContext * avi, const riff_tree_t * tree) {
+static int avi_read_main_header(demuxer_priv_t * avi, const riff_tree_t * tree) {
int i, tmp = 0, err;
assert(tree->type == 0);
assert(strFOURCC(tree->listname) == mmioFOURCC('h','d','r','l'));
@@ -286,7 +286,7 @@
return 0;
}
-static int avi_read_headers(AVIContext * avi) {
+static int avi_read_headers(demuxer_priv_t * avi) {
const riff_tree_t * tree;
int i, err;
if ((err = get_full_riff_tree(avi->in, avi->riff))) return err;
@@ -330,7 +330,7 @@
}
static void * init(FILE * in) {
- AVIContext * avi = malloc(sizeof(AVIContext));
+ demuxer_priv_t * avi = malloc(sizeof(demuxer_priv_t));
avi->avih = NULL;
avi->stream = NULL;
avi->index = NULL;
@@ -341,8 +341,7 @@
return avi;
}
-static void uninit(void * priv) {
- AVIContext * avi = priv;
+static void uninit(demuxer_priv_t * avi) {
if (!avi) return;
uninit_riff(avi->riff);
@@ -351,8 +350,7 @@
free(avi);
}
-static int read_headers(void * priv, nut_stream_header_t ** nut_streams) {
- AVIContext * avi = priv;
+static int read_headers(demuxer_priv_t * avi, nut_stream_header_t ** nut_streams) {
nut_stream_header_t * s;
int i;
if ((i = avi_read_headers(avi))) return i;
@@ -404,8 +402,7 @@
return 13;
}
-static int get_packet(void * priv, nut_packet_t * p, uint8_t ** buf) {
- AVIContext * avi = priv;
+static int get_packet(demuxer_priv_t * avi, nut_packet_t * p, uint8_t ** buf) {
char fourcc[4];
int err = 0;
int s; // stream
@@ -541,7 +538,7 @@
FILE * stats = NULL;
int main(int argc, char * argv []) {
FILE * in;
- AVIContext * avi = NULL;
+ demuxer_priv_t * avi = NULL;
int err = 0;
int i;
if (argc < 2) { printf("bleh, more params you fool...\n"); return 1; }
Modified: trunk/nututils/demux_nut.c
==============================================================================
--- trunk/nututils/demux_nut.c (original)
+++ trunk/nututils/demux_nut.c Sun Mar 26 16:27:24 2006
@@ -1,34 +1,31 @@
#include "nutmerge.h"
#define ABS(x) MAX(x,-x)
-typedef struct nutmerge_nut_s {
+struct demuxer_priv_s {
nut_context_t * nut;
uint8_t * buf;
-} nutmerge_nut_t;
+};
static void * init(FILE * in) {
- nutmerge_nut_t * nut = malloc(sizeof(nutmerge_nut_t));
+ demuxer_priv_t * nut = malloc(sizeof(demuxer_priv_t));
nut_demuxer_opts_t dopts = { { in, NULL, NULL, NULL, 0 } , 0};
nut->nut = nut_demuxer_init(&dopts);
nut->buf = NULL;
return nut;
}
-static void uninit(void * priv) {
- nutmerge_nut_t * nut = priv;
+static void uninit(demuxer_priv_t * nut) {
nut_demuxer_uninit(nut->nut);
free(nut->buf);
free(nut);
}
-static int read_headers(void * priv, nut_stream_header_t ** nut_streams) {
- nutmerge_nut_t * nut = priv;
+static int read_headers(demuxer_priv_t * nut, nut_stream_header_t ** nut_streams) {
int err = nut_read_headers(nut->nut, nut_streams);
return err == 1 ? -1 : ABS(err);
}
-static int get_packet(void * priv, nut_packet_t * p, uint8_t ** buf) {
- nutmerge_nut_t * nut = priv;
+static int get_packet(demuxer_priv_t * nut, nut_packet_t * p, uint8_t ** buf) {
int err;
int len;
do {
Modified: trunk/nututils/demux_ogg.c
==============================================================================
--- trunk/nututils/demux_ogg.c (original)
+++ trunk/nututils/demux_ogg.c Sun Mar 26 16:27:24 2006
@@ -7,9 +7,6 @@
#define PAGE_ALLOC 65000
-struct ogg_s;
-typedef struct ogg_s ogg_t;
-struct ogg_stream_s;
typedef struct ogg_stream_s ogg_stream_t;
typedef struct ogg_codec_s {
@@ -18,7 +15,7 @@
char * fourcc;
int fourcc_len;
int type;
- int (*read_headers)(ogg_t * ogg, int stream);
+ int (*read_headers)(demuxer_priv_t * ogg, int stream);
int (*get_pts)(ogg_stream_t * os);
int (*is_key)(ogg_stream_t * os);
void (*uninit)(ogg_stream_t * os);
@@ -53,7 +50,7 @@
int channel_count;
};
-struct ogg_s {
+struct demuxer_priv_s {
FILE * in;
ogg_stream_t * streams;
int nstreams;
@@ -71,7 +68,7 @@
uint8_t segments;
} ogg_header_t;
-static int vorbis_read_headers(ogg_t * ogg, int stream);
+static int vorbis_read_headers(demuxer_priv_t * ogg, int stream);
static int vorbis_get_pts(ogg_stream_t * os);
static void vorbis_uninit(ogg_stream_t * os);
@@ -90,7 +87,7 @@
NULL
};
-static int find_stream(ogg_t * ogg, int serial) {
+static int find_stream(demuxer_priv_t * ogg, int serial) {
ogg_stream_t * os;
int i;
for (i = 0; i < ogg->nstreams; i++) {
@@ -109,7 +106,7 @@
return i;
}
-static int read_page(ogg_t * ogg, int * stream) {
+static int read_page(demuxer_priv_t * ogg, int * stream) {
ogg_header_t tmp;
ogg_stream_t * os;
uint8_t seg[256];
@@ -153,7 +150,7 @@
return 0;
}
-static int get_headers(ogg_t * ogg) {
+static int get_headers(demuxer_priv_t * ogg) {
int i;
int err;
int stream;
@@ -234,7 +231,7 @@
#define CHECK(x) do{ if ((err = (x))) return err; }while(0)
-static int vorbis_read_headers(ogg_t * ogg, int stream) {
+static int vorbis_read_headers(demuxer_priv_t * ogg, int stream) {
ogg_stream_t * os = &ogg->streams[stream];
bit_packer_t bp;
uint64_t num;
@@ -494,7 +491,7 @@
// END
static void * init(FILE * in) {
- ogg_t * ogg = malloc(sizeof(ogg_t));
+ demuxer_priv_t * ogg = malloc(sizeof(demuxer_priv_t));
ogg->streams = NULL;
ogg->nstreams = 0;
ogg->in = in;
@@ -502,8 +499,7 @@
return ogg;
}
-static void uninit(void * priv) {
- ogg_t * ogg = priv;
+static void uninit(demuxer_priv_t * ogg) {
int i;
for (i = 0; i < ogg->nstreams; i++) {
if (ogg->streams[i].oc && ogg->streams[i].oc->uninit)
@@ -514,8 +510,7 @@
free(ogg);
}
-static int read_headers(void * priv, nut_stream_header_t ** nut_streams) {
- ogg_t * ogg = priv;
+static int read_headers(demuxer_priv_t * ogg, nut_stream_header_t ** nut_streams) {
nut_stream_header_t * s;
int i;
int err;
@@ -553,8 +548,7 @@
return 0;
}
-static int get_packet(void * priv, nut_packet_t * p, uint8_t ** buf) {
- ogg_t * ogg = priv;
+static int get_packet(demuxer_priv_t * ogg, nut_packet_t * p, uint8_t ** buf) {
int stream = ogg->last_stream;
ogg_stream_t * os = &ogg->streams[stream];
int err;
@@ -593,7 +587,7 @@
#ifdef OGG_PROG
int main(int argc, char *argv[]) {
FILE * in;
- ogg_t * ogg = NULL;
+ demuxer_priv_t * ogg = NULL;
int err = 0;
int i;
nut_packet_t p;
Modified: trunk/nututils/nutmerge.c
==============================================================================
--- trunk/nututils/nutmerge.c (original)
+++ trunk/nututils/nutmerge.c Sun Mar 26 16:27:24 2006
@@ -45,8 +45,7 @@
int main(int argc, char * argv []) {
FILE * in = NULL, * out = NULL;
- struct demuxer_t * demuxer = NULL;
- void * demuxer_priv = NULL;
+ struct demuxer_t demuxer = { .extention = NULL, .priv = NULL };
nut_context_t * nut = NULL;
nut_stream_header_t * nut_stream = NULL;
nut_muxer_opts_t mopts;
@@ -68,9 +67,9 @@
extention = argv[1];
for (i = 0; argv[1][i]; i++) if (argv[1][i] == '.') extention = &argv[1][i+1];
for (i = 0; demuxers[i]; i++)
- if (!strcmp(demuxers[i]->extention, extention)) demuxer = demuxers[i];
+ if (!strcmp(demuxers[i]->extention, extention)) demuxer = *demuxers[i];
- if (!demuxer) {
+ if (!demuxer.extention) {
printf("unsupported file format\n");
err = 1;
goto err_out;
@@ -79,9 +78,9 @@
in = fopen(argv[1], "rb");
out = fopen(argv[2], "wb");
- demuxer_priv = demuxer->init(in);
+ demuxer.priv = demuxer.init(in);
- if ((err = demuxer->read_headers(demuxer_priv, &nut_stream))) goto err_out;
+ if ((err = demuxer.read_headers(demuxer.priv, &nut_stream))) goto err_out;
mopts.output = (nut_output_stream_t){ .priv = out, .write = NULL };
mopts.write_index = 1;
mopts.fti = ft_default;
@@ -102,7 +101,7 @@
}
if (stats) fprintf(stats, "%10s%10s%10s%10s\n", "stream", "len", "pts_diff", "flags");
- while (!(err = demuxer->get_packet(demuxer_priv, &p, &buf))) {
+ while (!(err = demuxer.get_packet(demuxer.priv, &p, &buf))) {
int s = p.stream;
nut_write_frame_reorder(nut, &p, buf);
if (++frames_pos[s] > frames_alloc[s]) {
@@ -141,7 +140,7 @@
err_out:
nut_muxer_uninit_reorder(nut);
free(nut_stream);
- if (demuxer) demuxer->uninit(demuxer_priv);
+ if (demuxer.priv) demuxer.uninit(demuxer.priv);
if (in) fclose(in);
if (out) fclose(out);
if (stats) fclose(stats);
Modified: trunk/nututils/nutmerge.h
==============================================================================
--- trunk/nututils/nutmerge.h (original)
+++ trunk/nututils/nutmerge.h Sun Mar 26 16:27:24 2006
@@ -10,12 +10,15 @@
extern FILE * stats;
+typedef struct demuxer_priv_s demuxer_priv_t;
+
struct demuxer_t {
char * extention;
void * (*init)(FILE * in); ///< returns priv
/// nut_streams must be free()'d!! nut_streams becomes invalid after uninit!!
- int (*read_headers)(void * priv, nut_stream_header_t ** nut_streams);
+ int (*read_headers)(demuxer_priv_t * priv, nut_stream_header_t ** nut_streams);
/// buf must be handled by demuxer! no free-ing or mallocing done by controller.
- int (*get_packet)(void * priv, nut_packet_t * p, uint8_t ** buf);
- void (*uninit)(void * priv);
+ int (*get_packet)(demuxer_priv_t * priv, nut_packet_t * p, uint8_t ** buf);
+ void (*uninit)(demuxer_priv_t * priv);
+ demuxer_priv_t * priv;
};
More information about the NUT-devel
mailing list