[NUT-devel] [NUT] (ods15): r86 - in /trunk: libnut/demuxer.c libnut/muxer.c libnut/nut.h libnut/priv.h libnut/reorder.c nututils/demux_avi.c nututils/demux_ogg.c nututils/nutmerge.c
syncmail at mplayerhq.hu
syncmail at mplayerhq.hu
Sat Mar 11 10:31:42 CET 2006
Author: ods15
Date: Sat Mar 11 10:31:41 2006
New Revision: 86
Log:
decode_delay, framecode table and max_distance are configurable via libnut
api.
some cleanup
Modified:
trunk/libnut/demuxer.c
trunk/libnut/muxer.c
trunk/libnut/nut.h
trunk/libnut/priv.h
trunk/libnut/reorder.c
trunk/nututils/demux_avi.c
trunk/nututils/demux_ogg.c
trunk/nututils/nutmerge.c
Modified: trunk/libnut/demuxer.c
==============================================================================
--- trunk/libnut/demuxer.c (original)
+++ trunk/libnut/demuxer.c Sat Mar 11 10:31:41 2006
@@ -278,7 +278,7 @@
GET_V(tmp, sc->sh.timebase.den);
GET_V(tmp, sc->msb_pts_shift);
GET_V(tmp, sc->max_pts_distance);
- GET_V(tmp, sc->decode_delay);
+ GET_V(tmp, sc->sh.decode_delay);
CHECK(get_bytes(tmp, 1, &a));
sc->sh.fixed_fps = a & 1;
CHECK(get_vb(tmp, &sc->sh.codec_specific_len, &sc->sh.codec_specific));
@@ -469,7 +469,7 @@
int i;
for (i = 0; i < nut->stream_count; i++) {
int j;
- for (j = 0; j < nut->sc[i].decode_delay; j++) nut->sc[i].pts_cache[j] = -1;
+ for (j = 0; j < nut->sc[i].sh.decode_delay; j++) nut->sc[i].pts_cache[j] = -1;
nut->sc[i].last_dts = -1;
}
}
@@ -577,7 +577,7 @@
static void push_frame(nut_context_t * nut, nut_packet_t * pd) {
stream_context_t * sc = &nut->sc[pd->stream];
sc->last_pts = pd->pts;
- sc->last_dts = get_dts(sc->decode_delay, sc->pts_cache, pd->pts);
+ sc->last_dts = get_dts(sc->sh.decode_delay, sc->pts_cache, pd->pts);
if (pd->flags & NUT_KEY_STREAM_FLAG && !sc->last_key) sc->last_key = pd->pts + 1;
if (pd->flags & NUT_EOR_STREAM_FLAG) sc->eor = pd->pts + 1;
else sc->eor = 0;
@@ -728,13 +728,12 @@
if (tmp != STREAM_STARTCODE) return -ERR_NOSTREAM_STARTCODE;
CHECK(get_stream_header(nut, i));
if (!nut->sc[i].pts_cache) {
- nut->sc[i].pts_cache = malloc(nut->sc[i].decode_delay * sizeof(int64_t));
- for (j = 0; j < nut->sc[i].decode_delay; j++)
+ nut->sc[i].pts_cache = malloc(nut->sc[i].sh.decode_delay * sizeof(int64_t));
+ for (j = 0; j < nut->sc[i].sh.decode_delay; j++)
nut->sc[i].pts_cache[j] = -1;
}
}
if (nut->dopts.read_index) {
- off_t pos = bctello(nut->i);
uint64_t tmp;
CHECK(get_bytes(nut->i, 8, &tmp));
if (tmp == INDEX_STARTCODE) nut->seek_status = 2;
@@ -1038,7 +1037,7 @@
stopper_syncpoint = buf_before;
for (i = 0; i < nut->stream_count; i++) {
if (!(pts[i] & 1)) {
- if ((good_key[i]>>1) > (stopper->back_ptr>>1)) n = 0;
+ if (good_key[i]>>1) n = 0;
else good_key[i] |= 1; // flag that we don't care about this stream
}
}
@@ -1265,7 +1264,6 @@
nut->syncpoints.pts = NULL;
nut->syncpoints.eor = NULL;
- nut->fti = NULL;
nut->sc = NULL;
nut->last_headers = 0;
nut->stream_count = 0;
Modified: trunk/libnut/muxer.c
==============================================================================
--- trunk/libnut/muxer.c (original)
+++ trunk/libnut/muxer.c Sat Mar 11 10:31:41 2006
@@ -3,32 +3,6 @@
#include <stdio.h>
#include "nut.h"
#include "priv.h"
-
-frame_table_input_t ft_default[] = {
- // There must be atleast this safety net:
- //{ 3, 3, 0, 0, 1, 0, 0, 0 },
- //{ flag, fields, sflag, pts, mul, stream, size, count }
- { 4, 0, 0, 0, 1, 0, 0, 0 }, // invalid 0x00
- { 1, 1, 1, 0, 1, 0, 0, 0 }, // safety net non key frame
- { 1, 0, 0, 0, 1, 0, 0, 0 }, // safety net key frame
- { 3, 0, 0, 0, 1, 0, 0, 0 }, // one more safety net
- { 0, 5, 1, 1, 337, 2, 336, 0 }, // used 82427 times
- { 0, 5, 1, 1, 385, 2, 384, 0 }, // used 56044 times
- { 0, 5, 0, 2, 7, 1, 6, 0 }, // used 20993 times
- { 0, 5, 0, 1, 7, 1, 6, 0 }, // used 10398 times
- { 0, 5, 1, 1, 481, 2, 480, 0 }, // used 3527 times
- { 0, 5, 1, 1, 289, 2, 288, 0 }, // used 2042 times
- { 0, 5, 1, 1, 577, 2, 576, 0 }, // used 1480 times
- { 0, 5, 1, 1, 673, 2, 672, 0 }, // used 862 times
- { 0, 5, 1, 1, 769, 2, 768, 0 }, // used 433 times
- { 0, 5, 1, 1, 961, 2, 960, 0 }, // used 191 times
- { 1, 4, 0, 2, 104, 1, 0, 0 }, // "1.2.0" => 14187
- { 1, 4, 0, -1, 42, 1, 0, 0 }, // "1.-1.0" => 5707
- { 1, 4, 0, 1, 83, 1, 0, 0 }, // "1.1.0" => 11159
- { 1, 4, 1, 1, 11, 1, 0, 0 }, // "1.1.1" => 1409
- { 4, 3, 0, 0, 1, 0, 0, 0 }, // invalid 0xFF
- { -1, 0, 0, 0, 0, 0, 0, 0 }, // end
-};
static int stream_write(void * priv, size_t len, const uint8_t * buf) {
return fwrite(buf, 1, len, priv);
@@ -273,7 +247,7 @@
put_data(nut->o, fd->len, data);
sc->last_pts = fd->pts;
- sc->last_dts = get_dts(sc->decode_delay, sc->pts_cache, fd->pts);
+ sc->last_dts = get_dts(sc->sh.decode_delay, sc->pts_cache, fd->pts);
sc->sh.max_pts = MAX(sc->sh.max_pts, fd->pts);
}
@@ -303,18 +277,18 @@
put_v(tmp, nut->stream_count);
put_v(tmp, nut->max_distance);
for(n=i=0; i < 256; n++) {
- assert(nut->fti[n].tmp_flag != -1);
- put_v(tmp, flag = nut->fti[n].tmp_flag);
- put_v(tmp, fields = nut->fti[n].tmp_fields);
- if (fields > 0) put_v(tmp, sflag = nut->fti[n].tmp_sflag);
+ assert(nut->mopts.fti[n].tmp_flag != -1);
+ put_v(tmp, flag = nut->mopts.fti[n].tmp_flag);
+ put_v(tmp, fields = nut->mopts.fti[n].tmp_fields);
+ if (fields > 0) put_v(tmp, sflag = nut->mopts.fti[n].tmp_sflag);
else sflag = 0;
- if (fields > 1) put_s(tmp, timestamp = nut->fti[n].tmp_pts);
- if (fields > 2) put_v(tmp, mul = nut->fti[n].tmp_mul);
- if (fields > 3) put_v(tmp, stream = nut->fti[n].tmp_stream);
- if (fields > 4) put_v(tmp, size = nut->fti[n].tmp_size);
+ if (fields > 1) put_s(tmp, timestamp = nut->mopts.fti[n].tmp_pts);
+ if (fields > 2) put_v(tmp, mul = nut->mopts.fti[n].tmp_mul);
+ if (fields > 3) put_v(tmp, stream = nut->mopts.fti[n].tmp_stream);
+ if (fields > 4) put_v(tmp, size = nut->mopts.fti[n].tmp_size);
else size = 0;
if (fields > 5) put_v(tmp, 0); // reserved
- if (fields > 6) put_v(tmp, count = nut->fti[n].count);
+ if (fields > 6) put_v(tmp, count = nut->mopts.fti[n].count);
else count = mul - size;
for(j = 0; j < count && i < 256; j++, i++) {
@@ -332,7 +306,7 @@
}
}
- assert(nut->fti[n].tmp_flag == -1);
+ assert(nut->mopts.fti[n].tmp_flag == -1);
put_header(nut->o, tmp, MAIN_STARTCODE, 0);
}
@@ -347,7 +321,7 @@
put_v(tmp, sc->sh.timebase.den);
put_v(tmp, sc->msb_pts_shift);
put_v(tmp, sc->max_pts_distance);
- put_v(tmp, sc->decode_delay);
+ put_v(tmp, sc->sh.decode_delay);
put_bytes(tmp, 1, sc->sh.fixed_fps ? 1 : 0);
put_vb(tmp, sc->sh.codec_specific_len, sc->sh.codec_specific);
@@ -516,9 +490,12 @@
nut->o = new_output_buffer(mopts->output);
nut->tmp_buffer = new_mem_buffer(); // general purpose buffer
- nut->max_distance = 32768; // TODO
- nut->fti = ft_default; // TODO
+ nut->max_distance = mopts->max_distance;
nut->mopts = *mopts;
+
+ for (i = 0; mopts->fti[i].tmp_flag != -1; i++);
+ nut->mopts.fti = malloc(++i * sizeof(frame_table_input_t));
+ memcpy(nut->mopts.fti, mopts->fti, i * sizeof(frame_table_input_t));
nut->sync_overhead = 0;
@@ -540,7 +517,6 @@
nut->sc[i].last_dts = -1;
nut->sc[i].msb_pts_shift = 7; // TODO
nut->sc[i].max_pts_distance = (s[i].timebase.den + s[i].timebase.nom - 1) / s[i].timebase.nom; // TODO
- nut->sc[i].decode_delay = !i; // ### TODO
nut->sc[i].eor = 0;
nut->sc[i].sh = s[i];
nut->sc[i].sh.max_pts = 0;
@@ -551,11 +527,11 @@
nut->sc[i].sh.codec_specific = malloc(s[i].codec_specific_len);
memcpy(nut->sc[i].sh.codec_specific, s[i].codec_specific, s[i].codec_specific_len);
- nut->sc[i].pts_cache = malloc(nut->sc[i].decode_delay * sizeof(int64_t));
+ nut->sc[i].pts_cache = malloc(nut->sc[i].sh.decode_delay * sizeof(int64_t));
// reorder.c
- nut->sc[i].reorder_pts_cache = malloc(nut->sc[i].decode_delay * sizeof(int64_t));
- for (j = 0; j < nut->sc[i].decode_delay; j++) nut->sc[i].reorder_pts_cache[j] = nut->sc[i].pts_cache[j] = -1;
+ nut->sc[i].reorder_pts_cache = malloc(nut->sc[i].sh.decode_delay * sizeof(int64_t));
+ for (j = 0; j < nut->sc[i].sh.decode_delay; j++) nut->sc[i].reorder_pts_cache[j] = nut->sc[i].pts_cache[j] = -1;
nut->sc[i].next_pts = 0;
nut->sc[i].packets = NULL;
nut->sc[i].num_packets = 0;
@@ -634,6 +610,7 @@
free(nut->syncpoints.s);
free(nut->syncpoints.pts);
free(nut->syncpoints.eor);
+ free(nut->mopts.fti);
free_buffer(nut->tmp_buffer);
free_buffer(nut->o); // flushes file
Modified: trunk/libnut/nut.h
==============================================================================
--- trunk/libnut/nut.h (original)
+++ trunk/libnut/nut.h Sat Mar 11 10:31:41 2006
@@ -33,6 +33,7 @@
uint8_t * fourcc;
nut_timebase_t timebase;
int fixed_fps;
+ int decode_delay;
int codec_specific_len;
uint8_t * codec_specific;
// video
@@ -50,8 +51,21 @@
} nut_stream_header_t;
typedef struct {
+ int tmp_flag; // 1 => use msb, 2 => coded sflags, 4 => invalid, -1 => end
+ int tmp_fields;
+ int tmp_sflag; // tmp_fields = 1
+ int tmp_pts; // tmp_fields = 2
+ int tmp_mul; // tmp_fields = 3
+ int tmp_stream; // tmp_fields = 4
+ int tmp_size; // tmp_fields = 5
+ int count; // tmp_fields = 7 (6 is reserved)
+} frame_table_input_t;
+
+typedef struct {
nut_output_stream_t output;
int write_index;
+ int max_distance;
+ frame_table_input_t * fti;
} nut_muxer_opts_t;
typedef struct {
Modified: trunk/libnut/priv.h
==============================================================================
--- trunk/libnut/priv.h (original)
+++ trunk/libnut/priv.h Sat Mar 11 10:31:41 2006
@@ -98,7 +98,6 @@
int64_t last_dts;
int msb_pts_shift;
int max_pts_distance;
- int decode_delay;
nut_stream_header_t sh;
int64_t * pts_cache;
int64_t eor;
@@ -112,17 +111,6 @@
int tot_size;
int total_frames;
} stream_context_t;
-
-typedef struct {
- int tmp_flag; // 1 => use msb, 2 => coded sflags, 4 => invalid
- int tmp_fields;
- int tmp_sflag; // tmp_fields = 1
- int tmp_pts; // tmp_fields = 2
- int tmp_mul; // tmp_fields = 3
- int tmp_stream; // tmp_fields = 4
- int tmp_size; // tmp_fields = 5
- int count; // tmp_fields = 7 (6 is reserved)
-} frame_table_input_t;
struct nut_context_s {
nut_muxer_opts_t mopts;
@@ -138,7 +126,6 @@
nut_info_packet_t * info;
int max_distance;
- frame_table_input_t * fti;
frame_table_t ft[256];
off_t last_syncpoint; // for checking corruption and putting syncpoints, also for back_ptr
Modified: trunk/libnut/reorder.c
==============================================================================
--- trunk/libnut/reorder.c (original)
+++ trunk/libnut/reorder.c Sat Mar 11 10:31:41 2006
@@ -80,7 +80,7 @@
s->num_packets++;
s->packets = realloc(s->packets, s->num_packets * sizeof(reorder_packet_t));
s->packets[s->num_packets - 1].p = *p;
- s->packets[s->num_packets - 1].dts = get_dts(s->decode_delay, s->reorder_pts_cache, p->pts);
+ s->packets[s->num_packets - 1].dts = get_dts(s->sh.decode_delay, s->reorder_pts_cache, p->pts);
s->packets[s->num_packets - 1].buf = malloc(p->len); // FIXME
memcpy(s->packets[s->num_packets - 1].buf, buf, p->len);
Modified: trunk/nututils/demux_avi.c
==============================================================================
--- trunk/nututils/demux_avi.c (original)
+++ trunk/nututils/demux_avi.c Sat Mar 11 10:31:41 2006
@@ -362,6 +362,7 @@
s[i].timebase.den = avi->stream[i].strh->dwRate;
s[i].timebase.nom = avi->stream[i].strh->dwScale;
s[i].fixed_fps = 1;
+ s[i].decode_delay = !i; // FIXME
s[i].codec_specific_len = avi->stream[i].extra_len;
s[i].codec_specific = avi->stream[i].extra;
if (avi->stream[i].type == 0) { // video
Modified: trunk/nututils/demux_ogg.c
==============================================================================
--- trunk/nututils/demux_ogg.c (original)
+++ trunk/nututils/demux_ogg.c Sat Mar 11 10:31:41 2006
@@ -40,6 +40,7 @@
int time_base_denom;
int time_base_nom;
int fixed_fps;
+ int decode_delay;
int codec_specific_len;
uint8_t * codec_specific;
int width;
@@ -262,6 +263,7 @@
os->time_base_denom = sample_rate / gcd(sample_rate, i);
os->time_base_nom = i / gcd(sample_rate, i);
os->fixed_fps = 0;
+ os->decode_delay = 0;
os->codec_specific_len = 0;
os->codec_specific = NULL;
os->samplerate_nom = sample_rate;
@@ -530,6 +532,7 @@
s[i].timebase.den = os->time_base_denom;
s[i].timebase.nom = os->time_base_nom;
s[i].fixed_fps = os->fixed_fps;
+ s[i].decode_delay = os->decode_delay;
s[i].codec_specific = os->codec_specific;
s[i].codec_specific_len = os->codec_specific_len;
switch (os->oc->type) {
Modified: trunk/nututils/nutmerge.c
==============================================================================
--- trunk/nututils/nutmerge.c (original)
+++ trunk/nututils/nutmerge.c Sat Mar 11 10:31:41 2006
@@ -13,6 +13,32 @@
&nut_demuxer,
&ogg_demuxer,
NULL
+};
+
+frame_table_input_t ft_default[] = {
+ // There must be atleast this safety net:
+ //{ 3, 3, 0, 0, 1, 0, 0, 0 },
+ //{ flag, fields, sflag, pts, mul, stream, size, count }
+ { 4, 0, 0, 0, 1, 0, 0, 0 }, // invalid 0x00
+ { 1, 1, 1, 0, 1, 0, 0, 0 }, // safety net non key frame
+ { 1, 0, 0, 0, 1, 0, 0, 0 }, // safety net key frame
+ { 3, 0, 0, 0, 1, 0, 0, 0 }, // one more safety net
+ { 0, 5, 1, 1, 337, 2, 336, 0 }, // used 82427 times
+ { 0, 5, 1, 1, 385, 2, 384, 0 }, // used 56044 times
+ { 0, 5, 0, 2, 7, 1, 6, 0 }, // used 20993 times
+ { 0, 5, 0, 1, 7, 1, 6, 0 }, // used 10398 times
+ { 0, 5, 1, 1, 481, 2, 480, 0 }, // used 3527 times
+ { 0, 5, 1, 1, 289, 2, 288, 0 }, // used 2042 times
+ { 0, 5, 1, 1, 577, 2, 576, 0 }, // used 1480 times
+ { 0, 5, 1, 1, 673, 2, 672, 0 }, // used 862 times
+ { 0, 5, 1, 1, 769, 2, 768, 0 }, // used 433 times
+ { 0, 5, 1, 1, 961, 2, 960, 0 }, // used 191 times
+ { 1, 4, 0, 2, 104, 1, 0, 0 }, // "1.2.0" => 14187
+ { 1, 4, 0, -1, 42, 1, 0, 0 }, // "1.-1.0" => 5707
+ { 1, 4, 0, 1, 83, 1, 0, 0 }, // "1.1.0" => 11159
+ { 1, 4, 1, 1, 11, 1, 0, 0 }, // "1.1.1" => 1409
+ { 4, 3, 0, 0, 1, 0, 0, 0 }, // invalid 0xFF
+ { -1, 0, 0, 0, 0, 0, 0, 0 }, // end
};
int main(int argc, char * argv []) {
@@ -56,6 +82,8 @@
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;
+ mopts.max_distance = 32768;
nut = nut_muxer_init(&mopts, nut_stream, NULL);
for (i = 0; nut_stream[i].type >= 0; i++);
More information about the NUT-devel
mailing list