+#ifdef DEBUG
+#define COUNT_NAL_TYPE(data, nal) data->packet_types_received[(nal) & 0x1f]++
+#define NAL_COUNTERS data->packet_types_received
+#else
+#define COUNT_NAL_TYPE(data, nal) do { } while (0)
+#define NAL_COUNTERS NULL
+#endif
+#define NAL_MASK 0x1f
+
+static const uint8_t start_sequence[] = { 0, 0, 0, 1 };
+
+static void parse_profile_level_id(AVFormatContext *s,
+ PayloadContext *h264_data,
+ const char *value)
+{
+ char buffer[3];
+ // 6 characters=3 bytes, in hex.
+ uint8_t profile_idc;
+ uint8_t profile_iop;
+ uint8_t level_idc;
+
+ buffer[0] = value[0];
+ buffer[1] = value[1];
+ buffer[2] = '\0';
+ profile_idc = strtol(buffer, NULL, 16);
+ buffer[0] = value[2];
+ buffer[1] = value[3];
+ profile_iop = strtol(buffer, NULL, 16);
+ buffer[0] = value[4];
+ buffer[1] = value[5];
+ level_idc = strtol(buffer, NULL, 16);
+
+ av_log(s, AV_LOG_DEBUG,
+ "RTP Profile IDC: %x Profile IOP: %x Level: %x\n",
+ profile_idc, profile_iop, level_idc);
+ h264_data->profile_idc = profile_idc;
+ h264_data->profile_iop = profile_iop;
+ h264_data->level_idc = level_idc;
+}
+
+int ff_h264_parse_sprop_parameter_sets(AVFormatContext *s,
+ uint8_t **data_ptr, int *size_ptr,
+ const char *value)
+{
+ char base64packet[1024];
+ uint8_t decoded_packet[1024];
+ int packet_size;
+
+ while (*value) {
+ char *dst = base64packet;
+
+ while (*value && *value != ','
+ && (dst - base64packet) < sizeof(base64packet) - 1) {
+ *dst++ = *value++;
+ }
+ *dst++ = '\0';
+
+ if (*value == ',')
+ value++;
+
+ packet_size = av_base64_decode(decoded_packet, base64packet,
+ sizeof(decoded_packet));
+ if (packet_size > 0) {
+ uint8_t *dest = av_realloc(*data_ptr,
+ packet_size + sizeof(start_sequence) +
+ *size_ptr +
+ AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!dest) {
+ av_log(s, AV_LOG_ERROR,
+ "Unable to allocate memory for extradata!\n");
+ return AVERROR(ENOMEM);
+ }
+ *data_ptr = dest;
+
+ memcpy(dest + *size_ptr, start_sequence,
+ sizeof(start_sequence));
+ memcpy(dest + *size_ptr + sizeof(start_sequence),
+ decoded_packet, packet_size);
+ memset(dest + *size_ptr + sizeof(start_sequence) +
+ packet_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+ *size_ptr += sizeof(start_sequence) + packet_size;
+ }
+ }
+
+ return 0;
+}
+
+static int sdp_parse_fmtp_config_h264(AVFormatContext *s,
+ AVStream *stream,
+ PayloadContext *h264_data,
+ const char *attr, const char *value)