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.

105 lines
3.1KB

  1. /*
  2. * Ensoniq Paris Audio File demuxer
  3. * Copyright (c) 2012 Paul B Mahol
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/intreadwrite.h"
  22. #include "avformat.h"
  23. #include "internal.h"
  24. #include "pcm.h"
  25. static int epaf_probe(AVProbeData *p)
  26. {
  27. if (((AV_RL32(p->buf) == MKTAG('f','a','p',' ') &&
  28. AV_RL32(p->buf + 8) == 1) ||
  29. (AV_RL32(p->buf) == MKTAG(' ','p','a','f') &&
  30. AV_RN32(p->buf + 8) == 0)) &&
  31. !AV_RN32(p->buf + 4) && AV_RN32(p->buf + 12) &&
  32. AV_RN32(p->buf + 20))
  33. return AVPROBE_SCORE_MAX / 4 * 3;
  34. return 0;
  35. }
  36. static int epaf_read_header(AVFormatContext *s)
  37. {
  38. int le, sample_rate, codec, channels;
  39. AVStream *st;
  40. avio_skip(s->pb, 4);
  41. if (avio_rl32(s->pb))
  42. return AVERROR_INVALIDDATA;
  43. le = avio_rl32(s->pb);
  44. if (le && le != 1)
  45. return AVERROR_INVALIDDATA;
  46. if (le) {
  47. sample_rate = avio_rl32(s->pb);
  48. codec = avio_rl32(s->pb);
  49. channels = avio_rl32(s->pb);
  50. } else {
  51. sample_rate = avio_rb32(s->pb);
  52. codec = avio_rb32(s->pb);
  53. channels = avio_rb32(s->pb);
  54. }
  55. if (!channels || !sample_rate)
  56. return AVERROR_INVALIDDATA;
  57. st = avformat_new_stream(s, NULL);
  58. if (!st)
  59. return AVERROR(ENOMEM);
  60. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  61. st->codec->channels = channels;
  62. st->codec->sample_rate = sample_rate;
  63. switch (codec) {
  64. case 0:
  65. st->codec->codec_id = le ? AV_CODEC_ID_PCM_S16LE : AV_CODEC_ID_PCM_S16BE;
  66. break;
  67. case 2:
  68. st->codec->codec_id = AV_CODEC_ID_PCM_S8;
  69. break;
  70. case 1:
  71. avpriv_request_sample(s, "24-bit Paris PCM format");
  72. default:
  73. return AVERROR_INVALIDDATA;
  74. }
  75. st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
  76. st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8;
  77. avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
  78. if (avio_skip(s->pb, 2024) < 0)
  79. return AVERROR_INVALIDDATA;
  80. return 0;
  81. }
  82. AVInputFormat ff_epaf_demuxer = {
  83. .name = "epaf",
  84. .long_name = NULL_IF_CONFIG_SMALL("Ensoniq Paris Audio File"),
  85. .read_probe = epaf_probe,
  86. .read_header = epaf_read_header,
  87. .read_packet = ff_pcm_read_packet,
  88. .read_seek = ff_pcm_read_seek,
  89. .extensions = "paf,fap",
  90. .flags = AVFMT_GENERIC_INDEX,
  91. };