Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
mapengfei53 committed Jan 8, 2023
1 parent 1921dde commit 4f83d39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
42 changes: 21 additions & 21 deletions trunk/src/kernel/srs_kernel_mp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5947,19 +5947,7 @@ srs_error_t SrsMp4Encoder::flush()
SrsMp4SampleDescriptionBox* stsd = new SrsMp4SampleDescriptionBox();
stbl->set_stsd(stsd);

if (vcodec == SrsVideoCodecIdHEVC) {
SrsMp4VisualSampleEntry* hev1 = new SrsMp4VisualSampleEntry(SrsMp4BoxTypeHEV1);
stsd->append(hev1);

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

SrsMp4HvcCBox* hvcC = new SrsMp4HvcCBox();
hev1->set_hvcC(hvcC);

hvcC->hevc_config = phvcc;
} else {
if (vcodec == SrsVideoCodecIdAVC) {
SrsMp4VisualSampleEntry* avc1 = new SrsMp4VisualSampleEntry(SrsMp4BoxTypeAVC1);
stsd->append(avc1);

Expand All @@ -5971,6 +5959,18 @@ srs_error_t SrsMp4Encoder::flush()
avc1->set_avcC(avcC);

avcC->avc_config = pavcc;
} else {
SrsMp4VisualSampleEntry* hev1 = new SrsMp4VisualSampleEntry(SrsMp4BoxTypeHEV1);
stsd->append(hev1);

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

SrsMp4HvcCBox* hvcC = new SrsMp4HvcCBox();
hev1->set_hvcC(hvcC);

hvcC->hevc_config = phvcc;
}
}

Expand Down Expand Up @@ -6130,14 +6130,6 @@ srs_error_t SrsMp4Encoder::copy_sequence_header(SrsFormat* format, bool vsh, uin
srs_error_t err = srs_success;

if (vsh) {
// HEVC
if (format->vcodec->id == SrsVideoCodecIdHEVC && !phvcc.empty()) {
if (nb_sample == (uint32_t)phvcc.size() && srs_bytes_equals(sample, &phvcc[0], (int)phvcc.size())) {
return err;
}

return srs_error_new(ERROR_MP4_HVCC_CHANGE, "doesn't support hvcC change");
}
// AVC
if (format->vcodec->id == SrsVideoCodecIdAVC && !pavcc.empty()) {
if (nb_sample == (uint32_t)pavcc.size() && srs_bytes_equals(sample, &pavcc[0], (int)pavcc.size())) {
Expand All @@ -6146,6 +6138,14 @@ srs_error_t SrsMp4Encoder::copy_sequence_header(SrsFormat* format, bool vsh, uin

return srs_error_new(ERROR_MP4_AVCC_CHANGE, "doesn't support avcc change");
}
// HEVC
if (format->vcodec->id == SrsVideoCodecIdHEVC && !phvcc.empty()) {
if (nb_sample == (uint32_t)phvcc.size() && srs_bytes_equals(sample, &phvcc[0], (int)phvcc.size())) {
return err;
}

return srs_error_new(ERROR_MP4_HVCC_CHANGE, "doesn't support hvcC change");
}
}

if (!vsh && !pasc.empty()) {
Expand Down
5 changes: 5 additions & 0 deletions trunk/src/utest/srs_utest_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5266,6 +5266,7 @@ VOID TEST(KernelMP4Test, CoverMP4CodecSingleFrame)
}

enc.acodec = SrsAudioCodecIdAAC;
enc.vcodec = SrsVideoCodecIdAVC;

HELPER_EXPECT_SUCCESS(enc.flush());
//mock_print_mp4(string(f.data(), f.filesize()));
Expand Down Expand Up @@ -5382,6 +5383,7 @@ VOID TEST(KernelMP4Test, CoverMP4MultipleVideos)
}

enc.acodec = SrsAudioCodecIdAAC;
enc.vcodec = SrsVideoCodecIdAVC;

// Flush encoder.
HELPER_EXPECT_SUCCESS(enc.flush());
Expand Down Expand Up @@ -5482,6 +5484,7 @@ VOID TEST(KernelMP4Test, CoverMP4MultipleCTTs)
}

enc.acodec = SrsAudioCodecIdAAC;
enc.vcodec = SrsVideoCodecIdAVC;

// Flush encoder.
HELPER_EXPECT_SUCCESS(enc.flush());
Expand Down Expand Up @@ -5596,6 +5599,7 @@ VOID TEST(KernelMP4Test, CoverMP4MultipleAVs)
}

enc.acodec = SrsAudioCodecIdAAC;
enc.vcodec = SrsVideoCodecIdAVC;

// Flush encoder.
HELPER_EXPECT_SUCCESS(enc.flush());
Expand Down Expand Up @@ -5714,6 +5718,7 @@ VOID TEST(KernelMP4Test, CoverMP4MultipleAVsWithMp3)
}

enc.acodec = SrsAudioCodecIdMP3;
enc.vcodec = SrsVideoCodecIdAVC;

// Flush encoder.
HELPER_EXPECT_SUCCESS(enc.flush());
Expand Down

0 comments on commit 4f83d39

Please sign in to comment.