int main(int argc, char **argv) { int ret; int counter=0; int ch_count = 0; long channel; char data; int i2c_instance = 0; int i2c_device_type = 0; uint16_t i2c_device_addr = 0x20; uint16_t chip_id_reg = 0xff; uint16_t chip_id_reg_value = 0x40; int handle; uint32_t read_len = 0; uint16_t width, hight; int framerate = 0; int goplen = 0; int audio_threshold = 20; int current_audio_intensity = 0; uint16_t regval = 0; fd_aud = NULL; //initialize audio part ************************** ret = mxuvc_audio_init("alsa","device = Condor"); if(ret<0) goto error; ret = mxuvc_alert_init(); if(ret < 0) goto error; ret = mxuvc_audio_register_cb(AUD_CH2,(mxuvc_audio_cb_t) audio_cb, NULL); if(ret < 0) goto error; ret = mxuvc_audio_set_samplerate(AUD_CH2, SAMP_FREQ); if(ret < 0) goto error; mxuvc_audio_set_volume(100); //initialize video part ************************** ret = mxuvc_video_init("v4l2","dev_offset=0"); if(ret < 0) return 1; /* Register callback functions */ ret = mxuvc_video_register_cb(CH1, ch_cb, (void*)CH1); if(ret < 0) goto error; printf("\n"); //get channel count of MUX channel ret = mxuvc_video_get_channel_count(&ch_count); printf("Total Channel count: %ld\n",ch_count); //remove raw channel from count ch_count = ch_count - 1; for(channel=CH2 ; channel<ch_count; channel++) { ret = mxuvc_video_register_cb(channel, ch_cb, (void*)channel); if(ret < 0) goto error; } /***** Start audio streaming ************/ ret = mxuvc_audio_start(AUD_CH2); if(ret < 0) goto error; /***** Start video streaming ************/ for(channel=CH1; channel<ch_count ; channel++){ /* Start streaming */ ret = mxuvc_video_start(channel); if(ret < 0) goto error; } if (audio_threshold > 0){ ret = mxuvc_alert_audio_set_threshold(audio_threshold); if (ret){ printf("mxuvc_alert_audio_set_threshold() failed\n"); goto error; } ret = mxuvc_alert_audio_register_cb(&aalarm_callback, (void *)&data); if (ret){ printf("mxuvc_alert_audio_register_callback() failed\n"); goto error; } ret = mxuvc_alert_audio_enable(); if (ret){ printf("mxuvc_alert_audio_enable() failed\n"); goto error; } } //sleep usleep(5000); //start i2c notification handle = mxuvc_i2c_open(i2c_instance, i2c_device_type, i2c_device_addr, chip_id_reg, chip_id_reg_value); if(handle <= 0){ printf("err: mxuvc_i2c_open failed\n"); goto error; } #if 0 ret = mxuvc_i2c_notification_read_register(handle, 0x10, ®val, 1); if(ret < 0){ printf("err: mxuvc_i2c_notification_read_register failed\n"); goto error; } printf("regval %x\n",regval); ret = mxuvc_i2c_notification_write_register(handle, 0x10, 0x2, 1); if(ret < 0){ printf("err: mxuvc_i2c_notification_write_register failed\n"); goto error; } ret = mxuvc_i2c_notification_read_register(handle, 0x10, ®val, 1); if(ret < 0){ printf("err: mxuvc_i2c_notification_read_register failed\n"); goto error; } printf("regval %x\n",regval); #endif //sleep(1); read_len = 1; //max 2 bytes can be read together ret = mxuvc_i2c_register_notification_callback( handle, i2c_notify_cb, 2000, //polling time chip_id_reg, read_len); if(ret < 0){ printf("err: mxuvc_i2c_register_notification_callback failed\n"); goto error; } ret = mxuvc_i2c_notification_add_threshold( handle, 0x10, 0x20); if(ret < 0){ printf("err: mxuvc_i2c_notification_add_threshold failed\n"); goto error; } ret = mxuvc_i2c_notification_add_threshold( handle, 0x50, 0x60); if(ret < 0){ printf("err: mxuvc_i2c_notification_add_threshold failed\n"); goto error; } /* Main 'loop' */ if (argc > 1){ counter = atoi(argv[1]); } else counter = 15; while(counter--) { if (!mxuvc_audio_alive() || !mxuvc_video_alive()) goto error; printf("\r%i secs left", counter); if(counter==10){ ret = mxuvc_i2c_notification_remove_threshold( handle, 0x10, 0x20); if(ret < 0){ printf("err: mxuvc_i2c_notification_remove_threshold failed\n"); goto error; } } fflush(stdout); sleep(1); } if (audio_threshold > 0){ mxuvc_alert_audio_disable(); sleep(1); } ret = mxuvc_i2c_close(handle); mxuvc_alert_deinit(); /* Stop audio streaming */ ret = mxuvc_audio_stop(AUD_CH2); if(ret < 0) goto error; mxuvc_audio_deinit(); /* Stop video streaming */ for(channel=CH1; channel<ch_count ; channel++) { /* Stop streaming */ ret = mxuvc_video_stop(channel); if(ret < 0) goto error; } /* Deinitialize and exit */ mxuvc_video_deinit(); close_fds(); return 0; error: mxuvc_alert_deinit(); mxuvc_audio_deinit(); mxuvc_video_deinit(); mxuvc_custom_control_deinit(); close_fds(); printf("Failed\n"); return 1; }
int main(int argc, char **argv) { int ret=0; int count=0; video_format_t fmt; int ch_count = 0; long channel; int framerate = 0; int goplen = 0; long ch; /* Initialize camera */ ret = mxuvc_video_init("v4l2","dev_offset=0"); if(ret < 0) return 1; ret = mxuvc_video_get_channel_count(&ch_count); printf("Total Channel count: %d\n",ch_count); ch = ch_count-1; // by default, we have RAW channel as the last channel in our design ret = mxuvc_video_get_resolution(ch, &nRawChW, &nRawChH); printf("Raw Channel: %4d x %4d\n", nRawChW, nRawChH); mbWidth = (nRawChW + 15)/16; mbHeight = (nRawChH + 15)/16; mbStride = ((mbWidth + 7) & ~0x7); nMBStatSize = mbWidth * mbHeight; mbStatsOffset = mbStride * mbHeight; printf("MBW %d MBH %d MBS %d; MBStatSize=%d; mbStatOffset=%d\n", mbWidth, mbHeight, mbStride, nMBStatSize, mbStatsOffset); LumaAvgMBData = malloc(sizeof(int)*nMBStatSize); #ifdef CH1_CAPTURE /* Register callback functions */ ret = mxuvc_video_register_cb(CH1, ch_cb, (void*)CH1); if(ret < 0) goto error; #endif ret = mxuvc_video_register_cb(ch_count-1, ch_cb, (void*)ch); if(ret < 0) goto error; printf("\n"); //get channel count of MUX channel ret = mxuvc_video_get_channel_count(&ch_count); printf("Total Channel count: %d\n",ch_count); //Commented following in order to use the default format set in firmware //ret = mxuvc_video_set_format(ch_count - 1, VID_FORMAT_GREY_RAW); STRUCT_Q_EPTZ_MODE_WM_ZCL eptzWM_ZclParam; eptzWM_ZclParam.Phi0 = 55; eptzWM_ZclParam.Rx = 2; eptzWM_ZclParam.Ry = 1; eptzWM_ZclParam.Rz = 1; eptzWM_ZclParam.Gshift = 0; //mxuvc_video_set_dewarp_params((video_channel_t) ch_count - 1, 0, EMODE_WM_ZCL, (dewarp_params_t*) &eptzWM_ZclParam); //ret = mxuvc_video_set_resolution(ch_count - 1, 320, 240); //if(ret < 0) // goto error; #ifdef CH1_CAPTURE ret = mxuvc_video_start(CH1); if(ret < 0) goto error; #endif usleep(5000); ret = mxuvc_video_start(ch_count - 1); if(ret < 0) goto error; usleep(5000); /* Main 'loop' */ int counter; if (argc > 1){ counter = atoi(argv[1]); } else counter = 15; while(counter--) { if(!mxuvc_video_alive()) { goto error; } printf("\r%i secs left", counter+1); fflush(stdout); sleep(1); } #ifdef CH1_CAPTURE ret = mxuvc_video_stop(CH1); if(ret < 0) goto error; #endif ret = mxuvc_video_stop(ch_count - 1); if(ret < 0) goto error; /* Deinitialize and exit */ mxuvc_video_deinit(); close_fds(); printf("Success\n"); return 0; error: mxuvc_video_deinit(); close_fds(); printf("Failure\n"); return 1; }
int main(int argc, char **argv) { int ret; int counter=0; int bitrate; int aec_enable = 0; if ( argc < 2 ){ printf("USAGE: capture_audmux <aec_enable 0/1> [sampling freq 8000|16000|24000] [no:of seconds to run the test]\n"); return 0; } ret = mxuvc_video_init("v4l2","dev_offset=0"); if(ret < 0) return 1; /* Register callback functions */ ret = mxuvc_video_register_cb(CH1, ch_cb, (void*)CH1); if(ret < 0) goto error; ret = mxuvc_audio_init("alsa","device = MAX64380"); if(ret<0) goto error; ret = mxuvc_audio_register_cb(AUD_CH2, audio_cb, NULL); if(ret < 0) goto error; mxuvc_custom_control_init(); if(argv[1] != NULL) aec_enable = atoi(argv[1]); if(aec_enable) { ret = mxuvc_custom_control_enable_aec(); if(ret < 0) goto error; } else { ret = mxuvc_custom_control_disable_aec(); if(ret < 0) goto error; } //TBD ret = mxuvc_audio_set_format(AUD_CH2, AUD_FORMAT_AAC_RAW); if(ret < 0) goto error; if(aec_enable){ ret = mxuvc_custom_control_set_audio_codec_samplerate(BOARD_SAMPLE_RATE); if(ret < 0) goto error; } if(argc > 2) samp_freq = atoi(argv[2]); if(samp_freq == 8000 || samp_freq == 16000 || samp_freq == 24000){ ret = mxuvc_audio_set_samplerate(AUD_CH2, samp_freq); if(ret < 0) goto error; }else printf("ERR: Unsupported sampling frequency %d\n",samp_freq); mxuvc_audio_set_volume(100); if(ret < 0) goto error; ret = mxuvc_audio_get_bitrate(&bitrate); if(ret < 0) goto error; printf("audio bitrate %d\n",bitrate); sleep(1); /* Main 'loop' */ if(argc > 3){ counter = atoi(argv[3]); } else{ counter = 15; } ret = mxuvc_audio_start(AUD_CH2); if(ret < 0) goto error; while(counter--) { if (!mxuvc_audio_alive()) goto error; printf("\r%i secs left", counter+1); fflush(stdout); sleep(1); /* uncomment to test Mute/Unmute */ /* if (counter >= 15) mxuvc_set_mic_mute(1); else mxuvc_set_mic_mute(0);*/ } /* Stop audio streaming */ ret = mxuvc_audio_stop(AUD_CH2); if(ret < 0) goto error; mxuvc_audio_deinit(); mxuvc_video_deinit(); mxuvc_custom_control_deinit(); close_fds(); return 0; error: mxuvc_audio_deinit(); close_fds(); printf("Failed\n"); return 1; }