static void parse_profile_level_id(AVFormatContext *s,
PayloadContext *h264_data,
- char *value)
+ const char *value)
{
char buffer[3];
// 6 characters=3 bytes, in hex.
uint8_t *dest = av_realloc(*data_ptr,
packet_size + sizeof(start_sequence) +
*size_ptr +
- FF_INPUT_BUFFER_PADDING_SIZE);
+ AV_INPUT_BUFFER_PADDING_SIZE);
if (!dest) {
av_log(s, AV_LOG_ERROR,
"Unable to allocate memory for extradata!\n");
memcpy(dest + *size_ptr + sizeof(start_sequence),
decoded_packet, packet_size);
memset(dest + *size_ptr + sizeof(start_sequence) +
- packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ packet_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
*size_ptr += sizeof(start_sequence) + packet_size;
}
static int sdp_parse_fmtp_config_h264(AVFormatContext *s,
AVStream *stream,
PayloadContext *h264_data,
- char *attr, char *value)
+ const char *attr, const char *value)
{
AVCodecContext *codec = stream->codec;
return 0;
}
+void ff_h264_parse_framesize(AVCodecContext *codec, const char *p)
+{
+ char buf1[50];
+ char *dst = buf1;
+
+ // remove the protocol identifier
+ while (*p && *p == ' ')
+ p++; // strip spaces.
+ while (*p && *p != ' ')
+ p++; // eat protocol identifier
+ while (*p && *p == ' ')
+ p++; // strip trailing spaces.
+ while (*p && *p != '-' && (dst - buf1) < sizeof(buf1) - 1)
+ *dst++ = *p++;
+ *dst = '\0';
+
+ // a='framesize:96 320-240'
+ // set our parameters
+ codec->width = atoi(buf1);
+ codec->height = atoi(p + 1); // skip the -
+}
+
int ff_h264_handle_aggregated_packet(AVFormatContext *ctx, AVPacket *pkt,
const uint8_t *buf, int len,
int skip_between, int *nal_counters,
return 0;
}
+int ff_h264_handle_frag_packet(AVPacket *pkt, const uint8_t *buf, int len,
+ int start_bit, const uint8_t *nal_header,
+ int nal_header_len)
+{
+ int ret;
+ int tot_len = len;
+ int pos = 0;
+ if (start_bit)
+ tot_len += sizeof(start_sequence) + nal_header_len;
+ if ((ret = av_new_packet(pkt, tot_len)) < 0)
+ return ret;
+ if (start_bit) {
+ memcpy(pkt->data + pos, start_sequence, sizeof(start_sequence));
+ pos += sizeof(start_sequence);
+ memcpy(pkt->data + pos, nal_header, nal_header_len);
+ pos += nal_header_len;
+ }
+ memcpy(pkt->data + pos, buf, len);
+ return 0;
+}
+
static int h264_handle_packet_fu_a(AVFormatContext *ctx, AVPacket *pkt,
const uint8_t *buf, int len,
int *nal_counters, int nal_mask)
{
uint8_t fu_indicator, fu_header, start_bit, nal_type, nal;
- int ret;
if (len < 3) {
av_log(ctx, AV_LOG_ERROR, "Too short data for FU-A H264 RTP packet\n");
buf += 2;
len -= 2;
- if (start_bit) {
- if (nal_counters)
- nal_counters[nal_type & nal_mask]++;
- /* copy in the start sequence, and the reconstructed nal */
- if ((ret = av_new_packet(pkt, sizeof(start_sequence) + sizeof(nal) + len)) < 0)
- return ret;
- memcpy(pkt->data, start_sequence, sizeof(start_sequence));
- pkt->data[sizeof(start_sequence)] = nal;
- memcpy(pkt->data + sizeof(start_sequence) + sizeof(nal), buf, len);
- } else {
- if ((ret = av_new_packet(pkt, len)) < 0)
- return ret;
- memcpy(pkt->data, buf, len);
- }
-
- return 0;
+ if (start_bit && nal_counters)
+ nal_counters[nal_type & nal_mask]++;
+ return ff_h264_handle_frag_packet(pkt, buf, len, start_bit, &nal, 1);
}
// return 0 on packet, no more left, 1 on packet, 1 on partial packet
return result;
}
-static PayloadContext *h264_new_context(void)
-{
- return av_mallocz(sizeof(PayloadContext));
-}
-
-static void h264_free_context(PayloadContext *data)
+static void h264_close_context(PayloadContext *data)
{
#ifdef DEBUG
int ii;
data->packet_types_received[ii], ii);
}
#endif
-
- av_free(data);
}
static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
PayloadContext *h264_data, const char *line)
{
AVStream *stream;
- AVCodecContext *codec;
const char *p = line;
if (st_index < 0)
return 0;
stream = s->streams[st_index];
- codec = stream->codec;
if (av_strstart(p, "framesize:", &p)) {
- char buf1[50];
- char *dst = buf1;
-
- // remove the protocol identifier
- while (*p && *p == ' ')
- p++; // strip spaces.
- while (*p && *p != ' ')
- p++; // eat protocol identifier
- while (*p && *p == ' ')
- p++; // strip trailing spaces.
- while (*p && *p != '-' && (dst - buf1) < sizeof(buf1) - 1)
- *dst++ = *p++;
- *dst = '\0';
-
- // a='framesize:96 320-240'
- // set our parameters
- codec->width = atoi(buf1);
- codec->height = atoi(p + 1); // skip the -
+ ff_h264_parse_framesize(stream->codec, p);
} else if (av_strstart(p, "fmtp:", &p)) {
return ff_parse_fmtp(s, stream, h264_data, p, sdp_parse_fmtp_config_h264);
} else if (av_strstart(p, "cliprect:", &p)) {
.codec_type = AVMEDIA_TYPE_VIDEO,
.codec_id = AV_CODEC_ID_H264,
.need_parsing = AVSTREAM_PARSE_FULL,
+ .priv_data_size = sizeof(PayloadContext),
.parse_sdp_a_line = parse_h264_sdp_line,
- .alloc = h264_new_context,
- .free = h264_free_context,
+ .close = h264_close_context,
.parse_packet = h264_handle_packet,
};