Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
mapengfei53 committed Jan 7, 2023
1 parent 573c31c commit 29a959b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 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
13 changes: 9 additions & 4 deletions trunk/src/utest/srs_utest_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5265,7 +5265,8 @@ VOID TEST(KernelMP4Test, CoverMP4CodecSingleFrame)
));
}

enc.acodec = SrsAudioCodecIdAAC;
enc.acodec = fmt.acodec->id;
enc.vcodec = fmt.vcodec->id;

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

enc.acodec = SrsAudioCodecIdAAC;
enc.acodec = fmt.acodec->id;
enc.vcodec = fmt.vcodec->id;

// Flush encoder.
HELPER_EXPECT_SUCCESS(enc.flush());
Expand Down Expand Up @@ -5481,7 +5483,8 @@ VOID TEST(KernelMP4Test, CoverMP4MultipleCTTs)
));
}

enc.acodec = SrsAudioCodecIdAAC;
enc.acodec = fmt.acodec->id;
enc.vcodec = fmt.vcodec->id;

// Flush encoder.
HELPER_EXPECT_SUCCESS(enc.flush());
Expand Down Expand Up @@ -5595,7 +5598,8 @@ VOID TEST(KernelMP4Test, CoverMP4MultipleAVs)
));
}

enc.acodec = SrsAudioCodecIdAAC;
enc.acodec = fmt.acodec->id;
enc.vcodec = fmt.vcodec->id;

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

enc.acodec = SrsAudioCodecIdMP3;
enc.vcodec = fmt.vcodec->id;

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

0 comments on commit 29a959b

Please sign in to comment.