1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com> 3cabdff1aSopenharmony_ci * 4cabdff1aSopenharmony_ci * This file is part of FFmpeg. 5cabdff1aSopenharmony_ci * 6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 9cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 10cabdff1aSopenharmony_ci * 11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14cabdff1aSopenharmony_ci * Lesser General Public License for more details. 15cabdff1aSopenharmony_ci * 16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19cabdff1aSopenharmony_ci */ 20cabdff1aSopenharmony_ci 21cabdff1aSopenharmony_ci/** 22cabdff1aSopenharmony_ci * @file 23cabdff1aSopenharmony_ci * Cook audio parser 24cabdff1aSopenharmony_ci * 25cabdff1aSopenharmony_ci * Determines subpacket duration from extradata. 26cabdff1aSopenharmony_ci */ 27cabdff1aSopenharmony_ci 28cabdff1aSopenharmony_ci#include <stdint.h> 29cabdff1aSopenharmony_ci 30cabdff1aSopenharmony_ci#include "libavutil/intreadwrite.h" 31cabdff1aSopenharmony_ci#include "parser.h" 32cabdff1aSopenharmony_ci 33cabdff1aSopenharmony_citypedef struct CookParseContext { 34cabdff1aSopenharmony_ci int duration; 35cabdff1aSopenharmony_ci} CookParseContext; 36cabdff1aSopenharmony_ci 37cabdff1aSopenharmony_cistatic int cook_parse(AVCodecParserContext *s1, AVCodecContext *avctx, 38cabdff1aSopenharmony_ci const uint8_t **poutbuf, int *poutbuf_size, 39cabdff1aSopenharmony_ci const uint8_t *buf, int buf_size) 40cabdff1aSopenharmony_ci{ 41cabdff1aSopenharmony_ci CookParseContext *s = s1->priv_data; 42cabdff1aSopenharmony_ci 43cabdff1aSopenharmony_ci if (!s->duration && 44cabdff1aSopenharmony_ci avctx->extradata && avctx->extradata_size >= 8 && avctx->ch_layout.nb_channels) 45cabdff1aSopenharmony_ci s->duration = AV_RB16(avctx->extradata + 4) / avctx->ch_layout.nb_channels; 46cabdff1aSopenharmony_ci 47cabdff1aSopenharmony_ci s1->duration = s->duration; 48cabdff1aSopenharmony_ci 49cabdff1aSopenharmony_ci /* always return the full packet. this parser isn't doing any splitting or 50cabdff1aSopenharmony_ci combining, only setting packet duration */ 51cabdff1aSopenharmony_ci *poutbuf = buf; 52cabdff1aSopenharmony_ci *poutbuf_size = buf_size; 53cabdff1aSopenharmony_ci return buf_size; 54cabdff1aSopenharmony_ci} 55cabdff1aSopenharmony_ci 56cabdff1aSopenharmony_ciconst AVCodecParser ff_cook_parser = { 57cabdff1aSopenharmony_ci .codec_ids = { AV_CODEC_ID_COOK }, 58cabdff1aSopenharmony_ci .priv_data_size = sizeof(CookParseContext), 59cabdff1aSopenharmony_ci .parser_parse = cook_parse, 60cabdff1aSopenharmony_ci}; 61