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

« back to all changes in this revision

Viewing changes to mpeglib/lib/mpegplay/mpegVideoBitWindow.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
  bitwindow mpeg video
 
3
  Copyright (C) 2000  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 __MPEGVIDEOBITWINDOW_H
 
16
#define __MPEGVIDEOBITWINDOW_H
 
17
 
 
18
#include "../input/inputPlugin.h"
 
19
 
 
20
 
 
21
#define ISO_11172_END_CODE          ((unsigned int)0x000001b9)
 
22
 
 
23
class MpegVideoBitWindow {
 
24
  int size;                             /* size of buffer */
 
25
  unsigned int bit_offset;              /* Bit offset in stream.      */
 
26
  unsigned int *buffer;                 /* Pointer to next byte in buffer */
 
27
  int buf_length;                       /* Length of remaining buffer.*/
 
28
  unsigned int *buf_start;              /* Pointer to buffer start.   */
 
29
  int max_buf_length;                   /* Max length of buffer.      */
 
30
  unsigned int num_left;                /* from ReadPacket - leftover */
 
31
  unsigned int leftover_bytes;          /* from ReadPacket - leftover */
 
32
  unsigned int curBits;                 /* current bits               */
 
33
  
 
34
 
 
35
  unsigned int nBitMask[33];
 
36
 
 
37
 
 
38
 public:
 
39
  MpegVideoBitWindow();
 
40
  ~MpegVideoBitWindow();
 
41
  
 
42
  int appendToBuffer(unsigned char* ptr,int len);
 
43
  int getLinearFree();
 
44
  // true if feof() is true and the buffer is emtpy
 
45
  int isEof();
 
46
  void flushByteOffset();
 
47
  void appendToBuffer(unsigned int startCode);
 
48
 
 
49
  
 
50
  inline void updateCurBits() {
 
51
    curBits = *buffer << bit_offset;
 
52
  }
 
53
 
 
54
  inline unsigned int showBits(int bits) {
 
55
    
 
56
    unsigned int mask=nBitMask[bits];
 
57
    int shift=32-(bits);
 
58
    int bO;                                                               
 
59
    shift=(curBits & mask)>>shift;
 
60
    bO = bit_offset + bits;                                    
 
61
    if (bO > 32) {
 
62
      return (shift | (*(buffer+1)>>(64-bO)));
 
63
    }                                                                     
 
64
    return shift;    
 
65
  }
 
66
 
 
67
  inline unsigned int showBits32() {
 
68
    if (bit_offset) {                                         
 
69
      return (curBits | (*(buffer+1) >> (32 - bit_offset)));   
 
70
    }                                                                     
 
71
    return curBits;  
 
72
  }
 
73
 
 
74
  inline void flushBitsDirect(unsigned int bits) {
 
75
    bit_offset += bits;       
 
76
    if (bit_offset & 0x20) {                                
 
77
      bit_offset -= 32;
 
78
      bit_offset &= 0x1f;
 
79
      buffer++;                                             
 
80
      updateCurBits();
 
81
      buf_length--;                                         
 
82
    }                                                                   
 
83
    else {                                                              
 
84
      curBits <<= bits;                                      
 
85
    }    
 
86
  }
 
87
 
 
88
  inline unsigned int getBits(int bits) {
 
89
    unsigned int result=showBits(bits);
 
90
    flushBitsDirect(bits);
 
91
    return result;
 
92
  }
 
93
  
 
94
  void clear();
 
95
  int getLength();
 
96
 
 
97
  int hasBytes(int bytes);
 
98
 
 
99
  void printChar(int bytes);
 
100
  void printInt(int bytes);
 
101
  void print();
 
102
  void resizeBuffer(int insertBytes);
 
103
  void fillWithIsoEndCode(int bytes);
 
104
 
 
105
 
 
106
 
 
107
};
 
108
#endif