mpeg3demux.h
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:4k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #ifndef MPEG3DEMUX_H
  2. #define MPEG3DEMUX_H
  3. #include "mpeg3title.h"
  4. #include <stdio.h>
  5. typedef struct
  6. {
  7. /* mpeg3_t */
  8. void* file;
  9. /* One packet. MPEG3_RAW_SIZE allocated since we don't know the packet size */
  10. unsigned char *raw_data;
  11. long raw_offset;
  12. /* Amount loaded in last raw_data */
  13. int raw_size;
  14. /* One packet payload */
  15. unsigned char *data_buffer;
  16. long data_size;
  17. long data_position;
  18. /* Only one is on depending on which track owns the demultiplexer. */
  19. int do_audio;
  20. int do_video;
  21. /* Direction of reads */
  22. int reverse;
  23. /* Set to 1 when eof or attempt to read before beginning */
  24. int error_flag;
  25. /* Temp variables for returning */
  26. unsigned char next_char;
  27. /* Correction factor for time discontinuity */
  28. double time_offset;
  29. int read_all;
  30. /* Info for mpeg3cat */
  31. long last_packet_start;
  32. long last_packet_end;
  33. long last_packet_decryption;
  34. /* Titles */
  35. mpeg3_title_t *titles[MPEG3_MAX_STREAMS];
  36. int total_titles;
  37. int current_title;
  38. /* Tables of every stream ID encountered */
  39. int astream_table[MPEG3_MAX_STREAMS];  /* macro of audio format if audio  */
  40. int vstream_table[MPEG3_MAX_STREAMS];  /* 1 if video */
  41. /* Programs */
  42. int total_programs;
  43. int current_program;
  44. /* Timecode in the current title */
  45. int current_timecode;
  46. /* Byte position in the current title */
  47. long current_byte;
  48. int transport_error_indicator;
  49. int payload_unit_start_indicator;
  50. int pid;
  51. int transport_scrambling_control;
  52. int adaptation_field_control;
  53. int continuity_counter;
  54. int is_padding;
  55. int pid_table[MPEG3_PIDMAX];
  56. int continuity_counters[MPEG3_PIDMAX];
  57. int total_pids;
  58. int adaptation_fields;
  59. double time;           /* Time in seconds */
  60. int audio_pid;
  61. int video_pid;
  62. int astream;     /* Video stream ID being decoded.  -1 = select first ID in stream */
  63. int vstream;     /* Audio stream ID being decoded.  -1 = select first ID in stream */
  64. int aformat;      /* format of the audio derived from multiplexing codes */
  65. long program_association_tables;
  66. int table_id;
  67. int section_length;
  68. int transport_stream_id;
  69. long pes_packets;
  70. double pes_audio_time;  /* Presentation Time stamps */
  71. double pes_video_time;  /* Presentation Time stamps */
  72. } mpeg3_demuxer_t;
  73. /* ========================================================================= */
  74. /*                             Entry points */
  75. /* ========================================================================= */
  76. unsigned char mpeg3demux_read_char_packet(mpeg3_demuxer_t *demuxer);
  77. unsigned char mpeg3demux_read_prev_char_packet(mpeg3_demuxer_t *demuxer);
  78. #define mpeg3demux_error(demuxer) (((mpeg3_demuxer_t *)(demuxer))->error_flag)
  79. #define mpeg3demux_time_offset(demuxer) (((mpeg3_demuxer_t *)(demuxer))->time_offset)
  80. #define mpeg3demux_current_time(demuxer) (((mpeg3_demuxer_t *)(demuxer))->time + ((mpeg3_demuxer_t *)(demuxer))->time_offset)
  81. static __inline unsigned char mpeg3demux_read_char(mpeg3_demuxer_t *demuxer)
  82. {
  83. //printf("mpeg3demux_read_char %lx %lxn", demuxer->data_position, demuxer->data_size);
  84. if(demuxer->data_position < demuxer->data_size)
  85. {
  86. return demuxer->data_buffer[demuxer->data_position++];
  87. }
  88. else
  89. {
  90. return mpeg3demux_read_char_packet(demuxer);
  91. }
  92. }
  93. static __inline unsigned char mpeg3demux_read_prev_char(mpeg3_demuxer_t *demuxer)
  94. {
  95. if(demuxer->data_position != 0)
  96. {
  97. return demuxer->data_buffer[demuxer->data_position--];
  98. }
  99. else
  100. {
  101. return mpeg3demux_read_prev_char_packet(demuxer);
  102. }
  103. }
  104. int mpeg3demux_eof(mpeg3_demuxer_t *demuxer);
  105. #endif