]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/ipmovie.c
Split ac3 byte swapping into a separate function.
[ffmpeg] / libavformat / ipmovie.c
index 3c0459938073cd8ded6097d44fd5de4d6a4f9a0b..bf403d7c736519502ac2739e1509b4bc28c07823 100644 (file)
@@ -227,7 +227,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
 
     /* see if there are any pending packets */
     chunk_type = load_ipmovie_packet(s, pb, pkt);
-    if ((chunk_type == CHUNK_VIDEO) && (chunk_type != CHUNK_DONE))
+    if (chunk_type != CHUNK_DONE)
         return chunk_type;
 
     /* read the next chunk, wherever the file happens to be pointing */
@@ -236,8 +236,8 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
     if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
         CHUNK_PREAMBLE_SIZE)
         return CHUNK_BAD;
-    chunk_size = LE_16(&chunk_preamble[0]);
-    chunk_type = LE_16(&chunk_preamble[2]);
+    chunk_size = AV_RL16(&chunk_preamble[0]);
+    chunk_type = AV_RL16(&chunk_preamble[2]);
 
     debug_ipmovie("chunk type 0x%04X, 0x%04X bytes: ", chunk_type, chunk_size);
 
@@ -287,7 +287,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
             break;
         }
 
-        opcode_size = LE_16(&opcode_preamble[0]);
+        opcode_size = AV_RL16(&opcode_preamble[0]);
         opcode_type = opcode_preamble[2];
         opcode_version = opcode_preamble[3];
 
@@ -325,10 +325,10 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
                 chunk_type = CHUNK_BAD;
                 break;
             }
-            s->fps = 1000000.0 / (LE_32(&scratch[0]) * LE_16(&scratch[4]));
+            s->fps = 1000000.0 / (AV_RL32(&scratch[0]) * AV_RL16(&scratch[4]));
             s->frame_pts_inc = 90000 / s->fps;
             debug_ipmovie("  %.2f frames/second (timer div = %d, subdiv = %d)\n",
-                s->fps, LE_32(&scratch[0]), LE_16(&scratch[4]));
+                s->fps, AV_RL32(&scratch[0]), AV_RL16(&scratch[4]));
             break;
 
         case OPCODE_INIT_AUDIO_BUFFERS:
@@ -343,8 +343,8 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
                 chunk_type = CHUNK_BAD;
                 break;
             }
-            s->audio_sample_rate = LE_16(&scratch[4]);
-            audio_flags = LE_16(&scratch[2]);
+            s->audio_sample_rate = AV_RL16(&scratch[4]);
+            audio_flags = AV_RL16(&scratch[2]);
             /* bit 0 of the flags: 0 = mono, 1 = stereo */
             s->audio_channels = (audio_flags & 1) + 1;
             /* bit 1 of the flags: 0 = 8 bit, 1 = 16 bit */
@@ -381,8 +381,8 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
                 chunk_type = CHUNK_BAD;
                 break;
             }
-            s->video_width = LE_16(&scratch[0]) * 8;
-            s->video_height = LE_16(&scratch[2]) * 8;
+            s->video_width = AV_RL16(&scratch[0]) * 8;
+            s->video_height = AV_RL16(&scratch[2]) * 8;
             debug_ipmovie("video resolution: %d x %d\n",
                 s->video_width, s->video_height);
             break;
@@ -442,8 +442,8 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
             }
 
             /* load the palette into internal data structure */
-            first_color = LE_16(&scratch[0]);
-            last_color = first_color + LE_16(&scratch[2]) - 1;
+            first_color = AV_RL16(&scratch[0]);
+            last_color = first_color + AV_RL16(&scratch[2]) - 1;
             /* sanity check (since they are 16 bit values) */
             if ((first_color > 0xFF) || (last_color > 0xFF)) {
                 debug_ipmovie("demux_ipmovie: set_palette indices out of range (%d -> %d)\n",
@@ -507,8 +507,6 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
 
 static int ipmovie_probe(AVProbeData *p)
 {
-    if (p->buf_size < IPMOVIE_SIGNATURE_SIZE)
-        return 0;
     if (strncmp(p->buf, IPMOVIE_SIGNATURE, IPMOVIE_SIGNATURE_SIZE) != 0)
         return 0;
 
@@ -518,7 +516,7 @@ static int ipmovie_probe(AVProbeData *p)
 static int ipmovie_read_header(AVFormatContext *s,
                                AVFormatParameters *ap)
 {
-    IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
+    IPMVEContext *ipmovie = s->priv_data;
     ByteIOContext *pb = &s->pb;
     AVPacket pkt;
     AVStream *st;
@@ -541,8 +539,8 @@ static int ipmovie_read_header(AVFormatContext *s,
      * it; if it is the first video chunk, this is a silent file */
     if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
         CHUNK_PREAMBLE_SIZE)
-        return AVERROR_IO;
-    chunk_type = LE_16(&chunk_preamble[2]);
+        return AVERROR(EIO);
+    chunk_type = AV_RL16(&chunk_preamble[2]);
     url_fseek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR);
 
     if (chunk_type == CHUNK_VIDEO)
@@ -553,7 +551,7 @@ static int ipmovie_read_header(AVFormatContext *s,
     /* initialize the stream decoders */
     st = av_new_stream(s, 0);
     if (!st)
-        return AVERROR_NOMEM;
+        return AVERROR(ENOMEM);
     av_set_pts_info(st, 33, 1, 90000);
     ipmovie->video_stream_index = st->index;
     st->codec->codec_type = CODEC_TYPE_VIDEO;
@@ -568,7 +566,7 @@ static int ipmovie_read_header(AVFormatContext *s,
     if (ipmovie->audio_type) {
         st = av_new_stream(s, 0);
         if (!st)
-            return AVERROR_NOMEM;
+            return AVERROR(ENOMEM);
         av_set_pts_info(st, 33, 1, 90000);
         ipmovie->audio_stream_index = st->index;
         st->codec->codec_type = CODEC_TYPE_AUDIO;
@@ -590,7 +588,7 @@ static int ipmovie_read_header(AVFormatContext *s,
 static int ipmovie_read_packet(AVFormatContext *s,
                                AVPacket *pkt)
 {
-    IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
+    IPMVEContext *ipmovie = s->priv_data;
     ByteIOContext *pb = &s->pb;
     int ret;
 
@@ -598,18 +596,20 @@ static int ipmovie_read_packet(AVFormatContext *s,
     if (ret == CHUNK_BAD)
         ret = AVERROR_INVALIDDATA;
     else if (ret == CHUNK_EOF)
-        ret = AVERROR_IO;
+        ret = AVERROR(EIO);
     else if (ret == CHUNK_NOMEM)
-        ret = AVERROR_NOMEM;
-    else
+        ret = AVERROR(ENOMEM);
+    else if (ret == CHUNK_VIDEO)
         ret = 0;
+    else
+        ret = -1;
 
     return ret;
 }
 
 static int ipmovie_read_close(AVFormatContext *s)
 {
-//    IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
+//    IPMVEContext *ipmovie = s->priv_data;
 
     return 0;
 }