Revision df2ad829 chunker_streamer/chunker_streamer.c

View differences:

chunker_streamer/chunker_streamer.c
11 11
#include "chunker_streamer.h"
12 12

  
13 13

  
14
#define DEBUG_AUDIO_FRAMES
15
#define DEBUG_VIDEO_FRAMES
14
//#define DEBUG_AUDIO_FRAMES
15
//#define DEBUG_VIDEO_FRAMES
16 16
#define DEBUG_CHUNKER
17
#define DEBUG_TIME
18 17
#define DEBUG_ANOMALIES
18
#define DEBUG_TIMESTAMPING
19 19

  
20 20
#define MAX(a,b) ((a>b)?(a):(b))
21 21

  
......
98 98
	//stuff needed to compute the right timestamps
99 99
	short int FirstTimeAudio=1, FirstTimeVideo=1;
100 100
	short int pts_anomalies_counter=0;
101
	short int newtime_anomalies_counter=0;
101 102
	long long newTime=0, newTime_audio=0, newTime_prev=0;
102 103
	struct timeval lastAudioSent = {0, 0};
103 104
	double ptsvideo1=0.0;
......
368 369
			}
369 370
		}
370 371

  
372
		if(newtime_anomalies_counter > 50) { //just a random threshold
373
			if(live_source) { //restart just in case of live source
374
#ifdef DEBUG_ANOMALIES
375
				fprintf(stderr, "READLOOP: too many NEGATIVE TIMESTAMPS anomalies. Restarting.\n");
376
#endif
377
				goto close;
378
			}
379
		}
380

  
371 381
		// Is this a packet from the video stream?
372 382
		if(packet.stream_index==videoStream)
373 383
		{
......
464 474
					if(frame->number>0) {
465 475
						newTime = ((double)target_pts-ptsvideo1)*1000.0/((double)delta_video*(double)av_q2d(pFormatCtx->streams[videoStream]->r_frame_rate));
466 476
					}
467
#ifdef DEBUG_VIDEO_FRAMES
477
#ifdef DEBUG_TIMESTAMPING
468 478
					fprintf(stderr, "VIDEO: NEWTIMESTAMP %ld\n", newTime);
469 479
#endif
470 480
					if(newTime<0) {
471 481
#ifdef DEBUG_VIDEO_FRAMES
472 482
						fprintf(stderr, "VIDEO: SKIPPING FRAME\n");
473 483
#endif
484
						newtime_anomalies_counter++;
474 485
						continue; //SKIP THIS FRAME, bad timestamp
475 486
					}
476 487
	
......
603 614
					newTime_audio = newTime*1000;
604 615
					
605 616
				}
606
#ifdef DEBUG_AUDIO_FRAMES
617
#ifdef DEBUG_TIMESTAMPING
607 618
				fprintf(stderr, "AUDIO: NEWTIMESTAMP %d\n", newTime);
608 619
#endif
609 620
				if(newTime<0) {
610 621
#ifdef DEBUG_AUDIO_FRAMES
611 622
					fprintf(stderr, "AUDIO: SKIPPING FRAME\n");
612 623
#endif
624
					newtime_anomalies_counter++;
613 625
					continue; //SKIP THIS FRAME, bad timestamp
614 626
				}
615 627

  
......
685 697
		}
686 698
	}
687 699

  
700
close:
688 701
	if(chunk->seq != 0 && chunk->frames_num>0) {
689 702
		//SAVE ON FILE
690 703
		//saveChunkOnFile(chunk);
......
744 757
		FirstTimeAudio=1;
745 758
		FirstTimeVideo=1;
746 759
		pts_anomalies_counter=0;
760
		newtime_anomalies_counter=0;
747 761
		newTime=0;
748 762
		newTime_audio=0;
749 763
		newTime_prev=0;

Also available in: Unified diff