Skip to content

Commit

Permalink
added: show profile information in codec info when available
Browse files Browse the repository at this point in the history
Add patches to our ffmpeg that cause the profile information to be shown
in parantheses after the codec name in the codec info.

The core patches have been sent and applied upstream, while the profile
arrays have been sent upstream but may undergo minor changes before
being applied.
  • Loading branch information
anssih committed Jan 21, 2011
1 parent 669d501 commit fd71175
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 0 deletions.
6 changes: 6 additions & 0 deletions xbmc/cores/dvdplayer/Codecs/ffmpeg/libavcodec/aacenc.c
Expand Up @@ -636,6 +636,11 @@ static av_cold int aac_encode_end(AVCodecContext *avctx)
return 0;
}

static const AVProfile profiles[] = {
{ FF_PROFILE_AAC_LOW, "Low" },
{ FF_PROFILE_UNKNOWN },
};

AVCodec aac_encoder = {
"aac",
AVMEDIA_TYPE_AUDIO,
Expand All @@ -647,4 +652,5 @@ AVCodec aac_encoder = {
.capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
.sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
.profiles = profiles,
};
18 changes: 18 additions & 0 deletions xbmc/cores/dvdplayer/Codecs/ffmpeg/libavcodec/avcodec.h
Expand Up @@ -2714,6 +2714,14 @@ typedef struct AVCodecContext {
int lpc_passes;
} AVCodecContext;

/**
* AVProfile.
*/
typedef struct AVProfile {
int profile;
const char *name; ///< short name for the profile
} AVProfile;

/**
* AVCodec.
*/
Expand Down Expand Up @@ -2754,6 +2762,7 @@ typedef struct AVCodec {
const enum SampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
uint8_t max_lowres; ///< maximum value for lowres supported by the decoder
const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
} AVCodec;

/**
Expand Down Expand Up @@ -3310,6 +3319,15 @@ AVCodec *avcodec_find_decoder(enum CodecID id);
AVCodec *avcodec_find_decoder_by_name(const char *name);
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);

/**
* Return a name for the specified profile, if available.
*
* @param codec the codec that is searched for the given profile
* @param profile the profile value for which a name is requested
* @return A name for the profile if found, NULL otherwise.
*/
const char *av_get_profile_name(const AVCodec *codec, int profile);

/**
* Set the fields of the given AVCodecContext to default values.
*
Expand Down
10 changes: 10 additions & 0 deletions xbmc/cores/dvdplayer/Codecs/ffmpeg/libavcodec/dca.c
Expand Up @@ -1817,6 +1817,15 @@ static av_cold int dca_decode_end(AVCodecContext * avctx)
return 0;
}

static const AVProfile profiles[] = {
{ FF_PROFILE_DTS, "DTS" },
{ FF_PROFILE_DTS_ES, "DTS-ES" },
{ FF_PROFILE_DTS_96_24, "DTS 96/24" },
{ FF_PROFILE_DTS_HD_HRA, "DTS-HD HRA" },
{ FF_PROFILE_DTS_HD_MA, "DTS-HD MA" },
{ FF_PROFILE_UNKNOWN },
};

AVCodec dca_decoder = {
.name = "dca",
.type = AVMEDIA_TYPE_AUDIO,
Expand All @@ -1826,4 +1835,5 @@ AVCodec dca_decoder = {
.decode = dca_decode_frame,
.close = dca_decode_end,
.long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
.profiles = profiles,
};
13 changes: 13 additions & 0 deletions xbmc/cores/dvdplayer/Codecs/ffmpeg/libavcodec/h264.c
Expand Up @@ -3382,6 +3382,17 @@ av_cold int ff_h264_decode_end(AVCodecContext *avctx)
return 0;
}

static const AVProfile profiles[] = {
{ FF_PROFILE_H264_BASELINE, "Baseline" },
{ FF_PROFILE_H264_MAIN, "Main" },
{ FF_PROFILE_H264_EXTENDED, "Extended" },
{ FF_PROFILE_H264_HIGH, "High" },
{ FF_PROFILE_H264_HIGH_10, "High 10" },
{ FF_PROFILE_H264_HIGH_422, "High 4:2:2" },
{ FF_PROFILE_H264_HIGH_444, "High 4:4:4" },
{ FF_PROFILE_H264_CAVLC_444, "CAVLC 4:4:4" },
{ FF_PROFILE_UNKNOWN },
};

AVCodec h264_decoder = {
"h264",
Expand All @@ -3395,6 +3406,7 @@ AVCodec h264_decoder = {
/*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_DELAY,
.flush= flush_dpb,
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
.profiles = profiles,
};

#if CONFIG_H264_VDPAU_DECODER
Expand All @@ -3411,5 +3423,6 @@ AVCodec h264_vdpau_decoder = {
.flush= flush_dpb,
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_H264, PIX_FMT_NONE},
.profiles = profiles,
};
#endif
9 changes: 9 additions & 0 deletions xbmc/cores/dvdplayer/Codecs/ffmpeg/libavcodec/libfaac.c
Expand Up @@ -145,6 +145,14 @@ static av_cold int Faac_encode_close(AVCodecContext *avctx)
return 0;
}

static const AVProfile profiles[] = {
{ FF_PROFILE_AAC_MAIN, "Main" },
{ FF_PROFILE_AAC_LOW, "Low" },
{ FF_PROFILE_AAC_SSR, "SSR" },
{ FF_PROFILE_AAC_LTP, "LTP" },
{ FF_PROFILE_UNKNOWN },
};

AVCodec libfaac_encoder = {
"libfaac",
AVMEDIA_TYPE_AUDIO,
Expand All @@ -155,4 +163,5 @@ AVCodec libfaac_encoder = {
Faac_encode_close,
.sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("libfaac AAC (Advanced Audio Codec)"),
.profiles = profiles,
};
21 changes: 21 additions & 0 deletions xbmc/cores/dvdplayer/Codecs/ffmpeg/libavcodec/utils.c
Expand Up @@ -840,6 +840,7 @@ size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_ta
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
{
const char *codec_name;
const char *profile = NULL;
AVCodec *p;
char buf1[32];
int bitrate;
Expand All @@ -852,6 +853,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)

if (p) {
codec_name = p->name;
profile = av_get_profile_name(p, enc->profile);
} else if (enc->codec_id == CODEC_ID_MPEG2TS) {
/* fake mpeg2 transport stream codec (currently not
registered) */
Expand All @@ -871,6 +873,9 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
snprintf(buf, buf_size,
"Video: %s%s",
codec_name, enc->mb_decision ? " (hq)" : "");
if (profile)
snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
if (enc->pix_fmt != PIX_FMT_NONE) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
", %s",
Expand Down Expand Up @@ -906,6 +911,9 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
snprintf(buf, buf_size,
"Audio: %s",
codec_name);
if (profile)
snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
if (enc->sample_rate) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
", %d Hz", enc->sample_rate);
Expand Down Expand Up @@ -945,6 +953,19 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
}
}

const char *av_get_profile_name(const AVCodec *codec, int profile)
{
const AVProfile *p;
if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
return NULL;

for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
if (p->profile == profile)
return p->name;

return NULL;
}

unsigned avcodec_version( void )
{
return LIBAVCODEC_VERSION_INT;
Expand Down
@@ -0,0 +1,84 @@
From 060ec0a8294d912f694cf48546f1543805f83a48 Mon Sep 17 00:00:00 2001
From: Anssi Hannula <anssi.hannula@iki.fi>
Date: Fri, 7 Jan 2011 22:27:26 +0000
Subject: [PATCH] Add av_get_profile_name() to get profile names.

Patch by Anssi Hannula, anssi d hannula a iki d fi

Originally committed as revision 26259 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
doc/APIchanges | 3 +++
libavcodec/avcodec.h | 22 ++++++++++++++++++++--
libavcodec/utils.c | 13 +++++++++++++
3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7850e1d..309edae 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2794,6 +2794,14 @@ typedef struct AVCodecContext {
} AVCodecContext;

/**
+ * AVProfile.
+ */
+typedef struct AVProfile {
+ int profile;
+ const char *name; ///< short name for the profile
+} AVProfile;
+
+/**
* AVCodec.
*/
typedef struct AVCodec {
@@ -2834,6 +2842,7 @@ typedef struct AVCodec {
const enum SampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
uint8_t max_lowres; ///< maximum value for lowres supported by the decoder
+ const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
} AVCodec;

/**
@@ -3394,6 +3403,15 @@ AVCodec *avcodec_find_decoder_by_name(const char *name);
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);

/**
+ * Return a name for the specified profile, if available.
+ *
+ * @param codec the codec that is searched for the given profile
+ * @param profile the profile value for which a name is requested
+ * @return A name for the profile if found, NULL otherwise.
+ */
+const char *av_get_profile_name(const AVCodec *codec, int profile);
+
+/**
* Set the fields of the given AVCodecContext to default values.
*
* @param s The AVCodecContext of which the fields should be set to default values.
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index ce74735..c11e4f5 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -966,6 +966,19 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
}
}

+const char *av_get_profile_name(const AVCodec *codec, int profile)
+{
+ const AVProfile *p;
+ if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
+ return NULL;
+
+ for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
+ if (p->profile == profile)
+ return p->name;
+
+ return NULL;
+}
+
unsigned avcodec_version( void )
{
return LIBAVCODEC_VERSION_INT;
--
1.7.3

@@ -0,0 +1,55 @@
From 2a81f4bde50f731074c1be7368128de49f78925a Mon Sep 17 00:00:00 2001
From: Anssi Hannula <anssi.hannula@iki.fi>
Date: Sat, 8 Jan 2011 09:23:25 +0000
Subject: [PATCH] Show profile in avcodec_string().

Patch by Anssi Hannula, anssi d hannula a iki d fi

Originally committed as revision 26264 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
libavcodec/utils.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 0295147..8cc9299 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -871,6 +871,7 @@ size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_ta
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
{
const char *codec_name;
+ const char *profile = NULL;
AVCodec *p;
char buf1[32];
int bitrate;
@@ -883,6 +884,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)

if (p) {
codec_name = p->name;
+ profile = av_get_profile_name(p, enc->profile);
} else if (enc->codec_id == CODEC_ID_MPEG2TS) {
/* fake mpeg2 transport stream codec (currently not
registered) */
@@ -902,6 +904,9 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
snprintf(buf, buf_size,
"Video: %s%s",
codec_name, enc->mb_decision ? " (hq)" : "");
+ if (profile)
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ " (%s)", profile);
if (enc->pix_fmt != PIX_FMT_NONE) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
", %s",
@@ -937,6 +942,9 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
snprintf(buf, buf_size,
"Audio: %s",
codec_name);
+ if (profile)
+ snprintf(buf + strlen(buf), buf_size - strlen(buf),
+ " (%s)", profile);
if (enc->sample_rate) {
snprintf(buf + strlen(buf), buf_size - strlen(buf),
", %d Hz", enc->sample_rate);
--
1.7.3

@@ -0,0 +1,51 @@
From 306bd2d20ada5782ea28037072e9d4f0cc9dae90 Mon Sep 17 00:00:00 2001
From: Anssi Hannula <anssi.hannula@iki.fi>
Date: Fri, 7 Jan 2011 18:59:17 +0200
Subject: [PATCH 43/46] h264: add profile names for the existing defines

Submitted upstream.

---
libavcodec/h264.c | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 40dc276..04caa9f 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -3354,6 +3354,17 @@ av_cold int ff_h264_decode_end(AVCodecContext *avctx)
return 0;
}

+static const AVProfile profiles[] = {
+ { FF_PROFILE_H264_BASELINE, "Baseline" },
+ { FF_PROFILE_H264_MAIN, "Main" },
+ { FF_PROFILE_H264_EXTENDED, "Extended" },
+ { FF_PROFILE_H264_HIGH, "High" },
+ { FF_PROFILE_H264_HIGH_10, "High 10" },
+ { FF_PROFILE_H264_HIGH_422, "High 4:2:2" },
+ { FF_PROFILE_H264_HIGH_444, "High 4:4:4" },
+ { FF_PROFILE_H264_CAVLC_444, "CAVLC 4:4:4" },
+ { FF_PROFILE_UNKNOWN },
+};

AVCodec h264_decoder = {
"h264",
@@ -3367,6 +3378,7 @@ AVCodec h264_decoder = {
/*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_DELAY,
.flush= flush_dpb,
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
+ .profiles = profiles,
};

#if CONFIG_H264_VDPAU_DECODER
@@ -3383,5 +3395,6 @@ AVCodec h264_vdpau_decoder = {
.flush= flush_dpb,
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_H264, PIX_FMT_NONE},
+ .profiles = profiles,
};
#endif
--
1.7.3

0 comments on commit fd71175

Please sign in to comment.