Re: [libav-devel] [PATCH 29/39] alac: use AVPacket fields directly in alac_decode_frame()

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> ---
>  libavcodec/alac.c |   11 +--
>  1 files changed, 5 insertions(+), 6 deletions(-)
> 

Ok.


-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 18/39] alac: simplify 1st order prediction and reading of warm-up samples

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> ---
>  libavcodec/alac.c |   18 +-
>  1 files changed, 5 insertions(+), 13 deletions(-)

Ok.


-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 13/39] alac: remove a duplicate local variable

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> ---
>  libavcodec/alac.c |1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
> 

Ok.


-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 10/39] alac: adjust conditions for updating entropy decoder history

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> avoids some unnecessary arithmetic in certain situations
> ---
>  libavcodec/alac.c |6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 

Ok.


-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 09/39] alac: cosmetics: reindent after last commit

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> ---
>  libavcodec/alac.c |   16 
>  1 files changed, 8 insertions(+), 8 deletions(-)
> 

Looks ok.

-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 08/39] alac: limit the rice param before passing to decode_scalar()

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> reduces the number of parameters to decode_scalar() and slightly simplifies
> the code
> ---
>  libavcodec/alac.c |   16 +++-
>  1 files changed, 7 insertions(+), 9 deletions(-)

Looks fine.

lu

-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 10/10] mxfdec: fix off by one error.

2012-07-09 Thread Luca Barbato
From: Michael Niedermayer 

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer 
Signed-off-by: Luca Barbato 
---
 libavformat/mxfdec.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 3c1a47d..fe1a909 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1070,7 +1070,7 @@ static int mxf_edit_unit_absolute_offset(MXFContext *mxf, 
MXFIndexTable *index_t
 if (s->nb_index_entries == 2 * s->index_duration + 1)
 index *= 2; /* Avid index */
 
-if (index < 0 || index > s->nb_index_entries) {
+if (index < 0 || index >= s->nb_index_entries) {
 av_log(mxf->fc, AV_LOG_ERROR, "IndexSID %i segment at 
%"PRId64" IndexEntryArray too small\n",
index_table->index_sid, s->index_start_position);
 return AVERROR_INVALIDDATA;
-- 
1.7.8.rc1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 09/10] mxfdec: Only parse next partition pack if parsing forward

2012-07-09 Thread Luca Barbato
From: Tomas Härdin 

Signed-off-by: Michael Niedermayer 
Signed-off-by: Luca Barbato 
---
 libavformat/mxfdec.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 91015a9..3c1a47d 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1873,6 +1873,9 @@ static int mxf_read_header(AVFormatContext *s)
 /* next partition pack - keep going, seek to previous partition or 
stop */
 if(mxf_parse_handle_partition_or_eof(mxf) <= 0)
 break;
+else if (mxf->parsing_backward)
+continue;
+/* we're still parsing forward. proceed to parsing this partition 
pack */
 }
 
 for (metadata = mxf_metadata_read_table; metadata->read; metadata++) {
-- 
1.7.8.rc1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 08/10] mxfdec: Let pkt->pts = mxf->current_edit_unit if intra-only

2012-07-09 Thread Luca Barbato
From: Tomas Härdin 

We cannot do this in general since we could be reading a file
with B-frames while lacking an index.

Signed-off-by: Michael Niedermayer 
Signed-off-by: Luca Barbato 
---
 libavformat/mxfdec.c |   11 +++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 24c613d..91015a9 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2000,11 +2000,17 @@ static int mxf_read_packet_old(AVFormatContext *s, 
AVPacket *pkt)
 IS_KLV_KEY(klv.key, mxf_avid_essence_element_key)) {
 int index = mxf_get_stream_index(s, &klv);
 int64_t next_ofs, next_klv;
+AVStream *st;
+MXFTrack *track;
 
 if (index < 0) {
 av_log(s, AV_LOG_ERROR, "error getting stream index %d\n", 
AV_RB32(klv.key+12));
 goto skip;
 }
+
+st = s->streams[index];
+track = st->priv_data;
+
 if (s->streams[index]->discard == AVDISCARD_ALL)
 goto skip;
 
@@ -2045,6 +2051,11 @@ static int mxf_read_packet_old(AVFormatContext *s, 
AVPacket *pkt)
 mxf->current_edit_unit < t->nb_ptses) {
 pkt->dts = mxf->current_edit_unit + t->first_dts;
 pkt->pts = t->ptses[mxf->current_edit_unit];
+} else if (track->intra_only) {
+/* intra-only -> PTS = EditUnit.
+ * let utils.c figure out DTS since it can be
+ * < PTS if low_delay = 0 (Sony IMX30) */
+pkt->pts = mxf->current_edit_unit;
 }
 }
 
-- 
1.7.8.rc1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 07/10] mxfdec: fix frame height vs field height confusion

2012-07-09 Thread Luca Barbato
From: Joseph Artsimovich 

Reviewed-by: Tomas Härdin 
Reveiwed-by: Baptiste Coudurier 
Signed-off-by: Michael Niedermayer 
Signed-off-by: Luca Barbato 
---
 libavformat/mxf.h|8 
 libavformat/mxfdec.c |   33 -
 2 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index 8d3c0b9..f39a013 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -46,6 +46,14 @@ enum MXFMetadataSetType {
 TypeBottom,// add metadata type before this
 };
 
+enum MXFFrameLayout {
+ FullFrame = 0,
+ MixedFields,
+ OneField,
+ SegmentedFrame,
+ SeparateFields
+};
+
 typedef struct {
 UID key;
 int64_t offset;
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 63e2c47..24c613d 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -132,7 +132,8 @@ typedef struct {
 AVRational sample_rate;
 AVRational aspect_ratio;
 int width;
-int height;
+int height; /* Field height, not frame height */
+int frame_layout; /* See MXFFrameLayout enum */
 int channels;
 int bits_per_sample;
 unsigned int component_depth;
@@ -824,6 +825,9 @@ static int mxf_read_generic_descriptor(void *arg, 
AVIOContext *pb, int tag, int
 case 0x3202:
 descriptor->height = avio_rb32(pb);
 break;
+case 0x320C:
+descriptor->frame_layout = avio_r8(pb);
+break;
 case 0x320E:
 descriptor->aspect_ratio.num = avio_rb32(pb);
 descriptor->aspect_ratio.den = avio_rb32(pb);
@@ -1467,7 +1471,34 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 if (st->codec->codec_id == CODEC_ID_NONE)
 st->codec->codec_id = container_ul->id;
 st->codec->width = descriptor->width;
+/* Field height, not frame height */
 st->codec->height = descriptor->height;
+switch (descriptor->frame_layout) {
+case SegmentedFrame:
+/* This one is a weird layout I don't fully understand. */
+av_log(mxf->fc, AV_LOG_INFO,
+   "SegmentedFrame layout isn't currently 
supported\n");
+break;
+case FullFrame:
+break;
+case OneField:
+/* Every other line is stored and needs to be duplicated. 
*/
+av_log(mxf->fc, AV_LOG_INFO,
+   "OneField frame layout isn't currently 
supported\n");
+break;
+/* The correct thing to do here is fall through, but by
+ * breaking we might be able to decode some streams at half
+ * the vertical resolution, rather than not al all.
+ * It's also for compatibility with the old behavior. */
+case SeparateFields:
+case MixedFields:
+/* Turn field height into frame height. */
+st->codec->height *= 2;
+default:
+av_log(mxf->fc, AV_LOG_INFO,
+   "Unknown frame layout type: %d\n",
+   descriptor->frame_layout);
+}
 if (st->codec->codec_id == CODEC_ID_RAWVIDEO) {
 st->codec->pix_fmt = descriptor->pix_fmt;
 if (st->codec->pix_fmt == PIX_FMT_NONE) {
-- 
1.7.8.rc1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 06/10] mxfdec: Add intra_only flag to MXFTrack

2012-07-09 Thread Luca Barbato
From: Tomas Härdin 

This allows future assumptions to be made without affecting non-intra files.

Signed-off-by: Michael Niedermayer 
Signed-off-by: Luca Barbato 
---
 libavformat/mxfdec.c |   23 +++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index cf6cd59..63e2c47 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -121,6 +121,7 @@ typedef struct {
 int track_id;
 uint8_t track_number[4];
 AVRational edit_rate;
+int intra_only;
 } MXFTrack;
 
 typedef struct {
@@ -912,6 +913,19 @@ static const MXFCodecUL 
mxf_picture_essence_container_uls[] = {
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x05,0x00,0x00 
}, 14,   CODEC_ID_RAWVIDEO }, /* Uncompressed Picture */
 { { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,  CODEC_ID_NONE },
 };
+
+/* EC ULs for intra-only formats */
+static const MXFCodecUL mxf_intra_only_essence_container_uls[] = {
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x00,0x00 
}, 14, CODEC_ID_MPEG2VIDEO }, /* MXF-GC SMPTE D-10 Mappings */
+{ { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,   CODEC_ID_NONE },
+};
+
+/* intra-only PictureEssenceCoding ULs, where no corresponding EC UL exists */
+static const MXFCodecUL mxf_intra_only_picture_essence_coding_uls[] = {
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 
}, 14,   CODEC_ID_H264 }, /* H.264/MPEG-4 AVC Intra Profiles */
+{ { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,   CODEC_ID_NONE },
+};
+
 static const MXFCodecUL mxf_sound_essence_container_uls[] = {
 // sound essence container uls
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 
}, 14, CODEC_ID_PCM_S16LE }, /* BWF Frame wrapped */
@@ -1284,6 +1298,14 @@ finish_decoding_index:
 return ret;
 }
 
+static int mxf_is_intra_only(MXFDescriptor *d)
+{
+return mxf_get_codec_ul(mxf_intra_only_essence_container_uls,
+&d->essence_container_ul)->id != CODEC_ID_NONE ||
+   mxf_get_codec_ul(mxf_intra_only_picture_essence_coding_uls,
+&d->essence_codec_ul)->id != CODEC_ID_NONE;
+}
+
 static int mxf_parse_structural_metadata(MXFContext *mxf)
 {
 MXFPackage *material_package = NULL;
@@ -1440,6 +1462,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 st->codec->extradata_size = descriptor->extradata_size;
 }
 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+source_track->intra_only = mxf_is_intra_only(descriptor);
 container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, 
essence_container_ul);
 if (st->codec->codec_id == CODEC_ID_NONE)
 st->codec->codec_id = container_ul->id;
-- 
1.7.8.rc1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 05/10] mxfdec: Fix Avid AirSpeed files being misinterpreted as OP1a

2012-07-09 Thread Luca Barbato
From: Tomas Härdin 

The "ECs != 1 -> OP1a" assumption was wrong. Luckily, the file that triggered
that behavior had two ECs, not zero. Hence distinguishing between them is
simple in this case.

Signed-off-by: Michael Niedermayer 
Signed-off-by: Luca Barbato 
---
 libavformat/mxfdec.c |   14 +-
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 63221bd..cf6cd59 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -510,16 +510,20 @@ static int mxf_read_partition_pack(void *arg, AVIOContext 
*pb, int tag, int size
 else if (op[12] == 64&& op[13] == 1) mxf->op = OPSonyOpt;
 else if (op[12] == 0x10) {
 /* SMPTE 390m: "There shall be exactly one essence container"
- * 2011_DCPTEST_24FPS.V.mxf violates this and is frame wrapped,
- * which is why we assume OP1a. */
+ * The following block deals with files that violate this, namely:
+ * 2011_DCPTEST_24FPS.V.mxf - two ECs, OP1a
+ * abcdefghiv016f56415e.mxf - zero ECs, OPAtom, output by Avid 
AirSpeed */
 if (nb_essence_containers != 1) {
+MXFOP op = nb_essence_containers ? OP1a : OPAtom;
+
 /* only nag once */
 if (!mxf->op)
 av_log(mxf->fc, AV_LOG_WARNING,
-   "\"OPAtom\" with %u ECs - assuming OP1a\n",
-   nb_essence_containers);
+   "\"OPAtom\" with %u ECs - assuming %s\n",
+   nb_essence_containers,
+   op == OP1a ? "OP1a" : "OPAtom");
 
-mxf->op = OP1a;
+mxf->op = op;
 } else
 mxf->op = OPAtom;
 } else {
-- 
1.7.8.rc1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 04/10] mxfdec: Truncate packets that extend past the next edit unit

2012-07-09 Thread Luca Barbato
From: Tomas Härdin 

This fixes rare cases where OPAtom may be treated as OP1a, causing all essence
to be read into RAM.

Signed-off-by: Michael Niedermayer 
Signed-off-by: Luca Barbato 
---
 libavformat/mxfdec.c |   64 ++---
 1 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index f24e25f..63221bd 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -1877,48 +1877,53 @@ static int mxf_read_header(AVFormatContext *s)
 }
 
 /**
- * Computes DTS and PTS for the given video packet based on its offset.
+ * Sets mxf->current_edit_unit based on what offset we're currently at.
+ * @return next_ofs if OK, <0 on error
  */
-static void mxf_packet_timestamps(MXFContext *mxf, AVPacket *pkt)
+static int64_t mxf_set_current_edit_unit(MXFContext *mxf, int64_t 
current_offset)
 {
-int64_t last_ofs = -1, next_ofs;
+int64_t last_ofs = -1, next_ofs = -1;
 MXFIndexTable *t = &mxf->index_tables[0];
 
 /* this is called from the OP1a demuxing logic, which means there
  * may be no index tables */
 if (mxf->nb_index_tables <= 0)
-return;
+return -1;
 
-/* find mxf->current_edit_unit so that the next edit unit starts ahead of 
pkt->pos */
+/* find mxf->current_edit_unit so that the next edit unit starts ahead
+ * of current_offset */
 while (mxf->current_edit_unit >= 0) {
-if (mxf_edit_unit_absolute_offset(mxf, t, mxf->current_edit_unit + 1, 
NULL, &next_ofs, 0) < 0)
-break;
+if (mxf_edit_unit_absolute_offset(mxf, t, mxf->current_edit_unit + 1,
+  NULL, &next_ofs, 0) < 0)
+return -1;
 
 if (next_ofs <= last_ofs) {
 /* large next_ofs didn't change or current_edit_unit wrapped
  * around this fixes the infinite loop on zzuf3.mxf */
 av_log(mxf->fc, AV_LOG_ERROR,
"next_ofs didn't change. not deriving packet timestamps\n");
-return;
+return -1;
 }
 
-if (next_ofs > pkt->pos)
+if (next_ofs > current_offset)
 break;
 
 last_ofs = next_ofs;
 mxf->current_edit_unit++;
 }
 
-if (mxf->current_edit_unit < 0 || mxf->current_edit_unit >= t->nb_ptses)
-return;
+/* not checking mxf->current_edit_unit >= t->nb_ptses here since CBR files
+ * may lack IndexEntryArrays */
+if (mxf->current_edit_unit < 0)
+return -1;
 
-pkt->dts = mxf->current_edit_unit + t->first_dts;
-pkt->pts = t->ptses[mxf->current_edit_unit];
+return next_ofs;
 }
 
 static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt)
 {
 KLVPacket klv;
+MXFContext *mxf = s->priv_data;
 
 while (!s->pb->eof_reached) {
 if (klv_read_packet(&klv, s->pb) < 0)
@@ -1936,12 +1941,29 @@ static int mxf_read_packet_old(AVFormatContext *s, 
AVPacket *pkt)
 if (IS_KLV_KEY(klv.key, mxf_essence_element_key) ||
 IS_KLV_KEY(klv.key, mxf_avid_essence_element_key)) {
 int index = mxf_get_stream_index(s, &klv);
+int64_t next_ofs, next_klv;
+
 if (index < 0) {
 av_log(s, AV_LOG_ERROR, "error getting stream index %d\n", 
AV_RB32(klv.key+12));
 goto skip;
 }
 if (s->streams[index]->discard == AVDISCARD_ALL)
 goto skip;
+
+next_klv = avio_tell(s->pb) + klv.length;
+next_ofs = mxf_set_current_edit_unit(mxf, klv.offset);
+
+if (next_ofs >= 0 && next_klv > next_ofs) {
+/* if this check is hit then it's possible OPAtom was treated
+ * as OP1a truncate the packet since it's probably very large
+ * (>2 GiB is common) */
+av_log_ask_for_sample(s,
+"KLV for edit unit %i extends into next edit unit "
+"- OPAtom misinterpreted as OP1a?\n",
+mxf->current_edit_unit);
+klv.length = next_ofs - avio_tell(s->pb);
+}
+
 /* check for 8 channels AES3 element */
 if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 
0x10) {
 if (mxf_get_d10_aes3_packet(s->pb, s->streams[index], pkt, 
klv.length) < 0) {
@@ -1956,8 +1978,20 @@ static int mxf_read_packet_old(AVFormatContext *s, 
AVPacket *pkt)
 pkt->stream_index = index;
 pkt->pos = klv.offset;
 
-if (s->streams[index]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
-mxf_packet_timestamps(s->priv_data, pkt);   /* offset -> 
EditUnit -> DTS/PTS */
+if (s->streams[index]->codec->codec_type == AVMEDIA_TYPE_VIDEO && 
next_ofs >= 0) {
+/* mxf->current_edit_unit good - see if we have an
+ * index table to derive timestamps from */
+MXFIndexTable *t = &mxf->index_tabl

[libav-devel] [PATCH 03/10] mxfdec: set pixel format for cdci picture formats

2012-07-09 Thread Luca Barbato
From: Philip de Nier 

The properties of the CDCI Descriptor are insufficient to specify
the pixel format for uncompressed picture data. SMPTE 377-1 and
RP224v10 have defined a set of picture coding labels to indicate what
formatting was used.

This patch uses 2 labels to detect UYVY422 or YUYV422 pixel formats.

It defaults to UYVY422 for 8-bit 4:2:2 pictures to support files
that were created before the coding labels were introduced ~2008

The codec pix_fmt default was changed from 0 (PIX_FMT_YUV420P) to
-1 (PIX_FMT_NONE)

Reviewed-by: Baptiste Coudurier 
Signed-off-by: Michael Niedermayer 
---
 libavformat/mxf.c|6 ++
 libavformat/mxf.h|1 +
 libavformat/mxfdec.c |   31 ++-
 3 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index e4d9fbd..77f0b58 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -55,6 +55,12 @@ const MXFCodecUL ff_mxf_codec_uls[] = {
 { { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,   CODEC_ID_NONE },
 };
 
+const MXFCodecUL ff_mxf_pixel_format_uls[] = {
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x01,0x01 
}, 16, PIX_FMT_UYVY422 },
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x01,0x02 
}, 16, PIX_FMT_YUYV422 },
+{ { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,PIX_FMT_NONE },
+};
+
 static const struct {
 enum PixelFormat pix_fmt;
 const char data[16];
diff --git a/libavformat/mxf.h b/libavformat/mxf.h
index beb6628..8d3c0b9 100644
--- a/libavformat/mxf.h
+++ b/libavformat/mxf.h
@@ -60,6 +60,7 @@ typedef struct {
 
 extern const MXFCodecUL ff_mxf_data_definition_uls[];
 extern const MXFCodecUL ff_mxf_codec_uls[];
+extern const MXFCodecUL ff_mxf_pixel_format_uls[];
 
 int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum PixelFormat 
*pix_fmt);
 
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 31585d7..f24e25f 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -134,6 +134,9 @@ typedef struct {
 int height;
 int channels;
 int bits_per_sample;
+unsigned int component_depth;
+unsigned int horiz_subsampling;
+unsigned int vert_subsampling;
 UID *sub_descriptors_refs;
 int sub_descriptors_count;
 int linked_track_id;
@@ -789,6 +792,7 @@ static void mxf_read_pixel_layout(AVIOContext *pb, 
MXFDescriptor *descriptor)
 static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, 
int size, UID uid, int64_t klv_offset)
 {
 MXFDescriptor *descriptor = arg;
+descriptor->pix_fmt = PIX_FMT_NONE;
 switch(tag) {
 case 0x3F01:
 descriptor->sub_descriptors_count = avio_rb32(pb);
@@ -819,6 +823,15 @@ static int mxf_read_generic_descriptor(void *arg, 
AVIOContext *pb, int tag, int
 descriptor->aspect_ratio.num = avio_rb32(pb);
 descriptor->aspect_ratio.den = avio_rb32(pb);
 break;
+case 0x3301:
+descriptor->component_depth = avio_rb32(pb);
+break;
+case 0x3302:
+descriptor->horiz_subsampling = avio_rb32(pb);
+break;
+case 0x3308:
+descriptor->vert_subsampling = avio_rb32(pb);
+break;
 case 0x3D03:
 descriptor->sample_rate.num = avio_rb32(pb);
 descriptor->sample_rate.den = avio_rb32(pb);
@@ -1294,6 +1307,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 UID *essence_container_ul = NULL;
 const MXFCodecUL *codec_ul = NULL;
 const MXFCodecUL *container_ul = NULL;
+const MXFCodecUL *pix_fmt_ul = NULL;
 AVStream *st;
 
 if (!(material_track = mxf_resolve_strong_ref(mxf, 
&material_package->tracks_refs[i], Track))) {
@@ -1427,8 +1441,23 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 st->codec->codec_id = container_ul->id;
 st->codec->width = descriptor->width;
 st->codec->height = descriptor->height;
-if (st->codec->codec_id == CODEC_ID_RAWVIDEO)
+if (st->codec->codec_id == CODEC_ID_RAWVIDEO) {
 st->codec->pix_fmt = descriptor->pix_fmt;
+if (st->codec->pix_fmt == PIX_FMT_NONE) {
+pix_fmt_ul = mxf_get_codec_ul(ff_mxf_pixel_format_uls,
+  
&descriptor->essence_codec_ul);
+st->codec->pix_fmt = pix_fmt_ul->id;
+if (st->codec->pix_fmt == PIX_FMT_NONE) {
+/* support files created before RP224v10 by defaulting 
to UYVY422
+   if subsampling is 4:2:2 and component depth is 
8-bit */
+if (descriptor->horiz_subsampling == 2 &&
+descriptor->vert_subsampling == 1 &&
+descriptor->component_depth == 8) {
+   

[libav-devel] Import mxfdec

2012-07-09 Thread Luca Barbato
I left out the timecode ones

mxfdec: set track edit rate num/den in expected order
mxfdec: detect uncomp pictures using essence container
mxfdec: set pixel format for cdci picture formats
mxfdec: Truncate packets that extend past the next
mxfdec: Fix Avid AirSpeed files being misinterpreted
mxfdec: Add intra_only flag to MXFTrack
mxfdec: fix frame height vs field height confusion
mxfdec: Let pkt->pts = mxf->current_edit_unit if
mxfdec: Only parse next partition pack if parsing
mxfdec: fix off by one error.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 02/10] mxfdec: detect uncomp pictures using essence container ul

2012-07-09 Thread Luca Barbato
From: Philip de Nier 

This supports detection of uncompressed picture in files that
didn't include a Picture Coding Label. The lables weren't
available until SMPTE 377-1 and RP224v10

Reviewed-by: Baptiste Coudurier 
Signed-off-by: Michael Niedermayer 
Signed-off-by: Luca Barbato 
---
 libavformat/mxfdec.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 70f9941..31585d7 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -892,6 +892,7 @@ static const MXFCodecUL mxf_picture_essence_container_uls[] 
= {
 // video essence container uls
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 
}, 14, CODEC_ID_MPEG2VIDEO }, /* MPEG-ES Frame wrapped */
 { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x41,0x01 
}, 14,CODEC_ID_DVVIDEO }, /* DV 625 25mbps */
+{ { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x05,0x00,0x00 
}, 14,   CODEC_ID_RAWVIDEO }, /* Uncompressed Picture */
 { { 
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
},  0,  CODEC_ID_NONE },
 };
 static const MXFCodecUL mxf_sound_essence_container_uls[] = {
-- 
1.7.8.rc1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 01/10] mxfdec: set track edit rate num/den in expected order

2012-07-09 Thread Luca Barbato
From: Philip de Nier 

This matches the order used for the index table edit rate.

Reviewed-by: Baptiste Coudurier 
Signed-off-by: Michael Niedermayer 
Signed-off-by: Luca Barbato 
---
 libavformat/mxfdec.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 594ba49..70f9941 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -631,8 +631,8 @@ static int mxf_read_track(void *arg, AVIOContext *pb, int 
tag, int size, UID uid
 avio_read(pb, track->track_number, 4);
 break;
 case 0x4B01:
-track->edit_rate.den = avio_rb32(pb);
 track->edit_rate.num = avio_rb32(pb);
+track->edit_rate.den = avio_rb32(pb);
 break;
 case 0x4803:
 avio_read(pb, track->sequence_ref, 16);
@@ -1369,7 +1369,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
 if (st->duration == -1)
 st->duration = AV_NOPTS_VALUE;
 st->start_time = component->start_position;
-avpriv_set_pts_info(st, 64, material_track->edit_rate.num, 
material_track->edit_rate.den);
+avpriv_set_pts_info(st, 64, material_track->edit_rate.den, 
material_track->edit_rate.num);
 
 PRINT_KEY(mxf->fc, "data definition   ul", 
source_track->sequence->data_definition_ul);
 codec_ul = mxf_get_codec_ul(ff_mxf_data_definition_uls, 
&source_track->sequence->data_definition_ul);
-- 
1.7.8.rc1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] mem: introduce av_malloc_array and av_mallocz_array

2012-07-09 Thread Luca Barbato
Both function ease allocating large arrays implementing the overflow
check inside it.
---

I'd rather be self consistent, pick what you like best.

 libavutil/mem.h |   37 +++--
 1 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/libavutil/mem.h b/libavutil/mem.h
index cd8490b..211d33f 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -63,9 +63,9 @@
 #endif
 
 #if AV_GCC_VERSION_AT_LEAST(4,3)
-#define av_alloc_size(n) __attribute__((alloc_size(n)))
+#define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
 #else
-#define av_alloc_size(n)
+#define av_alloc_size(...)
 #endif
 
 /**
@@ -79,6 +79,22 @@
 void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
 
 /**
+ * Helper function to allocate a block of size * nmemb bytes with
+ * using av_malloc()
+ * @param nmemb Number of elements
+ * @param size Size of the single element
+ * @return Pointer to the allocated block, NULL if the block cannot
+ * be allocated.
+ * @see av_malloc()
+ */
+av_alloc_size(1,2) static inline void *av_malloc_array(size_t nmemb, size_t 
size)
+{
+if (size <= 0 || nmemb >= INT_MAX / size)
+return NULL;
+return av_malloc(nmemb * size);
+}
+
+/**
  * Allocate or reallocate a block of memory.
  * If ptr is NULL and size > 0, allocate a new block. If
  * size is zero, free the memory block pointed to by ptr.
@@ -113,6 +129,23 @@ void av_free(void *ptr);
 void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
 
 /**
+ * Helper function to allocate a block of size * nmemb bytes with
+ * using av_mallocz()
+ * @param nmemb Number of elements
+ * @param size Size of the single element
+ * @return Pointer to the allocated block, NULL if the block cannot
+ * be allocated.
+ * @see av_mallocz()
+ * @see av_malloc_array()
+ */
+av_alloc_size(1,2) static inline void *av_mallocz_array(size_t nmemb, size_t 
size)
+{
+if (size <= 0 || nmemb >= INT_MAX / size)
+return NULL;
+return av_mallocz(nmemb * size);
+}
+
+/**
  * Duplicate the string s.
  * @param s string to be duplicated
  * @return Pointer to a newly allocated string containing a
-- 
1.7.8.rc1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 07/39] alac: reduce the number of parameters to bastardized_rice_decompress()

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> Use the ALACContext fields directly instead.
> ---
>  libavcodec/alac.c |   16 +---
>  1 files changed, 5 insertions(+), 11 deletions(-)
> 

Ok.


-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 06/39] alac: cosmetics: rename some ALACContext parameters

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> ---
>  libavcodec/alac.c |  127 
> ++---
>  1 files changed, 63 insertions(+), 64 deletions(-)

Fine for me.

-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 05/39] alac: clean up and update comments leftover from reverse-engineering

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> ---
>  libavcodec/alac.c |   49 ++---
>  1 files changed, 18 insertions(+), 31 deletions(-)
> 

Ok.


-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 02/39] caf: fix 'pakt' chunk parsing

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> according to the CAF specification:
> "... the value for mChunkSize can be greater than the actual valid content
> of the packet table chunk"
> ---
>  libavformat/cafdec.c |5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)

Ok.


-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 01/39] caf: support either old or new style ALAC magic kuki chunk

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:23 PM, Justin Ruggles wrote:
> ---
>  libavformat/cafdec.c |   26 ++
>  1 files changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
> index d5ee9be..0475175 100644
> --- a/libavformat/cafdec.c
> +++ b/libavformat/cafdec.c
> @@ -121,18 +121,36 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t 
> size)
>  } else if (st->codec->codec_id == CODEC_ID_ALAC) {
>  #define ALAC_PREAMBLE 12
>  #define ALAC_HEADER   36
> -if (size < ALAC_PREAMBLE + ALAC_HEADER) {
> +#define ALAC_NEW_KUKI 24
> +uint8_t preamble[12];
> +if (size < 24 || size > 48) {

Probably using ALAC_NEW_KUKI and ALAC_PREAMBLE + ALAC_HEADER would be
good, the rest seems fine.

lu

-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] dct/fft-test: use a replacement getopt() if the system has none present.

2012-07-09 Thread Luca Barbato
On 07/09/2012 11:12 PM, Anton Khirnov wrote:
> From: "Ronald S. Bultje" 
> 
> This allows compiling and running these tests on systems lacking a built-
> in version of getopt(), such as MSVC.
> 

As long everybody is happy with it.

lu

-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] dvbsubdec: Always log into a context.

2012-07-09 Thread Luca Barbato
On 07/10/2012 01:07 AM, Alex Converse wrote:
> ---
>  libavcodec/dvbsubdec.c |   29 -
>  1 files changed, 16 insertions(+), 13 deletions(-)
> 

Looks good.


-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 33/39] alac: use get_bits_long() in decode_scalar()

2012-07-09 Thread Alex Converse
On Mon, Jul 9, 2012 at 2:24 PM, Justin Ruggles  wrote:
> allows for a larger sample size than MIN_CACHE_BITS
> ---
>  libavcodec/alac.c |9 ++---
>  1 files changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/alac.c b/libavcodec/alac.c
> index 5f2c8a0..0e62adb 100644
> --- a/libavcodec/alac.c
> +++ b/libavcodec/alac.c
> @@ -84,7 +84,7 @@ static inline int decode_scalar(GetBitContext *gb, int k, 
> int readsamplesize)
>
>  if (x > 8) { /* RICE THRESHOLD */
>  /* use alternative encoding */
> -x = get_bits(gb, readsamplesize);
> +x = get_bits_long(gb, readsamplesize);
>  } else if (k != 1) {
>  int extrabits = show_bits(gb, k);
>
> @@ -294,6 +294,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
> *data,
>  hassize = get_bits1(&alac->gb);
>
>  alac->extra_bits = get_bits(&alac->gb, 2) << 3;
> +readsamplesize = alac->sample_size - alac->extra_bits + channels - 1;
>
>  /* whether the frame is compressed */
>  is_compressed = !get_bits1(&alac->gb);
> @@ -321,12 +322,6 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
> *data,
>  alac->output_samples_buffer[ch] = (int32_t 
> *)alac->frame.data[ch];
>  }
>
> -readsamplesize = alac->sample_size - alac->extra_bits + channels - 1;
> -if (readsamplesize > MIN_CACHE_BITS) {
> -av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", 
> readsamplesize);
> -return -1;
> -}
> -

What about the case where sample_size = 32, channels = 6, and
extra_bits is 0? It seems possible and results in readsamplesize = 37
which is still too big.


>  if (is_compressed) {
>  int16_t predictor_coef_table[MAX_CHANNELS][32];
>  int predictor_coef_num[MAX_CHANNELS];
> --
> 1.7.1
>
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] dvbsubdec: Always log into a context.

2012-07-09 Thread Alex Converse
---
 libavcodec/dvbsubdec.c |   29 -
 1 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index cc14622..f5fc7f2 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -318,7 +318,7 @@ static void delete_region_display_list(DVBSubContext *ctx, 
DVBSubRegion *region)
 
 }
 
-static void delete_state(DVBSubContext *ctx)
+static void delete_state(AVCodecContext *avctx, DVBSubContext *ctx)
 {
 DVBSubRegion *region;
 DVBSubCLUT *clut;
@@ -345,7 +345,7 @@ static void delete_state(DVBSubContext *ctx)
 
 /* Should already be null */
 if (ctx->object_list)
-av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n");
+av_log(avctx, AV_LOG_ERROR, "Memory deallocation error!\n");
 }
 
 static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
@@ -430,7 +430,7 @@ static av_cold int dvbsub_close_decoder(AVCodecContext 
*avctx)
 DVBSubContext *ctx = avctx->priv_data;
 DVBSubRegionDisplay *display;
 
-delete_state(ctx);
+delete_state(avctx, ctx);
 
 while (ctx->display_list) {
 display = ctx->display_list;
@@ -442,7 +442,8 @@ static av_cold int dvbsub_close_decoder(AVCodecContext 
*avctx)
 return 0;
 }
 
-static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,
+static int dvbsub_read_2bit_string(AVCodecContext *avctx,
+   uint8_t *destbuf, int dbuf_len,
const uint8_t **srcbuf, int buf_size,
int non_mod, uint8_t *map_table)
 {
@@ -540,14 +541,15 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int 
dbuf_len,
 }
 
 if (get_bits(&gb, 6))
-av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
+av_log(avctx, AV_LOG_ERROR, "line overflow\n");
 
 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
 
 return pixels_read;
 }
 
-static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len,
+static int dvbsub_read_4bit_string(AVCodecContext *avctx,
+   uint8_t *destbuf, int dbuf_len,
const uint8_t **srcbuf, int buf_size,
int non_mod, uint8_t *map_table)
 {
@@ -661,14 +663,15 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int 
dbuf_len,
 }
 
 if (get_bits(&gb, 8))
-av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
+av_log(avctx, AV_LOG_ERROR, "line overflow\n");
 
 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
 
 return pixels_read;
 }
 
-static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len,
+static int dvbsub_read_8bit_string(AVCodecContext *avctx,
+uint8_t *destbuf, int dbuf_len,
 const uint8_t **srcbuf, int buf_size,
 int non_mod, uint8_t *map_table)
 {
@@ -720,7 +723,7 @@ static int dvbsub_read_8bit_string(uint8_t *destbuf, int 
dbuf_len,
 }
 
 if (*(*srcbuf)++)
-av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
+av_log(avctx, AV_LOG_ERROR, "line overflow\n");
 
 return pixels_read;
 }
@@ -785,7 +788,7 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext 
*avctx, DVBSubObjectDis
 else
 map_table = NULL;
 
-x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + 
x_pos,
+x_pos += dvbsub_read_2bit_string(avctx, pbuf + (y_pos * 
region->width) + x_pos,
 region->width - x_pos, &buf, 
buf_end - buf,
 non_mod, map_table);
 break;
@@ -800,7 +803,7 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext 
*avctx, DVBSubObjectDis
 else
 map_table = NULL;
 
-x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + 
x_pos,
+x_pos += dvbsub_read_4bit_string(avctx, pbuf + (y_pos * 
region->width) + x_pos,
 region->width - x_pos, &buf, 
buf_end - buf,
 non_mod, map_table);
 break;
@@ -810,7 +813,7 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext 
*avctx, DVBSubObjectDis
 return;
 }
 
-x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + 
x_pos,
+x_pos += dvbsub_read_8bit_string(avctx, pbuf + (y_pos * 
region->width) + x_pos,
 region->width - x_pos, &buf, 
buf_end - buf,
 non_mod, NULL);
 break;
@@ -1114,7 +1117,7 @@ static void dvbsub_parse_page_segment(AVCodecContext 
*avctx,
 av_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
 
 if (page_state == 2) {
-delete

Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Måns Rullgård
"Ronald S. Bultje"  writes:

> Hi,
>
> On Mon, Jul 9, 2012 at 12:44 PM, Anton Khirnov  wrote:
>>
>> After some discussion on IRC I think I'll drop this set and we'll go
>> back to the original Ronald's getopt() replacement, just moved to some
>> less controversial place like compat/.
>>
>> I'll send a new patch tomorrow if nobody beats me to it.
>
> I find it incredibly sad that we're wasting Anton's time with this
> bullshit.

It's *your* bullshit, and Anton, Martin, and I have spent countless
hours cleaning up your mess.  Showing a little gratitude is the least
you could do.

-- 
Måns Rullgård
m...@mansr.com
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Ronald S. Bultje
Hi,

On Mon, Jul 9, 2012 at 12:44 PM, Anton Khirnov  wrote:
>
> After some discussion on IRC I think I'll drop this set and we'll go
> back to the original Ronald's getopt() replacement, just moved to some
> less controversial place like compat/.
>
> I'll send a new patch tomorrow if nobody beats me to it.

I find it incredibly sad that we're wasting Anton's time with this
bullshit. Grow up, kiddos.

Ronald
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 04/39] avformat: move 'chan' tag parsing to mov_chan.c to share with the CAF demuxer

2012-07-09 Thread Alex Converse
On Mon, Jul 9, 2012 at 2:23 PM, Justin Ruggles  wrote:
> ---
>  libavformat/cafdec.c   |6 ++
>  libavformat/mov.c  |   39 +--
>  libavformat/mov_chan.c |   44 
>  libavformat/mov_chan.h |   11 +++
>  4 files changed, 62 insertions(+), 38 deletions(-)
>

Some symbols (e.g. ff_mov_get_channel_label,
ff_mov_get_channel_layout_tag) could be made static. Although making
them static could be needless churn if we are planning on enhancing
support for chan in the muxer.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 03/39] caf: use int64_t for num_packets

2012-07-09 Thread Alex Converse
On Mon, Jul 9, 2012 at 2:23 PM, Justin Ruggles  wrote:
> It is used to store a value read by avio_rb64().
> ---
>  libavformat/cafdec.c |4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>

OK
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 39/39] alac: cosmetics: general pretty-printing and comment clean up

2012-07-09 Thread Diego Biurrun
On Mon, Jul 09, 2012 at 05:24:07PM -0400, Justin Ruggles wrote:
> 
> --- a/libavcodec/alac.c
> +++ b/libavcodec/alac.c
> @@ -399,10 +384,11 @@ static int decode_element(AVCodecContext *avctx, void 
> *data, int ch_index,
>  /* not compressed, easy case */
>  for (i = 0; i < alac->nb_samples; i++) {
>  for (ch = 0; ch < channels; ch++) {
> -alac->output_samples_buffer[ch][i] = 
> get_sbits_long(&alac->gb, alac->sample_size);
> +alac->output_samples_buffer[ch][i] =
> + get_sbits_long(&alac->gb, alac->sample_size);
>  }
>  }

Indenting by 8 spaces seems arbitrary, we use 4.
Drop the {} like in other places.

> @@ -472,9 +458,10 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
> *data,
>  
> -if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8)
> +if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8) {
>  av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n",
> avpkt->size * 8 - get_bits_count(&alac->gb));
> +}

Why?  We usually drop these - and you even do in this very patch.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 39/39] alac: cosmetics: general pretty-printing and comment clean up

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   49 ++---
 1 files changed, 18 insertions(+), 31 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 7ad6b42..0f6b3fd 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -56,14 +56,11 @@
 #define MAX_CHANNELS 8
 
 typedef struct {
-
 AVCodecContext *avctx;
 AVFrame frame;
 GetBitContext gb;
-
 int channels;
 
-/* buffers */
 int32_t *predict_error_buffer[2];
 int32_t *output_samples_buffer[2];
 int32_t *extra_bits_buffer[2];
@@ -74,8 +71,8 @@ typedef struct {
 uint8_t  rice_initial_history;
 uint8_t  rice_limit;
 
-int extra_bits; /**< number of extra bits beyond 
16-bit */
-int nb_samples; /**< number of samples in the 
current frame */
+int extra_bits; /**< number of extra bits beyond 16-bit */
+int nb_samples; /**< number of samples in the current frame */
 } ALACContext;
 
 enum RawDataBlockType {
@@ -144,16 +141,15 @@ static void rice_decompress(ALACContext *alac, int32_t 
*output_buffer,
 for (i = 0; i < nb_samples; i++) {
 int x, k;
 
-/* read k, that is bits as is */
+/* calculate rice param and decode next value */
 k = av_log2((history >> 9) + 3);
 k = FFMIN(k, alac->rice_limit);
 x = decode_scalar(&alac->gb, k, bps);
 x += sign_modifier;
 sign_modifier = 0;
-
 output_buffer[i] = (x >> 1) ^ -(x & 1);
 
-/* now update the history */
+/* update the history */
 if (x > 0x)
 history = 0x;
 else
@@ -164,9 +160,9 @@ static void rice_decompress(ALACContext *alac, int32_t 
*output_buffer,
 if ((history < 128) && (i + 1 < nb_samples)) {
 int block_size;
 
-k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
+/* calculate rice param and decode block size */
+k = 7 - av_log2(history) + ((history + 16) >> 6);
 k = FFMIN(k, alac->rice_limit);
-
 block_size = decode_scalar(&alac->gb, k, 16);
 
 if (block_size > 0) {
@@ -180,10 +176,8 @@ static void rice_decompress(ALACContext *alac, int32_t 
*output_buffer,
block_size * sizeof(*output_buffer));
 i += block_size;
 }
-
 if (block_size <= 0x)
 sign_modifier = 1;
-
 history = 0;
 }
 }
@@ -229,7 +223,6 @@ static void lpc_prediction(int32_t *error_buffer, int32_t 
*buffer_out,
 
 /* NOTE: 4 and 8 are very common cases that could be optimized. */
 
-/* general case */
 for (i = lpc_order; i < nb_samples - 1; i++) {
 int j;
 int val = 0;
@@ -237,13 +230,11 @@ static void lpc_prediction(int32_t *error_buffer, int32_t 
*buffer_out,
 int error_sign;
 int d = buffer_out[i - lpc_order];
 
-for (j = 0; j < lpc_order; j++) {
+/* LPC prediction */
+for (j = 0; j < lpc_order; j++)
 val += (buffer_out[i - j] - d) * lpc_coefs[j];
-}
-
 val = (val + (1 << (lpc_quant - 1))) >> lpc_quant;
 val += d + error_val;
-
 buffer_out[i + 1] = sign_extend(val, bps);
 
 /* adapt LPC coefficients */
@@ -261,9 +252,8 @@ static void lpc_prediction(int32_t *error_buffer, int32_t 
*buffer_out,
 }
 }
 
-static void decorrelate_stereo(int32_t *buffer[2],
-   int nb_samples, int decorr_shift,
-   int decorr_left_weight)
+static void decorrelate_stereo(int32_t *buffer[2], int nb_samples,
+   int decorr_shift, int decorr_left_weight)
 {
 int i;
 
@@ -281,8 +271,7 @@ static void decorrelate_stereo(int32_t *buffer[2],
 }
 }
 
-static void append_extra_bits(int32_t *buffer[2],
-  int32_t *extra_bits_buffer[2],
+static void append_extra_bits(int32_t *buffer[2], int32_t 
*extra_bits_buffer[2],
   int extra_bits, int channels, int nb_samples)
 {
 int i, ch;
@@ -296,13 +285,9 @@ static int decode_element(AVCodecContext *avctx, void 
*data, int ch_index,
   int channels)
 {
 ALACContext *alac = avctx->priv_data;
-int has_size;
-int bps;
-int is_compressed;
-int decorr_shift;
-int decorr_left_weight;
+int has_size, bps, is_compressed, decorr_shift, decorr_left_weight, ret;
 uint32_t output_samples;
-int i, ch, ret;
+int i, ch;
 
 skip_bits(&alac->gb, 4);  /* element instance tag */
 skip_bits(&alac->gb, 12); /* unused header bits */
@@ -399,10 +384,11 @@ static int decode_element(AVCodecContext *avctx, void 
*data, int ch_index,
 /* not compressed, easy case */
 for (i = 0; i < alac->nb_samples; i++) {
 for (ch = 0; ch < channels; ch++) {
-alac->output_samples_buffer[ch][i] = get_sbits_long(&a

[libav-devel] [PATCH 38/39] alac: calculate buffer size outside the loop in allocate_buffers()

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index cf95959..7ad6b42 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -500,9 +500,9 @@ static av_cold int alac_decode_close(AVCodecContext *avctx)
 static int allocate_buffers(ALACContext *alac)
 {
 int ch;
-for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) {
-int buf_size = alac->max_samples_per_frame * sizeof(int32_t);
+int buf_size = alac->max_samples_per_frame * sizeof(int32_t);
 
+for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) {
 FF_ALLOC_OR_GOTO(alac->avctx, alac->predict_error_buffer[ch],
  buf_size, buf_alloc_fail);
 
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 37/39] alac: change some data types to plain int

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   10 +-
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index db5633c..cf95959 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -262,8 +262,8 @@ static void lpc_prediction(int32_t *error_buffer, int32_t 
*buffer_out,
 }
 
 static void decorrelate_stereo(int32_t *buffer[2],
-   int nb_samples, uint8_t decorr_shift,
-   uint8_t decorr_left_weight)
+   int nb_samples, int decorr_shift,
+   int decorr_left_weight)
 {
 int i;
 
@@ -297,10 +297,10 @@ static int decode_element(AVCodecContext *avctx, void 
*data, int ch_index,
 {
 ALACContext *alac = avctx->priv_data;
 int has_size;
-unsigned int bps;
+int bps;
 int is_compressed;
-uint8_t decorr_shift;
-uint8_t decorr_left_weight;
+int decorr_shift;
+int decorr_left_weight;
 uint32_t output_samples;
 int i, ch, ret;
 
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 36/39] alac: cosmetics: rename some variables and function names

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |  165 -
 1 files changed, 75 insertions(+), 90 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 4dbfea8..db5633c 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -112,13 +112,13 @@ static const uint16_t alac_channel_layouts[8] = {
 AV_CH_LAYOUT_7POINT1_WIDE_BACK
 };
 
-static inline int decode_scalar(GetBitContext *gb, int k, int readsamplesize)
+static inline int decode_scalar(GetBitContext *gb, int k, int bps)
 {
 int x = get_unary_0_9(gb);
 
 if (x > 8) { /* RICE THRESHOLD */
 /* use alternative encoding */
-x = get_bits_long(gb, readsamplesize);
+x = get_bits_long(gb, bps);
 } else if (k != 1) {
 int extrabits = show_bits(gb, k);
 
@@ -134,27 +134,24 @@ static inline int decode_scalar(GetBitContext *gb, int k, 
int readsamplesize)
 return x;
 }
 
-static void bastardized_rice_decompress(ALACContext *alac,
-int32_t *output_buffer,
-int output_size,
-int readsamplesize,
-int rice_history_mult)
+static void rice_decompress(ALACContext *alac, int32_t *output_buffer,
+int nb_samples, int bps, int rice_history_mult)
 {
-int output_count;
+int i;
 unsigned int history = alac->rice_initial_history;
 int sign_modifier = 0;
 
-for (output_count = 0; output_count < output_size; output_count++) {
+for (i = 0; i < nb_samples; i++) {
 int x, k;
 
 /* read k, that is bits as is */
 k = av_log2((history >> 9) + 3);
 k = FFMIN(k, alac->rice_limit);
-x = decode_scalar(&alac->gb, k, readsamplesize);
+x = decode_scalar(&alac->gb, k, bps);
 x += sign_modifier;
 sign_modifier = 0;
 
-output_buffer[output_count] = (x >> 1) ^ -(x & 1);
+output_buffer[i] = (x >> 1) ^ -(x & 1);
 
 /* now update the history */
 if (x > 0x)
@@ -164,7 +161,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
((history * rice_history_mult) >> 9);
 
 /* special case: there may be compressed blocks of 0 */
-if ((history < 128) && (output_count+1 < output_size)) {
+if ((history < 128) && (i + 1 < nb_samples)) {
 int block_size;
 
 k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
@@ -173,13 +170,15 @@ static void bastardized_rice_decompress(ALACContext *alac,
 block_size = decode_scalar(&alac->gb, k, 16);
 
 if (block_size > 0) {
-if(block_size >= output_size - output_count){
-av_log(alac->avctx, AV_LOG_ERROR, "invalid zero block size 
of %d %d %d\n", block_size, output_size, output_count);
-block_size= output_size - output_count - 1;
+if (block_size >= nb_samples - i) {
+av_log(alac->avctx, AV_LOG_ERROR,
+   "invalid zero block size of %d %d %d\n", block_size,
+   nb_samples, i);
+block_size = nb_samples - i - 1;
 }
-memset(&output_buffer[output_count + 1], 0,
+memset(&output_buffer[i + 1], 0,
block_size * sizeof(*output_buffer));
-output_count += block_size;
+i += block_size;
 }
 
 if (block_size <= 0x)
@@ -195,93 +194,86 @@ static inline int sign_only(int v)
 return v ? FFSIGN(v) : 0;
 }
 
-static void predictor_decompress_fir_adapt(int32_t *error_buffer,
-   int32_t *buffer_out,
-   int output_size,
-   int readsamplesize,
-   int16_t *predictor_coef_table,
-   int predictor_coef_num,
-   int predictor_quantitization)
+static void lpc_prediction(int32_t *error_buffer, int32_t *buffer_out,
+   int nb_samples, int bps, int16_t *lpc_coefs,
+   int lpc_order, int lpc_quant)
 {
 int i;
 
 /* first sample always copies */
 *buffer_out = *error_buffer;
 
-if (output_size <= 1)
+if (nb_samples <= 1)
 return;
 
-if (!predictor_coef_num) {
+if (!lpc_order) {
 memcpy(&buffer_out[1], &error_buffer[1],
-   (output_size - 1) * sizeof(*buffer_out));
+   (nb_samples - 1) * sizeof(*buffer_out));
 return;
 }
 
-if (predictor_coef_num == 31) {
+if (lpc_order == 31) {
 /* simple 1st-order prediction */
-for (i = 1; i < output_size; i++) {
+for (i = 1; i < nb_samples; i++) {
 buffer_out[i] = sign

[libav-devel] [PATCH 35/39] alac: multi-channel decoding support

2012-07-09 Thread Justin Ruggles
From: Andrew D'Addesio 

Signed-off-by: Justin Ruggles 
---
 libavcodec/alac.c |   61 +---
 1 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 1ba7e9a..4dbfea8 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -45,7 +45,7 @@
  * 32bit  samplerate
  */
 
-
+#include "libavutil/audioconvert.h"
 #include "avcodec.h"
 #include "get_bits.h"
 #include "bytestream.h"
@@ -53,7 +53,7 @@
 #include "mathops.h"
 
 #define ALAC_EXTRADATA_SIZE 36
-#define MAX_CHANNELS 2
+#define MAX_CHANNELS 8
 
 typedef struct {
 
@@ -64,9 +64,9 @@ typedef struct {
 int channels;
 
 /* buffers */
-int32_t *predict_error_buffer[MAX_CHANNELS];
-int32_t *output_samples_buffer[MAX_CHANNELS];
-int32_t *extra_bits_buffer[MAX_CHANNELS];
+int32_t *predict_error_buffer[2];
+int32_t *output_samples_buffer[2];
+int32_t *extra_bits_buffer[2];
 
 uint32_t max_samples_per_frame;
 uint8_t  sample_size;
@@ -90,6 +90,28 @@ enum RawDataBlockType {
 TYPE_END
 };
 
+static const uint8_t alac_channel_layout_offsets[8][8] = {
+{ 0 },
+{ 0, 1 },
+{ 2, 0, 1 },
+{ 2, 0, 1, 3 },
+{ 2, 0, 1, 3, 4 },
+{ 2, 0, 1, 4, 5, 3 },
+{ 2, 0, 1, 4, 5, 6, 3 },
+{ 2, 6, 7, 0, 1, 4, 5, 3 }
+};
+
+static const uint16_t alac_channel_layouts[8] = {
+AV_CH_LAYOUT_MONO,
+AV_CH_LAYOUT_STEREO,
+AV_CH_LAYOUT_SURROUND,
+AV_CH_LAYOUT_4POINT0,
+AV_CH_LAYOUT_5POINT0_BACK,
+AV_CH_LAYOUT_5POINT1_BACK,
+AV_CH_LAYOUT_6POINT1_BACK,
+AV_CH_LAYOUT_7POINT1_WIDE_BACK
+};
+
 static inline int decode_scalar(GetBitContext *gb, int k, int readsamplesize)
 {
 int x = get_unary_0_9(gb);
@@ -247,7 +269,7 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 }
 }
 
-static void decorrelate_stereo(int32_t *buffer[MAX_CHANNELS],
+static void decorrelate_stereo(int32_t *buffer[2],
int numsamples, uint8_t interlacing_shift,
uint8_t interlacing_leftweight)
 {
@@ -267,8 +289,8 @@ static void decorrelate_stereo(int32_t 
*buffer[MAX_CHANNELS],
 }
 }
 
-static void append_extra_bits(int32_t *buffer[MAX_CHANNELS],
-  int32_t *extra_bits_buffer[MAX_CHANNELS],
+static void append_extra_bits(int32_t *buffer[2],
+  int32_t *extra_bits_buffer[2],
   int extra_bits, int numchannels, int numsamples)
 {
 int i, ch;
@@ -320,7 +342,7 @@ static int decode_element(AVCodecContext *avctx, void 
*data, int ch_index,
 }
 if (alac->sample_size > 16) {
 for (ch = 0; ch < channels; ch++)
-alac->output_samples_buffer[ch] = (int32_t 
*)alac->frame.data[ch_index + ch];
+alac->output_samples_buffer[ch] = (int32_t 
*)alac->frame.extended_data[ch_index + ch];
 }
 } else if (output_samples != alac->nb_samples) {
 av_log(avctx, AV_LOG_ERROR, "sample count mismatch: %u != %d\n",
@@ -330,11 +352,11 @@ static int decode_element(AVCodecContext *avctx, void 
*data, int ch_index,
 alac->nb_samples = output_samples;
 
 if (is_compressed) {
-int16_t predictor_coef_table[MAX_CHANNELS][32];
-int predictor_coef_num[MAX_CHANNELS];
-int prediction_type[MAX_CHANNELS];
-int prediction_quantitization[MAX_CHANNELS];
-int ricemodifier[MAX_CHANNELS];
+int16_t predictor_coef_table[2][32];
+int predictor_coef_num[2];
+int prediction_type[2];
+int prediction_quantitization[2];
+int ricemodifier[2];
 
 interlacing_shift = get_bits(&alac->gb, 8);
 interlacing_leftweight = get_bits(&alac->gb, 8);
@@ -413,7 +435,7 @@ static int decode_element(AVCodecContext *avctx, void 
*data, int ch_index,
 switch(alac->sample_size) {
 case 16: {
 for (ch = 0; ch < channels; ch++) {
-int16_t *outbuffer = (int16_t *)alac->frame.data[ch_index + ch];
+int16_t *outbuffer = (int16_t *)alac->frame.extended_data[ch_index 
+ ch];
 for (i = 0; i < alac->nb_samples; i++)
 *outbuffer++ = alac->output_samples_buffer[ch][i];
 }}
@@ -456,7 +478,9 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 return AVERROR_INVALIDDATA;
 }
 
-ret = decode_element(avctx, data, ch, channels);
+ret = decode_element(avctx, data,
+ alac_channel_layout_offsets[alac->channels - 
1][ch],
+ channels);
 if (ret < 0)
 return ret;
 
@@ -478,7 +502,7 @@ static av_cold int alac_decode_close(AVCodecContext *avctx)
 ALACContext *alac = avctx->priv_data;
 
 int ch;
-for (ch = 0; ch < alac->channels; ch++) {
+for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) {
 av_freep(&alac->predict_error_buffer[ch]);
 if (alac->sa

[libav-devel] [PATCH 34/39] alac: split element parsing into a separate function

2012-07-09 Thread Justin Ruggles
This will make multi-channel implementation simpler.
Based partially on a patch by Andrew D'Addesio .
---
 libavcodec/alac.c |  121 +++-
 1 files changed, 81 insertions(+), 40 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 0e62adb..1ba7e9a 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -78,6 +78,18 @@ typedef struct {
 int nb_samples; /**< number of samples in the 
current frame */
 } ALACContext;
 
+enum RawDataBlockType {
+/* At the moment, only SCE, CPE, LFE, and END are recognized. */
+TYPE_SCE,
+TYPE_CPE,
+TYPE_CCE,
+TYPE_LFE,
+TYPE_DSE,
+TYPE_PCE,
+TYPE_FIL,
+TYPE_END
+};
+
 static inline int decode_scalar(GetBitContext *gb, int k, int readsamplesize)
 {
 int x = get_unary_0_9(gb);
@@ -266,27 +278,18 @@ static void append_extra_bits(int32_t 
*buffer[MAX_CHANNELS],
 buffer[ch][i] = (buffer[ch][i] << extra_bits) | 
extra_bits_buffer[ch][i];
 }
 
-static int alac_decode_frame(AVCodecContext *avctx, void *data,
- int *got_frame_ptr, AVPacket *avpkt)
+static int decode_element(AVCodecContext *avctx, void *data, int ch_index,
+  int channels)
 {
 ALACContext *alac = avctx->priv_data;
-
-int channels;
 int hassize;
 unsigned int readsamplesize;
 int is_compressed;
 uint8_t interlacing_shift;
 uint8_t interlacing_leftweight;
+uint32_t output_samples;
 int i, ch, ret;
 
-init_get_bits(&alac->gb, avpkt->data, avpkt->size * 8);
-
-channels = get_bits(&alac->gb, 3) + 1;
-if (channels != avctx->channels) {
-av_log(avctx, AV_LOG_ERROR, "frame header channel count mismatch\n");
-return AVERROR_INVALIDDATA;
-}
-
 skip_bits(&alac->gb, 4);  /* element instance tag */
 skip_bits(&alac->gb, 12); /* unused header bits */
 
@@ -299,28 +302,32 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 /* whether the frame is compressed */
 is_compressed = !get_bits1(&alac->gb);
 
-if (hassize) {
-/* now read the number of samples as a 32bit integer */
-uint32_t output_samples = get_bits_long(&alac->gb, 32);
-if (!output_samples || output_samples > alac->max_samples_per_frame) {
-av_log(avctx, AV_LOG_ERROR, "invalid samples per frame: %d\n",
-   output_samples);
-return AVERROR_INVALIDDATA;
-}
-alac->nb_samples = output_samples;
-} else
-alac->nb_samples = alac->max_samples_per_frame;
-
-/* get output buffer */
-alac->frame.nb_samples = alac->nb_samples;
-if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) {
-av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-return ret;
+if (hassize)
+output_samples = get_bits_long(&alac->gb, 32);
+else
+output_samples = alac->max_samples_per_frame;
+if (!output_samples || output_samples > alac->max_samples_per_frame) {
+av_log(avctx, AV_LOG_ERROR, "invalid samples per frame: %d\n",
+   output_samples);
+return AVERROR_INVALIDDATA;
 }
-if (alac->sample_size > 16) {
-for (ch = 0; ch < alac->channels; ch++)
-alac->output_samples_buffer[ch] = (int32_t *)alac->frame.data[ch];
+if (!alac->nb_samples) {
+/* get output buffer */
+alac->frame.nb_samples = output_samples;
+if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) {
+av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+return ret;
+}
+if (alac->sample_size > 16) {
+for (ch = 0; ch < channels; ch++)
+alac->output_samples_buffer[ch] = (int32_t 
*)alac->frame.data[ch_index + ch];
+}
+} else if (output_samples != alac->nb_samples) {
+av_log(avctx, AV_LOG_ERROR, "sample count mismatch: %u != %d\n",
+   output_samples, alac->nb_samples);
+return AVERROR_INVALIDDATA;
 }
+alac->nb_samples = output_samples;
 
 if (is_compressed) {
 int16_t predictor_coef_table[MAX_CHANNELS][32];
@@ -385,16 +392,13 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 /* not compressed, easy case */
 for (i = 0; i < alac->nb_samples; i++) {
 for (ch = 0; ch < channels; ch++) {
-alac->output_samples_buffer[ch][i] = get_sbits_long(&alac->gb,
-
alac->sample_size);
+alac->output_samples_buffer[ch][i] = get_sbits_long(&alac->gb, 
alac->sample_size);
 }
 }
 alac->extra_bits = 0;
 interlacing_shift = 0;
 interlacing_leftweight = 0;
 }
-if (get_bits(&alac->gb, 3) != 7)
-av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");
 
 if (channels == 2 && interlacing_leftweight) {
 decorrel

[libav-devel] [PATCH 33/39] alac: use get_bits_long() in decode_scalar()

2012-07-09 Thread Justin Ruggles
allows for a larger sample size than MIN_CACHE_BITS
---
 libavcodec/alac.c |9 ++---
 1 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 5f2c8a0..0e62adb 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -84,7 +84,7 @@ static inline int decode_scalar(GetBitContext *gb, int k, int 
readsamplesize)
 
 if (x > 8) { /* RICE THRESHOLD */
 /* use alternative encoding */
-x = get_bits(gb, readsamplesize);
+x = get_bits_long(gb, readsamplesize);
 } else if (k != 1) {
 int extrabits = show_bits(gb, k);
 
@@ -294,6 +294,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 hassize = get_bits1(&alac->gb);
 
 alac->extra_bits = get_bits(&alac->gb, 2) << 3;
+readsamplesize = alac->sample_size - alac->extra_bits + channels - 1;
 
 /* whether the frame is compressed */
 is_compressed = !get_bits1(&alac->gb);
@@ -321,12 +322,6 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 alac->output_samples_buffer[ch] = (int32_t *)alac->frame.data[ch];
 }
 
-readsamplesize = alac->sample_size - alac->extra_bits + channels - 1;
-if (readsamplesize > MIN_CACHE_BITS) {
-av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", 
readsamplesize);
-return -1;
-}
-
 if (is_compressed) {
 int16_t predictor_coef_table[MAX_CHANNELS][32];
 int predictor_coef_num[MAX_CHANNELS];
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 32/39] alac: output in planar sample format

2012-07-09 Thread Justin Ruggles
Avoids unneeded interleaving and allows for reusing the AVFrame output buffer
as the internal buffer for 24-bit and 32-bit sample size.
---
 libavcodec/alac.c |   46 +++---
 1 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 268d592..5f2c8a0 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -316,6 +316,10 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 return ret;
 }
+if (alac->sample_size > 16) {
+for (ch = 0; ch < alac->channels; ch++)
+alac->output_samples_buffer[ch] = (int32_t *)alac->frame.data[ch];
+}
 
 readsamplesize = alac->sample_size - alac->extra_bits + channels - 1;
 if (readsamplesize > MIN_CACHE_BITS) {
@@ -409,33 +413,18 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 
 switch(alac->sample_size) {
 case 16: {
-int16_t *outbuffer = (int16_t *)alac->frame.data[0];
-for (i = 0; i < alac->nb_samples; i++) {
-*outbuffer++ = alac->output_samples_buffer[0][i];
-if (channels == 2)
-*outbuffer++ = alac->output_samples_buffer[1][i];
+for (ch = 0; ch < alac->channels; ch++) {
+int16_t *outbuffer = (int16_t *)alac->frame.data[ch];
+for (i = 0; i < alac->nb_samples; i++)
+*outbuffer++ = alac->output_samples_buffer[ch][i];
 }}
 break;
 case 24: {
-int32_t *outbuffer = (int32_t *)alac->frame.data[0];
-for (i = 0; i < alac->nb_samples; i++) {
-*outbuffer++ = alac->output_samples_buffer[0][i] << 8;
-if (channels == 2)
-*outbuffer++ = alac->output_samples_buffer[1][i] << 8;
+for (ch = 0; ch < alac->channels; ch++) {
+for (i = 0; i < alac->nb_samples; i++)
+alac->output_samples_buffer[ch][i] <<= 8;
 }}
 break;
-case 32:
-if (channels == 2) {
-int32_t *outbuffer = (int32_t *)alac->frame.data[0];
-for (i = 0; i < alac->nb_samples; i++) {
-*outbuffer++ = alac->output_samples_buffer[0][i];
-*outbuffer++ = alac->output_samples_buffer[1][i];
-}
-} else {
-memcpy(alac->frame.data[0], alac->output_samples_buffer[0],
-   alac->nb_samples * sizeof(*alac->output_samples_buffer[0]));
-}
-break;
 }
 
 if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8)
@@ -455,7 +444,8 @@ static av_cold int alac_decode_close(AVCodecContext *avctx)
 int ch;
 for (ch = 0; ch < alac->channels; ch++) {
 av_freep(&alac->predict_error_buffer[ch]);
-av_freep(&alac->output_samples_buffer[ch]);
+if (alac->sample_size == 16)
+av_freep(&alac->output_samples_buffer[ch]);
 av_freep(&alac->extra_bits_buffer[ch]);
 }
 
@@ -471,8 +461,10 @@ static int allocate_buffers(ALACContext *alac)
 FF_ALLOC_OR_GOTO(alac->avctx, alac->predict_error_buffer[ch],
  buf_size, buf_alloc_fail);
 
-FF_ALLOC_OR_GOTO(alac->avctx, alac->output_samples_buffer[ch],
- buf_size, buf_alloc_fail);
+if (alac->sample_size == 16) {
+FF_ALLOC_OR_GOTO(alac->avctx, alac->output_samples_buffer[ch],
+ buf_size, buf_alloc_fail);
+}
 
 FF_ALLOC_OR_GOTO(alac->avctx, alac->extra_bits_buffer[ch],
  buf_size, buf_alloc_fail);
@@ -530,10 +522,10 @@ static av_cold int alac_decode_init(AVCodecContext * 
avctx)
 }
 
 switch (alac->sample_size) {
-case 16: avctx->sample_fmt= AV_SAMPLE_FMT_S16;
+case 16: avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
  break;
 case 24:
-case 32: avctx->sample_fmt= AV_SAMPLE_FMT_S32;
+case 32: avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
  break;
 default: av_log_ask_for_sample(avctx, "Sample depth %d is not 
supported.\n",
alac->sample_size);
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 31/39] alac: add 32-bit decoding support

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   15 ++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index df3c314..268d592 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -424,6 +424,18 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 *outbuffer++ = alac->output_samples_buffer[1][i] << 8;
 }}
 break;
+case 32:
+if (channels == 2) {
+int32_t *outbuffer = (int32_t *)alac->frame.data[0];
+for (i = 0; i < alac->nb_samples; i++) {
+*outbuffer++ = alac->output_samples_buffer[0][i];
+*outbuffer++ = alac->output_samples_buffer[1][i];
+}
+} else {
+memcpy(alac->frame.data[0], alac->output_samples_buffer[0],
+   alac->nb_samples * sizeof(*alac->output_samples_buffer[0]));
+}
+break;
 }
 
 if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8)
@@ -520,7 +532,8 @@ static av_cold int alac_decode_init(AVCodecContext * avctx)
 switch (alac->sample_size) {
 case 16: avctx->sample_fmt= AV_SAMPLE_FMT_S16;
  break;
-case 24: avctx->sample_fmt= AV_SAMPLE_FMT_S32;
+case 24:
+case 32: avctx->sample_fmt= AV_SAMPLE_FMT_S32;
  break;
 default: av_log_ask_for_sample(avctx, "Sample depth %d is not 
supported.\n",
alac->sample_size);
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 30/39] alac: simplify channel interleaving

2012-07-09 Thread Justin Ruggles
From: Andrew D'Addesio 

Signed-off-by: Justin Ruggles 
---
 libavcodec/alac.c |   57 +
 1 files changed, 14 insertions(+), 43 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index ac51c2f..df3c314 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -266,28 +266,6 @@ static void append_extra_bits(int32_t 
*buffer[MAX_CHANNELS],
 buffer[ch][i] = (buffer[ch][i] << extra_bits) | 
extra_bits_buffer[ch][i];
 }
 
-static void interleave_stereo_16(int32_t *buffer[MAX_CHANNELS],
- int16_t *buffer_out, int numsamples)
-{
-int i;
-
-for (i = 0; i < numsamples; i++) {
-*buffer_out++ = buffer[0][i];
-*buffer_out++ = buffer[1][i];
-}
-}
-
-static void interleave_stereo_24(int32_t *buffer[MAX_CHANNELS],
- int32_t *buffer_out, int numsamples)
-{
-int i;
-
-for (i = 0; i < numsamples; i++) {
-*buffer_out++ = buffer[0][i] << 8;
-*buffer_out++ = buffer[1][i] << 8;
-}
-}
-
 static int alac_decode_frame(AVCodecContext *avctx, void *data,
  int *got_frame_ptr, AVPacket *avpkt)
 {
@@ -430,28 +408,21 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 
 switch(alac->sample_size) {
-case 16:
-if (channels == 2) {
-interleave_stereo_16(alac->output_samples_buffer,
- (int16_t *)alac->frame.data[0],
- alac->nb_samples);
-} else {
-int16_t *outbuffer = (int16_t *)alac->frame.data[0];
-for (i = 0; i < alac->nb_samples; i++) {
-outbuffer[i] = alac->output_samples_buffer[0][i];
-}
-}
+case 16: {
+int16_t *outbuffer = (int16_t *)alac->frame.data[0];
+for (i = 0; i < alac->nb_samples; i++) {
+*outbuffer++ = alac->output_samples_buffer[0][i];
+if (channels == 2)
+*outbuffer++ = alac->output_samples_buffer[1][i];
+}}
 break;
-case 24:
-if (channels == 2) {
-interleave_stereo_24(alac->output_samples_buffer,
- (int32_t *)alac->frame.data[0],
- alac->nb_samples);
-} else {
-int32_t *outbuffer = (int32_t *)alac->frame.data[0];
-for (i = 0; i < alac->nb_samples; i++)
-outbuffer[i] = alac->output_samples_buffer[0][i] << 8;
-}
+case 24: {
+int32_t *outbuffer = (int32_t *)alac->frame.data[0];
+for (i = 0; i < alac->nb_samples; i++) {
+*outbuffer++ = alac->output_samples_buffer[0][i] << 8;
+if (channels == 2)
+*outbuffer++ = alac->output_samples_buffer[1][i] << 8;
+}}
 break;
 }
 
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 28/39] alac: fix check for valid max_samples_per_frame

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index db83796..1fc4dc5 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -511,9 +511,9 @@ static int alac_set_info(ALACContext *alac)
 bytestream2_skipu(&gb, 12); // size:4, alac:4, version:4
 
 alac->max_samples_per_frame = bytestream2_get_be32u(&gb);
-if (alac->max_samples_per_frame >= UINT_MAX/4){
-av_log(alac->avctx, AV_LOG_ERROR,
-   "max_samples_per_frame too large\n");
+if (!alac->max_samples_per_frame || alac->max_samples_per_frame > INT_MAX) 
{
+av_log(alac->avctx, AV_LOG_ERROR, "max samples per frame invalid: 
%u\n",
+   alac->max_samples_per_frame);
 return AVERROR_INVALIDDATA;
 }
 bytestream2_skipu(&gb, 1);  // compatible version
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 29/39] alac: use AVPacket fields directly in alac_decode_frame()

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   11 +--
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 1fc4dc5..ac51c2f 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -291,8 +291,6 @@ static void interleave_stereo_24(int32_t 
*buffer[MAX_CHANNELS],
 static int alac_decode_frame(AVCodecContext *avctx, void *data,
  int *got_frame_ptr, AVPacket *avpkt)
 {
-const uint8_t *inbuffer = avpkt->data;
-int input_buffer_size = avpkt->size;
 ALACContext *alac = avctx->priv_data;
 
 int channels;
@@ -303,7 +301,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 uint8_t interlacing_leftweight;
 int i, ch, ret;
 
-init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);
+init_get_bits(&alac->gb, avpkt->data, avpkt->size * 8);
 
 channels = get_bits(&alac->gb, 3) + 1;
 if (channels != avctx->channels) {
@@ -457,13 +455,14 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 break;
 }
 
-if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8)
-av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", 
input_buffer_size * 8 - get_bits_count(&alac->gb));
+if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8)
+av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n",
+   avpkt->size * 8 - get_bits_count(&alac->gb));
 
 *got_frame_ptr   = 1;
 *(AVFrame *)data = alac->frame;
 
-return input_buffer_size;
+return avpkt->size;
 }
 
 static av_cold int alac_decode_close(AVCodecContext *avctx)
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 26/39] alac: move the current samples per frame to the ALACContext

2012-07-09 Thread Justin Ruggles
This will simplify the multi-channel implementation.
---
 libavcodec/alac.c |   45 ++---
 1 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index f803f9a..9e77f67 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -75,6 +75,7 @@ typedef struct {
 uint8_t  rice_limit;
 
 int extra_bits; /**< number of extra bits beyond 
16-bit */
+int nb_samples; /**< number of samples in the 
current frame */
 } ALACContext;
 
 static inline int decode_scalar(GetBitContext *gb, int k, int readsamplesize)
@@ -295,7 +296,6 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 ALACContext *alac = avctx->priv_data;
 
 int channels;
-unsigned int outputsamples;
 int hassize;
 unsigned int readsamplesize;
 int is_compressed;
@@ -324,21 +324,18 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 
 if (hassize) {
 /* now read the number of samples as a 32bit integer */
-outputsamples = get_bits_long(&alac->gb, 32);
-if (outputsamples > alac->max_samples_per_frame) {
-av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n",
-   outputsamples, alac->max_samples_per_frame);
-return -1;
+uint32_t output_samples = get_bits_long(&alac->gb, 32);
+if (!output_samples || output_samples > alac->max_samples_per_frame) {
+av_log(avctx, AV_LOG_ERROR, "invalid samples per frame: %d\n",
+   output_samples);
+return AVERROR_INVALIDDATA;
 }
+alac->nb_samples = output_samples;
 } else
-outputsamples = alac->max_samples_per_frame;
+alac->nb_samples = alac->max_samples_per_frame;
 
 /* get output buffer */
-if (outputsamples > INT32_MAX) {
-av_log(avctx, AV_LOG_ERROR, "unsupported block size: %u\n", 
outputsamples);
-return AVERROR_INVALIDDATA;
-}
-alac->frame.nb_samples = outputsamples;
+alac->frame.nb_samples = alac->nb_samples;
 if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) {
 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 return ret;
@@ -373,7 +370,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 
 if (alac->extra_bits) {
-for (i = 0; i < outputsamples; i++) {
+for (i = 0; i < alac->nb_samples; i++) {
 for (ch = 0; ch < channels; ch++)
 alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, 
alac->extra_bits);
 }
@@ -381,7 +378,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 for (ch = 0; ch < channels; ch++) {
 bastardized_rice_decompress(alac,
 alac->predict_error_buffer[ch],
-outputsamples,
+alac->nb_samples,
 readsamplesize,
 ricemodifier[ch] * 
alac->rice_history_mult / 4);
 
@@ -396,7 +393,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
  */
 predictor_decompress_fir_adapt(alac->predict_error_buffer[ch],
alac->predict_error_buffer[ch],
-   outputsamples, readsamplesize,
+   alac->nb_samples, 
readsamplesize,
NULL, 31, 0);
 } else if (prediction_type[ch] > 0) {
 av_log(avctx, AV_LOG_WARNING, "unknown prediction type: %i\n",
@@ -404,14 +401,14 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 predictor_decompress_fir_adapt(alac->predict_error_buffer[ch],
alac->output_samples_buffer[ch],
-   outputsamples, readsamplesize,
+   alac->nb_samples, readsamplesize,
predictor_coef_table[ch],
predictor_coef_num[ch],
prediction_quantitization[ch]);
 }
 } else {
 /* not compressed, easy case */
-for (i = 0; i < outputsamples; i++) {
+for (i = 0; i < alac->nb_samples; i++) {
 for (ch = 0; ch < channels; ch++) {
 alac->output_samples_buffer[ch][i] = get_sbits_long(&alac->gb,
 
alac->sample_size);
@@ -425,23 +422,24 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");
 
 if (channels == 2 && inter

[libav-devel] [PATCH 27/39] alac: use get_sbits() to read LPC coefficients instead of casting

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 9e77f67..db83796 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -366,7 +366,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 
 /* read the predictor table */
 for (i = 0; i < predictor_coef_num[ch]; i++)
-predictor_coef_table[ch][i] = (int16_t)get_bits(&alac->gb, 16);
+predictor_coef_table[ch][i] = get_sbits(&alac->gb, 16);
 }
 
 if (alac->extra_bits) {
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 25/39] alac: avoid using a double-negative when checking if the frame is compressed

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |7 +++
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 474531b..f803f9a 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -298,7 +298,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 unsigned int outputsamples;
 int hassize;
 unsigned int readsamplesize;
-int isnotcompressed;
+int is_compressed;
 uint8_t interlacing_shift;
 uint8_t interlacing_leftweight;
 int i, ch, ret;
@@ -320,7 +320,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 alac->extra_bits = get_bits(&alac->gb, 2) << 3;
 
 /* whether the frame is compressed */
-isnotcompressed = get_bits1(&alac->gb);
+is_compressed = !get_bits1(&alac->gb);
 
 if (hassize) {
 /* now read the number of samples as a 32bit integer */
@@ -350,8 +350,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 return -1;
 }
 
-if (!isnotcompressed) {
-/* so it is compressed */
+if (is_compressed) {
 int16_t predictor_coef_table[MAX_CHANNELS][32];
 int predictor_coef_num[MAX_CHANNELS];
 int prediction_type[MAX_CHANNELS];
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 24/39] alac: factor out output_size check in predictor_decompress_fir_adapt()

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |8 +++-
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 42dfdad..474531b 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -173,10 +173,10 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 /* first sample always copies */
 *buffer_out = *error_buffer;
 
-if (!predictor_coef_num) {
-if (output_size <= 1)
-return;
+if (output_size <= 1)
+return;
 
+if (!predictor_coef_num) {
 memcpy(&buffer_out[1], &error_buffer[1],
(output_size - 1) * sizeof(*buffer_out));
 return;
@@ -184,8 +184,6 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 
 if (predictor_coef_num == 31) {
 /* simple 1st-order prediction */
-if (output_size <= 1)
-return;
 for (i = 1; i < output_size; i++) {
 buffer_out[i] = sign_extend(buffer_out[i - 1] + error_buffer[i],
 readsamplesize);
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 22/39] alac: factor out loading of next decoded sample in LPC prediction

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index eeb888e..e2a7d79 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -206,15 +206,16 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 int val = 0;
 int error_val = error_buffer[i + 1];
 int error_sign;
+int d = buffer_out[i - predictor_coef_num];
 
 for (j = 0; j < predictor_coef_num; j++) {
-val += (buffer_out[i - j] - buffer_out[i - predictor_coef_num]) *
+val += (buffer_out[i - j] - d) *
predictor_coef_table[j];
 }
 
 val = (val + (1 << (predictor_quantitization - 1))) >>
   predictor_quantitization;
-val += buffer_out[i - predictor_coef_num] + error_val;
+val += d + error_val;
 
 buffer_out[i + 1] = sign_extend(val, readsamplesize);
 
@@ -223,7 +224,7 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 if (error_sign) {
 for (j = predictor_coef_num - 1; j >= 0 && error_val * error_sign 
> 0; j--) {
 int sign;
-val  = buffer_out[i - predictor_coef_num] - buffer_out[i - j];
+val  = d - buffer_out[i - j];
 sign = sign_only(val) * error_sign;
 predictor_coef_table[j] -= sign;
 val *= sign;
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 23/39] alac: use sizeof() in memcpy() instead of hardcoded data size

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index e2a7d79..42dfdad 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -177,7 +177,8 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 if (output_size <= 1)
 return;
 
-memcpy(buffer_out+1, error_buffer+1, (output_size-1) * 4);
+memcpy(&buffer_out[1], &error_buffer[1],
+   (output_size - 1) * sizeof(*buffer_out));
 return;
 }
 
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 21/39] alac: use index into buffer_out instead of incrementing the pointer

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   14 ++
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index f48079c..eeb888e 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -201,29 +201,29 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 /* NOTE: 4 and 8 are very common cases that could be optimized. */
 
 /* general case */
-for (i = predictor_coef_num + 1; i < output_size; i++) {
+for (i = predictor_coef_num; i < output_size - 1; i++) {
 int j;
 int val = 0;
-int error_val = error_buffer[i];
+int error_val = error_buffer[i + 1];
 int error_sign;
 
 for (j = 0; j < predictor_coef_num; j++) {
-val += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
+val += (buffer_out[i - j] - buffer_out[i - predictor_coef_num]) *
predictor_coef_table[j];
 }
 
 val = (val + (1 << (predictor_quantitization - 1))) >>
   predictor_quantitization;
-val += buffer_out[0] + error_val;
+val += buffer_out[i - predictor_coef_num] + error_val;
 
-buffer_out[predictor_coef_num + 1] = sign_extend(val, readsamplesize);
+buffer_out[i + 1] = sign_extend(val, readsamplesize);
 
 /* adapt LPC coefficients */
 error_sign = sign_only(error_val);
 if (error_sign) {
 for (j = predictor_coef_num - 1; j >= 0 && error_val * error_sign 
> 0; j--) {
 int sign;
-val  = buffer_out[0] - buffer_out[predictor_coef_num - j];
+val  = buffer_out[i - predictor_coef_num] - buffer_out[i - j];
 sign = sign_only(val) * error_sign;
 predictor_coef_table[j] -= sign;
 val *= sign;
@@ -231,8 +231,6 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
   (predictor_coef_num - j));
 }
 }
-
-buffer_out++;
 }
 }
 
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 20/39] alac: simplify lpc coefficient adaptation

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   41 ++---
 1 files changed, 10 insertions(+), 31 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 997362b..f48079c 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -205,6 +205,7 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 int j;
 int val = 0;
 int error_val = error_buffer[i];
+int error_sign;
 
 for (j = 0; j < predictor_coef_num; j++) {
 val += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
@@ -217,39 +218,17 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 
 buffer_out[predictor_coef_num + 1] = sign_extend(val, readsamplesize);
 
-if (error_val > 0) {
-int predictor_num = predictor_coef_num - 1;
-
-while (predictor_num >= 0 && error_val > 0) {
+/* adapt LPC coefficients */
+error_sign = sign_only(error_val);
+if (error_sign) {
+for (j = predictor_coef_num - 1; j >= 0 && error_val * error_sign 
> 0; j--) {
 int sign;
-val  = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
-sign = sign_only(val);
-
-predictor_coef_table[predictor_num] -= sign;
-
-val *= sign; /* absolute value */
-
+val  = buffer_out[0] - buffer_out[predictor_coef_num - j];
+sign = sign_only(val) * error_sign;
+predictor_coef_table[j] -= sign;
+val *= sign;
 error_val -= ((val >> predictor_quantitization) *
-  (predictor_coef_num - predictor_num));
-
-predictor_num--;
-}
-} else if (error_val < 0) {
-int predictor_num = predictor_coef_num - 1;
-
-while (predictor_num >= 0 && error_val < 0) {
-int sign;
-val  = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
-sign = -sign_only(val);
-
-predictor_coef_table[predictor_num] -= sign;
-
-val *= sign; /* neg value */
-
-error_val -= ((val >> predictor_quantitization) *
-  (predictor_coef_num - predictor_num));
-
-predictor_num--;
+  (predictor_coef_num - j));
 }
 }
 
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 18/39] alac: simplify 1st order prediction and reading of warm-up samples

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   18 +-
 1 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 840c722..7e940fa 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -185,25 +185,17 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 /* simple 1st-order prediction */
 if (output_size <= 1)
 return;
-for (i = 0; i < output_size - 1; i++) {
-int32_t prev_value;
-int32_t error_value;
-
-prev_value = buffer_out[i];
-error_value = error_buffer[i+1];
-buffer_out[i+1] =
-sign_extend((prev_value + error_value), readsamplesize);
+for (i = 1; i < output_size; i++) {
+buffer_out[i] = sign_extend(buffer_out[i - 1] + error_buffer[i],
+readsamplesize);
 }
 return;
 }
 
 /* read warm-up samples */
 for (i = 0; i < predictor_coef_num; i++) {
-int32_t val;
-
-val = buffer_out[i] + error_buffer[i+1];
-val = sign_extend(val, readsamplesize);
-buffer_out[i+1] = val;
+buffer_out[i + 1] = sign_extend(buffer_out[i] + error_buffer[i + 1],
+readsamplesize);
 }
 
 /* NOTE: 4 and 8 are very common cases that could be optimized. */
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 19/39] alac: reduce the number of local variables needed in lpc prediction

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   24 
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 7e940fa..997362b 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -203,28 +203,27 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 /* general case */
 for (i = predictor_coef_num + 1; i < output_size; i++) {
 int j;
-int sum = 0;
-int outval;
+int val = 0;
 int error_val = error_buffer[i];
 
 for (j = 0; j < predictor_coef_num; j++) {
-sum += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
+val += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
predictor_coef_table[j];
 }
 
-outval = (1 << (predictor_quantitization-1)) + sum;
-outval = outval >> predictor_quantitization;
-outval = outval + buffer_out[0] + error_val;
-outval = sign_extend(outval, readsamplesize);
+val = (val + (1 << (predictor_quantitization - 1))) >>
+  predictor_quantitization;
+val += buffer_out[0] + error_val;
 
-buffer_out[predictor_coef_num+1] = outval;
+buffer_out[predictor_coef_num + 1] = sign_extend(val, readsamplesize);
 
 if (error_val > 0) {
 int predictor_num = predictor_coef_num - 1;
 
 while (predictor_num >= 0 && error_val > 0) {
-int val = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
-int sign = sign_only(val);
+int sign;
+val  = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
+sign = sign_only(val);
 
 predictor_coef_table[predictor_num] -= sign;
 
@@ -239,8 +238,9 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 int predictor_num = predictor_coef_num - 1;
 
 while (predictor_num >= 0 && error_val < 0) {
-int val = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
-int sign = - sign_only(val);
+int sign;
+val  = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
+sign = -sign_only(val);
 
 predictor_coef_table[predictor_num] -= sign;
 
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 17/39] alac: cosmetics: reindent after last commit

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   90 ++--
 1 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 23f437f..840c722 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -198,71 +198,71 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 }
 
 /* read warm-up samples */
-for (i = 0; i < predictor_coef_num; i++) {
-int32_t val;
+for (i = 0; i < predictor_coef_num; i++) {
+int32_t val;
 
-val = buffer_out[i] + error_buffer[i+1];
-val = sign_extend(val, readsamplesize);
-buffer_out[i+1] = val;
-}
+val = buffer_out[i] + error_buffer[i+1];
+val = sign_extend(val, readsamplesize);
+buffer_out[i+1] = val;
+}
 
 /* NOTE: 4 and 8 are very common cases that could be optimized. */
 
 /* general case */
-for (i = predictor_coef_num + 1; i < output_size; i++) {
-int j;
-int sum = 0;
-int outval;
-int error_val = error_buffer[i];
-
-for (j = 0; j < predictor_coef_num; j++) {
-sum += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
-   predictor_coef_table[j];
-}
+for (i = predictor_coef_num + 1; i < output_size; i++) {
+int j;
+int sum = 0;
+int outval;
+int error_val = error_buffer[i];
+
+for (j = 0; j < predictor_coef_num; j++) {
+sum += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
+   predictor_coef_table[j];
+}
 
-outval = (1 << (predictor_quantitization-1)) + sum;
-outval = outval >> predictor_quantitization;
-outval = outval + buffer_out[0] + error_val;
-outval = sign_extend(outval, readsamplesize);
+outval = (1 << (predictor_quantitization-1)) + sum;
+outval = outval >> predictor_quantitization;
+outval = outval + buffer_out[0] + error_val;
+outval = sign_extend(outval, readsamplesize);
 
-buffer_out[predictor_coef_num+1] = outval;
+buffer_out[predictor_coef_num+1] = outval;
 
-if (error_val > 0) {
-int predictor_num = predictor_coef_num - 1;
+if (error_val > 0) {
+int predictor_num = predictor_coef_num - 1;
 
-while (predictor_num >= 0 && error_val > 0) {
-int val = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
-int sign = sign_only(val);
+while (predictor_num >= 0 && error_val > 0) {
+int val = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
+int sign = sign_only(val);
 
-predictor_coef_table[predictor_num] -= sign;
+predictor_coef_table[predictor_num] -= sign;
 
-val *= sign; /* absolute value */
+val *= sign; /* absolute value */
 
-error_val -= ((val >> predictor_quantitization) *
-  (predictor_coef_num - predictor_num));
+error_val -= ((val >> predictor_quantitization) *
+  (predictor_coef_num - predictor_num));
 
-predictor_num--;
-}
-} else if (error_val < 0) {
-int predictor_num = predictor_coef_num - 1;
+predictor_num--;
+}
+} else if (error_val < 0) {
+int predictor_num = predictor_coef_num - 1;
 
-while (predictor_num >= 0 && error_val < 0) {
-int val = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
-int sign = - sign_only(val);
+while (predictor_num >= 0 && error_val < 0) {
+int val = buffer_out[0] - buffer_out[predictor_coef_num - 
predictor_num];
+int sign = - sign_only(val);
 
-predictor_coef_table[predictor_num] -= sign;
+predictor_coef_table[predictor_num] -= sign;
 
-val *= sign; /* neg value */
+val *= sign; /* neg value */
 
-error_val -= ((val >> predictor_quantitization) *
-  (predictor_coef_num - predictor_num));
+error_val -= ((val >> predictor_quantitization) *
+  (predictor_coef_num - predictor_num));
 
-predictor_num--;
-}
+predictor_num--;
 }
-
-buffer_out++;
 }
+
+buffer_out++;
+}
 }
 
 static void decorrelate_stereo(int32_t *buffer[MAX_CHANNELS],
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 16/39] alac: remove unneeded conditionals in predictor_decompress_fir_adapt()

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 915b7eb..23f437f 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -198,7 +198,6 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 }
 
 /* read warm-up samples */
-if (predictor_coef_num > 0)
 for (i = 0; i < predictor_coef_num; i++) {
 int32_t val;
 
@@ -210,7 +209,6 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 /* NOTE: 4 and 8 are very common cases that could be optimized. */
 
 /* general case */
-if (predictor_coef_num > 0) {
 for (i = predictor_coef_num + 1; i < output_size; i++) {
 int j;
 int sum = 0;
@@ -265,7 +263,6 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 
 buffer_out++;
 }
-}
 }
 
 static void decorrelate_stereo(int32_t *buffer[MAX_CHANNELS],
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 15/39] alac: use sizeof() in memset() instead of hardcoded data size

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 91c94d7..915b7eb 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -142,7 +142,8 @@ static void bastardized_rice_decompress(ALACContext *alac,
 av_log(alac->avctx, AV_LOG_ERROR, "invalid zero block size 
of %d %d %d\n", block_size, output_size, output_count);
 block_size= output_size - output_count - 1;
 }
-memset(&output_buffer[output_count+1], 0, block_size * 4);
+memset(&output_buffer[output_count + 1], 0,
+   block_size * sizeof(*output_buffer));
 output_count += block_size;
 }
 
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 14/39] alac: make block_size signed

2012-07-09 Thread Justin Ruggles
It does not need to be unsigned.
---
 libavcodec/alac.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 74da253..91c94d7 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -130,7 +130,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
 /* special case: there may be compressed blocks of 0 */
 if ((history < 128) && (output_count+1 < output_size)) {
-unsigned int block_size;
+int block_size;
 
 k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
 k = FFMIN(k, alac->rice_limit);
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 13/39] alac: remove a duplicate local variable

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 0aeb410..74da253 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -130,7 +130,6 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
 /* special case: there may be compressed blocks of 0 */
 if ((history < 128) && (output_count+1 < output_size)) {
-int k;
 unsigned int block_size;
 
 k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 12/39] alac: conditionally set sign_modifier to 1

2012-07-09 Thread Justin Ruggles
It is already unconditionally set to 0 prior to this, so we can modify it
only when needed.
---
 libavcodec/alac.c |6 ++
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 2aab84c..0aeb410 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -133,8 +133,6 @@ static void bastardized_rice_decompress(ALACContext *alac,
 int k;
 unsigned int block_size;
 
-sign_modifier = 1;
-
 k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
 k = FFMIN(k, alac->rice_limit);
 
@@ -149,8 +147,8 @@ static void bastardized_rice_decompress(ALACContext *alac,
 output_count += block_size;
 }
 
-if (block_size > 0x)
-sign_modifier = 0;
+if (block_size <= 0x)
+sign_modifier = 1;
 
 history = 0;
 }
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 11/39] alac: eliminate 2 unneeded local variables in bastardized_rice_decompress()

2012-07-09 Thread Justin Ruggles
x_modified is just unnecessary, and final_val can be removed by simplifying
the unsigned-to-signed conversion.
---
 libavcodec/alac.c |   23 +++
 1 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index f27992d..2aab84c 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -110,32 +110,23 @@ static void bastardized_rice_decompress(ALACContext *alac,
 int sign_modifier = 0;
 
 for (output_count = 0; output_count < output_size; output_count++) {
-int32_t x;
-int32_t x_modified;
-int32_t final_val;
-
-/* standard rice encoding */
-int k; /* size of extra bits */
+int x, k;
 
 /* read k, that is bits as is */
 k = av_log2((history >> 9) + 3);
 k = FFMIN(k, alac->rice_limit);
 x = decode_scalar(&alac->gb, k, readsamplesize);
-
-x_modified = sign_modifier + x;
-final_val = (x_modified + 1) / 2;
-if (x_modified & 1) final_val *= -1;
-
-output_buffer[output_count] = final_val;
-
+x += sign_modifier;
 sign_modifier = 0;
 
+output_buffer[output_count] = (x >> 1) ^ -(x & 1);
+
 /* now update the history */
-if (x_modified > 0x)
+if (x > 0x)
 history = 0x;
 else
-history += x_modified * rice_history_mult -
-((history * rice_history_mult) >> 9);
+history += x * rice_history_mult -
+   ((history * rice_history_mult) >> 9);
 
 /* special case: there may be compressed blocks of 0 */
 if ((history < 128) && (output_count+1 < output_size)) {
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 10/39] alac: adjust conditions for updating entropy decoder history

2012-07-09 Thread Justin Ruggles
avoids some unnecessary arithmetic in certain situations
---
 libavcodec/alac.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 84f7e42..f27992d 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -131,11 +131,11 @@ static void bastardized_rice_decompress(ALACContext *alac,
 sign_modifier = 0;
 
 /* now update the history */
-history += x_modified * rice_history_mult -
-((history * rice_history_mult) >> 9);
-
 if (x_modified > 0x)
 history = 0x;
+else
+history += x_modified * rice_history_mult -
+((history * rice_history_mult) >> 9);
 
 /* special case: there may be compressed blocks of 0 */
 if ((history < 128) && (output_count+1 < output_size)) {
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 09/39] alac: cosmetics: reindent after last commit

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   16 
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 76ef499..84f7e42 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -85,16 +85,16 @@ static inline int decode_scalar(GetBitContext *gb, int k, 
int readsamplesize)
 /* use alternative encoding */
 x = get_bits(gb, readsamplesize);
 } else if (k != 1) {
-int extrabits = show_bits(gb, k);
+int extrabits = show_bits(gb, k);
 
-/* multiply x by 2^k - 1, as part of their strange algorithm */
-x = (x << k) - x;
+/* multiply x by 2^k - 1, as part of their strange algorithm */
+x = (x << k) - x;
 
-if (extrabits > 1) {
-x += extrabits - 1;
-skip_bits(gb, k);
-} else
-skip_bits(gb, k - 1);
+if (extrabits > 1) {
+x += extrabits - 1;
+skip_bits(gb, k);
+} else
+skip_bits(gb, k - 1);
 }
 return x;
 }
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 08/39] alac: limit the rice param before passing to decode_scalar()

2012-07-09 Thread Justin Ruggles
reduces the number of parameters to decode_scalar() and slightly simplifies
the code
---
 libavcodec/alac.c |   16 +++-
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 8824ae8..76ef499 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -77,17 +77,14 @@ typedef struct {
 int extra_bits; /**< number of extra bits beyond 
16-bit */
 } ALACContext;
 
-static inline int decode_scalar(GetBitContext *gb, int k, int limit, int 
readsamplesize){
+static inline int decode_scalar(GetBitContext *gb, int k, int readsamplesize)
+{
 int x = get_unary_0_9(gb);
 
 if (x > 8) { /* RICE THRESHOLD */
 /* use alternative encoding */
 x = get_bits(gb, readsamplesize);
-} else {
-if (k >= limit)
-k = limit;
-
-if (k != 1) {
+} else if (k != 1) {
 int extrabits = show_bits(gb, k);
 
 /* multiply x by 2^k - 1, as part of their strange algorithm */
@@ -98,7 +95,6 @@ static inline int decode_scalar(GetBitContext *gb, int k, int 
limit, int readsam
 skip_bits(gb, k);
 } else
 skip_bits(gb, k - 1);
-}
 }
 return x;
 }
@@ -123,7 +119,8 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
 /* read k, that is bits as is */
 k = av_log2((history >> 9) + 3);
-x = decode_scalar(&alac->gb, k, alac->rice_limit, readsamplesize);
+k = FFMIN(k, alac->rice_limit);
+x = decode_scalar(&alac->gb, k, readsamplesize);
 
 x_modified = sign_modifier + x;
 final_val = (x_modified + 1) / 2;
@@ -148,8 +145,9 @@ static void bastardized_rice_decompress(ALACContext *alac,
 sign_modifier = 1;
 
 k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
+k = FFMIN(k, alac->rice_limit);
 
-block_size = decode_scalar(&alac->gb, k, alac->rice_limit, 16);
+block_size = decode_scalar(&alac->gb, k, 16);
 
 if (block_size > 0) {
 if(block_size >= output_size - output_count){
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 06/39] alac: cosmetics: rename some ALACContext parameters

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |  127 ++---
 1 files changed, 63 insertions(+), 64 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 699b86a..4848ea2 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -37,7 +37,7 @@
  *  8bit  sample size
  *  8bit  history mult (40)
  *  8bit  initial history  (14)
- *  8bit  kmodifier(10)
+ *  8bit  rice param limit (10)
  *  8bit  channels
  * 16bit  maxRun   (255)
  * 32bit  max coded frame size (0 means unknown)
@@ -61,20 +61,18 @@ typedef struct {
 AVFrame frame;
 GetBitContext gb;
 
-int numchannels;
+int channels;
 
 /* buffers */
-int32_t *predicterror_buffer[MAX_CHANNELS];
-
-int32_t *outputsamples_buffer[MAX_CHANNELS];
-
+int32_t *predict_error_buffer[MAX_CHANNELS];
+int32_t *output_samples_buffer[MAX_CHANNELS];
 int32_t *extra_bits_buffer[MAX_CHANNELS];
 
-uint32_t setinfo_max_samples_per_frame;
-uint8_t setinfo_sample_size;
-uint8_t setinfo_rice_historymult;
-uint8_t setinfo_rice_initialhistory;
-uint8_t setinfo_rice_kmodifier;
+uint32_t max_samples_per_frame;
+uint8_t  sample_size;
+uint8_t  rice_history_mult;
+uint8_t  rice_initial_history;
+uint8_t  rice_limit;
 
 int extra_bits; /**< number of extra bits beyond 
16-bit */
 } ALACContext;
@@ -109,13 +107,13 @@ static void bastardized_rice_decompress(ALACContext *alac,
 int32_t *output_buffer,
 int output_size,
 int readsamplesize,
-int rice_initialhistory,
-int rice_kmodifier,
-int rice_historymult,
+int rice_initial_history,
+int rice_limit,
+int rice_history_mult,
 int rice_kmodifier_mask)
 {
 int output_count;
-unsigned int history = rice_initialhistory;
+unsigned int history = rice_initial_history;
 int sign_modifier = 0;
 
 for (output_count = 0; output_count < output_size; output_count++) {
@@ -128,7 +126,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
 /* read k, that is bits as is */
 k = av_log2((history >> 9) + 3);
-x= decode_scalar(&alac->gb, k, rice_kmodifier, readsamplesize);
+x= decode_scalar(&alac->gb, k, rice_limit, readsamplesize);
 
 x_modified = sign_modifier + x;
 final_val = (x_modified + 1) / 2;
@@ -139,8 +137,8 @@ static void bastardized_rice_decompress(ALACContext *alac,
 sign_modifier = 0;
 
 /* now update the history */
-history += x_modified * rice_historymult
-   - ((history * rice_historymult) >> 9);
+history += x_modified * rice_history_mult -
+((history * rice_history_mult) >> 9);
 
 if (x_modified > 0x)
 history = 0x;
@@ -154,7 +152,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
 k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
 
-block_size= decode_scalar(&alac->gb, k, rice_kmodifier, 16);
+block_size = decode_scalar(&alac->gb, k, rice_limit, 16);
 
 if (block_size > 0) {
 if(block_size >= output_size - output_count){
@@ -377,12 +375,13 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 if (hassize) {
 /* now read the number of samples as a 32bit integer */
 outputsamples = get_bits_long(&alac->gb, 32);
-if(outputsamples > alac->setinfo_max_samples_per_frame){
-av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n", 
outputsamples, alac->setinfo_max_samples_per_frame);
+if (outputsamples > alac->max_samples_per_frame) {
+av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n",
+   outputsamples, alac->max_samples_per_frame);
 return -1;
 }
 } else
-outputsamples = alac->setinfo_max_samples_per_frame;
+outputsamples = alac->max_samples_per_frame;
 
 /* get output buffer */
 if (outputsamples > INT32_MAX) {
@@ -395,7 +394,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 return ret;
 }
 
-readsamplesize = alac->setinfo_sample_size - alac->extra_bits + channels - 
1;
+readsamplesize = alac->sample_size - alac->extra_bits + channels - 1;
 if (readsamplesize > MIN_CACHE_BITS) {
 av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", 
readsamplesize);
 return -1;
@@ -432,13 +431,13 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 for (ch = 0; ch < channels; ch++) {

[libav-devel] [PATCH 07/39] alac: reduce the number of parameters to bastardized_rice_decompress()

2012-07-09 Thread Justin Ruggles
Use the ALACContext fields directly instead.
---
 libavcodec/alac.c |   16 +---
 1 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 4848ea2..8824ae8 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -107,13 +107,10 @@ static void bastardized_rice_decompress(ALACContext *alac,
 int32_t *output_buffer,
 int output_size,
 int readsamplesize,
-int rice_initial_history,
-int rice_limit,
-int rice_history_mult,
-int rice_kmodifier_mask)
+int rice_history_mult)
 {
 int output_count;
-unsigned int history = rice_initial_history;
+unsigned int history = alac->rice_initial_history;
 int sign_modifier = 0;
 
 for (output_count = 0; output_count < output_size; output_count++) {
@@ -126,7 +123,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
 /* read k, that is bits as is */
 k = av_log2((history >> 9) + 3);
-x= decode_scalar(&alac->gb, k, rice_limit, readsamplesize);
+x = decode_scalar(&alac->gb, k, alac->rice_limit, readsamplesize);
 
 x_modified = sign_modifier + x;
 final_val = (x_modified + 1) / 2;
@@ -152,7 +149,7 @@ static void bastardized_rice_decompress(ALACContext *alac,
 
 k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
 
-block_size = decode_scalar(&alac->gb, k, rice_limit, 16);
+block_size = decode_scalar(&alac->gb, k, alac->rice_limit, 16);
 
 if (block_size > 0) {
 if(block_size >= output_size - output_count){
@@ -434,10 +431,7 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 alac->predict_error_buffer[ch],
 outputsamples,
 readsamplesize,
-alac->rice_initial_history,
-alac->rice_limit,
-ricemodifier[ch] * 
alac->rice_history_mult / 4,
-(1 << alac->rice_limit) - 1);
+ricemodifier[ch] * 
alac->rice_history_mult / 4);
 
 /* adaptive FIR filter */
 if (prediction_type[ch] == 15) {
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 05/39] alac: clean up and update comments leftover from reverse-engineering

2012-07-09 Thread Justin Ruggles
---
 libavcodec/alac.c |   49 ++---
 1 files changed, 18 insertions(+), 31 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index ab9fb81..699b86a 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -70,19 +70,16 @@ typedef struct {
 
 int32_t *extra_bits_buffer[MAX_CHANNELS];
 
-/* stuff from setinfo */
-uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 *//* max 
samples per frame? */
-uint8_t setinfo_sample_size; /* 0x10 */
-uint8_t setinfo_rice_historymult; /* 0x28 */
-uint8_t setinfo_rice_initialhistory; /* 0x0a */
-uint8_t setinfo_rice_kmodifier; /* 0x0e */
-/* end setinfo stuff */
+uint32_t setinfo_max_samples_per_frame;
+uint8_t setinfo_sample_size;
+uint8_t setinfo_rice_historymult;
+uint8_t setinfo_rice_initialhistory;
+uint8_t setinfo_rice_kmodifier;
 
 int extra_bits; /**< number of extra bits beyond 
16-bit */
 } ALACContext;
 
 static inline int decode_scalar(GetBitContext *gb, int k, int limit, int 
readsamplesize){
-/* read x - number of 1s before 0 represent the rice */
 int x = get_unary_0_9(gb);
 
 if (x > 8) { /* RICE THRESHOLD */
@@ -109,14 +106,13 @@ static inline int decode_scalar(GetBitContext *gb, int k, 
int limit, int readsam
 }
 
 static void bastardized_rice_decompress(ALACContext *alac,
- int32_t *output_buffer,
- int output_size,
- int readsamplesize, /* arg_10 */
- int rice_initialhistory, /* arg424->b */
- int rice_kmodifier, /* arg424->d */
- int rice_historymult, /* arg424->c */
- int rice_kmodifier_mask /* arg424->e */
-)
+int32_t *output_buffer,
+int output_size,
+int readsamplesize,
+int rice_initialhistory,
+int rice_kmodifier,
+int rice_historymult,
+int rice_kmodifier_mask)
 {
 int output_count;
 unsigned int history = rice_initialhistory;
@@ -203,10 +199,8 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 return;
 }
 
-if (predictor_coef_num == 0x1f) { /* 1 - max value of 
predictor_coef_num */
-  /* second-best case scenario for fir decompression,
-   * error describes a small difference from the previous sample only
-   */
+if (predictor_coef_num == 31) {
+/* simple 1st-order prediction */
 if (output_size <= 1)
 return;
 for (i = 0; i < output_size - 1; i++) {
@@ -231,9 +225,7 @@ static void predictor_decompress_fir_adapt(int32_t 
*error_buffer,
 buffer_out[i+1] = val;
 }
 
-/* 4 and 8 are very common cases (the only ones i've seen). these
- * should be unrolled and optimized
- */
+/* NOTE: 4 and 8 are very common cases that could be optimized. */
 
 /* general case */
 if (predictor_coef_num > 0) {
@@ -371,14 +363,10 @@ static int alac_decode_frame(AVCodecContext *avctx, void 
*data,
 return AVERROR_INVALIDDATA;
 }
 
-/* 2^result = something to do with output waiting.
- * perhaps matters if we read > 1 frame in a pass?
- */
-skip_bits(&alac->gb, 4);
+skip_bits(&alac->gb, 4);  /* element instance tag */
+skip_bits(&alac->gb, 12); /* unused header bits */
 
-skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */
-
-/* the output sample size is stored soon */
+/* the number of output samples is stored in the frame */
 hassize = get_bits1(&alac->gb);
 
 alac->extra_bits = get_bits(&alac->gb, 2) << 3;
@@ -578,7 +566,6 @@ static int alac_set_info(ALACContext *alac)
 
 bytestream2_skipu(&gb, 12); // size:4, alac:4, version:4
 
-/* buffer size / 2 ? */
 alac->setinfo_max_samples_per_frame = bytestream2_get_be32u(&gb);
 if (alac->setinfo_max_samples_per_frame >= UINT_MAX/4){
 av_log(alac->avctx, AV_LOG_ERROR,
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 04/39] avformat: move 'chan' tag parsing to mov_chan.c to share with the CAF demuxer

2012-07-09 Thread Justin Ruggles
---
 libavformat/cafdec.c   |6 ++
 libavformat/mov.c  |   39 +--
 libavformat/mov_chan.c |   44 
 libavformat/mov_chan.h |   11 +++
 4 files changed, 62 insertions(+), 38 deletions(-)

diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 64ec62f..e59f104 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -29,6 +29,7 @@
 #include "internal.h"
 #include "riff.h"
 #include "isom.h"
+#include "mov_chan.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/dict.h"
@@ -262,6 +263,11 @@ static int read_header(AVFormatContext *s)
 found_data = 1;
 break;
 
+case MKBETAG('c','h','a','n'):
+if ((ret = ff_mov_read_chan(s, st, size)) < 0)
+return ret;
+break;
+
 /* magic cookie chunk */
 case MKBETAG('k','u','k','i'):
 if (read_kuki_chunk(s, size))
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 647fd0e..59d7b1a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -575,10 +575,6 @@ static int mov_read_dec3(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 AVStream *st;
-uint8_t av_unused version;
-uint32_t av_unused flags;
-uint32_t layout_tag, bitmap, num_descr, label_mask;
-int i;
 
 if (c->fc->nb_streams < 1)
 return 0;
@@ -587,40 +583,7 @@ static int mov_read_chan(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 if (atom.size < 16)
 return 0;
 
-version = avio_r8(pb);
-flags   = avio_rb24(pb);
-
-layout_tag = avio_rb32(pb);
-bitmap = avio_rb32(pb);
-num_descr  = avio_rb32(pb);
-
-if (atom.size < 16ULL + num_descr * 20ULL)
-return 0;
-
-av_dlog(c->fc, "chan: size=%ld version=%u flags=%u layout=%u bitmap=%u 
num_descr=%u\n",
-atom.size, version, flags, layout_tag, bitmap, num_descr);
-
-label_mask = 0;
-for (i = 0; i < num_descr; i++) {
-uint32_t label;
-label = avio_rb32(pb);  // mChannelLabel
-avio_rb32(pb);  // mChannelFlags
-avio_rl32(pb);  // mCoordinates[0]
-avio_rl32(pb);  // mCoordinates[1]
-avio_rl32(pb);  // mCoordinates[2]
-if (layout_tag == 0) {
-uint32_t mask_incr = ff_mov_get_channel_label(label);
-if (mask_incr == 0) {
-label_mask = 0;
-break;
-}
-label_mask |= mask_incr;
-}
-}
-if (layout_tag == 0)
-st->codec->channel_layout = label_mask;
-else
-st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, 
bitmap);
+ff_mov_read_chan(c->fc, st, atom.size - 4);
 
 return 0;
 }
diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c
index edd5f6c..9ad1073 100644
--- a/libavformat/mov_chan.c
+++ b/libavformat/mov_chan.c
@@ -542,3 +542,47 @@ uint32_t ff_mov_get_channel_layout_tag(enum CodecID 
codec_id,
 
 return tag;
 }
+
+int ff_mov_read_chan(AVFormatContext *s, AVStream *st, int64_t size)
+{
+AVIOContext *pb = s->pb;
+uint32_t layout_tag, bitmap, num_descr, label_mask;
+int i;
+
+if (size < 12)
+return AVERROR_INVALIDDATA;
+
+layout_tag = avio_rb32(pb);
+bitmap = avio_rb32(pb);
+num_descr  = avio_rb32(pb);
+
+av_dlog(s, "chan: layout=%u bitmap=%u num_descr=%u\n",
+layout_tag, bitmap, num_descr);
+
+if (size < 12ULL + num_descr * 20ULL)
+return 0;
+
+label_mask = 0;
+for (i = 0; i < num_descr; i++) {
+uint32_t label;
+label = avio_rb32(pb);  // mChannelLabel
+avio_rb32(pb);  // mChannelFlags
+avio_rl32(pb);  // mCoordinates[0]
+avio_rl32(pb);  // mCoordinates[1]
+avio_rl32(pb);  // mCoordinates[2]
+if (layout_tag == 0) {
+uint32_t mask_incr = ff_mov_get_channel_label(label);
+if (mask_incr == 0) {
+label_mask = 0;
+break;
+}
+label_mask |= mask_incr;
+}
+}
+if (layout_tag == 0)
+st->codec->channel_layout = label_mask;
+else
+st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, 
bitmap);
+
+return 0;
+}
diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h
index bd6adf6..0441d9f 100644
--- a/libavformat/mov_chan.h
+++ b/libavformat/mov_chan.h
@@ -29,6 +29,7 @@
 #include 
 
 #include "libavcodec/avcodec.h"
+#include "avformat.h"
 
 /**
  * Get the channel layout for the specified channel layout tag.
@@ -60,4 +61,14 @@ uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id,
u

[libav-devel] [PATCH 03/39] caf: use int64_t for num_packets

2012-07-09 Thread Justin Ruggles
It is used to store a value read by avio_rb64().
---
 libavformat/cafdec.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 6e5b2c8..64ec62f 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -168,8 +168,8 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t size)
 AVIOContext *pb = s->pb;
 AVStream *st  = s->streams[0];
 CaffContext *caf  = s->priv_data;
-int64_t pos = 0, ccount;
-int num_packets, i;
+int64_t pos = 0, ccount, num_packets;
+int i;
 
 ccount = avio_tell(pb);
 
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 02/39] caf: fix 'pakt' chunk parsing

2012-07-09 Thread Justin Ruggles
according to the CAF specification:
"... the value for mChunkSize can be greater than the actual valid content
of the packet table chunk"
---
 libavformat/cafdec.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 0475175..6e5b2c8 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -188,10 +188,11 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t 
size)
 st->duration += caf->frames_per_packet ? caf->frames_per_packet : 
ff_mp4_read_descr_len(pb);
 }
 
-if (avio_tell(pb) - ccount != size) {
+if (avio_tell(pb) - ccount > size) {
 av_log(s, AV_LOG_ERROR, "error reading packet table\n");
-return -1;
+return AVERROR_INVALIDDATA;
 }
+avio_skip(pb, ccount + size - avio_tell(pb));
 
 caf->num_bytes = pos;
 return 0;
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 01/39] caf: support either old or new style ALAC magic kuki chunk

2012-07-09 Thread Justin Ruggles
---
 libavformat/cafdec.c |   26 ++
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index d5ee9be..0475175 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -121,18 +121,36 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t 
size)
 } else if (st->codec->codec_id == CODEC_ID_ALAC) {
 #define ALAC_PREAMBLE 12
 #define ALAC_HEADER   36
-if (size < ALAC_PREAMBLE + ALAC_HEADER) {
+#define ALAC_NEW_KUKI 24
+uint8_t preamble[12];
+if (size < 24 || size > 48) {
 av_log(s, AV_LOG_ERROR, "invalid ALAC magic cookie\n");
 avio_skip(pb, size);
 return AVERROR_INVALIDDATA;
 }
-avio_skip(pb, ALAC_PREAMBLE);
+avio_read(pb, preamble, ALAC_PREAMBLE);
+
 st->codec->extradata = av_mallocz(ALAC_HEADER + 
FF_INPUT_BUFFER_PADDING_SIZE);
 if (!st->codec->extradata)
 return AVERROR(ENOMEM);
-avio_read(pb, st->codec->extradata, ALAC_HEADER);
+
+if (!memcmp(&preamble[4], "frmaalac", 8)) {
+if (size < ALAC_PREAMBLE + ALAC_HEADER) {
+av_log(s, AV_LOG_ERROR, "invalid ALAC magic cookie\n");
+av_freep(&st->codec->extradata);
+return AVERROR_INVALIDDATA;
+}
+avio_read(pb, st->codec->extradata, ALAC_HEADER);
+avio_skip(pb, size - ALAC_PREAMBLE - ALAC_HEADER);
+} else {
+AV_WB32(st->codec->extradata, 36);
+memcpy(&st->codec->extradata[4], "alac", 4);
+AV_WB32(&st->codec->extradata[8], 0);
+memcpy(&st->codec->extradata[12], preamble, 12);
+avio_read(pb, &st->codec->extradata[24], ALAC_NEW_KUKI - 12);
+avio_skip(pb, size - ALAC_NEW_KUKI);
+}
 st->codec->extradata_size = ALAC_HEADER;
-avio_skip(pb, size - ALAC_PREAMBLE - ALAC_HEADER);
 } else {
 st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
 if (!st->codec->extradata)
-- 
1.7.1

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH 00/39] ALAC decoder improvements

2012-07-09 Thread Justin Ruggles
- Misc clean ups and fixes
- Planar output
- 32-bit decoding
- multi-channel decoding

Andrew D'Addesio (2):
  alac: simplify channel interleaving
  alac: multi-channel decoding support

Justin Ruggles (37):
  caf: support either old or new style ALAC magic kuki chunk
  caf: fix 'pakt' chunk parsing
  caf: use int64_t for num_packets
  avformat: move 'chan' tag parsing to mov_chan.c to share with the CAF
demuxer
  alac: clean up and update comments leftover from reverse-engineering
  alac: cosmetics: rename some ALACContext parameters
  alac: reduce the number of parameters to
bastardized_rice_decompress()
  alac: limit the rice param before passing to decode_scalar()
  alac: cosmetics: reindent after last commit
  alac: adjust conditions for updating entropy decoder history
  alac: eliminate 2 unneeded local variables in
bastardized_rice_decompress()
  alac: conditionally set sign_modifier to 1
  alac: remove a duplicate local variable
  alac: make block_size signed
  alac: use sizeof() in memset() instead of hardcoded data size
  alac: remove unneeded conditionals in
predictor_decompress_fir_adapt()
  alac: cosmetics: reindent after last commit
  alac: simplify 1st order prediction and reading of warm-up samples
  alac: reduce the number of local variables needed in lpc prediction
  alac: simplify lpc coefficient adaptation
  alac: use index into buffer_out instead of incrementing the pointer
  alac: factor out loading of next decoded sample in LPC prediction
  alac: use sizeof() in memcpy() instead of hardcoded data size
  alac: factor out output_size check in
predictor_decompress_fir_adapt()
  alac: avoid using a double-negative when checking if the frame is
compressed
  alac: move the current samples per frame to the ALACContext
  alac: use get_sbits() to read LPC coefficients instead of casting
  alac: fix check for valid max_samples_per_frame
  alac: use AVPacket fields directly in alac_decode_frame()
  alac: add 32-bit decoding support
  alac: output in planar sample format
  alac: use get_bits_long() in decode_scalar()
  alac: split element parsing into a separate function
  alac: cosmetics: rename some variables and function names
  alac: change some data types to plain int
  alac: calculate buffer size outside the loop in allocate_buffers()
  alac: cosmetics: general pretty-printing and comment clean up

 libavcodec/alac.c  |  661 ++--
 libavformat/cafdec.c   |   41 +++-
 libavformat/mov.c  |   39 +---
 libavformat/mov_chan.c |   44 
 libavformat/mov_chan.h |   11 +
 5 files changed, 389 insertions(+), 407 deletions(-)

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] dct/fft-test: use a replacement getopt() if the system has none present.

2012-07-09 Thread Anton Khirnov
From: "Ronald S. Bultje" 

This allows compiling and running these tests on systems lacking a built-
in version of getopt(), such as MSVC.

Signed-off-by: Anton Khirnov 
---
 compat/getopt.c   |   84 +
 configure |2 ++
 libavcodec/dct-test.c |7 +
 libavcodec/fft-test.c |6 
 4 files changed, 99 insertions(+)
 create mode 100644 compat/getopt.c

diff --git a/compat/getopt.c b/compat/getopt.c
new file mode 100644
index 000..3a873b2
--- /dev/null
+++ b/compat/getopt.c
@@ -0,0 +1,84 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * This file was copied from the following newsgroup posting:
+ *
+ * Newsgroups: mod.std.unix
+ * Subject: public domain AT&T getopt source
+ * Date: 3 Nov 85 19:34:15 GMT
+ *
+ * Here's something you've all been waiting for:  the AT&T public domain
+ * source for getopt(3).  It is the code which was given out at the 1985
+ * UNIFORUM conference in Dallas.  I obtained it by electronic mail
+ * directly from AT&T.  The people there assure me that it is indeed
+ * in the public domain.
+ */
+
+#define EOF (-1)
+
+static int opterr = 1;
+static int optind = 1;
+static int optopt;
+static char *optarg;
+
+#undef fprintf
+
+static int getopt(int argc, char *argv[], char *opts)
+{
+static int sp = 1;
+int c;
+char *cp;
+
+if (sp == 1)
+if (optind >= argc ||
+argv[optind][0] != '-' || argv[optind][1] == '\0')
+return EOF;
+else if (!strcmp(argv[optind], "--")) {
+optind++;
+return EOF;
+}
+optopt = c = argv[optind][sp];
+if (c == ':' || (cp = strchr(opts, c)) == NULL) {
+fprintf(stderr, ": illegal option -- %c\n", c);
+if (argv[optind][++sp] == '\0') {
+optind++;
+sp = 1;
+}
+return '?';
+}
+if (*++cp == ':') {
+if (argv[optind][sp+1] != '\0')
+optarg = &argv[optind++][sp+1];
+else if(++optind >= argc) {
+fprintf(stderr, ": option requires an argument -- %c\n", c);
+sp = 1;
+return '?';
+} else
+optarg = argv[optind++];
+sp = 1;
+} else {
+if (argv[optind][++sp] == '\0') {
+sp = 1;
+optind++;
+}
+optarg = NULL;
+}
+
+return c;
+}
diff --git a/configure b/configure
index 7507f8f..b8bc8d9 100755
--- a/configure
+++ b/configure
@@ -1082,6 +1082,7 @@ HAVE_LIST="
 fork
 getaddrinfo
 gethrtime
+getopt
 GetProcessAffinityMask
 GetProcessMemoryInfo
 GetProcessTimes
@@ -2852,6 +2853,7 @@ check_func  fcntl
 check_func  fork
 check_func  getaddrinfo $network_extralibs
 check_func  gethrtime
+check_func  getopt
 check_func  getrusage
 check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
 check_func  gettimeofday
diff --git a/libavcodec/dct-test.c b/libavcodec/dct-test.c
index 4647642..ceff448 100644
--- a/libavcodec/dct-test.c
+++ b/libavcodec/dct-test.c
@@ -25,10 +25,13 @@
  * Started from sample code by Juan J. Sierralta P.
  */
 
+#include "config.h"
 #include 
 #include 
 #include 
+#if HAVE_UNISTD_H
 #include 
+#endif
 #include 
 
 #include "libavutil/cpu.h"
@@ -474,6 +477,10 @@ static void help(void)
"-t  speed test\n");
 }
 
+#if !HAVE_GETOPT
+#include "compat/getopt.c"
+#endif
+
 int main(int argc, char **argv)
 {
 int test_idct = 0, test_248_dct = 0;
diff --git a/libavcodec/fft-test.c b/libavcodec/fft-test.c
index 75941a1..1e46750 100644
--- a/libavcodec/fft-test.c
+++ b/libavcodec/fft-test.c
@@ -34,7 +34,9 @@
 #include "rdft.h"
 #endif
 #include 
+#if HAVE_UNISTD_H
 #include 
+#endif
 #include 
 #include 
 
@@ -229,6 +231,10 @@ enum tf_transform {
 TRANSFORM_DCT,
 };
 
+#if !HAVE_GETOPT
+#include "compat/getopt.c"
+#endif
+
 int main(int argc, char **argv)
 {
 FFTComplex *tab, *tab1, *tab_ref;
-- 
1.7.10

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Måns Rullgård
Alex Converse  writes:

> On Mon, Jul 9, 2012 at 1:44 PM, Måns Rullgård  wrote:
>> Derek Buitenhuis  writes:
>>
>>> On 09/07/2012 6:17 AM, Måns Rullgård wrote:
 I don't like this one bit.  It makes the code considerably more
 complicated only to allow running two minor tests on an obscure
 platform.

 Just make the tests conditional.
>>>
>>> -1
>>>
>>> Not OK with making FFT testing conditional.
>>
>> FFT is still tested by all the codecs that use it.  Please stop making
>> strawman arguments.
>
> But FFT test is used to separate problems in the FFT from problems the
> codec logic.

An FFT error will break all FFT-based codecs.  A codec-level error will
not.

The separate FFT test is mainly there to make sure a range of sizes work
correctly.  If they all work on those platforms that do test them, and
some sizes (those tested by codecs) work on a given platform, it is very
highly unlikely that other sizes will be broken on the latter platform.

Maybe you should at least _try_ to understand how the tests actually
work before making up silly arguments.

-- 
Måns Rullgård
m...@mansr.com
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Måns Rullgård
Alex Converse  writes:

> ob·scure adj \äb-ˈskyu̇r, əb-\
>
> Definition of OBSCURE
>
> 1
> a : dark, dim

Sure, for some meanings of those words.

> b : shrouded in or hidden by darkness

Definitely.

> 2
> : not readily understood or clearly expressed; also : mysterious

Oh yes.

A clear match for three distinct meanings of the word, and you still
think it's not a good description?

-- 
Måns Rullgård
m...@mansr.com
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Alex Converse
On Mon, Jul 9, 2012 at 1:44 PM, Måns Rullgård  wrote:
> Derek Buitenhuis  writes:
>
>> On 09/07/2012 6:17 AM, Måns Rullgård wrote:
>>> I don't like this one bit.  It makes the code considerably more
>>> complicated only to allow running two minor tests on an obscure
>>> platform.
>>>
>>> Just make the tests conditional.
>>
>> -1
>>
>> Not OK with making FFT testing conditional.
>
> FFT is still tested by all the codecs that use it.  Please stop making
> strawman arguments.
>

But FFT test is used to separate problems in the FFT from problems the
codec logic.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Måns Rullgård
Derek Buitenhuis  writes:

> On 09/07/2012 6:17 AM, Måns Rullgård wrote:
>> I don't like this one bit.  It makes the code considerably more
>> complicated only to allow running two minor tests on an obscure
>> platform.
>> 
>> Just make the tests conditional.
>
> -1
>
> Not OK with making FFT testing conditional.

FFT is still tested by all the codecs that use it.  Please stop making
strawman arguments.

-- 
Måns Rullgård
m...@mansr.com
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Anton Khirnov

After some discussion on IRC I think I'll drop this set and we'll go
back to the original Ronald's getopt() replacement, just moved to some
less controversial place like compat/.

I'll send a new patch tomorrow if nobody beats me to it.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Alex Converse
On Mon, Jul 9, 2012 at 7:55 AM, Luca Barbato  wrote:
> On 07/09/2012 04:35 PM, Derek Buitenhuis wrote:
>> On 09/07/2012 6:17 AM, Måns Rullgård wrote:
>>> I don't like this one bit.  It makes the code considerably more
>>> complicated only to allow running two minor tests on an obscure
>>> platform.
>>>
>>> Just make the tests conditional.

It's a very important test for diagnosing issues that manifest in the
AAC and Vorbis decoders.

>>
>> -1
>>
>> I'd hardly call one of the most (if not the most) widely used
>> platforms for Libav "obscure". Not OK with making FFT testing
>> conditional.

I agree with Derek.

>
> The supported platform for windows is and will be mingw.
>

And MSVC will be supported too soon, or should we go ahead and revert
all the MSVC patches that have been applied so far?

> I don't know how you think that giving some kind of support for an
> utterly broken compiler makes it not an obscure platform.
>

Why does the "brokenness" of the compiler make it "obscure"? It is one
of the most popular and well known compilers out there.

ob·scure adj \äb-ˈskyu̇r, əb-\

Definition of OBSCURE

1
a : dark, dim
b : shrouded in or hidden by darkness
c : not clearly seen or easily distinguished : faint 
2
: not readily understood or clearly expressed; also : mysterious
3
: relatively unknown: as
a : remote, secluded 
b : not prominent or famous 
4
: constituting the unstressed vowel \ə\ or having unstressed \ə\ as its value
- ob·scure·ly adverb
- ob·scure·ness noun

> That said, since it is an obscure platform having the best test coverage
> could be nice.
>

--Alex
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] MS Expression Encoder Screen decoder

2012-07-09 Thread Kostya Shishkov
On Sat, Jul 07, 2012 at 09:38:53AM -0700, Jason Garrett-Glaser wrote:
[...]

This should address most of your and Diego's comments.
>From fdd64b45b5e0ebf220ba39593d8bf9ff87083d8f Mon Sep 17 00:00:00 2001
From: Kostya Shishkov 
Date: Sat, 7 Jul 2012 13:21:52 +0200
Subject: [PATCH] MS Expression Encoder Screen decoder

---
 Changelog  |1 +
 doc/general.texi   |2 +
 libavcodec/Makefile|1 +
 libavcodec/allcodecs.c |1 +
 libavcodec/avcodec.h   |1 +
 libavcodec/mss4.c  |  657 
 libavformat/riff.c |1 +
 7 files changed, 664 insertions(+), 0 deletions(-)
 create mode 100644 libavcodec/mss4.c

diff --git a/Changelog b/Changelog
index 39ad8a3..44db4a1 100644
--- a/Changelog
+++ b/Changelog
@@ -31,6 +31,7 @@ version :
 - join audio filter
 - audio channel mapping filter
 - Microsoft ATC Screen decoder
+- Microsoft Expression Encoder Screen decoder
 
 
 version 0.8:
diff --git a/doc/general.texi b/doc/general.texi
index 4ea47b4..efa7809 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -533,6 +533,8 @@ following image formats are supported:
 @item lossless MJPEG @tab  X  @tab  X
 @item Microsoft ATC Screen   @tab @tab  X
 @tab Also known as Microsoft Screen 3.
+@item Microsoft Expression Encoder Screen  @tab @tab  X
+@tab Also known as Microsoft Titanium Screen 2.
 @item Microsoft RLE  @tab @tab  X
 @item Microsoft Screen 1 @tab @tab  X
 @tab Also known as Windows Media Video V7 Screen.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 77126a6..8222726 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -296,6 +296,7 @@ OBJS-$(CONFIG_MSA1_DECODER)+= mss3.o mss34dsp.o
 OBJS-$(CONFIG_MSS1_DECODER)+= mss1.o
 OBJS-$(CONFIG_MSVIDEO1_DECODER)+= msvideo1.o
 OBJS-$(CONFIG_MSZH_DECODER)+= lcldec.o
+OBJS-$(CONFIG_MTS2_DECODER)+= mss4.o mss34dsp.o
 OBJS-$(CONFIG_MXPEG_DECODER)   += mxpegdec.o mjpegdec.o mjpeg.o
 OBJS-$(CONFIG_NELLYMOSER_DECODER)  += nellymoserdec.o nellymoser.o
 OBJS-$(CONFIG_NELLYMOSER_ENCODER)  += nellymoserenc.o nellymoser.o \
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index cb08e33..7b28c34 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -160,6 +160,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER (MSS1, mss1);
 REGISTER_DECODER (MSVIDEO1, msvideo1);
 REGISTER_DECODER (MSZH, mszh);
+REGISTER_DECODER (MTS2, mts2);
 REGISTER_DECODER (MXPEG, mxpeg);
 REGISTER_DECODER (NUV, nuv);
 REGISTER_ENCDEC  (PAM, pam);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 2b70b96..cc1c797 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -257,6 +257,7 @@ enum CodecID {
 CODEC_ID_ZEROCODEC,
 CODEC_ID_MSS1,
 CODEC_ID_MSA1,
+CODEC_ID_MTS2,
 
 /* various PCM "codecs" */
 CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the start of audio codecs
diff --git a/libavcodec/mss4.c b/libavcodec/mss4.c
new file mode 100644
index 000..f03c296
--- /dev/null
+++ b/libavcodec/mss4.c
@@ -0,0 +1,657 @@
+/*
+ * Microsoft Screen 4 (aka Microsoft Expression Encoder Screen) decoder
+ * Copyright (c) 2012 Konstantin Shishkov
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Microsoft Screen 4 (aka Microsoft Titanium Screen 2,
+ * aka Microsoft Expression Encoder Screen) decoder
+ */
+
+#include "avcodec.h"
+#include "bytestream.h"
+#include "dsputil.h"
+#include "get_bits.h"
+#include "mss34dsp.h"
+#include "unary.h"
+
+#define HEADER_SIZE 8
+
+enum FrameType {
+INTRA_FRAME = 0,
+INTER_FRAME,
+SKIP_FRAME
+};
+
+enum BlockType {
+SKIP_BLOCK = 0,
+DCT_BLOCK,
+IMAGE_BLOCK,
+};
+
+static const uint8_t mss4_dc_vlc_lens[2][16] = {
+{ 0, 1, 5, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 },
+{ 0, 3, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0 }
+};
+
+static const uint8_t mss4_ac_vlc_lens[2][16] = {
+{ 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125 },
+{ 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119 }
+};
+
+static const uint8_t mss4_ac_vlc_syms[2][162] = {
+  { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x1

Re: [libav-devel] [PATCH 3/4] rtsp listen mode: make rtsp_open_transport_ctx visible out of rtsp.c (remove static)

2012-07-09 Thread Jordi Ortiz
>>
>> Would it be better something like: ?
>>
>> -
>> rtsp: convert rtsp_open_transport_ctx() to non-static.
>>
>> The RTSP listen mode, which is implemented in rtspdec.c, needs this
>> functionality and in consequence more visibility for
>> rtsp_open_transport_ctx() is needed.
>> -
>
>
> You can make it even simpler:
>
> --8<--
> rtsp: Make rtsp_open_transport_ctx() non-static
>
> This is required for the upcoming RTSP listen mode.
> --8<--
>
> This says all of it without being too wordy, don't you think?
>

Yes, you are right. More isn't always better =)
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] MS Expression Encoder Screen decoder

2012-07-09 Thread Diego Biurrun
On Mon, Jul 09, 2012 at 06:48:08PM +0200, Kostya Shishkov wrote:
> On Mon, Jul 09, 2012 at 11:46:17AM +0200, Diego Biurrun wrote:
> > On Sat, Jul 07, 2012 at 02:35:23PM +0200, Kostya Shishkov wrote:
> > > 
> > > --- a/Changelog
> > > +++ b/Changelog
> > > @@ -31,6 +31,7 @@ version :
> > >  - Microsoft ATC Screen decoder
> > > +- Microsoft Expression Encoder Screen decoder
> > >  
> > > --- a/doc/general.texi
> > > +++ b/doc/general.texi
> > > @@ -533,6 +533,8 @@ following image formats are supported:
> > >  @item Microsoft ATC Screen   @tab @tab  X
> > >  @tab Also known as Microsoft Screen 3.
> > > +@item Microsoft EE Screen@tab @tab  X
> > > +@tab Also known as Microsoft Titanium Screen 2.
> > 
> > These two names do not match.
> 
> ?

Expression Encoder vs. EE

Please use the long form in the documentation.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] MS Expression Encoder Screen decoder

2012-07-09 Thread Kostya Shishkov
On Mon, Jul 09, 2012 at 11:46:17AM +0200, Diego Biurrun wrote:
> On Sat, Jul 07, 2012 at 02:35:23PM +0200, Kostya Shishkov wrote:
> > 
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -31,6 +31,7 @@ version :
> >  - Microsoft ATC Screen decoder
> > +- Microsoft Expression Encoder Screen decoder
> >  
> > --- a/doc/general.texi
> > +++ b/doc/general.texi
> > @@ -533,6 +533,8 @@ following image formats are supported:
> >  @item Microsoft ATC Screen   @tab @tab  X
> >  @tab Also known as Microsoft Screen 3.
> > +@item Microsoft EE Screen@tab @tab  X
> > +@tab Also known as Microsoft Titanium Screen 2.
> 
> These two names do not match.

?
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 3/4] rtsp listen mode: make rtsp_open_transport_ctx visible out of rtsp.c (remove static)

2012-07-09 Thread Martin Storsjö

On Mon, 9 Jul 2012, Jordi Ortiz wrote:


Ok as well, but you might try to improve the commit message. You shouldn't try 
to cram everything into the first line - try to make that one as short as 
possible while still describing the commit. If you need to say more than that, 
add extra full sentences below.



Would it be better something like: ?

-
rtsp: convert rtsp_open_transport_ctx() to non-static.

The RTSP listen mode, which is implemented in rtspdec.c, needs this
functionality and in consequence more visibility for
rtsp_open_transport_ctx() is needed.
-


You can make it even simpler:

--8<--
rtsp: Make rtsp_open_transport_ctx() non-static

This is required for the upcoming RTSP listen mode.
--8<--

This says all of it without being too wordy, don't you think?

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] TechSmith Screen Codec 2 decoder

2012-07-09 Thread Kostya Shishkov
On Mon, Jul 09, 2012 at 08:06:27AM -0700, Jason Garrett-Glaser wrote:
> On Sun, Jul 8, 2012 at 9:42 PM, Kostya Shishkov
>  wrote:
> > On Sun, Jul 08, 2012 at 08:17:10PM -0700, Jason Garrett-Glaser wrote:
> >> > +#define UNQUANT(val, q) ((q * val + 0x80) >> 8)
> >>
> >> I'd call this DEQUANT, but that's just me.
> >
> > I don't have preferences here, so why not.
> >
> >> > +for (i = 0; i < 4; i++) {
> >> > +if (i & 1) {
> >> > +t0 = UNQUANT(q[1], in[0 * 4 + i]);
> >> > +t1 = UNQUANT(q[2], in[1 * 4 + i]);
> >> > +t2 = UNQUANT(q[1], in[2 * 4 + i]);
> >> > +t3 = UNQUANT(q[2], in[3 * 4 + i]);
> >> > +} else {
> >> > +t0 = UNQUANT(q[0], in[0 * 4 + i]);
> >> > +t1 = UNQUANT(q[1], in[1 * 4 + i]);
> >> > +t2 = UNQUANT(q[0], in[2 * 4 + i]);
> >> > +t3 = UNQUANT(q[1], in[3 * 4 + i]);
> >> > +}
> >>
> >> Branchless please?  Maybe q[0+(i&1)] or such?
> >
> > Done.
> >
> >> > +static const uint8_t tscc2_zigzag[16] = {
> >> > +   0,  1,  4,  8,
> >> > +   5,  2,  3,  6,
> >> > +   9, 12, 13, 10,
> >> > +   7, 11, 14, 15
> >> > +// 0,  4,  1,  2,
> >> > +// 5,  8, 12,  9,
> >> > +// 6,  3,  7, 10,
> >> > +//13, 14, 11, 15
> >> > +};
> >>
> >> Use an existing one if possible?
> >
> > We have several standard ones but they are all 8x8.
> 
> H.264's is 4x4 and I think it matches that?

It does but IMO making it common doesn't worth the effort.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 3/4] rtsp listen mode: make rtsp_open_transport_ctx visible out of rtsp.c (remove static)

2012-07-09 Thread Jordi Ortiz
> Ok as well, but you might try to improve the commit message. You shouldn't 
> try to cram everything into the first line - try to make that one as short as 
> possible while still describing the commit. If you need to say more than 
> that, add extra full sentences below.
>

Would it be better something like: ?

-
rtsp: convert rtsp_open_transport_ctx() to non-static.

The RTSP listen mode, which is implemented in rtspdec.c, needs this
functionality and in consequence more visibility for
rtsp_open_transport_ctx() is needed.
-
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] mss3: split DSP functions that are used in MTS2(MSS4) into separate file

2012-07-09 Thread Kostya Shishkov
On Mon, Jul 09, 2012 at 11:17:17AM +0200, Diego Biurrun wrote:
> On Mon, Jul 09, 2012 at 11:13:47AM +0200, Kostya Shishkov wrote:
> > On Mon, Jul 09, 2012 at 11:05:19AM +0200, Diego Biurrun wrote:
> > > On Mon, Jul 09, 2012 at 07:57:22AM +0200, Kostya Shishkov wrote:
> > > > ---
> > > > I also took the liberty to get rid of floats in matrix generation.
> > > 
> > > Shouldn't that go in a separate patch?
> > 
> > It was mostly a matter of interface change.
> 
> Whatever you prefer; push when you feel like it.

Done (with your comments taken into account)
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] mss3: use standard zigzag table

2012-07-09 Thread Kostya Shishkov
On Mon, Jul 09, 2012 at 02:19:27PM +0200, Luca Barbato wrote:
> On 07/09/2012 02:10 PM, Kostya Shishkov wrote:
> > On Mon, Jul 09, 2012 at 02:03:26PM +0200, Kostya Shishkov wrote:
> >> On Mon, Jul 09, 2012 at 02:01:40PM +0200, Luca Barbato wrote:
> >>> On 07/09/2012 01:42 PM, Kostya Shishkov wrote:
>  ---
>   libavcodec/mss3.c |   14 ++
>   1 files changed, 2 insertions(+), 12 deletions(-)
> 
> >>>
> >>> seems fine, is the table always defined? Otherwise add the proper deps.
> >>
> >> It's ff_zigzag_direct[] from dsputil.c which is always compiled.
> 
> Perfect then =)

Rebased over another patch and pushed
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Derek Buitenhuis
On 09/07/2012 10:55 AM, Luca Barbato wrote:
> I don't know how you think that giving some kind of support for an
> utterly broken compiler makes it not an obscure platform.

The fact that Chrome will be using it (and I bet Steam too) will
instantly make it widely used. :P

- Derek
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 3/3] RTMPE protocol support

2012-07-09 Thread Samuel Pitoiset
On Mon, Jul 9, 2012 at 4:45 PM, Martin Storsjö  wrote:
> Hi,
>
> When sending a patchset, please send it all as one git send-email
> invocation, or if not, please set the in-reply-to header properly, so that
> the mails get chained together properly. Now the 3 patches in this series
> have ended up as 3 different mail threads, making it much harder to locate
> them.

Okay, no problem.

>
> On Thu, 5 Jul 2012, Samuel Pitoiset wrote:
>
>> diff --git a/libavformat/rtmpenc.c b/libavformat/rtmpenc.c
>>
>> +static int rtmpe_read(URLContext *h, uint8_t *buf, int size)
>> +{
>> +RTMPEContext *rt = h->priv_data;
>> +int ret, off = 0;
>> +
>> +/* try to read one byte in nonblocking mode */
>> +rt->stream->flags |= AVIO_FLAG_NONBLOCK;
>> +ret = ffurl_read_complete(rt->stream, buf, 1);
>> +rt->stream->flags &= ~AVIO_FLAG_NONBLOCK;
>> +
>> +if (ret == AVERROR(EAGAIN)) {
>> +if (rt->out_size > 0) {
>> +/* send a new request when there is no incoming data to
>> handle */
>> +if ((ret = rtmpe_send_request(h)) < 0)
>> +return ret;
>> +}
>> +if (h->flags & AVIO_FLAG_NONBLOCK)
>> +return AVERROR(EAGAIN);
>> +} else if (ret < 0) {
>> +return ret;
>> +} else if (ret == 1) {
>> +off  += ret;
>> +size -= ret;
>> +}
>> +
>> +ret = ffurl_read(rt->stream, buf + off, size);
>> +if (ret < 0 && ret != AVERROR_EOF)
>> +return ret;
>
>
> This isn't good - what if there was 1 byte to read, but only one single
> byte? Then you'll block here without returning to the caller.
>
> This is different from the RTMPT case.
>
> Luckily for you, it's also very much simpler. You shouldn't need any of this
> complication. There's no need to buffer up the outgoing requests at all.
> Since RC4 is a stream cipher, you can just encrypt as many or few bytes you
> want to send in rtmpe_write, and send it right away. Then this function also
> becomes much simpler.
>
> The only case where you need to care about nonblocking mode is when
> publishing data. At the start of rtmpe_read, you probably want to do it like
> this:
>
>
> rt->stream->flags &= ~AVIO_FLAG_NONBLOCK;
> rt->stream->flags |= h->flags & AVIO_FLAG_NONBLOCK;
>
> That is, if the caller has set us to nonblocking mode, do the lower level
> read in the same mode. And if not, clear it.

Okay, I'll improve that part of code.

>
> I didn't find anything else that looked immediately wrong right now,
> although I didn't read it that thorhoughly. Looking forward to see the
> version with gnutls/nettle/gcrypt support.

Yes, I'm trying to add the GnuTLS support but it doesn't work yet.
However, event if it's not specified in the commit message, this patch
is still in work in progress state.



-- 
Best regards,
Samuel Pitoiset.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] TechSmith Screen Codec 2 decoder

2012-07-09 Thread Jason Garrett-Glaser
On Sun, Jul 8, 2012 at 9:42 PM, Kostya Shishkov
 wrote:
> On Sun, Jul 08, 2012 at 08:17:10PM -0700, Jason Garrett-Glaser wrote:
>> > +#define UNQUANT(val, q) ((q * val + 0x80) >> 8)
>>
>> I'd call this DEQUANT, but that's just me.
>
> I don't have preferences here, so why not.
>
>> > +for (i = 0; i < 4; i++) {
>> > +if (i & 1) {
>> > +t0 = UNQUANT(q[1], in[0 * 4 + i]);
>> > +t1 = UNQUANT(q[2], in[1 * 4 + i]);
>> > +t2 = UNQUANT(q[1], in[2 * 4 + i]);
>> > +t3 = UNQUANT(q[2], in[3 * 4 + i]);
>> > +} else {
>> > +t0 = UNQUANT(q[0], in[0 * 4 + i]);
>> > +t1 = UNQUANT(q[1], in[1 * 4 + i]);
>> > +t2 = UNQUANT(q[0], in[2 * 4 + i]);
>> > +t3 = UNQUANT(q[1], in[3 * 4 + i]);
>> > +}
>>
>> Branchless please?  Maybe q[0+(i&1)] or such?
>
> Done.
>
>> > +static const uint8_t tscc2_zigzag[16] = {
>> > +   0,  1,  4,  8,
>> > +   5,  2,  3,  6,
>> > +   9, 12, 13, 10,
>> > +   7, 11, 14, 15
>> > +// 0,  4,  1,  2,
>> > +// 5,  8, 12,  9,
>> > +// 6,  3,  7, 10,
>> > +//13, 14, 11, 15
>> > +};
>>
>> Use an existing one if possible?
>
> We have several standard ones but they are all 8x8.

H.264's is 4x4 and I think it matches that?

Jason
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Luca Barbato
On 07/09/2012 04:35 PM, Derek Buitenhuis wrote:
> On 09/07/2012 6:17 AM, Måns Rullgård wrote:
>> I don't like this one bit.  It makes the code considerably more
>> complicated only to allow running two minor tests on an obscure
>> platform.
>>
>> Just make the tests conditional.
> 
> -1
> 
> I'd hardly call one of the most (if not the most) widely used
> platforms for Libav "obscure". Not OK with making FFT testing
> conditional.

The supported platform for windows is and will be mingw.

I don't know how you think that giving some kind of support for an
utterly broken compiler makes it not an obscure platform.

That said, since it is an obscure platform having the best test coverage
could be nice.

lu

-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Diego Biurrun
On Mon, Jul 09, 2012 at 10:35:46AM -0400, Derek Buitenhuis wrote:
> On 09/07/2012 6:17 AM, Måns Rullgård wrote:
> > I don't like this one bit.  It makes the code considerably more
> > complicated only to allow running two minor tests on an obscure
> > platform.
> > 
> > Just make the tests conditional.
> 
> -1
> 
> I'd hardly call one of the most (if not the most) widely used
> platforms for Libav "obscure".

MSVC is not the most widely used platform for libav.  It cannot be,
since to date, libav has never worked at all on MSVC.  And while
Windows is still popular on desktop computers, the most widely-used
platform is now Android.

> Not OK with making FFT testing conditional.

Can we please take this step-by-step?  First let's get the thing to
compile.  After that we can work on getting all tests to run.
Conditional compilation will allow the former.  The latter can be
done afterwards or decided in the next trollwar, whatever.  Just
let's please not get hung up with details that do not concern us
immediately.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 3/3] RTMPE protocol support

2012-07-09 Thread Martin Storsjö

Hi,

When sending a patchset, please send it all as one git send-email 
invocation, or if not, please set the in-reply-to header properly, so that 
the mails get chained together properly. Now the 3 patches in this series 
have ended up as 3 different mail threads, making it much harder to locate 
them.


On Thu, 5 Jul 2012, Samuel Pitoiset wrote:


diff --git a/libavformat/rtmpenc.c b/libavformat/rtmpenc.c
+static int rtmpe_read(URLContext *h, uint8_t *buf, int size)
+{
+RTMPEContext *rt = h->priv_data;
+int ret, off = 0;
+
+/* try to read one byte in nonblocking mode */
+rt->stream->flags |= AVIO_FLAG_NONBLOCK;
+ret = ffurl_read_complete(rt->stream, buf, 1);
+rt->stream->flags &= ~AVIO_FLAG_NONBLOCK;
+
+if (ret == AVERROR(EAGAIN)) {
+if (rt->out_size > 0) {
+/* send a new request when there is no incoming data to handle */
+if ((ret = rtmpe_send_request(h)) < 0)
+return ret;
+}
+if (h->flags & AVIO_FLAG_NONBLOCK)
+return AVERROR(EAGAIN);
+} else if (ret < 0) {
+return ret;
+} else if (ret == 1) {
+off  += ret;
+size -= ret;
+}
+
+ret = ffurl_read(rt->stream, buf + off, size);
+if (ret < 0 && ret != AVERROR_EOF)
+return ret;


This isn't good - what if there was 1 byte to read, but only one single 
byte? Then you'll block here without returning to the caller.


This is different from the RTMPT case.

Luckily for you, it's also very much simpler. You shouldn't need any of 
this complication. There's no need to buffer up the outgoing requests at 
all. Since RC4 is a stream cipher, you can just encrypt as many or few 
bytes you want to send in rtmpe_write, and send it right away. Then this 
function also becomes much simpler.


The only case where you need to care about nonblocking mode is when 
publishing data. At the start of rtmpe_read, you probably want to do it 
like this:


rt->stream->flags &= ~AVIO_FLAG_NONBLOCK;
rt->stream->flags |= h->flags & AVIO_FLAG_NONBLOCK;

That is, if the caller has set us to nonblocking mode, do the lower level 
read in the same mode. And if not, clear it.



I didn't find anything else that looked immediately wrong right now, 
although I didn't read it that thorhoughly. Looking forward to see the 
version with gnutls/nettle/gcrypt support.


// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/4] fft-test: don't use getopt().

2012-07-09 Thread Derek Buitenhuis
On 09/07/2012 6:17 AM, Måns Rullgård wrote:
> I don't like this one bit.  It makes the code considerably more
> complicated only to allow running two minor tests on an obscure
> platform.
> 
> Just make the tests conditional.

-1

I'd hardly call one of the most (if not the most) widely used
platforms for Libav "obscure". Not OK with making FFT testing
conditional.

- Derek
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] tcp: add initial timeout limit for incomming connections

2012-07-09 Thread Martin Storsjö

On Wed, 4 Jul 2012, Jordi Ortiz wrote:


---
libavformat/tcp.c |   11 ++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 6a65860..e5be465 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -43,7 +43,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
char buf[256];
int ret;
socklen_t optlen;
-int timeout = 100;
+int timeout = 100, listen_timeout = -1;
char hostname[1024],proto[1024],path[1024];
char portstr[10];

@@ -59,6 +59,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
timeout = strtol(buf, NULL, 10);
}
+if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) {
+listen_timeout = strtol(buf, NULL, 10);
+}
}
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
@@ -87,6 +90,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
if (listen_socket) {
int fd1;
int reuse = 1;
+struct pollfd lp = {fd, POLLIN, 0};
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
if (ret) {
@@ -98,6 +102,11 @@ static int tcp_open(URLContext *h, const char *uri, int 
flags)
ret = ff_neterrno();
goto fail1;
}
+ret = poll(&lp, 1, listen_timeout);
+if (ret <= 0) {
+ret = AVERROR(ETIMEDOUT);
+goto fail1;
+}
fd1 = accept(fd, NULL, NULL);
if (fd1 < 0) {
ret = ff_neterrno();
--
1.7.10


Pushed with a minor fix - for poll, -1 is special as timeout value, 
passing -1000 doesn't work. Since this isn't easy to know as a caller 
(especially how you use it in rtspdec.c), I fixed it so that it interprets 
all negative values as infinite timeout.


// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 4/4] rtsp: listen mode

2012-07-09 Thread Luca Barbato
On 07/09/2012 04:00 PM, Martin Storsjö wrote:
> On Mon, 9 Jul 2012, Luca Barbato wrote:
> 
>> On 07/09/2012 03:53 PM, Martin Storsjö wrote:
>>> +av_strlcatf(message, sizeof(message), "Server: LibAVFormat %d\r\n",
>>
>> While at it Libavformat instead of LibAVFormat
> 
> If he switches to LIBAVFORMAT_IDENT, that (actually "Lavf") will be a
> part of it automatically, matching what we write elsewhere as well.
> 

Fine for me =)

lu

-- 

Luca Barbato
Gentoo/linux
http://dev.gentoo.org/~lu_zero

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 4/4] rtsp: listen mode

2012-07-09 Thread Martin Storsjö

On Wed, 4 Jul 2012, Jordi Ortiz wrote:


+static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl)
+{
+RTSPState *rt = s->priv_data;
+RTSPMessageHeader request = { 0 };
+int ret   = 0;
+char url[1024];
+RTSPStream *rtsp_st;
+char responseheaders[1024];
+int localport= -1;
+int transportidx = 0;
+
+ret = rtsp_read_request(s, &request, "SETUP");
+if (ret)
+return ret;
+rt->seq++;
+if (!request.nb_transports) {
+av_log(s, AV_LOG_ERROR, "No transport defined in SETUP\n");
+return AVERROR_INVALIDDATA;
+}
+for (transportidx = 0; transportidx < request.nb_transports;
+ transportidx++) {
+if (!request.transports[transportidx].mode_record
+|| (request.transports[transportidx].lower_transport
+!= RTSP_LOWER_TRANSPORT_UDP &&
+request.transports[transportidx].lower_transport
+!= RTSP_LOWER_TRANSPORT_TCP)) {
+av_log(s, AV_LOG_ERROR, "mode=record/receive not set or transport"
+   " protocol not supported (yet)\n");
+return AVERROR_INVALIDDATA;
+}
+}
+if (request.nb_transports > 1)
+av_log(s, AV_LOG_WARNING, "More than one transport not supported, "
+   "using first of all\n");
+if (strcmp(rt->rtsp_streams[0]->control_url,
+   controlurl)) {
+av_log(s, AV_LOG_ERROR, "Unable to find requested track\n");
+return AVERROR_STREAM_NOT_FOUND;
+}
+rtsp_st   = rt->rtsp_streams[0];
+localport = rt->rtp_port_min;
+
+if (request.transports[0].lower_transport
+== RTSP_LOWER_TRANSPORT_TCP) {
+rt->lower_transport = RTSP_LOWER_TRANSPORT_TCP;
+if ((ret = ff_rtsp_open_transport_ctx(s, rtsp_st))) {
+rtsp_send_reply(s, RTSP_STATUS_TRANSPORT, NULL, request.seq);
+return ret;
+}
+snprintf(responseheaders, sizeof(responseheaders), "Transport: "
+ "RTP/AVP/TCP;unicast;mode=receive;source=%s;interleaved=%d-%d"
+ "\r\n", host, request.transports[0].interleaved_min,
+ request.transports[0].interleaved_max);


Here you need to store interleaved_min/max into rtsp_st too, I think I 
already told you this in some earlier review?


Right now, receiving more than one stream over TCP is broken.


After fixing this and the other things I mentioned, I was able to receive 
streams from both avconv, QuickTime Broadcaster and Wirecast.


// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] ppc{,64}-darwin FATE failures

2012-07-09 Thread Sean McGovern
On Monday, July 9, 2012, Thibaut VARENE  wrote:
> On Fri, Jul 6, 2012 at 4:32 PM, Sean McGovern  wrote:
>>
>>
>> On Thursday, July 5, 2012, Måns Rullgård  wrote:
>>> Sean McGovern  writes:
>>>
 On Thursday, July 5, 2012, Måns Rullgård  wrote:
> Sean McGovern  writes:
>
>> Hi folks,
>>
>> It looks like the test failures we are seeing on these 2 build
>> configurations are false negatives. The checksums are correct, but
the
>> filename text is missing a * in front. This must be a faulty regexp
in
>> tests/md5.sh
>
> Which variant does it end up using?
>

 I don't have these setups myself (they're run by Thibaut VARÈNE) , but
I
 think this broke relatively recently -- which suggests it's the 2nd
 variant
 that uses 'command' that we changed in 00c78a0a.
>>>
>>> Without knowing which command is used and what its output actually looks
>>> like, there is nothing I can do.
>>>
>>
>> Hello Thibaut,
>
> Hi,
>
>> Is there any chance you could verify which of the MD5 checksum commands
in
>> tests/md5.she is being used on these PPC Darwin FATE runs?
>
> I'm not sure what I'm supposed to do there. Care to guide me a little? ;)
> Note that Mik has full access to this machine and to the testsuite
> running on this machine.
>

Hi Thibaut and Michael,

In the Libav source tree, tests/md5.sh contains 4 different ways of getting
an MD5 checksum for comparison with a known value. Recently, these tests
have been "failing" on PPC Darwin (my x86_64 versions run on 10.6 Snow
Leopard don't have the same failure). I need to know which of the 4
commands are being used on that run. This would most likely involve
commenting them out one-by-one and running 1 of the failing FATE tests.

-- Sean McG.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 4/4] rtsp: listen mode

2012-07-09 Thread Martin Storsjö

On Wed, 4 Jul 2012, Jordi Ortiz wrote:


---
libavformat/rtsp.c  |   30 ++-
libavformat/rtsp.h  |   12 ++
libavformat/rtspcodes.h |   14 ++
libavformat/rtspdec.c   |  549 ---
4 files changed, 566 insertions(+), 39 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index d4206a1..f98dc6b 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -63,7 +63,8 @@

#define RTSP_FLAG_OPTS(name, longname) \
{ name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC, 
"rtsp_flags" }, \
-{ "filter_src", "Only receive packets from the negotiated peer IP", 0, 
AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" }
+{ "filter_src", "Only receive packets from the negotiated peer IP", 0, 
AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" }, \
+{ "listen", "Wait for incoming connections", 0, AV_OPT_TYPE_CONST, 
{RTSP_FLAG_LISTEN}, 0, 0, DEC, "rtsp_flags" }

#define RTSP_MEDIATYPE_OPTS(name, longname) \
{ name, longname, OFFSET(media_type_mask), AV_OPT_TYPE_FLAGS, { (1 << 
(AVMEDIA_TYPE_DATA+1)) - 1 }, INT_MIN, INT_MAX, DEC, "allowed_media_types" }, \
@@ -83,6 +84,7 @@ const AVOption ff_rtsp_options[] = {
RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the 
server"),
{ "min_port", "Minimum local UDP port", OFFSET(rtp_port_min), 
AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
{ "max_port", "Maximum local UDP port", OFFSET(rtp_port_max), 
AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
+{ "timeout", "Maximum timeout (in seconds) to wait for incoming connections. -1 
is infinite. Implies flag listen", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {-1}, INT_MIN, 
INT_MAX, DEC },
{ NULL },
};

@@ -1714,14 +1716,24 @@ static int udp_read_packet(AVFormatContext *s, 
RTSPStream **prtsp_st,
}
#if CONFIG_RTSP_DEMUXER
if (tcp_fd != -1 && p[0].revents & POLLIN) {
-RTSPMessageHeader reply;
-
-ret = ff_rtsp_read_reply(s, &reply, NULL, 0, NULL);
-if (ret < 0)
-return ret;
-/* XXX: parse message */
-if (rt->state != RTSP_STATE_STREAMING)
-return 0;
+if (rt->rtsp_flags & RTSP_FLAG_LISTEN) {
+if (rt->state == RTSP_STATE_STREAMING) {
+if (!ff_rtsp_parse_streaming_commands(s))
+return AVERROR_EOF;
+else
+av_log(s, AV_LOG_WARNING,
+   "Unable to answer to TEARDOWN\n");
+} else
+return 0;
+} else {
+RTSPMessageHeader reply;
+ret = ff_rtsp_read_reply(s, &reply, NULL, 0, NULL);
+if (ret < 0)
+return ret;
+/* XXX: parse message */
+if (rt->state != RTSP_STATE_STREAMING)
+return 0;
+}
}
#endif
} else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 41bf8bb..a1dbf33 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -372,11 +372,17 @@ typedef struct RTSPState {
 * Minimum and maximum local UDP ports.
 */
int rtp_port_min, rtp_port_max;
+
+/**
+ * Timeout to wait for incoming connections.
+ */
+int initial_timeout;
} RTSPState;

#define RTSP_FLAG_FILTER_SRC  0x1/**< Filter incoming UDP packets -
  receive packets only from the right
  source address and port. */
+#define RTSP_FLAG_LISTEN 0x2 /**< Wait for incoming connections. */

/**
 * Describe a single stream, as identified by a single m= line block in the
@@ -529,6 +535,12 @@ int ff_rtsp_setup_input_streams(AVFormatContext *s, 
RTSPMessageHeader *reply);
int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr);

/**
+ * Parses RTSP commands (OPTIONS, PAUSE and TEARDOWN) on listen mode.
+ * @return 0 if SUCCESS and 1 if TEARDOWN Received
+ */
+int ff_rtsp_parse_streaming_commands(AVFormatContext *s);
+
+/**
 * Parse an SDP description of streams by populating an RTSPState struct
 * within the AVFormatContext; also allocate the RTP streams and the
 * pollfd array used for UDP streams.
diff --git a/libavformat/rtspcodes.h b/libavformat/rtspcodes.h
index 63ceb66..31ab336 100644
--- a/libavformat/rtspcodes.h
+++ b/libavformat/rtspcodes.h
@@ -37,4 +37,18 @@ RTSP_STATUS_SERVICE =503, /**< Service Unavailable */
RTSP_STATUS_VERSION =505, /**< RTSP Version not supported */
};

+enum RTSPMethod {
+DESCRIBE,
+ANNOUNCE,
+OPTIONS,
+SETUP,
+PLAY,
+PAUSE,
+TEARDOWN,
+GET_PARAMETER,
+SET_PARAMETER,
+REDIREC

  1   2   >