-
Notifications
You must be signed in to change notification settings - Fork 0
/
mygclientrecord.cpp
123 lines (94 loc) · 3.44 KB
/
mygclientrecord.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "mygclientrecord.h"
#include "QDir"
#include "iostream"
#include "statics.h"
mygclientrecord::mygclientrecord(QObject *parent) :
QObject(parent)
{
}
static gboolean
cb_print_position (GstElement *pipeline)
{
gint64 pos, len;
GstFormat c = GST_FORMAT_TIME;
if (gst_element_query_position (pipeline,&c, &pos)
&& gst_element_query_duration (pipeline, &c, &len)) {
// g_print ("Time: %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "\r",
// GST_TIME_ARGS (pos), GST_TIME_ARGS (len));
char buff[100];
snprintf(buff, sizeof(buff), "%" GST_TIME_FORMAT "", GST_TIME_ARGS (pos));
std::string buffAsStdStr = buff;
audio_info = buffAsStdStr;
//audio_current_second = GST_TIME_ARGS (pos);
//audio_max_seconds = GST_TIME_ARGS (len);
//std::cout<<audio_info<<std::endl;
}
/* call me again */
return TRUE;
}
void mygclientrecord::record_start(std::string filename)
{
/* Initialisation */
loop = g_main_loop_new (NULL, FALSE);
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("audio-recorder");
//----------------------------------------------------------------------------------------
source = gst_element_factory_make ("alsasrc", "src");
conv = gst_element_factory_make ("audioconvert", "converter");
lamemp3enc = gst_element_factory_make ("lamemp3enc" , "mp3");
sink = gst_element_factory_make ("filesink", "audio-output");
//----------------------------------------------------------------------------------------
/* check objects */
if (!pipeline || !source || !conv || !sink || !lamemp3enc ) {
g_printerr ("One element could not be created. Exiting.\n");
return;
}
else
{
printf("OK\n");
}
/* Set up the pipeline bin */
gst_bin_add_many (GST_BIN (pipeline),source, lamemp3enc , conv, sink, NULL);
/* Set up the links */
gboolean abool = gst_element_link (source , conv);
gboolean bbool = gst_element_link (conv , lamemp3enc);
gboolean cbool = gst_element_link (lamemp3enc , sink);
g_object_set (G_OBJECT (sink), "location", filename.c_str(), NULL);
/* check the links */
if ( abool && bbool && cbool )
{
printf("OK link\n");
}
else
{
printf("! link error\n");
}
mtlog->insert_log("gclientrecord","PGITIC - Gstreamer Interface record_start ","INFO");
GstStateChangeReturn ret;
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n");
return ;
}
g_timeout_add (200, (GSourceFunc) cb_print_position, pipeline);
g_print ("Recording...\n");
g_main_loop_run (loop);
}
void mygclientrecord::record_stop()
{
g_main_loop_quit(loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping recording\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
//gst_object_unref (GST_OBJECT (pipeline));
//g_source_remove (bus_watch_id);
g_main_loop_unref (loop);
//==========================================================================
mtlog->insert_log("gclientrecord","PGITIC - Gstreamer Interface Finished ","INFO");
}
void mygclientrecord::start()
{
app_exited = false;
mtlog->insert_log("gclientrecord","PGITIC - Gstreamer Interface Client Start","INFO");
}