gstffmpeg.c 3.96 KB
Newer Older
Andy Wingo Wingo's avatar
Andy Wingo Wingo committed
1
/* GStreamer
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/* First, include the header file for the plugin, to bring in the
 * object definition and other useful things.
 */
23

24
#ifdef HAVE_CONFIG_H
25
#include "config.h"
26
#endif
27 28
#include <stdio.h>
#include <string.h>
29
#include <gst/gst.h>
30
#ifdef HAVE_LIBAV_UNINSTALLED
31 32 33
#include <avcodec.h>
#include <avformat.h>
#else
34 35
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
36
#endif
37

38
#include "gstffmpeg.h"
39
#include "gstffmpegutils.h"
40

41
GST_DEBUG_CATEGORY (ffmpeg_debug);
42

43 44 45 46
static GStaticMutex gst_avcodec_mutex = G_STATIC_MUTEX_INIT;


int
47 48
gst_ffmpeg_avcodec_open (AVCodecContext * avctx, AVCodec * codec)
{
49 50 51 52 53
  int ret;

  g_static_mutex_lock (&gst_avcodec_mutex);
  ret = avcodec_open (avctx, codec);
  g_static_mutex_unlock (&gst_avcodec_mutex);
54

55 56 57 58
  return ret;
}

int
59 60
gst_ffmpeg_avcodec_close (AVCodecContext * avctx)
{
61
  int ret;
62

63 64 65
  g_static_mutex_lock (&gst_avcodec_mutex);
  ret = avcodec_close (avctx);
  g_static_mutex_unlock (&gst_avcodec_mutex);
66

67 68 69
  return ret;
}

70
int
71 72
gst_ffmpeg_av_find_stream_info (AVFormatContext * ic)
{
73 74 75 76 77 78 79 80 81
  int ret;

  g_static_mutex_lock (&gst_avcodec_mutex);
  ret = av_find_stream_info (ic);
  g_static_mutex_unlock (&gst_avcodec_mutex);

  return ret;
}

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 88
  gint len = strlen (fmt);
  gchar *fmt2 = NULL;
89

90 91 92
  if (_shut_up_I_am_probing)
    return;

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  switch (level) {
    case AV_LOG_QUIET:
      gst_level = GST_LEVEL_NONE;
      break;
    case AV_LOG_ERROR:
      gst_level = GST_LEVEL_ERROR;
      break;
    case AV_LOG_INFO:
      gst_level = GST_LEVEL_INFO;
      break;
    case AV_LOG_DEBUG:
      gst_level = GST_LEVEL_DEBUG;
      break;
    default:
      gst_level = GST_LEVEL_INFO;
      break;
  }

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 118
  gst_debug_log_valist (ffmpeg_debug, gst_level, "", "", 0, NULL,
      fmt2 ? fmt2 : fmt, vl);
119

120
  g_free (fmt2);
121
}
122
#endif
123

124 125 126 127
#ifndef GST_DISABLE_GST_DEBUG
gboolean _shut_up_I_am_probing = FALSE;
#endif

128
static gboolean
Thomas Vander Stichele's avatar
indent  
Thomas Vander Stichele committed
129
plugin_init (GstPlugin * plugin)
130
{
131
  GST_DEBUG_CATEGORY_INIT (ffmpeg_debug, "libav", 0, "libav 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 140
  av_register_all ();

141 142
  gst_ffmpegenc_register (plugin);
  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
  gst_ffmpegaudioresample_register (plugin);
Wim Taymans's avatar
Wim Taymans committed
152
#endif
153

154 155
  av_register_protocol2 (&gstreamer_protocol, sizeof (URLProtocol));
  av_register_protocol2 (&gstpipe_protocol, sizeof (URLProtocol));
156 157 158 159 160

  /* Now we can return the pointer to the newly created Plugin object. */
  return TRUE;
}

Thomas Vander Stichele's avatar
indent  
Thomas Vander Stichele committed
161 162
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
163 164
    libav,
    "All libav codecs and formats (" LIBAV_SOURCE ")",
165
    plugin_init, PACKAGE_VERSION,
166
#ifdef GST_LIBAV_ENABLE_LGPL
167 168 169 170
    "LGPL",
#else
    "GPL",
#endif
171
    "libav", "http://www.libav.org")