00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef H264UTILS_H_
00034 #define H264UTILS_H_
00035
00036 #include <stdint.h>
00037
00038 namespace H264
00039 {
00040
00048 class NALUnitType
00049 {
00050 public:
00052 enum
00053 {
00054 UNKNOWN = 0,
00055 SLICE = 1,
00056 SLICE_DPA = 2,
00057 SLICE_DPB = 3,
00058 SLICE_DPC = 4,
00059 SLICE_IDR = 5,
00060 SEI = 6,
00061 SPS = 7,
00062 PPS = 8,
00063 AU_DELIMITER = 9,
00064 END_SEQUENCE = 10,
00065 END_STREAM = 11,
00066 FILLER_DATA = 12,
00067 SPS_EXT = 13,
00068 AUXILIARY_SLICE = 19,
00069 };
00070
00072 static bool IsVCLType(const uint8_t type)
00073 { return (type > UNKNOWN && type < SEI); }
00074
00075 static const char *toString(const uint8_t type)
00076 {
00077 switch (type)
00078 {
00079 case SLICE:
00080 return "SLICE";
00081
00082 case SLICE_DPA:
00083 return "SLICE_DPA";
00084
00085 case SLICE_DPB:
00086 return "SLICE_DPB";
00087
00088 case SLICE_DPC:
00089 return "SLICE_DPC";
00090
00091 case SLICE_IDR:
00092 return "SLICE_IDR";
00093
00094 case SEI:
00095 return "SEI";
00096
00097 case SPS:
00098 return "SPS";
00099
00100 case PPS:
00101 return "PPS";
00102
00103 case AU_DELIMITER:
00104 return "AU_DELIMITER";
00105
00106 case END_SEQUENCE:
00107 return "END_SEQUENCE";
00108
00109 case END_STREAM:
00110 return "END_STREAM";
00111
00112 case FILLER_DATA:
00113 return "FILLER_DATA";
00114
00115 case SPS_EXT:
00116 return "SPS_EXT";
00117
00118 case AUXILIARY_SLICE:
00119 return "AUXILIARY_SLICE";
00120
00121 default:
00122 return "UNKNOWN";
00123 }
00124 }
00125 };
00126
00143 class KeyframeSequencer
00144 {
00145 public:
00146 KeyframeSequencer();
00147
00148 inline bool IsErrored(void) const
00149 { return errored; }
00150 inline bool HasStateChanged(void) const
00151 { return state_changed; }
00152
00153 void Reset(void);
00154
00161 uint32_t AddBytes(const uint8_t *bytes, const uint32_t byte_count,
00162 const int64_t stream_offset);
00163
00165 inline uint8_t LastSyncedType(void) const
00166 { return first_NAL_byte & 0x1f; }
00167
00168 bool IsOnFrame(void) const;
00169 inline bool IsOnKeyframe(void) const
00170 { return keyframe; }
00171
00172 inline int64_t KeyframeAUStreamOffset(void) const
00173 { return keyframe_sync_stream_offset; }
00174
00175 private:
00176 void KeyframePredicate(const uint8_t new_first_NAL_byte);
00177
00178 bool errored;
00179 bool state_changed;
00180
00181 uint32_t sync_accumulator;
00182 int64_t sync_stream_offset;
00183
00184 uint8_t first_NAL_byte;
00185
00186 bool saw_AU_delimiter;
00187 bool saw_first_VCL_NAL_unit;
00188 bool saw_sps;
00189
00190 bool did_evaluate_once;
00191 bool keyframe;
00192 int64_t keyframe_sync_stream_offset;
00193 };
00194
00195 }
00196
00197 #endif // H264UTILS_H_