예제 #1
0
파일: log.c 프로젝트: jlledom/MIT_6.828-xv6
void
initlog(int dev)
{
  if (sizeof(struct logheader) >= BSIZE)
    panic("initlog: too big logheader");

  struct superblock sb;
  initlock(&log.lock, "log");
  readsb(dev, &sb);
  log.start = sb.logstart;
  log.size = sb.nlog;
  log.dev = dev;
  recover_from_log();
}
예제 #2
0
파일: log.c 프로젝트: joaobatalha/zv6
void
initlog(void)
{
  if (sizeof(struct logheader) >= BSIZE)
    panic("initlog: too big logheader");

  struct superblock sb;
  initlock(&log.lock, "log");
  readsb(ROOTDEV, &sb);
  log.start = sb.size - sb.nlog;
  log.size = sb.nlog;
  log.dev = ROOTDEV;
  recover_from_log();
}
int init_seg_union(Segment_U * segment_union ,int prog_no) {   //传递是指针变量的地址


	Segment_U * seg_union =segment_union;

	seg_union->segment_no = 0;
	seg_union->picture_capture = avcodec_alloc_frame();
	seg_union->picture_capture_no = 0;

	/*	-----------base seg_union do something---------------	*/
	//	create directory
	create_directory(seg_union->storage_dir);

	// create m3u8 file
	create_m3u8_name(seg_union);
	chris_printf("seg_union->full_m3u8_name = %s \n" ,seg_union->full_m3u8_name);

	/*----------following ,start to set  Output_Context information----- */
	//malloc Output_context
	if( (seg_union->output_ctx = malloc (sizeof(Output_Context))) == NULL){

		fprintf(stderr ,"ptr_output_ctx malloc failed .\n");
		exit(MEMORY_MALLOC_FAIL);
	}
	//segment element in output context
	seg_union->output_ctx->frame_rate				=		 seg_union->frame_rate;						 //frame rate
	seg_union->output_ctx->width					=		 seg_union->width;							//video width
	seg_union->output_ctx->height					=		 seg_union->height;							//video height
	seg_union->output_ctx->video_rate				=		 seg_union->video_rate;						//video bitrate
	seg_union->output_ctx->audio_rate				=		 seg_union->audio_rate;						//audio bitrate
	seg_union->output_ctx->sample					=		 seg_union->sample;							//audio sample
	seg_union->output_ctx->channel					=		 seg_union->channel;						//audio channels
	seg_union->output_ctx->num_in_dir				= seg_union->num_in_dir;
	seg_union->output_ctx->num_in_m3u8 				= seg_union->num_in_m3u8;
	seg_union->output_ctx->segment_duration 		=		 seg_union->segment_duration;
	seg_union->output_ctx->ts_prfix_name 			= 		 seg_union->ts_prfix_name;
	seg_union->output_ctx->mode_type				=		 seg_union->mode_type;
	//
	seg_union->output_ctx->segment_no				= 		 seg_union->segment_no;
	seg_union->output_ctx->full_m3u8_name			=		 seg_union->full_m3u8_name;
	seg_union->output_ctx->m3u8						= 		 seg_union->m3u8_name;
	//
	seg_union->output_ctx->frame_count 				= 0;			//this frame_count be used to generate video pts.


	chris_printf("num_in_m3u8 = %d ,num_in_dir = %d \n\n" ,seg_union->output_ctx->num_in_m3u8 ,seg_union->output_ctx->num_in_dir);

	/*-----------	following ,only do in the mode_type yy_live	--------------*/
	if(seg_union->mode_type == YY_LIVE){	// live mode

		/*	live something	*/
		//malloc live_buffer for m3u8 buffer  //the content of m3u8
		seg_union->output_ctx->live_write_buf = malloc(sizeof(char) * 1024 * 100);
		if (!seg_union->output_ctx->live_write_buf) {
			fprintf(stderr, "Could not allocate write buffer for live_write_buf\n");
			exit(ALLOCATE_M3U8_WRITE_BUFFER_LIVE);
		}
		memset(seg_union->output_ctx->live_write_buf ,0  ,1024*100);

		chris_printf("ptr_output_ctx->num_in_m3u8 = %d \n" ,seg_union->output_ctx->num_in_m3u8);
		seg_union->output_ctx->seg_duration_arr = malloc(sizeof(double) *  ( seg_union->output_ctx->num_in_m3u8 + 1) );  	//use to storage the every ts file length in the m3u8 ,the array[0] reserved
		if(seg_union->output_ctx->seg_duration_arr == NULL){
			fprintf(stderr ,"seg_duration_arr malloc failed .. ,%s ,line %d \n" ,__FILE__ ,__LINE__);
			exit(MEMORY_MALLOC_FAIL);
		}

		/*	judge for the log.info 	*/
		int ret =find_log_file(seg_union);
		if(ret){//find the log file ,and recover the scene ,recover the segment_no use to create the ts name
			recover_from_log(seg_union);
			chris_printf("......after recover from the log file ...\n\n\n");
		}
	}

	//splice the first ts name
	create_first_ts_name(seg_union ,seg_union->mode_type);

	//the followint ,dir_name_len and ts_name set must be set after the function create_first_ts_name!!!!
	seg_union->output_ctx->dir_name_len 		    = 		 seg_union->dir_name_len;   //
	seg_union->output_ctx->ts_name 					=		 seg_union->ts_name;		//
	chris_printf("--------------->before transcode init function  ,seg_union->ts_name = %s..\n" ,seg_union->ts_name);

	//add audio stream and video into the output_ctx ,of course ,set codec information also in the function init_output
//	init_output(seg_union->output_ctx ,seg_union->ts_name );  //add stream information in this function
	init_output(seg_union->output_ctx ,seg_union->ts_name , prog_no);  //add stream information in this function

	//open video and audio codecs ,set video_out_buf and audio_out_buf
	open_stream_codec(seg_union->output_ctx ,prog_no);
	chris_printf("--------------->after transcode init function ..\n");


	return 0;
}