rendered paste body#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include "cooler-core.h"
#include "cooler-media.h"
#define SAMPLERATE 44100
#define CHANNELS 2
//TODO: most of this stuff shall be moved as into the nmsplugin.h public interface of cooler-media
typedef void * (*plugin_interface_get) (void);
#define NEUROS_OUTPUT_PLUGIN_INTERFACE "GetNmsOutputPlugin"
//END TODO
#define NEUROS_OUTPUT_PLUGIN_PATH NMS_PLUGIN_DIR "libdm320nmso.so"
static media_desc_t output_mode_info = {
.adesc = {
.audio_type = NMS_AC_PCM,
.num_channels = CHANNELS,
.sample_rate = SAMPLERATE,
.bitrate = CHANNELS * SAMPLERATE * 16,
},
.vdesc = {
.video_type = NMS_VC_NO_VIDEO,
.width = 0,
.height = 0,
.frame_rate = 0,
},
.sdesc = {
.subtitle_type = NMS_SC_NO_SUBTITLE,
},
};
static media_buf_t buf;
static media_output_plugin_t * LoadNMSPlugin()
{
void * plugin_lib;
void * interface_get;
media_output_plugin_t * plugin;
plugin_lib = dlopen(NEUROS_OUTPUT_PLUGIN_PATH, RTLD_LAZY);
if (plugin_lib == NULL) {
printf ("Neuros Output Plugin is not in %s\n", NEUROS_OUTPUT_PLUGIN_PATH);
return NULL;
}
interface_get = dlsym(plugin_lib, NEUROS_OUTPUT_PLUGIN_INTERFACE);
if (interface_get == NULL) {
printf ("Neuros Output Plugin has interface symbol %d\n", NEUROS_OUTPUT_PLUGIN_INTERFACE);
return NULL;
}
plugin = (media_output_plugin_t *) (((plugin_interface_get)interface_get)());
if (plugin == NULL) {
printf ("Neuros Output Plugin did not return plugin interface\n");
return NULL;
}
else {
printf("Neuros Ouput Plugin loaded: \"%s\" ver \"%s\" descr: \"%d\"\n",
plugin->brief, plugin->ver, plugin->description );
}
return plugin;
}
int main()
{
media_output_plugin_t * plugin;
int ret;
plugin = LoadNMSPlugin();
if (plugin == NULL) return -1;
//initialize plugin for doing only direct PCM-audio-only output
//second param (mode) doesn't really matter as it's NTSC/PAL for video
ret = plugin->init(&output_mode_info, 0);
if (ret == -1) {
printf("plugin->init failed\n");
return -1;
}
FILE* f = fopen("/media/USB/test.raw", "r");
int bytes = -1;
memset(&buf, sizeof(buf), 0);
if (f == NULL) {
printf("Test file failed to open\n");
goto fail;
}
printf("-------- calling plugin->start ----------\n");
ret = plugin->start();
if (ret == -1) {
printf("plugin->start failed\n");
return -1;
}
while ( 1 )
{
//Get output buffers (2st param = timeout, 3rd param = "we're preloading")
ret = plugin->getBuffer(&buf, 500, 1);
printf("Output buffer returned\tvbuf-size = %u \tabuf-size = %u \tsbuf-size = %u \n", buf.vbuf.size, buf.abuf.size, buf.sbuf.size);
if (ret == 1)
{
printf("No empty buffers available, let's wait a while\n");
sleep(1);
continue;
} else if (ret < 0) {
printf("plugin->getBuffer failed\n");
goto fail;
}
if (buf.abuf.size > 0) {
bytes = fread(buf.abuf.data, 1, buf.abuf.size, f);
buf.curbuf = &buf.abuf;
printf("Read %d bytes from file.\n", bytes);
if (bytes <= 0) break;
} else {
goto fail;
}
plugin->write(&buf);
}
fclose(f);
plugin->flush(1);
plugin->finish(1);
return 0;
fail:
plugin->flush(1);
plugin->finish(1);
return -1;
}