Lines Matching refs:stream

49 PV_STATUS BitstreamFillCache(BitstreamDecVideo *stream)
51 uint8 *bitstreamBuffer = stream->bitstreamBuffer;
55 stream->curr_word |= (stream->next_word >> stream->incnt); // stream->incnt cannot be 32
56 stream->next_word <<= (31 - stream->incnt);
57 stream->next_word <<= 1;
58 num_bits = stream->incnt_next + stream->incnt;
61 stream->incnt_next -= (32 - stream->incnt);
62 stream->incnt = 32;
66 v = bitstreamBuffer + stream->read_point;
68 if (stream->read_point > stream->data_end_pos - 4)
70 if (stream->data_end_pos <= stream->read_point)
72 stream->incnt = num_bits;
73 stream->incnt_next = 0;
77 stream->next_word = 0;
79 for (i = 0; i < stream->data_end_pos - stream->read_point; i++)
81 stream->next_word |= (v[i] << ((3 - i) << 3));
84 stream->read_point = stream->data_end_pos;
85 stream->curr_word |= (stream->next_word >> num_bits); // this is safe
87 stream->next_word <<= (31 - num_bits);
88 stream->next_word <<= 1;
90 stream->incnt += stream->incnt_next;
91 stream->incnt_next = num_bits - (32 - stream->incnt);
92 if (stream->incnt_next < 0)
94 stream->incnt += num_bits;
95 stream->incnt_next = 0;
99 stream->incnt = 32;
104 stream->next_word = ((uint32)v[0] << 24) | (v[1] << 16) | (v[2] << 8) | v[3];
105 stream->read_point += 4;
107 stream->curr_word |= (stream->next_word >> num_bits); // this is safe
108 stream->next_word <<= (31 - num_bits);
109 stream->next_word <<= 1;
110 stream->incnt_next += stream->incnt;
111 stream->incnt = 32;
124 void BitstreamReset(BitstreamDecVideo *stream, uint8 *buffer, int32 buffer_size)
127 oscl_memset(stream, 0, sizeof(BitstreamDecVideo));
128 stream->data_end_pos = buffer_size;
129 stream->bitstreamBuffer = buffer;
140 int BitstreamOpen(BitstreamDecVideo *stream, int)
144 // stream->currentBytePos = 0;
145 stream->data_end_pos = 0;
147 stream->incnt = 0;
148 stream->incnt_next = 0;
149 stream->bitcnt = 0;
150 stream->curr_word = stream->next_word = 0;
151 stream->read_point = stream->data_end_pos;
175 PV_STATUS BitstreamShowBits32HC(BitstreamDecVideo *stream, uint32 *code)
179 if (stream->incnt < 32)
182 status = BitstreamFillCache(stream);
184 *code = stream->curr_word;
193 PV_STATUS BitstreamShowBits32(BitstreamDecVideo *stream, int nbits, uint32 *code)
197 if (stream->incnt < nbits)
200 status = BitstreamFillCache(stream);
202 *code = stream->curr_word >> (32 - nbits);
215 PV_STATUS BitstreamShowBits16(BitstreamDecVideo *stream, int nbits, uint *code)
220 if (stream->incnt < nbits)
223 status = BitstreamFillCache(stream);
226 *code = stream->curr_word >> (32 - nbits);
238 PV_STATUS BitstreamShow15Bits(BitstreamDecVideo *stream, uint *code)
242 if (stream->incnt < 15)
245 status = BitstreamFillCache(stream);
247 *code = stream->curr_word >> 17;
257 PV_STATUS BitstreamShow13Bits(BitstreamDecVideo *stream, uint *code)
261 if (stream->incnt < 13)
264 status = BitstreamFillCache(stream);
266 *code = stream->curr_word >> 19;
270 uint BitstreamReadBits16_INLINE(BitstreamDecVideo *stream, int nbits)
275 if (stream->incnt < nbits)
278 status = BitstreamFillCache(stream);
280 code = stream->curr_word >> (32 - nbits);
281 PV_BitstreamFlushBits(stream, nbits);
286 uint BitstreamRead1Bits_INLINE(BitstreamDecVideo *stream)
292 if (stream->incnt < 1)
295 status = BitstreamFillCache(stream);
297 code = stream->curr_word >> 31;
298 PV_BitstreamFlushBits(stream, 1);
311 uint BitstreamReadBits16(BitstreamDecVideo *stream, int nbits)
315 if (stream->incnt < nbits)
318 BitstreamFillCache(stream);
320 code = stream->curr_word >> (32 - nbits);
321 PV_BitstreamFlushBits(stream, nbits);
333 uint BitstreamRead1Bits(BitstreamDecVideo *stream)
337 if (stream->incnt < 1)
340 BitstreamFillCache(stream);
342 code = stream->curr_word >> 31;
343 PV_BitstreamFlushBits(stream, 1);
355 PV_STATUS PV_BitstreamFlushBitsCheck(BitstreamDecVideo *stream, int nbits)
359 stream->bitcnt += nbits;
360 stream->incnt -= nbits;
361 if (stream->incnt < 0)
364 status = BitstreamFillCache(stream);
366 if (stream->incnt < 0)
368 stream->bitcnt += stream->incnt;
369 stream->incnt = 0;
372 stream->curr_word <<= nbits;
382 uint32 BitstreamReadBits32(BitstreamDecVideo *stream, int nbits)
386 if (stream->incnt < nbits)
389 BitstreamFillCache(stream);
391 code = stream->curr_word >> (32 - nbits);
392 PV_BitstreamFlushBits(stream, nbits);
396 uint32 BitstreamReadBits32HC(BitstreamDecVideo *stream)
400 BitstreamShowBits32HC(stream, &code);
401 stream->bitcnt += 32;
402 stream->incnt = 0;
403 stream->curr_word = 0;
415 PV_STATUS BitstreamCheckEndBuffer(BitstreamDecVideo *stream)
417 if (stream->read_point >= stream->data_end_pos && stream->incnt <= 0) return PV_END_OF_VOP;
422 PV_STATUS PV_BitstreamShowBitsByteAlign(BitstreamDecVideo *stream, int nbits, uint32 *code)
428 n_stuffed = 8 - (stream->bitcnt & 0x7); /* 07/05/01 */
430 if (stream->incnt < (nbits + n_stuffed))
433 status = BitstreamFillCache(stream);
436 *code = (stream->curr_word << n_stuffed) >> (32 - nbits);
441 PV_STATUS PV_BitstreamShowBitsByteAlignNoForceStuffing(BitstreamDecVideo *stream, int nbits, uint32 *code)
447 n_stuffed = (8 - (stream->bitcnt & 0x7)) & 7;
449 if (stream->incnt < (nbits + n_stuffed))
452 status = BitstreamFillCache(stream);
455 *code = (stream->curr_word << n_stuffed) >> (32 - nbits);
460 PV_STATUS PV_BitstreamByteAlign(BitstreamDecVideo *stream)
465 n_stuffed = 8 - (stream->bitcnt & 0x7); /* 07/05/01 */
468 if (stream->incnt < n_stuffed)
471 status = BitstreamFillCache(stream);
475 stream->bitcnt += n_stuffed;
476 stream->incnt -= n_stuffed;
477 stream->curr_word <<= n_stuffed;
478 if (stream->incnt < 0)
480 stream->bitcnt += stream->incnt;
481 stream->incnt = 0;
487 PV_STATUS BitstreamByteAlignNoForceStuffing(BitstreamDecVideo *stream)
491 n_stuffed = (8 - (stream->bitcnt & 0x7)) & 0x7; /* 07/05/01 */
493 stream->bitcnt += n_stuffed;
494 stream->incnt -= n_stuffed;
496 if (stream->incnt < 0)
498 stream->bitcnt += stream->incnt;
499 stream->incnt = 0;
501 stream->curr_word <<= n_stuffed;
513 int32 getPointer(BitstreamDecVideo *stream)
515 return stream->bitcnt;
529 PV_STATUS movePointerTo(BitstreamDecVideo *stream, int32 pos)
539 if (byte_pos > stream->data_end_pos)
541 byte_pos = stream->data_end_pos;
544 stream->read_point = byte_pos & -4;
545 stream->bitcnt = stream->read_point << 3;;
546 stream->curr_word = 0;
547 stream->next_word = 0;
548 stream->incnt = 0;
549 stream->incnt_next = 0;
550 BitstreamFillCache(stream);
551 PV_BitstreamFlushBits(stream, ((pos & 0x7) + ((byte_pos & 0x3) << 3)));
565 Bool validStuffing(BitstreamDecVideo *stream)
571 n_stuffed = 8 - (stream->bitcnt & 0x7);
572 BitstreamShowBits16(stream, n_stuffed, &pattern);
577 Bool validStuffing_h263(BitstreamDecVideo *stream)
583 n_stuffed = (8 - (stream->bitcnt & 0x7)) & 7; // stream->incnt % 8
588 BitstreamShowBits16(stream, n_stuffed, &pattern);
603 PV_STATUS PVSearchNextH263Frame(BitstreamDecVideo *stream)
608 int32 initial_byte_aligned_position = (stream->bitcnt + 7) >> 3;
610 ptr = stream->bitstreamBuffer + initial_byte_aligned_position;
612 i = PVLocateH263FrameHeader(ptr, stream->data_end_pos - initial_byte_aligned_position);
613 if (stream->data_end_pos <= initial_byte_aligned_position + i)
617 (void)movePointerTo(stream, ((i + initial_byte_aligned_position) << 3)); /* ptr + i */
632 PV_STATUS PVSearchNextM4VFrame(BitstreamDecVideo *stream)
637 int32 initial_byte_aligned_position = (stream->bitcnt + 7) >> 3;
639 ptr = stream->bitstreamBuffer + initial_byte_aligned_position;
641 i = PVLocateFrameHeader(ptr, stream->data_end_pos - initial_byte_aligned_position);
642 if (stream->data_end_pos <= initial_byte_aligned_position + i)
646 (void)movePointerTo(stream, ((i + initial_byte_aligned_position) << 3)); /* ptr + i */
652 void PVLocateM4VFrameBoundary(BitstreamDecVideo *stream)
655 int32 byte_pos = (stream->bitcnt >> 3);
657 stream->searched_frame_boundary = 1;
658 ptr = stream->bitstreamBuffer + byte_pos;
660 stream->data_end_pos = PVLocateFrameHeader(ptr, (int32)stream->data_end_pos - byte_pos) + byte_pos;
663 void PVLocateH263FrameBoundary(BitstreamDecVideo *stream)
666 int32 byte_pos = (stream->bitcnt >> 3);
668 stream->searched_frame_boundary = 1;
669 ptr = stream->bitstreamBuffer + byte_pos;
671 stream->data_end_pos = PVLocateH263FrameHeader(ptr, (int32)stream->data_end_pos - byte_pos) + byte_pos;
682 PV_STATUS quickSearchVideoPacketHeader(BitstreamDecVideo *stream, int marker_length)
688 if (stream->searched_frame_boundary == 0)
690 PVLocateM4VFrameBoundary(stream);
695 status = BitstreamCheckEndBuffer(stream);
697 PV_BitstreamShowBitsByteAlign(stream, marker_length, &tmpvar);
699 PV_BitstreamFlushBits(stream, 8);
706 PV_STATUS quickSearchH263SliceHeader(BitstreamDecVideo *stream)
712 if (stream->searched_frame_boundary == 0)
714 PVLocateH263FrameBoundary(stream);
719 status = BitstreamCheckEndBuffer(stream);
721 PV_BitstreamShowBitsByteAlignNoForceStuffing(stream, 17, &tmpvar);
723 PV_BitstreamFlushBits(stream, 8);
784 PV_STATUS quickSearchMotionMarker(BitstreamDecVideo *stream)
790 if (stream->searched_frame_boundary == 0)
792 PVLocateM4VFrameBoundary(stream);
797 status = BitstreamCheckEndBuffer(stream);
800 BitstreamShowBits32(stream, 17, &tmpvar);
813 PV_BitstreamFlushBits(stream, (int)(12 + firstZero[tmpvar]));
825 PV_BitstreamFlushBits(stream, (int)(7 + lastOne[tmpvar2]));
835 PV_BitstreamFlushBits(stream, (int)(3 + lastOne[tmpvar2]));
849 PV_BitstreamFlushBits(stream, 17);
853 PV_BitstreamFlushBits(stream, (int)(lastOne[tmpvar2] - 1));
875 PV_STATUS quickSearchDCM(BitstreamDecVideo *stream)
881 if (stream->searched_frame_boundary == 0)
883 PVLocateM4VFrameBoundary(stream);
888 status = BitstreamCheckEndBuffer(stream);
890 BitstreamShowBits32(stream, 19, &tmpvar);
902 PV_BitstreamFlushBits(stream, 12);
912 PV_BitstreamFlushBits(stream, (int)(7 + lastOne[tmpvar2]));
920 PV_BitstreamFlushBits(stream, (int)(3 + lastOne[tmpvar2]));
930 PV_BitstreamFlushBits(stream, 19);
934 PV_BitstreamFlushBits(stream, (int)(lastOne[tmpvar2] - 1));
950 PV_STATUS quickSearchGOBHeader(BitstreamDecVideo *stream)
955 BitstreamByteAlignNoForceStuffing(stream);
957 if (stream->searched_frame_boundary == 0)
959 PVLocateH263FrameBoundary(stream);
964 status = BitstreamCheckEndBuffer(stream);
967 if (stream->incnt < 24)
969 status = BitstreamFillCache(stream);
973 byte1 = (stream->curr_word << 8) >> 24;
976 byte2 = (stream->curr_word << 16) >> 24;
989 byte0 = stream->curr_word >> 24;
992 PV_BitstreamFlushBits(stream, 8 - shift);
995 PV_BitstreamFlushBits(stream, 8); /* third_byte is not zero */
999 PV_BitstreamFlushBits(stream, 8);