-
Notifications
You must be signed in to change notification settings - Fork 0
/
appsrc_test2.c
215 lines (158 loc) · 4.79 KB
/
appsrc_test2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <stdint.h>
#include <stdio.h>
#include <math.h>
int want = 1;
double frame[630][64]={0,};
static void prepare_buffer(GstAppSrc* appsrc, int index) {
//static gboolean white = FALSE;
static GstClockTime timestamp = 0;
GstBuffer *buffer;
guint size;
GstFlowReturn ret;
////////////////////////////////////
//double frame2[1024][640]={0,};//
char filename[16];
char s2[13]="data_point/";
if(10>index){
sprintf(filename,"000000000%d.txt",index);
}else if(99>= index && index>=10){
sprintf(filename,"00000000%d.txt",index);
}else if(999>= index && index>=100){
sprintf(filename,"0000000%d.txt",index);
}
char *filename2=strcat(s2, filename);
printf("%s\n", filename2);
FILE* fp;
fp = fopen(filename2,"r");
double read_num, x, y, z;
double xy_theta, z_theta, range, xy_theta_round, y_theta_round;
double dif_chk_xy, dif_chk_y;
double val = 57.2958;
int cnt=1;
while(fgetc(fp) != EOF){
fscanf(fp, "%lf", &read_num);
if(cnt%4==0){
//calculate
xy_theta=atan(y/x)*val+45;
z_theta=atan(z/x)*val+5;
if( 0<z_theta & z_theta<=64 & 0< xy_theta & xy_theta<=90 ){
range=round(sqrt(x*x+y*y+z*z)*100)/100;
xy_theta=xy_theta*7;
xy_theta_round=round(xy_theta);
y_theta_round=round(z_theta);
frame[(int)xy_theta][(int)z_theta]=range;
//printf("range=%f z_theta=%f xy_theta=%f \n", range, z_theta , xy_theta);//frame=%f\n , frame[(int)xy_theta][(int)z_theta]
}
/**
x=(round(x)+320);
y=(round(y)+612);
if(x<640 & y<1024){
frame2[(int)x][(int)y]=z;
printf("zz=%f",z);
}
*/
}else if(cnt%4==1){
//x
x=read_num;
//printf("x=%f",x);
}else if(cnt%4==2){
//y
y=read_num;
//printf(" y=%f",y);
}else if(cnt%4==3){
//z
z=read_num;
//printf(" z=%f\n",z);
}
cnt=cnt+1;
}
printf("number of point cnt=%d\n",cnt/4);
fclose(fp);
/**
int col = 630;
int row = 64;
int cnt2=0;
for(int i=0; i<col; i++){
for(int j=0; j<row; j++){
if(frame[i][j]==0){
//printf("%5.2f ",frame[i][j]);
cnt2=cnt2+1;
}
}
//printf("\n");
}
printf("number of point cnt2=%d\n",cnt2);
*/
////////////////////////////////////
if (!want) return;
want = 0;
/////////////////////
size = 630*64*2;
buffer = gst_buffer_new_wrapped_full( 0, (gpointer)frame, size, 0, size, NULL, NULL );
////////////////////////
GST_BUFFER_PTS (buffer) = timestamp;
GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND, 4);
timestamp += GST_BUFFER_DURATION (buffer);
ret = gst_app_src_push_buffer(appsrc, buffer);
if (ret != GST_FLOW_OK) {
/* something wrong, stop pushing */
// g_main_loop_quit (loop);
}
}
static void cb_need_data (GstElement *appsrc, guint unused_size, gpointer user_data) {
//prepare_buffer((GstAppSrc*)appsrc);
want = 1;
}
gint main (gint argc, gchar *argv[]) {
GstElement *pipeline, *appsrc, *conv, *videosink;
/////
int file_list[157]={0,};
for(int i=0; i<157;i++){
file_list[i]=i;
//printf("ss==%ld",sizeof(file_list));
}
/////
/* init GStreamer */
gst_init (&argc, &argv);
/* setup pipeline */
pipeline = gst_pipeline_new ("pipeline");
appsrc = gst_element_factory_make ("appsrc", "source");
conv = gst_element_factory_make ("videoconvert", "conv");
videosink = gst_element_factory_make ("xvimagesink", "videosink");
/* setup */
g_object_set (G_OBJECT (appsrc), "caps",
gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "RGB16",
"width", G_TYPE_INT, 630,
"height", G_TYPE_INT, 64,
"framerate", GST_TYPE_FRACTION, 25, 1,
NULL), NULL);
gst_bin_add_many (GST_BIN (pipeline), appsrc, conv, videosink, NULL);
gst_element_link_many (appsrc, conv, videosink, NULL);
/* setup appsrc */
g_object_set (G_OBJECT (appsrc),
"stream-type", 0, // GST_APP_STREAM_TYPE_STREAM
"format", GST_FORMAT_TIME,
"is-live", TRUE,
NULL);
g_signal_connect (appsrc, "need-data", G_CALLBACK (cb_need_data), NULL);
/* play */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/**
while (1) {
prepare_buffer((GstAppSrc*)appsrc);
g_main_context_iteration(g_main_context_default(),FALSE);
}*/
////////////////////sizeof(file_list)/8
for(int i=0; i<sizeof(file_list)/4; i++) {
prepare_buffer((GstAppSrc*)appsrc, file_list[i]);
g_main_context_iteration(g_main_context_default(),FALSE);
}
/////////////////////////
/* clean up */
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (pipeline));
return 0;
}