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.

95 lines
2.8KB

  1. /*
  2. * H.261 parser
  3. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  4. * Copyright (c) 2004 Maarten Daniels
  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
  24. * H.261 parser
  25. */
  26. #include "parser.h"
  27. static int h261_find_frame_end(ParseContext *pc, AVCodecContext *avctx,
  28. const uint8_t *buf, int buf_size)
  29. {
  30. int vop_found, i, j;
  31. uint32_t state;
  32. vop_found = pc->frame_start_found;
  33. state = pc->state;
  34. for (i = 0; i < buf_size && !vop_found; i++) {
  35. state = (state << 8) | buf[i];
  36. for (j = 0; j < 8; j++) {
  37. if (((state >> j) & 0xFFFFF0) == 0x000100) {
  38. vop_found = 1;
  39. break;
  40. }
  41. }
  42. }
  43. if (vop_found) {
  44. for (; i < buf_size; i++) {
  45. state = (state << 8) | buf[i];
  46. for (j = 0; j < 8; j++) {
  47. if (((state >> j) & 0xFFFFF0) == 0x000100) {
  48. pc->frame_start_found = 0;
  49. pc->state = (state >> (3 * 8)) + 0xFF00;
  50. return i - 2;
  51. }
  52. }
  53. }
  54. }
  55. pc->frame_start_found = vop_found;
  56. pc->state = state;
  57. return END_NOT_FOUND;
  58. }
  59. static int h261_parse(AVCodecParserContext *s,
  60. AVCodecContext *avctx,
  61. const uint8_t **poutbuf, int *poutbuf_size,
  62. const uint8_t *buf, int buf_size)
  63. {
  64. ParseContext *pc = s->priv_data;
  65. int next;
  66. if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
  67. next = buf_size;
  68. } else {
  69. next = h261_find_frame_end(pc, avctx, buf, buf_size);
  70. if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
  71. *poutbuf = NULL;
  72. *poutbuf_size = 0;
  73. return buf_size;
  74. }
  75. }
  76. *poutbuf = buf;
  77. *poutbuf_size = buf_size;
  78. return next;
  79. }
  80. AVCodecParser ff_h261_parser = {
  81. .codec_ids = { AV_CODEC_ID_H261 },
  82. .priv_data_size = sizeof(ParseContext),
  83. .parser_parse = h261_parse,
  84. .parser_close = ff_parse_close,
  85. };