apc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * CRYO APC audio format demuxer
  3. * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
  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 <string.h>
  22. #include "avformat.h"
  23. static int apc_probe(AVProbeData *p)
  24. {
  25. if (!strncmp(p->buf, "CRYO_APC", 8))
  26. return AVPROBE_SCORE_MAX;
  27. return 0;
  28. }
  29. static int apc_read_header(AVFormatContext *s, AVFormatParameters *ap)
  30. {
  31. ByteIOContext *pb = s->pb;
  32. AVStream *st;
  33. get_le32(pb); /* CRYO */
  34. get_le32(pb); /* _APC */
  35. get_le32(pb); /* 1.20 */
  36. st = av_new_stream(s, 0);
  37. if (!st)
  38. return AVERROR(ENOMEM);
  39. st->codec->codec_type = CODEC_TYPE_AUDIO;
  40. st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS;
  41. get_le32(pb); /* number of samples */
  42. st->codec->sample_rate = get_le32(pb);
  43. st->codec->extradata_size = 2 * 4;
  44. st->codec->extradata = av_malloc(st->codec->extradata_size +
  45. FF_INPUT_BUFFER_PADDING_SIZE);
  46. if (!st->codec->extradata)
  47. return AVERROR(ENOMEM);
  48. /* initial predictor values for adpcm decoder */
  49. get_buffer(pb, st->codec->extradata, 2 * 4);
  50. st->codec->channels = 1;
  51. if (get_le32(pb))
  52. st->codec->channels = 2;
  53. st->codec->bits_per_coded_sample = 4;
  54. st->codec->bit_rate = st->codec->bits_per_coded_sample * st->codec->channels
  55. * st->codec->sample_rate;
  56. st->codec->block_align = 1;
  57. return 0;
  58. }
  59. #define MAX_READ_SIZE 4096
  60. static int apc_read_packet(AVFormatContext *s, AVPacket *pkt)
  61. {
  62. if (av_get_packet(s->pb, pkt, MAX_READ_SIZE) <= 0)
  63. return AVERROR(EIO);
  64. pkt->stream_index = 0;
  65. return 0;
  66. }
  67. AVInputFormat apc_demuxer = {
  68. "apc",
  69. NULL_IF_CONFIG_SMALL("CRYO APC format"),
  70. 0,
  71. apc_probe,
  72. apc_read_header,
  73. apc_read_packet,
  74. };