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.

99 lines
2.6KB

  1. /*
  2. * ADP demuxer
  3. * Copyright (c) 2013 James Almer
  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 "libavutil/intreadwrite.h"
  23. #include "avformat.h"
  24. #include "internal.h"
  25. static int adp_probe(AVProbeData *p)
  26. {
  27. int i, changes = 0;
  28. char last = 0;
  29. if (p->buf_size < 32)
  30. return 0;
  31. for (i = 0; i < p->buf_size - 3; i+=32) {
  32. if (p->buf[i] != p->buf[i+2] || p->buf[i+1] != p->buf[i+3])
  33. return 0;
  34. if (p->buf[i] != last)
  35. changes++;
  36. last = p->buf[i];
  37. }
  38. if (changes <= 1)
  39. return 0;
  40. return p->buf_size < 260 ? 1 : AVPROBE_SCORE_MAX / 4;
  41. }
  42. static int adp_read_header(AVFormatContext *s)
  43. {
  44. AVStream *st;
  45. st = avformat_new_stream(s, NULL);
  46. if (!st)
  47. return AVERROR(ENOMEM);
  48. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  49. st->codec->codec_id = AV_CODEC_ID_ADPCM_DTK;
  50. st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
  51. st->codec->channels = 2;
  52. st->codec->sample_rate = 48000;
  53. st->start_time = 0;
  54. if (s->pb->seekable)
  55. st->duration = av_get_audio_frame_duration(st->codec, avio_size(s->pb));
  56. avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
  57. return 0;
  58. }
  59. static int adp_read_packet(AVFormatContext *s, AVPacket *pkt)
  60. {
  61. int ret, size = 1024;
  62. if (url_feof(s->pb))
  63. return AVERROR_EOF;
  64. ret = av_get_packet(s->pb, pkt, size);
  65. if (ret != size) {
  66. if (ret < 0) {
  67. av_free_packet(pkt);
  68. return ret;
  69. }
  70. av_shrink_packet(pkt, ret);
  71. }
  72. pkt->stream_index = 0;
  73. return ret;
  74. }
  75. AVInputFormat ff_adp_demuxer = {
  76. .name = "adp",
  77. .long_name = NULL_IF_CONFIG_SMALL("ADP"),
  78. .read_probe = adp_probe,
  79. .read_header = adp_read_header,
  80. .read_packet = adp_read_packet,
  81. .extensions = "adp,dtk",
  82. };