yading@10: /* yading@10: * Copyright (c) 2012 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: * GSM audio parser yading@10: * yading@10: * Splits packets into individual blocks. yading@10: */ yading@10: yading@10: #include "parser.h" yading@10: #include "gsm.h" yading@10: yading@10: typedef struct GSMParseContext { yading@10: ParseContext pc; yading@10: int block_size; yading@10: int duration; yading@10: int remaining; yading@10: } GSMParseContext; yading@10: yading@10: static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx, yading@10: const uint8_t **poutbuf, int *poutbuf_size, yading@10: const uint8_t *buf, int buf_size) yading@10: { yading@10: GSMParseContext *s = s1->priv_data; yading@10: ParseContext *pc = &s->pc; yading@10: int next; yading@10: yading@10: if (!s->block_size) { yading@10: switch (avctx->codec_id) { yading@10: case AV_CODEC_ID_GSM: yading@10: s->block_size = GSM_BLOCK_SIZE; yading@10: s->duration = GSM_FRAME_SIZE; yading@10: break; yading@10: case AV_CODEC_ID_GSM_MS: yading@10: s->block_size = GSM_MS_BLOCK_SIZE; yading@10: s->duration = GSM_FRAME_SIZE * 2; yading@10: break; yading@10: default: yading@10: *poutbuf = buf; yading@10: *poutbuf_size = buf_size; yading@10: av_log(avctx, AV_LOG_ERROR, "Invalid codec_id\n"); yading@10: return buf_size; yading@10: } yading@10: } yading@10: 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: next = END_NOT_FOUND; 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 = s->duration; yading@10: yading@10: *poutbuf = buf; yading@10: *poutbuf_size = buf_size; yading@10: return next; yading@10: } yading@10: yading@10: AVCodecParser ff_gsm_parser = { yading@10: .codec_ids = { AV_CODEC_ID_GSM, AV_CODEC_ID_GSM_MS }, yading@10: .priv_data_size = sizeof(GSMParseContext), yading@10: .parser_parse = gsm_parse, yading@10: .parser_close = ff_parse_close, yading@10: };