Anmelden Registrieren

Einloggen

Username *
Password *
an mich erinnern

Neuen Account anlegen

Die mit einem Sternchen (*) gekennzeichneten Felder sind Pflichtfelder.
Name *
Username *
Password *
Verify password *
Email *
Verify email *
Captcha *

A typical record to ASF file application in C/C++

//- 

// ==========================================================================
// Copyright (C) 2009 Enciris Technologies, SAS. and/or its licensors. All
// rights reserved.
//
// The coded instructions, statements, computer programs, and/or related
// material (collectively the "Data") in these files contain unpublished
// information proprietary to Enciris Technologies, SAS. and/or its
// licensors, which is protected by copyright law of the European Union
// and by international treaties.
//
// The Data is provided for use exclusively by You. You have the right
// to use, modify, and incorporate this Data into other products for
// purposes authorized by the Enciris software license agreement,
// without fee.
//
// The copyright notices in the Software and this entire statement,
// including the above license grant, this restriction and the
// following disclaimer, must be included in all copies of the
// Software, in whole or in part, and all derivative works of
// the Software, unless such copies or derivative works are solely
// in the form of machine-executable object code generated by a
// source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
// ENCIRIS DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
// WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
// NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
// PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR
// TRADE PRACTICE. IN NO EVENT WILL ENCIRIS AND/OR ITS LICENSORS
// BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
// DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF ENCIRIS
// AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY
// OR PROBABILITY OF SUCH DAMAGES.
//
// ==========================================================================
//+

// A sample application that records compressed video data to asf files

#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include "../../lib/enciris_ltlib.h"

#define MAX_FR_SZ 10//2048*2048*2
#define ASF_PKT_SZ 2048
#define ASF_IDX_SZ 1024*1024


int main(int argc, char* argv[])
{
// Device handling
char DevicePath[256];
int DeviceIndex = 0;
int LtHandle = 0;
int LoopCnt = 0;
int Status = LT_SUCCESS;

//VideoInformation
char String[128];
double RefreshRate = 0;
int PixelRate = 0;
int HorizontalFreq = 0;
int IsInterlaced = 0;
int Vc1Width = 0;
int Vc1Height = 0;
int FrameType = 0;

// Buffer
unsigned char *pAsfData = (unsigned char *)malloc(MAX_FR_SZ);
int asfBytesXfered = 0;
unsigned char *pIdxBuffer = (unsigned char *)malloc(ASF_IDX_SZ);
int IdxBufferSize = ASF_IDX_SZ;
int IdxByteTransfered;
unsigned char *pHdrBuffer = (unsigned char *)malloc(ASF_PKT_SZ);
int HdrBufferSize = ASF_PKT_SZ;
unsigned long long fileSize;
int HdrByteTransfered;

FILE *pFileAsf = fopen ( "output_asf.asf", "wb" );

#ifdef _WINDOWS
// Load lt dll
HMODULE m_ltDll;
printf("--> LoadLtDll\n");
m_ltDll = LoadLtDll("encirislt.dll");
#else
// Load lt dll
void * m_ltDll;
printf("--> LoadLtDll\n");
m_ltDll = LoadLtDll("../../lib/libencirislt.so.1.0.1");
#endif

///////////////////////////////////////////////////////////////////////////////////////////
// Get path to LT

DeviceIndex = 0;
Status = LT_GetDevicePath(DevicePath, DeviceIndex);
if( Status < 0)
{
LT_GetError(Status);
printf("Check if your LT101 board is connected and properly configured...\n");
printf("Please also check in device manager (devmgmt.msc) if encirisLT board is present in video controller section\n");
getchar();
return Status;
}

///////////////////////////////////////////////////////////////////////////////////////////
// OpenDevice

printf("--> OpenDevice\n");
LtHandle = LT_OpenDevice(DevicePath);
if( LtHandle < 0 )
{
printf("Can't open %s - Error : %d\n",DevicePath,LtHandle);
LT_GetError(LtHandle);
return LtHandle;
}
printf("<-- OpenDevice\n\n");


///////////////////////////////////////////////////////////////////////////////////////////
// Change encoder parameters here

// Input Connector
//LT_SetParam(LtHandle,LT_PARAMS_VIDEO_INPUT,VID_HD_DIGITAL);
//LT_SetParam(LtHandle,LT_PARAMS_VIDEO_INPUT,VID_HD_ANALOG);
//LT_SetParam(LtHandle,LT_PARAMS_VIDEO_INPUT,VID_SVIDEO);
LT_SetParam(LtHandle,LT_PARAMS_VIDEO_INPUT,VID_COMPOSITE);
//LT_SetParam(LtHandle,LT_PARAMS_VIDEO_INPUT,VID_COLORBAR);

// Input Resolution
LT_SetParam(LtHandle,LT_PARAMS_VIDEO_RESOLUTION,AUTO);
//LT_SetParam(LtHandle,LT_PARAMS_VIDEO_RESOLUTION,V480P2997);
//LT_SetParam(LtHandle,LT_PARAMS_VIDEO_RESOLUTION,V1080I5994);

// Input Colorspace
LT_SetParam(LtHandle,LT_PARAMS_VIDEO_COLORSPACE,VID_RGB);
//LT_SetParam(LtHandle,LT_PARAMS_VIDEO_COLORSPACE,VID_YUV);

// Input Smooth filter
LT_SetParam(LtHandle,LT_PARAMS_VIDEO_SMOOTHING_FILTER,0);

// Vc1
LT_SetParam(LtHandle,LT_PARAMS_VC1_FRAMERATE,AUTO);
LT_SetParam(LtHandle,LT_PARAMS_VC1_BITRATE,10000000); // Bits/s
LT_SetParam(LtHandle,LT_PARAMS_ENC_GOP_LENGTH,14);
LT_SetParam(LtHandle,LT_PARAMS_VC1_STUFFING_LENGTH,0);
LT_SetParam(LtHandle,LT_PARAMS_VC1_SCALING,0);

#if 1 //PCM
//audio
LT_SetParam(LtHandle,LT_PARAMS_AUDIO_MODE,AUD_PCM_16BIT_STEREO_48KHZ);

// Asf
LT_SetParam(LtHandle,LT_PARAMS_ASF_ENABLE_ASF,1);
LT_SetParam(LtHandle,LT_PARAMS_ASF_PACKET_SIZE,ASF_PKT_SZ);
LT_SetParam(LtHandle,LT_PARAMS_ASF_PREROLL,33);
#else //WMA
//audio config
double aud_bitrate = 192000;//in bits/sec
LT_SetParam(LtHandle,LT_PARAMS_AUDIO_MODE,AUD_WMA8_STEREO_48KHZ);
LT_SetParam(LtHandle,LT_PARAMS_AUDIO_BITRATE,aud_bitrate);

//asf config
int wma_block_align = (int)(aud_bitrate/187.5);
LT_SetParam(LtHandle,LT_PARAMS_ASF_ENABLE_ASF,1);
LT_SetParam(LtHandle,LT_PARAMS_ASF_PACKET_SIZE,wma_block_align + 28);//wma_block_align + 28
LT_SetParam(LtHandle,LT_PARAMS_ASF_PREROLL,33);
#endif

// To commit each parameters changes, call LT_UploadDeviceParameters

///////////////////////////////////////////////////////////////////////////////////////////
// Load config into device

printf("--> UploadDeviceParameters\n");
Status = LT_UploadDeviceParameters(LtHandle);

// Get video signal characteristics
LT_GetVideoDescription(LtHandle, String, 0, &RefreshRate, &PixelRate, &HorizontalFreq, &IsInterlaced);
printf("\n");
printf("Video description : %s\n", String);
printf("Refeshrate : %f\n", RefreshRate);
printf("Pixelrate : %d\n", PixelRate);
printf("HorizontalFrequency : %d\n", HorizontalFreq);
printf("IsInterlaced : %d\n", IsInterlaced);
printf("\n");


if( Status < 0 )
{
LT_GetError(Status);
return Status;
}
printf("<-- UploadDeviceParameters\n\n");


///////////////////////////////////////////////////////////////////////////////////////////
// At this point Lt device is ready to be used

LT_GetParam(LtHandle,LT_PARAMS_VC1_WIDTH,&Vc1Width);
LT_GetParam(LtHandle,LT_PARAMS_VC1_HEIGHT,&Vc1Height);


printf("Vc1Width : %d\n",Vc1Width);
printf("Vc1Height : %d\n",Vc1Height);
printf("\n");


///////////////////////////////////////////////////////////////////////////////////////////
// Record a VC1 sequence to a file

printf("--> GetAsfFrames\n");
LT_StartVc1(LtHandle);
LT_StartAudio(LtHandle);

while( LoopCnt < 30*60 )
{
printf("LoopCnt: %d\r", LoopCnt);

//#########################################################################################
Status = LT_GetMuxedFrame(LtHandle, pAsfData, MAX_FR_SZ, &asfBytesXfered, &FrameType);
// is an error occured ?
if( Status < 0 )
{
printf("\n");
printf("ASF fetch error\n");
LT_GetError(Status);
return Status;
}
//#########################################################################################

fwrite(pAsfData,1,asfBytesXfered,pFileAsf);
LoopCnt++;
}

//do ASF file postprocessing now
#if 0
//this function retrieves the ASF index buffer
LT_GetAsfIndexBuffer(LtHandle, pIdxBuffer, IdxBufferSize, &IdxByteTransfered);

//append index to file
fwrite(pIdxBuffer,1,IdxByteTransfered,pFileAsf);

//get file size
fileSize = ftell(pFileAsf);

//this function retrieves the ASF top level header
LT_GetAsfHeaderObject(LtHandle, pHdrBuffer, HdrBufferSize, fileSize, &HdrByteTransfered);

//rewind file pointer
rewind(pFileAsf);

//overwrite top level header object to .ASF file
fwrite(pHdrBuffer,1,HdrByteTransfered,pFileAsf);
#endif

LT_StopVc1(LtHandle,0);
LT_StopAudio(LtHandle,0);
printf("\n");
printf("<-- GetAsfFrames\n\n");

 

/////////////////////////////////////////////////////////////////////////////////////////
// Close Lautrec handle

printf("--> CloseDevice\n");
LT_CloseDevice(LtHandle);


FreeLtDll(m_ltDll);
fclose(pFileAsf);
printf("<-- CloseDevice\n\n");

char CurrentPath[_MAX_PATH];
_getcwd(CurrentPath, _MAX_PATH);
printf("output_asf.asf has been generated in %s\n", CurrentPath);
printf("You can play output_asf.asf with the media player of your choise (e.g VLC, WMP11 ...) \n");
printf("\nType enter to exit program\n");
getchar();
return 0;
}