Merge branch 'master' into 0.11

Conflicts:
	configure.ac
	ext/ffmpeg/gstffmpegdec.c
This commit is contained in:
Wim Taymans 2011-07-07 13:50:18 +02:00
commit fc6b32330a
6 changed files with 88 additions and 18 deletions

2
common

@ -1 +1 @@
Subproject commit 69b981f10caa234ad0ff639179d0fda8505bd94b Subproject commit 605cd9a65ed61505f24b840d3fe8e252be72b151

View file

@ -1864,7 +1864,7 @@ gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
caps = gst_caps_new_empty (); caps = gst_caps_new_empty ();
for (i = 0; codec->sample_fmts[i] != -1; i++) { for (i = 0; codec->sample_fmts[i] != -1; i++) {
temp = temp =
gst_ffmpeg_smpfmt_to_caps (codec->sample_fmts[0], context, codec_id); gst_ffmpeg_smpfmt_to_caps (codec->sample_fmts[i], context, codec_id);
if (temp != NULL) if (temp != NULL)
gst_caps_append (caps, temp); gst_caps_append (caps, temp);
} }

View file

@ -122,6 +122,7 @@ struct _GstFFMpegDec
gboolean do_padding; gboolean do_padding;
gboolean debug_mv; gboolean debug_mv;
gboolean crop; gboolean crop;
int max_threads;
/* QoS stuff *//* with LOCK */ /* QoS stuff *//* with LOCK */
gdouble proportion; gdouble proportion;
@ -192,6 +193,7 @@ gst_ts_info_get (GstFFMpegDec * dec, gint idx)
#define DEFAULT_DO_PADDING TRUE #define DEFAULT_DO_PADDING TRUE
#define DEFAULT_DEBUG_MV FALSE #define DEFAULT_DEBUG_MV FALSE
#define DEFAULT_CROP TRUE #define DEFAULT_CROP TRUE
#define DEFAULT_MAX_THREADS 0
enum enum
{ {
@ -202,6 +204,7 @@ enum
PROP_DO_PADDING, PROP_DO_PADDING,
PROP_DEBUG_MV, PROP_DEBUG_MV,
PROP_CROP, PROP_CROP,
PROP_MAX_THREADS,
PROP_LAST PROP_LAST
}; };
@ -355,6 +358,8 @@ gst_ffmpegdec_class_init (GstFFMpegDecClass * klass)
gobject_class->get_property = gst_ffmpegdec_get_property; gobject_class->get_property = gst_ffmpegdec_get_property;
if (klass->in_plugin->type == AVMEDIA_TYPE_VIDEO) { if (klass->in_plugin->type == AVMEDIA_TYPE_VIDEO) {
int caps;
g_object_class_install_property (gobject_class, PROP_SKIPFRAME, g_object_class_install_property (gobject_class, PROP_SKIPFRAME,
g_param_spec_enum ("skip-frame", "Skip frames", g_param_spec_enum ("skip-frame", "Skip frames",
"Which types of frames to skip during decoding", "Which types of frames to skip during decoding",
@ -382,6 +387,15 @@ gst_ffmpegdec_class_init (GstFFMpegDecClass * klass)
"Crop images to the display region", "Crop images to the display region",
DEFAULT_CROP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); DEFAULT_CROP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
#endif #endif
caps = klass->in_plugin->capabilities;
if (caps & (CODEC_CAP_FRAME_THREADS | CODEC_CAP_SLICE_THREADS)) {
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_THREADS,
g_param_spec_int ("max-threads", "Maximum decode threads",
"Maximum number of worker threads to spawn. (0 = auto)",
0, G_MAXINT, DEFAULT_MAX_THREADS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
} }
gstelement_class->change_state = gst_ffmpegdec_change_state; gstelement_class->change_state = gst_ffmpegdec_change_state;
@ -423,6 +437,7 @@ gst_ffmpegdec_init (GstFFMpegDec * ffmpegdec)
ffmpegdec->do_padding = DEFAULT_DO_PADDING; ffmpegdec->do_padding = DEFAULT_DO_PADDING;
ffmpegdec->debug_mv = DEFAULT_DEBUG_MV; ffmpegdec->debug_mv = DEFAULT_DEBUG_MV;
ffmpegdec->crop = DEFAULT_CROP; ffmpegdec->crop = DEFAULT_CROP;
ffmpegdec->max_threads = DEFAULT_MAX_THREADS;
ffmpegdec->format.video.par_n = -1; ffmpegdec->format.video.par_n = -1;
ffmpegdec->format.video.fps_n = -1; ffmpegdec->format.video.fps_n = -1;
@ -839,6 +854,11 @@ gst_ffmpegdec_setcaps (GstFFMpegDec * ffmpegdec, GstCaps * caps)
* supports it) */ * supports it) */
ffmpegdec->context->debug_mv = ffmpegdec->debug_mv; ffmpegdec->context->debug_mv = ffmpegdec->debug_mv;
if (ffmpegdec->max_threads == 0)
ffmpegdec->context->thread_count = gst_ffmpeg_auto_max_threads ();
else
ffmpegdec->context->thread_count = ffmpegdec->max_threads;
/* open codec - we don't select an output pix_fmt yet, /* open codec - we don't select an output pix_fmt yet,
* simply because we don't know! We only get it * simply because we don't know! We only get it
* during playback... */ * during playback... */
@ -1657,16 +1677,12 @@ flush_queued (GstFFMpegDec * ffmpegdec)
return res; return res;
} }
static AVPacket * static void
gst_avpacket_new (guint8 * data, guint size) gst_avpacket_init (AVPacket * packet, guint8 * data, guint size)
{ {
AVPacket *res; memset (packet, 0, sizeof (AVPacket));
packet->data = data;
res = g_malloc0 (sizeof (AVPacket)); packet->size = size;
res->data = data;
res->size = size;
return res;
} }
/* gst_ffmpegdec_[video|audio]_frame: /* gst_ffmpegdec_[video|audio]_frame:
@ -1696,7 +1712,7 @@ gst_ffmpegdec_video_frame (GstFFMpegDec * ffmpegdec,
GstClockTime out_timestamp, out_duration, out_pts; GstClockTime out_timestamp, out_duration, out_pts;
gint64 out_offset; gint64 out_offset;
const GstTSInfo *out_info; const GstTSInfo *out_info;
AVPacket *packet; AVPacket packet;
*ret = GST_FLOW_OK; *ret = GST_FLOW_OK;
*outbuf = NULL; *outbuf = NULL;
@ -1742,9 +1758,9 @@ gst_ffmpegdec_video_frame (GstFFMpegDec * ffmpegdec,
GST_DEBUG_OBJECT (ffmpegdec, "stored opaque values idx %d", dec_info->idx); GST_DEBUG_OBJECT (ffmpegdec, "stored opaque values idx %d", dec_info->idx);
/* now decode the frame */ /* now decode the frame */
packet = gst_avpacket_new (data, size); gst_avpacket_init (&packet, data, size);
len = avcodec_decode_video2 (ffmpegdec->context, len = avcodec_decode_video2 (ffmpegdec->context,
ffmpegdec->picture, &have_data, packet); ffmpegdec->picture, &have_data, &packet);
/* restore previous state */ /* restore previous state */
if (!decode) if (!decode)
@ -2106,7 +2122,7 @@ gst_ffmpegdec_audio_frame (GstFFMpegDec * ffmpegdec,
GstClockTime out_timestamp, out_duration; GstClockTime out_timestamp, out_duration;
gint64 out_offset; gint64 out_offset;
int16_t *odata; int16_t *odata;
AVPacket *packet; AVPacket packet;
GST_DEBUG_OBJECT (ffmpegdec, GST_DEBUG_OBJECT (ffmpegdec,
"size:%d, offset:%" G_GINT64_FORMAT ", ts:%" GST_TIME_FORMAT ", dur:%" "size:%d, offset:%" G_GINT64_FORMAT ", ts:%" GST_TIME_FORMAT ", dur:%"
@ -2118,8 +2134,8 @@ gst_ffmpegdec_audio_frame (GstFFMpegDec * ffmpegdec,
odata = gst_buffer_map (*outbuf, NULL, NULL, GST_MAP_WRITE); odata = gst_buffer_map (*outbuf, NULL, NULL, GST_MAP_WRITE);
packet = gst_avpacket_new (data, size); gst_avpacket_init (&packet, data, size);
len = avcodec_decode_audio3 (ffmpegdec->context, odata, &have_data, packet); len = avcodec_decode_audio3 (ffmpegdec->context, odata, &have_data, &packet);
GST_DEBUG_OBJECT (ffmpegdec, GST_DEBUG_OBJECT (ffmpegdec,
"Decode audio: len=%d, have_data=%d", len, have_data); "Decode audio: len=%d, have_data=%d", len, have_data);
@ -2865,6 +2881,9 @@ gst_ffmpegdec_set_property (GObject * object,
case PROP_CROP: case PROP_CROP:
ffmpegdec->crop = g_value_get_boolean (value); ffmpegdec->crop = g_value_get_boolean (value);
break; break;
case PROP_MAX_THREADS:
ffmpegdec->max_threads = g_value_get_int (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -2896,6 +2915,9 @@ gst_ffmpegdec_get_property (GObject * object,
case PROP_CROP: case PROP_CROP:
g_value_set_boolean (value, ffmpegdec->crop); g_value_set_boolean (value, ffmpegdec->crop);
break; break;
case PROP_MAX_THREADS:
g_value_set_int (value, ffmpegdec->max_threads);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -3033,6 +3055,14 @@ gst_ffmpegdec_register (GstPlugin * plugin)
case CODEC_ID_MP3: case CODEC_ID_MP3:
rank = GST_RANK_NONE; rank = GST_RANK_NONE;
break; break;
/* TEMPORARILY DISABLING AC3/EAC3/DTS for 0.10.12 release
* due to downmixing failure.
* See Bug #608892 for more details */
case CODEC_ID_EAC3:
case CODEC_ID_AC3:
case CODEC_ID_DTS:
rank = GST_RANK_NONE;
break;
default: default:
rank = GST_RANK_MARGINAL; rank = GST_RANK_MARGINAL;
break; break;

View file

@ -21,6 +21,10 @@
#include "config.h" #include "config.h"
#endif #endif
#include "gstffmpegutils.h" #include "gstffmpegutils.h"
#include <unistd.h>
#ifdef __APPLE__
#include <sys/sysctl.h>
#endif
G_CONST_RETURN gchar * G_CONST_RETURN gchar *
gst_ffmpeg_get_codecid_longname (enum CodecID codec_id) gst_ffmpeg_get_codecid_longname (enum CodecID codec_id)
@ -440,3 +444,37 @@ new_aligned_buffer (gint size)
return buf; return buf;
} }
int
gst_ffmpeg_auto_max_threads (void)
{
static gsize n_threads = 0;
if (g_once_init_enter (&n_threads)) {
int n = 1;
#if defined(_WIN32)
{
const char *s = getenv ("NUMBER_OF_PROCESSORS");
if (s) {
n = atoi (s);
}
}
#elif defined(__APPLE__)
{
int mib[] = { CTL_HW, HW_NCPU };
size_t dataSize = sizeof (int);
if (sysctl (mib, 2, &n_threads, &dataSize, NULL, 0)) {
n = 1;
}
}
#else
n = sysconf (_SC_NPROCESSORS_CONF);
#endif
if (n < 1)
n = 1;
g_once_init_leave (&n_threads, n);
}
return (int) (n_threads);
}

View file

@ -80,6 +80,8 @@ gst_ffmpeg_time_gst_to_ff (guint64 time, AVRational base)
void void
gst_ffmpeg_init_pix_fmt_info(void); gst_ffmpeg_init_pix_fmt_info(void);
int
gst_ffmpeg_auto_max_threads(void);
G_CONST_RETURN gchar * G_CONST_RETURN gchar *
gst_ffmpeg_get_codecid_longname (enum CodecID codec_id); gst_ffmpeg_get_codecid_longname (enum CodecID codec_id);

@ -1 +1 @@
Subproject commit 371266daa3df35c424203fff0ce2e6de0e33a29d Subproject commit 9c709f053474dd74890f32662b7d7010e5cc0b0d