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.

82 lines
2.4KB

  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. st->codec->extradata_size = 1;
  39. st->codec->extradata = av_mallocz(1 + FF_INPUT_BUFFER_PADDING_SIZE);
  40. if (!st->codec->extradata)
  41. return AVERROR(ENOMEM);
  42. st->codec->extradata[0] = 8 * st->codec->channels;
  43. c->data_end = avio_rb32(s->pb) + 32LL;
  44. st->duration = avio_rb32(s->pb);
  45. st->codec->sample_rate = avio_rb16(s->pb);
  46. avio_skip(s->pb, 22);
  47. avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
  48. return 0;
  49. }
  50. static int afc_read_packet(AVFormatContext *s, AVPacket *pkt)
  51. {
  52. AFCDemuxContext *c = s->priv_data;
  53. int64_t size;
  54. int ret;
  55. size = FFMIN(c->data_end - avio_tell(s->pb), 18 * 128);
  56. if (size <= 0)
  57. return AVERROR_EOF;
  58. ret = av_get_packet(s->pb, pkt, size);
  59. pkt->stream_index = 0;
  60. return ret;
  61. }
  62. AVInputFormat ff_afc_demuxer = {
  63. .name = "afc",
  64. .long_name = NULL_IF_CONFIG_SMALL("AFC"),
  65. .priv_data_size = sizeof(AFCDemuxContext),
  66. .read_header = afc_read_header,
  67. .read_packet = afc_read_packet,
  68. .extensions = "afc",
  69. .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
  70. };