void *ffmpegDecode(void *filterParams) { struct ffmpegDecode *params = (struct ffmpegDecode *)filterParams; ///////////////// // Decode Loop // ///////////////// AVPacket packet; int currentFrame = 1; while(av_read_frame(params->formatContext, &packet) >= 0) { if(packet.stream_index == params->videoStream) { avcodec_decode_video2( params->codecContext, params->frame, ¶ms->frameFinished, &packet); if(params->frameFinished) { currentFrame++; if(currentFrame % 500 == 0) MkvsynthMessage("Finished Frame %i", currentFrame); sws_scale ( params->resizeContext, (uint8_t const * const *)params->frame->data, params->frame->linesize, 0, params->codecContext->height, params->rgbFrame->data, params->rgbFrame->linesize); params->outputPayload = malloc(getBytes(params->output->metaData)); memcpy(params->outputPayload, params->rgbFrame->data[0], getBytes(params->output->metaData)); putFrame(params->output, params->outputPayload); } } av_free_packet(&packet); } //////////////////////// // Stream Termination // //////////////////////// putFrame(params->output, NULL); ///////////////////////// // Memory Deallocation // ///////////////////////// av_free(params->frame); av_free(params->rgbFrame); av_free(params->rgbFramePayload); avcodec_close(params->codecContext); avformat_close_input(¶ms->formatContext); free(params); return NULL; }
void *testingGradient(void *filterParams) { struct TestingGradientParams *params = (struct TestingGradientParams*)filterParams; int i, j; for(i = 0; i < params->frames; i++) { uint8_t *payload = malloc(getBytes(params->output->metaData)); uint16_t *shortPayload = (uint16_t *)payload; int bytes = getBytes(params->output->metaData); for(j = 0; j < bytes / 2; j++) shortPayload[j] = (j + i) % 65536; putFrame(params->output, payload); } putFrame(params->output, NULL); free(params); return NULL; }
status_t V4L2VideoNode::putFrame(struct v4l2_buffer const *buf) { int index = buf->index; LOG2("@%s, index:%d, addr:%p name:%s", __FUNCTION__, buf->index, (void *)buf->m.userptr, mName.string()); mBufferPool.editItemAt(index).vbuffer.m.userptr = buf->m.userptr; // reserved2 indicates whether this frame requires per-frame parameters mBufferPool.editItemAt(index).vbuffer.reserved2 = buf->reserved2; if (putFrame(index) < 0) return UNKNOWN_ERROR; return NO_ERROR; }