~ubuntu-branches/ubuntu/lucid/mythtv/lucid

« back to all changes in this revision

Viewing changes to programs/mythtranscode/replex/mpg_common.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2009-10-02 00:23:18 UTC
  • mfrom: (1.1.36 upstream)
  • Revision ID: james.westby@ubuntu.com-20091002002318-5qu2fr0gxl59egft
Tags: 0.22.0~trunk22167-0ubuntu1
* New upstream checkout (r22167).
  - Fixes some segfaults.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * mpg_common.c: COMMON MPEG functions for replex
3
3
 *        
4
4
 *
5
 
 * Copyright (C) 2003 - 2006
6
 
 *                    Marcus Metzler <mocm@metzlerbros.de>
 
5
 * Copyright (C) 2003 Marcus Metzler <mocm@metzlerbros.de>
7
6
 *                    Metzler Brothers Systementwicklung GbR
8
 
 *           (C) 2006 Reel Multimedia
9
7
 *
10
8
 * This program is free software; you can redistribute it and/or
11
9
 * modify it under the terms of the GNU General Public License
63
61
        }
64
62
}
65
63
 
66
 
//----------------------------------------------------------------------------
67
 
#define CMP_CORE(offset) \
68
 
        x=Data[i+1+offset]; \
69
 
        if (x<2) { \
70
 
                if (x==0) { \
71
 
                        if ( Data[i+offset]==0 && Data[i+2+offset]==1) \
72
 
                                return i+offset; \
73
 
                        else if (Data[i+2+offset]==0 && Data[i+3+offset]==1) \
74
 
                                return i+1+offset; \
75
 
                } \
76
 
                else if (x==1 && Data[i-1+offset]==0 && Data[i+offset]==0 && (i+offset)>0) \
77
 
                         return i-1+offset; \
78
 
         }
79
 
 
80
 
int FindPacketHeader(const uint8_t *Data, int s, int l)
81
 
{
82
 
        int i;
83
 
        uint8_t x;
84
 
 
85
 
        if (l>12) {
86
 
                for(i=s;i<l-12;i+=12) { 
87
 
                        CMP_CORE(0);
88
 
                        CMP_CORE(3);
89
 
                        CMP_CORE(6);
90
 
                        CMP_CORE(9);
91
 
                }
92
 
 
93
 
                for(; i<l-3; i+=3) {
94
 
                        CMP_CORE(0);
95
 
                }              
96
 
        }
97
 
        else {
98
 
                for(i=s; i<l-3; i+=3) {
99
 
                        CMP_CORE(0);
100
 
                }
101
 
        }
102
 
        return -1;
103
 
}
104
 
//----------------------------------------------------------------------------
105
 
 
106
 
int find_mpg_header(uint8_t head, uint8_t *buf, int Count)
107
 
{
108
 
        int n=0;
109
 
        uint8_t *Data=buf;
110
 
        while(n<Count) {
111
 
                int x;
112
 
                x=FindPacketHeader(Data, 0, Count - n); // returns position of first 00
113
 
                if (x!=-1) {
114
 
                        Data+=x;
115
 
                        n+=x;
116
 
                        if (Data[3]==head) {
117
 
                                return n; 
118
 
                        }
119
 
                        n+=3;
120
 
                        Data+=3;
121
 
                        Count-=3;
122
 
                }
123
 
                else
124
 
                        break;
125
 
        }
126
 
        return -1;
127
 
 
128
 
}
129
 
 
130
 
int find_any_header(uint8_t *head, uint8_t *buf, int Count)
131
 
{
132
 
        int n=0;
133
 
        uint8_t *Data=buf;
134
 
        while(n<Count) {
135
 
                int x;
136
 
                x=FindPacketHeader(Data, 0, Count - n); // returns position of first 00
137
 
                if (x!=-1) {
138
 
                        Data+=x;
139
 
                        n+=x;
140
 
                        *head=Data[3];
141
 
                        return n; 
142
 
                }
143
 
                else
144
 
                        break;
145
 
        }
146
 
        return -1;
147
 
 
148
 
}
149
 
 
150
 
int find_mpg_headerx(uint8_t head, uint8_t *buf, int length)
 
64
 
 
65
 
 
66
int find_mpg_header(uint8_t head, uint8_t *buf, int length)
151
67
{
152
68
 
153
69
        int c = 0;
183
99
}
184
100
 
185
101
 
186
 
int find_any_headerx(uint8_t *head, uint8_t *buf, int length)
 
102
int find_any_header(uint8_t *head, uint8_t *buf, int length)
187
103
{
188
104
 
189
105
        int c = 0;
237
153
}
238
154
 
239
155
 
240
 
int mring_peek( ringbuffer *rbuf, uint8_t *buf, int l, long off)
 
156
int mring_peek( ringbuffer *rbuf, uint8_t *buf, unsigned int l, uint32_t off)
241
157
{
242
158
        int c = 0;
243
159
 
289
205
}
290
206
 
291
207
 
292
 
#define PEEK_SIZE (512+1024)
293
 
int ring_find_any_headery(ringbuffer *rbuf, uint8_t *head, int off, int le)
294
 
{
295
 
        uint8_t buf[PEEK_SIZE];
296
 
//      int xoff;
297
 
        int res,x;
298
 
//      int found;
299
 
        int n=off;
300
 
        int peek_snip;
301
 
//      printf("# %i %i\n",off,le);
302
 
        while(le>0) {
303
 
                if (le>PEEK_SIZE)
304
 
                        peek_snip=PEEK_SIZE;
305
 
                else
306
 
                        peek_snip=le;
307
 
 
308
 
                res=mring_peek(rbuf, buf, peek_snip, n);
309
 
                if (res<0) {
310
 
                        peek_snip=ring_avail(rbuf);
311
 
//                      printf("PP %i\n",peek_snip);
312
 
                        if (peek_snip>PEEK_SIZE)
313
 
                                peek_snip=PEEK_SIZE;
314
 
                        if (peek_snip>le)
315
 
                                peek_snip=le;
316
 
                        res=mring_peek(rbuf,buf,peek_snip,n);
317
 
                        if (res<0)
318
 
                                return -1;
319
 
                }
320
 
//              printf("ZZ %i %i\n",peek_snip,n);
321
 
                x=FindPacketHeader(buf, 0, peek_snip); // returns position of first 00
322
 
                if (x!=-1 && x<=peek_snip-4) {
323
 
                        n+=x-off;
324
 
                        
325
 
                        *head=buf[x+3];
326
 
                        return n; 
327
 
                }
328
 
                if (peek_snip<=4) {
329
 
                        int i;
330
 
                        for(i=0;i<peek_snip;i++)
331
 
                                if (buf[i]==0)
332
 
                                        return -2;
333
 
                        return -1;
334
 
                }
335
 
 
336
 
                n+=peek_snip-4;
337
 
                le-=peek_snip-4;
338
 
        }
339
 
        return -1; // Not found
340
 
}
341
 
 
342
 
int ring_find_any_headerx(ringbuffer *rbuf, uint8_t *head, int off, int le)
 
208
int ring_find_any_header(ringbuffer *rbuf, uint8_t *head, int off, int le)
343
209
{
344
210
 
345
211
        int c = 0;
378
244
        else return -1;
379
245
}
380
246
 
381
 
int ring_find_any_header(ringbuffer *rbuf, uint8_t *head, int off, int le)
382
 
{
383
 
        uint8_t a=0;
384
 
//      uint8_t b=0;
385
 
        int x;
386
 
//      int y;
387
 
 
388
 
        x=ring_find_any_headery(rbuf, &a, off, le);
389
 
#if 0
390
 
        y=ring_find_any_headery(rbuf, &b, off, le);
391
 
        if (x!=y || a!=b)
392
 
                printf("MY %i %i, ORG %i %i\n",y, b, x, a);
393
 
#endif
394
 
        *head=a;
395
 
        return x;
396
 
}