changeset 223:848b612d0595 libavformat

move packetheader after startcodes
author al3x
date Sun, 07 Sep 2003 00:37:46 +0000
parents 1da43d2bdcae
children 8d1569be0ee1
files nut.c
diffstat 1 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/nut.c	Sat Sep 06 23:17:17 2003 +0000
+++ b/nut.c	Sun Sep 07 00:37:46 2003 +0000
@@ -217,10 +217,9 @@
 	    stream_length = s->streams[i]->duration * (AV_TIME_BASE / 1000);
     }
 
-    put_packetheader(nut, bc, 120);
-    
     /* 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 */
@@ -234,8 +233,8 @@
     {
 	codec = &s->streams[i]->codec;
 	
+	put_be64(bc, STREAM_STARTCODE);
 	put_packetheader(nut, bc, 120);
-	put_be64(bc, STREAM_STARTCODE);
 	put_v(bc, i /*s->streams[i]->index*/);
 	put_v(bc, (codec->codec_type == CODEC_TYPE_AUDIO) ? 32 : 0);
 	if (codec->codec_tag)
@@ -285,9 +284,9 @@
 
 #if 0
     /* info header */
+    put_be64(bc, INFO_STARTCODE);
     put_packetheader(nut, bc, 16+strlen(s->author)+strlen(s->title)+
         strlen(s->comment)+strlen(s->copyright)); 
-    put_be64(bc, INFO_STARTCODE);
     if (s->author[0])
     {
         put_v(bc, 5); /* type */
@@ -339,8 +338,6 @@
     if (enc->codec_type == CODEC_TYPE_VIDEO)
 	key_frame = enc->coded_frame->key_frame;
 
-    put_packetheader(nut, bc, size+(key_frame?8:0)+20);
-
     if (key_frame)
 	put_be64(bc, KEYFRAME_STARTCODE);
     
@@ -352,6 +349,8 @@
     flags<<=1; flags|=0; //reserved
 
     put_byte(bc, flags);
+
+    put_packetheader(nut, bc, size+20);
     put_v(bc, stream_index);
     put_s(bc, force_pts); /* lsb_timestamp */
     update_packetheader(nut, bc, size);
@@ -374,8 +373,8 @@
 
     for (i = 0; s->nb_streams; i++)
     {
+	put_be64(bc, INDEX_STARTCODE);
 	put_packetheader(nut, bc, 64);
-	put_be64(bc, INDEX_STARTCODE);
 	put_v(bc, s->streams[i]->id);
 	put_v(bc, ...);
 	put_be32(bc, 0); /* FIXME: checksum */
@@ -412,10 +411,10 @@
     int cur_stream, nb_streams;
     
     /* main header */
-    get_packetheader(nut, bc);
     tmp = get_be64(bc);
     if (tmp != MAIN_STARTCODE)
 	fprintf(stderr, "damaged? startcode!=1 (%Ld)\n", tmp);
+    get_packetheader(nut, bc);
     
     tmp = get_v(bc);
     if (tmp != 0)
@@ -436,10 +435,10 @@
 	int class;
 	AVStream *st;
 	
-	get_packetheader(nut, bc);
 	tmp = get_be64(bc);
 	if (tmp != STREAM_STARTCODE)
 	    fprintf(stderr, "damaged? startcode!=1 (%Ld)\n", tmp);
+	get_packetheader(nut, bc);
 	st = av_new_stream(s, get_v(bc));
 	if (!st)
 	    return AVERROR_NOMEM;
@@ -508,7 +507,6 @@
     int key_frame = 0;
     uint64_t tmp;
 
-    get_packetheader(nut, bc);
 
     if (url_feof(bc))
 	return -1;
@@ -527,6 +525,7 @@
 	else
 	    fprintf(stderr, "error in zero bit / startcode %LX\n", tmp);
     }
+    get_packetheader(nut, bc);
 #if 0
     if (((tmp & 0x60)>>5) > 3) /* priority <= 3 */
 	fprintf(stderr, "sanity check failed!\n");
@@ -573,7 +572,7 @@
 #elif defined(CONFIG_MP3LAME)
     CODEC_ID_MP3LAME,
 #else
-    CODEC_ID_AC3,
+    CODEC_ID_MP2, /* AC3 needs liba52 decoder */
 #endif
     CODEC_ID_MPEG4,
     nut_write_header,