Revision 88fe20d0

View differences:

chunker_player.c
37 37

  
38 38
#define SDL_AUDIO_BUFFER_SIZE 1024
39 39

  
40
#define QUEUE_FILLING_THRESHOLD 200
40
#define QUEUE_FILLING_THRESHOLD 30
41 41
#define MAX_TOLLERANCE 40
42 42
#define AUDIO	1
43 43
#define VIDEO	2
44 44

  
45
//#define DEBUG_AUDIO
45
#define DEBUG_AUDIO
46 46
//#define DEBUG_VIDEO
47
//#define DEBUG_QUEUE
48
//#define DEBUG_SOURCE
47
#define DEBUG_QUEUE
48
#define DEBUG_SOURCE
49 49
//#define DEBUG_ENQUEUE
50 50
//#define DEBUG_STATS
51
//#define DEBUG_AUDIO_BUFFER
52
//#define DEBUG_ENQUEUE
51
#define DEBUG_AUDIO_BUFFER
52

  
53 53

  
54 54
short int QueueFillingMode=1;
55 55
short int QueueStopped=0;
......
60 60
	int nb_packets;
61 61
	int size;
62 62
	SDL_mutex *mutex;
63
	//SDL_cond *cond;
64 63
	short int queueType;
65 64
	int last_frame_extracted; //HINT THIS SHOULD BE MORE THAN 4 BYTES
66 65
	int total_lost_frames;
......
99 98
#endif
100 99
	memset(q,0,sizeof(PacketQueue));
101 100
	q->mutex = SDL_CreateMutex();
102
	//q->cond = SDL_CreateCond();
103 101
	QueueFillingMode=1;
104 102
	q->queueType=Type;
105
	q->last_frame_extracted = 3;
103
	q->last_frame_extracted = -1;
106 104
	q->total_lost_frames = 0;
107 105
	q->first_pkt= NULL;
108 106
	//q->last_pkt = NULL;
......
137 135
#endif
138 136

  
139 137
	QueueFillingMode=1;
140
	q->last_frame_extracted = 3;
138
	q->last_frame_extracted = -1;
141 139
	q->total_lost_frames = 0;
142 140
	q->first_pkt= NULL;
143 141
	//q->last_pkt = NULL;
......
158 156
	//make a copy of the incoming packet
159 157
	if(av_dup_packet(pkt) < 0) {
160 158
#ifdef DEBUG_QUEUE
161
		printf("QUEUE: PUT in Queue cannot duplicate in packet	: NPackets=%d Type=%d\n",q->nb_packets,q->queueType);
159
		printf("QUEUE: PUT in Queue cannot duplicate in packet	: NPackets=%d Type=%d\n",q->nb_packets, q->queueType);
162 160
#endif
163 161
		return -1;
164 162
	}
......
173 171

  
174 172
	SDL_LockMutex(q->mutex);
175 173

  
176
/*
177
	if(QueueFillingMode) {
178
		q->last_frame_extracted = 0;
179
		FirstTime = 1;
180
		FirstTimeAudio = 1;
181
	}
182
*/
183

  
184 174
	// INSERTION SORT ALGORITHM
185 175
	// before inserting pkt, check if pkt.stream_index is <= current_extracted_frame.
186

  
187
	if(pkt->stream_index>q->last_frame_extracted) {
176
	if(pkt->stream_index > q->last_frame_extracted) {
188 177
		// either checking starting from the first_pkt or needed other struct like AVPacketList with next and prev....
189 178
		//if (!q->last_pkt)
190 179
		if(!q->first_pkt)
......
197 186
		}
198 187
		else {
199 188
			tmp = q->first_pkt;
200
			while(tmp->pkt.stream_index<pkt->stream_index) {
189
			while(tmp->pkt.stream_index < pkt->stream_index) {
201 190
				prevtmp = tmp;
202 191
				tmp = tmp->next;
203 192

  
......
205 194
					break;
206 195
				}
207 196
			}
208
			if(tmp && tmp->pkt.stream_index==pkt->stream_index) {
197
			if(tmp && tmp->pkt.stream_index == pkt->stream_index) {
209 198
				//we already have a frame with that index
210 199
				skip = 1;
211 200
#ifdef DEBUG_QUEUE
......
218 207
			}
219 208
			//q->last_pkt->next = pkt1; // It was uncommented when not insertion sort
220 209
		}
221
		if(skip==0) {
210
		if(skip == 0) {
222 211
			//q->last_pkt = pkt1;
223 212
			q->nb_packets++;
224 213
			q->size += pkt1->pkt.size;
......
228 217
#ifdef DEBUG_QUEUE
229 218
				printf("QUEUE: PUT: FillingMode set to zero\n");
230 219
#endif
231
				//SDL_CondSignal(q->cond);
232 220
			}
233
			//WHYq->last_frame_extracted = pkt->stream_index;
234 221
		}
235 222
	}
236 223
	else {
......
246 233
}
247 234

  
248 235

  
249
void decode_enqueued_audio_packet(AVPacket *pkt) {
236
int decode_enqueued_audio_packet(AVPacket *pkt, PacketQueue *q) {
250 237
	uint16_t *audio_bufQ = NULL;
251 238
	int16_t *dataQ = NULL;
252 239
	int data_sizeQ = AVCODEC_MAX_AUDIO_FRAME_SIZE;
......
258 245
	audio_bufQ = (uint16_t *)av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
259 246
	if(audio_bufQ) {
260 247
#ifdef DEBUG_AUDIO_BUFFER
261
			printf("AUDIO_BUFFER: about to decode packet %d, size %d, data %d\n", pkt->stream_index, pkt->size, pkt->data);
248
		printf("AUDIO_BUFFER: about to decode packet %d, size %d, data %d\n", pkt->stream_index, pkt->size, pkt->data);
262 249
#endif
263 250
		//decode the packet data
264 251
		lenQ = avcodec_decode_audio3(aCodecCtx, (int16_t *)audio_bufQ, &data_sizeQ, pkt);
......
266 253
			dataQ = (int16_t *)av_malloc(data_sizeQ); //this will be free later at the time of playback
267 254
			if(dataQ) {
268 255
				memcpy(dataQ, audio_bufQ, data_sizeQ);
269
				//discard the encoded bytes
256
				//discard the old encoded bytes
270 257
				av_free(pkt->data);
258
				//subtract them from queue size
259
				q->size -= pkt->size;
271 260
				pkt->data = (int8_t *)dataQ;
272 261
				pkt->size = data_sizeQ;
262
				//add new size to queue size
263
				q->size += pkt->size;
264
				return 1;
273 265
			}
274 266
			else {
275
				//discard the encoded bytes
276
				av_free(pkt->data);
277
				pkt->data = NULL;
278
				pkt->size = 0;
279 267
#ifdef DEBUG_AUDIO_BUFFER
280 268
				printf("AUDIO_BUFFER: cannot alloc space for decoded packet %d\n", pkt->stream_index);
281 269
#endif
282 270
			}
283 271
		}
284 272
		else {
285
			//discard the encoded bytes
286
			av_free(pkt->data);
287
			pkt->data = NULL;
288
			pkt->size = 0;
289 273
#ifdef DEBUG_AUDIO_BUFFER
290 274
			printf("AUDIO_BUFFER: cannot decode packet %d\n", pkt->stream_index);
291 275
#endif
......
293 277
		av_free(audio_bufQ);
294 278
	}
295 279
	else {
296
		//discard the encoded bytes
297
		av_free(pkt->data);
298
		pkt->data = NULL;
299
		pkt->size = 0;
300 280
#ifdef DEBUG_AUDIO_BUFFER
301 281
		printf("AUDIO_BUFFER: cannot alloc decode buffer for packet %d\n", pkt->stream_index);
302 282
#endif
303 283
	}
284
	return 0; //problems occurred
304 285
}
305 286

  
306 287

  
288
//removes a packet from the list and returns the next
289
AVPacketList *remove_from_queue(PacketQueue *q, AVPacketList *p) {
290
	AVPacketList *retpk = p->next;
291
	q->nb_packets--;
292
	//adjust size here and not in the various cases of the dequeue
293
	q->size -= p->pkt.size;
294
	av_free_packet(&p->pkt);
295
	av_free(p);
296
	return retpk;
297
}
307 298

  
299
AVPacketList *seek_and_decode_packet_starting_from(AVPacketList *p, PacketQueue *q) {
300
	while(p) {
301
			//check if audio packet has been already decoded
302
			if(p->pkt.convergence_duration == 0) {
303
				//not decoded yet, try to decode it
304
				if( !decode_enqueued_audio_packet(&(p->pkt), q) ) {
305
					//it was not possible to decode this packet, return next one
306
					p = remove_from_queue(q, p);
307
				}
308
				else
309
					return p;
310
			}
311
			else
312
				return p;
313
	}
314
	return NULL;
315
}
316

  
317
void update_queue_stats(PacketQueue *q, int packet_index) {
318
	//compute lost frame statistics
319
	if(q->last_frame_extracted > 0 && packet_index > q->last_frame_extracted) {
320
		q->total_lost_frames = q->total_lost_frames + packet_index - q->last_frame_extracted - 1;
321
#ifdef DEBUG_STATS
322
		printf("  STATS QUEUE stats: stidx %d last %d tot %d\n", packet_index, q->last_frame_extracted, q->total_lost_frames);
323
#endif
324
	}
325
}
308 326

  
309 327
int packet_queue_get(PacketQueue *q, AVPacket *pkt, short int av) {
310 328
	//AVPacket tmp;
......
322 340
	{
323 341
		SDL_UnlockMutex(q->mutex);
324 342
		return -1;
325
		//SDL_CondWait(q->cond, q->mutex);
326 343
	}
327 344

  
328
	pkt1 = q->first_pkt;
329
	if (pkt1) {
330
		if(av==1) {
331

  
332

  
333
			//check if audio packet has been alread decoded
334
			if(pkt1->pkt.convergence_duration == 0) {
335
				//not decoded yet, decode it
336
				decode_enqueued_audio_packet(&(pkt1->pkt));
337
			}
338

  
339

  
340
			if(pkt1->pkt.size-AudioQueueOffset>dimAudioQ) {
345
	if(av==1) { //somebody requested an audio packet, q is the audio queue
346
		//try to dequeue the first packet of the audio queue
347
		pkt1 = seek_and_decode_packet_starting_from(q->first_pkt, q);
348
		if(pkt1) { //yes we have them!
349
			if(pkt1->pkt.size-AudioQueueOffset > dimAudioQ) {
350
				//one packet if enough to give us the requested number of bytes by the audio_callback
341 351
#ifdef DEBUG_QUEUE
342 352
				printf("  AV=1 and Extract from the same packet\n");
343 353
#endif
344
				//av_init_packet(&tmp);
345
				q->size -= dimAudioQ;
346 354
				pkt->size = dimAudioQ;
347
				//tmp.data = pkt1->pkt.data+AudioQueueOffset;
348 355
				memcpy(pkt->data,pkt1->pkt.data+AudioQueueOffset,dimAudioQ);
349 356
				pkt->dts = pkt1->pkt.dts;
350 357
				pkt->pts = pkt1->pkt.pts;
......
352 359
				pkt->flags = 1;
353 360
				pkt->pos = -1;
354 361
				pkt->convergence_duration = -1;
355

  
356
				//*pkt = tmp;
357
				//pkt1->pkt.size -= dimAudioQ;
358 362
#ifdef DEBUG_QUEUE
359
				printf("   Adjust timestamps Old = %lld New = %lld\n",pkt1->pkt.dts,(int64_t)(pkt1->pkt.dts + deltaAudioQ + deltaAudioQError));
363
				printf("   Adjust timestamps Old = %lld New = %lld\n", pkt1->pkt.dts, (int64_t)(pkt1->pkt.dts + deltaAudioQ + deltaAudioQError));
360 364
#endif
361 365
				int64_t Olddts=pkt1->pkt.dts;
362 366
				pkt1->pkt.dts += deltaAudioQ + deltaAudioQError;
......
366 370
#ifdef DEBUG_QUEUE
367 371
				printf("   deltaAudioQError = %f\n",deltaAudioQError);
368 372
#endif
369
				
370
				ret = 1;
371
				//compute lost frame statistics
372
				if(q->last_frame_extracted > 0 && pkt->stream_index > q->last_frame_extracted) {
373
					q->total_lost_frames = q->total_lost_frames + pkt->stream_index - q->last_frame_extracted - 1;
374
#ifdef DEBUG_STATS
375
					printf("  AUDIO stats: stidx %d last %d tot %d\n", pkt->stream_index, q->last_frame_extracted, q->total_lost_frames);
376
#endif
377
				}
373
				//update overall state of queue
374
				//size is diminished because we played some audio samples
375
				//but packet is not removed since a portion has still to be played
376
				//HINT ERRATA we had a size mismatch since size grows with the
377
				//number of compressed bytes, and diminishes here with the number
378
				//of raw uncompressed bytes, hence we update size during the
379
				//real removes and not here anymore
380
				//q->size -= dimAudioQ;
381
				update_queue_stats(q, pkt->stream_index);
378 382
				//update index of last frame extracted
379 383
				q->last_frame_extracted = pkt->stream_index;
380 384
#ifdef DEBUG_AUDIO_BUFFER
381 385
				printf("1: idx %d    \taqo %d    \tstc %d    \taqe %f    \tpsz %d\n", pkt1->pkt.stream_index, AudioQueueOffset, SizeToCopy, deltaAudioQError, pkt1->pkt.size);
382 386
#endif
387
				ret = 1; //OK
383 388
			}
384 389
			else {
390
				//we need bytes from two consecutive packets to satisfy the audio_callback
385 391
#ifdef DEBUG_QUEUE
386 392
				printf("  AV = 1 and Extract from 2 packets\n");
387 393
#endif
388
				// Check for loss
394
				//check for a valid next packet since we will finish the current packet
395
				//and also take some bytes from the next one
396
				pkt1->next = seek_and_decode_packet_starting_from(pkt1->next, q);
389 397
				if(pkt1->next) {
390

  
391
					//check if next audio packet has been already decoded
392
					if(pkt1->next->pkt.convergence_duration == 0) {
393
						//not decoded yet, decode it
394
						decode_enqueued_audio_packet(&(pkt1->next->pkt));
395
					}
396

  
397 398
#ifdef DEBUG_QUEUE
398 399
					printf("   we have a next...\n");
399 400
#endif
400
					//av_init_packet(&tmp);
401 401
					pkt->size = dimAudioQ;
402 402
					pkt->dts = pkt1->pkt.dts;
403 403
					pkt->pts = pkt1->pkt.pts;
......
410 410
#ifdef DEBUG_QUEUE
411 411
						printf("      SizeToCopy=%d\n",SizeToCopy);
412 412
#endif
413
						memcpy(pkt->data,pkt1->pkt.data+AudioQueueOffset,SizeToCopy);
414
						memcpy(pkt->data+SizeToCopy,pkt1->next->pkt.data,(dimAudioQ-SizeToCopy)*sizeof(uint8_t));
413
						memcpy(pkt->data, pkt1->pkt.data+AudioQueueOffset, SizeToCopy);
414
						memcpy(pkt->data+SizeToCopy, pkt1->next->pkt.data, (dimAudioQ-SizeToCopy)*sizeof(uint8_t));
415 415
					}
416 416
#ifdef DEBUG_AUDIO_BUFFER
417 417
					printf("2: idx %d    \taqo %d    \tstc %d    \taqe %f    \tpsz %d\n", pkt1->pkt.stream_index, AudioQueueOffset, SizeToCopy, deltaAudioQError, pkt1->pkt.size);
......
422 422
					printf("2: NONEXT\n");
423 423
				}
424 424
#endif
425
				q->first_pkt = pkt1->next;
426
//				if (!q->first_pkt)
427
//					q->last_pkt = NULL;
428
				q->nb_packets--;
429
				q->size -= SizeToCopy;
430
				av_free_packet(&pkt1->pkt);//free(pkt1->pkt.data);
431
				av_free(pkt1);
425
				//HINT SEE before q->size -= SizeToCopy;
426
				q->first_pkt = remove_from_queue(q, pkt1);
432 427

  
433 428
				// Adjust timestamps
434 429
				pkt1 = q->first_pkt;
435
				if(pkt1)
436
				{
430
				if(pkt1) {
437 431
					int Offset=(dimAudioQ-SizeToCopy)*1000/(spec.freq*2*spec.channels);
438 432
					int64_t LastDts=pkt1->pkt.dts;
439 433
					pkt1->pkt.dts += Offset + deltaAudioQError;
......
443 437
					printf("   Adjust timestamps Old = %lld New = %lld\n", LastDts, pkt1->pkt.dts);
444 438
#endif
445 439
					AudioQueueOffset = dimAudioQ - SizeToCopy;
446
					q->size -= AudioQueueOffset;
440
					//SEE BEFORE HINT q->size -= AudioQueueOffset;
447 441
					ret = 1;
448 442
				}
449
				else
450
				{
443
				else {
451 444
					AudioQueueOffset=0;
452 445
#ifdef DEBUG_AUDIO_BUFFER
453 446
					printf("0: idx %d    \taqo %d    \tstc %d    \taqe %f    \tpsz %d\n", pkt1->pkt.stream_index, AudioQueueOffset, SizeToCopy, deltaAudioQError, pkt1->pkt.size);
......
456 449
#ifdef DEBUG_QUEUE
457 450
				printf("   deltaAudioQError = %f\n",deltaAudioQError);
458 451
#endif
459

  
460
				//compute lost frame statistics
461
				if(q->last_frame_extracted > 0 && pkt->stream_index > q->last_frame_extracted) {
462
					q->total_lost_frames = q->total_lost_frames + pkt->stream_index - q->last_frame_extracted - 1;
463
#ifdef DEBUG_STATS
464
					printf("  AUDIO stats: stidx %d last %d tot %d\n", pkt->stream_index, q->last_frame_extracted, q->total_lost_frames);
465
#endif
466
				}
452
				update_queue_stats(q, pkt->stream_index);
467 453
				//update index of last frame extracted
468 454
				q->last_frame_extracted = pkt->stream_index;
469 455
			}
470 456
		}
471
		else {
457
	}
458
	else { //somebody requested a video packet, q is the video queue
459
		pkt1 = q->first_pkt;
460
		if(pkt1) {
472 461
#ifdef DEBUG_QUEUE
473 462
			printf("  AV not 1\n");
474 463
#endif
475
			q->first_pkt = pkt1->next;
476
//			if (!q->first_pkt)
477
//				q->last_pkt = NULL;
478
			q->nb_packets--;
479
			q->size -= pkt1->pkt.size;
480
			
481 464
			pkt->size = pkt1->pkt.size;
482 465
			pkt->dts = pkt1->pkt.dts;
483 466
			pkt->pts = pkt1->pkt.pts;
......
486 469
			pkt->pos = pkt1->pkt.pos;
487 470
			pkt->convergence_duration = pkt1->pkt.convergence_duration;
488 471
			//*pkt = pkt1->pkt;
489
			memcpy(pkt->data,pkt1->pkt.data,pkt1->pkt.size);
490
			av_free_packet(&pkt1->pkt);//free(pkt1->pkt.data);
491
			av_free(pkt1);
472
			memcpy(pkt->data, pkt1->pkt.data, pkt1->pkt.size);
473

  
474
			//HINT SEE BEFORE q->size -= pkt1->pkt.size;
475
			q->first_pkt = remove_from_queue(q, pkt1);
476

  
492 477
			ret = 1;
493
			//compute lost frame statistics
494
			if(q->last_frame_extracted > 0 && pkt->stream_index > q->last_frame_extracted) {
495
#ifdef DEBUG_STATS
496
				//printf("  VIDEO stats: stidx %d last %d tot %d\n", pkt->stream_index, q->last_frame_extracted, q->total_lost_frames);
497
#endif
498
				q->total_lost_frames = q->total_lost_frames + pkt->stream_index - q->last_frame_extracted - 1;
499
			}
478
			update_queue_stats(q, pkt->stream_index);
500 479
			//update index of last frame extracted
501 480
			q->last_frame_extracted = pkt->stream_index;
502 481
		}
503
	}
504 482
#ifdef DEBUG_QUEUE
505
	else {
506
		printf("  pk1 NULL!!!!\n");
507
	}
483
		else {
484
			printf("  VIDEO pk1 NULL!!!!\n");
485
		}
508 486
#endif
487
	}
509 488

  
510 489
	if(q->nb_packets==0 && q->queueType==AUDIO) {
511 490
		QueueFillingMode=1;
......
693 672

  
694 673
		DecodeVideo = 0;
695 674
		SkipVideo = 0;
696
		//gettimeofday(&now,NULL);
697
		//Now = (unsigned long long)now.tv_sec*1000+(unsigned long long)now.tv_usec/1000;
698 675
		Now=(long long)SDL_GetTicks();
699 676
		if(FirstTime==1 && videoq.size>0) {
700 677
			if(videoq.first_pkt->pkt.pts>0)
......
713 690
		if(videoq.first_pkt)
714 691
		{
715 692
			printf("VIDEO: VideoCallback - Syncro params: Delta:%lld Now:%lld pts=%lld pts+Delta=%lld ",(long long)DeltaTime,Now,(long long)videoq.first_pkt->pkt.pts,(long long)videoq.first_pkt->pkt.pts+DeltaTime);
716
			printf("VIDEO: Index=%d ",(int)videoq.first_pkt->pkt.stream_index);
717
			printf("VIDEO: QueueLen=%d ",(int)videoq.nb_packets);
718
			printf("VIDEO: QueueSize=%d\n",(int)videoq.size);
693
			printf("VIDEO: Index=%d ", (int)videoq.first_pkt->pkt.stream_index);
694
			printf("VIDEO: QueueLen=%d ", (int)videoq.nb_packets);
695
			printf("VIDEO: QueueSize=%d\n", (int)videoq.size);
719 696
		}
720 697
		else
721 698
			printf("VIDEO: VideoCallback - Empty queue\n");
......
1221 1198
#ifdef DEBUG_ENQUEUE
1222 1199
printf("O\n");
1223 1200
#endif
1224

  
1225
			//video_bufQ = (uint8_t *)malloc(frame->size); //this gets freed at the time of packet_queue_get
1226
			//if(video_bufQ) {
1227
				//memcpy(video_bufQ, buffer, frame->size);
1228 1201
				packet.data = buffer;//video_bufQ;
1229 1202
				packet.size = frame->size;
1230 1203
				packet.pts = frame->timestamp.tv_sec*(unsigned long long)1000+frame->timestamp.tv_usec;
......
1234 1207
#ifdef DEBUG_ENQUEUE
1235 1208
printf("BBBBBBBO\n");
1236 1209
#endif
1237
				packet_queue_put(&videoq,&packet);//makes a copy of the packet
1210
			if(packet.size > 0)
1211
				packet_queue_put(&videoq, &packet); //the _put makes a copy of the packet
1238 1212
#ifdef DEBUG_ENQUEUE
1239 1213
printf("AAAAAAAAAAO\n");
1240 1214
#endif
1241 1215
#ifdef DEBUG_SOURCE
1242 1216
				printf("SOURCE: Insert video in queue pts=%lld %d %d sindex:%d\n",packet.pts,(int)frame->timestamp.tv_sec,(int)frame->timestamp.tv_usec,packet.stream_index);
1243 1217
#endif
1244
			//}
1245 1218
		}
1246 1219
		else { // audio frame
1247 1220
#ifdef DEBUG_ENQUEUE
......
1252 1225
#ifdef DEBUG_ENQUEUE
1253 1226
printf("O\n");
1254 1227
#endif
1255

  
1256 1228
			packetaudio.data = buffer;
1257 1229
			packetaudio.size = frame->size;
1258

  
1259 1230
			packetaudio.pts = frame->timestamp.tv_sec*(unsigned long long)1000+frame->timestamp.tv_usec;
1260 1231
			packetaudio.dts = frame->timestamp.tv_sec*(unsigned long long)1000+frame->timestamp.tv_usec;
1261 1232
			//packetaudio.duration = frame->timestamp.tv_sec;
......
1267 1238
			packetaudio.convergence_duration = 0;
1268 1239

  
1269 1240
			// insert the audio frame into the queue
1270
/*
1271
			data_sizeQ = AVCODEC_MAX_AUDIO_FRAME_SIZE;
1272

  
1273
			lenQ = avcodec_decode_audio3(aCodecCtx, (int16_t *)audio_bufQ, &data_sizeQ, &packetaudio);
1274

  
1275
			if(lenQ>0)
1276
			{
1277

  
1278
				// for freeing there is some memory still in tempdata to be freed
1279
				dataQ = (int16_t *)av_malloc(data_sizeQ);
1280
				if(dataQ)
1281
				{
1282
					memcpy(dataQ,audio_bufQ,data_sizeQ);
1283
					packetaudio.data = (int8_t *)dataQ;
1284
					packetaudio.size = data_sizeQ;
1285
					packetaudio.stream_index = frame->number; // use of stream_index for number frame
1286
*/
1287 1241
#ifdef DEBUG_ENQUEUE
1288 1242
printf("BEFORAO\n");
1289 1243
#endif
1290
					packet_queue_put(&audioq, &packetaudio);//makes a copy of the packet so i can free here
1244
			if(packetaudio.size > 0)
1245
				packet_queue_put(&audioq, &packetaudio);//makes a copy of the packet so i can free here
1291 1246
#ifdef DEBUG_ENQUEUE
1292 1247
printf("AFTAO\n");
1293 1248
#endif
1294
/*
1295
					av_free(dataQ);
1296
*/
1297 1249
#ifdef DEBUG_SOURCE
1298
					printf("SOURCE: Insert audio in queue pts=%lld sindex:%d\n", packetaudio.pts, packetaudio.stream_index);
1250
			printf("SOURCE: Insert audio in queue pts=%lld sindex:%d\n", packetaudio.pts, packetaudio.stream_index);
1299 1251
#endif
1300
/*
1301
				}
1302
			}
1303
*/
1304 1252
		}
1305 1253
		j = j - sizeFrame - frame->size;
1306 1254
	}

Also available in: Unified diff