Skip to content

Commit

Permalink
Fix #939, response right A/V flag in FLV header. 3.0.113
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 4, 2020
1 parent 68efca4 commit 4f39303
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ For previous versions, please read:

## V3 changes

* v3.0, 2020-02-04, Fix [#939][bug #939], response right A/V flag in FLV header. 3.0.113
* v3.0, 2020-02-04, For [#939][bug #939], always enable fast FLV streaming.
* <strong>v3.0, 2020-02-02, [3.0 beta0(3.0.112)][r3.0b0] released. 121709 lines.</strong>
* v3.0, 2020-01-29, Support isolate version file. 3.0.112
Expand Down
67 changes: 62 additions & 5 deletions trunk/src/app/srs_app_http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ srs_error_t SrsTsStreamEncoder::dump_cache(SrsConsumer* /*consumer*/, SrsRtmpJit

SrsFlvStreamEncoder::SrsFlvStreamEncoder()
{
header_written = false;
enc = new SrsFlvTransmuxer();
}

Expand All @@ -265,26 +266,39 @@ srs_error_t SrsFlvStreamEncoder::initialize(SrsFileWriter* w, SrsBufferCache* /*
return srs_error_wrap(err, "init encoder");
}

// write flv header.
if ((err = enc->write_header()) != srs_success) {
return srs_error_wrap(err, "write header");
}

return err;
}

srs_error_t SrsFlvStreamEncoder::write_audio(int64_t timestamp, char* data, int size)
{
srs_error_t err = srs_success;

if ((err = write_header()) != srs_success) {
return srs_error_wrap(err, "write header");
}

return enc->write_audio(timestamp, data, size);
}

srs_error_t SrsFlvStreamEncoder::write_video(int64_t timestamp, char* data, int size)
{
srs_error_t err = srs_success;

if ((err = write_header()) != srs_success) {
return srs_error_wrap(err, "write header");
}

return enc->write_video(timestamp, data, size);
}

srs_error_t SrsFlvStreamEncoder::write_metadata(int64_t timestamp, char* data, int size)
{
srs_error_t err = srs_success;

if ((err = write_header()) != srs_success) {
return srs_error_wrap(err, "write header");
}

return enc->write_metadata(SrsFrameTypeScript, data, size);
}

Expand All @@ -302,9 +316,52 @@ srs_error_t SrsFlvStreamEncoder::dump_cache(SrsConsumer* /*consumer*/, SrsRtmpJi

srs_error_t SrsFlvStreamEncoder::write_tags(SrsSharedPtrMessage** msgs, int count)
{
srs_error_t err = srs_success;

// For https://github.com/ossrs/srs/issues/939
if (!header_written) {
bool has_video = false;
bool has_audio = false;

for (int i = 0; i < count && (!has_video || !has_audio); i++) {
SrsSharedPtrMessage* msg = msgs[i];
if (msg->is_video()) {
has_video = true;
} else if (msg->is_audio()) {
has_audio = true;
}
}

// Drop data if no A+V.
if (!has_video && !has_audio) {
return err;
}

if ((err = write_header(has_video, has_audio)) != srs_success) {
return srs_error_wrap(err, "write header");
}
}

return enc->write_tags(msgs, count);
}

srs_error_t SrsFlvStreamEncoder::write_header(bool has_video, bool has_audio)
{
srs_error_t err = srs_success;

if (!header_written) {
header_written = true;

if ((err = enc->write_header(has_video, has_audio)) != srs_success) {
return srs_error_wrap(err, "write header");
}

srs_trace("FLV: write header audio=%d, video=%d", has_audio, has_video);
}

return err;
}

SrsAacStreamEncoder::SrsAacStreamEncoder()
{
enc = new SrsAacTransmuxer();
Expand Down
5 changes: 4 additions & 1 deletion trunk/src/app/srs_app_http_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ class ISrsBufferEncoder
// Transmux RTMP to HTTP Live Streaming.
class SrsFlvStreamEncoder : public ISrsBufferEncoder
{
protected:
private:
SrsFlvTransmuxer* enc;
bool header_written;
public:
SrsFlvStreamEncoder();
virtual ~SrsFlvStreamEncoder();
Expand All @@ -98,6 +99,8 @@ class SrsFlvStreamEncoder : public ISrsBufferEncoder
public:
// Write the tags in a time.
virtual srs_error_t write_tags(SrsSharedPtrMessage** msgs, int count);
private:
virtual srs_error_t write_header(bool has_video = true, bool has_audio = true);
};

// Transmux RTMP to HTTP TS Streaming.
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION3_HPP
#define SRS_CORE_VERSION3_HPP

#define SRS_VERSION3_REVISION 112
#define SRS_VERSION3_REVISION 113

#endif

0 comments on commit 4f39303

Please sign in to comment.