Revision cdcae696

View differences:

chunker_streamer/chunker_streamer.c
104 104
	//stuff needed to compute the right timestamps
105 105
	short int FirstTimeAudio=1, FirstTimeVideo=1;
106 106
	short int pts_anomalies_counter=0;
107
	long long newTime=0, newTime_prev=0;
107
	long long newTime=0, newTime_video=0, newTime_prev=0;
108 108
	double ptsvideo1=0.0;
109 109
	double ptsaudio1=0.0;
110 110
	int64_t last_pkt_dts=0, delta_video=0, delta_audio=0, last_pkt_dts_audio=0, target_pts=0;
......
349 349
	//main loop to read from the input file
350 350
	while(av_read_frame(pFormatCtx, &packet)>=0) {
351 351
		if(!live_source) {
352
			sleep = (long)newTime - (long)newTime_prev;
352
			if(sleep==1) { //video packet, lets sleep
353
				sleep = (long)newTime_video - (long)newTime_prev;
354
				newTime_prev = newTime_video;
355
			}
353 356
			if(sleep > 0) {
354 357
#ifdef DEBUG_ANOMALIES
355 358
				fprintf(stderr, "\nREADLOOP: going to sleep for %ld\n", sleep);
......
357 360
				usleep(sleep * 1000);
358 361
				//usleep(40 * 1000);
359 362
			}
360
			newTime_prev = newTime;
361 363
		}
362 364

  
363 365
		//detect if a strange number of anomalies is occurring
......
380 382

  
381 383
		// Is this a packet from the video stream?
382 384
		if(packet.stream_index==videoStream) {
385
			sleep=1; //sleep in case of video packet (and if not live)
383 386
			//decode the video packet into a raw pFrame
384 387
			if(avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet)>0) {
385 388
#ifdef DEBUG_VIDEO_FRAMES
......
452 455
					//compute the new video timestamp in milliseconds
453 456
					if(frame->number>0) {
454 457
						newTime = ((double)target_pts-ptsvideo1)*1000.0/((double)delta_video*(double)av_q2d(pFormatCtx->streams[videoStream]->r_frame_rate));
458
						newTime_video = newTime; //for computing sleep
455 459
					}
456 460
#ifdef DEBUG_VIDEO_FRAMES
457 461
					fprintf(stderr, "VIDEO: NEWTIMESTAMP %ld\n", newTime);
......
494 498
			}
495 499
		}
496 500
		else if(packet.stream_index==audioStream) {
501
			sleep=0;
497 502
			audio_data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
498 503
			//decode the audio packet into a raw audio source buffer
499 504
			if(avcodec_decode_audio3(aCodecCtx, samples, &audio_data_size, &packet)>0) {

Also available in: Unified diff