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.

120 lines
3.2KB

  1. /*
  2. * VC-1 and WMV3 parser
  3. * Copyright (c) 2006-2007 Konstantin Shishkov
  4. * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
  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 vc1_parser.c
  24. * VC-1 and WMV3 parser
  25. */
  26. #include "parser.h"
  27. #define VC1_PARSER_ONLY
  28. #include "vc1.h"
  29. /**
  30. * finds the end of the current frame in the bitstream.
  31. * @return the position of the first byte of the next frame, or -1
  32. */
  33. static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf,
  34. int buf_size) {
  35. int pic_found, i;
  36. uint32_t state;
  37. pic_found= pc->frame_start_found;
  38. state= pc->state;
  39. i=0;
  40. if(!pic_found){
  41. for(i=0; i<buf_size; i++){
  42. state= (state<<8) | buf[i];
  43. if(state == VC1_CODE_FRAME || state == VC1_CODE_FIELD){
  44. i++;
  45. pic_found=1;
  46. break;
  47. }
  48. }
  49. }
  50. if(pic_found){
  51. /* EOF considered as end of frame */
  52. if (buf_size == 0)
  53. return 0;
  54. for(; i<buf_size; i++){
  55. state= (state<<8) | buf[i];
  56. if(IS_MARKER(state) && state != VC1_CODE_FIELD && state != VC1_CODE_SLICE){
  57. pc->frame_start_found=0;
  58. pc->state=-1;
  59. return i-3;
  60. }
  61. }
  62. }
  63. pc->frame_start_found= pic_found;
  64. pc->state= state;
  65. return END_NOT_FOUND;
  66. }
  67. static int vc1_parse(AVCodecParserContext *s,
  68. AVCodecContext *avctx,
  69. uint8_t **poutbuf, int *poutbuf_size,
  70. const uint8_t *buf, int buf_size)
  71. {
  72. ParseContext *pc = s->priv_data;
  73. int next;
  74. if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
  75. next= buf_size;
  76. }else{
  77. next= vc1_find_frame_end(pc, buf, buf_size);
  78. if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
  79. *poutbuf = NULL;
  80. *poutbuf_size = 0;
  81. return buf_size;
  82. }
  83. }
  84. *poutbuf = (uint8_t *)buf;
  85. *poutbuf_size = buf_size;
  86. return next;
  87. }
  88. static int vc1_split(AVCodecContext *avctx,
  89. const uint8_t *buf, int buf_size)
  90. {
  91. int i;
  92. uint32_t state= -1;
  93. for(i=0; i<buf_size; i++){
  94. state= (state<<8) | buf[i];
  95. if(IS_MARKER(state) && state != VC1_CODE_SEQHDR && state != VC1_CODE_ENTRYPOINT)
  96. return i-3;
  97. }
  98. return 0;
  99. }
  100. AVCodecParser vc1_parser = {
  101. { CODEC_ID_VC1 },
  102. sizeof(ParseContext1),
  103. NULL,
  104. vc1_parse,
  105. ff_parse1_close,
  106. vc1_split,
  107. };