- if (p_vbox_audio_start < 1)
- {
- /* set time the first time */
- p_vbox_audio_start = now_d;
- } else
- {
- /* calculate the number of bytes */
- tosend = (unsigned long)((now_d-p_vbox_audio_start)*8000) - p_vbox_audio_transferred;
-
- /* wait for more */
- if (tosend < 32)
- return(Port::handler());
-
- /* too many samples, so we just process 128 bytes until the next call of handler() */
- if (tosend > 128)
- tosend = 128;
-
- /* dummy read, to clock record buffer */
- read_audio((unsigned char *)buffer, tosend, 0);
-
- /* add the number of samples elapsed */
- p_vbox_audio_transferred += tosend;
-
- /* if announcement is currently played, send audio data */
- if (p_vbox_announce_fh >=0)
- {
- tosend = read_tone(p_vbox_announce_fh, buffer, p_vbox_announce_codec, tosend, p_vbox_announce_size, &p_vbox_announce_left, 1);
- if (tosend <= 0)
- {
- /* end of file */
- close(p_vbox_announce_fh);
- p_vbox_announce_fh = -1;
- fhuse--;
-
- time(¤ttime);
- p_vbox_record_start = currenttime;
-
- /* connect if not already */
- epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
- if (epoint)
- {
- /* if we sent our announcement during ringing, we must now connect */
- if (p_vbox_apppbx->e_ext.vbox_free)
- {
- /* send connect message */
- message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
- memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
- message_put(message);
- new_state(PORT_STATE_CONNECT);
- }
- }
-
- /* start recording, if not already */
- if (p_vbox_mode == VBOX_MODE_NORMAL)
- {
- /* send recording start message */
- message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_VBOX_RECORD);
- message_put(message);
- } else // else!!
- if (p_vbox_mode == VBOX_MODE_ANNOUNCEMENT)
- {
- /* send release */
- message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
- message->param.disconnectinfo.cause = 16;
- message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
- message_put(message);
- /* recording is close during destruction */
- delete this;
- return(-1); /* must return because port is gone */
- }
- } else
- {
- message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DATA);
- message->param.data.port_type = p_type;
- message->param.data.port_id = p_serial;
- message->param.data.len = tosend;
- memcpy(message->param.data.data, buffer, tosend);
+ return 0;
+}
+
+void VBoxPort::send_announcement(void)
+{
+ struct lcr_msg *message;
+ unsigned int tosend;
+ 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; /* 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)/125;
+
+ /* set time the first time */
+ if (!p_vbox_audio_start)
+ 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 = PORT_TRANSMIT + PORT_TRANSMIT - tosend;
+ if (temp < 0)
+ temp = 0;
+ schedule_timer(&p_vbox_announce_timer, 0, temp*125);
+
+ /* add the number of samples elapsed */
+ p_vbox_audio_transferred += tosend;
+
+ /* if announcement is currently played, send audio data */
+ tosend = read_tone(p_vbox_announce_fh, buffer, p_vbox_announce_codec, tosend, p_vbox_announce_size, &p_vbox_announce_left, 1);
+ if (tosend <= 0) {
+ /* end of file */
+ close(p_vbox_announce_fh);
+ p_vbox_announce_fh = -1;
+ fhuse--;
+
+ if (p_vbox_record_limit)
+ schedule_timer(&p_vbox_record_timeout, p_vbox_record_limit, 0);
+
+ /* connect if not already */
+ epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
+ if (epoint) {
+ /* if we sent our announcement during ringing, we must now connect */
+ if (p_vbox_ext.vbox_free) {
+ /* send connect message */
+ message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
+ memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));