Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/avformat: Added codec_name to AVCodecContext and AVCodecParameters
@ 2024-07-02 13:03 Bernardo Pilarz via ffmpeg-devel
  0 siblings, 0 replies; 7+ messages in thread
From: Bernardo Pilarz via ffmpeg-devel @ 2024-07-02 13:03 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Bernardo Pilarz

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(+)

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".

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH] avcodec/avformat: Added codec_name to AVCodecContext and AVCodecParameters
@ 2024-07-03  7:47 Bernardo Pilarz via ffmpeg-devel
  2024-07-03  8:02 ` Hendrik Leppkes
  0 siblings, 1 reply; 7+ messages in thread
From: Bernardo Pilarz via ffmpeg-devel @ 2024-07-03  7:47 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Bernardo Pilarz

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(+)

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".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-07-03 12:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-02 13:03 [FFmpeg-devel] [PATCH] avcodec/avformat: Added codec_name to AVCodecContext and AVCodecParameters Bernardo Pilarz via ffmpeg-devel
2024-07-03  7:47 Bernardo Pilarz via ffmpeg-devel
2024-07-03  8:02 ` Hendrik Leppkes
2024-07-03  8:10   ` Bernardo Pilarz via ffmpeg-devel
2024-07-03  9:10     ` Anton Khirnov
2024-07-03  9:56       ` Bernardo Pilarz via ffmpeg-devel
2024-07-03 12:30         ` Bernardo Pilarz via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git