Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

slice.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #ifndef SLICE_H
00021 #define SLICE_H
00022 
00023 #ifndef _WIN32
00024 #include <pthread.h>
00025 #endif
00026 
00027 /* Array of these feeds the slice decoders */
00028 typedef struct
00029 {
00030         unsigned char *data;   /* Buffer for holding the slice data */
00031         int buffer_size;         /* Size of buffer */
00032         int buffer_allocation;   /* Space allocated for buffer  */
00033         int current_position;    /* Position in buffer */
00034         unsigned MPEG3_INT32 bits;
00035         int bits_size;
00036         pthread_mutex_t completion_lock; /* Lock slice until completion */
00037         int done;           /* Signal for slice decoder to skip */
00038 } mpeg3_slice_buffer_t;
00039 
00040 /* Each slice decoder */
00041 typedef struct
00042 {
00043         struct mpeg3video_rec *video;
00044         mpeg3_slice_buffer_t *slice_buffer;
00045 
00046         int thread_number;      /* Number of this thread */
00047         int current_buffer;     /* Buffer this slice decoder is on */
00048         int buffer_step;        /* Number of buffers to skip */
00049         int last_buffer;        /* Last buffer this decoder should process */
00050         int fault;
00051         int done;
00052         int quant_scale;
00053         int pri_brk;                  /* slice/macroblock */
00054         short block[12][64];
00055         int sparse[12];
00056         pthread_t tid;   /* ID of thread */
00057         pthread_mutex_t input_lock, output_lock;
00058 } mpeg3_slice_t;
00059 
00060 #define mpeg3slice_fillbits(buffer, nbits) \
00061         while(((mpeg3_slice_buffer_t*)(buffer))->bits_size < (nbits)) \
00062         { \
00063                 if(((mpeg3_slice_buffer_t*)(buffer))->current_position < ((mpeg3_slice_buffer_t*)(buffer))->buffer_size) \
00064                 { \
00065                         ((mpeg3_slice_buffer_t*)(buffer))->bits <<= 8; \
00066                         ((mpeg3_slice_buffer_t*)(buffer))->bits |= ((mpeg3_slice_buffer_t*)(buffer))->data[((mpeg3_slice_buffer_t*)(buffer))->current_position++]; \
00067                 } \
00068                 ((mpeg3_slice_buffer_t*)(buffer))->bits_size += 8; \
00069         }
00070 
00071 #define mpeg3slice_flushbits(buffer, nbits) \
00072         { \
00073                 mpeg3slice_fillbits((buffer), (nbits)); \
00074                 ((mpeg3_slice_buffer_t*)(buffer))->bits_size -= (nbits); \
00075         }
00076 
00077 #define mpeg3slice_flushbit(buffer) \
00078 { \
00079         if(((mpeg3_slice_buffer_t*)(buffer))->bits_size) \
00080                 ((mpeg3_slice_buffer_t*)(buffer))->bits_size--; \
00081         else \
00082         if(((mpeg3_slice_buffer_t*)(buffer))->current_position < ((mpeg3_slice_buffer_t*)(buffer))->buffer_size) \
00083         { \
00084                 ((mpeg3_slice_buffer_t*)(buffer))->bits = \
00085                         ((mpeg3_slice_buffer_t*)(buffer))->data[((mpeg3_slice_buffer_t*)(buffer))->current_position++]; \
00086                 ((mpeg3_slice_buffer_t*)(buffer))->bits_size = 7; \
00087         } \
00088 }
00089 
00090 extern inline unsigned int mpeg3slice_getbit(mpeg3_slice_buffer_t *buffer)
00091 {
00092         if(buffer->bits_size)
00093                 return (buffer->bits >> (--buffer->bits_size)) & 0x1;
00094         else
00095         if(buffer->current_position < buffer->buffer_size)
00096         {
00097                 buffer->bits = buffer->data[buffer->current_position++];
00098                 buffer->bits_size = 7;
00099                 return (buffer->bits >> 7) & 0x1;
00100         }
00101         return 0; // WWA - stop warn
00102 }
00103 
00104 extern inline unsigned int mpeg3slice_getbits2(mpeg3_slice_buffer_t *buffer)
00105 {
00106         if(buffer->bits_size >= 2)
00107                 return (buffer->bits >> (buffer->bits_size -= 2)) & 0x3;
00108         else
00109         if(buffer->current_position < buffer->buffer_size)
00110         {
00111                 buffer->bits <<= 8;
00112                 buffer->bits |= buffer->data[buffer->current_position++];
00113                 buffer->bits_size += 6;
00114                 return (buffer->bits >> buffer->bits_size)  & 0x3;
00115         }
00116         return 0; // WWA - stop warn
00117 }
00118 
00119 extern inline unsigned int mpeg3slice_getbyte(mpeg3_slice_buffer_t *buffer)
00120 {
00121         if(buffer->bits_size >= 8)
00122                 return (buffer->bits >> (buffer->bits_size -= 8)) & 0xff;
00123         else
00124         if(buffer->current_position < buffer->buffer_size)
00125         {
00126                 buffer->bits <<= 8;
00127                 buffer->bits |= buffer->data[buffer->current_position++];
00128                 return (buffer->bits >> buffer->bits_size) & 0xff;
00129         }
00130         return 0; // WWA - stop warn
00131 }
00132 
00133 
00134 extern inline unsigned int mpeg3slice_getbits(mpeg3_slice_buffer_t *slice_buffer, int bits)
00135 {
00136         if(bits == 1) return mpeg3slice_getbit(slice_buffer);
00137         mpeg3slice_fillbits(slice_buffer, bits);
00138         return (slice_buffer->bits >> (slice_buffer->bits_size -= bits)) & (0xffffffff >> (32 - bits));
00139 }
00140 
00141 extern inline unsigned int mpeg3slice_showbits16(mpeg3_slice_buffer_t *buffer)
00142 {
00143         if(buffer->bits_size >= 16)
00144                 return (buffer->bits >> (buffer->bits_size - 16)) & 0xffff;
00145         else
00146         if(buffer->current_position < buffer->buffer_size)
00147         {
00148                 buffer->bits <<= 16;
00149                 buffer->bits_size += 16;
00150                 buffer->bits |= (unsigned int)buffer->data[buffer->current_position++] << 8;
00151                 buffer->bits |= buffer->data[buffer->current_position++];
00152                 return (buffer->bits >> (buffer->bits_size - 16)) & 0xffff;
00153         }
00154         return 0; // WWA - stop warn
00155 }
00156 
00157 extern inline unsigned int mpeg3slice_showbits9(mpeg3_slice_buffer_t *buffer)
00158 {
00159         if(buffer->bits_size >= 9)
00160                 return (buffer->bits >> (buffer->bits_size - 9)) & 0x1ff;
00161         else
00162         if(buffer->current_position < buffer->buffer_size)
00163         {
00164                 buffer->bits <<= 16;
00165                 buffer->bits_size += 16;
00166                 buffer->bits |= (unsigned int)buffer->data[buffer->current_position++] << 8;
00167                 buffer->bits |= buffer->data[buffer->current_position++];
00168                 return (buffer->bits >> (buffer->bits_size - 9)) & 0x1ff;
00169         }
00170         return 0; // WWA - stop warn
00171 }
00172 
00173 extern inline unsigned int mpeg3slice_showbits5(mpeg3_slice_buffer_t *buffer)
00174 {
00175         if(buffer->bits_size >= 5)
00176                 return (buffer->bits >> (buffer->bits_size - 5)) & 0x1f;
00177         else
00178         if(buffer->current_position < buffer->buffer_size)
00179         {
00180                 buffer->bits <<= 8;
00181                 buffer->bits_size += 8;
00182                 buffer->bits |= buffer->data[buffer->current_position++];
00183                 return (buffer->bits >> (buffer->bits_size - 5)) & 0x1f;
00184         }
00185         return 0; // WWA - stop warn
00186 }
00187 
00188 extern inline unsigned int mpeg3slice_showbits(mpeg3_slice_buffer_t *slice_buffer, int bits)
00189 {
00190         mpeg3slice_fillbits(slice_buffer, bits);
00191         return (slice_buffer->bits >> (slice_buffer->bits_size - bits)) & (0xffffffff >> (32 - bits));
00192 }
00193 
00194 #endif

Generated on Sat Nov 5 16:15:37 2005 for OPIE by  doxygen 1.4.2