changeset 4610:41542d2edcf4 libavformat

Separate the raw FLAC demuxer from raw.c and put in a new file, flacdec.c.
author jbr
date Sat, 28 Feb 2009 17:24:46 +0000
parents 065557d6fffb
children 11cce150a895
files Makefile flacdec.c raw.c raw.h
diffstat 4 files changed, 93 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sat Feb 28 16:02:29 2009 +0000
+++ b/Makefile	Sat Feb 28 17:24:46 2009 +0000
@@ -53,7 +53,7 @@
 OBJS-$(CONFIG_EAC3_MUXER)                += raw.o
 OBJS-$(CONFIG_FFM_DEMUXER)               += ffmdec.o
 OBJS-$(CONFIG_FFM_MUXER)                 += ffmenc.o
-OBJS-$(CONFIG_FLAC_DEMUXER)              += raw.o id3v2.o
+OBJS-$(CONFIG_FLAC_DEMUXER)              += flacdec.o raw.o id3v2.o
 OBJS-$(CONFIG_FLAC_MUXER)                += flacenc.o
 OBJS-$(CONFIG_FLIC_DEMUXER)              += flic.o
 OBJS-$(CONFIG_FLV_DEMUXER)               += flvdec.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flacdec.c	Sat Feb 28 17:24:46 2009 +0000
@@ -0,0 +1,72 @@
+/*
+ * Raw FLAC demuxer
+ * Copyright (c) 2001 Fabrice Bellard
+ *
+ * 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
+ */
+
+#include "avformat.h"
+#include "raw.h"
+#include "id3v2.h"
+
+static int flac_read_header(AVFormatContext *s,
+                             AVFormatParameters *ap)
+{
+    uint8_t buf[ID3v2_HEADER_SIZE];
+    int ret;
+    AVStream *st = av_new_stream(s, 0);
+    if (!st)
+        return AVERROR(ENOMEM);
+    st->codec->codec_type = CODEC_TYPE_AUDIO;
+    st->codec->codec_id = CODEC_ID_FLAC;
+    st->need_parsing = AVSTREAM_PARSE_FULL;
+    /* the parameters will be extracted from the compressed bitstream */
+
+        /* skip ID3v2 header if found */
+        ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
+        if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf)) {
+            int len = ff_id3v2_tag_len(buf);
+            url_fseek(s->pb, len - ID3v2_HEADER_SIZE, SEEK_CUR);
+        } else {
+            url_fseek(s->pb, 0, SEEK_SET);
+        }
+    return 0;
+}
+
+static int flac_probe(AVProbeData *p)
+{
+    uint8_t *bufptr = p->buf;
+    uint8_t *end    = p->buf + p->buf_size;
+
+    if(ff_id3v2_match(bufptr))
+        bufptr += ff_id3v2_tag_len(bufptr);
+
+    if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
+    else                                            return AVPROBE_SCORE_MAX/2;
+}
+
+AVInputFormat flac_demuxer = {
+    "flac",
+    NULL_IF_CONFIG_SMALL("raw FLAC"),
+    0,
+    flac_probe,
+    flac_read_header,
+    ff_raw_read_partial_packet,
+    .flags= AVFMT_GENERIC_INDEX,
+    .extensions = "flac",
+    .value = CODEC_ID_FLAC,
+};
--- a/raw.c	Sat Feb 28 16:02:29 2009 +0000
+++ b/raw.c	Sat Feb 28 17:24:46 2009 +0000
@@ -130,7 +130,7 @@
     return ret;
 }
 
-static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
+int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int ret, size;
 
@@ -258,17 +258,6 @@
     st->need_parsing = AVSTREAM_PARSE_FULL;
     /* the parameters will be extracted from the compressed bitstream */
 
-    if(st->codec->codec_id == CODEC_ID_FLAC) {
-        /* skip ID3v2 header if found */
-        uint8_t buf[ID3v2_HEADER_SIZE];
-        int ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
-        if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf)) {
-            int len = ff_id3v2_tag_len(buf);
-            url_fseek(s->pb, len - ID3v2_HEADER_SIZE, SEEK_CUR);
-        } else {
-            url_fseek(s->pb, 0, SEEK_SET);
-        }
-    }
     return 0;
 }
 
@@ -593,20 +582,6 @@
 }
 #endif
 
-#if CONFIG_FLAC_DEMUXER
-static int flac_probe(AVProbeData *p)
-{
-    uint8_t *bufptr = p->buf;
-    uint8_t *end    = p->buf + p->buf_size;
-
-    if(ff_id3v2_match(bufptr))
-        bufptr += ff_id3v2_tag_len(bufptr);
-
-    if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
-    else                                            return AVPROBE_SCORE_MAX/2;
-}
-#endif
-
 #if CONFIG_AAC_DEMUXER
 static int adts_aac_probe(AVProbeData *p)
 {
@@ -655,7 +630,7 @@
     0,
     adts_aac_probe,
     audio_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "aac",
     .value = CODEC_ID_AAC,
@@ -669,7 +644,7 @@
     0,
     ac3_probe,
     audio_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "ac3",
     .value = CODEC_ID_AC3,
@@ -698,7 +673,7 @@
     0,
     dirac_probe,
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .value = CODEC_ID_DIRAC,
 };
@@ -726,7 +701,7 @@
     0,
     dnxhd_probe,
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .value = CODEC_ID_DNXHD,
 };
@@ -754,7 +729,7 @@
     0,
     dts_probe,
     audio_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "dts",
     .value = CODEC_ID_DTS,
@@ -783,7 +758,7 @@
     0,
     eac3_probe,
     audio_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "eac3",
     .value = CODEC_ID_EAC3,
@@ -805,20 +780,6 @@
 };
 #endif
 
-#if CONFIG_FLAC_DEMUXER
-AVInputFormat flac_demuxer = {
-    "flac",
-    NULL_IF_CONFIG_SMALL("raw FLAC"),
-    0,
-    flac_probe,
-    audio_read_header,
-    raw_read_partial_packet,
-    .flags= AVFMT_GENERIC_INDEX,
-    .extensions = "flac",
-    .value = CODEC_ID_FLAC,
-};
-#endif
-
 #if CONFIG_GSM_DEMUXER
 AVInputFormat gsm_demuxer = {
     "gsm",
@@ -826,7 +787,7 @@
     0,
     NULL,
     audio_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "gsm",
     .value = CODEC_ID_GSM,
@@ -840,7 +801,7 @@
     0,
     h261_probe,
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "h261",
     .value = CODEC_ID_H261,
@@ -869,7 +830,7 @@
     0,
     h263_probe,
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
 //    .extensions = "h263", //FIXME remove after writing mpeg4_probe
     .value = CODEC_ID_H263,
@@ -898,7 +859,7 @@
     0,
     h264_probe,
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
     .value = CODEC_ID_H264,
@@ -941,7 +902,7 @@
     0,
     mpeg4video_probe, /** probing for MPEG-4 data */
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "m4v",
     .value = CODEC_ID_MPEG4,
@@ -970,7 +931,7 @@
     0,
     NULL,
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "mjpg,mjpeg",
     .value = CODEC_ID_MJPEG,
@@ -999,7 +960,7 @@
     0,
     NULL,
     audio_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "mlp",
     .value = CODEC_ID_MLP,
@@ -1043,7 +1004,7 @@
     0,
     mpegvideo_probe,
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .value = CODEC_ID_MPEG1VIDEO,
 };
@@ -1056,7 +1017,7 @@
     0,
     cavsvideo_probe,
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .value = CODEC_ID_CAVS,
 };
@@ -1132,7 +1093,7 @@
     0,
     NULL,
     audio_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "shn",
     .value = CODEC_ID_SHORTEN,
@@ -1146,7 +1107,7 @@
     0,
     NULL /* vc1_probe */,
     video_read_header,
-    raw_read_partial_packet,
+    ff_raw_read_partial_packet,
     .extensions = "vc1",
     .value = CODEC_ID_VC1,
 };
--- a/raw.h	Sat Feb 28 16:02:29 2009 +0000
+++ b/raw.h	Sat Feb 28 17:24:46 2009 +0000
@@ -27,4 +27,6 @@
 int pcm_read_seek(AVFormatContext *s,
                   int stream_index, int64_t timestamp, int flags);
 
+int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt);
+
 #endif /* AVFORMAT_RAW_H */