| 186 | } |
| 187 | |
| 188 | butil::Status FlvReader::ReadHeader() { |
| 189 | if (!_read_header) { |
| 190 | // 9 is the size of FlvHeader, which is usually composed of |
| 191 | // { 'F', 'L', 'V', 0x01, 0x05, 0, 0, 0, 0x09 }. |
| 192 | char header_buf[9 + 4/* PreviousTagSize0 */]; |
| 193 | const char* p = (const char*)_buf->fetch(header_buf, sizeof(header_buf)); |
| 194 | if (p == NULL) { |
| 195 | return butil::Status(EAGAIN, "Fail to read, not enough data"); |
| 196 | } |
| 197 | const char flv_header_signature[3] = { 'F', 'L', 'V' }; |
| 198 | if (memcmp(p, flv_header_signature, sizeof(flv_header_signature)) != 0) { |
| 199 | LOG(FATAL) << "Fail to parse FLV header"; |
| 200 | return butil::Status(EINVAL, "Fail to parse FLV header"); |
| 201 | } |
| 202 | _buf->pop_front(sizeof(header_buf)); |
| 203 | _read_header = true; |
| 204 | } |
| 205 | return butil::Status::OK(); |
| 206 | } |
| 207 | |
| 208 | butil::Status FlvReader::PeekMessageType(FlvTagType* type_out) { |
| 209 | butil::Status st = ReadHeader(); |