h263_parser.c 2.3 KB

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