/** * test the flv encoder, * write metadata tag */ VOID TEST(KernelFlvTest, FlvEncoderWriteMetadata) { MockSrsFileWriter fs; EXPECT_TRUE(ERROR_SUCCESS == fs.open("")); SrsFlvEncoder enc; ASSERT_TRUE(ERROR_SUCCESS == enc.initialize(&fs)); // 11 bytes tag header char tag_header[] = { (char)18, // TagType UB [5], 18 = script data (char)0x00, (char)0x00, (char)0x08, // DataSize UI24 Length of the message. (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. (char)0x00, // TimestampExtended UI8 (char)0x00, (char)0x00, (char)0x00, // StreamID UI24 Always 0. }; char md[] = { (char)0x01, (char)0x02, (char)0x03, (char)0x04, (char)0x04, (char)0x03, (char)0x02, (char)0x01 }; char pts[] = { (char)0x00, (char)0x00, (char)0x00, (char)19 }; ASSERT_TRUE(ERROR_SUCCESS == enc.write_metadata(md, 8)); ASSERT_TRUE(11 + 8 + 4 == fs.offset); EXPECT_TRUE(srs_bytes_equals(tag_header, fs.data, 11)); EXPECT_TRUE(srs_bytes_equals(md, fs.data + 11, 8)); EXPECT_TRUE(true); // donot know why, if not add it, the print is disabled. EXPECT_TRUE(srs_bytes_equals(pts, fs.data + 19, 4)); }
int SrsDvrHssPlan::on_meta_data(SrsOnMetaDataPacket* metadata) { int ret = ERROR_SUCCESS; SrsRequest* req = _req; // new flv file std::stringstream path; path << _srs_config->get_dvr_path(req->vhost) << "/" << req->app << "/" << req->stream << ".header.flv"; SrsFileStream fs; if ((ret = fs.open_write(path.str().c_str())) != ERROR_SUCCESS) { return ret; } SrsFlvEncoder enc; if ((ret = enc.initialize(&fs)) != ERROR_SUCCESS) { return ret; } if ((ret = enc.write_header()) != ERROR_SUCCESS) { return ret; } int size = 0; char* payload = NULL; if ((ret = metadata->encode(size, payload)) != ERROR_SUCCESS) { return ret; } SrsAutoFree(char, payload); if ((ret = enc.write_metadata(payload, size)) != ERROR_SUCCESS) { return ret; } #ifdef SRS_AUTO_HTTP_CALLBACK if ((ret = on_dvr_hss_reap_flv_header(path.str())) != ERROR_SUCCESS) { return ret; } #endif return ret; }