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
e5502abe
Commit
e5502abe
authored
Oct 18, 2017
by
d.basulto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time verification and pointer update are now in handoff
parent
25fb8daf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
23 deletions
+22
-23
StreamRecorder.cpp
StreamRecorder.cpp
+21
-17
StreamRecorder.h
StreamRecorder.h
+1
-6
No files found.
StreamRecorder.cpp
View file @
e5502abe
...
@@ -39,20 +39,19 @@ StreamRecorder::StreamRecorder(const char* source, int time)
...
@@ -39,20 +39,19 @@ StreamRecorder::StreamRecorder(const char* source, int time)
recordTime
=
nFrames
*
READSIZE
/
STREAMRECORDER_SAMPLERATE
;
recordTime
=
nFrames
*
READSIZE
/
STREAMRECORDER_SAMPLERATE
;
cout
<<
"record time: "
<<
recordTime
<<
endl
;
cout
<<
"record time: "
<<
recordTime
<<
endl
;
// Required record time
audioFileDuration
=
time
;
audioFileDuration
=
time
;
strcpy
(
pluginUri
,
source
);
strcpy
(
pluginUri
,
source
);
bufferSize
=
nFrames
*
READSIZE
*
STREAMRECORDER_BYTESPERSAMPLE
;
bufferSize
=
nFrames
*
READSIZE
*
STREAMRECORDER_BYTESPERSAMPLE
;
audioBuffer
=
new
unsigned
char
[
bufferSize
];
audioBuffer
=
new
unsigned
char
[
bufferSize
];
bytesPerSecond
=
bufferSize
/
audioFileDuration
;
// New buffer
// New buffer
memset
(
audioBuffer
,
0
,
bufferSize
);
memset
(
audioBuffer
,
0
,
bufferSize
);
audioBufferPosition
=
audioBuffer
;
audioBufferPosition
=
audioBuffer
;
nBytes
=
0
;
nBytes
=
0
;
createMainPipeline
();
createMainPipeline
();
connect
();
connect
();
}
}
...
@@ -195,7 +194,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
...
@@ -195,7 +194,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
switch
(
error
->
code
)
switch
(
error
->
code
)
{
{
case
STREAM_ENOUGH_DATA_ERROR
:
case
STREAM_ENOUGH_DATA_ERROR
:
/** Last message in errors se
c
uence*/
/** Last message in errors se
q
uence*/
((
StreamRecorder
*
)
user_data
)
->
isDisconnected
=
true
;
((
StreamRecorder
*
)
user_data
)
->
isDisconnected
=
true
;
break
;
break
;
...
@@ -233,6 +232,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
...
@@ -233,6 +232,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
void
StreamRecorder
::
saveBuffer
()
void
StreamRecorder
::
saveBuffer
()
{
{
compressBuffer
();
compressBuffer
();
// Restart buffer configuration
audioBufferPosition
=
audioBuffer
;
audioBufferPosition
=
audioBuffer
;
memset
(
audioBuffer
,
0
,
bufferSize
);
memset
(
audioBuffer
,
0
,
bufferSize
);
nBytes
=
0
;
nBytes
=
0
;
...
@@ -248,7 +248,7 @@ void StreamRecorder::saveBuffer()
...
@@ -248,7 +248,7 @@ void StreamRecorder::saveBuffer()
void
StreamRecorder
::
srcNewPad_callback
(
GstElement
*
element
,
GstPad
*
pad
,
void
*
data
)
void
StreamRecorder
::
srcNewPad_callback
(
GstElement
*
element
,
GstPad
*
pad
,
void
*
data
)
{
{
cout
<<
gst_element_get_name
(
element
)
<<
" adding pad..
"
<<
gst_pad_get_name
(
pad
)
<<
endl
;
cout
<<
gst_element_get_name
(
element
)
<<
" adding pad..
."
<<
endl
;
cout
<<
"Pad Name: "
<<
gst_pad_get_name
(
pad
)
<<
endl
;
cout
<<
"Pad Name: "
<<
gst_pad_get_name
(
pad
)
<<
endl
;
GstPad
*
sinkpad
;
GstPad
*
sinkpad
;
...
@@ -298,7 +298,9 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
...
@@ -298,7 +298,9 @@ 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));
if
(((
StreamRecorder
*
)
user_data
)
->
isDisconnected
){
// If we come from a disconnection
if
(((
StreamRecorder
*
)
user_data
)
->
isDisconnected
)
{
currentTime
=
time
(
NULL
);
currentTime
=
time
(
NULL
);
actualRecordTime
=
currentTime
-
((
StreamRecorder
*
)
user_data
)
->
timestamp
;
actualRecordTime
=
currentTime
-
((
StreamRecorder
*
)
user_data
)
->
timestamp
;
...
@@ -313,14 +315,15 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
...
@@ -313,14 +315,15 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
}
}
else
else
{
{
long
int
bytesToAdd
=
actualRecordTime
*
((
StreamRecorder
*
)
user_data
)
->
bytesPerSecond
;
long
int
bytesToAdd
=
actualRecordTime
*
STREAMRECORDER_SAMPLERATE
*
STREAMRECORDER_BYTESPERSAMPLE
*
NCHANNELS
;
unsigned
char
*
newPosition
;
printf
(
"Bytes to add: %ld
\n
"
,
bytesToAdd
);
printf
(
"Bytes to add %d
\n
"
,
bytesToAdd
);
// Adjust the bytes to add value to a buffer size divider
bytesToAdd
=
ceil
(
bytesToAdd
/
(
STREAMRECORDER_BYTESPERSAMPLE
*
READSIZE
))
*
STREAMRECORDER_BYTESPERSAMPLE
*
READSIZE
;
newPosition
=
((
StreamRecorder
*
)
user_data
)
->
audioBuffer
;
printf
(
"Adjusted to: %ld
\n
"
,
bytesToAdd
);
newPosition
+=
bytesToAdd
;
((
StreamRecorder
*
)
user_data
)
->
audioBufferPosition
=
newPosition
;
((
StreamRecorder
*
)
user_data
)
->
audioBufferPosition
=
((
StreamRecorder
*
)
user_data
)
->
audioBuffer
;
((
StreamRecorder
*
)
user_data
)
->
audioBufferPosition
+=
bytesToAdd
;
((
StreamRecorder
*
)
user_data
)
->
nBytes
=
bytesToAdd
;
((
StreamRecorder
*
)
user_data
)
->
nBytes
=
bytesToAdd
;
cout
<<
"The pointer has been updated..."
<<
endl
;
cout
<<
"The pointer has been updated..."
<<
endl
;
...
@@ -342,9 +345,11 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
...
@@ -342,9 +345,11 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
* @param length Data length
* @param length Data length
* @return Bytes writen
* @return Bytes writen
*/
*/
int
StreamRecorder
::
addToBuffer
(
unsigned
char
*
data
,
int
length
)
{
int
StreamRecorder
::
addToBuffer
(
unsigned
char
*
data
,
int
length
)
{
int
bytesRead
=
length
;
// READSIZE*STREAMRECORDER_BYTESPERSAMPLE;
int
bytesRead
=
length
;
// READSIZE*STREAMRECORDER_BYTESPERSAMPLE;
bool
aux
=
false
;
bool
isNewAudioFile
;
bool
isNewAudioFile
;
/** Useful for obtain the filename*/
/** Useful for obtain the filename*/
...
@@ -363,10 +368,9 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
...
@@ -363,10 +368,9 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
{
{
cout
<<
"New audio stream"
<<
endl
;
cout
<<
"New audio stream"
<<
endl
;
/** filename */
/** filename
and initial record time
*/
timestamp
=
time
(
NULL
);
timestamp
=
time
(
NULL
);
cout
<<
"Audio filename (timestamp): "
<<
timestamp
<<
endl
;
cout
<<
"Audio filename (timestamp): "
<<
timestamp
<<
endl
;
printf
(
"Audio buffer %d
\n
"
,
audioBuffer
);
}
}
else
else
{
{
...
...
StreamRecorder.h
View file @
e5502abe
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#define STREAMRECORDER_SAMPLERATE 44100
#define STREAMRECORDER_SAMPLERATE 44100
#define READSIZE 1152 //For MPEG1, frame_size = 1152 samples/frame
#define READSIZE 1152 //For MPEG1, frame_size = 1152 samples/frame
#define STREAMRECORDER_BYTESPERSAMPLE 2
#define STREAMRECORDER_BYTESPERSAMPLE 2
#define NCHANNELS 1
#define ERROR_MSG_SIZE 50
#define ERROR_MSG_SIZE 50
#define DST_URI_SIZE 80
#define DST_URI_SIZE 80
...
@@ -52,16 +53,10 @@ class StreamRecorder
...
@@ -52,16 +53,10 @@ class StreamRecorder
/** Audio filename */
/** Audio filename */
long
int
timestamp
=
0
;
long
int
timestamp
=
0
;
long
int
oldTmpTimestamp
=
0
;
long
int
newTmpTimestamp
=
0
;
long
int
bytesPerSecond
=
0
;
bool
isDisconnected
=
false
;
bool
isDisconnected
=
false
;
bool
isValidDisconnectedEvent
=
false
;
bool
isValidDisconnectedEvent
=
false
;
//char* sourceName;
//char* sourceName;
//GstElement* audioResample;
//GstElement* audioResample;
//GstElement* tempBin;
//GstElement* tempBin;
...
...
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