changeset 4581:c52d40f0a955 libavformat

Share the function to write a raw FLAC header and use it in the Matroska muxer.
author jbr
date Thu, 26 Feb 2009 02:41:53 +0000
parents f9775a0b7fdb
children 082712eaff7e
files Makefile flacenc.c flacenc.h matroskaenc.c
diffstat 4 files changed, 42 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Feb 26 02:33:19 2009 +0000
+++ b/Makefile	Thu Feb 26 02:41:53 2009 +0000
@@ -83,9 +83,9 @@
 OBJS-$(CONFIG_LMLM4_DEMUXER)             += lmlm4.o
 OBJS-$(CONFIG_M4V_DEMUXER)               += raw.o
 OBJS-$(CONFIG_M4V_MUXER)                 += raw.o
-OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER)      += matroskaenc.o matroska.o riff.o isom.o avc.o
+OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER)      += matroskaenc.o matroska.o riff.o isom.o avc.o flacenc.o
 OBJS-$(CONFIG_MATROSKA_DEMUXER)          += matroskadec.o matroska.o riff.o isom.o
-OBJS-$(CONFIG_MATROSKA_MUXER)            += matroskaenc.o matroska.o riff.o isom.o avc.o
+OBJS-$(CONFIG_MATROSKA_MUXER)            += matroskaenc.o matroska.o riff.o isom.o avc.o flacenc.o
 OBJS-$(CONFIG_MJPEG_DEMUXER)             += raw.o
 OBJS-$(CONFIG_MJPEG_MUXER)               += raw.o
 OBJS-$(CONFIG_MLP_DEMUXER)               += raw.o id3v2.o
--- a/flacenc.c	Thu Feb 26 02:33:19 2009 +0000
+++ b/flacenc.c	Thu Feb 26 02:41:53 2009 +0000
@@ -21,13 +21,13 @@
 
 #include "libavcodec/flac.h"
 #include "avformat.h"
+#include "flacenc.h"
 
-static int flac_write_header(struct AVFormatContext *s)
+int ff_flac_write_header(ByteIOContext *pb, AVCodecContext *codec)
 {
     static const uint8_t header[8] = {
         0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
     };
-    AVCodecContext *codec = s->streams[0]->codec;
     uint8_t *streaminfo;
     enum FLACExtradataFormat format;
 
@@ -36,15 +36,20 @@
 
     /* write "fLaC" stream marker and first metadata block header if needed */
     if (format == FLAC_EXTRADATA_FORMAT_STREAMINFO) {
-        put_buffer(s->pb, header, 8);
+        put_buffer(pb, header, 8);
     }
 
     /* write STREAMINFO or full header */
-    put_buffer(s->pb, codec->extradata, codec->extradata_size);
+    put_buffer(pb, codec->extradata, codec->extradata_size);
 
     return 0;
 }
 
+static int flac_write_header(struct AVFormatContext *s)
+{
+    return ff_flac_write_header(s->pb, s->streams[0]->codec);
+}
+
 static int flac_write_trailer(struct AVFormatContext *s)
 {
     ByteIOContext *pb = s->pb;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flacenc.h	Thu Feb 26 02:41:53 2009 +0000
@@ -0,0 +1,29 @@
+/*
+ * raw FLAC muxer
+ * Copyright (C) 2009 Justin Ruggles
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_FLACENC_H
+#define AVFORMAT_FLACENC_H
+
+#include "avformat.h"
+
+int ff_flac_write_header(ByteIOContext *pb, AVCodecContext *codec);
+
+#endif /* AVFORMAT_FLACENC_H */
--- a/matroskaenc.c	Thu Feb 26 02:33:19 2009 +0000
+++ b/matroskaenc.c	Thu Feb 26 02:41:53 2009 +0000
@@ -24,11 +24,11 @@
 #include "isom.h"
 #include "matroska.h"
 #include "avc.h"
+#include "flacenc.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/md5.h"
 #include "libavcodec/xiph.h"
 #include "libavcodec/mpeg4audio.h"
-#include "libavcodec/flac.h"
 
 typedef struct ebml_master {
     int64_t         pos;                ///< absolute offset in the file where the master's elements start
@@ -421,25 +421,6 @@
     return 0;
 }
 
-static int put_flac_codecpriv(AVFormatContext *s, ByteIOContext *pb, AVCodecContext *codec)
-{
-    uint8_t *streaminfo;
-    enum FLACExtradataFormat format;
-
-    if (!ff_flac_is_extradata_valid(codec, &format, &streaminfo)) {
-        av_log(s, AV_LOG_ERROR, "Invalid FLAC extradata\n");
-        return -1;
-    }
-    if (format == FLAC_EXTRADATA_FORMAT_STREAMINFO) {
-        // only the streaminfo packet
-        put_buffer(pb, "fLaC", 4);
-        put_byte(pb, 0x80);
-        put_be24(pb, FLAC_STREAMINFO_SIZE);
-    }
-    put_buffer(pb, codec->extradata, codec->extradata_size);
-    return 0;
-}
-
 static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, int *sample_rate, int *output_sample_rate)
 {
     int sri;
@@ -481,7 +462,7 @@
         if (codec->codec_id == CODEC_ID_VORBIS || codec->codec_id == CODEC_ID_THEORA)
             ret = put_xiph_codecpriv(s, dyn_cp, codec);
         else if (codec->codec_id == CODEC_ID_FLAC)
-            ret = put_flac_codecpriv(s, dyn_cp, codec);
+            ret = ff_flac_write_header(dyn_cp, codec);
         else if (codec->codec_id == CODEC_ID_H264)
             ret = ff_isom_write_avcc(dyn_cp, codec->extradata, codec->extradata_size);
         else if (codec->extradata_size)