]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/wc3movie.c
Make write_header() and write_headers() return an error code in case of
[ffmpeg] / libavformat / wc3movie.c
index 42f50d493e3cf9e3e79190edef5bab8596e468c8..d5f0863e71959e492bbadaa7b285c73ae59c8ce7 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 /**
- * @file libavformat/wc3movie.c
+ * @file
  * Wing Commander III Movie file demuxer
  * by Mike Melanson (melanson@pcisys.net)
  * for more information on the WC3 .mve file format, visit:
@@ -76,9 +76,9 @@ typedef struct Wc3DemuxContext {
  * palette lookup table that does gamma correction
  *
  * can be calculated by this formula:
- * for i between 0 and 252 inclusive:
- * wc3_pal_lookup[i] = pow(i / 256.0, 0.8) * 256;
- * values 253, 254 and 255 are all 0xFD
+ * for i between 0 and 251 inclusive:
+ * wc3_pal_lookup[i] = round(pow(i / 256.0, 0.8) * 256);
+ * values 252, 253, 254 and 255 are all 0xFD
  * calculating this at runtime should not cause any
  * rounding issues, the maximum difference between
  * the table values and the calculated doubles is
@@ -140,10 +140,9 @@ static int wc3_read_header(AVFormatContext *s,
     unsigned int fourcc_tag;
     unsigned int size;
     AVStream *st;
-    char buffer[513];
     int ret = 0;
     int current_palette = 0;
-    int bytes_to_read;
+    char *buffer;
     int i;
     unsigned char rotate;
 
@@ -185,14 +184,14 @@ static int wc3_read_header(AVFormatContext *s,
 
         case BNAM_TAG:
             /* load up the name */
-            if ((unsigned)size < 512)
-                bytes_to_read = size;
-            else
-                bytes_to_read = 512;
-            if ((ret = get_buffer(pb, buffer, bytes_to_read)) != bytes_to_read)
+            buffer = av_malloc(size+1);
+            if (!buffer)
+                return AVERROR(ENOMEM);
+            if ((ret = get_buffer(pb, buffer, size)) != size)
                 return AVERROR(EIO);
-            buffer[bytes_to_read] = 0;
-            av_metadata_set(&s->metadata, "title", buffer);
+            buffer[size] = 0;
+            av_metadata_set2(&s->metadata, "title", buffer,
+                                   AV_METADATA_DONT_STRDUP_VAL);
             break;
 
         case SIZE_TAG:
@@ -224,8 +223,8 @@ static int wc3_read_header(AVFormatContext *s,
 
         default:
             av_log(s, AV_LOG_ERROR, "  unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
-                (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24),
-                (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24));
+                (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24),
+                (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24));
             return AVERROR_INVALIDDATA;
             break;
         }
@@ -244,7 +243,7 @@ static int wc3_read_header(AVFormatContext *s,
         return AVERROR(ENOMEM);
     av_set_pts_info(st, 33, 1, WC3_FRAME_FPS);
     wc3->video_stream_index = st->index;
-    st->codec->codec_type = CODEC_TYPE_VIDEO;
+    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
     st->codec->codec_id = CODEC_ID_XAN_WC3;
     st->codec->codec_tag = 0;  /* no fourcc */
     st->codec->width = wc3->width;
@@ -258,7 +257,7 @@ static int wc3_read_header(AVFormatContext *s,
         return AVERROR(ENOMEM);
     av_set_pts_info(st, 33, 1, WC3_FRAME_FPS);
     wc3->audio_stream_index = st->index;
-    st->codec->codec_type = CODEC_TYPE_AUDIO;
+    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codec->codec_id = CODEC_ID_PCM_S16LE;
     st->codec->codec_tag = 1;
     st->codec->channels = WC3_AUDIO_CHANNELS;
@@ -356,8 +355,8 @@ static int wc3_read_packet(AVFormatContext *s,
 
         default:
             av_log (s, AV_LOG_ERROR, "  unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
-                (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24),
-                (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24));
+                (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24),
+                (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24));
             ret = AVERROR_INVALIDDATA;
             packet_read = 1;
             break;