OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / contrib / ffmpeg / A00-latm.patch
index a286f4c..192d703 100644 (file)
@@ -1,28 +1,8 @@
-diff -Naur ffmpeg.orig/libavcodec/Makefile ffmpeg/libavcodec/Makefile
---- ffmpeg.orig/libavcodec/Makefile    2008-12-01 01:40:36.000000000 -0500
-+++ ffmpeg/libavcodec/Makefile 2009-02-21 08:25:13.000000000 -0500
-@@ -338,7 +338,7 @@
- OBJS-$(CONFIG_LIBDIRAC_DECODER)        += libdiracdec.o
- OBJS-$(CONFIG_LIBDIRAC_ENCODER)        += libdiracenc.o libdirac_libschro.o
- OBJS-$(CONFIG_LIBFAAC)                 += libfaac.o
--OBJS-$(CONFIG_LIBFAAD)                 += libfaad.o
-+OBJS-$(CONFIG_LIBFAAD)                 += libfaad.o latmaac.o
- OBJS-$(CONFIG_LIBGSM)                  += libgsm.o
- OBJS-$(CONFIG_LIBMP3LAME)              += libmp3lame.o
- OBJS-$(CONFIG_LIBSCHROEDINGER_DECODER) += libschroedingerdec.o libschroedinger.o libdirac_libschro.o
-@@ -350,7 +350,7 @@
- OBJS-$(CONFIG_LIBXVID)                 += libxvidff.o libxvid_rc.o
- # parsers
--OBJS-$(CONFIG_AAC_PARSER)              += aac_parser.o aac_ac3_parser.o mpeg4audio.o
-+OBJS-$(CONFIG_AAC_PARSER)              += aac_parser.o aac_ac3_parser.o mpeg4audio.o latm_parser.o
- OBJS-$(CONFIG_AC3_PARSER)              += ac3_parser.o ac3tab.o aac_ac3_parser.o
- OBJS-$(CONFIG_CAVSVIDEO_PARSER)        += cavs_parser.o
- OBJS-$(CONFIG_DCA_PARSER)              += dca_parser.o
-diff -Naur ffmpeg.orig/libavcodec/allcodecs.c ffmpeg/libavcodec/allcodecs.c
---- ffmpeg.orig/libavcodec/allcodecs.c 2008-12-01 01:40:36.000000000 -0500
-+++ ffmpeg/libavcodec/allcodecs.c      2009-02-21 08:25:13.000000000 -0500
-@@ -291,6 +291,7 @@
+Index: ffmpeg-r22950/libavcodec/allcodecs.c
+===================================================================
+--- ffmpeg-r22950/libavcodec/allcodecs.c       (revision 22950)
++++ ffmpeg-r22950/libavcodec/allcodecs.c       (working copy)
+@@ -334,6 +334,7 @@
      REGISTER_ENCDEC  (LIBDIRAC, libdirac);
      REGISTER_ENCODER (LIBFAAC, libfaac);
      REGISTER_DECODER (LIBFAAD, libfaad);
@@ -30,7 +10,7 @@ diff -Naur ffmpeg.orig/libavcodec/allcodecs.c ffmpeg/libavcodec/allcodecs.c
      REGISTER_ENCDEC  (LIBGSM, libgsm);
      REGISTER_ENCDEC  (LIBGSM_MS, libgsm_ms);
      REGISTER_ENCODER (LIBMP3LAME, libmp3lame);
-@@ -303,6 +304,7 @@
+@@ -349,6 +350,7 @@
  
      /* parsers */
      REGISTER_PARSER  (AAC, aac);
@@ -38,10 +18,11 @@ diff -Naur ffmpeg.orig/libavcodec/allcodecs.c ffmpeg/libavcodec/allcodecs.c
      REGISTER_PARSER  (AC3, ac3);
      REGISTER_PARSER  (CAVSVIDEO, cavsvideo);
      REGISTER_PARSER  (DCA, dca);
-diff -Naur ffmpeg.orig/libavcodec/avcodec.h ffmpeg/libavcodec/avcodec.h
---- ffmpeg.orig/libavcodec/avcodec.h   2008-12-01 01:40:36.000000000 -0500
-+++ ffmpeg/libavcodec/avcodec.h        2009-02-21 08:25:13.000000000 -0500
-@@ -264,6 +264,7 @@
+Index: ffmpeg-r22950/libavcodec/avcodec.h
+===================================================================
+--- ffmpeg-r22950/libavcodec/avcodec.h (revision 22950)
++++ ffmpeg-r22950/libavcodec/avcodec.h (working copy)
+@@ -286,6 +286,7 @@
      CODEC_ID_MP2= 0x15000,
      CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
      CODEC_ID_AAC,
@@ -49,142 +30,33 @@ diff -Naur ffmpeg.orig/libavcodec/avcodec.h ffmpeg/libavcodec/avcodec.h
      CODEC_ID_AC3,
      CODEC_ID_DTS,
      CODEC_ID_VORBIS,
-diff -Naur ffmpeg.orig/libavcodec/latm_parser.c ffmpeg/libavcodec/latm_parser.c
---- ffmpeg.orig/libavcodec/latm_parser.c       1969-12-31 19:00:00.000000000 -0500
-+++ ffmpeg/libavcodec/latm_parser.c    2009-02-21 08:25:13.000000000 -0500
-@@ -0,0 +1,128 @@
-+/*
-+ * LATM parser
-+ * Copyright (c) 2008 Paul Kendall <paul@kcbbs.gen.nz>
-+ *
-+ * This file is part of FFmpeg.
-+ *
-+ * FFmpeg is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU Lesser General Public
-+ * License as published by the Free Software Foundation; either
-+ * version 2.1 of the License, or (at your option) any later version.
-+ *
-+ * FFmpeg is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-+ * Lesser General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU Lesser General Public
-+ * License along with FFmpeg; if not, write to the Free Software
-+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-+ */
-+
-+/**
-+ * @file latm_parser.c
-+ * LATM parser
-+ */
-+
-+#include "parser.h"
-+
-+#define LATM_HEADER     0x56e000      // 0x2b7 (11 bits)
-+#define LATM_MASK       0xFFE000      // top 11 bits
-+#define LATM_SIZE_MASK  0x001FFF      // bottom 13 bits
-+
-+typedef struct LATMParseContext{
-+    ParseContext pc;
-+    int count;
-+} LATMParseContext;
-+
-+/**
-+ * finds the end of the current frame in the bitstream.
-+ * @return the position of the first byte of the next frame, or -1
-+ */
-+static int latm_find_frame_end(AVCodecParserContext *s1, const uint8_t *buf,
-+                               int buf_size) {
-+    LATMParseContext *s = s1->priv_data;
-+    ParseContext *pc = &s->pc;
-+    int pic_found, i;
-+    uint32_t state;
-+
-+    pic_found = pc->frame_start_found;
-+    state = pc->state;
-+
-+    i = 0;
-+    if(!pic_found){
-+        for(i=0; i<buf_size; i++){
-+            state = (state<<8) | buf[i];
-+            if((state & LATM_MASK) == LATM_HEADER){
-+                i++;
-+                s->count = - i;
-+                pic_found=1;
-+                break;
-+            }
-+        }
-+    }
-+
-+    if(pic_found){
-+        /* EOF considered as end of frame */
-+        if (buf_size == 0)
-+            return 0;
-+        if((state & LATM_SIZE_MASK) - s->count <= buf_size) {
-+            pc->frame_start_found = 0;
-+            pc->state = -1;
-+            return (state & LATM_SIZE_MASK) - s->count;
-+      }
-+    }
-+
-+    s->count += buf_size;
-+    pc->frame_start_found = pic_found;
-+    pc->state = state;
-+    return END_NOT_FOUND;
-+}
-+
-+static int latm_parse(AVCodecParserContext *s1,
-+                           AVCodecContext *avctx,
-+                           const uint8_t **poutbuf, int *poutbuf_size,
-+                           const uint8_t *buf, int buf_size)
-+{
-+    LATMParseContext *s = s1->priv_data;
-+    ParseContext *pc = &s->pc;
-+    int next;
-+
-+    if(s1->flags & PARSER_FLAG_COMPLETE_FRAMES){
-+        next = buf_size;
-+    }else{
-+        next = latm_find_frame_end(s1, buf, buf_size);
-+
-+        if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
-+            *poutbuf = NULL;
-+            *poutbuf_size = 0;
-+            return buf_size;
-+        }
-+    }
-+    *poutbuf = buf;
-+    *poutbuf_size = buf_size;
-+    return next;
-+}
-+
-+static int latm_split(AVCodecContext *avctx,
-+                           const uint8_t *buf, int buf_size)
-+{
-+    int i;
-+    uint32_t state= -1;
-+
-+    for(i=0; i<buf_size; i++){
-+        state= (state<<8) | buf[i];
-+        if((state & LATM_MASK) == LATM_HEADER)
-+            return i-2;
-+    }
-+    return 0;
-+}
-+
-+AVCodecParser aac_latm_parser = {
-+    { CODEC_ID_AAC_LATM },
-+    sizeof(LATMParseContext),
-+    NULL,
-+    latm_parse,
-+    ff_parse_close,
-+    latm_split,
-+};
-diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
---- ffmpeg.orig/libavcodec/latmaac.c   1969-12-31 19:00:00.000000000 -0500
-+++ ffmpeg/libavcodec/latmaac.c        2009-02-21 08:25:13.000000000 -0500
-@@ -0,0 +1,624 @@
+Index: ffmpeg-r22950/libavcodec/Makefile
+===================================================================
+--- ffmpeg-r22950/libavcodec/Makefile  (revision 22950)
++++ ffmpeg-r22950/libavcodec/Makefile  (working copy)
+@@ -505,7 +505,7 @@
+ OBJS-$(CONFIG_LIBDIRAC_DECODER)           += libdiracdec.o
+ OBJS-$(CONFIG_LIBDIRAC_ENCODER)           += libdiracenc.o libdirac_libschro.o
+ OBJS-$(CONFIG_LIBFAAC_ENCODER)            += libfaac.o
+-OBJS-$(CONFIG_LIBFAAD_DECODER)            += libfaad.o
++OBJS-$(CONFIG_LIBFAAD_DECODER)            += libfaad.o latmaac.o
+ OBJS-$(CONFIG_LIBGSM_DECODER)             += libgsm.o
+ OBJS-$(CONFIG_LIBGSM_ENCODER)             += libgsm.o
+ OBJS-$(CONFIG_LIBGSM_MS_DECODER)          += libgsm.o
+@@ -529,7 +529,7 @@
+ # parsers
+ OBJS-$(CONFIG_AAC_PARSER)              += aac_parser.o aac_ac3_parser.o \
+-                                          mpeg4audio.o
++                                          mpeg4audio.o latm_parser.o
+ OBJS-$(CONFIG_AC3_PARSER)              += ac3_parser.o ac3tab.o \
+                                           aac_ac3_parser.o
+ OBJS-$(CONFIG_CAVSVIDEO_PARSER)        += cavs_parser.o
+Index: ffmpeg-r22950/libavcodec/latmaac.c
+===================================================================
+--- ffmpeg-r22950/libavcodec/latmaac.c (revision 0)
++++ ffmpeg-r22950/libavcodec/latmaac.c (revision 0)
+@@ -0,0 +1,642 @@
 +/*
 + * copyright (c) 2008 Paul Kendall <paul@kcbbs.gen.nz>
 + *
@@ -217,7 +89,8 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +#include <sys/types.h>
 +
 +#include "parser.h"
-+#include "bitstream.h"
++#include "get_bits.h"
++#include "put_bits.h"
 +#include "mpeg4audio.h"
 +#include "neaacdec.h"
 +
@@ -294,14 +167,17 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +
 +static void readGASpecificConfig(struct AACConfig *cfg, GetBitContext *b, PutBitContext *o)
 +{
-+    int framelen_flag = get_bits(b, 1);
-+    put_bits(o, 1, framelen_flag);
-+    int dependsOnCoder = get_bits(b, 1);
-+    put_bits(o, 1, dependsOnCoder);
++    int framelen_flag;
++    int dependsOnCoder;
 +    int ext_flag;
 +    int delay;
 +    int layerNr;
 +
++    framelen_flag = get_bits(b, 1);
++    put_bits(o, 1, framelen_flag);
++    dependsOnCoder = get_bits(b, 1);
++    put_bits(o, 1, dependsOnCoder);
++
 +    if (dependsOnCoder) {
 +        delay = get_bits(b, 14);
 +        put_bits(o, 14, delay);
@@ -340,13 +216,16 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +
 +static int readAudioSpecificConfig(struct AACConfig *cfg, GetBitContext *b)
 +{
++    int ret;
++    int sbr_present;
 +    PutBitContext o;
++
 +    init_put_bits(&o, cfg->extra, sizeof(cfg->extra));
 +
 +    // returns the number of bits read
-+    int ret = 0;
-+    int sbr_present = -1;
 +
++    ret = 0;
++    sbr_present = -1;
 +    // object
 +    cfg->audioObjectType = get_bits(b, 5);
 +        put_bits(&o, 5, cfg->audioObjectType);
@@ -414,6 +293,8 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +    }
 +
 +    if (parser->audio_mux_version_A == 0) {
++        int frame_length_type;
++
 +        if (parser->audio_mux_version == 1) {
 +            parser->taraFullness = latm_get_value(b);
 +        }
@@ -441,7 +322,7 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +        }
 +
 +        // these are not needed... perhaps
-+        int frame_length_type = get_bits(b, 3);
++        frame_length_type = get_bits(b, 3);
 +        parser->frameLengthType = frame_length_type;
 +        if (frame_length_type == 0) {
 +            get_bits(b, 8);
@@ -450,10 +331,12 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +        } else if (frame_length_type == 3 ||
 +            frame_length_type == 4 ||
 +            frame_length_type == 5) {
-+            int celp_table_index = get_bits(b, 6);
++            int celp_table_index;
++            celp_table_index = get_bits(b, 6);
 +        } else if (frame_length_type == 6 ||
 +            frame_length_type == 7) {
-+            int hvxc_table_index = get_bits(b, 1);
++            int hvxc_table_index;
++            hvxc_table_index = get_bits(b, 1);
 +        }
 +
 +        // other data
@@ -464,8 +347,8 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +                parser->other_data_bits = latm_get_value(b);
 +            } else {
 +                // other data not present
-+                parser->other_data_bits = 0;
 +                int esc, tmp;
++                parser->other_data_bits = 0;
 +                do {
 +                    parser->other_data_bits <<= 8;
 +                    esc = get_bits(b, 1);
@@ -528,9 +411,10 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +
 +static int readAudioSyncStream(struct AACParser *parser, GetBitContext *b, int size, uint8_t *payload, int *payloadsize)
 +{
++    int muxlength;
 +    // ISO/IEC 14496-3 Table 1.28 - Syntax of AudioMuxElement()
 +    if (get_bits(b, 11) != 0x2b7) return -1;        // not LATM
-+    int muxlength = get_bits(b, 13);
++    muxlength = get_bits(b, 13);
 +
 +    if (3+muxlength > size) return 0;            // not enough data
 +
@@ -655,7 +539,11 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +
 +    // are we going to initialize from decoder specific info ?
 +    if (decoder->parser->config.extrasize > 0) {
-+        char ret = NeAACDecInit2(decoder->aac_decoder, (unsigned char*)decoder->parser->config.extra, decoder->parser->config.extrasize, &decoder->in_samplerate, &decoder->in_channels);
++        char ret;
++        unsigned long samplerate;
++
++        ret = NeAACDecInit2(decoder->aac_decoder, (unsigned char*)decoder->parser->config.extra, decoder->parser->config.extrasize, &samplerate, &decoder->in_channels);
++        decoder->in_samplerate = samplerate;
 +        if (ret < 0) {
 +            aac_filter_close(decoder);        // gone wrong ?
 +            return -1;
@@ -668,7 +556,7 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +    return 0;
 +}
 +
-+AACDecoder *aac_filter_create()
++static AACDecoder *aac_filter_create()
 +{
 +    AACDecoder *decoder = (AACDecoder *)av_malloc(sizeof(AACDecoder));
 +    decoder->parser = latm_create_parser();
@@ -677,14 +565,14 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +    return (void *)decoder;
 +}
 +
-+void aac_filter_destroy(AACDecoder *decoder)
++static void aac_filter_destroy(AACDecoder *decoder)
 +{
 +    aac_filter_close(decoder);
 +    latm_destroy_parser(decoder->parser);
 +    av_free(decoder);
 +}
 +
-+int aac_filter_receive(AACDecoder *decoder, void *out, int *out_size, uint8_t *data, int size)
++static int aac_filter_receive(AACDecoder *decoder, void *out, int *out_size, uint8_t *data, int size)
 +{
 +    uint8_t    tempbuf[32*1024];
 +    int        ret;
@@ -701,6 +589,9 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +    latm_write_data(decoder->parser, data, size);
 +
 +    do {
++        NeAACDecFrameInfo    info;
++        void *buf;
++
 +        ret = latm_parse_packet(decoder->parser, tempbuf, sizeof(tempbuf));
 +                if (ret < 0) {
 +                        latm_flush(decoder->parser);
@@ -727,8 +618,7 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +        //-------------------------------------------------------------------------
 +        // Decode samples
 +        //-------------------------------------------------------------------------
-+        NeAACDecFrameInfo    info;
-+        void *buf = NeAACDecDecode(decoder->aac_decoder, &info, data, size);
++        buf = NeAACDecDecode(decoder->aac_decoder, &info, data, size);
 +
 +        if (buf) {
 +            decoder->in_samplerate = info.samplerate;
@@ -758,7 +648,7 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +    return consumed;
 +}
 +
-+void aac_filter_getinfo(AACDecoder *decoder, int *sample_rate, int *channels)
++static void aac_filter_getinfo(AACDecoder *decoder, int *sample_rate, int *channels)
 +{
 +    if(!decoder->open) return;
 +    *sample_rate = decoder->in_samplerate;
@@ -768,6 +658,7 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +static int faac_decode_init(AVCodecContext *avctx)
 +{
 +    FAACContext *s = avctx->priv_data;
++    avctx->sample_fmt = SAMPLE_FMT_S16;
 +    avctx->frame_size = 360;
 +    avctx->sample_rate = 48000;
 +    avctx->channels = 2;
@@ -778,13 +669,13 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +
 +static int faac_decode_frame(AVCodecContext *avctx,
 +                             void *data, int *data_size,
-+                             uint8_t *buf, int buf_size)
++                             AVPacket *avpkt)
 +{
 +    FAACContext *s = avctx->priv_data;
 +    int ret;
 +
 +    if (s->decoder == NULL) faac_decode_init(avctx);
-+    ret = aac_filter_receive(s->decoder, data, data_size, buf, buf_size);
++    ret = aac_filter_receive(s->decoder, data, data_size, avpkt->data, avpkt->size);
 +    aac_filter_getinfo(s->decoder, &(avctx->sample_rate), &(avctx->channels));
 +    return ret;
 +}
@@ -808,11 +699,178 @@ diff -Naur ffmpeg.orig/libavcodec/latmaac.c ffmpeg/libavcodec/latmaac.c
 +    .decode = faac_decode_frame,
 +    .long_name = "AAC over LATM",
 +};
+Index: ffmpeg-r22950/libavcodec/latm_parser.c
+===================================================================
+--- ffmpeg-r22950/libavcodec/latm_parser.c     (revision 0)
++++ ffmpeg-r22950/libavcodec/latm_parser.c     (revision 0)
+@@ -0,0 +1,128 @@
++/*
++ * LATM parser
++ * Copyright (c) 2008 Paul Kendall <paul@kcbbs.gen.nz>
++ *
++ * This file is part of FFmpeg.
++ *
++ * FFmpeg is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU Lesser General Public
++ * License as published by the Free Software Foundation; either
++ * version 2.1 of the License, or (at your option) any later version.
++ *
++ * FFmpeg is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++ * Lesser General Public License for more details.
++ *
++ * You should have received a copy of the GNU Lesser General Public
++ * License along with FFmpeg; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
++ */
++
++/**
++ * @file latm_parser.c
++ * LATM parser
++ */
++
++#include "parser.h"
++
++#define LATM_HEADER     0x56e000      // 0x2b7 (11 bits)
++#define LATM_MASK       0xFFE000      // top 11 bits
++#define LATM_SIZE_MASK  0x001FFF      // bottom 13 bits
++
++typedef struct LATMParseContext{
++    ParseContext pc;
++    int count;
++} LATMParseContext;
++
++/**
++ * finds the end of the current frame in the bitstream.
++ * @return the position of the first byte of the next frame, or -1
++ */
++static int latm_find_frame_end(AVCodecParserContext *s1, const uint8_t *buf,
++                               int buf_size) {
++    LATMParseContext *s = s1->priv_data;
++    ParseContext *pc = &s->pc;
++    int pic_found, i;
++    uint32_t state;
++
++    pic_found = pc->frame_start_found;
++    state = pc->state;
++
++    i = 0;
++    if(!pic_found){
++        for(i=0; i<buf_size; i++){
++            state = (state<<8) | buf[i];
++            if((state & LATM_MASK) == LATM_HEADER){
++                i++;
++                s->count = - i;
++                pic_found=1;
++                break;
++            }
++        }
++    }
++
++    if(pic_found){
++        /* EOF considered as end of frame */
++        if (buf_size == 0)
++            return 0;
++        if((state & LATM_SIZE_MASK) - s->count <= buf_size) {
++            pc->frame_start_found = 0;
++            pc->state = -1;
++            return (state & LATM_SIZE_MASK) - s->count;
++      }
++    }
++
++    s->count += buf_size;
++    pc->frame_start_found = pic_found;
++    pc->state = state;
++    return END_NOT_FOUND;
++}
++
++static int latm_parse(AVCodecParserContext *s1,
++                           AVCodecContext *avctx,
++                           const uint8_t **poutbuf, int *poutbuf_size,
++                           const uint8_t *buf, int buf_size)
++{
++    LATMParseContext *s = s1->priv_data;
++    ParseContext *pc = &s->pc;
++    int next;
++
++    if(s1->flags & PARSER_FLAG_COMPLETE_FRAMES){
++        next = buf_size;
++    }else{
++        next = latm_find_frame_end(s1, buf, buf_size);
++
++        if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
++            *poutbuf = NULL;
++            *poutbuf_size = 0;
++            return buf_size;
++        }
++    }
++    *poutbuf = buf;
++    *poutbuf_size = buf_size;
++    return next;
++}
++
++static int latm_split(AVCodecContext *avctx,
++                           const uint8_t *buf, int buf_size)
++{
++    int i;
++    uint32_t state= -1;
++
++    for(i=0; i<buf_size; i++){
++        state= (state<<8) | buf[i];
++        if((state & LATM_MASK) == LATM_HEADER)
++            return i-2;
++    }
++    return 0;
++}
 +
-diff -Naur ffmpeg.orig/libavformat/mpeg.c ffmpeg/libavformat/mpeg.c
---- ffmpeg.orig/libavformat/mpeg.c     2008-10-02 12:03:00.000000000 -0400
-+++ ffmpeg/libavformat/mpeg.c  2009-02-21 08:25:13.000000000 -0500
-@@ -281,7 +281,7 @@
++AVCodecParser aac_latm_parser = {
++    { CODEC_ID_AAC_LATM },
++    sizeof(LATMParseContext),
++    NULL,
++    latm_parse,
++    ff_parse_close,
++    latm_split,
++};
+Index: ffmpeg-r22950/libavformat/mpegts.c
+===================================================================
+--- ffmpeg-r22950/libavformat/mpegts.c (revision 22950)
++++ ffmpeg-r22950/libavformat/mpegts.c (working copy)
+@@ -497,7 +497,7 @@
+     { 0x04, AVMEDIA_TYPE_AUDIO,        CODEC_ID_MP3 },
+     { 0x0f, AVMEDIA_TYPE_AUDIO,        CODEC_ID_AAC },
+     { 0x10, AVMEDIA_TYPE_VIDEO,      CODEC_ID_MPEG4 },
+-  //{ 0x11, AVMEDIA_TYPE_AUDIO,        CODEC_ID_AAC }, /* LATM syntax */
++    { 0x11, AVMEDIA_TYPE_AUDIO,   CODEC_ID_AAC_LATM }, /* LATM syntax */
+     { 0x1b, AVMEDIA_TYPE_VIDEO,       CODEC_ID_H264 },
+     { 0xd1, AVMEDIA_TYPE_VIDEO,      CODEC_ID_DIRAC },
+     { 0xea, AVMEDIA_TYPE_VIDEO,        CODEC_ID_VC1 },
+@@ -684,7 +684,7 @@
+                     if ((!pes->st && pes->stream->nb_streams == MAX_STREAMS) ||
+                         (pes->st && pes->st->discard == AVDISCARD_ALL) ||
+-                        code == 0x1be) /* padding_stream */
++                        code == 0x1be || code == 0x1fa) /* padding_stream */
+                         goto skip;
+                     /* stream not present in PMT */
+Index: ffmpeg-r22950/libavformat/mpegts.h
+===================================================================
+--- ffmpeg-r22950/libavformat/mpegts.h (revision 22950)
++++ ffmpeg-r22950/libavformat/mpegts.h (working copy)
+@@ -49,6 +49,7 @@
+ #define STREAM_TYPE_PRIVATE_DATA    0x06
+ #define STREAM_TYPE_AUDIO_AAC       0x0f
+ #define STREAM_TYPE_VIDEO_MPEG4     0x10
++#define STREAM_TYPE_AUDIO_AAC_LATM  0x11
+ #define STREAM_TYPE_VIDEO_H264      0x1b
+ #define STREAM_TYPE_VIDEO_VC1       0xea
+ #define STREAM_TYPE_VIDEO_DIRAC     0xd1
+Index: ffmpeg-r22950/libavformat/mpeg.c
+===================================================================
+--- ffmpeg-r22950/libavformat/mpeg.c   (revision 22950)
++++ ffmpeg-r22950/libavformat/mpeg.c   (working copy)
+@@ -287,7 +287,7 @@
      /* find matching stream */
      if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
            (startcode >= 0x1e0 && startcode <= 0x1ef) ||
@@ -821,19 +879,20 @@ diff -Naur ffmpeg.orig/libavformat/mpeg.c ffmpeg/libavformat/mpeg.c
          goto redo;
      if (ppos) {
          *ppos = url_ftell(s->pb) - 4;
-@@ -441,6 +441,9 @@
+@@ -454,6 +454,9 @@
          } else if(es_type == STREAM_TYPE_AUDIO_AAC){
              codec_id = CODEC_ID_AAC;
-             type = CODEC_TYPE_AUDIO;
+             type = AVMEDIA_TYPE_AUDIO;
 +        } else if(es_type == STREAM_TYPE_AUDIO_AAC_LATM){
 +            codec_id = CODEC_ID_AAC_LATM;
 +            type = CODEC_TYPE_AUDIO;
          } else if(es_type == STREAM_TYPE_VIDEO_MPEG4){
              codec_id = CODEC_ID_MPEG4;
-             type = CODEC_TYPE_VIDEO;
-diff -Naur ffmpeg.orig/libavformat/mpeg.h ffmpeg/libavformat/mpeg.h
---- ffmpeg.orig/libavformat/mpeg.h     2008-08-31 03:39:47.000000000 -0400
-+++ ffmpeg/libavformat/mpeg.h  2009-02-21 08:25:13.000000000 -0500
+             type = AVMEDIA_TYPE_VIDEO;
+Index: ffmpeg-r22950/libavformat/mpeg.h
+===================================================================
+--- ffmpeg-r22950/libavformat/mpeg.h   (revision 22950)
++++ ffmpeg-r22950/libavformat/mpeg.h   (working copy)
 @@ -53,6 +53,7 @@
  #define STREAM_TYPE_PRIVATE_DATA    0x06
  #define STREAM_TYPE_AUDIO_AAC       0x0f
@@ -842,45 +901,3 @@ diff -Naur ffmpeg.orig/libavformat/mpeg.h ffmpeg/libavformat/mpeg.h
  #define STREAM_TYPE_VIDEO_H264      0x1b
  
  #define STREAM_TYPE_AUDIO_AC3       0x81
-diff -Naur ffmpeg.orig/libavformat/mpegts.c ffmpeg/libavformat/mpegts.c
---- ffmpeg.orig/libavformat/mpegts.c   2008-10-02 12:28:58.000000000 -0400
-+++ ffmpeg/libavformat/mpegts.c        2009-02-21 08:25:13.000000000 -0500
-@@ -625,6 +625,7 @@
-         case STREAM_TYPE_VIDEO_VC1:
-         case STREAM_TYPE_VIDEO_DIRAC:
-         case STREAM_TYPE_AUDIO_AAC:
-+        case STREAM_TYPE_AUDIO_AAC_LATM:
-         case STREAM_TYPE_AUDIO_AC3:
-         case STREAM_TYPE_AUDIO_DTS:
-         case STREAM_TYPE_AUDIO_HDMV_DTS:
-@@ -847,7 +848,7 @@
-                     code = pes->header[3] | 0x100;
-                     if (!((code >= 0x1c0 && code <= 0x1df) ||
-                           (code >= 0x1e0 && code <= 0x1ef) ||
--                          (code == 0x1bd) || (code == 0x1fd)))
-+                          (code == 0x1bd) || (code == 0x1fa) || (code == 0x1fd)))
-                         goto skip;
-                     if (!pes->st) {
-                         /* allocate stream */
-@@ -968,6 +969,10 @@
-         codec_type = CODEC_TYPE_AUDIO;
-         codec_id = CODEC_ID_AAC;
-         break;
-+    case STREAM_TYPE_AUDIO_AAC_LATM:
-+        codec_type = CODEC_TYPE_AUDIO;
-+        codec_id = CODEC_ID_AAC_LATM;
-+        break;
-     case STREAM_TYPE_AUDIO_AC3:
-         codec_type = CODEC_TYPE_AUDIO;
-         codec_id = CODEC_ID_AC3;
-diff -Naur ffmpeg.orig/libavformat/mpegts.h ffmpeg/libavformat/mpegts.h
---- ffmpeg.orig/libavformat/mpegts.h   2008-08-31 03:39:47.000000000 -0400
-+++ ffmpeg/libavformat/mpegts.h        2009-02-21 08:25:13.000000000 -0500
-@@ -50,6 +50,7 @@
- #define STREAM_TYPE_PRIVATE_DATA    0x06
- #define STREAM_TYPE_AUDIO_AAC       0x0f
- #define STREAM_TYPE_VIDEO_MPEG4     0x10
-+#define STREAM_TYPE_AUDIO_AAC_LATM  0x11
- #define STREAM_TYPE_VIDEO_H264      0x1b
- #define STREAM_TYPE_VIDEO_VC1       0xea
- #define STREAM_TYPE_VIDEO_DIRAC     0xd1