summaryrefslogtreecommitdiff
path: root/command/queue.h
blob: 8f40ac39a0c7b7046b7454900ce7f246dc85c5b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * queue.h: A program for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 */

#ifndef __queue_h_
#define __queue_h_

#include <stdint.h>

#ifndef uchar
typedef unsigned char uchar;
#endif

typedef struct MarkAdPacket
{
    uchar *Data;
    int Length;
    unsigned int Timestamp;
    bool Offcnt;
} MarkAdPacket;

class cMarkAdPaketQueue
{
    struct MP2HDR
    {
unsigned Sync1:
        8;
unsigned Protection:
        1;
unsigned Layer:
        2;
unsigned MpegID:
        2;
unsigned Sync2:
        3;
unsigned Private:
        1;
unsigned Padding:
        1;
unsigned SampleRateIndex:
        2;
unsigned BitRateIndex:
        4;
unsigned Emphasis:
        2;
unsigned Original:
        1;
unsigned Copyright:
        1;
unsigned ModeExt:
        2;
unsigned Mode:
        2;
    };

#pragma pack(1)
    struct AC3HDR
    {
unsigned Sync1:
        8;
unsigned Sync2:
        8;
unsigned CRC1:
        8;
unsigned CRC2:
        8;
unsigned FrameSizeIndex:
        6;
unsigned SampleRateIndex:
        2;
    };
#pragma pack()

#pragma pack(1)
    struct PESHDROPT
    {
unsigned OOC:
        1;
unsigned CY:
        1;
unsigned DAI:
        1;
unsigned PESP:
        1;
unsigned PESSC:
        2;
unsigned MarkerBits:
        2;
unsigned EXT:
        1;
unsigned CRC:
        1;
unsigned ACI:
        1;
unsigned TM:
        1;
unsigned RATE:
        1;
unsigned ESCR:
        1;
unsigned TSF:
        2;
unsigned Length:
        8;
    };
#pragma pack()

private:
    char *name;
    struct pktinfo
    {
        int pkthdr;
        int pktsyncsize;
        int streamsize;
        bool ispes;
    } pktinfo;

    int percent;
    int mpercent;

    uchar *buffer;
    int maxqueue;
    int inptr;
    int outptr;

    uint32_t scanner;
    int scannerstart;

    int FindPktHeader(int Start, int *StreamSize,int *SyncSize, bool LongStartCode);
    int FindAudioHeader(int Start, int *FrameSize, int *SyncSize, bool AC3);
public:
    cMarkAdPaketQueue(const char *Name, int Size=32768);
    ~cMarkAdPaketQueue();
    int Length()
    {
        return inptr-outptr;
    }
    void Clear()
    {
        inptr=outptr=0;
        pktinfo.pkthdr=-1;
        scanner=0xFFFFFFFF;
        scannerstart=-1;
    }
    bool Inject(uchar *Data, int Size);
    bool Put(uchar *Data, int Size);
    uchar *Get(int *Size);
    uchar *Peek(int Size);

#define MA_PACKET_PKT		0x10 // 0x00 0x00 0x01 (PES / H262)
#define MA_PACKET_H264		0x11 // 0x00 0x00 0x00 0x01 (H264)
#define MA_PACKET_AC3		0x20
#define MA_PACKET_MP2		0x30

    uchar *GetPacket(int *Size, int Type);
};

#endif