gstffmpeg.c 3.82 KB
Newer Older
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 31 32 33 34 35 36
#ifdef HAVE_FFMPEG_UNINSTALLED
#include <avcodec.h>
#include <avformat.h>
#else
#include <ffmpeg/avcodec.h>
#include <ffmpeg/avformat.h>
#endif
37

38
#include "gstffmpeg.h"
39
#include "gstffmpegcodecmap.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
Thomas Vander Stichele committed
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 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
#endif
152
  gst_ffmpegaudioresample_register (plugin);
153

154
  register_protocol (&gstreamer_protocol);
155 156 157 158 159

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

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
160 161 162
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
    "ffmpeg",
163
    "All FFMPEG codecs (" FFMPEG_SOURCE ")",
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
164
    plugin_init,
165
    PACKAGE_VERSION, "LGPL", "FFMpeg", "http://ffmpeg.sourceforge.net/")