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.

80 lines
2.2KB

  1. /*
  2. * RTP packetization for MPEG video
  3. * Copyright (c) 2002 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 "rtp_internal.h"
  23. /* NOTE: a single frame must be passed with sequence header if
  24. needed. XXX: use slices. */
  25. void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
  26. {
  27. RTPDemuxContext *s = s1->priv_data;
  28. AVStream *st = s1->streams[0];
  29. int len, h, max_packet_size;
  30. int b=1, e=0;
  31. uint8_t *q;
  32. max_packet_size = s->max_payload_size;
  33. while (size > 0) {
  34. len = max_packet_size - 4;
  35. if (len >= size) {
  36. len = size;
  37. e = 1;
  38. }
  39. h = 0;
  40. h |= b << 12;
  41. h |= e << 11;
  42. // if (st->codec->sub_id == 2)
  43. // h |= 1 << 26; /* mpeg 2 indicator */
  44. q = s->buf;
  45. *q++ = h >> 24;
  46. *q++ = h >> 16;
  47. *q++ = h >> 8;
  48. *q++ = h;
  49. /* if (st->codec->sub_id == 2) {
  50. h = 0;
  51. *q++ = h >> 24;
  52. *q++ = h >> 16;
  53. *q++ = h >> 8;
  54. *q++ = h;
  55. } */
  56. memcpy(q, buf1, len);
  57. q += len;
  58. /* 90 KHz time stamp */
  59. s->timestamp = s->base_timestamp +
  60. av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
  61. ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
  62. buf1 += len;
  63. size -= len;
  64. }
  65. s->cur_timestamp++;
  66. }