* commit 'a2efbecc4ed12d287cf29856418c4da4a7648d95':
libavformat: Move avc mp4 startcode parsing to a shared file
Merged-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -191,3 +191,20 @@ int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size) |
191 | 191 |
*size = out_size; |
192 | 192 |
return 0; |
193 | 193 |
} |
194 |
+ |
|
195 |
+const uint8_t *ff_avc_mp4_find_startcode(const uint8_t *start, |
|
196 |
+ const uint8_t *end, |
|
197 |
+ int nal_length_size) |
|
198 |
+{ |
|
199 |
+ unsigned int res = 0; |
|
200 |
+ |
|
201 |
+ if (end - start < nal_length_size) |
|
202 |
+ return NULL; |
|
203 |
+ while (nal_length_size--) |
|
204 |
+ res = (res << 8) | *start++; |
|
205 |
+ |
|
206 |
+ if (res > end - start) |
|
207 |
+ return NULL; |
|
208 |
+ |
|
209 |
+ return start + res; |
|
210 |
+} |
... | ... |
@@ -30,5 +30,8 @@ int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size); |
30 | 30 |
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len); |
31 | 31 |
const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end); |
32 | 32 |
int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size); |
33 |
+const uint8_t *ff_avc_mp4_find_startcode(const uint8_t *start, |
|
34 |
+ const uint8_t *end, |
|
35 |
+ int nal_length_size); |
|
33 | 36 |
|
34 | 37 |
#endif /* AVFORMAT_AVC_H */ |
... | ... |
@@ -29,21 +29,6 @@ |
29 | 29 |
#include "avc.h" |
30 | 30 |
#include "rtpenc.h" |
31 | 31 |
|
32 |
-static const uint8_t *avc_mp4_find_startcode(const uint8_t *start, const uint8_t *end, int nal_length_size) |
|
33 |
-{ |
|
34 |
- unsigned int res = 0; |
|
35 |
- |
|
36 |
- if (end - start < nal_length_size) |
|
37 |
- return NULL; |
|
38 |
- while (nal_length_size--) |
|
39 |
- res = (res << 8) | *start++; |
|
40 |
- |
|
41 |
- if (res > end - start) |
|
42 |
- return NULL; |
|
43 |
- |
|
44 |
- return start + res; |
|
45 |
-} |
|
46 |
- |
|
47 | 32 |
static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last) |
48 | 33 |
{ |
49 | 34 |
RTPMuxContext *s = s1->priv_data; |
... | ... |
@@ -88,14 +73,14 @@ void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size) |
88 | 88 |
|
89 | 89 |
s->timestamp = s->cur_timestamp; |
90 | 90 |
if (s->nal_length_size) |
91 |
- r = avc_mp4_find_startcode(buf1, end, s->nal_length_size) ? buf1 : end; |
|
91 |
+ r = ff_avc_mp4_find_startcode(buf1, end, s->nal_length_size) ? buf1 : end; |
|
92 | 92 |
else |
93 | 93 |
r = ff_avc_find_startcode(buf1, end); |
94 | 94 |
while (r < end) { |
95 | 95 |
const uint8_t *r1; |
96 | 96 |
|
97 | 97 |
if (s->nal_length_size) { |
98 |
- r1 = avc_mp4_find_startcode(r, end, s->nal_length_size); |
|
98 |
+ r1 = ff_avc_mp4_find_startcode(r, end, s->nal_length_size); |
|
99 | 99 |
if (!r1) |
100 | 100 |
r1 = end; |
101 | 101 |
r += s->nal_length_size; |