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.

89 lines
2.8KB

  1. /*
  2. * copyright (c) 2007 Luca Abeni
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "avformat.h"
  21. #include "rtp_aac.h"
  22. #include "rtp.h"
  23. #define MAX_FRAMES_PER_PACKET (s->max_frames_per_packet ? s->max_frames_per_packet : 5)
  24. #define MAX_AU_HEADERS_SIZE (2 + 2 * MAX_FRAMES_PER_PACKET)
  25. void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
  26. {
  27. RTPDemuxContext *s = s1->priv_data;
  28. int len, max_packet_size;
  29. uint8_t *p;
  30. /* skip ADTS header, if present */
  31. if ((s1->streams[0]->codec->extradata_size) == 0) {
  32. size -= 7;
  33. buff += 7;
  34. }
  35. max_packet_size = s->max_payload_size - MAX_AU_HEADERS_SIZE;
  36. /* test if the packet must be sent */
  37. len = (s->buf_ptr - s->buf);
  38. if ((s->read_buf_index == MAX_FRAMES_PER_PACKET) || (len && (len + size) > max_packet_size)) {
  39. int au_size = s->read_buf_index * 2;
  40. p = s->buf + MAX_AU_HEADERS_SIZE - au_size - 2;
  41. if (p != s->buf) {
  42. memmove(p + 2, s->buf + 2, au_size);
  43. }
  44. /* Write the AU header size */
  45. p[0] = ((au_size * 8) & 0xFF) >> 8;
  46. p[1] = (au_size * 8) & 0xFF;
  47. ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
  48. s->read_buf_index = 0;
  49. }
  50. if (s->read_buf_index == 0) {
  51. s->buf_ptr = s->buf + MAX_AU_HEADERS_SIZE;
  52. s->timestamp = s->cur_timestamp;
  53. }
  54. if (size < max_packet_size) {
  55. p = s->buf + s->read_buf_index++ * 2 + 2;
  56. *p++ = size >> 5;
  57. *p = (size & 0x1F) << 3;
  58. memcpy(s->buf_ptr, buff, size);
  59. s->buf_ptr += size;
  60. } else {
  61. if (s->buf_ptr != s->buf + MAX_AU_HEADERS_SIZE) {
  62. av_log(s1, AV_LOG_ERROR, "Strange...\n");
  63. av_abort();
  64. }
  65. max_packet_size = s->max_payload_size - 4;
  66. p = s->buf;
  67. p[0] = 0;
  68. p[1] = 16;
  69. while (size > 0) {
  70. len = FFMIN(size, max_packet_size);
  71. p[2] = len >> 5;
  72. p[3] = (size & 0x1F) << 3;
  73. memcpy(p + 4, buff, len);
  74. ff_rtp_send_data(s1, p, len + 4, len == size);
  75. size -= len;
  76. buff += len;
  77. }
  78. }
  79. }