]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7517 FS-7519 add H264 STAP-A packetizing support so it would work with FireFox
authorSeven Du <dujinfang@gmail.com>
Wed, 17 Jun 2015 01:42:35 +0000 (09:42 +0800)
committerSeven Du <dujinfang@gmail.com>
Wed, 17 Jun 2015 01:43:00 +0000 (09:43 +0800)
src/mod/applications/mod_av/avcodec.c
src/mod/codecs/mod_openh264/mod_openh264.cpp

index f2b62a1eee8cfea7e9c16e3835c0cdf62b902cf7..9537ae43db021e2b20a36283786967a0a4cc5a1f 100644 (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);
index fa2ddfaf1e34ed2e4e36831ab262408b03edeacb..c2e0fc8eeed9ad50f0be9cf58d2a8f02b7b42dd8 100644 (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);