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.

92 lines
2.4KB

  1. /*
  2. * H.263 parser
  3. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  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. * H.263 parser
  24. */
  25. #include "parser.h"
  26. #include "h263_parser.h"
  27. int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
  28. int vop_found, i;
  29. uint32_t state;
  30. vop_found= pc->frame_start_found;
  31. state= pc->state;
  32. i=0;
  33. if(!vop_found){
  34. for(i=0; i<buf_size; i++){
  35. state= (state<<8) | buf[i];
  36. if(state>>(32-22) == 0x20){
  37. i++;
  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. if(state>>(32-22) == 0x20){
  47. pc->frame_start_found=0;
  48. pc->state=-1;
  49. return i-3;
  50. }
  51. }
  52. }
  53. pc->frame_start_found= vop_found;
  54. pc->state= state;
  55. return END_NOT_FOUND;
  56. }
  57. static int h263_parse(AVCodecParserContext *s,
  58. AVCodecContext *avctx,
  59. const uint8_t **poutbuf, int *poutbuf_size,
  60. const uint8_t *buf, int buf_size)
  61. {
  62. ParseContext *pc = s->priv_data;
  63. int next;
  64. next= ff_h263_find_frame_end(pc, buf, buf_size);
  65. if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
  66. *poutbuf = NULL;
  67. *poutbuf_size = 0;
  68. return buf_size;
  69. }
  70. *poutbuf = buf;
  71. *poutbuf_size = buf_size;
  72. return next;
  73. }
  74. AVCodecParser ff_h263_parser = {
  75. .codec_ids = { AV_CODEC_ID_H263 },
  76. .priv_data_size = sizeof(ParseContext),
  77. .parser_parse = h263_parse,
  78. .parser_close = ff_parse_close,
  79. };