~ubuntu-branches/ubuntu/raring/gnomeradio/raring

« back to all changes in this revision

Viewing changes to .pc/gnomeradio-record_information.patch/src/rec_tech.c

  • Committer: Package Import Robot
  • Author(s): POJAR GEORGE
  • Date: 2012-07-02 20:54:09 UTC
  • Revision ID: package-import@ubuntu.com-20120702205409-0imetkxstcihst9e
Tags: 1.8-2ubuntu3
* debian/patches/gnomeradio-g_thread_init_deprecation.patch: Fix obsolete
  g_thread_init(). (LP: #1013383)
* debian/patches/gnomeradio-gtk_grid.patch: Port to GtkGrid from deprecated
  GtkTable. (LP: #1018398)
* gnomeradio-record_information.patch: Redesigned
  'Gnomeradio recording status' window to show more recording information.
  (LP: #1019981)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  This program is free software; you can redistribute it and/or modify
 
3
 *  it under the terms of the GNU General Public License as published by
 
4
 *  the Free Software Foundation; either version 2 of the License, or
 
5
 *  (at your option) any later version.
 
6
 *
 
7
 *  This program is distributed in the hope that it will be useful,
 
8
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
 *  GNU Library General Public License for more details.
 
11
 *
 
12
 *  You should have received a copy of the GNU General Public License
 
13
 *  along with this program; if not, write to the Free Software
 
14
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
15
 */
 
16
 
 
17
 
 
18
#include "rec_tech.h"
 
19
#include <gtk/gtk.h>
 
20
#include <glib/gi18n.h>
 
21
#include <libgnome-media-profiles/audio-profile.h>
 
22
#include <sys/types.h>
 
23
#include <sys/stat.h>
 
24
#include <unistd.h>
 
25
#include <fcntl.h>
 
26
 
 
27
static void error_cb(GstBus *bus, GstMessage *message, gpointer user_data)
 
28
{
 
29
        GError *error = NULL;
 
30
        GstElement *pipeline = user_data;
 
31
        g_assert(pipeline);
 
32
        
 
33
        /* Make sure the pipeline is not running any more */
 
34
        gst_element_set_state (pipeline, GST_STATE_NULL);
 
35
        
 
36
        gst_message_parse_error(message, &error, NULL);
 
37
        g_warning(_("GStreamer runtime error: %s\n"), error->message);
 
38
        g_error_free(error);
 
39
}
 
40
 
 
41
Recording*
 
42
recording_start(const char* filename)
 
43
{
 
44
        GMAudioProfile *profile;
 
45
        GstElement *pipeline, *source, *encoder, *filesink;
 
46
        pipeline = source = encoder = filesink = NULL;
 
47
        
 
48
        profile = gm_audio_profile_lookup(rec_settings.profile);
 
49
        g_assert(profile);
 
50
        
 
51
        pipeline = gst_pipeline_new("gnomeradio-record-pipeline");
 
52
        if (!pipeline) {
 
53
                g_warning(_("Could not create GStreamer pipeline. Check your Gstreamer installation!\n"));
 
54
                goto error;
 
55
        }               
 
56
        
 
57
        source = gst_element_factory_make("autoaudiosrc", "audio_source");
 
58
        if (!source) {
 
59
                g_warning(_("Could not open Gstreamer AUDIO Source. Verify your Gstreamer AUDIO subsystem installation!\n"));
 
60
                goto error;
 
61
        }
 
62
        
 
63
        GstBus *bus = gst_element_get_bus(pipeline);
 
64
        gst_bus_add_signal_watch(bus);
 
65
        g_signal_connect(G_OBJECT(bus), "message::error", G_CALLBACK(error_cb), pipeline);
 
66
 
 
67
        char* pipeline_str = g_strdup_printf("audioconvert ! %s", gm_audio_profile_get_pipeline(profile));
 
68
        encoder = gst_parse_bin_from_description(pipeline_str, TRUE, NULL);
 
69
        g_free(pipeline_str);
 
70
        if (!encoder) {
 
71
                char *caption = g_strdup_printf(_("Could not create encoder \"%s\"."), gm_audio_profile_get_name (profile));
 
72
                g_warning(_("%s Verify your Gstreamer plugins installation!\n"), caption);
 
73
                g_free(caption);
 
74
                goto error;
 
75
        }
 
76
        
 
77
        /* Write to disk */
 
78
        filesink = gst_element_factory_make("filesink", "file-sink");
 
79
        if (!filesink) {        
 
80
                g_warning(_("Could not create Gstreamer filesink. Check your Gstreamer installation!"));
 
81
                goto error;
 
82
        }
 
83
        
 
84
        /* Add the elements to the pipeline */
 
85
        gst_bin_add_many(GST_BIN(pipeline), source, encoder, filesink, NULL);
 
86
        
 
87
        /* Link it all together */
 
88
        if (!gst_element_link_many(source, encoder, filesink, NULL)) {
 
89
                g_warning("Could not link elements. This is bad!\n");
 
90
                goto error;
 
91
        }
 
92
        char* path = g_strdup_printf("%s.%s", filename, gm_audio_profile_get_extension(profile));       
 
93
        g_object_set(G_OBJECT(filesink), "location", path, NULL);
 
94
        
 
95
        gst_element_set_state(pipeline, GST_STATE_PLAYING);
 
96
        
 
97
        Recording *recording = g_malloc0(sizeof(Recording));
 
98
        recording->filename = path;
 
99
        recording->pipeline = pipeline;
 
100
        
 
101
        return recording;
 
102
        
 
103
error:
 
104
        if (pipeline)
 
105
                gst_object_unref(GST_OBJECT(pipeline));
 
106
        if (source)
 
107
                gst_object_unref(GST_OBJECT(source));
 
108
        if (encoder)
 
109
                gst_object_unref(GST_OBJECT(encoder));
 
110
        if (filesink)
 
111
                gst_object_unref(GST_OBJECT(filesink));
 
112
        
 
113
        return NULL;
 
114
}               
 
115
 
 
116
void
 
117
recording_stop(Recording *recording)
 
118
{
 
119
        g_assert(recording);
 
120
 
 
121
        GstState state;
 
122
        gst_element_get_state(recording->pipeline, &state, NULL, GST_CLOCK_TIME_NONE);
 
123
        if (state != GST_STATE_PLAYING) {
 
124
        g_print("Ups!\n");
 
125
        } else {
 
126
                gst_element_set_state(recording->pipeline, GST_STATE_NULL);
 
127
        }
 
128
        gst_object_unref(GST_OBJECT(recording->pipeline));
 
129
        g_free(recording->filename);
 
130
        g_free(recording->station);
 
131
        g_free(recording);
 
132
}       
 
133
 
 
134
/*
 
135
 * Miscellanelous functions
 
136
 */
 
137
 
 
138
int get_file_size(char *filename)
 
139
{
 
140
        struct stat buffer;
 
141
        g_assert(filename);
 
142
        
 
143
        if (lstat(filename, &buffer))
 
144
                return -1;
 
145
        return (int)buffer.st_size;
 
146
}
 
147
 
 
148
int check_filename(const char *filename)
 
149
{
 
150
        int flags, retval;
 
151
        
 
152
        g_assert(filename);
 
153
        
 
154
        flags = O_RDWR | O_CREAT | O_APPEND;
 
155
        
 
156
        retval = open(filename, flags, 0664);
 
157
        
 
158
        if (retval < 0)
 
159
        {
 
160
                return 0;
 
161
        }
 
162
 
 
163
        close(retval);
 
164
        return 1;
 
165
}