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

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

update libeplayer3 to v47

File size: 5.8 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#define B_GET_BITS(w,e,b)  (((w)>>(b))&(((unsigned)(-1))>>((sizeof(unsigned))*8-(e+1-b))))
56#define B_SET_BITS(name,v,e,b)  (((unsigned)(v))<<(b))
57
58
59#ifdef SAM_WITH_DEBUG
60#define DIVX_DEBUG
61#else
62#define DIVX_SILENT
63#endif
64
65#ifdef DIVX_DEBUG
66
67static short debug_level = 0;
68
69#define divx_printf(level, fmt, x...) do { \
70if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)
71#else
72#define divx_printf(level, fmt, x...)
73#endif
74
75#ifndef DIVX_SILENT
76#define divx_err(fmt, x...) do { printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)
77#else
78#define divx_err(fmt, x...)
79#endif
80
81/* ***************************** */
82/* Types                         */
83/* ***************************** */
84
85/* ***************************** */
86/* Varaibles                     */
87/* ***************************** */
88static uint8_t initialHeader = 1;
89static uint8_t brcm_divx311_sequence_header[] =
90{
91    0x00, 0x00, 0x01, 0xE0, 0x00, 0x34, 0x80, 0x80, // PES HEADER
92    0x05, 0x2F, 0xFF, 0xFF, 0xFF, 0xFF,
93    0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20, /* 0 .. 7 */
94    0x08, 0xC8, 0x0D, 0x40, 0x00, 0x53, 0x88, 0x40, /* 8 .. 15 */
95    0x0C, 0x40, 0x01, 0x90, 0x00, 0x97, 0x53, 0x0A, /* 16 .. 24 */
96    0x00, 0x00, 0x00, 0x00,
97    0x30, 0x7F, 0x00, 0x00, 0x01, 0xB2, 0x44, 0x69, /* 0 .. 7 */
98    0x76, 0x58, 0x33, 0x31, 0x31, 0x41, 0x4E, 0x44  /* 8 .. 15 */
99};
100
101/* ***************************** */
102/* Prototypes                    */
103/* ***************************** */
104
105/* ***************************** */
106/* MISC Functions                */
107/* ***************************** */
108static int reset()
109{
110    initialHeader = 1;
111    return 0;
112}
113
114static int writeData(void* _call)
115{
116    WriterAVCallData_t* call = (WriterAVCallData_t*) _call;
117
118    unsigned char  PesHeader[PES_MAX_HEADER_SIZE + 4];
119    unsigned char  Version = 5;
120    unsigned int   FakeStartCode       = (Version << 8) | PES_VERSION_FAKE_START_CODE;
121
122    divx_printf(10, "\n");
123
124    if (call == NULL)
125    {
126        divx_err("call data is NULL...\n");
127        return 0;
128    }
129
130    if ((call->data == NULL) || (call->len <= 0))
131    {
132        divx_err("parsing NULL Data. ignoring...\n");
133        return 0;
134    }
135
136    if (call->fd < 0)
137    {
138        divx_err("file pointer < 0. ignoring ...\n");
139        return 0;
140    }
141
142    divx_printf(10, "AudioPts %lld\n", call->Pts);
143
144
145    struct iovec iov[8];
146    int ic = 0;
147   
148    if(initialHeader)
149    {
150        initialHeader = 0;
151        uint8_t *data = brcm_divx311_sequence_header;
152        int32_t height = call->Height;
153        int32_t width  = call->Width;
154        data += 38;
155        data[0] = B_GET_BITS(width,11,4);
156        data[1] = B_SET_BITS("width [3..0]", B_GET_BITS(width,3,0), 7, 4) |
157            B_SET_BITS("'10'", 0x02, 3, 2) |
158            B_SET_BITS("height [11..10]", B_GET_BITS(height,11,10), 1, 0);
159        data[2] = B_GET_BITS(height,9,2);
160        data[3]= B_SET_BITS("height [1.0]", B_GET_BITS(height,1,0), 7, 6) |
161            B_SET_BITS("'100000'", 0x20, 5, 0);
162           
163        iov[ic].iov_base = brcm_divx311_sequence_header;
164        iov[ic++].iov_len = sizeof(brcm_divx311_sequence_header);
165    }
166   
167    iov[ic].iov_base = PesHeader;
168    uint32_t headerSize = 0;
169   
170    if (memcmp(call->data, "\x00\x00\x01\xb6", 4))
171    {
172        headerSize = InsertPesHeader (PesHeader, call->len+4, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
173        memcpy(PesHeader + headerSize, "\x00\x00\x01\xb6", 4);
174        headerSize += 4;
175    }
176    else
177    {
178        headerSize = InsertPesHeader (PesHeader, call->len, MPEG_VIDEO_PES_START_CODE, call->Pts, 0);
179    }
180    iov[ic++].iov_len = headerSize;
181   
182    iov[ic].iov_base = call->data;
183    iov[ic++].iov_len = call->len;
184
185    int len = call->WriteV(call->fd, iov, ic);
186
187    divx_printf(10, "xvid_Write < len=%d\n", len);
188
189    return len;
190}
191
192/* ***************************** */
193/* Writer  Definition            */
194/* ***************************** */
195
196static WriterCaps_t divix3_caps = {
197    "divix3",
198    eVideo,
199    "V_DIVX3",
200    VIDEO_ENCODING_MPEG4P2,
201    STREAMTYPE_DIVX311,
202    -1
203};
204
205struct Writer_s WriterVideoDIVX3 = {
206    &reset,
207    &writeData,
208    NULL,
209    &divix3_caps
210};
Note: See TracBrowser for help on using the repository browser.