Lines Matching refs:stream

54     BitstreamEncVideo *stream;
55 stream = (BitstreamEncVideo *) M4VENC_MALLOC(sizeof(BitstreamEncVideo));
56 if (stream == NULL)
60 stream->bufferSize = bufferSize;
61 stream->bitstreamBuffer = (UChar *) M4VENC_MALLOC(stream->bufferSize * sizeof(UChar));
62 if (stream->bitstreamBuffer == NULL)
64 M4VENC_FREE(stream);
65 stream = NULL;
68 M4VENC_MEMSET(stream->bitstreamBuffer, 0, stream->bufferSize*sizeof(UChar));
69 stream->word = 0;
71 stream->bitLeft = 32;
73 stream->bitLeft = 16;
75 stream->byteCount = 0;
77 stream->overrunBuffer = NULL;
78 stream->oBSize = 0;
80 return stream;
88 stream : the bitstream to be closed */
93 Void BitstreamCloseEnc(BitstreamEncVideo *stream)
95 if (stream)
97 if (stream->bitstreamBuffer)
99 M4VENC_FREE(stream->bitstreamBuffer);
102 M4VENC_FREE(stream);
108 /* Function : BitstreamPutBits(BitstreamEncVideo *stream, Int Length,
111 /* Purpose : put Length (1-16) number of bits to the stream */
114 /* stream the bitstream where the bits are put in */
120 PV_STATUS BitstreamPutBits(BitstreamEncVideo *stream, Int Length, UInt Value)
124 if (stream->bitLeft > Length)
126 stream->word <<= Length;
127 stream->word |= Value; /* assuming Value is not larger than Length */
128 stream->bitLeft -= Length;
134 stream->word <<= stream->bitLeft;
135 Length -= stream->bitLeft;
136 stream->word |= ((UInt)Value >> Length);
138 status = BitstreamSaveWord(stream);
146 stream->word = Value;
147 stream->bitLeft -= Length;
149 /* stream->bitLeft should be greater than zero at this point */
150 //if(stream->bitLeft<=0)
157 /* Function : BitstreamPutGT16Bits(BitstreamEncVideo *stream, Int Length, UInt32 Value) */
160 /* for 16-bit machine the stream. */
162 /* stream the bitstream where the bits are put in */
168 PV_STATUS BitstreamPutGT16Bits(BitstreamEncVideo *stream, Int Length, ULong Value)
179 status = BitstreamPutBits(stream, topLength, topValue);
186 status = BitstreamPutBits(stream, 16, (UInt)(Value & 0xFFFF));
192 status = BitstreamPutBits(stream, Length, (UInt)Value);
202 /* stream the bitstream where the bits are put in */
207 PV_STATUS BitstreamSaveWord(BitstreamEncVideo *stream)
212 /* assume that stream->bitLeft is always zero when this function is called */
213 if (stream->byteCount + WORD_SIZE > stream->bufferSize)
215 if (PV_SUCCESS != BitstreamUseOverrunBuffer(stream, WORD_SIZE))
217 stream->byteCount += WORD_SIZE;
222 ptr = stream->bitstreamBuffer + stream->byteCount;
223 word = stream->word;
224 stream->word = 0; /* important to reset to zero */
236 stream->byteCount += 4;
237 stream->bitLeft = 32;
239 stream->byteCount += 2;
240 stream->bitLeft = 16;
252 /* stream the bitstream where the bits are put in */
257 PV_STATUS BitstreamSavePartial(BitstreamEncVideo *stream, Int *fraction)
263 bitleft = stream->bitLeft;
267 if (stream->byteCount + numbyte > stream->bufferSize)
269 if (PV_SUCCESS != BitstreamUseOverrunBuffer(stream, numbyte))
271 stream->byteCount += numbyte;
276 ptr = stream->bitstreamBuffer + stream->byteCount;
277 word = stream->word;
280 stream->byteCount += numbyte;
291 stream->bitLeft = bitleft;
307 stream->word = word >> bitleft;
318 /* BitstreamEncVideo *stream) */
326 Int BitstreamShortHeaderByteAlignStuffing(BitstreamEncVideo *stream)
331 restBits = (stream->bitLeft & 0x7); /* modulo 8 */
336 BitstreamPutBits(stream, restBits, 0);
339 if (stream->bitLeft != (WORD_SIZE << 3))
341 BitstreamSavePartial(stream, &fraction);
348 /* Function : BitstreamMpeg4ByteAlignStuffing(BitstreamEncVideo *stream) */
355 Int BitstreamMpeg4ByteAlignStuffing(BitstreamEncVideo *stream)
365 BitstreamPutBits(stream, 1, 0);
367 restBits = (stream->bitLeft & 0x7); /* modulo 8 */
372 BitstreamPutBits(stream, restBits, Mask[restBits]);
375 if (stream->bitLeft != (WORD_SIZE << 3))
377 BitstreamSavePartial(stream, &fraction);
395 /*Int BitstreamNextResyncMarkerEnc(BitstreamEncVideo *stream)
398 BitstreamPut1Bits(stream,0);
399 count=8-stream->totalBits & 8;
400 BitstreamPutBits(stream,count,Mask[count]);
753 /* Function : BitstreamGetPos( BitstreamEncVideo *stream */
760 Int BitstreamGetPos(BitstreamEncVideo *stream)
763 return stream->byteCount*8 + (WORD_SIZE << 3) - stream->bitLeft;
766 void BitstreamEncReset(BitstreamEncVideo *stream)
768 stream->bitLeft = (WORD_SIZE << 3);
769 stream->word = 0;
770 stream->byteCount = 0;
776 Void BitstreamSetOverrunBuffer(BitstreamEncVideo* stream, UChar* overrunBuffer, Int oBSize, VideoEncData *video)
778 stream->overrunBuffer = overrunBuffer;
779 stream->oBSize = oBSize;
780 stream->video = video;
787 PV_STATUS BitstreamUseOverrunBuffer(BitstreamEncVideo* stream, Int numExtraBytes)
789 VideoEncData *video = stream->video;
791 if (stream->overrunBuffer != NULL) // overrunBuffer is set
793 if (stream->bitstreamBuffer != stream->overrunBuffer) // not already used
795 if (stream->byteCount + numExtraBytes >= stream->oBSize)
797 stream->oBSize = stream->byteCount + numExtraBytes + 100;
798 stream->oBSize &= (~0x3); // make it multiple of 4
805 video->oBSize = stream->oBSize;
806 video->overrunBuffer = (UChar*) M4VENC_MALLOC(sizeof(UChar) * stream->oBSize);
807 stream->overrunBuffer = video->overrunBuffer;
808 if (stream->overrunBuffer == NULL)
815 memcpy(stream->overrunBuffer, stream->bitstreamBuffer, stream->byteCount);
816 stream->bitstreamBuffer = stream->overrunBuffer;
817 stream->bufferSize = stream->oBSize;
821 if (stream->byteCount + numExtraBytes >= stream->oBSize)
823 stream->oBSize = stream->byteCount + numExtraBytes + 100;
827 stream->oBSize &= (~0x3); // make it multiple of 4
828 video->oBSize = stream->oBSize;
829 video->overrunBuffer = (UChar*) M4VENC_MALLOC(sizeof(UChar) * stream->oBSize);
836 memcpy(video->overrunBuffer, stream->overrunBuffer, stream->byteCount);
838 M4VENC_FREE(stream->overrunBuffer);
840 stream->overrunBuffer = video->overrunBuffer;
841 stream->bitstreamBuffer = stream->overrunBuffer;
842 stream->bufferSize = stream->oBSize;