Skip to content

Commit

Permalink
av_freepの使い方が誤っていたのを修正。
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed Mar 23, 2024
1 parent 9093933 commit 55cf273
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions NVEncCore/rgy_avutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ std::string tagToStr(uint32_t tag);

//AVStreamのside data関連
template<typename T>
std::unique_ptr<T, decltype(&av_freep)> AVStreamGetSideData(const AVStream *stream, const AVPacketSideDataType type, size_t& side_data_size) {
std::unique_ptr<T, decltype(&av_freep)> side_data_copy(nullptr, av_freep);
std::unique_ptr<T, RGYAVDeleter<T>> AVStreamGetSideData(const AVStream *stream, const AVPacketSideDataType type, size_t& side_data_size) {
std::unique_ptr<T, RGYAVDeleter<T>> side_data_copy(nullptr, RGYAVDeleter<T>(av_freep));
#if AVCODEC_PAR_CODED_SIDE_DATA_AVAIL
auto side_data = av_packet_side_data_get(stream->codecpar->coded_side_data, stream->codecpar->nb_coded_side_data, type);
if (side_data) {
side_data_size = side_data->size;
side_data_copy = unique_ptr<T, decltype(&av_freep)>((T *)av_malloc(side_data->size + AV_INPUT_BUFFER_PADDING_SIZE), av_freep);
side_data_copy = unique_ptr<T, RGYAVDeleter<T>>((T *)av_malloc(side_data->size + AV_INPUT_BUFFER_PADDING_SIZE), RGYAVDeleter<T>(av_freep));
memcpy(side_data_copy.get(), side_data, side_data->size);
}
#else
Expand All @@ -428,7 +428,7 @@ std::unique_ptr<T, decltype(&av_freep)> AVStreamGetSideData(const AVStream *stre
}

template<typename T>
int AVStreamAddSideData(AVStream *stream, const AVPacketSideDataType type, std::unique_ptr<T, decltype(&av_freep)>& side_data, const size_t side_data_size) {
int AVStreamAddSideData(AVStream *stream, const AVPacketSideDataType type, std::unique_ptr<T, RGYAVDeleter<T>>& side_data, const size_t side_data_size) {
#if AVCODEC_PAR_CODED_SIDE_DATA_AVAIL
auto ptr = av_packet_side_data_add(&stream->codecpar->coded_side_data, &stream->codecpar->nb_coded_side_data, type, (void *)side_data.get(), side_data_size, 0);
int ret = ptr ? 0 : AVERROR(ENOMEM);
Expand Down
8 changes: 4 additions & 4 deletions NVEncCore/rgy_input_avcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ AVDemuxVideo::AVDemuxVideo() :
hevcNaluLengthSize(0),
hdr10plusMetadataCopy(false),
doviRpuCopy(false),
masteringDisplay(std::unique_ptr<AVMasteringDisplayMetadata, decltype(&av_freep)>(nullptr, av_freep)),
contentLight(std::unique_ptr<AVContentLightMetadata, decltype(&av_freep)>(nullptr, av_freep)),
masteringDisplay(std::unique_ptr<AVMasteringDisplayMetadata, RGYAVDeleter<AVMasteringDisplayMetadata>>(nullptr, RGYAVDeleter<AVMasteringDisplayMetadata>(av_freep))),
contentLight(std::unique_ptr<AVContentLightMetadata, RGYAVDeleter<AVContentLightMetadata>>(nullptr, RGYAVDeleter<AVContentLightMetadata>(av_freep))),
qpTableListRef(nullptr),
parse_nal_h264(get_parse_nal_unit_h264_func()),
parse_nal_hevc(get_parse_nal_unit_hevc_func()) {
Expand Down Expand Up @@ -1187,7 +1187,7 @@ RGY_ERR RGYInputAvcodec::parseHDRData() {
if (got_frame) {
auto side_data = av_frame_get_side_data(frameDec.get(), AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
if (side_data) {
m_Demux.video.masteringDisplay = std::unique_ptr<AVMasteringDisplayMetadata, decltype(&av_freep)>(av_mastering_display_metadata_alloc(), av_freep);
m_Demux.video.masteringDisplay = std::unique_ptr<AVMasteringDisplayMetadata, RGYAVDeleter<AVMasteringDisplayMetadata>>(av_mastering_display_metadata_alloc(), RGYAVDeleter<AVMasteringDisplayMetadata>(av_freep));
memcpy(m_Demux.video.masteringDisplay.get(), side_data->data, sizeof(AVMasteringDisplayMetadata));
AddMessage(RGY_LOG_DEBUG, _T("Mastering Display: R(%f,%f) G(%f,%f) B(%f %f) WP(%f, %f) L(%f,%f)\n"),
av_q2d(m_Demux.video.masteringDisplay->display_primaries[0][0]),
Expand All @@ -1202,7 +1202,7 @@ RGY_ERR RGYInputAvcodec::parseHDRData() {
side_data = av_frame_get_side_data(frameDec.get(), AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
if (side_data) {
size_t st_size = 0;
m_Demux.video.contentLight = std::unique_ptr<AVContentLightMetadata, decltype(&av_freep)>(av_content_light_metadata_alloc(&st_size), av_freep);
m_Demux.video.contentLight = std::unique_ptr<AVContentLightMetadata, RGYAVDeleter<AVContentLightMetadata>>(av_content_light_metadata_alloc(&st_size), RGYAVDeleter<AVContentLightMetadata>(av_freep));
memcpy(m_Demux.video.contentLight.get(), side_data->data, st_size);
AddMessage(RGY_LOG_DEBUG, _T("MaxCLL=%d, MaxFALL=%d\n"), m_Demux.video.contentLight->MaxCLL, m_Demux.video.contentLight->MaxFALL);
}
Expand Down
4 changes: 2 additions & 2 deletions NVEncCore/rgy_input_avcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,8 @@ struct AVDemuxVideo {
bool hdr10plusMetadataCopy; //HDR10plusのメタ情報を取得する
bool doviRpuCopy; //dovi rpuのメタ情報を取得する

std::unique_ptr<AVMasteringDisplayMetadata, decltype(&av_freep)> masteringDisplay; //入力ファイルから抽出したHDRメタ情報
std::unique_ptr<AVContentLightMetadata, decltype(&av_freep)> contentLight; //入力ファイルから抽出したHDRメタ情報
std::unique_ptr<AVMasteringDisplayMetadata, RGYAVDeleter<AVMasteringDisplayMetadata>> masteringDisplay; //入力ファイルから抽出したHDRメタ情報
std::unique_ptr<AVContentLightMetadata, RGYAVDeleter<AVContentLightMetadata>> contentLight; //入力ファイルから抽出したHDRメタ情報

RGYListRef<RGYFrameDataQP> *qpTableListRef; //qp tableを格納するときのベース構造体
decltype(parse_nal_unit_h264_c) *parse_nal_h264; // H.264用のnal unit分解関数へのポインタ
Expand Down
4 changes: 2 additions & 2 deletions NVEncCore/rgy_output_avcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ RGY_ERR RGYOutputAvcodec::InitVideo(const VideoInfo *videoOutputInfo, const Avco

const auto HEVCHdrSeiPrm = prm->hdrMetadata->getprm();
if (false && HEVCHdrSeiPrm.masterdisplay_set) {
std::unique_ptr<AVMasteringDisplayMetadata, decltype(&av_freep)> mastering(av_mastering_display_metadata_alloc(), av_freep);
std::unique_ptr<AVMasteringDisplayMetadata, RGYAVDeleter<AVMasteringDisplayMetadata>> mastering(av_mastering_display_metadata_alloc(), RGYAVDeleter<AVMasteringDisplayMetadata>(av_freep));

//streamのside dataとしてmasteringdisplay等を設定する
mastering->display_primaries[1][0] = av_make_q(HEVCHdrSeiPrm.masterdisplay[0]); //G
Expand Down Expand Up @@ -984,7 +984,7 @@ RGY_ERR RGYOutputAvcodec::InitVideo(const VideoInfo *videoOutputInfo, const Avco

if (false && HEVCHdrSeiPrm.contentlight_set) {
size_t coll_size = 0;
std::unique_ptr<AVContentLightMetadata, decltype(&av_freep)> coll(av_content_light_metadata_alloc(&coll_size), av_freep);
std::unique_ptr<AVContentLightMetadata, RGYAVDeleter<AVContentLightMetadata>> coll(av_content_light_metadata_alloc(&coll_size), RGYAVDeleter<AVContentLightMetadata>(av_freep));
coll->MaxCLL = HEVCHdrSeiPrm.maxcll;
coll->MaxFALL = HEVCHdrSeiPrm.maxfall;
AddMessage(RGY_LOG_DEBUG, _T("MaxCLL=%d, MaxFALL=%d\n"),
Expand Down

0 comments on commit 55cf273

Please sign in to comment.