Re: [FFmpeg-devel] [PATCH 2/2] Add experimental demuxing support for FLAC in ISO BMFF (MP4).

2016-11-21 Thread James Almer
On 11/1/2016 8:23 PM, Matthew Gregan wrote:
> At 2016-11-01T18:07:07-0300, James Almer wrote:
>> > Just include libavcodec/flac.h which already defines it.
>> > 
>> > With the above header you'll also be able to use the inline function
>> > flac_parse_block_header() for this. See flac and matroska demuxers.
>> > 
>> > INVALIDDATA errors would ideally also throw an error message.
>> > 
>> > Use ff_get_extradata(), which combines these two into a single function.
> Thanks for the feedback.  Updated patch attached with these addressed.
> 
> 
> 0002-Add-experimental-demuxing-support-for-FLAC-in-ISO-BM.patch
> 
> 
> From 7f08d03c7c73105098e3c398f10e5127b17eb368 Mon Sep 17 00:00:00 2001
> From: Matthew Gregan 
> Date: Fri, 21 Oct 2016 16:10:43 +1300
> Subject: [PATCH 2/2] Add experimental demuxing support for FLAC in ISO BMFF
>  (MP4).
> 
> Based on the draft spec at 
> https://git.xiph.org/?p=flac.git;a=blob;f=doc/isoflac.txt
> 
> Signed-off-by: Matthew Gregan 
> ---
>  libavformat/mov.c | 39 +++
>  1 file changed, 39 insertions(+)

Pushed, thanks!

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] Add experimental demuxing support for FLAC in ISO BMFF (MP4).

2016-11-01 Thread Matthew Gregan
At 2016-11-01T18:07:07-0300, James Almer wrote:
> Just include libavcodec/flac.h which already defines it.
> 
> With the above header you'll also be able to use the inline function
> flac_parse_block_header() for this. See flac and matroska demuxers.
> 
> INVALIDDATA errors would ideally also throw an error message.
> 
> Use ff_get_extradata(), which combines these two into a single function.

Thanks for the feedback.  Updated patch attached with these addressed.
>From 7f08d03c7c73105098e3c398f10e5127b17eb368 Mon Sep 17 00:00:00 2001
From: Matthew Gregan 
Date: Fri, 21 Oct 2016 16:10:43 +1300
Subject: [PATCH 2/2] Add experimental demuxing support for FLAC in ISO BMFF
 (MP4).

Based on the draft spec at https://git.xiph.org/?p=flac.git;a=blob;f=doc/isoflac.txt

Signed-off-by: Matthew Gregan 
---
 libavformat/mov.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 4222088..6f00f12 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -44,6 +44,7 @@
 #include "libavutil/sha.h"
 #include "libavutil/timecode.h"
 #include "libavcodec/ac3tab.h"
+#include "libavcodec/flac.h"
 #include "libavcodec/mpegaudiodecheader.h"
 #include "avformat.h"
 #include "internal.h"
@@ -4684,6 +4685,43 @@ static int mov_read_saiz(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 return 0;
 }
 
+static int mov_read_dfla(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+AVStream *st;
+int last, type, size, ret;
+uint8_t buf[4];
+
+if (c->fc->nb_streams < 1)
+return 0;
+st = c->fc->streams[c->fc->nb_streams-1];
+
+if ((uint64_t)atom.size > (1<<30) || atom.size < 42)
+return AVERROR_INVALIDDATA;
+
+/* Check FlacSpecificBox version. */
+if (avio_r8(pb) != 0)
+return AVERROR_INVALIDDATA;
+
+avio_rb24(pb); /* Flags */
+
+avio_read(pb, buf, sizeof(buf));
+flac_parse_block_header(buf, , , );
+
+if (type != FLAC_METADATA_TYPE_STREAMINFO || size != FLAC_STREAMINFO_SIZE) {
+av_log(c->fc, AV_LOG_ERROR, "STREAMINFO must be first FLACMetadataBlock\n");
+return AVERROR_INVALIDDATA;
+}
+
+ret = ff_get_extradata(c->fc, st->codecpar, pb, size);
+if (ret < 0)
+return ret;
+
+if (!last)
+av_log(c->fc, AV_LOG_WARNING, "non-STREAMINFO FLACMetadataBlock(s) ignored\n");
+
+return 0;
+}
+
 static int cenc_filter(MOVContext *c, MOVStreamContext *sc, uint8_t *input, int size)
 {
 uint32_t encrypted_bytes;
@@ -4858,6 +4896,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('f','r','m','a'), mov_read_frma },
 { MKTAG('s','e','n','c'), mov_read_senc },
 { MKTAG('s','a','i','z'), mov_read_saiz },
+{ MKTAG('d','f','L','a'), mov_read_dfla },
 { 0, NULL }
 };
 
-- 
2.10.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] Add experimental demuxing support for FLAC in ISO BMFF (MP4).

2016-11-01 Thread James Almer
On 10/31/2016 3:27 AM, Matthew Gregan wrote:
> Based on the draft spec at 
> https://git.xiph.org/?p=flac.git;a=blob;f=doc/isoflac.txt
> 
> Signed-off-by: Matthew Gregan 
> ---
>  libavformat/mov.c | 41 +
>  1 file changed, 41 insertions(+)
> 
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 357d800..fc36b0e 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -4684,6 +4684,46 @@ static int mov_read_saiz(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  return 0;
>  }
>  
> +static int mov_read_dfla(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> +{
> +const size_t FLAC_STREAMINFO_SIZE = 34;

Just include libavcodec/flac.h which already defines it.

> +AVStream *st;
> +uint8_t type;
> +size_t size;
> +
> +if (c->fc->nb_streams < 1)
> +return 0;
> +st = c->fc->streams[c->fc->nb_streams-1];
> +
> +if ((uint64_t)atom.size > (1<<30) || atom.size < 42)
> +return AVERROR_INVALIDDATA;
> +
> +/* Check FlacSpecificBox version. */
> +if (avio_r8(pb) != 0)
> +return AVERROR_INVALIDDATA;
> +
> +avio_rb24(pb); /* Flags */
> +
> +type = avio_r8(pb);
> +/* TODO: Read other METADATA_BLOCK_TYPEs if the decoder wants them. */
> +if (!(type & 0x80)) {
> +  av_log(c->fc, AV_LOG_WARNING, "ignoring non-STREAMINFO 
> FLACMetadataBlocks\n");
> +}
> +type = type & 0x7f;
> +size = avio_rb24(pb);

With the above header you'll also be able to use the inline function
flac_parse_block_header() for this. See flac and matroska demuxers.

> +
> +/* The first METADATA_BLOCK_TYPE must be STREAMINFO. */
> +if (type != 0 || size != FLAC_STREAMINFO_SIZE)
> +return AVERROR_INVALIDDATA;

INVALIDDATA errors would ideally also throw an error message.

> +
> +if (ff_alloc_extradata(st->codecpar, size))
> +return AVERROR(ENOMEM);
> +
> +avio_read(pb, st->codecpar->extradata, size);

Use ff_get_extradata(), which combines these two into a single function.

> +
> +return 0;
> +}
> +
>  static int cenc_filter(MOVContext *c, MOVStreamContext *sc, uint8_t *input, 
> int size)
>  {
>  uint32_t encrypted_bytes;
> @@ -4858,6 +4898,7 @@ static const MOVParseTableEntry 
> mov_default_parse_table[] = {
>  { MKTAG('f','r','m','a'), mov_read_frma },
>  { MKTAG('s','e','n','c'), mov_read_senc },
>  { MKTAG('s','a','i','z'), mov_read_saiz },
> +{ MKTAG('d','f','L','a'), mov_read_dfla },
>  { 0, NULL }
>  };
>  
> 

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] Add experimental demuxing support for FLAC in ISO BMFF (MP4).

2016-10-31 Thread Matthew Gregan
Based on the draft spec at 
https://git.xiph.org/?p=flac.git;a=blob;f=doc/isoflac.txt

Signed-off-by: Matthew Gregan 
---
 libavformat/mov.c | 41 +
 1 file changed, 41 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 357d800..fc36b0e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4684,6 +4684,46 @@ static int mov_read_saiz(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
+static int mov_read_dfla(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+const size_t FLAC_STREAMINFO_SIZE = 34;
+AVStream *st;
+uint8_t type;
+size_t size;
+
+if (c->fc->nb_streams < 1)
+return 0;
+st = c->fc->streams[c->fc->nb_streams-1];
+
+if ((uint64_t)atom.size > (1<<30) || atom.size < 42)
+return AVERROR_INVALIDDATA;
+
+/* Check FlacSpecificBox version. */
+if (avio_r8(pb) != 0)
+return AVERROR_INVALIDDATA;
+
+avio_rb24(pb); /* Flags */
+
+type = avio_r8(pb);
+/* TODO: Read other METADATA_BLOCK_TYPEs if the decoder wants them. */
+if (!(type & 0x80)) {
+  av_log(c->fc, AV_LOG_WARNING, "ignoring non-STREAMINFO 
FLACMetadataBlocks\n");
+}
+type = type & 0x7f;
+size = avio_rb24(pb);
+
+/* The first METADATA_BLOCK_TYPE must be STREAMINFO. */
+if (type != 0 || size != FLAC_STREAMINFO_SIZE)
+return AVERROR_INVALIDDATA;
+
+if (ff_alloc_extradata(st->codecpar, size))
+return AVERROR(ENOMEM);
+
+avio_read(pb, st->codecpar->extradata, size);
+
+return 0;
+}
+
 static int cenc_filter(MOVContext *c, MOVStreamContext *sc, uint8_t *input, 
int size)
 {
 uint32_t encrypted_bytes;
@@ -4858,6 +4898,7 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('f','r','m','a'), mov_read_frma },
 { MKTAG('s','e','n','c'), mov_read_senc },
 { MKTAG('s','a','i','z'), mov_read_saiz },
+{ MKTAG('d','f','L','a'), mov_read_dfla },
 { 0, NULL }
 };
 
-- 
2.10.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel