static void usb_flash_device_info_print(const struct usb_flash_device * dev) { int i; PRINTF_ADD("USB device: %s", device_to_string(dev->devices[0])); for ( i = 1; dev->devices[i]; ++i ) PRINTF_ADD("/%s", device_to_string(dev->devices[i])); PRINTF_ADD(" (%#04x:%#04x) in %s mode", dev->vendor, dev->product, usb_flash_protocol_to_string(dev->protocol)); }
static void* pthread_b_work(void* args) { sorm_connection_t *_conn; int ret = sorm_open(DB_FILE, SORM_DB_SQLITE, 0, &rwlock, SORM_ENABLE_RWLOCK, &_conn); assert(ret == SORM_OK); pthread_mutex_lock(&mutex); while (condition_b == 0) { pthread_cond_wait(&cond_b, &mutex); } pthread_mutex_unlock(&mutex); sorm_iterator_t *iterator; sorm_begin_read_transaction(_conn); device_t *device; ret = device_select_iterate_by_open(_conn, ALL_COLUMNS, NULL, &iterator); while (1) { device_select_iterate_by(iterator, &device); if (!device_select_iterate_more(iterator)) { break; } char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } device_select_iterate_close(iterator); sorm_commit_transaction(_conn); //pthread_mutex_lock(&mutex); //condition_a = 1; //pthread_mutex_unlock(&mutex); //pthread_cond_signal(&cond_a); //printf("wait for input\n"); //ret = getchar(); //printf("continue running\n"); //ret = device_select_by_uuid(_conn, ALL_COLUMNS, "uuid0", // &device); //assert(ret == SORM_OK); //printf("get small num : %d\n", device->small_num); //device_free(device); // //sorm_commit_transaction(_conn); printf("b finish\n"); sorm_close(_conn); }
static void* pthread_a_work(void* args) { sorm_connection_t *_conn; int ret = sorm_open(DB_FILE, SORM_DB_SQLITE, 0, &rwlock, SORM_ENABLE_RWLOCK, &_conn); assert(ret == SORM_OK); device_t *device; sorm_iterator_t *iterator; ret = device_select_iterate_by_open(_conn, ALL_COLUMNS, NULL, &iterator); sorm_begin_read_transaction(_conn); int i; for (i = 0; i < 4; i ++) { device_select_iterate_by(iterator, &device); char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } sorm_begin_write_transaction(_conn); device = device_new(); device_set_id(device, 3); device_set_uuid(device, "uuid-3"); device_set_name(device, "name-3"); device_set_password(device, "passwd-3"); ret = device_insert(_conn, device); assert(ret == SORM_OK); device_free(device); printf("insert uuid-3\n"); pthread_mutex_lock(&mutex); condition_b = 1; pthread_mutex_unlock(&mutex); pthread_cond_signal(&cond_b); printf("wait for input\n"); ret = getchar(); printf("continue running\n"); sorm_commit_transaction(_conn); while (1) { device_select_iterate_by(iterator, &device); if (!device_select_iterate_more(iterator)) { break; } char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } sorm_commit_transaction(_conn); device_select_iterate_close(iterator); //sorm_commit_transaction(_conn); printf("a finish\n"); sorm_close(_conn); }
int main() { pthread_rwlock_init(&rwlock, NULL); pthread_t p1, p2; sorm_init(0); sorm_connection_t *_conn; int ret = sorm_open(DB_FILE, SORM_DB_SQLITE, 0, &rwlock, SORM_ENABLE_RWLOCK, &_conn); ret = device_create_table(_conn); assert(ret == SORM_OK); /* insert rows for select */ int i; device_t *device; for(i = 0; i < 10; i ++) { if (i == 3) { continue; } device = device_new(); device->id = i; device->id_stat = SORM_STAT_VALUED; sprintf(device->uuid,"uuid-%d", i); device->uuid_stat = SORM_STAT_VALUED; sprintf(device->name,"name-%d", i); device->name_stat = SORM_STAT_VALUED; sprintf(device->password, "passwd-%d", i); device->password_stat = SORM_STAT_VALUED; device_insert(_conn, device); device_free(device); } ret = pthread_create(&p1, NULL, pthread_a_work, (void*)_conn); assert(ret == 0); ret = pthread_create(&p2, NULL, pthread_b_work, (void*)_conn); assert(ret == 0); pthread_join(p1, NULL); pthread_join(p2, NULL); sorm_iterator_t *iterator; ret = device_select_iterate_by_open(_conn, ALL_COLUMNS, NULL, &iterator); while (1) { device_select_iterate_by(iterator, &device); if (!device_select_iterate_more(iterator)) { break; } char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } device_select_iterate_close(iterator); ret = device_delete_table(_conn); assert(ret == SORM_OK); sorm_close(_conn); }
bool PrivateDecoderCrystalHD::Init(const QString &decoder, PlayerFlags flags, AVCodecContext *avctx) { if ((decoder != "crystalhd") || !(flags & kDecodeAllowEXT) || !avctx || getenv("NO_CRYSTALHD")) return false; static bool debugged = false; uint32_t well_documented = DTS_PLAYBACK_MODE | DTS_LOAD_FILE_PLAY_FW | DTS_SKIP_TX_CHK_CPB | DTS_PLAYBACK_DROP_RPT_MODE | DTS_DFLT_RESOLUTION(vdecRESOLUTION_CUSTOM); INIT_ST; st = DtsDeviceOpen(&m_device, well_documented); CHECK_ST; if (!ok) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to open CrystalHD device"); return false; } _BC_INFO_CRYSTAL_ info; st = DtsCrystalHDVersion(m_device, &info); CHECK_ST; if (!ok) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to get device info."); return false; } m_device_type = (BC_DEVICE_TYPE)info.device; if (!debugged) { LOG(VB_GENERAL, LOG_INFO, LOC + QString("Device: %1") .arg(device_to_string(m_device_type))); LOG(VB_GENERAL, LOG_INFO, LOC + QString("Library : %1.%2.%3") .arg(info.dilVersion.dilMajor) .arg(info.dilVersion.dilMinor) .arg(info.dilVersion.version)); LOG(VB_GENERAL, LOG_INFO, LOC + QString("Driver : %1.%2.%3") .arg(info.drvVersion.drvMajor) .arg(info.drvVersion.drvMinor) .arg(info.drvVersion.version)); LOG(VB_GENERAL, LOG_INFO, LOC + QString("Firmware: %1.%2.%3") .arg(info.fwVersion.fwMajor) .arg(info.fwVersion.fwMinor) .arg(info.fwVersion.version)); } if (BC_70012 == m_device_type) { LOG(VB_GENERAL, LOG_ERR, LOC + "BCM70012 device is currently unsupported."); return false; } BC_HW_CAPS hw_caps; uint32_t codecs; st = DtsGetCapabilities(m_device, &hw_caps); CHECK_ST; if (!ok) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to get device capabilities"); return false; } BC_OUTPUT_FORMAT m_desired_fmt = (m_device_type == BC_70015) ? OUTPUT_MODE422_YUY2 : OUTPUT_MODE420; m_pix_fmt = OUTPUT_MODE_INVALID; for (int i = 0; i < hw_caps.ColorCaps.Count; i++) { if (m_desired_fmt == hw_caps.ColorCaps.OutFmt[i]) m_pix_fmt = m_desired_fmt; if (!debugged) { LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Supported output format: %1") .arg(bcmpixfmt_to_string(hw_caps.ColorCaps.OutFmt[i]))); } } if (m_pix_fmt != m_desired_fmt) { LOG(VB_PLAYBACK, LOG_ERR, LOC + "Failed to find correct output format."); return false; } LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Using: %1") .arg(bcmpixfmt_to_string(m_pix_fmt))); codecs = hw_caps.DecCaps; if (!debugged) { LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("H.264 support: %1") .arg((bool)(codecs & BC_DEC_FLAGS_H264))); LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("MPEG2 support: %1") .arg((bool)(codecs & BC_DEC_FLAGS_MPEG2))); LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("VC1 support: %1") .arg((bool)(codecs & BC_DEC_FLAGS_VC1))); LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("MPEG4 support: %1") .arg((bool)(codecs & BC_DEC_FLAGS_M4P2))); debugged = true; } BC_MEDIA_SUBTYPE sub_type = BC_MSUBTYPE_INVALID; switch (avctx->codec_id) { case AV_CODEC_ID_MPEG4: if (codecs & BC_DEC_FLAGS_M4P2) sub_type = BC_MSUBTYPE_DIVX; break; case AV_CODEC_ID_MPEG1VIDEO: if (codecs & BC_DEC_FLAGS_MPEG2) sub_type = BC_MSUBTYPE_MPEG1VIDEO; break; case AV_CODEC_ID_MPEG2VIDEO: if (codecs & BC_DEC_FLAGS_MPEG2) sub_type = BC_MSUBTYPE_MPEG2VIDEO; break; case AV_CODEC_ID_VC1: if (codecs & BC_DEC_FLAGS_VC1) { if (avctx->codec_tag == MKTAG('W','V','C','1')) sub_type = BC_MSUBTYPE_WVC1; else sub_type = BC_MSUBTYPE_VC1; } break; case AV_CODEC_ID_WMV3: if (codecs & BC_DEC_FLAGS_VC1) sub_type = BC_MSUBTYPE_WMV3; break; case AV_CODEC_ID_H264: if (codecs & BC_DEC_FLAGS_H264) { if (avctx->extradata[0] == 0x01) { if (!CreateFilter(avctx)) { LOG(VB_PLAYBACK, LOG_ERR, LOC + "Failed to create stream filter"); return false; } sub_type = BC_MSUBTYPE_AVC1; } else sub_type = BC_MSUBTYPE_H264; } break; } if (sub_type == BC_MSUBTYPE_INVALID) { LOG(VB_PLAYBACK, LOG_ERR, LOC + QString("Codec %1 not supported") .arg(ff_codec_id_string(avctx->codec_id))); return false; } int nalsize = 4; if (avctx->codec_id == AV_CODEC_ID_H264) { LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("H.264 Profile: %1 RefFrames: %2 Codec tag: %3") .arg(avctx->profile).arg(avctx->refs) .arg(fourcc_str(avctx->codec_tag))); if (avctx->extradata[0] == 1) { nalsize = (avctx->extradata[4] & 0x03) + 1; LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("avcC nal size: %1") .arg(nalsize)); } } BC_INPUT_FORMAT fmt; memset(&fmt, 0, sizeof(BC_INPUT_FORMAT)); fmt.OptFlags = 0x80000000 | vdecFrameRateUnknown; fmt.width = avctx->coded_width; fmt.height = avctx->coded_height; fmt.Progressive = 1; fmt.FGTEnable = 0; fmt.MetaDataEnable = 0; fmt.metaDataSz = avctx->extradata_size; fmt.pMetaData = avctx->extradata; fmt.startCodeSz = nalsize; fmt.mSubtype = sub_type; st = DtsSetInputFormat(m_device, &fmt); CHECK_ST; if (!ok) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to set decoder input format"); return false; } st = DtsOpenDecoder(m_device, BC_STREAM_TYPE_ES); CHECK_ST; if (!ok) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to open CrystalHD decoder"); return false; } st = DtsSetColorSpace(m_device, m_pix_fmt); if (!ok) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to set decoder output format"); return false; } st = DtsStartDecoder(m_device); if (!ok) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to start decoder"); return false; } st = DtsStartCapture(m_device); if (!ok) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to start capture"); return false; } Reset(); LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Created decoder %1 %2x%3") .arg(ff_codec_id_string(avctx->codec_id)) .arg(avctx->coded_width).arg(avctx->coded_height)); return true; }
static struct usb_device_info * usb_device_is_valid(struct libusb_device * dev) { int err, i; char product[1024]; libusb_device_handle * udev; struct usb_device_info * ret = NULL; struct libusb_device_descriptor desc; if ( libusb_get_device_descriptor(dev, &desc) < 0 ) { PRINTF_LINE("libusb_get_device_descriptor failed"); PRINTF_END(); return NULL; } for ( i = 0; usb_devices[i].vendor; ++i ) { if ( desc.idVendor == usb_devices[i].vendor && desc.idProduct == usb_devices[i].product ) { printf("\b\b "); PRINTF_END(); PRINTF_ADD("Found "); usb_flash_device_info_print(&usb_devices[i]); PRINTF_END(); PRINTF_LINE("Opening USB..."); err = libusb_open(dev, &udev); if ( err < 0 ) { PRINTF_ERROR("libusb_open failed"); fprintf(stderr, "\n"); return NULL; } usb_descriptor_info_print(udev, dev, product, sizeof(product)); if ( usb_devices[i].interface >= 0 ) { PRINTF_LINE("Detaching kernel from USB interface..."); libusb_detach_kernel_driver(udev, usb_devices[i].interface); PRINTF_LINE("Claiming USB interface..."); if ( libusb_claim_interface(udev, usb_devices[i].interface) < 0 ) { PRINTF_ERROR("libusb_claim_interface failed"); fprintf(stderr, "\n"); usb_reattach_kernel_driver(udev, usb_devices[i].interface); libusb_close(udev); return NULL; } } if ( usb_devices[i].alternate >= 0 ) { PRINTF_LINE("Setting alternate USB interface..."); if ( libusb_set_interface_alt_setting(udev, usb_devices[i].interface, usb_devices[i].alternate) < 0 ) { PRINTF_ERROR("libusb_claim_interface failed"); fprintf(stderr, "\n"); usb_reattach_kernel_driver(udev, usb_devices[i].interface); libusb_close(udev); return NULL; } } if ( usb_devices[i].configuration >= 0 ) { PRINTF_LINE("Setting USB configuration..."); if ( libusb_set_configuration(udev, usb_devices[i].configuration) < 0 ) { PRINTF_ERROR("libusb_set_configuration failed"); fprintf(stderr, "\n"); usb_reattach_kernel_driver(udev, usb_devices[i].interface); libusb_close(udev); return NULL; } } ret = calloc(1, sizeof(struct usb_device_info)); if ( ! ret ) { ALLOC_ERROR(); usb_reattach_kernel_driver(udev, usb_devices[i].interface); libusb_close(udev); return NULL; } if ( strstr(product, "N900") ) ret->device = DEVICE_RX_51; else if ( strstr(product, "N950") ) ret->device = DEVICE_RM_680; else ret->device = DEVICE_UNKNOWN; /* TODO: Autodetect more devices */ if ( device_to_string(ret->device) ) PRINTF_LINE("Detected USB device: %s", device_to_string(ret->device)); else PRINTF_LINE("Detected USB device: (not detected)"); PRINTF_END(); if ( ret->device ) { enum device * device; for ( device = usb_devices[i].devices; *device; ++device ) if ( *device == ret->device ) break; if ( ! *device ) { ERROR("Device mishmash"); fprintf(stderr, "\n"); usb_reattach_kernel_driver(udev, usb_devices[i].interface); libusb_close(udev); free(ret); return NULL; } } ret->hwrev = -1; ret->flash_device = &usb_devices[i]; ret->udev = udev; break; } } return ret; }
static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) { int i; char product[1024]; struct usb_device_info * ret = NULL; for ( i = 0; usb_devices[i].vendor; ++i ) { if ( dev->descriptor.idVendor == usb_devices[i].vendor && dev->descriptor.idProduct == usb_devices[i].product ) { printf("\b\b "); PRINTF_END(); PRINTF_ADD("Found "); usb_flash_device_info_print(&usb_devices[i]); PRINTF_END(); PRINTF_LINE("Opening USB..."); usb_dev_handle * udev = usb_open(dev); if ( ! udev ) { PRINTF_ERROR("usb_open failed"); fprintf(stderr, "\n"); return NULL; } usb_descriptor_info_print(udev, dev, product, sizeof(product)); #if defined(LIBUSB_HAS_GET_DRIVER_NP) && defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP) PRINTF_LINE("Detaching kernel from USB interface..."); usb_detach_kernel_driver_np(udev, usb_devices[i].interface); #endif PRINTF_LINE("Claiming USB interface..."); if ( usb_claim_interface(udev, usb_devices[i].interface) < 0 ) { PRINTF_ERROR("usb_claim_interface failed"); fprintf(stderr, "\n"); usb_close(udev); return NULL; } if ( usb_devices[i].alternate >= 0 ) { PRINTF_LINE("Setting alternate USB interface..."); if ( usb_set_altinterface(udev, usb_devices[i].alternate) < 0 ) { PRINTF_ERROR("usb_claim_interface failed"); fprintf(stderr, "\n"); usb_close(udev); return NULL; } } if ( usb_devices[i].configuration >= 0 ) { PRINTF_LINE("Setting USB configuration..."); if ( usb_set_configuration(udev, usb_devices[i].configuration) < 0 ) { PRINTF_ERROR("usb_set_configuration failed"); fprintf(stderr, "\n"); usb_close(udev); return NULL; } } ret = calloc(1, sizeof(struct usb_device_info)); if ( ! ret ) { ALLOC_ERROR(); usb_close(udev); return NULL; } if ( strstr(product, "N900") ) ret->device = DEVICE_RX_51; else ret->device = DEVICE_UNKNOWN; /* TODO: Autodetect more devices */ if ( device_to_string(ret->device) ) PRINTF_LINE("Detected USB device: %s", device_to_string(ret->device)); else PRINTF_LINE("Detected USB device: (not detected)"); PRINTF_END(); if ( ret->device ) { enum device * device; for ( device = usb_devices[i].devices; *device; ++device ) if ( *device == ret->device ) break; if ( ! *device ) { ERROR("Device mishmash"); fprintf(stderr, "\n"); usb_close(udev); return NULL; } } ret->hwrev = -1; ret->flash_device = &usb_devices[i]; ret->udev = udev; break; } } return ret; }