68 const uint8_t *a = p + 4 - ((intptr_t)p & 3);
70 for (end -= 3; p < a && p < end; p++) {
71 if (p[0] == 0 && p[1] == 0 && p[2] == 1)
75 for (end -= 3; p < end; p += 4) {
76 uint32_t x = *(
const uint32_t*)p;
77 if ((x - 0x01010101) & (~x) & 0x80808080) {
79 if (p[0] == 0 && p[2] == 1)
81 if (p[2] == 0 && p[3] == 1)
85 if (p[2] == 0 && p[4] == 1)
87 if (p[4] == 0 && p[5] == 1)
93 for (end += 3; p < end; p++) {
94 if (p[0] == 0 && p[1] == 0 && p[2] == 1)
105 if (p < out && out < end && !out[-1]) {
117 context->
type = type;
168 for (i = 0; i < n_sps; i++) {
169 sps_len = ntohs(*(uint16_t *)p);
170 p +=
sizeof(uint16_t);
171 left -=
sizeof(uint16_t);
173 if (left < sps_len) {
193 for (i = 0; i < n_pps; i++) {
194 pps_len = ntohs(*(uint16_t *)p);
195 p +=
sizeof(uint16_t);
196 left -=
sizeof(uint16_t);
198 if (left < pps_len) {
217 const uint8_t *p = data;
218 const uint8_t *end = p + size;
233 len = htonl(*(uint32_t *)p);
234 left -=
sizeof(uint32_t);
237 p +=
sizeof(uint32_t);
291 uint8_t nalu_hdr = 0;
292 uint8_t nalu_type = 0;
295 uint8_t *p = frame->
data;
297 int n = nalu->
len / slice_size + 1;
298 int real_slice_size = nalu->
len / n + 1 + 2;
300 if (nalu->
start == NULL) {
305 nalu_hdr = *(uint8_t *)(nalu->
start);
306 nalu_type = nalu_hdr & 0x1f;
307 nri = nalu_hdr & 0x60;
309 if (real_slice_size > slice_size) real_slice_size = slice_size;
310 if (frame->
datalen < slice_size) {
316 if (nalu_type == 0x05) {
331 }
else if (nalu_type == 0x07) {
333 }
else if (nalu_type == 0x08) {
338 if (nalu->
len <= slice_size) {
352 if (nalu_type == 0x05) {
360 if (left <= (real_slice_size - 2)) {
362 p[1] = 0x40 | nalu_type;
363 memcpy(p+2, nalu->
eat, left);
377 p[1] = start | nalu_type;
378 if (start) nalu->
eat++;
379 memcpy(p+2, nalu->
eat, real_slice_size - 2);
380 nalu->
eat += (real_slice_size - 2);
381 frame->
datalen = real_slice_size;
void switch_packetizer_close(switch_packetizer_t **packetizer)
#define SWITCH_CHANNEL_LOG
switch_status_t switch_packetizer_feed(switch_packetizer_t *packetizer, void *data, uint32_t size)
switch_packetizer_t * switch_packetizer_create(switch_packetizer_bitstream_t type, uint32_t slice_size)
const uint8_t * ff_avc_find_startcode(const uint8_t *p, const uint8_t *end)
our_h264_nalu_t nalus[MAX_NALUS]
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
static const uint8_t * fs_avc_find_startcode(const uint8_t *p, const uint8_t *end)
struct our_h264_nalu_s our_h264_nalu_t
An abstraction of a data frame.
struct h264_packetizer_s h264_packetizer_t
switch_packetizer_bitstream_t type
switch_status_t switch_packetizer_read(switch_packetizer_t *packetizer, switch_frame_t *frame)
switch_status_t switch_packetizer_feed_extradata(switch_packetizer_t *packetizer, void *data, uint32_t size)
switch_status_t
Common return values.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_packetizer_bitstream_t
static const uint8_t * fs_avc_find_startcode_internal(const uint8_t *p, const uint8_t *end)