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.

80 lines
2.3KB

  1. /*
  2. * AFC 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/channel_layout.h"
  22. #include "avformat.h"
  23. #include "internal.h"
  24. typedef struct AFCDemuxContext {
  25. int64_t data_end;
  26. } AFCDemuxContext;
  27. static int afc_read_header(AVFormatContext *s)
  28. {
  29. AFCDemuxContext *c = s->priv_data;
  30. AVStream *st;
  31. st = avformat_new_stream(s, NULL);
  32. if (!st)
  33. return AVERROR(ENOMEM);
  34. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  35. st->codec->codec_id = AV_CODEC_ID_ADPCM_AFC;
  36. st->codec->channels = 2;
  37. st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
  38. if (ff_alloc_extradata(st->codec, 1))
  39. return AVERROR(ENOMEM);
  40. st->codec->extradata[0] = 8 * st->codec->channels;
  41. c->data_end = avio_rb32(s->pb) + 32LL;
  42. st->duration = avio_rb32(s->pb);
  43. st->codec->sample_rate = avio_rb16(s->pb);
  44. avio_skip(s->pb, 22);
  45. avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
  46. return 0;
  47. }
  48. static int afc_read_packet(AVFormatContext *s, AVPacket *pkt)
  49. {
  50. AFCDemuxContext *c = s->priv_data;
  51. int64_t size;
  52. int ret;
  53. size = FFMIN(c->data_end - avio_tell(s->pb), 18 * 128);
  54. if (size <= 0)
  55. return AVERROR_EOF;
  56. ret = av_get_packet(s->pb, pkt, size);
  57. pkt->stream_index = 0;
  58. return ret;
  59. }
  60. AVInputFormat ff_afc_demuxer = {
  61. .name = "afc",
  62. .long_name = NULL_IF_CONFIG_SMALL("AFC"),
  63. .priv_data_size = sizeof(AFCDemuxContext),
  64. .read_header = afc_read_header,
  65. .read_packet = afc_read_packet,
  66. .extensions = "afc",
  67. .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
  68. };