void p264_close(p264_state_t* s) { if(s == NULL) return; video_codec_close(s->controller); free(s->controller); free(s); }
C_RESULT vlib_stage_decoding_close(vlib_stage_decoding_config_t *cfg) { if(!cfg->block_mode_enable) { vp_os_free(stream.bytes); stream.bytes = NULL; } else cfg->controller.in_stream.bytes = NULL; return video_codec_close( &cfg->controller ); }
void stream_stop(void) { if ( !stream_thread ) return; stream_thread_alive = 0; pthread_join(stream_thread, NULL); stream_thread = 0; if ( video_udp_socket >= 0 ) { close( video_udp_socket ); video_udp_socket = -1; } video_codec_close( &controller ); }
void stream_run(void) { C_RESULT status; if( stream_thread ) return; memset(&controller, 0, sizeof(controller)); memset(&picture, 0, sizeof(picture)); memset(picture_buf, 0, VIDEO_BUFFER_SIZE); pictureBpp = 2; /// Picture configuration picture.format = PIX_FMT_RGB565; picture.width = H_ACQ_WIDTH; picture.height = H_ACQ_HEIGHT; picture.framerate = 15; picture.y_line_size = picture.width * pictureBpp; picture.cb_line_size = 0; picture.cr_line_size = 0; picture.y_buf = (uint8_t *)picture_buf; picture.cb_buf = NULL; picture.cr_buf = NULL; status = video_codec_open( &controller, UVLC_CODEC ); if (status) { INFO("video_codec_open() failed\n"); } video_controller_set_motion_estimation(&controller, FALSE); video_controller_set_format( &controller, H_ACQ_WIDTH, H_ACQ_HEIGHT ); if( pthread_create(&stream_thread, NULL, stream_loop, NULL) ) { video_codec_close(&controller); INFO("pthread_create: %s\n", strerror(errno)); } }
C_RESULT vlib_stage_encoding_close(vlib_stage_encoding_config_t *cfg) { return video_codec_close( &cfg->controller ); }
C_RESULT video_codec_open( video_controller_t* controller, codec_type_t codec_type ) { C_RESULT res; // Data used to initilize macroblock's cache int32_t i; int16_t* cache; video_macroblock_t* mb; // Close any previously allocated codec for this controller video_codec_close( controller ); video_utils_init( controller ); controller->mode = 0; controller->use_me = FALSE; controller->do_azq = FALSE; controller->aq = 0; controller->bq = 0; controller->target_bitrate = VLIB_DEFAULT_BITRATE; controller->num_frames = 0; controller->picture_type = 0; controller->width = 0; controller->height = 0; controller->num_blockline = 0; controller->mb_blockline = 0; controller->blockline = 0; controller->picture_complete= 0; #ifdef USE_TABLE_QUANTIZATION controller->quant = TABLE_QUANTIZATION; #else controller->quant = DEFAULT_QUANTIZATION; #endif controller->dquant = 0; controller->Qp = 0; controller->invQp = 1; controller->gobs = NULL; controller->cache = NULL; controller->codec_type = 0; controller->video_codec = NULL; if( controller->blockline_cache == NULL ) { // We alloc two buffers to be compatible with an asynchronous DCT // When a DCT will be performed on one buffer, we will be able to use the other for caching or computing purpose // DCT_BUFFER_SIZE = MAX_NUM_MACRO_BLOCKS_PER_CALL * 6 * MCU_BLOCK_SIZE controller->blockline_cache = (int16_t*)vp_os_aligned_malloc( 2*DCT_BUFFER_SIZE*sizeof(int16_t), VLIB_ALLOC_ALIGN ); } controller->cache_mbs = vp_os_malloc( 2 * MAX_NUM_MACRO_BLOCKS_PER_CALL * sizeof(video_macroblock_t) ); mb = &controller->cache_mbs[0]; cache = controller->blockline_cache; for(i = 2*MAX_NUM_MACRO_BLOCKS_PER_CALL; i > 0; i-- ) { mb->data = cache; cache += MCU_BLOCK_SIZE*6; mb ++; } video_packetizer_init( controller ); video_quantizer_init( controller ); switch( codec_type ) { case UVLC_CODEC: uvlc_codec_alloc( controller ); break; case P263_CODEC: p263_codec_alloc( controller ); break; default: controller->video_codec = NULL; break; } if( controller->video_codec != NULL ) { controller->codec_type = codec_type; res = C_OK; } else { res = C_FAIL; } return res; }