~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/frame/framer.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  base class for converting raw data(stream) into some frametype.
 
3
  Copyright (C) 2001  Martin Vogt
 
4
 
 
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.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
 
 
15
#ifndef __FRAMER_H
 
16
#define __FRAMER_H
 
17
 
 
18
 
 
19
#include <stdio.h>
 
20
#include <iostream.h>
 
21
#include <stdlib.h>
 
22
#include <string.h>
 
23
 
 
24
#define FRAME_NEED     0
 
25
#define FRAME_WORK     1
 
26
#define FRAME_HAS      2
 
27
 
 
28
 
 
29
#include "rawDataBuffer.h"
 
30
 
 
31
 
 
32
/**
 
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.
 
37
   
 
38
   This class tells you how many bytes it can read and
 
39
   gives you information wether we have a valid frame or not.
 
40
 
 
41
   This class has three public states:
 
42
 
 
43
                 FRAME_NEED
 
44
              /             \
 
45
             /               \
 
46
            /                 \
 
47
   FRAME_WORK  <---------->  FRAME_HAS
 
48
 
 
49
 
 
50
   after the "FRAME_HAS" state we devliver _excatly_ one time
 
51
   this state, and then automatically go to "FRAME_WORK" state.
 
52
 
 
53
 
 
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"
 
59
 
 
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!
 
63
 
 
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")
 
68
*/
 
69
 
 
70
 
 
71
 
 
72
 
 
73
class Framer {
 
74
 
 
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.
 
78
  // Examples:
 
79
  // avi-Chunk : 65KB
 
80
  // mpeg audio: 4KB is always enough
 
81
  // mpeg video: 224K (spec says this)
 
82
 
 
83
  // this can be a remote buffer or a local one
 
84
  unsigned char* buffer_data;
 
85
  RawDataBuffer* buffer_info;
 
86
 
 
87
  // state from FIND->READ->HAS
 
88
  int process_state;
 
89
  // state between NEED <-> PROCESS
 
90
  int main_state;
 
91
 
 
92
  RawDataBuffer* input_info;
 
93
  int lAutoNext;
 
94
 
 
95
  // stores if we have alloceated outdata or not
 
96
  int lDeleteOutPtr;
 
97
  // internal: unsync not done
 
98
  int lConstruct;
 
99
 
 
100
 public:
 
101
  // allocate local output buffer
 
102
  Framer(int outsize);
 
103
 
 
104
  // outbuffer is remote.
 
105
  Framer(int outsize,unsigned char* outptr);
 
106
 
 
107
  virtual ~Framer();
 
108
 
 
109
  //
 
110
  // process states (transitions) [START]
 
111
  //
 
112
 
 
113
  // stores pointer to input and len
 
114
  void store(unsigned char* start,int bytes);
 
115
  int  work();
 
116
  void reset();
 
117
  void next();
 
118
  // returns pointer to outbuffer (frameheader+data)
 
119
  unsigned char* outdata();
 
120
  
 
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();
 
125
  
 
126
 
 
127
  //
 
128
  // process states (transitions) [END]
 
129
  //
 
130
 
 
131
  
 
132
  //
 
133
  // state helper functions [START]
 
134
  //
 
135
  int getState();
 
136
  // returns number of bytes.
 
137
  int canStore();
 
138
 
 
139
  // returns length of frame == len(frameheader+data) 
 
140
  int len();
 
141
 
 
142
  // returns number of bytes still in input(needed for a/v sync)
 
143
  int restBytes();
 
144
  //
 
145
  // state helper functions [END]
 
146
  //
 
147
 
 
148
  // debugging
 
149
  void printMainStates(const char* msg);
 
150
 
 
151
 private:
 
152
  void init(int outsize,unsigned char* outptr,int lDeleteOutptr);
 
153
 
 
154
  void setState(int state);
 
155
  
 
156
  //
 
157
  // Overload functions for specialized framers [START]
 
158
  //
 
159
 
 
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);
 
166
  // debugging
 
167
  virtual void printPrivateStates();
 
168
 
 
169
  //
 
170
  // Overload functions for specialized framers [END]
 
171
  //
 
172
 
 
173
 protected:
 
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);
 
178
 
 
179
};
 
180
 
 
181
 
 
182
#endif