On 02.03.2015 16:21, Luca Barbato wrote:
On 02/03/15 16:06, Andreas Cadhalpun wrote:
Yes, the rm format can contain larger frames split into slices and
packed in multiple packets. But currently the rv10/rv20 encoders always
produce a whole frame and the rm muxer always produces one packet per
frame.

Then there is the missing_feature logger call and AVERROR(ENOSYS).

OK.

You could make the constant self-explanatory by doing something like

#define MAX_HEADER_SIZE (7 + 4 + 12)
#define MAX_PACKET_SIZE (UINT16_MAX - MAX_HEADER_SIZE)

Fine with me. New patch attached.

Best regards,
Andreas

>From 17536f5ca03a6fdda8486495bfd3bfd4f5258e70 Mon Sep 17 00:00:00 2001
From: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
Date: Mon, 2 Mar 2015 16:52:26 +0100
Subject: [PATCH] avformat/rm: limit packet size

The chunk size is limited to UINT16_MAX (written by avio_wb16), so make
sure that the packet size is not too large.

Such large frames need to be split into slices smaller than 64 kB, but
that is currently supported neither by the rv10/rv20 encoders nor the rm
muxer.

Signed-off-by: Andreas Cadhalpun <andreas.cadhal...@googlemail.com>
---
 libavformat/rmenc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavformat/rmenc.c b/libavformat/rmenc.c
index 838388f..8e91dc0 100644
--- a/libavformat/rmenc.c
+++ b/libavformat/rmenc.c
@@ -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)
@@ -396,6 +400,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);
-- 
2.1.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to