changeset 228:542e6d639bb9 libavformat

fixed endianness dependancies (untested)
author bellard
date Mon, 08 Sep 2003 20:00:13 +0000
parents b0d2d719ae41
children b0771ae979e3
files nut.c
diffstat 1 files changed, 23 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/nut.c	Mon Sep 08 04:17:40 2003 +0000
+++ b/nut.c	Mon Sep 08 20:00:13 2003 +0000
@@ -38,6 +38,7 @@
 
 #include "avformat.h"
 #include "mpegaudio.h"
+#include "avi.h"
 
 //from /dev/random
 
@@ -85,21 +86,17 @@
         return (v>>1);
 }
 
-static int get_b(ByteIOContext *bc, char *data, int maxlen)
+static int get_b(ByteIOContext *bc)
 {
-    int i, len;
+    int i, len, val;
     
     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);
+    val = 0;
+    for (i = 0; i < len; i++) {
+        if (i < 4)
+            val |= get_byte(bc) << (i * 8);
     }
-
-    return 0;
+    return val;
 }
 
 static int get_packetheader(NUTContext *nut, ByteIOContext *bc)
@@ -167,6 +164,13 @@
     return 0;
 }
 
+static int put_bi(ByteIOContext *bc, int val)
+{
+    put_v(bc, 4);
+    put_le32(bc, val);
+    return 0;
+}
+
 static int put_packetheader(NUTContext *nut, ByteIOContext *bc, int max_size)
 {
     put_flush_packet(bc);
@@ -238,20 +242,16 @@
 	put_v(bc, i /*s->streams[i]->index*/);
 	put_v(bc, (codec->codec_type == CODEC_TYPE_AUDIO) ? 32 : 0);
 	if (codec->codec_tag)
-	    put_b(bc, &codec->codec_tag, 4);
+	    put_bi(bc, codec->codec_tag);
 	else if (codec->codec_type == CODEC_TYPE_VIDEO)
 	{
 	    int tmp = codec_get_bmp_tag(codec->codec_id);
-	    put_b(bc, &tmp, 4);
-//	    put_v(bc, 4); /* len */
-//	    put_be32(bc, codec_get_bmp_tag(codec->codec_id));
+	    put_bi(bc, tmp);
 	}
 	else if (codec->codec_type == CODEC_TYPE_AUDIO)
 	{
 	    int tmp = codec_get_wav_tag(codec->codec_id);
-	    put_b(bc, &tmp, 4);
-//	    put_v(bc, 4); /* len */
-//	    put_be32(bc, codec_get_wav_tag(codec->codec_id));
+	    put_bi(bc, tmp);
 	}
 	put_v(bc, codec->bit_rate);
 	put_v(bc, 0); /* no language code */
@@ -278,6 +278,8 @@
 		put_v(bc, 0); /* csp type -- unknown */
 		put_be32(bc, 0); /* FIXME: checksum */
 		break;
+            default:
+                break;
 	}
         update_packetheader(nut, bc, 0);
     }
@@ -328,7 +330,7 @@
     NUTContext *nut = s->priv_data;
     ByteIOContext *bc = &s->pb;
     int key_frame = 0;
-    int flags, size2;
+    int flags;
     AVCodecContext *enc;
 
     if (stream_index > s->nb_streams)
@@ -364,7 +366,6 @@
 
 static int nut_write_trailer(AVFormatContext *s)
 {
-    NUTContext *nut = s->priv_data;
     ByteIOContext *bc = &s->pb;
 #if 0
     int i;
@@ -447,18 +448,14 @@
 	{
 	    case 0:
 		st->codec.codec_type = CODEC_TYPE_VIDEO;
-//		get_v(bc);
-//		tmp = get_be32(bc);
-		get_b(bc, (char*)&tmp, 4);
+		tmp = get_b(bc);
 		st->codec.codec_id = codec_get_bmp_id(tmp);
 		if (st->codec.codec_id == CODEC_ID_NONE)
 		    fprintf(stderr, "Unknown codec?!\n");
 		break;
 	    case 32:
 		st->codec.codec_type = CODEC_TYPE_AUDIO;
-//		tmp = get_v(bc);
-//		tmp = get_be32(bc);
-		get_b(bc, (char*)&tmp, 4);
+		tmp = get_b(bc);
 		st->codec.codec_id = codec_get_wav_id(tmp);
 		if (st->codec.codec_id == CODEC_ID_NONE)
 		    fprintf(stderr, "Unknown codec?!\n");