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)
recordTime
=
nFrames
*
READSIZE
/
STREAMRECORDER_SAMPLERATE
;
cout
<<
"record time: "
<<
recordTime
<<
endl
;
// Required record time
audioFileDuration
=
time
;
strcpy
(
pluginUri
,
source
);
bufferSize
=
nFrames
*
READSIZE
*
STREAMRECORDER_BYTESPERSAMPLE
;
audioBuffer
=
new
unsigned
char
[
bufferSize
];
bytesPerSecond
=
bufferSize
/
audioFileDuration
;
// New buffer
memset
(
audioBuffer
,
0
,
bufferSize
);
audioBufferPosition
=
audioBuffer
;
nBytes
=
0
;
createMainPipeline
();
connect
();
}
...
...
@@ -195,7 +194,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
switch
(
error
->
code
)
{
case
STREAM_ENOUGH_DATA_ERROR
:
/** Last message in errors se
c
uence*/
/** Last message in errors se
q
uence*/
((
StreamRecorder
*
)
user_data
)
->
isDisconnected
=
true
;
break
;
...
...
@@ -233,6 +232,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
void
StreamRecorder
::
saveBuffer
()
{
compressBuffer
();
// Restart buffer configuration
audioBufferPosition
=
audioBuffer
;
memset
(
audioBuffer
,
0
,
bufferSize
);
nBytes
=
0
;
...
...
@@ -248,7 +248,7 @@ void StreamRecorder::saveBuffer()
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
;
GstPad
*
sinkpad
;
...
...
@@ -298,7 +298,9 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
//GST_BUFFER_DATA is for gst v0.1
// ((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
);
actualRecordTime
=
currentTime
-
((
StreamRecorder
*
)
user_data
)
->
timestamp
;
...
...
@@ -313,14 +315,15 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
}
else
{
long
int
bytesToAdd
=
actualRecordTime
*
((
StreamRecorder
*
)
user_data
)
->
bytesPerSecond
;
unsigned
char
*
newPosition
;
printf
(
"Bytes to add %d
\n
"
,
bytesToAdd
);
newPosition
=
((
StreamRecorder
*
)
user_data
)
->
audioBuffer
;
newPosition
+=
bytesToAdd
;
((
StreamRecorder
*
)
user_data
)
->
audioBufferPosition
=
newPosition
;
long
int
bytesToAdd
=
actualRecordTime
*
STREAMRECORDER_SAMPLERATE
*
STREAMRECORDER_BYTESPERSAMPLE
*
NCHANNELS
;
printf
(
"Bytes to add: %ld
\n
"
,
bytesToAdd
);
// Adjust the bytes to add value to a buffer size divider
bytesToAdd
=
ceil
(
bytesToAdd
/
(
STREAMRECORDER_BYTESPERSAMPLE
*
READSIZE
))
*
STREAMRECORDER_BYTESPERSAMPLE
*
READSIZE
;
printf
(
"Adjusted to: %ld
\n
"
,
bytesToAdd
);
((
StreamRecorder
*
)
user_data
)
->
audioBufferPosition
=
((
StreamRecorder
*
)
user_data
)
->
audioBuffer
;
((
StreamRecorder
*
)
user_data
)
->
audioBufferPosition
+=
bytesToAdd
;
((
StreamRecorder
*
)
user_data
)
->
nBytes
=
bytesToAdd
;
cout
<<
"The pointer has been updated..."
<<
endl
;
...
...
@@ -342,9 +345,11 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
* @param length Data length
* @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;
bool
aux
=
false
;
bool
isNewAudioFile
;
/** Useful for obtain the filename*/
...
...
@@ -363,10 +368,9 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
{
cout
<<
"New audio stream"
<<
endl
;
/** filename */
/** filename
and initial record time
*/
timestamp
=
time
(
NULL
);
cout
<<
"Audio filename (timestamp): "
<<
timestamp
<<
endl
;
printf
(
"Audio buffer %d
\n
"
,
audioBuffer
);
}
else
{
...
...
StreamRecorder.h
View file @
e5502abe
...
...
@@ -23,6 +23,7 @@
#define STREAMRECORDER_SAMPLERATE 44100
#define READSIZE 1152 //For MPEG1, frame_size = 1152 samples/frame
#define STREAMRECORDER_BYTESPERSAMPLE 2
#define NCHANNELS 1
#define ERROR_MSG_SIZE 50
#define DST_URI_SIZE 80
...
...
@@ -52,16 +53,10 @@ class StreamRecorder
/** Audio filename */
long
int
timestamp
=
0
;
long
int
oldTmpTimestamp
=
0
;
long
int
newTmpTimestamp
=
0
;
long
int
bytesPerSecond
=
0
;
bool
isDisconnected
=
false
;
bool
isValidDisconnectedEvent
=
false
;
//char* sourceName;
//GstElement* audioResample;
//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