g723_1.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "libavutil/audioconvert.h"
  26. #include "avformat.h"
  27. #include "internal.h"
  28. static const uint8_t frame_size[4] = { 24, 20, 4, 1 };
  29. static int g723_1_init(AVFormatContext *s)
  30. {
  31. AVStream *st;
  32. st = avformat_new_stream(s, NULL);
  33. if (!st)
  34. return AVERROR(ENOMEM);
  35. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  36. st->codec->codec_id = AV_CODEC_ID_G723_1;
  37. st->codec->channel_layout = AV_CH_LAYOUT_MONO;
  38. st->codec->channels = 1;
  39. st->codec->sample_rate = 8000;
  40. avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
  41. st->start_time = 0;
  42. return 0;
  43. }
  44. static int g723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
  45. {
  46. int size, byte, ret;
  47. pkt->pos = avio_tell(s->pb);
  48. byte = avio_r8(s->pb);
  49. size = frame_size[byte & 3];
  50. ret = av_new_packet(pkt, size);
  51. if (ret < 0)
  52. return ret;
  53. pkt->data[0] = byte;
  54. pkt->duration = 240;
  55. pkt->stream_index = 0;
  56. ret = avio_read(s->pb, pkt->data + 1, size - 1);
  57. if (ret < size - 1) {
  58. av_free_packet(pkt);
  59. return ret < 0 ? ret : AVERROR_EOF;
  60. }
  61. return pkt->size;
  62. }
  63. AVInputFormat ff_g723_1_demuxer = {
  64. .name = "g723_1",
  65. .long_name = NULL_IF_CONFIG_SMALL("G.723.1"),
  66. .read_header = g723_1_init,
  67. .read_packet = g723_1_read_packet,
  68. .extensions = "tco,rco,g723_1",
  69. .flags = AVFMT_GENERIC_INDEX
  70. };