X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=vbox.cpp;h=8447b896667b6a64935aa8b5ddacc21ee684d9de;hp=6eb0ce20e0bf59ebbf9fdec060228f3357f231f8;hb=034d3a91404addedc1c7a3494862c79532b0b878;hpb=8bb49ccb7b3eba0a3f20d3b097541304b3580f70 diff --git a/vbox.cpp b/vbox.cpp index 6eb0ce2..8447b89 100644 --- a/vbox.cpp +++ b/vbox.cpp @@ -23,7 +23,7 @@ int record_timeout(struct lcr_timer *timer, void *instance, int index); /* * initialize vbox port */ -VBoxPort::VBoxPort(int type, struct port_settings *settings) : Port(type, "vbox", settings) +VBoxPort::VBoxPort(int type, struct port_settings *settings) : Port(type, "vbox", settings, NULL) { p_vbox_timeout = 0; p_vbox_announce_fh = -1; @@ -103,35 +103,34 @@ void VBoxPort::send_announcement(void) { struct lcr_msg *message; unsigned int tosend; - unsigned char buffer[ISDN_TRANSMIT]; + unsigned char buffer[PORT_TRANSMIT + PORT_TRANSMIT]; /* use twice of the buffer, so we can send more in case of delayed main loop execution */ class Endpoint *epoint; int temp; struct timeval current_time; - long long now; + long long now; /* Time in samples */ /* don't restart timer, if announcement is played */ if (p_vbox_announce_fh < 0) return; gettimeofday(¤t_time, NULL); - now = current_time.tv_sec * MICRO_SECONDS + current_time.tv_usec; + now = (current_time.tv_sec * MICRO_SECONDS + current_time.tv_usec)/125; /* set time the first time */ if (!p_vbox_audio_start) - p_vbox_audio_start = now - ISDN_TRANSMIT; + p_vbox_audio_start = now - PORT_TRANSMIT; /* calculate the number of bytes */ tosend = (unsigned int)(now - p_vbox_audio_start) - p_vbox_audio_transferred; + if (tosend > sizeof(buffer)) + tosend = sizeof(buffer); /* schedule next event */ - temp = ISDN_TRANSMIT + ISDN_TRANSMIT - tosend; + temp = PORT_TRANSMIT + PORT_TRANSMIT - tosend; if (temp < 0) temp = 0; schedule_timer(&p_vbox_announce_timer, 0, temp*125); - if (tosend > sizeof(buffer)) - tosend = sizeof(buffer); - /* add the number of samples elapsed */ p_vbox_audio_transferred += tosend; @@ -185,13 +184,22 @@ void VBoxPort::send_announcement(void) } else { if (p_record) record(buffer, tosend, 0); // from down - message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DATA); - message->param.data.len = tosend; - memcpy(message->param.data.data, buffer, tosend); - message_put(message); + /* send to remote, if bridged */ + bridge_tx(buffer, tosend); } } +int VBoxPort::bridge_rx(unsigned char *data, int len) +{ + int ret; + + if ((ret = Port::bridge_rx(data, len))) + return ret; + + if (p_record) + record(data, len, 1); // from up + return 0; +} /* * endpoint sends messages to the vbox port @@ -212,10 +220,6 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param } switch(message_id) { - case MESSAGE_DATA: - record(param->data.data, param->data.len, 1); // from up - return(1); - case MESSAGE_DISCONNECT: /* call has been disconnected */ new_state(PORT_STATE_OUT_DISCONNECT); vbox_trace_header(this, "DISCONNECT to VBox", DIRECTION_OUT); @@ -238,7 +242,6 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param /* recording is close during destruction */ delete this; return(-1); /* must return because port is gone */ - break; case MESSAGE_RELEASE: /* release vbox port */ vbox_trace_header(this, "RELEASE to VBox", DIRECTION_OUT); @@ -250,11 +253,11 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param /* recording is close during destruction */ delete this; return(-1); /* must return because port is gone */ - break; case MESSAGE_SETUP: /* dial-out command received from epoint, answer with connect */ /* get apppbx */ - memcpy(&p_vbox_ext, &((class EndpointAppPBX *)(epoint->ep_app))->e_ext, sizeof(p_vbox_ext)); + if (epoint->ep_app_type == EAPP_TYPE_PBX) + memcpy(&p_vbox_ext, &((class EndpointAppPBX *)(epoint->ep_app))->e_ext, sizeof(p_vbox_ext)); /* extract optional announcement file */ if ((c = strchr(param->setup.dialinginfo.id, ','))) { if (c[1] == '/') @@ -322,7 +325,7 @@ int VBoxPort::message_epoint(unsigned int epoint_id, int message_id, union param vbox_trace_header(this, "RECORDING", DIRECTION_IN); end_trace(); } - break; + return(1); default: PDEBUG(DEBUG_VBOX, "PORT(%s) vbox port with (caller id %s) received an unsupported message: %d\n", p_name, p_callerinfo.id, message_id);