flacdec.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Raw FLAC demuxer
  3. * Copyright (c) 2001 Fabrice Bellard
  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 "avformat.h"
  22. #include "raw.h"
  23. #include "id3v2.h"
  24. static int flac_read_header(AVFormatContext *s,
  25. AVFormatParameters *ap)
  26. {
  27. uint8_t buf[ID3v2_HEADER_SIZE];
  28. int ret;
  29. AVStream *st = av_new_stream(s, 0);
  30. if (!st)
  31. return AVERROR(ENOMEM);
  32. st->codec->codec_type = CODEC_TYPE_AUDIO;
  33. st->codec->codec_id = CODEC_ID_FLAC;
  34. st->need_parsing = AVSTREAM_PARSE_FULL;
  35. /* the parameters will be extracted from the compressed bitstream */
  36. /* skip ID3v2 header if found */
  37. ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
  38. if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf)) {
  39. int len = ff_id3v2_tag_len(buf);
  40. url_fseek(s->pb, len - ID3v2_HEADER_SIZE, SEEK_CUR);
  41. } else {
  42. url_fseek(s->pb, 0, SEEK_SET);
  43. }
  44. return 0;
  45. }
  46. static int flac_probe(AVProbeData *p)
  47. {
  48. uint8_t *bufptr = p->buf;
  49. uint8_t *end = p->buf + p->buf_size;
  50. if(ff_id3v2_match(bufptr))
  51. bufptr += ff_id3v2_tag_len(bufptr);
  52. if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
  53. else return AVPROBE_SCORE_MAX/2;
  54. }
  55. AVInputFormat flac_demuxer = {
  56. "flac",
  57. NULL_IF_CONFIG_SMALL("raw FLAC"),
  58. 0,
  59. flac_probe,
  60. flac_read_header,
  61. ff_raw_read_partial_packet,
  62. .flags= AVFMT_GENERIC_INDEX,
  63. .extensions = "flac",
  64. .value = CODEC_ID_FLAC,
  65. };