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.5KB

  1. /*
  2. * H261 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 h261_parser.c
  24. * h261codec.
  25. */
  26. #include "dsputil.h"
  27. #include "parser.h"
  28. static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
  29. int vop_found, i, j;
  30. uint32_t state;
  31. vop_found= pc->frame_start_found;
  32. state= pc->state;
  33. for(i=0; i<buf_size && !vop_found; i++){
  34. state= (state<<8) | buf[i];
  35. for(j=0; j<8; j++){
  36. if(((state>>j)&0xFFFFF) == 0x00010){
  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. for(j=0; j<8; j++){
  46. if(((state>>j)&0xFFFFF) == 0x00010){
  47. pc->frame_start_found=0;
  48. pc->state= state>>(2*8);
  49. return i-1;
  50. }
  51. }
  52. }
  53. }
  54. pc->frame_start_found= vop_found;
  55. pc->state= state;
  56. return END_NOT_FOUND;
  57. }
  58. static int h261_parse(AVCodecParserContext *s,
  59. AVCodecContext *avctx,
  60. uint8_t **poutbuf, int *poutbuf_size,
  61. const uint8_t *buf, int buf_size)
  62. {
  63. ParseContext *pc = s->priv_data;
  64. int next;
  65. next= h261_find_frame_end(pc,avctx, buf, buf_size);
  66. if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
  67. *poutbuf = NULL;
  68. *poutbuf_size = 0;
  69. return buf_size;
  70. }
  71. *poutbuf = (uint8_t *)buf;
  72. *poutbuf_size = buf_size;
  73. return next;
  74. }
  75. AVCodecParser h261_parser = {
  76. { CODEC_ID_H261 },
  77. sizeof(ParseContext),
  78. NULL,
  79. h261_parse,
  80. ff_parse_close,
  81. };