Skip to content

Commit

Permalink
Add FlvWriterOption as member variable
Browse files Browse the repository at this point in the history
  • Loading branch information
v1siuol committed Aug 5, 2021
1 parent 169377a commit d8003eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/brpc/rtmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ int WriteWithoutOvercrowded(Socket*, SocketMessagePtr<>& msg);
}

FlvWriter::FlvWriter(butil::IOBuf* buf)
: _write_header(false), _buf(buf) {
: _write_header(false), _buf(buf), _options() {
}

FlvWriter::FlvWriter(butil::IOBuf* buf, const FlvWriterOptions& options)
: _write_header(false), _buf(buf) {
const int flags_bit_index = 4;
_header[flags_bit_index] = static_cast<uint8_t>(options.flv_content_type);
: _write_header(false), _buf(buf), _options(options) {
}

butil::Status FlvWriter::Write(const RtmpVideoMessage& msg) {
char buf[32];
char* p = buf;
if (!_write_header) {
_write_header = true;
memcpy(p, _header, sizeof(_header));
p += sizeof(_header);
const char flags_bit = static_cast<char>(_options.flv_content_type);
const char header[9] = { 'F', 'L', 'V', 0x01, flags_bit, 0, 0, 0, 0x09 };
memcpy(p, header, sizeof(header));
p += sizeof(header);
policy::WriteBigEndian4Bytes(&p, 0); // PreviousTagSize0
}
// FLV tag
Expand All @@ -100,8 +100,10 @@ butil::Status FlvWriter::Write(const RtmpAudioMessage& msg) {
char* p = buf;
if (!_write_header) {
_write_header = true;
memcpy(p, _header, sizeof(_header));
p += sizeof(_header);
const char flags_bit = static_cast<char>(_options.flv_content_type);
const char header[9] = { 'F', 'L', 'V', 0x01, flags_bit, 0, 0, 0, 0x09 };
memcpy(p, header, sizeof(header));
p += sizeof(header);
policy::WriteBigEndian4Bytes(&p, 0); // PreviousTagSize0
}
// FLV tag
Expand Down Expand Up @@ -129,8 +131,10 @@ butil::Status FlvWriter::WriteScriptData(const butil::IOBuf& req_buf, uint32_t t
char* p = buf;
if (!_write_header) {
_write_header = true;
memcpy(p, _header, sizeof(_header));
p += sizeof(_header);
const char flags_bit = static_cast<char>(_options.flv_content_type);
const char header[9] = { 'F', 'L', 'V', 0x01, flags_bit, 0, 0, 0, 0x09 };
memcpy(p, header, sizeof(header));
p += sizeof(header);
policy::WriteBigEndian4Bytes(&p, 0); // PreviousTagSize0
}
// FLV tag
Expand Down
2 changes: 1 addition & 1 deletion src/brpc/rtmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ class FlvWriter {

private:
bool _write_header;
char _header[9] = { 'F', 'L', 'V', 0x01, 0x05, 0, 0, 0, 0x09 };
butil::IOBuf* _buf;
FlvWriterOptions _options;
};

class FlvReader {
Expand Down

0 comments on commit d8003eb

Please sign in to comment.