server version files

parent c7b72e66
......@@ -29,23 +29,27 @@ using namespace std;
/**
* Constructor
* @param source streaming url
* @param streamURL streaming url
* @param time split recording in segments of time seconds.
*/
StreamRecorder::StreamRecorder(const char* source, int time)
{
int nFrames = ceil(time*STREAMRECORDER_SAMPLERATE/READSIZE);
recordTime = nFrames*READSIZE/STREAMRECORDER_SAMPLERATE;
StreamRecorder::StreamRecorder(const char* streamURL, int time, int samplesPerPackage)
{
int nFrames;
//readsize
samplesNumber = samplesPerPackage;
nFrames = ceil(time*STREAMRECORDER_SAMPLERATE/samplesNumber);
cout << nFrames << endl;
recordTime = nFrames*samplesNumber/STREAMRECORDER_SAMPLERATE;
cout << "record time: " << recordTime << endl;
// Required record time
audioFileDuration = time;
fileDuration = time;
strcpy(pluginUri,source);
strcpy(pluginUri,streamURL);
bufferSize=nFrames*READSIZE*STREAMRECORDER_BYTESPERSAMPLE;
bufferSize=nFrames*samplesNumber*STREAMRECORDER_BYTESPERSAMPLE;
audioBuffer = new unsigned char[bufferSize];
// New buffer
......@@ -114,13 +118,13 @@ int StreamRecorder::createMainPipeline()
filterCaps = gst_element_factory_make("capsfilter", "filter_cap");
GstCaps *fc = gst_caps_new_full(gst_structure_new ("audio/x-raw",
"channels", G_TYPE_INT, 1,
"rate", G_TYPE_INT, STREAMRECORDER_SAMPLERATE,
"format", G_TYPE_STRING, "S16LE",
"signed", G_TYPE_BOOLEAN, 1, //MUST BE SIGNED
"endianness", G_TYPE_INT, 1234,
NULL),
NULL);
"channels", G_TYPE_INT, 1,
"rate", G_TYPE_INT, STREAMRECORDER_SAMPLERATE,
"format", G_TYPE_STRING, "S16LE",
"signed", G_TYPE_BOOLEAN, 1, //MUST BE SIGNED
"endianness", G_TYPE_INT, 1234,
NULL),
NULL);
g_object_set(G_OBJECT (filterCaps), "caps", fc, NULL);
......@@ -181,11 +185,8 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
{
case GST_MESSAGE_EOS:
cout << "** End of stream **" << endl << endl;
((StreamRecorder*)user_data)->isDisconnected = true;
break;
case GST_MESSAGE_ERROR:
GError *error;
......@@ -237,7 +238,7 @@ void StreamRecorder::saveBuffer()
{
compressBuffer();
// Restart buffer configuration
audioBufferPosition=audioBuffer;
audioBufferPosition = audioBuffer;
memset (audioBuffer, 0, bufferSize);
nBytes=0;
}
......@@ -311,7 +312,7 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
currentTime = time(NULL);
actualRecordTime = currentTime - ((StreamRecorder*)user_data)->timestamp;
if(actualRecordTime >= ((StreamRecorder*)user_data)->audioFileDuration)
if(actualRecordTime >= ((StreamRecorder*)user_data)->fileDuration)
{
/** Complete the buffer with missing bytes*/
((StreamRecorder*)user_data)->nBytes = ((StreamRecorder*)user_data)->bufferSize;
......@@ -325,7 +326,7 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
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;
bytesToAdd = ceil(bytesToAdd/(STREAMRECORDER_BYTESPERSAMPLE*((StreamRecorder*)user_data)->samplesNumber))*STREAMRECORDER_BYTESPERSAMPLE*((StreamRecorder*)user_data)->samplesNumber;
printf("Adjusted to: %ld\n", bytesToAdd);
((StreamRecorder*)user_data)->audioBufferPosition = ((StreamRecorder*)user_data)->audioBuffer;
......@@ -424,7 +425,7 @@ int StreamRecorder::compressBuffer()
// Restart timestamp;
timestamp = 0;
int readsize = READSIZE;
int readsize = samplesNumber;
FLAC__bool ok = true;
FLAC__StreamEncoder *encoder = 0;
FLAC__StreamMetadata *metadata[2];
......
......@@ -21,7 +21,7 @@
//------------------------------------------------------------------------------
#define STREAMRECORDER_SAMPLERATE 44100
#define READSIZE 1152 //For MPEG1, frame_size = 1152 samples/frame
// #define READSIZE 2048 //For MPEG1, frame_size = 1152 samples/frame
#define STREAMRECORDER_BYTESPERSAMPLE 2
#define NCHANNELS 1
......@@ -45,9 +45,10 @@ class StreamRecorder
unsigned int nBytes;
unsigned int bufferSize;
unsigned int samplesNumber;
int recordTime;
int audioFileDuration;
int fileDuration;
/** Audio filename */
long int timestamp = 0;
......@@ -88,7 +89,7 @@ class StreamRecorder
public:
StreamRecorder(const char* source, int time);
StreamRecorder(const char* source, int time, int readsize);
};
//------------------------------------------------------------------------------
#endif
GNU nano 2.8.7 File: crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
......@@ -12,11 +14,8 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#16 14 24 11 * root /home/geoint/GStreamer_audioRecorder/startRecord.sh 60
#17 14 24 11 * root /home/geoint/GStreamer_audioRecorder/killRecorders.sh
17 9 26 10 4 root /home/geoint/GStreamer_audioRecorder/startRecord.sh 60
#21 16 24 10 * root /home/geoint/GStreamer_audioRecorder/killRecorders.sh
0 7 * * * root /home/geoint/GStreamer_audioRecorder/startRecord.sh 60
0 0 * * * root /home/geoint/GStreamer_audioRecorder/killRecorders.sh
@reboot root /home/geoint/GStreamer_audioRecorder/restartRecording.sh
#
......@@ -5,4 +5,6 @@ for pid in `pgrep -f streamRecorder && pgrep -f record.sh`
do
echo "killing " $pid
kill $pid
done
\ No newline at end of file
done
#sudo reboot
////////////////////////////////////////////////////////////////////////////////
//
//
//
////////////////////////////////////////////////////////////////////////////////
#include <cstdlib>
#include <iostream>
#include "StreamRecorder.h"
using namespace std;
//------------------------------------------------------------------------------
int main(int argc, char *argv[]) {
if(argc < 3) {
if(argc < 4) {
cerr << "too few arguments" << endl;
cerr << "Use example: ./StreamRecorder <url> <audio duration> <samples number>" << endl;
return EXIT_FAILURE;
}
gst_init (&argc, &argv);
StreamRecorder myRecorder = StreamRecorder(argv[1],atoi(argv[2]));
StreamRecorder myRecorder = StreamRecorder(argv[1],atoi(argv[2]), atoi(argv[3]));
GMainLoop* main_loop = NULL;
main_loop = g_main_loop_new (NULL, FALSE);
......
......@@ -3,6 +3,7 @@
#$1 stream name
#$2 stream uri
#$3 record time
#$4 samples number
#===============================================================================
cd /home/geoint/virtualHDD/m3/recordings
......@@ -29,6 +30,6 @@ if [ ! -d "$day" ]; then
fi
cd $day
/home/geoint/GStreamer_audioRecorder/streamRecorder $2 $3
/home/geoint/GStreamer_audioRecorder/streamRecorder $2 $3 $4
......@@ -3,7 +3,6 @@
H=$(date +%H%M)
START=0700
END=2359
touch hola.txt
if (( $START <= $H && $H <= $END )); then
/home/geoint/GStreamer_audioRecorder/startRecord.sh 60
/home/geoint/GStreamer_audioRecorder/startRecord.sh 60
fi
......@@ -3,10 +3,10 @@
#===============================================================================
if [ $# -ne 1 ]; then
echo 'Example: ./startRecord.sh 60'
echo 'Example: ./startRecord.sh 60'
else
# crontab -l > $HOME/GStreamer_audioRecorder/crontab.txt
sudo mount -a
cd /home/geoint/GStreamer_audioRecorder/
/usr/bin/python streamsManager.py $1
# crontab -l > $HOME/GStreamer_audioRecorder/crontab.txt
sudo mount -a
cd /home/geoint/GStreamer_audioRecorder/
/usr/bin/python streamsManager.py $1
fi
[
{
"pubDirName" : "RadioFormula1041", "url" : "http://streamingmovil.radioformula.com:8000/m1041", "website" : "http://www.radioformula.com.mx/", "publisher" : "Radio Formula"
"pubDirName" : "RadioFormula1041",
"streamURL" : "http://streamingmovil.radioformula.com:8000/m1041",
"website" : "http://www.radioformula.com.mx/",
"publisher" : "Radio Formula",
"samplesNumber": "1152"
},
{
"pubDirName" : "RadioFormula1033", "url" : "http://streamingmovil.radioformula.com:8000/m1033", "website" : "http://www.radioformula.com.mx/", "publisher" : "Radio Formula"
"pubDirName" : "RadioFormula1033",
"streamURL" : "http://streamingmovil.radioformula.com:8000/m1033",
"website" : "http://www.radioformula.com.mx/",
"publisher" : "Radio Formula",
"samplesNumber": "1152"
},
{
"pubDirName" : "NoticiasMVS1025", "url" : "http://20323.live.streamtheworld.com:3690/XHMVSFM_SC", "website" : "http://www.mvsnoticias.com", "publisher" : "MVS Noticias"
"pubDirName" : "NoticiasMVS1025",
"streamURL" : "http://20323.live.streamtheworld.com:3690/XHMVSFM_SC",
"website" : "http://www.mvsnoticias.com",
"publisher" : "MVS Noticias",
"samplesNumber": "1152"
},
{
"pubDirName" : "RadioIBERO9091", "url" : "http://noasrv.caster.fm:10182/stream", "website" : "http://ibero909.fm/", "publisher" : "Radio Ibero"
"pubDirName" : "RadioIBERO9091",
"streamURL" : "http://noasrv.caster.fm:10182/stream",
"website" : "http://ibero909.fm/",
"publisher" : "Radio Ibero",
"samplesNumber": "1152"
},
{
"pubDirName" : "RadioIPN957", "url" : "http://148.204.216.116:8080/radioipn.mp3", "website" : "http://www.radio.ipn.mx/", "publisher" : "Radio IPN"
"pubDirName" : "RadioIPN957",
"streamURL" : "http://148.204.216.116:8080/radioipn.mp3",
"website" : "http://www.radio.ipn.mx/",
"publisher" : "Radio IPN",
"samplesNumber": "1152"
},
{
"pubDirName" : "RadioYucatan929",
"streamURL" : "http://imer-edge1.cdnstream.com/1508_64?cb=596052.mp3",
"website" : "http://www.imer.mx/yucatanfm/",
"publisher" : "Radio Yucatan",
"samplesNumber": "2048"
},
{
"pubDirName" : "RadioUAM941",
"streamURL" : "http://streaming.shoutcast.com/uamradio",
"website" : "http://uamradio.uam.mx/",
"publisher" : "Radio UAM",
"samplesNumber": "1024"
},
{
"pubDirName": "StereoCien1001",
"streamURL": "http://15373.live.streamtheworld.com/XHMMFMAAC_SC",
"website" : "http://www.stereocien.com.mx/",
"publisher" : "Radio Cien",
"samplesNumber": "2048"
},
{
"pubDirName": "RadioFormulaYuc945",
"streamURL": "http://148.244.103.252:8000/merida1",
"website" : "http://radioformulayucatan.com/",
"publisher" : "Radio Formula Yucatan",
"samplesNumber": "1152"
},
{
"pubDirName": "RadioFormulaYuc1051",
"streamURL": "http://148.244.103.252:8000/merida2",
"website" : "http://radioformulayucatan.com/",
"publisher" : "Radio Formula Yucatan",
"samplesNumber": "1152"
},
{
"pubDirName": "ExaCDMX1049",
"streamURL": "http://19813.live.streamtheworld.com/XHEXA_SC",
"website": "http://www.exafm.com/#!/mexico/home",
"publisher": "Exa",
"samplesNumber": "2304"
},
{
"pubDirName": "ExaYUC993",
"streamURL": "http://17963.live.streamtheworld.com/XHMRA_SC",
"website": "http://www.exafm.com/#!/mexico/home",
"publisher": "Exa",
"samplesNumber": "2304"
}
]
\ No newline at end of file
No preview for this file type
......@@ -3,15 +3,15 @@ import os
from json import load as jsonDec
# File config
executeAppCommand = './record.sh'
appName = 'record'
executeBashCommand = './record.sh'
bashFilename = 'record'
# Streams owners file
streamPublishersFile = 'streamPublishers.json'
# Child
def startStream(publisher_name,publisher_url, record_time):
os.execl(executeAppCommand, appName, publisher_name, publisher_url, record_time)
def startStream(publisher_name, stream_url, record_time, samplesNumber):
os.execl(executeBashCommand, bashFilename, publisher_name, stream_url, record_time, samplesNumber)
os._exit(0)
# Parent
......@@ -23,7 +23,12 @@ def streamsInitializer(record_time):
for i in range(len(publishers_data)):
new_pid = os.fork()
if(new_pid == 0):
startStream(publishers_data[i]["pubDirName"], publishers_data[i]["url"], record_time)
startStream(
publishers_data[i]["pubDirName"],
publishers_data[i]["streamURL"],
record_time,
publishers_data[i]["samplesNumber"]
)
else:
pids = (os.getpid(), new_pid)
print("parent: %d, child: %d\n" % pids)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment