1 | /*
|
---|
2 | * linuxdvb output/writer handling.
|
---|
3 | *
|
---|
4 | * konfetti 2010 based on linuxdvb.c code from libeplayer2
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
19 | *
|
---|
20 | */
|
---|
21 |
|
---|
22 | /* ***************************** */
|
---|
23 | /* Includes */
|
---|
24 | /* ***************************** */
|
---|
25 |
|
---|
26 | #include <stdio.h>
|
---|
27 | #include <string.h>
|
---|
28 | #include <stdlib.h>
|
---|
29 | #include <unistd.h>
|
---|
30 | #include <fcntl.h>
|
---|
31 | #include <sys/types.h>
|
---|
32 | #include <sys/stat.h>
|
---|
33 | #include <sys/ioctl.h>
|
---|
34 | #include <sys/uio.h>
|
---|
35 | #include <linux/dvb/video.h>
|
---|
36 | #include <linux/dvb/audio.h>
|
---|
37 | #include <memory.h>
|
---|
38 | #include <asm/types.h>
|
---|
39 | #include <pthread.h>
|
---|
40 | #include <errno.h>
|
---|
41 |
|
---|
42 | #include "stm_ioctls.h"
|
---|
43 | #include "bcm_ioctls.h"
|
---|
44 |
|
---|
45 | #include "common.h"
|
---|
46 | #include "output.h"
|
---|
47 | #include "debug.h"
|
---|
48 | #include "misc.h"
|
---|
49 | #include "pes.h"
|
---|
50 | #include "writer.h"
|
---|
51 |
|
---|
52 | /* ***************************** */
|
---|
53 | /* Makros/Constants */
|
---|
54 | /* ***************************** */
|
---|
55 |
|
---|
56 | #define MPEG2_DEBUG
|
---|
57 |
|
---|
58 | #ifdef MPEG2_DEBUG
|
---|
59 |
|
---|
60 | static short debug_level = 0;
|
---|
61 |
|
---|
62 | #define mpeg2_printf(level, fmt, x...) do { \
|
---|
63 | if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)
|
---|
64 | #else
|
---|
65 | #define mpeg2_printf(level, fmt, x...)
|
---|
66 | #endif
|
---|
67 |
|
---|
68 | #ifndef MPEG2_SILENT
|
---|
69 | #define mpeg2_err(fmt, x...) do { printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)
|
---|
70 | #else
|
---|
71 | #define mpeg2_err(fmt, x...)
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | /* ***************************** */
|
---|
75 | /* Types */
|
---|
76 | /* ***************************** */
|
---|
77 |
|
---|
78 | /* ***************************** */
|
---|
79 | /* Varaibles */
|
---|
80 | /* ***************************** */
|
---|
81 |
|
---|
82 | /* ***************************** */
|
---|
83 | /* Prototypes */
|
---|
84 | /* ***************************** */
|
---|
85 |
|
---|
86 | /* ***************************** */
|
---|
87 | /* MISC Functions */
|
---|
88 | /* ***************************** */
|
---|
89 |
|
---|
90 | static int reset()
|
---|
91 | {
|
---|
92 | return 0;
|
---|
93 | }
|
---|
94 |
|
---|
95 | static int writeData(void* _call)
|
---|
96 | {
|
---|
97 | WriterAVCallData_t* call = (WriterAVCallData_t*) _call;
|
---|
98 |
|
---|
99 | unsigned char PesHeader[PES_MAX_HEADER_SIZE];
|
---|
100 | int len = 0;
|
---|
101 | unsigned int Position = 0;
|
---|
102 |
|
---|
103 | mpeg2_printf(10, "\n");
|
---|
104 |
|
---|
105 | if (call == NULL)
|
---|
106 | {
|
---|
107 | mpeg2_err("call data is NULL...\n");
|
---|
108 | return 0;
|
---|
109 | }
|
---|
110 |
|
---|
111 | mpeg2_printf(10, "VideoPts %lld\n", call->Pts);
|
---|
112 |
|
---|
113 | if ((call->data == NULL) || (call->len <= 0))
|
---|
114 | {
|
---|
115 | mpeg2_err("parsing NULL Data. ignoring...\n");
|
---|
116 | return 0;
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (call->fd < 0)
|
---|
120 | {
|
---|
121 | mpeg2_err("file pointer < 0. ignoring ...\n");
|
---|
122 | return 0;
|
---|
123 | }
|
---|
124 |
|
---|
125 | while(Position < call->len)
|
---|
126 | {
|
---|
127 | int PacketLength = (call->len - Position) <= MAX_PES_PACKET_SIZE ?
|
---|
128 | (call->len - Position) : MAX_PES_PACKET_SIZE;
|
---|
129 |
|
---|
130 | int Remaining = call->len - Position - PacketLength;
|
---|
131 |
|
---|
132 | mpeg2_printf(20, "PacketLength=%d, Remaining=%d, Position=%d\n", PacketLength, Remaining, Position);
|
---|
133 |
|
---|
134 | struct iovec iov[2];
|
---|
135 | iov[0].iov_base = PesHeader;
|
---|
136 | iov[0].iov_len = InsertPesHeader (PesHeader, PacketLength, 0xe0, call->Pts, 0);
|
---|
137 | iov[1].iov_base = call->data + Position;
|
---|
138 | iov[1].iov_len = PacketLength;
|
---|
139 |
|
---|
140 | ssize_t l = writev_with_retry(call->fd, iov, 2);
|
---|
141 | if (l < 0) {
|
---|
142 | len = l;
|
---|
143 | break;
|
---|
144 | }
|
---|
145 | len += l;
|
---|
146 |
|
---|
147 | Position += PacketLength;
|
---|
148 | call->Pts = INVALID_PTS_VALUE;
|
---|
149 | }
|
---|
150 |
|
---|
151 | mpeg2_printf(10, "< len %d\n", len);
|
---|
152 | return len;
|
---|
153 | }
|
---|
154 |
|
---|
155 | /* ***************************** */
|
---|
156 | /* Writer Definition */
|
---|
157 | /* ***************************** */
|
---|
158 | static WriterCaps_t caps = {
|
---|
159 | "mpeg2",
|
---|
160 | eVideo,
|
---|
161 | "V_MPEG2",
|
---|
162 | VIDEO_ENCODING_AUTO,
|
---|
163 | STREAMTYPE_MPEG2,
|
---|
164 | CT_MPEG2
|
---|
165 | };
|
---|
166 |
|
---|
167 | struct Writer_s WriterVideoMPEG2 = {
|
---|
168 | &reset,
|
---|
169 | &writeData,
|
---|
170 | NULL,
|
---|
171 | &caps
|
---|
172 | };
|
---|
173 |
|
---|
174 | static WriterCaps_t mpg1_caps = {
|
---|
175 | "mpge1",
|
---|
176 | eVideo,
|
---|
177 | "V_MPEG1",
|
---|
178 | VIDEO_ENCODING_H264,
|
---|
179 | STREAMTYPE_MPEG1,
|
---|
180 | CT_MPEG1
|
---|
181 | };
|
---|
182 |
|
---|
183 | struct Writer_s WriterVideoMPEG1 = {
|
---|
184 | &reset,
|
---|
185 | &writeData,
|
---|
186 | NULL,
|
---|
187 | &mpg1_caps
|
---|
188 | };
|
---|