Ejemplo n.º 1
0
int process_ctrl_packets(void *ctx) {
	int n, nof_packets;
	int i;

	do {
		moddebug("receiving control\n",0);
		n = oesr_itf_read(ctrl_in, ctrl_in_buffer,
				sizeof(struct ctrl_in_pkt)*MAX_INPUT_PACKETS,oesr_tstamp(ctx));
		if (n == -1) {
			oesr_perror("oesr_itf_read");
			return -1;
		} else if (n>0) {
			if (n % sizeof(struct ctrl_in_pkt)) {
				moderror_msg("Received %d bytes but packet size is %d\n", n,
						sizeof(struct ctrl_in_pkt));
			}
			nof_packets = n / sizeof(struct ctrl_in_pkt);
			for (i=0;i<nof_packets;i++) {
				if (process_ctrl_packet(ctx, &ctrl_in_buffer[i])) {
					moderror_msg("Error processing control packet %d/%d\n",i,nof_packets);
					return -1;
				}
			}
		}
	} while(n>0);
	return 0;
}
Ejemplo n.º 2
0
int Run(void *_ctx) {
	ctx = _ctx;
	int tstamp = oesr_tstamp(ctx);
	moddebug("enter ts=%d\n",oesr_tstamp(ctx));
	int i;
	int n;

	if (ctrl_in) {
		do {
			n = oesr_itf_read(ctrl_in, &ctrl_in_buffer, CTRL_IN_BUFFER);
			if (n == -1) {
				oesr_perror("oesr_itf_read");
				return -1;
			} else if (n>0) {
				if (process_ctrl_packet()) {
					moderror("Error processing control packet\n");
					return -1;
				}
			}
		} while(n>0);
	}

	for (i=0;i<nof_input_itf;i++) {
		if (!inputs[i]) {
			input_ptr[i] = NULL;
			rcv_len[i] = 0;
		} else {
			n = oesr_itf_ptr_get(inputs[i], &input_ptr[i], &rcv_len[i], tstamp);
			if (n == 0) {
				itfdebug("[ts=%d] received no input from %d\n",rtdal_time_slot(),i);
			} else if (n == -1) {
				oesr_perror("oesr_itf_get");
				return -1;
			} else {
				itfdebug("[ts=%d] received %d bytes\n",rtdal_time_slot(),rcv_len[i]);
				rcv_len[i] /= input_sample_sz;
			}
		}
	}
	for (i=0;i<nof_output_itf;i++) {
		if (!outputs[i]) {
			output_ptr[i] = NULL;
		} else {
			n = oesr_itf_ptr_request(outputs[i], &output_ptr[i]);
			if (n == 0) {
/*				moderror_msg("[ts=%d] no packets available in output interface %d\n",rtdal_time_slot(),i);
*/			} else if (n == -1) {
				oesr_perror("oesr_itf_request");
				return -1;
			}
		}
	}

	memset(snd_len,0,sizeof(int)*nof_output_itf);

#if MOD_DEBUG==1
	oesr_counter_start(counter);
#endif
	n = work(input_ptr,output_ptr);
#if MOD_DEBUG==1
	oesr_counter_stop(counter);
	moddebug("work exec time: %d us\n",oesr_counter_usec(counter));
#endif
	if (n<0) {
		return -1;
	}

	memset(rcv_len,0,sizeof(int)*nof_input_itf);

	for (i=0;i<nof_output_itf;i++) {
		if (!snd_len[i] && output_ptr[i]) {
			snd_len[i] = n*output_sample_sz;
		}
	}

	for (i=0;i<nof_input_itf;i++) {
		if (input_ptr[i]) {
			n = oesr_itf_ptr_release(inputs[i]);
			if (n == 0) {
				itfdebug("[ts=%d] packet from interface %d not released\n",rtdal_time_slot(),i);
			} else if (n == -1) {
				oesr_perror("oesr_itf_ptr_release\n");
				return -1;
			}
		}
	}
	for (i=0;i<nof_output_itf;i++) {
		if (output_ptr[i] && snd_len[i]) {
			n = oesr_itf_ptr_put(outputs[i],snd_len[i],tstamp);
			if (n == 0) {
				itfdebug("[ts=%d] no space left in output interface %d\n",rtdal_time_slot(),i);
			} else if (n == -1) {
				oesr_perror("oesr_itf_ptr_put\n");
				return -1;
			}
		}
	}

	moddebug("exit ts=%d\n",oesr_tstamp(ctx));
	return 0;
}