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.

81 lines
2.6KB

  1. /*
  2. * Shorten demuxer
  3. * Copyright (c) 2001 Fabrice Bellard
  4. * Copyright (c) 2005 Alex Beregszaszi
  5. * Copyright (c) 2015 Carl Eugen Hoyos
  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 "avformat.h"
  24. #include "rawdec.h"
  25. #include "libavcodec/golomb.h"
  26. static int shn_probe(const AVProbeData *p)
  27. {
  28. GetBitContext gb;
  29. int version, internal_ftype, channels, blocksize;
  30. if (AV_RB32(p->buf) != 0x616a6b67)
  31. return 0;
  32. version = p->buf[4];
  33. if (init_get_bits8(&gb, p->buf + 5, p->buf_size - 5 - AV_INPUT_BUFFER_PADDING_SIZE) < 0)
  34. return 0;
  35. if (!version) {
  36. internal_ftype = get_ur_golomb_shorten(&gb, 4);
  37. channels = get_ur_golomb_shorten(&gb, 0);
  38. blocksize = 256;
  39. } else {
  40. unsigned k;
  41. k = get_ur_golomb_shorten(&gb, 2);
  42. if (k > 31)
  43. return 0;
  44. internal_ftype = get_ur_golomb_shorten(&gb, k);
  45. k = get_ur_golomb_shorten(&gb, 2);
  46. if (k > 31)
  47. return 0;
  48. channels = get_ur_golomb_shorten(&gb, k);
  49. k = get_ur_golomb_shorten(&gb, 2);
  50. if (k > 31)
  51. return 0;
  52. blocksize = get_ur_golomb_shorten(&gb, k);
  53. }
  54. if (internal_ftype != 2 && internal_ftype != 3 && internal_ftype != 5)
  55. return 0;
  56. if (channels < 1 || channels > 8)
  57. return 0;
  58. if (blocksize < 1 || blocksize > 65535)
  59. return 0;
  60. return AVPROBE_SCORE_EXTENSION + 1;
  61. }
  62. FF_RAW_DEMUXER_CLASS(shorten)
  63. AVInputFormat ff_shorten_demuxer = {
  64. .name = "shn",
  65. .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
  66. .read_probe = shn_probe,
  67. .read_header = ff_raw_audio_read_header,
  68. .read_packet = ff_raw_read_partial_packet,
  69. .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS,
  70. .extensions = "shn",
  71. .raw_codec_id = AV_CODEC_ID_SHORTEN,
  72. .priv_data_size = sizeof(FFRawDemuxerContext),
  73. .priv_class = &shorten_demuxer_class,
  74. };