Add preliminary streaming code for testing

- Add some temporary streaming code using FFmpeg.  FFmpeg itself is not
   very ideal for streaming; lack of direct control of the sockets and
   no framedrop handling means that FFmpeg is definitely not something
   you want to use without wrapper code.  I'd prefer writing my own
   network framework in this particular case just because you give away
   so much control of the network interface.  Wasted an entire day
   trying to go through FFmpeg issues.

   There's just no way FFmpeg should be used for real streaming (at
   least without being patched or submitting some sort of patch, but I'm
   sort of feeling "meh" on that idea)

   I had to end up writing multiple threads just to handle both
   connecting and writing, because av_interleaved_write_frame blocks
   every call, stalling the main encoder thread, and thus also stalling
   draw signals.

 - Add some temporary user interface for streaming settings.  This is
   just temporary for the time being.  It's in the outputs section of
   the basic-mode settings

 - Make it so that dynamic arrays do not free all their data when the
   size just happens to be reduced to 0.  This prevents constant
   reallocation when an array keeps going from 1 item to 0 items.  Also,
   it was bad to become dependent upon that functionality.  You must now
   always explicitly call "free" on it to ensure the data is free, and
   that's how it should be.  Implicit functionality can lead to
   confusion and maintainability issues.
This commit is contained in:
jp9000
2014-03-10 13:10:35 -07:00
parent b2202c4843
commit 02a07ea0a0
13 changed files with 482 additions and 99 deletions

View File

@@ -262,6 +262,11 @@ struct obs_output {
void *data;
struct obs_output_info info;
obs_data_t settings;
signal_handler_t signals;
proc_handler_t procs;
bool valid;
};

View File

@@ -39,38 +39,57 @@ obs_output_t obs_output_create(const char *id, const char *name,
return NULL;
}
output = bmalloc(sizeof(struct obs_output));
output = bzalloc(sizeof(struct obs_output));
output->signals = signal_handler_create();
if (!output->signals)
goto fail;
output->procs = proc_handler_create();
if (!output->procs)
goto fail;
output->info = *info;
output->settings = obs_data_newref(settings);
output->data = info->create(output->settings, output);
if (!output->data) {
obs_data_release(output->settings);
bfree(output);
return NULL;
}
if (!output->data)
goto fail;
output->name = bstrdup(name);
pthread_mutex_lock(&obs->data.outputs_mutex);
da_push_back(obs->data.outputs, &output);
pthread_mutex_unlock(&obs->data.outputs_mutex);
output->valid = true;
return output;
fail:
obs_output_destroy(output);
return NULL;
}
void obs_output_destroy(obs_output_t output)
{
if (output) {
if (output->info.active) {
if (output->info.active(output->data))
output->info.stop(output->data);
if (output->valid) {
if (output->info.active) {
if (output->info.active(output->data))
output->info.stop(output->data);
}
pthread_mutex_lock(&obs->data.outputs_mutex);
da_erase_item(obs->data.outputs, &output);
pthread_mutex_unlock(&obs->data.outputs_mutex);
}
pthread_mutex_lock(&obs->data.outputs_mutex);
da_erase_item(obs->data.outputs, &output);
pthread_mutex_unlock(&obs->data.outputs_mutex);
if (output->data)
output->info.destroy(output->data);
signal_handler_destroy(output->signals);
proc_handler_destroy(output->procs);
output->info.destroy(output->data);
obs_data_release(output->settings);
bfree(output->name);
bfree(output);
@@ -143,3 +162,13 @@ void obs_output_pause(obs_output_t output)
if (output && output->info.pause)
output->info.pause(output->data);
}
signal_handler_t obs_output_signalhandler(obs_output_t output)
{
return output->signals;
}
proc_handler_t obs_output_prochandler(obs_output_t output)
{
return output->procs;
}

View File

@@ -487,6 +487,11 @@ void obs_shutdown(void)
free_module(obs->modules.array+i);
da_free(obs->modules);
da_free(obs->data.sources);
da_free(obs->data.outputs);
da_free(obs->data.encoders);
da_free(obs->data.displays);
bfree(obs);
obs = NULL;
}

View File

@@ -677,6 +677,12 @@ EXPORT void obs_output_pause(obs_output_t output);
/* Gets the current output settings string */
EXPORT obs_data_t obs_output_get_settings(obs_output_t output);
/** Returns the signal handler for an output */
EXPORT signal_handler_t obs_output_signalhandler(obs_output_t output);
/** Returns the procedure handler for an output */
EXPORT proc_handler_t obs_output_prochandler(obs_output_t output);
/* ------------------------------------------------------------------------- */
/* Encoders */

View File

@@ -125,7 +125,7 @@ static inline void darray_resize(const size_t element_size,
if (size == dst->num) {
return;
} else if (size == 0) {
darray_free(dst);
dst->num = 0;
return;
}
@@ -305,7 +305,7 @@ static inline void darray_erase(const size_t element_size, struct darray *dst,
return;
if (!--dst->num) {
darray_free(dst);
dst->num = 0;
return;
}
@@ -336,7 +336,7 @@ static inline void darray_erase_range(const size_t element_size,
darray_erase(element_size, dst, start);
return;
} else if (count == dst->num) {
darray_free(dst);
dst->num = 0;
return;
}