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.

89 lines
2.3KB

  1. /*
  2. * Dirac parser
  3. *
  4. * Copyright (c) 2007 Marco Gerards <marco@gnu.org>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file dirac_parser.c
  24. * Dirac Parser
  25. * @author Marco Gerards <marco@gnu.org>
  26. */
  27. #include "parser.h"
  28. #define DIRAC_PARSE_INFO_PREFIX 0x42424344
  29. /**
  30. * Finds the end of the current frame in the bitstream.
  31. * @return the position of the first byte of the next frame or -1
  32. */
  33. static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
  34. {
  35. uint32_t state = pc->state;
  36. int i;
  37. for (i = 0; i < buf_size; i++) {
  38. state = (state << 8) | buf[i];
  39. if (state == DIRAC_PARSE_INFO_PREFIX) {
  40. pc->frame_start_found ^= 1;
  41. if (!pc->frame_start_found) {
  42. pc->state = -1;
  43. return i - 3;
  44. }
  45. }
  46. }
  47. pc->state = state;
  48. return END_NOT_FOUND;
  49. }
  50. static int dirac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
  51. const uint8_t **poutbuf, int *poutbuf_size,
  52. const uint8_t *buf, int buf_size)
  53. {
  54. ParseContext *pc = s->priv_data;
  55. int next;
  56. if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
  57. next = buf_size;
  58. }else{
  59. next = find_frame_end(pc, buf, buf_size);
  60. if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
  61. *poutbuf = NULL;
  62. *poutbuf_size = 0;
  63. return buf_size;
  64. }
  65. }
  66. *poutbuf = buf;
  67. *poutbuf_size = buf_size;
  68. return next;
  69. }
  70. AVCodecParser dirac_parser = {
  71. { CODEC_ID_DIRAC },
  72. sizeof(ParseContext),
  73. NULL,
  74. dirac_parse,
  75. ff_parse_close,
  76. };