summaryrefslogtreecommitdiffstats
path: root/libmpcodecs
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2012-07-24 09:01:47 +0300
committerUoti Urpala <uau@mplayer2.org>2012-07-24 09:01:47 +0300
commit5f3c3f8c32d20405a2caf7de66aa1ea7f513d4d2 (patch)
tree44a68334360af69b358dafc0cecf773ca5871ecc /libmpcodecs
parent65b24e46a1c2f26688458cf16a11733e96da0f22 (diff)
downloadmpv-5f3c3f8c32d20405a2caf7de66aa1ea7f513d4d2.tar.bz2
mpv-5f3c3f8c32d20405a2caf7de66aa1ea7f513d4d2.tar.xz
video, audio: use lavc decoders without codecs.conf entries
Add support for using libavcodec decoders that do not have entries in codecs.conf. This is currently only used with demux_lavf, and the codec selection is based on codec_id returned by libavformat. Also modify codec-related terminal output somewhat to make it use information from libavcodec and avoid excessively long default output. The new any-lavc-codec support is implemented with codecs.conf entries that invoke vd_ffmpeg/ad_ffmpeg without directly specifying any libavcodec codec name. In this mode, the decoders now instead select the libavcodec codec based on codec_id previously set by demux_lavf (if any). These new "generic" codecs.conf entries specify "status buggy", so that they're tried after any specific entries with higher-priority status. Add new directive "anyinput" to codecs.conf syntax. This means the entry will always match regardless of fourcc. This is used for the above new codecs.conf entries (so the driver always gets to decide whether to accept the input, and will fail init() if it can't find a suitable codec in libavcodec). Remove parsing support for the obsolete codecs.conf directive "cpuflags". This directive has not had any effect and has not been used in default codecs.conf since many years ago. Shorten codec-related terminal output. When using libavcodec decoders, show the libavcodec long_name field rather than codecs.conf "info" field as the name of the codec. Stop showing the codecs.conf entry name and "vfm/afm" name by default, as these are rarely needed; they're now in verbose output only. Show "VIDEO:" line at VO initialization rather than at demuxer open. This didn't really belong in demuxer code; the new location may show more accurate values (known after decoder has been opened) and works right if video track is changed after initial demuxer open. The vd.c changes (primarily done for terminal output changes) remove round-to-even behavior from code setting dimensions based on aspect ratio. I hope nothing depended on this; at least the even values were not consistently guaranteed anyway, as the rounding code did not run if the video file did not specify a nonzero aspect value.
Diffstat (limited to 'libmpcodecs')
-rw-r--r--libmpcodecs/ad_ffmpeg.c39
-rw-r--r--libmpcodecs/dec_audio.c51
-rw-r--r--libmpcodecs/dec_video.c15
-rw-r--r--libmpcodecs/mpc_info.h1
-rw-r--r--libmpcodecs/vd.c28
-rw-r--r--libmpcodecs/vd_ffmpeg.c43
6 files changed, 115 insertions, 62 deletions
diff --git a/libmpcodecs/ad_ffmpeg.c b/libmpcodecs/ad_ffmpeg.c
index 0bfc5e5f0a..a20689eab8 100644
--- a/libmpcodecs/ad_ffmpeg.c
+++ b/libmpcodecs/ad_ffmpeg.c
@@ -38,11 +38,12 @@
static const ad_info_t info =
{
- "FFmpeg/libavcodec audio decoders",
+ "libavcodec audio decoders",
"ffmpeg",
- "Nick Kurshev",
- "ffmpeg.sf.net",
- ""
+ "",
+ "",
+ "",
+ .print_name = "libavcodec",
};
LIBAD_EXTERN(ffmpeg)
@@ -112,16 +113,31 @@ static int init(sh_audio_t *sh_audio)
AVCodecContext *lavc_context;
AVCodec *lavc_codec;
- mp_msg(MSGT_DECAUDIO, MSGL_V, "FFmpeg's libavcodec audio codec\n");
-
- lavc_codec = avcodec_find_decoder_by_name(sh_audio->codec->dll);
- if (!lavc_codec) {
- mp_tmsg(MSGT_DECAUDIO, MSGL_ERR,
- "Cannot find codec '%s' in libavcodec...\n",
- sh_audio->codec->dll);
+ if (sh_audio->codec->dll) {
+ lavc_codec = avcodec_find_decoder_by_name(sh_audio->codec->dll);
+ if (!lavc_codec) {
+ mp_tmsg(MSGT_DECAUDIO, MSGL_ERR,
+ "Cannot find codec '%s' in libavcodec...\n",
+ sh_audio->codec->dll);
+ return 0;
+ }
+ } else if (!sh_audio->libav_codec_id) {
+ mp_tmsg(MSGT_DECAUDIO, MSGL_INFO, "No Libav codec ID known. "
+ "Generic lavc decoder is not applicable.\n");
return 0;
+ } else {
+ lavc_codec = avcodec_find_decoder(sh_audio->libav_codec_id);
+ if (!lavc_codec) {
+ mp_tmsg(MSGT_DECAUDIO, MSGL_INFO, "Libavcodec has no decoder "
+ "for this codec\n");
+ return 0;
+ }
}
+ sh_audio->codecname = lavc_codec->long_name;
+ if (!sh_audio->codecname)
+ sh_audio->codecname = lavc_codec->name;
+
struct priv *ctx = talloc_zero(NULL, struct priv);
sh_audio->context = ctx;
lavc_context = avcodec_alloc_context3(lavc_codec);
@@ -217,6 +233,7 @@ static int init(sh_audio_t *sh_audio)
static void uninit(sh_audio_t *sh)
{
+ sh->codecname = NULL;
struct priv *ctx = sh->context;
if (!ctx)
return;
diff --git a/libmpcodecs/dec_audio.c b/libmpcodecs/dec_audio.c
index 2445649075..59c05a187a 100644
--- a/libmpcodecs/dec_audio.c
+++ b/libmpcodecs/dec_audio.c
@@ -96,14 +96,12 @@ static int init_audio_codec(sh_audio_t *sh_audio)
sh_audio->audio_out_minsize, base_size, sh_audio->a_buffer_size);
sh_audio->a_buffer = av_mallocz(sh_audio->a_buffer_size);
- if (!sh_audio->a_buffer) {
- mp_tmsg(MSGT_DECAUDIO, MSGL_ERR, "Cannot allocate audio out buffer.\n");
- return 0;
- }
+ if (!sh_audio->a_buffer)
+ abort();
sh_audio->a_buffer_len = 0;
if (!sh_audio->ad_driver->init(sh_audio)) {
- mp_tmsg(MSGT_DECAUDIO, MSGL_WARN, "ADecoder init failed :(\n");
+ mp_tmsg(MSGT_DECAUDIO, MSGL_V, "ADecoder init failed :(\n");
uninit_audio(sh_audio); // free buffers
return 0;
}
@@ -111,7 +109,8 @@ static int init_audio_codec(sh_audio_t *sh_audio)
sh_audio->initialized = 1;
if (!sh_audio->channels || !sh_audio->samplerate) {
- mp_tmsg(MSGT_DECAUDIO, MSGL_WARN, "Unknown/missing audio format -> no sound\n");
+ mp_tmsg(MSGT_DECAUDIO, MSGL_ERR, "Audio decoder did not specify "
+ "audio format!\n");
uninit_audio(sh_audio); // free buffers
return 0;
}
@@ -119,18 +118,6 @@ static int init_audio_codec(sh_audio_t *sh_audio)
if (!sh_audio->o_bps)
sh_audio->o_bps = sh_audio->channels * sh_audio->samplerate
* sh_audio->samplesize;
-
- mp_msg(MSGT_DECAUDIO, MSGL_INFO,
- "AUDIO: %d Hz, %d ch, %s, %3.1f kbit/%3.2f%% (ratio: %d->%d)\n",
- sh_audio->samplerate, sh_audio->channels,
- af_fmt2str_short(sh_audio->sample_format),
- sh_audio->i_bps * 8 * 0.001,
- ((float) sh_audio->i_bps / sh_audio->o_bps) * 100.0,
- sh_audio->i_bps, sh_audio->o_bps);
- mp_msg(MSGT_IDENTIFY, MSGL_INFO,
- "ID_AUDIO_BITRATE=%d\nID_AUDIO_RATE=%d\n" "ID_AUDIO_NCH=%d\n",
- sh_audio->i_bps * 8, sh_audio->samplerate, sh_audio->channels);
-
return 1;
}
@@ -181,13 +168,12 @@ static int init_audio(sh_audio_t *sh_audio, char *codecname, char *afm,
}
// it's available, let's try to init!
// init()
- mp_tmsg(MSGT_DECAUDIO, MSGL_INFO, "Opening audio decoder: [%s] %s\n",
+ mp_tmsg(MSGT_DECAUDIO, MSGL_V, "Opening audio decoder: [%s] %s\n",
mpadec->info->short_name, mpadec->info->name);
sh_audio->ad_driver = mpadec;
if (!init_audio_codec(sh_audio)) {
- mp_tmsg(MSGT_DECAUDIO, MSGL_WARN,
- "Could not open audio decoder %s.\n",
- mpadec->info->short_name);
+ mp_tmsg(MSGT_DECAUDIO, MSGL_WARN, "Audio decoder init failed for "
+ "codecs.conf entry \"%s\".\n", sh_audio->codec->name);
continue; // try next...
}
// Yeah! We got it!
@@ -251,8 +237,25 @@ int init_best_audio_codec(sh_audio_t *sh_audio, char **audio_codec_list,
return 0; // failed
}
- mp_tmsg(MSGT_DECAUDIO, MSGL_INFO, "Selected audio codec: [%s] afm: %s (%s)\n",
- sh_audio->codec->name, sh_audio->codec->drv, sh_audio->codec->info);
+ mp_tmsg(MSGT_DECAUDIO, MSGL_INFO, "Selected audio codec: %s [%s]\n",
+ sh_audio->codecname ? sh_audio->codecname : sh_audio->codec->info,
+ sh_audio->ad_driver->info->print_name ?
+ sh_audio->ad_driver->info->print_name :
+ sh_audio->ad_driver->info->short_name);
+ mp_tmsg(MSGT_DECAUDIO, MSGL_V,
+ "Audio codecs.conf entry: %s (%s) afm: %s\n",
+ sh_audio->codec->name, sh_audio->codec->info, sh_audio->codec->drv);
+ mp_msg(MSGT_DECAUDIO, MSGL_INFO,
+ "AUDIO: %d Hz, %d ch, %s, %3.1f kbit/%3.2f%% (ratio: %d->%d)\n",
+ sh_audio->samplerate, sh_audio->channels,
+ af_fmt2str_short(sh_audio->sample_format),
+ sh_audio->i_bps * 8 * 0.001,
+ ((float) sh_audio->i_bps / sh_audio->o_bps) * 100.0,
+ sh_audio->i_bps, sh_audio->o_bps);
+ mp_msg(MSGT_IDENTIFY, MSGL_INFO,
+ "ID_AUDIO_BITRATE=%d\nID_AUDIO_RATE=%d\n" "ID_AUDIO_NCH=%d\n",
+ sh_audio->i_bps * 8, sh_audio->samplerate, sh_audio->channels);
+
return 1; // success
}
diff --git a/libmpcodecs/dec_video.c b/libmpcodecs/dec_video.c
index 14cf029fbe..baa8467c1e 100644
--- a/libmpcodecs/dec_video.c
+++ b/libmpcodecs/dec_video.c
@@ -310,13 +310,14 @@ static int init_video(sh_video_t *sh_video, char *codecname, char *vfm,
// init()
const struct vd_functions *vd = sh_video->vd_driver;
- mp_tmsg(MSGT_DECVIDEO, MSGL_INFO, "Opening video decoder: [%s] %s\n",
+ mp_tmsg(MSGT_DECVIDEO, MSGL_V, "Opening video decoder: [%s] %s\n",
vd->info->short_name, vd->info->name);
// clear vf init error, it is no longer relevant
if (sh_video->vf_initialized < 0)
sh_video->vf_initialized = 0;
if (!vd->init(sh_video)) {
- mp_tmsg(MSGT_DECVIDEO, MSGL_INFO, "VDecoder init failed :(\n");
+ mp_tmsg(MSGT_DECVIDEO, MSGL_INFO, "Video decoder init failed for "
+ "codecs.conf entry \"%s\".\n", sh_video->codec->name);
sh_video->disp_w = orig_w;
sh_video->disp_h = orig_h;
if (sh_video->bih) {
@@ -389,8 +390,14 @@ int init_best_video_codec(sh_video_t *sh_video, char **video_codec_list,
return 0; // failed
}
- mp_tmsg(MSGT_DECVIDEO, MSGL_INFO, "Selected video codec: [%s] vfm: %s (%s)\n",
- sh_video->codec->name, sh_video->codec->drv, sh_video->codec->info);
+ mp_tmsg(MSGT_DECVIDEO, MSGL_INFO, "Selected video codec: %s [%s]\n",
+ sh_video->codecname ? sh_video->codecname : sh_video->codec->info,
+ sh_video->vd_driver->info->print_name ?
+ sh_video->vd_driver->info->print_name :
+ sh_video->vd_driver->info->short_name);
+ mp_tmsg(MSGT_DECVIDEO, MSGL_V,
+ "Video codecs.conf entry: %s (%s) vfm: %s\n",
+ sh_video->codec->name, sh_video->codec->info, sh_video->codec->drv);
return 1; // success
}
diff --git a/libmpcodecs/mpc_info.h b/libmpcodecs/mpc_info.h
index 45139947cb..de1631cad8 100644
--- a/libmpcodecs/mpc_info.h
+++ b/libmpcodecs/mpc_info.h
@@ -31,6 +31,7 @@ struct mp_codec_info
const char *author;
/* any additional comments */
const char *comment;
+ const char *print_name;
};
#define CONTROL_OK 1
diff --git a/libmpcodecs/vd.c b/libmpcodecs/vd.c
index 5a96e07783..a883f257b5 100644
--- a/libmpcodecs/vd.c
+++ b/libmpcodecs/vd.c
@@ -125,6 +125,11 @@ int mpcodecs_config_vo2(sh_video_t *sh, int w, int h,
if (h)
sh->disp_h = h;
+ mp_msg(MSGT_DECVIDEO, MSGL_INFO,
+ "VIDEO: %dx%d %5.3f fps %5.1f kbps (%4.1f kB/s)\n",
+ sh->disp_w, sh->disp_h, sh->fps, sh->i_bps * 0.008,
+ sh->i_bps / 1000.0);
+
if (!sh->disp_w || !sh->disp_h)
return 0;
@@ -293,22 +298,23 @@ int mpcodecs_config_vo2(sh_video_t *sh, int w, int h,
}
}
if (sh->aspect > 0.01) {
- int w;
- mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "Movie-Aspect is %.2f:1 - prescaling to correct movie aspect.\n",
- sh->aspect);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ASPECT=%1.4f\n",
sh->aspect);
- w = (int) ((float) screen_size_y * sh->aspect);
- w += w % 2; // round
+ int w = screen_size_y * sh->aspect;
+ int h = screen_size_y;
// we don't like horizontal downscale || user forced width:
if (w < screen_size_x || opts->screen_size_xy > 8) {
- screen_size_y =
- (int) ((float) screen_size_x * (1.0 / sh->aspect));
- screen_size_y += screen_size_y % 2; // round
- } else
- screen_size_x = w; // keep new width
+ w = screen_size_x;
+ h = screen_size_x / sh->aspect;
+ }
+ if (abs(screen_size_x - w) >= 4 || abs(screen_size_y - h) >= 4) {
+ screen_size_x = w;
+ screen_size_y = h;
+ mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "Aspect ratio is %.2f:1 - "
+ "scaling to correct movie aspect.\n", sh->aspect);
+ }
} else {
- mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "Movie-Aspect is undefined - no prescaling applied.\n");
+ mp_tmsg(MSGT_CPLAYER, MSGL_V, "Movie-Aspect is undefined - no prescaling applied.\n");
}
}
diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c
index 5a45fef6d8..b34b5b5593 100644
--- a/libmpcodecs/vd_ffmpeg.c
+++ b/libmpcodecs/vd_ffmpeg.c
@@ -43,11 +43,12 @@
#include "osdep/numcores.h"
static const vd_info_t info = {
- "FFmpeg's libavcodec codec family",
+ "libavcodec video codecs",
"ffmpeg",
- "A'rpi",
- "A'rpi, Michael, Alex",
- "native codecs"
+ "",
+ "",
+ "native codecs",
+ .print_name = "libavcodec",
};
#include "libavcodec/avcodec.h"
@@ -129,14 +130,32 @@ static int init(sh_video_t *sh)
ctx = sh->context = talloc_zero(NULL, vd_ffmpeg_ctx);
- lavc_codec = avcodec_find_decoder_by_name(sh->codec->dll);
- if (!lavc_codec) {
- mp_tmsg(MSGT_DECVIDEO, MSGL_ERR,
- "Cannot find codec '%s' in libavcodec...\n", sh->codec->dll);
- uninit(sh);
+ if (sh->codec->dll) {
+ lavc_codec = avcodec_find_decoder_by_name(sh->codec->dll);
+ if (!lavc_codec) {
+ mp_tmsg(MSGT_DECVIDEO, MSGL_ERR,
+ "Cannot find codec '%s' in libavcodec...\n",
+ sh->codec->dll);
+ uninit(sh);
+ return 0;
+ }
+ } else if (!sh->libav_codec_id) {
+ mp_tmsg(MSGT_DECVIDEO, MSGL_INFO, "No Libav codec ID known. "
+ "Generic lavc decoder is not applicable.\n");
return 0;
+ } else {
+ lavc_codec = avcodec_find_decoder(sh->libav_codec_id);
+ if (!lavc_codec) {
+ mp_tmsg(MSGT_DECVIDEO, MSGL_INFO, "Libavcodec has no decoder "
+ "for this codec\n");
+ return 0;
+ }
}
+ sh->codecname = lavc_codec->long_name;
+ if (!sh->codecname)
+ sh->codecname = lavc_codec->name;
+
if (sh->opts->vd_use_slices
&& (lavc_codec->capabilities & CODEC_CAP_DRAW_HORIZ_BAND)
&& !do_vis_debug)
@@ -191,7 +210,7 @@ static int init(sh_video_t *sh)
if (lavc_param->threads > 1) {
ctx->do_dr1 = false;
ctx->do_slices = false;
- mp_tmsg(MSGT_DECVIDEO, MSGL_INFO, "Asking decoder to use "
+ mp_tmsg(MSGT_DECVIDEO, MSGL_V, "Asking decoder to use "
"%d threads if supported.\n", lavc_param->threads);
}
@@ -320,8 +339,7 @@ static int init(sh_video_t *sh)
uninit(sh);
return 0;
}
- mp_msg(MSGT_DECVIDEO, MSGL_V, "INFO: libavcodec init OK!\n");
- return 1; //mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, IMGFMT_YV12);
+ return 1;
}
static void uninit(sh_video_t *sh)
@@ -329,6 +347,7 @@ static void uninit(sh_video_t *sh)
vd_ffmpeg_ctx *ctx = sh->context;
AVCodecContext *avctx = ctx->avctx;
+ sh->codecname = NULL;
if (sh->opts->lavc_param.vstats && avctx->coded_frame) {
for (int i = 1; i < 32; i++)
mp_msg(MSGT_DECVIDEO, MSGL_INFO,