2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 /* First, include the header file for the plugin, to bring in the
21 * object definition and other useful things.
32 #include "gstavutils.h"
35 #ifdef GST_LIBAV_ENABLE_GPL
38 #define LICENSE "LGPL"
41 GST_DEBUG_CATEGORY (ffmpeg_debug);
43 static GMutex gst_avcodec_mutex;
46 * Check for FFmpeg-provided libavcodec/format
48 static inline gboolean
49 gst_ffmpeg_avcodec_is_ffmpeg (void)
51 guint av_version = avcodec_version ();
53 GST_DEBUG ("Using libavcodec version %d.%d.%d",
54 av_version >> 16, (av_version & 0x00ff00) >> 8, av_version & 0xff);
56 /* FFmpeg *_MICRO versions start at 100 and Libav's at 0 */
57 if ((av_version & 0xff) < 100)
64 gst_ffmpeg_avcodec_open (AVCodecContext * avctx, AVCodec * codec)
68 g_mutex_lock (&gst_avcodec_mutex);
69 ret = avcodec_open2 (avctx, codec, NULL);
70 g_mutex_unlock (&gst_avcodec_mutex);
76 gst_ffmpeg_avcodec_close (AVCodecContext * avctx)
80 g_mutex_lock (&gst_avcodec_mutex);
81 ret = avcodec_close (avctx);
82 g_mutex_unlock (&gst_avcodec_mutex);
88 gst_ffmpeg_av_find_stream_info (AVFormatContext * ic)
92 g_mutex_lock (&gst_avcodec_mutex);
93 ret = avformat_find_stream_info (ic, NULL);
94 g_mutex_unlock (&gst_avcodec_mutex);
99 #ifndef GST_DISABLE_GST_DEBUG
101 gst_ffmpeg_log_callback (void *ptr, int level, const char *fmt, va_list vl)
103 GstDebugLevel gst_level;
104 gint len = strlen (fmt);
109 gst_level = GST_LEVEL_NONE;
112 gst_level = GST_LEVEL_ERROR;
115 gst_level = GST_LEVEL_INFO;
118 gst_level = GST_LEVEL_DEBUG;
121 gst_level = GST_LEVEL_INFO;
125 /* remove trailing newline as it gets already appended by the logger */
126 if (fmt[len - 1] == '\n') {
127 fmt2 = g_strdup (fmt);
128 fmt2[len - 1] = '\0';
131 gst_debug_log_valist (ffmpeg_debug, gst_level, "", "", 0, NULL,
132 fmt2 ? fmt2 : fmt, vl);
139 plugin_init (GstPlugin * plugin)
141 GST_DEBUG_CATEGORY_INIT (ffmpeg_debug, "libav", 0, "libav elements");
143 /* Bail if not FFmpeg. We can no longer ensure operation with Libav */
144 if (!gst_ffmpeg_avcodec_is_ffmpeg ()) {
145 GST_ERROR_OBJECT (plugin,
146 "Incompatible, non-FFmpeg libavcodec/format found");
149 #ifndef GST_DISABLE_GST_DEBUG
150 av_log_set_callback (gst_ffmpeg_log_callback);
153 gst_ffmpeg_init_pix_fmt_info ();
155 /* build global ffmpeg param/property info */
156 gst_ffmpeg_cfg_init ();
158 gst_ffmpegaudenc_register (plugin);
159 gst_ffmpegvidenc_register (plugin);
160 gst_ffmpegauddec_register (plugin);
161 gst_ffmpegviddec_register (plugin);
162 gst_ffmpegdemux_register (plugin);
163 gst_ffmpegmux_register (plugin);
164 gst_ffmpegdeinterlace_register (plugin);
166 /* Now we can return the pointer to the newly created Plugin object. */
170 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
173 "All libav codecs and formats (" LIBAV_SOURCE ")",
174 plugin_init, PACKAGE_VERSION, LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)