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.

67 lines
1.9KB

  1. /*
  2. * VP9 compatible video decoder
  3. *
  4. * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
  5. * Copyright (C) 2013 Clément Bœsch <u pkh me>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include "libavutil/intreadwrite.h"
  24. #include "libavcodec/get_bits.h"
  25. #include "parser.h"
  26. static int parse(AVCodecParserContext *ctx,
  27. AVCodecContext *avctx,
  28. const uint8_t **out_data, int *out_size,
  29. const uint8_t *data, int size)
  30. {
  31. GetBitContext gb;
  32. int res, profile, keyframe;
  33. *out_data = data;
  34. *out_size = size;
  35. if ((res = init_get_bits8(&gb, data, size)) < 0)
  36. return size; // parsers can't return errors
  37. get_bits(&gb, 2); // frame marker
  38. profile = get_bits1(&gb);
  39. profile |= get_bits1(&gb) << 1;
  40. if (profile == 3) profile += get_bits1(&gb);
  41. if (get_bits1(&gb)) {
  42. keyframe = 0;
  43. } else {
  44. keyframe = !get_bits1(&gb);
  45. }
  46. if (!keyframe) {
  47. ctx->pict_type = AV_PICTURE_TYPE_P;
  48. ctx->key_frame = 0;
  49. } else {
  50. ctx->pict_type = AV_PICTURE_TYPE_I;
  51. ctx->key_frame = 1;
  52. }
  53. return size;
  54. }
  55. AVCodecParser ff_vp9_parser = {
  56. .codec_ids = { AV_CODEC_ID_VP9 },
  57. .parser_parse = parse,
  58. };