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.

64 lines
2.0KB

  1. /*
  2. * Canopus common routines
  3. * Copyright (c) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <stdint.h>
  22. #include "libavutil/rational.h"
  23. #include "avcodec.h"
  24. #include "bytestream.h"
  25. #include "canopus.h"
  26. int ff_canopus_parse_info_tag(AVCodecContext *avctx,
  27. const uint8_t *src, size_t size)
  28. {
  29. GetByteContext gbc;
  30. int par_x, par_y, field_order;
  31. bytestream2_init(&gbc, src, size);
  32. /* Parse aspect ratio. */
  33. bytestream2_skip(&gbc, 8); // unknown, 16 bits 1
  34. par_x = bytestream2_get_le32(&gbc);
  35. par_y = bytestream2_get_le32(&gbc);
  36. if (par_x && par_y)
  37. av_reduce(&avctx->sample_aspect_ratio.num,
  38. &avctx->sample_aspect_ratio.den,
  39. par_x, par_y, 255);
  40. /* Short INFO tag (used in CLLC) has only AR data. */
  41. if (size == 0x18)
  42. return 0;
  43. bytestream2_skip(&gbc, 16); // unknown RDRT tag
  44. /* Parse FIEL tag. */
  45. bytestream2_skip(&gbc, 8); // 'FIEL' and 4 bytes 0
  46. field_order = bytestream2_get_le32(&gbc);
  47. switch (field_order) {
  48. case 0: avctx->field_order = AV_FIELD_TT; break;
  49. case 1: avctx->field_order = AV_FIELD_BB; break;
  50. case 2: avctx->field_order = AV_FIELD_PROGRESSIVE; break;
  51. }
  52. return 0;
  53. }