/*****************************************************************************
 Prototype    : jpg_encoder_create
 Description  : create jpeg encoder
 Input        : ParamsMngHandle hParamsMng  
 Output       : None
 Return Value : 
 Calls        : 
 Called By    : 
 
  History        :
  1.Date         : 2012/3/20
    Author       : Sun
    Modification : Created function

*****************************************************************************/
EncoderHandle jpg_encoder_create(IN EncoderParams *encParams, IN UploadParams *uploadParams, IN pthread_mutex_t *mutex)
{
	
	EncoderAttrs		encAttrs;
	JpgEncInitParams	jpgEncInitParams;
	EncoderHandle		hJpgEncoder;

	jpgEncInitParams.maxWidth = IMG_MAX_WIDTH;
	jpgEncInitParams.maxHeight = IMG_MAX_HEIGHT;
	jpgEncInitParams.size = sizeof(JpgEncInitParams);
	
	encAttrs.name = IMG_ENC_NAME;
	encAttrs.msgName = MSG_IMG_ENC;
	encAttrs.dstName = NULL;
	encAttrs.encFxns = &JPGENC_ALG_FXNS;
	encAttrs.encInitParams = &jpgEncInitParams;
	encAttrs.encOps = &c_jpgEncOps;
	encAttrs.poolBufNum = IMG_ENC_POOL_BUF_NUM;
	encAttrs.saveRootPath = SD0_MNT_PATH;
	encAttrs.mutex = mutex;
	encAttrs.encBufSize = IMG_MAX_WIDTH * IMG_MAX_HEIGHT * 8 / 10;

	/* display milisecod for jpeg img */
	encParams->osdInfo.flags |= CAM_OSD_FLAG_MILISEC_EN;

	hJpgEncoder = encoder_create(&encAttrs, encParams, uploadParams);
	if(!hJpgEncoder) {
		ERR("create jpg encoder error...");
		return NULL;
	}

	return hJpgEncoder;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	srand(time(NULL));

	struct timespec start, end;
	double cpu_time = 0.0;
	if (argc < 3) {
		fprintf(stdout, "Usage: %s [file_name] [decode file]\n", argv[0]);
	}

	FILE *fp;
	fp = fopen(argv[1], "r");

	FILE *fb;
	fb = fopen(argv[2], "w");

	uint32_t symbol_size = 16*70;//16 bytes = 128 bits for SIMD
	struct encoder *encoder = encoder_create(symbol_size);

	/*int32_t i;
	for (i = 0; i < encoder->block_size; i++) {
		encoder->block[i] = (uint8_t) rand();
	}*/

	uint8_t *payload = calloc(encoder->symbol_size + 1, sizeof(uint8_t));

	clock_gettime(CLOCK_REALTIME, &start);
	while (!feof(fp)) {
		int number = fread(encoder->block, sizeof(char), symbol_size, fp);

		struct decoder *decoder = decoder_create(symbol_size);

		/* systematic */
		int o;
		for (o = 0; o < encoder->symbols; o++) {
			encoder->flag = 1;
			encoder_write_payload(encoder, payload);

			/* with 75% probability to trigger systematic */
			if ((rand() % 4) != 0) {
				decoder_read_payload(decoder, payload);
				printf("decoder rank = %u\n", decoder->rank);
				decoder_print(decoder);
			}
		}

		/* rlnc */
		while (decoder->rank < 8) {
			encoder->flag = 0;
			encoder_write_payload(encoder, payload);
			decoder_read_payload(decoder, payload);
			//printf("decoder rank = %u\n", decoder->rank);
			//decoder_print(decoder);
		}

		printf("\ndecoding block...\n\n");
		decoder_decode_block(decoder);
		decoder_print(decoder);

		printf("\ndecode finished\n\n");

		if (memcmp(decoder->block, encoder->block, decoder->symbols * decoder->symbol_size) == 0)
			printf("decode success\n");
		else
			printf("decode fail\n");

		fwrite(decoder->block, sizeof(char), number, fb);
		memset(payload, 0, encoder->symbol_size + 1);
		decoder_flush(decoder);
		decoder_destroy(&decoder);
	}
	clock_gettime(CLOCK_REALTIME, &end);
	cpu_time = diff_in_second(start, end);
	printf("execution time of transmission : %lf sec\n", cpu_time);

	fclose(fb);
	free(payload);
	encoder_destroy(&encoder);
	return 0;
}
//SET UP ENCODER
jstring Java_edu_sdsu_server_util_EncoderActivationInterface_encoderStart
  	(JNIEnv *env, jclass cls, /*jstring outfile,*/ jint width,
  			jint height, jint frame_rate, jint bps, jint variableRate) {

	//Open a socket
	g_sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if(g_sockfd <= 0)
	{
		__android_log_print(ANDROID_LOG_ERROR, "DWRIGHT--UDPSEND", "Failed to create socket");
		return env->NewStringUTF("Failed to open socket");
	}

	//Bind to port on host side
	sockaddr_in address;

	address.sin_family = AF_INET;
	address.sin_addr.s_addr = INADDR_ANY;
	address.sin_port = htons((unsigned short) PORT);

	int bound = bind(g_sockfd, (sockaddr*) &address, sizeof(address));
	if(bound < 0)
	{
		__android_log_print(ANDROID_LOG_ERROR, "DWRIGHT--UDPSEND", "Failed to bind to socket: %s", strerror(errno));
		close(g_sockfd);
		return env->NewStringUTF("Failed to open socket");
	}
	else
	{
		__android_log_print(ANDROID_LOG_ERROR, "DWRIGHT--UDPSEND", "Bound to socket!: %s", inet_ntoa(address.sin_addr));
	}

	//Set non-blocking
	int nonBlocking = 1;
	if(fcntl(g_sockfd, F_SETFL, O_NONBLOCK, nonBlocking) == -1)
	{
		__android_log_print(ANDROID_LOG_ERROR, "DWRIGHT--UDPSEND", "Failed to set nonblocking");
		close(g_sockfd);
		return env->NewStringUTF("Failed to open socket");
	}

	//Set up encoder params
	g_encoder = NULL;
	g_timeStamp = 0;

	g_params.frameWidth = width;
	g_params.frameHeight = height;
	g_params.frameRate = frame_rate;//30; //Specify frame rate at 30fps
	g_params.rateControl = 3;//2;
	//Need better bitrate calculation
	g_params.bitRate = bps == 0 ? width * height * 3 : bps;
	g_params.codecString = NULL;

	//Flag to vary bitrate
	variable_rate = variableRate;

	//const char *outputFileName = env->GetStringUTFChars(outfile,0);
	//__android_log_print(ANDROID_LOG_ERROR,"QCOMOMXINTERFACE", "FRAME WxH = %dx%d TO %s", width, height, outputFileName);

	//f = fopen(outputFileName, "wb");

	int status = 0;
	g_encoder = encoder_create(&status, &g_params);
	if (g_encoder == NULL) {
		return env->NewStringUTF(resultDescription(status));
	}

	// The input semaphore is important; by using it, the procedure for
	// feeding the component will wait for an available input buffer when
	// the component is busy.
	//
	omx_setup_input_semaphore(g_encoder);

//#if USE_BITRATE_ENCODING_TEST
//	// Uses the variable bitrate encoding as given in BitrateTest.cpp.  The
//	// bitrate setting in g_params is ignored in this version.
//	omx_interface_register_output_callback(g_encoder, handleOutputEncodedToFile, f);
//
//#else
//	// Default implementation uses arbitrary bitrate of width * height * 3 kbps
//	omx_interface_register_output_callback(g_encoder, handleOutputEncoded, f);
//
//#endif

	omx_interface_register_output_callback(g_encoder, pipeEncodedtoPacket, NULL);

	// Initialize the component and set to the execution state, waiting
	// for frames from the camera.
	status = omx_interface_init(g_encoder);

//	status = omx_interface_set_region_of_interest(g_encoder, 0);
//	if(status != 0)
//	{
//		__android_log_print(ANDROID_LOG_ERROR, "DWRIGHT--UDPSEND", "Failed to set region of interest (input)");
//
//	}
//	else
//	{
//		status = omx_interface_set_region_of_interest(g_encoder, 1);
//		if(status != 0)
//		{
//			__android_log_print(ANDROID_LOG_ERROR, "DWRIGHT--UDPSEND", "Failed to set region of interest (output)");
//
//		}
//	}

	// Return the state
	const char *result = resultDescription(status);
	return env->NewStringUTF(result);
}