summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/mpegplay/mpegVideoLength.h
blob: 79bece6a5f266ead05001777da7f7d02a96ca45a (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
86
87
88
89
90
91
92
93
/*
  mpg I video/audio player plugin
  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 __MPEGVIDEOLENGTH_H
#define __MPEGVIDEOLENGTH_H

#include "../input/inputPlugin.h"






/**
   This class calculates the length (in seconds) of an mpeg stream.
   I do not know how to make it right, my approach
   seeks at the beginning of the stream for the timecode in
   the picture gop then jumps near the end and does the same.
   then it substracts the values.
   It has some limitations, it does not seek higher than 600 MB,
   because it seems the kernel has some problems with this.
   (It resets the scsi system, and sometimes hang/crash)
   Thus it only seek near 600 and assumes linear relation
   for the rest. (Means: it calculates the length of the rest
   with the sec/mb value calculates from the 600 mb
   should be exact enough.
*/

class MpegVideoStream;
class MpegVideoHeader;
class MpegSystemStream;
class MpegSystemHeader;
class GOP;

class MpegVideoLength {

  // these are used fo non system streams
  MpegVideoHeader*     mpegVideoHeader;
  MpegVideoStream*     mpegVideoStream;

  // these for system streams
  MpegSystemHeader*    mpegSystemHeader;
  MpegSystemStream*    mpegSystemStream;

  
  InputStream* input;
  GOP* startGOP;
  GOP* endGOP;
  GOP* lengthGOP;


  int lHasStart;
  int lHasEnd;
  int lCanSeek;
  int lHasStream;
  int lHasSystemStream;
  int lHasRawStream;
  int lHasResync;
  int lSysLayer;
  long upperEnd;
  long realLength;

 public:
  MpegVideoLength(InputStream* input);
  ~MpegVideoLength();

  int firstInitialize();

  long getLength();
  long getSeekPos(int seconds);


 private:
  int seekToStart();
  int seekToEnd();
  int seekValue(unsigned int code,long& endPos);
  int parseToGOP(GOP* gop);
  int parseToPTS(GOP* gop);
  

};
#endif