| 1 |
/* dvbcut |
| 2 |
Copyright (c) 2005 Sven Over <[email protected]> |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 2 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
/* $Id$ */ |
| 20 |
|
| 21 |
#ifndef _DVBCUT_TSFILE_H |
| 22 |
#define _DVBCUT_TSFILE_H |
| 23 |
|
| 24 |
#include <stdint.h> |
| 25 |
#include "mpgfile.h" |
| 26 |
#define MAXPACKETSIZE (208) |
| 27 |
#define TSPACKETSIZE (188) |
| 28 |
#define TSSYNCBYTE (0x47) |
| 29 |
|
| 30 |
// stuff to identify proprietary (topfield) headers and find bookmarks |
| 31 |
// ==> magic ('TFrc') &version number, position of bookmarks, length of header, max number of bookmarks |
| 32 |
#define TF5XXXPVR_MAGIC (0x54467263) |
| 33 |
#define TF5XXXPVR_LEN (20*TSPACKETSIZE) |
| 34 |
#define TF5XXXPVR_MAX (64) |
| 35 |
#define TF5000PVR_VERSION (0x5000) |
| 36 |
#define TF5000PVR_POS (1400) |
| 37 |
#define TF5010PVR_VERSION (0x5010) |
| 38 |
#define TF5010PVR_POS (1404) |
| 39 |
#define TF4000PVR_LEN (3*TSPACKETSIZE) |
| 40 |
#define TF4000PVR_POS (216) |
| 41 |
#define TF7700HDPVR_LEN (2636) |
| 42 |
#define TF7700HDPVR_MAX (48) |
| 43 |
#define TF7700HDPVR_POS (1040) |
| 44 |
|
| 45 |
/** |
| 46 |
@author Sven Over |
| 47 |
*/ |
| 48 |
|
| 49 |
class tsfile : public mpgfile |
| 50 |
{ |
| 51 |
protected: |
| 52 |
struct tspacket { |
| 53 |
uint8_t data[MAXPACKETSIZE]; |
| 54 |
|
| 55 |
int pid() const { |
| 56 |
return ((data[1]&0x1f)<<8) | data[2]; |
| 57 |
} |
| 58 |
bool transport_error_indicator() const { |
| 59 |
return data[1] & 0x80; |
| 60 |
} |
| 61 |
bool payload_unit_start_indicator() const { |
| 62 |
return data[1] & 0x40; |
| 63 |
} |
| 64 |
bool transport_priority() const { |
| 65 |
return data[1] & 0x20; |
| 66 |
} |
| 67 |
int transport_scrambling_control() const { |
| 68 |
return (data[3]>>6)&0x03; |
| 69 |
} |
| 70 |
bool contains_adaptation_field() const { |
| 71 |
return data[3]&0x20; |
| 72 |
} |
| 73 |
bool contains_payload() const { |
| 74 |
return data[3]&0x10; |
| 75 |
} |
| 76 |
int continuity_counter() const { |
| 77 |
return data[3]&0x0f; |
| 78 |
} |
| 79 |
const void *adaptation_field() const { |
| 80 |
return contains_adaptation_field()?&data[4]:0; |
| 81 |
} |
| 82 |
int adaptation_field_length() const { |
| 83 |
return contains_adaptation_field()?(1+data[4]):0; |
| 84 |
} |
| 85 |
const void *payload() const { |
| 86 |
return contains_payload()?(void*) &data[4+adaptation_field_length()]:0; |
| 87 |
} |
| 88 |
int payload_length() const { |
| 89 |
return contains_payload()?(184-adaptation_field_length()):0; |
| 90 |
} |
| 91 |
int sid() const { |
| 92 |
if (!(payload_unit_start_indicator()&&contains_payload())) |
| 93 |
return -1; |
| 94 |
int afl=adaptation_field_length(); |
| 95 |
if (afl>180) |
| 96 |
return -1; // no space for four bytes of payload |
| 97 |
const uint8_t *d=data+4+afl; |
| 98 |
if (d[0]==0 && d[1]==0 && d[2]==1) |
| 99 |
return d[3]; |
| 100 |
return -1; |
| 101 |
} |
| 102 |
}; |
| 103 |
|
| 104 |
unsigned int packetsize; // usually 188, but sometimes more |
| 105 |
|
| 106 |
int streamnumber[8192]; // TS pids are 0..8191 |
| 107 |
|
| 108 |
bool check_si_tables(); |
| 109 |
size_t get_si_table(uint8_t*, size_t, size_t&, int, int); |
| 110 |
|
| 111 |
int isTOPFIELD(const uint8_t*, int, std::string); |
| 112 |
int isTF7700HDPVR(std::string); |
| 113 |
enum bookmarktype { none, byte, time, pic }; |
| 114 |
bookmarktype bmtype; // indicates type of read bookmarks |
| 115 |
std::vector<int> pic_bookmarks; // to store the bookmarks as frame numbers (returned by getbookmarks) |
| 116 |
std::vector<dvbcut_off_t> byte_bookmarks; // to store the bookmarks as byte positions |
| 117 |
std::vector<pts_t> time_bookmarks; // to store the bookmarks as time stamps |
| 118 |
|
| 119 |
public: |
| 120 |
tsfile(inbuffer &b, int initial_offset, int stride); |
| 121 |
|
| 122 |
~tsfile(); |
| 123 |
int streamreader(struct streamhandle &s); |
| 124 |
static int probe(inbuffer &buf, int stride); |
| 125 |
virtual int mplayeraudioid(int astr) { |
| 126 |
return s[audiostream(astr)].id; |
| 127 |
} |
| 128 |
virtual bool istransportstream() { |
| 129 |
return true; |
| 130 |
} |
| 131 |
virtual std::vector<int> getbookmarks() { |
| 132 |
if(bmtype==byte) { |
| 133 |
// convert byte positions to frame numbers if not already done/stored |
| 134 |
int picnr; |
| 135 |
for (std::vector<dvbcut_off_t>::iterator b = byte_bookmarks.begin(); b != byte_bookmarks.end(); ++b) |
| 136 |
if((picnr = getpictureatposition(*b)) >= 0) |
| 137 |
pic_bookmarks.push_back(picnr); |
| 138 |
bmtype = pic; |
| 139 |
} else if(bmtype==time) { |
| 140 |
// convert pts positions to frame numbers if not already done/stored |
| 141 |
int picnr; |
| 142 |
for (std::vector<pts_t>::iterator b = time_bookmarks.begin(); b != time_bookmarks.end(); ++b) |
| 143 |
if((picnr = getpictureattime(*b)) >= 0) |
| 144 |
pic_bookmarks.push_back(picnr); |
| 145 |
bmtype = pic; |
| 146 |
} |
| 147 |
return pic_bookmarks; |
| 148 |
} |
| 149 |
|
| 150 |
}; |
| 151 |
|
| 152 |
#endif |