Git init
[framework/multimedia/gstreamer0.10-ffmpeg.git] / ext / ffmpeg / gstffmpeg.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
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.
8  *
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.
13  *
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /* First, include the header file for the plugin, to bring in the
21  * object definition and other useful things.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 #include <stdio.h>
28 #include <string.h>
29 #include <gst/gst.h>
30 #ifdef HAVE_FFMPEG_UNINSTALLED
31 #include <avcodec.h>
32 #include <avformat.h>
33 #else
34 #include <libavcodec/avcodec.h>
35 #include <libavformat/avformat.h>
36 #endif
37
38 #include "gstffmpeg.h"
39 #include "gstffmpegutils.h"
40
41 GST_DEBUG_CATEGORY (ffmpeg_debug);
42
43 static GStaticMutex gst_avcodec_mutex = G_STATIC_MUTEX_INIT;
44
45
46 int
47 gst_ffmpeg_avcodec_open (AVCodecContext * avctx, AVCodec * codec)
48 {
49   int ret;
50
51   g_static_mutex_lock (&gst_avcodec_mutex);
52   ret = avcodec_open (avctx, codec);
53   g_static_mutex_unlock (&gst_avcodec_mutex);
54
55   return ret;
56 }
57
58 int
59 gst_ffmpeg_avcodec_close (AVCodecContext * avctx)
60 {
61   int ret;
62
63   g_static_mutex_lock (&gst_avcodec_mutex);
64   ret = avcodec_close (avctx);
65   g_static_mutex_unlock (&gst_avcodec_mutex);
66
67   return ret;
68 }
69
70 int
71 gst_ffmpeg_av_find_stream_info (AVFormatContext * ic)
72 {
73   int ret;
74
75   g_static_mutex_lock (&gst_avcodec_mutex);
76   ret = av_find_stream_info (ic);
77   g_static_mutex_unlock (&gst_avcodec_mutex);
78
79   return ret;
80 }
81
82 #ifndef GST_DISABLE_GST_DEBUG
83 static void
84 gst_ffmpeg_log_callback (void *ptr, int level, const char *fmt, va_list vl)
85 {
86   GstDebugLevel gst_level;
87   gint len = strlen (fmt);
88   gchar *fmt2 = NULL;
89
90   if (_shut_up_I_am_probing)
91     return;
92
93   switch (level) {
94     case AV_LOG_QUIET:
95       gst_level = GST_LEVEL_NONE;
96       break;
97     case AV_LOG_ERROR:
98       gst_level = GST_LEVEL_ERROR;
99       break;
100     case AV_LOG_INFO:
101       gst_level = GST_LEVEL_INFO;
102       break;
103     case AV_LOG_DEBUG:
104       gst_level = GST_LEVEL_DEBUG;
105       break;
106     default:
107       gst_level = GST_LEVEL_INFO;
108       break;
109   }
110
111   /* remove trailing newline as it gets already appended by the logger */
112   if (fmt[len - 1] == '\n') {
113     fmt2 = g_strdup (fmt);
114     fmt2[len - 1] = '\0';
115   }
116
117   gst_debug_log_valist (ffmpeg_debug, gst_level, "", "", 0, NULL,
118       fmt2 ? fmt2 : fmt, vl);
119
120   g_free (fmt2);
121 }
122 #endif
123
124 #ifndef GST_DISABLE_GST_DEBUG
125 gboolean _shut_up_I_am_probing = FALSE;
126 #endif
127
128 static gboolean
129 plugin_init (GstPlugin * plugin)
130 {
131   GST_DEBUG_CATEGORY_INIT (ffmpeg_debug, "ffmpeg", 0, "FFmpeg elements");
132 #ifndef GST_DISABLE_GST_DEBUG
133
134   av_log_set_callback (gst_ffmpeg_log_callback);
135 #endif
136
137   gst_ffmpeg_init_pix_fmt_info ();
138
139   av_register_all ();
140
141   gst_ffmpegenc_register (plugin);
142   gst_ffmpegdec_register (plugin);
143   gst_ffmpegdemux_register (plugin);
144   gst_ffmpegmux_register (plugin);
145   gst_ffmpegdeinterlace_register (plugin);
146 #if 0
147   gst_ffmpegscale_register (plugin);
148 #endif
149 #if 0
150   gst_ffmpegcsp_register (plugin);
151 #endif
152   gst_ffmpegaudioresample_register (plugin);
153
154   register_protocol (&gstreamer_protocol);
155   register_protocol (&gstpipe_protocol);
156
157   /* Now we can return the pointer to the newly created Plugin object. */
158   return TRUE;
159 }
160
161 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
162     GST_VERSION_MINOR,
163     "ffmpeg",
164     "All FFmpeg codecs and formats (" FFMPEG_SOURCE ")",
165     plugin_init, PACKAGE_VERSION, "LGPL", "FFmpeg", "http://ffmpeg.org/")