/* Destroy SVP instance. svp may be NULL. */ void svp_destroy(SVP_T *svp) { if (svp) { MMAL_COMPONENT_T *components[] = { svp->reader, svp->video_decode, svp->camera }; MMAL_COMPONENT_T **comp; /* Stop thread, disable connection and components */ svp_stop(svp); for (comp = components; comp < components + vcos_countof(components); comp++) { mmal_component_disable(*comp); } /* Destroy connection + components */ if (svp->connection) { mmal_connection_destroy(svp->connection); } for (comp = components; comp < components + vcos_countof(components); comp++) { mmal_component_destroy(*comp); } /* Free remaining resources */ if (svp->out_pool) { mmal_pool_destroy(svp->out_pool); } if (svp->queue) { mmal_queue_destroy(svp->queue); } if (svp->created & SVP_CREATED_WD_TIMER) { vcos_timer_delete(&svp->wd_timer); } if (svp->created & SVP_CREATED_TIMER) { vcos_timer_delete(&svp->timer); } if (svp->created & SVP_CREATED_MUTEX) { vcos_mutex_delete(&svp->mutex); } if (svp->created & SVP_CREATED_SEM) { vcos_semaphore_delete(&svp->sema); } vcos_free(svp); } }
static MMAL_STATUS_T mmal_connection_destroy_internal(MMAL_CONNECTION_T *connection) { MMAL_STATUS_T status; if (connection->is_enabled) { status = mmal_connection_disable(connection); if (status != MMAL_SUCCESS) return status; } /* Special case for tunnelling */ if (connection->flags & MMAL_CONNECTION_FLAG_TUNNELLING) { status = mmal_port_disconnect(connection->out); if (status != MMAL_SUCCESS) LOG_ERROR("connection %s could not be cleared", connection->name); } /* Cleanup resources */ if (connection->pool) mmal_pool_destroy(connection->pool); if (connection->queue) mmal_queue_destroy(connection->queue); vcos_free(connection); return MMAL_SUCCESS; }
/* Release all internal resources */ static void mmal_port_clock_teardown(MMAL_PORT_T *port) { if (!port) return; mmal_queue_destroy(port->priv->module->queue); mmal_clock_destroy(port->priv->module->clock); }
void camera_release() { if(video_queue) mmal_queue_destroy(video_queue); if(video_pool) mmal_port_pool_destroy(preview_port,video_pool); }
CMMALRenderer::~CMMALRenderer() { CLog::Log(LOGDEBUG, "%s::%s", CLASSNAME, __func__); // shutdown thread mmal_queue_put(m_release_queue, &m_quit_packet); m_sync.Wait(); mmal_queue_destroy(m_release_queue); UnInit(); }
/** Destroy a previously created component */ static MMAL_STATUS_T splitter_component_destroy(MMAL_COMPONENT_T *component) { unsigned int i; for(i = 0; i < component->input_num; i++) if(component->input[i]->priv->module->queue) mmal_queue_destroy(component->input[i]->priv->module->queue); if(component->input_num) mmal_ports_free(component->input, component->input_num); for(i = 0; i < component->output_num; i++) if(component->output[i]->priv->module->queue) mmal_queue_destroy(component->output[i]->priv->module->queue); if(component->output_num) mmal_ports_free(component->output, component->output_num); vcos_free(component->priv->module); return MMAL_SUCCESS; }
static void CloseDecoder(decoder_t *dec) { decoder_sys_t *sys = dec->p_sys; MMAL_BUFFER_HEADER_T *buffer; if (!sys) return; if (sys->component && sys->component->control->is_enabled) mmal_port_disable(sys->component->control); if (sys->input && sys->input->is_enabled) mmal_port_disable(sys->input); if (sys->output && sys->output->is_enabled) mmal_port_disable(sys->output); if (sys->component && sys->component->is_enabled) mmal_component_disable(sys->component); if (sys->input_pool) mmal_pool_destroy(sys->input_pool); if (sys->output_format) mmal_format_free(sys->output_format); /* Free pictures which are decoded but have not yet been sent * out to the core */ while ((buffer = mmal_queue_get(sys->decoded_pictures))) { picture_t *pic = (picture_t *)buffer->user_data; picture_Release(pic); if (sys->output_pool) { buffer->user_data = NULL; buffer->alloc_size = 0; buffer->data = NULL; mmal_buffer_header_release(buffer); } } if (sys->decoded_pictures) mmal_queue_destroy(sys->decoded_pictures); if (sys->output_pool) mmal_pool_destroy(sys->output_pool); if (sys->component) mmal_component_release(sys->component); vlc_mutex_destroy(&sys->mutex); vlc_sem_destroy(&sys->sem); free(sys); bcm_host_deinit(); }
void CCameraOutput::Release() { if(OutputQueue) mmal_queue_destroy(OutputQueue); if(BufferPool) mmal_port_pool_destroy(BufferPort,BufferPool); if(Connection) mmal_connection_destroy(Connection); if(ResizerComponent) mmal_component_destroy(ResizerComponent); memset(this,0,sizeof(CCameraOutput)); }
/** Destroy a previously created component */ static MMAL_STATUS_T sdl_component_destroy(MMAL_COMPONENT_T *component) { MMAL_COMPONENT_MODULE_T *module = component->priv->module; if (module->audio_opened) SDL_CloseAudio(); SDL_QuitSubSystem(SDL_INIT_AUDIO); if(component->input_num) mmal_ports_free(component->input, 1); if(module->queue) mmal_queue_destroy(module->queue); vcos_free(module); return MMAL_SUCCESS; }
static av_cold int ffmmal_close_decoder(AVCodecContext *avctx) { MMALDecodeContext *ctx = avctx->priv_data; if (ctx->decoder) ffmmal_stop_decoder(avctx); mmal_component_destroy(ctx->decoder); ctx->decoder = NULL; mmal_queue_destroy(ctx->queue_decoded_frames); mmal_pool_destroy(ctx->pool_in); ffmmal_poolref_unref(ctx->pool_out); mmal_vc_deinit(); return 0; }
void CMMALRenderer::UnInitMMAL() { CSingleLock lock(m_sharedSection); CLog::Log(LOGDEBUG, "%s::%s pool(%p)", CLASSNAME, __func__, m_vout_input_pool); if (m_queue) { StopThread(true); mmal_queue_destroy(m_queue); m_queue = nullptr; } if (m_vout) { mmal_component_disable(m_vout); } if (m_vout_input) { mmal_port_flush(m_vout_input); mmal_port_disable(m_vout_input); } ReleaseBuffers(); if (m_vout_input_pool) { mmal_port_pool_destroy(m_vout_input, m_vout_input_pool); m_vout_input_pool = NULL; } m_vout_input = NULL; if (m_vout) { mmal_component_release(m_vout); m_vout = NULL; } m_src_rect.SetRect(0, 0, 0, 0); m_dst_rect.SetRect(0, 0, 0, 0); m_video_stereo_mode = RENDER_STEREO_MODE_OFF; m_display_stereo_mode = RENDER_STEREO_MODE_OFF; m_StereoInvert = false; m_format = RENDER_FMT_NONE; m_bConfigured = false; m_bMMALConfigured = false; }
/** Destroy a previously created component */ static MMAL_STATUS_T sdl_component_destroy(MMAL_COMPONENT_T *component) { MMAL_COMPONENT_MODULE_T *module = component->priv->module; SDL_Event event = {SDL_QUIT}; module->quit = MMAL_TRUE; SDL_PushEvent(&event); if(module->thread) SDL_WaitThread(module->thread, NULL); if(module->sdl_overlay) SDL_FreeYUVOverlay(module->sdl_overlay); if(module->sdl_surface) SDL_FreeSurface(module->sdl_surface); SDL_QuitSubSystem(SDL_INIT_VIDEO); if(component->input_num) mmal_ports_free(component->input, 1); if(module->queue) mmal_queue_destroy(module->queue); vcos_free(module); return MMAL_SUCCESS; }
static void Close(filter_t *filter) { filter_sys_t *sys = filter->p_sys; MMAL_BUFFER_HEADER_T *buffer; if (!sys) return; if (sys->component && sys->component->control->is_enabled) mmal_port_disable(sys->component->control); if (sys->input && sys->input->is_enabled) mmal_port_disable(sys->input); if (sys->output && sys->output->is_enabled) mmal_port_disable(sys->output); if (sys->component && sys->component->is_enabled) mmal_component_disable(sys->component); while ((buffer = mmal_queue_get(sys->filtered_pictures))) { picture_t *pic = (picture_t *)buffer->user_data; picture_Release(pic); } if (sys->filtered_pictures) mmal_queue_destroy(sys->filtered_pictures); if (sys->component) mmal_component_release(sys->component); vlc_mutex_destroy(&sys->mutex); vlc_mutex_destroy(&sys->buffer_cond_mutex); vlc_cond_destroy(&sys->buffer_cond); free(sys); bcm_host_deinit(); }
/* Destroys the pools of buffers used by the GL renderer. * @param state Pointer to the GL preview state. */ void raspitex_destroy(RASPITEX_STATE *state) { vcos_log_trace("%s", VCOS_FUNCTION); if (state->preview_pool) { mmal_pool_destroy(state->preview_pool); state->preview_pool = NULL; } if (state->preview_queue) { mmal_queue_destroy(state->preview_queue); state->preview_queue = NULL; } if (state->ops.destroy_native_window) state->ops.destroy_native_window(state); if (state->ops.close) state->ops.close(state); vcos_semaphore_delete(&state->capture.start_sem); vcos_semaphore_delete(&state->capture.completed_sem); }
bool CCameraOutput::Init(int width, int height, MMAL_COMPONENT_T* input_component, int input_port_idx, bool do_argb_conversion) { printf("Init camera output with %d/%d\n",width,height); Width = width; Height = height; MMAL_COMPONENT_T *resizer = 0; MMAL_CONNECTION_T* connection = 0; MMAL_STATUS_T status; MMAL_POOL_T* video_buffer_pool = 0; MMAL_QUEUE_T* output_queue = 0; //got the port we're receiving from MMAL_PORT_T* input_port = input_component->output[input_port_idx]; //check if user wants conversion to argb or the width or height is different to the input if(do_argb_conversion || width != input_port->format->es->video.width || height != input_port->format->es->video.height) { //create the resizing component, reading from the splitter output resizer = CreateResizeComponentAndSetupPorts(input_port,do_argb_conversion); if(!resizer) goto error; //create and enable a connection between the video output and the resizer input status = mmal_connection_create(&connection, input_port, resizer->input[0], MMAL_CONNECTION_FLAG_TUNNELLING | MMAL_CONNECTION_FLAG_ALLOCATION_ON_INPUT); if (status != MMAL_SUCCESS) { printf("Failed to create connection\n"); goto error; } status = mmal_connection_enable(connection); if (status != MMAL_SUCCESS) { printf("Failed to enable connection\n"); goto error; } //set the buffer pool port to be the resizer output BufferPort = resizer->output[0]; } else { //no convert/resize needed so just set the buffer pool port to be the input port BufferPort = input_port; } //setup the video buffer callback video_buffer_pool = EnablePortCallbackAndCreateBufferPool(BufferPort,VideoBufferCallback,3); if(!video_buffer_pool) goto error; //create the output queue output_queue = mmal_queue_create(); if(!output_queue) { printf("Failed to create output queue\n"); goto error; } ResizerComponent = resizer; BufferPool = video_buffer_pool; OutputQueue = output_queue; Connection = connection; return true; error: if(output_queue) mmal_queue_destroy(output_queue); if(video_buffer_pool) mmal_port_pool_destroy(resizer->output[0],video_buffer_pool); if(connection) mmal_connection_destroy(connection); if(resizer) mmal_component_destroy(resizer); return false; }
int main(int argc, char **argv) { MMAL_STATUS_T status = MMAL_EINVAL; MMAL_COMPONENT_T *decoder = 0; MMAL_POOL_T *pool_in = 0, *pool_out = 0; unsigned int count; if (argc < 2) { fprintf(stderr, "invalid arguments\n"); return -1; } #ifndef WIN32 // TODO verify that we dont really need to call bcm_host_init bcm_host_init(); #endif vcos_semaphore_create(&context.semaphore, "example", 1); SOURCE_OPEN(argv[1]); /* Create the decoder component. * This specific component exposes 2 ports (1 input and 1 output). Like most components * its expects the format of its input port to be set by the client in order for it to * know what kind of data it will be fed. */ status = mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_DECODER, &decoder); CHECK_STATUS(status, "failed to create decoder"); /* Set format of video decoder input port */ MMAL_ES_FORMAT_T *format_in = decoder->input[0]->format; format_in->type = MMAL_ES_TYPE_VIDEO; format_in->encoding = MMAL_ENCODING_H264; format_in->es->video.width = 1280; format_in->es->video.height = 720; format_in->es->video.frame_rate.num = 30; format_in->es->video.frame_rate.den = 1; format_in->es->video.par.num = 1; format_in->es->video.par.den = 1; /* If the data is known to be framed then the following flag should be set: * format_in->flags |= MMAL_ES_FORMAT_FLAG_FRAMED; */ SOURCE_READ_CODEC_CONFIG_DATA(codec_header_bytes, codec_header_bytes_size); status = mmal_format_extradata_alloc(format_in, codec_header_bytes_size); CHECK_STATUS(status, "failed to allocate extradata"); format_in->extradata_size = codec_header_bytes_size; if (format_in->extradata_size) memcpy(format_in->extradata, codec_header_bytes, format_in->extradata_size); status = mmal_port_format_commit(decoder->input[0]); CHECK_STATUS(status, "failed to commit format"); /* Display the output port format */ MMAL_ES_FORMAT_T *format_out = decoder->output[0]->format; fprintf(stderr, "%s\n", decoder->output[0]->name); fprintf(stderr, " type: %i, fourcc: %4.4s\n", format_out->type, (char *)&format_out->encoding); fprintf(stderr, " bitrate: %i, framed: %i\n", format_out->bitrate, !!(format_out->flags & MMAL_ES_FORMAT_FLAG_FRAMED)); fprintf(stderr, " extra data: %i, %p\n", format_out->extradata_size, format_out->extradata); fprintf(stderr, " width: %i, height: %i, (%i,%i,%i,%i)\n", format_out->es->video.width, format_out->es->video.height, format_out->es->video.crop.x, format_out->es->video.crop.y, format_out->es->video.crop.width, format_out->es->video.crop.height); /* The format of both ports is now set so we can get their buffer requirements and create * our buffer headers. We use the buffer pool API to create these. */ decoder->input[0]->buffer_num = decoder->input[0]->buffer_num_min; decoder->input[0]->buffer_size = decoder->input[0]->buffer_size_min; decoder->output[0]->buffer_num = decoder->output[0]->buffer_num_min; decoder->output[0]->buffer_size = decoder->output[0]->buffer_size_min; pool_in = mmal_pool_create(decoder->input[0]->buffer_num, decoder->input[0]->buffer_size); pool_out = mmal_pool_create(decoder->output[0]->buffer_num, decoder->output[0]->buffer_size); /* Create a queue to store our decoded video frames. The callback we will get when * a frame has been decoded will put the frame into this queue. */ context.queue = mmal_queue_create(); /* Store a reference to our context in each port (will be used during callbacks) */ decoder->input[0]->userdata = (void *)&context; decoder->output[0]->userdata = (void *)&context; /* Enable all the input port and the output port. * The callback specified here is the function which will be called when the buffer header * we sent to the component has been processed. */ status = mmal_port_enable(decoder->input[0], input_callback); CHECK_STATUS(status, "failed to enable input port"); status = mmal_port_enable(decoder->output[0], output_callback); CHECK_STATUS(status, "failed to enable output port"); /* Component won't start processing data until it is enabled. */ status = mmal_component_enable(decoder); CHECK_STATUS(status, "failed to enable component"); /* Start decoding */ fprintf(stderr, "start decoding\n"); /* This is the main processing loop */ for (count = 0; count < 500; count++) { MMAL_BUFFER_HEADER_T *buffer; /* Wait for buffer headers to be available on either of the decoder ports */ vcos_semaphore_wait(&context.semaphore); /* Send data to decode to the input port of the video decoder */ if ((buffer = mmal_queue_get(pool_in->queue)) != NULL) { SOURCE_READ_DATA_INTO_BUFFER(buffer); if (!buffer->length) break; fprintf(stderr, "sending %i bytes\n", (int)buffer->length); status = mmal_port_send_buffer(decoder->input[0], buffer); CHECK_STATUS(status, "failed to send buffer"); } /* Get our decoded frames */ while ((buffer = mmal_queue_get(context.queue)) != NULL) { /* We have a frame, do something with it (why not display it for instance?). * Once we're done with it, we release it. It will automatically go back * to its original pool so it can be reused for a new video frame. */ fprintf(stderr, "decoded frame\n"); mmal_buffer_header_release(buffer); } /* Send empty buffers to the output port of the decoder */ while ((buffer = mmal_queue_get(pool_out->queue)) != NULL) { status = mmal_port_send_buffer(decoder->output[0], buffer); CHECK_STATUS(status, "failed to send buffer"); } } /* Stop decoding */ fprintf(stderr, "stop decoding\n"); /* Stop everything. Not strictly necessary since mmal_component_destroy() * will do that anyway */ mmal_port_disable(decoder->input[0]); mmal_port_disable(decoder->output[0]); mmal_component_disable(decoder); error: /* Cleanup everything */ if (decoder) mmal_component_destroy(decoder); if (pool_in) mmal_pool_destroy(pool_in); if (pool_out) mmal_pool_destroy(pool_out); if (context.queue) mmal_queue_destroy(context.queue); SOURCE_CLOSE(); vcos_semaphore_delete(&context.semaphore); return status == MMAL_SUCCESS ? 0 : -1; }