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

Last change on this file since 44958 was 44958, checked in by obi, 3 years ago

[libeplayer3] update to v68

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