Skip to content

Commit

Permalink
[video][subtitles] Use unique_ptr for A53 side data
Browse files Browse the repository at this point in the history
  • Loading branch information
enen92 committed Dec 31, 2022
1 parent dd24650 commit a562c10
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
45 changes: 43 additions & 2 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,46 @@ VideoPicture& VideoPicture::SetParams(const VideoPicture &pic)
return *this;
}

VideoPicture::VideoPicture(VideoPicture const&) = default;
VideoPicture& VideoPicture::operator=(VideoPicture const&) = default;
VideoPicture& VideoPicture::operator=(VideoPicture const& pic)
{
if (this != &pic)
{
if (videoBuffer)
videoBuffer->Release();
videoBuffer = pic.videoBuffer;
if (videoBuffer)
videoBuffer->Acquire();

pts = pic.pts;
dts = pic.dts;
iFlags = pic.iFlags;
iRepeatPicture = pic.iRepeatPicture;
iDuration = pic.iDuration;
iFrameType = pic.iFrameType;
color_space = pic.color_space;
color_range = pic.color_range;
chroma_position = pic.chroma_position;
color_primaries = pic.color_primaries;
color_transfer = pic.color_transfer;
colorBits = pic.colorBits;
stereoMode = pic.stereoMode;

iWidth = pic.iWidth;
iHeight = pic.iHeight;
iDisplayWidth = pic.iDisplayWidth;
iDisplayHeight = pic.iDisplayHeight;

hasDisplayMetadata = pic.hasDisplayMetadata;
hasLightMetadata = pic.hasLightMetadata;

qp_table = pic.qp_table;
qstride = pic.qstride;
qscale_type = pic.qscale_type;
pict_type = pic.pict_type;

if (pic.HasA53SideData())
SetA53SideData(pic.m_A53SideData.get());
}

return *this;
}
20 changes: 14 additions & 6 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class CSetting;
#define FRAME_TYPE_B 3
#define FRAME_TYPE_D 4

/*!
* \brief Deleter for AVBufferRef (ATSC A53 closed captions)
*/
struct AVBufferRefDeleter
{
void operator()(AVBufferRef* ref) { av_buffer_unref(&ref); }
};

// should be entirely filled by all codecs
struct VideoPicture
Expand All @@ -53,19 +60,20 @@ struct VideoPicture
* \brief Gets the A53 side data of the video picture (closed captions)
* \return the A53 side data, reseting the value
*/
AVBufferRef* ConsumeA53SideData()
std::unique_ptr<AVBufferRef, AVBufferRefDeleter> GetA53SideData()
{
AVBufferRef* sideData = m_A53SideData;
m_A53SideData = nullptr;
return sideData;
return std::move(m_A53SideData);
}

/*!
* \brief Set the A53 side data on the video picture
*
* \param[in] sideData the data to store as A53 side data
*/
void SetA53SideData(AVBufferRef* sideData) { m_A53SideData = av_buffer_ref(sideData); }
void SetA53SideData(AVBufferRef* sideData)
{
m_A53SideData = std::unique_ptr<AVBufferRef, AVBufferRefDeleter>(av_buffer_ref(sideData));
}

/*!
* \brief Releases the sidedata data, decreasing its reference count
Expand Down Expand Up @@ -110,7 +118,7 @@ struct VideoPicture
private:
VideoPicture(VideoPicture const&);
VideoPicture& operator=(VideoPicture const&);
AVBufferRef* m_A53SideData;
std::unique_ptr<AVBufferRef, AVBufferRefDeleter> m_A53SideData;
};

#define DVP_FLAG_TOP_FIELD_FIRST 0x00000001
Expand Down
3 changes: 1 addition & 2 deletions xbmc/cores/VideoPlayer/VideoPlayerVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,9 @@ bool CVideoPlayerVideo::ProcessDecoderOutput(double &frametime, double &pts)
CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
CSettings::SETTING_SUBTITLES_PARSECAPTIONS))
{
AVBufferRef* a53SideData = m_picture.ConsumeA53SideData();
std::unique_ptr<AVBufferRef, AVBufferRefDeleter> a53SideData = m_picture.GetA53SideData();
auto ccData =
std::make_unique<CCaptionBlock>(m_picture.pts, a53SideData->data, a53SideData->size);
m_picture.ReleaseA53SideData(&a53SideData);
m_messageParent.Put(std::make_shared<CDVDMsgSubtitleCCData>(ccData));
}

Expand Down

0 comments on commit a562c10

Please sign in to comment.