Skip to content

Commit

Permalink
Fix #1105, dvr mp4 supports playing on Chrome/Safari/Firefox. 3.0.86
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Dec 26, 2019
1 parent c70bc01 commit 7584c47
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
2 changes: 2 additions & 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, 2019-12-26, For [#1105][bug #1105], dvr mp4 supports playing on Chrome/Safari/Firefox. 3.0.86
* <strong>v3.0, 2019-12-26, [3.0 alpha6(3.0.85)][r3.0a6] released. 116056 lines.</strong>
* v3.0, 2019-12-26, For [#1488][bug #1488], pass client ip to http callback. 3.0.85
* v3.0, 2019-12-25, For [#1537][bug #1537], [#1282][bug #1282], support aarch64 for armv8. 3.0.84
Expand Down Expand Up @@ -1565,6 +1566,7 @@ Winlin
[bug #1537]: https://github.com/ossrs/srs/issues/1537
[bug #1538]: https://github.com/ossrs/srs/issues/1538
[bug #1282]: https://github.com/ossrs/srs/issues/1282
[bug #1105]: https://github.com/ossrs/srs/issues/1105
[bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx

[exo #828]: https://github.com/google/ExoPlayer/pull/828
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ srs_error_t SrsDvrMp4Segmenter::encode_audio(SrsSharedPtrMessage* audio, SrsForm
uint32_t nb_sample = (uint32_t)format->nb_raw;

uint32_t dts = (uint32_t)audio->timestamp;
if ((err = enc->write_sample(SrsMp4HandlerTypeSOUN, 0x00, ct, dts, dts, sample, nb_sample)) != srs_success) {
if ((err = enc->write_sample(format, SrsMp4HandlerTypeSOUN, 0x00, ct, dts, dts, sample, nb_sample)) != srs_success) {
return srs_error_wrap(err, "write sample");
}

Expand All @@ -515,7 +515,7 @@ srs_error_t SrsDvrMp4Segmenter::encode_video(SrsSharedPtrMessage* video, SrsForm

uint8_t* sample = (uint8_t*)format->raw;
uint32_t nb_sample = (uint32_t)format->nb_raw;
if ((err = enc->write_sample(SrsMp4HandlerTypeVIDE, frame_type, ct, dts, pts, sample, nb_sample)) != srs_success) {
if ((err = enc->write_sample(format, SrsMp4HandlerTypeVIDE, frame_type, ct, dts, pts, sample, nb_sample)) != srs_success) {
return srs_error_wrap(err, "write sample");
}

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// The version config.
#define VERSION_MAJOR 3
#define VERSION_MINOR 0
#define VERSION_REVISION 85
#define VERSION_REVISION 86

// The macros generated by configure script.
#include <srs_auto_headers.hpp>
Expand Down
44 changes: 34 additions & 10 deletions trunk/src/kernel/srs_kernel_mp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2047,10 +2047,8 @@ stringstream& SrsMp4TrackHeaderBox::dumps_detail(stringstream& ss, SrsMp4DumpCon
if (volume) {
ss << ", volume=" << uint32_t(volume>>8) << "." << uint32_t(volume&0xFF);
}

if (width || height) {
ss << ", size=" << uint16_t(width>>16) << "x" << uint16_t(height>>16);
}

ss << ", size=" << uint16_t(width>>16) << "x" << uint16_t(height>>16);

return ss;
}
Expand Down Expand Up @@ -5528,6 +5526,26 @@ srs_error_t SrsMp4Encoder::initialize(ISrsWriteSeeker* ws)
return srs_error_wrap(err, "write ftyp");
}
}

// 8B reserved free box.
if (true) {
SrsMp4FreeSpaceBox* freeb = new SrsMp4FreeSpaceBox(SrsMp4BoxTypeFREE);
SrsAutoFree(SrsMp4FreeSpaceBox, freeb);

int nb_data = freeb->nb_bytes();
std::vector<char> data(nb_data);

SrsBuffer* buffer = new SrsBuffer(&data[0], nb_data);
SrsAutoFree(SrsBuffer, buffer);

if ((err = freeb->encode(buffer)) != srs_success) {
return srs_error_wrap(err, "encode free box");
}

if ((err = wsio->write(&data[0], nb_data, NULL)) != srs_success) {
return srs_error_wrap(err, "write free box");
}
}

// Write mdat box.
if (true) {
Expand Down Expand Up @@ -5564,8 +5582,10 @@ srs_error_t SrsMp4Encoder::initialize(ISrsWriteSeeker* ws)
return err;
}

srs_error_t SrsMp4Encoder::write_sample(SrsMp4HandlerType ht, uint16_t ft, uint16_t ct, uint32_t dts, uint32_t pts, uint8_t* sample, uint32_t nb_sample)
{
srs_error_t SrsMp4Encoder::write_sample(
SrsFormat* format, SrsMp4HandlerType ht, uint16_t ft, uint16_t ct, uint32_t dts, uint32_t pts,
uint8_t* sample, uint32_t nb_sample
) {
srs_error_t err = srs_success;

SrsMp4Sample* ps = new SrsMp4Sample();
Expand All @@ -5574,7 +5594,7 @@ srs_error_t SrsMp4Encoder::write_sample(SrsMp4HandlerType ht, uint16_t ft, uint1
bool vsh = (ht == SrsMp4HandlerTypeVIDE) && (ct == (uint16_t)SrsVideoAvcFrameTraitSequenceHeader);
bool ash = (ht == SrsMp4HandlerTypeSOUN) && (ct == (uint16_t)SrsAudioAacFrameTraitSequenceHeader);
if (vsh || ash) {
err = copy_sequence_header(vsh, sample, nb_sample);
err = copy_sequence_header(format, vsh, sample, nb_sample);
srs_freep(ps);
return err;
}
Expand Down Expand Up @@ -5683,6 +5703,7 @@ srs_error_t SrsMp4Encoder::flush()

avc1->width = width;
avc1->height = height;
avc1->data_reference_index = 1;

SrsMp4AvccBox* avcC = new SrsMp4AvccBox();
avc1->set_avcC(avcC);
Expand Down Expand Up @@ -5741,6 +5762,7 @@ srs_error_t SrsMp4Encoder::flush()
stbl->set_stsd(stsd);

SrsMp4AudioSampleEntry* mp4a = new SrsMp4AudioSampleEntry();
mp4a->data_reference_index = 1;
mp4a->samplerate = uint32_t(srs_flv_srates[sample_rate]) << 16;
if (sound_bits == SrsAudioSampleBits16bit) {
mp4a->samplesize = 16;
Expand Down Expand Up @@ -5826,7 +5848,7 @@ srs_error_t SrsMp4Encoder::flush()
return err;
}

srs_error_t SrsMp4Encoder::copy_sequence_header(bool vsh, uint8_t* sample, uint32_t nb_sample)
srs_error_t SrsMp4Encoder::copy_sequence_header(SrsFormat* format, bool vsh, uint8_t* sample, uint32_t nb_sample)
{
srs_error_t err = srs_success;

Expand All @@ -5848,8 +5870,10 @@ srs_error_t SrsMp4Encoder::copy_sequence_header(bool vsh, uint8_t* sample, uint3

if (vsh) {
pavcc = std::vector<char>(sample, sample + nb_sample);

// TODO: FIXME: Parse the width and height.
if (format && format->vcodec) {
width = format->vcodec->width;
height = format->vcodec->height;
}
}

if (!vsh) {
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/kernel/srs_kernel_mp4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2024,12 +2024,12 @@ class SrsMp4Encoder
// @param pts The output pts in milliseconds.
// @param sample The output payload, user must free it.
// @param nb_sample The output size of payload.
virtual srs_error_t write_sample(SrsMp4HandlerType ht, uint16_t ft, uint16_t ct,
virtual srs_error_t write_sample(SrsFormat* format, SrsMp4HandlerType ht, uint16_t ft, uint16_t ct,
uint32_t dts, uint32_t pts, uint8_t* sample, uint32_t nb_sample);
// Flush the encoder, to write the moov.
virtual srs_error_t flush();
private:
virtual srs_error_t copy_sequence_header(bool vsh, uint8_t* sample, uint32_t nb_sample);
virtual srs_error_t copy_sequence_header(SrsFormat* format, bool vsh, uint8_t* sample, uint32_t nb_sample);
virtual srs_error_t do_write_sample(SrsMp4Sample* ps, uint8_t* sample, uint32_t nb_sample);
};

Expand Down
8 changes: 4 additions & 4 deletions trunk/src/utest/srs_utest_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4589,7 +4589,7 @@ VOID TEST(KernelMP4Test, CoverMP4Codec)
};
EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw
NULL, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw
));
}

Expand All @@ -4599,7 +4599,7 @@ VOID TEST(KernelMP4Test, CoverMP4Codec)
};
EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw
NULL, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw
));
}

Expand All @@ -4615,7 +4615,7 @@ VOID TEST(KernelMP4Test, CoverMP4Codec)
};
EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 34, 34, (uint8_t*)fmt.raw, fmt.nb_raw
NULL, SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 34, 34, (uint8_t*)fmt.raw, fmt.nb_raw
));
}

Expand All @@ -4634,7 +4634,7 @@ VOID TEST(KernelMP4Test, CoverMP4Codec)
};
EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 40, 40, (uint8_t*)fmt.raw, fmt.nb_raw
NULL, SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 40, 40, (uint8_t*)fmt.raw, fmt.nb_raw
));
}

Expand Down

0 comments on commit 7584c47

Please sign in to comment.