| 1 | commit e7c7b2d87842c689ae7da4d6d636a08cb1e9ce88
|
|---|
| 2 | Author: Luca Abeni <lucabe72@email.it>
|
|---|
| 3 | Date: Wed Jun 15 17:59:03 2011 +0200
|
|---|
| 4 |
|
|---|
| 5 | Full support for sending H.264 in RTP
|
|---|
| 6 |
|
|---|
| 7 | This implements support for the "MP4" syntax of H.264 bitstreams.
|
|---|
| 8 |
|
|---|
| 9 | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
|
|---|
| 10 |
|
|---|
| 11 | diff --git a/libavformat/rtpenc_h264.c b/libavformat/rtpenc_h264.c
|
|---|
| 12 | index 697def6..be9cb2c 100644
|
|---|
| 13 | --- a/libavformat/rtpenc_h264.c
|
|---|
| 14 | +++ b/libavformat/rtpenc_h264.c
|
|---|
| 15 | @@ -29,6 +29,24 @@
|
|---|
| 16 | #include "avc.h"
|
|---|
| 17 | #include "rtpenc.h"
|
|---|
| 18 |
|
|---|
| 19 | +static const uint8_t *avc_mp4_find_startcode(const uint8_t *start, const uint8_t *end, int nal_lenght_size)
|
|---|
| 20 | +{
|
|---|
| 21 | + int res = 0;
|
|---|
| 22 | +
|
|---|
| 23 | + if (end - start < nal_lenght_size) {
|
|---|
| 24 | + return NULL;
|
|---|
| 25 | + }
|
|---|
| 26 | + while (nal_lenght_size--) {
|
|---|
| 27 | + res = (res << 8) | *start++;
|
|---|
| 28 | + }
|
|---|
| 29 | +
|
|---|
| 30 | + if (res + start > end) {
|
|---|
| 31 | + return NULL;
|
|---|
| 32 | + }
|
|---|
| 33 | +
|
|---|
| 34 | + return res + start;
|
|---|
| 35 | +}
|
|---|
| 36 | +
|
|---|
| 37 | static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last)
|
|---|
| 38 | {
|
|---|
| 39 | RTPMuxContext *s = s1->priv_data;
|
|---|
| 40 | @@ -66,12 +84,20 @@ void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size)
|
|---|
| 41 | RTPMuxContext *s = s1->priv_data;
|
|---|
| 42 |
|
|---|
| 43 | s->timestamp = s->cur_timestamp;
|
|---|
| 44 | - r = ff_avc_find_startcode(buf1, buf1 + size);
|
|---|
| 45 | + r = s->nal_length_size ? (avc_mp4_find_startcode(buf1, buf1 + size, s->nal_length_size) ? buf1 : buf1 + size) : ff_avc_find_startcode(buf1, buf1 + size);
|
|---|
| 46 | while (r < buf1 + size) {
|
|---|
| 47 | const uint8_t *r1;
|
|---|
| 48 |
|
|---|
| 49 | - while(!*(r++));
|
|---|
| 50 | - r1 = ff_avc_find_startcode(r, buf1 + size);
|
|---|
| 51 | + if (s->nal_length_size) {
|
|---|
| 52 | + r1 = avc_mp4_find_startcode(r, buf1 + size, s->nal_length_size);
|
|---|
| 53 | + if (!r1) {
|
|---|
| 54 | + r1 = buf1 + size;
|
|---|
| 55 | + }
|
|---|
| 56 | + r += s->nal_length_size;
|
|---|
| 57 | + } else {
|
|---|
| 58 | + while(!*(r++));
|
|---|
| 59 | + r1 = ff_avc_find_startcode(r, buf1 + size);
|
|---|
| 60 | + }
|
|---|
| 61 | nal_send(s1, r, r1 - r, (r1 == buf1 + size));
|
|---|
| 62 | r = r1;
|
|---|
| 63 | }
|
|---|