Commit 820dc52c authored by d.basulto's avatar d.basulto

restart the connection and save partial buffer

parent e0753bee
This diff is collapsed.
......@@ -14,6 +14,7 @@
// your public header include
//------------------------------------------------------------------------------
#include <gst/gst.h>
#include <jmorecfg.h>
//------------------------------------------------------------------------------
#define STREAMRECORDER_SAMPLERATE 44100
#define READSIZE 1152 //For MPEG1, frame_size = 1152 samples/frame
......@@ -22,46 +23,51 @@
//------------------------------------------------------------------------------
class StreamRecorder
{
private:
unsigned int nBytes;
unsigned int bufferSize;
unsigned char* audioBuffer;
unsigned char* audioBufferPosition;
int recordTime;
char* sourceName;
GstElement* streamSrc;
GstElement* audioConvert;
GstElement* audioResample;
GstElement* filterCaps;
GstElement* queue0;
GstElement* queue1;
GstElement* filter;
// GstElement* compressor;
// GstElement* queue2;
// GstElement* muxer;
// GstElement* fileSink;
GstElement* fakeSink;
GstElement* audioSink;
GstElement* mainPipeline;
// GstElement* sinkPipeline;
private:
GstElement* tempBin;
int createMainPipeline();
// int createSinkPipeline();
int connect(const char *uri);
int disconnect();
static void srcNewPad_callback(GstElement *element, GstPad *pad, void *data);
static int bus_callback(GstBus *bus, GstMessage *message, void *data);
// static void block_async_cb (GstPad * pad, gboolean blocked, gpointer user_data);
static void buffer_callback(GstElement *fakesink, GstBuffer *buffer, GstPad *pad, gpointer user_data);
static int filter_handoff_callback(GstElement* filter, GstBuffer* buffer, void* user_data);
int addToBuffer(unsigned char* data, int length);
int compressBuffer();
int saveWav(unsigned char* data, int size) const;
void printCaps(GstPad *pad);
public:
StreamRecorder(const char* source, int time);
unsigned int nBytes;
unsigned int bufferSize;
unsigned char* audioBuffer;
unsigned char* audioBufferPosition;
int recordTime;
bool isConnectionLost;
char * pluginUri;
//char* sourceName;
GstElement* streamSrc;
GstElement* audioConvert;
//GstElement* audioResample;
GstElement* filterCaps;
GstElement* queue0;
GstElement* queue1;
GstElement* filter;
GstElement* fakeSink;
//GstElement* audioSink;
GstElement* mainPipeline;
//GstElement* tempBin;
int createMainPipeline();
int connect(const char *uri);
int disconnect();
// callbacks
static void srcNewPad_callback(GstElement *element, GstPad *pad, void *data);
static int bus_callback(GstBus *bus, GstMessage *message, void *data);
static int filter_handoff_callback(GstElement* filter, GstBuffer* buffer, void* user_data);
// add data to buffer
int addToBuffer(unsigned char* data, int length);
int compressBuffer();
// Save information when connection fails
static void savePartialBuffer(void *user_data);
// Restart the pipeline
static gboolean reconnectURIStream(void *data);
public:
StreamRecorder(const char* source, int time);
};
//------------------------------------------------------------------------------
#endif
No preview for this file type
......@@ -8,19 +8,20 @@
#include "StreamRecorder.h"
using namespace std;
//------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
if(argc < 2)
{
int main(int argc, char *argv[]) {
if(argc < 3) {
cerr << "too few arguments" << endl;
return EXIT_FAILURE;
}
gst_init (&argc, &argv);
StreamRecorder myRecorder = StreamRecorder(argv[1],atoi(argv[2]));
GMainLoop* main_loop = NULL;
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run(main_loop);
return 0;
return 0;
}
//------------------------------------------------------------------------------
No preview for this file type
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