]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rmenc.c
fate/mp3: use the f32le format as output
[ffmpeg] / libavformat / rmenc.c
index 6d8fa434671e1f99a10a3954a9545e275cfdd20a..ad2c17d529c4f443e0f3b945a739fc3aacf21dcc 100644 (file)
@@ -44,6 +44,10 @@ typedef struct RMMuxContext {
 
 /* in ms */
 #define BUFFER_DURATION 0
+/* the header needs at most 7 + 4 + 12 B */
+#define MAX_HEADER_SIZE (7 + 4 + 12)
+/* UINT16_MAX is the maximal chunk size */
+#define MAX_PACKET_SIZE (UINT16_MAX - MAX_HEADER_SIZE)
 
 
 static void put_str(AVIOContext *s, const char *tag)
@@ -351,29 +355,23 @@ static int rm_write_header(AVFormatContext *s)
 
 static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags)
 {
-    uint8_t *buf1;
     RMMuxContext *rm = s->priv_data;
     AVIOContext *pb = s->pb;
     StreamInfo *stream = rm->audio_stream;
     int i;
 
-    /* XXX: suppress this malloc */
-    buf1 = av_malloc(size * sizeof(uint8_t));
-
     write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY));
 
     if (stream->enc->codec_id == AV_CODEC_ID_AC3) {
         /* for AC-3, the words seem to be reversed */
-        for(i=0;i<size;i+=2) {
-            buf1[i] = buf[i+1];
-            buf1[i+1] = buf[i];
+        for (i = 0; i < size; i += 2) {
+            avio_w8(pb, buf[i + 1]);
+            avio_w8(pb, buf[i]);
         }
-        avio_write(pb, buf1, size);
     } else {
         avio_write(pb, buf, size);
     }
     stream->nb_frames++;
-    av_free(buf1);
     return 0;
 }
 
@@ -389,6 +387,10 @@ static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int
     /* Well, I spent some time finding the meaning of these bits. I am
        not sure I understood everything, but it works !! */
 #if 1
+    if (size > MAX_PACKET_SIZE) {
+        avpriv_report_missing_feature(s, "Muxing packets larger than 64 kB");
+        return AVERROR(ENOSYS);
+    }
     write_packet_header(s, stream, size + 7 + (size >= 0x4000)*4, key_frame);
     /* bit 7: '1' if final packet of a frame converted in several packets */
     avio_w8(pb, 0x81);