2006-11-08 00:10:07 +02:00
|
|
|
/*
|
|
|
|
* RTP H264 Protocol (RFC3984)
|
2009-01-19 17:46:40 +02:00
|
|
|
* Copyright (c) 2006 Ryan Martell
|
2006-11-08 00:10:07 +02:00
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* This file is part of Libav.
|
2006-11-08 00:10:07 +02:00
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2006-11-08 00:10:07 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2006-11-08 00:10:07 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 19:35:10 +02:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2006-11-08 00:10:07 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-05-05 00:05:52 +03:00
|
|
|
* @file
|
2006-11-08 00:10:07 +02:00
|
|
|
* @brief H.264 / RTP Code (RFC3984)
|
|
|
|
* @author Ryan Martell <rdm4@martellventures.com>
|
|
|
|
*
|
|
|
|
* @note Notes:
|
|
|
|
* Notes:
|
|
|
|
* This currently supports packetization mode:
|
|
|
|
* Single Nal Unit Mode (0), or
|
|
|
|
* Non-Interleaved Mode (1). It currently does not support
|
2012-05-05 00:05:52 +03:00
|
|
|
* Interleaved Mode (2). (This requires implementing STAP-B, MTAP16, MTAP24,
|
|
|
|
* FU-B packet types)
|
2006-11-08 00:10:07 +02:00
|
|
|
*/
|
|
|
|
|
2013-04-18 16:54:26 +03:00
|
|
|
#include "libavutil/attributes.h"
|
2008-05-09 14:56:36 +03:00
|
|
|
#include "libavutil/base64.h"
|
2015-02-19 21:04:45 +02:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2008-05-09 14:56:36 +03:00
|
|
|
#include "libavutil/avstring.h"
|
2006-11-08 00:10:07 +02:00
|
|
|
#include "avformat.h"
|
|
|
|
|
2009-02-06 12:35:52 +02:00
|
|
|
#include "rtpdec.h"
|
2010-07-30 15:04:27 +03:00
|
|
|
#include "rtpdec_formats.h"
|
2006-11-08 00:10:07 +02:00
|
|
|
|
2008-10-04 07:11:12 +03:00
|
|
|
struct PayloadContext {
|
2012-05-05 00:05:52 +03:00
|
|
|
// sdp setup parameters
|
2012-05-04 23:46:18 +03:00
|
|
|
uint8_t profile_idc;
|
|
|
|
uint8_t profile_iop;
|
|
|
|
uint8_t level_idc;
|
|
|
|
int packetization_mode;
|
2006-11-08 00:10:07 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
int packet_types_received[32];
|
|
|
|
#endif
|
2008-10-04 07:11:12 +03:00
|
|
|
};
|
2006-11-08 00:10:07 +02:00
|
|
|
|
2012-05-05 00:28:25 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define COUNT_NAL_TYPE(data, nal) data->packet_types_received[(nal) & 0x1f]++
|
2015-02-19 22:12:21 +02:00
|
|
|
#define NAL_COUNTERS data->packet_types_received
|
2012-05-05 00:28:25 +03:00
|
|
|
#else
|
|
|
|
#define COUNT_NAL_TYPE(data, nal) do { } while (0)
|
2015-02-19 22:12:21 +02:00
|
|
|
#define NAL_COUNTERS NULL
|
2012-05-05 00:28:25 +03:00
|
|
|
#endif
|
2015-02-19 22:12:21 +02:00
|
|
|
#define NAL_MASK 0x1f
|
2012-05-05 00:28:25 +03:00
|
|
|
|
2012-05-05 00:33:39 +03:00
|
|
|
static const uint8_t start_sequence[] = { 0, 0, 0, 1 };
|
|
|
|
|
2015-02-14 00:38:14 +02:00
|
|
|
static void parse_profile_level_id(AVFormatContext *s,
|
|
|
|
PayloadContext *h264_data,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-02-19 22:18:55 +02:00
|
|
|
int ff_h264_parse_sprop_parameter_sets(AVFormatContext *s,
|
|
|
|
uint8_t **data_ptr, int *size_ptr,
|
|
|
|
const char *value)
|
2015-02-14 00:38:14 +02:00
|
|
|
{
|
|
|
|
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) {
|
2015-02-19 21:19:29 +02:00
|
|
|
uint8_t *dest = av_realloc(*data_ptr,
|
2015-02-19 21:12:06 +02:00
|
|
|
packet_size + sizeof(start_sequence) +
|
2015-02-19 21:19:29 +02:00
|
|
|
*size_ptr +
|
2015-02-19 21:12:06 +02:00
|
|
|
FF_INPUT_BUFFER_PADDING_SIZE);
|
2015-02-14 00:38:14 +02:00
|
|
|
if (!dest) {
|
|
|
|
av_log(s, AV_LOG_ERROR,
|
|
|
|
"Unable to allocate memory for extradata!\n");
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
2015-02-19 21:19:29 +02:00
|
|
|
*data_ptr = dest;
|
2015-02-14 00:38:14 +02:00
|
|
|
|
2015-02-19 21:19:29 +02:00
|
|
|
memcpy(dest + *size_ptr, start_sequence,
|
2015-02-14 00:38:14 +02:00
|
|
|
sizeof(start_sequence));
|
2015-02-19 21:19:29 +02:00
|
|
|
memcpy(dest + *size_ptr + sizeof(start_sequence),
|
2015-02-14 00:38:14 +02:00
|
|
|
decoded_packet, packet_size);
|
2015-02-19 21:19:29 +02:00
|
|
|
memset(dest + *size_ptr + sizeof(start_sequence) +
|
2015-02-14 00:38:14 +02:00
|
|
|
packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
|
2015-02-19 21:19:29 +02:00
|
|
|
*size_ptr += sizeof(start_sequence) + packet_size;
|
2015-02-14 00:38:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-05 10:01:07 +03:00
|
|
|
static int sdp_parse_fmtp_config_h264(AVFormatContext *s,
|
|
|
|
AVStream *stream,
|
2012-05-05 17:42:15 +03:00
|
|
|
PayloadContext *h264_data,
|
2010-06-28 14:26:29 +03:00
|
|
|
char *attr, char *value)
|
2006-11-08 00:10:07 +02:00
|
|
|
{
|
|
|
|
AVCodecContext *codec = stream->codec;
|
|
|
|
|
|
|
|
if (!strcmp(attr, "packetization-mode")) {
|
2014-07-05 10:01:07 +03:00
|
|
|
av_log(s, AV_LOG_DEBUG, "RTP Packetization Mode: %d\n", atoi(value));
|
2007-08-10 16:34:56 +03:00
|
|
|
h264_data->packetization_mode = atoi(value);
|
2006-11-08 00:10:07 +02:00
|
|
|
/*
|
2012-05-05 00:05:52 +03:00
|
|
|
* Packetization Mode:
|
|
|
|
* 0 or not present: Single NAL mode (Only nals from 1-23 are allowed)
|
|
|
|
* 1: Non-interleaved Mode: 1-23, 24 (STAP-A), 28 (FU-A) are allowed.
|
|
|
|
* 2: Interleaved Mode: 25 (STAP-B), 26 (MTAP16), 27 (MTAP24), 28 (FU-A),
|
|
|
|
* and 29 (FU-B) are allowed.
|
2006-11-08 00:10:07 +02:00
|
|
|
*/
|
|
|
|
if (h264_data->packetization_mode > 1)
|
2014-07-05 10:01:07 +03:00
|
|
|
av_log(s, AV_LOG_ERROR,
|
2012-05-05 20:48:08 +03:00
|
|
|
"Interleaved RTP mode is not supported yet.\n");
|
2006-11-08 00:10:07 +02:00
|
|
|
} else if (!strcmp(attr, "profile-level-id")) {
|
2015-02-14 00:38:14 +02:00
|
|
|
if (strlen(value) == 6)
|
|
|
|
parse_profile_level_id(s, h264_data, value);
|
2012-05-05 17:42:15 +03:00
|
|
|
} else if (!strcmp(attr, "sprop-parameter-sets")) {
|
2015-02-19 21:19:29 +02:00
|
|
|
int ret;
|
2012-05-05 17:42:15 +03:00
|
|
|
codec->extradata_size = 0;
|
2012-05-05 16:55:20 +03:00
|
|
|
av_freep(&codec->extradata);
|
2015-02-19 22:18:55 +02:00
|
|
|
ret = ff_h264_parse_sprop_parameter_sets(s, &codec->extradata,
|
|
|
|
&codec->extradata_size, value);
|
2015-02-19 21:19:29 +02:00
|
|
|
av_log(s, AV_LOG_DEBUG, "Extradata set to %p (size: %d)\n",
|
|
|
|
codec->extradata, codec->extradata_size);
|
|
|
|
return ret;
|
2006-11-08 00:10:07 +02:00
|
|
|
}
|
2010-06-28 14:25:39 +03:00
|
|
|
return 0;
|
2006-11-08 00:10:07 +02:00
|
|
|
}
|
|
|
|
|
2015-02-19 22:18:55 +02:00
|
|
|
int ff_h264_handle_aggregated_packet(AVFormatContext *ctx, AVPacket *pkt,
|
2015-02-19 21:40:48 +02:00
|
|
|
const uint8_t *buf, int len,
|
2015-02-22 23:25:28 +02:00
|
|
|
int skip_between, int *nal_counters,
|
2015-02-19 22:12:21 +02:00
|
|
|
int nal_mask)
|
2015-02-14 00:38:14 +02:00
|
|
|
{
|
|
|
|
int pass = 0;
|
|
|
|
int total_length = 0;
|
|
|
|
uint8_t *dst = NULL;
|
|
|
|
int ret;
|
|
|
|
|
2015-02-19 21:49:18 +02:00
|
|
|
// first we are going to figure out the total size
|
2015-02-14 00:38:14 +02:00
|
|
|
for (pass = 0; pass < 2; pass++) {
|
|
|
|
const uint8_t *src = buf;
|
|
|
|
int src_len = len;
|
|
|
|
|
|
|
|
while (src_len > 2) {
|
|
|
|
uint16_t nal_size = AV_RB16(src);
|
|
|
|
|
|
|
|
// consume the length of the aggregate
|
|
|
|
src += 2;
|
|
|
|
src_len -= 2;
|
|
|
|
|
|
|
|
if (nal_size <= src_len) {
|
|
|
|
if (pass == 0) {
|
|
|
|
// counting
|
|
|
|
total_length += sizeof(start_sequence) + nal_size;
|
|
|
|
} else {
|
|
|
|
// copying
|
|
|
|
memcpy(dst, start_sequence, sizeof(start_sequence));
|
|
|
|
dst += sizeof(start_sequence);
|
|
|
|
memcpy(dst, src, nal_size);
|
2015-02-19 22:12:21 +02:00
|
|
|
if (nal_counters)
|
|
|
|
nal_counters[(*src) & nal_mask]++;
|
2015-02-14 00:38:14 +02:00
|
|
|
dst += nal_size;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"nal size exceeds length: %d %d\n", nal_size, src_len);
|
2015-02-19 21:28:01 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2015-02-14 00:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// eat what we handled
|
2015-02-22 23:25:28 +02:00
|
|
|
src += nal_size + skip_between;
|
|
|
|
src_len -= nal_size + skip_between;
|
2015-02-14 00:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pass == 0) {
|
|
|
|
/* now we know the total size of the packet (with the
|
|
|
|
* start sequences added) */
|
|
|
|
if ((ret = av_new_packet(pkt, total_length)) < 0)
|
|
|
|
return ret;
|
|
|
|
dst = pkt->data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:38:14 +02:00
|
|
|
static int h264_handle_packet_fu_a(AVFormatContext *ctx, AVPacket *pkt,
|
2015-02-19 22:12:21 +02:00
|
|
|
const uint8_t *buf, int len,
|
|
|
|
int *nal_counters, int nal_mask)
|
2015-02-14 00:38:14 +02:00
|
|
|
{
|
|
|
|
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");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
fu_indicator = buf[0];
|
|
|
|
fu_header = buf[1];
|
|
|
|
start_bit = fu_header >> 7;
|
|
|
|
nal_type = fu_header & 0x1f;
|
|
|
|
nal = fu_indicator & 0xe0 | nal_type;
|
|
|
|
|
|
|
|
// skip the fu_indicator and fu_header
|
|
|
|
buf += 2;
|
|
|
|
len -= 2;
|
|
|
|
|
|
|
|
if (start_bit) {
|
2015-02-19 22:12:21 +02:00
|
|
|
if (nal_counters)
|
|
|
|
nal_counters[nal_type & nal_mask]++;
|
2015-02-14 00:38:14 +02:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2012-05-05 00:05:52 +03:00
|
|
|
// return 0 on packet, no more left, 1 on packet, 1 on partial packet
|
2012-05-05 17:42:15 +03:00
|
|
|
static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
|
|
|
|
AVStream *st, AVPacket *pkt, uint32_t *timestamp,
|
2012-12-10 15:38:32 +03:00
|
|
|
const uint8_t *buf, int len, uint16_t seq,
|
|
|
|
int flags)
|
2006-11-08 00:10:07 +02:00
|
|
|
{
|
2012-05-04 22:31:46 +03:00
|
|
|
uint8_t nal;
|
|
|
|
uint8_t type;
|
2012-05-05 17:42:15 +03:00
|
|
|
int result = 0;
|
2006-11-08 00:10:07 +02:00
|
|
|
|
2012-05-04 22:31:46 +03:00
|
|
|
if (!len) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
nal = buf[0];
|
|
|
|
type = nal & 0x1f;
|
|
|
|
|
2012-05-05 00:05:52 +03:00
|
|
|
/* Simplify the case (these are all the nal types used internally by
|
|
|
|
* the h264 codec). */
|
2006-11-08 00:10:07 +02:00
|
|
|
if (type >= 1 && type <= 23)
|
2012-05-05 00:05:52 +03:00
|
|
|
type = 1;
|
2006-11-08 00:10:07 +02:00
|
|
|
switch (type) {
|
2010-12-06 14:44:09 +02:00
|
|
|
case 0: // undefined, but pass them through
|
2006-11-08 00:10:07 +02:00
|
|
|
case 1:
|
2013-12-13 03:27:26 +03:00
|
|
|
if ((result = av_new_packet(pkt, len + sizeof(start_sequence))) < 0)
|
|
|
|
return result;
|
2006-11-08 00:10:07 +02:00
|
|
|
memcpy(pkt->data, start_sequence, sizeof(start_sequence));
|
2012-05-05 17:42:15 +03:00
|
|
|
memcpy(pkt->data + sizeof(start_sequence), buf, len);
|
2012-05-05 00:28:25 +03:00
|
|
|
COUNT_NAL_TYPE(data, nal);
|
2006-11-08 00:10:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 24: // STAP-A (one packet, multiple nals)
|
|
|
|
// consume the STAP-A NAL
|
|
|
|
buf++;
|
|
|
|
len--;
|
2015-02-19 22:18:55 +02:00
|
|
|
result = ff_h264_handle_aggregated_packet(ctx, pkt, buf, len, 0,
|
|
|
|
NAL_COUNTERS, NAL_MASK);
|
2006-11-08 00:10:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 25: // STAP-B
|
|
|
|
case 26: // MTAP-16
|
|
|
|
case 27: // MTAP-24
|
|
|
|
case 29: // FU-B
|
2009-03-02 11:28:37 +02:00
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
2015-02-20 20:57:17 +02:00
|
|
|
"Unhandled type (%d) (See RFC for implementation details)\n",
|
2006-11-08 00:10:07 +02:00
|
|
|
type);
|
2012-05-05 00:29:15 +03:00
|
|
|
result = AVERROR(ENOSYS);
|
2006-11-08 00:10:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 28: // FU-A (fragmented nal)
|
2015-02-19 22:12:21 +02:00
|
|
|
result = h264_handle_packet_fu_a(ctx, pkt, buf, len,
|
|
|
|
NAL_COUNTERS, NAL_MASK);
|
2006-11-08 00:10:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 30: // undefined
|
|
|
|
case 31: // undefined
|
|
|
|
default:
|
2012-05-05 20:48:08 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)\n", type);
|
2012-05-05 00:29:15 +03:00
|
|
|
result = AVERROR_INVALIDDATA;
|
2006-11-08 00:10:07 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-03-03 15:51:34 +02:00
|
|
|
pkt->stream_index = st->index;
|
|
|
|
|
2006-11-08 00:10:07 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-07-27 17:29:06 +03:00
|
|
|
static PayloadContext *h264_new_context(void)
|
2006-11-08 00:10:07 +02:00
|
|
|
{
|
2015-02-23 22:03:44 +02:00
|
|
|
return av_mallocz(sizeof(PayloadContext));
|
2006-11-08 00:10:07 +02:00
|
|
|
}
|
|
|
|
|
2009-07-27 17:29:06 +03:00
|
|
|
static void h264_free_context(PayloadContext *data)
|
2006-11-08 00:10:07 +02:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
int ii;
|
|
|
|
|
|
|
|
for (ii = 0; ii < 32; ii++) {
|
|
|
|
if (data->packet_types_received[ii])
|
|
|
|
av_log(NULL, AV_LOG_DEBUG, "Received %d packets of type %d\n",
|
|
|
|
data->packet_types_received[ii], ii);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
av_free(data);
|
|
|
|
}
|
|
|
|
|
2013-04-18 16:54:26 +03:00
|
|
|
static av_cold int h264_init(AVFormatContext *s, int st_index,
|
|
|
|
PayloadContext *data)
|
2013-01-17 16:29:12 +03:00
|
|
|
{
|
|
|
|
if (st_index < 0)
|
|
|
|
return 0;
|
|
|
|
s->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-06 20:41:17 +02:00
|
|
|
static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
|
|
|
|
PayloadContext *h264_data, const char *line)
|
2006-11-08 00:10:07 +02:00
|
|
|
{
|
2012-04-06 23:07:12 +03:00
|
|
|
AVStream *stream;
|
|
|
|
AVCodecContext *codec;
|
2006-11-08 00:10:07 +02:00
|
|
|
const char *p = line;
|
|
|
|
|
2012-04-06 23:07:12 +03:00
|
|
|
if (st_index < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
stream = s->streams[st_index];
|
2012-05-05 17:42:15 +03:00
|
|
|
codec = stream->codec;
|
2006-11-08 00:10:07 +02:00
|
|
|
|
2007-06-24 14:27:12 +03:00
|
|
|
if (av_strstart(p, "framesize:", &p)) {
|
2006-11-08 00:10:07 +02:00
|
|
|
char buf1[50];
|
|
|
|
char *dst = buf1;
|
|
|
|
|
2012-05-05 00:05:52 +03:00
|
|
|
// remove the protocol identifier
|
2012-05-05 17:42:15 +03:00
|
|
|
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)
|
2006-11-08 00:10:07 +02:00
|
|
|
*dst++ = *p++;
|
|
|
|
*dst = '\0';
|
|
|
|
|
|
|
|
// a='framesize:96 320-240'
|
2012-05-05 00:05:52 +03:00
|
|
|
// set our parameters
|
2012-05-05 17:42:15 +03:00
|
|
|
codec->width = atoi(buf1);
|
|
|
|
codec->height = atoi(p + 1); // skip the -
|
2007-06-24 14:27:12 +03:00
|
|
|
} else if (av_strstart(p, "fmtp:", &p)) {
|
2014-07-05 10:01:07 +03:00
|
|
|
return ff_parse_fmtp(s, stream, h264_data, p, sdp_parse_fmtp_config_h264);
|
2007-06-24 14:27:12 +03:00
|
|
|
} else if (av_strstart(p, "cliprect:", &p)) {
|
2006-11-08 00:10:07 +02:00
|
|
|
// could use this if we wanted.
|
|
|
|
}
|
|
|
|
|
2012-05-04 23:46:18 +03:00
|
|
|
return 0;
|
2006-11-08 00:10:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RTPDynamicProtocolHandler ff_h264_dynamic_handler = {
|
2009-07-27 17:29:06 +03:00
|
|
|
.enc_name = "H264",
|
2010-03-31 02:30:55 +03:00
|
|
|
.codec_type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 12:11:04 +03:00
|
|
|
.codec_id = AV_CODEC_ID_H264,
|
2013-01-17 16:29:12 +03:00
|
|
|
.init = h264_init,
|
2009-07-27 17:29:06 +03:00
|
|
|
.parse_sdp_a_line = parse_h264_sdp_line,
|
2011-04-20 15:36:37 +03:00
|
|
|
.alloc = h264_new_context,
|
|
|
|
.free = h264_free_context,
|
2015-02-23 22:06:41 +02:00
|
|
|
.parse_packet = h264_handle_packet,
|
2006-11-08 00:10:07 +02:00
|
|
|
};
|