[longomatch/livecapture: 9/9] Improve error handling creating new elements like muxers and encoder that might be unavailable
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch/livecapture: 9/9] Improve error handling creating new elements like muxers and encoder that might be unavailable
- Date: Sun, 28 Mar 2010 23:21:19 +0000 (UTC)
commit 23de41681329d477f65d63413c32546810f8af52
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Mon Mar 29 01:16:44 2010 +0200
Improve error handling creating new elements like muxers and encoder that might be unavailable
CesarPlayer/Capturer/GstCameraCapturer.cs | 48 +++++++++-------
libcesarplayer/src/gst-camera-capturer.c | 88 +++++++++++++++++++---------
libcesarplayer/src/gst-camera-capturer.h | 21 +++----
3 files changed, 96 insertions(+), 61 deletions(-)
---
diff --git a/CesarPlayer/Capturer/GstCameraCapturer.cs b/CesarPlayer/Capturer/GstCameraCapturer.cs
index 50f05ce..5fa1880 100644
--- a/CesarPlayer/Capturer/GstCameraCapturer.cs
+++ b/CesarPlayer/Capturer/GstCameraCapturer.cs
@@ -237,25 +237,6 @@ namespace LongoMatch.Video.Capturer {
}
[DllImport("libcesarplayer.dll")]
- static extern bool gst_camera_capturer_set_video_muxer(IntPtr raw, int type);
-
- public bool SetVideoMuxer(LongoMatch.Video.Capturer.GccVideoMuxerType type) {
- bool raw_ret = gst_camera_capturer_set_video_muxer(Handle, (int) type);
- bool ret = raw_ret;
- return ret;
- }
-
-
- [DllImport("libcesarplayer.dll")]
- static extern bool gst_camera_capturer_set_video_encoder(IntPtr raw, int type);
-
- public bool SetVideoEncoder(LongoMatch.Video.Capturer.GccVideoEncoderType type) {
- bool raw_ret = gst_camera_capturer_set_video_encoder(Handle, (int) type);
- bool ret = raw_ret;
- return ret;
- }
-
- [DllImport("libcesarplayer.dll")]
static extern void gst_camera_capturer_init_backend(out int argc, IntPtr argv);
public static int InitBackend(string argv) {
@@ -293,12 +274,37 @@ namespace LongoMatch.Video.Capturer {
public void Run() {
gst_camera_capturer_run(Handle);
}
+
+ [DllImport("libcesarplayer.dll")]
+ static extern bool gst_camera_capturer_set_video_muxer(IntPtr raw, int type, out IntPtr error);
+ public bool SetVideoMuxer(LongoMatch.Video.Capturer.GccVideoMuxerType type) {
+ IntPtr error = IntPtr.Zero;
+ bool raw_ret = gst_camera_capturer_set_video_muxer(Handle, (int) type, out error);
+ if (error != IntPtr.Zero) throw new GLib.GException (error);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+
[DllImport("libcesarplayer.dll")]
- static extern bool gst_camera_capturer_set_audio_encoder(IntPtr raw, int type);
+ static extern bool gst_camera_capturer_set_video_encoder(IntPtr raw, int type, out IntPtr error);
+
+ public bool SetVideoEncoder(LongoMatch.Video.Capturer.GccVideoEncoderType type) {
+ IntPtr error = IntPtr.Zero;
+ bool raw_ret = gst_camera_capturer_set_video_encoder(Handle, (int) type, out error);
+ if (error != IntPtr.Zero) throw new GLib.GException (error);
+ bool ret = raw_ret;
+ return ret;
+ }
+
+ [DllImport("libcesarplayer.dll")]
+ static extern bool gst_camera_capturer_set_audio_encoder(IntPtr raw, int type, out IntPtr error);
public bool SetAudioEncoder(LongoMatch.Video.Capturer.GccAudioEncoderType type) {
- bool raw_ret = gst_camera_capturer_set_audio_encoder(Handle, (int) type);
+ IntPtr error = IntPtr.Zero;
+ bool raw_ret = gst_camera_capturer_set_audio_encoder(Handle, (int) type, out error);
+ if (error != IntPtr.Zero) throw new GLib.GException (error);
bool ret = raw_ret;
return ret;
}
diff --git a/libcesarplayer/src/gst-camera-capturer.c b/libcesarplayer/src/gst-camera-capturer.c
index b320ba1..fe3fc4c 100644
--- a/libcesarplayer/src/gst-camera-capturer.c
+++ b/libcesarplayer/src/gst-camera-capturer.c
@@ -971,45 +971,58 @@ gst_camera_capturer_stop (GstCameraCapturer * gcc)
gboolean
gst_camera_capturer_set_video_encoder (GstCameraCapturer * gcc,
- GccVideoEncoderType type)
+ GccVideoEncoderType type,
+ GError ** err)
{
+ gchar *name = NULL;
+
g_return_val_if_fail (GST_IS_CAMERA_CAPTURER (gcc), FALSE);
+
switch (type)
{
case GCC_VIDEO_ENCODER_TYPE_MPEG4:
gcc->priv->videoenc =
gst_element_factory_make ("ffenc_mpeg4", "video-encoder");
- g_object_set (gcc->priv->camerabin, "video-encoder", gcc->priv->videoenc,
- NULL);
+ name = "FFmpeg mpeg4 video encoder";
break;
case GCC_VIDEO_ENCODER_TYPE_XVID:
gcc->priv->videoenc = gst_element_factory_make ("xvid_enc", "video-encoder");
- g_object_set (gcc->priv->camerabin, "video-encoder", gcc->priv->videoenc,
- NULL);
+ name = "Xvid video encoder";
break;
case GCC_VIDEO_ENCODER_TYPE_THEORA:
gcc->priv->videoenc =
gst_element_factory_make ("theoraenc", "video-encoder");
- g_object_set (gcc->priv->camerabin, "video-encoder", gcc->priv->videoenc,
- NULL);
+ name = "Theora video encoder";
break;
case GCC_VIDEO_ENCODER_TYPE_H264:
gcc->priv->videoenc = gst_element_factory_make ("x264enc", "video-encoder");
- g_object_set (gcc->priv->camerabin, "video-encoder", gcc->priv->videoenc,
- NULL);
+ name = "X264 video encoder";
break;
-
+ }
+ if (!gcc->priv->videoenc){
+ g_set_error (err,
+ GCC_ERROR,
+ GCC_ERROR_PLUGIN_LOAD,
+ "Failed to create the %s element. "
+ "Please check your GStreamer installation.",
+ name);
+ } else {
+ g_object_set (gcc->priv->camerabin, "audio-encoder", gcc->priv->audioenc,
+ NULL);
}
return TRUE;
}
gboolean
gst_camera_capturer_set_audio_encoder (GstCameraCapturer * gcc,
- GccAudioEncoderType type)
+ GccAudioEncoderType type,
+ GError ** err)
{
+ gchar *name = NULL;
+
g_return_val_if_fail (GST_IS_CAMERA_CAPTURER (gcc), FALSE);
switch (type)
@@ -1017,60 +1030,79 @@ gst_camera_capturer_set_audio_encoder (GstCameraCapturer * gcc,
case GCC_AUDIO_ENCODER_MP3:
gcc->priv->audioenc =
gst_element_factory_make ("ffenc_libmp3lame", "audio-encoder");
- g_object_set (gcc->priv->camerabin, "audio-encoder", gcc->priv->audioenc,
- NULL);
+ name = "Mp3 audio encoder";
break;
case GCC_AUDIO_ENCODER_AAC:
gcc->priv->audioenc = gst_element_factory_make ("faac", "audio-encoder");
- g_object_set (gcc->priv->camerabin, "audio-encoder", gcc->priv->audioenc,
- NULL);
+ name = "AAC audio encoder";
break;
case GCC_AUDIO_ENCODER_VORBIS:
gcc->priv->audioenc =
gst_element_factory_make ("vorbisenc", "audio-encoder");
- g_object_set (gcc->priv->camerabin, "audio-encoder", gcc->priv->audioenc,
- NULL);
+ name = "Vorbis audio encoder";
break;
}
+
+ if (!gcc->priv->audioenc){
+ g_set_error (err,
+ GCC_ERROR,
+ GCC_ERROR_PLUGIN_LOAD,
+ "Failed to create the %s element. "
+ "Please check your GStreamer installation.",
+ name);
+ } else {
+ g_object_set (gcc->priv->camerabin, "audio-encoder", gcc->priv->audioenc,
+ NULL);
+ }
return TRUE;
-
}
gboolean
gst_camera_capturer_set_video_muxer (GstCameraCapturer * gcc,
- GccVideoMuxerType type)
+ GccVideoMuxerType type,
+ GError ** err)
{
+ gchar *name = NULL;
+
g_return_val_if_fail (GST_IS_CAMERA_CAPTURER (gcc), FALSE);
switch (type)
{
case GCC_VIDEO_MUXER_OGG:
+ name = "OGG muxer";
gcc->priv->videomux = gst_element_factory_make ("oggmux", "video-muxer");
- g_object_set (gcc->priv->camerabin, "video-muxer", gcc->priv->videomux,
- NULL);
break;
case GCC_VIDEO_MUXER_AVI:
+ name = "AVI muxer";
gcc->priv->videomux = gst_element_factory_make ("avimux", "video-muxer");
- g_object_set (gcc->priv->camerabin, "video-muxer", gcc->priv->videomux,
- NULL);
break;
case GCC_VIDEO_MUXER_MP4:
+ name = "MP4 muxer";
gcc->priv->videomux =
gst_element_factory_make ("qtmux", "video-muxer");
- g_object_set (gcc->priv->camerabin, "video-muxer", gcc->priv->videomux,
- NULL);
break;
case GCC_VIDEO_MUXER_MATROSKA:
+ name = "Matroska muxer";
gcc->priv->videomux =
gst_element_factory_make ("matroskamux", "video-muxer");
- g_object_set (gcc->priv->camerabin, "video-muxer", gcc->priv->videomux,
- NULL);
break;
}
-
+
+ if (!gcc->priv->videomux){
+ g_set_error (err,
+ GCC_ERROR,
+ GCC_ERROR_PLUGIN_LOAD,
+ "Failed to create the %s element. "
+ "Please check your GStreamer installation.",
+ name);
+ } else {
+ g_object_set (gcc->priv->camerabin, "video-muxer", gcc->priv->videomux,
+ NULL);
+ }
+
return TRUE;
}
diff --git a/libcesarplayer/src/gst-camera-capturer.h b/libcesarplayer/src/gst-camera-capturer.h
index 094ada8..152ac22 100644
--- a/libcesarplayer/src/gst-camera-capturer.h
+++ b/libcesarplayer/src/gst-camera-capturer.h
@@ -127,18 +127,15 @@ EXPORT void gst_camera_capturer_run (GstCameraCapturer * gcc);
EXPORT void gst_camera_capturer_start (GstCameraCapturer * gcc);
EXPORT void gst_camera_capturer_toggle_pause (GstCameraCapturer * gcc);
EXPORT void gst_camera_capturer_stop (GstCameraCapturer * gcc);
-EXPORT gboolean gst_camera_capturer_set_video_encoder (GstCameraCapturer
- * gcc,
- GccVideoEncoderType
- type);
-EXPORT gboolean gst_camera_capturer_set_audio_encoder (GstCameraCapturer
- * gcc,
- GccAudioEncoderType
- type);
-EXPORT gboolean gst_camera_capturer_set_video_muxer (GstCameraCapturer *
- gcc,
- GccVideoMuxerType
- type);
+EXPORT gboolean gst_camera_capturer_set_video_encoder (GstCameraCapturer * gcc,
+ GccVideoEncoderType type,
+ GError ** err);
+EXPORT gboolean gst_camera_capturer_set_audio_encoder (GstCameraCapturer * gcc,
+ GccAudioEncoderType type,
+ GError ** err);
+EXPORT gboolean gst_camera_capturer_set_video_muxer (GstCameraCapturer * gcc,
+ GccVideoMuxerType type,
+ GError ** err);
EXPORT GValueArray gst_camera_capturer_enum_devices (GstCameraCapturer * gcc);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]