You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1KB

  1. /*
  2. * IPU parser
  3. * Copyright (c) 2020 Paul B Mahol
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * IPU parser
  24. */
  25. #include "parser.h"
  26. typedef struct IPUParseContext {
  27. ParseContext pc;
  28. } IPUParseContext;
  29. static int ipu_parse(AVCodecParserContext *s, AVCodecContext *avctx,
  30. const uint8_t **poutbuf, int *poutbuf_size,
  31. const uint8_t *buf, int buf_size)
  32. {
  33. IPUParseContext *ipc = s->priv_data;
  34. uint32_t state = ipc->pc.state;
  35. int next = END_NOT_FOUND, i = 0;
  36. s->pict_type = AV_PICTURE_TYPE_NONE;
  37. s->duration = 1;
  38. *poutbuf_size = 0;
  39. *poutbuf = NULL;
  40. if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
  41. next = buf_size;
  42. } else {
  43. for (; i < buf_size; i++) {
  44. state = (state << 8) | buf[i];
  45. if (state == 0x1b0) {
  46. next = i + 1;
  47. break;
  48. }
  49. }
  50. ipc->pc.state = state;
  51. if (ff_combine_frame(&ipc->pc, next, &buf, &buf_size) < 0) {
  52. *poutbuf = NULL;
  53. *poutbuf_size = 0;
  54. return buf_size;
  55. }
  56. }
  57. *poutbuf = buf;
  58. *poutbuf_size = buf_size;
  59. return next;
  60. }
  61. AVCodecParser ff_ipu_parser = {
  62. .codec_ids = { AV_CODEC_ID_IPU },
  63. .priv_data_size = sizeof(IPUParseContext),
  64. .parser_parse = ipu_parse,
  65. .parser_close = ff_parse_close,
  66. };