FFmpeg ff_h264_parse_sprop_parameter_sets函数剖析

SDP中SPS内容        sprop-parameter-sets=Z0IAKpY1QPAET8s3AQEBQAABwgAAV+QB,aM48gA==该函数主要是读取Z0IAKpY1QPAET8s3AQEBQAABwgAAV+QB的内容到data_ptr,一共32个字节还没有读取SPS的每一个字段,然后赋值给SPS相应的字段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) {//通过dst保存数据的头指针        char *dst = base64packet;//将value字符串拷贝一份到dst指针        while (*value && *value != ','               && (dst - base64packet) < sizeof(base64packet) - 1) {            *dst++ = *value++;        }        *dst++ = '\0';//base64packet=Z0IAKpY1QPAET8s3AQEBQAABwgAAV+QB        if (*value == ',')            value++;//base64解码结果,保存在decoded_packet        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);//static const uint8_t start_sequence[] = { 'B', 'B', 'C', 'D' };不是很明白            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){    AVCodecParameters *par = stream->codecpar;    if (!strcmp(attr, "packetization-mode")) {        av_log(s, AV_LOG_DEBUG, "RTP Packetization Mode: %d\n", atoi(value));        h264_data->packetization_mode = atoi(value);        /*         * 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.         */        if (h264_data->packetization_mode > 1)            av_log(s, AV_LOG_ERROR,                   "Interleaved RTP mode is not supported yet.\n");    } else if (!strcmp(attr, "profile-level-id")) {        if (strlen(value) == 6)            parse_profile_level_id(s, h264_data, value);    } else if (!strcmp(attr, "sprop-parameter-sets")) {        int ret;        if (*value == 0 || value[strlen(value) - 1] == ',') {            av_log(s, AV_LOG_WARNING, "Missing PPS in sprop-parameter-sets, ignoring\n");            return 0;        }        par->extradata_size = 0;        av_freep(&par->extradata);//这一段代码主要是将value的值拷贝到par->extradata字符串中        ret = ff_h264_parse_sprop_parameter_sets(s, &par->extradata,                                                 &par->extradata_size, value);        av_log(s, AV_LOG_DEBUG, "Extradata set to %p (size: %d)\n",               par->extradata, par->extradata_size);        return ret;    }    return 0;}疑问,aM48gA==这一段数据,并没有使用,是否意味着这只是读取了SPS,而没有读取到PPS,导致出现non-existing PPS 0 referenced函数的调用逻辑sdp_read_header  ----ff_sdp_parse    ----sdp_parse_line      -----parse_fmtp        ----parse_sdp_a_line------>parse_h264_sdp_line                        --------sdp_parse_fmtp_config_h264参考https://www.cnblogs.com/lihaiping/p/6612511.html引用海康SDP信息v=0o=- 1515162567455825 1515162567455825 IN IP4 192.168.0.150s=Media Presentatione=NONEb=AS:5050t=0 0a=control:rtsp://192.168.0.150:554/h264/ch1/main/av_stream/m=video 0 RTP/AVP 96c=IN IP4 0.0.0.0b=AS:5000a=recvonlya=x-dimensions:1920,1080a=control:rtsp://192.168.0.150:554/h264/ch1/main/av_stream/trackID=1a=rtpmap:96 H264/90000a=fmtp:96 profile-level-id=420029; packetization-mode=1; sprop-parameter-sets=Z0IAKpY1QPAET8s3AQEBQAABwgAAV+QB,aM48gA==a=Media_header:MEDIAINFO=494D4B48010200000400000100000000000000000000000000000000000000000000000000000000;a=appversion:1.0SETUP rtsp://192.168.0.150:554/h264/ch1/main/av_stream/trackID=1 RTSP/1.0CSeq: 5Authorization: Digest username="admin", realm="IP Camera(77056)", nonce="a3a53f4dcb9e6ceca90de6d90c884d29", uri="rtsp://192.168.0.150:554/h264/ch1/main/av_stream/", response="32b6afa222b54c2518efff16ec1aa766"User-Agent: LibVLC/2.2.4 (LIVE555 Streaming Media v2016.02.22)Transport: RTP/AVP/TCP;unicast;interleaved=0-1

本站公众号
   欢迎关注本站公众号,获取更多程序园信息
开发小院