Don't modify the decode unit in place

This commit is contained in:
Cameron Gutman
2019-04-30 18:55:18 -07:00
parent 115966ce0f
commit 2f687cc58a
3 changed files with 45 additions and 79 deletions
+5 -41
View File
@@ -24,34 +24,16 @@
static h264_stream_t* h264_stream; static h264_stream_t* h264_stream;
static int initial_width, initial_height; static int initial_width, initial_height;
static int replay_sps;
void gs_sps_init(int width, int height) { void gs_sps_init(int width, int height) {
h264_stream = h264_new(); h264_stream = h264_new();
initial_width = width; initial_width = width;
initial_height = height; initial_height = height;
} }
void gs_sps_fix(PDECODE_UNIT decodeUnit, int flags) { void gs_sps_fix(PLENTRY sps, int flags, uint8_t* out_buf, uint32_t* out_offset) {
PLENTRY entry = decodeUnit->bufferList;
const char naluHeader[] = {0x00, 0x00, 0x00, 0x01}; const char naluHeader[] = {0x00, 0x00, 0x00, 0x01};
if (replay_sps == 1) { read_nal_unit(h264_stream, sps->data+4, sps->length-4);
PLENTRY replay_entry = (PLENTRY) malloc(sizeof(*replay_entry) + 128);
if (replay_entry == NULL)
return;
replay_entry->data = (char *) (entry + 1);
memcpy(replay_entry->data, naluHeader, sizeof(naluHeader));
h264_stream->sps->profile_idc = H264_PROFILE_HIGH;
replay_entry->length = write_nal_unit(h264_stream, replay_entry->data+4, 124) + 4;
decodeUnit->fullLength += replay_entry->length;
replay_entry->next = entry;
entry = replay_entry;
replay_sps = 2;
} else if ((entry->data[4] & 0x1F) == NAL_UNIT_TYPE_SPS) {
read_nal_unit(h264_stream, entry->data+4, entry->length-4);
// Some decoders rely on H264 level to decide how many buffers are needed // Some decoders rely on H264 level to decide how many buffers are needed
// Since we only need one frame buffered, we'll set level as low as we can // Since we only need one frame buffered, we'll set level as low as we can
@@ -93,26 +75,8 @@ void gs_sps_fix(PDECODE_UNIT decodeUnit, int flags) {
} else // Devices that didn't/couldn't get bitstream restrictions before GFE 2.5.11 will continue to not receive them now } else // Devices that didn't/couldn't get bitstream restrictions before GFE 2.5.11 will continue to not receive them now
h264_stream->sps->vui.bitstream_restriction_flag = 0; h264_stream->sps->vui.bitstream_restriction_flag = 0;
if ((flags & GS_SPS_BASELINE_HACK) == GS_SPS_BASELINE_HACK && !replay_sps) memcpy(out_buf+*out_offset, naluHeader, 4);
h264_stream->sps->profile_idc = H264_PROFILE_BASELINE; *out_offset += 4;
PLENTRY sps_entry = (PLENTRY) malloc(sizeof(*sps_entry) + 128);
if (sps_entry == NULL)
return;
PLENTRY next = entry->next;
decodeUnit->fullLength -= entry->length;
free(entry);
sps_entry->data = (char*) (sps_entry + 1);
memcpy(sps_entry->data, naluHeader, sizeof(naluHeader));
sps_entry->length = write_nal_unit(h264_stream, sps_entry->data+4, 124) + 4;
sps_entry->next = next;
entry = sps_entry;
decodeUnit->fullLength += entry->length;
} else if ((entry->data[4] & 0x1F) == NAL_UNIT_TYPE_PPS) {
if ((flags & GS_SPS_BASELINE_HACK) == GS_SPS_BASELINE_HACK && !replay_sps)
replay_sps = 1;
} *out_offset = write_nal_unit(h264_stream, out_buf+*out_offset, 128);
decodeUnit->bufferList = entry;
} }
+1 -2
View File
@@ -20,7 +20,6 @@
#include <Limelight.h> #include <Limelight.h>
#define GS_SPS_BITSTREAM_FIXUP 0x01 #define GS_SPS_BITSTREAM_FIXUP 0x01
#define GS_SPS_BASELINE_HACK 0x02
void gs_sps_init(int width, int height); void gs_sps_init(int width, int height);
void gs_sps_fix(PDECODE_UNIT decodeUnit, int flags); void gs_sps_fix(PLENTRY sps, int flags, uint8_t* out_buf, uint32_t* out_offset);
+4 -1
View File
@@ -209,7 +209,6 @@ static void decoder_renderer_cleanup() {
static int decoder_renderer_submit_decode_unit(PDECODE_UNIT decodeUnit) { static int decoder_renderer_submit_decode_unit(PDECODE_UNIT decodeUnit) {
OMX_BUFFERHEADERTYPE *buf = NULL; OMX_BUFFERHEADERTYPE *buf = NULL;
gs_sps_fix(decodeUnit, GS_SPS_BITSTREAM_FIXUP);
PLENTRY entry = decodeUnit->bufferList; PLENTRY entry = decodeUnit->bufferList;
while (entry != NULL) { while (entry != NULL) {
if (buf == NULL) { if (buf == NULL) {
@@ -226,8 +225,12 @@ static int decoder_renderer_submit_decode_unit(PDECODE_UNIT decodeUnit) {
} }
} }
if (entry->bufferType == BUFFER_TYPE_SPS)
gs_sps_fix(entry, GS_SPS_BITSTREAM_FIXUP, buf->pBuffer, &buf->nFilledLen);
else {
memcpy(buf->pBuffer + buf->nFilledLen, entry->data, entry->length); memcpy(buf->pBuffer + buf->nFilledLen, entry->data, entry->length);
buf->nFilledLen += entry->length; buf->nFilledLen += entry->length;
}
if (entry->bufferType != BUFFER_TYPE_PICDATA || entry->next == NULL || entry->next->bufferType != BUFFER_TYPE_PICDATA) { if (entry->bufferType != BUFFER_TYPE_PICDATA || entry->next == NULL || entry->next->bufferType != BUFFER_TYPE_PICDATA) {
if(port_settings_changed == 0 && ((buf->nFilledLen > 0 && ilclient_remove_event(video_decode, OMX_EventPortSettingsChanged, 131, 0, 0, 1) == 0) || (buf->nFilledLen == 0 && ilclient_wait_for_event(video_decode, OMX_EventPortSettingsChanged, 131, 0, 0, 1, ILCLIENT_EVENT_ERROR | ILCLIENT_PARAMETER_CHANGED, 10000) == 0))) { if(port_settings_changed == 0 && ((buf->nFilledLen > 0 && ilclient_remove_event(video_decode, OMX_EventPortSettingsChanged, 131, 0, 0, 1) == 0) || (buf->nFilledLen == 0 && ilclient_wait_for_event(video_decode, OMX_EventPortSettingsChanged, 131, 0, 0, 1, ILCLIENT_EVENT_ERROR | ILCLIENT_PARAMETER_CHANGED, 10000) == 0))) {