| OLD | NEW |
| 1 /* | 1 /* |
| 2 * RTP packetization for Xiph audio and video | 2 * RTP packetization for Xiph audio and video |
| 3 * Copyright (c) 2010 Josh Allmann | 3 * Copyright (c) 2010 Josh Allmann |
| 4 * | 4 * |
| 5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
| 6 * | 6 * |
| 7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 break; | 45 break; |
| 46 case 0x03: // vorbis comments | 46 case 0x03: // vorbis comments |
| 47 case 0x81: // theora comments | 47 case 0x81: // theora comments |
| 48 xdt = 2; // comment payload | 48 xdt = 2; // comment payload |
| 49 break; | 49 break; |
| 50 default: | 50 default: |
| 51 xdt = 0; // raw data payload | 51 xdt = 0; // raw data payload |
| 52 break; | 52 break; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Set ident. Must match the one in sdp.c | 55 // Set ident. |
| 56 // Probably need a non-fixed way of generating | 56 // Probably need a non-fixed way of generating |
| 57 // this, but it has to be done in SDP and passed in from there. | 57 // this, but it has to be done in SDP and passed in from there. |
| 58 q = s->buf; | 58 q = s->buf; |
| 59 *q++ = 0xfe; | 59 *q++ = (RTP_XIPH_IDENT >> 16) & 0xff; |
| 60 *q++ = 0xcd; | 60 *q++ = (RTP_XIPH_IDENT >> 8) & 0xff; |
| 61 *q++ = 0xba; | 61 *q++ = (RTP_XIPH_IDENT ) & 0xff; |
| 62 | 62 |
| 63 // set fragment | 63 // set fragment |
| 64 // 0 - whole frame (possibly multiple frames) | 64 // 0 - whole frame (possibly multiple frames) |
| 65 // 1 - first fragment | 65 // 1 - first fragment |
| 66 // 2 - fragment continuation | 66 // 2 - fragment continuation |
| 67 // 3 - last fragmement | 67 // 3 - last fragmement |
| 68 frag = size <= max_pkt_size ? 0 : 1; | 68 frag = size <= max_pkt_size ? 0 : 1; |
| 69 | 69 |
| 70 if (!frag && !xdt) { // do we have a whole frame of raw data? | 70 if (!frag && !xdt) { // do we have a whole frame of raw data? |
| 71 unsigned end_ptr = (unsigned)s->buf + 6 + max_pkt_size; // what we're al
lowed to write | 71 uint8_t *end_ptr = s->buf + 6 + max_pkt_size; // what we're allowed to w
rite |
| 72 unsigned ptr = (unsigned)s->buf_ptr + 2 + size; // what we're going
to write | 72 uint8_t *ptr = s->buf_ptr + 2 + size; // what we're going to write |
| 73 int remaining = end_ptr - ptr; | 73 int remaining = end_ptr - ptr; |
| 74 | 74 |
| 75 assert(s->num_frames <= s->max_frames_per_packet); |
| 75 if ((s->num_frames > 0 && remaining < 0) || | 76 if ((s->num_frames > 0 && remaining < 0) || |
| 76 s->num_frames >= s->max_frames_per_packet) { | 77 s->num_frames == s->max_frames_per_packet) { |
| 77 // send previous packets now; no room for new data | 78 // send previous packets now; no room for new data |
| 78 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); | 79 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); |
| 79 s->num_frames = 0; | 80 s->num_frames = 0; |
| 80 } | 81 } |
| 81 | 82 |
| 82 // buffer current frame to send later | 83 // buffer current frame to send later |
| 83 if (0 == s->num_frames) s->timestamp = s->cur_timestamp; | 84 if (0 == s->num_frames) s->timestamp = s->cur_timestamp; |
| 84 s->num_frames++; | 85 s->num_frames++; |
| 85 | 86 |
| 86 // Set packet header. Normally, this is OR'd with frag and xdt, | 87 // Set packet header. Normally, this is OR'd with frag and xdt, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 116 memcpy(q, buff, len); | 117 memcpy(q, buff, len); |
| 117 q += len; | 118 q += len; |
| 118 buff += len; | 119 buff += len; |
| 119 size -= len; | 120 size -= len; |
| 120 | 121 |
| 121 ff_rtp_send_data(s1, s->buf, q - s->buf, 0); | 122 ff_rtp_send_data(s1, s->buf, q - s->buf, 0); |
| 122 | 123 |
| 123 frag = size <= max_pkt_size ? 3 : 2; | 124 frag = size <= max_pkt_size ? 3 : 2; |
| 124 } | 125 } |
| 125 } | 126 } |
| OLD | NEW |