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
6b4a2e43
Commit
6b4a2e43
authored
Aug 18, 2017
by
d.basulto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add format
parent
820dc52c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
172 additions
and
182 deletions
+172
-182
StreamRecorder.cpp
StreamRecorder.cpp
+172
-182
No files found.
StreamRecorder.cpp
View file @
6b4a2e43
...
@@ -139,7 +139,7 @@ int StreamRecorder::createMainPipeline() {
...
@@ -139,7 +139,7 @@ int StreamRecorder::createMainPipeline() {
gst_bin_add_many
(
GST_BIN
(
mainPipeline
),
streamSrc
,
audioConvert
,
filterCaps
,
queue0
,
filter
,
queue1
,
fakeSink
,
NULL
);
gst_bin_add_many
(
GST_BIN
(
mainPipeline
),
streamSrc
,
audioConvert
,
filterCaps
,
queue0
,
filter
,
queue1
,
fakeSink
,
NULL
);
if
(
!
gst_element_link_many
(
audioConvert
,
filterCaps
,
queue0
,
filter
,
queue1
,
fakeSink
,
NULL
)){
if
(
!
gst_element_link_many
(
audioConvert
,
filterCaps
,
queue0
,
filter
,
queue1
,
fakeSink
,
NULL
)){
//gst_bin_add_many (GST_BIN (mainPipeline), streamSrc, audioConvert, filterCaps, queue0, filter, queue1, audioSink, NULL);
//gst_bin_add_many (GST_BIN (mainPipeline), streamSrc, audioConvert, filterCaps, queue0, filter, queue1, audioSink, NULL);
//
if(!gst_element_link_many(audioConvert, filterCaps, queue0, filter, queue1, audioSink, NULL)){
//
if(!gst_element_link_many(audioConvert, filterCaps, queue0, filter, queue1, audioSink, NULL)){
cerr
<<
"mainPipeline: Failed to link elements in the pipeline"
<<
endl
;
cerr
<<
"mainPipeline: Failed to link elements in the pipeline"
<<
endl
;
exit
(
0
);
exit
(
0
);
...
@@ -171,7 +171,6 @@ gboolean StreamRecorder::reconnectURIStream(void *instance){
...
@@ -171,7 +171,6 @@ gboolean StreamRecorder::reconnectURIStream(void *instance){
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));
if
(
GST_MESSAGE_TYPE
(
message
)
==
GST_MESSAGE_EOS
){
if
(
GST_MESSAGE_TYPE
(
message
)
==
GST_MESSAGE_EOS
){
...
@@ -256,8 +255,8 @@ void StreamRecorder::srcNewPad_callback(GstElement *element, GstPad *pad, void *
...
@@ -256,8 +255,8 @@ void StreamRecorder::srcNewPad_callback(GstElement *element, GstPad *pad, void *
GstPad
*
sinkpad
;
GstPad
*
sinkpad
;
//
gst_pad_get_caps is for gst v0.1
//gst_pad_get_caps is for gst v0.1
//
GstCaps *new_pad_caps = gst_pad_get_caps (pad);
//
GstCaps *new_pad_caps = gst_pad_get_caps (pad);
GstCaps
*
new_pad_caps
=
gst_pad_query_caps
(
pad
,
NULL
);
GstCaps
*
new_pad_caps
=
gst_pad_query_caps
(
pad
,
NULL
);
GstStructure
*
new_pad_struct
=
gst_caps_get_structure
(
new_pad_caps
,
0
);
GstStructure
*
new_pad_struct
=
gst_caps_get_structure
(
new_pad_caps
,
0
);
...
@@ -270,7 +269,6 @@ void StreamRecorder::srcNewPad_callback(GstElement *element, GstPad *pad, void *
...
@@ -270,7 +269,6 @@ void StreamRecorder::srcNewPad_callback(GstElement *element, GstPad *pad, void *
sinkpad
=
gst_element_get_static_pad
(
nextElement
,
"sink"
);
sinkpad
=
gst_element_get_static_pad
(
nextElement
,
"sink"
);
if
(
GST_PAD_LINK_FAILED
(
gst_pad_link
(
pad
,
sinkpad
)))
{
if
(
GST_PAD_LINK_FAILED
(
gst_pad_link
(
pad
,
sinkpad
)))
{
cerr
<<
"Type is "
<<
new_pad_type
<<
" but link failed."
<<
endl
;
cerr
<<
"Type is "
<<
new_pad_type
<<
" but link failed."
<<
endl
;
exit
(
0
);
exit
(
0
);
}
}
...
@@ -286,8 +284,8 @@ void StreamRecorder::srcNewPad_callback(GstElement *element, GstPad *pad, void *
...
@@ -286,8 +284,8 @@ void StreamRecorder::srcNewPad_callback(GstElement *element, GstPad *pad, void *
* @return unimplemented
* @return unimplemented
*/
*/
int
StreamRecorder
::
compressBuffer
()
int
StreamRecorder
::
compressBuffer
()
{
{
long
int
currentTime
=
time
(
NULL
);
long
int
currentTime
=
time
(
NULL
);
stringstream
ss
;
stringstream
ss
;
string
fileNameStr
,
currentTimeStr
;
string
fileNameStr
,
currentTimeStr
;
...
@@ -305,11 +303,11 @@ int StreamRecorder::compressBuffer()
...
@@ -305,11 +303,11 @@ int StreamRecorder::compressBuffer()
FLAC__StreamEncoderInitStatus
init_status
;
FLAC__StreamEncoderInitStatus
init_status
;
/* allocate the encoder */
/* allocate the encoder */
if
((
encoder
=
FLAC__stream_encoder_new
())
==
NULL
)
if
((
encoder
=
FLAC__stream_encoder_new
())
==
NULL
)
{
{
fprintf
(
stderr
,
"ERROR: allocating encoder
\n
"
);
fprintf
(
stderr
,
"ERROR: allocating encoder
\n
"
);
return
1
;
return
1
;
}
}
ok
&=
FLAC__stream_encoder_set_verify
(
encoder
,
true
);
ok
&=
FLAC__stream_encoder_set_verify
(
encoder
,
true
);
ok
&=
FLAC__stream_encoder_set_compression_level
(
encoder
,
5
);
ok
&=
FLAC__stream_encoder_set_compression_level
(
encoder
,
5
);
ok
&=
FLAC__stream_encoder_set_channels
(
encoder
,
1
);
ok
&=
FLAC__stream_encoder_set_channels
(
encoder
,
1
);
...
@@ -318,8 +316,7 @@ int StreamRecorder::compressBuffer()
...
@@ -318,8 +316,7 @@ int StreamRecorder::compressBuffer()
ok
&=
FLAC__stream_encoder_set_total_samples_estimate
(
encoder
,
nBytes
/
STREAMRECORDER_BYTESPERSAMPLE
);
ok
&=
FLAC__stream_encoder_set_total_samples_estimate
(
encoder
,
nBytes
/
STREAMRECORDER_BYTESPERSAMPLE
);
/* now add some metadata; we'll add some tags and a padding block */
/* now add some metadata; we'll add some tags and a padding block */
if
(
ok
)
if
(
ok
)
{
{
if
(
if
(
(
metadata
[
0
]
=
FLAC__metadata_object_new
(
FLAC__METADATA_TYPE_VORBIS_COMMENT
))
==
NULL
||
(
metadata
[
0
]
=
FLAC__metadata_object_new
(
FLAC__METADATA_TYPE_VORBIS_COMMENT
))
==
NULL
||
(
metadata
[
1
]
=
FLAC__metadata_object_new
(
FLAC__METADATA_TYPE_PADDING
))
==
NULL
||
(
metadata
[
1
]
=
FLAC__metadata_object_new
(
FLAC__METADATA_TYPE_PADDING
))
==
NULL
||
...
@@ -357,19 +354,16 @@ int StreamRecorder::compressBuffer()
...
@@ -357,19 +354,16 @@ int StreamRecorder::compressBuffer()
int
*
pcm
=
new
int
[
readsize
*
channels
];
int
*
pcm
=
new
int
[
readsize
*
channels
];
/* read blocks of samples from WAVE file and feed to encoder */
/* read blocks of samples from WAVE file and feed to encoder */
if
(
ok
)
if
(
ok
)
{
{
int
left
=
nBytes
;
int
left
=
nBytes
;
while
(
left
&&
ok
)
while
(
left
&&
ok
)
{
{
int
need
=
(
left
>
readsize
?
readsize
:
left
);
int
need
=
(
left
>
readsize
?
readsize
:
left
);
memcpy
(
buffer
,
audioBufferTmp
,
need
);
//*sizeof(short));
memcpy
(
buffer
,
audioBufferTmp
,
need
);
//*sizeof(short));
audioBufferTmp
+=
need
;
//*sizeof(short);
audioBufferTmp
+=
need
;
//*sizeof(short);
/* convert the packed little-endian 16-bit PCM samples from WAVE into an interleaved FLAC__int32 buffer for libFLAC */
// /* convert the packed little-endian 16-bit PCM samples from WAVE into an interleaved FLAC__int32 buffer for libFLAC */
for
(
int
i
=
0
;
i
<
need
*
channels
;
i
++
)
for
(
int
i
=
0
;
i
<
need
*
channels
;
i
++
)
{
{
/* inefficient but simple and works on big- or little-endian machines */
/* inefficient but simple and works on big- or little-endian machines */
pcm
[
i
]
=
(
FLAC__int32
)(((
FLAC__int16
)(
FLAC__int8
)
buffer
[
2
*
i
+
1
]
<<
8
)
|
(
FLAC__int16
)
buffer
[
2
*
i
]);
pcm
[
i
]
=
(
FLAC__int32
)(((
FLAC__int16
)(
FLAC__int8
)
buffer
[
2
*
i
+
1
]
<<
8
)
|
(
FLAC__int16
)
buffer
[
2
*
i
]);
}
}
...
@@ -378,8 +372,7 @@ int StreamRecorder::compressBuffer()
...
@@ -378,8 +372,7 @@ int StreamRecorder::compressBuffer()
left
-=
need
;
left
-=
need
;
}
}
}
}
else
else
{
{
cout
<<
"-ERROR-"
<<
endl
;
cout
<<
"-ERROR-"
<<
endl
;
}
}
...
@@ -419,17 +412,14 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
...
@@ -419,17 +412,14 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
audioBufferPosition
+=
bytesRead
;
audioBufferPosition
+=
bytesRead
;
nBytes
+=
bytesRead
;
//READSIZE;
nBytes
+=
bytesRead
;
//READSIZE;
cout
<<
"Bytes readed "
<<
nBytes
<<
endl
;
cout
<<
"Bytes readed "
<<
nBytes
<<
endl
;
cout
<<
"Buffer size "
<<
bufferSize
<<
endl
;
cout
<<
"Buffer size "
<<
bufferSize
<<
endl
;
if
(
nBytes
>=
bufferSize
)
{
if
(
nBytes
>=
bufferSize
)
{
compressBuffer
();
compressBuffer
();
audioBufferPosition
=
audioBuffer
;
audioBufferPosition
=
audioBuffer
;
memset
(
audioBuffer
,
0
,
bufferSize
);
memset
(
audioBuffer
,
0
,
bufferSize
);
nBytes
=
0
;
nBytes
=
0
;
}
}
return
nBytes
;
return
nBytes
;
...
@@ -446,8 +436,8 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
...
@@ -446,8 +436,8 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
* @return unimplemented
* @return unimplemented
*/
*/
int
StreamRecorder
::
filter_handoff_callback
(
GstElement
*
filter
,
GstBuffer
*
buffer
,
void
*
user_data
)
int
StreamRecorder
::
filter_handoff_callback
(
GstElement
*
filter
,
GstBuffer
*
buffer
,
void
*
user_data
)
{
{
cout
<<
"LLEGO INFO"
<<
endl
;
cout
<<
"LLEGO INFO"
<<
endl
;
GstMapInfo
info
;
GstMapInfo
info
;
if
(
!
gst_buffer_map
(
buffer
,
&
info
,
GST_MAP_READ
))
{
if
(
!
gst_buffer_map
(
buffer
,
&
info
,
GST_MAP_READ
))
{
...
@@ -455,7 +445,7 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
...
@@ -455,7 +445,7 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
}
}
//GST_BUFFER_DATA is for gst v0.1
//GST_BUFFER_DATA is for gst v0.1
//
((StreamRecorder*)user_data)->addToBuffer((unsigned char*)GST_BUFFER_DATA (buffer));
//
((StreamRecorder*)user_data)->addToBuffer((unsigned char*)GST_BUFFER_DATA (buffer));
// user data is the class
// user data is the class
((
StreamRecorder
*
)
user_data
)
->
addToBuffer
((
unsigned
char
*
)
info
.
data
,
info
.
size
);
((
StreamRecorder
*
)
user_data
)
->
addToBuffer
((
unsigned
char
*
)
info
.
data
,
info
.
size
);
...
...
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