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.

87 lines
2.7KB

  1. /*
  2. * copyright (c) 2007 Luca Abeni
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/intreadwrite.h"
  21. #include "avformat.h"
  22. #include "rtpenc.h"
  23. void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
  24. {
  25. RTPMuxContext *s = s1->priv_data;
  26. AVStream *st = s1->streams[0];
  27. const int max_au_headers_size = 2 + 2 * s->max_frames_per_packet;
  28. int len, max_packet_size = s->max_payload_size - max_au_headers_size;
  29. uint8_t *p;
  30. /* skip ADTS header, if present */
  31. if ((s1->streams[0]->codecpar->extradata_size) == 0) {
  32. size -= 7;
  33. buff += 7;
  34. }
  35. /* test if the packet must be sent */
  36. len = (s->buf_ptr - s->buf);
  37. if (s->num_frames &&
  38. (s->num_frames == s->max_frames_per_packet ||
  39. (len + size) > s->max_payload_size ||
  40. av_compare_ts(s->cur_timestamp - s->timestamp, st->time_base,
  41. s1->max_delay, AV_TIME_BASE_Q) >= 0)) {
  42. int au_size = s->num_frames * 2;
  43. p = s->buf + max_au_headers_size - au_size - 2;
  44. if (p != s->buf) {
  45. memmove(p + 2, s->buf + 2, au_size);
  46. }
  47. /* Write the AU header size */
  48. AV_WB16(p, au_size * 8);
  49. ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
  50. s->num_frames = 0;
  51. }
  52. if (s->num_frames == 0) {
  53. s->buf_ptr = s->buf + max_au_headers_size;
  54. s->timestamp = s->cur_timestamp;
  55. }
  56. if (size <= max_packet_size) {
  57. p = s->buf + s->num_frames++ * 2 + 2;
  58. AV_WB16(p, size * 8);
  59. memcpy(s->buf_ptr, buff, size);
  60. s->buf_ptr += size;
  61. } else {
  62. int au_size = size;
  63. max_packet_size = s->max_payload_size - 4;
  64. p = s->buf;
  65. AV_WB16(p, 2 * 8);
  66. while (size > 0) {
  67. len = FFMIN(size, max_packet_size);
  68. AV_WB16(&p[2], au_size * 8);
  69. memcpy(p + 4, buff, len);
  70. ff_rtp_send_data(s1, p, len + 4, len == size);
  71. size -= len;
  72. buff += len;
  73. }
  74. }
  75. }