Revision 22c1f65f

View differences:

libavformat/Makefile
201 201
OBJS-$(CONFIG_ROQ_MUXER)                 += raw.o
202 202
OBJS-$(CONFIG_RPL_DEMUXER)               += rpl.o
203 203
OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o         \
204
                                            rtp_aac.o     \
205
                                            rtp_amr.o     \
206
                                            rtp_h263.o    \
207
                                            rtp_mpv.o     \
204
                                            rtpenc_aac.o     \
205
                                            rtpenc_amr.o     \
206
                                            rtpenc_h263.o    \
207
                                            rtpenc_mpv.o     \
208 208
                                            rtpenc.o      \
209 209
                                            rtpenc_h264.o \
210 210
                                            avc.o
libavformat/rtp_aac.c
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

  
21
#include "avformat.h"
22
#include "rtpenc.h"
23

  
24

  
25
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
26
{
27
    RTPMuxContext *s = s1->priv_data;
28
    int len, max_packet_size;
29
    uint8_t *p;
30
    const int max_frames_per_packet = s->max_frames_per_packet ? s->max_frames_per_packet : 5;
31
    const int max_au_headers_size = 2 + 2 * max_frames_per_packet;
32

  
33
    /* skip ADTS header, if present */
34
    if ((s1->streams[0]->codec->extradata_size) == 0) {
35
        size -= 7;
36
        buff += 7;
37
    }
38
    max_packet_size = s->max_payload_size - max_au_headers_size;
39

  
40
    /* test if the packet must be sent */
41
    len = (s->buf_ptr - s->buf);
42
    if ((s->num_frames == max_frames_per_packet) || (len && (len + size) > s->max_payload_size)) {
43
        int au_size = s->num_frames * 2;
44

  
45
        p = s->buf + max_au_headers_size - au_size - 2;
46
        if (p != s->buf) {
47
            memmove(p + 2, s->buf + 2, au_size);
48
        }
49
        /* Write the AU header size */
50
        p[0] = ((au_size * 8) & 0xFF) >> 8;
51
        p[1] = (au_size * 8) & 0xFF;
52

  
53
        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
54

  
55
        s->num_frames = 0;
56
    }
57
    if (s->num_frames == 0) {
58
        s->buf_ptr = s->buf + max_au_headers_size;
59
        s->timestamp = s->cur_timestamp;
60
    }
61

  
62
    if (size <= max_packet_size) {
63
        p = s->buf + s->num_frames++ * 2 + 2;
64
        *p++ = size >> 5;
65
        *p = (size & 0x1F) << 3;
66
        memcpy(s->buf_ptr, buff, size);
67
        s->buf_ptr += size;
68
    } else {
69
        int au_size = size;
70

  
71
        max_packet_size = s->max_payload_size - 4;
72
        p = s->buf;
73
        p[0] = 0;
74
        p[1] = 16;
75
        while (size > 0) {
76
            len = FFMIN(size, max_packet_size);
77
            p[2] = au_size >> 5;
78
            p[3] = (au_size & 0x1F) << 3;
79
            memcpy(p + 4, buff, len);
80
            ff_rtp_send_data(s1, p, len + 4, len == size);
81
            size -= len;
82
            buff += len;
83
        }
84
    }
85
}
libavformat/rtp_amr.c
1
/*
2
 * RTP packetization for AMR audio
3
 * Copyright (c) 2007 Luca Abeni
4
 * Copyright (c) 2009 Martin Storsjo
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

  
23
#include "avformat.h"
24
#include "rtpenc.h"
25

  
26
/**
27
 * Packetize AMR frames into RTP packets according to RFC 3267,
28
 * in octet-aligned mode.
29
 */
30
void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
31
{
32
    RTPMuxContext *s          = s1->priv_data;
33
    int max_header_toc_size   = 1 + s->max_frames_per_packet;
34
    uint8_t *p;
35
    int len;
36

  
37
    /* Test if the packet must be sent. */
38
    len = s->buf_ptr - s->buf;
39
    if (s->num_frames == s->max_frames_per_packet || (len && len + size - 1 > s->max_payload_size)) {
40
        int header_size = s->num_frames + 1;
41
        p = s->buf + max_header_toc_size - header_size;
42
        if (p != s->buf)
43
            memmove(p, s->buf, header_size);
44

  
45
        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
46

  
47
        s->num_frames = 0;
48
    }
49

  
50
    if (!s->num_frames) {
51
        s->buf[0]    = 0xf0;
52
        s->buf_ptr   = s->buf + max_header_toc_size;
53
        s->timestamp = s->cur_timestamp;
54
    } else {
55
        /* Mark the previous TOC entry as having more entries following. */
56
        s->buf[1 + s->num_frames - 1] |= 0x80;
57
    }
58

  
59
    /* Copy the frame type and quality bits. */
60
    s->buf[1 + s->num_frames++] = buff[0] & 0x7C;
61
    buff++;
62
    size--;
63
    memcpy(s->buf_ptr, buff, size);
64
    s->buf_ptr += size;
65
}
66

  
libavformat/rtp_h263.c
1
/*
2
 * RTP packetization for H.263 video
3
 * Copyright (c) 2009 Luca Abeni
4
 * Copyright (c) 2009 Martin Storsjo
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

  
23
#include "avformat.h"
24
#include "rtpenc.h"
25

  
26
static const uint8_t *find_resync_marker_reverse(const uint8_t *restrict start,
27
                                                 const uint8_t *restrict end)
28
{
29
    const uint8_t *p = end - 1;
30
    start += 1; /* Make sure we never return the original start. */
31
    for (; p > start; p -= 2) {
32
        if (!*p) {
33
            if      (!p[ 1] && p[2]) return p;
34
            else if (!p[-1] && p[1]) return p - 1;
35
        }
36
    }
37
    return end;
38
}
39

  
40
/**
41
 * Packetize H.263 frames into RTP packets according to RFC 4629
42
 */
43
void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
44
{
45
    RTPMuxContext *s = s1->priv_data;
46
    int len, max_packet_size;
47
    uint8_t *q;
48

  
49
    max_packet_size = s->max_payload_size;
50

  
51
    while (size > 0) {
52
        q = s->buf;
53
        if ((buf1[0] == 0) && (buf1[1] == 0)) {
54
            *q++ = 0x04;
55
            buf1 += 2;
56
            size -= 2;
57
        } else {
58
            *q++ = 0;
59
        }
60
        *q++ = 0;
61

  
62
        len = FFMIN(max_packet_size - 2, size);
63

  
64
        /* Look for a better place to split the frame into packets. */
65
        if (len < size) {
66
            const uint8_t *end = find_resync_marker_reverse(buf1, buf1 + len);
67
            len = end - buf1;
68
        }
69

  
70
        memcpy(q, buf1, len);
71
        q += len;
72

  
73
        /* 90 KHz time stamp */
74
        s->timestamp = s->cur_timestamp;
75
        ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
76

  
77
        buf1 += len;
78
        size -= len;
79
    }
80
}
libavformat/rtp_mpv.c
1
/*
2
 * RTP packetization for MPEG video
3
 * Copyright (c) 2002 Fabrice Bellard
4
 * Copyright (c) 2007 Luca Abeni
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

  
23
#include "libavcodec/mpegvideo.h"
24
#include "avformat.h"
25
#include "rtpenc.h"
26

  
27
/* NOTE: a single frame must be passed with sequence header if
28
   needed. XXX: use slices. */
29
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
30
{
31
    RTPMuxContext *s = s1->priv_data;
32
    int len, h, max_packet_size;
33
    uint8_t *q;
34
    const uint8_t *end = buf1 + size;
35
    int begin_of_slice, end_of_slice, frame_type, temporal_reference;
36

  
37
    max_packet_size = s->max_payload_size;
38
    begin_of_slice = 1;
39
    end_of_slice = 0;
40
    frame_type = 0;
41
    temporal_reference = 0;
42

  
43
    while (size > 0) {
44
        int begin_of_sequence;
45

  
46
        begin_of_sequence = 0;
47
        len = max_packet_size - 4;
48

  
49
        if (len >= size) {
50
            len = size;
51
            end_of_slice = 1;
52
        } else {
53
            const uint8_t *r, *r1;
54
            int start_code;
55

  
56
            r1 = buf1;
57
            while (1) {
58
                start_code = -1;
59
                r = ff_find_start_code(r1, end, &start_code);
60
                if((start_code & 0xFFFFFF00) == 0x100) {
61
                    /* New start code found */
62
                    if (start_code == 0x100) {
63
                        frame_type = (r[1] & 0x38) >> 3;
64
                        temporal_reference = (int)r[0] << 2 | r[1] >> 6;
65
                    }
66
                    if (start_code == 0x1B8) {
67
                        begin_of_sequence = 1;
68
                    }
69

  
70
                    if (r - buf1 - 4 <= len) {
71
                        /* The current slice fits in the packet */
72
                        if (begin_of_slice == 0) {
73
                            /* no slice at the beginning of the packet... */
74
                            end_of_slice = 1;
75
                            len = r - buf1 - 4;
76
                            break;
77
                        }
78
                        r1 = r;
79
                    } else {
80
                        if ((r1 - buf1 > 4) && (r - r1 < max_packet_size)) {
81
                            len = r1 - buf1 - 4;
82
                            end_of_slice = 1;
83
                        }
84
                        break;
85
                    }
86
                } else {
87
                    break;
88
                }
89
            }
90
        }
91

  
92
        h = 0;
93
        h |= temporal_reference << 16;
94
        h |= begin_of_sequence << 13;
95
        h |= begin_of_slice << 12;
96
        h |= end_of_slice << 11;
97
        h |= frame_type << 8;
98

  
99
        q = s->buf;
100
        *q++ = h >> 24;
101
        *q++ = h >> 16;
102
        *q++ = h >> 8;
103
        *q++ = h;
104

  
105
        memcpy(q, buf1, len);
106
        q += len;
107

  
108
        /* 90kHz time stamp */
109
        s->timestamp = s->cur_timestamp;
110
        ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
111

  
112
        buf1 += len;
113
        size -= len;
114
        begin_of_slice = end_of_slice;
115
        end_of_slice = 0;
116
    }
117
}
118

  
119

  
libavformat/rtpenc_aac.c
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

  
21
#include "avformat.h"
22
#include "rtpenc.h"
23

  
24

  
25
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
26
{
27
    RTPMuxContext *s = s1->priv_data;
28
    int len, max_packet_size;
29
    uint8_t *p;
30
    const int max_frames_per_packet = s->max_frames_per_packet ? s->max_frames_per_packet : 5;
31
    const int max_au_headers_size = 2 + 2 * max_frames_per_packet;
32

  
33
    /* skip ADTS header, if present */
34
    if ((s1->streams[0]->codec->extradata_size) == 0) {
35
        size -= 7;
36
        buff += 7;
37
    }
38
    max_packet_size = s->max_payload_size - max_au_headers_size;
39

  
40
    /* test if the packet must be sent */
41
    len = (s->buf_ptr - s->buf);
42
    if ((s->num_frames == max_frames_per_packet) || (len && (len + size) > s->max_payload_size)) {
43
        int au_size = s->num_frames * 2;
44

  
45
        p = s->buf + max_au_headers_size - au_size - 2;
46
        if (p != s->buf) {
47
            memmove(p + 2, s->buf + 2, au_size);
48
        }
49
        /* Write the AU header size */
50
        p[0] = ((au_size * 8) & 0xFF) >> 8;
51
        p[1] = (au_size * 8) & 0xFF;
52

  
53
        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
54

  
55
        s->num_frames = 0;
56
    }
57
    if (s->num_frames == 0) {
58
        s->buf_ptr = s->buf + max_au_headers_size;
59
        s->timestamp = s->cur_timestamp;
60
    }
61

  
62
    if (size <= max_packet_size) {
63
        p = s->buf + s->num_frames++ * 2 + 2;
64
        *p++ = size >> 5;
65
        *p = (size & 0x1F) << 3;
66
        memcpy(s->buf_ptr, buff, size);
67
        s->buf_ptr += size;
68
    } else {
69
        int au_size = size;
70

  
71
        max_packet_size = s->max_payload_size - 4;
72
        p = s->buf;
73
        p[0] = 0;
74
        p[1] = 16;
75
        while (size > 0) {
76
            len = FFMIN(size, max_packet_size);
77
            p[2] = au_size >> 5;
78
            p[3] = (au_size & 0x1F) << 3;
79
            memcpy(p + 4, buff, len);
80
            ff_rtp_send_data(s1, p, len + 4, len == size);
81
            size -= len;
82
            buff += len;
83
        }
84
    }
85
}
libavformat/rtpenc_amr.c
1
/*
2
 * RTP packetization for AMR audio
3
 * Copyright (c) 2007 Luca Abeni
4
 * Copyright (c) 2009 Martin Storsjo
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

  
23
#include "avformat.h"
24
#include "rtpenc.h"
25

  
26
/**
27
 * Packetize AMR frames into RTP packets according to RFC 3267,
28
 * in octet-aligned mode.
29
 */
30
void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
31
{
32
    RTPMuxContext *s          = s1->priv_data;
33
    int max_header_toc_size   = 1 + s->max_frames_per_packet;
34
    uint8_t *p;
35
    int len;
36

  
37
    /* Test if the packet must be sent. */
38
    len = s->buf_ptr - s->buf;
39
    if (s->num_frames == s->max_frames_per_packet || (len && len + size - 1 > s->max_payload_size)) {
40
        int header_size = s->num_frames + 1;
41
        p = s->buf + max_header_toc_size - header_size;
42
        if (p != s->buf)
43
            memmove(p, s->buf, header_size);
44

  
45
        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
46

  
47
        s->num_frames = 0;
48
    }
49

  
50
    if (!s->num_frames) {
51
        s->buf[0]    = 0xf0;
52
        s->buf_ptr   = s->buf + max_header_toc_size;
53
        s->timestamp = s->cur_timestamp;
54
    } else {
55
        /* Mark the previous TOC entry as having more entries following. */
56
        s->buf[1 + s->num_frames - 1] |= 0x80;
57
    }
58

  
59
    /* Copy the frame type and quality bits. */
60
    s->buf[1 + s->num_frames++] = buff[0] & 0x7C;
61
    buff++;
62
    size--;
63
    memcpy(s->buf_ptr, buff, size);
64
    s->buf_ptr += size;
65
}
66

  
libavformat/rtpenc_h263.c
1
/*
2
 * RTP packetization for H.263 video
3
 * Copyright (c) 2009 Luca Abeni
4
 * Copyright (c) 2009 Martin Storsjo
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

  
23
#include "avformat.h"
24
#include "rtpenc.h"
25

  
26
static const uint8_t *find_resync_marker_reverse(const uint8_t *restrict start,
27
                                                 const uint8_t *restrict end)
28
{
29
    const uint8_t *p = end - 1;
30
    start += 1; /* Make sure we never return the original start. */
31
    for (; p > start; p -= 2) {
32
        if (!*p) {
33
            if      (!p[ 1] && p[2]) return p;
34
            else if (!p[-1] && p[1]) return p - 1;
35
        }
36
    }
37
    return end;
38
}
39

  
40
/**
41
 * Packetize H.263 frames into RTP packets according to RFC 4629
42
 */
43
void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
44
{
45
    RTPMuxContext *s = s1->priv_data;
46
    int len, max_packet_size;
47
    uint8_t *q;
48

  
49
    max_packet_size = s->max_payload_size;
50

  
51
    while (size > 0) {
52
        q = s->buf;
53
        if ((buf1[0] == 0) && (buf1[1] == 0)) {
54
            *q++ = 0x04;
55
            buf1 += 2;
56
            size -= 2;
57
        } else {
58
            *q++ = 0;
59
        }
60
        *q++ = 0;
61

  
62
        len = FFMIN(max_packet_size - 2, size);
63

  
64
        /* Look for a better place to split the frame into packets. */
65
        if (len < size) {
66
            const uint8_t *end = find_resync_marker_reverse(buf1, buf1 + len);
67
            len = end - buf1;
68
        }
69

  
70
        memcpy(q, buf1, len);
71
        q += len;
72

  
73
        /* 90 KHz time stamp */
74
        s->timestamp = s->cur_timestamp;
75
        ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
76

  
77
        buf1 += len;
78
        size -= len;
79
    }
80
}
libavformat/rtpenc_mpv.c
1
/*
2
 * RTP packetization for MPEG video
3
 * Copyright (c) 2002 Fabrice Bellard
4
 * Copyright (c) 2007 Luca Abeni
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

  
23
#include "libavcodec/mpegvideo.h"
24
#include "avformat.h"
25
#include "rtpenc.h"
26

  
27
/* NOTE: a single frame must be passed with sequence header if
28
   needed. XXX: use slices. */
29
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
30
{
31
    RTPMuxContext *s = s1->priv_data;
32
    int len, h, max_packet_size;
33
    uint8_t *q;
34
    const uint8_t *end = buf1 + size;
35
    int begin_of_slice, end_of_slice, frame_type, temporal_reference;
36

  
37
    max_packet_size = s->max_payload_size;
38
    begin_of_slice = 1;
39
    end_of_slice = 0;
40
    frame_type = 0;
41
    temporal_reference = 0;
42

  
43
    while (size > 0) {
44
        int begin_of_sequence;
45

  
46
        begin_of_sequence = 0;
47
        len = max_packet_size - 4;
48

  
49
        if (len >= size) {
50
            len = size;
51
            end_of_slice = 1;
52
        } else {
53
            const uint8_t *r, *r1;
54
            int start_code;
55

  
56
            r1 = buf1;
57
            while (1) {
58
                start_code = -1;
59
                r = ff_find_start_code(r1, end, &start_code);
60
                if((start_code & 0xFFFFFF00) == 0x100) {
61
                    /* New start code found */
62
                    if (start_code == 0x100) {
63
                        frame_type = (r[1] & 0x38) >> 3;
64
                        temporal_reference = (int)r[0] << 2 | r[1] >> 6;
65
                    }
66
                    if (start_code == 0x1B8) {
67
                        begin_of_sequence = 1;
68
                    }
69

  
70
                    if (r - buf1 - 4 <= len) {
71
                        /* The current slice fits in the packet */
72
                        if (begin_of_slice == 0) {
73
                            /* no slice at the beginning of the packet... */
74
                            end_of_slice = 1;
75
                            len = r - buf1 - 4;
76
                            break;
77
                        }
78
                        r1 = r;
79
                    } else {
80
                        if ((r1 - buf1 > 4) && (r - r1 < max_packet_size)) {
81
                            len = r1 - buf1 - 4;
82
                            end_of_slice = 1;
83
                        }
84
                        break;
85
                    }
86
                } else {
87
                    break;
88
                }
89
            }
90
        }
91

  
92
        h = 0;
93
        h |= temporal_reference << 16;
94
        h |= begin_of_sequence << 13;
95
        h |= begin_of_slice << 12;
96
        h |= end_of_slice << 11;
97
        h |= frame_type << 8;
98

  
99
        q = s->buf;
100
        *q++ = h >> 24;
101
        *q++ = h >> 16;
102
        *q++ = h >> 8;
103
        *q++ = h;
104

  
105
        memcpy(q, buf1, len);
106
        q += len;
107

  
108
        /* 90kHz time stamp */
109
        s->timestamp = s->cur_timestamp;
110
        ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
111

  
112
        buf1 += len;
113
        size -= len;
114
        begin_of_slice = end_of_slice;
115
        end_of_slice = 0;
116
    }
117
}
118

  
119

  

Also available in: Unified diff