]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/flacdec.c
Silicon Graphics Movie demuxer
[ffmpeg] / libavformat / flacdec.c
index 7174fcf75881385fdca6fc96b50b1e1d34b7a05f..11360a9da131671b9eed45d241f2d84f727e0ad3 100644 (file)
 
 #include "libavcodec/flac.h"
 #include "avformat.h"
+#include "flac_picture.h"
 #include "internal.h"
 #include "rawdec.h"
 #include "oggdec.h"
 #include "vorbiscomment.h"
+#include "replaygain.h"
 #include "libavcodec/bytestream.h"
 
 static int flac_read_header(AVFormatContext *s)
@@ -36,7 +38,7 @@ static int flac_read_header(AVFormatContext *s)
     if (!st)
         return AVERROR(ENOMEM);
     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
-    st->codec->codec_id = CODEC_ID_FLAC;
+    st->codec->codec_id = AV_CODEC_ID_FLAC;
     st->need_parsing = AVSTREAM_PARSE_FULL;
     /* the parameters will be extracted from the compressed bitstream */
 
@@ -55,6 +57,7 @@ static int flac_read_header(AVFormatContext *s)
         /* allocate and read metadata block for supported types */
         case FLAC_METADATA_TYPE_STREAMINFO:
         case FLAC_METADATA_TYPE_CUESHEET:
+        case FLAC_METADATA_TYPE_PICTURE:
         case FLAC_METADATA_TYPE_VORBIS_COMMENT:
             buffer = av_mallocz(metadata_size + FF_INPUT_BUFFER_PADDING_SIZE);
             if (!buffer) {
@@ -121,6 +124,13 @@ static int flac_read_header(AVFormatContext *s)
                 offset += ti * 12;
                 avpriv_new_chapter(s, track, st->time_base, start, AV_NOPTS_VALUE, isrc);
             }
+        } else if (metadata_type == FLAC_METADATA_TYPE_PICTURE) {
+            ret = ff_flac_parse_picture(s, buffer, metadata_size);
+            av_freep(&buffer);
+            if (ret < 0) {
+                av_log(s, AV_LOG_ERROR, "Error parsing attached picture.\n");
+                return ret;
+            }
         } else {
             /* STREAMINFO must be the first block */
             if (!found_streaminfo) {
@@ -137,16 +147,18 @@ static int flac_read_header(AVFormatContext *s)
         }
     }
 
+    ret = ff_replaygain_export(st, s->metadata);
+    if (ret < 0)
+        return ret;
+
     return 0;
 }
 
 static int flac_probe(AVProbeData *p)
 {
-    uint8_t *bufptr = p->buf;
-    uint8_t *end    = p->buf + p->buf_size;
-
-    if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
-    else                                            return AVPROBE_SCORE_MAX/2;
+    if (p->buf_size < 4 || memcmp(p->buf, "fLaC", 4))
+        return 0;
+    return AVPROBE_SCORE_EXTENSION;
 }
 
 AVInputFormat ff_flac_demuxer = {
@@ -155,7 +167,7 @@ AVInputFormat ff_flac_demuxer = {
     .read_probe     = flac_probe,
     .read_header    = flac_read_header,
     .read_packet    = ff_raw_read_partial_packet,
-    .flags= AVFMT_GENERIC_INDEX,
-    .extensions = "flac",
-    .raw_codec_id   = CODEC_ID_FLAC,
+    .flags          = AVFMT_GENERIC_INDEX,
+    .extensions     = "flac",
+    .raw_codec_id   = AV_CODEC_ID_FLAC,
 };