int vpuInit(void)
{
	int err;
	vpu_versioninfo ver;

	err = vpu_Init(NULL);
	if (err) {
		err_msg("VPU Init Failure.\n");
		return -1;
	}

	err = vpu_GetVersionInfo(&ver);
	if (err) {
		err_msg("Cannot get version info, err:%d\n", err);
		vpu_UnInit();
		return -1;
	}

	info_msg("VPU firmware version: %d.%d.%d_r%d\n",
			ver.fw_major, ver.fw_minor,
			ver.fw_release, ver.fw_code);
	info_msg("VPU library version: %d.%d.%d\n", ver.lib_major,
			ver.lib_minor, ver.lib_release);

	info_msg("VPU: Init framebuffer pool\n");
	framebuf_init();

	info_msg("VPU was successfully initialized\n\n");

	return 0;
}
Example #2
0
vpu_t::vpu_t(void)
	: worked_( false )
{
        RetCode rc = vpu_Init(0);
	worked_ = (RETCODE_SUCCESS == rc);
	if( !worked_ )
                fprintf(stderr, "Error %d initializing VPU\n", rc );
}
Example #3
0
int vpu_init(void)
{
	vpu_versioninfo ver;

	framebuf_init();
	vpu_Init(NULL);
	vpu_GetVersionInfo(&ver);

	pthread_mutex_init(&vpu_mutex, NULL);
	fprintf(stderr, "VPU firmware version: %d.%d.%d\n", ver.fw_major, ver.fw_minor, ver.fw_release);
	fprintf(stderr, "VPU library version: %d.%d.%d\n", ver.lib_major, ver.lib_minor, ver.lib_release);
	return 0;
}
iMX27RtpInterface::iMX27RtpInterface(SkypeVideoRTPInterfaceCb *pCallback) :
	m_BitRate(0),
	m_pCb(pCallback),
	m_ReceiveBStat(3000000),
	m_SendBStat(3000000),
	m_KeyFrameRequested(0),
	m_RecordingStarted(false),
	m_ReceivePcnt(0),
	m_SendPcnt(0),
	m_ReceiveFcnt(0),
	m_SendFcnt(0),
	m_PayloadFormat(FORMAT_FRAMES),
	m_pSendWrapper(NULL),
	m_pReceiveWrapper(NULL)
{
	RTP_FUNCLOG;
	if (!Configuration::GetCfg()->IsInitialized())
		Configuration::GetCfg()->Init("RTPTestEngine.conf");
	m_PayloadFormat = (PayloadFmtType)Configuration::GetCfg()->GetIntVal("PayloadFormat");
#ifndef MINIMAL_MODE
	if ((Configuration::GetCfg()->GetIntVal("SendPacketsFromAnxbFile") || Configuration::GetCfg()->GetIntVal("SendPacketsFromPcapFile")) && !Configuration::GetCfg()->GetIntVal("RenderVideo")) {
		return;
	}
	vpu_versioninfo vpuVersion;
	RetCode ret = RETCODE_SUCCESS;
	pMutexLock scopedLock(m_VpuMutex); // Scoped lock on VPU mutex

	// Initialize VPU hardware and data structures/resources
	ret = vpu_Init(NULL);
	if (ret != RETCODE_SUCCESS) {
		FATAL("%s: vpu_Init() failed. Return code: %d", ret);
	}

	// Read out the version information running on the system
	ret = vpu_GetVersionInfo(&vpuVersion);
	scopedLock.mutex.Release(); // VPU access - unlock
	if (ret != RETCODE_SUCCESS) {
		if (ret != RETCODE_NOT_INITIALIZED) {
			vpu_UnInit();
		}
		FATAL("vpu_GetVersionInfo() failed. Return code: %d\n", ret);
	}
	RTP_DBG("i.MX%x Silicon Revision: %x.%x", mxc_cpu(), ((mxc_cpu_rev() >> 4) & 0xF), (mxc_cpu_rev() & 0xF));
	RTP_DBG("i.MX%x VPU Firmware version: %d.%d.%d", mxc_cpu(), vpuVersion.fw_major, vpuVersion.fw_minor, vpuVersion.fw_release);
	RTP_DBG("i.MX%x VPU Library version: %d.%d.%d", mxc_cpu(), vpuVersion.lib_major, vpuVersion.lib_minor, vpuVersion.lib_release);
#endif
}
Example #5
0
static void enc_init(MSFilter *f){
	EncData *d=ms_new(EncData,1);
	d->enc=NULL;
	d->keyframe_int=10; /*10 seconds */
	d->mode=0;
	d->framenum=0;
	d->generate_keyframe=FALSE;
	d->packer=NULL;
	d->vconf_list = &x264_conf_list[0];
	d->vconf = ms_video_find_best_configuration_for_bitrate(d->vconf_list, 384000);
	d->flv = newFLVStream(2*1024*1024);
	d->enc = ms_new0(struct x264_encode,1);
	f->data=d;
	
    if(vpu_Init(NULL)!=0)
    {
        ms_error("MSH264Enc: VPU Init error\n");
        return ;
    }

    d->mem_desc.size = STREAM_BUF_SIZE;
    if(IOGetPhyMem(&d->mem_desc)!=0) {
        ms_error("MSH264Enc: Unable to obtain physical memory\n");
        return ;
    }

    /* mmap that physical buffer */
    d->enc->virt_bsbuf_addr = IOGetVirtMem(&d->mem_desc);
    if (d->enc->virt_bsbuf_addr <= 0) {
        IOFreePhyMem(&d->mem_desc);
        ms_error("MSH264Enc: Unable to map physical memory\n");
        return ;
    }

    d->enc->phy_bsbuf_addr = d->mem_desc.phy_addr;
}
Example #6
0
bool video_imx_init() {
  return vpu_Init(NULL) == RETCODE_SUCCESS;
}
main(int argc, char *argv[])
#endif
{
	int err, nargc, i, ret = 0;
	char *pargv[32] = {0}, *dbg_env;
	pthread_t sigtid;
#ifdef COMMON_INIT
	vpu_versioninfo ver;
#endif
	int ret_thr;

#ifndef COMMON_INIT
	srand((unsigned)time(0)); /* init seed of rand() */
#endif

	dbg_env=getenv("VPU_TEST_DBG");
	if (dbg_env)
		vpu_test_dbg_level = atoi(dbg_env);
	else
		vpu_test_dbg_level = 0;

	err = parse_main_args(argc, argv);
	if (err) {
		goto usage;
	}

	if (!instance) {
		goto usage;
	}

	info_msg("VPU test program built on %s %s\n", __DATE__, __TIME__);
#ifndef _FSL_VTS_
	sigemptyset(&sigset);
	sigaddset(&sigset, SIGINT);
	pthread_sigmask(SIG_BLOCK, &sigset, NULL);
	pthread_create(&sigtid, NULL, (void *)&signal_thread, NULL);
#endif

#ifdef COMMON_INIT
	err = vpu_Init(NULL);
	if (err) {
		err_msg("VPU Init Failure.\n");
		return -1;
	}

	err = vpu_GetVersionInfo(&ver);
	if (err) {
		err_msg("Cannot get version info, err:%d\n", err);
		vpu_UnInit();
		return -1;
	}

	info_msg("VPU firmware version: %d.%d.%d_r%d\n", ver.fw_major, ver.fw_minor,
						ver.fw_release, ver.fw_code);
	info_msg("VPU library version: %d.%d.%d\n", ver.lib_major, ver.lib_minor,
						ver.lib_release);
#else
	// just to enable cpu_is_xx() to be used in command line parsing
	err = vpu_Init(NULL);
	if (err) {
		err_msg("VPU Init Failure.\n");
		return -1;
	}

	vpu_UnInit();

#endif

	if (instance > 1) {
		for (i = 0; i < instance; i++) {
#ifndef COMMON_INIT
			/* sleep roughly a frame interval to test multi-thread race
			   especially vpu_Init/vpu_UnInit */
			usleep((int)(rand()%ONE_FRAME_INTERV));
#endif
			if (using_config_file == 0) {
				get_arg(input_arg[i].line, &nargc, pargv);
				err = parse_args(nargc, pargv, i);
				if (err) {
					vpu_UnInit();
					goto usage;
				}
			}

			if (check_params(&input_arg[i].cmd,
						input_arg[i].mode) == 0) {
				if (open_files(&input_arg[i].cmd) == 0) {
					if (input_arg[i].mode == DECODE) {
					     pthread_create(&input_arg[i].tid,
						   NULL,
						   (void *)&decode_test,
						   (void *)&input_arg[i].cmd);
					} else if (input_arg[i].mode ==
							ENCODE) {
					     pthread_create(&input_arg[i].tid,
						   NULL,
						   (void *)&encode_test,
						   (void *)&input_arg[i].cmd);
					}
				}
			}

		}
	} else {
		if (using_config_file == 0) {
			get_arg(input_arg[0].line, &nargc, pargv);
			err = parse_args(nargc, pargv, 0);
			if (err) {
				vpu_UnInit();
				goto usage;
			}
		}

		if (check_params(&input_arg[0].cmd, input_arg[0].mode) == 0) {
			if (open_files(&input_arg[0].cmd) == 0) {
				if (input_arg[0].mode == DECODE) {
					ret = decode_test(&input_arg[0].cmd);
				} else if (input_arg[0].mode == ENCODE) {
					ret = encode_test(&input_arg[0].cmd);
                                } else if (input_arg[0].mode == TRANSCODE) {
                                        ret = transcode_test(&input_arg[0].cmd);
				}

				close_files(&input_arg[0].cmd);
			} else {
				ret = -1;
			}
		} else {
			ret = -1;
		}

		if (input_arg[0].mode == LOOPBACK) {
			encdec_test(&input_arg[0].cmd);
		}
	}

	if (instance > 1) {
		for (i = 0; i < instance; i++) {
			if (input_arg[i].tid != 0) {
				pthread_join(input_arg[i].tid, (void *)&ret_thr);
				if (ret_thr)
					ret = -1;
				close_files(&input_arg[i].cmd);
			}
		}
	}

#ifdef COMMON_INIT
	vpu_UnInit();
#endif
	return ret;

usage:
	info_msg("\n%s", usage);
	return -1;
}
int main(void){
    int ret = 0, i;
    vpu_versioninfo ver;            // vpu version information
    vpu_mem_desc bit_stream_buf;    // input bit stream allocated memory
    vpu_mem_desc source_buf;        // source buffer allocated memory
    FrameBuffer source_frame;       // source framebuffer

    // VPU specific members defined in vpu_lib.h
    EncHandle *handle = malloc(sizeof(EncHandle));
    EncOpenParam *encOP = malloc(sizeof(EncOpenParam));
    EncInitialInfo *initialInfo = malloc(sizeof(EncInitialInfo));
    EncOutputInfo *outputInfo = malloc(sizeof(EncOutputInfo));
    EncParam *encParam = malloc(sizeof(EncParam));

    // Set allocated memory to zero
    memset (initialInfo, 0, sizeof (EncInitialInfo));
    memset (encParam, 0, sizeof (EncParam));
    memset (encOP, 0, sizeof (EncOpenParam));
    memset (outputInfo, 0, sizeof (EncOutputInfo));
    memset (&bit_stream_buf, 0, sizeof (vpu_mem_desc));

    // Init VPU
    if(vpu_Init (NULL) < 0) {
        printf(">> failed to call vpu_Init()\n");
        ret = -1;
        goto free;
    }
    vpu_GetVersionInfo(&ver);
    printf("VPU Version: firmware %d.%d.%d; libvpu: %d.%d.%d \n", ver.fw_major,
              ver.fw_minor, ver.fw_release, ver.lib_major, ver.lib_minor,
              ver.lib_release);

    // Allocate input buffer
    bit_stream_buf.size = BUFF_FILL_SIZE;
    IOGetPhyMem (&bit_stream_buf);
    if(bit_stream_buf.phy_addr == 0) {
        printf(">> error allocating encoder bitstream buffer\n");
        ret = -1;
        goto free;
    }
    IOGetVirtMem (&bit_stream_buf);

    // Set up encoder operation parameters
    encOP->bitstreamBuffer = bit_stream_buf.phy_addr;
    encOP->bitstreamBufferSize = BUFF_FILL_SIZE;
    encOP->bitstreamFormat = STD_AVC;
    encOP->gopSize = DEFAULT_GOP_SIZE;
    encOP->rcIntraQp = VPU_DEFAULT_H264_QP;
    encOP->userQpMaxEnable = 1;
    encOP->userQpMax = H264_QP_MAX;
    encOP->userQpMinEnable = 1;
    encOP->userQpMin = H264_QP_MIN;
    encOP->frameRateInfo = DEFAULT_FRAME_RATE;
    encOP->picWidth = DEFAULT_WIDTH;
    encOP->picHeight = DEFAULT_HEIGHT;
    encOP->ringBufferEnable = 0;

    // Open encoder
    vpu_EncOpen (handle, encOP);

    // Configure IRAM memory
    SearchRamParam search_pa = { 0 };
    iram_t iram;
    int ram_size;
    memset (&iram, 0, sizeof (iram_t));
    ram_size = ((DEFAULT_WIDTH + 15) & ~15) * 36 + 2048;
    IOGetIramBase (&iram);
    if ((iram.end - iram.start) < ram_size)
      ram_size = iram.end - iram.start;
    search_pa.searchRamAddr = iram.start;
    search_pa.SearchRamSize = ram_size;
    vpu_EncGiveCommand (*handle, ENC_SET_SEARCHRAM_PARAM, &search_pa);

    vpu_EncGetInitialInfo (*handle, initialInfo);

    // Disable rotation/mirroring
    vpu_EncGiveCommand (*handle, DISABLE_ROTATION, 0);
    vpu_EncGiveCommand (*handle, DISABLE_MIRRORING, 0);

    // Allocate memory for source frame buffer
    source_buf.size = DEFAULT_WIDTH * DEFAULT_HEIGHT * 3/2;
    IOGetPhyMem (&source_buf);
    if(source_buf.phy_addr == 0) {
        printf(">> error allocating source frame buffer\n");
        ret = -1;
        goto close;
    }
    IOGetVirtMem(&source_buf);
    source_frame.strideY = DEFAULT_WIDTH;
    source_frame.strideC = DEFAULT_WIDTH >> 1;
    source_frame.bufY = source_buf.phy_addr;
    source_frame.bufCb = source_frame.bufY + DEFAULT_WIDTH * DEFAULT_HEIGHT;
    source_frame.bufCr = source_frame.bufCb + (DEFAULT_WIDTH * DEFAULT_HEIGHT >> 2);
    printf("source frame buffer %i phys(%p) virt(%p)\n", 0, source_buf.phy_addr, source_buf.virt_uaddr);

    // Get number of destination frame buffers and allocate
    int num = initialInfo->minFrameBufferCount;
    printf("number of needed frame buffers: %d\n", num);

    vpu_mem_desc *framedesc = malloc(sizeof(vpu_mem_desc) * num);
    FrameBuffer *frame = malloc(sizeof(FrameBuffer) * num);
    memset (framedesc, 0, (sizeof (vpu_mem_desc) * num));
    memset (frame, 0, (sizeof (FrameBuffer) * num));

    // Allocate each destination frame buffer
    for (i = 0; i < num; i++) {
        framedesc[i].size = DEFAULT_WIDTH * DEFAULT_HEIGHT * 3/2;
        IOGetPhyMem (&(framedesc[i]));
        if (framedesc[i].phy_addr == 0) {
            printf(">> error allocating destination frame buffers\n");
            ret = -1;
            goto frame;
        }
        IOGetVirtMem (&(framedesc[i]));
        frame[i].strideY = DEFAULT_WIDTH;
        frame[i].strideC = DEFAULT_WIDTH >> 1;

        frame[i].bufY = framedesc[i].phy_addr;
        frame[i].bufCb = frame[i].bufY + (DEFAULT_WIDTH * DEFAULT_HEIGHT);
        frame[i].bufCr = frame[i].bufCb + ((DEFAULT_WIDTH * DEFAULT_HEIGHT) >> 2);
        printf("destination frame buffer %i phys(%p) virt(%p)\n", i, framedesc[i].phy_addr, framedesc[i].virt_uaddr);
    }

    // Register allocated frame buffers
    vpu_EncRegisterFrameBuffer (*handle, frame, num, DEFAULT_WIDTH, DEFAULT_WIDTH, 0, 0, NULL);

    encParam->forceIPicture = 0;
    encParam->skipPicture = 0;
    encParam->enableAutoSkip = 0;
    encParam->quantParam = VPU_DEFAULT_H264_QP;

    // Get encoding Headers
    EncHeaderParam enchdr_param = { 0 };
    uint8_t *ptr;
    uint8_t *header[NUM_INPUT_BUF];
    uint32_t headersize[NUM_INPUT_BUF];      // size for each header element

    enchdr_param.headerType = SPS_RBSP;
    vpu_EncGiveCommand (*handle, ENC_PUT_AVC_HEADER, &enchdr_param);
    headersize[SPS_HDR] = enchdr_param.size;
    header[SPS_HDR] = malloc (enchdr_param.size);
    if (header[SPS_HDR] == NULL) {
      printf (">> error in allocating memory for SPS_RBSP Header" );
      ret = -1;
      goto frame;
    }
    ptr = (uint8_t*) (bit_stream_buf.virt_uaddr + enchdr_param.buf - bit_stream_buf.phy_addr);
    memcpy (header[SPS_HDR], ptr, enchdr_param.size);
    printf("header[SPS_HDR]: %d bytes\n",  headersize[SPS_HDR]);

    enchdr_param.headerType = PPS_RBSP;
    vpu_EncGiveCommand (*handle, ENC_PUT_AVC_HEADER, &enchdr_param);
    headersize[PPS_HDR] = enchdr_param.size;
    header[PPS_HDR] = malloc (enchdr_param.size);
    if (header[PPS_HDR] == NULL) {
      printf (">> error in allocating memory for PPS_HDR Header" );
      ret = -1;
      goto frame;
    }
    ptr = (uint8_t*) (bit_stream_buf.virt_uaddr + enchdr_param.buf - bit_stream_buf.phy_addr);
    memcpy (header[PPS_HDR], ptr, enchdr_param.size);
    printf("header[PPS_HDR]: %d bytes\n",  headersize[PPS_HDR]);

    // Open output file and write headers
    FILE *out = fopen ("BigBuckBunny_640x360_small.h264", "w"); //stdout
    fwrite(header[SPS_HDR], 1, headersize[SPS_HDR], out);
    fwrite(header[PPS_HDR], 1, headersize[PPS_HDR], out);

    // Copy and Encode
    FILE *in = fopen ("BigBuckBunny_640x360_small.yuv", "r");
    while(fread((void*) source_buf.virt_uaddr, 1, DEFAULT_WIDTH * DEFAULT_HEIGHT * 3/2, in)) {
        encParam->sourceFrame = &source_frame;

        // Encode a single frame
        vpu_EncStartOneFrame (*handle, encParam);
        while(vpu_IsBusy()) {
            vpu_WaitForInt (100);
        }

        vpu_EncGetOutputInfo (*handle, outputInfo);

        // Write bitstream to file
        fwrite((void*) bit_stream_buf.virt_uaddr, 1, outputInfo->bitstreamSize, out);
    }
    printf("\n");
    fclose(in);
    fclose(out);
frame:
    for (i = 0; i < num; i++) {
        IOFreeVirtMem(&(framedesc[i]));
        IOFreePhyMem(&(framedesc[i]));
    }
    free(frame);
    free(framedesc);
close:
    // Close encoder
    vpu_EncClose (*handle);

    // Free alocated input buffer
    IOFreeVirtMem (&bit_stream_buf);
    IOFreePhyMem (&bit_stream_buf);
free:
    free(encOP);
    free(initialInfo);
    free(outputInfo);
    free(encParam);
    free(handle);
    return ret;
}