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

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