static int audio_ioctl_cmd(u8 *msg, unsigned long arg, int len, int sub_cmd) { int ret, msgid; struct sk_buff *skb; struct atc_header *header; struct response_msg *reply; pr_debug("send ioctl cmd:%d\n", sub_cmd); if (copy_from_user(msg, (void __user *)arg, len)) return -EFAULT; if (sub_cmd == ATC_MUTECTL) { ret = audio_mute_check((struct mute_ctlmsg *)msg); if (!ret) return 0; } mutex_lock(&ioctl_lock); msgid = MAKE_REQ_HANDLE(); /* msg_id field is always at the end of cmd struct */ *(u32 *) (msg + len - sizeof(reply->msg_id)) = msgid; ret = audio_send(msg, len, sub_cmd, CMD_TYPE_EXECUTE); if (ret < 0) { mutex_unlock(&ioctl_lock); return ret; } while (1) { ret = wait_for_completion_timeout(&ioctl_completion, IOCTL_TIMEOUT * HZ); if (!ret) { pr_err("<<<<ioctl cmd %d timeout>>>>\n", sub_cmd); mutex_unlock(&ioctl_lock); return -ETIMEDOUT; } /* go through all responses until desired one is found */ skb = skb_dequeue(&ctl_rxq); if (unlikely(!skb)) { mutex_unlock(&ioctl_lock); return -EIO; } header = (struct atc_header *)skb->data; reply = (struct response_msg *)(skb->data + sizeof(struct atc_header)); if (header->sub_cmd == sub_cmd && reply->msg_id == msgid) { kfree_skb(skb); break; } kfree_skb(skb); } mutex_unlock(&ioctl_lock); return 0; }
int process_get(request * req) { int bytes_written; volatile int bytes_to_write; bytes_to_write = req->filesize - req->filepos; if (bytes_to_write > SOCKETBUF_SIZE) bytes_to_write = SOCKETBUF_SIZE; if (sigsetjmp(env, 1) == 0) { handle_sigbus = 1; #ifdef SERVER_SSL if(req->ssl == NULL){ #endif /*SERVER_SSL*/ bytes_written = write(req->fd, req->data_mem + req->filepos, bytes_to_write); #ifdef SERVER_SSL }else{ bytes_written = SSL_write(req->ssl, req->data_mem + req->filepos, bytes_to_write); #if 0 printf("SSL_write\n"); #endif /*0*/ } #endif /*SERVER_SSL*/ handle_sigbus = 0; /* OK, SIGBUS **after** this point is very bad! */ } else { /* sigbus! */ log_error_doc(req); /* sending an error here is inappropriate * if we are here, the file is mmapped, and thus, * a content-length has been sent. If we send fewer bytes * the client knows there has been a problem. * We run the risk of accidentally sending the right number * of bytes (or a few too many) and the client * won't be the wiser. */ req->status = DEAD; fprintf(stderr, "%sGot SIGBUS in write(2)!\n", get_commonlog_time()); return 0; } if (bytes_written < 0) { if (errno == EWOULDBLOCK || errno == EAGAIN) return -1; /* request blocked at the pipe level, but keep going */ else { if (errno != EPIPE) { log_error_doc(req); /* Can generate lots of log entries, */ perror("write"); /* OK to disable if your logs get too big */ } req->status = DEAD; return 0; } } req->filepos += bytes_written; req->busy_flag = BUSY_FLAG_AUDIO|BUSY_FLAG_VIDEO; if (req->filepos == req->filesize) { /* EOF */ #ifdef DAVINCI_IPCAM if (req->http_stream == URI_STREAM_MJPEG) { #if 1 #if 0 while (audio_get(req) > 0); if (req->audio_length >= AUDIO_SEND_SIZE) { audio_send(req); return 1; } #else if (audio_get(req, FMT_MJPEG) > 0) return 1; #endif #else req->busy_flag &= ~BUSY_FLAG_AUDIO; #endif if (req->serial_lock) { GetAVData(AV_OP_UNLOCK_MJPEG, req->serial_lock, NULL); req->serial_lock = 0; } GetAVData(AV_OP_GET_MJPEG_SERIAL, -1, &req->av_data); if (req->av_data.serial < req->serial_book) { req->busy_flag &= ~BUSY_FLAG_VIDEO; return 1; } GetAVData(AV_OP_LOCK_MJPEG, req->av_data.serial, &req->av_data ); req->data_mem = req->av_data.ptr; req->filesize = req->av_data.size+16; req->filepos = 0; req->serial_lock = req->av_data.serial; req->serial_book = req->av_data.serial+1; reset_output_buffer(req); req_write(req, "\r\n"); print_mjpeg_headers(req); return 1; } if (req->http_stream == URI_STREAM_MPEG4 || req->http_stream == URI_STREAM_AVC) { int ret; #if 1 #if 0 while (audio_get(req) > 0); if (req->audio_length > AUDIO_SEND_SIZE) { req->busy_flag |= BUSY_FLAG_AUDIO; audio_send(req); return 1; } #else if (audio_get(req, FMT_MPEG4) > 0) return 1; #endif #else req->busy_flag &= ~BUSY_FLAG_AUDIO; #endif ret = GetAVData(AV_OP_LOCK_MP4, req->serial_book, &req->av_data); if (ret == RET_SUCCESS) { GetAVData(AV_OP_UNLOCK_MP4, req->serial_lock, NULL); req->data_mem = req->av_data.ptr; req->filesize = req->av_data.size+16; req->filepos = 0; req->serial_lock = req->av_data.serial; req->serial_book = req->av_data.serial+1; reset_output_buffer(req); req_write(req, "\r\n"); if (req->http_stream == URI_STREAM_AVC) { print_avc_headers(req); } else { print_mpeg4_headers(req); } return 1; } else if (ret == RET_NO_VALID_DATA) { req->busy_flag &= ~BUSY_FLAG_VIDEO; return 1; } else { GetAVData(AV_OP_GET_MPEG4_SERIAL, -1, &req->av_data ); req->serial_book = req->av_data.serial; dbg("lock error ret=%d\n", ret); return 1; } } if (req->http_stream == URI_STREAM_MPEG4CIF || req->http_stream == URI_STREAM_AVCCIF) { int ret; #if 1 #if 0 while (audio_get(req) > 0); if (req->audio_length > AUDIO_SEND_SIZE) { audio_send(req); return 1; } #else if (audio_get(req, FMT_MPEG4_EXT) > 0) return 1; #endif #else req->busy_flag &= ~BUSY_FLAG_AUDIO; #endif ret = GetAVData(AV_OP_LOCK_MP4_CIF, req->serial_book, &req->av_data); if (ret == RET_SUCCESS) { GetAVData(AV_OP_UNLOCK_MP4_CIF, req->serial_lock, NULL); req->data_mem = req->av_data.ptr; req->filesize = req->av_data.size+16; req->filepos = 0; req->serial_lock = req->av_data.serial; req->serial_book = req->av_data.serial+1; reset_output_buffer(req); req_write(req, "\r\n"); if (req->http_stream == URI_STREAM_AVCCIF) { print_avc_headers(req); } else { print_mpeg4_headers(req); } return 1; } else if (ret == RET_NO_VALID_DATA) { req->busy_flag &= ~BUSY_FLAG_VIDEO; return 1; } else { GetAVData(AV_OP_GET_MPEG4_CIF_SERIAL, -1, &req->av_data ); req->serial_book = req->av_data.serial; dbg("lock error ret=%d\n", ret); return 1; } } #endif // DAVINCI_IPCAM return 0; } else return 1; /* more to do */ }
void audio_io_task(void) { sndbuf_t * out_buf; sndbuf_t * in_buf; uint32_t ts = 0; int i; tracef("%s(): <%d> started...", __func__, thinkos_thread_self()); tonegen_init(&tonegen, 0, 0); spectrum_init(&audio_tx_sa, SAMPLE_RATE); spectrum_init(&audio_rx_sa, SAMPLE_RATE); for (;;) { #if DISABLE_JITBUF out_buf = xfr_buf; #else out_buf = jitbuf_dequeue(&audio_drv.jitbuf); #endif if (audio_drv.tone_mode == TONE_DAC) { if (out_buf == NULL) { if ((out_buf = sndbuf_alloc()) != NULL) tonegen_apply(&tonegen, out_buf); else out_buf = (sndbuf_t *)&sndbuf_zero; } } else { if (out_buf == NULL) { #if 0 tracef("%s(): out_buf == NULL!", __func__); #endif out_buf = (sndbuf_t *)&sndbuf_zero; } } spectrum_rec(&audio_tx_sa, out_buf); in_buf = i2s_io(out_buf); for (i = 0; i < SNDBUF_LEN; i++) in_buf->data[i] = FxaIirApply(&iir_hp_120hz, in_buf->data[i]); // in_buf->data[i] = FxaIirApply(&iir_hp_240hz, in_buf->data[i]); led_flash(LED_I2S, 100); if (in_buf != &sndbuf_null) { if (audio_drv.tone_mode == TONE_ADC) tonegen_apply(&tonegen, in_buf); spectrum_rec(&audio_rx_sa, in_buf); } if (audio_drv.stream_enabled) { #if ENABLE_G711 if (g711_alaw_send(0, in_buf, ts) < 0) { tracef("%s(): net_send() failed!", __func__); } #else if (audio_send(0, in_buf, ts) < 0) { tracef("%s(): net_send() failed!", __func__); } #endif led_flash(LED_NET, 100); } ts += SNDBUF_LEN; sndbuf_free(in_buf); sndbuf_free(out_buf); } }