Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GStreamer_audioRecorder
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
m3
GStreamer_audioRecorder
Commits
b8dc7be7
Commit
b8dc7be7
authored
Oct 02, 2017
by
d.basulto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
solve bug related to segmentation core
parent
af6a6793
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
88 deletions
+109
-88
StreamRecorder.cpp
StreamRecorder.cpp
+60
-40
StreamRecorder.h
StreamRecorder.h
+49
-48
No files found.
StreamRecorder.cpp
View file @
b8dc7be7
...
@@ -166,6 +166,7 @@ gboolean StreamRecorder::reconnectURIStream(void* instance)
...
@@ -166,6 +166,7 @@ gboolean StreamRecorder::reconnectURIStream(void* instance)
* @param user_data NULL
* @param user_data NULL
* @return unimplemented
* @return unimplemented
*/
*/
int
StreamRecorder
::
bus_callback
(
GstBus
*
bus
,
GstMessage
*
message
,
void
*
user_data
)
int
StreamRecorder
::
bus_callback
(
GstBus
*
bus
,
GstMessage
*
message
,
void
*
user_data
)
{
{
//printf("StreamRecorder got %s message\n", GST_MESSAGE_TYPE_NAME (message));
//printf("StreamRecorder got %s message\n", GST_MESSAGE_TYPE_NAME (message));
...
@@ -187,15 +188,17 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
...
@@ -187,15 +188,17 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
long
int
actualRecordTime
;
long
int
actualRecordTime
;
long
int
currentTime
=
time
(
NULL
);
long
int
currentTime
=
time
(
NULL
);
long
int
addTime
;
long
int
bytesToAdd
;
//cout << "Audio start time (timestamp): " << ((StreamRecorder*)user_data)->timestamp << endl;
//cout << "Audio start time (timestamp): " << ((StreamRecorder*)user_data)->timestamp << endl;
//cout << "Actual time (timestamp): " << currentTime << endl;
//cout << "Actual time (timestamp): " << currentTime << endl;
actualRecordTime
=
currentTime
-
((
StreamRecorder
*
)
user_data
)
->
timestamp
;
actualRecordTime
=
currentTime
-
((
StreamRecorder
*
)
user_data
)
->
timestamp
;
cout
<<
"Record time: "
<<
actualRecordTime
<<
endl
;
cout
<<
"Record time: "
<<
actualRecordTime
<<
endl
;
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
/**
Record time is greater than th required
*/
/**
The calculated record time is greater?
*/
if
(
actualRecordTime
>=
((
StreamRecorder
*
)
user_data
)
->
audioFileDuration
)
if
(
actualRecordTime
>=
((
StreamRecorder
*
)
user_data
)
->
audioFileDuration
)
{
{
cout
<<
"Bytes readed: "
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
endl
;
cout
<<
"Bytes readed: "
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
endl
;
...
@@ -204,7 +207,10 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
...
@@ -204,7 +207,10 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
else
else
{
{
/** Moves the pointer to the position corresponding to the difference of the timestamps */
/** Moves the pointer to the position corresponding to the difference of the timestamps */
long
int
bytesToAdd
=
actualRecordTime
*
READSIZE
*
STREAMRECORDER_BYTESPERSAMPLE
*
10
;
addTime
=
currentTime
-
((
StreamRecorder
*
)
user_data
)
->
oldTmpTimestamp
;
cout
<<
"Time to add: "
<<
addTime
<<
endl
;
bytesToAdd
=
addTime
*
READSIZE
*
STREAMRECORDER_BYTESPERSAMPLE
*
10
;
cout
<<
"-------------------------------------"
<<
endl
;
cout
<<
"-------------------------------------"
<<
endl
;
cout
<<
"Actual Bytes number: "
<<
"("
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
") + "
;
cout
<<
"Actual Bytes number: "
<<
"("
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
") + "
;
...
@@ -223,7 +229,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
...
@@ -223,7 +229,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
((
StreamRecorder
*
)
user_data
)
->
isConnectionLost
=
false
;
((
StreamRecorder
*
)
user_data
)
->
isConnectionLost
=
false
;
/** Try reconnect with the radio stream*/
/** Try reconnect with the radio stream*/
g_timeout_add
(
5
*
1000
,
reconnectURIStream
,
user_data
);
g_timeout_add
(
1
*
1000
,
reconnectURIStream
,
user_data
);
}
}
break
;
break
;
...
@@ -237,10 +243,11 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
...
@@ -237,10 +243,11 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
g_free
(
debug
);
g_free
(
debug
);
strcpy
(((
StreamRecorder
*
)
user_data
)
->
errorMessage
,
error
->
message
);
strcpy
(((
StreamRecorder
*
)
user_data
)
->
errorMessage
,
error
->
message
);
/** The message doesn't contains null character*/
/** The message doesn't contains null character*/
((
StreamRecorder
*
)
user_data
)
->
errorMessage
[
ERROR_MSG_SIZE
-
1
]
=
'\0'
;
((
StreamRecorder
*
)
user_data
)
->
errorMessage
[
ERROR_MSG_SIZE
-
1
]
=
'\0'
;
cerr
<<
"Error: "
<<
((
StreamRecorder
*
)
user_data
)
->
errorMessage
<<
endl
;
//
cerr << "Error: "<< ((StreamRecorder*)user_data)->errorMessage << endl;
g_error_free
(
error
);
g_error_free
(
error
);
if
(
strcmp
(((
StreamRecorder
*
)
user_data
)
->
errorMessage
,
"Stream doesn't contain enough data."
)
==
0
)
if
(
strcmp
(((
StreamRecorder
*
)
user_data
)
->
errorMessage
,
"Stream doesn't contain enough data."
)
==
0
)
...
@@ -249,57 +256,66 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
...
@@ -249,57 +256,66 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
/** Not audio stream received */
/** Not audio stream received */
if
(((
StreamRecorder
*
)
user_data
)
->
timestamp
==
0
)
if
(((
StreamRecorder
*
)
user_data
)
->
timestamp
==
0
)
{
{
g_timeout_add
(
5
*
1000
,
reconnectURIStream
,
user_data
);
g_timeout_add
(
1
*
1000
,
reconnectURIStream
,
user_data
);
}
}
else
else
{
{
long
int
actualRecordTime
;
long
int
currentTime
=
time
(
NULL
);
long
int
addTime
;
cout
<<
"Actual time (timestamp): "
<<
currentTime
<<
endl
;
actualRecordTime
=
currentTime
-
((
StreamRecorder
*
)
user_data
)
->
timestamp
;
cout
<<
"Record time: "
<<
actualRecordTime
<<
endl
;
/** Record time is greater than th required */
if
(
actualRecordTime
>=
((
StreamRecorder
*
)
user_data
)
->
audioFileDuration
)
{
cout
<<
"Bytes readed: "
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
endl
;
saveBuffer
(
user_data
);
}
else
{
/** Moves the pointer to the position corresponding to the difference of the timestamps */
addTime
=
currentTime
-
((
StreamRecorder
*
)
user_data
)
->
oldTmpTimestamp
;
cout
<<
"Time to add: "
<<
1
<<
endl
;
long
int
bytesToAdd
=
1
*
READSIZE
*
STREAMRECORDER_BYTESPERSAMPLE
*
10
;
cout
<<
"-------------------------------------"
<<
endl
;
cout
<<
"Actual Bytes number: "
<<
"("
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
") + "
;
cout
<<
"Bytes t/add: "
<<
"("
<<
bytesToAdd
<<
")"
<<
endl
;
/** Update the pointer and the bytes number */
((
StreamRecorder
*
)
user_data
)
->
nBytes
+=
bytesToAdd
;
((
StreamRecorder
*
)
user_data
)
->
audioBufferPosition
+=
bytesToAdd
;
cout
<<
"Result : "
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
endl
;
cout
<<
"Buffer size: "
<<
((
StreamRecorder
*
)
user_data
)
->
bufferSize
<<
endl
;
cout
<<
"-------------------------------------"
<<
endl
;
}
long
int
actualRecordTime
;
long
int
currentTime
=
time
(
NULL
);
//cout << "Audio start time (timestamp): " << ((StreamRecorder *) user_data)->timestamp << endl;
//cout << "Actual time (timestamp): " << currentTime << endl;
actualRecordTime
=
currentTime
-
((
StreamRecorder
*
)
user_data
)
->
timestamp
;
cout
<<
"Record time: "
<<
actualRecordTime
<<
endl
;
/** Record time is greater than th required */
if
(
actualRecordTime
>=
((
StreamRecorder
*
)
user_data
)
->
audioFileDuration
)
{
cout
<<
"Bytes readed: "
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
endl
;
saveBuffer
(
user_data
);
}
else
{
/** Moves the pointer to the position corresponding to the difference of the timestamps */
long
int
bytesToAdd
=
actualRecordTime
*
READSIZE
*
STREAMRECORDER_BYTESPERSAMPLE
*
10
;
cout
<<
"-------------------------------------"
<<
endl
;
cout
<<
"Actual Bytes number: "
<<
"("
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
") + "
;
cout
<<
"Bytes t/add: "
<<
"("
<<
bytesToAdd
<<
")"
<<
endl
;
/** Update the pointer and the bytes number */
((
StreamRecorder
*
)
user_data
)
->
nBytes
+=
bytesToAdd
;
((
StreamRecorder
*
)
user_data
)
->
audioBufferPosition
+=
bytesToAdd
;
cout
<<
"Result : "
<<
((
StreamRecorder
*
)
user_data
)
->
nBytes
<<
endl
;
cout
<<
"Buffer size: "
<<
((
StreamRecorder
*
)
user_data
)
->
bufferSize
<<
endl
;
cout
<<
"-------------------------------------"
<<
endl
;
}
((
StreamRecorder
*
)
user_data
)
->
isConnectionLost
=
false
;
((
StreamRecorder
*
)
user_data
)
->
isConnectionLost
=
false
;
/** Try reconnect with the radio stream*/
/** Try reconnect with the radio stream*/
g_timeout_add
(
5
*
1000
,
reconnectURIStream
,
user_data
);
g_timeout_add
(
1
*
1000
,
reconnectURIStream
,
user_data
);
}
}
}
}
break
;
break
;
default
:
default
:
break
;
break
;
}
}
return
TRUE
;
return
TRUE
;
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
StreamRecorder
::
saveBuffer
(
void
*
user_data
)
void
StreamRecorder
::
saveBuffer
(
void
*
user_data
)
{
{
...
@@ -392,7 +408,8 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
...
@@ -392,7 +408,8 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
cout
<<
"Data size: "
<<
bytesRead
<<
endl
;
cout
<<
"Data size: "
<<
bytesRead
<<
endl
;
//if(nBytes < bufferSize){
//if(nBytes < bufferSize)
//{
/** Update pointer*/
/** Update pointer*/
memcpy
((
char
*
)
audioBufferPosition
,
(
char
*
)
data
,
bytesRead
);
memcpy
((
char
*
)
audioBufferPosition
,
(
char
*
)
data
,
bytesRead
);
nBytes
+=
bytesRead
;
nBytes
+=
bytesRead
;
...
@@ -411,6 +428,9 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
...
@@ -411,6 +428,9 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
{
{
currentTime
=
time
(
NULL
);
currentTime
=
time
(
NULL
);
oldTmpTimestamp
=
newTmpTimestamp
;
newTmpTimestamp
=
currentTime
;
actualRecordTime
=
currentTime
-
timestamp
;
actualRecordTime
=
currentTime
-
timestamp
;
cout
<<
"Record time: "
<<
actualRecordTime
<<
endl
;
cout
<<
"Record time: "
<<
actualRecordTime
<<
endl
;
...
...
StreamRecorder.h
View file @
b8dc7be7
...
@@ -35,59 +35,60 @@ class StreamRecorder
...
@@ -35,59 +35,60 @@ class StreamRecorder
{
{
private
:
private
:
unsigned
char
*
audioBuffer
;
unsigned
char
*
audioBuffer
;
unsigned
char
*
audioBufferPosition
;
unsigned
char
*
audioBufferPosition
;
char
errorMessage
[
ERROR_MSG_SIZE
];
char
errorMessage
[
ERROR_MSG_SIZE
];
char
pluginUri
[
DST_URI_SIZE
];
char
pluginUri
[
DST_URI_SIZE
];
unsigned
int
nBytes
;
unsigned
int
bufferSize
;
int
recordTime
;
unsigned
int
nBytes
;
int
audioFileDuration
;
unsigned
int
bufferSize
;
/** Audio filename */
int
recordTime
;
long
int
timestamp
=
0
;
int
audioFileDuration
;
bool
isConnectionLost
;
/** Audio filename */
long
int
timestamp
=
0
;
//char* sourceName;
long
int
oldTmpTimestamp
=
0
;
//GstElement* audioResample;
long
int
newTmpTimestamp
=
0
;
//GstElement* tempBin;
//GstElement* audioSink;
bool
isConnectionLost
;
GstElement
*
streamSrc
;
//char* sourceName;
GstElement
*
audioConvert
;
//GstElement* audioResample;
GstElement
*
filterCaps
;
//GstElement* tempBin;
GstElement
*
queue0
;
//GstElement* audioSink;
GstElement
*
queue1
;
GstElement
*
streamSrc
;
GstElement
*
filter
;
GstElement
*
audioConvert
;
GstElement
*
fakeSink
;
GstElement
*
filterCaps
;
GstElement
*
mainPipeline
;
GstElement
*
queue0
;
GstElement
*
queue1
;
int
createMainPipeline
();
GstElement
*
filter
;
int
connect
();
GstElement
*
fakeSink
;
int
disconnect
();
GstElement
*
mainPipeline
;
/** add data to buffer */
int
createMainPipeline
();
int
addToBuffer
(
unsigned
char
*
data
,
int
length
);
int
connect
();
int
compressBuffer
();
int
disconnect
();
/** plugin's callbacks */
/** add data to buffer */
static
void
srcNewPad_callback
(
GstElement
*
element
,
GstPad
*
pad
,
void
*
data
);
int
addToBuffer
(
unsigned
char
*
data
,
int
length
);
static
int
bus_callback
(
GstBus
*
bus
,
GstMessage
*
message
,
void
*
data
);
int
compressBuffer
();
static
int
filter_handoff_callback
(
GstElement
*
filter
,
GstBuffer
*
buffer
,
void
*
user_data
);
/** plugin's callbacks */
/** Save audio*/
static
void
srcNewPad_callback
(
GstElement
*
element
,
GstPad
*
pad
,
void
*
data
);
static
void
saveBuffer
(
void
*
user_data
);
static
int
bus_callback
(
GstBus
*
bus
,
GstMessage
*
message
,
void
*
data
);
static
int
filter_handoff_callback
(
GstElement
*
filter
,
GstBuffer
*
buffer
,
void
*
user_data
);
/** Restart the pipeline */
static
gboolean
reconnectURIStream
(
void
*
data
);
/** Save audio*/
static
void
saveBuffer
(
void
*
user_data
);
/** Restart the pipeline */
static
gboolean
reconnectURIStream
(
void
*
data
);
public
:
public
:
StreamRecorder
(
const
char
*
source
,
int
time
);
StreamRecorder
(
const
char
*
source
,
int
time
);
};
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment