Originally committed as revision 11589 to svn://svn.ffmpeg.org/ffmpeg/trunk
Luca Abeni authored on 2008/01/21 23:01:57... | ... |
@@ -139,7 +139,12 @@ OBJS-$(CONFIG_RM_DEMUXER) += rmdec.o |
139 | 139 |
OBJS-$(CONFIG_RM_MUXER) += rmenc.o |
140 | 140 |
OBJS-$(CONFIG_ROQ_DEMUXER) += idroq.o |
141 | 141 |
OBJS-$(CONFIG_ROQ_MUXER) += raw.o |
142 |
-OBJS-$(CONFIG_RTP_MUXER) += rtp.o rtpenc.o rtp_mpv.o rtp_aac.o |
|
142 |
+OBJS-$(CONFIG_RTP_MUXER) += rtp.o \ |
|
143 |
+ rtpenc.o \ |
|
144 |
+ rtp_mpv.o \ |
|
145 |
+ rtp_aac.o \ |
|
146 |
+ rtpenc_h264.o \ |
|
147 |
+ avc.o |
|
143 | 148 |
OBJS-$(CONFIG_RTSP_DEMUXER) += rtsp.o |
144 | 149 |
OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o rtp.o rtpdec.o rtp_h264.o |
145 | 150 |
OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o |
... | ... |
@@ -28,6 +28,7 @@ |
28 | 28 |
#include "rtp_internal.h" |
29 | 29 |
#include "rtp_mpv.h" |
30 | 30 |
#include "rtp_aac.h" |
31 |
+#include "rtp_h264.h" |
|
31 | 32 |
|
32 | 33 |
//#define DEBUG |
33 | 34 |
|
... | ... |
@@ -334,6 +335,9 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) |
334 | 334 |
case CODEC_ID_MPEG2TS: |
335 | 335 |
rtp_send_mpegts_raw(s1, buf1, size); |
336 | 336 |
break; |
337 |
+ case CODEC_ID_H264: |
|
338 |
+ ff_rtp_send_h264(s1, buf1, size); |
|
339 |
+ break; |
|
337 | 340 |
default: |
338 | 341 |
/* better than nothing : send the codec raw data */ |
339 | 342 |
rtp_send_raw(s1, buf1, size); |
340 | 343 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,78 @@ |
0 |
+/* |
|
1 |
+ * RTP packetization for H.264 (RFC3984) |
|
2 |
+ * Copyright (c) 2008 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 |
+/** |
|
22 |
+ * @file rtpenc_h264.c |
|
23 |
+ * @brief H.264 packetization |
|
24 |
+ * @author Luca Abeni <lucabe72@email.it> |
|
25 |
+ */ |
|
26 |
+ |
|
27 |
+#include "avformat.h" |
|
28 |
+#include "avc.h" |
|
29 |
+#include "rtp_h264.h" |
|
30 |
+ |
|
31 |
+static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last) |
|
32 |
+{ |
|
33 |
+ RTPDemuxContext *s = s1->priv_data; |
|
34 |
+ |
|
35 |
+ av_log(s1, AV_LOG_DEBUG, "Sending NAL %x of len %d M=%d\n", buf[0] & 0x1F, size, last); |
|
36 |
+ if (size <= s->max_payload_size) { |
|
37 |
+ ff_rtp_send_data(s1, buf, size, last); |
|
38 |
+ } else { |
|
39 |
+ uint8_t type = buf[0] & 0x1F; |
|
40 |
+ uint8_t nri = buf[0] & 0x60; |
|
41 |
+ |
|
42 |
+ av_log(s1, AV_LOG_DEBUG, "NAL size %d > %d\n", size, s->max_payload_size); |
|
43 |
+ s->buf[0] = 28; /* FU Indicator; Type = 28 ---> FU-A */ |
|
44 |
+ s->buf[0] |= nri; |
|
45 |
+ s->buf[1] = type; |
|
46 |
+ s->buf[1] |= 1 << 7; |
|
47 |
+ buf += 1; |
|
48 |
+ size -= 1; |
|
49 |
+ while (size + 2 > s->max_payload_size) { |
|
50 |
+ memcpy(&s->buf[2], buf, s->max_payload_size - 2); |
|
51 |
+ ff_rtp_send_data(s1, s->buf, s->max_payload_size, 0); |
|
52 |
+ buf += s->max_payload_size - 2; |
|
53 |
+ size -= s->max_payload_size - 2; |
|
54 |
+ s->buf[1] &= ~(1 << 7); |
|
55 |
+ } |
|
56 |
+ s->buf[1] |= 1 << 6; |
|
57 |
+ memcpy(&s->buf[2], buf, size); |
|
58 |
+ ff_rtp_send_data(s1, s->buf, size + 2, 1); |
|
59 |
+ } |
|
60 |
+} |
|
61 |
+ |
|
62 |
+void ff_rtp_send_h264(AVFormatContext *s1, uint8_t *buf1, int size) |
|
63 |
+{ |
|
64 |
+ uint8_t *r; |
|
65 |
+ RTPDemuxContext *s = s1->priv_data; |
|
66 |
+ |
|
67 |
+ s->timestamp = s->cur_timestamp; |
|
68 |
+ r = ff_avc_find_startcode(buf1, buf1 + size); |
|
69 |
+ while (r < buf1 + size) { |
|
70 |
+ uint8_t *r1; |
|
71 |
+ |
|
72 |
+ while(!*(r++)); |
|
73 |
+ r1 = ff_avc_find_startcode(r, buf1 + size); |
|
74 |
+ nal_send(s1, r, r1 - r, (r1 == buf1 + size)); |
|
75 |
+ r = r1; |
|
76 |
+ } |
|
77 |
+} |