]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Share the function to write a raw FLAC header and use it in the Matroska
authorjbr <jbr@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Thu, 26 Feb 2009 02:41:53 +0000 (02:41 +0000)
committerjbr <jbr@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Thu, 26 Feb 2009 02:41:53 +0000 (02:41 +0000)
muxer.

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@17606 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavformat/Makefile
libavformat/flacenc.c
libavformat/flacenc.h [new file with mode: 0644]
libavformat/matroskaenc.c

index 505a6ba82595ede1b72bb706e18b30dec0de1e21..c6b99e7f43921a849202f81b65ef8710bec22bb6 100644 (file)
@@ -83,9 +83,9 @@ OBJS-$(CONFIG_ISS_DEMUXER)               += iss.o
 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
index b391f8891d6b05421269f4b427f7b93139fed896..81844cc2d297f221798bc08b6a8d409470defb0c 100644 (file)
 
 #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 @@ static int flac_write_header(struct AVFormatContext *s)
 
     /* 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;
diff --git a/libavformat/flacenc.h b/libavformat/flacenc.h
new file mode 100644 (file)
index 0000000..a9b7f62
--- /dev/null
@@ -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 */
index 0b0adef1ba8bceb217cd3a6d690bcd83a2d709d5..051fb1b613f54e3c65b8c165b211502e2d880963 100644 (file)
 #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 @@ static int put_xiph_codecpriv(AVFormatContext *s, ByteIOContext *pb, AVCodecCont
     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 @@ static int mkv_write_codecprivate(AVFormatContext *s, ByteIOContext *pb, AVCodec
         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)