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.

105 lines
3.4KB

  1. /*
  2. * RTP packetization for H.263 video
  3. * Copyright (c) 2012 Martin Storsjo
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; 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 "rtpenc.h"
  23. #include "libavcodec/put_bits.h"
  24. #include "libavcodec/get_bits.h"
  25. struct H263Info {
  26. int src;
  27. int i;
  28. int u;
  29. int s;
  30. int a;
  31. int pb;
  32. int tr;
  33. };
  34. static void send_mode_a(AVFormatContext *s1, const struct H263Info *info,
  35. const uint8_t *buf, int len, int m)
  36. {
  37. RTPMuxContext *s = s1->priv_data;
  38. PutBitContext pb;
  39. init_put_bits(&pb, s->buf, 32);
  40. put_bits(&pb, 1, 0); /* F - 0, mode A */
  41. put_bits(&pb, 1, 0); /* P - 0, normal I/P */
  42. put_bits(&pb, 3, 0); /* SBIT - 0 bits */
  43. put_bits(&pb, 3, 0); /* EBIT - 0 bits */
  44. put_bits(&pb, 3, info->src); /* SRC - source format */
  45. put_bits(&pb, 1, info->i); /* I - inter/intra */
  46. put_bits(&pb, 1, info->u); /* U - unrestricted motion vector */
  47. put_bits(&pb, 1, info->s); /* S - syntax-baesd arithmetic coding */
  48. put_bits(&pb, 1, info->a); /* A - advanced prediction */
  49. put_bits(&pb, 4, 0); /* R - reserved */
  50. put_bits(&pb, 2, 0); /* DBQ - 0 */
  51. put_bits(&pb, 3, 0); /* TRB - 0 */
  52. put_bits(&pb, 8, info->tr); /* TR */
  53. flush_put_bits(&pb);
  54. memcpy(s->buf + 4, buf, len);
  55. ff_rtp_send_data(s1, s->buf, len + 4, m);
  56. }
  57. void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size)
  58. {
  59. RTPMuxContext *s = s1->priv_data;
  60. int len;
  61. GetBitContext gb;
  62. struct H263Info info = { 0 };
  63. s->timestamp = s->cur_timestamp;
  64. init_get_bits(&gb, buf, size*8);
  65. if (get_bits(&gb, 22) == 0x20) { /* Picture Start Code */
  66. info.tr = get_bits(&gb, 8);
  67. skip_bits(&gb, 2); /* PTYPE start, H261 disambiguation */
  68. skip_bits(&gb, 3); /* Split screen, document camera, freeze picture release */
  69. info.src = get_bits(&gb, 3);
  70. info.i = get_bits(&gb, 1);
  71. info.u = get_bits(&gb, 1);
  72. info.s = get_bits(&gb, 1);
  73. info.a = get_bits(&gb, 1);
  74. info.pb = get_bits(&gb, 1);
  75. }
  76. while (size > 0) {
  77. len = FFMIN(s->max_payload_size - 4, size);
  78. /* Look for a better place to split the frame into packets. */
  79. if (len < size) {
  80. const uint8_t *end = ff_h263_find_resync_marker_reverse(buf,
  81. buf + len);
  82. len = end - buf;
  83. if (len == s->max_payload_size - 4)
  84. av_log(s1, AV_LOG_WARNING,
  85. "No GOB boundary found within MTU size, splitting at "
  86. "a random boundary\n");
  87. }
  88. send_mode_a(s1, &info, buf, len, len == size);
  89. buf += len;
  90. size -= len;
  91. }
  92. }