From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 45F6D4B97D for ; Tue, 2 Jul 2024 13:03:44 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BA1A268D8DF; Tue, 2 Jul 2024 16:03:41 +0300 (EEST) 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: , From: Bernardo Pilarz via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: Bernardo Pilarz Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".