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