annotate rtpenc_h264.c @ 6434:ca5676c4563d libavformat

cosmetic
author aurel
date Sun, 29 Aug 2010 21:23:52 +0000
parents 178de7695c6c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2960
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
1 /*
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
2 * RTP packetization for H.264 (RFC3984)
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 3052
diff changeset
3 * Copyright (c) 2008 Luca Abeni
2960
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
4 *
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
5 * This file is part of FFmpeg.
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
6 *
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
11 *
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
15 * Lesser General Public License for more details.
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
16 *
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
20 */
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
21
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
22 /**
5969
178de7695c6c Remove explicit filename from Doxygen @file commands.
diego
parents: 4944
diff changeset
23 * @file
2960
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
24 * @brief H.264 packetization
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
25 * @author Luca Abeni <lucabe72@email.it>
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
26 */
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
27
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
28 #include "avformat.h"
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
29 #include "avc.h"
4388
80f21f72d7d6 Split rtp.h in rtp.h, rtpdec.h, and rtpenc.h
lucabe
parents: 4331
diff changeset
30 #include "rtpenc.h"
2960
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
31
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
32 static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last)
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
33 {
4388
80f21f72d7d6 Split rtp.h in rtp.h, rtpdec.h, and rtpenc.h
lucabe
parents: 4331
diff changeset
34 RTPMuxContext *s = s1->priv_data;
2960
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
35
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
36 av_log(s1, AV_LOG_DEBUG, "Sending NAL %x of len %d M=%d\n", buf[0] & 0x1F, size, last);
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
37 if (size <= s->max_payload_size) {
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
38 ff_rtp_send_data(s1, buf, size, last);
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
39 } else {
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
40 uint8_t type = buf[0] & 0x1F;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
41 uint8_t nri = buf[0] & 0x60;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
42
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
43 av_log(s1, AV_LOG_DEBUG, "NAL size %d > %d\n", size, s->max_payload_size);
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
44 s->buf[0] = 28; /* FU Indicator; Type = 28 ---> FU-A */
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
45 s->buf[0] |= nri;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
46 s->buf[1] = type;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
47 s->buf[1] |= 1 << 7;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
48 buf += 1;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
49 size -= 1;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
50 while (size + 2 > s->max_payload_size) {
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
51 memcpy(&s->buf[2], buf, s->max_payload_size - 2);
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
52 ff_rtp_send_data(s1, s->buf, s->max_payload_size, 0);
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
53 buf += s->max_payload_size - 2;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
54 size -= s->max_payload_size - 2;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
55 s->buf[1] &= ~(1 << 7);
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
56 }
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
57 s->buf[1] |= 1 << 6;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
58 memcpy(&s->buf[2], buf, size);
4944
4c1e9b3799a4 Fix the M bit for multi-packet NALs.
lucabe
parents: 4388
diff changeset
59 ff_rtp_send_data(s1, s->buf, size + 2, last);
2960
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
60 }
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
61 }
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
62
3052
93cee0e79c5b Add some const, fixes warnings:
reimar
parents: 2960
diff changeset
63 void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size)
2960
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
64 {
3052
93cee0e79c5b Add some const, fixes warnings:
reimar
parents: 2960
diff changeset
65 const uint8_t *r;
4388
80f21f72d7d6 Split rtp.h in rtp.h, rtpdec.h, and rtpenc.h
lucabe
parents: 4331
diff changeset
66 RTPMuxContext *s = s1->priv_data;
2960
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
67
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
68 s->timestamp = s->cur_timestamp;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
69 r = ff_avc_find_startcode(buf1, buf1 + size);
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
70 while (r < buf1 + size) {
3052
93cee0e79c5b Add some const, fixes warnings:
reimar
parents: 2960
diff changeset
71 const uint8_t *r1;
2960
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
72
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
73 while(!*(r++));
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
74 r1 = ff_avc_find_startcode(r, buf1 + size);
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
75 nal_send(s1, r, r1 - r, (r1 == buf1 + size));
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
76 r = r1;
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
77 }
e5d44127b182 Add support for H.264 video in the RTP muxer
lucabe
parents:
diff changeset
78 }