@@ -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
@@ -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
@@ -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).
*/
@@ -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);
@@ -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
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 <bernardo.pilarz@aitek.it> --- 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(+)