g723_1.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * G.723.1 demuxer
  3. * Copyright (c) 2010 Mohamed Naufal Basheer
  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. /**
  22. * @file
  23. * G.723.1 demuxer
  24. */
  25. #include "avformat.h"
  26. #include "internal.h"
  27. static const uint8_t frame_size[4] = {24, 20, 4, 1};
  28. static int g723_1_init(AVFormatContext *s, AVFormatParameters *ap)
  29. {
  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 = CODEC_ID_G723_1;
  36. st->codec->channels = 1;
  37. st->codec->sample_rate = 8000;
  38. avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
  39. return 0;
  40. }
  41. static int g723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
  42. {
  43. int size, byte, ret;
  44. pkt->pos = avio_tell(s->pb);
  45. byte = avio_r8(s->pb);
  46. size = frame_size[byte & 3];
  47. ret = av_new_packet(pkt, size);
  48. if (ret < 0)
  49. return ret;
  50. pkt->data[0] = byte;
  51. pkt->duration = 240;
  52. pkt->stream_index = 0;
  53. ret = avio_read(s->pb, pkt->data + 1, size - 1);
  54. if (ret < size - 1) {
  55. av_free_packet(pkt);
  56. return ret < 0 ? ret : AVERROR_EOF;
  57. }
  58. return pkt->size;
  59. }
  60. AVInputFormat ff_g723_1_demuxer = {
  61. .name = "g723_1",
  62. .long_name = NULL_IF_CONFIG_SMALL("G.723.1 format"),
  63. .read_header = g723_1_init,
  64. .read_packet = g723_1_read_packet,
  65. .extensions = "tco,rco",
  66. .flags = AVFMT_GENERIC_INDEX
  67. };