h261_parser.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 libavcodec/h261_parser.c
  24. * h261codec.
  25. */
  26. #include "parser.h"
  27. static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
  28. int vop_found, i, j;
  29. uint32_t state;
  30. vop_found= pc->frame_start_found;
  31. state= pc->state;
  32. for(i=0; i<buf_size && !vop_found; i++){
  33. state= (state<<8) | buf[i];
  34. for(j=0; j<8; j++){
  35. if(((state>>j)&0xFFFFF0) == 0x000100){
  36. vop_found=1;
  37. break;
  38. }
  39. }
  40. }
  41. if(vop_found){
  42. for(; i<buf_size; i++){
  43. state= (state<<8) | buf[i];
  44. for(j=0; j<8; j++){
  45. if(((state>>j)&0xFFFFF0) == 0x000100){
  46. pc->frame_start_found=0;
  47. pc->state= (state>>(3*8))+0xFF00;
  48. return i-2;
  49. }
  50. }
  51. }
  52. }
  53. pc->frame_start_found= vop_found;
  54. pc->state= state;
  55. return END_NOT_FOUND;
  56. }
  57. static int h261_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= h261_find_frame_end(pc,avctx, 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 h261_parser = {
  75. { CODEC_ID_H261 },
  76. sizeof(ParseContext),
  77. NULL,
  78. h261_parse,
  79. ff_parse_close,
  80. };