2
base class for converting raw data(stream) into some frametype.
3
Copyright (C) 2001 Martin Vogt
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation.
9
For more information look at the file COPYRIGHT in this package
29
#include "rawDataBuffer.h"
33
If we want to have a "push" interface, this means the decoder
34
does not read from an input interface, we must be sure
35
that we have a valid mpeg audio frame, before we feed
36
this whole frame to the decoder.
38
This class tells you how many bytes it can read and
39
gives you information wether we have a valid frame or not.
41
This class has three public states:
47
FRAME_WORK <----------> FRAME_HAS
50
after the "FRAME_HAS" state we devliver _excatly_ one time
51
this state, and then automatically go to "FRAME_WORK" state.
54
You can reset() the class which empties the buffer and then
55
starts searching for a new sync code, or you can
56
do a next() which searches for the sync code, without
57
emptying the buffer (this is done automatically,
58
after the first call, when we was ins state "FRAME_HAS"
60
Note: i) You need a reset() if a "seek" occurs in your stream
61
ii) First call to the class must be "getState" which does the
62
Post-Constructor setup in derived classes!
64
The FRAME_NEED state is entered if the input buffer is empty
65
you then need to "push" data in this class.
66
The FRAME_NEED state is necessary to avoid an additonal memcpy
67
and a ringbuffer.(This safes "overhead"/"cpu cycles")
75
// this is our destination buffer for the output frame
76
// this buffer must be able to store the maximum size
77
// a frame of this type can have.
80
// mpeg audio: 4KB is always enough
81
// mpeg video: 224K (spec says this)
83
// this can be a remote buffer or a local one
84
unsigned char* buffer_data;
85
RawDataBuffer* buffer_info;
87
// state from FIND->READ->HAS
89
// state between NEED <-> PROCESS
92
RawDataBuffer* input_info;
95
// stores if we have alloceated outdata or not
97
// internal: unsync not done
101
// allocate local output buffer
104
// outbuffer is remote.
105
Framer(int outsize,unsigned char* outptr);
110
// process states (transitions) [START]
113
// stores pointer to input and len
114
void store(unsigned char* start,int bytes);
118
// returns pointer to outbuffer (frameheader+data)
119
unsigned char* outdata();
121
// returns pointer to inbuffer (raw data)
122
// Note: this ptr is not fixed! It may vary from time to time
123
// Cannot be stores in a variable!
124
unsigned char* indata();
128
// process states (transitions) [END]
133
// state helper functions [START]
136
// returns number of bytes.
139
// returns length of frame == len(frameheader+data)
142
// returns number of bytes still in input(needed for a/v sync)
145
// state helper functions [END]
149
void printMainStates(const char* msg);
152
void init(int outsize,unsigned char* outptr,int lDeleteOutptr);
154
void setState(int state);
157
// Overload functions for specialized framers [START]
160
// return true, if frame header found
161
virtual int find_frame(RawDataBuffer* input,RawDataBuffer* store);
162
// return true, if frame data read.
163
virtual int read_frame(RawDataBuffer* input,RawDataBuffer* store);
164
// makes buffer invalid, reset to begin of "find_frame"
165
virtual void unsync(RawDataBuffer* store,int lReset);
167
virtual void printPrivateStates();
170
// Overload functions for specialized framers [END]
174
// this can be used, if the outptr come from a different framer
175
// (eg: OGG framer). You then need to call the construtor with
176
// some "dummy" size.
177
void setRemoteFrameBuffer(unsigned char* outptr,int size);