Implement output, improve video/audio subsystems

- Fill in the rest of the FFmpeg test output code for testing so it
   actually properly outputs data.

 - Improve the main video subsystem to be a bit more optimal and
   automatically output I420 or NV12 if needed.

 - Fix audio subsystem insertation and byte calculation.  Now it will
   seamlessly insert new audio data in to the audio stream based upon
   its timestamp value.  (Be extremely cautious when using floating
   point calculations for important things like this, and always round
   your values and check your values)

 - Use 32 byte alignment in case of future optimizations and export a
   function to get the current alignment.

 - Make os_sleepto_ns return true if slept, false if the time has
   already been passed before the call.

 - Fix sinewave output so that it actually properly calculates a middle
   C sinewave.

 - Change the use of row_bytes to linesize (also makes it a bit more
   consistent with FFmpeg's naming as well)
This commit is contained in:
jp9000
2014-02-09 05:51:06 -07:00
parent 4461281a3b
commit 6c92cf5841
30 changed files with 500 additions and 312 deletions

View File

@@ -1,28 +1,31 @@
#include <math.h>
#include "test-sinewave.h"
/* middle C */
const double rate = 261.63/48000.0;
#define M_PI 3.1415926535897932384626433832795
#define M_PI_X2 M_PI*2
static void *sinewave_thread(void *pdata)
{
struct sinewave_data *swd = pdata;
uint64_t last_time = os_gettime_ns();
uint64_t ts = 0;
double sin_val = 0.0;
double cos_val = 0.0;
uint8_t bytes[480];
while (event_try(&swd->event) == EAGAIN) {
os_sleepto_ns(last_time += 10000000);
if (!os_sleepto_ns(last_time += 10000000))
last_time = os_gettime_ns();
for (size_t i = 0; i < 480; i++) {
sin_val += rate * M_PI;
if (sin_val > M_PI)
sin_val -= M_PI;
cos_val += rate * M_PI_X2;
if (cos_val > M_PI_X2)
cos_val -= M_PI_X2;
double wave = sin(sin_val);
bytes[i] = (uint8_t)(wave * 255.0);
double wave = cos(cos_val);
bytes[i] = (uint8_t)((wave+1.0)*0.5 * 255.0);
}
struct source_audio data;