++/**
++ * 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,
++};
+Index: libavformat/mpegts.c
+===================================================================
+--- ffmpeg.orig/libavformat/mpegts.c (revision 20594)
++++ ffmpeg/libavformat/mpegts.c (working copy)
+@@ -499,7 +499,7 @@
+ { 0x04, CODEC_TYPE_AUDIO, CODEC_ID_MP3 },
+ { 0x0f, CODEC_TYPE_AUDIO, CODEC_ID_AAC },
+ { 0x10, CODEC_TYPE_VIDEO, CODEC_ID_MPEG4 },
+- { 0x11, CODEC_TYPE_AUDIO, CODEC_ID_AAC }, /* LATM syntax */
++ { 0x11, CODEC_TYPE_AUDIO, CODEC_ID_AAC_LATM }, /* LATM syntax */
+ { 0x1b, CODEC_TYPE_VIDEO, CODEC_ID_H264 },
+ { 0xd1, CODEC_TYPE_VIDEO, CODEC_ID_DIRAC },
+ { 0xea, CODEC_TYPE_VIDEO, CODEC_ID_VC1 },
+@@ -683,7 +683,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: libavformat/mpegts.h
+===================================================================
+--- ffmpeg.orig/libavformat/mpegts.h (revision 20594)
++++ ffmpeg/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: libavformat/mpeg.c
+===================================================================
+--- ffmpeg.orig/libavformat/mpeg.c (revision 20594)
++++ ffmpeg/libavformat/mpeg.c (working copy)
+@@ -282,7 +282,7 @@