summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/util/timeStampArray.h
blob: 8b11765291fbf85a1483b48558234e8d6e787336 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
  class for managing byte positions and associated time positions
  Copyright (C) 1999  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */


#ifndef __TIMESTAMPARRAY_H
#define __TIMESTAMPARRAY_H

#include "abstract/abs_thread.h"
#include "timeStamp.h"


/**
   This class deals with the problem to sync audio and video.
   Both streams are decoded in different threads, sometimes
   the video is decoded faster than the audio and sometimes
   not.
   <p>
   You need a general mechanism to decide, which is faster.
   It works like this:
   <p>
   When the mpeg stream is split in video/audio part the split thread
   writes the video/audio data to the inputInterface.
   Additionally it writes a timestamp to the interface.
   The interface counts the bytes and forward the bytes/timeStamp
   pait to this class.
   Later when the threads write to the outputInterface the ask
   this class (with the bytePostions) which timestamp it
   has and hass the data and the timestamp to the outputInterface.
   There we can decide what to do with the data.
   <p>
   1) audio faster than video = drop video picture
   <p>
   2) video faster than audio - wait for audio.
*/



class TimeStampArray {

  TimeStamp** tStampArray;

  int lastWritePos;
  int writePos;
  int readPos;
  int fillgrade;
  char* name;
  int entries;
  
  abs_thread_mutex_t writeInMut;
  abs_thread_mutex_t changeMut;


 public:
  TimeStampArray(char* name,int entries);
  ~TimeStampArray();


  int insertTimeStamp(TimeStamp* src,long key,int len);
  TimeStamp*  getReadTimeStamp();
  TimeStamp*  getTimeStamp(long key);
  int getFillgrade();
  void forward();
  void clear();

  int bytesUntilNext(long key);

 private:
  void lockStampArray();
  void unlockStampArray();
  void internalForward();
  


};
#endif