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.

101 lines
3.1KB

  1. /*
  2. * raw ADTS AAC demuxer
  3. * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
  4. * Copyright (c) 2009 Robert Swain ( rob opendot cl )
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "libavutil/intreadwrite.h"
  23. #include "avformat.h"
  24. #include "internal.h"
  25. #include "rawdec.h"
  26. #include "id3v1.h"
  27. #include "apetag.h"
  28. static int adts_aac_probe(AVProbeData *p)
  29. {
  30. int max_frames = 0, first_frames = 0;
  31. int fsize, frames;
  32. const uint8_t *buf0 = p->buf;
  33. const uint8_t *buf2;
  34. const uint8_t *buf;
  35. const uint8_t *end = buf0 + p->buf_size - 7;
  36. buf = buf0;
  37. for(; buf < end; buf= buf2+1) {
  38. buf2 = buf;
  39. for(frames = 0; buf2 < end; frames++) {
  40. uint32_t header = AV_RB16(buf2);
  41. if((header&0xFFF6) != 0xFFF0)
  42. break;
  43. fsize = (AV_RB32(buf2 + 3) >> 13) & 0x1FFF;
  44. if(fsize < 7)
  45. break;
  46. fsize = FFMIN(fsize, end - buf2);
  47. buf2 += fsize;
  48. }
  49. max_frames = FFMAX(max_frames, frames);
  50. if(buf == buf0)
  51. first_frames= frames;
  52. }
  53. if (first_frames>=3) return AVPROBE_SCORE_EXTENSION + 1;
  54. else if(max_frames>500)return AVPROBE_SCORE_EXTENSION;
  55. else if(max_frames>=3) return AVPROBE_SCORE_EXTENSION / 2;
  56. else if(max_frames>=1) return 1;
  57. else return 0;
  58. }
  59. static int adts_aac_read_header(AVFormatContext *s)
  60. {
  61. AVStream *st;
  62. st = avformat_new_stream(s, NULL);
  63. if (!st)
  64. return AVERROR(ENOMEM);
  65. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  66. st->codec->codec_id = s->iformat->raw_codec_id;
  67. st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
  68. ff_id3v1_read(s);
  69. if (s->pb->seekable &&
  70. !av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
  71. int64_t cur = avio_tell(s->pb);
  72. ff_ape_parse_tag(s);
  73. avio_seek(s->pb, cur, SEEK_SET);
  74. }
  75. //LCM of all possible ADTS sample rates
  76. avpriv_set_pts_info(st, 64, 1, 28224000);
  77. return 0;
  78. }
  79. AVInputFormat ff_aac_demuxer = {
  80. .name = "aac",
  81. .long_name = NULL_IF_CONFIG_SMALL("raw ADTS AAC (Advanced Audio Coding)"),
  82. .read_probe = adts_aac_probe,
  83. .read_header = adts_aac_read_header,
  84. .read_packet = ff_raw_read_partial_packet,
  85. .flags = AVFMT_GENERIC_INDEX,
  86. .extensions = "aac",
  87. .raw_codec_id = AV_CODEC_ID_AAC,
  88. };