Mercurial > libavformat.hg
comparison avc.c @ 5686:a84525174bcf libavformat
Attempt to fix the completely random values returned by ff_avc_find_startcode().
author | michael |
---|---|
date | Mon, 22 Feb 2010 00:34:27 +0000 |
parents | 6ea4f08de89a |
children | d63669d827bc |
comparison
equal
deleted
inserted
replaced
5685:e8614dbd9b7b | 5686:a84525174bcf |
---|---|
21 | 21 |
22 #include "libavutil/intreadwrite.h" | 22 #include "libavutil/intreadwrite.h" |
23 #include "avformat.h" | 23 #include "avformat.h" |
24 #include "avio.h" | 24 #include "avio.h" |
25 | 25 |
26 const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end) | 26 static const uint8_t *ff_avc_find_startcode_internal(const uint8_t *p, const uint8_t *end) |
27 { | 27 { |
28 const uint8_t *a = p + 4 - ((intptr_t)p & 3); | 28 const uint8_t *a = p + 4 - ((intptr_t)p & 3); |
29 | 29 |
30 for (end -= 3; p < a && p < end; p++) { | 30 for (end -= 3; p < a && p < end; p++) { |
31 if (p[0] == 0 && p[1] == 0 && p[2] == 1) | 31 if (p[0] == 0 && p[1] == 0 && p[2] == 1) |
37 // if ((x - 0x01000100) & (~x) & 0x80008000) // little endian | 37 // if ((x - 0x01000100) & (~x) & 0x80008000) // little endian |
38 // if ((x - 0x00010001) & (~x) & 0x00800080) // big endian | 38 // if ((x - 0x00010001) & (~x) & 0x00800080) // big endian |
39 if ((x - 0x01010101) & (~x) & 0x80808080) { // generic | 39 if ((x - 0x01010101) & (~x) & 0x80808080) { // generic |
40 if (p[1] == 0) { | 40 if (p[1] == 0) { |
41 if (p[0] == 0 && p[2] == 1) | 41 if (p[0] == 0 && p[2] == 1) |
42 return p-1; | 42 return p; |
43 if (p[2] == 0 && p[3] == 1) | 43 if (p[2] == 0 && p[3] == 1) |
44 return p; | 44 return p+1; |
45 } | 45 } |
46 if (p[3] == 0) { | 46 if (p[3] == 0) { |
47 if (p[2] == 0 && p[4] == 1) | 47 if (p[2] == 0 && p[4] == 1) |
48 return p+1; | 48 return p+2; |
49 if (p[4] == 0 && p[5] == 1) | 49 if (p[4] == 0 && p[5] == 1) |
50 return p+2; | 50 return p+3; |
51 } | 51 } |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 for (end += 3; p < end; p++) { | 55 for (end += 3; p < end; p++) { |
56 if (p[0] == 0 && p[1] == 0 && p[2] == 1) | 56 if (p[0] == 0 && p[1] == 0 && p[2] == 1) |
57 return p; | 57 return p; |
58 } | 58 } |
59 | 59 |
60 return end + 3; | 60 return end + 3; |
61 } | |
62 | |
63 const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end){ | |
64 const uint8_t *out= ff_avc_find_startcode_internal(p, end); | |
65 if(p<out && out<end && !out[-1]) out--; | |
66 return out; | |
61 } | 67 } |
62 | 68 |
63 int ff_avc_parse_nal_units(ByteIOContext *pb, const uint8_t *buf_in, int size) | 69 int ff_avc_parse_nal_units(ByteIOContext *pb, const uint8_t *buf_in, int size) |
64 { | 70 { |
65 const uint8_t *p = buf_in; | 71 const uint8_t *p = buf_in; |