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

📄 writefile.c

📁 It s a tool designed to extract as much information as possible from Bluetooth devices without the r
💻 C
📖 第 1 页 / 共 2 页
字号:
static intfiles_video(void *handle, struct ng_video_buf *buf){    struct files_handle *h = handle;    int rc = -1;    FILE *fp;    if (h->gotcha) {	fprintf(stderr,"Oops: can't count up file names any more\n");	return -1;    }        switch (h->video.fmtid) {    case VIDEO_RGB24:	rc = write_ppm(h->file, buf);	break;    case VIDEO_GRAY:	rc = write_pgm(h->file, buf);	break;    case VIDEO_JPEG:	if (NULL == (fp = fopen(h->file,"w"))) {	    fprintf(stderr,"grab: can't open %s: %s\n",h->file,strerror(errno));	    rc = -1;	} else {	    fwrite(buf->data,buf->size,1,fp);	    fclose(fp);	    rc = 0;	}    }    if (1 != patch_up(h->file))	h->gotcha = 1;    return rc;}static intfiles_audio(void *handle, struct ng_audio_buf *buf){    struct files_handle *h = handle;    if (buf->size != write(h->wav_fd,buf->data,buf->size))	return -1;    h->wav_size += buf->size;    return 0;}static intfiles_close(void *handle){    struct files_handle *h = handle;    if (h->audio.fmtid != AUDIO_NONE) {	wav_stop_write(h->wav_fd,&h->wav_header,h->wav_size);	close(h->wav_fd);    }    free(h);    return 0;}/* ---------------------------------------------------------------------- */struct raw_priv {    int      yuv4mpeg;};struct raw_handle {    /* format */    struct ng_video_fmt video;    struct ng_audio_fmt audio;    const struct raw_priv *vpriv;    /* video file*/    int      fd;    /* *.wav file */    int      wav_fd;    WAVEHDR  wav_header;    int      wav_size;};static void*raw_open(char *videoname, char *audioname,	 struct ng_video_fmt *video, const void *priv_video, int fps,	 struct ng_audio_fmt *audio, const void *priv_audio){    struct raw_handle *h;    int frame_rate_code = 0;    int frame_rate_mul  = fps;    int frame_rate_div  = 1000;        if (NULL == (h = malloc(sizeof(*h))))	return NULL;    /* init */    memset(h,0,sizeof(*h));    h->video         = *video;    h->audio         = *audio;    h->vpriv         = priv_video;    /* audio */    if (h->audio.fmtid != AUDIO_NONE) {	h->wav_fd = open(audioname, O_CREAT | O_RDWR | O_TRUNC, 0666);	if (-1 == h->wav_fd) {	    fprintf(stderr,"open %s: %s\n",audioname,strerror(errno));	    free(h);	    return NULL;	}	wav_start_write(h->wav_fd,&h->wav_header,&h->audio);    }    /* video */    if (h->video.fmtid != VIDEO_NONE) {	if (h->vpriv && h->vpriv->yuv4mpeg) {	    switch (fps) {	    case 23976:  frame_rate_code = 1;          /* 24000 / 1001 */		         frame_rate_mul  = 24000;			 frame_rate_div  = 1001;			 break;	    case 29970:  frame_rate_code = 4;          /* 30000 / 1001 */		         frame_rate_mul  = 30000;		         frame_rate_div  = 1001;			 break;	    case 59940:  frame_rate_code = 7;          /* 60000 / 1001 */		         frame_rate_mul  = 60000;			 frame_rate_div  = 1001;			 break;	    case 24000:  frame_rate_code = 2; break;	    case 25000:  frame_rate_code = 3; break;	    case 30000:  frame_rate_code = 5; break;	    case 50000:  frame_rate_code = 6; break;	    case 60000:  frame_rate_code = 8; break;	    default:		fprintf(stderr,"illegal frame rate\n");		free(h);		return NULL;	    }	}	if (NULL != videoname) {	    h->fd = open(videoname, O_CREAT | O_RDWR | O_TRUNC, 0666);	    if (-1 == h->fd) {		fprintf(stderr,"open %s: %s\n",videoname,strerror(errno));		if (h->wav_fd)		    close(h->wav_fd);		free(h);		return NULL;	    }	} else {	    h->fd = 1; /* use stdout */	}	if (h->vpriv && h->vpriv->yuv4mpeg) {	    char header[64];	    switch (h->vpriv->yuv4mpeg) {	    case 1:		sprintf(header, "YUV4MPEG %d %d %d\n",			h->video.width, h->video.height,frame_rate_code);		break;	    case 2:	    	sprintf(header, "YUV4MPEG2 W%d H%d F%d:%d\n",			h->video.width, h->video.height,			frame_rate_mul, frame_rate_div);		break;	    }	    write(h->fd, header, strlen(header));	}    }    return h;}static intraw_video(void *handle, struct ng_video_buf *buf){    struct raw_handle *h = handle;    if (h->vpriv && h->vpriv->yuv4mpeg) 	switch (h->vpriv->yuv4mpeg) {	case 1:	   if (6 != write(h->fd, "FRAME\n", 6))	   	return -1;	   break;	case 2:	   if (7 != write(h->fd, "FRAME \n", 7))	   	return -1;	   break;	}    if (buf->size != write(h->fd,buf->data,buf->size))	return -1;    return 0;}static intraw_audio(void *handle, struct ng_audio_buf *buf){    struct raw_handle *h = handle;    if (buf->size != write(h->wav_fd,buf->data,buf->size))	return -1;    h->wav_size += buf->size;    return 0;}static intraw_close(void *handle){    struct raw_handle *h = handle;    if (h->audio.fmtid != AUDIO_NONE) {	wav_stop_write(h->wav_fd,&h->wav_header,h->wav_size);	close(h->wav_fd);    }    if (h->video.fmtid != VIDEO_NONE && 1 != h->fd)	close(h->fd);    free(h);    return 0;}/* ----------------------------------------------------------------------- *//* data structures describing our capabilities                             */static const struct ng_format_list files_vformats[] = {    {	name:  "ppm",	ext:   "ppm",	fmtid: VIDEO_RGB24,    },{	name:  "pgm",	ext:   "pgm",	fmtid: VIDEO_GRAY,    },{	name:  "jpeg",	ext:   "jpeg",	fmtid: VIDEO_JPEG,    },{	/* EOF */    }};static struct raw_priv yuv4mpeg = {    yuv4mpeg: 1};static struct raw_priv yuv4mpeg2 = {    yuv4mpeg: 2};static const struct ng_format_list raw_vformats[] = {    {	name:  "rgb",	ext:   "raw",	fmtid: VIDEO_RGB24,    },{	name:  "gray",	ext:   "raw",	fmtid: VIDEO_GRAY,    },{	name:  "422",	ext:   "raw",	fmtid: VIDEO_YUYV,    },{	name:  "422p",	ext:   "raw",	fmtid: VIDEO_YUV422P,    },{	name:  "4mpeg",	desc:  "yuv4mpeg (mpeg2enc >= 1.6)",	ext:   "yuv",	fmtid: VIDEO_YUV420P,	priv:  &yuv4mpeg2,    },{	name:  "4mpeg-o",	desc:  "yuv4mpeg (old mpeg2enc)",	ext:   "yuv",	fmtid: VIDEO_YUV420P,	priv:  &yuv4mpeg,    },{	/* EOF */    }};static const struct ng_format_list wav_aformats[] = {    {	name:  "mono8",	ext:   "wav",	fmtid: AUDIO_U8_MONO,    },{	name:  "mono16",	ext:   "wav",	fmtid: AUDIO_S16_LE_MONO,    },{	name:  "stereo",	ext:   "wav",	fmtid: AUDIO_S16_LE_STEREO,    },{	/* EOF */    }};struct ng_writer files_writer = {    name:      "files",    desc:      "multiple image files",    video:     files_vformats,    audio:     wav_aformats,    wr_open:   files_open,    wr_video:  files_video,    wr_audio:  files_audio,    wr_close:  files_close,};struct ng_writer raw_writer = {    name:      "raw",    desc:      "single file, raw video data",    video:     raw_vformats,    audio:     wav_aformats,    wr_open:   raw_open,    wr_video:  raw_video,    wr_audio:  raw_audio,    wr_close:  raw_close,};/* ------------------------------------------------------------------- */static void __init writefile_init(void){    ng_writer_register(NG_PLUGIN_MAGIC,__FILE__,&files_writer);    ng_writer_register(NG_PLUGIN_MAGIC,__FILE__,&raw_writer);}

⌨️ 快捷键说明

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