From patchwork Wed Jul 3 07:47:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernardo Pilarz X-Patchwork-Id: 50301 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp2906859vqv; Wed, 3 Jul 2024 00:48:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUKxSmj/6AK2STdZcgjHaL0RCezWbgyAWR3DR/YhlmmTKHUsKeLwwNhwlLVv7qV9DJ/51P7dEjs3i7lBJ+Qt/pV4WdEWH343f8FkQ== X-Google-Smtp-Source: AGHT+IFL1QddMnH1q909OPOgbyYzsAsQ1OLlkmqiIPW8PtJfe0KQJDGPoUeKgZgqJn+kVSyW5+TS X-Received: by 2002:a17:907:26c7:b0:a72:603f:1ea2 with SMTP id a640c23a62f3a-a75144baeb3mr833695366b.62.1719992885236; Wed, 03 Jul 2024 00:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719992885; cv=none; d=google.com; s=arc-20160816; b=P5bG6fdYTcRhS18btbEy5yzBE195xc/8IT8+wCs4CIBQ//I/lqzEuJ9QTyOriPrk0G Vsl/GZ7nj0Q6++sTTT4p9W1BpCKGK5F7FizO4UYlka5X4Drv+nnQyeykU0boI8pu6OKA MduFakYv2M2Gp+teboL+AEjOxBBUtF9F67ZooV0+vXSnMMjMo88gaarTm+RE8u5QAN2s h7cTNd8rdQrpOiLBB6W5RMoRTYYJtgqLpb1fmBhG8lEFZXvNDp4po/fejU3c4INacasY SlDCK2lXKGdPgRKSD3eQWCP+VFY69X88wLlw3vhCeq7cagT8gQGiyoWZighRcHk7CYNi O/iQ== 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=8S+mnf4AV7fH9M8mWDOfyiQSA104en2hQH73f+QsnSw=; fh=BLn51q7SjHgGIj+gC34mWa6upHCOzzwSChD7Q8MutZ0=; b=dIdRtIZPG0uTytwZqWEvOAS1Pb9bkm6UDGl/SWWUDcFyqR4sB1AlXRxywVnhQrBKtU YVVKO2W6XPDMPSaEWlkeC2w91YgJbNxTfT70iZqhgAxj4EGc/yiqH4wbiMYndOEsOKe4 VR6RLNktvynUumnvkZJ97ixtj0usKseWJsCGTIGpLddStbUXMoZoYuEWmRv5ss9a/XIX cDAmIG7NHYX+nDboKb9c5pe8/XkP7rVxX9AUSjWVa0SqyJnNiVqMELj910nfwzCaZM/s PO2/FATAAKlKyQDHpJge7YemlEq1htJ3lD6LnKAvt+Y08mEY/KZIjN7YsYnoPyxKJE7P V0rA==; 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-a74914ce9e9si448415866b.456.2024.07.03.00.48.04; Wed, 03 Jul 2024 00:48:05 -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 EC82568D88F; Wed, 3 Jul 2024 10:48:01 +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 EFCD168D88F for ; Wed, 3 Jul 2024 10:47:54 +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 5181A18007DD for ; Wed, 3 Jul 2024 09:47:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.aitek.it 5181A18007DD Message-ID: Date: Wed, 3 Jul 2024 09:47:47 +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: A731C858849.A8B22 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: bJt8PzfGcssX 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;