MythTV  master
element.h
Go to the documentation of this file.
1 /*
2  * element.h
3  *
4  *
5  * Copyright (C) 2003 Marcus Metzler <mocm@metzlerbros.de>
6  * Metzler Brothers Systementwicklung GbR
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * General Public License for more details.
18  *
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
24  *
25  */
26 
27 #ifndef ELEMENT_H
28 #define ELEMENT_H
29 
30 #include <cstdint>
31 
32 #include "ringbuffer.h"
33 
34 #define PICTURE_START_CODE 0x00
35 #define SLICE_START_CODE_S 0x01
36 
37 #define SLICE_START_CODE_E 0xAF
38 #define EXCEPT_SLICE 0xb0
39 
40 #define USR_DATA_START_CODE 0xB2
41 #define SEQUENCE_HDR_CODE 0xB3
42 #define SEQUENCE_ERR_CODE 0xB4
43 #define EXTENSION_START_CODE 0xB5
44 #define SEQUENCE_END_CODE 0xB7
45 #define GROUP_START_CODE 0xB8
46 
47 #define SEQUENCE_EXTENSION 0x01
48 #define SEQUENCE_DISPLAY_EXTENSION 0x02
49 #define PICTURE_CODING_EXTENSION 0x08
50 #define QUANT_MATRIX_EXTENSION 0x03
51 #define PICTURE_DISPLAY_EXTENSION 0x07
52 
53 #define I_FRAME 0x01
54 #define P_FRAME 0x02
55 #define B_FRAME 0x03
56 #define D_FRAME 0x04
57 
58 #define OFF_SIZE 4
59 #define FIRST_FIELD 0
60 #define SECOND_FIELD 1
61 #define VIDEO_FRAME_PICTURE 0x03
62 
63 #define MPG_TIMESTEP 90000ULL
65 
66 #define CSPF_FLAG 0x04
67 #define INTRAQ_FLAG 0x02
68 #define NONINTRAQ_FLAG 0x01
69 
70 #define AUDIO_SYNCWORD 0x7ff /* or is it 0xfff */
71 #define AC3_SYNCWORD 0x0b77
72 
73 #define NOPULLDOWN 0
74 #define PULLDOWN32 1
75 #define PULLDOWN23 2
76 
77 #define CLOCK_MS 27000LL
78 #define CLOCK_PER 27000000000LL
79 #define SEC_PER (CLOCK_PER/s->frame_rate)
80 
81 
82 enum {
84 };
85 
86 struct sequence_t {
87  int set;
88  int ext_set;
91  uint8_t aspect_ratio;
92  uint32_t frame_rate;
93  uint32_t bit_rate;
94  uint32_t vbv_buffer_size;
95  uint8_t flags;
96  uint8_t intra_quant[64];
97  uint8_t non_intra_quant[64];
99  uint8_t profile;
100  uint8_t progressive;
101  uint8_t chroma;
102  uint8_t pulldown_set;
103  uint8_t pulldown;
104  uint8_t current_frame;
105  uint8_t current_tmpref;
106 };
107 
109  int set;
110  int layer;
111  uint32_t bit_rate;
112  uint32_t frequency;
113  uint32_t mode;
114  uint32_t mode_extension;
115  uint32_t emphasis;
116  uint32_t framesize;
117  uint32_t frametime;
118  uint32_t off;
119  char language[4];
120 };
121 
122 void pts2time(uint64_t pts, uint8_t *buf, int len);
123 int find_audio_sync(ringbuffer *rbuf, uint8_t *buf, int off, int type, int le);
124 int find_audio_s(const uint8_t *rbuf, int off, int type, int le);
125 int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le);
126 int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le);
127 int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le);
128 uint64_t add_pts_audio(uint64_t pts, audio_frame_t *aframe, uint64_t frames);
129 uint64_t next_ptsdts_video(uint64_t *pts, sequence_t *s, uint64_t fcount, uint64_t gcount);
130 void fix_audio_count(uint64_t *acount, audio_frame_t *aframe,
131  uint64_t origpts, uint64_t pts);
132 void fix_video_count(sequence_t *s, uint64_t *frame, uint64_t origpts,
133  uint64_t pts, uint64_t origdts, uint64_t dts);
134 
136  int off, int le, int type);
137 int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le);
138 
139 #endif /* ELEMENT_H */
VIDEO_NTSC
@ VIDEO_NTSC
Definition: element.h:64
ringbuffer.h
sequence_t::frame_rate
uint32_t frame_rate
Definition: element.h:92
sequence_t::pulldown_set
uint8_t pulldown_set
Definition: element.h:102
sequence_t::current_frame
uint8_t current_frame
Definition: element.h:104
find_audio_s
int find_audio_s(const uint8_t *rbuf, int off, int type, int le)
Definition: element.cpp:376
check_audio_header
int check_audio_header(ringbuffer *rbuf, audio_frame_t *af, int off, int le, int type)
Definition: element.cpp:418
get_audio_info
int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.cpp:482
get_video_info
int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.cpp:195
ringbuffer
Definition: ringbuffer.h:36
sequence_t
Definition: element.h:86
MAX_TYPES
@ MAX_TYPES
Definition: element.h:83
audio_frame_t::language
char language[4]
Definition: element.h:119
add_pts_audio
uint64_t add_pts_audio(uint64_t pts, audio_frame_t *aframe, uint64_t frames)
Definition: element.cpp:56
pts2time
void pts2time(uint64_t pts, uint8_t *buf, int len)
Definition: element.cpp:154
AC3
@ AC3
Definition: element.h:83
audio_frame_t::bit_rate
uint32_t bit_rate
Definition: element.h:111
sequence_t::bit_rate
uint32_t bit_rate
Definition: element.h:93
sequence_t::aspect_ratio
uint8_t aspect_ratio
Definition: element.h:91
NONE
@ NONE
Definition: element.h:83
sequence_t::pulldown
uint8_t pulldown
Definition: element.h:103
sequence_t::non_intra_quant
uint8_t non_intra_quant[64]
Definition: element.h:97
sequence_t::set
int set
Definition: element.h:87
fix_video_count
void fix_video_count(sequence_t *s, uint64_t *frame, uint64_t origpts, uint64_t pts, uint64_t origdts, uint64_t dts)
Definition: element.cpp:117
get_video_ext_info
int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.cpp:590
find_audio_sync
int find_audio_sync(ringbuffer *rbuf, uint8_t *buf, int off, int type, int le)
Definition: element.cpp:326
sequence_t::h_size
uint16_t h_size
Definition: element.h:89
sequence_t::current_tmpref
uint8_t current_tmpref
Definition: element.h:105
get_ac3_info
int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.cpp:533
fix_audio_count
void fix_audio_count(uint64_t *acount, audio_frame_t *aframe, uint64_t origpts, uint64_t pts)
Definition: element.cpp:65
audio_frame_t::frequency
uint32_t frequency
Definition: element.h:112
sequence_t::profile
uint8_t profile
Definition: element.h:99
audio_frame_t::set
int set
Definition: element.h:109
audio_frame_t::frametime
uint32_t frametime
Definition: element.h:117
audio_frame_t::emphasis
uint32_t emphasis
Definition: element.h:115
sequence_t::flags
uint8_t flags
Definition: element.h:95
sequence_t::v_size
uint16_t v_size
Definition: element.h:90
next_ptsdts_video
uint64_t next_ptsdts_video(uint64_t *pts, sequence_t *s, uint64_t fcount, uint64_t gcount)
Definition: element.cpp:76
sequence_t::ext_set
int ext_set
Definition: element.h:88
audio_frame_t::mode_extension
uint32_t mode_extension
Definition: element.h:114
MPEG_AUDIO
@ MPEG_AUDIO
Definition: element.h:83
sequence_t::vbv_buffer_size
uint32_t vbv_buffer_size
Definition: element.h:94
sequence_t::video_format
int video_format
Definition: element.h:98
sequence_t::intra_quant
uint8_t intra_quant[64]
Definition: element.h:96
VIDEO_PAL
@ VIDEO_PAL
Definition: element.h:64
audio_frame_t::mode
uint32_t mode
Definition: element.h:113
audio_frame_t::framesize
uint32_t framesize
Definition: element.h:116
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:1
audio_frame_t
Definition: element.h:108
VIDEO_NONE
@ VIDEO_NONE
Definition: element.h:64
audio_frame_t::off
uint32_t off
Definition: element.h:118
audio_frame_t::layer
int layer
Definition: element.h:110
sequence_t::chroma
uint8_t chroma
Definition: element.h:101
sequence_t::progressive
uint8_t progressive
Definition: element.h:100
LPCM
@ LPCM
Definition: element.h:83