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.

117 lines
3.2KB

  1. /*
  2. * DPX parser
  3. * Copyright (c) 2013 Paul B Mahol
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; 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. * DPX parser
  24. */
  25. #include "libavutil/bswap.h"
  26. #include "libavutil/common.h"
  27. #include "parser.h"
  28. typedef struct DPXParseContext {
  29. ParseContext pc;
  30. uint32_t index;
  31. uint32_t fsize;
  32. uint32_t remaining_size;
  33. int is_be;
  34. } DPXParseContext;
  35. static int dpx_parse(AVCodecParserContext *s, AVCodecContext *avctx,
  36. const uint8_t **poutbuf, int *poutbuf_size,
  37. const uint8_t *buf, int buf_size)
  38. {
  39. DPXParseContext *d = s->priv_data;
  40. uint32_t state = d->pc.state;
  41. int next = END_NOT_FOUND;
  42. int i = 0;
  43. s->pict_type = AV_PICTURE_TYPE_I;
  44. *poutbuf_size = 0;
  45. if (buf_size == 0)
  46. next = 0;
  47. if (!d->pc.frame_start_found) {
  48. for (; i < buf_size; i++) {
  49. state = (state << 8) | buf[i];
  50. if (state == MKBETAG('S','D','P','X') ||
  51. state == MKTAG('S','D','P','X')) {
  52. d->pc.frame_start_found = 1;
  53. d->is_be = state == MKBETAG('S','D','P','X');
  54. d->index = 0;
  55. break;
  56. }
  57. }
  58. d->pc.state = state;
  59. } else {
  60. if (d->remaining_size) {
  61. i = FFMIN(d->remaining_size, buf_size);
  62. d->remaining_size -= i;
  63. if (d->remaining_size)
  64. goto flush;
  65. }
  66. }
  67. for (; d->pc.frame_start_found && i < buf_size; i++) {
  68. d->pc.state = (d->pc.state << 8) | buf[i];
  69. d->index++;
  70. if (d->index == 17) {
  71. d->fsize = d->is_be ? d->pc.state : av_bswap32(d->pc.state);
  72. if (d->fsize <= 1664) {
  73. d->pc.frame_start_found = 0;
  74. goto flush;
  75. }
  76. if (d->fsize > buf_size - i + 19)
  77. d->remaining_size = d->fsize - buf_size + i - 19;
  78. else
  79. i += d->fsize - 19;
  80. break;
  81. } else if (d->index > 17) {
  82. if (d->pc.state == MKBETAG('S','D','P','X') ||
  83. d->pc.state == MKTAG('S','D','P','X')) {
  84. next = i - 3;
  85. break;
  86. }
  87. }
  88. }
  89. flush:
  90. if (ff_combine_frame(&d->pc, next, &buf, &buf_size) < 0)
  91. return buf_size;
  92. d->pc.frame_start_found = 0;
  93. *poutbuf = buf;
  94. *poutbuf_size = buf_size;
  95. return next;
  96. }
  97. AVCodecParser ff_dpx_parser = {
  98. .codec_ids = { AV_CODEC_ID_DPX },
  99. .priv_data_size = sizeof(DPXParseContext),
  100. .parser_parse = dpx_parse,
  101. .parser_close = ff_parse_close,
  102. };