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.

115 lines
3.2KB

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