From patchwork Tue Jul 2 13:03:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernardo Pilarz X-Patchwork-Id: 50283 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp2419005vqv; Tue, 2 Jul 2024 06:03:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCULk5pT3XsxLUY+kHoqvngT9ST/4b+kZgifOkihp6UuWLQ5TwEPDD6Ke5u071yPCpY10l/+I5vMqeLmmaH/T4xDjTak2AL3Ibt/FQ== X-Google-Smtp-Source: AGHT+IFYI6M0N9C7NB5CUNxPudXX3d3jbv+NaP2MQmskOB4wp2H/TJxM/9p/Y6Nq3yRXYGSvh2td X-Received: by 2002:a17:906:a087:b0:a72:88e2:c327 with SMTP id a640c23a62f3a-a75143fdd54mr539412466b.38.1719925427063; Tue, 02 Jul 2024 06:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719925427; cv=none; d=google.com; s=arc-20160816; b=ME/0SZYj5GGMD8U00GUTZ/6nQBG1ypMzewCLwyEtaI3QUWoqSk8vlgoV2i3vZzEKt1 PSeZRkYr2D/6J2Flt2/50MBe/GtBwKUAN5MCX3L0zzdDhNdhO491NnXWM/8Ai4Q3ddCf m0p8CIKiueSWajNuFNwA67sJkQYvotmDnEvuojRCc+EM2dx6hlrkgh0nqGHlJ6AMTwG9 BDL9AbTujC6VcGG2u8NQAt2M8QdTlc06XWZHvn/0zwBN8ZoDcoGL3A8s0WL0oj91k/tm X3/W/sw9f7m0hr5uky9xGr+Tw7do9sDnaLFSciPYij9ZqIT4Rk+HtBSC7hBmq+jiZSPE QygA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:content-language:to:mime-version:date :message-id:dkim-filter:delivered-to; bh=0dlZyDXbzrpwDU8XqTPd2btYRQQtKh5TP/4L3ORAhNE=; fh=BLn51q7SjHgGIj+gC34mWa6upHCOzzwSChD7Q8MutZ0=; b=quMaZr/sswanO3JqqNtuMb/Ri7+N7scNRreFyvB2/W+hY8I2eTcK9GPKr0MocadG4v 8alNOErSwqXHo+v+n9g1+nyuhCfj4R35hcHYdPu3gGAGcXcXkM8M2JGKt/+CWzuLE25d mnn0Xz2qhj6lSmjotz2nbnSfojcUZkvwXOTOo4Gv6TrR5rsd8A2eBISzGR+wBoqNUYhh ojvaODUWd/fN9BPCgWLfH446KJrcA/ODgTHY8Om2Q7RVTLRK+Kh5Kbv9m6bS+udW7VA4 zxHm6fFTjr2vjNcrztLnmjziybjcFQp5TXF0WkAY/a/dtTdncjWpCu/EwM5s5Rf6C+t4 twlg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a72ab092d75si463510766b.802.2024.07.02.06.03.45; Tue, 02 Jul 2024 06:03:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2689868D88E; Tue, 2 Jul 2024 16:03:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay.aitek.it (dns1.aitek.it [194.244.35.21]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9D79468D8AE for ; Tue, 2 Jul 2024 16:03:34 +0300 (EEST) Received: from mail-server.aitek.it (mail-server.aitek.it [172.30.0.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay.aitek.it (Postfix) with ESMTPS id 2F6631800840 for ; Tue, 2 Jul 2024 15:03:35 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.aitek.it 2F6631800840 Message-ID: Date: Tue, 2 Jul 2024 15:03:24 +0200 MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Content-Language: en-US, it X-Aitek-Mail-Server-MailScanner-Information: Please contact the ISP for more information X-Aitek-Mail-Server-MailScanner-ID: D768985884A.A79D1 X-Aitek-Mail-Server-MailScanner: Found to be clean X-Aitek-Mail-Server-MailScanner-From: bernardo.pilarz@aitek.it X-Spam-Status: No Subject: [FFmpeg-devel] [PATCH] avcodec/avformat: Added codec_name to AVCodecContext and AVCodecParameters X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bernardo Pilarz via ffmpeg-devel From: Bernardo Pilarz Reply-To: FFmpeg development discussions and patches Cc: Bernardo Pilarz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +v4PpJXsr3xP Added the codec_name field, in which the unprocessed, not-interpreted codec name is stored. This is useful when codecs that are not handled by the libav (i.e. AV_CODEC_ID_NONE) are encountered, since the application might still want to handle them. Having this field allows the application to determine the codec type. As of this commit, the codec_name field is only filled when opening an RTSP stream, during the parsing of the SDP. Signed-off-by: bpilarz --- libavcodec/avcodec.h | 10 ++++++++++ libavcodec/codec_par.c | 19 +++++++++++++++++++ libavcodec/codec_par.h | 10 ++++++++++ libavcodec/options.c | 1 + libavformat/rtsp.c | 5 +++++ 5 files changed, 45 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 2da63c87ea..464b4078fc 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -451,6 +451,16 @@ typedef struct AVCodecContext { int log_level_offset; enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */ + /** + * Generic codec name of the encoded data. + * + * Null-terminated string, can be NULL. + * Contents may vary depending on the source of the data stream. + * This is typically the string that's interpreted to determine 'codec_id'. + * Must be allocated with av_malloc() or av_strdup() and will be freed by + * avcodec_free_context(). + */ + char *codec_name; const struct AVCodec *codec; enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */ diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c index 790ea01d10..27d9880b53 100644 --- a/libavcodec/codec_par.c +++ b/libavcodec/codec_par.c @@ -31,6 +31,7 @@ static void codec_parameters_reset(AVCodecParameters *par) { + av_freep(&par->codec_name); av_freep(&par->extradata); av_channel_layout_uninit(&par->ch_layout); av_packet_side_data_free(&par->coded_side_data, &par->nb_coded_side_data); @@ -110,6 +111,13 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src codec_parameters_reset(dst); memcpy(dst, src, sizeof(*dst)); + dst->codec_name = NULL; + if (src->codec_name) { + dst->codec_name = av_strdup(src->codec_name); + if (!dst->codec_name) + return AVERROR(ENOMEM); + } + dst->ch_layout = (AVChannelLayout){0}; dst->extradata = NULL; dst->extradata_size = 0; @@ -142,6 +150,11 @@ int avcodec_parameters_from_context(AVCodecParameters *par, codec_parameters_reset(par); par->codec_type = codec->codec_type; + if (codec->codec_name) { + par->codec_name = av_strdup(codec->codec_name); + if (!par->codec_name) + return AVERROR(ENOMEM); + } par->codec_id = codec->codec_id; par->codec_tag = codec->codec_tag; @@ -206,6 +219,12 @@ int avcodec_parameters_to_context(AVCodecContext *codec, int ret; codec->codec_type = par->codec_type; + av_freep(&codec->codec_name); + if (par->codec_name) { + codec->codec_name = av_strdup(par->codec_name); + if (!codec->codec_name) + return AVERROR(ENOMEM); + } codec->codec_id = par->codec_id; codec->codec_tag = par->codec_tag; diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h index f4b9bb5c06..196ef1fc66 100644 --- a/libavcodec/codec_par.h +++ b/libavcodec/codec_par.h @@ -49,6 +49,16 @@ typedef struct AVCodecParameters { * General type of the encoded data. */ enum AVMediaType codec_type; + /** + * Generic codec name of the encoded data. + * + * Null-terminated string, can be NULL. + * Contents may vary depending on the source of the data stream. + * This is typically the string that's interpreted to determine 'codec_id'. + * Must be allocated with av_malloc() or av_strdup() and will be freed by + * avcodec_parameters_free(). + */ + char *codec_name; /** * Specific type of the encoded data (the codec used). */ diff --git a/libavcodec/options.c b/libavcodec/options.c index f60c41bdc3..c107f4efbd 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -170,6 +170,7 @@ void avcodec_free_context(AVCodecContext **pavctx) ff_codec_close(avctx); + av_freep(&avctx->codec_name); av_freep(&avctx->extradata); av_freep(&avctx->subtitle_header); av_freep(&avctx->intra_matrix); diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index db78735c7a..56363caeda 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -317,6 +317,11 @@ static int sdp_parse_rtpmap(AVFormatContext *s, par->codec_id = ff_rtp_codec_id(buf, par->codec_type); } + /* Copy the codec name, regardless of whether we can handle it. + * Applications might handle unknown codecs on their own. */ + av_freep(&par->codec_name); + par->codec_name = av_strdup(buf); + desc = avcodec_descriptor_get(par->codec_id); if (desc && desc->name) c_name = desc->name; -- 2.43.0