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.

79 lines
2.4KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "libavutil/intreadwrite.h"
  19. #include "avcodec.h"
  20. static int parse(AVCodecParserContext *s,
  21. AVCodecContext *avctx,
  22. const uint8_t **poutbuf, int *poutbuf_size,
  23. const uint8_t *buf, int buf_size)
  24. {
  25. unsigned int frame_type;
  26. unsigned int profile;
  27. if (buf_size < 3)
  28. return AVERROR_INVALIDDATA;
  29. frame_type = buf[0] & 1;
  30. profile = (buf[0] >> 1) & 7;
  31. if (profile > 3) {
  32. av_log(avctx, AV_LOG_ERROR, "Invalid profile %u.\n", profile);
  33. return AVERROR_INVALIDDATA;
  34. }
  35. avctx->profile = profile;
  36. s->key_frame = frame_type == 0;
  37. s->pict_type = frame_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
  38. s->format = AV_PIX_FMT_YUV420P;
  39. s->field_order = AV_FIELD_PROGRESSIVE;
  40. s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
  41. if (frame_type == 0) {
  42. unsigned int sync_code;
  43. unsigned int width, height;
  44. if (buf_size < 10)
  45. return AVERROR_INVALIDDATA;
  46. sync_code = AV_RL24(buf + 3);
  47. if (sync_code != 0x2a019d) {
  48. av_log(avctx, AV_LOG_ERROR, "Invalid sync code %06x.\n", sync_code);
  49. return AVERROR_INVALIDDATA;
  50. }
  51. width = AV_RL16(buf + 6) & 0x3fff;
  52. height = AV_RL16(buf + 8) & 0x3fff;
  53. s->width = width;
  54. s->height = height;
  55. s->coded_width = FFALIGN(width, 16);
  56. s->coded_height = FFALIGN(height, 16);
  57. }
  58. *poutbuf = buf;
  59. *poutbuf_size = buf_size;
  60. return buf_size;
  61. }
  62. AVCodecParser ff_vp8_parser = {
  63. .codec_ids = { AV_CODEC_ID_VP8 },
  64. .parser_parse = parse,
  65. };