• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/adx_parser.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011  Justin Ruggles
00003  *
00004  * This file is part of Libav.
00005  *
00006  * Libav is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * Libav is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with Libav; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00028 #include "libavutil/intreadwrite.h"
00029 #include "parser.h"
00030 #include "adx.h"
00031 
00032 typedef struct ADXParseContext {
00033     ParseContext pc;
00034     int header_size;
00035     int block_size;
00036     int remaining;
00037 } ADXParseContext;
00038 
00039 static int adx_parse(AVCodecParserContext *s1,
00040                            AVCodecContext *avctx,
00041                            const uint8_t **poutbuf, int *poutbuf_size,
00042                            const uint8_t *buf, int buf_size)
00043 {
00044     ADXParseContext *s = s1->priv_data;
00045     ParseContext *pc = &s->pc;
00046     int next = END_NOT_FOUND;
00047     int i;
00048     uint64_t state = pc->state64;
00049 
00050     if (!s->header_size) {
00051         for (i = 0; i < buf_size; i++) {
00052             state = (state << 8) | buf[i];
00053             /* check for fixed fields in ADX header for possible match */
00054             if ((state & 0xFFFF0000FFFFFF00) == 0x8000000003120400ULL) {
00055                 int channels    = state & 0xFF;
00056                 int header_size = ((state >> 32) & 0xFFFF) + 4;
00057                 if (channels > 0 && header_size >= 8) {
00058                     s->header_size = header_size;
00059                     s->block_size  = BLOCK_SIZE * channels;
00060                     s->remaining   = i - 7 + s->header_size + s->block_size;
00061                     break;
00062                 }
00063             }
00064         }
00065         pc->state64 = state;
00066     }
00067 
00068     if (s->header_size) {
00069         if (!s->remaining)
00070             s->remaining = s->block_size;
00071         if (s->remaining <= buf_size) {
00072             next = s->remaining;
00073             s->remaining = 0;
00074         } else
00075             s->remaining -= buf_size;
00076     }
00077 
00078     if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
00079         *poutbuf      = NULL;
00080         *poutbuf_size = 0;
00081         return buf_size;
00082     }
00083     *poutbuf = buf;
00084     *poutbuf_size = buf_size;
00085     return next;
00086 }
00087 
00088 AVCodecParser ff_adx_parser = {
00089     .codec_ids      = { CODEC_ID_ADPCM_ADX },
00090     .priv_data_size = sizeof(ADXParseContext),
00091     .parser_parse   = adx_parse,
00092     .parser_close   = ff_parse_close,
00093 };
Generated on Sat Mar 17 2012 12:57:42 for Libav by doxygen 1.7.1