apc.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. AVIOContext *pb = s->pb;
  32. AVStream *st;
  33. avio_rl32(pb); /* CRYO */
  34. avio_rl32(pb); /* _APC */
  35. avio_rl32(pb); /* 1.20 */
  36. st = av_new_stream(s, 0);
  37. if (!st)
  38. return AVERROR(ENOMEM);
  39. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  40. st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS;
  41. avio_rl32(pb); /* number of samples */
  42. st->codec->sample_rate = avio_rl32(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. avio_read(pb, st->codec->extradata, 2 * 4);
  50. st->codec->channels = 1;
  51. if (avio_rl32(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 ff_apc_demuxer = {
  68. .name = "apc",
  69. .long_name = NULL_IF_CONFIG_SMALL("CRYO APC format"),
  70. .read_probe = apc_probe,
  71. .read_header = apc_read_header,
  72. .read_packet = apc_read_packet,
  73. };