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

📄 mjpeg_avi_fileinfo.c

📁 ADI blackfin DSP的基于device friver的jpeg压缩算法
💻 C
字号:
/*****************************************************************************
Copyright(c) 2005 Analog Devices, Inc.  All Rights Reserved. This software is 
proprietary and confidential to Analog Devices, Inc. and its licensors.
******************************************************************************

$RCSfile: MJPEG_AVI_FileInfo.c,v $
$Revision: 1.1 $
$Date: 2006/07/17 07:44:02 $

Project:	MJPEG Decoder
Title:		AVI File reader
Author(s):	RKB
Revised by: 

Description	   : This file contains code to extract the JPEG parameters
                 from the AVI file. 

References:
	
******************************************************************************
Tab Setting:			4
Target Processor:		Blackfin
Target Tools Revision:	VDSP++ 4.0
******************************************************************************

Modification History:
====================
$Log: MJPEG_AVI_FileInfo.c,v $
Revision 1.1  2006/07/17 07:44:02  bmk
JPEG-MJPEG User access files


******************************************************************************/

#include "MJPEG_AVI_FileReader.h"
#include "JPEG_api_decoder.h"
#include "JPEG_bitsbuffer.h"
#include "JPEG_memalloc.h"

/*
*******************************************************************************
Name            : MJPEG_AVI_GetImageInfo
Description     : Extracts JPEG parameters from the first frame of a stream
Parameter       : Input filename
				  tJpegParam structure to fill
				  Pointer to the size of the first frame in bytes
				  stdio file for messages
Return Value    : MJPEG_AVI_RETURN_OK if no errors
				  MJPEG_AVI_RETURN_NOMORESAMPLES if the buffer was too short
				  MJPEG_AVI_RETURN_ERROR otherwise
*******************************************************************************
*/
section ("MJPEGDEC_P0") // All code
int32 MJPEG_AVI_GetImageInfo(	int8 *lInputFileName, tJpegParam *limageParam, 
								uint32* lBufLength,  FILE *TestReportFile)
{
#ifndef MJPEGREWIND	
    	int32 					lResult = 0;		
	    uint32 					lInputFileHandle = 0;
    	uint32 					lStreamHandle = 0;
    	tMJPEG_AVI_STREAMINFO 	lStreamInfo; 
        MemObjHandle            *StreamBuffer_Obj;
    	uint8					*StreamBuffer = 0;      
    	tJpegDecoder    		*handle;
    	tIMG_BufferInfo			lInputBufferInfo;		    	
    	/* Open the AVI file */
	    lResult = MJPEG_AVI_OpenFileRead(&lInputFileHandle, (int8 *)lInputFileName);
		if(lResult != MJPEG_AVI_RETURN_OK)
		{
			fprintf(TestReportFile, "Cannot open AVI input file: %s\n", lInputFileName);
			return (MJPEG_AVI_RETURN_ERROR);
		}
	 
		/**/
	    /* Get the handle for AVI stream */
	    lResult = MJPEG_AVI_OpenStreamRead (lInputFileHandle, &lStreamHandle, 
	                                 	 MJPEG_AVI_StreamTypeVIDEO, 0);
		if(lResult != MJPEG_AVI_RETURN_OK)
		{
			fprintf(TestReportFile, "Cannot get the AVI stream handle\n");
			return (MJPEG_AVI_RETURN_ERROR);
		}
	
		/**/
	    /* Get information about AVI stream */
	    lResult = MJPEG_AVI_ReadStreamInfo(lStreamHandle, &lStreamInfo, 
	                               sizeof(tMJPEG_AVI_STREAMINFO));
		if(lResult != MJPEG_AVI_RETURN_OK)
		{
			fprintf(TestReportFile, "Cannot read AVI information\n");
			return (MJPEG_AVI_RETURN_ERROR);
		}	

		
		/**/
		/* Read the JPEG parameters from the first frame of the stream, then rewind stream */
		lResult = MJPEG_AVI_ReadToNextFrame(lStreamHandle, lBufLength);
		if(lResult != MJPEG_AVI_RETURN_OK) {
        	if(lResult == MJPEG_AVI_RETURN_NOMORESAMPLES)
        	{
				fprintf(TestReportFile, "Not enough samples to read the first JPEG image from stream\n");
            } else {
				fprintf(TestReportFile, "Couldn't read JPEG parameters from first frame\n");
            }
			return (MJPEG_AVI_RETURN_ERROR);
		}
		/* Read the image */		
		//StreamBuffer = (uint8 *) malloc(*lBufLength);
	    StreamBuffer_Obj = JPEG_MemAlloc_NEW(*lBufLength,1,MEM_TYPE_DATA);
		if(StreamBuffer_Obj == NULL)
		{
			fprintf(TestReportFile,"Memory allocation for StreamBuffer failed.\n");
		    fprintf(TestReportFile, "Could not allocate %d bytes for input buffer\n", *lBufLength);
			return MJPEG_AVI_RETURN_ERROR;	
		}
		StreamBuffer = (uint8*)JPEG_MemAlloc_ADDRESS(StreamBuffer_Obj);
		
		lResult = MJPEG_AVI_ReadNextFrame(lStreamHandle, StreamBuffer, *lBufLength);
		if(lResult != MJPEG_AVI_RETURN_OK) {
			fprintf(TestReportFile, "Cannot read first frame of the stream\n");
			return (MJPEG_AVI_RETURN_ERROR);
		}
	
		/* Determine JPEG image parameters */
		/**/
		/* Start with a new image */
		if (JPEG_Param_INIT (limageParam) != E_SUCCESS) 
		{
			fprintf(TestReportFile, "Could not initialize JPEG parameters.\n");
			return (MJPEG_AVI_RETURN_ERROR);
		}	
	
		/* Read the details for the first image from the stream */
		lInputBufferInfo.Length  = *lBufLength;
		lInputBufferInfo.Pointer  = StreamBuffer;
		JPEG_Param_CONFIG(limageParam, JPEG_POINTER_INPUT, (int)&lInputBufferInfo);

		/**/
		/* Creating the JPEG decoder instance from the memory created */
		handle = JPEG_Decoder_NEW(limageParam);		
		if (handle == NULL)
		{
		    fprintf(TestReportFile, "Could not create JPEG decoder instance\n");
			return E_FAILURE;
		}
		/**/
		/* Process the JPEG header and extract image parameters */
		lResult = JPEG_ProcessHeader(handle, limageParam);
		if(lResult != E_SUCCESS) {
			fprintf(TestReportFile, "Cannot read first frame of the stream\n");
			return (MJPEG_AVI_RETURN_ERROR);
		}
		/* Delete the JPEG Resource */
		JPEG_Decoder_DELETE(handle);
		
        JPEG_MemAlloc_DELETE(StreamBuffer_Obj);
		
	    /* Delete the handle for AVI stream */
	    MJPEG_AVI_CloseStreamRead(lStreamHandle);
	    
	    /* Close the AVI file */
	    MJPEG_AVI_CloseFileRead(lInputFileHandle);
#endif	    
	    return MJPEG_AVI_RETURN_OK;
}

⌨️ 快捷键说明

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