64 int packet_types_received[32];
68 #define MAGIC_COOKIE (0xdeadbeef)
69 #define DEAD_COOKIE (0xdeaddead)
74 char *attr,
char *value)
78 assert(h264_data !=
NULL);
80 if (!strcmp(attr,
"packetization-mode")) {
91 "Interleaved RTP mode is not supported yet.");
92 }
else if (!strcmp(attr,
"profile-level-id")) {
93 if (strlen(value) == 6) {
100 buffer[0] = value[0]; buffer[1] = value[1]; buffer[2] =
'\0';
101 profile_idc = strtol(buffer,
NULL, 16);
102 buffer[0] = value[2]; buffer[1] = value[3];
103 profile_iop = strtol(buffer,
NULL, 16);
104 buffer[0] = value[4]; buffer[1] = value[5];
105 level_idc = strtol(buffer,
NULL, 16);
109 "RTP Profile IDC: %x Profile IOP: %x Level: %x\n",
110 profile_idc, profile_iop, level_idc);
115 }
else if (!strcmp(attr,
"sprop-parameter-sets")) {
116 uint8_t start_sequence[]= { 0, 0, 1 };
121 char base64packet[1024];
122 uint8_t decoded_packet[1024];
124 char *dst = base64packet;
126 while (*value && *value !=
','
127 && (dst - base64packet) <
sizeof(base64packet) - 1) {
135 packet_size=
av_base64_decode(decoded_packet, base64packet,
sizeof(decoded_packet));
136 if (packet_size > 0) {
137 uint8_t *dest =
av_malloc(packet_size +
sizeof(start_sequence) +
149 memcpy(dest+codec->
extradata_size, start_sequence,
sizeof(start_sequence));
150 memcpy(dest+codec->
extradata_size+
sizeof(start_sequence), decoded_packet, packet_size);
172 uint32_t * timestamp,
176 uint8_t nal = buf[0];
177 uint8_t type = (nal & 0x1f);
179 uint8_t start_sequence[]= {0, 0, 1};
187 if (type >= 1 && type <= 23)
193 memcpy(pkt->
data, start_sequence,
sizeof(start_sequence));
194 memcpy(pkt->
data+
sizeof(start_sequence), buf, len);
196 data->packet_types_received[nal & 0x1f]++;
210 for(pass= 0; pass<2; pass++) {
211 const uint8_t *src= buf;
215 uint16_t nal_size =
AV_RB16(src);
221 if (nal_size <= src_len) {
224 total_length+=
sizeof(start_sequence)+nal_size;
228 memcpy(dst, start_sequence,
sizeof(start_sequence));
229 dst+=
sizeof(start_sequence);
230 memcpy(dst, src, nal_size);
232 data->packet_types_received[*src & 0x1f]++;
238 "nal size exceeds length: %d %d\n", nal_size, src_len);
247 "Consumed more bytes than we got! (%d)\n", src_len);
248 }
while (src_len > 2);
255 assert(dst-pkt->
data==total_length);
266 "Unhandled type (%d) (See RFC for implementation details\n",
276 uint8_t fu_indicator = nal;
277 uint8_t fu_header = *buf;
278 uint8_t start_bit = fu_header >> 7;
280 uint8_t nal_type = (fu_header & 0x1f);
281 uint8_t reconstructed_nal;
284 reconstructed_nal = fu_indicator & (0xe0);
285 reconstructed_nal |= nal_type;
293 data->packet_types_received[nal_type]++;
298 memcpy(pkt->
data, start_sequence,
sizeof(start_sequence));
299 pkt->
data[
sizeof(start_sequence)]= reconstructed_nal;
300 memcpy(pkt->
data+
sizeof(start_sequence)+
sizeof(nal), buf, len);
303 memcpy(pkt->
data, buf, len);
340 for (ii = 0; ii < 32; ii++) {
341 if (data->packet_types_received[ii])
343 data->packet_types_received[ii], ii);
362 const char *p = line;
371 while (*p && *p ==
' ') p++;
372 while (*p && *p !=
' ') p++;
373 while (*p && *p ==
' ') p++;
374 while (*p && *p !=
'-' && (dst - buf1) <
sizeof(buf1) - 1) {
381 codec->
width = atoi(buf1);
382 codec->
height = atoi(p + 1);
uint8_t profile_idc
from the sdp setup parameters.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
static int sdp_parse_fmtp_config_h264(AVStream *stream, PayloadContext *h264_data, char *attr, char *value)
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_WB24 AV_RB16
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
RTP/H264 specific private data.
#define DEAD_COOKIE
Cookie for the extradata; once it is freed.
int index
stream index in AVFormatContext
int packetization_mode
from the sdp setup parameters.
RTPDynamicProtocolHandler ff_h264_dynamic_handler
This is the structure for expanding on the dynamic rtp protocols (makes everything static...
static void h264_free_context(PayloadContext *data)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
bitstream reader API header.
static PayloadContext * h264_new_context(void)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int parse_h264_sdp_line(AVFormatContext *s, int st_index, PayloadContext *h264_data, const char *line)
void av_log(void *avcl, int level, const char *fmt,...)
AVCodecContext * codec
codec context
int width
picture width / height.
uint8_t profile_iop
from the sdp setup parameters.
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t level_idc
from the sdp setup parameters.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
#define MAGIC_COOKIE
Cookie for the extradata; to verify we are what we think we are, and that we haven't been freed...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
unsigned long cookie
sanity check, to make sure we get the pointer we're expecting.
int av_base64_decode(uint8_t *out, const char *in, int out_size)
Decode a base64-encoded string.
int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p, int(*parse_fmtp)(AVStream *stream, PayloadContext *data, char *attr, char *value))
static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data, AVStream *st, AVPacket *pkt, uint32_t *timestamp, const uint8_t *buf, int len, int flags)