[FFmpeg-devel] [PATCH] auenc: strict check for supported codec

Paul B Mahol onemda at gmail.com
Tue Jan 29 12:07:14 CET 2013


Remove put_au_header() function as such level of abstraction is pointless.
Also check number of streams and give error message why muxing failed.
This prevents muxing unsupported codec with known and supported tag.

Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavformat/au.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/libavformat/au.c b/libavformat/au.c
index b3a793d..c07ba30 100644
--- a/libavformat/au.c
+++ b/libavformat/au.c
@@ -151,11 +151,21 @@ AVInputFormat ff_au_demuxer = {
 
 #include "rawenc.h"
 
-/* AUDIO_FILE header */
-static int put_au_header(AVIOContext *pb, AVCodecContext *enc)
+static int au_write_header(AVFormatContext *s)
 {
-    if (!enc->codec_tag)
+    AVIOContext *pb = s->pb;
+    AVCodecContext *enc = s->streams[0]->codec;
+
+    if (s->nb_streams != 1) {
+        av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
+        return AVERROR(EINVAL);
+    }
+
+    enc->codec_tag = ff_codec_get_tag(codec_au_tags, enc->codec_id);
+    if (!enc->codec_tag) {
+        av_log(s, AV_LOG_ERROR, "unsupported codec\n");
         return AVERROR(EINVAL);
+    }
 
     ffio_wfourcc(pb, ".snd");                   /* magic number */
     avio_wb32(pb, AU_HEADER_SIZE);              /* header size */
@@ -165,17 +175,6 @@ static int put_au_header(AVIOContext *pb, AVCodecContext *enc)
     avio_wb32(pb, enc->channels);
     avio_wb64(pb, 0); /* annotation field */
 
-    return 0;
-}
-
-static int au_write_header(AVFormatContext *s)
-{
-    AVIOContext *pb = s->pb;
-    int ret;
-
-    if ((ret = put_au_header(pb, s->streams[0]->codec)) < 0)
-        return ret;
-
     avio_flush(pb);
 
     return 0;
-- 
1.7.11.4



More information about the ffmpeg-devel mailing list