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 <stdint.h>
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 27000ULL
78 #define CLOCK_PER 27000000000ULL
79 #define SEC_PER (CLOCK_PER/s->frame_rate)
80 
81 
82 enum {
84 };
85 
86 typedef struct sequence_s{
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 } sequence_t;
107 
108 typedef
109 struct audio_frame_s{
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 } audio_frame_t;
122 
123 void pts2time(uint64_t pts, uint8_t *buf, int len);
124 int find_audio_sync(ringbuffer *rbuf, uint8_t *buf, int off, int type, int le);
125 int find_audio_s(const uint8_t *rbuf, int off, int type, int le);
126 int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le);
127 int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le);
128 int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le);
129 uint64_t add_pts_audio(uint64_t pts, audio_frame_t *aframe, uint64_t frames);
130 uint64_t next_ptsdts_video(uint64_t *pts, sequence_t *s, uint64_t fcount, uint64_t gcount);
131 void fix_audio_count(uint64_t *acount, audio_frame_t *aframe,
132  uint64_t origpts, uint64_t pts);
133 void fix_video_count(sequence_t *s, uint64_t *frame, uint64_t origpts,
134  uint64_t pts, uint64_t origdts, uint64_t dts);
135 
137  int off, int le, int type);
138 int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le);
139 
140 #endif /*_ELEMENT_H_*/
uint8_t flags
Definition: element.h:95
int check_audio_header(ringbuffer *rbuf, audio_frame_t *af, int off, int le, int type)
Definition: element.c:415
int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.c:479
int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.c:192
int set
Definition: element.h:87
uint32_t bit_rate
Definition: element.h:112
uint8_t current_frame
Definition: element.h:104
uint8_t aspect_ratio
Definition: element.h:91
uint64_t add_pts_audio(uint64_t pts, audio_frame_t *aframe, uint64_t frames)
Definition: element.c:56
void pts2time(uint64_t pts, uint8_t *buf, int len)
Definition: element.c:151
uint8_t pulldown
Definition: element.h:103
int find_audio_s(const uint8_t *rbuf, int off, int type, int le)
Definition: element.c:373
Definition: element.h:83
uint32_t framesize
Definition: element.h:117
Definition: element.h:83
uint32_t frametime
Definition: element.h:118
uint8_t pulldown_set
Definition: element.h:102
uint16_t v_size
Definition: element.h:90
uint32_t mode_extension
Definition: element.h:115
void fix_video_count(sequence_t *s, uint64_t *frame, uint64_t origpts, uint64_t pts, uint64_t origdts, uint64_t dts)
Definition: element.c:116
Definition: element.h:83
int ext_set
Definition: element.h:88
int find_audio_sync(ringbuffer *rbuf, uint8_t *buf, int off, int type, int le)
Definition: element.c:323
uint8_t chroma
Definition: element.h:101
int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.c:585
void fix_audio_count(uint64_t *acount, audio_frame_t *aframe, uint64_t origpts, uint64_t pts)
Definition: element.c:65
uint8_t progressive
Definition: element.h:100
unsigned short uint16_t
Definition: iso6937tables.h:1
int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.c:530
uint32_t off
Definition: element.h:119
uint32_t frequency
Definition: element.h:113
uint32_t mode
Definition: element.h:114
uint64_t next_ptsdts_video(uint64_t *pts, sequence_t *s, uint64_t fcount, uint64_t gcount)
Definition: element.c:75
uint32_t vbv_buffer_size
Definition: element.h:94
uint32_t frame_rate
Definition: element.h:92
uint8_t profile
Definition: element.h:99
uint8_t current_tmpref
Definition: element.h:105
uint8_t non_intra_quant[64]
Definition: element.h:97
struct audio_frame_s audio_frame_t
const char * frames[3]
Definition: element.c:46
uint32_t emphasis
Definition: element.h:116
int video_format
Definition: element.h:98
struct sequence_s sequence_t
uint8_t intra_quant[64]
Definition: element.h:96
char language[4]
Definition: element.h:120
uint16_t h_size
Definition: element.h:89
uint32_t bit_rate
Definition: element.h:93