Hi,

Can anyone tell me the c code for taking snap and saving it to directory.

Thanks

Do provide evidence of having done some work yourself if posting questions from school or work assignments

Do provide evidence of having done some work yourself if posting questions from school or work assignments

#include "ApproDrvMsg.h"
#include "Appro_interface.h"
#include "cmem.h"
#include "Msg_Def.h"
#include <stdio.h>
int i;

void Init_Interface(int Msg_id)
{
	int qid;
	if(ApproDrvInit(Msg_id))
	exit(1);

	if(func_get_mem(&qid))
	{
	ApproDrvExit();
	exit(1);
	}
}

int SaveAudioFile( char *pFileName )
{
        FILE *pfd = NULL;
        int error_code = 0;
        int     SerialBook = -1;
        int     SerialLock = -1;
        int     ret = 0;
        int     save_cnt = 1;
        AV_DATA av_data;        

        pfd = fopen(pFileName,"wb");
        if( pfd == NULL )
        {
               // ERR("open file error!!");
                error_code = -1;
                goto RECORD_QUIT;
        }

        if( fseek( pfd, 0, SEEK_SET ) < 0)
        {
               // ERR("seek file error!!");
                error_code = -1;
                goto RECORD_QUIT;
        }        

        do
        {
                GetAVData(AV_OP_GET_MJPEG_SERIAL, -1, &av_data );
        } while (av_data.serial < 0);        

        SerialBook = av_data.serial;        

        while( save_cnt > 0)
        {
                ret = GetAVData(AV_OP_LOCK_MJPEG, SerialBook, &av_data );
                if (ret == RET_SUCCESS)
                {
                        if( fwrite( av_data.ptr,av_data.size,1, pfd )  <= 0)
                        {
                               // ERR("save file error!!");
                                error_code = -1;
                                goto RECORD_QUIT;
                        }
                        if (SerialLock >= 0)
                        {
                                GetAVData(AV_OP_UNLOCK_MJPEG, SerialLock, &av_data);
                        }
                        SerialLock = SerialBook;
                        save_cnt--;
                        SerialBook++;
                }
                else
                {
                        GetAVData(AV_OP_GET_MJPEG_SERIAL, -1, &av_data );    
                        if( SerialBook > av_data.serial )
                        {
                                // delay for waiting next frame 
                               // usleep(5);
                                 // sleep();
				for(i=0;i<1000;i++);

                        }else{
                                SerialBook = av_data.serial;
                        }
                }
        }

        GetAVData(AV_OP_UNLOCK_MJPEG, SerialLock, &av_data);
RECORD_QUIT:
        if( pfd )
        {
                fclose(pfd);
        }
        return error_code;
}

int main()
{
	int result = 0;
	char *pFileName = "snap_test.jpg";
	Init_Interface(0x01);
	result = SaveAudioFile(pFileName );
	return 0;
}

we tried with code but not getting??

result = SaveAudioFile(pFileName); Are you sure a JPEG is supposed to be an Audio file? Furthermore, what libraries are you getting all of these functions from?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.