cook_parser.c 1.8 KB

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