/*
- * NUT (de)muxer based on initial draft
+ * "NUT" Container Format muxer and demuxer (DRAFT-20031003)
* Copyright (c) 2003 Alex Beregszaszi
*
* This library is free software; you can redistribute it and/or
*
* NUT DRAFT can be found in MPlayer CVS at DOCS/tech/mpcf.txt
*
- * Compatible with draft version 20030906
+ * AND http://people.fsn.hu/~alex/nut/ (TeX, pdf, ps, dvi, ..)
*
*/
/*
* TODO:
* - checksumming
- * - correct rate denom/nom and sample_mul
- * - correct timestamp handling
+ * - optimal timestamp handling
* - index writing
* - info and index packet reading support
* - startcode searching for broken streams
* - subpacket support
- * - handling of codec specific headers
*/
//#define DEBUG 1
{
uint64_t val = 0;
-// for (; bytes_left(s)*8 > 0; )
for(; bytes_left(bc) > 0; )
{
int tmp = get_byte(bc);
len = get_v(bc);
for (i = 0; i < len && i < maxlen; i++)
data[i] = get_byte(bc);
- if (i < len)
- {
- len = i;
- for (i = 0; i < len; i++)
- get_byte(bc);
- }
+ /* skip remaining bytes */
+ url_fskip(bc, len-i);
return 0;
}
static int get_bi(ByteIOContext *bc)
{
- int i, len, val;
+ int i, len, val = 0;
len = get_v(bc);
- if(len > 4) return -1;
-
- val = 0;
- for (i = 0; i < len; i++) {
+ for (i = 0; i < len && i <= 4; i++)
val |= get_byte(bc) << (i * 8);
- }
+ /* skip remaining bytes */
+ url_fskip(bc, len-i);
return val;
}
return 7; //not reached
}
+#ifdef CONFIG_ENCODERS
static int put_v(ByteIOContext *bc, uint64_t val)
{
int i;
ByteIOContext *bc = &s->pb;
AVCodecContext *codec;
int i;
- int stream_length = 0;
-
- for (i = 0; i < s->nb_streams; i++)
- {
- if (stream_length < (s->streams[i]->duration * (AV_TIME_BASE / 1000)))
- stream_length = s->streams[i]->duration * (AV_TIME_BASE / 1000);
- }
/* main header */
put_be64(bc, MAIN_STARTCODE);
put_packetheader(nut, bc, 120);
put_v(bc, 0); /* version */
put_v(bc, s->nb_streams);
- put_v(bc, 0); /* file size */
- put_v(bc, stream_length); /* len in msec */
put_be32(bc, 0); /* FIXME: checksum */
update_packetheader(nut, bc, 0);
/* stream headers */
for (i = 0; i < s->nb_streams; i++)
{
+ int nom, denom;
+
codec = &s->streams[i]->codec;
put_be64(bc, STREAM_STARTCODE);
int tmp = codec_get_wav_tag(codec->codec_id);
put_bi(bc, tmp);
}
+
+ if (codec->codec_type == CODEC_TYPE_VIDEO)
+ {
+ nom = codec->frame_rate;
+ denom = codec->frame_rate_base;
+ }
+ else
+ {
+ nom = codec->sample_rate/8;
+ denom = 8;
+ }
put_v(bc, codec->bit_rate);
put_v(bc, 0); /* no language code */
- put_v(bc, codec->frame_rate_base);
- put_v(bc, codec->frame_rate);
- put_v(bc, 0); /* timestamp_shift */
+ put_v(bc, nom);
+ put_v(bc, denom);
+ put_v(bc, 0); /* msb timestamp_shift */
put_v(bc, 0); /* shuffle type */
put_byte(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */
switch(codec->codec_type)
{
case CODEC_TYPE_AUDIO:
- put_v(bc, codec->sample_rate / (double)(codec->frame_rate_base / codec->frame_rate));
+ put_v(bc, (codec->sample_rate * denom) / nom);
put_v(bc, codec->channels);
put_be32(bc, 0); /* FIXME: checksum */
break;
return 0;
}
+#endif //CONFIG_ENCODERS
static int nut_probe(AVProbeData *p)
{
fprintf(stderr, "bad version (%Ld)\n", tmp);
nb_streams = get_v(bc);
-
- s->file_size = get_v(bc);
- s->duration = get_v(bc) / (AV_TIME_BASE / 1000);
-
get_be32(bc); /* checkusm */
s->bit_rate = 0;
/* stream header */
for (cur_stream = 0; cur_stream < nb_streams; cur_stream++)
{
- int class;
+ int class, nom, denom;
AVStream *st;
tmp = get_be64(bc);
}
s->bit_rate += get_v(bc);
get_b(bc, NULL, 0); /* language code */
- st->codec.frame_rate_base = get_v(bc);
- st->codec.frame_rate = get_v(bc);
+ nom = get_v(bc);
+ denom = get_v(bc);
get_v(bc); /* FIXME: msb timestamp base */
get_v(bc); /* shuffle type */
get_byte(bc); /* flags */
-
- get_v(bc); /* FIXME: codec specific data headers */
+
+ /* codec specific data headers */
+ while(get_v(bc) != 0)
+ url_fskip(bc, get_v(bc));
if (class == 0) /* VIDEO */
{
get_v(bc); /* aspected h */
get_v(bc); /* csp type */
get_be32(bc); /* checksum */
+
+ st->codec.frame_rate = nom;
+ st->codec.frame_rate_base = denom;
}
if (class == 32) /* AUDIO */
{
- st->codec.sample_rate = get_v(bc) * (double)(st->codec.frame_rate_base / st->codec.frame_rate);
+ st->codec.sample_rate = (get_v(bc) * nom) / denom;
st->codec.channels = get_v(bc);
get_be32(bc); /* checksum */
}
.extensions = "nut",
};
+#ifdef CONFIG_ENCODERS
static AVOutputFormat nut_oformat = {
"nut",
"nut format",
nut_write_packet,
nut_write_trailer,
};
+#endif //CONFIG_ENCODERS
int nut_init(void)
{
av_register_input_format(&nut_iformat);
+#ifdef CONFIG_ENCODERS
av_register_output_format(&nut_oformat);
+#endif //CONFIG_ENCODERS
return 0;
}