/usr/include/mpeg3/mpeg3protos.h is in libmpeg3-dev 1.8.dfsg-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 | #ifndef MPEG3PROTOS_H
#define MPEG3PROTOS_H
#ifndef CLAMP
#define CLAMP(x, y, z) ((x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x))))
#endif
/* CSS */
mpeg3_css_t* mpeg3_new_css();
/* Workarounds */
int64_t mpeg3io_tell_gcc(mpeg3_fs_t *fs);
double mpeg3_add_double_gcc(double x, double y);
double mpeg3_divide_double_gcc(double x, double y);
int64_t mpeg3_total_bytes_gcc(mpeg3_title_t *title);
int64_t mpeg3io_path_total_bytes(char *path);
int64_t mpeg3io_get_total_bytes(mpeg3_fs_t *fs);
int mpeg3_copy_fs(mpeg3_fs_t *dst, mpeg3_fs_t *src);
/* TITLE */
mpeg3_title_t* mpeg3_new_title(mpeg3_t *file, char *path);
void mpeg3_new_cell(mpeg3_title_t *title,
int64_t program_start,
int64_t program_end,
int64_t title_start,
int64_t title_end,
int program);
/* Called by mpeg3_open for a single file */
int mpeg3demux_create_title(mpeg3_demuxer_t *demuxer,
FILE *toc);
int mpeg3_delete_title(mpeg3_title_t *title);
int mpeg3_create_title(mpeg3_demuxer_t *demuxer, FILE *toc);
/* ATRACK */
mpeg3_atrack_t* mpeg3_new_atrack(mpeg3_t *file,
int custom_id,
int is_ac3,
mpeg3_demuxer_t *demuxer,
int number);
int mpeg3_delete_atrack(mpeg3_t *file, mpeg3_atrack_t *atrack);
void mpeg3_append_samples(mpeg3_atrack_t *atrack, int64_t offset);
/* These return 1 on failure and 0 on success */
int mpeg3_next_header();
/* VTRACK */
mpeg3_vtrack_t* mpeg3_new_vtrack(mpeg3_t *file,
int custom_id,
mpeg3_demuxer_t *demuxer,
int number);
int mpeg3_delete_vtrack(mpeg3_t *file, mpeg3_vtrack_t *vtrack);
void mpeg3_append_frame(mpeg3_vtrack_t *vtrack, int64_t offset, int is_keyframe);
/* STRACK */
mpeg3_strack_t* mpeg3_new_strack(int id);
void mpeg3_delete_strack(mpeg3_strack_t *ptr);
void mpeg3_copy_strack(mpeg3_strack_t *dst, mpeg3_strack_t *src);
/* Get matching subtitle track based on ID or return 0 if it doesn't exist. */
mpeg3_strack_t* mpeg3_get_strack_id(mpeg3_t *file, int id);
/* get the subtitle track based on number starting from 0 */
mpeg3_strack_t* mpeg3_get_strack(mpeg3_t *file, int number);
/* Create new subtitle track and add to table in right order. */
mpeg3_strack_t* mpeg3_create_strack(mpeg3_t *file, int id);
/* Append program offset of a subtitle to the track */
void mpeg3_append_subtitle_offset(mpeg3_strack_t *dst, int64_t program_offset);
/* Delete a subtitle object */
void mpeg3_delete_subtitle(mpeg3_subtitle_t *subtitle);
/* Store subtitle object as current subtitle. */
/* The object is deleted by the subtitle track. */
void mpeg3_append_subtitle(mpeg3_strack_t *strack, mpeg3_subtitle_t *subtitle);
/* Get the first subtitle in the track which is not currently being drawn. */
mpeg3_subtitle_t* mpeg3_get_subtitle(mpeg3_strack_t *strack);
/* Remove the pointer and delete the first subtitle from the track. */
void mpeg3_pop_subtitle(mpeg3_strack_t *strack, int number, int delete_it);
/* Remove all subtitles from track. */
void mpeg3_pop_all_subtitles(mpeg3_strack_t *strack);
/* Remove all subtitles from all buffers */
void mpeg3_reset_subtitles(mpeg3_t *file);
int mpeg3_subtitle_tracks(mpeg3_t *file);
/* AUDIO */
mpeg3audio_t* mpeg3audio_new(mpeg3_t *file,
mpeg3_atrack_t *track,
int is_ac3);
int mpeg3audio_delete(mpeg3audio_t *audio);
/* Decode up to requested number of samples. */
/* Return 0 on success and 1 on failure. */
int mpeg3audio_decode_audio(mpeg3audio_t *audio,
float *output_f,
short *output_i,
int channel,
int len);
/* Shift the audio by the number of samples */
/* Used by table of contents routines and decode_audio */
void mpeg3_shift_audio(mpeg3audio_t *audio, int diff);
/* Audio consists of many possible formats, each packetized into frames. */
/* Each format has a constructor, header decoder, frame decoder, and destructor. */
/* The function set is determined by the audio format. */
/* To decode audio, for each frame read the header sized number of bytes. */
/* Call the header decoder for the format. */
/* Call the frame decoder for the format. */
int mpeg3_new_decode_tables(mpeg3_layer_t *audio);
int mpeg3_init_layer3(mpeg3_layer_t *audio);
int mpeg3_init_layer2(mpeg3_layer_t *audio);
/* Create a new layer decoder */
mpeg3_layer_t* mpeg3_new_layer();
/* Create a new ac3 decoder */
mpeg3_ac3_t* mpeg3_new_ac3();
/* Create a new pcm decoder */
mpeg3_pcm_t* mpeg3_new_pcm();
/* Delete a new layer decoder */
void mpeg3_delete_layer(mpeg3_layer_t *audio);
/* Delete a new ac3 decoder */
void mpeg3_delete_ac3(mpeg3_ac3_t *audio);
/* Delete a new pcm decoder */
void mpeg3_delete_pcm(mpeg3_pcm_t *audio);
/* Return 1 if the data isn't a header */
int mpeg3_layer_check(unsigned char *data);
int mpeg3_ac3_check(unsigned char *header);
int mpeg3_pcm_check(unsigned char *header);
/* These return the size of the next frame including the header */
/* or 0 if it wasn't a header. */
/* Decode a layer header */
/* This is used directly in Quicktime */
int mpeg3_layer_header(mpeg3_layer_t *layer_data, unsigned char *data);
/* Decode an AC3 header */
int mpeg3_ac3_header(mpeg3_ac3_t *audio, unsigned char *header);
/* Decode an PCM header */
int mpeg3_pcm_header(mpeg3_pcm_t *audio, unsigned char *header);
/* Reset after a seek */
void mpeg3_layer_reset(mpeg3_layer_t *audio);
/* Decode a frame of layer 3 audio. */
/* The output is linear, one buffer for every channel. */
/* The user should get the channel count from one of the header commands */
/* The output must be big enough to hold the largest frame of audio */
/* These functions return the number of samples rendered */
int mpeg3audio_dolayer3(mpeg3_layer_t *audio,
char *frame,
int frame_size,
float **output,
int render);
/* Decode a frame of layer 2 audio */
int mpeg3audio_dolayer2(mpeg3_layer_t *audio,
char *frame,
int frame_size,
float **output,
int render);
/* Decode a frame of ac3 audio */
int mpeg3audio_doac3(mpeg3_ac3_t *audio,
char *frame,
int frame_size,
float **output,
int render);
/* Decode a frame of ac3 audio */
int mpeg3audio_dopcm(mpeg3_pcm_t *audio,
char *frame,
int frame_size,
float **output,
int render);
/* VIDEO */
mpeg3video_t* mpeg3video_new(mpeg3_t *file,
mpeg3_vtrack_t *track);
int mpeg3video_delete(mpeg3video_t *video);
int mpeg3video_read_frame(mpeg3video_t *video,
unsigned char **output_rows,
int in_x,
int in_y,
int in_w,
int in_h,
int out_w,
int out_h,
int color_model);
void mpeg3video_dump(mpeg3video_t *video);
int mpeg3video_prev_code(mpeg3_demuxer_t *demuxer, unsigned int code);
int mpeg3video_next_code(mpeg3_bits_t* stream, unsigned int code);
void mpeg3video_toc_error();
int mpeg3_rewind_video(mpeg3video_t *video);
int mpeg3_read_yuvframe_ptr(mpeg3_t *file,
char **y_output,
char **u_output,
char **v_output,
int stream);
int mpeg3_read_yuvframe(mpeg3_t *file,
char *y_output,
char *u_output,
char *v_output,
int in_x,
int in_y,
int in_w,
int in_h,
int stream);
// cache_it - store dropped frames in cache
int mpeg3video_drop_frames(mpeg3video_t *video, long frames, int cache_it);
void mpeg3_decode_subtitle(mpeg3video_t *video);
/* FRAME CACHING */
mpeg3_cache_t* mpeg3_new_cache();
void mpeg3_delete_cache(mpeg3_cache_t *ptr);
void mpeg3_reset_cache(mpeg3_cache_t *ptr);
void mpeg3_cache_put_frame(mpeg3_cache_t *ptr,
int64_t frame_number,
unsigned char *y,
unsigned char *u,
unsigned char *v,
int y_size,
int u_size,
int v_size);
// Return 1 if the frame was found.
int mpeg3_cache_get_frame(mpeg3_cache_t *ptr,
int64_t frame_number,
unsigned char **y,
unsigned char **u,
unsigned char **v);
int mpeg3_ceche_has_frame(mpeg3_cache_t *ptr,
int64_t frame_number);
int64_t mpeg3_cache_usage(mpeg3_cache_t *ptr);
/* FILESYSTEM */
mpeg3_fs_t* mpeg3_new_fs(char *path);
int mpeg3_delete_fs(mpeg3_fs_t *fs);
int mpeg3io_open_file(mpeg3_fs_t *fs);
int mpeg3io_close_file(mpeg3_fs_t *fs);
int mpeg3io_seek(mpeg3_fs_t *fs, int64_t byte);
int mpeg3io_seek_relative(mpeg3_fs_t *fs, int64_t bytes);
int mpeg3io_read_data(unsigned char *buffer, int64_t bytes, mpeg3_fs_t *fs);
void mpeg3io_complete_path(char *complete_path, char *path);
void mpeg3io_get_directory(char *directory, char *path);
void mpeg3io_get_filename(char *filename, char *path);
void mpeg3io_joinpath(char *title_path, char *directory, char *new_filename);
/* MAIN */
mpeg3_t* mpeg3_new(char *path);
mpeg3_index_t* mpeg3_new_index();
void mpeg3_delete_index(mpeg3_index_t *index);
int mpeg3_delete(mpeg3_t *file);
/* Returns 1 on error. */
/* Returns 2 if TOC is wrong version. */
int mpeg3_get_file_type(mpeg3_t *file,
mpeg3_t *old_file,
int *toc_atracks,
int *toc_vtracks);
int mpeg3_read_toc(mpeg3_t *file, int *atracks_return, int *vtracks_return);
/* DEMUXER */
mpeg3_demuxer_t* mpeg3_new_demuxer(mpeg3_t *file,
int do_audio,
int do_video,
int custom_id);
int mpeg3_delete_demuxer(mpeg3_demuxer_t *demuxer);
mpeg3_demuxer_t* mpeg3_get_demuxer(mpeg3_t *file);
int mpeg3demux_read_data(mpeg3_demuxer_t *demuxer,
unsigned char *output,
int size);
/* Append elementary stream data */
/* Used by streaming mode. */
void mpeg3demux_append_data(mpeg3_demuxer_t *demuxer,
unsigned char *data,
/* Bytes of data */
int bytes);
/* Shift elementary data out */
/* Used by streaming mode */
void mpeg3demux_shift_data(mpeg3_demuxer_t *demuxer,
int bytes);
/* Convert absolute byte position to position in program */
int64_t mpeg3_absolute_to_program(mpeg3_demuxer_t *demuxer,
int64_t absolute_byte);
int mpeg3_read_next_packet(mpeg3_demuxer_t *demuxer);
int mpeg3_read_prev_packet(mpeg3_demuxer_t *demuxer);
unsigned int mpeg3demux_read_int32(mpeg3_demuxer_t *demuxer);
unsigned int mpeg3demux_read_int24(mpeg3_demuxer_t *demuxer);
unsigned int mpeg3demux_read_int16(mpeg3_demuxer_t *demuxer);
/* Give total number of bytes in all titles which belong to the current program. */
int64_t mpeg3demux_movie_size(mpeg3_demuxer_t *demuxer);
/* Give byte offset relative to start of movie */
int64_t mpeg3demux_tell_byte(mpeg3_demuxer_t *demuxer);
/* Give program the current packet belongs to */
int mpeg3demux_tell_program(mpeg3_demuxer_t *demuxer);
double mpeg3demux_get_time(mpeg3_demuxer_t *demuxer);
int mpeg3demux_eof(mpeg3_demuxer_t *demuxer);
int mpeg3demux_bof(mpeg3_demuxer_t *demuxer);
void mpeg3demux_start_reverse(mpeg3_demuxer_t *demuxer);
void mpeg3demux_start_forward(mpeg3_demuxer_t *demuxer);
int mpeg3demux_open_title(mpeg3_demuxer_t *demuxer, int title_number);
/* Go to the absolute byte given */
int mpeg3demux_seek_byte(mpeg3_demuxer_t *demuxer, int64_t byte);
/* Seek to the title and cell containing the absolute byte of the */
/* demuxer. */
/* Called at the beginning of every packet. */
int mpeg3_seek_phys(mpeg3_demuxer_t *demuxer);
unsigned char mpeg3demux_read_char_packet(mpeg3_demuxer_t *demuxer);
unsigned char mpeg3demux_read_prev_char_packet(mpeg3_demuxer_t *demuxer);
int mpeg3demux_read_program(mpeg3_demuxer_t *demuxer);
/* Get last pts read */
double mpeg3demux_audio_pts(mpeg3_demuxer_t *demuxer);
double mpeg3demux_video_pts(mpeg3_demuxer_t *demuxer);
/* Set the last pts read to -1 for audio and video */
void mpeg3demux_reset_pts(mpeg3_demuxer_t *demuxer);
/* scan forward for next pts. Used in byte seeking to synchronize */
double mpeg3demux_scan_pts(mpeg3_demuxer_t *demuxer);
/* seek using sequential search to the pts given. Used in byte seeking. */
int mpeg3demux_goto_pts(mpeg3_demuxer_t *demuxer, double pts);
/* Get number of finished subtitles in the table matching id. */
/* If id = -1, get all finished subtitles. */
int mpeg3_finished_subtitles(mpeg3_demuxer_t *demuxer, int id);
unsigned char mpeg3demux_read_char_packet(mpeg3_demuxer_t *demuxer);
unsigned char mpeg3demux_read_prev_char_packet(mpeg3_demuxer_t *demuxer);
#define mpeg3demux_error(demuxer) (((mpeg3_demuxer_t *)(demuxer))->error_flag)
static unsigned char mpeg3demux_read_char(mpeg3_demuxer_t *demuxer)
{
//printf("mpeg3demux_read_char %lx %lx\n", demuxer->data_position, demuxer->data_size);
if(demuxer->data_position < demuxer->data_size)
{
return demuxer->data_buffer[demuxer->data_position++];
}
else
{
return mpeg3demux_read_char_packet(demuxer);
}
}
static unsigned char mpeg3demux_read_prev_char(mpeg3_demuxer_t *demuxer)
{
if(demuxer->data_position != 0)
{
return demuxer->data_buffer[demuxer->data_position--];
}
else
{
return mpeg3demux_read_prev_char_packet(demuxer);
}
}
// Bitstream
mpeg3_bits_t* mpeg3bits_new_stream(mpeg3_t *file, mpeg3_demuxer_t *demuxer);
int mpeg3bits_delete_stream(mpeg3_bits_t* stream);
int mpeg3bits_seek_byte(mpeg3_bits_t* stream, int64_t position);
int mpeg3bits_open_title(mpeg3_bits_t* stream, int title);
/* Give absolute byte offset in all titles. */
int64_t mpeg3bits_tell(mpeg3_bits_t* stream);
/* Reset bit bucket */
void mpeg3bits_reset(mpeg3_bits_t *stream);
int mpeg3bits_refill(mpeg3_bits_t* stream);
int mpeg3bits_use_ptr(mpeg3_bits_t* stream, unsigned char *buffer);
int mpeg3bits_getbitoffset(mpeg3_bits_t *stream);
int mpeg3bits_byte_align(mpeg3_bits_t *stream);
void mpeg3bits_start_forward(mpeg3_bits_t* stream);
void mpeg3bits_start_reverse(mpeg3_bits_t* stream);
#define mpeg3bits_error(stream) mpeg3demux_error((stream)->demuxer)
#define mpeg3bits_eof(stream) mpeg3demux_eof((stream)->demuxer)
#define mpeg3bits_bof(stream) mpeg3demux_bof((stream)->demuxer)
/* Read bytes backward from the file until the reverse_bits is full. */
static void mpeg3bits_fill_reverse_bits(mpeg3_bits_t* stream, int bits)
{
// Right justify
while(stream->bit_number > 7)
{
stream->bfr >>= 8;
stream->bfr_size -= 8;
stream->bit_number -= 8;
}
// Insert bytes before bfr_size
while(stream->bfr_size - stream->bit_number < bits)
{
if(stream->input_ptr)
stream->bfr |= (unsigned int)(*--stream->input_ptr) << stream->bfr_size;
else
stream->bfr |= (unsigned int)mpeg3demux_read_prev_char(stream->demuxer) << stream->bfr_size;
stream->bfr_size += 8;
}
}
/* Read bytes forward from the file until the forward_bits is full. */
static void mpeg3bits_fill_bits(mpeg3_bits_t* stream, int bits)
{
while(stream->bit_number < bits)
{
stream->bfr <<= 8;
if(stream->input_ptr)
{
stream->bfr |= *stream->input_ptr++;
}
else
{
stream->bfr |= mpeg3demux_read_char(stream->demuxer);
}
stream->bit_number += 8;
stream->bfr_size += 8;
if(stream->bfr_size > 32) stream->bfr_size = 32;
}
}
/* Return 8 bits, advancing the file position. */
static unsigned int mpeg3bits_getbyte_noptr(mpeg3_bits_t* stream)
{
if(stream->bit_number < 8)
{
stream->bfr <<= 8;
if(stream->input_ptr)
stream->bfr |= *stream->input_ptr++;
else
stream->bfr |= mpeg3demux_read_char(stream->demuxer);
stream->bfr_size += 8;
if(stream->bfr_size > 32) stream->bfr_size = 32;
return (stream->bfr >> stream->bit_number) & 0xff;
}
return (stream->bfr >> (stream->bit_number -= 8)) & 0xff;
}
static unsigned int mpeg3bits_getbit_noptr(mpeg3_bits_t* stream)
{
if(!stream->bit_number)
{
stream->bfr <<= 8;
stream->bfr |= mpeg3demux_read_char(stream->demuxer);
stream->bfr_size += 8;
if(stream->bfr_size > 32) stream->bfr_size = 32;
stream->bit_number = 7;
return (stream->bfr >> 7) & 0x1;
}
return (stream->bfr >> (--stream->bit_number)) & (0x1);
}
/* Return n number of bits, advancing the file position. */
/* Use in place of flushbits */
static unsigned int mpeg3bits_getbits(mpeg3_bits_t* stream, int bits)
{
if(bits <= 0) return 0;
mpeg3bits_fill_bits(stream, bits);
return (stream->bfr >> (stream->bit_number -= bits)) & (0xffffffff >> (32 - bits));
}
static unsigned int mpeg3bits_showbits24_noptr(mpeg3_bits_t* stream)
{
while(stream->bit_number < 24)
{
stream->bfr <<= 8;
stream->bfr |= mpeg3demux_read_char(stream->demuxer);
stream->bit_number += 8;
stream->bfr_size += 8;
if(stream->bfr_size > 32) stream->bfr_size = 32;
}
return (stream->bfr >> (stream->bit_number - 24)) & 0xffffff;
}
static unsigned int mpeg3bits_showbits32_noptr(mpeg3_bits_t* stream)
{
while(stream->bit_number < 32)
{
stream->bfr <<= 8;
stream->bfr |= mpeg3demux_read_char(stream->demuxer);
stream->bit_number += 8;
stream->bfr_size += 8;
if(stream->bfr_size > 32) stream->bfr_size = 32;
}
return stream->bfr;
}
static unsigned int mpeg3bits_showbits(mpeg3_bits_t* stream, int bits)
{
mpeg3bits_fill_bits(stream, bits);
return (stream->bfr >> (stream->bit_number - bits)) & (0xffffffff >> (32 - bits));
}
static unsigned int mpeg3bits_getbits_reverse(mpeg3_bits_t* stream, int bits)
{
unsigned int result;
mpeg3bits_fill_reverse_bits(stream, bits);
result = (stream->bfr >> stream->bit_number) & (0xffffffff >> (32 - bits));
stream->bit_number += bits;
return result;
}
static unsigned int mpeg3bits_showbits_reverse(mpeg3_bits_t* stream, int bits)
{
unsigned int result;
mpeg3bits_fill_reverse_bits(stream, bits);
result = (stream->bfr >> stream->bit_number) & (0xffffffff >> (32 - bits));
return result;
}
// I/O
// I/O must be character based so the buffer doesn't get overrun
void mpeg3io_read_buffer(mpeg3_fs_t *fs);
#define mpeg3io_tell(fs) (((mpeg3_fs_t *)(fs))->current_byte)
// End of file
#define mpeg3io_eof(fs) (((mpeg3_fs_t *)(fs))->current_byte >= ((mpeg3_fs_t *)(fs))->total_bytes)
// Beginning of file
#define mpeg3io_bof(fs) (((mpeg3_fs_t *)(fs))->current_byte < 0)
#define mpeg3io_get_fd(fs) (fileno(((mpeg3_fs_t *)(fs))->fd))
#define mpeg3io_total_bytes(fs) (((mpeg3_fs_t *)(fs))->total_bytes)
static int mpeg3io_sync_buffer(mpeg3_fs_t *fs)
{
// Reposition buffer offset
if(fs->buffer_position + fs->buffer_offset != fs->current_byte)
{
fs->buffer_offset = fs->current_byte - fs->buffer_position;
}
// Load new buffer
if(fs->current_byte < fs->buffer_position ||
fs->current_byte >= fs->buffer_position + fs->buffer_size)
{
mpeg3io_read_buffer(fs);
}
return !fs->buffer_size;
}
static unsigned int mpeg3io_read_char(mpeg3_fs_t *fs)
{
unsigned int result;
mpeg3io_sync_buffer(fs);
result = fs->buffer[fs->buffer_offset++];
fs->current_byte++;
return result;
}
static unsigned char mpeg3io_next_char(mpeg3_fs_t *fs)
{
unsigned char result;
mpeg3io_sync_buffer(fs);
result = fs->buffer[fs->buffer_offset];
return result;
}
static uint32_t mpeg3io_read_int32(mpeg3_fs_t *fs)
{
int a, b, c, d;
uint32_t result;
/* Do not fread. This breaks byte ordering. */
a = mpeg3io_read_char(fs);
b = mpeg3io_read_char(fs);
c = mpeg3io_read_char(fs);
d = mpeg3io_read_char(fs);
result = (a << 24) |
(b << 16) |
(c << 8) |
(d);
return result;
}
static uint32_t mpeg3io_read_int24(mpeg3_fs_t *fs)
{
int b, c, d;
uint32_t result;
/* Do not fread. This breaks byte ordering. */
b = mpeg3io_read_char(fs);
c = mpeg3io_read_char(fs);
d = mpeg3io_read_char(fs);
result = (b << 16) |
(c << 8) |
(d);
return result;
}
static uint16_t mpeg3io_read_int16(mpeg3_fs_t *fs)
{
int c, d;
uint16_t result;
/* Do not fread. This breaks byte ordering. */
c = mpeg3io_read_char(fs);
d = mpeg3io_read_char(fs);
result = (c << 8) |
(d);
return result;
}
// More bitstream
#define mpeg3slice_fillbits(buffer, nbits) \
while(((mpeg3_slice_buffer_t*)(buffer))->bits_size < (nbits)) \
{ \
if(((mpeg3_slice_buffer_t*)(buffer))->current_position < ((mpeg3_slice_buffer_t*)(buffer))->buffer_size) \
{ \
((mpeg3_slice_buffer_t*)(buffer))->bits <<= 8; \
((mpeg3_slice_buffer_t*)(buffer))->bits |= ((mpeg3_slice_buffer_t*)(buffer))->data[((mpeg3_slice_buffer_t*)(buffer))->current_position++]; \
} \
((mpeg3_slice_buffer_t*)(buffer))->bits_size += 8; \
}
#define mpeg3slice_flushbits(buffer, nbits) \
{ \
mpeg3slice_fillbits((buffer), (nbits)); \
((mpeg3_slice_buffer_t*)(buffer))->bits_size -= (nbits); \
}
#define mpeg3slice_flushbit(buffer) \
{ \
if(((mpeg3_slice_buffer_t*)(buffer))->bits_size) \
((mpeg3_slice_buffer_t*)(buffer))->bits_size--; \
else \
if(((mpeg3_slice_buffer_t*)(buffer))->current_position < ((mpeg3_slice_buffer_t*)(buffer))->buffer_size) \
{ \
((mpeg3_slice_buffer_t*)(buffer))->bits = \
((mpeg3_slice_buffer_t*)(buffer))->data[((mpeg3_slice_buffer_t*)(buffer))->current_position++]; \
((mpeg3_slice_buffer_t*)(buffer))->bits_size = 7; \
} \
}
static unsigned int mpeg3slice_getbit(mpeg3_slice_buffer_t *buffer)
{
if(buffer->bits_size)
return (buffer->bits >> (--buffer->bits_size)) & 0x1;
else
if(buffer->current_position < buffer->buffer_size)
{
buffer->bits = buffer->data[buffer->current_position++];
buffer->bits_size = 7;
return (buffer->bits >> 7) & 0x1;
}
return 0;
}
static unsigned int mpeg3slice_getbits2(mpeg3_slice_buffer_t *buffer)
{
if(buffer->bits_size >= 2)
return (buffer->bits >> (buffer->bits_size -= 2)) & 0x3;
else
if(buffer->current_position < buffer->buffer_size)
{
buffer->bits <<= 8;
buffer->bits |= buffer->data[buffer->current_position++];
buffer->bits_size += 6;
return (buffer->bits >> buffer->bits_size) & 0x3;
}
return 0;
}
static unsigned int mpeg3slice_getbyte(mpeg3_slice_buffer_t *buffer)
{
if(buffer->bits_size >= 8)
return (buffer->bits >> (buffer->bits_size -= 8)) & 0xff;
else
if(buffer->current_position < buffer->buffer_size)
{
buffer->bits <<= 8;
buffer->bits |= buffer->data[buffer->current_position++];
return (buffer->bits >> buffer->bits_size) & 0xff;
}
return 0;
}
static unsigned int mpeg3slice_getbits(mpeg3_slice_buffer_t *slice_buffer, int bits)
{
if(bits == 1) return mpeg3slice_getbit(slice_buffer);
mpeg3slice_fillbits(slice_buffer, bits);
return (slice_buffer->bits >> (slice_buffer->bits_size -= bits)) & (0xffffffff >> (32 - bits));
}
static unsigned int mpeg3slice_showbits16(mpeg3_slice_buffer_t *buffer)
{
if(buffer->bits_size >= 16)
return (buffer->bits >> (buffer->bits_size - 16)) & 0xffff;
else
if(buffer->current_position < buffer->buffer_size)
{
buffer->bits <<= 16;
buffer->bits_size += 16;
buffer->bits |= (unsigned int)buffer->data[buffer->current_position++] << 8;
buffer->bits |= buffer->data[buffer->current_position++];
return (buffer->bits >> (buffer->bits_size - 16)) & 0xffff;
}
return 0;
}
static unsigned int mpeg3slice_showbits9(mpeg3_slice_buffer_t *buffer)
{
if(buffer->bits_size >= 9)
return (buffer->bits >> (buffer->bits_size - 9)) & 0x1ff;
else
if(buffer->current_position < buffer->buffer_size)
{
buffer->bits <<= 16;
buffer->bits_size += 16;
buffer->bits |= (unsigned int)buffer->data[buffer->current_position++] << 8;
buffer->bits |= buffer->data[buffer->current_position++];
return (buffer->bits >> (buffer->bits_size - 9)) & 0x1ff;
}
return 0;
}
static unsigned int mpeg3slice_showbits5(mpeg3_slice_buffer_t *buffer)
{
if(buffer->bits_size >= 5)
return (buffer->bits >> (buffer->bits_size - 5)) & 0x1f;
else
if(buffer->current_position < buffer->buffer_size)
{
buffer->bits <<= 8;
buffer->bits_size += 8;
buffer->bits |= buffer->data[buffer->current_position++];
return (buffer->bits >> (buffer->bits_size - 5)) & 0x1f;
}
return 0;
}
static unsigned int mpeg3slice_showbits(mpeg3_slice_buffer_t *slice_buffer, int bits)
{
mpeg3slice_fillbits(slice_buffer, bits);
return (slice_buffer->bits >> (slice_buffer->bits_size - bits)) & (0xffffffff >> (32 - bits));
}
int mpeg3_read_ifo(mpeg3_t *file, int read_cells);
#endif
|