⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tskmpeg2.c.bak

📁 用于dm642中的mpeg2的解码任务
💻 BAK
字号:
/*
 *	Copyright 2007 by EECS Peking University
 */
// MPEG2 decoder
#include <std.h>
#include <stdio.h>
#include <csl.h>
#include <csl_cache.h>
#include <csl_dat.h>
#include <chan.h>
#include <scom.h>
#include <utl.h>
#include "fvid.h"
#include "cellmpeg2dec.h"
#include "appmain.h"
#include "appThreads.h"
#include "tskMpeg2.h"          
#include "impeg2vdec.h"
#include "appBiosObjects.h"

/*Input requirements for MPEG-2 decoder module */
#define	MAX_PICT_SIZE		0x098800		/* 610KB.  Enough for 720x576 4:2:0. */
#define		NO_OF_FRAME_BUF			4
#pragma	DATA_ALIGN(frame_all_storage, 32)
far unsigned char frame_all_storage[NO_OF_FRAME_BUF * MAX_PICT_SIZE];
int out_para[40];

/*Buffer to store the encoded bitstream*/
#define BIT_BUF_SIZE 512000
//unsigned char  bitBuf[BIT_BUF_SIZE];

int mpeg2_decsize = 0;
unsigned char *mpeg2_decbuf = 0;
extern int recv_mpeg2_size;
extern unsigned char *recv_mpeg2_buf;

FILE * file_in;
FILE * file_out;

ThrMPEG2 thrMpeg2;

IMPEG2VDEC_Params mpeg2decParams;
unsigned int *out[3];

int mpeg2_decode_flag = 0;

void tskMPEG2Init()
{
	ICELL_Obj  *cell;
	ICELL_Obj   defaultCell = ICELL_DEFAULT;
	ICC_Handle  inputIcc;
	ICC_Handle  outputIcc;
	
//	thrMpeg2.bufInput = bitBuf;
	thrMpeg2.bufInput = mpeg2_decbuf;

	/*-----------------------------------------------------------*/
	/* Create the inputICC: object used as input interface to    */ 
	/* decoder cell                                             */
	/*-----------------------------------------------------------*/
	inputIcc = (ICC_Handle)ICC_linearCreate(thrMpeg2.bufInput,
                                            sizeof(mpeg2_decsize));
//                                            sizeof(BIT_BUF_SIZE));
	UTL_assert( inputIcc != NULL);
	
	cell = &thrMpeg2.cellList[0];
	*cell                = defaultCell;
	cell->name           = "MPEG2DEC";
	cell->cellFxns       = &MPEG2DEC_CELLFXNS;            
	cell->algFxns        = (IALG_Fxns *)&MPEG2DEC_IMPEG2DEC;
	cell->algParams      = (IALG_Params *)&mpeg2decParams;
	cell->scrBucketIndex = THRIOSSCRBUCKET;
//	cell->scrBucketIndex = THRPROCESSSCRBUCKET;	

	/*-----------------------------------------------------------*/
	/* Create the outputICC: object used as output interface to  */ 
	/* decoder cell                                              */
	/*-----------------------------------------------------------*/
	outputIcc = (ICC_Handle)ICC_linearCreate(thrMpeg2.bufOutput,
                                            sizeof(unsigned char*)*3);
	UTL_assert( outputIcc != NULL);	
	
	CHAN_regCell( cell, &inputIcc, 1, &outputIcc, 1 );
	
	thrMpeg2.cellList[0].algParams = (IALG_Params *)&mpeg2decParams;
	
//	file_in = fopen("tens.m2v", "rb");
//	fread(bitBuf, 1, 44508, file_in);
//	fclose(file_in);
//	printf("read\n");
}

void tskMpeg2Start()
{
	Bool rc;
	/*------------------------------------------------------------*/
   	/* Open the channel: this causes the algorithms to be created */
	/*------------------------------------------------------------*/
	rc = CHAN_open( &thrMpeg2.chanList[0], 
	                &thrMpeg2.cellList[0], 
	                1,
	                NULL );
	
	UTL_assert( rc == TRUE );
}

volatile unsigned int frameIdx = 0;
void tskMpeg2()
{
    Bool rc;
//    Mpeg2ScomBuf * pMsgBuf;
              
    DECODE_OUT *decode_out;
//    char *frame[3];
//    unsigned int *bufs;
    
    CHAN_Handle chanHandle;
    
    int next_ptr;
    
    
    SCOM_Handle fromMpeg2toOut, fromPrdtoMpeg2;
    fromMpeg2toOut = SCOM_open("MPEG2OUT");
    fromPrdtoMpeg2 = SCOM_open("PRD2MPEG");
//    fromPrdtoProc	= SCOM_open("PRDTOPROC");

	next_ptr = 0;
	mpeg2_decode_flag = 1;
    
    while(1)
    {
    	/*-----------------------------------------------------------*/
    	/* Wait for the message from  input task to recieve captured */
    	/* frame to be cycled through encoding and decoding.         */
    	/*-----------------------------------------------------------*/
    	SCOM_getMsg(fromPrdtoMpeg2, SYS_FOREVER);
//    	if (frameIdx == 6)
//    	if (next_ptr > 44508)
//    	{
//    		continue;
//    		next_ptr = 0;
//    		thrMpeg2.bufInput = bitBuf;
//    	}
    		if (mpeg2_decbuf != recv_mpeg2_buf)
    		{
    			if (mpeg2_decbuf)
    			{
    				mmBulkFree(mpeg2_decbuf);
    			}
    			mpeg2_decsize = recv_mpeg2_size;
    			mpeg2_decbuf = recv_mpeg2_buf;
    			next_ptr = 0;
    			thrMpeg2.bufInput = mpeg2_decbuf;
    		}
    		if (mpeg2_decsize == 0)
    		{
    			continue;
    		}
    	if (next_ptr > mpeg2_decsize)
    	{
    		next_ptr = 0;
    		thrMpeg2.bufInput = mpeg2_decbuf;
    	}
      
		UTL_logDebug1("enter process with frame index: %d", frameIdx);
     
	    chanHandle = &thrMpeg2.chanList[0];
	
		/*------------------------------------------------------------*/
    	/* Set the input ICC buffer for MPEG2DEC cell for each channel*/
        /*------------------------------------------------------------*/

//		if (frameIdx != 0)
//		{
	   		ICC_setBuf(chanHandle->cellSet[0].inputIcc[0],
	   				thrMpeg2.bufInput,
	   				sizeof(mpeg2_decsize - next_ptr));         
//	   				sizeof(BIT_BUF_SIZE - next_ptr));
//	   	}
    
	    /*----------------------------------------------------------*/
	    // Set the output ICC buffer for MPEG-2 decoder
	    /*----------------------------------------------------------*/
	    out[1] = (unsigned int *) &out_para[0];
		out[2] = (unsigned int *) &frame_all_storage[0];
																												
		ICC_setBuf(chanHandle->cellSet[0].outputIcc[0],
		           &out, 
		           sizeof(unsigned char*)*3);
	            	            
	    /*----------------------------------------------------------*/
	    // execute the channel 
	    /*----------------------------------------------------------*/
//	    UTL_stsStart( stsTime1 );  // start the stopwatch
	    rc = CHAN_execute( chanHandle, frameIdx );
	    UTL_assert( rc == TRUE );
//	    UTL_stsStop( stsTime1 );   // elapsed time goes to this STS 	            
	   		
	   	decode_out = (DECODE_OUT *)(out[1]);
	   	UTL_logDebug1("thrProcess.bufIntermediate %x", thrMpeg2.bufInput);
//	   	thrProcess.bufIntermediate = bitBuf + decode_out->next_wptr * 4;
		next_ptr += decode_out->next_wptr * 4;
	   	thrMpeg2.bufInput = mpeg2_decbuf + next_ptr;
//	   	thrMpeg2.bufInput = bitBuf + next_ptr;
//	   	if (decode_out->outputing)
//	   	{
//	   		fwrite(decode_out->outframe[0], 1, 352 * 240, file_out);
//	   		fwrite(decode_out->outframe[1], 1, 352 * 240 / 4, file_out);
//	   		fwrite(decode_out->outframe[2], 1, 352 * 240 / 4, file_out);
//	   		printf("store %d frame\n", frameIdx);
//	   	}
		    
//		UTL_logDebug1("fault: %x", decode_out->fault);
//		UTL_logDebug1("pict_type: %x", decode_out->pict_type);
//		UTL_logDebug1("pict_struct: %x", decode_out->pict_struct);
//		UTL_logDebug1("next_wptr: %x", decode_out->next_wptr);
//		UTL_logDebug1("topfirst: %x", decode_out->topfirst);
//		UTL_logDebug1("end_of_seq: %x", decode_out->end_of_seq);
//		UTL_logDebug1("outputing: %x", decode_out->outputing);
//		UTL_logDebug1("outframe0: %x", decode_out->outframe[0]);
//		UTL_logDebug1("outframe1: %x", decode_out->outframe[1]);
//		UTL_logDebug1("outframe2: %x", decode_out->outframe[2]);
//		UTL_logDebug1("initial_params_valid: %x", decode_out->initial_params_valid);
//		UTL_logDebug1("START_OUT fault: %x", decode_out->initial_params.fault);
//		UTL_logDebug1("START_OUT ld_mpeg2: %x", decode_out->initial_params.ld_mpeg2);
//		UTL_logDebug1("START_OUT bit_rate: %x", decode_out->initial_params.bit_rate);
//		UTL_logDebug1("START_OUT vertical_size: %x", decode_out->initial_params.vertical_size);
//		UTL_logDebug1("START_OUT horizontal_size: %x", decode_out->initial_params.horizontal_size);
//		UTL_logDebug1("START_OUT coded_picture_width: %x", decode_out->initial_params.coded_picture_width);
//		UTL_logDebug1("START_OUT coded_picture_height: %x", decode_out->initial_params.coded_picture_height);
//		UTL_logDebug1("START_OUT chroma_format: %x", decode_out->initial_params.chroma_format);
//		UTL_logDebug1("START_OUT chrom_width: %x", decode_out->initial_params.chrom_width);
//		UTL_logDebug1("START_OUT prog_seq: %x", decode_out->initial_params.prog_seq);
//		UTL_logDebug1("frame0: %x", frame[0]);
//		UTL_logDebug1("frame1: %x", frame[1]);
//		UTL_logDebug1("frame2: %x", frame[2]);
		
		/*-----------------------------*/
	   	/* Send message to output task with pointers to decoded frame*/
   		/*-----------------------------------------------------------*/
   		thrMpeg2.scomMsgTx.status = decode_out->outputing;
   		thrMpeg2.scomMsgTx.width = decode_out->initial_params.horizontal_size;
   		thrMpeg2.scomMsgTx.height = decode_out->initial_params.vertical_size;
   		thrMpeg2.scomMsgTx.frame[0] = decode_out->outframe[0];
   		thrMpeg2.scomMsgTx.frame[1] = decode_out->outframe[1];
   		thrMpeg2.scomMsgTx.frame[2] = decode_out->outframe[2];
//   		SCOM_putMsg(fromMpeg2toOut, &(thrMpeg2.scomMsgTx));
//   		if (decode_out->outputing)
   			SCOM_putMsg(fromMpeg2toOut, &(thrMpeg2.scomMsgTx));
		frameIdx ++;
	}	                            
}

void tskPrdMpeg2()
{
	SCOM_Handle PrdtoMpeg2, PrdtoRx;
	
	PrdtoMpeg2 = SCOM_open("PRD2MPEG");
	PrdtoRx = SCOM_open("PRD2RX");
	SCOM_putMsg(PrdtoRx, &(thrMpeg2.scomMsgTx));
	if (mpeg2_decode_flag)
	{
		SCOM_putMsg(PrdtoMpeg2, &(thrMpeg2.scomMsgTx));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -