Skip to content

Commit 7d16c46

Browse files
committed
Video starting to appear
1 parent 2be4e61 commit 7d16c46

17 files changed

Lines changed: 257 additions & 75 deletions

File tree

JavaGUI/jni/TSDRLibraryNDK.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,6 @@ JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_setGain (JNIEnv * en
160160
THROW(tsdr_setgain(&tsdr_instance, (float) gain));
161161
}
162162

163-
JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_setResolution (JNIEnv * env, jobject obj, jint width, jint height) {
164-
THROW(tsdr_setresolution(&tsdr_instance, (int) width, (int) height));
165-
}
166-
167-
JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_setVfreq (JNIEnv * env, jobject obj, jfloat freq) {
168-
THROW(tsdr_setvfreq(&tsdr_instance, (float) freq));
169-
}
170-
171-
JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_setHfreq (JNIEnv * env, jobject obj, jfloat freq) {
172-
THROW(tsdr_sethfreq(&tsdr_instance, (float) freq));
163+
JNIEXPORT void JNICALL Java_martin_tempest_core_TSDRLibrary_setResolution (JNIEnv * env, jobject obj, jint width, jint height, jfloat refreshrate) {
164+
THROW(tsdr_setresolution(&tsdr_instance, (int) width, (int) height, (float) refreshrate));
173165
}

JavaGUI/jni/TSDRLibraryNDK.h

Lines changed: 2 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaGUI/jni/include/TSDRLibrary.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
struct tsdr_lib {
77
void * plugin;
88
void * mutex_sync_unload;
9+
void * mutex_video_stopped;
910
uint32_t samplerate;
1011
int width;
1112
int height;
12-
float vf;
13-
float hf;
13+
float refreshrate;
14+
float fh;
15+
float fv;
1416
volatile int running;
1517
} typedef tsdr_lib_t;
1618

@@ -22,8 +24,6 @@
2224
int tsdr_setgain(tsdr_lib_t * tsdr, float gain);
2325
int tsdr_readasync(tsdr_lib_t * tsdr, const char * pluginfilepath, tsdr_readasync_function cb, void *, const char * params);
2426
int tsdr_unloadplugin(tsdr_lib_t * tsdr);
25-
int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height);
26-
int tsdr_setvfreq(tsdr_lib_t * tsdr, float freq);
27-
int tsdr_sethfreq(tsdr_lib_t * tsdr, float freq);
27+
int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height, float refreshrate);
2828

2929
#endif

JavaGUI/src/martin/tempest/Main.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
public class Main implements TSDRLibrary.FrameReadyCallback {
1313

14-
private static final int WIDTH = 800;
15-
private static final int HEIGHT = 600;
14+
private static final int WIDTH = 1056;
15+
private static final int HEIGHT = 628;
16+
private static final float REFRESHRATE = 50.11061e6f;
17+
private static final String COMMAND = "D:\\Dokumenti\\Cambridge\\project\\mphilproj\\Toshiba-440CDX\\toshiba.iq";
1618

1719
private final ImageVisualizer viz = new ImageVisualizer();
1820
private JFrame frame;
@@ -39,7 +41,7 @@ public void run() {
3941
try {
4042
TSDRLibrary sdrlib = new TSDRLibrary();
4143
sdrlib.registerFrameReadyCallback(Main.this);
42-
sdrlib.startAsync(TSDRSource.fromRawFile("D:\\Dokumenti\\Cambridge\\project\\mphilproj\\Toshiba-440CDX\\toshiba.iq"), WIDTH, HEIGHT);
44+
sdrlib.startAsync(TSDRSource.fromRawFile(COMMAND), WIDTH, HEIGHT, REFRESHRATE);
4345
} catch (Throwable e) {e.printStackTrace();};
4446

4547
};

JavaGUI/src/martin/tempest/core/TSDRLibrary.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,12 @@ public TSDRLibrary() throws TSDRException {
139139
public native void stop() throws TSDRException;
140140
public native void setGain(float gain) throws TSDRException;
141141

142-
public native void setResolution(int width, int height) throws TSDRException;
143-
public native void setVfreq(float freq) throws TSDRException;
144-
public native void setHfreq(float freq) throws TSDRException;
142+
public native void setResolution(int width, int height, float refreshrate) throws TSDRException;
145143

146-
public void startAsync(final TSDRSource plugin, int width, int height) throws TSDRException {
144+
public void startAsync(final TSDRSource plugin, int width, int height, float refreshrate) throws TSDRException {
147145
final String absolute_path = plugin.absolute ? plugin.libname : (extractLibrary(plugin.libname).getAbsolutePath());
148146

149-
setResolution(width, height);
147+
setResolution(width, height, refreshrate);
150148

151149
Runtime.getRuntime().addShutdownHook(unloaderhook);
152150

TSDRPlugin_RawFile/src/TSDRPlugin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
typedef void(*tsdrplugin_readasync_function)(float *buf, uint32_t len, void *ctx);
77

88
void tsdrplugin_getName(char *);
9-
int tsdrplugin_setsamplerate(uint32_t rate);
9+
uint32_t tsdrplugin_setsamplerate(uint32_t rate);
10+
uint32_t tsdrplugin_getsamplerate();
1011
int tsdrplugin_setbasefreq(uint32_t freq);
1112
int tsdrplugin_stop(void);
1213
int tsdrplugin_setgain(float gain);

TSDRPlugin_RawFile/src/TSDRPlugin_RawFile.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@
1212
#define TYPE_BYTE (1)
1313
#define TYPE_SHORT (2)
1414

15-
#define SAMPLES_TO_READ_AT_ONCE (800*600)
15+
#define SAMPLES_TO_READ_AT_ONCE (2048)
1616

1717
TickTockTimer_t timer;
1818
volatile int working = 0;
1919

2020
int type = TYPE_FLOAT;
2121
int sizepersample = 4; // matlab single TODO! change via parameter
2222

23+
uint32_t samplerate = 100e6 / 4; // TODO! real sample rate
24+
2325
void tsdrplugin_getName(char * name) {
2426
strcpy(name, "TSDR Raw File Source Plugin");
2527
}
2628

27-
int tsdrplugin_setsamplerate(uint32_t rate) {
28-
return TSDR_NOT_IMPLEMENTED;
29+
uint32_t tsdrplugin_setsamplerate(uint32_t rate) {
30+
return samplerate;
31+
}
32+
33+
uint32_t tsdrplugin_getsamplerate() {
34+
return samplerate;
2935
}
3036

3137
int tsdrplugin_setbasefreq(uint32_t freq) {
@@ -75,7 +81,7 @@ int tsdrplugin_readasync(tsdrplugin_readasync_function cb, void *ctx, const char
7581
if (working) {
7682

7783
if (type == TYPE_FLOAT) {
78-
memccpy(outbuf, buf, 0, bytestoread);
84+
memcpy(outbuf, buf, bytestoread);
7985
}
8086

8187
cb(outbuf, SAMPLES_TO_READ_AT_ONCE, ctx);

TempestSDR/makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Define all of the C files here
2-
OBJS = TSDRLibrary.o TSDRPluginLoader.o threading.o
2+
OBJS = TSDRLibrary.o TSDRPluginLoader.o threading.o circbuff.o
33

44
# Define all of the dependencies here
5-
DEPS = include/TSDRLibrary.h TSDRPluginLoader.h include/TSDRPlugin.h osdetect.h threading.h
5+
DEPS = include/TSDRLibrary.h TSDRPluginLoader.h include/TSDRPlugin.h osdetect.h threading.h circbuff.h
66

77
# USER CONFIGURATION ENDS HERE
88

TempestSDR/src/TSDRLibrary.c

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
#include "TSDRPluginLoader.h"
1414
#include "osdetect.h"
1515
#include "threading.h"
16+
#include <math.h>
17+
#include "circbuff.h"
1618

1719
#define MAX_ARR_SIZE (4000*4000)
20+
#define CIRC_BUFF_FRAME_COUNT (100)
1821

1922
struct tsdr_context {
2023
tsdr_readasync_function cb;
2124
float * buffer;
2225
tsdr_lib_t * this;
2326
int bufsize;
2427
void *ctx;
28+
CircBuff_t circbuf;
2529
} typedef tsdr_context_t;
2630

2731
int tsdr_setsamplerate(tsdr_lib_t * tsdr, uint32_t rate) {
@@ -30,6 +34,12 @@ int tsdr_setsamplerate(tsdr_lib_t * tsdr, uint32_t rate) {
3034
return TSDR_OK;
3135
}
3236

37+
int tsdr_getsamplerate(tsdr_lib_t * tsdr) {
38+
pluginsource_t * plugin = (pluginsource_t *)(tsdr->plugin);
39+
tsdr->samplerate = plugin->tsdrplugin_getsamplerate();
40+
return TSDR_OK;
41+
}
42+
3343
int tsdr_setbasefreq(tsdr_lib_t * tsdr, uint32_t freq) {
3444
pluginsource_t * plugin = (pluginsource_t *)(tsdr->plugin);
3545
return plugin->tsdrplugin_setbasefreq(freq);
@@ -44,6 +54,7 @@ int tsdr_stop(tsdr_lib_t * tsdr) {
4454

4555
mutex_wait((mutex_t *) tsdr->mutex_sync_unload);
4656

57+
mutex_free((mutex_t *) tsdr->mutex_sync_unload);
4758
free(tsdr->mutex_sync_unload);
4859
return status;
4960
}
@@ -55,15 +66,38 @@ int tsdr_setgain(tsdr_lib_t * tsdr, float gain) {
5566
return plugin->tsdrplugin_setgain(gain);
5667
}
5768

69+
void videodecodingthread(void * ctx) {
70+
tsdr_context_t * context = (tsdr_context_t *) ctx;
71+
72+
const uint32_t samplerate = context->this->samplerate;
73+
const int height = context->this->height;
74+
const int width = context->this->width;
75+
const float fh = context->this->fh;
76+
const float fv = context->this->fv;
77+
78+
while (context->this->running) {
79+
if (cb_rem_blocking(&context->circbuf, context->buffer, context->bufsize) == CB_OK) {
80+
context->cb(context->buffer, context->this->width, context->this->height, context->ctx);
81+
}
82+
}
83+
84+
mutex_signal((mutex_t *) context->this->mutex_video_stopped);
85+
}
86+
5887
void process(float *buf, uint32_t len, void *ctx) {
5988
tsdr_context_t * context = (tsdr_context_t *) ctx;
6089

61-
const int length = (len < context->bufsize) ? (len) : (context->bufsize);
90+
int i = 0;
91+
int id;
92+
const int size = len/2;
93+
for (id = 0; id < size; id++) {
94+
const float I = buf[i++];
95+
const float Q = buf[i++];
6296

63-
int i;
64-
for (i = 0; i < length; i++) context->buffer[i] = buf[i];
97+
buf[id] = sqrtf(I*I+Q*Q);
98+
}
6599

66-
context->cb(context->buffer, context->this->width, context->this->height, context->ctx);
100+
cb_add(&context->circbuf, buf, size);
67101
}
68102

69103
int tsdr_readasync(tsdr_lib_t * tsdr, const char * pluginfilepath, tsdr_readasync_function cb, void *ctx, const char * params) {
@@ -82,6 +116,10 @@ int tsdr_readasync(tsdr_lib_t * tsdr, const char * pluginfilepath, tsdr_readasyn
82116

83117
tsdr->mutex_sync_unload = malloc(sizeof(mutex_t));
84118
mutex_init((mutex_t *) tsdr->mutex_sync_unload);
119+
120+
tsdr->mutex_video_stopped = malloc(sizeof(mutex_t));
121+
mutex_init((mutex_t *) tsdr->mutex_video_stopped);
122+
85123
pluginsource_t * plugin = (pluginsource_t *)(tsdr->plugin);
86124

87125
const int width = tsdr->width;
@@ -97,40 +135,43 @@ int tsdr_readasync(tsdr_lib_t * tsdr, const char * pluginfilepath, tsdr_readasyn
97135
context->bufsize = width * height;
98136
context->buffer = (float *) malloc(sizeof(float) * context->bufsize);
99137
context->ctx = ctx;
138+
cb_init(&context->circbuf, CIRC_BUFF_FRAME_COUNT*context->bufsize);
100139

140+
tsdr_getsamplerate(tsdr);
141+
142+
thread_start(videodecodingthread, (void *) context);
101143
status = plugin->tsdrplugin_readasync(process, (void *) context, params);
144+
tsdr->running = 0;
145+
146+
mutex_wait((mutex_t *) tsdr->mutex_video_stopped);
147+
148+
mutex_free((mutex_t *) tsdr->mutex_video_stopped);
149+
free(tsdr->mutex_video_stopped);
102150

103151
if (status != TSDR_OK) return status;
104152

105153
free(context->buffer);
106154
free(context);
107155

156+
cb_free(&context->circbuf);
108157
tsdrplug_close((pluginsource_t *)(tsdr->plugin));
109158
free(tsdr->plugin);
110159

111160
mutex_signal((mutex_t *) tsdr->mutex_sync_unload);
112161

113-
tsdr->running = 0;
114162
return status;
115163
}
116164

117-
int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height) {
165+
int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height, float refreshrate) {
166+
if (width < 0 || height < 0 || width*height > MAX_ARR_SIZE || refreshrate <= 0)
167+
return TSDR_WRONG_WIDTHHEIGHT;
168+
118169
tsdr->width = width;
119170
tsdr->height = height;
120-
121-
if (width < 0 || height < 0 || width*height > MAX_ARR_SIZE)
122-
return TSDR_WRONG_WIDTHHEIGHT;
171+
tsdr->refreshrate = refreshrate;
172+
tsdr->fh = refreshrate / (float) width;
173+
tsdr->fv = refreshrate / (float) height;
123174

124175
return TSDR_OK;
125176
}
126177

127-
int tsdr_setvfreq(tsdr_lib_t * tsdr, float freq) {
128-
tsdr->vf = freq;
129-
return TSDR_OK;
130-
}
131-
132-
int tsdr_sethfreq(tsdr_lib_t * tsdr, float freq) {
133-
tsdr->hf = freq;
134-
return TSDR_OK;
135-
136-
}

TempestSDR/src/TSDRPluginLoader.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ int tsdrplug_load(pluginsource_t * plugin, const char *dlname)
2525
if (plugin->fd == NULL)
2626
return TSDR_ERR_PLUGIN;
2727

28+
if ((plugin->tsdrplugin_getsamplerate = tsdrplug_getfunction(plugin, "tsdrplugin_getsamplerate")) == 0) return TSDR_ERR_PLUGIN;
2829
if ((plugin->tsdrplugin_getName = tsdrplug_getfunction(plugin, "tsdrplugin_getName")) == 0) return TSDR_ERR_PLUGIN;
2930
if ((plugin->tsdrplugin_setsamplerate = tsdrplug_getfunction(plugin, "tsdrplugin_setsamplerate")) == 0) return TSDR_ERR_PLUGIN;
3031
if ((plugin->tsdrplugin_setbasefreq = tsdrplug_getfunction(plugin, "tsdrplugin_setbasefreq")) == 0) return TSDR_ERR_PLUGIN;

0 commit comments

Comments
 (0)