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 <array>
31 #include <cstdint>
32 
33 #include "ringbuffer.h"
34 
35 #define PICTURE_START_CODE 0x00
36 #define SLICE_START_CODE_S 0x01
37 
38 #define SLICE_START_CODE_E 0xAF
39 #define EXCEPT_SLICE 0xb0
40 
41 #define USR_DATA_START_CODE 0xB2
42 #define SEQUENCE_HDR_CODE 0xB3
43 #define SEQUENCE_ERR_CODE 0xB4
44 #define EXTENSION_START_CODE 0xB5
45 #define SEQUENCE_END_CODE 0xB7
46 #define GROUP_START_CODE 0xB8
47 
48 #define SEQUENCE_EXTENSION 0x01
49 #define SEQUENCE_DISPLAY_EXTENSION 0x02
50 #define PICTURE_CODING_EXTENSION 0x08
51 #define QUANT_MATRIX_EXTENSION 0x03
52 #define PICTURE_DISPLAY_EXTENSION 0x07
53 
54 #define I_FRAME 0x01
55 #define P_FRAME 0x02
56 #define B_FRAME 0x03
57 #define D_FRAME 0x04
58 
59 #define OFF_SIZE 4
60 #define FIRST_FIELD 0
61 #define SECOND_FIELD 1
62 #define VIDEO_FRAME_PICTURE 0x03
63 
64 #define MPG_TIMESTEP 90000ULL
66 
67 #define CSPF_FLAG 0x04
68 #define INTRAQ_FLAG 0x02
69 #define NONINTRAQ_FLAG 0x01
70 
71 #define AUDIO_SYNCWORD 0x7ff /* or is it 0xfff */
72 #define AC3_SYNCWORD 0x0b77
73 
74 #define NOPULLDOWN 0
75 #define PULLDOWN32 1
76 #define PULLDOWN23 2
77 
78 #define CLOCK_MS 27000LL
79 #define CLOCK_PER 27000000000LL
80 #define SEC_PER (CLOCK_PER/s->frame_rate)
81 
82 
83 enum {
85 };
86 
87 struct sequence_t {
88  int set;
89  int ext_set;
92  uint8_t aspect_ratio;
93  uint32_t frame_rate;
94  uint32_t bit_rate;
95  uint32_t vbv_buffer_size;
96  uint8_t flags;
97  uint8_t intra_quant[64];
98  uint8_t non_intra_quant[64];
100  uint8_t profile;
101  uint8_t progressive;
102  uint8_t chroma;
103  uint8_t pulldown_set;
104  uint8_t pulldown;
105  uint8_t current_frame;
106  uint8_t current_tmpref;
107 };
108 
110  int set;
111  int layer;
112  uint32_t bit_rate;
113  uint32_t frequency;
114  uint32_t mode;
115  uint32_t mode_extension;
116  uint32_t emphasis;
117  uint32_t framesize;
118  uint32_t frametime;
119  uint32_t off;
120  char language[4];
121 };
122 
123 using audio_sync_buf = std::array<uint8_t,7>;
124 
125 void pts2time(uint64_t pts, uint8_t *buf, int len);
126 int find_audio_sync(ringbuffer *rbuf, audio_sync_buf &buf, int off, int type, int le);
127 int find_audio_s(const uint8_t *rbuf, int off, int type, int le);
128 int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le);
129 int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le);
130 int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le);
131 uint64_t add_pts_audio(uint64_t pts, audio_frame_t *aframe, uint64_t frames);
132 uint64_t next_ptsdts_video(uint64_t *pts, sequence_t *s, uint64_t fcount, uint64_t gcount);
133 void fix_audio_count(uint64_t *acount, audio_frame_t *aframe,
134  uint64_t origpts, uint64_t pts);
135 void fix_video_count(sequence_t *s, uint64_t *frame, uint64_t origpts,
136  uint64_t pts, uint64_t origdts, uint64_t dts);
137 
139  int off, int le, int type);
140 int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le);
141 
142 #endif /* ELEMENT_H */
ringbuffer.h
sequence_t::frame_rate
uint32_t frame_rate
Definition: element.h:93
sequence_t::pulldown_set
uint8_t pulldown_set
Definition: element.h:103
sequence_t::current_frame
uint8_t current_frame
Definition: element.h:105
find_audio_s
int find_audio_s(const uint8_t *rbuf, int off, int type, int le)
Definition: element.cpp:377
check_audio_header
int check_audio_header(ringbuffer *rbuf, audio_frame_t *af, int off, int le, int type)
Definition: element.cpp:419
get_audio_info
int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.cpp:483
get_video_info
int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.cpp:195
ringbuffer
Definition: ringbuffer.h:39
sequence_t
Definition: element.h:87
audio_frame_t::language
char language[4]
Definition: element.h:120
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
audio_frame_t::bit_rate
uint32_t bit_rate
Definition: element.h:112
sequence_t::bit_rate
uint32_t bit_rate
Definition: element.h:94
sequence_t::aspect_ratio
uint8_t aspect_ratio
Definition: element.h:92
VIDEO_NONE
@ VIDEO_NONE
Definition: element.h:65
sequence_t::pulldown
uint8_t pulldown
Definition: element.h:104
sequence_t::non_intra_quant
uint8_t non_intra_quant[64]
Definition: element.h:98
sequence_t::set
int set
Definition: element.h:88
MAX_TYPES
@ MAX_TYPES
Definition: element.h:84
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
VIDEO_PAL
@ VIDEO_PAL
Definition: element.h:65
VIDEO_NTSC
@ VIDEO_NTSC
Definition: element.h:65
NONE
@ NONE
Definition: element.h:84
get_video_ext_info
int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.cpp:591
audio_sync_buf
std::array< uint8_t, 7 > audio_sync_buf
Definition: element.h:123
sequence_t::h_size
uint16_t h_size
Definition: element.h:90
sequence_t::current_tmpref
uint8_t current_tmpref
Definition: element.h:106
LPCM
@ LPCM
Definition: element.h:84
get_ac3_info
int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.cpp:534
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:113
sequence_t::profile
uint8_t profile
Definition: element.h:100
audio_frame_t::set
int set
Definition: element.h:110
audio_frame_t::frametime
uint32_t frametime
Definition: element.h:118
audio_frame_t::emphasis
uint32_t emphasis
Definition: element.h:116
sequence_t::flags
uint8_t flags
Definition: element.h:96
sequence_t::v_size
uint16_t v_size
Definition: element.h:91
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:89
audio_frame_t::mode_extension
uint32_t mode_extension
Definition: element.h:115
sequence_t::vbv_buffer_size
uint32_t vbv_buffer_size
Definition: element.h:95
sequence_t::video_format
int video_format
Definition: element.h:99
find_audio_sync
int find_audio_sync(ringbuffer *rbuf, audio_sync_buf &buf, int off, int type, int le)
Definition: element.cpp:327
sequence_t::intra_quant
uint8_t intra_quant[64]
Definition: element.h:97
audio_frame_t::mode
uint32_t mode
Definition: element.h:114
audio_frame_t::framesize
uint32_t framesize
Definition: element.h:117
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:3
audio_frame_t
Definition: element.h:109
audio_frame_t::off
uint32_t off
Definition: element.h:119
audio_frame_t::layer
int layer
Definition: element.h:111
sequence_t::chroma
uint8_t chroma
Definition: element.h:102
AC3
@ AC3
Definition: element.h:84
sequence_t::progressive
uint8_t progressive
Definition: element.h:101
MPEG_AUDIO
@ MPEG_AUDIO
Definition: element.h:84