source: titan/libeplayer3/output/writer/mipsel/mpeg4.c @ 42162

Last change on this file since 42162 was 42162, checked in by obi, 6 years ago

update libeplayer3 to v47

File size: 4.3 KB
Line 
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 SAM_WITH_DEBUG
57#ifdef SAM_WITH_DEBUG
58#define MPEG4_DEBUG
59#else
60#define MPEG4_SILENT
61#endif
62
63#ifdef MPEG4_DEBUG
64
65static short debug_level = 0;
66
67#define mpeg4_printf(level, fmt, x...) do { \
68if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)
69#else
70#define mpeg4_printf(level, fmt, x...)
71#endif
72
73#ifndef MPEG4_SILENT
74#define mpeg4_err(fmt, x...) do { printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)
75#else
76#define mpeg4_err(fmt, x...)
77#endif
78
79/* ***************************** */
80/* Types                         */
81/* ***************************** */
82
83/* ***************************** */
84/* Varaibles                     */
85/* ***************************** */
86static int initialHeader = 1;
87
88/* ***************************** */
89/* Prototypes                    */
90/* ***************************** */
91
92/* ***************************** */
93/* MISC Functions                */
94/* ***************************** */
95static int reset()
96{
97    initialHeader = 1;
98    return 0;
99}
100
101static int writeData(void* _call)
102{
103    WriterAVCallData_t* call = (WriterAVCallData_t*) _call;
104
105    unsigned char  PesHeader[PES_MAX_HEADER_SIZE];
106
107    mpeg4_printf(10, "\n");
108
109    if (call == NULL)
110    {
111        mpeg4_err("call data is NULL...\n");
112        return 0;
113    }
114
115    if ((call->data == NULL) || (call->len <= 0))
116    {
117        mpeg4_err("parsing NULL Data. ignoring...\n");
118        return 0;
119    }
120
121    if (call->fd < 0)
122    {
123        mpeg4_err("file pointer < 0. ignoring ...\n");
124        return 0;
125    }
126
127    mpeg4_printf(10, "VideoPts %lld\n", call->Pts);
128
129
130    unsigned int PacketLength = call->len;
131    if (initialHeader && call->private_size && call->private_data != NULL)
132    {
133        PacketLength += call->private_size;
134    }
135
136    struct iovec iov[3];
137    int ic = 0;
138    iov[ic].iov_base = PesHeader;
139    iov[ic++].iov_len = InsertPesHeader (PesHeader, PacketLength, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
140
141    if (initialHeader && call->private_size && call->private_data != NULL)
142    {
143        initialHeader = 0;
144        iov[ic].iov_base = call->private_data;
145        iov[ic++].iov_len = call->private_size;
146    }
147    iov[ic].iov_base = call->data;
148    iov[ic++].iov_len = call->len;
149
150    int len = call->WriteV(call->fd, iov, ic);
151
152    mpeg4_printf(10, "xvid_Write < len=%d\n", len);
153
154    return len;
155}
156
157/* ***************************** */
158/* Writer  Definition            */
159/* ***************************** */
160
161static WriterCaps_t mpeg4p2_caps = {
162    "mpeg4p2",
163    eVideo,
164    "V_MPEG4",
165    VIDEO_ENCODING_MPEG4P2,
166    STREAMTYPE_MPEG4_Part2,
167    -1
168};
169
170struct Writer_s WriterVideoMPEG4 = {
171    &reset,
172    &writeData,
173    NULL,
174    &mpeg4p2_caps
175};
Note: See TracBrowser for help on using the repository browser.