FS-7517 FS-7519 add H264 STAP-A packetizing support so it would work with FireFox

This commit is contained in:
Seven Du 2015-06-17 09:42:35 +08:00
parent 5734b9b2ce
commit 8f7c2f9ed9
2 changed files with 60 additions and 0 deletions

View File

@ -187,6 +187,36 @@ static switch_status_t buffer_h264_nalu(h264_codec_context_t *context, switch_fr
}
switch_buffer_write(buffer, (void *)(data + 2), frame->datalen - 2);
} else if (nalu_type == 24) { // 0x18 STAP-A
uint16_t nalu_size;
int left = frame->datalen - 1;
data++;
again:
if (left > 2) {
nalu_size = ntohs(*(uint16_t *)data);
data += 2;
left -= 2;
if (nalu_size > left) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID PACKET\n");
context->got_pps = 0;
switch_buffer_zero(buffer);
return SWITCH_STATUS_FALSE;
}
nalu_hdr = *data;
nalu_type = nalu_hdr & 0x1f;
if (context->got_pps <= 0 && nalu_type == 7) context->got_pps = 1;
switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes));
switch_buffer_write(buffer, (void *)data, nalu_size);
data += nalu_size;
left -= nalu_size;
goto again;
}
} else {
switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes));
switch_buffer_write(buffer, frame->data, frame->datalen);

View File

@ -246,6 +246,36 @@ static switch_size_t buffer_h264_nalu(h264_codec_context_t *context, switch_fram
}
size = switch_buffer_write(buffer, (void *)(data + 2), frame->datalen - 2);
} else if (nalu_type == 24) { // 0x18 STAP-A
uint16_t nalu_size;
int left = frame->datalen - 1;
data++;
again:
if (left > 2) {
nalu_size = ntohs(*(uint16_t *)data);
data += 2;
left -= 2;
if (nalu_size > left) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID PACKET\n");
context->got_sps = 0;
switch_buffer_zero(buffer);
return SWITCH_STATUS_FALSE;
}
nalu_hdr = *data;
nalu_type = nalu_hdr & 0x1f;
if (context->got_sps <= 0 && nalu_type == 7) context->got_sps = 1;
size += switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes));
size += switch_buffer_write(buffer, (void *)data, nalu_size);
data += nalu_size;
left -= nalu_size;
goto again;
}
} else {
size = switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes));
size = switch_buffer_write(buffer, frame->data, frame->datalen);