yading@10: /* yading@10: * Copyright (c) 2011 Justin Ruggles yading@10: * yading@10: * This file is part of Libav. yading@10: * yading@10: * Libav is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * Libav is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with Libav; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: /** yading@10: * @file yading@10: * ADX audio parser yading@10: * yading@10: * Splits packets into individual blocks. yading@10: */ yading@10: yading@10: #include "libavutil/intreadwrite.h" yading@10: #include "parser.h" yading@10: #include "adx.h" yading@10: yading@10: typedef struct ADXParseContext { yading@10: ParseContext pc; yading@10: int header_size; yading@10: int block_size; yading@10: int remaining; yading@10: } ADXParseContext; yading@10: yading@10: static int adx_parse(AVCodecParserContext *s1, yading@10: AVCodecContext *avctx, yading@10: const uint8_t **poutbuf, int *poutbuf_size, yading@10: const uint8_t *buf, int buf_size) yading@10: { yading@10: ADXParseContext *s = s1->priv_data; yading@10: ParseContext *pc = &s->pc; yading@10: int next = END_NOT_FOUND; yading@10: int i; yading@10: uint64_t state = pc->state64; yading@10: yading@10: if (!s->header_size) { yading@10: for (i = 0; i < buf_size; i++) { yading@10: state = (state << 8) | buf[i]; yading@10: /* check for fixed fields in ADX header for possible match */ yading@10: if ((state & 0xFFFF0000FFFFFF00) == 0x8000000003120400ULL) { yading@10: int channels = state & 0xFF; yading@10: int header_size = ((state >> 32) & 0xFFFF) + 4; yading@10: if (channels > 0 && header_size >= 8) { yading@10: s->header_size = header_size; yading@10: s->block_size = BLOCK_SIZE * channels; yading@10: s->remaining = i - 7 + s->header_size + s->block_size; yading@10: break; yading@10: } yading@10: } yading@10: } yading@10: pc->state64 = state; yading@10: } yading@10: yading@10: if (s->header_size) { yading@10: if (!s->remaining) yading@10: s->remaining = s->block_size; yading@10: if (s->remaining <= buf_size) { yading@10: next = s->remaining; yading@10: s->remaining = 0; yading@10: } else yading@10: s->remaining -= buf_size; yading@10: } yading@10: yading@10: if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) { yading@10: *poutbuf = NULL; yading@10: *poutbuf_size = 0; yading@10: return buf_size; yading@10: } yading@10: yading@10: s1->duration = BLOCK_SAMPLES; yading@10: yading@10: *poutbuf = buf; yading@10: *poutbuf_size = buf_size; yading@10: return next; yading@10: } yading@10: yading@10: AVCodecParser ff_adx_parser = { yading@10: .codec_ids = { AV_CODEC_ID_ADPCM_ADX }, yading@10: .priv_data_size = sizeof(ADXParseContext), yading@10: .parser_parse = adx_parse, yading@10: .parser_close = ff_parse_close, yading@10: };